Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitcore-lib

Package Overview
Dependencies
Maintainers
3
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcore-lib - npm Package Compare versions

Comparing version 8.17.1 to 8.20.0

6

lib/transaction/input/input.js

@@ -202,4 +202,5 @@ 'use strict';

Input.prototype.isValidSignature = function(transaction, signature) {
Input.prototype.isValidSignature = function(transaction, signature, signingMethod) {
// FIXME: Refactor signature so this is not necessary
signingMethod = signingMethod || 'ecdsa';
signature.signature.nhashtype = signature.sigtype;

@@ -211,3 +212,4 @@ return Sighash.verify(

signature.inputIndex,
this.output.script
this.output.script,
signingMethod
);

@@ -214,0 +216,0 @@ };

@@ -70,5 +70,6 @@ '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);
sigtype = sigtype || Signature.SIGHASH_ALL;
signingMethod = signingMethod || 'ecdsa';

@@ -84,3 +85,3 @@ var self = this;

inputIndex: index,
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.output.script),
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.output.script, signingMethod),
sigtype: sigtype

@@ -94,7 +95,7 @@ }));

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()]),
$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()], "Signature Undefined"),
'Signature has no matching public key');
$.checkState(this.isValidSignature(transaction, signature));
$.checkState(this.isValidSignature(transaction, signature, signingMethod), "Invalid Signature");
this.signatures[this.publicKeyIndex[signature.publicKey.toString()]] = signature;

@@ -117,2 +118,3 @@ this._updateScript();

_.filter(this.signatures, function(signature) { return !_.isUndefined(signature); }),
// Future signature types may need refactor of toDER
function(signature) {

@@ -153,3 +155,3 @@ return BufferUtil.concat([

MultiSigInput.prototype.isValidSignature = function(transaction, signature) {
MultiSigInput.prototype.isValidSignature = function(transaction, signature, signingMethod) {
// FIXME: Refactor signature so this is not necessary

@@ -162,3 +164,4 @@ signature.signature.nhashtype = signature.sigtype;

signature.inputIndex,
this.output.script
this.output.script,
signingMethod
);

@@ -174,5 +177,6 @@ };

* @param {Input} input
* @param {String} signingMethod - method used to sign - 'ecdsa' or 'schnorr' (future signing method)
* @returns {TransactionSignature[]}
*/
MultiSigInput.normalizeSignatures = function(transaction, input, inputIndex, signatures, publicKeys) {
MultiSigInput.normalizeSignatures = function(transaction, input, inputIndex, signatures, publicKeys, signingMethod) {
return publicKeys.map(function (pubKey) {

@@ -200,3 +204,4 @@ var signatureMatch = null;

signature.inputIndex,
input.output.script
input.output.script,
signingMethod
);

@@ -203,0 +208,0 @@

@@ -118,5 +118,6 @@ 'use strict';

MultiSigScriptHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype) {
MultiSigScriptHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData, signingMethod) {
$.checkState(this.output instanceof Output);
sigtype = sigtype || Signature.SIGHASH_ALL;
signingMethod = signingMethod || 'ecdsa';

@@ -131,5 +132,5 @@ var self = this;

var satoshisBuffer = self.getSatoshisBuffer();
signature = SighashWitness.sign(transaction, privateKey, sigtype, index, scriptCode, satoshisBuffer);
signature = SighashWitness.sign(transaction, privateKey, sigtype, index, scriptCode, satoshisBuffer, signingMethod);
} else {
signature = Sighash.sign(transaction, privateKey, sigtype, index, self.redeemScript);
signature = Sighash.sign(transaction, privateKey, sigtype, index, self.redeemScript, signingMethod);
}

@@ -149,7 +150,7 @@ results.push(new TransactionSignature({

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), "Invalid Signature!");
this.signatures[this.publicKeyIndex[signature.publicKey.toString()]] = signature;

@@ -221,3 +222,4 @@ this._updateScript();

MultiSigScriptHashInput.prototype.isValidSignature = function(transaction, signature) {
MultiSigScriptHashInput.prototype.isValidSignature = function(transaction, signature, signingMethod) {
signingMethod = signingMethod || 'ecdsa';
if (this.nestedWitness || this.type === Address.PayToWitnessScriptHash) {

@@ -233,3 +235,4 @@ signature.signature.nhashtype = signature.sigtype;

scriptCode,
satoshisBuffer
satoshisBuffer,
signingMethod
);

@@ -244,3 +247,4 @@ } else {

signature.inputIndex,
this.redeemScript
this.redeemScript,
signingMethod
);

@@ -247,0 +251,0 @@ }

@@ -29,5 +29,6 @@ 'use strict';

* @param {number=} sigtype - the type of signature, defaults to Signature.SIGHASH_ALL
* @param {String} signingMethod - method used to sign input - 'ecdsa' or 'schnorr' (future signing method)
* @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;

inputIndex: index,
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script),
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, signingMethod),
sigtype: sigtype

@@ -57,6 +58,7 @@ })];

* @param {number=} signature.sigtype
* @param {String} signingMethod - method used to sign - 'ecdsa' or 'schnorr' (future signing method)
* @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(

@@ -63,0 +65,0 @@ signature.signature.toDER(),

@@ -69,8 +69,10 @@ 'use strict';

* @param {Buffer=} hashData - the precalculated hash of the public key associated with the privateKey provided
* @param {String} signingMethod - method used to sign - 'ecdsa' or 'schnorr' (future signing method)
* @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);
hashData = hashData || Hash.sha256ripemd160(privateKey.publicKey.toBuffer());
sigtype = sigtype || Signature.SIGHASH_ALL;
signingMethod = signingMethod || 'ecdsa';

@@ -89,5 +91,5 @@ var script;

var scriptCode = this.getScriptCode(privateKey.publicKey);
signature = SighashWitness.sign(transaction, privateKey, sigtype, index, scriptCode, satoshisBuffer);
signature = SighashWitness.sign(transaction, privateKey, sigtype, index, scriptCode, satoshisBuffer, signingMethod);
} else {
signature = Sighash.sign(transaction, privateKey, sigtype, index, this.output.script);
signature = Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, signingMethod);
}

