Quickstart

The SDK is TypeScript on viem. Amounts are in base units (wei for ETH, 6 decimals for USDG).

import {
  Rings, PrivateWallet, unlockShieldedKeys, httpIndexer, httpProver,
  registerShieldedAddress, sendPrepared, ETH_TOKEN,
} from "@rings/sdk";

// 1. Shielded keys from one EIP-712 message. The SDK asks for the signature twice and
//    compares: a wallet that signs a different way each time would lose your notes.
const keys = await unlockShieldedKeys(account, (td) => walletClient.signTypedData({ account, ...td }));

// 2. Clients.
const indexer = httpIndexer(INDEXER_URL);
const rings = new Rings({ chainId: 4663n, pool: POOL, publicClient, prover: httpProver(PROVER_URL), indexer, registry: REGISTRY });
const wallet = new PrivateWallet(keys, indexer, rings.assets);

// 3. Register your shielded address once.
await registerShieldedAddress({ keys, publicClient, walletClient, registry: REGISTRY });

// 4. Deposit 0.01 ETH (ERC-20: send the returned approve call first, then prepare again).
const dep = await rings.prepareDeposit({ keys, token: ETH_TOKEN, amount: 10n ** 16n });
await sendPrepared(walletClient, dep.deposit!);     // already proved and simulated

// 5. Send privately, then withdraw.
await wallet.sync();
const tx = await rings.prepareTransfer({ keys, wallet, to: BOB, token: ETH_TOKEN, amount: 4n * 10n ** 15n });
const txHash = await sendPrepared(walletClient, tx);
const wd = await rings.prepareWithdraw({ keys, wallet, token: ETH_TOKEN, amount: 10n ** 15n, recipient: account });
await sendPrepared(walletClient, wd);

// 6. History and disclosure.
await wallet.sync();
wallet.balances(); wallet.history();               // each entry has .world (what the world sees)
const key = wallet.exportTxViewingKey(txHash);      // "rtvk1:..." opens this one transaction

Prove on your own machine

The hosted prover receives the witness of each proof. The witness includes the nullifier secret. The prover is stateless. The alternative is the prover binary from this repo on your machine. Point the app (wallet, prover note) or the SDK at it:

cd services/prover && ./fetch-keys.sh && go build -o prover .
./prover serve -keys keys       # HTTP on :3001, then use httpProver("http://127.0.0.1:3001")
./prover prove < witness.json   # or one proof from the command line (SDK: localBinaryProver)