Skip to content

Commit

Permalink
Merge branch 'fix-schnorr-sig' of github.com:msinkec/bitcore
Browse files Browse the repository at this point in the history
  • Loading branch information
kajoseph committed Oct 3, 2024
2 parents 439fb47 + 70960d5 commit 7df79da
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/bitcore-lib/lib/crypto/schnorr.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Schnorr.sign = function(privateKey, message, aux) {
const Rbuf = Buffer.from(R.encodeCompressed().slice(1)); // slice(1) removes the encoding prefix byte
const k = R.y.isEven() ? kPrime : n.sub(kPrime);
const e = new BN(new TaggedHash('BIP0340/challenge', Buffer.concat([Rbuf, Pbuf, message])).finalize()).mod(n);
const sig = Buffer.concat([Rbuf, k.add(e.mul(d)).mod(n).toBuffer()]);
const sig = Buffer.concat([Rbuf, k.add(e.mul(d)).mod(n).toBuffer({ size: 32 })]);

if (!Schnorr.verify(Pbuf, message, sig)) {
throw new Error('Error creating schnorr signature. Verification failed');
Expand All @@ -74,7 +74,7 @@ Schnorr.sign = function(privateKey, message, aux) {

/**
* Verify a schnorr signature
* @param {PublicKey|Buffer} publicKey
* @param {PublicKey|Buffer} publicKey
* @param {String|Buffer} message Hex string or buffer
* @param {String|Signature|Buffer} signature Hex string, Signature instance, or buffer
* @returns {Boolean}
Expand Down Expand Up @@ -139,4 +139,4 @@ const getE = function(r, P, message) {
return new BN(hash).mod(n);
};

module.exports = Schnorr;
module.exports = Schnorr;

0 comments on commit 7df79da

Please sign in to comment.