diff --git a/packages/wallet-connect/src/lib/wallet-connect.ts b/packages/wallet-connect/src/lib/wallet-connect.ts index 508649615..023a3cfc7 100644 --- a/packages/wallet-connect/src/lib/wallet-connect.ts +++ b/packages/wallet-connect/src/lib/wallet-connect.ts @@ -149,6 +149,18 @@ const disconnect = async ({ state }: { state: WalletConnectState }) => { }); }; +const getSignatureData = (result: Uint8Array) => { + if (result instanceof Uint8Array) { + return result; + } else if (Array.isArray(result)) { + return new Uint8Array(result); + } else if (typeof result === "object" && result !== null) { + return new Uint8Array(Object.values(result)); + } else { + throw new Error("Unexpected result type from near_signTransaction"); + } +}; + const WalletConnect: WalletBehaviourFactory< BridgeWallet, { params: WalletConnectExtraOptions } @@ -354,7 +366,11 @@ const WalletConnect: WalletBehaviourFactory< }, }); - return nearAPI.transactions.SignedTransaction.decode(Buffer.from(result)); + const signatureData = getSignatureData(result); + + return nearAPI.transactions.SignedTransaction.decode( + Buffer.from(signatureData) + ); }; const requestSignTransactions = async (transactions: Array) => { @@ -408,7 +424,11 @@ const WalletConnect: WalletBehaviourFactory< }); return results.map((result) => { - return nearAPI.transactions.SignedTransaction.decode(Buffer.from(result)); + const signatureData = getSignatureData(result); + + return nearAPI.transactions.SignedTransaction.decode( + Buffer.from(signatureData) + ); }); };