diff --git a/networks/cosmos/src/query/cosmos-query-client.ts b/networks/cosmos/src/query/cosmos-query-client.ts index b8462d07..cf4e99d7 100644 --- a/networks/cosmos/src/query/cosmos-query-client.ts +++ b/networks/cosmos/src/query/cosmos-query-client.ts @@ -51,6 +51,7 @@ import { ICosmosProtocolAdapter } from '../adapters/base'; import { BaseAccount, getAccount } from '@interchainjs/cosmos-types'; import { accountFromAny, type PubkeyDecoderMap } from '../utils'; import { encodePubkey } from '@interchainjs/pubkey'; +import { EncodedMessage } from '../signers'; @@ -327,7 +328,7 @@ export class CosmosQueryClient implements ICosmosQueryClient { // Account queries async getBaseAccount( address: string, - opts?: { readonly pubkeyDecoders?: PubkeyDecoderMap } + opts?: { readonly pubkeyDecoders?: PubkeyDecoderMap, encodePublicKey?: (publicKey: Uint8Array) => EncodedMessage } ): Promise { try { // Create a plain RPC object so getAccount can mutate it @@ -348,7 +349,7 @@ export class CosmosQueryClient implements ICosmosQueryClient { // Convert the standardized Account back to BaseAccount format return { address: account.address, - pubKey: account.pubkey ? encodePubkey(account.pubkey) : undefined, + pubKey: account.pubkey ? opts?.encodePublicKey ? opts.encodePublicKey(account.pubkey.value) : encodePubkey(account.pubkey) : undefined, accountNumber: BigInt(account.accountNumber), sequence: BigInt(account.sequence), }; diff --git a/networks/cosmos/src/signers/base-signer.ts b/networks/cosmos/src/signers/base-signer.ts index d9d82e3c..a9551f34 100644 --- a/networks/cosmos/src/signers/base-signer.ts +++ b/networks/cosmos/src/signers/base-signer.ts @@ -15,7 +15,8 @@ import { CosmosSignArgs, EncodedMessage, DirectSignResponse, - AminoSignResponse + AminoSignResponse, + DocOptions } from './types'; import { ISigningClient, Encoder } from '../types/signing-client'; import { getSimulate, SimulationResponse } from '@interchainjs/cosmos-types'; @@ -246,10 +247,10 @@ export abstract class BaseCosmosSigner implements ICosmosSigner, ISigningClient throw new Error('Unable to determine chain ID from any available source'); } - async getAccountNumber(address: string): Promise { + async getAccountNumber(address: string, opts?: DocOptions): Promise { // Use the getBaseAccount method for proper account querying try { - const baseAccount = await this.config.queryClient.getBaseAccount(address); + const baseAccount = await this.config.queryClient.getBaseAccount(address, opts); if (baseAccount) { return baseAccount.accountNumber; } @@ -261,10 +262,10 @@ export abstract class BaseCosmosSigner implements ICosmosSigner, ISigningClient } } - async getSequence(address: string): Promise { + async getSequence(address: string, opts?: DocOptions): Promise { // Use the getBaseAccount method for proper account querying try { - const baseAccount = await this.config.queryClient.getBaseAccount(address); + const baseAccount = await this.config.queryClient.getBaseAccount(address, opts); if (baseAccount) { return baseAccount.sequence; } diff --git a/networks/cosmos/src/signers/types.ts b/networks/cosmos/src/signers/types.ts index 5585368a..9c7b382b 100644 --- a/networks/cosmos/src/signers/types.ts +++ b/networks/cosmos/src/signers/types.ts @@ -5,6 +5,7 @@ import { BroadcastTxAsyncResponse, BroadcastTxCommitResponse, BroadcastTxSyncRes import { AminoConverter, Encoder } from '../types/signing-client'; import { Any, SignMode, SimulationResponse, TxResponse } from '@interchainjs/cosmos-types'; import { StdSignature } from '@interchainjs/amino'; +import { AccountFromAnyOptions } from '../utils'; export type CosmosSignerConfig = EndpointOptions & DocOptions; @@ -160,8 +161,8 @@ export interface ICosmosSigner extends IUniSigner< > { getAddresses(): Promise; getChainId(): Promise; - getAccountNumber(address: string): Promise; - getSequence(address: string): Promise; + getAccountNumber(address: string, opts?: DocOptions): Promise; + getSequence(address: string, opts?: DocOptions): Promise; addEncoders(encoders: Encoder[]): void; getEncoder(typeUrl: string): Encoder; addConverters?(converters: AminoConverter[]): void; @@ -195,7 +196,7 @@ export interface AminoMessage { value: any; } -export type DocOptions = FeeOptions & SignOptions & TxOptions; +export type DocOptions = FeeOptions & SignOptions & TxOptions & AccountFromAnyOptions; export interface FeeOptions { multiplier?: number; diff --git a/networks/cosmos/src/workflows/plugins/amino-sign-doc.ts b/networks/cosmos/src/workflows/plugins/amino-sign-doc.ts index 60fc2a97..c8eafa02 100644 --- a/networks/cosmos/src/workflows/plugins/amino-sign-doc.ts +++ b/networks/cosmos/src/workflows/plugins/amino-sign-doc.ts @@ -61,9 +61,9 @@ export class AminoSignDocPlugin extends BaseWorkflowBuilderPlugin< throw new Error('No signer address provided in options'); } const accountNumber = options?.accountNumber ?? - await ctx.getSigner().getAccountNumber(address); + await ctx.getSigner().getAccountNumber(address, options); const sequence = options?.sequence ?? - await ctx.getSigner().getSequence(address); + await ctx.getSigner().getSequence(address, options); // Convert messages to amino format const aminoMsgs: AminoMessage[] = messages.map(msg => { diff --git a/networks/cosmos/src/workflows/plugins/direct-sign-doc.ts b/networks/cosmos/src/workflows/plugins/direct-sign-doc.ts index 7ae70aec..44da9398 100644 --- a/networks/cosmos/src/workflows/plugins/direct-sign-doc.ts +++ b/networks/cosmos/src/workflows/plugins/direct-sign-doc.ts @@ -57,7 +57,7 @@ export class DirectSignDocPlugin extends BaseWorkflowBuilderPlugin< } const accountNumber = options?.accountNumber ?? - await ctx.getSigner().getAccountNumber(address); + await ctx.getSigner().getAccountNumber(address, options); diff --git a/networks/cosmos/src/workflows/plugins/signer-info.ts b/networks/cosmos/src/workflows/plugins/signer-info.ts index e5888681..f7eba2af 100644 --- a/networks/cosmos/src/workflows/plugins/signer-info.ts +++ b/networks/cosmos/src/workflows/plugins/signer-info.ts @@ -45,7 +45,7 @@ export class SignerInfoPlugin extends BaseWorkflowBuilderPlugin< } const sequence = options?.sequence ?? - await ctx.getSigner().getSequence(signerAddress); + await ctx.getSigner().getSequence(signerAddress, options); // Get sign mode from options or use default const signMode = options?.signMode ?? params.signMode ?? this.defaultSignMode; diff --git a/networks/injective/src/signers/config.ts b/networks/injective/src/signers/config.ts index acc225dd..270d4818 100644 --- a/networks/injective/src/signers/config.ts +++ b/networks/injective/src/signers/config.ts @@ -2,6 +2,7 @@ import { PRESET_INJECTIVE_SIGNATURE_FORMATS } from './signature-processor'; import deepmerge from 'deepmerge'; import { CosmosCryptoSecp256k1PubKey as Secp256k1PubKey } from '@interchainjs/cosmos-types'; import { EncodedMessage, DocOptions, CosmosSignerConfig } from '@interchainjs/cosmos'; +import { Any } from '@interchainjs/types'; /** * Encode public key for Injective @@ -43,6 +44,12 @@ export const DEFAULT_INJECTIVE_SIGNER_CONFIG: Partial = { // Public key encoding - Injective specific encodePublicKey: encodeInjectivePublicKey + pubkeyDecoders: { + '/injective.crypto.v1beta1.ethsecp256k1.PubKey': (pubkey: Any): Secp256k1PubKey => { + const { key } = Secp256k1PubKey.decode(pubkey.value); + return Secp256k1PubKey.fromPartial({ key }); + } + } }; /**