@kohaku-eth/tornado-cash 0.0.2-alpha.11 → 0.0.2-alpha.13

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.
@@ -1,10 +1,14 @@
1
1
  import * as comlink from 'comlink';
2
2
  import { combineReducers } from '@reduxjs/toolkit';
3
3
  import * as _kohaku_eth_plugins from '@kohaku-eth/plugins';
4
- import { SignedAuthorization } from 'viem';
4
+ import { ExternalSyncPoolId, ExternalRawEvent, AccountId } from '@kohaku-eth/plugins';
5
+ import { Hex } from 'ox/Hex';
5
6
  import * as _kohaku_eth_provider from '@kohaku-eth/provider';
7
+ import { TxData } from '@kohaku-eth/provider';
8
+ import { Address as Address$1 } from 'ox/Address';
6
9
 
7
10
  type Address = bigint & {};
11
+ type Commitment = bigint & {};
8
12
  interface IContract {
9
13
  address: Address;
10
14
  }
@@ -26,6 +30,43 @@ interface ProtocolConfigState {
26
30
  type RootState = ReturnType<ReturnType<typeof combineReducers<typeof reducers>>>;
27
31
  type PublicRootState = Omit<RootState, 'userSecrets'>;
28
32
 
33
+ interface IBaseEvent {
34
+ blockNumber: bigint;
35
+ transactionHash: bigint;
36
+ }
37
+ interface IPoolEvent extends IBaseEvent {
38
+ pool: Address;
39
+ }
40
+ interface IDepositEvent extends IPoolEvent {
41
+ commitment: Commitment;
42
+ leafIndex: number;
43
+ timestamp: bigint;
44
+ }
45
+ interface IIndexedDepositEvent extends IDepositEvent {
46
+ index: number;
47
+ }
48
+ interface IDepositWithAsset extends IIndexedDepositEvent {
49
+ assetAddress: Address;
50
+ }
51
+ interface IDepositWithBalance extends IDepositWithAsset {
52
+ balance: bigint;
53
+ }
54
+
55
+ /**
56
+ * Worker-facing view of the host's `ExternalSyncProvider`. The host exposes a
57
+ * streaming provider (`streamEvents` returning an async iterator), but async
58
+ * iterators cannot cross the Comlink worker boundary. The plugin adapts the
59
+ * provider into this materialized-array shape on the main thread before proxying
60
+ * it into the state-manager worker (see `plugin/base.ts`).
61
+ */
62
+ type ExternalSyncClient = {
63
+ getEvents(params: ExternalSyncPoolId & {
64
+ fromBlock: Hex;
65
+ toBlock: Hex;
66
+ }): Promise<ExternalRawEvent[]>;
67
+ lastCoveredBlock(params: ExternalSyncPoolId): Promise<Hex | null>;
68
+ };
69
+
29
70
  interface IRelayerStatusResponse {
30
71
  currentQueue: number;
31
72
  netId: number;
@@ -47,18 +88,6 @@ interface IRelayerClient {
47
88
  withdraw(relayerUrl: string, body: ITornadoWithdrawRequest): Promise<ITornadoWithdrawResponse>;
48
89
  }
49
90
 
50
- interface TornadoWithdrawInputs {
51
- nullifier: bigint;
52
- secret: bigint;
53
- pathElements: bigint[];
54
- pathIndices: number[];
55
- root: bigint;
56
- nullifierHash: bigint;
57
- recipient: bigint;
58
- relayer: bigint;
59
- fee: bigint;
60
- refund: bigint;
61
- }
62
91
  interface TornadoProveOutput {
63
92
  proof: `0x${string}`;
64
93
  args: [
@@ -70,9 +99,6 @@ interface TornadoProveOutput {
70
99
  `0x${string}`
71
100
  ];
72
101
  }
73
- interface ITornadoProver {
74
- prove(inputs: TornadoWithdrawInputs): Promise<TornadoProveOutput>;
75
- }
76
102
 
77
103
  interface IRelayerFeeConfig {
78
104
  minFee: number;
@@ -84,10 +110,36 @@ declare enum DepositStrategy {
84
110
  MinFee = 1
85
111
  }
86
112
 
87
- interface SignedDelegation {
88
- senderAddress: `0x${string}`;
89
- authorization: SignedAuthorization;
113
+ interface SerializedAuth {
114
+ address: Address$1;
115
+ chainId: Hex;
116
+ nonce: Hex;
117
+ r: Hex;
118
+ s: Hex;
119
+ yParity: Hex;
120
+ }
121
+ /**
122
+ * A userOp serialized to the hex shape expected by `eth_sendUserOperation`, so
123
+ * it can be carried as plain (JSON-serializable) data from the prepare phase
124
+ * (thunk) to the broadcast phase.
125
+ */
126
+ interface SerializedUserOperation {
127
+ sender: `0x${string}`;
128
+ nonce: `0x${string}`;
129
+ callData: `0x${string}`;
130
+ callGasLimit: `0x${string}`;
131
+ verificationGasLimit: `0x${string}`;
132
+ preVerificationGas: `0x${string}`;
133
+ maxFeePerGas: `0x${string}`;
134
+ maxPriorityFeePerGas: `0x${string}`;
135
+ paymaster?: `0x${string}`;
136
+ paymasterVerificationGasLimit?: `0x${string}`;
137
+ paymasterPostOpGasLimit?: `0x${string}`;
138
+ paymasterData?: `0x${string}`;
139
+ signature: `0x${string}`;
140
+ eip7702Auth?: SerializedAuth;
90
141
  }
142
+
91
143
  interface IGenericPaymasterWithdrawalPayload {
92
144
  mode: 'paymaster';
93
145
  proof: TornadoProveOutput;
@@ -96,8 +148,7 @@ interface IGenericPaymasterWithdrawalPayload {
96
148
  paymasterAddress: `0x${string}`;
97
149
  entryPointAddress: `0x${string}`;
98
150
  bundlerUrl: string;
99
- accountAddress: `0x${string}`;
100
- delegation?: SignedDelegation;
151
+ userOperation: SerializedUserOperation;
101
152
  }
102
153
 
103
154
  type DelegationConfig = {
@@ -144,28 +195,37 @@ interface IRelayerWithdrawParams extends IWithdrawBaseParams {
144
195
  interface IPaymasterWithdrawParams extends IWithdrawBaseParams {
145
196
  mode: 'paymaster';
146
197
  delegation?: DelegationConfig;
198
+ tailCalls?: (address: AccountId) => Promise<TxData[]>;
147
199
  }
148
200
  type IWithdrawapOperationParams = IRelayerWithdrawParams | IPaymasterWithdrawParams;
201
+ interface IGetNotesParams extends IBaseOperationParams {
202
+ includeSpent?: boolean;
203
+ assets?: Address[];
204
+ }
205
+ type TCNote = Pick<IDepositWithBalance, 'commitment' | 'balance' | 'assetAddress' | 'timestamp' | 'leafIndex' | 'pool'> & {
206
+ /** Fixed pool denomination for this note. */
207
+ amount: bigint;
208
+ depositIndex: number;
209
+ };
149
210
  type StoreKey = `${string}-${string}`;
150
211
  type StoreStorageKey = `tornado-cash-state-${StoreKey}`;
151
212
 
152
- declare function makeLazyProverFactory(artifactsLoader: () => Promise<ITornadoArtifacts>, version?: 'legacy' | 'js'): () => Promise<ITornadoProver>;
153
-
154
213
  interface WorkerInitOptions {
155
214
  protocolConfig: TCProtocolConfig;
156
215
  relayerConfig?: IRelayerFeeConfig;
157
216
  accountIndex: number;
158
217
  paymasterConfig: IChainsPaymastersConfig;
159
- proverVersion?: Parameters<typeof makeLazyProverFactory>[1];
218
+ minExternalSyncBlocksAmount?: number;
160
219
  }
161
220
 
162
221
  declare function loadStateManagerWorker(workerUrl?: string | URL): {
163
222
  remote: comlink.Remote<{
164
- init(provider: _kohaku_eth_provider.EthereumProvider, relayerClient: IRelayerClient, keystore: _kohaku_eth_plugins.Keystore, rawStorage: Omit<_kohaku_eth_plugins.Storage, "_brand">, initialState: () => Promise<Record<string, PublicRootState>>, artifactsLoader: () => Promise<ITornadoArtifacts>, { protocolConfig, accountIndex, relayerConfig, paymasterConfig, proverVersion }: WorkerInitOptions): Promise<void>;
223
+ init(provider: _kohaku_eth_provider.EthereumProvider, relayerClient: IRelayerClient, keystore: _kohaku_eth_plugins.Keystore, rawStorage: Omit<_kohaku_eth_plugins.Storage, "_brand">, initialState: () => Promise<Record<string, PublicRootState>>, artifactsLoader: () => Promise<ITornadoArtifacts>, externalSyncProvider: ExternalSyncClient | undefined, { protocolConfig, accountIndex, relayerConfig, paymasterConfig, minExternalSyncBlocksAmount }: WorkerInitOptions): Promise<void>;
165
224
  sync(): Promise<void>;
166
225
  getBalances(assets?: Address[]): Promise<Map<Address, bigint>>;
226
+ getNotes(params: IGetNotesParams): Promise<TCNote[]>;
167
227
  getDepositPayload(params: IDepositOperationParams): Promise<_kohaku_eth_provider.TxData[]>;
168
- getWithdrawalPayloads(params: IWithdrawapOperationParams): Promise<IWithdrawalPayload[]>;
228
+ getWithdrawalPayloads(params: IWithdrawapOperationParams, tailCalls?: IPaymasterWithdrawParams["tailCalls"]): Promise<IWithdrawalPayload[]>;
169
229
  dumpState(): Record<StoreStorageKey, Omit<RootState, "userSecrets">>;
170
230
  }>;
171
231
  onError: (handler: (err: Error) => void) => void;
@@ -1,11 +1,15 @@
1
1
  import * as comlink from 'comlink';
2
2
  import { combineReducers } from '@reduxjs/toolkit';
3
3
  import * as _kohaku_eth_plugins from '@kohaku-eth/plugins';
4
- import { SignedAuthorization } from 'viem';
4
+ import { ExternalSyncPoolId, ExternalRawEvent, AccountId } from '@kohaku-eth/plugins';
5
+ import { Hex } from 'ox/Hex';
5
6
  import * as _kohaku_eth_provider from '@kohaku-eth/provider';
7
+ import { TxData } from '@kohaku-eth/provider';
8
+ import { Address as Address$1 } from 'ox/Address';
6
9
  import { Worker } from 'worker_threads';
7
10
 
8
11
  type Address = bigint & {};
12
+ type Commitment = bigint & {};
9
13
  interface IContract {
10
14
  address: Address;
11
15
  }
@@ -27,6 +31,43 @@ interface ProtocolConfigState {
27
31
  type RootState = ReturnType<ReturnType<typeof combineReducers<typeof reducers>>>;
28
32
  type PublicRootState = Omit<RootState, 'userSecrets'>;
29
33
 
34
+ interface IBaseEvent {
35
+ blockNumber: bigint;
36
+ transactionHash: bigint;
37
+ }
38
+ interface IPoolEvent extends IBaseEvent {
39
+ pool: Address;
40
+ }
41
+ interface IDepositEvent extends IPoolEvent {
42
+ commitment: Commitment;
43
+ leafIndex: number;
44
+ timestamp: bigint;
45
+ }
46
+ interface IIndexedDepositEvent extends IDepositEvent {
47
+ index: number;
48
+ }
49
+ interface IDepositWithAsset extends IIndexedDepositEvent {
50
+ assetAddress: Address;
51
+ }
52
+ interface IDepositWithBalance extends IDepositWithAsset {
53
+ balance: bigint;
54
+ }
55
+
56
+ /**
57
+ * Worker-facing view of the host's `ExternalSyncProvider`. The host exposes a
58
+ * streaming provider (`streamEvents` returning an async iterator), but async
59
+ * iterators cannot cross the Comlink worker boundary. The plugin adapts the
60
+ * provider into this materialized-array shape on the main thread before proxying
61
+ * it into the state-manager worker (see `plugin/base.ts`).
62
+ */
63
+ type ExternalSyncClient = {
64
+ getEvents(params: ExternalSyncPoolId & {
65
+ fromBlock: Hex;
66
+ toBlock: Hex;
67
+ }): Promise<ExternalRawEvent[]>;
68
+ lastCoveredBlock(params: ExternalSyncPoolId): Promise<Hex | null>;
69
+ };
70
+
30
71
  interface IRelayerStatusResponse {
31
72
  currentQueue: number;
32
73
  netId: number;
@@ -48,18 +89,6 @@ interface IRelayerClient {
48
89
  withdraw(relayerUrl: string, body: ITornadoWithdrawRequest): Promise<ITornadoWithdrawResponse>;
49
90
  }
50
91
 
51
- interface TornadoWithdrawInputs {
52
- nullifier: bigint;
53
- secret: bigint;
54
- pathElements: bigint[];
55
- pathIndices: number[];
56
- root: bigint;
57
- nullifierHash: bigint;
58
- recipient: bigint;
59
- relayer: bigint;
60
- fee: bigint;
61
- refund: bigint;
62
- }
63
92
  interface TornadoProveOutput {
64
93
  proof: `0x${string}`;
65
94
  args: [
@@ -71,9 +100,6 @@ interface TornadoProveOutput {
71
100
  `0x${string}`
72
101
  ];
73
102
  }
74
- interface ITornadoProver {
75
- prove(inputs: TornadoWithdrawInputs): Promise<TornadoProveOutput>;
76
- }
77
103
 
78
104
  interface IRelayerFeeConfig {
79
105
  minFee: number;
@@ -85,10 +111,36 @@ declare enum DepositStrategy {
85
111
  MinFee = 1
86
112
  }
87
113
 
88
- interface SignedDelegation {
89
- senderAddress: `0x${string}`;
90
- authorization: SignedAuthorization;
114
+ interface SerializedAuth {
115
+ address: Address$1;
116
+ chainId: Hex;
117
+ nonce: Hex;
118
+ r: Hex;
119
+ s: Hex;
120
+ yParity: Hex;
121
+ }
122
+ /**
123
+ * A userOp serialized to the hex shape expected by `eth_sendUserOperation`, so
124
+ * it can be carried as plain (JSON-serializable) data from the prepare phase
125
+ * (thunk) to the broadcast phase.
126
+ */
127
+ interface SerializedUserOperation {
128
+ sender: `0x${string}`;
129
+ nonce: `0x${string}`;
130
+ callData: `0x${string}`;
131
+ callGasLimit: `0x${string}`;
132
+ verificationGasLimit: `0x${string}`;
133
+ preVerificationGas: `0x${string}`;
134
+ maxFeePerGas: `0x${string}`;
135
+ maxPriorityFeePerGas: `0x${string}`;
136
+ paymaster?: `0x${string}`;
137
+ paymasterVerificationGasLimit?: `0x${string}`;
138
+ paymasterPostOpGasLimit?: `0x${string}`;
139
+ paymasterData?: `0x${string}`;
140
+ signature: `0x${string}`;
141
+ eip7702Auth?: SerializedAuth;
91
142
  }
143
+
92
144
  interface IGenericPaymasterWithdrawalPayload {
93
145
  mode: 'paymaster';
94
146
  proof: TornadoProveOutput;
@@ -97,8 +149,7 @@ interface IGenericPaymasterWithdrawalPayload {
97
149
  paymasterAddress: `0x${string}`;
98
150
  entryPointAddress: `0x${string}`;
99
151
  bundlerUrl: string;
100
- accountAddress: `0x${string}`;
101
- delegation?: SignedDelegation;
152
+ userOperation: SerializedUserOperation;
102
153
  }
103
154
 
104
155
  type DelegationConfig = {
@@ -145,28 +196,37 @@ interface IRelayerWithdrawParams extends IWithdrawBaseParams {
145
196
  interface IPaymasterWithdrawParams extends IWithdrawBaseParams {
146
197
  mode: 'paymaster';
147
198
  delegation?: DelegationConfig;
199
+ tailCalls?: (address: AccountId) => Promise<TxData[]>;
148
200
  }
149
201
  type IWithdrawapOperationParams = IRelayerWithdrawParams | IPaymasterWithdrawParams;
202
+ interface IGetNotesParams extends IBaseOperationParams {
203
+ includeSpent?: boolean;
204
+ assets?: Address[];
205
+ }
206
+ type TCNote = Pick<IDepositWithBalance, 'commitment' | 'balance' | 'assetAddress' | 'timestamp' | 'leafIndex' | 'pool'> & {
207
+ /** Fixed pool denomination for this note. */
208
+ amount: bigint;
209
+ depositIndex: number;
210
+ };
150
211
  type StoreKey = `${string}-${string}`;
151
212
  type StoreStorageKey = `tornado-cash-state-${StoreKey}`;
152
213
 
153
- declare function makeLazyProverFactory(artifactsLoader: () => Promise<ITornadoArtifacts>, version?: 'legacy' | 'js'): () => Promise<ITornadoProver>;
154
-
155
214
  interface WorkerInitOptions {
156
215
  protocolConfig: TCProtocolConfig;
157
216
  relayerConfig?: IRelayerFeeConfig;
158
217
  accountIndex: number;
159
218
  paymasterConfig: IChainsPaymastersConfig;
160
- proverVersion?: Parameters<typeof makeLazyProverFactory>[1];
219
+ minExternalSyncBlocksAmount?: number;
161
220
  }
162
221
 
163
222
  declare function loadStateManagerWorker(workerUrl?: string | URL): {
164
223
  remote: comlink.Remote<{
165
- init(provider: _kohaku_eth_provider.EthereumProvider, relayerClient: IRelayerClient, keystore: _kohaku_eth_plugins.Keystore, rawStorage: Omit<_kohaku_eth_plugins.Storage, "_brand">, initialState: () => Promise<Record<string, PublicRootState>>, artifactsLoader: () => Promise<ITornadoArtifacts>, { protocolConfig, accountIndex, relayerConfig, paymasterConfig, proverVersion }: WorkerInitOptions): Promise<void>;
224
+ init(provider: _kohaku_eth_provider.EthereumProvider, relayerClient: IRelayerClient, keystore: _kohaku_eth_plugins.Keystore, rawStorage: Omit<_kohaku_eth_plugins.Storage, "_brand">, initialState: () => Promise<Record<string, PublicRootState>>, artifactsLoader: () => Promise<ITornadoArtifacts>, externalSyncProvider: ExternalSyncClient | undefined, { protocolConfig, accountIndex, relayerConfig, paymasterConfig, minExternalSyncBlocksAmount }: WorkerInitOptions): Promise<void>;
166
225
  sync(): Promise<void>;
167
226
  getBalances(assets?: Address[]): Promise<Map<Address, bigint>>;
227
+ getNotes(params: IGetNotesParams): Promise<TCNote[]>;
168
228
  getDepositPayload(params: IDepositOperationParams): Promise<_kohaku_eth_provider.TxData[]>;
169
- getWithdrawalPayloads(params: IWithdrawapOperationParams): Promise<IWithdrawalPayload[]>;
229
+ getWithdrawalPayloads(params: IWithdrawapOperationParams, tailCalls?: IPaymasterWithdrawParams["tailCalls"]): Promise<IWithdrawalPayload[]>;
170
230
  dumpState(): Record<StoreStorageKey, Omit<RootState, "userSecrets">>;
171
231
  }>;
172
232
  onError: (handler: (err: Error) => void) => Worker;
@@ -2,16 +2,11 @@
2
2
  import { wrap } from "comlink";
3
3
  import nodeEndpoint from "comlink/dist/umd/node-adapter.js";
4
4
  import { Worker } from "worker_threads";
5
- import { fileURLToPath } from "url";
6
- import { dirname, resolve } from "path";
7
5
  function loadStateManagerWorker(workerUrl) {
8
6
  if (workerUrl !== void 0) {
9
7
  console.warn("[worker-loader.node] workerUrl is ignored in Node.js \u2014 the worker file is always loaded from the local filesystem.");
10
8
  }
11
- const thisFile = fileURLToPath(import.meta.url);
12
- const thisDir = dirname(thisFile);
13
- const workerPath = resolve(thisDir, `./state-manager.worker.node.cjs`);
14
- const worker = new Worker(workerPath);
9
+ const worker = new Worker(new URL("./state-manager.worker.node.js", import.meta.url));
15
10
  return {
16
11
  remote: wrap(nodeEndpoint(worker)),
17
12
  onError: (handler) => worker.on("error", handler)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kohaku-eth/tornado-cash",
3
- "version": "0.0.2-alpha.11",
3
+ "version": "0.0.2-alpha.13",
4
4
  "description": "Tornado Cash Shielded Pool Kohaku Plugin",
5
5
  "type": "module",
6
6
  "private": false,
@@ -20,6 +20,11 @@
20
20
  },
21
21
  "#circuit-loader": {
22
22
  "default": "./dist/circuit-loader.js"
23
+ },
24
+ "#merkle-tree": {
25
+ "node": "./dist/merkle-tree.node.js",
26
+ "browser": "./dist/merkle-tree.browser.js",
27
+ "default": "./dist/merkle-tree.browser.js"
23
28
  }
24
29
  },
25
30
  "exports": {
@@ -36,7 +41,6 @@
36
41
  },
37
42
  "./worker-loader.browser": "./dist/worker-loader.browser.js",
38
43
  "./worker-loader.node": "./dist/worker-loader.node.js",
39
- "./circuits/*": "./circuits/*",
40
44
  "./package.json": "./package.json"
41
45
  },
42
46
  "engines": {
@@ -64,20 +68,15 @@
64
68
  "dependencies": {
65
69
  "@noble/curves": "^2.2.0",
66
70
  "@noble/hashes": "^2.2.0",
67
- "@privacy-paymasters/sdk": "0.0.2",
71
+ "@privacy-paymasters/sdk": "0.0.4",
68
72
  "@reduxjs/toolkit": "^2.11.2",
69
- "buffer": "^6.0.3",
70
- "circomlibjs": "0.1.2",
71
73
  "comlink": "^4.4.2",
72
- "fixed-merkle-tree": "^0.7.3",
73
- "maci-crypto": "2.5.0",
74
- "micro-zk-proofs": "0.3.0",
74
+ "micro-zk-proofs": "0.3.1",
75
75
  "ox": "^0.12.0",
76
- "snarkjs": "git+https://github.com/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5",
77
76
  "viem": "^2.51.3",
78
- "websnark": "git+https://github.com/tornadocash/websnark.git#4c0af6a8b65aabea3c09f377f63c44e7a58afa6d",
79
77
  "@kohaku-eth/provider": "0.1.0-alpha.8",
80
- "@kohaku-eth/plugins": "0.0.1-alpha.9"
78
+ "mimc-tree": "0.1.0",
79
+ "@kohaku-eth/plugins": "0.0.1-alpha.11"
81
80
  },
82
81
  "devDependencies": {
83
82
  "@types/node": "^24.12.2",