@0xbow/privacy-pools-core-sdk

中文文档
1.5.0发布于 2026/09/01Apache-2.0TypeScriptES Module近 30 天下载 7583

Typescript SDK for the Privacy Pool protocol

原始使用文档
文档目录15 节
  1. Installation
  2. Setup
  3. Available Scripts
  4. Usage
  5. Initialization
  6. Commitment Proofs
  7. Withdrawal Proofs
  8. Key Derivation
  9. Account Recovery
  10. Contract Interactions
  11. Mnemonic Security
  12. Circuit Artifact Integrity
  13. Features
  14. Contributing
  15. License

Privacy Pool Core SDK

A TypeScript SDK for interacting with the Privacy Pool protocol. This SDK provides cryptographic utilities, proof generation, account management, and contract interactions for Privacy Pool integration.

Installation

npm install @0xbow/privacy-pools-core-sdk
# or
yarn add @0xbow/privacy-pools-core-sdk
# or
pnpm add @0xbow/privacy-pools-core-sdk

Setup

  1. Install dependencies by running pnpm install
  2. Build the SDK by running pnpm build

Available Scripts

ScriptDescription
buildBuild the SDK using Rollup
build:bundleBuild the SDK and set up circuits
check-typesCheck for TypeScript type issues
cleanRemove build artifacts
lintRun ESLint to check code quality
lint:fixFix linting issues automatically
formatCheck code formatting using Prettier
format:fixFix formatting issues automatically
testRun tests using Vitest
test:covGenerate test coverage report

Usage

Initialization

import { PrivacyPoolSDK, Circuits } from '@0xbow/privacy-pools-core-sdk';

// In Node.js — set browser: false to load artifacts from the filesystem
const circuits = new Circuits({ browser: false });

// In the browser — the default (browser: true) uses fetch
// const circuits = new Circuits();

const sdk = new PrivacyPoolSDK(circuits);

Commitment Proofs

const commitmentProof = await sdk.proveCommitment(value, label, nullifier, secret);
const isValid = await sdk.verifyCommitment(commitmentProof);

Withdrawal Proofs

const withdrawalProof = await sdk.proveWithdrawal(commitment, withdrawalInput);
const isValid = await sdk.verifyWithdrawal(withdrawalProof);

Key Derivation

The SDK derives deterministic master keys from a BIP-39 mnemonic phrase using generateMasterKeys. These keys are used to generate per-deposit and per-withdrawal nullifiers and secrets.

import { generateMasterKeys, generateDepositSecrets, generateWithdrawalSecrets } from '@0xbow/privacy-pools-core-sdk';

const { masterNullifier, masterSecret } = generateMasterKeys(mnemonic);

const depositSecrets = generateDepositSecrets(
  { masterNullifier, masterSecret },
  scope,
  index,
);

const withdrawalSecrets = generateWithdrawalSecrets(
  { masterNullifier, masterSecret },
  label,
  index,
);

Account Recovery

The AccountService reconstructs on-chain account state from a mnemonic by scanning deposit, withdrawal, and ragequit events.

import { AccountService, DataService } from '@0xbow/privacy-pools-core-sdk';

const { account, legacyAccount, errors } = await AccountService.initializeWithEvents(
  dataService,
  { mnemonic },
  pools,
);

Incomplete Scopes

A non-empty errors array means one or more pools failed to load. Reconstructed state for those scopes is absent, not empty — the account may hold notes that are not visible, so treating the scope as having no accounts will understate the next deposit index and produce a deposit that later reconstructions cannot find.

Check status before acting on a scope:

account.getScopeStatus(scope); // 'complete' | 'incomplete' | 'not-loaded'
account.isScopeComplete(scope); // true only for 'complete'
account.getIncompleteScopes(); // scopes whose last load failed

Block deposits and withdrawals for any scope that is not complete. createDepositSecrets(scope) without an explicit index throws for such a scope rather than guessing; pass an explicit index only in recovery flows. Status is stored on the account, so it survives persisting and restoring it.

To retry the failed pools, pass both services returned by the original call:

const retry = await AccountService.initializeWithEvents(
  dataService,
  { service: account, legacyService: legacyAccount },
  pools,
);

Omitting legacyService reconstructs the retried scopes without migration discovery, which silently omits migration-derived accounts.

Empty Nodes

account.getSpendableCommitments() returns the latest decrypted commitment of each account. By default (includeEmptyNodes: true) the result includes empty (zero-value), migrated, and ragequit nodes alongside spendable ones, so callers can see the full decrypted state.

