@0xbow/privacy-pools-core-sdk 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +102 -23
  2. package/dist/esm/{fetchArtifacts.esm-B6qveiM8.js → fetchArtifacts.esm-B0qaot8v.js} +2 -2
  3. package/dist/esm/{fetchArtifacts.esm-B6qveiM8.js.map → fetchArtifacts.esm-B0qaot8v.js.map} +1 -1
  4. package/dist/esm/{fetchArtifacts.node-BPQQPsnb.js → fetchArtifacts.node-PzijuwVc.js} +2 -2
  5. package/dist/esm/{fetchArtifacts.node-BPQQPsnb.js.map → fetchArtifacts.node-PzijuwVc.js.map} +1 -1
  6. package/dist/esm/{index-CRtEyHEf.js → index-BjOXETm6.js} +316 -316
  7. package/dist/esm/{index-CRtEyHEf.js.map → index-BjOXETm6.js.map} +1 -1
  8. package/dist/esm/index.mjs +1 -1
  9. package/dist/index.d.mts +81 -0
  10. package/dist/node/{fetchArtifacts.esm-z-KXbilc.js → fetchArtifacts.esm-B6uU6QdA.js} +2 -2
  11. package/dist/node/{fetchArtifacts.esm-z-KXbilc.js.map → fetchArtifacts.esm-B6uU6QdA.js.map} +1 -1
  12. package/dist/node/{fetchArtifacts.node-DvqhqpW9.js → fetchArtifacts.node-CZRy6KmV.js} +2 -2
  13. package/dist/node/{fetchArtifacts.node-DvqhqpW9.js.map → fetchArtifacts.node-CZRy6KmV.js.map} +1 -1
  14. package/dist/node/{index-BsmEKESv.js → index-b-U_m4Mi.js} +337 -337
  15. package/dist/node/{index-BsmEKESv.js.map → index-b-U_m4Mi.js.map} +1 -1
  16. package/dist/node/index.mjs +1 -1
  17. package/dist/types/circuits/artifactHashes.d.ts +19 -0
  18. package/dist/types/core/account.service.d.ts +79 -0
  19. package/dist/types/core/tmp.d.ts +1 -0
  20. package/dist/types/{fetchArtifacts.esm-DF01Zpo3.js → fetchArtifacts.esm-BKxGrC6w.js} +1 -1
  21. package/dist/types/{fetchArtifacts.node-BO6FBCAw.js → fetchArtifacts.node-kXMUDgNn.js} +1 -1
  22. package/dist/types/{index-CH7gk4sK.js → index-BwyNuaY0.js} +336 -336
  23. package/dist/types/index.js +1 -1
  24. package/dist/types/types/account.d.ts +2 -0
  25. package/package.json +1 -1
  26. package/src/circuits/artifactHashes.ts +74 -0
  27. package/src/circuits/circuits.impl.ts +8 -0
  28. package/src/core/account.service.ts +329 -35
  29. package/src/core/data.service.ts +3 -9
  30. package/src/core/tmp.ts +4 -0
  31. package/src/crypto.ts +5 -6
  32. package/src/types/account.ts +3 -1
  33. package/dist/types/keys.d.ts +0 -18
  34. package/src/keys.ts +0 -42
package/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # Privacy Pool Core SDK
2
2
 
3
- A TypeScript SDK for interacting with the Privacy Pool protocol. This SDK provides a comprehensive set of tools and utilities for integrating with Privacy Pool, enabling deposits, withdrawals, and other core functionality.
3
+ 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.
4
4
 
5
5
  ## Installation
6
6
 
