Using Bitcore to sign Counterparty transactions?

(Priestc) #1

I’m trying to use Bitcore to sign a transaction made by CounterParty. I’m getting an error though:

hex = "01000000014330a448667526595512e6da39b77d3f3aaa78b82e06176f5f368101e82594f8020000001976a914ad44fd5f413830597f94896600574d68d63e7a1b88acffffffff0336150000000000001976a91443878e562582fc0201cac32258bd696ee1cf40e588ac00000000000000001e6a1c40029655dfedd4425bfba0441cec6ec532ab25d38052c542d3ba5b854dc70000000000001976a914ad44fd5f413830597f94896600574d68d63e7a1b88ac00000000";

tx = new bitcore.Transaction(hex);
tx.sign("KzWsS4UaUaCfUbrtg1k...")

Am I doing this correctly? The error I get is “Invalid state: undefined”

0 Likes

(Braydon Fuller) #2

Is there a stack trace from the error?

The transaction decodes as:

> tx.toObject()
{ hash: '527595bd68d56be4bc334cf5b740b505acaa684718b25be3a215ea589e6bb3b0',
  version: 1,
  inputs: 
   [ { prevTxId: 'f89425e80181365f6f17062eb878aa3a3f7db739dae612555926756648a43043',
       outputIndex: 2,
       sequenceNumber: 4294967295,
       script: '76a914ad44fd5f413830597f94896600574d68d63e7a1b88ac',
       scriptString: 'OP_DUP OP_HASH160 20 0xad44fd5f413830597f94896600574d68d63e7a1b OP_EQUALVERIFY OP_CHECKSIG' } ],
  outputs: 
   [ { satoshis: 5430,
       script: '76a91443878e562582fc0201cac32258bd696ee1cf40e588ac' },
     { satoshis: 0,
       script: '6a1c40029655dfedd4425bfba0441cec6ec532ab25d38052c542d3ba5b85' },
     { satoshis: 51021,
       script: '76a914ad44fd5f413830597f94896600574d68d63e7a1b88ac' } ],
  nLockTime: 0 }
0 Likes

(Priestc) #3

Hi Braydon!

Here is the stack trace I’m getting:

at Error.r (http://localhost:8001/static/bitcore-lib.min.js:2:8703)
at Object.checkState (http://localhost:8001/static/bitcore-lib.min.js:5:24301)
at n.sign (http://localhost:8001/static/bitcore-lib.min.js:5:13569)
at test_counterparty (http://localhost:8001/static/wallet.js:830:12)
at :1:1

0 Likes

How can I sign unsigned transaction made from counterparty?
(Braydon Fuller) #4

Looks like it’s pointing to some obscure point in the minified code, however from context of what’s going on here, I’m fairly sure it’s because of this check: https://github.com/bitpay/bitcore-lib/blob/master/lib/transaction/transaction.js#L1053

Signing transactions requires some additional information (previous outputs) that is not available in standard serialization of a transaction.

0 Likes

(Priestc) #5

Are you sure because I was able to sign the transaction successfully with pybitcointools. I think whatever issue is hodling this up should be fixed because signing unsigned transactions is a very common operation.

0 Likes

(Braydon Fuller) #6

Yes both the UTXO amount and scriptPubKey need to be known. In the above transaction the scriptPubKey looks to be in the place of the scriptSig, however the amount isn’t known.

// This will add an input that will have the information for signing
tx.from({
  txid: '<txid-of-utxo>', 
  outputIndex: <output-index-of-utxo>, 
  script: '<script-hex-of-utxo>', 
  address: '<address-of-utxo>', 
  satoshis: <amount-of-utxo>
});
0 Likes