SDK & Integration

SDK overview

@shh/sdk is isomorphic: a browser-safe entry for notes, the Merkle tree, and witness building, plus a Node-only entry that adds Groth16 proving via snarkjs. The split keeps node builtins out of the browser bundle.

The SDK is the client half of shh. It builds the exact witness inputs the circuits expect, manages notes and the Merkle tree, and (in Node) generates Groth16 proofs formatted for the Solidity verifiers.

Two entry points

ImportContainsEnvironment
@shh/sdkNotes, Poseidon, Merkle tree, witness-input builders, proof formattingBrowser-safe — no snarkjs, no node builtins
@shh/sdk/nodeGroth16 proving (prove, generatePoolWithdraw, generateTransaction)Node only — pulls snarkjs + wasm

What the main entry exports

typescript
// from "@shh/sdk"
export * from "./constants";   // FIELD_SIZE, LEVELS, ZERO_VALUE
export * from "./poseidon";    // poseidon([...])
export * from "./random";      // randomField()
export * from "./merkleTree";  // MerkleTree
export * from "./proof";       // formatProof()
export * from "./pool";        // PoolNote, buildPoolWithdrawInput
export * from "./utxo";        // Keypair, Utxo, buildTransactionInput, hashExtData

Foundations

poseidon(inputs)
Promise-returning Poseidon hash over field elements — the one hash used everywhere.
randomField()
Cryptographically secure random F_p (Web Crypto getRandomValues, reduced into the field).
FIELD_SIZE / LEVELS / ZERO_VALUE
The constants from the cryptographic core.

A typical client flow

  1. 1
    Reconstruct the treeFetch leaves from the backend and build a local MerkleTree.
  2. 2
    Build the witnessCall buildPoolWithdrawInput or buildTransactionInput with your note(s).
  3. 3
    ProveRun Groth16 — @shh/sdk/node in Node, or a snarkjs Web Worker in the browser.
  4. 4
    SubmitSend the formatted proof to the contract directly, or to the relayer for a gasless withdrawal.

Continue with the model that matches your profile: Privacy Pool notes or Shielded UTXO.