bitcore-lib-cash
Advanced tools
Comparing version 10.0.2 to 10.0.3
@@ -33,3 +33,3 @@ 'use strict'; | ||
obj.compressed : this.compressed; // whether the recovered pubkey is compressed | ||
this.isSchnorr = obj.isSchnorr; | ||
this.isSchnorr = obj.isSchnorr || this.isSchnorr; | ||
this.nhashtype = obj.nhashtype || this.nhashtype || undefined; | ||
@@ -67,4 +67,5 @@ return this; | ||
Signature.fromDER = Signature.fromBuffer = function(buf, strict) { | ||
// Schnorr Signatures use 65 byte for in tx r [len] 32 , s [len] 32, nhashtype | ||
if((buf.length === 64 || buf.length === 65) && buf[0] != 0x30) { | ||
// Schnorr signatures are 64 bytes: r [len] 32 || s [len] 32 | ||
// There can be a 65th byte that is the nhashtype. It needs to be trimmed before calling this. | ||
if (buf.length === 64) { | ||
let obj = Signature.parseSchnorrEncodedSig(buf); | ||
@@ -76,4 +77,2 @@ let sig = new Signature(); | ||
return sig; | ||
} if (buf.length === 64 && buf[0] === 0x30) { | ||
return "64 DER (ecdsa) signatures not allowed"; | ||
} | ||
@@ -108,2 +107,4 @@ | ||
// This assumes the str is a raw signature DER and does not have nhashtype | ||
// Use Signature.fromTxString when decoding a tx | ||
Signature.fromString = function(str) { | ||
@@ -115,3 +116,8 @@ var buf = Buffer.from(str, 'hex'); | ||
// Use this when decoding a tx signature string | ||
Signature.fromTxString = function(str, encoding = 'hex') { | ||
return Signature.fromTxFormat(Buffer.from(str, encoding)) | ||
} | ||
Signature.parseSchnorrEncodedSig = function(buf) { | ||
@@ -215,3 +221,3 @@ let r = buf.slice(0,32); | ||
Signature.prototype.toBuffer = Signature.prototype.toDER = function(signingMethod) { | ||
Signature.prototype.toBuffer = Signature.prototype.toDER = function() { | ||
@@ -221,5 +227,3 @@ // Schnorr signatures use a 64 byte r,s format, where as ECDSA takes the form decribed | ||
signingMethod = signingMethod || "ecdsa"; | ||
if(signingMethod === "schnorr") { | ||
if(this.isSchnorr) { | ||
return Buffer.concat([this.r.toBuffer({size: 32}), this.s.toBuffer({size: 32})]); | ||
@@ -226,0 +230,0 @@ } |
@@ -33,3 +33,3 @@ 'use strict'; | ||
$.checkState(this.output instanceof Output); | ||
sigtype = sigtype || Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID; | ||
sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID); | ||
const signature = new TransactionSignature({ | ||
@@ -36,0 +36,0 @@ publicKey: privateKey.publicKey, |
@@ -78,3 +78,3 @@ 'use strict'; | ||
var results = []; | ||
_.each(this.publicKeys, function(publicKey) { | ||
for (const publicKey of this.publicKeys) { | ||
if (publicKey.toString() === privateKey.publicKey.toString()) { | ||
@@ -90,3 +90,3 @@ results.push(new TransactionSignature({ | ||
} | ||
}); | ||
} | ||
return results; | ||
@@ -155,4 +155,3 @@ }; | ||
MultiSigScriptHashInput.prototype.isValidSignature = function(transaction, signature, signingMethod) { | ||
// FIXME: Refactor signature so this is not necessary | ||
signingMethod = signingMethod || "ecdsa"; | ||
signingMethod = signingMethod || (signature.signature.isSchnorr ? 'schnorr' : 'ecdsa'); | ||
signature.signature.nhashtype = signature.sigtype; | ||
@@ -159,0 +158,0 @@ return Sighash.verify( |
@@ -286,3 +286,3 @@ 'use strict'; | ||
* @param {flags} verification flags | ||
* @param {signingMethod} signingMethod "ecdsa" or "schnorr" to sign a tx | ||
* @param {signingMethod} signingMethod 'ecdsa' or 'schnorr' to sign a tx | ||
* @return {boolean} | ||
@@ -295,7 +295,7 @@ */ | ||
signingMethod = signingMethod || "ecdsa"; | ||
signingMethod = signingMethod || 'ecdsa'; | ||
if (signingMethod === "schnorr") { | ||
if (signingMethod === 'schnorr') { | ||
return Schnorr.verify(hashbuf, signature, publicKey, 'little') | ||
} else if(signingMethod === "ecdsa") { | ||
} else if(signingMethod === 'ecdsa') { | ||
return ECDSA.verify(hashbuf, signature, publicKey, 'little'); | ||
@@ -302,0 +302,0 @@ } |
@@ -1210,7 +1210,9 @@ 'use strict'; | ||
var hashData = Hash.sha256ripemd160(privKey.publicKey.toBuffer()); | ||
_.each(this.inputs, function forEachInput(input, index) { | ||
_.each(input.getSignatures(transaction, privKey, index, sigtype, hashData, signingMethod), function(signature) { | ||
for (let index = 0; index < this.inputs.length; index++) { | ||
var input = this.inputs[index]; | ||
var signatures = input.getSignatures(transaction, privKey, index, sigtype, hashData, signingMethod); | ||
for (let signature of signatures) { | ||
results.push(signature); | ||
}); | ||
}); | ||
} | ||
} | ||
return results; | ||
@@ -1419,3 +1421,3 @@ }; | ||
const reclaimSignature = Signature.fromString(reclaimSignatureString); | ||
const reclaimSignature = Signature.fromTxString(reclaimSignatureString); | ||
reclaimSignature.nhashtype = sighashAll; | ||
@@ -1422,0 +1424,0 @@ |
{ | ||
"name": "bitcore-lib-cash", | ||
"version": "10.0.2", | ||
"version": "10.0.3", | ||
"description": "A pure and powerful JavaScript Bitcoin Cash library.", | ||
@@ -38,3 +38,3 @@ "author": "BitPay <dev@bitpay.com>", | ||
"dependencies": { | ||
"bitcore-lib": "^10.0.2", | ||
"bitcore-lib": "^10.0.3", | ||
"bn.js": "=4.11.8", | ||
@@ -49,3 +49,3 @@ "bs58": "^4.0.1", | ||
"base-x": "=3.0.4", | ||
"bitcore-build": "^10.0.2", | ||
"bitcore-build": "^10.0.3", | ||
"brfs": "^2.0.1", | ||
@@ -57,3 +57,3 @@ "chai": "^4.2.0", | ||
"license": "MIT", | ||
"gitHead": "80d89c0038a64a104d2a188615114d4768c33682" | ||
"gitHead": "98611e6bb8be12be6667babfe857f73b8b0095c6" | ||
} |
@@ -293,28 +293,26 @@ 'use strict'; | ||
describe('bitcoind script evaluation fixtures', function() { | ||
var testAllFixtures = function(set) { | ||
var c = 0; var l = set.length; | ||
set.forEach(function(vector) { | ||
if (vector.length === 1) { | ||
return; | ||
} | ||
c++; | ||
let c = 0; | ||
const l = script_tests.length; | ||
for (const vector of script_tests) { | ||
if (vector.length === 1) { | ||
continue; | ||
} | ||
c++; | ||
var extraData; | ||
if (_.isArray (vector[0])) { | ||
extraData = vector.shift(); | ||
} | ||
let extraData; | ||
if (Array.isArray(vector[0])) { | ||
extraData = vector.shift(); | ||
} | ||
var fullScriptString = vector[0] + ' ' + vector[1]; | ||
var expected = vector[3] == 'OK'; | ||
var descstr = vector[4]; | ||
var comment = descstr ? (' (' + descstr + ')') : ''; | ||
var txt = 'should ' +( vector[3] == 'OK' ? 'PASS' : 'FAIL') + ' script_tests ' + | ||
'vector #' + c + '/ ' + l + ': ' + fullScriptString + comment; | ||
const fullScriptString = vector[0] + ' ' + vector[1]; | ||
const expected = vector[3] == 'OK'; | ||
const descstr = vector[4]; | ||
const comment = descstr ? (' (' + descstr + ')') : ''; | ||
const result = vector[3] == 'OK' ? 'PASS' : 'FAIL'; | ||
const txt = `should ${result} script_tests vector #${c}/${l}: ${fullScriptString + comment}`; | ||
it(txt, function() { testFixture(vector, expected, extraData); }); | ||
it(txt, function() { | ||
testFixture(vector, expected, extraData); | ||
}); | ||
}; | ||
testAllFixtures(script_tests); | ||
} | ||
}); | ||
@@ -321,0 +319,0 @@ describe('libauth vmb evaluation fixtures', () => { |
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
3104786
36366
Updatedbitcore-lib@^10.0.3