@0xbow/privacy-pools-core-sdk 1.1.1 → 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-DbVRphob.js → fetchArtifacts.esm-B0qaot8v.js} +2 -2
  3. package/dist/esm/{fetchArtifacts.esm-DbVRphob.js.map → fetchArtifacts.esm-B0qaot8v.js.map} +1 -1
  4. package/dist/esm/{fetchArtifacts.node-D-fJGtzV.js → fetchArtifacts.node-PzijuwVc.js} +2 -2
  5. package/dist/esm/{fetchArtifacts.node-D-fJGtzV.js.map → fetchArtifacts.node-PzijuwVc.js.map} +1 -1
  6. package/dist/esm/{index-DkNRxKxP.js → index-BjOXETm6.js} +312 -315
  7. package/dist/esm/{index-DkNRxKxP.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-BIT-b_1_.js → fetchArtifacts.esm-B6uU6QdA.js} +2 -2
  11. package/dist/node/{fetchArtifacts.esm-BIT-b_1_.js.map → fetchArtifacts.esm-B6uU6QdA.js.map} +1 -1
  12. package/dist/node/{fetchArtifacts.node-CKwwU50E.js → fetchArtifacts.node-CZRy6KmV.js} +2 -2
  13. package/dist/node/{fetchArtifacts.node-CKwwU50E.js.map → fetchArtifacts.node-CZRy6KmV.js.map} +1 -1
  14. package/dist/node/{index-C3RV9Cri.js → index-b-U_m4Mi.js} +333 -336
  15. package/dist/node/{index-C3RV9Cri.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-DT5RuODl.js → fetchArtifacts.esm-BKxGrC6w.js} +1 -1
  21. package/dist/types/{fetchArtifacts.node-D_iVIPqW.js → fetchArtifacts.node-kXMUDgNn.js} +1 -1
  22. package/dist/types/{index-CHy3YamH.js → index-BwyNuaY0.js} +332 -335
  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 -10
  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
