diff --git a/src/wallet/walletconnect/WalletConnectV2.ts b/src/wallet/walletconnect/WalletConnectV2.ts index e09cd374..e2d43195 100644 --- a/src/wallet/walletconnect/WalletConnectV2.ts +++ b/src/wallet/walletconnect/WalletConnectV2.ts @@ -19,17 +19,21 @@ type GetAccountResponse = { pubkey: string; }; -type SignAminoResponse = - | { - // Keplr - signature: { - signature: string; - }; - } - | { - // Cosmostation - signature: string; - }; +type SignAminoResponse = { + signature: string; + signed: StdSignDoc; +}; + +/** + * The data returned by the `cosmos_signAmino` for keplr-like wallets. `signed` is + * optional because some wallets (like cosmostation) do not return it. + */ +type PartialSignAminoResponse = { + signature: { + signature: string; + }; + signed?: StdSignDoc | undefined; +}; const Method = { GET_ACCOUNTS: "cosmos_getAccounts", @@ -172,8 +176,8 @@ export class WalletConnectV2 { chainId: string, signerAddress: string, signDoc: StdSignDoc - ): Promise { - const { signature } = await this.request( + ): Promise { + const { signature, signed } = await this.request( chainId, Method.SIGN_AMINO, { @@ -181,7 +185,10 @@ export class WalletConnectV2 { signDoc, } ); - return typeof signature === "string" ? signature : signature.signature; + return { + signature: signature.signature, + signed: signed ?? signDoc, // simply return the original sign doc if `signed` is not returned + }; } /** diff --git a/src/wallet/wallets/cosmostation/CosmostationWalletConnectV2.ts b/src/wallet/wallets/cosmostation/CosmostationWalletConnectV2.ts index 5ef10998..faf1526c 100644 --- a/src/wallet/wallets/cosmostation/CosmostationWalletConnectV2.ts +++ b/src/wallet/wallets/cosmostation/CosmostationWalletConnectV2.ts @@ -3,6 +3,7 @@ import { Adapter, broadcastTx } from "cosmes/client"; import { fromBase64ToUint8Array } from "cosmes/codec"; import { CosmosBaseV1beta1Coin as Coin, + CosmosTxV1beta1Fee as Fee, CosmosTxSigningV1beta1SignMode as SignMode, } from "cosmes/protobufs"; import { WalletName, WalletType } from "cosmes/wallet"; @@ -52,7 +53,7 @@ export class CosmostationWalletConnectV2 extends ConnectedWallet { opts ); const { memo } = unsignedTx; - const signature = await this.wc.signAmino( + const { signature, signed } = await this.wc.signAmino( this.chainId, this.address, tx.toStdSignDoc({ @@ -65,12 +66,17 @@ export class CosmostationWalletConnectV2 extends ConnectedWallet { ); // Since `sendTx` on WC isn't implemented yet, we have to broadcast manually return broadcastTx(this.rpc, { - sequence, - fee, + tx, + sequence: BigInt(signed.sequence), + fee: new Fee({ + amount: signed.fee.amount as Coin[], + gasLimit: BigInt(signed.fee.gas), + payer: signed.fee.payer, + granter: signed.fee.granter, + }), signMode: SignMode.LEGACY_AMINO_JSON, signature: fromBase64ToUint8Array(signature), - tx, - memo, + memo: signed.memo, }); } } diff --git a/src/wallet/wallets/keplr/KeplrWalletConnectV2.ts b/src/wallet/wallets/keplr/KeplrWalletConnectV2.ts index 98ce17c6..50d740da 100644 --- a/src/wallet/wallets/keplr/KeplrWalletConnectV2.ts +++ b/src/wallet/wallets/keplr/KeplrWalletConnectV2.ts @@ -3,6 +3,7 @@ import { Adapter, broadcastTx } from "cosmes/client"; import { fromBase64ToUint8Array } from "cosmes/codec"; import { CosmosBaseV1beta1Coin as Coin, + CosmosTxV1beta1Fee as Fee, CosmosTxSigningV1beta1SignMode as SignMode, } from "cosmes/protobufs"; import { WalletName, WalletType } from "cosmes/wallet"; @@ -53,7 +54,7 @@ export class KeplrWalletConnectV2 extends ConnectedWallet { opts ); const { memo } = unsignedTx; - const signature = await this.wc.signAmino( + const { signature, signed } = await this.wc.signAmino( this.chainId, this.address, tx.toStdSignDoc({ @@ -66,12 +67,17 @@ export class KeplrWalletConnectV2 extends ConnectedWallet { ); // Since `sendTx` on WC isn't implemented yet, we have to broadcast manually return broadcastTx(this.rpc, { - sequence, - fee, + tx, + sequence: BigInt(signed.sequence), + fee: new Fee({ + amount: signed.fee.amount as Coin[], + gasLimit: BigInt(signed.fee.gas), + payer: signed.fee.payer, + granter: signed.fee.granter, + }), signMode: SignMode.LEGACY_AMINO_JSON, signature: fromBase64ToUint8Array(signature), - tx, - memo, + memo: signed.memo, }); } } diff --git a/src/wallet/wallets/leap/LeapWalletConnectV2.ts b/src/wallet/wallets/leap/LeapWalletConnectV2.ts index 8a4e90b0..3961fb50 100644 --- a/src/wallet/wallets/leap/LeapWalletConnectV2.ts +++ b/src/wallet/wallets/leap/LeapWalletConnectV2.ts @@ -3,6 +3,7 @@ import { Adapter, broadcastTx } from "cosmes/client"; import { fromBase64ToUint8Array } from "cosmes/codec"; import { CosmosBaseV1beta1Coin as Coin, + CosmosTxV1beta1Fee as Fee, CosmosTxSigningV1beta1SignMode as SignMode, } from "cosmes/protobufs"; import { WalletName, WalletType } from "cosmes/wallet"; @@ -52,7 +53,7 @@ export class LeapWalletConnectV2 extends ConnectedWallet { opts ); const { memo } = unsignedTx; - const signature = await this.wc.signAmino( + const { signature, signed } = await this.wc.signAmino( this.chainId, this.address, tx.toStdSignDoc({ @@ -65,12 +66,17 @@ export class LeapWalletConnectV2 extends ConnectedWallet { ); // Since `sendTx` on WC isn't implemented yet, we have to broadcast manually return broadcastTx(this.rpc, { - sequence, - fee, + tx, + sequence: BigInt(signed.sequence), + fee: new Fee({ + amount: signed.fee.amount as Coin[], + gasLimit: BigInt(signed.fee.gas), + payer: signed.fee.payer, + granter: signed.fee.granter, + }), signMode: SignMode.LEGACY_AMINO_JSON, signature: fromBase64ToUint8Array(signature), - tx, - memo, + memo: signed.memo, }); } }