Skip to main content

Verify Commitment Inclusion

Build a sorted-pair Merkle tree, derive a proof for one Block hash, and verify its inclusion against the Merkle root hash. A valid proof confirms only that the Block hash is included in the leaf collection represented by that Merkle root.

Before You Start​

Use the JavaScript Merkle helpers with valid lowercase 0x-prefixed 32-byte leaves. Synthetic Block hashes keep the example independent of production data and network access. buildMerkleTree() sorts the leaves, so leaf order does not change the Merkle root hash.

How It Works

  1. Build a Merkle tree from normalized Block hashes.
  2. Select a leaf and derive its sibling path.
  3. Verify its inclusion against the Merkle root.
  4. Change the leaf or proof and confirm verification fails.

When to Use This Workflow​

Use an inclusion proof when a verifier has a trusted Merkle root hash and needs to check one Block hash without loading every leaf. The proof does not establish that the root is trustworthy; the verifier obtains the root through a trusted channel or an onchain record.

Install the package as shown in Quick Start; no network connection or deployed contract is required. The example runs on Node.js 20, 21, or 22, imports @alx-protocol/sdk and @alx-protocol/sdk/merkle, and executes entirely offchain.