Script: removes Script.createP2SHMultiSigScriptSig

It is favoured to compose the scriptSig manually using
Script.createP2SHScriptSig and Script.createMultisigScriptSig.

Added a test to verify that createMultisigScriptSig throws when not
enough signatures a provided and the redeemScript is given.
This commit is contained in:
Daniel Cousens 2014-05-09 16:18:35 +10:00
parent f8e662e495
commit f18c5e4c1e
3 changed files with 23 additions and 16 deletions

View file

@ -317,7 +317,15 @@ Script.createPubKeyHashScriptSig = function(signature, pubKey) {
} }
// OP_0 [signatures ...] // OP_0 [signatures ...]
Script.createMultisigScriptSig = function(signatures) { Script.createMultisigScriptSig = function(signatures, scriptPubKey) {
if (scriptPubKey) {
assert(isMultisig.call(scriptPubKey))
var m = scriptPubKey.chunks[0]
var k = m - (Opcode.map.OP_1 - 1)
assert(k <= signatures.length, 'Not enough signatures provided')
}
var inScript = new Script() var inScript = new Script()
inScript.writeOp(Opcode.map.OP_0) inScript.writeOp(Opcode.map.OP_0)
@ -335,18 +343,6 @@ Script.createP2SHScriptSig = function(scriptSig, scriptPubKey) {
return inScript return inScript
} }
// [signatures ...] {m [pubKeys ...] n OP_CHECKSIG}
Script.createP2SHMultisigScriptSig = function(signatures, scriptPubKey) {
assert(isMultisig.call(scriptPubKey))
var m = scriptPubKey.chunks[0]
var k = m - (Opcode.map.OP_1 - 1)
assert(k <= signatures.length, 'Not enough signatures provided')
var scriptSig = Script.createMultisigScriptSig(signatures)
return Script.createP2SHScriptSig(scriptSig, scriptPubKey)
}
Script.prototype.clone = function() { Script.prototype.clone = function() {
return new Script(this.buffer) return new Script(this.buffer)
} }

View file

@ -121,9 +121,19 @@ describe('Script', function() {
it('should create a valid P2SH multisig scriptSig', function() { it('should create a valid P2SH multisig scriptSig', function() {
var redeemScript = Script.createMultisigScriptPubKey(2, pubKeys) var redeemScript = Script.createMultisigScriptPubKey(2, pubKeys)
var actual = Script.createP2SHMultisigScriptSig(signatures, redeemScript) var redeemScriptSig = Script.createMultisigScriptSig(signatures)
assert.equal(b2h(actual.buffer), expected) var scriptSig = Script.createP2SHScriptSig(redeemScriptSig, redeemScript)
assert.equal(b2h(scriptSig.buffer), expected)
})
it('should throw on not enough signatures', function() {
var redeemScript = Script.createMultisigScriptPubKey(2, pubKeys)
assert.throws(function() {
Script.createMultisigScriptSig(signatures.slice(1), redeemScript)
})
}) })
}) })
}) })

View file

@ -264,7 +264,8 @@ describe('Transaction', function() {
return tx.signScriptSig(0, redeemScript, privKey) return tx.signScriptSig(0, redeemScript, privKey)
}) })
var scriptSig = Script.createP2SHMultisigScriptSig(signatures, redeemScript) var redeemScriptSig = Script.createMultisigScriptSig(signatures)
var scriptSig = Script.createP2SHScriptSig(redeemScriptSig, redeemScript)
tx.setScriptSig(0, scriptSig) tx.setScriptSig(0, scriptSig)
signatures.forEach(function(sig, i){ signatures.forEach(function(sig, i){