Comments (5)
I'm not a dev on this project, but also going to be tackling the same problem soon. My thought process is the following:
- Create the transactions in your atomic transfer group, as you would normally
- 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 - Sign each individual transaction using AlgoSigner
- 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.
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.
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.
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.
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.
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)
- Encrypt & Decrypt messages similar to Metamask API
- Uncaught error leads to blocking call HOT 1
- Support the presence of the extraPages field HOT 7
- v2 Sign - converting circular structures error HOT 1
- Cannot connect to sandbox nodes HOT 2
- Wrong total displayed HOT 1
- Inject Algosigner also into Iframes HOT 6
- Firefox extension HOT 3
- Is it possible to sign single transactions belonging to a group? HOT 1
- Unable to sign transaction w/ 2nd Ledger Nano S account HOT 4
- How to call the `AlgoSigner` class with typscript ? HOT 1
- Algosigner not injected again after refreshing page in React HOT 2
- Pressing ctrl+shift+T reopens the algosigner window HOT 3
- Validation failed for transaction due to invalid properties HOT 1
- Add About section to Algosinger HOT 1
- No Pop Up to Submit vote for Governance HOT 3
- Inclusion of empty "signers" array in groups returns error "address appears to be malformed" HOT 5
- Internal server error HOT 1
- AlgoSigner is not added to `window` global in certain cases HOT 1
- Is this library actively maintained? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algosigner.