@kohaku-eth/tornado-cash 0.0.1 → 0.0.2-alpha.8

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.
@@ -0,0 +1,152 @@
1
+ import * as comlink from 'comlink';
2
+ import { combineReducers } from '@reduxjs/toolkit';
3
+ import * as _kohaku_eth_plugins from '@kohaku-eth/plugins';
4
+ import { SignedAuthorization } from 'viem';
5
+ import * as _kohaku_eth_provider from '@kohaku-eth/provider';
6
+
7
+ type Address = bigint & {};
8
+ interface IContract {
9
+ address: Address;
10
+ }
11
+ interface IScrapeableContract extends IContract {
12
+ deploymentBlock: bigint;
13
+ }
14
+
15
+ interface InstanceRegistryConfig extends IScrapeableContract {
16
+ lastDeployedOnBlock?: bigint;
17
+ }
18
+ interface ProtocolConfigState {
19
+ chainId: bigint;
20
+ ensSubdomainKey: string;
21
+ instanceRegistry: InstanceRegistryConfig;
22
+ relayerRegistry: IScrapeableContract;
23
+ aggregator: IContract;
24
+ }
25
+
26
+ type RootState = ReturnType<ReturnType<typeof combineReducers<typeof reducers>>>;
27
+ type PublicRootState = Omit<RootState, 'userSecrets'>;
28
+
29
+ interface IRelayerStatusResponse {
30
+ currentQueue: number;
31
+ netId: number;
32
+ rewardAccount: string;
33
+ version: string;
34
+ tornadoServiceFee: number;
35
+ ethPrices: Record<string, string>;
36
+ }
37
+ interface ITornadoWithdrawRequest {
38
+ proof: `0x${string}`;
39
+ args: [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`];
40
+ contract: `0x${string}`;
41
+ }
42
+ interface ITornadoWithdrawResponse {
43
+ id: string;
44
+ }
45
+ interface IRelayerClient {
46
+ getStatus(hostname: string): Promise<IRelayerStatusResponse>;
47
+ withdraw(relayerUrl: string, body: ITornadoWithdrawRequest): Promise<ITornadoWithdrawResponse>;
48
+ }
49
+
50
+ interface TornadoProveOutput {
51
+ proof: `0x${string}`;
52
+ args: [
53
+ `0x${string}`,
54
+ `0x${string}`,
55
+ `0x${string}`,
56
+ `0x${string}`,
57
+ `0x${string}`,
58
+ `0x${string}`
59
+ ];
60
+ }
61
+
62
+ interface IRelayerFeeConfig {
63
+ minFee: number;
64
+ maxFee: number;
65
+ }
66
+
67
+ declare enum DepositStrategy {
68
+ MaxAnonimitySet = 0,
69
+ MinFee = 1
70
+ }
71
+
72
+ interface SignedDelegation {
73
+ senderAddress: `0x${string}`;
74
+ authorization: SignedAuthorization;
75
+ }
76
+ interface IPaymasterWithdrawalPayload {
77
+ mode: 'paymaster';
78
+ proof: TornadoProveOutput;
79
+ poolAddress: Address;
80
+ isERC20: boolean;
81
+ delegation?: SignedDelegation;
82
+ }
83
+
84
+ type DelegationConfig = {
85
+ mode: 'deterministic';
86
+ path?: string;
87
+ } | {
88
+ mode: 'random';
89
+ };
90
+ type StringAddress = `0x${string}`;
91
+ interface IPaymasterConfig {
92
+ paymasterAddress: StringAddress;
93
+ entryPointAddress: StringAddress;
94
+ poolsAccountsMap: Record<StringAddress, StringAddress>;
95
+ bundlerUrl: string;
96
+ }
97
+ type IChainsPaymastersConfig = Record<number, IPaymasterConfig>;
98
+ interface IRelayerWithdrawalPayload {
99
+ mode: 'relayer';
100
+ proof: TornadoProveOutput;
101
+ poolAddress: Address;
102
+ relayerUrl: string;
103
+ }
104
+ type IWithdrawalPayload = IRelayerWithdrawalPayload | IPaymasterWithdrawalPayload;
105
+ interface ITornadoArtifacts {
106
+ circuitText: string;
107
+ provingKey: ArrayBuffer;
108
+ }
109
+ type TCProtocolConfig = Omit<ProtocolConfigState, 'chainId'>;
110
+ interface IBaseOperationParams {
111
+ }
112
+ interface IDepositOperationParams extends IBaseOperationParams {
113
+ asset: Address;
114
+ amount: bigint;
115
+ strategy: DepositStrategy;
116
+ }
117
+ interface IWithdrawBaseParams extends Omit<IDepositOperationParams, 'amount' | 'strategy'> {
118
+ amount?: bigint;
119
+ recipient: Address;
120
+ }
121
+ interface IRelayerWithdrawParams extends IWithdrawBaseParams {
122
+ mode: 'relayer';
123
+ preferredRelayersEns?: string[];
124
+ }
125
+ interface IPaymasterWithdrawParams extends IWithdrawBaseParams {
126
+ mode: 'paymaster';
127
+ delegation?: DelegationConfig;
128
+ }
129
+ type IWithdrawapOperationParams = IRelayerWithdrawParams | IPaymasterWithdrawParams;
130
+ type StoreKey = `${string}-${string}`;
131
+ type StoreStorageKey = `tornado-cash-state-${StoreKey}`;
132
+
133
+ interface WorkerInitOptions {
134
+ protocolConfig: TCProtocolConfig;
135
+ relayerConfig?: IRelayerFeeConfig;
136
+ accountIndex: number;
137
+ paymasterConfig: IChainsPaymastersConfig;
138
+ }
139
+
140
+ declare function loadStateManagerWorker(workerUrl?: string | URL): {
141
+ remote: comlink.Remote<{
142
+ 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 }: WorkerInitOptions): Promise<void>;
143
+ sync(): Promise<void>;
144
+ getBalances(assets?: Address[]): Promise<Map<Address, bigint>>;
145
+ getDepositPayload(params: IDepositOperationParams): Promise<_kohaku_eth_provider.TxData[]>;
146
+ getWithdrawalPayloads(params: IWithdrawapOperationParams): Promise<IWithdrawalPayload[]>;
147
+ dumpState(): Record<StoreStorageKey, Omit<RootState, "userSecrets">>;
148
+ }>;
149
+ onError: (handler: (err: Error) => void) => void;
150
+ };
151
+
152
+ export { loadStateManagerWorker };
@@ -0,0 +1,13 @@
1
+ // src/plugin/worker-loader.browser.ts
2
+ import { wrap } from "comlink";
3
+ function loadStateManagerWorker(workerUrl) {
4
+ const url = workerUrl ?? new URL("../state/state-manager.worker.js", import.meta.url);
5
+ const worker = new Worker(url, { type: "module" });
6
+ return {
7
+ remote: wrap(worker),
8
+ onError: (handler) => worker.addEventListener("error", (e) => handler(e.error ?? new Error(e.message)))
9
+ };
10
+ }
11
+ export {
12
+ loadStateManagerWorker
13
+ };
@@ -0,0 +1,153 @@
1
+ import * as comlink from 'comlink';
2
+ import { combineReducers } from '@reduxjs/toolkit';
3
+ import * as _kohaku_eth_plugins from '@kohaku-eth/plugins';
4
+ import { SignedAuthorization } from 'viem';
5
+ import * as _kohaku_eth_provider from '@kohaku-eth/provider';
6
+ import { Worker } from 'worker_threads';
7
+
8
+ type Address = bigint & {};
9
+ interface IContract {
10
+ address: Address;
11
+ }
12
+ interface IScrapeableContract extends IContract {
13
+ deploymentBlock: bigint;
14
+ }
15
+
16
+ interface InstanceRegistryConfig extends IScrapeableContract {
17
+ lastDeployedOnBlock?: bigint;
18
+ }
19
+ interface ProtocolConfigState {
20
+ chainId: bigint;
21
+ ensSubdomainKey: string;
22
+ instanceRegistry: InstanceRegistryConfig;
23
+ relayerRegistry: IScrapeableContract;
24
+ aggregator: IContract;
25
+ }
26
+
27
+ type RootState = ReturnType<ReturnType<typeof combineReducers<typeof reducers>>>;
28
+ type PublicRootState = Omit<RootState, 'userSecrets'>;
29
+
30
+ interface IRelayerStatusResponse {
31
+ currentQueue: number;
32
+ netId: number;
33
+ rewardAccount: string;
34
+ version: string;
35
+ tornadoServiceFee: number;
36
+ ethPrices: Record<string, string>;
37
+ }
38
+ interface ITornadoWithdrawRequest {
39
+ proof: `0x${string}`;
40
+ args: [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`];
41
+ contract: `0x${string}`;
42
+ }
43
+ interface ITornadoWithdrawResponse {
44
+ id: string;
45
+ }
46
+ interface IRelayerClient {
47
+ getStatus(hostname: string): Promise<IRelayerStatusResponse>;
48
+ withdraw(relayerUrl: string, body: ITornadoWithdrawRequest): Promise<ITornadoWithdrawResponse>;
49
+ }
50
+
51
+ interface TornadoProveOutput {
52
+ proof: `0x${string}`;
53
+ args: [
54
+ `0x${string}`,
55
+ `0x${string}`,
56
+ `0x${string}`,
57
+ `0x${string}`,
58
+ `0x${string}`,
59
+ `0x${string}`
60
+ ];
61
+ }
62
+
63
+ interface IRelayerFeeConfig {
64
+ minFee: number;
65
+ maxFee: number;
66
+ }
67
+
68
+ declare enum DepositStrategy {
69
+ MaxAnonimitySet = 0,
70
+ MinFee = 1
71
+ }
72
+
73
+ interface SignedDelegation {
74
+ senderAddress: `0x${string}`;
75
+ authorization: SignedAuthorization;
76
+ }
77
+ interface IPaymasterWithdrawalPayload {
78
+ mode: 'paymaster';
79
+ proof: TornadoProveOutput;
80
+ poolAddress: Address;
81
+ isERC20: boolean;
82
+ delegation?: SignedDelegation;
83
+ }
84
+
85
+ type DelegationConfig = {
86
+ mode: 'deterministic';
87
+ path?: string;
88
+ } | {
89
+ mode: 'random';
90
+ };
91
+ type StringAddress = `0x${string}`;
92
+ interface IPaymasterConfig {
93
+ paymasterAddress: StringAddress;
94
+ entryPointAddress: StringAddress;
95
+ poolsAccountsMap: Record<StringAddress, StringAddress>;
96
+ bundlerUrl: string;
97
+ }
98
+ type IChainsPaymastersConfig = Record<number, IPaymasterConfig>;
99
+ interface IRelayerWithdrawalPayload {
100
+ mode: 'relayer';
101
+ proof: TornadoProveOutput;
102
+ poolAddress: Address;
103
+ relayerUrl: string;
104
+ }
105
+ type IWithdrawalPayload = IRelayerWithdrawalPayload | IPaymasterWithdrawalPayload;
106
+ interface ITornadoArtifacts {
107
+ circuitText: string;
108
+ provingKey: ArrayBuffer;
109
+ }
110
+ type TCProtocolConfig = Omit<ProtocolConfigState, 'chainId'>;
111
+ interface IBaseOperationParams {
112
+ }
113
+ interface IDepositOperationParams extends IBaseOperationParams {
114
+ asset: Address;
115
+ amount: bigint;
116
+ strategy: DepositStrategy;
117
+ }
118
+ interface IWithdrawBaseParams extends Omit<IDepositOperationParams, 'amount' | 'strategy'> {
119
+ amount?: bigint;
120
+ recipient: Address;
121
+ }
122
+ interface IRelayerWithdrawParams extends IWithdrawBaseParams {
123
+ mode: 'relayer';
124
+ preferredRelayersEns?: string[];
125
+ }
126
+ interface IPaymasterWithdrawParams extends IWithdrawBaseParams {
127
+ mode: 'paymaster';
128
+ delegation?: DelegationConfig;
129
+ }
130
+ type IWithdrawapOperationParams = IRelayerWithdrawParams | IPaymasterWithdrawParams;
131
+ type StoreKey = `${string}-${string}`;
132
+ type StoreStorageKey = `tornado-cash-state-${StoreKey}`;
133
+
134
+ interface WorkerInitOptions {
135
+ protocolConfig: TCProtocolConfig;
136
+ relayerConfig?: IRelayerFeeConfig;
137
+ accountIndex: number;
138
+ paymasterConfig: IChainsPaymastersConfig;
139
+ }
140
+
141
+ declare function loadStateManagerWorker(workerUrl?: string | URL): {
142
+ remote: comlink.Remote<{
143
+ 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 }: WorkerInitOptions): Promise<void>;
144
+ sync(): Promise<void>;
145
+ getBalances(assets?: Address[]): Promise<Map<Address, bigint>>;
146
+ getDepositPayload(params: IDepositOperationParams): Promise<_kohaku_eth_provider.TxData[]>;
147
+ getWithdrawalPayloads(params: IWithdrawapOperationParams): Promise<IWithdrawalPayload[]>;
148
+ dumpState(): Record<StoreStorageKey, Omit<RootState, "userSecrets">>;
149
+ }>;
150
+ onError: (handler: (err: Error) => void) => Worker;
151
+ };
152
+
153
+ export { loadStateManagerWorker };
@@ -0,0 +1,22 @@
1
+ // src/plugin/worker-loader.node.ts
2
+ import { wrap } from "comlink";
3
+ import nodeEndpoint from "comlink/dist/umd/node-adapter.js";
4
+ import { Worker } from "worker_threads";
5
+ import { fileURLToPath } from "url";
6
+ import { dirname, resolve } from "path";
7
+ function loadStateManagerWorker(workerUrl) {
8
+ if (workerUrl !== void 0) {
9
+ console.warn("[worker-loader.node] workerUrl is ignored in Node.js \u2014 the worker file is always loaded from the local filesystem.");
10
+ }
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);
15
+ return {
16
+ remote: wrap(nodeEndpoint(worker)),
17
+ onError: (handler) => worker.on("error", handler)
18
+ };
19
+ }
20
+ export {
21
+ loadStateManagerWorker
22
+ };
package/package.json CHANGED
@@ -1,17 +1,115 @@
1
1
  {
2
2
  "name": "@kohaku-eth/tornado-cash",
3
- "version": "0.0.1",
4
- "description": "",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
3
+ "version": "0.0.2-alpha.8",
4
+ "description": "Simplified Privacy Pools TS utils",
5
+ "type": "module",
6
+ "private": false,
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/ethereum/kohaku.git",
13
+ "directory": "packages/tornado-cash"
14
+ },
15
+ "imports": {
16
+ "#worker-loader": {
17
+ "node": "./dist/worker-loader.node.js",
18
+ "browser": "./src/plugin/worker-loader.browser.ts",
19
+ "default": "./src/plugin/worker-loader.browser.ts"
20
+ },
21
+ "#circuit-loader": {
22
+ "default": "./dist/circuit-loader.js"
23
+ }
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ },
30
+ "./state-manager.worker.js": "./dist/state-manager.worker.js",
31
+ "./state-manager.worker.node.cjs": "./dist/state-manager.worker.node.cjs",
32
+ "./worker-loader": {
33
+ "node": "./dist/worker-loader.node.js",
34
+ "browser": "./dist/worker-loader.browser.js",
35
+ "default": "./dist/worker-loader.browser.js"
36
+ },
37
+ "./worker-loader.browser": "./dist/worker-loader.browser.js",
38
+ "./worker-loader.node": "./dist/worker-loader.node.js",
39
+ "./circuits/*": "./circuits/*",
40
+ "./package.json": "./package.json"
41
+ },
42
+ "engines": {
43
+ "node": ">=18"
44
+ },
45
+ "files": [
46
+ "dist",
47
+ "circuits"
48
+ ],
49
+ "sideEffects": false,
50
+ "publishConfig": {
51
+ "access": "public"
8
52
  },
