@@ -6,6 +6,7 @@ var T = require('../src/transaction')
66var Transaction = T . Transaction
77var TransactionOut = T . TransactionOut
88var Script = require ( '../src/script' )
9+ var network = require ( '..' ) . network
910
1011var fixtureTxes = require ( './fixtures/mainnet_tx' )
1112var fixtureTx1Hex = fixtureTxes . prevTx
@@ -220,6 +221,33 @@ describe('Transaction', function() {
220221 } )
221222 } )
222223
224+ describe ( 'p2shsign' , function ( ) {
225+ var tx = new Transaction ( )
226+ tx . addInput ( 'deadbeefcafe' , 0 )
227+ tx . addOutput ( 'mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r' , 1 , network . testnet )
228+
229+ var privKeys = [
230+ '5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf' ,
231+ '5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAvUcVfH'
232+ ] . map ( function ( wif ) {
233+ return ECKey . fromWIF ( wif )
234+ } )
235+ var pubKeys = privKeys . map ( function ( eck ) { return eck . pub } )
236+ var pubKeyBuffers = pubKeys . map ( function ( q ) { return q . toBuffer ( ) } )
237+ var redeemScript = Script . createMultisigOutputScript ( 2 , pubKeyBuffers )
238+
239+ var signatures = privKeys . map ( function ( eck ) {
240+ return tx . p2shsign ( 0 , redeemScript , eck )
241+ } )
242+
243+ var scriptSig = Script . createP2SHMultisigScriptSig ( signatures , redeemScript )
244+ tx . setScriptSig ( 0 , scriptSig )
245+
246+ var expected = '0100000001fecaefbeadde00000000fd1b0100483045022100a165904d2a3123ae887bd573b685e903a0ce158b1d21faba2ed4a42b3ca6126e02205f4e0e0cb333666d5b6b0b017fe0df0ac15a20f296a3fb8eab4e1572da2b3dea01473044022054e0cb54d62465a4003a2d0876048cde2b43dcab9385ffe173a2886bfa4d04b00220239811a8923887aa147d92987fa5c16f09a7fb7eea1d331c1a1d5303fd81f9c8014c8752410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a52aeffffffff0101000000000000001976a914751e76e8199196d454941c45d1b3a323f1433bd688ac00000000'
247+
248+ assert . equal ( b2h ( tx . serialize ( ) ) , expected )
249+ } )
250+
223251 describe ( 'TransactionOut' , function ( ) {
224252 describe ( 'scriptPubKey' , function ( ) {
225253 it ( 'returns hex string' , function ( ) {
0 commit comments