Script: use PubKey objects not prebuilt Buffers
This commit is contained in:
parent
54cc123d31
commit
55681e7e5d
4 changed files with 13 additions and 13 deletions
|
@ -295,12 +295,15 @@ Script.createP2SHScriptPubKey = function(hash) {
|
|||
// m [pubKeys ...] n OP_CHECKMULTISIG
|
||||
Script.createMultisigScriptPubKey = function(m, pubKeys) {
|
||||
var script = new Script()
|
||||
var n = pubKeys.length
|
||||
|
||||
script.writeOp(opcodes.OP_1 + m - 1)
|
||||
for (var i = 0; i < pubKeys.length; ++i) {
|
||||
script.writeBytes(pubKeys[i])
|
||||
}
|
||||
script.writeOp(opcodes.OP_1 + pubKeys.length - 1)
|
||||
script.writeOp((opcodes.OP_1 - 1) + m)
|
||||
|
||||
pubKeys.forEach(function(pubKey) {
|
||||
script.writeBytes(pubKey.toBuffer())
|
||||
})
|
||||
|
||||
script.writeOp((opcodes.OP_1 - 1) + n)
|
||||
script.writeOp(opcodes.OP_CHECKMULTISIG)
|
||||
|
||||
return script
|
||||
|
|
|
@ -27,10 +27,7 @@ describe('p2sh', function() {
|
|||
var pubKeys = privKeys.map(function(eck) {
|
||||
return eck.pub
|
||||
})
|
||||
var pubKeyBuffers = pubKeys.map(function(q) {
|
||||
return q.toBuffer()
|
||||
})
|
||||
var redeemScript = Script.createMultisigScriptPubKey(2, pubKeyBuffers)
|
||||
var redeemScript = Script.createMultisigScriptPubKey(2, pubKeys)
|
||||
var hash160 = crypto.hash160(redeemScript.buffer)
|
||||
var multisigAddress = new Address(hash160, networks.testnet.scriptHash)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ var crypto = require('../src/crypto')
|
|||
var networks = require('../src/networks')
|
||||
|
||||
var Address = require('../src/address')
|
||||
var ECPubKey = require('../src/ecpubkey')
|
||||
var Script = require('../src/script')
|
||||
|
||||
var fixtures = require('./fixtures/script')
|
||||
|
@ -95,7 +96,7 @@ describe('Script', function() {
|
|||
'02ea1297665dd733d444f31ec2581020004892cdaaf3dd6c0107c615afb839785f',
|
||||
'02fab2dea1458990793f56f42e4a47dbf35a12a351f26fa5d7e0cc7447eaafa21f',
|
||||
'036c6802ce7e8113723dd92cdb852e492ebb157a871ca532c3cb9ed08248ff0e19'
|
||||
].map(h2b)
|
||||
].map(ECPubKey.fromHex)
|
||||
})
|
||||
|
||||
it('should create valid redeemScript', function() {
|
||||
|
@ -112,7 +113,7 @@ describe('Script', function() {
|
|||
var pubKeys = [
|
||||
'02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1',
|
||||
'0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a'
|
||||
].map(h2b)
|
||||
].map(ECPubKey.fromHex)
|
||||
var signatures = [
|
||||
'304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801',
|
||||
'3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501'
|
||||
|
|
|
@ -255,8 +255,7 @@ describe('Transaction', function() {
|
|||
return ECKey.fromWIF(wif)
|
||||
})
|
||||
var pubKeys = privKeys.map(function(eck) { return eck.pub })
|
||||
var pubKeyBuffers = pubKeys.map(function(q) { return q.toBuffer() })
|
||||
var redeemScript = Script.createMultisigScriptPubKey(2, pubKeyBuffers)
|
||||
var redeemScript = Script.createMultisigScriptPubKey(2, pubKeys)
|
||||
|
||||
var signatures = privKeys.map(function(privKey) {
|
||||
return tx.signScriptSig(0, redeemScript, privKey)
|
||||
|
|
Loading…
Add table
Reference in a new issue