9
53
  "keywords": [],
10
54
  "author": "",
11
- "license": "ISC",
12
- "packageManager": "pnpm@10.15.0",
13
- "private": false,
14
- "publishConfig": {
15
- "access": "public"
55
+ "license": "MIT",
56
+ "peerDependencies": {
57
+ "ethers": "^6.13.1"
58
+ },
59
+ "peerDependenciesMeta": {
60
+ "ethers": {
61
+ "optional": true
16
62
  }
17
- }
63
+ },
64
+ "dependencies": {
65
+ "@noble/curves": "^2.2.0",
66
+ "@noble/hashes": "^2.2.0",
67
+ "@privacy-paymasters/sdk": "0.0.2",
68
+ "@reduxjs/toolkit": "^2.11.2",
69
+ "buffer": "^6.0.3",
70
+ "circomlibjs": "0.1.2",
71
+ "comlink": "^4.4.2",
72
+ "fixed-merkle-tree": "^0.7.3",
73
+ "maci-crypto": "2.5.0",
74
+ "micro-zk-proofs": "0.3.0",
75
+ "ox": "^0.12.0",
76
+ "snarkjs": "git+https://github.com/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5",
77
+ "viem": "^2.51.3",
78
+ "websnark": "git+https://github.com/tornadocash/websnark.git#4c0af6a8b65aabea3c09f377f63c44e7a58afa6d",
79
+ "@kohaku-eth/plugins": "0.0.1-alpha.8",
80
+ "@kohaku-eth/provider": "0.1.0-alpha.8"
81
+ },
82
+ "devDependencies": {
83
+ "@types/node": "^24.12.2",
84
+ "dotenv": "^17.2.1",
85
+ "ethers": "^6.16.0",
86
+ "get-port": "^7.1.0",
87
+ "prool": "^0.0.24",
88
+ "ts-node": "^10.9.2",
89
+ "tsup": "^8.5.0",
90
+ "tsx": "^4.17.0",
91
+ "typescript": "^5.9.2",
92
+ "vitest": "^3.0.0"
93
+ },
94
+ "scripts": {
95
+ "aux": "tsx src/account/keys.ts",
96
+ "check": "tsc --noEmit -p ./tsconfig.json",
97
+ "build": "echo Building @kohaku-eth/tornado-cash && tsup --config tsup.config.ts",
98
+ "dev": "tsup --config tsup.config.ts --watch",
99
+ "demo": "tsx demo/simple.ts",
100
+ "test": "vitest run --project=e2e-sepolia",
101
+ "test:unit": "vitest run --project=unit",
102
+ "test:e2e:sepolia": ". ./.env.e2e.tests && vitest run --project=e2e-sepolia",
103
+ "test:e2e:wl": ". ./.env.e2e.tests && vitest run --project=withdraw-sepolia",
104
+ "test:e2e:sh": ". ./.env.e2e.tests && vitest run --project=shield-sepolia",
105
+ "test:e2e:sh:debugger": ". ./.env.e2e.tests && vitest --inspect-brk --no-file-parallelism run --project=shield",
106
+ "test:e2e:wp:sepolia": "vitest run --project=withdraw-paymaster-sepolia",
107
+ "test:e2e:debugger": ". ./.env.e2e.tests && vitest --inspect-brk --no-file-parallelism run e2e",
108
+ "test:sync:sepolia": ". ./.env.e2e.tests && vitest run --project=sync-sepolia",
109
+ "test:sync:mainnet": ". ./.env.e2e.tests && vitest run --project=sync-mainnet",
110
+ "test:sync:debugger": ". ./.env.e2e.tests && vitest --inspect-brk --no-file-parallelism run --project=sync",
111
+ "test:watch": "vitest",
112
+ "lint": "eslint .",
113
+ "lint:fix": "eslint . --fix"
114
+ }
115
+ }
package/index.js DELETED
File without changes