magiclabs / magic-js

Magic browser/React Native JavaScript SDK is your entry-point to integrating passwordless authentication inside your application.
https://magic.link/docs/api-reference/client-side-sdks/web
Apache License 2.0
463 stars 86 forks source link

Algorand group transactions #185

Closed solkimicreb closed 2 years ago

solkimicreb commented 3 years ago

✅ Prerequisites

🐛 Description

The algorand extension removes the transaction group field before signing transactions. This causes atomic group transactions to always fail.

  const params = await algodclient.getTransactionParams().do(); 

  const tx1 = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
    suggestedParams: params,
    from: addr1,
    to: addr2,
    amount: 200000,
  });

  const tx2 = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
    suggestedParams: params,
    from: addr1,
    to: addr2,
    amount: 200000,
  });

  const txs = [fundTx, rekeyTx];
  // this calculates and assigns a group field to both transactions
  algosdk.assignGroupID(txs);

  // the magic algorand extension removes the group field before signing the transactions
  const tx1Signed = await magic.algorand.signTransaction(tx1._getDictForDisplay());
  const tx2Signed = await magic.algorand.signTransaction(tx2._getDictForDisplay());

  // this fails because the transactions are sent in an atomic group with no group field
  await algodclient.sendRawTransaction([tx1Signed.blob, tx2Signed.blob]).do();

🤔 Expected behavior

The group field should not be removed before signing transactions. It is a Uint8Array for transactions created by the official algorand js sdk so you might have to convert them to a string before networking or window.postMessage calls. This is a nice example: https://github.com/randlabs/myalgo-connect/blob/f42ca7e52aa24a5cd98c6300ee6e5df8c9fda48e/lib/main.js#L193.

A small note

I can't find the source code of the @magic-ext/algorand lib. Is it available somewhere?

smithki commented 3 years ago

cc @harryEth

solkimicreb commented 3 years ago

Hi! Any update on this? I would be happy to help if you can point me in the right direction.

harryEth commented 3 years ago

@solkimicreb we support the group transaction now. Please check our doc here: https://magic.link/docs/blockchains/algorand

and demo https://github.com/magiclabs/example-algorand/blob/e6a4a426ddaebaa39f524f64dc6517cb3818bd90/src/App.js#L85

solkimicreb commented 3 years ago

Thanks! I will try it in the afternoon.