Renames p2shsign to signScriptSig
This commit is contained in:
parent
fbf8211cab
commit
8ad8f6f169
@ -312,15 +312,15 @@ Transaction.deserialize = function(buffer) {
|
|||||||
*/
|
*/
|
||||||
Transaction.prototype.sign = function(index, key, type, network) {
|
Transaction.prototype.sign = function(index, key, type, network) {
|
||||||
assert(key instanceof ECKey)
|
assert(key instanceof ECKey)
|
||||||
type = type || SIGHASH_ALL
|
|
||||||
network = network || Network.bitcoin
|
network = network || Network.bitcoin
|
||||||
|
|
||||||
var address = key.pub.getAddress(network.pubKeyHash)
|
var address = key.pub.getAddress(network.pubKeyHash)
|
||||||
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)
|
|
||||||
|
|
||||||
|
// FIXME: Assumed prior TX was pay-to-pubkey-hash
|
||||||
|
var script = Script.createOutputScript(address, network)
|
||||||
|
var signature = this.signScriptSig(index, script, key, type)
|
||||||
|
|
||||||
|
var scriptSig = Script.createInputScript(signature, key.pub)
|
||||||
this.setScriptSig(index, scriptSig)
|
this.setScriptSig(index, scriptSig)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,10 +358,7 @@ Transaction.prototype.signWithKeys = function(keys, outputs, type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
Transaction.prototype.signScriptSig = function(index, script, key, type) {
|
||||||
* Signs a P2SH output at some index with the given key
|
|
||||||
*/
|
|
||||||
Transaction.prototype.p2shsign = function(index, script, key, type) {
|
|
||||||
type = type || SIGHASH_ALL
|
type = type || SIGHASH_ALL
|
||||||
var hash = this.hashTransactionForSignature(script, index, type)
|
var hash = this.hashTransactionForSignature(script, index, type)
|
||||||
return key.sign(hash).concat([type])
|
return key.sign(hash).concat([type])
|
||||||
|
|||||||
@ -221,7 +221,7 @@ describe('Transaction', function() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('p2shsign', function() {
|
describe('signScriptSig', function() {
|
||||||
var tx = new Transaction()
|
var tx = new Transaction()
|
||||||
tx.addInput('deadbeefcafe', 0)
|
tx.addInput('deadbeefcafe', 0)
|
||||||
tx.addOutput('mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r', 1, network.testnet)
|
tx.addOutput('mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r', 1, network.testnet)
|
||||||
@ -236,8 +236,8 @@ describe('Transaction', function() {
|
|||||||
var pubKeyBuffers = pubKeys.map(function(q) { return q.toBuffer() })
|
var pubKeyBuffers = pubKeys.map(function(q) { return q.toBuffer() })
|
||||||
var redeemScript = Script.createMultisigOutputScript(2, pubKeyBuffers)
|
var redeemScript = Script.createMultisigOutputScript(2, pubKeyBuffers)
|
||||||
|
|
||||||
var signatures = privKeys.map(function(eck) {
|
var signatures = privKeys.map(function(privKey) {
|
||||||
return tx.p2shsign(0, redeemScript, eck)
|
return tx.signScriptSig(0, redeemScript, privKey)
|
||||||
})
|
})
|
||||||
|
|
||||||
var scriptSig = Script.createP2SHMultisigScriptSig(signatures, redeemScript)
|
var scriptSig = Script.createP2SHMultisigScriptSig(signatures, redeemScript)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user