Commit ae4cea62 authored by Bijun Li's avatar Bijun Li
Browse files

Update vss lib for share hash

parent c6da190a
Showing with 20 additions and 1 deletion
+20 -1
......@@ -158,6 +158,22 @@ exports.verifyShare = function (bls, share, vvec) {
return Boolean(isEqual)
}
/**
* calculates a hash against a share
* @param {Object} bls - an instance of [bls-wasm](https://github.com/herumi/bls-wasm)
* @param {Object} share - a share to be verified
* @return {String}
*/
exports.hashShare = function (bls, share) {
const sk = new bls.SecretKey()
sk.deserialize(share.sk)
const sHash = new bls.Fr()
sHash.setHashOf(sk.serializeToHexStr())
return sHash.serializeToHexStr()
}
/**
* recovers the secret from a selection of shares
* @param {Object} bls - an instance of [bls-wasm](https://github.com/herumi/bls-wasm)
......
......@@ -18,6 +18,9 @@ const curveTest = (curveType, name) => {
setup.shares.forEach(share => {
const verified = vss.verifyShare(bls, share, result.verificationVector)
assert.strict.deepEqual(verified, true, 'should verify share')
const shareHash = vss.hashShare(bls, share)
console.log('shareHash:', shareHash)
})
var reSecret = vss.recoverSecret(bls, setup.shares.slice(0, threshold))
......@@ -36,7 +39,7 @@ const curveTest = (curveType, name) => {
reSecret = vss.recoverSecret(bls, renewal.shares.slice(0, threshold))
const sec2 = new bls.SecretKey()
sec2.deserialize(reSecret)
console.log('recovered:', sec2.serializeToHexStr())
console.log('renew-recovered:', sec2.serializeToHexStr())
assert.strict.deepEqual(reSecret, result.secret, 'secret should not change after share renewal')
} catch (e) {
console.log(`TEST FAIL ${e}`)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment