# @cosmjs/proto-signing Agent Guide

> **Package**: `@cosmjs/proto-signing` v0.38.0 **Purpose**: Protobuf Direct
> signing for Cosmos SDK 0.40+ **Layer**: Signing Layer (depends on crypto,
> encoding, math, utils)

## Package Overview

Provides Protobuf-based transaction signing (Direct mode) for modern Cosmos SDK
chains (0.40+). This is the preferred signing method over Amino for new
applications.

### Key Features

- **DirectSecp256k1HdWallet**: HD wallet with Protobuf signing
- **Registry**: Type URL to protobuf codec mapping
- **Transaction Building**: Create and encode protobuf transactions
- **Fee Calculation**: Gas estimation and fee utilities

## Key Exports

| Export                    | Purpose                           |
| ------------------------- | --------------------------------- |
| `DirectSecp256k1HdWallet` | HD wallet for Direct signing      |
| `DirectSecp256k1Wallet`   | Single-key wallet                 |
| `Registry`                | Protobuf type registry            |
| `makeAuthInfoBytes()`     | Create AuthInfo for transactions  |
| `makeSignDoc()`           | Create SignDoc for Direct signing |
| `TxBodyEncodeObject`      | Transaction body type             |
| `EncodeObject`            | Generic message type              |

## Common Usage

### Creating a Wallet

```typescript
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";

const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
  prefix: "cosmos",
});

const accounts = await wallet.getAccounts();
```

### Using Registry

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

const registry = new Registry(defaultRegistryTypes);

// Register custom types
registry.register("/custom.MsgCustom", MsgCustom);

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

### Creating Transactions

```typescript
import { makeSignDoc, makeAuthInfoBytes, TxRaw } from "@cosmjs/proto-signing";

const txBodyBytes = registry.encode({
  typeUrl: "/cosmos.tx.v1beta1.TxBody",
  value: {
    messages: [msgSend],
    memo: "My transaction",
  },
});

const authInfoBytes = makeAuthInfoBytes(
  [{ pubkey, sequence }],
  [{ denom: "uatom", amount: "5000" }],
  200000,
  undefined,
  undefined,
);

const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
```

## Common Patterns

### Pattern: Multi-Message Transaction

```typescript
const messages = [
  {
    typeUrl: "/cosmos.bank.v1beta1.MsgSend",
    value: MsgSend.fromPartial({
      /* ... */
    }),
  },
  {
    typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
    value: MsgDelegate.fromPartial({
      /* ... */
    }),
  },
];
```

### Pattern: Fee Calculation

```typescript
import { calculateFee, GasPrice } from "@cosmjs/stargate";

const gasPrice = GasPrice.fromString("0.025uatom");
const fee = calculateFee(200000, gasPrice);
// { amount: [{ denom: "uatom", amount: "5000" }], gas: "200000" }
```

## Integration with Stargate

```typescript
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { SigningStargateClient } from "@cosmjs/stargate";

const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic);
const client = await SigningStargateClient.connectWithSigner(rpcUrl, wallet);
```

---

**Last Updated**: January 6, 2026 **Package Version**: 0.38.0


