EOSCommunity.org Forums

Cosigning transaction

Trying to implement this cosigning flow

My cosignTransaction() function sends transaction body to the backend and gets back modified transaction with prepended noop action and a valid signature for the new transaction signed by resource provider.

Here’s the snippet:

async function handleAnchor(actions: Action[]) {
  const session = await anchor.login();
  if (!session) return "";

  const [ info, abis ] = await Promise.all([
    session.client.v1.chain.get_info(),
    session.client.v1.chain.get_abi(actions[0].account)
  ]);
  const header = info.getTransactionHeader(300)
  const trx = Transaction.from({
    ...header,
    actions
  }, abis.abi);

  const { transaction, signatures } = await cosignTransaction( trx, session.auth );

  const signedTransaction = SignedTransaction.from({
      ...transaction,
      signatures,
  })

  const result = await session.transact({ transaction: signedTransaction});

  return result.transaction.id;
}

But looks like session.transact() ignores supplied signature.

So after signing it in Anchor I get this error (note that the only signature here is the one I signed in Anchor):

transaction declares authority '{"actor":"<resourceacc>","permission":"noop"}', but does not have signatures for it under a provided delay of 0 ms, provided permissions [], provided keys ["EOS4w768L97otYaqNcoippcMVKAPwmj2dVZaog7eLLDFsZQteRHCu"], and a delay max limit of 3888000000 ms

Am I doing it wrong?

You’ll need to merge the signatures together, the one from the cosigner and the one from the wallet.

Here’s the section from an example I wrote a while back:

The transact call doesn’t broadcast by default, so it’ll return the signature to you for you to merge and then broadcast manually.

That was it. Got it to work. Thanks for the quick reply!

One more related question.
Is there a way to suppress this “Success!” message when signing a transaction without broadcasting?

image

In the browser transport options, there’s a way to suppress the status at the end.

const transport = new AnchorLinkBrowserTransport({
    /** Whether to display request success and error messages, defaults to true */
    requestStatus: false,
})
const link = new AnchorLink({transport})

Thanks, that worked.