@kohaku-eth/tornado-cash 0.0.2-alpha.19 → 0.0.2-alpha.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/index.d.ts +37 -2
- package/dist/index.js +43 -5
- package/dist/state-manager.worker.js +203 -55
- package/dist/state-manager.worker.node.js +203 -55
- package/dist/worker-loader.browser.d.ts +53 -1
- package/dist/worker-loader.node.d.ts +53 -1
- package/package.json +8 -5
|
@@ -17284,10 +17284,16 @@ async function SecretManager({
|
|
|
17284
17284
|
const deriveDelegatorSigner = async ({ path }) => {
|
|
17285
17285
|
return Promise.resolve(keystore.deriveAt(path));
|
|
17286
17286
|
};
|
|
17287
|
+
const LEGACY_EPHEMERAL_SALT = asciiToBytes("KOHAKU7702");
|
|
17288
|
+
const deriveLegacyEphemeralSigner = async ({ nullifier }) => {
|
|
17289
|
+
const hash2 = keccak_256(concatBytes2(numberToBytesLE(nullifier, 31), LEGACY_EPHEMERAL_SALT));
|
|
17290
|
+
return `0x${bytesToHex2(hash2)}`;
|
|
17291
|
+
};
|
|
17287
17292
|
return {
|
|
17288
17293
|
getDepositSecrets: (params) => deriveSecrets(params),
|
|
17289
17294
|
deriveEphemeralSigner,
|
|
17290
|
-
deriveDelegatorSigner
|
|
17295
|
+
deriveDelegatorSigner,
|
|
17296
|
+
deriveLegacyEphemeralSigner
|
|
17291
17297
|
};
|
|
17292
17298
|
}
|
|
17293
17299
|
function tcPath({ accountIndex, secretType, depositIndex }) {
|
|
@@ -18323,10 +18329,10 @@ function getUnexpectedStateShapeWarningMessage(inputState, reducers2, action, un
|
|
|
18323
18329
|
function assertReducerShape(reducers2) {
|
|
18324
18330
|
Object.keys(reducers2).forEach((key) => {
|
|
18325
18331
|
const reducer = reducers2[key];
|
|
18326
|
-
const
|
|
18332
|
+
const initialState10 = reducer(void 0, {
|
|
18327
18333
|
type: actionTypes_default.INIT
|
|
18328
18334
|
});
|
|
18329
|
-
if (typeof
|
|
18335
|
+
if (typeof initialState10 === "undefined") {
|
|
18330
18336
|
throw new Error(false ? formatProdErrorMessage(12) : `The slice reducer for key "${key}" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.`);
|
|
18331
18337
|
}
|
|
18332
18338
|
if (typeof reducer(void 0, {
|
|
@@ -19567,7 +19573,7 @@ function createThunkMiddleware(extraArgument) {
|
|
|
19567
19573
|
var thunk = createThunkMiddleware();
|
|
19568
19574
|
var withExtraArgument = createThunkMiddleware;
|
|
19569
19575
|
|
|
19570
|
-
// ../../node_modules/.pnpm/@reduxjs+toolkit@2.12.0_react@19.2.
|
|
19576
|
+
// ../../node_modules/.pnpm/@reduxjs+toolkit@2.12.0_react@19.2.8/node_modules/@reduxjs/toolkit/dist/redux-toolkit.modern.mjs
|
|
19571
19577
|
var composeWithDevTools = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function() {
|
|
19572
19578
|
if (arguments.length === 0) return void 0;
|
|
19573
19579
|
if (typeof arguments[0] === "object") return compose;
|
|
@@ -20188,7 +20194,7 @@ function executeReducerBuilderCallback(builderCallback) {
|
|
|
20188
20194
|
function isStateFunction(x) {
|
|
20189
20195
|
return typeof x === "function";
|
|
20190
20196
|
}
|
|
20191
|
-
function createReducer(
|
|
20197
|
+
function createReducer(initialState10, mapOrBuilderCallback) {
|
|
20192
20198
|
if (true) {
|
|
20193
20199
|
if (typeof mapOrBuilderCallback === "object") {
|
|
20194
20200
|
throw new Error(false ? formatProdErrorMessage(8) : "The object notation for `createReducer` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
|
|
@@ -20196,10 +20202,10 @@ function createReducer(initialState9, mapOrBuilderCallback) {
|
|
|
20196
20202
|
}
|
|
20197
20203
|
let [actionsMap, finalActionMatchers, finalDefaultCaseReducer] = executeReducerBuilderCallback(mapOrBuilderCallback);
|
|
20198
20204
|
let getInitialState;
|
|
20199
|
-
if (isStateFunction(
|
|
20200
|
-
getInitialState = () => freezeDraftable(
|
|
20205
|
+
if (isStateFunction(initialState10)) {
|
|
20206
|
+
getInitialState = () => freezeDraftable(initialState10());
|
|
20201
20207
|
} else {
|
|
20202
|
-
const frozenInitialState = freezeDraftable(
|
|
20208
|
+
const frozenInitialState = freezeDraftable(initialState10);
|
|
20203
20209
|
getInitialState = () => frozenInitialState;
|
|
20204
20210
|
}
|
|
20205
20211
|
function reducer(state = getInitialState(), action) {
|
|
@@ -20851,10 +20857,29 @@ var relayersSelector = createSelector(
|
|
|
20851
20857
|
)
|
|
20852
20858
|
);
|
|
20853
20859
|
var relayerFeeConfigSelector = (state) => state.relayers.feeConfig;
|
|
20854
|
-
var
|
|
20860
|
+
var derivedUserSecretsSelector = selectEntityMap(
|
|
20855
20861
|
(s) => s.userSecrets.byPool,
|
|
20856
20862
|
deserialize
|
|
20857
20863
|
);
|
|
20864
|
+
var legacyUserSecretsSelector = selectEntityMap(
|
|
20865
|
+
(s) => s.legacySecrets.byPool,
|
|
20866
|
+
deserialize
|
|
20867
|
+
);
|
|
20868
|
+
var userSecretsSelector = createSelector(
|
|
20869
|
+
[derivedUserSecretsSelector, legacyUserSecretsSelector],
|
|
20870
|
+
(derived, legacy) => {
|
|
20871
|
+
const result = /* @__PURE__ */ new Map();
|
|
20872
|
+
for (const [poolAddress, records] of legacy) {
|
|
20873
|
+
const existing = result.get(poolAddress) ?? [];
|
|
20874
|
+
result.set(poolAddress, [...existing, ...records.map((record) => ({ kind: "legacy", ...record }))]);
|
|
20875
|
+
}
|
|
20876
|
+
for (const [poolAddress, records] of derived) {
|
|
20877
|
+
const existing = result.get(poolAddress) ?? [];
|
|
20878
|
+
result.set(poolAddress, [...existing, ...records.map((record) => ({ kind: "derived", ...record }))]);
|
|
20879
|
+
}
|
|
20880
|
+
return result;
|
|
20881
|
+
}
|
|
20882
|
+
);
|
|
20858
20883
|
|
|
20859
20884
|
// src/state/selectors/deposits.selector.ts
|
|
20860
20885
|
var myDepositsSelector = createSelector(
|
|
@@ -20868,7 +20893,7 @@ var myDepositsSelector = createSelector(
|
|
|
20868
20893
|
const commitment = BigInt(r.commitment);
|
|
20869
20894
|
const deposit = poolDeposits.get(commitment);
|
|
20870
20895
|
if (deposit) {
|
|
20871
|
-
result.set(commitment, { ...deposit, index: r.depositIndex });
|
|
20896
|
+
result.set(commitment, { ...deposit, index: r.kind === "derived" ? r.depositIndex : -1 });
|
|
20872
20897
|
}
|
|
20873
20898
|
}
|
|
20874
20899
|
}
|
|
@@ -21249,6 +21274,28 @@ var userSecretsSlice = createSlice({
|
|
|
21249
21274
|
var { addUserSecret } = userSecretsSlice.actions;
|
|
21250
21275
|
var userSecretsReducer = userSecretsSlice.reducer;
|
|
21251
21276
|
|
|
21277
|
+
// src/state/slices/legacySecretsSlice.ts
|
|
21278
|
+
var initialState9 = {
|
|
21279
|
+
byPool: []
|
|
21280
|
+
};
|
|
21281
|
+
var legacySecretsSlice = createSlice({
|
|
21282
|
+
name: "legacySecrets",
|
|
21283
|
+
initialState: initialState9,
|
|
21284
|
+
reducers: {
|
|
21285
|
+
addLegacyUserSecret: ({ byPool }, { payload: { poolAddress, record } }) => {
|
|
21286
|
+
const map = new Map(deserialize(byPool));
|
|
21287
|
+
const records = map.get(poolAddress) || [];
|
|
21288
|
+
if (!records.some((r) => r.commitment === record.commitment)) {
|
|
21289
|
+
records.push(record);
|
|
21290
|
+
}
|
|
21291
|
+
map.set(poolAddress, records);
|
|
21292
|
+
return serialize({ byPool: [...map] });
|
|
21293
|
+
}
|
|
21294
|
+
}
|
|
21295
|
+
});
|
|
21296
|
+
var { addLegacyUserSecret } = legacySecretsSlice.actions;
|
|
21297
|
+
var legacySecretsReducer = legacySecretsSlice.reducer;
|
|
21298
|
+
|
|
21252
21299
|
// src/state/store.ts
|
|
21253
21300
|
var reducers = {
|
|
21254
21301
|
deposits: depositsReducer,
|
|
@@ -21258,7 +21305,8 @@ var reducers = {
|
|
|
21258
21305
|
relayers: relayersReducer,
|
|
21259
21306
|
instanceRegistryInfo: protocolConfigReducer,
|
|
21260
21307
|
sync: syncReducer,
|
|
21261
|
-
userSecrets: userSecretsReducer
|
|
21308
|
+
userSecrets: userSecretsReducer,
|
|
21309
|
+
legacySecrets: legacySecretsReducer
|
|
21262
21310
|
};
|
|
21263
21311
|
var loggerFactory = (logLevel) => (api) => (next) => (action) => {
|
|
21264
21312
|
const result = next(action);
|
|
@@ -21288,11 +21336,11 @@ var loggerFactory = (logLevel) => (api) => (next) => (action) => {
|
|
|
21288
21336
|
};
|
|
21289
21337
|
var storeFactory = ({
|
|
21290
21338
|
protocolConfig,
|
|
21291
|
-
initialState:
|
|
21339
|
+
initialState: initialState10,
|
|
21292
21340
|
logLevel = "error"
|
|
21293
21341
|
}) => {
|
|
21294
21342
|
const store = configureStore({
|
|
21295
|
-
preloadedState:
|
|
21343
|
+
preloadedState: initialState10,
|
|
21296
21344
|
reducer: reducers,
|
|
21297
21345
|
middleware: (getDefaultMiddleware) => {
|
|
21298
21346
|
const defaultMiddleware = getDefaultMiddleware({
|
|
@@ -22003,7 +22051,7 @@ var discoverUserEventsThunk = createAsyncThunk(
|
|
|
22003
22051
|
const deposits = depositsSelector(state);
|
|
22004
22052
|
const pools = poolsSelector(state);
|
|
22005
22053
|
const { chainId } = instanceRegistryInfoSelector(state);
|
|
22006
|
-
const userSecrets =
|
|
22054
|
+
const userSecrets = derivedUserSecretsSelector(state);
|
|
22007
22055
|
for (const [poolAddress] of pools) {
|
|
22008
22056
|
const startIndex = userSecrets.get(poolAddress)?.length ?? 0;
|
|
22009
22057
|
const poolDeposits = deposits.get(poolAddress);
|
|
@@ -22207,7 +22255,7 @@ var createTx = (address, payload, value = BigInt(0)) => {
|
|
|
22207
22255
|
init_exports();
|
|
22208
22256
|
init_encodeAbiParameters2();
|
|
22209
22257
|
|
|
22210
|
-
// ../../node_modules/.pnpm/@privacy-paymasters+sdk@0.0.
|
|
22258
|
+
// ../../node_modules/.pnpm/@privacy-paymasters+sdk@0.0.5_typescript@5.9.3_zod@4.4.3/node_modules/@privacy-paymasters/sdk/dist/index.js
|
|
22211
22259
|
function encodePaymasterData(adapter, adapterData) {
|
|
22212
22260
|
return encodeAbiParameters2(parseAbiParameters("(address adapter, bytes adapterData)"), [{ adapter, adapterData }]);
|
|
22213
22261
|
}
|
|
@@ -22389,7 +22437,7 @@ var baseGasUnits = {
|
|
|
22389
22437
|
preVerificationGas: 100000n,
|
|
22390
22438
|
verificationGasLimit: 50000n,
|
|
22391
22439
|
callGasLimit: 300000n,
|
|
22392
|
-
paymasterVerificationGasLimit:
|
|
22440
|
+
paymasterVerificationGasLimit: 450000n,
|
|
22393
22441
|
paymasterPostOpGasLimit: 50000n
|
|
22394
22442
|
};
|
|
22395
22443
|
function reasonableGasUnits(isERC20) {
|
|
@@ -24255,6 +24303,22 @@ var paymasterWithdrawThunk = createAsyncThunk("withdraw/executePaymasterWithdraw
|
|
|
24255
24303
|
);
|
|
24256
24304
|
const bundlerClient = createPaymasterBundlerClient(bundlerUrl);
|
|
24257
24305
|
const { standard: { maxFeePerGas, maxPriorityFeePerGas } } = await getUserOperationGasPrice(bundlerClient);
|
|
24306
|
+
const refineGasWithBundler = async (baselineGas2, provisionalUserOperation) => {
|
|
24307
|
+
try {
|
|
24308
|
+
const estimated = await estimateUserOperationGas2(bundlerClient, provisionalUserOperation, entryPointAddress);
|
|
24309
|
+
const buffer2 = (x) => x * 12n / 10n;
|
|
24310
|
+
const orBaseline = (e, b) => e > 0n ? buffer2(e) : b;
|
|
24311
|
+
return {
|
|
24312
|
+
callGasLimit: orBaseline(estimated.callGasLimit, baselineGas2.callGasLimit),
|
|
24313
|
+
verificationGasLimit: orBaseline(estimated.verificationGasLimit, baselineGas2.verificationGasLimit),
|
|
24314
|
+
preVerificationGas: orBaseline(estimated.preVerificationGas, baselineGas2.preVerificationGas),
|
|
24315
|
+
paymasterVerificationGasLimit: orBaseline(estimated.paymasterVerificationGasLimit, baselineGas2.paymasterVerificationGasLimit),
|
|
24316
|
+
paymasterPostOpGasLimit: orBaseline(estimated.paymasterPostOpGasLimit, baselineGas2.paymasterPostOpGasLimit)
|
|
24317
|
+
};
|
|
24318
|
+
} catch {
|
|
24319
|
+
return baselineGas2;
|
|
24320
|
+
}
|
|
24321
|
+
};
|
|
24258
24322
|
const relayerAddress = BigInt(paymasterAddress);
|
|
24259
24323
|
const bigintChainId = await dataService.getChainId();
|
|
24260
24324
|
const { recipient: originalRecipient, ...restWithoutRecipient } = rest;
|
|
@@ -24281,11 +24345,13 @@ var paymasterWithdrawThunk = createAsyncThunk("withdraw/executePaymasterWithdraw
|
|
|
24281
24345
|
)
|
|
24282
24346
|
);
|
|
24283
24347
|
};
|
|
24284
|
-
const ephemeralSigner = async (deposit) => privateKeyToAccount(
|
|
24285
|
-
|
|
24286
|
-
|
|
24287
|
-
|
|
24288
|
-
|
|
24348
|
+
const ephemeralSigner = async (deposit) => privateKeyToAccount(
|
|
24349
|
+
deposit.kind === "legacy" ? await secretManager.deriveLegacyEphemeralSigner({ nullifier: deposit.nullifier }) : await secretManager.deriveEphemeralSigner({
|
|
24350
|
+
depositIndex: deposit.depositIndex,
|
|
24351
|
+
chainId: bigintChainId,
|
|
24352
|
+
poolAddress: deposit.pool
|
|
24353
|
+
})
|
|
24354
|
+
);
|
|
24289
24355
|
const resolveBatchDelegator = async () => {
|
|
24290
24356
|
if (delegation?.mode === "random") return privateKeyToAccount(generatePrivateKey());
|
|
24291
24357
|
if (delegation?.mode === "deterministic" && delegation.path) {
|
|
@@ -24299,19 +24365,36 @@ var paymasterWithdrawThunk = createAsyncThunk("withdraw/executePaymasterWithdraw
|
|
|
24299
24365
|
if (!needsConsolidation) {
|
|
24300
24366
|
const deposit = deposits[0];
|
|
24301
24367
|
const signer2 = await resolveIndependentSigner(deposit);
|
|
24302
|
-
const
|
|
24303
|
-
|
|
24304
|
-
|
|
24305
|
-
|
|
24368
|
+
const baselineGas2 = { ...reasonableGasUnits(poolInfo.isERC20), callGasLimit: 0n };
|
|
24369
|
+
let fee2 = await quoteFee(computeMinimumViableFee(baselineGas2, maxFeePerGas));
|
|
24370
|
+
let gas2 = baselineGas2;
|
|
24371
|
+
let proof = await prove(deposit, originalRecipient, relayerAddress, fee2);
|
|
24372
|
+
let userOperation2 = await buildSignedTornadoUserOp({
|
|
24306
24373
|
signer: signer2,
|
|
24307
24374
|
chainId,
|
|
24308
24375
|
paymasterAddress,
|
|
24309
24376
|
paymasterData: buildPaymasterData(deposit.pool, proof),
|
|
24310
|
-
gas:
|
|
24377
|
+
gas: gas2,
|
|
24311
24378
|
maxFeePerGas,
|
|
24312
24379
|
maxPriorityFeePerGas,
|
|
24313
24380
|
nonce: 0n
|
|
24314
24381
|
});
|
|
24382
|
+
const estimatedGas = await refineGasWithBundler(baselineGas2, userOperation2);
|
|
24383
|
+
if (estimatedGas !== baselineGas2) {
|
|
24384
|
+
gas2 = { ...estimatedGas, callGasLimit: 0n };
|
|
24385
|
+
fee2 = await quoteFee(computeMinimumViableFee(gas2, maxFeePerGas));
|
|
24386
|
+
proof = await prove(deposit, originalRecipient, relayerAddress, fee2);
|
|
24387
|
+
userOperation2 = await buildSignedTornadoUserOp({
|
|
24388
|
+
signer: signer2,
|
|
24389
|
+
chainId,
|
|
24390
|
+
paymasterAddress,
|
|
24391
|
+
paymasterData: buildPaymasterData(deposit.pool, proof),
|
|
24392
|
+
gas: gas2,
|
|
24393
|
+
maxFeePerGas,
|
|
24394
|
+
maxPriorityFeePerGas,
|
|
24395
|
+
nonce: 0n
|
|
24396
|
+
});
|
|
24397
|
+
}
|
|
24315
24398
|
return [{
|
|
24316
24399
|
mode: "paymaster",
|
|
24317
24400
|
proof,
|
|
@@ -24380,22 +24463,12 @@ var paymasterWithdrawThunk = createAsyncThunk("withdraw/executePaymasterWithdraw
|
|
|
24380
24463
|
let gas = baselineGas;
|
|
24381
24464
|
let sponsoringProof = await prove(sponsoringDeposit, senderAddress, relayerAddress, fee);
|
|
24382
24465
|
let userOperation = await buildOp(gas, fee, buildPaymasterData(sponsoringDeposit.pool, sponsoringProof));
|
|
24383
|
-
|
|
24384
|
-
|
|
24385
|
-
const buffer2 = (x) => x * 12n / 10n;
|
|
24386
|
-
const orBaseline = (e, b) => e > 0n ? buffer2(e) : b;
|
|
24387
|
-
const refinedGas = {
|
|
24388
|
-
callGasLimit: orBaseline(estimated.callGasLimit, baselineGas.callGasLimit),
|
|
24389
|
-
verificationGasLimit: orBaseline(estimated.verificationGasLimit, baselineGas.verificationGasLimit),
|
|
24390
|
-
preVerificationGas: orBaseline(estimated.preVerificationGas, baselineGas.preVerificationGas),
|
|
24391
|
-
paymasterVerificationGasLimit: orBaseline(estimated.paymasterVerificationGasLimit, baselineGas.paymasterVerificationGasLimit),
|
|
24392
|
-
paymasterPostOpGasLimit: orBaseline(estimated.paymasterPostOpGasLimit, baselineGas.paymasterPostOpGasLimit)
|
|
24393
|
-
};
|
|
24394
|
-
fee = await quoteFee(computeMinimumViableFee(refinedGas, maxFeePerGas));
|
|
24466
|
+
const refinedGas = await refineGasWithBundler(baselineGas, userOperation);
|
|
24467
|
+
if (refinedGas !== baselineGas) {
|
|
24395
24468
|
gas = refinedGas;
|
|
24469
|
+
fee = await quoteFee(computeMinimumViableFee(gas, maxFeePerGas));
|
|
24396
24470
|
sponsoringProof = await prove(sponsoringDeposit, senderAddress, relayerAddress, fee);
|
|
24397
24471
|
userOperation = await buildOp(gas, fee, buildPaymasterData(sponsoringDeposit.pool, sponsoringProof));
|
|
24398
|
-
} catch {
|
|
24399
24472
|
}
|
|
24400
24473
|
return [{
|
|
24401
24474
|
mode: "paymaster",
|
|
@@ -24477,7 +24550,7 @@ var getDepositPayloadThunk = createAsyncThunk(
|
|
|
24477
24550
|
const state = getState();
|
|
24478
24551
|
const pools = poolsSelector(state);
|
|
24479
24552
|
const { chainId } = instanceRegistryInfoSelector(state);
|
|
24480
|
-
const userSecrets =
|
|
24553
|
+
const userSecrets = derivedUserSecretsSelector(state);
|
|
24481
24554
|
const poolsCandidates = Array.from(pools.values()).filter((p) => p.asset === asset);
|
|
24482
24555
|
if (poolsCandidates.length === 0) throw new Error(`No pools available for asset ${addressToHex(asset)}`);
|
|
24483
24556
|
const poolsToDepositInto = calculatePoolsDeposits(poolsCandidates, amount, strategy);
|
|
@@ -24526,6 +24599,62 @@ var getDepositPayloadThunk = createAsyncThunk(
|
|
|
24526
24599
|
}
|
|
24527
24600
|
);
|
|
24528
24601
|
|
|
24602
|
+
// src/account/legacyNote.ts
|
|
24603
|
+
init_utils2();
|
|
24604
|
+
var NOTE_REGEX = /^tornado-([a-zA-Z0-9]+)-([0-9.]+)-(\d+)-0x([0-9a-fA-F]+)$/;
|
|
24605
|
+
function parseLegacyNote(note) {
|
|
24606
|
+
const match = NOTE_REGEX.exec(note.trim());
|
|
24607
|
+
if (!match) {
|
|
24608
|
+
throw new Error(`Invalid tornado cash note: ${note}`);
|
|
24609
|
+
}
|
|
24610
|
+
const [, currency, denomination, chainId, preimageHex] = match;
|
|
24611
|
+
const preimageBytes = hexToBytes2(preimageHex);
|
|
24612
|
+
if (preimageBytes.length !== 62) {
|
|
24613
|
+
throw new Error(`Invalid tornado cash note preimage length: ${note}`);
|
|
24614
|
+
}
|
|
24615
|
+
const nullifierBytes = preimageBytes.subarray(0, 31);
|
|
24616
|
+
const saltBytes = preimageBytes.subarray(31, 62);
|
|
24617
|
+
return {
|
|
24618
|
+
currency,
|
|
24619
|
+
denomination,
|
|
24620
|
+
chainId: BigInt(chainId),
|
|
24621
|
+
nullifier: bytesToNumberLE(nullifierBytes),
|
|
24622
|
+
salt: bytesToNumberLE(saltBytes),
|
|
24623
|
+
commitment: pedersenHash2(preimageBytes),
|
|
24624
|
+
nullifierHash: pedersenHash2(nullifierBytes)
|
|
24625
|
+
};
|
|
24626
|
+
}
|
|
24627
|
+
|
|
24628
|
+
// src/state/thunks/importLegacyNotesThunk.ts
|
|
24629
|
+
var importLegacyNotesThunk = createAsyncThunk(
|
|
24630
|
+
"userSecrets/importLegacy",
|
|
24631
|
+
async ({ notes }, { getState, dispatch }) => {
|
|
24632
|
+
const state = getState();
|
|
24633
|
+
const deposits = depositsSelector(state);
|
|
24634
|
+
const { chainId } = instanceRegistryInfoSelector(state);
|
|
24635
|
+
return notes.map((note) => {
|
|
24636
|
+
const parsed = parseLegacyNote(note);
|
|
24637
|
+
if (parsed.chainId !== chainId) {
|
|
24638
|
+
return { note, status: "wrong-chain" };
|
|
24639
|
+
}
|
|
24640
|
+
const matchedPool = [...deposits].find(([, poolDeposits]) => poolDeposits.has(parsed.commitment))?.[0];
|
|
24641
|
+
if (!matchedPool) {
|
|
24642
|
+
return { note, status: "not-found" };
|
|
24643
|
+
}
|
|
24644
|
+
dispatch(addLegacyUserSecret({
|
|
24645
|
+
poolAddress: matchedPool,
|
|
24646
|
+
record: {
|
|
24647
|
+
commitment: parsed.commitment,
|
|
24648
|
+
nullifierHash: parsed.nullifierHash,
|
|
24649
|
+
nullifier: parsed.nullifier,
|
|
24650
|
+
salt: parsed.salt
|
|
24651
|
+
}
|
|
24652
|
+
}));
|
|
24653
|
+
return { note, status: "imported", poolAddress: matchedPool };
|
|
24654
|
+
});
|
|
24655
|
+
}
|
|
24656
|
+
);
|
|
24657
|
+
|
|
24529
24658
|
// src/state/state-manager.ts
|
|
24530
24659
|
var ETH_SEPOLIA_CHAIN_ID = 11155111n;
|
|
24531
24660
|
var getStoreKey = ({
|
|
@@ -24540,6 +24669,10 @@ var initializeSelectors = (store) => ({
|
|
|
24540
24669
|
getAllNotes: () => allNotesSelector(store.getState())
|
|
24541
24670
|
},
|
|
24542
24671
|
getPublicState: () => {
|
|
24672
|
+
const { userSecrets, legacySecrets, ...publicState } = store.getState();
|
|
24673
|
+
return publicState;
|
|
24674
|
+
},
|
|
24675
|
+
getPrivateState: () => {
|
|
24543
24676
|
const { userSecrets, ...publicState } = store.getState();
|
|
24544
24677
|
return publicState;
|
|
24545
24678
|
}
|
|
@@ -24569,13 +24702,13 @@ var storeByChainAndEntrypoint = ({
|
|
|
24569
24702
|
const rawStoredState = storageToSyncTo ? await storageToSyncTo.get(storageKey) : void 0;
|
|
24570
24703
|
const storedState = rawStoredState ? JSON.parse(rawStoredState) : void 0;
|
|
24571
24704
|
const snapshotInitialState = storedState || !resolveInitialState ? void 0 : (await resolveInitialState())[storageKey];
|
|
24572
|
-
let
|
|
24573
|
-
if (!
|
|
24574
|
-
|
|
24705
|
+
let initialState10 = storedState || snapshotInitialState;
|
|
24706
|
+
if (!initialState10 && getChainStoreParams.chainId === ETH_SEPOLIA_CHAIN_ID) {
|
|
24707
|
+
initialState10 = await Promise.resolve().then(() => __toESM(require_state_11155111_minimal(), 1)).then((a) => a["tornado-cash-state-11155111-447664927873626138772898946646079239273904189887"]);
|
|
24575
24708
|
}
|
|
24576
24709
|
const store = storeFactory({
|
|
24577
24710
|
protocolConfig,
|
|
24578
|
-
initialState:
|
|
24711
|
+
initialState: initialState10
|
|
24579
24712
|
});
|
|
24580
24713
|
store.dispatch(setRelayerFeeConfig(relayerConfig));
|
|
24581
24714
|
storeWithSelectors = initializeSelectors(store);
|
|
@@ -24604,14 +24737,14 @@ var storeStateManager = async ({
|
|
|
24604
24737
|
paymasterConfig,
|
|
24605
24738
|
proverFactory,
|
|
24606
24739
|
storageToSyncTo,
|
|
24607
|
-
initialState:
|
|
24740
|
+
initialState: initialState10,
|
|
24608
24741
|
protocolConfig,
|
|
24609
24742
|
relayerConfig
|
|
24610
24743
|
}) => {
|
|
24611
24744
|
const secretManager = await secretManagerFactory();
|
|
24612
24745
|
const { getChainStore, getAllStores } = storeByChainAndEntrypoint({
|
|
24613
24746
|
storageToSyncTo,
|
|
24614
|
-
initialState:
|
|
24747
|
+
initialState: initialState10
|
|
24615
24748
|
});
|
|
24616
24749
|
const getChainInfo = async () => {
|
|
24617
24750
|
const chainId = await dataService.getChainId();
|
|
@@ -24625,6 +24758,14 @@ var storeStateManager = async ({
|
|
|
24625
24758
|
}
|
|
24626
24759
|
};
|
|
24627
24760
|
};
|
|
24761
|
+
const persistStateIfAvailable = async (chainInfo, store) => {
|
|
24762
|
+
if (storageToSyncTo) {
|
|
24763
|
+
await storageToSyncTo.set(
|
|
24764
|
+
getStoreStorageKey(chainInfo),
|
|
24765
|
+
JSON.stringify(store.getPrivateState())
|
|
24766
|
+
);
|
|
24767
|
+
}
|
|
24768
|
+
};
|
|
24628
24769
|
return {
|
|
24629
24770
|
sync: async () => {
|
|
24630
24771
|
const chainInfo = await getChainInfo();
|
|
@@ -24640,12 +24781,7 @@ var storeStateManager = async ({
|
|
|
24640
24781
|
})
|
|
24641
24782
|
)
|
|
24642
24783
|
);
|
|
24643
|
-
|
|
24644
|
-
await storageToSyncTo.set(
|
|
24645
|
-
getStoreStorageKey(chainInfo),
|
|
24646
|
-
JSON.stringify(store.getPublicState())
|
|
24647
|
-
);
|
|
24648
|
-
}
|
|
24784
|
+
await persistStateIfAvailable(chainInfo, store);
|
|
24649
24785
|
},
|
|
24650
24786
|
getBalances: async (assets) => {
|
|
24651
24787
|
const { selectors: { specificAssetsBalanceSelector: specificAssetsBalanceSelector2 } } = await getChainStore(await getChainInfo());
|
|
@@ -24711,6 +24847,15 @@ var storeStateManager = async ({
|
|
|
24711
24847
|
)
|
|
24712
24848
|
);
|
|
24713
24849
|
},
|
|
24850
|
+
importNotes: async ({ notes }) => {
|
|
24851
|
+
const chainInfo = await getChainInfo();
|
|
24852
|
+
const store = await getChainStore(chainInfo);
|
|
24853
|
+
const result = unwrapResult(
|
|
24854
|
+
await store.dispatch(importLegacyNotesThunk({ notes }))
|
|
24855
|
+
);
|
|
24856
|
+
await persistStateIfAvailable(chainInfo, store);
|
|
24857
|
+
return result;
|
|
24858
|
+
},
|
|
24714
24859
|
dumpState: () => getAllStores()
|
|
24715
24860
|
};
|
|
24716
24861
|
};
|
|
@@ -24722,12 +24867,12 @@ function getStateManager() {
|
|
|
24722
24867
|
return _stateManager;
|
|
24723
24868
|
}
|
|
24724
24869
|
var workerApi = {
|
|
24725
|
-
async init(provider, relayerClient, keystore, rawStorage,
|
|
24870
|
+
async init(provider, relayerClient, keystore, rawStorage, initialState10, artifactsLoader, secretManager, externalSyncProvider, { protocolConfig, accountIndex, relayerConfig, paymasterConfig, minExternalSyncBlocksAmount }) {
|
|
24726
24871
|
const storage = rawStorage;
|
|
24727
24872
|
const dataService = new DataService({ provider });
|
|
24728
24873
|
_stateManager = await storeStateManager({
|
|
24729
24874
|
paymasterConfig,
|
|
24730
|
-
secretManagerFactory: () => SecretManager({ host: { keystore }, accountIndex }),
|
|
24875
|
+
secretManagerFactory: () => secretManager ? Promise.resolve(secretManager) : SecretManager({ host: { keystore }, accountIndex }),
|
|
24731
24876
|
dataService,
|
|
24732
24877
|
syncService: new SyncService({ dataService, externalSyncProvider, minExternalSyncBlocksAmount }),
|
|
24733
24878
|
relayerClient,
|
|
@@ -24735,7 +24880,7 @@ var workerApi = {
|
|
|
24735
24880
|
storageToSyncTo: storage,
|
|
24736
24881
|
protocolConfig,
|
|
24737
24882
|
relayerConfig,
|
|
24738
|
-
initialState:
|
|
24883
|
+
initialState: initialState10
|
|
24739
24884
|
});
|
|
24740
24885
|
},
|
|
24741
24886
|
sync() {
|
|
@@ -24750,6 +24895,9 @@ var workerApi = {
|
|
|
24750
24895
|
getDepositPayload(params) {
|
|
24751
24896
|
return getStateManager().getDepositPayload(params);
|
|
24752
24897
|
},
|
|
24898
|
+
importNotes(params) {
|
|
24899
|
+
return getStateManager().importNotes(params);
|
|
24900
|
+
},
|
|
24753
24901
|
getWithdrawalPayloads(params, tailCalls) {
|
|
24754
24902
|
const fullParams = params.mode === "paymaster" && tailCalls ? { ...params, tailCalls } : params;
|
|
24755
24903
|
return getStateManager().getWithdrawalPayloads(fullParams);
|