From 8ad8f6f169977da457c6459974bcc3c39ca3b750 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Sat, 26 Apr 2014 03:50:41 +1000 Subject: [PATCH] Renames p2shsign to signScriptSig --- src/transaction.js | 13 +++++-------- test/transaction.js | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index 29590eb..d1974b2 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -312,15 +312,15 @@ Transaction.deserialize = function(buffer) { */ Transaction.prototype.sign = function(index, key, type, network) { assert(key instanceof ECKey) - type = type || SIGHASH_ALL network = network || Network.bitcoin var address = key.pub.getAddress(network.pubKeyHash) + + // FIXME: Assumed prior TX was pay-to-pubkey-hash var script = Script.createOutputScript(address, network) - var hash = this.hashTransactionForSignature(script, index, type) - var sig = key.sign(hash).concat([type]) - var scriptSig = Script.createInputScript(sig, key.pub) + var signature = this.signScriptSig(index, script, key, type) + var scriptSig = Script.createInputScript(signature, key.pub) this.setScriptSig(index, scriptSig) } @@ -358,10 +358,7 @@ Transaction.prototype.signWithKeys = function(keys, outputs, type) { } } -/** - * Signs a P2SH output at some index with the given key - */ -Transaction.prototype.p2shsign = function(index, script, key, type) { +Transaction.prototype.signScriptSig = function(index, script, key, type) { type = type || SIGHASH_ALL var hash = this.hashTransactionForSignature(script, index, type) return key.sign(hash).concat([type]) diff --git a/test/transaction.js b/test/transaction.js index 68ddf84..743f496 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -221,7 +221,7 @@ describe('Transaction', function() { }) }) - describe('p2shsign', function() { + describe('signScriptSig', function() { var tx = new Transaction() tx.addInput('deadbeefcafe', 0) tx.addOutput('mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r', 1, network.testnet) @@ -236,8 +236,8 @@ describe('Transaction', function() { var pubKeyBuffers = pubKeys.map(function(q) { return q.toBuffer() }) var redeemScript = Script.createMultisigOutputScript(2, pubKeyBuffers) - var signatures = privKeys.map(function(eck) { - return tx.p2shsign(0, redeemScript, eck) + var signatures = privKeys.map(function(privKey) { + return tx.signScriptSig(0, redeemScript, privKey) }) var scriptSig = Script.createP2SHMultisigScriptSig(signatures, redeemScript)