@@ -1,4 +1,4 @@
1
- export { o as AccountError, A as AccountService, B as BlockchainProvider, p as CircuitName, k as Circuits, C as CommitmentService, n as ContractError, l as ContractInteractionsService, a as DEFAULT_LOG_FETCH_CONFIG, D as DataService, E as ErrorCode, I as InvalidRpcUrl, P as PrivacyPoolSDK, m as ProofError, S as SDKError, W as WithdrawalService, f as bigintToHash, i as bigintToHex, j as calculateContext, b as generateDepositSecrets, g as generateMasterKeys, e as generateMerkleProof, c as generateWithdrawalSecrets, d as getCommitment, h as hashPrecommitment } from './index-C3RV9Cri.js';
1
+ export { o as AccountError, A as AccountService, B as BlockchainProvider, p as CircuitName, k as Circuits, C as CommitmentService, n as ContractError, l as ContractInteractionsService, a as DEFAULT_LOG_FETCH_CONFIG, D as DataService, E as ErrorCode, I as InvalidRpcUrl, P as PrivacyPoolSDK, m as ProofError, S as SDKError, W as WithdrawalService, f as bigintToHash, i as bigintToHex, j as calculateContext, b as generateDepositSecrets, g as generateMasterKeys, e as generateMerkleProof, c as generateWithdrawalSecrets, d as getCommitment, h as hashPrecommitment } from './index-b-U_m4Mi.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'http';
@@ -0,0 +1,19 @@
1
+ import { CircuitNameString } from "./circuits.interface.js";
2
+ type ArtifactType = "wasm" | "vkey" | "zkey";
3
+ /**
4
+ * Expected SHA-256 hex digests for every downloaded circuit artifact.
5
+ *
6
+ * vkey and zkey hashes are derived from the trusted-setup ceremony outputs
7
+ * committed in packages/circuits/trusted-setup/final-keys/.
8
+ *
9
+ * wasm hashes are derived from the compiled circuit outputs
10
+ * in packages/circuits/build/.
11
+ *
12
+ * Every artifact downloaded by the SDK MUST have a hash entry here.
13
+ * verifyArtifactIntegrity throws if a hash is missing — refusing to
14
+ * load unverified artifacts is the correct security posture.
15
+ */
16
+ export declare const ARTIFACT_HASHES: Record<CircuitNameString, Partial<Record<ArtifactType, string>>>;
17
+ export declare function sha256Hex(data: Uint8Array): Promise<string>;
18
+ export declare function verifyArtifactIntegrity(circuitName: CircuitNameString, artifactType: ArtifactType, data: Uint8Array): Promise<void>;
19
+ export {};
@@ -35,6 +35,22 @@ export declare class AccountService {
35
35
  * @throws {AccountError} If account initialization fails
36
36
  */
37
37
  constructor(dataService: DataService, config: AccountServiceConfig);
38
+ /**
39
+ * Initializes a new account from a mnemonic phrase for the legacy account.
40
+ *
41
+ * @param mnemonic - The mnemonic phrase to derive keys from
42
+ * @returns A new PrivacyPoolAccount with derived master keys
43
+ *
44
+ * @remarks
45
+ * This method derives two master keys from the mnemonic:
46
+ * 1. A master nullifier key from account index 0
47
+ * 2. A master secret key from account index 1
48
+ * These keys are used to deterministically generate nullifiers and secrets for deposits and withdrawals.
49
+ *
50
+ * @throws {AccountError} If account initialization fails
51
+ * @private
52
+ */
53
+ protected static _initializeLegacyAccount(mnemonic: string): PrivacyPoolAccount;
38
54
  /**
39
55
  * Initializes a new account from a mnemonic phrase.
40
56
  *
@@ -187,6 +203,25 @@ export declare class AccountService {
187
203
  * @throws {AccountError} If no account is found for the commitment
188
204
  */
189
205
  addWithdrawalCommitment(parentCommitment: AccountCommitment, value: bigint, nullifier: Secret, secret: Secret, blockNumber: bigint, txHash: Hex): AccountCommitment;
206
+ /**
207
+ * Adds a new commitment to the account after migrate
208
+ *
209
+ * @param parentCommitment - The commitment that was spent
210
+ * @param value - The remaining value after spending
211
+ * @param nullifier - The nullifier used for migrate
212
+ * @param secret - The secret used for migrate
213
+ * @param blockNumber - The block number of the withdrawal
214
+ * @param txHash - The transaction hash of the withdrawal
215
+ * @returns The new commitment
216
+ *
217
+ * @remarks
218
+ * This method finds the account containing the parent commitment, creates a new
219
+ * commitment with the provided parameters, and adds it to the account's children.
220
+ * The new commitment inherits the label from the parent commitment.
221
+ *
222
+ * @throws {AccountError} If no account is found for the commitment
223
+ */
224
+ addMigrationCommitment(parentCommitment: AccountCommitment, value: bigint, nullifier: Secret, secret: Secret, blockNumber: bigint, txHash: Hex): AccountCommitment;
190
225
  /**
191
226
  * Adds a ragequit event to an existing pool account
192
227
  *
@@ -277,6 +312,25 @@ export declare class AccountService {
277
312
  *
278
313
  */
279
314
  private _processRagequitEvents;
315
+ /**
316
+ * Discovers commitments that were migrated from legacy accounts via 0-value withdrawal.
317
+ *
318
+ * @param scope - The scope of the pool
319
+ * @param legacyAccounts - The legacy pool accounts for this scope
320
+ * @param withdrawalEvents - The map of withdrawal events (keyed by spentNullifier)
321
+ *
322
+ * @remarks
323
+ * When a legacy account performs a 0-value withdrawal to rotate keys (migration),
324
+ * the resulting on-chain commitment is created with safe keys. This method finds
325
+ * those commitments by:
326
+ * 1. Identifying legacy accounts with the `isMigrated` flag (set by `addMigrationCommitment`)
327
+ * 2. Computing the expected commitment hash using safe keys at withdrawal index 0
328
+ * 3. Verifying the hash exists in on-chain withdrawal events
329
+ * 4. Adding verified commitments as new safe pool accounts
330
+ *
331
+ * @private
332
+ */
333
+ private _discoverMigratedCommitments;
280
334
  /**
281
335
  * Initializes an AccountService instance with events for a given set of pools
282
336
  *
@@ -304,8 +358,33 @@ export declare class AccountService {
304
358
  service: AccountService;
305
359
  }, pools: PoolInfo[]): Promise<{
306
360
  account: AccountService;
361
+ legacyAccount?: AccountService;
307
362
  errors: PoolEventsError[];
308
363
  }>;
364
+ /**
365
+ * Fetches and processes events for a set of pools.
366
+ *
367
+ * When a legacyAccount is provided, the full migration-aware pipeline runs
368
+ * for each scope:
369
+ * 1. Legacy account: process deposits and withdrawals (to detect migrations)
370
+ * 2. Safe account: discover migrated commitments from the legacy accounts
371
+ * 3. Safe account (this): process deposits (starting after migrated accounts)
372
+ * 4. Safe account: process withdrawals (now includes migrated accounts)
373
+ * 5. Both accounts: process ragequits
374
+ *
375
+ * Migration discovery (step 2) must run before safe deposit scanning (step 3)
376
+ * so that the migrated account count can be used as the starting index.
377
+ * Post-migration deposits use poolAccounts.length as their index, which
378
+ * sits right after the migrated slots; scanning from 0 would hit
379
+ * MAX_CONSECUTIVE_MISSES on the legacy-key indices and never reach them.
380
+ *
381
+ * Without a legacyAccount, only steps 3, 4, and 5 run (simple processing).
382
+ *
383
+ * Per-scope errors are caught and returned rather than thrown, and any
384
+ * partial state left by a mid-scope failure is cleaned from both accounts
385
+ * so that a subsequent retry starts fresh for that scope.
386
+ */
387
+ private _processEvents;
309
388
  /**
310
389
  * @deprecated Use `initializeWithEvents` for instantiating an account with history reconstruction
311
390
  * Retrieves the history of deposits and withdrawals for the given pools.
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { F as FetchArtifact } from './index-CHy3YamH.js';
1
+ import { F as FetchArtifact } from './index-BwyNuaY0.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'http';
@@ -1,4 +1,4 @@
1
- import { F as FetchArtifact } from './index-CHy3YamH.js';
1
+ import { F as FetchArtifact } from './index-BwyNuaY0.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'http';