7
-
8
7
  ```bash
9
8
  npm install @0xbow/privacy-pools-core-sdk
10
9
  # or
@@ -35,33 +34,113 @@ pnpm add @0xbow/privacy-pools-core-sdk
35
34
 
36
35
  ## Usage
37
36
 
37
+ ### Initialization
38
+
39
+ ```typescript
40
+ import { PrivacyPoolSDK, Circuits } from '@0xbow/privacy-pools-core-sdk';
41
+
42
+ // In Node.js — set browser: false to load artifacts from the filesystem
43
+ const circuits = new Circuits({ browser: false });
44
+
45
+ // In the browser — the default (browser: true) uses fetch
46
+ // const circuits = new Circuits();
47
+
48
+ const sdk = new PrivacyPoolSDK(circuits);
49
+ ```
50
+
51
+ ### Commitment Proofs
52
+
53
+ ```typescript
54
+ const commitmentProof = await sdk.proveCommitment(value, label, nullifier, secret);
55
+ const isValid = await sdk.verifyCommitment(commitmentProof);
56
+ ```
57
+
58
+ ### Withdrawal Proofs
59
+
60
+ ```typescript
61
+ const withdrawalProof = await sdk.proveWithdrawal(commitment, withdrawalInput);
62
+ const isValid = await sdk.verifyWithdrawal(withdrawalProof);
63
+ ```
64
+
65
+ ### Key Derivation
66
+
67
+ 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.
68
+
69
+ ```typescript
70
+ import { generateMasterKeys, generateDepositSecrets, generateWithdrawalSecrets } from '@0xbow/privacy-pools-core-sdk';
71
+
72
+ const { masterNullifier, masterSecret } = generateMasterKeys(mnemonic);
73
+
74
+ const depositSecrets = generateDepositSecrets(
75
+ { masterNullifier, masterSecret },
76
+ scope,
77
+ index,
78
+ );
79
+
80
+ const withdrawalSecrets = generateWithdrawalSecrets(
81
+ { masterNullifier, masterSecret },
82
+ label,
83
+ index,
84
+ );
85
+ ```
86
+
87
+ ### Account Recovery
88
+
89
+ The `AccountService` reconstructs on-chain account state from a mnemonic by scanning deposit, withdrawal, and ragequit events.
90
+
91
+ ```typescript
92
+ import { AccountService, DataService } from '@0xbow/privacy-pools-core-sdk';
93
+
94
+ const { account, errors } = await AccountService.initializeWithEvents(
95
+ dataService,
96
+ { mnemonic },
97
+ pools,
98
+ );
99
+ ```
100
+
101
+ ### Contract Interactions
102
+
38
103
  ```typescript
