From 80a0de09fd7f53c26749232388365f985505f71b Mon Sep 17 00:00:00 2001 From: Doug Richar Date: Sat, 16 Nov 2024 03:03:50 -0500 Subject: [PATCH] feat(*): migrate to algosdk v3.0.0 (#314) * feat(*): migrate to algosdk v3.0.0 BREAKING CHANGE: Update transaction handling to support algosdk v3.x API - Transaction properties renamed (from -> sender, firstRound -> firstValid) - New transaction construction format using type and params objects - Modified transaction signing and verification logic - Update all package.json files to use algosdk v3.0.0 - Refactor transaction creation and handling across all wallet implementations - Update test cases to use new transaction format and API * fix(examples): update transaction params for algosdk v3 Update transaction parameter names in all example projects to match algosdk v3: - Rename 'from' to 'sender' - Rename 'to' to 'receiver' Affects examples in Next.js, Nuxt, React, Solid, Vue, and vanilla TS --- examples/nextjs/package.json | 2 +- examples/nextjs/src/app/Connect.tsx | 4 +- examples/nuxt/components/Connect.vue | 4 +- examples/nuxt/package.json | 2 +- examples/react-ts/package.json | 2 +- examples/react-ts/src/Connect.tsx | 4 +- examples/solid-ts/package.json | 2 +- examples/solid-ts/src/Connect.tsx | 4 +- examples/vanilla-ts/package.json | 2 +- examples/vanilla-ts/src/WalletComponent.ts | 4 +- examples/vue-ts/package.json | 2 +- examples/vue-ts/src/components/Connect.vue | 4 +- packages/use-wallet-react/package.json | 4 +- packages/use-wallet-solid/package.json | 4 +- packages/use-wallet-vue/package.json | 4 +- packages/use-wallet/package.json | 4 +- .../use-wallet/src/__tests__/utils.test.ts | 152 ++++++++++-------- .../src/__tests__/wallets/custom.test.ts | 41 +++-- .../src/__tests__/wallets/defly.test.ts | 50 +++--- .../src/__tests__/wallets/exodus.test.ts | 49 +++--- .../src/__tests__/wallets/kibisis.test.ts | 50 +++--- .../src/__tests__/wallets/kmd.test.ts | 49 +++--- .../src/__tests__/wallets/liquid.test.ts | 15 +- .../src/__tests__/wallets/lute.test.ts | 52 +++--- .../src/__tests__/wallets/magic.test.ts | 51 +++--- .../src/__tests__/wallets/mnemonic.test.ts | 29 ++-- .../src/__tests__/wallets/pera.test.ts | 49 +++--- .../src/__tests__/wallets/pera2.test.ts | 49 +++--- .../__tests__/wallets/walletconnect.test.ts | 51 +++--- packages/use-wallet/src/utils.ts | 24 ++- packages/use-wallet/src/wallets/defly.ts | 11 +- packages/use-wallet/src/wallets/exodus.ts | 11 +- packages/use-wallet/src/wallets/kibisis.ts | 13 +- packages/use-wallet/src/wallets/kmd.ts | 11 +- packages/use-wallet/src/wallets/liquid.ts | 1 + packages/use-wallet/src/wallets/lute.ts | 16 +- packages/use-wallet/src/wallets/magic.ts | 11 +- packages/use-wallet/src/wallets/mnemonic.ts | 17 +- packages/use-wallet/src/wallets/pera.ts | 11 +- packages/use-wallet/src/wallets/pera2.ts | 11 +- .../use-wallet/src/wallets/walletconnect.ts | 11 +- pnpm-lock.yaml | 121 ++++++++------ 42 files changed, 485 insertions(+), 523 deletions(-) diff --git a/examples/nextjs/package.json b/examples/nextjs/package.json index 1891aaa5..04901d26 100644 --- a/examples/nextjs/package.json +++ b/examples/nextjs/package.json @@ -13,7 +13,7 @@ "@txnlab/use-wallet-react": "workspace:*", "@walletconnect/modal": "^2.7.0", "@walletconnect/sign-client": "^2.17.1", - "algosdk": "2.9.0", + "algosdk": "3.0.0", "lute-connect": "^1.4.1", "next": "14.2.15", "react": "18.3.1", diff --git a/examples/nextjs/src/app/Connect.tsx b/examples/nextjs/src/app/Connect.tsx index 0419480f..d9095c7d 100644 --- a/examples/nextjs/src/app/Connect.tsx +++ b/examples/nextjs/src/app/Connect.tsx @@ -53,8 +53,8 @@ export function Connect() { const suggestedParams = await algodClient.getTransactionParams().do() const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ - from: activeAddress, - to: activeAddress, + sender: activeAddress, + receiver: activeAddress, amount: 0, suggestedParams }) diff --git a/examples/nuxt/components/Connect.vue b/examples/nuxt/components/Connect.vue index daac3a9a..3b909c28 100644 --- a/examples/nuxt/components/Connect.vue +++ b/examples/nuxt/components/Connect.vue @@ -44,8 +44,8 @@ const sendTransaction = async (wallet: Wallet) => { const suggestedParams = await algodClient.value.getTransactionParams().do() const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ - from: wallet.activeAccount.address, - to: wallet.activeAccount.address, + sender: wallet.activeAccount.address, + receiver: wallet.activeAccount.address, amount: 0, suggestedParams }) diff --git a/examples/nuxt/package.json b/examples/nuxt/package.json index 767bdf06..92ff95d7 100644 --- a/examples/nuxt/package.json +++ b/examples/nuxt/package.json @@ -18,7 +18,7 @@ "@txnlab/use-wallet-vue": "workspace:*", "@walletconnect/modal": "^2.7.0", "@walletconnect/sign-client": "^2.17.1", - "algosdk": "2.9.0", + "algosdk": "3.0.0", "lute-connect": "^1.4.1", "nuxt": "3.13.2", "vue": "3.5.12", diff --git a/examples/react-ts/package.json b/examples/react-ts/package.json index fa10b81b..e0316d2d 100644 --- a/examples/react-ts/package.json +++ b/examples/react-ts/package.json @@ -15,7 +15,7 @@ "@txnlab/use-wallet-react": "workspace:*", "@walletconnect/modal": "^2.7.0", "@walletconnect/sign-client": "^2.17.1", - "algosdk": "2.9.0", + "algosdk": "3.0.0", "lute-connect": "^1.4.1", "react": "18.3.1", "react-dom": "18.3.1" diff --git a/examples/react-ts/src/Connect.tsx b/examples/react-ts/src/Connect.tsx index d93e564f..8b5f6433 100644 --- a/examples/react-ts/src/Connect.tsx +++ b/examples/react-ts/src/Connect.tsx @@ -50,8 +50,8 @@ export function Connect() { const suggestedParams = await algodClient.getTransactionParams().do() const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ - from: activeAddress, - to: activeAddress, + sender: activeAddress, + receiver: activeAddress, amount: 0, suggestedParams }) diff --git a/examples/solid-ts/package.json b/examples/solid-ts/package.json index 05ec43fd..7a68fee2 100644 --- a/examples/solid-ts/package.json +++ b/examples/solid-ts/package.json @@ -16,7 +16,7 @@ "@txnlab/use-wallet-solid": "workspace:*", "@walletconnect/modal": "^2.7.0", "@walletconnect/sign-client": "^2.17.1", - "algosdk": "2.9.0", + "algosdk": "3.0.0", "lute-connect": "^1.4.1", "solid-js": "1.9.2" }, diff --git a/examples/solid-ts/src/Connect.tsx b/examples/solid-ts/src/Connect.tsx index 34bd87c6..8155e99d 100644 --- a/examples/solid-ts/src/Connect.tsx +++ b/examples/solid-ts/src/Connect.tsx @@ -54,8 +54,8 @@ export function Connect() { const suggestedParams = await algodClient().getTransactionParams().do() const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ - from: sender, - to: sender, + sender: sender, + receiver: sender, amount: 0, suggestedParams }) diff --git a/examples/vanilla-ts/package.json b/examples/vanilla-ts/package.json index 7e95f2ae..5d314705 100644 --- a/examples/vanilla-ts/package.json +++ b/examples/vanilla-ts/package.json @@ -20,7 +20,7 @@ "@txnlab/use-wallet": "workspace:*", "@walletconnect/modal": "^2.7.0", "@walletconnect/sign-client": "^2.17.1", - "algosdk": "2.9.0", + "algosdk": "3.0.0", "lute-connect": "^1.4.1" } } diff --git a/examples/vanilla-ts/src/WalletComponent.ts b/examples/vanilla-ts/src/WalletComponent.ts index ad19be47..b06e5988 100644 --- a/examples/vanilla-ts/src/WalletComponent.ts +++ b/examples/vanilla-ts/src/WalletComponent.ts @@ -41,8 +41,8 @@ export class WalletComponent { const suggestedParams = await this.manager.algodClient.getTransactionParams().do() const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ - from: activeAddress, - to: activeAddress, + sender: activeAddress, + receiver: activeAddress, amount: 0, suggestedParams }) diff --git a/examples/vue-ts/package.json b/examples/vue-ts/package.json index 64c65fee..17718702 100644 --- a/examples/vue-ts/package.json +++ b/examples/vue-ts/package.json @@ -15,7 +15,7 @@ "@txnlab/use-wallet-vue": "workspace:*", "@walletconnect/modal": "^2.7.0", "@walletconnect/sign-client": "^2.17.1", - "algosdk": "2.9.0", + "algosdk": "3.0.0", "lute-connect": "^1.4.1", "vue": "3.5.12" }, diff --git a/examples/vue-ts/src/components/Connect.vue b/examples/vue-ts/src/components/Connect.vue index 011b8b3c..3362e24d 100644 --- a/examples/vue-ts/src/components/Connect.vue +++ b/examples/vue-ts/src/components/Connect.vue @@ -37,8 +37,8 @@ const sendTransaction = async (wallet: Wallet) => { const suggestedParams = await algodClient.value.getTransactionParams().do() const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ - from: wallet.activeAccount.address, - to: wallet.activeAccount.address, + sender: wallet.activeAccount.address, + receiver: wallet.activeAccount.address, amount: 0, suggestedParams }) diff --git a/packages/use-wallet-react/package.json b/packages/use-wallet-react/package.json index c78a3d05..641643f1 100644 --- a/packages/use-wallet-react/package.json +++ b/packages/use-wallet-react/package.json @@ -43,7 +43,7 @@ }, "devDependencies": { "@types/react": "18.3.11", - "algosdk": "2.9.0", + "algosdk": "3.0.0", "jsdom": "25.0.1", "react": "18.3.1", "react-dom": "18.3.1", @@ -57,7 +57,7 @@ "@walletconnect/modal": "^2.7.0", "@perawallet/connect": "^1.3.5", "@walletconnect/sign-client": "^2.17.1", - "algosdk": "^2.7.0", + "algosdk": "^3.0.0", "lute-connect": "^1.4.1", "magic-sdk": "^28.13.0", "react": "^17.0.0 || ^18.0.0", diff --git a/packages/use-wallet-solid/package.json b/packages/use-wallet-solid/package.json index a2ea53ff..6f42c5b7 100644 --- a/packages/use-wallet-solid/package.json +++ b/packages/use-wallet-solid/package.json @@ -66,7 +66,7 @@ }, "devDependencies": { "@solidjs/testing-library": "0.8.10", - "algosdk": "2.9.0", + "algosdk": "3.0.0", "solid-js": "1.9.2", "tsup": "8.3.0", "tsup-preset-solid": "2.2.0", @@ -79,7 +79,7 @@ "@perawallet/connect-beta": "^2.0.21", "@walletconnect/modal": "^2.7.0", "@walletconnect/sign-client": "^2.17.1", - "algosdk": "^2.7.0", + "algosdk": "^3.0.0", "lute-connect": "^1.4.1", "magic-sdk": "^28.13.0" }, diff --git a/packages/use-wallet-vue/package.json b/packages/use-wallet-vue/package.json index d7ee6f71..9e0382cc 100644 --- a/packages/use-wallet-vue/package.json +++ b/packages/use-wallet-vue/package.json @@ -42,7 +42,7 @@ "@txnlab/use-wallet": "workspace:*" }, "devDependencies": { - "algosdk": "2.9.0", + "algosdk": "3.0.0", "tsup": "8.3.0", "typescript": "5.6.3", "vue": "3.5.12" @@ -54,7 +54,7 @@ "@perawallet/connect-beta": "^2.0.21", "@walletconnect/modal": "^2.7.0", "@walletconnect/sign-client": "^2.17.1", - "algosdk": "^2.7.0", + "algosdk": "^3.0.0", "lute-connect": "^1.4.1", "magic-sdk": "^28.13.0", "vue": "^3.0.0" diff --git a/packages/use-wallet/package.json b/packages/use-wallet/package.json index eb64a087..a4725345 100644 --- a/packages/use-wallet/package.json +++ b/packages/use-wallet/package.json @@ -52,7 +52,7 @@ "@walletconnect/modal-core": "2.7.0", "@walletconnect/sign-client": "2.17.1", "@walletconnect/types": "2.17.1", - "algosdk": "2.9.0", + "algosdk": "3.0.0", "lute-connect": "1.4.1", "magic-sdk": "28.13.0", "tsup": "8.3.0", @@ -66,7 +66,7 @@ "@perawallet/connect-beta": "^2.0.21", "@walletconnect/modal": "^2.7.0", "@walletconnect/sign-client": "^2.17.1", - "algosdk": "^2.7.0", + "algosdk": "^3.0.0", "lute-connect": "^1.4.1" }, "peerDependenciesMeta": { diff --git a/packages/use-wallet/src/__tests__/utils.test.ts b/packages/use-wallet/src/__tests__/utils.test.ts index 32462da0..d187f17a 100644 --- a/packages/use-wallet/src/__tests__/utils.test.ts +++ b/packages/use-wallet/src/__tests__/utils.test.ts @@ -49,59 +49,60 @@ describe('compareAccounts', () => { describe('isSignedTxn', () => { const transaction = new algosdk.Transaction({ - from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - fee: 10, - amount: 847, - firstRound: 51, - lastRound: 61, - genesisHash: 'JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI=', - genesisID: 'testnet-v1.0' - }) - - const encodedTxn = { - amt: transaction.amount, - fee: transaction.fee, - fv: transaction.firstRound, - lv: transaction.lastRound, - snd: Buffer.from(transaction.from.publicKey), - type: 'pay', - gen: transaction.genesisID, - gh: transaction.genesisHash, - grp: Buffer.from(new Uint8Array(0)) - } - - const encodedSignedTxn = { txn: encodedTxn, sig: Buffer.from('sig') } + type: algosdk.TransactionType.pay, + sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { + receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + amount: 847 + } + }) + + const encodedTxn = algosdk.encodeMsgpack(transaction) + const decodedRawTxn = algosdk.msgpackRawDecode(encodedTxn) + + const txnObj = { txn: decodedRawTxn, sig: Buffer.from('sig') } it('should return true if the object is a signed transaction', () => { - expect(isSignedTxn(encodedSignedTxn)).toBe(true) + expect(isSignedTxn(txnObj)).toBe(true) }) it('should return false if the object is not a signed transaction', () => { - expect(isSignedTxn(encodedTxn)).toBe(false) + expect(isSignedTxn(decodedRawTxn)).toBe(false) }) }) describe('isTransaction', () => { const transaction = new algosdk.Transaction({ - from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - fee: 10, - amount: 847, - firstRound: 51, - lastRound: 61, - genesisHash: 'JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI=', - genesisID: 'testnet-v1.0' - }) - - const uInt8Array = transaction.toByte() + type: algosdk.TransactionType.pay, + sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { + receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + amount: 847 + } + }) + + const encodedTxn = algosdk.encodeMsgpack(transaction) it('should return true if the item is a Transaction', () => { expect(isTransaction(transaction)).toBe(true) }) it('should return false if the item is a Uint8Array', () => { - expect(isTransaction(uInt8Array)).toBe(false) + expect(isTransaction(encodedTxn)).toBe(false) }) it('should return false if the item is an object that is not a Transaction', () => { @@ -113,23 +114,28 @@ describe('isTransaction', () => { }) it('should return false if the item is an array of Uint8Arrays', () => { - expect(isTransaction([uInt8Array, uInt8Array])).toBe(false) + expect(isTransaction([encodedTxn, encodedTxn])).toBe(false) }) }) describe('isTransactionArray', () => { const transaction = new algosdk.Transaction({ - from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - fee: 10, - amount: 847, - firstRound: 51, - lastRound: 61, - genesisHash: 'JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI=', - genesisID: 'testnet-v1.0' - }) - - const uInt8Array = transaction.toByte() + type: algosdk.TransactionType.pay, + sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { + receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + amount: 847 + } + }) + + const encodedTxn = algosdk.encodeMsgpack(transaction) it('should return true if the item is an array of transactions', () => { expect(isTransactionArray([transaction, transaction])).toBe(true) @@ -144,39 +150,49 @@ describe('isTransactionArray', () => { }) it('should return false if the item is a single Uint8Array', () => { - expect(isTransactionArray(uInt8Array)).toBe(false) + expect(isTransactionArray(encodedTxn)).toBe(false) }) it('should return false if the item is an array of Uint8Arrays', () => { - expect(isTransactionArray([uInt8Array, uInt8Array])).toBe(false) + expect(isTransactionArray([encodedTxn, encodedTxn])).toBe(false) }) it('should return false if the item is a nested array of Uint8Arrays', () => { - expect(isTransactionArray([[uInt8Array, uInt8Array], [uInt8Array]])).toBe(false) + expect(isTransactionArray([[encodedTxn, encodedTxn], [encodedTxn]])).toBe(false) }) }) describe('flattenTxnGroup', () => { const transaction1 = new algosdk.Transaction({ - from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - fee: 10, - amount: 847, - firstRound: 51, - lastRound: 61, - genesisHash: 'JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI=', - genesisID: 'testnet-v1.0' + type: algosdk.TransactionType.pay, + sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { + receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + amount: 847 + } }) const transaction2 = new algosdk.Transaction({ - from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - fee: 15, - amount: 500, - firstRound: 100, - lastRound: 200, - genesisHash: 'JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI=', - genesisID: 'testnet-v1.0' + type: algosdk.TransactionType.pay, + sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + suggestedParams: { + fee: 0, + firstValid: 100, + lastValid: 200, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { + receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + amount: 500 + } }) const nestedTxnGroup = [[transaction1, transaction2], [transaction1]] diff --git a/packages/use-wallet/src/__tests__/wallets/custom.test.ts b/packages/use-wallet/src/__tests__/wallets/custom.test.ts index 1dce7b6e..c8372972 100644 --- a/packages/use-wallet/src/__tests__/wallets/custom.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/custom.test.ts @@ -293,14 +293,19 @@ describe('CustomWallet', () => { describe('signTransactions', () => { const txn = new algosdk.Transaction({ - from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - amount: 1000, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + type: algosdk.TransactionType.pay, + sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { + receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + amount: 1000 + } }) const txnGroup = [txn] @@ -337,14 +342,18 @@ describe('CustomWallet', () => { describe('transactionSigner', () => { const txn = new algosdk.Transaction({ - from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', - amount: 1000, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + type: algosdk.TransactionType.pay, + sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + suggestedParams: { + fee: 10, + firstValid: 51, + lastValid: 61, + minFee: 10 + }, + paymentParams: { + receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q', + amount: 1000 + } }) const txnGroup = [txn] diff --git a/packages/use-wallet/src/__tests__/wallets/defly.test.ts b/packages/use-wallet/src/__tests__/wallets/defly.test.ts index c8f4cc64..5d9d0dd6 100644 --- a/packages/use-wallet/src/__tests__/wallets/defly.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/defly.test.ts @@ -547,22 +547,28 @@ describe('DeflyWallet', () => { // Not connected account const notConnectedAcct = 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4' - const txnParams = { - from: connectedAcct1, - to: connectedAcct2, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + const makePayTxn = ({ amount = 1000, sender = connectedAcct1, receiver = connectedAcct2 }) => { + return new algosdk.Transaction({ + type: algosdk.TransactionType.pay, + sender, + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { receiver, amount } + }) } // Transactions used in tests - const txn1 = new algosdk.Transaction({ ...txnParams, amount: 1000 }) - const txn2 = new algosdk.Transaction({ ...txnParams, amount: 2000 }) - const txn3 = new algosdk.Transaction({ ...txnParams, amount: 3000 }) - const txn4 = new algosdk.Transaction({ ...txnParams, amount: 4000 }) + const txn1 = makePayTxn({ amount: 1000 }) + const txn2 = makePayTxn({ amount: 2000 }) + const txn3 = makePayTxn({ amount: 3000 }) + const txn4 = makePayTxn({ amount: 4000 }) + // Mock signed transaction const sTxn = new Uint8Array([1, 2, 3, 4]) beforeEach(async () => { @@ -683,23 +689,9 @@ describe('DeflyWallet', () => { }) it('should only send transactions with connected signers for signature', async () => { - const canSignTxn1 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct1, - amount: 1000 - }) - - const cannotSignTxn2 = new algosdk.Transaction({ - ...txnParams, - from: notConnectedAcct, - amount: 2000 - }) - - const canSignTxn3 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct2, - amount: 3000 - }) + const canSignTxn1 = makePayTxn({ sender: connectedAcct1, amount: 1000 }) + const cannotSignTxn2 = makePayTxn({ sender: notConnectedAcct, amount: 2000 }) + const canSignTxn3 = makePayTxn({ sender: connectedAcct2, amount: 3000 }) // Signer for gtxn2 is not a connected account const [gtxn1, gtxn2, gtxn3] = algosdk.assignGroupID([ diff --git a/packages/use-wallet/src/__tests__/wallets/exodus.test.ts b/packages/use-wallet/src/__tests__/wallets/exodus.test.ts index 9cd134b6..b2c43259 100644 --- a/packages/use-wallet/src/__tests__/wallets/exodus.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/exodus.test.ts @@ -232,21 +232,26 @@ describe('ExodusWallet', () => { // Not connected account const notConnectedAcct = 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4' - const txnParams = { - from: connectedAcct1, - to: connectedAcct2, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + const makePayTxn = ({ amount = 1000, sender = connectedAcct1, receiver = connectedAcct2 }) => { + return new algosdk.Transaction({ + type: algosdk.TransactionType.pay, + sender, + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { receiver, amount } + }) } // Transactions used in tests - const txn1 = new algosdk.Transaction({ ...txnParams, amount: 1000 }) - const txn2 = new algosdk.Transaction({ ...txnParams, amount: 2000 }) - const txn3 = new algosdk.Transaction({ ...txnParams, amount: 3000 }) - const txn4 = new algosdk.Transaction({ ...txnParams, amount: 4000 }) + const txn1 = makePayTxn({ amount: 1000 }) + const txn2 = makePayTxn({ amount: 2000 }) + const txn3 = makePayTxn({ amount: 3000 }) + const txn4 = makePayTxn({ amount: 4000 }) beforeEach(async () => { // Mock two connected accounts @@ -365,23 +370,9 @@ describe('ExodusWallet', () => { }) it('should only send transactions with connected signers for signature', async () => { - const canSignTxn1 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct1, - amount: 1000 - }) - - const cannotSignTxn2 = new algosdk.Transaction({ - ...txnParams, - from: notConnectedAcct, - amount: 2000 - }) - - const canSignTxn3 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct2, - amount: 3000 - }) + const canSignTxn1 = makePayTxn({ sender: connectedAcct1, amount: 1000 }) + const cannotSignTxn2 = makePayTxn({ sender: notConnectedAcct, amount: 2000 }) + const canSignTxn3 = makePayTxn({ sender: connectedAcct2, amount: 3000 }) // Signer for gtxn2 is not a connected account const [gtxn1, gtxn2, gtxn3] = algosdk.assignGroupID([ diff --git a/packages/use-wallet/src/__tests__/wallets/kibisis.test.ts b/packages/use-wallet/src/__tests__/wallets/kibisis.test.ts index 77785ff2..4e78afb9 100644 --- a/packages/use-wallet/src/__tests__/wallets/kibisis.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/kibisis.test.ts @@ -284,21 +284,26 @@ describe('KibisisWallet', () => { }) describe('signing transactions', () => { - const txnParams = { - from: ACCOUNT_1, - to: ACCOUNT_2, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: TESTNET_GENESIS_HASH, - genesisID: 'testnet-v1.0' + const makePayTxn = ({ amount = 1000, sender = ACCOUNT_1, receiver = ACCOUNT_2 }) => { + return new algosdk.Transaction({ + type: algosdk.TransactionType.pay, + sender, + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { receiver, amount } + }) } // Transactions used in tests - const txn1 = new algosdk.Transaction({ ...txnParams, amount: 1000 }) - const txn2 = new algosdk.Transaction({ ...txnParams, amount: 2000 }) - const txn3 = new algosdk.Transaction({ ...txnParams, amount: 3000 }) - const txn4 = new algosdk.Transaction({ ...txnParams, amount: 4000 }) + const txn1 = makePayTxn({ amount: 1000 }) + const txn2 = makePayTxn({ amount: 2000 }) + const txn3 = makePayTxn({ amount: 3000 }) + const txn4 = makePayTxn({ amount: 4000 }) // Mock signed transactions (base64 strings) returned by Kibisis const mockSignedTxns = [byteArrayToBase64(txn1.toByte())] @@ -439,23 +444,12 @@ describe('KibisisWallet', () => { }) it('should only send transactions with connected signers for signature', async () => { - const canSignTxn1 = new algosdk.Transaction({ - ...txnParams, - from: ACCOUNT_1, - amount: 1000 - }) + // Not connected account + const notConnectedAcct = 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4' - const cannotSignTxn2 = new algosdk.Transaction({ - ...txnParams, - from: 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4', // EW64GC is not connected - amount: 2000 - }) - - const canSignTxn3 = new algosdk.Transaction({ - ...txnParams, - from: ACCOUNT_2, - amount: 3000 - }) + const canSignTxn1 = makePayTxn({ sender: ACCOUNT_1, amount: 1000 }) + const cannotSignTxn2 = makePayTxn({ sender: notConnectedAcct, amount: 2000 }) + const canSignTxn3 = makePayTxn({ sender: ACCOUNT_2, amount: 3000 }) // Signer for gtxn2 is not a connected account const [gtxn1, gtxn2, gtxn3] = algosdk.assignGroupID([ diff --git a/packages/use-wallet/src/__tests__/wallets/kmd.test.ts b/packages/use-wallet/src/__tests__/wallets/kmd.test.ts index 4550d27e..86e7ed7b 100644 --- a/packages/use-wallet/src/__tests__/wallets/kmd.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/kmd.test.ts @@ -213,21 +213,26 @@ describe('KmdWallet', () => { // Not connected account const notConnectedAcct = 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4' - const txnParams = { - from: connectedAcct1, - to: connectedAcct2, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + const makePayTxn = ({ amount = 1000, sender = connectedAcct1, receiver = connectedAcct2 }) => { + return new algosdk.Transaction({ + type: algosdk.TransactionType.pay, + sender, + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'testnet-v1.0' + }, + paymentParams: { receiver, amount } + }) } // Transactions used in tests - const txn1 = new algosdk.Transaction({ ...txnParams, amount: 1000 }) - const txn2 = new algosdk.Transaction({ ...txnParams, amount: 2000 }) - const txn3 = new algosdk.Transaction({ ...txnParams, amount: 3000 }) - const txn4 = new algosdk.Transaction({ ...txnParams, amount: 4000 }) + const txn1 = makePayTxn({ amount: 1000 }) + const txn2 = makePayTxn({ amount: 2000 }) + const txn3 = makePayTxn({ amount: 3000 }) + const txn4 = makePayTxn({ amount: 4000 }) beforeEach(async () => { // Mock two connected accounts @@ -361,23 +366,9 @@ describe('KmdWallet', () => { }) it('should only send transactions with connected signers for signature', async () => { - const canSignTxn1 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct1, - amount: 1000 - }) - - const cannotSignTxn2 = new algosdk.Transaction({ - ...txnParams, - from: notConnectedAcct, - amount: 2000 - }) - - const canSignTxn3 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct2, - amount: 3000 - }) + const canSignTxn1 = makePayTxn({ sender: connectedAcct1, amount: 1000 }) + const cannotSignTxn2 = makePayTxn({ sender: notConnectedAcct, amount: 2000 }) + const canSignTxn3 = makePayTxn({ sender: connectedAcct2, amount: 3000 }) // Signer for gtxn2 is not a connected account const [gtxn1, gtxn2, gtxn3] = algosdk.assignGroupID([ diff --git a/packages/use-wallet/src/__tests__/wallets/liquid.test.ts b/packages/use-wallet/src/__tests__/wallets/liquid.test.ts index ef8ce286..53db9c88 100644 --- a/packages/use-wallet/src/__tests__/wallets/liquid.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/liquid.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach, afterEach, Mock } from 'vitest' import { Store } from '@tanstack/store' -import { Transaction } from 'algosdk' +import { Transaction, TransactionType } from 'algosdk' import { logger } from 'src/logger' import { StorageAdapter } from 'src/storage' import { LOCAL_STORAGE_KEY, State, WalletState, defaultState } from 'src/store' @@ -202,10 +202,9 @@ describe('LiquidWallet', () => { const suggestedParams = { flatFee: false, fee: 0, - firstRound: 43564565, - lastRound: 43565565, + firstValid: 43564565, + lastValid: 43565565, genesisID: 'testnet-v1.0', - genesisHash: 'SGO1GKSzyE7IEPItTxCByx8FmnrCDexi9/cOUJOiI=', minFee: 1000 } @@ -213,10 +212,10 @@ describe('LiquidWallet', () => { const txnGroup = [ new Transaction({ - from: algoAddress, - to: algoAddress, - amount: 0, - suggestedParams + type: TransactionType.pay, + sender: algoAddress, + suggestedParams, + paymentParams: { receiver: algoAddress, amount: 0 } }) ] diff --git a/packages/use-wallet/src/__tests__/wallets/lute.test.ts b/packages/use-wallet/src/__tests__/wallets/lute.test.ts index 16d1d5fe..cd239ceb 100644 --- a/packages/use-wallet/src/__tests__/wallets/lute.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/lute.test.ts @@ -55,7 +55,8 @@ function createWalletWithStore(store: Store): LuteWallet { getAlgodClient: () => ({ genesis: () => ({ - do: () => Promise.resolve({ id: 'mockGenesisID', network: 'mockGenesisNetwork' }) + do: () => + Promise.resolve(JSON.stringify({ id: 'mockGenesisID', network: 'mockGenesisNetwork' })) }) }) as any, store, @@ -222,21 +223,26 @@ describe('LuteWallet', () => { // Not connected account const notConnectedAcct = 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4' - const txnParams = { - from: connectedAcct1, - to: connectedAcct2, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + const makePayTxn = ({ amount = 1000, sender = connectedAcct1, receiver = connectedAcct2 }) => { + return new algosdk.Transaction({ + type: algosdk.TransactionType.pay, + sender, + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { receiver, amount } + }) } // Transactions used in tests - const txn1 = new algosdk.Transaction({ ...txnParams, amount: 1000 }) - const txn2 = new algosdk.Transaction({ ...txnParams, amount: 2000 }) - const txn3 = new algosdk.Transaction({ ...txnParams, amount: 3000 }) - const txn4 = new algosdk.Transaction({ ...txnParams, amount: 4000 }) + const txn1 = makePayTxn({ amount: 1000 }) + const txn2 = makePayTxn({ amount: 2000 }) + const txn3 = makePayTxn({ amount: 3000 }) + const txn4 = makePayTxn({ amount: 4000 }) beforeEach(async () => { const mockConnect = vi.fn().mockResolvedValue([connectedAcct1, connectedAcct2]) @@ -363,23 +369,9 @@ describe('LuteWallet', () => { }) it('should only send transactions with connected signers for signature', async () => { - const canSignTxn1 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct1, - amount: 1000 - }) - - const cannotSignTxn2 = new algosdk.Transaction({ - ...txnParams, - from: notConnectedAcct, - amount: 2000 - }) - - const canSignTxn3 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct2, - amount: 3000 - }) + const canSignTxn1 = makePayTxn({ sender: connectedAcct1, amount: 1000 }) + const cannotSignTxn2 = makePayTxn({ sender: notConnectedAcct, amount: 2000 }) + const canSignTxn3 = makePayTxn({ sender: connectedAcct2, amount: 3000 }) // Signer for gtxn2 is not a connected account const [gtxn1, gtxn2, gtxn3] = algosdk.assignGroupID([ diff --git a/packages/use-wallet/src/__tests__/wallets/magic.test.ts b/packages/use-wallet/src/__tests__/wallets/magic.test.ts index f3c17042..330ce305 100644 --- a/packages/use-wallet/src/__tests__/wallets/magic.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/magic.test.ts @@ -304,27 +304,32 @@ describe('MagicAuth', () => { }) describe('signing transactions', () => { - // Connected accounts + // Connected account const connectedAcct = '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q' // Not connected account const notConnectedAcct = 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4' - const txnParams = { - from: connectedAcct, - to: connectedAcct, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + const makePayTxn = ({ amount = 1000, sender = connectedAcct, receiver = connectedAcct }) => { + return new algosdk.Transaction({ + type: algosdk.TransactionType.pay, + sender, + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { receiver, amount } + }) } // Transactions used in tests - const txn1 = new algosdk.Transaction({ ...txnParams, amount: 1000 }) - const txn2 = new algosdk.Transaction({ ...txnParams, amount: 2000 }) - const txn3 = new algosdk.Transaction({ ...txnParams, amount: 3000 }) - const txn4 = new algosdk.Transaction({ ...txnParams, amount: 4000 }) + const txn1 = makePayTxn({ amount: 1000 }) + const txn2 = makePayTxn({ amount: 2000 }) + const txn3 = makePayTxn({ amount: 3000 }) + const txn4 = makePayTxn({ amount: 4000 }) beforeEach(async () => { // Mock two connected accounts @@ -451,23 +456,9 @@ describe('MagicAuth', () => { }) it('should only send transactions with connected signers for signature', async () => { - const canSignTxn1 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct, - amount: 1000 - }) - - const cannotSignTxn2 = new algosdk.Transaction({ - ...txnParams, - from: notConnectedAcct, - amount: 2000 - }) - - const canSignTxn3 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct, - amount: 3000 - }) + const canSignTxn1 = makePayTxn({ sender: connectedAcct, amount: 1000 }) + const cannotSignTxn2 = makePayTxn({ sender: notConnectedAcct, amount: 2000 }) + const canSignTxn3 = makePayTxn({ sender: connectedAcct, amount: 3000 }) // Signer for gtxn2 is not a connected account const [gtxn1, gtxn2, gtxn3] = algosdk.assignGroupID([ diff --git a/packages/use-wallet/src/__tests__/wallets/mnemonic.test.ts b/packages/use-wallet/src/__tests__/wallets/mnemonic.test.ts index b53c5a30..498716ce 100644 --- a/packages/use-wallet/src/__tests__/wallets/mnemonic.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/mnemonic.test.ts @@ -240,21 +240,26 @@ describe('MnemonicWallet', () => { }) describe('signing transactions', () => { - const txnParams = { - from: TEST_ADDRESS, - to: TEST_ADDRESS, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + const makePayTxn = ({ amount = 1000, sender = TEST_ADDRESS, receiver = TEST_ADDRESS }) => { + return new algosdk.Transaction({ + type: algosdk.TransactionType.pay, + sender, + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'testnet-v1.0' + }, + paymentParams: { receiver, amount } + }) } // Transactions used in tests - const txn1 = new algosdk.Transaction({ ...txnParams, amount: 1000 }) - const txn2 = new algosdk.Transaction({ ...txnParams, amount: 2000 }) - const txn3 = new algosdk.Transaction({ ...txnParams, amount: 3000 }) - const txn4 = new algosdk.Transaction({ ...txnParams, amount: 4000 }) + const txn1 = makePayTxn({ amount: 1000 }) + const txn2 = makePayTxn({ amount: 2000 }) + const txn3 = makePayTxn({ amount: 3000 }) + const txn4 = makePayTxn({ amount: 4000 }) beforeEach(async () => { await wallet.connect() diff --git a/packages/use-wallet/src/__tests__/wallets/pera.test.ts b/packages/use-wallet/src/__tests__/wallets/pera.test.ts index d5b290aa..2d1d1cd6 100644 --- a/packages/use-wallet/src/__tests__/wallets/pera.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/pera.test.ts @@ -547,21 +547,26 @@ describe('PeraWallet', () => { // Not connected account const notConnectedAcct = 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4' - const txnParams = { - from: connectedAcct1, - to: connectedAcct2, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + const makePayTxn = ({ amount = 1000, sender = connectedAcct1, receiver = connectedAcct2 }) => { + return new algosdk.Transaction({ + type: algosdk.TransactionType.pay, + sender, + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { receiver, amount } + }) } // Transactions used in tests - const txn1 = new algosdk.Transaction({ ...txnParams, amount: 1000 }) - const txn2 = new algosdk.Transaction({ ...txnParams, amount: 2000 }) - const txn3 = new algosdk.Transaction({ ...txnParams, amount: 3000 }) - const txn4 = new algosdk.Transaction({ ...txnParams, amount: 4000 }) + const txn1 = makePayTxn({ amount: 1000 }) + const txn2 = makePayTxn({ amount: 2000 }) + const txn3 = makePayTxn({ amount: 3000 }) + const txn4 = makePayTxn({ amount: 4000 }) const sTxn = new Uint8Array([1, 2, 3, 4]) @@ -683,23 +688,9 @@ describe('PeraWallet', () => { }) it('should only send transactions with connected signers for signature', async () => { - const canSignTxn1 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct1, - amount: 1000 - }) - - const cannotSignTxn2 = new algosdk.Transaction({ - ...txnParams, - from: notConnectedAcct, - amount: 2000 - }) - - const canSignTxn3 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct2, - amount: 3000 - }) + const canSignTxn1 = makePayTxn({ sender: connectedAcct1, amount: 1000 }) + const cannotSignTxn2 = makePayTxn({ sender: notConnectedAcct, amount: 2000 }) + const canSignTxn3 = makePayTxn({ sender: connectedAcct2, amount: 3000 }) // Signer for gtxn2 is not a connected account const [gtxn1, gtxn2, gtxn3] = algosdk.assignGroupID([ diff --git a/packages/use-wallet/src/__tests__/wallets/pera2.test.ts b/packages/use-wallet/src/__tests__/wallets/pera2.test.ts index 171760cf..e92a9265 100644 --- a/packages/use-wallet/src/__tests__/wallets/pera2.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/pera2.test.ts @@ -340,21 +340,26 @@ describe('PeraWallet', () => { // Not connected account const notConnectedAcct = 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4' - const txnParams = { - from: connectedAcct1, - to: connectedAcct2, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + const makePayTxn = ({ amount = 1000, sender = connectedAcct1, receiver = connectedAcct2 }) => { + return new algosdk.Transaction({ + type: algosdk.TransactionType.pay, + sender, + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { receiver, amount } + }) } // Transactions used in tests - const txn1 = new algosdk.Transaction({ ...txnParams, amount: 1000 }) - const txn2 = new algosdk.Transaction({ ...txnParams, amount: 2000 }) - const txn3 = new algosdk.Transaction({ ...txnParams, amount: 3000 }) - const txn4 = new algosdk.Transaction({ ...txnParams, amount: 4000 }) + const txn1 = makePayTxn({ amount: 1000 }) + const txn2 = makePayTxn({ amount: 2000 }) + const txn3 = makePayTxn({ amount: 3000 }) + const txn4 = makePayTxn({ amount: 4000 }) const sTxn = new Uint8Array([1, 2, 3, 4]) @@ -476,23 +481,9 @@ describe('PeraWallet', () => { }) it('should only send transactions with connected signers for signature', async () => { - const canSignTxn1 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct1, - amount: 1000 - }) - - const cannotSignTxn2 = new algosdk.Transaction({ - ...txnParams, - from: notConnectedAcct, - amount: 2000 - }) - - const canSignTxn3 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct2, - amount: 3000 - }) + const canSignTxn1 = makePayTxn({ sender: connectedAcct1, amount: 1000 }) + const cannotSignTxn2 = makePayTxn({ sender: notConnectedAcct, amount: 2000 }) + const canSignTxn3 = makePayTxn({ sender: connectedAcct2, amount: 3000 }) // Signer for gtxn2 is not a connected account const [gtxn1, gtxn2, gtxn3] = algosdk.assignGroupID([ diff --git a/packages/use-wallet/src/__tests__/wallets/walletconnect.test.ts b/packages/use-wallet/src/__tests__/wallets/walletconnect.test.ts index 5a4e5e6e..2ce7225c 100644 --- a/packages/use-wallet/src/__tests__/wallets/walletconnect.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/walletconnect.test.ts @@ -356,21 +356,26 @@ describe('WalletConnect', () => { // Not connected account const notConnectedAcct = 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4' - const txnParams = { - from: connectedAcct1, - to: connectedAcct2, - fee: 10, - firstRound: 51, - lastRound: 61, - genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - genesisID: 'mainnet-v1.0' + const makePayTxn = ({ amount = 1000, sender = connectedAcct1, receiver = connectedAcct2 }) => { + return new algosdk.Transaction({ + type: algosdk.TransactionType.pay, + sender, + suggestedParams: { + fee: 0, + firstValid: 51, + lastValid: 61, + minFee: 1000, + genesisID: 'mainnet-v1.0' + }, + paymentParams: { receiver, amount } + }) } // Transactions used in tests - const txn1 = new algosdk.Transaction({ ...txnParams, amount: 1000 }) - const txn2 = new algosdk.Transaction({ ...txnParams, amount: 2000 }) - const txn3 = new algosdk.Transaction({ ...txnParams, amount: 3000 }) - const txn4 = new algosdk.Transaction({ ...txnParams, amount: 4000 }) + const txn1 = makePayTxn({ amount: 1000 }) + const txn2 = makePayTxn({ amount: 2000 }) + const txn3 = makePayTxn({ amount: 3000 }) + const txn4 = makePayTxn({ amount: 4000 }) const expectedRpcRequest = (params: WalletTransaction[][]) => { return { @@ -525,23 +530,9 @@ describe('WalletConnect', () => { }) it('should only send transactions with connected signers for signature', async () => { - const canSignTxn1 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct1, - amount: 1000 - }) - - const cannotSignTxn2 = new algosdk.Transaction({ - ...txnParams, - from: notConnectedAcct, - amount: 2000 - }) - - const canSignTxn3 = new algosdk.Transaction({ - ...txnParams, - from: connectedAcct2, - amount: 3000 - }) + const canSignTxn1 = makePayTxn({ sender: connectedAcct1, amount: 1000 }) + const cannotSignTxn2 = makePayTxn({ sender: notConnectedAcct, amount: 2000 }) + const canSignTxn3 = makePayTxn({ sender: connectedAcct2, amount: 3000 }) // Signer for gtxn2 is not a connected account const [gtxn1, gtxn2, gtxn3] = algosdk.assignGroupID([ @@ -599,7 +590,7 @@ describe('WalletConnect', () => { }) await wallet.connect() - const txn = new algosdk.Transaction(txnParams) + const txn = makePayTxn({ amount: 1000 }) await wallet.signTransactions([txn]) expect(mockSignClient.request).toHaveBeenCalledWith( diff --git a/packages/use-wallet/src/utils.ts b/packages/use-wallet/src/utils.ts index 7b62b664..3bb494d3 100644 --- a/packages/use-wallet/src/utils.ts +++ b/packages/use-wallet/src/utils.ts @@ -74,15 +74,29 @@ export function byteArrayToString(array: Uint8Array): string { return result } -export function isSignedTxn( - txnDecodeObj: algosdk.EncodedTransaction | algosdk.EncodedSignedTransaction -): txnDecodeObj is algosdk.EncodedSignedTransaction { - return (txnDecodeObj as algosdk.EncodedSignedTransaction).txn !== undefined +export function isSignedTxn(txnObj: any): boolean { + if (!txnObj || typeof txnObj !== 'object') return false + if (!('sig' in txnObj && 'txn' in txnObj)) return false + + // Verify sig is a Uint8Array + if (!(txnObj.sig instanceof Uint8Array)) return false + + // Verify txn is an object + const txn = txnObj.txn + if (!txn || typeof txn !== 'object') return false + + // Check for common transaction properties + const hasRequiredProps = 'type' in txn && 'snd' in txn + + return hasRequiredProps } export function isTransaction(item: any): item is algosdk.Transaction { return ( - item && typeof item === 'object' && 'genesisID' in item && typeof item.genesisID === 'string' + item && + typeof item === 'object' && + 'sender' in item && + (item.sender instanceof algosdk.Address || typeof item.sender === 'string') ) } diff --git a/packages/use-wallet/src/wallets/defly.ts b/packages/use-wallet/src/wallets/defly.ts index 2128284f..67043294 100644 --- a/packages/use-wallet/src/wallets/defly.ts +++ b/packages/use-wallet/src/wallets/defly.ts @@ -180,7 +180,7 @@ export class DeflyWallet extends BaseWallet { txnGroup.forEach((txn, index) => { const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = this.addresses.includes(signer) if (isIndexMatch && canSignTxn) { @@ -200,18 +200,15 @@ export class DeflyWallet extends BaseWallet { const txnsToSign: SignerTransaction[] = [] txnGroup.forEach((txnBuffer, index) => { - const txnDecodeObj = algosdk.decodeObj(txnBuffer) as - | algosdk.EncodedTransaction - | algosdk.EncodedSignedTransaction - - const isSigned = isSignedTxn(txnDecodeObj) + const decodedObj = algosdk.msgpackRawDecode(txnBuffer) + const isSigned = isSignedTxn(decodedObj) const txn: algosdk.Transaction = isSigned ? algosdk.decodeSignedTransaction(txnBuffer).txn : algosdk.decodeUnsignedTransaction(txnBuffer) const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = !isSigned && this.addresses.includes(signer) if (isIndexMatch && canSignTxn) { diff --git a/packages/use-wallet/src/wallets/exodus.ts b/packages/use-wallet/src/wallets/exodus.ts index 250e07cc..8f9918c1 100644 --- a/packages/use-wallet/src/wallets/exodus.ts +++ b/packages/use-wallet/src/wallets/exodus.ts @@ -185,7 +185,7 @@ export class ExodusWallet extends BaseWallet { txnGroup.forEach((txn, index) => { const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = this.addresses.includes(signer) const txnString = byteArrayToBase64(txn.toByte()) @@ -207,18 +207,15 @@ export class ExodusWallet extends BaseWallet { const txnsToSign: WalletTransaction[] = [] txnGroup.forEach((txnBuffer, index) => { - const txnDecodeObj = algosdk.decodeObj(txnBuffer) as - | algosdk.EncodedTransaction - | algosdk.EncodedSignedTransaction - - const isSigned = isSignedTxn(txnDecodeObj) + const decodedObj = algosdk.msgpackRawDecode(txnBuffer) + const isSigned = isSignedTxn(decodedObj) const txn: algosdk.Transaction = isSigned ? algosdk.decodeSignedTransaction(txnBuffer).txn : algosdk.decodeUnsignedTransaction(txnBuffer) const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = !isSigned && this.addresses.includes(signer) const txnString = byteArrayToBase64(txn.toByte()) diff --git a/packages/use-wallet/src/wallets/kibisis.ts b/packages/use-wallet/src/wallets/kibisis.ts index f5a4cc71..3b799597 100644 --- a/packages/use-wallet/src/wallets/kibisis.ts +++ b/packages/use-wallet/src/wallets/kibisis.ts @@ -186,7 +186,7 @@ export class KibisisWallet extends BaseWallet { const algodClient = this.getAlgodClient() const version = await algodClient.versionsCheck().do() - return version.genesis_hash_b64 + return algosdk.bytesToBase64(version.genesisHashB64) } private async _initializeAVMWebClient(): Promise { @@ -409,7 +409,7 @@ export class KibisisWallet extends BaseWallet { txnGroup.forEach((txn, index) => { const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = this.addresses.includes(signer) const txnString = byteArrayToBase64(txn.toByte()) @@ -431,18 +431,15 @@ export class KibisisWallet extends BaseWallet { const txnsToSign: AVMWebProviderSDK.IARC0001Transaction[] = [] txnGroup.forEach((txnBuffer, index) => { - const txnDecodeObj = algosdk.decodeObj(txnBuffer) as - | algosdk.EncodedTransaction - | algosdk.EncodedSignedTransaction - - const isSigned = isSignedTxn(txnDecodeObj) + const decodedObj = algosdk.msgpackRawDecode(txnBuffer) + const isSigned = isSignedTxn(decodedObj) const txn: algosdk.Transaction = isSigned ? algosdk.decodeSignedTransaction(txnBuffer).txn : algosdk.decodeUnsignedTransaction(txnBuffer) const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = !isSigned && this.addresses.includes(signer) const txnString = byteArrayToBase64(txn.toByte()) diff --git a/packages/use-wallet/src/wallets/kmd.ts b/packages/use-wallet/src/wallets/kmd.ts index 6db0b4d3..92710086 100644 --- a/packages/use-wallet/src/wallets/kmd.ts +++ b/packages/use-wallet/src/wallets/kmd.ts @@ -179,7 +179,7 @@ export class KmdWallet extends BaseWallet { txnGroup.forEach((txn, index) => { const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = this.addresses.includes(signer) if (isIndexMatch && canSignTxn) { @@ -197,18 +197,15 @@ export class KmdWallet extends BaseWallet { const txnsToSign: algosdk.Transaction[] = [] txnGroup.forEach((txnBuffer, index) => { - const txnDecodeObj = algosdk.decodeObj(txnBuffer) as - | algosdk.EncodedTransaction - | algosdk.EncodedSignedTransaction - - const isSigned = isSignedTxn(txnDecodeObj) + const decodedObj = algosdk.msgpackRawDecode(txnBuffer) + const isSigned = isSignedTxn(decodedObj) const txn: algosdk.Transaction = isSigned ? algosdk.decodeSignedTransaction(txnBuffer).txn : algosdk.decodeUnsignedTransaction(txnBuffer) const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = !isSigned && this.addresses.includes(signer) if (isIndexMatch && canSignTxn) { diff --git a/packages/use-wallet/src/wallets/liquid.ts b/packages/use-wallet/src/wallets/liquid.ts index 72da210a..f247f059 100644 --- a/packages/use-wallet/src/wallets/liquid.ts +++ b/packages/use-wallet/src/wallets/liquid.ts @@ -139,6 +139,7 @@ export class LiquidWallet extends BaseWallet { this.logger.debug('Signing transactions...', { txnGroup, indexesToSign }) const authClient = this.authClient || (await this.initializeClient()) + // @ts-expect-error - TODO: update liquid-auth-use-wallet-client to use algosdk v3 return authClient.signTransactions(txnGroup, this.activeAddress, indexesToSign) } catch (error) { this.logger.error('Error signing transactions', error) diff --git a/packages/use-wallet/src/wallets/lute.ts b/packages/use-wallet/src/wallets/lute.ts index 7bf51a6e..5e20d1a9 100644 --- a/packages/use-wallet/src/wallets/lute.ts +++ b/packages/use-wallet/src/wallets/lute.ts @@ -67,7 +67,10 @@ export class LuteWallet extends BaseWallet { private async getGenesisId(): Promise { const algodClient = this.getAlgodClient() - const genesis = await algodClient.genesis().do() + const genesisStr = await algodClient.genesis().do() + const genesis = algosdk.parseJSON(genesisStr, { + intDecoding: algosdk.IntDecoding.MIXED + }) const genesisId = `${genesis.network}-${genesis.id}` return genesisId @@ -139,7 +142,7 @@ export class LuteWallet extends BaseWallet { txnGroup.forEach((txn, index) => { const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = this.addresses.includes(signer) const txnString = byteArrayToBase64(txn.toByte()) @@ -161,18 +164,15 @@ export class LuteWallet extends BaseWallet { const txnsToSign: WalletTransaction[] = [] txnGroup.forEach((txnBuffer, index) => { - const txnDecodeObj = algosdk.decodeObj(txnBuffer) as - | algosdk.EncodedTransaction - | algosdk.EncodedSignedTransaction - - const isSigned = isSignedTxn(txnDecodeObj) + const decodedObj = algosdk.msgpackRawDecode(txnBuffer) + const isSigned = isSignedTxn(decodedObj) const txn: algosdk.Transaction = isSigned ? algosdk.decodeSignedTransaction(txnBuffer).txn : algosdk.decodeUnsignedTransaction(txnBuffer) const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = !isSigned && this.addresses.includes(signer) const txnString = byteArrayToBase64(txn.toByte()) diff --git a/packages/use-wallet/src/wallets/magic.ts b/packages/use-wallet/src/wallets/magic.ts index 71d78c7b..dd13af37 100644 --- a/packages/use-wallet/src/wallets/magic.ts +++ b/packages/use-wallet/src/wallets/magic.ts @@ -218,7 +218,7 @@ export class MagicAuth extends BaseWallet { txnGroup.forEach((txn, index) => { const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = this.addresses.includes(signer) const txnString = byteArrayToBase64(txn.toByte()) @@ -240,18 +240,15 @@ export class MagicAuth extends BaseWallet { const txnsToSign: WalletTransaction[] = [] txnGroup.forEach((txnBuffer, index) => { - const txnDecodeObj = algosdk.decodeObj(txnBuffer) as - | algosdk.EncodedTransaction - | algosdk.EncodedSignedTransaction - - const isSigned = isSignedTxn(txnDecodeObj) + const decodedObj = algosdk.msgpackRawDecode(txnBuffer) + const isSigned = isSignedTxn(decodedObj) const txn: algosdk.Transaction = isSigned ? algosdk.decodeSignedTransaction(txnBuffer).txn : algosdk.decodeUnsignedTransaction(txnBuffer) const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = !isSigned && this.addresses.includes(signer) const txnString = byteArrayToBase64(txn.toByte()) diff --git a/packages/use-wallet/src/wallets/mnemonic.ts b/packages/use-wallet/src/wallets/mnemonic.ts index a729d1cf..4dda608b 100644 --- a/packages/use-wallet/src/wallets/mnemonic.ts +++ b/packages/use-wallet/src/wallets/mnemonic.ts @@ -110,7 +110,7 @@ export class MnemonicWallet extends BaseWallet { const walletAccount = { name: `${this.metadata.name} Account`, - address: account.addr + address: account.addr.toString() } const walletState: WalletState = { @@ -175,8 +175,8 @@ export class MnemonicWallet extends BaseWallet { txnGroup.forEach((txn, index) => { const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) - const canSignTxn = signer === this.account!.addr + const signer = txn.sender.toString() + const canSignTxn = signer === this.account!.addr.toString() if (isIndexMatch && canSignTxn) { txnsToSign.push(txn) @@ -193,19 +193,16 @@ export class MnemonicWallet extends BaseWallet { const txnsToSign: algosdk.Transaction[] = [] txnGroup.forEach((txnBuffer, index) => { - const txnDecodeObj = algosdk.decodeObj(txnBuffer) as - | algosdk.EncodedTransaction - | algosdk.EncodedSignedTransaction - - const isSigned = isSignedTxn(txnDecodeObj) + const decodedObj = algosdk.msgpackRawDecode(txnBuffer) + const isSigned = isSignedTxn(decodedObj) const txn: algosdk.Transaction = isSigned ? algosdk.decodeSignedTransaction(txnBuffer).txn : algosdk.decodeUnsignedTransaction(txnBuffer) const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) - const canSignTxn = !isSigned && signer === this.account!.addr + const signer = txn.sender.toString() + const canSignTxn = !isSigned && signer === this.account!.addr.toString() if (isIndexMatch && canSignTxn) { txnsToSign.push(txn) diff --git a/packages/use-wallet/src/wallets/pera.ts b/packages/use-wallet/src/wallets/pera.ts index 8a35bac6..fdeb7637 100644 --- a/packages/use-wallet/src/wallets/pera.ts +++ b/packages/use-wallet/src/wallets/pera.ts @@ -185,7 +185,7 @@ export class PeraWallet extends BaseWallet { txnGroup.forEach((txn, index) => { const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = this.addresses.includes(signer) if (isIndexMatch && canSignTxn) { @@ -205,18 +205,15 @@ export class PeraWallet extends BaseWallet { const txnsToSign: SignerTransaction[] = [] txnGroup.forEach((txnBuffer, index) => { - const txnDecodeObj = algosdk.decodeObj(txnBuffer) as - | algosdk.EncodedTransaction - | algosdk.EncodedSignedTransaction - - const isSigned = isSignedTxn(txnDecodeObj) + const decodedObj = algosdk.msgpackRawDecode(txnBuffer) + const isSigned = isSignedTxn(decodedObj) const txn: algosdk.Transaction = isSigned ? algosdk.decodeSignedTransaction(txnBuffer).txn : algosdk.decodeUnsignedTransaction(txnBuffer) const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = !isSigned && this.addresses.includes(signer) if (isIndexMatch && canSignTxn) { diff --git a/packages/use-wallet/src/wallets/pera2.ts b/packages/use-wallet/src/wallets/pera2.ts index 7e061710..bad03fa0 100644 --- a/packages/use-wallet/src/wallets/pera2.ts +++ b/packages/use-wallet/src/wallets/pera2.ts @@ -167,7 +167,7 @@ export class PeraWallet extends BaseWallet { txnGroup.forEach((txn, index) => { const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = this.addresses.includes(signer) if (isIndexMatch && canSignTxn) { @@ -187,18 +187,15 @@ export class PeraWallet extends BaseWallet { const txnsToSign: SignerTransaction[] = [] txnGroup.forEach((txnBuffer, index) => { - const txnDecodeObj = algosdk.decodeObj(txnBuffer) as - | algosdk.EncodedTransaction - | algosdk.EncodedSignedTransaction - - const isSigned = isSignedTxn(txnDecodeObj) + const decodedObj = algosdk.msgpackRawDecode(txnBuffer) + const isSigned = isSignedTxn(decodedObj) const txn: algosdk.Transaction = isSigned ? algosdk.decodeSignedTransaction(txnBuffer).txn : algosdk.decodeUnsignedTransaction(txnBuffer) const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = !isSigned && this.addresses.includes(signer) if (isIndexMatch && canSignTxn) { diff --git a/packages/use-wallet/src/wallets/walletconnect.ts b/packages/use-wallet/src/wallets/walletconnect.ts index 39165a41..4424ecc9 100644 --- a/packages/use-wallet/src/wallets/walletconnect.ts +++ b/packages/use-wallet/src/wallets/walletconnect.ts @@ -454,7 +454,7 @@ export class WalletConnect extends BaseWallet { txnGroup.forEach((txn, index) => { const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = this.addresses.includes(signer) const txnString = byteArrayToBase64(txn.toByte()) @@ -476,18 +476,15 @@ export class WalletConnect extends BaseWallet { const txnsToSign: WalletTransaction[] = [] txnGroup.forEach((txnBuffer, index) => { - const txnDecodeObj = algosdk.decodeObj(txnBuffer) as - | algosdk.EncodedTransaction - | algosdk.EncodedSignedTransaction - - const isSigned = isSignedTxn(txnDecodeObj) + const decodedObj = algosdk.msgpackRawDecode(txnBuffer) + const isSigned = isSignedTxn(decodedObj) const txn: algosdk.Transaction = isSigned ? algosdk.decodeSignedTransaction(txnBuffer).txn : algosdk.decodeUnsignedTransaction(txnBuffer) const isIndexMatch = !indexesToSign || indexesToSign.includes(index) - const signer = algosdk.encodeAddress(txn.from.publicKey) + const signer = txn.sender.toString() const canSignTxn = !isSigned && this.addresses.includes(signer) const txnString = byteArrayToBase64(txn.toByte()) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 25dabf8c..fbd8142d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -61,10 +61,10 @@ importers: dependencies: '@blockshake/defly-connect': specifier: ^1.1.6 - version: 1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@perawallet/connect': specifier: ^1.3.5 - version: 1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@txnlab/use-wallet-react': specifier: workspace:* version: link:../../packages/use-wallet-react @@ -75,8 +75,8 @@ importers: specifier: ^2.17.1 version: 2.17.1(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) algosdk: - specifier: 2.9.0 - version: 2.9.0 + specifier: 3.0.0 + version: 3.0.0 lute-connect: specifier: ^1.4.1 version: 1.4.1 @@ -116,10 +116,10 @@ importers: version: 1.1.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@blockshake/defly-connect': specifier: ^1.1.6 - version: 1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@perawallet/connect': specifier: ^1.3.5 - version: 1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@txnlab/use-wallet': specifier: workspace:* version: link:../../packages/use-wallet @@ -133,8 +133,8 @@ importers: specifier: ^2.17.1 version: 2.17.1(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) algosdk: - specifier: 2.9.0 - version: 2.9.0 + specifier: 3.0.0 + version: 3.0.0 lute-connect: specifier: ^1.4.1 version: 1.4.1 @@ -162,10 +162,10 @@ importers: version: 1.1.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@blockshake/defly-connect': specifier: ^1.1.6 - version: 1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@perawallet/connect': specifier: ^1.3.5 - version: 1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@txnlab/use-wallet-react': specifier: workspace:* version: link:../../packages/use-wallet-react @@ -176,8 +176,8 @@ importers: specifier: ^2.17.1 version: 2.17.1(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) algosdk: - specifier: 2.9.0 - version: 2.9.0 + specifier: 3.0.0 + version: 3.0.0 lute-connect: specifier: ^1.4.1 version: 1.4.1 @@ -226,10 +226,10 @@ importers: version: 1.1.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@blockshake/defly-connect': specifier: ^1.1.6 - version: 1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@perawallet/connect': specifier: ^1.3.5 - version: 1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@txnlab/use-wallet-solid': specifier: workspace:* version: link:../../packages/use-wallet-solid @@ -240,8 +240,8 @@ importers: specifier: ^2.17.1 version: 2.17.1(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) algosdk: - specifier: 2.9.0 - version: 2.9.0 + specifier: 3.0.0 + version: 3.0.0 lute-connect: specifier: ^1.4.1 version: 1.4.1 @@ -266,10 +266,10 @@ importers: version: 1.1.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@blockshake/defly-connect': specifier: ^1.1.6 - version: 1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@perawallet/connect': specifier: ^1.3.5 - version: 1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@txnlab/use-wallet': specifier: workspace:* version: link:../../packages/use-wallet @@ -280,8 +280,8 @@ importers: specifier: ^2.17.1 version: 2.17.1(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) algosdk: - specifier: 2.9.0 - version: 2.9.0 + specifier: 3.0.0 + version: 3.0.0 lute-connect: specifier: ^1.4.1 version: 1.4.1 @@ -303,10 +303,10 @@ importers: version: 1.1.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@blockshake/defly-connect': specifier: ^1.1.6 - version: 1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@perawallet/connect': specifier: ^1.3.5 - version: 1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@txnlab/use-wallet-vue': specifier: workspace:* version: link:../../packages/use-wallet-vue @@ -317,8 +317,8 @@ importers: specifier: ^2.17.1 version: 2.17.1(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) algosdk: - specifier: 2.9.0 - version: 2.9.0 + specifier: 3.0.0 + version: 3.0.0 lute-connect: specifier: ^1.4.1 version: 1.4.1 @@ -353,7 +353,7 @@ importers: version: 1.1.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@blockshake/defly-connect': specifier: 1.1.6 - version: 1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@magic-ext/algorand': specifier: 23.13.0 version: 23.13.0 @@ -362,10 +362,10 @@ importers: version: 28.13.0(localforage@1.10.0) '@perawallet/connect': specifier: 1.3.5 - version: 1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@perawallet/connect-beta': specifier: 2.0.21 - version: 2.0.21(algosdk@2.9.0)(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) + version: 2.0.21(algosdk@3.0.0)(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) '@types/node': specifier: 20.11.30 version: 20.11.30 @@ -382,8 +382,8 @@ importers: specifier: 2.17.1 version: 2.17.1(ioredis@5.4.1) algosdk: - specifier: 2.9.0 - version: 2.9.0 + specifier: 3.0.0 + version: 3.0.0 lute-connect: specifier: 1.4.1 version: 1.4.1 @@ -401,16 +401,16 @@ importers: dependencies: '@blockshake/defly-connect': specifier: ^1.1.6 - version: 1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@magic-ext/algorand': specifier: ^23.13.0 version: 23.13.0 '@perawallet/connect': specifier: ^1.3.5 - version: 1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@perawallet/connect-beta': specifier: ^2.0.21 - version: 2.0.21(algosdk@2.9.0)(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) + version: 2.0.21(algosdk@3.0.0)(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) '@tanstack/react-store': specifier: 0.5.5 version: 0.5.5(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -434,8 +434,8 @@ importers: specifier: 18.3.11 version: 18.3.11 algosdk: - specifier: 2.9.0 - version: 2.9.0 + specifier: 3.0.0 + version: 3.0.0 jsdom: specifier: 25.0.1 version: 25.0.1(bufferutil@4.0.8)(canvas@2.11.2)(utf-8-validate@5.0.10) @@ -456,16 +456,16 @@ importers: dependencies: '@blockshake/defly-connect': specifier: ^1.1.6 - version: 1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@magic-ext/algorand': specifier: ^23.13.0 version: 23.13.0 '@perawallet/connect': specifier: ^1.3.5 - version: 1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@perawallet/connect-beta': specifier: ^2.0.21 - version: 2.0.21(algosdk@2.9.0)(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) + version: 2.0.21(algosdk@3.0.0)(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) '@tanstack/solid-store': specifier: 0.5.5 version: 0.5.5(solid-js@1.9.2) @@ -489,8 +489,8 @@ importers: specifier: 0.8.10 version: 0.8.10(solid-js@1.9.2) algosdk: - specifier: 2.9.0 - version: 2.9.0 + specifier: 3.0.0 + version: 3.0.0 solid-js: specifier: 1.9.2 version: 1.9.2 @@ -508,16 +508,16 @@ importers: dependencies: '@blockshake/defly-connect': specifier: ^1.1.6 - version: 1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@magic-ext/algorand': specifier: ^23.13.0 version: 23.13.0 '@perawallet/connect': specifier: ^1.3.5 - version: 1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@perawallet/connect-beta': specifier: ^2.0.21 - version: 2.0.21(algosdk@2.9.0)(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) + version: 2.0.21(algosdk@3.0.0)(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) '@tanstack/vue-store': specifier: 0.5.5 version: 0.5.5(vue@3.5.12(typescript@5.6.3)) @@ -538,8 +538,8 @@ importers: version: 28.13.0 devDependencies: algosdk: - specifier: 2.9.0 - version: 2.9.0 + specifier: 3.0.0 + version: 3.0.0 tsup: specifier: 8.3.0 version: 8.3.0(jiti@2.3.3)(postcss@8.4.47)(typescript@5.6.3)(yaml@2.6.0) @@ -2394,10 +2394,18 @@ packages: resolution: {integrity: sha512-F1tGh056XczEaEAqu7s+hlZUDWwOBT70Eq0lfMpBP2YguSQVyxRbprLq5rELXKQOyOaixTWYhMeMQMzP0U5FoQ==} engines: {node: '>= 10'} + algorand-msgpack@1.1.0: + resolution: {integrity: sha512-08k7pBQnkaUB5p+jL7f1TRaUIlTSDE0cesFu1mD7llLao+1cAhtvvZmGE3OnisTd0xOn118QMw74SRqddqaYvw==} + engines: {node: '>= 14'} + algosdk@2.9.0: resolution: {integrity: sha512-o0n0nLMbTX6SFQdMUk2/2sy50jmEmZk5OTPYSh2aAeP8DUPxrhjMPfwGsYNvaO+qk75MixC2eWpfA9vygCQ/Mg==} engines: {node: '>=18.0.0'} + algosdk@3.0.0: + resolution: {integrity: sha512-PIKZ/YvbBpCudduug4KSH1CY/pTotI7/ccbUIbXKtcI9Onevl+57E+K5X4ow4gsCdysZ8zVvSLdxuCcXvsmPOw==} + engines: {node: '>=18.0.0'} + ansi-colors@4.1.3: resolution: {integrity: sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==} engines: {node: '>=6'} @@ -6780,11 +6788,11 @@ snapshots: '@babel/helper-validator-identifier': 7.25.7 to-fast-properties: 2.0.0 - '@blockshake/defly-connect@1.1.6(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10)': + '@blockshake/defly-connect@1.1.6(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: '@walletconnect/client': 1.8.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@walletconnect/types': 1.8.0 - algosdk: 2.9.0 + algosdk: 3.0.0 bowser: 2.11.0 buffer: 6.0.3 lottie-web: 5.12.2 @@ -7650,14 +7658,14 @@ snapshots: '@pedrouid/environment@1.0.1': {} - '@perawallet/connect-beta@2.0.21(algosdk@2.9.0)(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10)': + '@perawallet/connect-beta@2.0.21(algosdk@3.0.0)(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10)': dependencies: '@evanhahn/lottie-web-light': 5.8.1 '@json-rpc-tools/utils': 1.7.6 '@walletconnect/sign-client': 2.17.0(bufferutil@4.0.8)(ioredis@5.4.1)(utf-8-validate@5.0.10) '@walletconnect/types': 2.17.0(ioredis@5.4.1) '@walletconnect/utils': 2.17.0(ioredis@5.4.1) - algosdk: 2.9.0 + algosdk: 3.0.0 bowser: 2.11.0 buffer: 6.0.3 qr-code-styling: 1.6.0-rc.1 @@ -7679,12 +7687,12 @@ snapshots: - uWebSockets.js - utf-8-validate - '@perawallet/connect@1.3.5(algosdk@2.9.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10)': + '@perawallet/connect@1.3.5(algosdk@3.0.0)(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: '@evanhahn/lottie-web-light': 5.8.1 '@walletconnect/client': 1.8.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@walletconnect/types': 1.8.0 - algosdk: 2.9.0 + algosdk: 3.0.0 bowser: 2.11.0 buffer: 6.0.3 qr-code-styling: 1.6.0-rc.1 @@ -8892,6 +8900,8 @@ snapshots: algo-msgpack-with-bigint@2.1.1: {} + algorand-msgpack@1.1.0: {} + algosdk@2.9.0: dependencies: algo-msgpack-with-bigint: 2.1.1 @@ -8904,6 +8914,17 @@ snapshots: tweetnacl: 1.0.3 vlq: 2.0.4 + algosdk@3.0.0: + dependencies: + algorand-msgpack: 1.1.0 + hi-base32: 0.5.1 + js-sha256: 0.9.0 + js-sha3: 0.8.0 + js-sha512: 0.8.0 + json-bigint: 1.0.0 + tweetnacl: 1.0.3 + vlq: 2.0.4 + ansi-colors@4.1.3: {} ansi-escapes@4.3.2: