|
|
@ -897,15 +897,10 @@ TransactionBuilder.prototype._mergeInputSigP2sh = function(input, s0, s1) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
console.log('[TransactionBuilder.js.887:diff:]',diff); //TODO
|
|
|
|
// Add signatures
|
|
|
|
for (var j in diff) { |
|
|
|
var newSig = diff[j]; |
|
|
|
var order = this._getNewSignatureOrder(newSig.prio, s0, p2sh.txSigHash, pubkeys); |
|
|
|
|
|
|
|
if (this._getSighashType(newSig.chunk) !== this.signhash) |
|
|
|
throw new Error('signhash type mismatch at merge'); |
|
|
|
|
|
|
|
s0.chunks.splice(order + 1, 0, newSig.chunk); |
|
|
|
} |
|
|
|
s0.updateBuffer(); |
|
|
@ -918,12 +913,27 @@ TransactionBuilder.prototype._getSighashType = function(sig) { |
|
|
|
return sig[sig.length-1]; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
TransactionBuilder.prototype._checkSignHash = function(s1) { |
|
|
|
var l = s1.chunks.length-1; |
|
|
|
|
|
|
|
for(var i=0; i<l; i++) { |
|
|
|
|
|
|
|
if (i==0 && s1.chunks[i] === 0) |
|
|
|
continue; |
|
|
|
|
|
|
|
if (this._getSighashType(s1.chunks[i]) !== this.signhash) |
|
|
|
throw new Error('signhash type mismatch at merge p2sh'); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO this could be on Script class
|
|
|
|
TransactionBuilder.prototype._mergeInputSig = function(index, s0buf, s1buf) { |
|
|
|
if (buffertools.compare(s0buf, s1buf) === 0) |
|
|
|
return s0buf; |
|
|
|
|
|
|
|
console.log('[TransactionBuilder.js.925]'); //TODO
|
|
|
|
var s0 = new Script(s0buf); |
|
|
|
var s1 = new Script(s1buf); |
|
|
|
var l0 = s0.chunks.length; |
|
|
@ -933,25 +943,21 @@ console.log('[TransactionBuilder.js.925]'); //TODO |
|
|
|
if (l0 && l1 && ((l0 < 2 && l1 > 2) || (l1 < 2 && l0 > 2))) |
|
|
|
throw new Error('TX sig types mismatch in merge'); |
|
|
|
|
|
|
|
console.log('[TransactionBuilder.js.935]', l0, l1); //TODO
|
|
|
|
if ((!l0 && !l1) || (l0 && !l1) || (!l0 && l1)) |
|
|
|
return s1buf; |
|
|
|
if ((!l0 && !l1) || (l0 && !l1)) |
|
|
|
return s0buf; |
|
|
|
|
|
|
|
this._checkSignHash(s1); |
|
|
|
|
|
|
|
console.log('[TransactionBuilder.js.940]'); //TODO
|
|
|
|
if ((!l0 && l1)) |
|
|
|
return s1buf; |
|
|
|
|
|
|
|
// Get the pubkeys
|
|
|
|
var input = this.inputMap[index]; |
|
|
|
var type = input.scriptPubKey.classify(); |
|
|
|
|
|
|
|
console.log('[TransactionBuilder.js.941]'); //TODO
|
|
|
|
//p2pubkey or p2pubkeyhash
|
|
|
|
if (type === Script.TX_PUBKEYHASH || type === Script.TX_PUBKEY) { |
|
|
|
var s = new Script(s1buf); |
|
|
|
|
|
|
|
if (this._getSighashType(s.chunks[0]) !== this.signhash) |
|
|
|
throw new Error('signhash type mismatch at merge'); |
|
|
|
|
|
|
|
log.debug('Merging two signed inputs type:' + |
|
|
|
input.scriptPubKey.getRawOutType() + '. Signatures differs. Using the first version.'); |
|
|
|
return s0buf; |
|
|
@ -960,8 +966,6 @@ console.log('[TransactionBuilder.js.941]'); //TODO |
|
|
|
throw new Error('Script type:' + input.scriptPubKey.getRawOutType() + 'not supported at #merge'); |
|
|
|
} |
|
|
|
|
|
|
|
console.log('[TransactionBuilder.js.957]'); //TODO
|
|
|
|
|
|
|
|
return this._mergeInputSigP2sh(input, s0, s1); |
|
|
|
}; |
|
|
|
|
|
|
@ -969,7 +973,6 @@ console.log('[TransactionBuilder.js.957]'); //TODO |
|
|
|
TransactionBuilder.prototype._mergeTx = function(tx) { |
|
|
|
var v0 = this.tx; |
|
|
|
var v1 = tx; |
|
|
|
console.log('[TransactionBuilder.js.966:var:]'); //TODO
|
|
|
|
|
|
|
|
var l = v0.ins.length; |
|
|
|
if (l !== v1.ins.length) |
|
|
@ -977,7 +980,6 @@ console.log('[TransactionBuilder.js.966:var:]'); //TODO |
|
|
|
|
|
|
|
this.inputsSigned = 0; |
|
|
|
for (var i = 0; i < l; i++) { |
|
|
|
console.log('[TransactionBuilder.js.974:for:]',i); //TODO
|
|
|
|
var i0 = v0.ins[i]; |
|
|
|
var i1 = v1.ins[i]; |
|
|
|
|
|
|
@ -987,7 +989,6 @@ console.log('[TransactionBuilder.js.974:for:]',i); //TODO |
|
|
|
if (buffertools.compare(i0.o, i1.o) !== 0) |
|
|
|
throw new Error('TX .o in mismatch in merge. Input:', i); |
|
|
|
|
|
|
|
console.log('[TransactionBuilder.js.984]'); //TODO
|
|
|
|
i0.s = this._mergeInputSig(i, i0.s, i1.s); |
|
|
|
this.vanilla.scriptSig[i]= i0.s.toString('hex'); |
|
|
|
|
|
|
|