Using Bitcore to sign Counterparty transactions?

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);

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

Is there a stack trace from the error?

The transaction decodes as:

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

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

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:

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

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.

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
  txid: '<txid-of-utxo>', 
  outputIndex: <output-index-of-utxo>, 
  script: '<script-hex-of-utxo>', 
  address: '<address-of-utxo>', 
  satoshis: <amount-of-utxo>