Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions networks/cosmos/src/query/cosmos-query-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';



Expand Down Expand Up @@ -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<BaseAccount | null> {
try {
// Create a plain RPC object so getAccount can mutate it
Expand All @@ -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),
};
Expand Down
11 changes: 6 additions & 5 deletions networks/cosmos/src/signers/base-signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<bigint> {
async getAccountNumber(address: string, opts?: DocOptions): Promise<bigint> {
// 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;
}
Expand All @@ -261,10 +262,10 @@ export abstract class BaseCosmosSigner implements ICosmosSigner, ISigningClient
}
}

async getSequence(address: string): Promise<bigint> {
async getSequence(address: string, opts?: DocOptions): Promise<bigint> {
// 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;
}
Expand Down
7 changes: 4 additions & 3 deletions networks/cosmos/src/signers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -160,8 +161,8 @@ export interface ICosmosSigner extends IUniSigner<
> {
getAddresses(): Promise<string[]>;
getChainId(): Promise<string>;
getAccountNumber(address: string): Promise<bigint>;
getSequence(address: string): Promise<bigint>;
getAccountNumber(address: string, opts?: DocOptions): Promise<bigint>;
getSequence(address: string, opts?: DocOptions): Promise<bigint>;
addEncoders(encoders: Encoder[]): void;
getEncoder(typeUrl: string): Encoder;
addConverters?(converters: AminoConverter[]): void;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions networks/cosmos/src/workflows/plugins/amino-sign-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion networks/cosmos/src/workflows/plugins/direct-sign-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class DirectSignDocPlugin extends BaseWorkflowBuilderPlugin<
}

const accountNumber = options?.accountNumber ??
await ctx.getSigner().getAccountNumber(address);
await ctx.getSigner().getAccountNumber(address, options);



Expand Down
2 changes: 1 addition & 1 deletion networks/cosmos/src/workflows/plugins/signer-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions networks/injective/src/signers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,6 +44,12 @@ export const DEFAULT_INJECTIVE_SIGNER_CONFIG: Partial<DocOptions> = {

// 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 });
}
}
};

/**
Expand Down
Loading