3

Goal: be able to separately create, sign and broadcast a transaction:

Global for both approaches: const privkey = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'; Approach 1:

transferSignPushTr1 : async (from, to, amount, memo) => {
  const options = {
    authorization: `${from}@active`, //@active for activeKey, @owner for Owner key
    //default authorizations will be calculated.
    broadcast: false,
    sign: false,
  };

  const transaction = await eos.transaction(
    'eosio.token',
    acc => {
      acc.transfer(from, to, amount, memo);
    },
    options
  );
  const data = transaction.transaction.transaction.actions[0].data;
  const sig = await ecc.sign(data, privkey);
  const trFinal = await eos.pushTransaction({ compression: 'none', transaction: transaction, signatures: sig })
},

returns "Invalid packed transaction" Possible problem. Wrong transaction file in eos.pushTransaction() or wrong data for ecc.sign(data, ...)

Approach 2:

transferSignPushTr2 : async (from, to, amount, memo) => {
  const options = {
    authorization: `${from}@active`, //@active for activeKey, @owner for Owner key
    //default authorizations will be calculated.
    broadcast: false,
    sign: false,
  };

  const transaction = await eos.transaction(
    'eosio.token',
    acc => {
      acc.transfer(from, to, amount, memo);
    },
    options
  );
  const data = transaction.transaction.transaction.actions[0].data;
  const sig = await ecc.sign(data, privkey);
  transaction.transaction.signatures.push(sig);
  const trFinal = await eos.pushTransaction(transaction.transaction);
},

returns : api < error { message: 'transaction declares authority \'{"actor":"inita","permission":"active"}\', but does not have signatures for it under a provided delay of 0 ms, provided permissions [], and provided keys ["EOS7pDBdW8JeB8wxc9HyECgFtL3pYewYeimQ9uThoGLc1HE5cCikG"]', file: 'authorization_manager.cpp', line_number: 411, possible problem: ecc.sign() hast the wrong input. I tried to generate a digest as suggested here, but could not find the option in eosjs. In https://github.com/EOSIO/eosjs/blob/v14.1.1/src/write-api.js#L406-L419 , a Buffer is used. I was not yet able to replicate it since I did not find the Transaction object/arg.

1 Answer 1

1

The EOS code uses fcbuffer to pack the transactions. Once packed, the packed data is combined with the chain ID and the Context Free Data to generate the signature. Specifically, the chain ID, packed data, and hash of the context free data are concatenated then run through the hash function. Once the hash is generated, it can be signed by the private key. An example, in Java, can be found on our GitHub page.

It is important to remember that the private key that signs the transaction must be the private key belonging to the user listed in the authorization section.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.