Skip to content

Commit ed2bcd7

Browse files
authored
Merge pull request #191 from nowooj/fix/decode-pubkey
fix: decode custom pubkey in BaseAccount
2 parents 87e1587 + 791667f commit ed2bcd7

File tree

7 files changed

+24
-14
lines changed

7 files changed

+24
-14
lines changed

networks/cosmos/src/query/cosmos-query-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { ICosmosProtocolAdapter } from '../adapters/base';
5151
import { BaseAccount, getAccount } from '@interchainjs/cosmos-types';
5252
import { accountFromAny, type PubkeyDecoderMap } from '../utils';
5353
import { encodePubkey } from '@interchainjs/pubkey';
54+
import { EncodedMessage } from '../signers';
5455

5556

5657

@@ -327,7 +328,7 @@ export class CosmosQueryClient implements ICosmosQueryClient {
327328
// Account queries
328329
async getBaseAccount(
329330
address: string,
330-
opts?: { readonly pubkeyDecoders?: PubkeyDecoderMap }
331+
opts?: { readonly pubkeyDecoders?: PubkeyDecoderMap, encodePublicKey?: (publicKey: Uint8Array) => EncodedMessage }
331332
): Promise<BaseAccount | null> {
332333
try {
333334
// Create a plain RPC object so getAccount can mutate it
@@ -348,7 +349,7 @@ export class CosmosQueryClient implements ICosmosQueryClient {
348349
// Convert the standardized Account back to BaseAccount format
349350
return {
350351
address: account.address,
351-
pubKey: account.pubkey ? encodePubkey(account.pubkey) : undefined,
352+
pubKey: account.pubkey ? opts?.encodePublicKey ? opts.encodePublicKey(account.pubkey.value) : encodePubkey(account.pubkey) : undefined,
352353
accountNumber: BigInt(account.accountNumber),
353354
sequence: BigInt(account.sequence),
354355
};

networks/cosmos/src/signers/base-signer.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
CosmosSignArgs,
1616
EncodedMessage,
1717
DirectSignResponse,
18-
AminoSignResponse
18+
AminoSignResponse,
19+
DocOptions
1920
} from './types';
2021
import { ISigningClient, Encoder } from '../types/signing-client';
2122
import { getSimulate, SimulationResponse } from '@interchainjs/cosmos-types';
@@ -246,10 +247,10 @@ export abstract class BaseCosmosSigner implements ICosmosSigner, ISigningClient
246247
throw new Error('Unable to determine chain ID from any available source');
247248
}
248249

249-
async getAccountNumber(address: string): Promise<bigint> {
250+
async getAccountNumber(address: string, opts?: DocOptions): Promise<bigint> {
250251
// Use the getBaseAccount method for proper account querying
251252
try {
252-
const baseAccount = await this.config.queryClient.getBaseAccount(address);
253+
const baseAccount = await this.config.queryClient.getBaseAccount(address, opts);
253254
if (baseAccount) {
254255
return baseAccount.accountNumber;
255256
}
@@ -261,10 +262,10 @@ export abstract class BaseCosmosSigner implements ICosmosSigner, ISigningClient
261262
}
262263
}
263264

264-
async getSequence(address: string): Promise<bigint> {
265+
async getSequence(address: string, opts?: DocOptions): Promise<bigint> {
265266
// Use the getBaseAccount method for proper account querying
266267
try {
267-
const baseAccount = await this.config.queryClient.getBaseAccount(address);
268+
const baseAccount = await this.config.queryClient.getBaseAccount(address, opts);
268269
if (baseAccount) {
269270
return baseAccount.sequence;
270271
}

networks/cosmos/src/signers/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BroadcastTxAsyncResponse, BroadcastTxCommitResponse, BroadcastTxSyncRes
55
import { AminoConverter, Encoder } from '../types/signing-client';
66
import { Any, SignMode, SimulationResponse, TxResponse } from '@interchainjs/cosmos-types';
77
import { StdSignature } from '@interchainjs/amino';
8+
import { AccountFromAnyOptions } from '../utils';
89

910
export type CosmosSignerConfig = EndpointOptions & DocOptions;
1011

@@ -160,8 +161,8 @@ export interface ICosmosSigner extends IUniSigner<
160161
> {
161162
getAddresses(): Promise<string[]>;
162163
getChainId(): Promise<string>;
163-
getAccountNumber(address: string): Promise<bigint>;
164-
getSequence(address: string): Promise<bigint>;
164+
getAccountNumber(address: string, opts?: DocOptions): Promise<bigint>;
165+
getSequence(address: string, opts?: DocOptions): Promise<bigint>;
165166
addEncoders(encoders: Encoder[]): void;
166167
getEncoder(typeUrl: string): Encoder;
167168
addConverters?(converters: AminoConverter[]): void;
@@ -195,7 +196,7 @@ export interface AminoMessage {
195196
value: any;
196197
}
197198

198-
export type DocOptions = FeeOptions & SignOptions & TxOptions;
199+
export type DocOptions = FeeOptions & SignOptions & TxOptions & AccountFromAnyOptions;
199200

200201
export interface FeeOptions {
201202
multiplier?: number;

networks/cosmos/src/workflows/plugins/amino-sign-doc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ export class AminoSignDocPlugin extends BaseWorkflowBuilderPlugin<
6161
throw new Error('No signer address provided in options');
6262
}
6363
const accountNumber = options?.accountNumber ??
64-
await ctx.getSigner().getAccountNumber(address);
64+
await ctx.getSigner().getAccountNumber(address, options);
6565
const sequence = options?.sequence ??
66-
await ctx.getSigner().getSequence(address);
66+
await ctx.getSigner().getSequence(address, options);
6767

6868
// Convert messages to amino format
6969
const aminoMsgs: AminoMessage[] = messages.map(msg => {

networks/cosmos/src/workflows/plugins/direct-sign-doc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class DirectSignDocPlugin extends BaseWorkflowBuilderPlugin<
5757
}
5858

5959
const accountNumber = options?.accountNumber ??
60-
await ctx.getSigner().getAccountNumber(address);
60+
await ctx.getSigner().getAccountNumber(address, options);
6161

6262

6363

networks/cosmos/src/workflows/plugins/signer-info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class SignerInfoPlugin extends BaseWorkflowBuilderPlugin<
4545
}
4646

4747
const sequence = options?.sequence ??
48-
await ctx.getSigner().getSequence(signerAddress);
48+
await ctx.getSigner().getSequence(signerAddress, options);
4949

5050
// Get sign mode from options or use default
5151
const signMode = options?.signMode ?? params.signMode ?? this.defaultSignMode;

networks/injective/src/signers/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PRESET_INJECTIVE_SIGNATURE_FORMATS } from './signature-processor';
22
import deepmerge from 'deepmerge';
33
import { CosmosCryptoSecp256k1PubKey as Secp256k1PubKey } from '@interchainjs/cosmos-types';
44
import { EncodedMessage, DocOptions, CosmosSignerConfig } from '@interchainjs/cosmos';
5+
import { Any } from '@interchainjs/types';
56

67
/**
78
* Encode public key for Injective
@@ -43,6 +44,12 @@ export const DEFAULT_INJECTIVE_SIGNER_CONFIG: Partial<DocOptions> = {
4344

4445
// Public key encoding - Injective specific
4546
encodePublicKey: encodeInjectivePublicKey
47+
pubkeyDecoders: {
48+
'/injective.crypto.v1beta1.ethsecp256k1.PubKey': (pubkey: Any): Secp256k1PubKey => {
49+
const { key } = Secp256k1PubKey.decode(pubkey.value);
50+
return Secp256k1PubKey.fromPartial({ key });
51+
}
52+
}
4653
};
4754

4855
/**

0 commit comments

Comments
 (0)