diff --git a/packages/ledger/src/lib/ledger.ts b/packages/ledger/src/lib/ledger.ts index 125d1ffc5..98882205b 100644 --- a/packages/ledger/src/lib/ledger.ts +++ b/packages/ledger/src/lib/ledger.ts @@ -66,28 +66,32 @@ const Ledger: WalletBehaviourFactory = async ({ const signer: Signer = { createKey: () => { - throw Error("Not implemented"); + throw new Error("Not implemented"); }, - getPublicKey: async () => { - if (!_state.accounts.length) { - throw new Error(`${metadata.name} not connected`); + getPublicKey: async (accountId) => { + const account = _state.accounts.find((a) => a.accountId === accountId); + + if (!account) { + throw new Error("Failed to find public key for account"); } - return utils.PublicKey.from(_state.accounts[0].publicKey); + return utils.PublicKey.from(account.publicKey); }, - signMessage: async (message: Uint8Array) => { - if (!_state.accounts.length) { - throw new Error(`${metadata.name} not connected`); + signMessage: async (message, accountId) => { + const account = _state.accounts.find((a) => a.accountId === accountId); + + if (!account) { + throw new Error("Failed to find account for signing"); } const signature = await _state.client.sign({ data: message, - derivationPath: _state.accounts[0].derivationPath, + derivationPath: account.derivationPath, }); return { signature, - publicKey: utils.PublicKey.from(_state.accounts[0].publicKey), + publicKey: utils.PublicKey.from(account.publicKey), }; }, }; @@ -182,10 +186,12 @@ const Ledger: WalletBehaviourFactory = async ({ throw new Error("Wallet not connected"); } + const signerId = t.signerId ? t.signerId : _state.accounts[0].accountId; + return { receiverId: t.receiverId, actions: t.actions, - signerId: _state.accounts[0].accountId, + signerId, }; }); }; diff --git a/packages/math-wallet/src/lib/math-wallet.ts b/packages/math-wallet/src/lib/math-wallet.ts index 9b54d8564..45c6ec219 100644 --- a/packages/math-wallet/src/lib/math-wallet.ts +++ b/packages/math-wallet/src/lib/math-wallet.ts @@ -86,10 +86,12 @@ const MathWallet: WalletBehaviourFactory = async ({ } return transactions.map((t) => { + const signerId = t.signerId ? t.signerId : account.accountId; + return { receiverId: t.receiverId, actions: t.actions, - signerId: account.accountId, + signerId, }; }); }; diff --git a/packages/wallet-utils/src/lib/sign-transactions.ts b/packages/wallet-utils/src/lib/sign-transactions.ts index f8f5219c7..af776c85c 100644 --- a/packages/wallet-utils/src/lib/sign-transactions.ts +++ b/packages/wallet-utils/src/lib/sign-transactions.ts @@ -13,8 +13,6 @@ export const signTransactions = async ( signer: Signer, networkId: string ) => { - const publicKey = (await signer.getPublicKey()).toString(); - const provider = new providers.JsonRpcProvider({ url: networkId, }); @@ -22,6 +20,10 @@ export const signTransactions = async ( const signedTransactions: Array = []; for (let i = 0; i < transactions.length; i++) { + const publicKey = ( + await signer.getPublicKey(transactions[i].signerId, networkId) + ).toString(); + const [block, accessKey] = await Promise.all([ provider.block({ finality: "final" }), provider.query({