1.0.0 • Published 5 years ago
dark-crystal-secrets v1.0.0
Dark Crystal Secrets
Dark Crystal's encryption wrapper around Shamir's Secret Shares implementation secrets.js-grempe
.
Using a semantic versioning system, this module also provides backward compatibility to Dark Crystal records out there in the wild. This is required as we incrementally update Dark Crystal's encryption schemes, exploring, experimenting and improving our implementation.
Example
const { pack, unpack. share, verify, combine } = require('dark-crystal-secretes')
const labelledSecret = pack('burried under my tree fort', 'treasure chest 1')
const shares = share(labelledSecret, 5, 3) // split into 5 parts, quorum 3
shares.forEach(share => console.log(validateShard(share, '2.0.0'))
const validity = verify(share.slice(0,3), '2.0.0')
console.log(validity)
const recoveredLabelledSecret = combine(share.slice(0,3), '2.0.0')
const { secret, label } = unpack(recoveredLabelledSecret, '2.0.0')
API
pack(secret, label)
The secret
is bundled up with the label
given to the secret and stringified as JSON
unpack(secret, version)
The secret
is separated from the label
and returned as an object
share(secret, numOfShards, quorum)
- Generates a
MAC
which is composed the first 32 characters (16 bytes) of aSHA256
hash of thesecret
- Concatenates it at the beginning of the
secret
- Splits the secret into
numOfShards
, wherequorum
is the number required to reassemble - Compresses the
shards
fromhex
intobase64
for more efficient storage
verify(shards, version)
- Decompresses the
shards
frombase64
tohex
- Reassembles the secret
- Checksig
MAC
generated from the newly returned secret match theMAC
attached to the returned secret.- Returns
false
if fails to pass check
combine(shards, version)
- Decompresses the shards from base64 to hex
- Reassembles the secret
- Checksig
MAC
generated from the newly returned secret match theMAC
attached to the returned secret.- Throws an error if it fails to pass the check
- Returns the
JSON
string secret
validateShard(shard, version)
1.0.0
5 years ago