@dashevo/dashcore-lib
Advanced tools
Comparing version 0.19.15 to 0.19.16
@@ -149,16 +149,7 @@ const { isObject, isString } = require('lodash'); | ||
async verifySignatureAgainstQuorum(quorumEntry, requestId) { | ||
const { signature } = this; | ||
const { quorumPublicKey } = quorumEntry; | ||
const signHash = this.getSignHashForQuorumEntry(quorumEntry, requestId); | ||
const blsInstance = await bls.getInstance(); | ||
const quorumPubKey = blsInstance.PublicKey.fromBytes(Buffer.from(quorumPublicKey, 'hex')); | ||
const aggregationInfo = blsInstance.AggregationInfo.fromMsgHash(quorumPubKey, signHash); | ||
const thresholdSignature = blsInstance.Signature.fromBytes(Buffer.from(signature, 'hex')); | ||
thresholdSignature.setAggregationInfo(aggregationInfo); | ||
return thresholdSignature.verify(); | ||
return bls.verifySignature( | ||
this.signature.toString('hex'), | ||
this.getSignHashForQuorumEntry(quorumEntry, requestId), | ||
quorumEntry.quorumPublicKey, | ||
); | ||
} | ||
@@ -165,0 +156,0 @@ |
@@ -35,4 +35,41 @@ const EventEmitter = require('events'); | ||
}, | ||
/** | ||
* Validate bls signature | ||
* @param {string} signatureHex | ||
* @param {Uint8Array} messageHash | ||
* @param {string} publicKeyHex | ||
* @return {Promise<boolean>} | ||
*/ | ||
async verifySignature(signatureHex, messageHash, publicKeyHex) { | ||
const blsInstance = await this.getInstance(); | ||
let result = false; | ||
let thresholdSignature; | ||
let quorumPubKey; | ||
let aggregationInfo; | ||
try { | ||
thresholdSignature = blsInstance.Signature.fromBytes(Uint8Array.from(Buffer.from(signatureHex, 'hex'))); | ||
quorumPubKey = blsInstance.PublicKey.fromBytes(Uint8Array.from(Buffer.from(publicKeyHex, 'hex'))); | ||
aggregationInfo = blsInstance.AggregationInfo.fromMsgHash(quorumPubKey, messageHash); | ||
thresholdSignature.setAggregationInfo(aggregationInfo); | ||
result = thresholdSignature.verify(); | ||
} catch (e) { | ||
// This line is because BLS is a c++ WebAssembly binding, it will throw | ||
// cryptic error messages if it fails to parse the signature. | ||
return result; | ||
} finally { | ||
// Values from emscripten compiled code can't be garbage collected in JS, | ||
// so they have to be released first using .delete method | ||
if (thresholdSignature) { thresholdSignature.delete(); } | ||
if (quorumPubKey) { quorumPubKey.delete(); } | ||
if (aggregationInfo) { aggregationInfo.delete(); } | ||
} | ||
return result; | ||
}, | ||
}; | ||
module.exports = bls; |
@@ -303,23 +303,12 @@ const _ = require('lodash'); | ||
*/ | ||
QuorumEntry.prototype.isValidQuorumSig = function isValidQuorumSig() { | ||
return new Promise((resolve, reject) => { | ||
if (this.isOutdatedRPC) { | ||
return reject(new Error('Quorum cannot be verified: node running on outdated DashCore version (< 0.16)')); | ||
} | ||
QuorumEntry.prototype.isValidQuorumSig = async function isValidQuorumSig() { | ||
if (this.isOutdatedRPC) { | ||
throw new Error('Quorum cannot be verified: node running on outdated DashCore version (< 0.16)'); | ||
} | ||
return bls.getInstance().then((blsInstance) => { | ||
const quorumPubKey = blsInstance.PublicKey.fromBytes(Uint8Array.from(Buffer.from(this.quorumPublicKey, 'hex'))); | ||
const msgHash = Uint8Array.from(this.getCommitmentHash()); | ||
const aggregationInfo = blsInstance.AggregationInfo.fromMsgHash(quorumPubKey, msgHash); | ||
const thresholdSignature = blsInstance.Signature.fromBytes(Uint8Array.from(Buffer.from(this.quorumSig, 'hex'))); | ||
thresholdSignature.setAggregationInfo(aggregationInfo); | ||
const result = thresholdSignature.verify(); | ||
quorumPubKey.delete(); | ||
thresholdSignature.delete(); | ||
aggregationInfo.delete(); | ||
resolve(result); | ||
}); | ||
}); | ||
return bls.verifySignature( | ||
this.quorumSig, | ||
Uint8Array.from(this.getCommitmentHash()), | ||
this.quorumPublicKey, | ||
); | ||
}; | ||
@@ -326,0 +315,0 @@ |
@@ -150,16 +150,7 @@ const { isObject } = require('lodash'); | ||
async verifySignatureAgainstQuorum(quorumEntry, requestId) { | ||
const { signature } = this; | ||
const { quorumPublicKey } = quorumEntry; | ||
const signHash = this.getSignHashForQuorumEntry(quorumEntry, requestId); | ||
const blsInstance = await bls.getInstance(); | ||
const quorumPubKey = blsInstance.PublicKey.fromBytes(Buffer.from(quorumPublicKey, 'hex')); | ||
const aggregationInfo = blsInstance.AggregationInfo.fromMsgHash(quorumPubKey, signHash); | ||
const thresholdSignature = blsInstance.Signature.fromBytes(Buffer.from(signature, 'hex')); | ||
thresholdSignature.setAggregationInfo(aggregationInfo); | ||
return thresholdSignature.verify(); | ||
return bls.verifySignature( | ||
this.signature, | ||
this.getSignHashForQuorumEntry(quorumEntry, requestId), | ||
quorumEntry.quorumPublicKey, | ||
); | ||
} | ||
@@ -166,0 +157,0 @@ |
{ | ||
"name": "@dashevo/dashcore-lib", | ||
"version": "0.19.15", | ||
"version": "0.19.16", | ||
"description": "A pure and powerful JavaScript Dash library.", | ||
@@ -5,0 +5,0 @@ "author": "Dash Core Group, Inc. <dev@dash.org>", |
Sorry, the diff of this file is too big to display
22350
2739801