|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
var _ = require('lodash'); |
|
|
|
var inherits = require('inherits'); |
|
|
|
var Transaction = require('../transaction'); |
|
|
|
var Input = require('./input'); |
|
|
|
var Output = require('../output'); |
|
|
|
var $ = require('../../util/preconditions'); |
|
|
@ -152,6 +153,53 @@ MultiSigInput.prototype.isValidSignature = function(transaction, signature) { |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param {Buffer[]} signatures |
|
|
|
* @param {PublicKey[]} publicKeys |
|
|
|
* @param {Transaction} transaction |
|
|
|
* @param {Integer} inputIndex |
|
|
|
* @param {Input} input |
|
|
|
* @returns {TransactionSignature[]} |
|
|
|
*/ |
|
|
|
MultiSigInput.normalizeSignatures = function(transaction, input, inputIndex, signatures, publicKeys) { |
|
|
|
return publicKeys.map(function (pubKey) { |
|
|
|
var signatureMatch = null; |
|
|
|
signatures = signatures.filter(function (signatureBuffer) { |
|
|
|
if (signatureMatch) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
var signature = new TransactionSignature({ |
|
|
|
signature: Signature.fromTxFormat(signatureBuffer), |
|
|
|
publicKey: pubKey, |
|
|
|
prevTxId: input.prevTxId, |
|
|
|
outputIndex: input.outputIndex, |
|
|
|
inputIndex: inputIndex, |
|
|
|
sigtype: Signature.SIGHASH_ALL |
|
|
|
}); |
|
|
|
|
|
|
|
signature.signature.nhashtype = signature.sigtype; |
|
|
|
var isMatch = Sighash.verify( |
|
|
|
transaction, |
|
|
|
signature.signature, |
|
|
|
signature.publicKey, |
|
|
|
signature.inputIndex, |
|
|
|
input.output.script |
|
|
|
); |
|
|
|
|
|
|
|
if (isMatch) { |
|
|
|
signatureMatch = signature; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
}); |
|
|
|
|
|
|
|
return signatureMatch ? signatureMatch : null; |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
MultiSigInput.OPCODES_SIZE = 7; // serialized size (<=3) + 0 .. N .. M OP_CHECKMULTISIG
|
|
|
|
MultiSigInput.SIGNATURE_SIZE = 74; // size (1) + DER (<=72) + sighash (1)
|
|
|
|
MultiSigInput.PUBKEY_SIZE = 34; // size (1) + DER (<=33)
|
|
|
|