opened
dizda
username_0
Hi,

I have a multisig address, then I want to create a simple transaction from it.
The problem occurs when I'm trying to recover the serialized transaction with the `fromTransaction()` function from the `TransactionBuilder` class, 

So since the version 1.4.5, I've encounter this error:

```
/PATH/node_modules/bitcoinjs-lib/src/transaction_builder.js:271
  var canSign = input.hashType &&
                     ^
TypeError: Cannot read property 'hashType' of undefined
    at TransactionBuilder.sign (/PATH/node_modules/bitcoinjs-lib/src/transaction_builder.js:271:22)
```

You can reproduce with this sample script:

```js
var bitcoin = require('bitcoinjs-lib');

var pubKeys = [
    '0227fbadd0c4a2c8c89ab7996e5f5489dfcc3dfe7924fedd0167046166f1613eaa', // #1
    '034162edc518f6fc83ab826db81d50a8002b814b9f0b739a69560e14d3773296ee', // #2
    '0296a44a6f2ed29bec93d4a6afac0fbc243c9ea1599caad6f515a140e7f4ee61e7'  // #3
];

var privKeys = [
    'L2rVPg54JmbpUYBXbMCFHFFdZByXKT1UdaAN9zvYbgFGWoHTM4A3', // #1
    'L5h7uvxNbUwht99ewKxRedEZq7wii4RDwnVSVP327UCwWLYprysM', // #2
    'KzgkfPwEHKJzoQc8CyrdVLAB8dec861zj54BEYNaP6vALGum4K8C'  // #3
];

var redeemScript = '52210227fbadd0c4a2c8c89ab7996e5f5489dfcc3dfe7924fedd0167046166f1613eaa210296a44a6f2ed29bec93d4a6afac0fbc243c9ea1599caad6f515a140e7f4ee61e721034162edc518f6fc83ab826db81d50a8002b814b9f0b739a69560e14d3773296ee53ae';


// Recover transaction from raw_transaction created by bitcoind || or raw_signed_transaction
var tx  = bitcoin.Transaction.fromHex('0100000001a9c345321fa0866212a1852a48e32876816a1a059e03e8bfd34a2acdb8ac38170100000000ffffffff02204e0000000000001976a9140b167a9a9040e46e9c87d8c8291bbefae77c6bfe88ac503403000000000017a9147a82193d183b15125285cd88aac0b8fa9e322ac18700000000');

// Build it into Transaction Builder
var txb = bitcoin.TransactionBuilder.fromTransaction(tx);

var rawSignedTransaction;

// Loop on each inputs
txb.tx.ins.forEach(function(input, i) {

    // get the txid of the input
    var txid   = bitcoin.bufferutils.reverse(input.hash).toString('hex');

    // [...]

    // Sign the input
    txb.sign(i, bitcoin.ECKey.fromWIF(privKeys[0]), bitcoin.Script.fromHex(redeemScript));
//    txb.sign(i, bitcoin.ECKey.fromWIF(privKeys[1]), bitcoin.Script.fromHex(redeemScript));

    try {
        rawSignedTransaction = txb.build().toHex();

        console.log('Successfully signed.');
    } catch (e) {
        if ('Transaction is missing signatures' === e.message) {
            // Normal, because every inputs are not signed yet.

            rawSignedTransaction = txb.buildIncomplete().toHex();
        } else if ('Not enough signatures provided' === e.message) {
            console.log('Not enough signatures provided');

            rawSignedTransaction = txb.buildIncomplete().toHex();
        } else {
            console.log(e);
        }
    }
});

console.log(rawSignedTransaction);
```

FYI, this script worked well on 1.4.3 (I didn't test on 1.4.4).

When I comment this line https://github.com/bitcoinjs/bitcoinjs-lib/blob/09d8e440de71352e04e61a1129662c04f8de6d11/src/transaction_builder.js#L116 the signature process works again.

Any idea?
Thanks
Trying to sign a multisig transaction recovered with fromTransaction()
issue
created
thallium205
username_1
I can confirm as this is an issue for us as well.
comment
created
dcousens
username_2
Confirmed.  Sorry this took so long to get to. Will resolve asap.
comment
closed
dcousens
username_2
issue
created
dcousens
username_2
Resolved.  Tests still need to be added, see #382
comment