From 5d0f3b12d5d598b1e8b6a06629a9e5f84e2063c9 Mon Sep 17 00:00:00 2001 From: Jan Marcano Date: Tue, 30 Aug 2022 20:16:27 -0300 Subject: [PATCH 1/2] Fix regression affecting Ledger devices caused by #427 --- .../background/messaging/internalMethods.ts | 47 ++++++++----------- .../extension/src/background/utils/session.ts | 33 +++++++------ .../LedgerDevice/LedgerHardwareSign.ts | 15 ++++-- 3 files changed, 49 insertions(+), 46 deletions(-) diff --git a/packages/extension/src/background/messaging/internalMethods.ts b/packages/extension/src/background/messaging/internalMethods.ts index 9bf3851c..7c67f627 100644 --- a/packages/extension/src/background/messaging/internalMethods.ts +++ b/packages/extension/src/background/messaging/internalMethods.ts @@ -434,9 +434,9 @@ export class InternalMethods { } public static [JsonRpcMethod.LedgerGetSessionTxn](request: any, sendResponse: Function) { - if (session.txnWrap) { - // The transaction contains source and JSONRPC info, the body.params will be the transaction validation object - sendResponse(session.txnWrap); + if (session.txnRequest && 'body' in session.txnRequest) { + // The session object gets the transaction validation object from the original request + sendResponse(session.txnObject); } else { sendResponse({ error: 'Transaction not found in session.' }); } @@ -444,17 +444,18 @@ export class InternalMethods { } public static [JsonRpcMethod.LedgerSendTxnResponse](request: any, sendResponse: Function) { - if (session.txnWrap && 'body' in session.txnWrap) { - const txnBuf = Buffer.from(request.body.params.txn, 'base64'); + if (session.txnRequest && session.txnObject && request.body?.params?.txn) { + const signedTxn = request.body.params.txn; + const txnBuf = Buffer.from(signedTxn, 'base64'); const decodedTxn = algosdk.decodeSignedTransaction(txnBuf); const signedTxnEntries = Object.entries(decodedTxn.txn).sort(); // Get the session transaction - const sessTxn = session.txnWrap.body.params.transaction; + const sessTxn = session.txnObject.transaction; // Set the fee to the estimate we showed on the screen for validation if there is one. - if (session.txnWrap.body.params.estimatedFee) { - sessTxn['fee'] = session.txnWrap.body.params.estimatedFee; + if (session.txnObject.estimatedFee) { + sessTxn['fee'] = session.txnObject.estimatedFee; } const sessTxnEntries = Object.entries(sessTxn).sort(); @@ -485,26 +486,18 @@ export class InternalMethods { signedTxnEntries['closeRemainderTo'] === sessTxnEntries['closeRemainderTo'] ) { //Check the txnWrap for a dApp response and return the transaction - if (session.txnWrap.source === 'dapp') { - const message = session.txnWrap; - - // If v2 then it needs to return an array - if (session.txnWrap?.body?.params?.transactionsOrGroups) { - message.response = [ - { - blob: request.body.params.txn, - }, - ]; - } else { - message.response = { - blob: request.body.params.txn, - }; - } + if (session.txnRequest.source === 'dapp') { + const message = session.txnRequest; + message.response = [ + { + blob: signedTxn, + }, + ]; sendResponse({ message: message }); } // If this is a ui transaction then we need to also submit - else if (session.txnWrap.source === 'ui') { + else if (session.txnRequest.source === 'ui') { const ledger = getLedgerFromGenesisId(decodedTxn.txn.genesisID); const algod = this.getAlgod(ledger); @@ -533,7 +526,7 @@ export class InternalMethods { } // Clear the cached transaction - session.txnWrap.body.params.transaction = undefined; + session.txnRequest.body.params.transaction = undefined; } else { sendResponse({ error: 'Transaction not found in session, unable to validate for send.' }); } @@ -544,10 +537,10 @@ export class InternalMethods { // Protected because this should only be called from within the ui or dapp sign methods protected static [JsonRpcMethod.LedgerSignTransaction](request: any, sendResponse: Function) { // Access store here here to save the transaction wrap to cache before the site picks it up. - // Explicitly using txnWrap on session instead of auth message for two reasons: + // Explicitly saving txnRequest on session instead of auth message for two reasons: // 1) So it lives inside background sandbox containment. // 2) The extension may close before a proper id on the new tab can allow the data to be saved. - session.txnWrap = request.body.params; + session.txnRequest = request; // Transaction wrap will contain response message if from dApp and structure will be different const ledger = getLedgerFromGenesisId(request.body.params.transaction.genesisID); diff --git a/packages/extension/src/background/utils/session.ts b/packages/extension/src/background/utils/session.ts index 80e34b2f..4f2277ad 100644 --- a/packages/extension/src/background/utils/session.ts +++ b/packages/extension/src/background/utils/session.ts @@ -2,35 +2,40 @@ export default class Session { private _wallet: any; private _ledger: any; private _availableLedgers: any; - private _txnWrap: any; + private _txnRequest: any; - public set wallet(v: any) { - this._wallet = v; + public set wallet(w: any) { + this._wallet = w; } public get wallet(): any { return this._wallet; } - public set ledger(v: any) { - this._ledger = v; + public set ledger(l: any) { + this._ledger = l; } public get ledger(): any { return this._ledger; } - public set txnWrap(w: any) { - this._txnWrap = w; + public set txnRequest(r: any) { + this._txnRequest = r; } - public get txnWrap(): any { - const w = this._txnWrap; - return w; + public get txnRequest(): any { + const r = this._txnRequest; + return r; } - public set availableLedgers(v: any) { - this._availableLedgers = v; + public get txnObject(): any { + const r = this._txnRequest; + return r?.body?.params; + } + + public set availableLedgers(al: any) { + this._availableLedgers = al; } public get availableLedgers(): any { @@ -46,7 +51,7 @@ export default class Session { wallet: this._wallet, ledger: this._ledger, availableLedgers: this._availableLedgers || [], - txnWrap: this._txnWrap, + txnRequest: this._txnRequest, }; } @@ -54,6 +59,6 @@ export default class Session { this._wallet = undefined; this._ledger = undefined; this._availableLedgers = undefined; - this._txnWrap = undefined; + this._txnRequest = undefined; } } diff --git a/packages/ui/src/components/LedgerDevice/LedgerHardwareSign.ts b/packages/ui/src/components/LedgerDevice/LedgerHardwareSign.ts index f1073fb6..14f91364 100644 --- a/packages/ui/src/components/LedgerDevice/LedgerHardwareSign.ts +++ b/packages/ui/src/components/LedgerDevice/LedgerHardwareSign.ts @@ -85,17 +85,20 @@ const LedgerHardwareSign: FunctionalComponent = () => { } if (response && 'txId' in response) { - setTxResponseHeader('Transaction sent:'); + setTxResponseHeader('Transaction sent with ID:'); setTxResponseDetail(response['txId']); setIsComplete(true); - } else { + } else if (response) { console.log(`response: ${JSON.stringify(response)}`); setTxResponseHeader('Transaction signed. Result sent to origin tab.'); setTxResponseDetail(JSON.stringify(response)); setIsComplete(true); + } else { + console.log('response not found'); + setError('There was a problem signing the transaction, please try again.'); } - setLoading(true); + setLoading(false); }); }); }; @@ -111,9 +114,11 @@ const LedgerHardwareSign: FunctionalComponent = () => {
${isComplete && html` -
+

${txResponseHeader}

-

${txResponseDetail}

+
+              ${txResponseDetail}
+            

You may now close this site and relaunch AlgoSigner.

`} From 90529a62d50bb7775fa75463043b57b9496c8890 Mon Sep 17 00:00:00 2001 From: Jan Marcano Date: Wed, 31 Aug 2022 11:31:13 -0300 Subject: [PATCH 2/2] Patch 1.9.4 --- README.md | 2 +- package.json | 2 +- packages/common/package.json | 2 +- packages/crypto/package.json | 2 +- packages/dapp/package.json | 2 +- packages/extension/manifest.json | 2 +- packages/extension/package.json | 2 +- packages/storage/package.json | 2 +- packages/test-project/package.json | 2 +- packages/ui/package.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 53c1dc59..04617d01 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Developers working with dApps may also install directly from the release package An interactive transition guide is available [here](https://purestake.github.io/algosigner-dapp-example/v1v2TransitionGuide.html). -## 1.9.3 Release +## 1.9.4 Release ### Main updates This update adds supports for easier transfers with the new autocomplete feature. Start typing an account, contact name or name service alias on the destination field when sending Algos or ASAs and you'll be able to select the desired address from a dropdown. This also marks the end of the support of the older signing methods that were previously available. diff --git a/package.json b/package.json index 238a95cf..6d7573ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "algosigner", - "version": "1.9.3", + "version": "1.9.4", "author": "https://developer.purestake.io", "description": "Sign Algorand transactions in your browser with PureStake.", "repository": "https://github.com/PureStake/algosigner", diff --git a/packages/common/package.json b/packages/common/package.json index b61878a9..9b4da7af 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@algosigner/common", - "version": "1.9.3", + "version": "1.9.4", "author": "https://developer.purestake.io", "description": "Common library functions for AlgoSigner.", "repository": "https://github.com/PureStake/algosigner", diff --git a/packages/crypto/package.json b/packages/crypto/package.json index 14f90af6..e51fdd40 100644 --- a/packages/crypto/package.json +++ b/packages/crypto/package.json @@ -1,6 +1,6 @@ { "name": "algosigner-crypto", - "version": "1.9.3", + "version": "1.9.4", "author": "https://developer.purestake.io", "description": "Cryptographic wrapper for saving and retrieving extention information in AlgoSigner.", "repository": { diff --git a/packages/dapp/package.json b/packages/dapp/package.json index 3a2f8a71..a138a9d0 100644 --- a/packages/dapp/package.json +++ b/packages/dapp/package.json @@ -1,6 +1,6 @@ { "name": "@algosigner/dapp", - "version": "1.9.3", + "version": "1.9.4", "author": "https://developer.purestake.io", "repository": "https://github.com/PureStake/algosigner", "license": "MIT", diff --git a/packages/extension/manifest.json b/packages/extension/manifest.json index 600f7db7..87d0b0cf 100644 --- a/packages/extension/manifest.json +++ b/packages/extension/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "AlgoSigner", "author": "https://developer.purestake.io", - "version": "1.9.3", + "version": "1.9.4", "description": "Algorand Wallet Extension | Send & Receive ALGOs | Sign dApp Transactions", "icons": { "48": "icon.png" diff --git a/packages/extension/package.json b/packages/extension/package.json index 60eb55bd..ecc2a6c9 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -1,6 +1,6 @@ { "name": "algosigner-extension", - "version": "1.9.3", + "version": "1.9.4", "author": "https://developer.purestake.io", "repository": "https://github.com/PureStake/algosigner", "license": "MIT", diff --git a/packages/storage/package.json b/packages/storage/package.json index ab8f4708..38ca2925 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -1,6 +1,6 @@ { "name": "algosigner-storage", - "version": "1.9.3", + "version": "1.9.4", "author": "https://developer.purestake.io", "repository": "https://github.com/PureStake/algosigner", "license": "MIT", diff --git a/packages/test-project/package.json b/packages/test-project/package.json index 973234bb..0affbf31 100644 --- a/packages/test-project/package.json +++ b/packages/test-project/package.json @@ -1,6 +1,6 @@ { "name": "algorand-test-project", - "version": "1.9.3", + "version": "1.9.4", "repository": "https://github.com/PureStake/algosigner", "license": "MIT", "description": "Repository for tests", diff --git a/packages/ui/package.json b/packages/ui/package.json index 524989a6..20c47b82 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -1,6 +1,6 @@ { "name": "algosigner-ui", - "version": "1.9.3", + "version": "1.9.4", "author": "https://developer.purestake.io", "repository": "https://github.com/PureStake/algosigner", "license": "MIT",