Skip to content

Commit

Permalink
use config for signing client, test and bug fix
Browse files Browse the repository at this point in the history
Zetazzz committed Jan 23, 2025
1 parent c9da78e commit ed7d51b
Showing 3 changed files with 22 additions and 10 deletions.
8 changes: 8 additions & 0 deletions networks/cosmos/src/defaults.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@ import { sha256 } from '@noble/hashes/sha256';

import { CosmosAccount, EncodedMessage, FeeOptions, SignerOptions } from './types';
import { toDecoder } from './utils';
import { Secp256k1Auth } from '@interchainjs/auth/secp256k1';
import { WalletOptions } from './types/wallet';

export const defaultBroadcastOptions: BroadcastOptions = {
checkTx: true,
@@ -96,3 +98,9 @@ export const defaultSignerOptions: Required<SignerOptions> = {
encodePublicKey: defaultPublicKeyEncoder,
prefix: undefined,
};

export const defaultWalletOptions: WalletOptions = {
bip39Password: undefined,
createAuthsFromMnemonic: Secp256k1Auth.fromMnemonic,
signerConfig: defaultSignerOptions,
}
16 changes: 9 additions & 7 deletions networks/cosmos/src/wallets/secp256k1hd.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { Secp256k1Auth } from '@interchainjs/auth/secp256k1';
import { AddrDerivation, Auth, SignerConfig, SIGN_MODE, IGenericOfflineSignArgs } from '@interchainjs/types';

import { AminoDocSigner } from '../signers/amino';
import { defaultSignerConfig } from '../defaults';
import { defaultSignerConfig, defaultWalletOptions } from '../defaults';
import { DirectDocSigner } from '../signers/direct';
import {
CosmosAccount,
@@ -51,24 +51,26 @@ export class HDWallet extends BaseCosmosWallet<DirectDocSigner, AminoDocSigner>
derivations: AddrDerivation[],
options?: WalletOptions
) {
const walletOpts = { ...defaultWalletOptions, ...options };

const hdPaths = derivations.map((derivation) => derivation.hdPath);

let auths: Auth[];

if (options?.createAuthsFromMnemonic) {
auths = options.createAuthsFromMnemonic(mnemonic, hdPaths, {
bip39Password: options?.bip39Password,
if (walletOpts?.createAuthsFromMnemonic) {
auths = walletOpts.createAuthsFromMnemonic(mnemonic, hdPaths, {
bip39Password: walletOpts?.bip39Password,
});
} else {
auths = Secp256k1Auth.fromMnemonic(mnemonic, hdPaths, {
bip39Password: options?.bip39Password,
bip39Password: walletOpts?.bip39Password,
});
}

const accounts = auths.map((auth, i) => {
const derivation = derivations[i];

const opts = options.signerConfig as SignerOptions;
const opts = walletOpts.signerConfig as SignerOptions;

if (opts?.createAccount) {
return new opts.createAccount(derivation.prefix, auth, opts.publicKey.isCompressed);
@@ -77,7 +79,7 @@ export class HDWallet extends BaseCosmosWallet<DirectDocSigner, AminoDocSigner>
}
});

return new HDWallet(accounts, options?.signerConfig);
return new HDWallet(accounts, walletOpts?.signerConfig);
}
}

8 changes: 5 additions & 3 deletions networks/injective/starship/__tests__/gov.test.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { EthSecp256k1Auth } from '@interchainjs/auth/ethSecp256k1';
import { AminoSigner } from '@interchainjs/cosmos/signers/amino';
import { DirectSigner } from '@interchainjs/cosmos/signers/direct';
import { EthSecp256k1HDWallet } from '@interchainjs/injective/wallets/ethSecp256k1hd';
import { InjSigningClient } from '@interchainjs/injective/signing-client';
import { SigningClient } from '@interchainjs/cosmos/signing-client';
import {
assertIsDeliverTxSuccess,
createQueryRpc,
@@ -39,14 +39,15 @@ import { createGetValidators } from "@interchainjs/cosmos-types/cosmos/staking/v
import { QueryBalanceRequest, QueryBalanceResponse } from '@interchainjs/cosmos-types/cosmos/bank/v1beta1/query';
import { QueryProposalRequest, QueryProposalResponse, QueryVoteRequest, QueryVoteResponse } from '@interchainjs/cosmos-types/cosmos/gov/v1beta1/query';
import { QueryValidatorsRequest, QueryValidatorsResponse } from '@interchainjs/cosmos-types/cosmos/staking/v1beta1/query';
import { defaultSignerOptions } from '@interchainjs/injective/defaults';


const hdPath = "m/44'/60'/0'/0/0";

describe('Governance tests for injective', () => {
let directSigner: DirectSigner,
aminoSigner: AminoSigner,
signingClient: InjSigningClient,
signingClient: SigningClient,
directOfflineSigner: OfflineDirectSigner,
aminoOfflineSigner: OfflineAminoSigner,
denom: string,
@@ -120,10 +121,11 @@ describe('Governance tests for injective', () => {
aminoOfflineAddress = (await aminoOfflineSigner.getAccounts())[0].address;
testingOfflineAddress = aminoOfflineAddress;

signingClient = await InjSigningClient.connectWithSigner(
signingClient = await SigningClient.connectWithSigner(
await getRpcEndpoint(),
new AminoGenericOfflineSigner(aminoOfflineSigner),
{
signerOptions: defaultSignerOptions.Cosmos,
broadcast: {
checkTx: true,
deliverTx: true,

0 comments on commit ed7d51b

Please sign in to comment.