-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathv1.js
33 lines (32 loc) · 820 Bytes
/
v1.js
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
const secrets = require('secrets.js-grempe')
module.exports = {
pack: function packV1 (secret) {
return secret
},
unpack: function unpackV1 (secret) {
return { secret }
},
share: function shareV1 (secret, numOfShards, quorum) {
const hexSecret = secrets.str2hex(secret)
return secrets.share(hexSecret, numOfShards, quorum)
},
combine: function combineV1 (shards) {
const hex = secrets.combine(shards)
return secrets.hex2str(hex)
},
verify: function verifyV1 (shards) {
try {
throw new Error("version 1.0.0 doesn't support secret verification")
} catch (err) {
return false
}
},
validateShard: function validateShardV1 (shard) {
try {
secrets.extractShareComponents(shard)
} catch (err) {
return false
}
return true
}
}