@@ -115,6 +117,7 @@

* @param {number=} signature.sigtype
* @param {String} signingMethod - method used to sign - 'ecdsa' or 'schnorr' (future signing method)
* @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');

@@ -157,3 +160,3 @@ if (this.output.script.isWitnessPublicKeyHashOut() || this.output.script.isScriptHashOut()) {

PublicKeyHashInput.prototype.isValidSignature = function(transaction, signature) {
PublicKeyHashInput.prototype.isValidSignature = function(transaction, signature, signingMethod) {
// FIXME: Refactor signature so this is not necessary

@@ -170,3 +173,4 @@ signature.signature.nhashtype = signature.sigtype;

scriptCode,
satoshisBuffer
satoshisBuffer,
signingMethod
);

@@ -179,3 +183,4 @@ } else {

signature.inputIndex,
this.output.script
this.output.script,
signingMethod
);

@@ -182,0 +187,0 @@ }

@@ -101,10 +101,17 @@ 'use strict';

* @param {Script} subscript
* @param {String} signingMethod - method used to sign - 'ecdsa' or 'schnorr' (future signing method)
* @return {Signature}
*/
function sign(transaction, privateKey, sighashType, inputIndex, subscript) {
var hashbuf = sighash(transaction, sighashType, inputIndex, subscript);
var sig = ECDSA.sign(hashbuf, privateKey, 'little').set({
function sign(transaction, privateKey, sighashType, inputIndex, subscript, signingMethod) {
signingMethod = signingMethod || 'ecdsa';
var sig;
if(signingMethod === 'ecdsa') {
var hashbuf = sighash(transaction, sighashType, inputIndex, subscript);
sig = ECDSA.sign(hashbuf, privateKey, 'little').set({
nhashtype: sighashType
});
return sig;
}
throw new Error("signingMethod not supported ", signingMethod);
}

@@ -121,9 +128,15 @@

* @param {Script} subscript
* @param {String} signingMethod - method used to sign - 'ecdsa' or 'schnorr'
* @return {boolean}
*/
function verify(transaction, signature, publicKey, inputIndex, subscript) {
$.checkArgument(!_.isUndefined(transaction));
$.checkArgument(!_.isUndefined(signature) && !_.isUndefined(signature.nhashtype));
var hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript);
return ECDSA.verify(hashbuf, signature, publicKey, 'little');
function verify(transaction, signature, publicKey, inputIndex, subscript, signingMethod) {
$.checkArgument(!_.isUndefined(transaction), "Transaction Undefined");
$.checkArgument(!_.isUndefined(signature) && !_.isUndefined(signature.nhashtype), "Signature Undefined");
signingMethod = signingMethod || 'ecdsa';
if (signingMethod === 'ecdsa') {
var hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript);
return ECDSA.verify(hashbuf, signature, publicKey, 'little');
}
throw new Error("signingMethod not supported ", signingMethod);
}

@@ -130,0 +143,0 @@

@@ -114,10 +114,17 @@ 'use strict';

* @param {Script} subscript
* @param {String} signingMethod - method used to sign - 'ecdsa' or 'schnorr'
* @return {Signature}
*/
function sign(transaction, privateKey, sighashType, inputIndex, scriptCode, satoshisBuffer) {
var hashbuf = sighash(transaction, sighashType, inputIndex, scriptCode, satoshisBuffer);
var sig = ECDSA.sign(hashbuf, privateKey).set({
nhashtype: sighashType
});
return sig;
function sign(transaction, privateKey, sighashType, inputIndex, scriptCode, satoshisBuffer, signingMethod) {
signingMethod = signingMethod || 'ecdsa';
var sig;
if (signingMethod === 'ecdsa') {
let hashbuf = sighash(transaction, sighashType, inputIndex, scriptCode, satoshisBuffer);
sig = ECDSA.sign(hashbuf, privateKey).set({
nhashtype: sighashType
});
return sig;
}
throw new Error("signingMethod not supported ", signingMethod);
}

@@ -134,9 +141,15 @@

* @param {Script} subscript
* @param {String} signingMethod - method used to sign - 'ecdsa' or 'schnorr' (future signing method)
* @return {boolean}
*/
function verify(transaction, signature, publicKey, inputIndex, scriptCode, satoshisBuffer) {
function verify(transaction, signature, publicKey, inputIndex, scriptCode, satoshisBuffer, signingMethod) {
$.checkArgument(!_.isUndefined(transaction));
$.checkArgument(!_.isUndefined(signature) && !_.isUndefined(signature.nhashtype));
var hashbuf = sighash(transaction, signature.nhashtype, inputIndex, scriptCode, satoshisBuffer);
return ECDSA.verify(hashbuf, signature, publicKey);
signingMethod = signingMethod || 'ecdsa';
if (signingMethod === 'ecdsa') {
let hashbuf = sighash(transaction, signature.nhashtype, inputIndex, scriptCode, satoshisBuffer);
return ECDSA.verify(hashbuf, signature, publicKey);
}
throw new Error("signingMethod not supported ", signingMethod);
}

@@ -143,0 +156,0 @@

@@ -1147,5 +1147,6 @@ 'use strict';

* @param {number} sigtype
* @param {String} signingMethod - method used to sign - 'ecdsa' or 'schnorr'
* @return {Transaction} this, for chaining
*/
Transaction.prototype.sign = function(privateKey, sigtype) {
Transaction.prototype.sign = function(privateKey, sigtype, signingMethod) {
$.checkState(this.hasAllUtxoInfo(), 'Not all utxo information is available to sign the transaction.');

@@ -1155,8 +1156,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);
});

@@ -1166,3 +1167,3 @@ return this;

Transaction.prototype.getSignatures = function(privKey, sigtype) {
Transaction.prototype.getSignatures = function(privKey, sigtype, signingMethod) {
privKey = new PrivateKey(privKey);

@@ -1174,3 +1175,3 @@ sigtype = sigtype || Signature.SIGHASH_ALL;

_.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);

@@ -1190,6 +1191,7 @@ });

* @param {Signature} signature.signature
* @param {String} signingMethod - 'ecdsa' to sign transaction
* @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;

@@ -1212,3 +1214,3 @@ };

Transaction.prototype.isValidSignature = function(signature) {
Transaction.prototype.isValidSignature = function(signature, signingMethod) {
var self = this;

@@ -1221,9 +1223,10 @@ if (this.inputs[signature.inputIndex].isValidSignature === Input.prototype.isValidSignature) {

}
return this.inputs[signature.inputIndex].isValidSignature(self, signature);
return this.inputs[signature.inputIndex].isValidSignature(self, signature, signingMethod);
};
/**
* @param {String} signingMethod method used to sign - 'ecdsa' or 'schnorr' (future signing method)
* @returns {bool} whether the signature is valid for this transaction input
*/
Transaction.prototype.verifySignature = function(sig, pubkey, nin, subscript, sigversion, satoshis) {
Transaction.prototype.verifySignature = function(sig, pubkey, nin, subscript, sigversion, satoshis, signingMethod) {

@@ -1253,3 +1256,4 @@ if (_.isUndefined(sigversion)) {

scriptCodeWriter.toBuffer(),
satoshisBuffer
satoshisBuffer,
signingMethod
);

@@ -1259,3 +1263,3 @@ return verified;

return Sighash.verify(this, sig, pubkey, nin, subscript);
return Sighash.verify(this, sig, pubkey, nin, subscript, signingMethod);
};

@@ -1262,0 +1266,0 @@

{
"name": "bitcore-lib",
"version": "8.17.1",
"version": "8.20.0",
"description": "A pure and powerful JavaScript Bitcoin library.",

@@ -5,0 +5,0 @@ "author": "BitPay <dev@bitpay.com>",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc