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
| Import | Contains | Environment |
|---|---|---|
@shh/sdk | Notes, Poseidon, Merkle tree, witness-input builders, proof formatting | Browser-safe — no snarkjs, no node builtins |
@shh/sdk/node | Groth16 proving (prove, generatePoolWithdraw, generateTransaction) | Node only — pulls snarkjs + wasm |
What the main entry exports
// 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, hashExtDataFoundations
poseidon(inputs)- Promise-returning Poseidon hash over field elements — the one hash used everywhere.
randomField()- Cryptographically secure random
F_p(Web CryptogetRandomValues, reduced into the field). FIELD_SIZE/LEVELS/ZERO_VALUE- The constants from the cryptographic core.
A typical client flow
- 1Reconstruct the treeFetch leaves from the backend and build a local
MerkleTree. - 2Build the witnessCall
buildPoolWithdrawInputorbuildTransactionInputwith your note(s). - 3ProveRun Groth16 —
@shh/sdk/nodein Node, or a snarkjs Web Worker in the browser. - 4SubmitSend 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.