Giter VIP home page Giter VIP logo

Comments (5)

logiclogue avatar logiclogue commented on June 30, 2024

I'm not a dev on this project, but also going to be tackling the same problem soon. My thought process is the following:

  1. Create the transactions in your atomic transfer group, as you would normally
  2. Group them together using the JavaScript algosdk (https://github.com/algorand/js-algorand-sdk#transaction-group), this means each transaction will now have a group ID as well
  3. Sign each individual transaction using AlgoSigner
  4. Use AlgoSigner to send the transaction group (I hope this bit works, I'm not sure whether AlgoSigner supports it)

I'll let you know how my experiment goes!

from algosigner.

totenkatze avatar totenkatze commented on June 30, 2024

Been working on it for a few days and the issue I'm having is really just the fact that Algosigner expects a transaction object that is different than the one that algosdk.js produces.

See:
https://github.com/PureStake/algosigner/blob/develop/docs/dApp-integration.md#transaction-requirements

Particularly the following.

  • Must not have additional unknown fields

Addresses and the groupId are also byte arrays which seem to be incompatible with what AlgoSigner is expecting.

from algosigner.

totenkatze avatar totenkatze commented on June 30, 2024
        function base64ToArrayBuffer(base64) {
            var binary_string = window.atob(base64);
            var len = binary_string.length;
            var bytes = new Uint8Array(len);
            for (var i = 0; i < len; i++) {
                bytes[i] = binary_string.charCodeAt(i);
            }
            return bytes.buffer;
        }

        async function signGroupTransactions() {
            if (typeof AlgoSigner !== 'undefined') {
                await AlgoSigner.connect();

                // I have two accounts in algosigner.
                let accounts = await AlgoSigner.accounts({ ledger: `TestNet` });

                let txParams = await AlgoSigner.algod({
                    ledger: 'TestNet',
                    path: '/v2/transactions/params',
                });

                // First transaction from account 1 to account 2.
                let txn1 = {
                    from: accounts[0].address,
                    to: accounts[1].address,
                    fee: txParams['min-fee'],
                    type: 'pay',
                    amount: 1000000,
                    firstRound: txParams['last-round'],
                    lastRound: txParams['last-round'] + 1000,
                    genesisID: txParams['genesis-id'],
                    genesisHash: txParams['genesis-hash']
                };

                // Second transaction from account 2 to account 1.
                let txn2 = {
                    from: accounts[1].address,
                    to: accounts[1].address,
                    fee: txParams['min-fee'],
                    type: 'pay',
                    amount: 2000000,
                    firstRound: txParams['last-round'],
                    lastRound: txParams['last-round'] + 1000,
                    genesisID: txParams['genesis-id'],
                    genesisHash: txParams['genesis-hash']
                };

                // using the sdk to assign the group id.
                let txnGroup = algosdk.assignGroupID([txn1, txn2]);

                // Algosigner likes base64 encoded strings. So get the group id and set it on the two original transactions.
                let groupId = btoa(String.fromCharCode.apply(null, txnGroup[0].group));
                txn1.group = groupId;
                txn2.group = groupId;

                // Sign the transactions with AlgoSigner.
                let signedTxn1 = await AlgoSigner.sign(txn1);
                let signedTxn2 = await AlgoSigner.sign(txn2);

                // Get the signed transactions as arrays so that we cans send them with the sdk.
                // This is because I don't know how to send a transaction group through with AlgoSigner.
                let signed = [];
                signed.push(base64ToArrayBuffer(signedTxn1.blob));
                signed.push(base64ToArrayBuffer(signedTxn2.blob));

                try {
                    // Alas, this won't work.
                    let tx = (await algodClient.sendRawTransaction(signed).do());
                    console.log("Transaction : " + tx.txId);
                }
                catch (error) {
                    // Based on the error and decoded transactions, it looks like "group" was not in the signed transaction.
                    console.log(error);
                    console.log(algosdk.decodeSignedTransaction(base64ToArrayBuffer(signedTxn1.blob)));
                    console.log(algosdk.decodeSignedTransaction(base64ToArrayBuffer(signedTxn2.blob)));
                }
            }
        }

This is as close as I have come to producing an sending a transaction group with AlgoSigner with a little help from algosdk.js

from algosigner.

purestaketdb avatar purestaketdb commented on June 30, 2024

Hey, we are working on a fix for this right now, planned for release in the next week or so.

The issue lies in two places, one in the Algorand JS SDK transaction builder object constructor dropping the groupID and two, AlgoSigner itself not expecting the groupID to come across in the sign() in a string format that needs to be converted.

from algosigner.

purestaketdb avatar purestaketdb commented on June 30, 2024

This is complete and released here in GitHub, the Chrome Store update will be 1-3 days from now. See the example https://purestake.github.io/algosigner-dapp-example/tx-test/signTesting.html (group) and note the rules about concatenation of binary.

from algosigner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.