|
|
@ -9,12 +9,13 @@ var $ = require('../../util/preconditions'); |
|
|
|
var Script = require('../../script'); |
|
|
|
var Signature = require('../../crypto/signature'); |
|
|
|
var Sighash = require('../sighash'); |
|
|
|
var PublicKey = require('../../publickey'); |
|
|
|
var BufferUtil = require('../../util/buffer'); |
|
|
|
|
|
|
|
/** |
|
|
|
* @constructor |
|
|
|
*/ |
|
|
|
function MultiSigScriptHashInput(input, pubkeys, threshold) { |
|
|
|
function MultiSigScriptHashInput(input, pubkeys, threshold, signatures) { |
|
|
|
Input.apply(this, arguments); |
|
|
|
var self = this; |
|
|
|
this.publicKeys = _.sortBy(pubkeys, function(publicKey) { return publicKey.toString('hex'); }); |
|
|
@ -27,10 +28,50 @@ function MultiSigScriptHashInput(input, pubkeys, threshold) { |
|
|
|
}); |
|
|
|
this.threshold = threshold; |
|
|
|
// Empty array of signatures
|
|
|
|
this.signatures = new Array(this.publicKeys.length); |
|
|
|
this.signatures = signatures ? this._deserializeSignatures(signatures) : new Array(this.publicKeys.length); |
|
|
|
} |
|
|
|
inherits(MultiSigScriptHashInput, Input); |
|
|
|
|
|
|
|
MultiSigScriptHashInput.prototype.toObject = function() { |
|
|
|
var obj = Input.prototype.toObject.apply(this, arguments); |
|
|
|
obj.threshold = this.threshold; |
|
|
|
obj.publicKeys = _.map(this.publicKeys, function(publicKey) { return publicKey.toString(); }); |
|
|
|
obj.signatures = this._serializeSignatures(); |
|
|
|
return obj; |
|
|
|
}; |
|
|
|
|
|
|
|
MultiSigScriptHashInput.prototype._deserializeSignatures = function(signatures) { |
|
|
|
return _.map(signatures, function(signature) { |
|
|
|
if (!signature) { |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
return { |
|
|
|
publicKey: new PublicKey(signature.publicKey), |
|
|
|
prevTxId: signature.txId, |
|
|
|
outputIndex: signature.outputIndex, |
|
|
|
inputIndex: signature.inputIndex, |
|
|
|
signature: Signature.fromString(signature.signature), |
|
|
|
sigtype: signature.sigtype |
|
|
|
}; |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
MultiSigScriptHashInput.prototype._serializeSignatures = function() { |
|
|
|
return _.map(this.signatures, function(signature) { |
|
|
|
if (!signature) { |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
return { |
|
|
|
publicKey: signature.publicKey.toString(), |
|
|
|
prevTxId: signature.txId, |
|
|
|
outputIndex: signature.outputIndex, |
|
|
|
inputIndex: signature.inputIndex, |
|
|
|
signature: signature.signature.toString(), |
|
|
|
sigtype: signature.sigtype |
|
|
|
}; |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
MultiSigScriptHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype) { |
|
|
|
$.checkState(this.output instanceof Output); |
|
|
|
sigtype = sigtype || Signature.SIGHASH_ALL; |
|
|
|