bitcore-lib-cash
Advanced tools
Comparing version 8.16.0 to 8.16.1
@@ -75,3 +75,3 @@ 'use strict'; | ||
let k = nonceFunctionRFC6979(d.toBuffer(), e.toBuffer({ size: 32 })); | ||
let k = nonceFunctionRFC6979(d.toBuffer({ size: 32 }), e.toBuffer({ size: 32 })); | ||
@@ -110,5 +110,4 @@ let P = G.mul(d); | ||
if(!(this.pubkey.toBuffer().length === 32 || this.pubkey.toBuffer().length === 33)) { | ||
return 'pubkey must be 32 byte buffer'; | ||
} | ||
let hashbuf = this.endian === 'little' ? BufferUtil.reverse(this.hashbuf) : this.hashbuf | ||
@@ -134,3 +133,3 @@ let P = this.pubkey.point; | ||
let hash = Hash.sha256(Buffer.concat([Br, Bp, this.hashbuf])); | ||
let hash = Hash.sha256(Buffer.concat([Br, Bp, hashbuf])); | ||
let e = BN.fromBuffer(hash, 'big').umod(n); | ||
@@ -149,2 +148,3 @@ | ||
Schnorr.prototype.verify = function() { | ||
if (!this.sigError()) { | ||
@@ -168,6 +168,7 @@ this.verified = true; | ||
let blob = Buffer.concat([privkey, msgbuf, Buffer.from("Schnorr+SHA256 ", "utf-8")]); | ||
let blob = Buffer.concat([privkey, msgbuf, Buffer.from("", "ascii"), Buffer.from("Schnorr+SHA256 ", "ascii")]); | ||
K = Hash.sha256hmac(Buffer.concat([V, Buffer.from('00', 'hex'), blob]), K); | ||
V = Hash.sha256hmac(V,K); | ||
K = Hash.sha256hmac(Buffer.concat([V,Buffer.from('01','hex'), blob]), K); | ||
@@ -181,4 +182,5 @@ V = Hash.sha256hmac(V,K); | ||
T = BN.fromBuffer(V); | ||
$.checkState(T.toBuffer().length >= 32, "T failed test"); | ||
k = T; | ||
if (k.gt(new BN(0) && k.lt(Point.getN()))) { | ||
@@ -188,3 +190,3 @@ break; | ||
K = Hash.sha256hmac(Buffer.concat([V, Buffer.from("00", 'hex')]), K); | ||
V = Hash.hmac(Hash.sha256sha256, V, K); | ||
V = Hash.hmac(Hash.sha256, V, K); | ||
} | ||
@@ -206,3 +208,3 @@ return k; | ||
endian: endian, | ||
sig: sig, | ||
sig: {...sig, isSchnorr: true }, | ||
pubkey: pubkey | ||
@@ -212,4 +214,2 @@ }).verify().verified; | ||
module.exports = Schnorr; | ||
module.exports = Schnorr; |
@@ -66,4 +66,4 @@ 'use strict'; | ||
Signature.fromDER = Signature.fromBuffer = function(buf, strict) { | ||
// Schnorr Signatures use 64/65 byte for in tx r [len] 32 , s [len] 32, nhashtype | ||
if((buf.length === 64 || buf.length === 65)) { | ||
// Schnorr Signatures use 65 byte for in tx r [len] 32 , s [len] 32, nhashtype | ||
if((buf.length === 64) && buf[0] != 0x30) { | ||
let obj = Signature.parseSchnorrEncodedSig(buf); | ||
@@ -75,4 +75,6 @@ let sig = new Signature(); | ||
return sig; | ||
} if (buf.length === 64 && buf[0] === 0x30) { | ||
return "64 DER (ecdsa) signautres not allowed"; | ||
} | ||
var obj = Signature.parseDER(buf, strict); | ||
@@ -117,4 +119,4 @@ var sig = new Signature(); | ||
if (buf.length === 65) { | ||
hashtype = buf.slice(64,66); | ||
this.hashtype = hashtype; | ||
hashtype = buf.slice(64,65); | ||
this.nhashtype = hashtype; | ||
} | ||
@@ -124,3 +126,4 @@ | ||
r: BN.fromBuffer(r), | ||
s: BN.fromBuffer(s) | ||
s: BN.fromBuffer(s), | ||
nhashtype: hashtype | ||
}; | ||
@@ -211,7 +214,14 @@ | ||
Signature.prototype.toBuffer = Signature.prototype.toDER = function() { | ||
Signature.prototype.toBuffer = Signature.prototype.toDER = function(signingMethod) { | ||
// Schnorr signatures use a 64 byte r,s format, where as ECDSA takes the form decribed | ||
// below, above the isDER function signature. | ||
signingMethod = signingMethod || "ecdsa"; | ||
var rnbuf = this.r.toBuffer(); | ||
var snbuf = this.s.toBuffer(); | ||
if(this.isSchnorr) { | ||
if(signingMethod === "schnorr") { | ||
return Buffer.concat([rnbuf, snbuf]); | ||
@@ -419,4 +429,4 @@ } | ||
Signature.prototype.toTxFormat = function() { | ||
var derbuf = this.toDER(); | ||
Signature.prototype.toTxFormat = function(signingMethod) { | ||
var derbuf = this.toDER(signingMethod); | ||
var buf = Buffer.alloc(1); | ||
@@ -423,0 +433,0 @@ buf.writeUInt8(this.nhashtype, 0); |
@@ -758,3 +758,38 @@ var Address = require('../address'); | ||
var s = new Script(); | ||
s.add(Opcode.OP_0); | ||
if (opts.signingMethod === "schnorr" && opts.checkBits) { | ||
// Spec according to https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/2019-11-15-schnorrmultisig.md#scriptsig-size | ||
let checkBitsString = Buffer.from(opts.checkBits).reverse().join(''); | ||
let checkBitsDecimal = parseInt(checkBitsString, 2); | ||
let checkBitsHex = parseInt(checkBitsDecimal.toString(16), 16); | ||
let N = pubkeys.length; | ||
// N should only be 1-20 | ||
if (N >= 1 && N <= 4) { | ||
s.add(Opcode(checkBitsHex)); | ||
} | ||
else if (N >= 5 && N <= 8) { | ||
if(checkBitsHex === 0x81) { | ||
s.add(Opcode("OP_1NEGATE")) // OP_1NEGATE | ||
} else if(checkBitsHex > 0x10) { | ||
s.add(0x01); | ||
s.add(checkBitsHex); | ||
} else { | ||
s.add(Opcode(checkBitsHex)); | ||
} | ||
} | ||
else if (N >= 9 && N <= 16) { | ||
s.add(0x02); | ||
s.add(checkBitsHex); | ||
} | ||
else if (N >= 17 && N <= 20) { | ||
s.add(0x03); | ||
s.add(checkBitsHex); | ||
} | ||
} else { | ||
s.add(Opcode.OP_0); // ecdsa schnorr mode; multisig dummy param of 0 | ||
} | ||
_.each(signatures, function(signature) { | ||
@@ -777,2 +812,4 @@ $.checkArgument(BufferUtil.isBuffer(signature), 'Signatures must be an array of Buffers'); | ||
* @param {Script=} opts.cachedMultisig don't recalculate the redeemScript | ||
* @param {Uint8Array} opts.checkBits bitfield map 1 or 0 to check which signatures to map against public keys for verification in schnorr multisig mode | ||
* @param {String} opts.signingMethod method with which input will be signed "ecdsa" or "schnorr" | ||
* | ||
@@ -787,3 +824,37 @@ * @returns {Script} | ||
var s = new Script(); | ||
s.add(Opcode.OP_0); | ||
if (opts.signingMethod === "schnorr" && opts.checkBits) { | ||
// Spec according to https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/2019-11-15-schnorrmultisig.md#scriptsig-size | ||
let checkBitsString = Buffer.from(opts.checkBits).reverse().join(''); | ||
let checkBitsDecimal = parseInt(checkBitsString, 2); | ||
let checkBitsHex = parseInt(checkBitsDecimal.toString(16), 16); | ||
let N = pubkeys.length; | ||
// N should only be 1-20 | ||
if (N >= 1 && N <= 4) { | ||
s.add(Opcode(checkBitsDecimal)); | ||
} | ||
else if (N >= 5 && N <= 8) { | ||
if(checkBitsHex === 0x81) { | ||
s.add(Opcode("OP_1NEGATE")) // OP_1NEGATE | ||
} else if(checkBitsHex > 0x10) { | ||
s.add(0x01); | ||
s.add(checkBitsHex); | ||
} else { | ||
s.add(Opcode(checkBitsDecimal)); | ||
} | ||
} | ||
else if (N >= 9 && N <= 16) { | ||
s.add(0x02); | ||
s.add(checkBitsHex); | ||
} | ||
else if (N >= 17 && N <= 20) { | ||
s.add(0x03); | ||
s.add(checkBitsHex); | ||
} | ||
} else { | ||
s.add(Opcode.OP_0); // ecdsa schnorr mode; multisig dummy param of 0 | ||
} | ||
_.each(signatures, function(signature) { | ||
@@ -1038,3 +1109,3 @@ $.checkArgument(BufferUtil.isBuffer(signature), 'Signatures must be an array of Buffers'); | ||
Script.prototype.checkMinimalPush = function(i) { | ||
var chunk = this.chunks[i]; | ||
var chunk = this. chunks[i]; | ||
var buf = chunk.buf; | ||
@@ -1050,6 +1121,7 @@ var opcodenum = chunk.opcodenum; | ||
// Could have used OP_1 .. OP_16. | ||
return opcodenum === Opcode.OP_1 + (buf[0] - 1); | ||
// return opcodenum === Opcode.OP_1 + (buf[0] - 1); | ||
return false; | ||
} else if (buf.length === 1 && buf[0] === 0x81) { | ||
// Could have used OP_1NEGATE | ||
return opcodenum === Opcode.OP_1NEGATE; | ||
return false; | ||
} else if (buf.length <= 75) { | ||
@@ -1056,0 +1128,0 @@ // Could have used a direct push (opcode indicating number of bytes pushed + those bytes). |
@@ -151,2 +151,3 @@ 'use strict'; | ||
* public key associated with the private key provided | ||
* @param {String} signingMethod "schnorr" or "ecdsa", default to "ecdsa" if not provided | ||
* @abstract | ||
@@ -177,3 +178,3 @@ */ | ||
Input.prototype.isValidSignature = function(transaction, signature) { | ||
Input.prototype.isValidSignature = function(transaction, signature, signingMethod) { | ||
// FIXME: Refactor signature so this is not necessary | ||
@@ -187,3 +188,5 @@ signature.signature.nhashtype = signature.sigtype; | ||
this.output.script, | ||
this.output.satoshisBN | ||
this.output.satoshisBN, | ||
undefined, | ||
signingMethod | ||
); | ||
@@ -190,0 +193,0 @@ }; |
@@ -70,3 +70,3 @@ 'use strict'; | ||
MultiSigInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype) { | ||
MultiSigInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData, signingMethod) { | ||
$.checkState(this.output instanceof Output); | ||
@@ -84,3 +84,3 @@ sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID); | ||
inputIndex: index, | ||
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.output.script, self.output.satoshisBN), | ||
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.output.script, self.output.satoshisBN, undefined, signingMethod), | ||
sigtype: sigtype | ||
@@ -94,17 +94,17 @@ })); | ||
MultiSigInput.prototype.addSignature = function(transaction, signature) { | ||
MultiSigInput.prototype.addSignature = function(transaction, signature, signingMethod) { | ||
$.checkState(!this.isFullySigned(), 'All needed signatures have already been added'); | ||
$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()]), | ||
'Signature has no matching public key'); | ||
$.checkState(this.isValidSignature(transaction, signature)); | ||
$.checkState(this.isValidSignature(transaction, signature, signingMethod)); | ||
this.signatures[this.publicKeyIndex[signature.publicKey.toString()]] = signature; | ||
this._updateScript(); | ||
this._updateScript(signingMethod); | ||
return this; | ||
}; | ||
MultiSigInput.prototype._updateScript = function() { | ||
MultiSigInput.prototype._updateScript = function(signingMethod) { | ||
this.setScript(Script.buildMultisigIn( | ||
this.publicKeys, | ||
this.threshold, | ||
this._createSignatures() | ||
this._createSignatures(signingMethod) | ||
)); | ||
@@ -114,3 +114,3 @@ return this; | ||
MultiSigInput.prototype._createSignatures = function() { | ||
MultiSigInput.prototype._createSignatures = function(signingMethod) { | ||
return _.map( | ||
@@ -120,3 +120,3 @@ _.filter(this.signatures, function(signature) { return !_.isUndefined(signature); }), | ||
return BufferUtil.concat([ | ||
signature.signature.toDER(), | ||
signature.signature.toDER(signingMethod), | ||
BufferUtil.integerAsSingleByteBuffer(signature.sigtype) | ||
@@ -154,3 +154,3 @@ ]); | ||
MultiSigInput.prototype.isValidSignature = function(transaction, signature) { | ||
MultiSigInput.prototype.isValidSignature = function(transaction, signature, signingMethod) { | ||
// FIXME: Refactor signature so this is not necessary | ||
@@ -164,3 +164,5 @@ signature.signature.nhashtype = signature.sigtype; | ||
this.output.script, | ||
this.output.satoshisBN | ||
this.output.satoshisBN, | ||
undefined, | ||
signingMethod | ||
); | ||
@@ -178,3 +180,3 @@ }; | ||
*/ | ||
MultiSigInput.normalizeSignatures = function(transaction, input, inputIndex, signatures, publicKeys) { | ||
MultiSigInput.normalizeSignatures = function(transaction, input, inputIndex, signatures, publicKeys, signingMethod) { | ||
return publicKeys.map(function (pubKey) { | ||
@@ -202,3 +204,5 @@ var signatureMatch = null; | ||
signature.inputIndex, | ||
input.output.script | ||
input.output.script, | ||
undefined, | ||
signingMethod | ||
); | ||
@@ -205,0 +209,0 @@ |
@@ -42,2 +42,3 @@ 'use strict'; | ||
this.signatures = signatures ? this._deserializeSignatures(signatures) : new Array(this.publicKeys.length); | ||
this.checkBitsField = new Uint8Array(this.publicKeys.length); | ||
} | ||
@@ -72,3 +73,3 @@ inherits(MultiSigScriptHashInput, Input); | ||
MultiSigScriptHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype) { | ||
MultiSigScriptHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData, signingMethod) { | ||
$.checkState(this.output instanceof Output); | ||
@@ -86,3 +87,3 @@ sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID); | ||
inputIndex: index, | ||
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.redeemScript, self.output.satoshisBN), | ||
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.redeemScript, self.output.satoshisBN, undefined, signingMethod), | ||
sigtype: sigtype | ||
@@ -95,18 +96,19 @@ })); | ||
MultiSigScriptHashInput.prototype.addSignature = function(transaction, signature) { | ||
MultiSigScriptHashInput.prototype.addSignature = function(transaction, signature, signingMethod) { | ||
$.checkState(!this.isFullySigned(), 'All needed signatures have already been added'); | ||
$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()]), | ||
'Signature has no matching public key'); | ||
$.checkState(this.isValidSignature(transaction, signature)); | ||
$.checkState(this.isValidSignature(transaction, signature, signingMethod)); | ||
this.signatures[this.publicKeyIndex[signature.publicKey.toString()]] = signature; | ||
this._updateScript(); | ||
this.checkBitsField[this.publicKeyIndex[signature.publicKey.toString()]] = (signature !== undefined) ? 1 : 0; | ||
this._updateScript(signingMethod, this.checkBitsField); | ||
return this; | ||
}; | ||
MultiSigScriptHashInput.prototype._updateScript = function() { | ||
MultiSigScriptHashInput.prototype._updateScript = function(signingMethod, checkBitsField) { | ||
this.setScript(Script.buildP2SHMultisigIn( | ||
this.publicKeys, | ||
this.threshold, | ||
this._createSignatures(), | ||
{ cachedMultisig: this.redeemScript } | ||
this._createSignatures(signingMethod), | ||
{ cachedMultisig: this.redeemScript, checkBits: checkBitsField, signingMethod } | ||
)); | ||
@@ -116,3 +118,3 @@ return this; | ||
MultiSigScriptHashInput.prototype._createSignatures = function() { | ||
MultiSigScriptHashInput.prototype._createSignatures = function(signingMethod) { | ||
return _.map( | ||
@@ -122,3 +124,3 @@ _.filter(this.signatures, function(signature) { return !_.isUndefined(signature); }), | ||
return BufferUtil.concat([ | ||
signature.signature.toDER(), | ||
signature.signature.toDER(signingMethod), | ||
BufferUtil.integerAsSingleByteBuffer(signature.sigtype) | ||
@@ -156,4 +158,5 @@ ]); | ||
MultiSigScriptHashInput.prototype.isValidSignature = function(transaction, signature) { | ||
MultiSigScriptHashInput.prototype.isValidSignature = function(transaction, signature, signingMethod) { | ||
// FIXME: Refactor signature so this is not necessary | ||
signingMethod = signingMethod || "ecdsa"; | ||
signature.signature.nhashtype = signature.sigtype; | ||
@@ -166,3 +169,5 @@ return Sighash.verify( | ||
this.redeemScript, | ||
this.output.satoshisBN | ||
this.output.satoshisBN, | ||
undefined, | ||
signingMethod | ||
); | ||
@@ -169,0 +174,0 @@ }; |
@@ -29,5 +29,6 @@ 'use strict'; | ||
* @param {number=} sigtype - the type of signature, defaults to Signature.SIGHASH_ALL | ||
* @param {String} signingMethod - the signing method used to sign tx "ecdsa" or "schnorr" | ||
* @return {Array} of objects that can be | ||
*/ | ||
PublicKeyInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype) { | ||
PublicKeyInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData, signingMethod) { | ||
$.checkState(this.output instanceof Output); | ||
@@ -42,3 +43,3 @@ sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID); | ||
inputIndex: index, | ||
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, this.output.satoshisBN), | ||
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, this.output.satoshisBN, undefined, signingMethod), | ||
sigtype: sigtype | ||
@@ -57,8 +58,9 @@ })]; | ||
* @param {number=} signature.sigtype | ||
* @param {String} signingMethod - the method used in signing the tx "ecdsa" or "schnorr" | ||
* @return {PublicKeyInput} this, for chaining | ||
*/ | ||
PublicKeyInput.prototype.addSignature = function(transaction, signature) { | ||
$.checkState(this.isValidSignature(transaction, signature), 'Signature is invalid'); | ||
PublicKeyInput.prototype.addSignature = function(transaction, signature, signingMethod) { | ||
$.checkState(this.isValidSignature(transaction, signature, signingMethod), 'Signature is invalid'); | ||
this.setScript(Script.buildPublicKeyIn( | ||
signature.signature.toDER(), | ||
signature.signature.toDER(signingMethod), | ||
signature.sigtype | ||
@@ -65,0 +67,0 @@ )); |
@@ -32,5 +32,6 @@ 'use strict'; | ||
* @param {Buffer=} hashData - the precalculated hash of the public key associated with the privateKey provided | ||
* @param {String} signingMethod - the signing method used to sign tx "ecdsa" or "schnorr" | ||
* @return {Array} of objects that can be | ||
*/ | ||
PublicKeyHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData) { | ||
PublicKeyHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData, signingMethod) { | ||
$.checkState(this.output instanceof Output); | ||
@@ -46,3 +47,3 @@ hashData = hashData || Hash.sha256ripemd160(privateKey.publicKey.toBuffer()); | ||
inputIndex: index, | ||
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, this.output.satoshisBN), | ||
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, this.output.satoshisBN, undefined, signingMethod), | ||
sigtype: sigtype | ||
@@ -62,10 +63,12 @@ })]; | ||
* @param {number=} signature.sigtype | ||
* @param {String} signingMethod "ecdsa" or "schnorr" | ||
* @return {PublicKeyHashInput} this, for chaining | ||
*/ | ||
PublicKeyHashInput.prototype.addSignature = function(transaction, signature) { | ||
$.checkState(this.isValidSignature(transaction, signature), 'Signature is invalid'); | ||
PublicKeyHashInput.prototype.addSignature = function(transaction, signature, signingMethod) { | ||
$.checkState(this.isValidSignature(transaction, signature, signingMethod), 'Signature is invalid'); | ||
this.setScript(Script.buildPublicKeyHashIn( | ||
signature.publicKey, | ||
signature.signature.toDER(), | ||
signature.signature.toDER(signingMethod), | ||
signature.sigtype | ||
@@ -72,0 +75,0 @@ )); |
@@ -260,15 +260,15 @@ 'use strict'; | ||
signingMethod = signingMethod || "ecdsa"; | ||
let sig; | ||
if (signingMethod === "schnorr") { | ||
let sig = Schnorr.sign(hashbuf, privateKey, 'big').set({ | ||
sig = Schnorr.sign(hashbuf, privateKey, 'little').set({ | ||
nhashtype: sighashType | ||
}); | ||
return sig; | ||
} else if (signingMethod === "ecdsa") { | ||
sig = ECDSA.sign(hashbuf, privateKey, 'little').set({ | ||
nhashtype: sighashType | ||
}); | ||
return sig; | ||
} | ||
var sig = ECDSA.sign(hashbuf, privateKey, 'little').set({ | ||
nhashtype: sighashType | ||
}); | ||
return sig; | ||
} | ||
@@ -294,10 +294,10 @@ | ||
var hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript, satoshisBN, flags); | ||
signingMethod = signingMethod || "ecdsa"; | ||
if (signingMethod === "schnorr") { | ||
return Schnorr.verify(hashbuf, signature, publicKey, 'big'); | ||
return Schnorr.verify(hashbuf, signature, publicKey, 'little') | ||
} else if(signingMethod === "ecdsa") { | ||
return ECDSA.verify(hashbuf, signature, publicKey, 'little'); | ||
} | ||
return ECDSA.verify(hashbuf, signature, publicKey, 'little'); | ||
} | ||
@@ -304,0 +304,0 @@ |
@@ -543,3 +543,3 @@ 'use strict'; | ||
_.each(utxo, function(utxo) { | ||
self.from(utxo, pubkeys, threshold); | ||
self.from(utxo, pubkeys, threshold, opts); | ||
}); | ||
@@ -604,3 +604,3 @@ return this; | ||
script: Script.empty() | ||
}, pubkeys, threshold, opts)); | ||
}, pubkeys, threshold, undefined, opts)); | ||
}; | ||
@@ -1078,3 +1078,5 @@ | ||
*/ | ||
Transaction.prototype.sign = function(privateKey, sigtype) { | ||
Transaction.prototype.sign = function(privateKey, sigtype, signingMethod) { | ||
signingMethod = signingMethod || "ecdsa" | ||
$.checkState(this.hasAllUtxoInfo(), 'Not all utxo information is available to sign the transaction.'); | ||
@@ -1084,8 +1086,8 @@ var self = this; | ||
_.each(privateKey, function(privateKey) { | ||
self.sign(privateKey, sigtype); | ||
self.sign(privateKey, sigtype, signingMethod); | ||
}); | ||
return this; | ||
} | ||
_.each(this.getSignatures(privateKey, sigtype), function(signature) { | ||
self.applySignature(signature); | ||
_.each(this.getSignatures(privateKey, sigtype, signingMethod), function(signature) { | ||
self.applySignature(signature, signingMethod); | ||
}); | ||
@@ -1095,6 +1097,5 @@ return this; | ||
Transaction.prototype.getSignatures = function(privKey, sigtype) { | ||
Transaction.prototype.getSignatures = function(privKey, sigtype, signingMethod) { | ||
privKey = new PrivateKey(privKey); | ||
// By default, signs using ALL|FORKID | ||
@@ -1104,5 +1105,6 @@ sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID); | ||
var results = []; | ||
var hashData = Hash.sha256ripemd160(privKey.publicKey.toBuffer()); | ||
_.each(this.inputs, function forEachInput(input, index) { | ||
_.each(input.getSignatures(transaction, privKey, index, sigtype, hashData), function(signature) { | ||
_.each(input.getSignatures(transaction, privKey, index, sigtype, hashData, signingMethod), function(signature) { | ||
results.push(signature); | ||
@@ -1122,6 +1124,7 @@ }); | ||
* @param {Signature} signature.signature | ||
* @param {String} signingMethod "ecdsa" or "schnorr" | ||
* @return {Transaction} this, for chaining | ||
*/ | ||
Transaction.prototype.applySignature = function(signature) { | ||
this.inputs[signature.inputIndex].addSignature(this, signature); | ||
Transaction.prototype.applySignature = function(signature, signingMethod) { | ||
this.inputs[signature.inputIndex].addSignature(this, signature, signingMethod); | ||
return this; | ||
@@ -1158,4 +1161,4 @@ }; | ||
*/ | ||
Transaction.prototype.verifySignature = function(sig, pubkey, nin, subscript, satoshisBN, flags) { | ||
return Sighash.verify(this, sig, pubkey, nin, subscript, satoshisBN, flags); | ||
Transaction.prototype.verifySignature = function(sig, pubkey, nin, subscript, satoshisBN, flags, signingMethod) { | ||
return Sighash.verify(this, sig, pubkey, nin, subscript, satoshisBN, flags, signingMethod); | ||
}; | ||
@@ -1162,0 +1165,0 @@ |
{ | ||
"name": "bitcore-lib-cash", | ||
"version": "8.16.0", | ||
"version": "8.16.1", | ||
"description": "A pure and powerful JavaScript Bitcoin Cash library.", | ||
@@ -8,3 +8,2 @@ "author": "BitPay <dev@bitpay.com>", | ||
"scripts": { | ||
"lint": "gulp lint", | ||
"test": "gulp test", | ||
@@ -40,3 +39,3 @@ "test:ci": "npm run test", | ||
"dependencies": { | ||
"bitcore-lib": "^8.16.0", | ||
"bitcore-lib": "^8.16.1", | ||
"bn.js": "=4.11.8", | ||
@@ -51,3 +50,3 @@ "bs58": "^4.0.1", | ||
"base-x": "=3.0.4", | ||
"bitcore-build": "^8.16.0", | ||
"bitcore-build": "^8.16.1", | ||
"brfs": "^2.0.1", | ||
@@ -54,0 +53,0 @@ "chai": "^4.2.0", |
@@ -28,3 +28,3 @@ 'use strict'; | ||
it("Sign/Verify bitcoin-abc-test-spec", function() { | ||
schnorr.hashbuf = Hash.sha256sha256(Buffer.from('Very deterministic message', 'utf-8')); | ||
schnorr.hashbuf = Hash.sha256((Buffer.from('Very deterministic message', 'utf-8'))); | ||
schnorr.endianess = 'big'; | ||
@@ -43,3 +43,3 @@ schnorr.privkey = new Privkey(BN.fromBuffer('12b004fff7f4b69ef8650e767f18f11ede158148b425660723b9f9a66e61f747','hex'), 'livenet'); | ||
let privbn = new BN(1); | ||
// privbn.toBuffer({ size: 32}); | ||
let privkey = new Privkey(privbn); | ||
@@ -67,3 +67,3 @@ | ||
}); | ||
it("Sign/Verify Test 4", function() { | ||
@@ -96,2 +96,12 @@ var schnorr = new Schnorr(); | ||
it("Verify Test should pass from scripts_test", function() { | ||
// schnorr.hashbuf = Buffer.from('f4a222b692e7f86c299f878c4b981242238f49b467b8d990219fbf5cfc0838cd', 'hex'); | ||
schnorr.hashbuf = Buffer.from('cd3808fc5cbf9f2190d9b867b4498f234212984b8c879f296cf8e792b622a2f4', 'hex'); | ||
schnorr.endianess = 'big'; | ||
schnorr.pubkey = new Pubkey("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", { compressed: false} ); | ||
schnorr.sig = Signature.fromString("0df4be7f5fe74b2855b92082720e889038e15d8d747334fa3f300ef4ab1db1eea56aa83d1d60809ff6703791736be87cfb6cbc5c4036aeed3b4ea4e6dab35090"); | ||
console.log("Schnorr verify", schnorr.verify().verified); | ||
schnorr.verify().verified.should.equal(true); | ||
}); | ||
it("Verify Test 7, public key not on the curve", function() { | ||
@@ -102,2 +112,3 @@ (function() { | ||
}); | ||
@@ -104,0 +115,0 @@ it("Verify Test 8, has_square_y(R) is false", function() { |
@@ -199,2 +199,6 @@ 'use strict'; | ||
if(flagstr.indexOf('DISALLOW_SEGWIT_RECOVERY') !== -1) { | ||
flags = flags | Interpreter.SCRIPT_DISALLOW_SEGWIT_RECOVERY; | ||
} | ||
if (flagstr.indexOf('FORKID') !== -1) { | ||
@@ -212,2 +216,6 @@ flags = flags | Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID; | ||
if (flagstr.indexOf('SCHNORR_MULTISIG') !== -1) { | ||
flags = flags | Interpreter.SCRIPT_ENABLE_SCHNORR_MULTISIG; | ||
} | ||
if (flagstr.indexOf('MINIMALIF') !== -1) { | ||
@@ -226,2 +234,3 @@ flags = flags | Interpreter.SCRIPT_VERIFY_MINIMALIF; | ||
var testFixture = function(vector, expected, extraData) { | ||
var scriptSig = Script.fromBitcoindString(vector[0]); | ||
@@ -228,0 +237,0 @@ var scriptPubkey = Script.fromBitcoindString(vector[1]); |
@@ -13,2 +13,3 @@ 'use strict'; | ||
var Transaction = bitcore.Transaction; | ||
var Signature = bitcore.Signature; | ||
var Input = bitcore.Transaction.Input; | ||
@@ -1215,3 +1216,2 @@ var Output = bitcore.Transaction.Output; | ||
}); | ||
}); | ||
@@ -1218,0 +1218,0 @@ }); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2535388
32703
Updatedbitcore-lib@^8.16.1