Skip to main content
Provides Protobuf Direct signing mode for modern Cosmos SDK chains. This is the preferred signing method for new applications.
npm install @cosmjs/proto-signing

DirectSecp256k1HdWallet

HD wallet using BIP-39 mnemonic with Protobuf Direct signing. Implements OfflineDirectSigner.

Static Methods

MethodParametersReturns
generatelength?: 12 | 15 | 18 | 21 | 24, options?: Partial<DirectSecp256k1HdWalletOptions>Promise<DirectSecp256k1HdWallet>
fromMnemonicmnemonic: string, options?: Partial<DirectSecp256k1HdWalletOptions>Promise<DirectSecp256k1HdWallet>
deserializeserialization: string, password: stringPromise<DirectSecp256k1HdWallet>
deserializeWithEncryptionKeyserialization: string, encryptionKey: Uint8ArrayPromise<DirectSecp256k1HdWallet>

Instance Methods

MethodParametersReturns
getAccountsPromise<readonly AccountData[]>
signDirectsignerAddress: string, signDoc: SignDocPromise<DirectSignResponse>
serializepassword: stringPromise<string>
serializeWithEncryptionKeyencryptionKey: Uint8Array, kdfConfiguration: KdfConfigurationPromise<string>

Instance Properties

PropertyType
mnemonicstring

Options

interface DirectSecp256k1HdWalletOptions {
  readonly bip39Password: string;   // default: ""
  readonly hdPaths: readonly HdPath[]; // default: [makeCosmoshubPath(0)]
  readonly prefix: string;          // default: "cosmos"
}

Usage

import { DirectSecp256k1HdWallet, makeCosmoshubPath } from "@cosmjs/proto-signing";

const wallet = await DirectSecp256k1HdWallet.generate(24, { prefix: "cosmos" });
const [{ address, pubkey }] = await wallet.getAccounts();

const restored = await DirectSecp256k1HdWallet.fromMnemonic(wallet.mnemonic, {
  prefix: "osmo",
  hdPaths: [makeCosmoshubPath(0), makeCosmoshubPath(1)],
});

DirectSecp256k1Wallet

Single-key wallet for Protobuf Direct signing. Implements OfflineDirectSigner.
MethodParametersReturns
fromKey (static)privkey: Uint8Array, prefix?: stringPromise<DirectSecp256k1Wallet>
getAccountsPromise<readonly AccountData[]>
signDirectaddress: string, signDoc: SignDocPromise<DirectSignResponse>

DirectEthSecp256k1HdWallet

HD wallet using Ethereum’s secp256k1 curve for chains with EVM compatibility. Supports generate, fromMnemonic, getAccounts, and signDirect like DirectSecp256k1HdWallet, but uses the Ethereum HD path m/44'/60'/0'/0/0 by default and Keccak-256 for address derivation. Does not support wallet serialization (serialize/deserialize).

DirectEthSecp256k1Wallet

Single-key wallet using Ethereum’s secp256k1 curve. Supports fromKey, getAccounts, and signDirect like DirectSecp256k1Wallet, but reports algo: "eth_secp256k1" and uses Keccak-256 for signing.

Registry

Maps type URLs to protobuf codec implementations for encoding and decoding messages.
MethodParametersReturns
constructorcustomTypes?: Iterable<[string, GeneratedType]>Registry
registertypeUrl: string, type: GeneratedTypevoid
lookupTypetypeUrl: stringGeneratedType | undefined
encodeencodeObject: EncodeObjectUint8Array
encodeAsAnyencodeObject: EncodeObjectAny
encodeTxBodytxBodyFields: TxBodyValueUint8Array
decodedecodeObject: DecodeObjectany
decodeTxBodytxBody: Uint8ArrayTxBody

Usage

import { Registry } from "@cosmjs/proto-signing";
import { defaultRegistryTypes } from "@cosmjs/stargate";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";

const registry = new Registry(defaultRegistryTypes);
registry.register("/my.custom.MsgCustom", MsgCustom);

const encoded = registry.encode({
  typeUrl: "/cosmos.bank.v1beta1.MsgSend",
  value: MsgSend.fromPartial({
    fromAddress: "cosmos1sender...",
    toAddress: "cosmos1recipient...",
    amount: [{ denom: "uatom", amount: "1000" }],
  }),
});

Key Types

EncodeObject

interface EncodeObject {
  readonly typeUrl: string;
  readonly value: any;
}

DecodeObject

interface DecodeObject {
  readonly typeUrl: string;
  readonly value: Uint8Array;
}

TxBodyEncodeObject

interface TxBodyEncodeObject extends EncodeObject {
  readonly typeUrl: "/cosmos.tx.v1beta1.TxBody";
  readonly value: TxBodyValue;
}

AccountData

interface AccountData {
  readonly address: string;
  readonly algo: Algo;
  readonly pubkey: Uint8Array;
}

OfflineDirectSigner

interface OfflineDirectSigner {
  readonly getAccounts: () => Promise<readonly AccountData[]>;
  readonly signDirect: (signerAddress: string, signDoc: SignDoc) => Promise<DirectSignResponse>;
}

OfflineSigner

type OfflineSigner = OfflineAminoSigner | OfflineDirectSigner;

DecodedTxRaw

interface DecodedTxRaw {
  readonly authInfo: AuthInfo;
  readonly body: TxBody;
  readonly signatures: readonly Uint8Array[];
}

Helper Functions

FunctionParametersReturns
makeAuthInfoBytessigners: ReadonlyArray<{ pubkey: Any; sequence: bigint | number }>, feeAmount: readonly Coin[], gasLimit: number, feeGranter: string | undefined, feePayer: string | undefined, signMode?: SignModeUint8Array
makeSignDocbodyBytes: Uint8Array, authInfoBytes: Uint8Array, chainId: string, accountNumber: numberSignDoc
makeSignBytessignDoc: SignDocUint8Array
decodeTxRawtx: Uint8ArrayDecodedTxRaw
encodePubkeypubkey: PubkeyAny
decodePubkeypubkey: AnyPubkey
decodeOptionalPubkeypubkey: Any | null | undefinedPubkey | null
makeCosmoshubPathaccount: numberHdPath
coinamount: number | string, denom: stringCoin
coinsamount: number | string, denom: stringCoin[]
parseCoinsinput: stringCoin[]
extractKdfConfigurationserialization: stringKdfConfiguration
executeKdfpassword: string, configuration: KdfConfigurationPromise<Uint8Array>