-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDoWork.js
More file actions
34 lines (30 loc) · 929 Bytes
/
DoWork.js
File metadata and controls
34 lines (30 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const RandomWords = require('random-words')
const SHA256 = require('crypto-js/sha256')
function goodWork (data, conditionString) {
let challenge = JSON.stringify(data)
let proof = ''
let hash = 'abcde'
// keep iterating until we find a proof string that matches the requirement
while(hash.slice(0,conditionString.length) !== conditionString) {
proof = getAString()
hash = SHA256(challenge + proof).toString()
// console.log(hash)
}
// console.log('->' + proof)
// console.log('->' + hash)
return proof
}
// this most likely will produce a bogus proof
function bogusWork () {
return 'BAD STRING'
}
// creates a concatenated string of random English words
function getAString() {
let string = ''
for(let i = 0; i < 9; i++) {
string += RandomWords()
}
return string
}
module.exports.goodWork = goodWork
module.exports.bogusWork = bogusWork