diff --git a/README.md b/README.md index 4206d4f..9db9cb7 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ npm install @txnlab/use-wallet-js Install peer dependencies: ```bash -npm install @blockshake/defly-connect @perawallet/connect @randlabs/myalgo-connect @walletconnect/modal @walletconnect/sign-client @walletconnect/types algosdk +npm install @blockshake/defly-connect @perawallet/connect @walletconnect/modal @walletconnect/sign-client @walletconnect/types algosdk ``` ## Configuration @@ -69,7 +69,6 @@ const walletManager = new WalletManager({ wallets: [ WalletId.DEFLY, WalletId.EXODUS, - WalletId.MYALGO, WalletId.PERA, { id: WalletId.WALLETCONNECT, @@ -303,7 +302,6 @@ const walletManager = new WalletManager({ wallets: [ WalletId.DEFLY, WalletId.EXODUS, - WalletId.MYALGO, WalletId.PERA, { id: WalletId.WALLETCONNECT, diff --git a/bun.lockb b/bun.lockb index c74294a..e2b1241 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 3a913ad..dbf909c 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "pera", "defly", "exodus", - "myalgo", "algosdk", "kmd" ], @@ -39,7 +38,6 @@ "peerDependencies": { "@blockshake/defly-connect": "^1.1.6", "@perawallet/connect": "^1.3.3", - "@randlabs/myalgo-connect": "^1.4.2", "@walletconnect/modal": "^2.6.2", "@walletconnect/sign-client": "^2.10.2" }, @@ -50,9 +48,6 @@ "@perawallet/connect": { "optional": true }, - "@randlabs/myalgo-connect": { - "optional": true - }, "@walletconnect/modal": { "optional": true }, @@ -69,7 +64,6 @@ "@blockshake/defly-connect": "^1.1.6", "@jest/globals": "^29.7.0", "@perawallet/connect": "^1.3.3", - "@randlabs/myalgo-connect": "^1.4.2", "@types/jest": "^29.5.10", "@types/node": "^20.6.5", "@types/web": "^0.0.125", diff --git a/src/wallets/manager.ts b/src/wallets/manager.ts index b4e8f9f..b5b21fb 100644 --- a/src/wallets/manager.ts +++ b/src/wallets/manager.ts @@ -125,6 +125,10 @@ export class WalletManager { return [...this._wallets.values()] } + public getWallet(walletId: WalletId): BaseWallet | undefined { + return this._wallets.get(walletId) + } + public async resumeSessions(): Promise { const promises = this.wallets.map((wallet) => wallet?.resumeSession()) await Promise.all(promises) diff --git a/src/wallets/supported/constants.ts b/src/wallets/supported/constants.ts index a327217..519f8e2 100644 --- a/src/wallets/supported/constants.ts +++ b/src/wallets/supported/constants.ts @@ -5,7 +5,6 @@ export enum WalletId { EXODUS = 'exodus', KMD = 'kmd', MNEMONIC = 'mnemonic', - MYALGO = 'myalgo', PERA = 'pera', WALLETCONNECT = 'walletconnect' } diff --git a/src/wallets/supported/index.ts b/src/wallets/supported/index.ts index 7d3ed85..2bba1e8 100644 --- a/src/wallets/supported/index.ts +++ b/src/wallets/supported/index.ts @@ -3,7 +3,6 @@ export * from './defly' export * from './exodus' export * from './kmd' export * from './mnemonic' -export * from './myalgo' export * from './pera' export * from './types' export * from './utils' diff --git a/src/wallets/supported/myalgo.ts b/src/wallets/supported/myalgo.ts deleted file mode 100644 index ad08b04..0000000 --- a/src/wallets/supported/myalgo.ts +++ /dev/null @@ -1,179 +0,0 @@ -import algosdk from 'algosdk' -import { Store, StoreActions, type State } from 'src/store' -import { BaseWallet } from '../base' -import { WalletId } from './constants' -import { - isSignedTxnObject, - mergeSignedTxnsWithGroup, - normalizeTxnGroup, - shouldSignTxnObject -} from '../utils' -import type MyAlgoConnect from '@randlabs/myalgo-connect' -import type { WalletAccount, WalletConstructor, WalletTransaction } from '../types' - -export interface MyAlgoConnectOptions { - timeout?: number - bridgeUrl?: string - disableLedgerNano?: boolean -} - -const icon = - 'data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMzIgMzIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPgogIDxjaXJjbGUgZmlsbD0iIzI0NUVDNiIgY3g9IjE2IiBjeT0iMTYiIHI9IjE2Ii8+CiAgPHBvbHlnb24gZmlsbD0iI0ZGRkZGRiIgcG9pbnRzPSIxMi40LDIxLjIgMTQuNSwyMS4yIDE1LjMsMTkuOSAxNi42LDE3LjYgMTguMSwxNC45IDE5LjksMTEuNyAyMC4yLDExLjIgMjAuMywxMS43IDIyLjksMjEuMiAyNSwyMS4yIDIxLjUsOC45IDIxLjQsOC42IDE5LjUsOC42IDE5LjUsOC43IDE3LjgsMTEuOCAxNiwxNC45IDE1LjgsMTQuMSAxNS4yLDExLjcgMTUuMSwxMS41IDE0LjQsOC45IDE0LjMsOC42IDEyLjQsOC42IDEyLjQsOC43IDEwLjcsMTEuOCA4LjksMTUgNy4xLDE4IDUuMywyMS4yIDcuNCwyMS4yIDkuMiwxOCAxMSwxNC44IDEyLjgsMTEuNiAxMy4xLDExLjEgMTMuMiwxMS42IDEzLjcsMTMuNyAxNC40LDE2LjMgMTQuNiwxNy4yIDE0LjIsMTgiLz4KPC9zdmc+' - -export class MyAlgoWallet extends BaseWallet { - private client: MyAlgoConnect | null = null - private options: MyAlgoConnectOptions - - protected store: Store - protected notifySubscribers: () => void - - constructor({ - id, - store, - subscribe, - onStateChange, - options = {}, - metadata = {} - }: WalletConstructor) { - super({ id, metadata, store, subscribe, onStateChange }) - this.options = options - this.store = store - this.notifySubscribers = onStateChange - } - - static defaultMetadata = { name: 'MyAlgo', icon } - - private async initializeClient(): Promise { - console.info('[MyAlgoWallet] Initializing client...') - const MyAlgoConnect = (await import('@randlabs/myalgo-connect')).default - const client = new MyAlgoConnect(this.options) - this.client = client - return client - } - - public async connect(): Promise { - console.info('[MyAlgoWallet] Connecting...') - try { - const client = this.client || (await this.initializeClient()) - const accounts: WalletAccount[] = await client.connect() - - if (accounts.length === 0) { - throw new Error('No accounts found!') - } - - const activeAccount = accounts[0]! - - this.store.dispatch(StoreActions.ADD_WALLET, { - walletId: this.id, - wallet: { - accounts, - activeAccount - } - }) - - this.notifySubscribers() - - return accounts - } catch (error: any) { - if (!error.message.includes('Operation cancelled')) { - console.error('[MyAlgoWallet] Error connecting:', error) - } else { - console.info('[MyAlgoWallet] Connection cancelled.') - } - return [] - } - } - - public async disconnect(): Promise { - console.info('[MyAlgoWallet] Disconnecting...') - this.onDisconnect() - } - - public resumeSession(): Promise { - return Promise.resolve() - } - - public async transactionSigner( - txnGroup: algosdk.Transaction[], - indexesToSign: number[] - ): Promise { - if (!this.client) { - throw new Error('[MyAlgoWallet] Client not initialized!') - } - - const txnsToSign = txnGroup.reduce((acc, txn, idx) => { - const txnBase64 = Buffer.from(txn.toByte()).toString('base64') - - if (indexesToSign.includes(idx)) { - acc.push({ txn: txnBase64 }) - } else { - acc.push({ txn: txnBase64, signers: [] }) - } - return acc - }, []) - - const signTxnsResult = await this.client.signTxns(txnsToSign) - const signedTxnsBase64 = signTxnsResult.filter(Boolean) as string[] - - const signedTxns = signedTxnsBase64.map((txn) => new Uint8Array(Buffer.from(txn, 'base64'))) - return signedTxns - } - - public async signTransactions( - txnGroup: algosdk.Transaction[] | algosdk.Transaction[][] | Uint8Array[] | Uint8Array[][], - indexesToSign?: number[], - returnGroup = true - ): Promise { - if (!this.client) { - throw new Error('[MyAlgoWallet] Client not initialized!') - } - const txnsToSign: WalletTransaction[] = [] - const signedIndexes: number[] = [] - - const msgpackTxnGroup: Uint8Array[] = normalizeTxnGroup(txnGroup) - - // Decode transactions to access properties - const decodedObjects = msgpackTxnGroup.map((txn) => { - return algosdk.decodeObj(txn) - }) as Array - - // Marshal transactions into `WalletTransaction[]` - decodedObjects.forEach((txnObject, idx) => { - const isSigned = isSignedTxnObject(txnObject) - const shouldSign = shouldSignTxnObject(txnObject, this.addresses, indexesToSign, idx) - - const txnBuffer: Uint8Array = msgpackTxnGroup[idx]! - const txn: algosdk.Transaction = isSigned - ? algosdk.decodeSignedTransaction(txnBuffer).txn - : algosdk.decodeUnsignedTransaction(txnBuffer) - - const txnBase64 = Buffer.from(txn.toByte()).toString('base64') - - if (shouldSign) { - txnsToSign.push({ txn: txnBase64 }) - signedIndexes.push(idx) - } else { - txnsToSign.push({ txn: txnBase64, signers: [] }) - } - }) - - // Sign transactions - const signTxnsResult = await this.client.signTxns(txnsToSign) - - // Filter out null results - const signedTxnsBase64 = signTxnsResult.filter(Boolean) as string[] - - // Convert base64 signed transactions to msgpack - const signedTxns = signedTxnsBase64.map((txn) => new Uint8Array(Buffer.from(txn, 'base64'))) - - // Merge signed transactions back into original group - const txnGroupSigned = mergeSignedTxnsWithGroup( - signedTxns, - msgpackTxnGroup, - signedIndexes, - returnGroup - ) - - return txnGroupSigned - } -} diff --git a/src/wallets/supported/types.ts b/src/wallets/supported/types.ts index 0596853..8c7b302 100644 --- a/src/wallets/supported/types.ts +++ b/src/wallets/supported/types.ts @@ -4,7 +4,6 @@ import { DeflyWallet, type DeflyWalletConnectOptions } from './defly' import { ExodusWallet, type ExodusOptions } from './exodus' import { KmdWallet, type KmdOptions } from './kmd' import { MnemonicWallet, type MnemonicOptions } from './mnemonic' -import { MyAlgoWallet, type MyAlgoConnectOptions } from './myalgo' import { PeraWallet, type PeraWalletConnectOptions } from './pera' import { WalletConnect, type WalletConnectOptions } from './walletconnect' @@ -13,7 +12,6 @@ export type WalletMap = { [WalletId.EXODUS]: typeof ExodusWallet [WalletId.KMD]: typeof KmdWallet [WalletId.MNEMONIC]: typeof MnemonicWallet - [WalletId.MYALGO]: typeof MyAlgoWallet [WalletId.PERA]: typeof PeraWallet [WalletId.WALLETCONNECT]: typeof WalletConnect } @@ -23,7 +21,6 @@ export type WalletOptionsMap = { [WalletId.EXODUS]: ExodusOptions [WalletId.KMD]: KmdOptions [WalletId.MNEMONIC]: MnemonicOptions - [WalletId.MYALGO]: MyAlgoConnectOptions [WalletId.PERA]: PeraWalletConnectOptions [WalletId.WALLETCONNECT]: WalletConnectOptions } @@ -33,12 +30,10 @@ export type SupportedWallet = | WalletIdConfig | WalletIdConfig | WalletIdConfig - | WalletIdConfig | WalletIdConfig | WalletIdConfig | WalletId.DEFLY | WalletId.EXODUS | WalletId.KMD | WalletId.MNEMONIC - | WalletId.MYALGO | WalletId.PERA diff --git a/src/wallets/supported/utils.ts b/src/wallets/supported/utils.ts index 2011162..404323f 100644 --- a/src/wallets/supported/utils.ts +++ b/src/wallets/supported/utils.ts @@ -3,7 +3,6 @@ import { DeflyWallet } from './defly' import { ExodusWallet } from './exodus' import { KmdWallet } from './kmd' import { MnemonicWallet } from './mnemonic' -import { MyAlgoWallet } from './myalgo' import { PeraWallet } from './pera' import { WalletMap } from './types' import { WalletConnect } from './walletconnect' @@ -14,7 +13,6 @@ export function createWalletMap(): WalletMap { [WalletId.EXODUS]: ExodusWallet, [WalletId.KMD]: KmdWallet, [WalletId.MNEMONIC]: MnemonicWallet, - [WalletId.MYALGO]: MyAlgoWallet, [WalletId.PERA]: PeraWallet, [WalletId.WALLETCONNECT]: WalletConnect }