@kohaku-eth/tornado-cash 0.0.2-alpha.11 → 0.0.2-alpha.12
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 +70 -49
- package/dist/index.js +20 -5
- package/dist/merkle-tree-worker.browser.js +3570 -0
- package/dist/merkle-tree-worker.node.js +3595 -0
- package/dist/merkle-tree.browser.js +13 -0
- package/dist/merkle-tree.node.js +13 -0
- package/dist/msm-worker.browser.js +1 -1
- package/dist/msm-worker.js +1 -1
- package/dist/state-manager.worker.js +8214 -12673
- package/dist/{state-manager.worker.node.cjs → state-manager.worker.node.js} +4488 -7577
- package/dist/worker-loader.browser.d.ts +34 -19
- package/dist/worker-loader.node.d.ts +34 -19
- package/dist/worker-loader.node.js +1 -6
- package/package.json +9 -10
package/dist/index.d.ts
CHANGED
|
@@ -39,41 +39,6 @@ interface SecretManagerParams {
|
|
|
39
39
|
}
|
|
40
40
|
declare function SecretManager({ host: { keystore }, accountIndex }: SecretManagerParams): Promise<ISecretManager>;
|
|
41
41
|
|
|
42
|
-
interface IRelayerStatusResponse {
|
|
43
|
-
currentQueue: number;
|
|
44
|
-
netId: number;
|
|
45
|
-
rewardAccount: string;
|
|
46
|
-
version: string;
|
|
47
|
-
tornadoServiceFee: number;
|
|
48
|
-
ethPrices: Record<string, string>;
|
|
49
|
-
}
|
|
50
|
-
interface ITornadoWithdrawRequest {
|
|
51
|
-
proof: `0x${string}`;
|
|
52
|
-
args: [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`];
|
|
53
|
-
contract: `0x${string}`;
|
|
54
|
-
}
|
|
55
|
-
interface ITornadoWithdrawResponse {
|
|
56
|
-
id: string;
|
|
57
|
-
}
|
|
58
|
-
interface IRelayerClient {
|
|
59
|
-
getStatus(hostname: string): Promise<IRelayerStatusResponse>;
|
|
60
|
-
withdraw(relayerUrl: string, body: ITornadoWithdrawRequest): Promise<ITornadoWithdrawResponse>;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
interface InstanceRegistryConfig extends IScrapeableContract {
|
|
64
|
-
lastDeployedOnBlock?: bigint;
|
|
65
|
-
}
|
|
66
|
-
interface ProtocolConfigState {
|
|
67
|
-
chainId: bigint;
|
|
68
|
-
ensSubdomainKey: string;
|
|
69
|
-
instanceRegistry: InstanceRegistryConfig;
|
|
70
|
-
relayerRegistry: IScrapeableContract;
|
|
71
|
-
aggregator: IContract;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
type RootState = ReturnType<ReturnType<typeof combineReducers<typeof reducers>>>;
|
|
75
|
-
type PublicRootState = Omit<RootState, 'userSecrets'>;
|
|
76
|
-
|
|
77
42
|
interface IBaseEvent {
|
|
78
43
|
blockNumber: bigint;
|
|
79
44
|
transactionHash: bigint;
|
|
@@ -86,6 +51,15 @@ interface IDepositEvent extends IPoolEvent {
|
|
|
86
51
|
leafIndex: number;
|
|
87
52
|
timestamp: bigint;
|
|
88
53
|
}
|
|
54
|
+
interface IIndexedDepositEvent extends IDepositEvent {
|
|
55
|
+
index: number;
|
|
56
|
+
}
|
|
57
|
+
interface IDepositWithAsset extends IIndexedDepositEvent {
|
|
58
|
+
assetAddress: Address;
|
|
59
|
+
}
|
|
60
|
+
interface IDepositWithBalance extends IDepositWithAsset {
|
|
61
|
+
balance: bigint;
|
|
62
|
+
}
|
|
89
63
|
interface IWithdrawalEvent extends IPoolEvent {
|
|
90
64
|
to: Address;
|
|
91
65
|
nullifierHash: NullifierHash;
|
|
@@ -111,6 +85,41 @@ interface IAsset {
|
|
|
111
85
|
symbol: string;
|
|
112
86
|
}
|
|
113
87
|
|
|
88
|
+
interface IRelayerStatusResponse {
|
|
89
|
+
currentQueue: number;
|
|
90
|
+
netId: number;
|
|
91
|
+
rewardAccount: string;
|
|
92
|
+
version: string;
|
|
93
|
+
tornadoServiceFee: number;
|
|
94
|
+
ethPrices: Record<string, string>;
|
|
95
|
+
}
|
|
96
|
+
interface ITornadoWithdrawRequest {
|
|
97
|
+
proof: `0x${string}`;
|
|
98
|
+
args: [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`];
|
|
99
|
+
contract: `0x${string}`;
|
|
100
|
+
}
|
|
101
|
+
interface ITornadoWithdrawResponse {
|
|
102
|
+
id: string;
|
|
103
|
+
}
|
|
104
|
+
interface IRelayerClient {
|
|
105
|
+
getStatus(hostname: string): Promise<IRelayerStatusResponse>;
|
|
106
|
+
withdraw(relayerUrl: string, body: ITornadoWithdrawRequest): Promise<ITornadoWithdrawResponse>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface InstanceRegistryConfig extends IScrapeableContract {
|
|
110
|
+
lastDeployedOnBlock?: bigint;
|
|
111
|
+
}
|
|
112
|
+
interface ProtocolConfigState {
|
|
113
|
+
chainId: bigint;
|
|
114
|
+
ensSubdomainKey: string;
|
|
115
|
+
instanceRegistry: InstanceRegistryConfig;
|
|
116
|
+
relayerRegistry: IScrapeableContract;
|
|
117
|
+
aggregator: IContract;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
type RootState = ReturnType<ReturnType<typeof combineReducers<typeof reducers>>>;
|
|
121
|
+
type PublicRootState = Omit<RootState, 'userSecrets'>;
|
|
122
|
+
|
|
114
123
|
declare const POOL_EVENTS_SIGNATURES: {
|
|
115
124
|
readonly Deposited: {
|
|
116
125
|
readonly name: "Deposit";
|
|
@@ -323,16 +332,6 @@ interface IPaymasterBroadcasterClient {
|
|
|
323
332
|
broadcast(withdrawals: IPaymasterWithdrawalPayload[]): Promise<PaymasterBroadcastResult[]>;
|
|
324
333
|
}
|
|
325
334
|
|
|
326
|
-
declare function makeLazyProverFactory(artifactsLoader: () => Promise<ITornadoArtifacts>, version?: 'legacy' | 'js'): () => Promise<ITornadoProver>;
|
|
327
|
-
|
|
328
|
-
interface WorkerInitOptions {
|
|
329
|
-
protocolConfig: TCProtocolConfig;
|
|
330
|
-
relayerConfig?: IRelayerFeeConfig;
|
|
331
|
-
accountIndex: number;
|
|
332
|
-
paymasterConfig: IChainsPaymastersConfig;
|
|
333
|
-
proverVersion?: Parameters<typeof makeLazyProverFactory>[1];
|
|
334
|
-
}
|
|
335
|
-
|
|
336
335
|
type DelegationConfig = {
|
|
337
336
|
mode: 'deterministic';
|
|
338
337
|
path?: string;
|
|
@@ -367,7 +366,7 @@ interface ITornadoArtifacts {
|
|
|
367
366
|
provingKey: ArrayBuffer;
|
|
368
367
|
}
|
|
369
368
|
type TCProtocolConfig = Omit<ProtocolConfigState, 'chainId'>;
|
|
370
|
-
interface TCProtocolParams
|
|
369
|
+
interface TCProtocolParams {
|
|
371
370
|
accountIndex?: number;
|
|
372
371
|
paymasterConfig: IChainsPaymastersConfig;
|
|
373
372
|
secretManagerFactory: (params: SecretManagerParams) => Promise<ISecretManager>;
|
|
@@ -399,6 +398,15 @@ interface IPaymasterWithdrawParams extends IWithdrawBaseParams {
|
|
|
399
398
|
delegation?: DelegationConfig;
|
|
400
399
|
}
|
|
401
400
|
type IWithdrawapOperationParams = IRelayerWithdrawParams | IPaymasterWithdrawParams;
|
|
401
|
+
interface IGetNotesParams extends IBaseOperationParams {
|
|
402
|
+
includeSpent?: boolean;
|
|
403
|
+
assets?: Address[];
|
|
404
|
+
}
|
|
405
|
+
type TCNote = Pick<IDepositWithBalance, 'commitment' | 'balance' | 'assetAddress' | 'timestamp' | 'leafIndex' | 'pool'> & {
|
|
406
|
+
/** Fixed pool denomination for this note. */
|
|
407
|
+
amount: bigint;
|
|
408
|
+
depositIndex: number;
|
|
409
|
+
};
|
|
402
410
|
type StoreKey = `${string}-${string}`;
|
|
403
411
|
type StoreStorageKey = `tornado-cash-state-${StoreKey}`;
|
|
404
412
|
interface IStateManager {
|
|
@@ -419,6 +427,12 @@ interface IStateManager {
|
|
|
419
427
|
* All assets if not specified.
|
|
420
428
|
*/
|
|
421
429
|
getBalances: SpecificAssetBalanceFn<true>;
|
|
430
|
+
/**
|
|
431
|
+
* Gets all notes for the account.
|
|
432
|
+
* @param includeSpent - If true, include notes with zero balance
|
|
433
|
+
* @param assets - Optional filter by specific assets
|
|
434
|
+
*/
|
|
435
|
+
getNotes: (params: IGetNotesParams) => Promise<TCNote[]>;
|
|
422
436
|
dumpState: () => Record<StoreStorageKey, PublicRootState>;
|
|
423
437
|
}
|
|
424
438
|
|
|
@@ -431,7 +445,7 @@ type TCBroadcaster = Broadcaster<TCPrivateOperation, ITornadoWithdrawResponse[]>
|
|
|
431
445
|
interface TCBaseCredential {
|
|
432
446
|
accountIndex: number;
|
|
433
447
|
}
|
|
434
|
-
interface TCPluginParameters extends TCBroadcasterParameters, TCBaseCredential, Pick<TCProtocolParams, '
|
|
448
|
+
interface TCPluginParameters extends TCBroadcasterParameters, TCBaseCredential, Pick<TCProtocolParams, 'initialState'> {
|
|
435
449
|
protocolConfig: TCProtocolConfig;
|
|
436
450
|
relayerConfig?: IRelayerFeeConfig;
|
|
437
451
|
stateManagerWorkerUrl?: string;
|
|
@@ -463,6 +477,7 @@ type TCInstance = PluginInstance<TCAddress, {
|
|
|
463
477
|
output: TCAssetAmount;
|
|
464
478
|
read: TCAssetBalance;
|
|
465
479
|
};
|
|
480
|
+
note: TCNote;
|
|
466
481
|
extras: {
|
|
467
482
|
sync(): Promise<void>;
|
|
468
483
|
prepareShield(asset: TCAssetAmount, options: TCPrepareShieldOptions): Promise<TCPublicOperation>;
|
|
@@ -480,7 +495,7 @@ type RequireOnly<T, Keys extends keyof T> = Partial<T> & Pick<T, Keys>;
|
|
|
480
495
|
declare class TornadoCashProtocol implements TCInstance {
|
|
481
496
|
readonly host: Host;
|
|
482
497
|
private stateManager;
|
|
483
|
-
constructor(host: Host, { accountIndex, initialState, protocolConfig, artifactsLoader, stateManagerWorkerUrl, relayerConfig, paymasterConfig, relayerClientFactory,
|
|
498
|
+
constructor(host: Host, { accountIndex, initialState, protocolConfig, artifactsLoader, stateManagerWorkerUrl, relayerConfig, paymasterConfig, relayerClientFactory, }: RequireOnly<TCProtocolParams, 'protocolConfig'>);
|
|
484
499
|
instanceId: () => Promise<"0x1">;
|
|
485
500
|
/**
|
|
486
501
|
* Only process supported assets or error out?
|
|
@@ -488,6 +503,12 @@ declare class TornadoCashProtocol implements TCInstance {
|
|
|
488
503
|
* The assets retain the provided order. If an asset is not supported its balance will be 0
|
|
489
504
|
*/
|
|
490
505
|
balance(assets?: ERC20AssetId[]): Promise<TCAssetBalance[]>;
|
|
506
|
+
/**
|
|
507
|
+
* Returns all notes for the account.
|
|
508
|
+
* @param assets - Filter by specific assets (optional, if empty returns all)
|
|
509
|
+
* @param includeSpent - Include notes with zero balance (default: false)
|
|
510
|
+
*/
|
|
511
|
+
notes(assets?: ERC20AssetId[], includeSpent?: boolean): Promise<TCNote[]>;
|
|
491
512
|
prepareShield(assets: TCAssetAmount, options?: TCPrepareShieldOptions | `0x${string}`): Promise<TCPublicOperation>;
|
|
492
513
|
prepareUnshield(assets: AssetAmount, to: AccountId, options?: TCRelayerUnshieldOptions): Promise<TCPrivateOperation<'relayer'>>;
|
|
493
514
|
prepareUnshield(assets: AssetAmount, to: AccountId, options?: TCPaymasterUnshieldOptions): Promise<TCPrivateOperation<'paymaster'>>;
|
|
@@ -557,4 +578,4 @@ declare const TornadoCashConfigs: {
|
|
|
557
578
|
};
|
|
558
579
|
};
|
|
559
580
|
|
|
560
|
-
export { type Commitment, DepositStrategy, E_ADDRESS, type ISecretManager, type Nullifier, SecretManager, type SecretManagerParams, type TCAddress, type TCAssetAmount, type TCAssetBalance, type TCBroadcaster, type TCBroadcasterParameters, type TCInstance, type TCPaymasterUnshieldOptions, type TCPluginParameters, type TCPrepareShieldOptions, type TCPrepareUnshieldOptions, type TCRelayerUnshieldOptions, TornadoCashConfigs, TornadoCashProtocol, TornadoPaymasterConfigs, createTCBroadcaster, createTCPlugin };
|
|
581
|
+
export { type Commitment, DepositStrategy, E_ADDRESS, type ISecretManager, type Nullifier, SecretManager, type SecretManagerParams, type TCAddress, type TCAssetAmount, type TCAssetBalance, type TCBroadcaster, type TCBroadcasterParameters, type TCInstance, type TCNote, type TCPaymasterUnshieldOptions, type TCPluginParameters, type TCPrepareShieldOptions, type TCPrepareUnshieldOptions, type TCRelayerUnshieldOptions, TornadoCashConfigs, TornadoCashProtocol, TornadoPaymasterConfigs, createTCBroadcaster, createTCPlugin };
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,6 @@ import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
|
8
8
|
import { numberToBytesLE, bytesToNumberLE, concatBytes } from '@noble/curves/utils.js';
|
|
9
9
|
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
10
10
|
import { pedersenHash as pedersenHash$1, Point } from 'micro-zk-proofs/pedersen.js';
|
|
11
|
-
import 'micro-zk-proofs/mimcsponge.js';
|
|
12
|
-
import 'fixed-merkle-tree';
|
|
13
11
|
|
|
14
12
|
// src/state/thunks/getDepositPayloadThunk.ts
|
|
15
13
|
|
|
@@ -422,8 +420,7 @@ var TornadoCashProtocol = class {
|
|
|
422
420
|
stateManagerWorkerUrl,
|
|
423
421
|
relayerConfig,
|
|
424
422
|
paymasterConfig = TornadoPaymasterConfigs,
|
|
425
|
-
relayerClientFactory = () => new RelayerClient(host)
|
|
426
|
-
proverVersion
|
|
423
|
+
relayerClientFactory = () => new RelayerClient(host)
|
|
427
424
|
}) {
|
|
428
425
|
this.host = host;
|
|
429
426
|
this.stateManager = (async () => {
|
|
@@ -442,13 +439,14 @@ var TornadoCashProtocol = class {
|
|
|
442
439
|
proxy(host.storage),
|
|
443
440
|
proxy(initialState),
|
|
444
441
|
proxy(artifactsLoader),
|
|
445
|
-
{ protocolConfig, accountIndex, relayerConfig, paymasterConfig
|
|
442
|
+
{ protocolConfig, accountIndex, relayerConfig, paymasterConfig }
|
|
446
443
|
),
|
|
447
444
|
workerReady
|
|
448
445
|
]);
|
|
449
446
|
return {
|
|
450
447
|
sync: () => remote.sync(),
|
|
451
448
|
getBalances: ((assets) => remote.getBalances(assets)),
|
|
449
|
+
getNotes: (params) => remote.getNotes(params),
|
|
452
450
|
getDepositPayload: (params) => remote.getDepositPayload(params),
|
|
453
451
|
getWithdrawalPayloads: (params) => remote.getWithdrawalPayloads(params),
|
|
454
452
|
dumpState: (() => remote.dumpState())
|
|
@@ -487,6 +485,23 @@ var TornadoCashProtocol = class {
|
|
|
487
485
|
};
|
|
488
486
|
});
|
|
489
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* Returns all notes for the account.
|
|
490
|
+
* @param assets - Filter by specific assets (optional, if empty returns all)
|
|
491
|
+
* @param includeSpent - Include notes with zero balance (default: false)
|
|
492
|
+
*/
|
|
493
|
+
async notes(assets = [], includeSpent = false) {
|
|
494
|
+
const stateManager = await this.stateManager;
|
|
495
|
+
await stateManager.sync();
|
|
496
|
+
const assetAddresses = assets.map(({ contract }) => {
|
|
497
|
+
const parsedAddress = BigInt(contract);
|
|
498
|
+
return parsedAddress === E_ADDRESS_BIGINT ? 0n : parsedAddress;
|
|
499
|
+
});
|
|
500
|
+
return stateManager.getNotes({
|
|
501
|
+
includeSpent,
|
|
502
|
+
assets: assetAddresses.length > 0 ? assetAddresses : void 0
|
|
503
|
+
});
|
|
504
|
+
}
|
|
490
505
|
async prepareShield(assets, options) {
|
|
491
506
|
const { asset, amount } = assets;
|
|
492
507
|
const strategy = typeof options === "string" ? 1 /* MinFee */ : options?.strategy || 1 /* MinFee */;
|