@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.
- package/README.md +102 -23
- package/dist/esm/{fetchArtifacts.esm-B6qveiM8.js → fetchArtifacts.esm-B0qaot8v.js} +2 -2
- package/dist/esm/{fetchArtifacts.esm-B6qveiM8.js.map → fetchArtifacts.esm-B0qaot8v.js.map} +1 -1
- package/dist/esm/{fetchArtifacts.node-BPQQPsnb.js → fetchArtifacts.node-PzijuwVc.js} +2 -2
- package/dist/esm/{fetchArtifacts.node-BPQQPsnb.js.map → fetchArtifacts.node-PzijuwVc.js.map} +1 -1
- package/dist/esm/{index-CRtEyHEf.js → index-BjOXETm6.js} +316 -316
- package/dist/esm/{index-CRtEyHEf.js.map → index-BjOXETm6.js.map} +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/index.d.mts +81 -0
- package/dist/node/{fetchArtifacts.esm-z-KXbilc.js → fetchArtifacts.esm-B6uU6QdA.js} +2 -2
- package/dist/node/{fetchArtifacts.esm-z-KXbilc.js.map → fetchArtifacts.esm-B6uU6QdA.js.map} +1 -1
- package/dist/node/{fetchArtifacts.node-DvqhqpW9.js → fetchArtifacts.node-CZRy6KmV.js} +2 -2
- package/dist/node/{fetchArtifacts.node-DvqhqpW9.js.map → fetchArtifacts.node-CZRy6KmV.js.map} +1 -1
- package/dist/node/{index-BsmEKESv.js → index-b-U_m4Mi.js} +337 -337
- package/dist/node/{index-BsmEKESv.js.map → index-b-U_m4Mi.js.map} +1 -1
- package/dist/node/index.mjs +1 -1
- package/dist/types/circuits/artifactHashes.d.ts +19 -0
- package/dist/types/core/account.service.d.ts +79 -0
- package/dist/types/core/tmp.d.ts +1 -0
- package/dist/types/{fetchArtifacts.esm-DF01Zpo3.js → fetchArtifacts.esm-BKxGrC6w.js} +1 -1
- package/dist/types/{fetchArtifacts.node-BO6FBCAw.js → fetchArtifacts.node-kXMUDgNn.js} +1 -1
- package/dist/types/{index-CH7gk4sK.js → index-BwyNuaY0.js} +336 -336
- package/dist/types/index.js +1 -1
- package/dist/types/types/account.d.ts +2 -0
- package/package.json +1 -1
- package/src/circuits/artifactHashes.ts +74 -0
- package/src/circuits/circuits.impl.ts +8 -0
- package/src/core/account.service.ts +329 -35
- package/src/core/data.service.ts +3 -9
- package/src/core/tmp.ts +4 -0
- package/src/crypto.ts +5 -6
- package/src/types/account.ts +3 -1
- package/dist/types/keys.d.ts +0 -18
- package/src/keys.ts +0 -42
package/dist/esm/index.mjs
CHANGED
|
@@ -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-
|
|
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-BjOXETm6.js';
|
|
2
2
|
import 'viem/accounts';
|
|
3
3
|
import 'buffer';
|
|
4
4
|
import 'assert';
|
package/dist/index.d.mts
CHANGED
|
@@ -694,6 +694,7 @@ interface PoolAccount {
|
|
|
694
694
|
deposit: AccountCommitment;
|
|
695
695
|
children: AccountCommitment[];
|
|
696
696
|
ragequit?: RagequitEvent;
|
|
697
|
+
isMigrated?: boolean;
|
|
697
698
|
}
|
|
698
699
|
interface AccountCommitment {
|
|
699
700
|
hash: Hash;
|
|
@@ -704,6 +705,7 @@ interface AccountCommitment {
|
|
|
704
705
|
blockNumber: bigint;
|
|
705
706
|
timestamp?: bigint;
|
|
706
707
|
txHash: Hex;
|
|
708
|
+
isMigration?: boolean;
|
|
707
709
|
}
|
|
708
710
|
interface PrivacyPoolAccount {
|
|
709
711
|
masterKeys: [masterNullifier: Secret, masterSecret: Secret];
|
|
@@ -982,6 +984,22 @@ declare class AccountService {
|
|
|
982
984
|
* @throws {AccountError} If account initialization fails
|
|
983
985
|
*/
|
|
984
986
|
constructor(dataService: DataService, config: AccountServiceConfig);
|
|
987
|
+
/**
|
|
988
|
+
* Initializes a new account from a mnemonic phrase for the legacy account.
|
|
989
|
+
*
|
|
990
|
+
* @param mnemonic - The mnemonic phrase to derive keys from
|
|
991
|
+
* @returns A new PrivacyPoolAccount with derived master keys
|
|
992
|
+
*
|
|
993
|
+
* @remarks
|
|
994
|
+
* This method derives two master keys from the mnemonic:
|
|
995
|
+
* 1. A master nullifier key from account index 0
|
|
996
|
+
* 2. A master secret key from account index 1
|
|
997
|
+
* These keys are used to deterministically generate nullifiers and secrets for deposits and withdrawals.
|
|
998
|
+
*
|
|
999
|
+
* @throws {AccountError} If account initialization fails
|
|
1000
|
+
* @private
|
|
1001
|
+
*/
|
|
1002
|
+
protected static _initializeLegacyAccount(mnemonic: string): PrivacyPoolAccount;
|
|
985
1003
|
/**
|
|
986
1004
|
* Initializes a new account from a mnemonic phrase.
|
|
987
1005
|
*
|
|
@@ -1134,6 +1152,25 @@ declare class AccountService {
|
|
|
1134
1152
|
* @throws {AccountError} If no account is found for the commitment
|
|
1135
1153
|
*/
|
|
1136
1154
|
addWithdrawalCommitment(parentCommitment: AccountCommitment, value: bigint, nullifier: Secret, secret: Secret, blockNumber: bigint, txHash: Hex): AccountCommitment;
|
|
1155
|
+
/**
|
|
1156
|
+
* Adds a new commitment to the account after migrate
|
|
1157
|
+
*
|
|
1158
|
+
* @param parentCommitment - The commitment that was spent
|
|
1159
|
+
* @param value - The remaining value after spending
|
|
1160
|
+
* @param nullifier - The nullifier used for migrate
|
|
1161
|
+
* @param secret - The secret used for migrate
|
|
1162
|
+
* @param blockNumber - The block number of the withdrawal
|
|
1163
|
+
* @param txHash - The transaction hash of the withdrawal
|
|
1164
|
+
* @returns The new commitment
|
|
1165
|
+
*
|
|
1166
|
+
* @remarks
|
|
1167
|
+
* This method finds the account containing the parent commitment, creates a new
|
|
1168
|
+
* commitment with the provided parameters, and adds it to the account's children.
|
|
1169
|
+
* The new commitment inherits the label from the parent commitment.
|
|
1170
|
+
*
|
|
1171
|
+
* @throws {AccountError} If no account is found for the commitment
|
|
1172
|
+
*/
|
|
1173
|
+
addMigrationCommitment(parentCommitment: AccountCommitment, value: bigint, nullifier: Secret, secret: Secret, blockNumber: bigint, txHash: Hex): AccountCommitment;
|
|
1137
1174
|
/**
|
|
1138
1175
|
* Adds a ragequit event to an existing pool account
|
|
1139
1176
|
*
|
|
@@ -1224,6 +1261,25 @@ declare class AccountService {
|
|
|
1224
1261
|
*
|
|
1225
1262
|
*/
|
|
1226
1263
|
private _processRagequitEvents;
|
|
1264
|
+
/**
|
|
1265
|
+
* Discovers commitments that were migrated from legacy accounts via 0-value withdrawal.
|
|
1266
|
+
*
|
|
1267
|
+
* @param scope - The scope of the pool
|
|
1268
|
+
* @param legacyAccounts - The legacy pool accounts for this scope
|
|
1269
|
+
* @param withdrawalEvents - The map of withdrawal events (keyed by spentNullifier)
|
|
1270
|
+
*
|
|
1271
|
+
* @remarks
|
|
1272
|
+
* When a legacy account performs a 0-value withdrawal to rotate keys (migration),
|
|
1273
|
+
* the resulting on-chain commitment is created with safe keys. This method finds
|
|
1274
|
+
* those commitments by:
|
|
1275
|
+
* 1. Identifying legacy accounts with the `isMigrated` flag (set by `addMigrationCommitment`)
|
|
1276
|
+
* 2. Computing the expected commitment hash using safe keys at withdrawal index 0
|
|
1277
|
+
* 3. Verifying the hash exists in on-chain withdrawal events
|
|
1278
|
+
* 4. Adding verified commitments as new safe pool accounts
|
|
1279
|
+
*
|
|
1280
|
+
* @private
|
|
1281
|
+
*/
|
|
1282
|
+
private _discoverMigratedCommitments;
|
|
1227
1283
|
/**
|
|
1228
1284
|
* Initializes an AccountService instance with events for a given set of pools
|
|
1229
1285
|
*
|
|
@@ -1251,8 +1307,33 @@ declare class AccountService {
|
|
|
1251
1307
|
service: AccountService;
|
|
1252
1308
|
}, pools: PoolInfo[]): Promise<{
|
|
1253
1309
|
account: AccountService;
|
|
1310
|
+
legacyAccount?: AccountService;
|
|
1254
1311
|
errors: PoolEventsError[];
|
|
1255
1312
|
}>;
|
|
1313
|
+
/**
|
|
1314
|
+
* Fetches and processes events for a set of pools.
|
|
1315
|
+
*
|
|
1316
|
+
* When a legacyAccount is provided, the full migration-aware pipeline runs
|
|
1317
|
+
* for each scope:
|
|
1318
|
+
* 1. Legacy account: process deposits and withdrawals (to detect migrations)
|
|
1319
|
+
* 2. Safe account: discover migrated commitments from the legacy accounts
|
|
1320
|
+
* 3. Safe account (this): process deposits (starting after migrated accounts)
|
|
1321
|
+
* 4. Safe account: process withdrawals (now includes migrated accounts)
|
|
1322
|
+
* 5. Both accounts: process ragequits
|
|
1323
|
+
*
|
|
1324
|
+
* Migration discovery (step 2) must run before safe deposit scanning (step 3)
|
|
1325
|
+
* so that the migrated account count can be used as the starting index.
|
|
1326
|
+
* Post-migration deposits use poolAccounts.length as their index, which
|
|
1327
|
+
* sits right after the migrated slots; scanning from 0 would hit
|
|
1328
|
+
* MAX_CONSECUTIVE_MISSES on the legacy-key indices and never reach them.
|
|
1329
|
+
*
|
|
1330
|
+
* Without a legacyAccount, only steps 3, 4, and 5 run (simple processing).
|
|
1331
|
+
*
|
|
1332
|
+
* Per-scope errors are caught and returned rather than thrown, and any
|
|
1333
|
+
* partial state left by a mid-scope failure is cleaned from both accounts
|
|
1334
|
+
* so that a subsequent retry starts fresh for that scope.
|
|
1335
|
+
*/
|
|
1336
|
+
private _processEvents;
|
|
1256
1337
|
/**
|
|
1257
1338
|
* @deprecated Use `initializeWithEvents` for instantiating an account with history reconstruction
|
|
1258
1339
|
* Retrieves the history of deposits and withdrawals for the given pools.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as FetchArtifact } from './index-
|
|
1
|
+
import { F as FetchArtifact } from './index-b-U_m4Mi.js';
|
|
2
2
|
import 'viem/accounts';
|
|
3
3
|
import 'buffer';
|
|
4
4
|
import 'http';
|
|
@@ -32,4 +32,4 @@ async function fetchVersionedArtifact(artifactUrl) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export { fetchVersionedArtifact };
|
|
35
|
-
//# sourceMappingURL=fetchArtifacts.esm-
|
|
35
|
+
//# sourceMappingURL=fetchArtifacts.esm-B6uU6QdA.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchArtifacts.esm-
|
|
1
|
+
{"version":3,"file":"fetchArtifacts.esm-B6uU6QdA.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-
|
|
1
|
+
import { F as FetchArtifact } from './index-b-U_m4Mi.js';
|
|
2
2
|
import 'viem/accounts';
|
|
3
3
|
import 'buffer';
|
|
4
4
|
import 'http';
|
|
@@ -45,4 +45,4 @@ async function fetchVersionedArtifact(artifactUrl) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export { fetchVersionedArtifact };
|
|
48
|
-
//# sourceMappingURL=fetchArtifacts.node-
|
|
48
|
+
//# sourceMappingURL=fetchArtifacts.node-CZRy6KmV.js.map
|
package/dist/node/{fetchArtifacts.node-DvqhqpW9.js.map → fetchArtifacts.node-CZRy6KmV.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchArtifacts.node-
|
|
1
|
+
{"version":3,"file":"fetchArtifacts.node-CZRy6KmV.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;;;;"}
|