How can I sign unsigned transaction made from counterparty?

I use ‘IndieSqure’ API which uses CounterParty protocol.
I want to create transaction.

This is a sample code using shell.

curl -H “Content-Type: application/json” -X POST -d ‘{“source”: “1965areciqapsuL2hsia2yKkRLfAsH1smG”, “token”: “NETX”, “destination”: “12sWrxRY7E7Nhmuyjbz4TtGE9jRewGqEZD”, “quantity”: 1}’ https://api.indiesquare.me/v2/transactions/send

The result returns hex transaction ID like below.

{

“unsigned_tx”:“010000000414ae2264cdbe754b9ae4be18d84bfeb4f578af553b9b9e4f9cb2303d04ee9e45000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acffffffffec15d27b74516fefd921cecbe043ea63124d28a3903aef8fb1682ccc926b1c62000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acffffffff9878f76e1424c1d1eeb6b15d06902dd8f0c78f9bdb61263e4ca3ae68c571a292000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acfffffffffdac7f1c83b01a8924a8965d356b804c2608bc261fc18041116ddb4a143bc499000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acffffffff0336150000000000001976a9141485d9d03b41aaa9dca7d70d7f63ff4a0826100e88ac00000000000000001e6a1c246698efc5d81b78ceadf3179316b5eb6cc5c2c347c0b7b42121a94e92180000000000001976a91458b6e991b45487df810f4d96d5315da739637f1788ac00000000”
}

https://developer.indiesquare.me/?shell#create-send-transaction

I want to sign this unsigned transaction.
But I don’t know how, if you have any thought please let me know.

Thank you.

I tried referring this forum titled "Using Bitcore to sign Counterparty transactions?"
URL: Using Bitcore to sign Counterparty transactions?

My stack error is shown below.

Invalid state: undefined
Error
at Error.NodeError (/Users/NAMW/node_modules/bitcore-lib/lib/errors/index.js:20:41)
at Object.module.exports.checkState (/Users/NAME/node_modules/bitcore-lib/lib/util/preconditions.js:9:13)
at Transaction.sign (/Users/SONGDAVIDZHIYU/node_modules/bitcore-lib/lib/transaction/transaction.js:1053:5)
at repl:1:4
at REPLServer.defaultEval (repl.js:262:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer. (repl.js:431:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)

My transaction decode 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 }

Transaction signing expects to be able to know the amount of the UTXO, which is not included in transaction serialization. So it’s giving an assertion that all UTXO information isn’t available at: https://github.com/bitpay/bitcore-lib/blob/master/lib/transaction/transaction.js#L1053

Hi Braydon,
thanks for your reply.

Do you mean I should contain UTXO information in Transaction?
So if I write down code, how to implement?
My expectation is below.

■TO search UTXO

var UTXOS = ' ';
var address = 'SENDER ADDRESS';
var Insight = require('bitcore-explorers').Insight;
var insight = new Insight('testnet');

insight.getUnspentUtxos(address, function(err, utxos){
  if (err){
    // Handle errors...
  } else {
    UTXOS = utxos
}

【QUESTION】
I know totally how to collect UTXOS information.
But how to sign the transaction that is made by another protocol.

As I mentioned before, I want to create transaction using Counterparty protocol.
So I want to use ‘IndieSquare API’.
When I use this API to create a transaction, it returns ‘unsigned_txid’ which is hexadecimal style.

var unsigned_txid = '010000000414ae2264cdbe754b9ae4be18d84bfeb4f578af553b9b9e4f9cb2303d04ee9e45000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acffffffffec15d27b74516fefd921cecbe043ea63124d28a3903aef8fb1682ccc926b1c62000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acffffffff9878f76e1424c1d1eeb6b15d06902dd8f0c78f9bdb61263e4ca3ae68c571a292000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acfffffffffdac7f1c83b01a8924a8965d356b804c2608bc261fc18041116ddb4a143bc499000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acffffffff0336150000000000001976a9141485d9d03b41aaa9dca7d70d7f63ff4a0826100e88ac00000000000000001e6a1c246698efc5d81b78ceadf3179316b5eb6cc5c2c347c0b7b42121a94e92180000000000001976a91458b6e991b45487df810f4d96d5315da739637f1788ac00000000';

When I put the info into the variable, how to sign?
Just simply sign like below?

var privateKey = 'PRIVATE_KEY';
var tx = bitcore.Transaction(unsigned_txid);
tx.from = (UTXOS);
tx.sign(privateKey);