@0xbow/privacy-pools-core-sdk 0.1.19 → 0.1.21
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/dist/esm/{fetchArtifacts.esm-DYA5xgwo.js → fetchArtifacts.esm-CXLPgzhJ.js} +2 -2
- package/dist/esm/{fetchArtifacts.esm-DYA5xgwo.js.map → fetchArtifacts.esm-CXLPgzhJ.js.map} +1 -1
- package/dist/esm/{fetchArtifacts.node-nt928XQR.js → fetchArtifacts.node-B3pPMuWd.js} +2 -2
- package/dist/esm/{fetchArtifacts.node-nt928XQR.js.map → fetchArtifacts.node-B3pPMuWd.js.map} +1 -1
- package/dist/esm/{index-IxAruGRY.js → index-C_oO7cOn.js} +38 -350
- package/dist/esm/index-C_oO7cOn.js.map +1 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/index.d.mts +46 -169
- package/dist/node/{fetchArtifacts.esm-DkDPFXn4.js → fetchArtifacts.esm-DoJiimN3.js} +2 -2
- package/dist/node/{fetchArtifacts.esm-DkDPFXn4.js.map → fetchArtifacts.esm-DoJiimN3.js.map} +1 -1
- package/dist/node/{fetchArtifacts.node-C3SnDq3C.js → fetchArtifacts.node-B4Ey9DOV.js} +2 -2
- package/dist/node/{fetchArtifacts.node-C3SnDq3C.js.map → fetchArtifacts.node-B4Ey9DOV.js.map} +1 -1
- package/dist/node/{index-D8Hrpc7M.js → index-CwopFzOC.js} +38 -350
- package/dist/node/index-CwopFzOC.js.map +1 -0
- package/dist/node/index.mjs +1 -1
- package/dist/types/core/account.service.d.ts +4 -116
- package/dist/types/core/sdk.d.ts +1 -2
- package/dist/types/core/withdrawal.service.d.ts +2 -2
- package/dist/types/errors/account.error.d.ts +0 -2
- package/dist/types/{fetchArtifacts.esm-4yQJboFd.js → fetchArtifacts.esm-CxFhH8oR.js} +1 -1
- package/dist/types/{fetchArtifacts.node-C5d2dtAy.js → fetchArtifacts.node-Cqk_Z-mS.js} +1 -1
- package/dist/types/{index-CdgQB9Pw.js → index-CIvuCHHq.js} +37 -349
- package/dist/types/index.js +1 -1
- package/dist/types/types/events.d.ts +1 -11
- package/package.json +1 -1
- package/src/core/account.service.ts +64 -459
- package/src/core/data.service.ts +5 -4
- package/src/core/sdk.ts +1 -2
- package/src/core/withdrawal.service.ts +9 -25
- package/src/errors/account.error.ts +0 -14
- package/src/types/events.ts +1 -15
- package/dist/esm/index-IxAruGRY.js.map +0 -1
- package/dist/node/index-D8Hrpc7M.js.map +0 -1
- package/dist/types/errors/events.error.d.ts +0 -9
- package/src/errors/events.error.ts +0 -38
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as FetchArtifact } from './index-
|
|
1
|
+
import { F as FetchArtifact } from './index-C_oO7cOn.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-
|
|
18
|
+
//# sourceMappingURL=fetchArtifacts.esm-CXLPgzhJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchArtifacts.esm-
|
|
1
|
+
{"version":3,"file":"fetchArtifacts.esm-CXLPgzhJ.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-C_oO7cOn.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-
|
|
31
|
+
//# sourceMappingURL=fetchArtifacts.node-B3pPMuWd.js.map
|
package/dist/esm/{fetchArtifacts.node-nt928XQR.js.map → fetchArtifacts.node-B3pPMuWd.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchArtifacts.node-
|
|
1
|
+
{"version":3,"file":"fetchArtifacts.node-B3pPMuWd.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;;;;"}
|
|
@@ -45815,10 +45815,10 @@ const circuitToAsset = {
|
|
|
45815
45815
|
|
|
45816
45816
|
async function importFetchVersionedArtifact(isBrowser) {
|
|
45817
45817
|
if (isBrowser) {
|
|
45818
|
-
return import('./fetchArtifacts.esm-
|
|
45818
|
+
return import('./fetchArtifacts.esm-CXLPgzhJ.js');
|
|
45819
45819
|
}
|
|
45820
45820
|
else {
|
|
45821
|
-
return import('./fetchArtifacts.node-
|
|
45821
|
+
return import('./fetchArtifacts.node-B3pPMuWd.js');
|
|
45822
45822
|
}
|
|
45823
45823
|
}
|
|
45824
45824
|
|
|
@@ -69145,22 +69145,6 @@ class WithdrawalService {
|
|
|
69145
69145
|
* Prepares input signals for the withdrawal circuit.
|
|
69146
69146
|
*/
|
|
69147
69147
|
prepareInputSignals(commitment, input) {
|
|
69148
|
-
let existingValue;
|
|
69149
|
-
let existingNullifier;
|
|
69150
|
-
let existingSecret;
|
|
69151
|
-
let label;
|
|
69152
|
-
if ("preimage" in commitment) {
|
|
69153
|
-
existingValue = commitment.preimage.value;
|
|
69154
|
-
existingNullifier = commitment.preimage.precommitment.nullifier;
|
|
69155
|
-
existingSecret = commitment.preimage.precommitment.secret;
|
|
69156
|
-
label = commitment.preimage.label;
|
|
69157
|
-
}
|
|
69158
|
-
else {
|
|
69159
|
-
existingValue = commitment.value;
|
|
69160
|
-
existingNullifier = commitment.nullifier;
|
|
69161
|
-
existingSecret = commitment.secret;
|
|
69162
|
-
label = commitment.label;
|
|
69163
|
-
}
|
|
69164
69148
|
return {
|
|
69165
69149
|
// Public signals
|
|
69166
69150
|
withdrawnValue: input.withdrawalAmount,
|
|
@@ -69170,10 +69154,10 @@ class WithdrawalService {
|
|
|
69170
69154
|
ASPTreeDepth: input.aspTreeDepth,
|
|
69171
69155
|
context: input.context,
|
|
69172
69156
|
// Private signals
|
|
69173
|
-
label,
|
|
69174
|
-
existingValue,
|
|
69175
|
-
existingNullifier,
|
|
69176
|
-
existingSecret,
|
|
69157
|
+
label: commitment.preimage.label,
|
|
69158
|
+
existingValue: commitment.preimage.value,
|
|
69159
|
+
existingNullifier: commitment.preimage.precommitment.nullifier,
|
|
69160
|
+
existingSecret: commitment.preimage.precommitment.secret,
|
|
69177
69161
|
newNullifier: input.newNullifier,
|
|
69178
69162
|
newSecret: input.newSecret,
|
|
69179
69163
|
// Merkle Proofs
|
|
@@ -69253,12 +69237,6 @@ class AccountError extends SDKError {
|
|
|
69253
69237
|
static accountInitializationFailed(reason) {
|
|
69254
69238
|
return new AccountError(`Failed to initialize account: ${reason}`, ErrorCode.OPERATION_FAILED);
|
|
69255
69239
|
}
|
|
69256
|
-
static duplicatePools(scope) {
|
|
69257
|
-
return new AccountError(`Duplicate pools found for scope: ${scope.toString()}`, ErrorCode.INVALID_INPUT);
|
|
69258
|
-
}
|
|
69259
|
-
static invalidIndex(index) {
|
|
69260
|
-
return new AccountError(`Invalid index: ${index.toString()}`, ErrorCode.INVALID_INPUT);
|
|
69261
|
-
}
|
|
69262
69240
|
}
|
|
69263
69241
|
|
|
69264
69242
|
var LogLevel;
|
|
@@ -69302,38 +69280,6 @@ class Logger {
|
|
|
69302
69280
|
}
|
|
69303
69281
|
}
|
|
69304
69282
|
|
|
69305
|
-
class DataError extends SDKError {
|
|
69306
|
-
constructor(message, code = ErrorCode.NETWORK_ERROR, details) {
|
|
69307
|
-
super(message, code, details);
|
|
69308
|
-
this.name = "DataError";
|
|
69309
|
-
}
|
|
69310
|
-
static invalidLog(type, reason) {
|
|
69311
|
-
return new DataError(`Invalid ${type} log: ${reason}`, ErrorCode.INVALID_INPUT);
|
|
69312
|
-
}
|
|
69313
|
-
static chainNotConfigured(chainId) {
|
|
69314
|
-
return new DataError(`No configuration found for chain ID ${chainId}`, ErrorCode.INVALID_INPUT);
|
|
69315
|
-
}
|
|
69316
|
-
static networkError(chainId, error) {
|
|
69317
|
-
return new DataError(`Network error on chain ${chainId}: ${error.message}`, ErrorCode.NETWORK_ERROR, { originalError: error });
|
|
69318
|
-
}
|
|
69319
|
-
}
|
|
69320
|
-
|
|
69321
|
-
class EventError extends DataError {
|
|
69322
|
-
constructor(message, code = ErrorCode.NETWORK_ERROR, details) {
|
|
69323
|
-
super(message, code, details);
|
|
69324
|
-
this.name = "EventError";
|
|
69325
|
-
}
|
|
69326
|
-
static depositEventError(chainId, scope, error) {
|
|
69327
|
-
return new EventError(`Error fetching deposit events for chain ${chainId}: ${error.message}`, ErrorCode.NETWORK_ERROR, { originalError: error, scope });
|
|
69328
|
-
}
|
|
69329
|
-
static withdrawalEventError(chainId, scope, error) {
|
|
69330
|
-
return new EventError(`Error fetching withdrawal events for chain ${chainId}: ${error.message}`, ErrorCode.NETWORK_ERROR, { originalError: error, scope });
|
|
69331
|
-
}
|
|
69332
|
-
static ragequitEventError(chainId, scope, error) {
|
|
69333
|
-
return new EventError(`Error fetching ragequit events for chain ${chainId}: ${error.message}`, ErrorCode.NETWORK_ERROR, { originalError: error, scope });
|
|
69334
|
-
}
|
|
69335
|
-
}
|
|
69336
|
-
|
|
69337
69283
|
/**
|
|
69338
69284
|
* Service responsible for managing privacy pool accounts and their associated commitments.
|
|
69339
69285
|
* Handles account initialization, deposit/withdrawal tracking, and history synchronization.
|
|
@@ -69350,21 +69296,15 @@ class AccountService {
|
|
|
69350
69296
|
* Creates a new AccountService instance.
|
|
69351
69297
|
*
|
|
69352
69298
|
* @param dataService - Service for fetching on-chain events
|
|
69353
|
-
* @param
|
|
69354
|
-
* @param
|
|
69355
|
-
* @param config.account - Optional existing account to initialize with
|
|
69299
|
+
* @param account - Optional existing account to initialize with
|
|
69300
|
+
* @param mnemonic - Optional mnemonic for deterministic key generation
|
|
69356
69301
|
*
|
|
69357
69302
|
* @throws {AccountError} If account initialization fails
|
|
69358
69303
|
*/
|
|
69359
|
-
constructor(dataService,
|
|
69304
|
+
constructor(dataService, mnemonic, account) {
|
|
69360
69305
|
this.dataService = dataService;
|
|
69361
69306
|
this.logger = new Logger({ prefix: "Account" });
|
|
69362
|
-
|
|
69363
|
-
this.account = this._initializeAccount(config.mnemonic);
|
|
69364
|
-
}
|
|
69365
|
-
else {
|
|
69366
|
-
this.account = config.account;
|
|
69367
|
-
}
|
|
69307
|
+
this.account = account || this._initializeAccount(mnemonic);
|
|
69368
69308
|
}
|
|
69369
69309
|
/**
|
|
69370
69310
|
* Initializes a new account from a mnemonic phrase.
|
|
@@ -69392,7 +69332,7 @@ class AccountService {
|
|
|
69392
69332
|
masterKeys: [masterNullifier, masterSecret],
|
|
69393
69333
|
poolAccounts: new Map(),
|
|
69394
69334
|
creationTimestamp: 0n,
|
|
69395
|
-
lastUpdateTimestamp: 0n
|
|
69335
|
+
lastUpdateTimestamp: 0n
|
|
69396
69336
|
};
|
|
69397
69337
|
}
|
|
69398
69338
|
catch (error) {
|
|
@@ -69514,11 +69454,8 @@ class AccountService {
|
|
|
69514
69454
|
* The precommitment is a hash of the nullifier and secret, used in the deposit process.
|
|
69515
69455
|
*/
|
|
69516
69456
|
createDepositSecrets(scope, index) {
|
|
69517
|
-
if (index && index < 0n) {
|
|
69518
|
-
throw AccountError.invalidIndex(index);
|
|
69519
|
-
}
|
|
69520
69457
|
const accounts = this.account.poolAccounts.get(scope);
|
|
69521
|
-
index = index
|
|
69458
|
+
index = index || BigInt(accounts?.length || 0);
|
|
69522
69459
|
const nullifier = this._genDepositNullifier(scope, index);
|
|
69523
69460
|
const secret = this._genDepositSecret(scope, index);
|
|
69524
69461
|
const precommitment = this._hashPrecommitment(nullifier, secret);
|
|
@@ -69676,272 +69613,6 @@ class AccountService {
|
|
|
69676
69613
|
return foundAccount;
|
|
69677
69614
|
}
|
|
69678
69615
|
/**
|
|
69679
|
-
* Fetches deposit events for a given pool and returns a map of precommitments to their events for efficient lookup
|
|
69680
|
-
*
|
|
69681
|
-
* @param pool - The pool to fetch deposit events for
|
|
69682
|
-
*
|
|
69683
|
-
* @returns A map of precommitments to their events
|
|
69684
|
-
*/
|
|
69685
|
-
async getDepositEvents(pool) {
|
|
69686
|
-
try {
|
|
69687
|
-
const depositEvents = await this.dataService.getDeposits(pool);
|
|
69688
|
-
this.logger.info(`Found deposits for pool`, {
|
|
69689
|
-
poolAddress: pool.address,
|
|
69690
|
-
poolChainId: pool.chainId,
|
|
69691
|
-
depositCount: depositEvents.length,
|
|
69692
|
-
});
|
|
69693
|
-
const depositMap = new Map();
|
|
69694
|
-
for (const event of depositEvents) {
|
|
69695
|
-
depositMap.set(event.precommitment, event);
|
|
69696
|
-
}
|
|
69697
|
-
return depositMap;
|
|
69698
|
-
}
|
|
69699
|
-
catch (error) {
|
|
69700
|
-
throw EventError.depositEventError(pool.chainId, pool.scope, error);
|
|
69701
|
-
}
|
|
69702
|
-
}
|
|
69703
|
-
/**
|
|
69704
|
-
* Fetches withdrawal events for a given pool and returns a map of spent nullifiers to their events for efficient lookup
|
|
69705
|
-
*
|
|
69706
|
-
* @param pool - The pool to fetch withdrawal events for
|
|
69707
|
-
*
|
|
69708
|
-
* @returns A map of spent nullifiers to their events
|
|
69709
|
-
*/
|
|
69710
|
-
async getWithdrawalEvents(pool) {
|
|
69711
|
-
try {
|
|
69712
|
-
const withdrawalEvents = await this.dataService.getWithdrawals(pool);
|
|
69713
|
-
const withdrawalMap = new Map();
|
|
69714
|
-
for (const event of withdrawalEvents) {
|
|
69715
|
-
withdrawalMap.set(event.spentNullifier, event);
|
|
69716
|
-
}
|
|
69717
|
-
return withdrawalMap;
|
|
69718
|
-
}
|
|
69719
|
-
catch (error) {
|
|
69720
|
-
throw EventError.withdrawalEventError(pool.chainId, pool.scope, error);
|
|
69721
|
-
}
|
|
69722
|
-
}
|
|
69723
|
-
/**
|
|
69724
|
-
* Fetches ragequit events for a given pool and returns a map of ragequit labels to their events for efficient lookup
|
|
69725
|
-
*
|
|
69726
|
-
* @param pool - The pool to fetch ragequit events for
|
|
69727
|
-
*
|
|
69728
|
-
* @returns A map of ragequit labels to their events
|
|
69729
|
-
*/
|
|
69730
|
-
async getRagequitEvents(pool) {
|
|
69731
|
-
try {
|
|
69732
|
-
const ragequitEvents = await this.dataService.getRagequits(pool);
|
|
69733
|
-
const ragequitMap = new Map();
|
|
69734
|
-
for (const event of ragequitEvents) {
|
|
69735
|
-
ragequitMap.set(event.label, event);
|
|
69736
|
-
}
|
|
69737
|
-
return ragequitMap;
|
|
69738
|
-
}
|
|
69739
|
-
catch (error) {
|
|
69740
|
-
throw EventError.ragequitEventError(pool.chainId, pool.scope, error);
|
|
69741
|
-
}
|
|
69742
|
-
}
|
|
69743
|
-
/**
|
|
69744
|
-
* Fetches events for a given set of pools
|
|
69745
|
-
*
|
|
69746
|
-
* @param pools - The pools to fetch events for
|
|
69747
|
-
*
|
|
69748
|
-
* @returns A map of pool scopes to their events
|
|
69749
|
-
*/
|
|
69750
|
-
async getEvents(pools) {
|
|
69751
|
-
const events = new Map();
|
|
69752
|
-
const poolEventResults = await Promise.allSettled(pools.map(async (pool) => {
|
|
69753
|
-
this.logger.info(`Fetching events for pool`, {
|
|
69754
|
-
poolAddress: pool.address,
|
|
69755
|
-
poolChainId: pool.chainId,
|
|
69756
|
-
poolDeploymentBlock: pool.deploymentBlock,
|
|
69757
|
-
});
|
|
69758
|
-
const [depositEvents, withdrawalEvents, ragequitEvents] = await Promise.all([
|
|
69759
|
-
this.getDepositEvents(pool),
|
|
69760
|
-
this.getWithdrawalEvents(pool),
|
|
69761
|
-
this.getRagequitEvents(pool),
|
|
69762
|
-
]);
|
|
69763
|
-
return {
|
|
69764
|
-
scope: pool.scope,
|
|
69765
|
-
depositEvents,
|
|
69766
|
-
withdrawalEvents,
|
|
69767
|
-
ragequitEvents,
|
|
69768
|
-
};
|
|
69769
|
-
}));
|
|
69770
|
-
for (const result of poolEventResults) {
|
|
69771
|
-
if (result.status === "fulfilled") {
|
|
69772
|
-
const { scope, depositEvents, withdrawalEvents, ragequitEvents } = result.value;
|
|
69773
|
-
events.set(scope, {
|
|
69774
|
-
depositEvents,
|
|
69775
|
-
withdrawalEvents,
|
|
69776
|
-
ragequitEvents,
|
|
69777
|
-
});
|
|
69778
|
-
}
|
|
69779
|
-
else {
|
|
69780
|
-
events.set(result.reason.details?.scope, {
|
|
69781
|
-
reason: result.reason.message,
|
|
69782
|
-
scope: result.reason.details?.scope,
|
|
69783
|
-
});
|
|
69784
|
-
}
|
|
69785
|
-
}
|
|
69786
|
-
return events;
|
|
69787
|
-
}
|
|
69788
|
-
/**
|
|
69789
|
-
* Processes deposit events for a given scope and adds them to the account
|
|
69790
|
-
* Deterministically generate deposit secrets and check if they match on-chain deposits
|
|
69791
|
-
*
|
|
69792
|
-
* @param scope - The scope of the pool
|
|
69793
|
-
* @param depositEvents - The map of deposit events
|
|
69794
|
-
*
|
|
69795
|
-
*/
|
|
69796
|
-
_processDepositEvents(scope, depositEvents) {
|
|
69797
|
-
for (let index = BigInt(0); index < depositEvents.size; index++) {
|
|
69798
|
-
// Generate nullifier, secret, and precommitment for this index
|
|
69799
|
-
const { nullifier, secret, precommitment } = this.createDepositSecrets(scope, index);
|
|
69800
|
-
// Look for a deposit with this precommitment
|
|
69801
|
-
const event = depositEvents.get(precommitment);
|
|
69802
|
-
if (!event) {
|
|
69803
|
-
break; // No more deposits found, exit the loop
|
|
69804
|
-
}
|
|
69805
|
-
// Create a new pool account for this deposit
|
|
69806
|
-
this.addPoolAccount(scope, event.value, nullifier, secret, event.label, event.blockNumber, event.transactionHash);
|
|
69807
|
-
}
|
|
69808
|
-
}
|
|
69809
|
-
/**
|
|
69810
|
-
* Processes withdrawal events for a given scope and adds them to the account
|
|
69811
|
-
*
|
|
69812
|
-
* @param scope - The scope of the pool
|
|
69813
|
-
* @param withdrawalEvents - The map of withdrawal events
|
|
69814
|
-
*
|
|
69815
|
-
* @remarks
|
|
69816
|
-
* This method performs the following steps for each pool:
|
|
69817
|
-
* 1. Identifies the earliest deposit block for each scope
|
|
69818
|
-
* 2. For each account, reconstructs the withdrawal history by:
|
|
69819
|
-
* - Generating nullifiers sequentially
|
|
69820
|
-
* - Matching them against on-chain events
|
|
69821
|
-
* - Adding matched withdrawals to the account state
|
|
69822
|
-
*
|
|
69823
|
-
* @throws {DataError} If event fetching fails
|
|
69824
|
-
* @private
|
|
69825
|
-
*
|
|
69826
|
-
*/
|
|
69827
|
-
_processWithdrawalEvents(scope, withdrawalEvents) {
|
|
69828
|
-
const accounts = this.account.poolAccounts.get(scope);
|
|
69829
|
-
// Skip if no accounts for this scope
|
|
69830
|
-
if (!accounts || accounts.length === 0) {
|
|
69831
|
-
this.logger.info(`No accounts found for pool with this scope`, {
|
|
69832
|
-
scope,
|
|
69833
|
-
});
|
|
69834
|
-
return;
|
|
69835
|
-
}
|
|
69836
|
-
// Process each account in parallel for better performance
|
|
69837
|
-
for (const account of accounts) {
|
|
69838
|
-
let currentCommitment = account.deposit;
|
|
69839
|
-
let index = BigInt(0);
|
|
69840
|
-
// Continue processing withdrawals until no more are found secuentially
|
|
69841
|
-
while (true) {
|
|
69842
|
-
// Generate nullifier for this withdrawal
|
|
69843
|
-
const nullifierHash = hashingExports.poseidon([currentCommitment.nullifier]);
|
|
69844
|
-
// Look for a withdrawal event with this nullifier
|
|
69845
|
-
const withdrawal = withdrawalEvents.get(nullifierHash);
|
|
69846
|
-
if (!withdrawal) {
|
|
69847
|
-
break;
|
|
69848
|
-
}
|
|
69849
|
-
// Generate secret for this withdrawal
|
|
69850
|
-
const nullifier = this._genWithdrawalNullifier(account.label, index);
|
|
69851
|
-
const secret = this._genWithdrawalSecret(account.label, index);
|
|
69852
|
-
// Add the withdrawal commitment to the account
|
|
69853
|
-
const newCommitment = this.addWithdrawalCommitment(currentCommitment, currentCommitment.value - withdrawal.withdrawn, nullifier, secret, withdrawal.blockNumber, withdrawal.transactionHash);
|
|
69854
|
-
// Update current commitment to the newly created one
|
|
69855
|
-
currentCommitment = newCommitment;
|
|
69856
|
-
// Increment index for next potential withdrawal
|
|
69857
|
-
index++;
|
|
69858
|
-
}
|
|
69859
|
-
}
|
|
69860
|
-
}
|
|
69861
|
-
/**
|
|
69862
|
-
* Processes ragequit events for a given scope and adds them to the account
|
|
69863
|
-
*
|
|
69864
|
-
* @param scope - The scope of the pool
|
|
69865
|
-
* @param ragequitEvents - The map of ragequit events
|
|
69866
|
-
*
|
|
69867
|
-
* @remarks
|
|
69868
|
-
* This method performs the following steps for each pool:
|
|
69869
|
-
* 1. Adds ragequit events to accounts if found
|
|
69870
|
-
*
|
|
69871
|
-
* @throws {DataError} If event fetching fails
|
|
69872
|
-
* @private
|
|
69873
|
-
*
|
|
69874
|
-
*/
|
|
69875
|
-
_processRagequitEvents(scope, ragequitEvents) {
|
|
69876
|
-
const accounts = this.account.poolAccounts.get(scope);
|
|
69877
|
-
if (!accounts || accounts.length === 0) {
|
|
69878
|
-
this.logger.info(`No accounts found for pool with this scope`, {
|
|
69879
|
-
scope,
|
|
69880
|
-
});
|
|
69881
|
-
return;
|
|
69882
|
-
}
|
|
69883
|
-
for (const account of accounts) {
|
|
69884
|
-
const ragequit = ragequitEvents.get(account.label);
|
|
69885
|
-
if (ragequit) {
|
|
69886
|
-
this.addRagequitToAccount(account.label, ragequit);
|
|
69887
|
-
}
|
|
69888
|
-
}
|
|
69889
|
-
}
|
|
69890
|
-
/**
|
|
69891
|
-
* Initializes an AccountService instance with events for a given set of pools
|
|
69892
|
-
*
|
|
69893
|
-
* @param dataService - The data service to use for fetching events
|
|
69894
|
-
* @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
|
|
69895
|
-
* @param pools - The pools to fetch events for
|
|
69896
|
-
*
|
|
69897
|
-
* @remarks
|
|
69898
|
-
* This method performs the following steps for each pool:
|
|
69899
|
-
* 1. Fetches deposit, withdrawal, and ragequit events for each pool
|
|
69900
|
-
* 2. Processes deposit events and creates pool accounts
|
|
69901
|
-
* 3. Processes withdrawal events and adds commitments to pool accounts
|
|
69902
|
-
* 4. Processes ragequit events and adds ragequit to pool accounts
|
|
69903
|
-
*
|
|
69904
|
-
* @returns The initialized AccountService instance and array of errors if any pool events fetching fails
|
|
69905
|
-
*
|
|
69906
|
-
* if any pool events fetching fails, the account will be initialized without the events for that pool
|
|
69907
|
-
* user can then call to this method again with the same account and missing pools to fetch the missing events
|
|
69908
|
-
*
|
|
69909
|
-
* @throws {AccountError} If account state reconstruction fails or if duplicate pools are found
|
|
69910
|
-
*/
|
|
69911
|
-
static async initializeWithEvents(dataService, source, pools) {
|
|
69912
|
-
// Log the start of the history retrieval process
|
|
69913
|
-
const logger = new Logger({ prefix: "Account" });
|
|
69914
|
-
logger.info(`Fetching events for pools`, { poolLength: pools.length });
|
|
69915
|
-
// verify that pools don't contain duplicates based on scope
|
|
69916
|
-
const uniqueScopes = new Set();
|
|
69917
|
-
for (const pool of pools) {
|
|
69918
|
-
if (uniqueScopes.has(pool.scope)) {
|
|
69919
|
-
throw AccountError.duplicatePools(pool.scope);
|
|
69920
|
-
}
|
|
69921
|
-
uniqueScopes.add(pool.scope);
|
|
69922
|
-
}
|
|
69923
|
-
const errors = [];
|
|
69924
|
-
const account = new AccountService(dataService, "mnemonic" in source
|
|
69925
|
-
? { mnemonic: source.mnemonic }
|
|
69926
|
-
: { account: source.service.account });
|
|
69927
|
-
const events = await account.getEvents(pools);
|
|
69928
|
-
for (const [scope, result] of events.entries()) {
|
|
69929
|
-
if ("reason" in result) {
|
|
69930
|
-
errors.push(result);
|
|
69931
|
-
}
|
|
69932
|
-
else {
|
|
69933
|
-
// Process deposit events an create pool accounts
|
|
69934
|
-
account._processDepositEvents(scope, result.depositEvents);
|
|
69935
|
-
// Process withdrawal events and add commitments to pool accounts
|
|
69936
|
-
account._processWithdrawalEvents(scope, result.withdrawalEvents);
|
|
69937
|
-
// Process ragequit events and add ragequit to pool accounts
|
|
69938
|
-
account._processRagequitEvents(scope, result.ragequitEvents);
|
|
69939
|
-
}
|
|
69940
|
-
}
|
|
69941
|
-
return { account, errors };
|
|
69942
|
-
}
|
|
69943
|
-
/**
|
|
69944
|
-
* @deprecated Use `initializeWithEvents` for instantiating an account with history reconstruction
|
|
69945
69616
|
* Retrieves the history of deposits and withdrawals for the given pools.
|
|
69946
69617
|
*
|
|
69947
69618
|
* @param pools - Array of pool configurations to sync history for
|
|
@@ -69977,7 +69648,9 @@ class AccountService {
|
|
|
69977
69648
|
// Create a map of deposits by precommitment for efficient lookup
|
|
69978
69649
|
const depositMap = new Map();
|
|
69979
69650
|
for (const deposit of deposits) {
|
|
69980
|
-
depositMap.
|
|
69651
|
+
if (!depositMap.has(deposit.precommitment)) {
|
|
69652
|
+
depositMap.set(deposit.precommitment, deposit);
|
|
69653
|
+
}
|
|
69981
69654
|
}
|
|
69982
69655
|
// Track found deposits for logging and debugging
|
|
69983
69656
|
const foundDeposits = [];
|
|
@@ -70074,9 +69747,7 @@ class AccountService {
|
|
|
70074
69747
|
// Continue processing withdrawals until no more are found
|
|
70075
69748
|
while (true) {
|
|
70076
69749
|
// Generate nullifier for this withdrawal
|
|
70077
|
-
const nullifierHash = hashingExports.poseidon([
|
|
70078
|
-
currentCommitment.nullifier,
|
|
70079
|
-
]);
|
|
69750
|
+
const nullifierHash = hashingExports.poseidon([currentCommitment.nullifier]);
|
|
70080
69751
|
// Look for a withdrawal event with this nullifier
|
|
70081
69752
|
const withdrawal = withdrawalMap.get(nullifierHash);
|
|
70082
69753
|
if (!withdrawal) {
|
|
@@ -70101,6 +69772,22 @@ class AccountService {
|
|
|
70101
69772
|
}
|
|
70102
69773
|
}
|
|
70103
69774
|
|
|
69775
|
+
class DataError extends SDKError {
|
|
69776
|
+
constructor(message, code = ErrorCode.NETWORK_ERROR, details) {
|
|
69777
|
+
super(message, code, details);
|
|
69778
|
+
this.name = "DataError";
|
|
69779
|
+
}
|
|
69780
|
+
static invalidLog(type, reason) {
|
|
69781
|
+
return new DataError(`Invalid ${type} log: ${reason}`, ErrorCode.INVALID_INPUT);
|
|
69782
|
+
}
|
|
69783
|
+
static chainNotConfigured(chainId) {
|
|
69784
|
+
return new DataError(`No configuration found for chain ID ${chainId}`, ErrorCode.INVALID_INPUT);
|
|
69785
|
+
}
|
|
69786
|
+
static networkError(chainId, error) {
|
|
69787
|
+
return new DataError(`Network error on chain ${chainId}: ${error.message}`, ErrorCode.NETWORK_ERROR, { originalError: error });
|
|
69788
|
+
}
|
|
69789
|
+
}
|
|
69790
|
+
|
|
70104
69791
|
// Event signatures from the contract
|
|
70105
69792
|
const DEPOSIT_EVENT = parseAbiItem('event Deposited(address indexed _depositor, uint256 _commitment, uint256 _label, uint256 _value, uint256 _merkleRoot)');
|
|
70106
69793
|
const WITHDRAWAL_EVENT = parseAbiItem('event Withdrawn(address indexed _processooor, uint256 _value, uint256 _spentNullifier, uint256 _newCommitment)');
|
|
@@ -70129,11 +69816,12 @@ class DataService {
|
|
|
70129
69816
|
this.logger = new Logger({ prefix: "Data" });
|
|
70130
69817
|
try {
|
|
70131
69818
|
for (const config of chainConfigs) {
|
|
70132
|
-
if (!config.rpcUrl) {
|
|
70133
|
-
throw new Error(`Missing RPC URL for chain ${config.chainId}`);
|
|
69819
|
+
if (!config.rpcUrl || !config.apiKey) {
|
|
69820
|
+
throw new Error(`Missing RPC URL or API key for chain ${config.chainId}`);
|
|
70134
69821
|
}
|
|
70135
69822
|
const client = createPublicClient({
|
|
70136
69823
|
transport: http(config.rpcUrl),
|
|
69824
|
+
key: config.apiKey,
|
|
70137
69825
|
});
|
|
70138
69826
|
this.clients.set(config.chainId, client);
|
|
70139
69827
|
}
|
|
@@ -70167,14 +69855,14 @@ class DataService {
|
|
|
70167
69855
|
throw DataError.invalidLog("deposit", "missing args");
|
|
70168
69856
|
}
|
|
70169
69857
|
const { _depositor: depositor, _commitment: commitment, _label: label, _value: value, _merkleRoot: precommitment, } = log.args;
|
|
70170
|
-
if (!depositor || !commitment || !label || !
|
|
69858
|
+
if (!depositor || !commitment || !label || !precommitment || !log.blockNumber || !log.transactionHash) {
|
|
70171
69859
|
throw DataError.invalidLog("deposit", "missing required fields");
|
|
70172
69860
|
}
|
|
70173
69861
|
return {
|
|
70174
69862
|
depositor: depositor.toLowerCase(),
|
|
70175
69863
|
commitment: commitment,
|
|
70176
69864
|
label: label,
|
|
70177
|
-
value,
|
|
69865
|
+
value: value || BigInt(0),
|
|
70178
69866
|
precommitment: precommitment,
|
|
70179
69867
|
blockNumber: BigInt(log.blockNumber),
|
|
70180
69868
|
transactionHash: log.transactionHash,
|
|
@@ -70309,4 +69997,4 @@ class DataService {
|
|
|
70309
69997
|
}
|
|
70310
69998
|
|
|
70311
69999
|
export { AccountService as A, BlockchainProvider as B, CommitmentService as C, DataService as D, ErrorCode as E, FetchArtifact as F, InvalidRpcUrl as I, PrivacyPoolSDK as P, SDKError as S, WithdrawalService as W, generateDepositSecrets as a, generateWithdrawalSecrets as b, getCommitment as c, generateMerkleProof as d, bigintToHash as e, bigintToHex as f, generateMasterKeys as g, hashPrecommitment as h, calculateContext as i, Circuits as j, ContractInteractionsService as k, ProofError as l, ContractError as m, AccountError as n, CircuitName as o };
|
|
70312
|
-
//# sourceMappingURL=index-
|
|
70000
|
+
//# sourceMappingURL=index-C_oO7cOn.js.map
|