39
- import { PrivacyPoolSDK } from '@0xbow/privacy-pools-core-sdk';
40
-
41
- // Initialize the SDK
42
- const sdk = new PrivacyPoolSDK({
43
- // Configuration options
44
- });
45
-
46
- // Example: Create a deposit
47
- const deposit = await sdk.deposit({
48
- // Deposit parameters
49
- });
50
-
51
- // Example: Create a withdrawal
52
- const withdrawal = await sdk.withdraw({
53
- // Withdrawal parameters
54
- });
104
+ const contracts = sdk.createContractInstance(rpcUrl, chain, entrypointAddress, privateKey);
55
105
  ```
56
106
 
57
- For detailed usage examples and API documentation, please refer to our [documentation](https://github.com/defi-wonderland/privacy-pool-core/tree/main/docs).
107
+ ## Mnemonic Security
108
+
109
+ 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.
110
+
111
+ - **Never hardcode** mnemonics in source code or configuration files.
112
+ - **Never log or transmit** mnemonics in plaintext.
113
+ - **Store mnemonics** using OS-level secure storage (e.g. OS keychain, encrypted vault) — never in browser localStorage or unencrypted files.
114
+ - **Do not reuse** a single mnemonic across unrelated applications. A compromised mnemonic exposes all derived keys and the funds they control.
115
+ - 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.
116
+
117
+ ## Circuit Artifact Integrity
118
+
119
+ 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.
120
+
121
+ | Artifact | SHA-256 |
122
+ | --- | --- |
123
+ | `commitment.wasm` | `254d2130607182fd6fd1aee67971526b13cfe178c88e360da96dce92663828d8` |
124
+ | `commitment.vkey` | `7d48b4eb3dedc12fb774348287b587f0c18c3c7254cd60e9cf0f8b3636a570d8` |
125
+ | `commitment.zkey` | `494ae92d64098fda2a5649690ddc5821fcd7449ca5fe8ef99ee7447544d7e1f3` |
126
+ | `withdraw.wasm` | `36cda22791def3d520a55c0fc808369cd5849532a75fab65686e666ed3d55c10` |
127
+ | `withdraw.vkey` | `666bd0983b20c1611543b04f7712e067fbe8cad69f07ada8a310837ff398d21e` |
128
+ | `withdraw.zkey` | `2a893b42174c813566e5c40c715a8b90cd49fc4ecf384e3a6024158c3d6de677` |
129
+
130
+ You can independently verify these against the committed artifacts:
131
+
132
+ ```bash
133
+ shasum -a 256 packages/circuits/trusted-setup/final-keys/*.{vkey,zkey}
134
+ shasum -a 256 packages/circuits/build/*/*_js/*.wasm
135
+ ```
58
136
 
59
137
  ## Features
60
138
 
61
- - Deposit and withdrawal functionality
62
- - Zero-knowledge proof generation
63
- - Commitment management
64
- - Contract interactions
139
+ - Zero-knowledge proof generation and verification (commitments and withdrawals)
140
+ - Deterministic key derivation from BIP-39 mnemonics
141
+ - Account state recovery from on-chain events
142
+ - Commitment and Merkle proof utilities
143
+ - Contract interaction helpers
65
144
  - Type-safe API
66
145
 
67
146
  ## Contributing
@@ -1,4 +1,4 @@
1
- import { F as FetchArtifact } from './index-CRtEyHEf.js';
1
+ import { F as FetchArtifact } from './index-BjOXETm6.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'assert';
@@ -15,4 +15,4 @@ async function fetchVersionedArtifact(artifactUrl) {
15
15
  }
16
16
 
17
17
  export { fetchVersionedArtifact };
18
- //# sourceMappingURL=fetchArtifacts.esm-B6qveiM8.js.map
18
+ //# sourceMappingURL=fetchArtifacts.esm-B0qaot8v.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchArtifacts.esm-B6qveiM8.js","sources":["../../src/circuits/fetchArtifacts.esm.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAEO,eAAe,sBAAsB,CAC1C,WAAgB,EAAA;AAEhB,IAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC;AACpC,IAAA,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;AACtB,QAAA,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC;;AAEtC,IAAA,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,WAAW,EAAE;AACpC,IAAA,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC;AAC7B;;;;"}
1
+ {"version":3,"file":"fetchArtifacts.esm-B0qaot8v.js","sources":["../../src/circuits/fetchArtifacts.esm.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAEO,eAAe,sBAAsB,CAC1C,WAAgB,EAAA;AAEhB,IAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC;AACpC,IAAA,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;AACtB,QAAA,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC;;AAEtC,IAAA,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,WAAW,EAAE;AACpC,IAAA,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC;AAC7B;;;;"}
@@ -1,4 +1,4 @@
1
- import { F as FetchArtifact } from './index-CRtEyHEf.js';
1
+ import { F as FetchArtifact } from './index-BjOXETm6.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'assert';
@@ -28,4 +28,4 @@ async function fetchVersionedArtifact(artifactUrl) {
28
28
  }
29
29
 
30
30
  export { fetchVersionedArtifact };
31
- //# sourceMappingURL=fetchArtifacts.node-BPQQPsnb.js.map
31
+ //# sourceMappingURL=fetchArtifacts.node-PzijuwVc.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchArtifacts.node-BPQQPsnb.js","sources":["../../src/circuits/fetchArtifacts.node.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAEO,eAAe,sBAAsB,CAC1C,WAAgB,EAAA;AAEhB,IAAA,IAAI;QACF,MAAM,EAAE,GAAG,CAAC,MAAM,OAAO,IAAI,CAAC,EAAE,OAAO;QACvC,MAAM,WAAW,GAAoB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;AACnE,YAAA,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,KAAI;gBAC9C,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,GAAG,CAAC;;qBACN;oBACL,OAAO,CAAC,IAAI,CAAC;;AAEjB,aAAC,CAAC;AACJ,SAAC,CAAC;AACF,QAAA,MAAM,GAAG,GAAG,MAAM,WAAW;AAC7B,QAAA,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC;;IAC1B,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AACpB,QAAA,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC;;AAExC;;;;"}
1
+ {"version":3,"file":"fetchArtifacts.node-PzijuwVc.js","sources":["../../src/circuits/fetchArtifacts.node.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAEO,eAAe,sBAAsB,CAC1C,WAAgB,EAAA;AAEhB,IAAA,IAAI;QACF,MAAM,EAAE,GAAG,CAAC,MAAM,OAAO,IAAI,CAAC,EAAE,OAAO;QACvC,MAAM,WAAW,GAAoB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;AACnE,YAAA,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,KAAI;gBAC9C,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,GAAG,CAAC;;qBACN;oBACL,OAAO,CAAC,IAAI,CAAC;;AAEjB,aAAC,CAAC;AACJ,SAAC,CAAC;AACF,QAAA,MAAM,GAAG,GAAG,MAAM,WAAW;AAC7B,QAAA,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC;;IAC1B,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AACpB,QAAA,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC;;AAExC;;;;"}