> ## Documentation Index
> Fetch the complete documentation index at: https://cosmos-docs-cosmjs-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Protobuf (Direct) Encoding

> How Direct signing serializes transactions as Protocol Buffers binary

Direct signing serializes everything as Protocol Buffers binary. This is the
default and most compact format.

## SignDoc

The bytes that get signed are the Protobuf encoding of a `SignDoc`:

```typescript theme={"system"}
interface SignDoc {
  bodyBytes: Uint8Array;     // encoded TxBody
  authInfoBytes: Uint8Array; // encoded AuthInfo
  chainId: string;
  accountNumber: bigint;
}
```

CosmJS provides helpers to construct these:

```typescript theme={"system"}
import { makeAuthInfoBytes, makeSignDoc, makeSignBytes } from "@cosmjs/proto-signing";

const bodyBytes = registry.encodeTxBody({ messages, memo });

const authInfoBytes = makeAuthInfoBytes(
  [{ pubkey: encodedPubkey, sequence }],
  feeAmount,
  gasLimit,
  feeGranter,
  feePayer,
);

const signDoc = makeSignDoc(bodyBytes, authInfoBytes, chainId, accountNumber);
const bytesToSign = makeSignBytes(signDoc);
```

`makeSignBytes` produces the canonical byte representation by encoding the
`SignDoc` with `SignDoc.encode().finish()`. Standard `DirectSecp256k1*` wallets
hash this output with **SHA-256** before ECDSA signing; EVM-compatible
`DirectEthSecp256k1*` wallets hash the same bytes with **Keccak-256**.

## AuthInfo

`AuthInfo` contains signer metadata and fee information:

```typescript theme={"system"}
const authInfoBytes = makeAuthInfoBytes(
  signers,   // [{ pubkey, sequence }]
  feeAmount, // Coin[]
  gasLimit,  // number
  feeGranter,
  feePayer,
  signMode,  // defaults to SIGN_MODE_DIRECT
);
```

Each signer entry includes:

* **pubkey** — the signer's public key, encoded as `Any`
* **sequence** — the account's current transaction counter

The `signMode` parameter is a single global setting (not per-signer) that
defaults to `SIGN_MODE_DIRECT`.

## TxRaw

After signing, the final transaction is a `TxRaw`:

```typescript theme={"system"}
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";

const txRaw = TxRaw.fromPartial({
  bodyBytes,
  authInfoBytes,
  signatures: [signature],
});

const txBytes = TxRaw.encode(txRaw).finish();
```

These `txBytes` are what gets broadcast to the chain.