To restore the spendable-only behavior — returning only commitments with a non-zero value whose account has not been ragequit or migrated — set includeEmptyNodes: false:

const { account } = await AccountService.initializeWithEvents(
  dataService,
  { mnemonic },
  pools,
  { includeEmptyNodes: false },
);

The same option can be passed when constructing an AccountService directly:

const account = new AccountService(dataService, { mnemonic, includeEmptyNodes: false });

Note: when includeEmptyNodes is true, getSpendableCommitments() may return commitments that are not actually spendable (zero-value, migrated, or ragequit). Filter on value / account flags before attempting to spend.

Contract Interactions

const contracts = sdk.createContractInstance(rpcUrl, chain, entrypointAddress, privateKey);

Mnemonic Security

The SDK does not provide a generateMnemonic utility. Use a trusted BIP-39 library (e.g. @scure/bip39 or viem/accounts) to generate mnemonic phrases externally.

  • Never hardcode mnemonics in source code or configuration files.
  • Never log or transmit mnemonics in plaintext.
  • Store mnemonics using OS-level secure storage (e.g. OS keychain, encrypted vault) — never in browser localStorage or unencrypted files.
  • Do not reuse a single mnemonic across unrelated applications. A compromised mnemonic exposes all derived keys and the funds they control.
  • The mnemonic is the sole root of all derived keys. Loss of the mnemonic means permanent loss of access to all associated commitments and funds.

Circuit Artifact Integrity

The SDK verifies every downloaded circuit artifact (wasm, vkey, zkey) against expected SHA-256 digests. Artifacts without a registered hash are rejected at load time.

ArtifactSHA-256
commitment.wasm254d2130607182fd6fd1aee67971526b13cfe178c88e360da96dce92663828d8
commitment.vkey7d48b4eb3dedc12fb774348287b587f0c18c3c7254cd60e9cf0f8b3636a570d8
commitment.zkey494ae92d64098fda2a5649690ddc5821fcd7449ca5fe8ef99ee7447544d7e1f3
withdraw.wasm36cda22791def3d520a55c0fc808369cd5849532a75fab65686e666ed3d55c10
withdraw.vkey666bd0983b20c1611543b04f7712e067fbe8cad69f07ada8a310837ff398d21e
withdraw.zkey2a893b42174c813566e5c40c715a8b90cd49fc4ecf384e3a6024158c3d6de677

You can independently verify these against the committed artifacts:

shasum -a 256 packages/circuits/trusted-setup/final-keys/*.{vkey,zkey}
shasum -a 256 packages/circuits/build/*/*_js/*.wasm

Features

  • Zero-knowledge proof generation and verification (commitments and withdrawals)
  • Deterministic key derivation from BIP-39 mnemonics
  • Account state recovery from on-chain events
  • Commitment and Merkle proof utilities
  • Contract interaction helpers
  • Type-safe API

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

Apache-2.0 License - see the LICENSE file for details.

版本与发布记录

@0xbow/privacy-pools-core-sdk 共发布 45 个版本,首次发布于 2025/02/19;过去 12 个月发布了 16 个版本。

版本发布日期距今
1.5.0latest2026/09/012 个月前
1.4.02026/08/063 个月前
1.2.02026/03/207 个月前
1.1.12026/03/098 个月前
0.0.0-3dpf8pkcanary2026/03/058 个月前
1.1.02026/02/198 个月前

关于 @0xbow/privacy-pools-core-sdk 的常见问题

@0xbow/privacy-pools-core-sdk 是什么?

Typescript SDK for the Privacy Pool protocol

如何安装 @0xbow/privacy-pools-core-sdk?

在项目目录运行 npm install @0xbow/privacy-pools-core-sdk,或使用 pnpm add / yarn add / bun add。

@0xbow/privacy-pools-core-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@0xbow/privacy-pools-core-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@0xbow/privacy-pools-core-sdk 可以商用吗?

@0xbow/privacy-pools-core-sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@0xbow/privacy-pools-core-sdk 的下载量有多少?

根据 npm 官方下载统计,@0xbow/privacy-pools-core-sdk 在 2026/10/04 – 2026/11/02 这 30 天内被下载 7,583 次,日均约 253 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@0xbow/privacy-pools-core-sdk 还在维护吗?

最新版本 1.5.0 发布于 2026/09/01(2 个月前);至今共发布 45 个版本,其中过去 12 个月发布了 16 个;首次发布于 2025/02/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。