npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@0xgks/mandate-sdk

v0.1.0

Published

TypeScript SDK for generating and submitting MANDATE-compliant agent orders: Poseidon2 commitments, sparse-Merkle portfolio membership, Noir/Barretenberg proving, and sequencer/contract submission.

Downloads

172

Readme

@0xgks/mandate-sdk

TypeScript SDK for generating and submitting MANDATE-compliant agent orders.

This package wraps the MANDATE protocol's proving and submission pipeline behind a single call:

import { MandateClient } from "@0xgks/mandate-sdk";

const client = new MandateClient({
  agentId: "0x...",              // Poseidon2(session pk, salt) — this agent's registry identity
  sequencerUrl: "http://127.0.0.1:8787",
  rpcUrl: "http://127.0.0.1:8545",
  auctionAddress: "0x...",       // BatchAuction
  registryAddress: "0x...",      // MandateRegistry
  sessionPrivateKey: "0x...",    // the session EOA's private key (zero authority over funds)
  circuitDir: "/path/to/circuits/policy_check",
  policy: {
    whitelistRoot: 123n,
    maxOrderNotional: 1_000_000n,
    maxPosition: 1_000n,
    maxDailyLoss: 500n,
    policySalt: 42n,
  },
});

const result = await client.proveAndSubmit({
  market: "1",        // circuit market id, decimal string
  side: "buy",
  amount: "3",
  limitPrice: "3120",
});
// { epoch, orderCommitment, proof, publicInputs, txHash }

What proveAndSubmit does

  1. Normalizes the order (string amounts/prices -> the circuit's typed fields).
  2. Reads the current epoch, commit/reveal phase, breaker bit, and this agent's anchored state root from the BatchAuction contract.
  3. Checks the local plaintext policy still opens the commitment registered for this agent in MandateRegistry (refuses to prove with a stale or wrong mandate).
  4. Fetches the anchored portfolio witness (Merkle path + encoded position/PnL) from the sequencer, and refuses to proceed if it disagrees with the on-chain root — the chain is always the trusted source, never the sequencer's say-so.
  5. Generates the Poseidon2 order commitment and a Prover.toml, then runs nargo execute and bb prove against the Noir circuit. A mandate-violating order cannot be proven — this step throws MandateViolationError and nothing below it ever runs.
  6. Re-checks the commit window hasn't closed while proving, then submits the proof-gated commitment to BatchAuction.submitOrder.
  7. Hands the plaintext order envelope to the sequencer's /envelope endpoint for the reveal phase.

What this SDK is not

It does not decide what to trade — that's a strategy's job, and stays outside the SDK (see agents/src/strategies.ts in this monorepo for the demo's momentum/market-maker strategies). The SDK is the mechanical "prove this decided order and get it committed" primitive, safe to reuse from any agent runner or future MCP server.

Exports

Besides MandateClient, the package exports the lower-level primitives it's built from, for callers who want to compose their own flow:

  • PolicyProver — the Prover.tomlnargo executebb prove wrapper.
  • SparseMerkleTree — the ZeroTree sparse Merkle tree used for the whitelist and per-agent portfolio state.
  • hash, policyCommitment, orderCommitment, whitelistLeaf, portfolioLeaf — Poseidon2 commitment functions with byte-for-byte Noir parity (see client.test.ts).
  • toField, toHex32, encodeSigned, decodeSigned — field/encoding helpers matching the circuit exactly.
  • MandateViolationError, PortfolioMismatchError, PolicyMismatchError, EpochClosedError — typed errors for each rejection path.

Requirements

Node.js ≥ 20, and on PATH (or via the nargoBin/bbBin config fields / NARGO_BIN/BB_BIN env vars): nargo (1.0.0-beta.22) and bb (5.0.0-nightly, matched to nargo).

Testing

npm test

Runs the sparse-Merkle-tree unit tests and an integration test that mocks the chain and sequencer but performs real proving (nargo execute + bb prove) against circuits/policy_check, covering the compliant-order, mandate-violation, portfolio-mismatch, policy-mismatch, and closed-window paths.