@kohaku-eth/tornado-cash 0.0.2-alpha.10 → 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 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";
@@ -305,6 +314,17 @@ interface IPaymasterWithdrawalPayload {
305
314
  isERC20: boolean;
306
315
  delegation?: SignedDelegation;
307
316
  }
317
+ interface IGenericPaymasterWithdrawalPayload {
318
+ mode: 'paymaster';
319
+ proof: TornadoProveOutput;
320
+ poolAddress: Address;
321
+ isERC20: boolean;
322
+ paymasterAddress: `0x${string}`;
323
+ entryPointAddress: `0x${string}`;
324
+ bundlerUrl: string;
325
+ accountAddress: `0x${string}`;
326
+ delegation?: SignedDelegation;
327
+ }
308
328
  interface PaymasterBroadcastResult {
309
329
  userOpHash: Hash;
310
330
  }
@@ -332,7 +352,7 @@ interface IRelayerWithdrawalPayload {
332
352
  poolAddress: Address;
333
353
  relayerUrl: string;
334
354
  }
335
- type IWithdrawalPayload = IRelayerWithdrawalPayload | IPaymasterWithdrawalPayload;
355
+ type IWithdrawalPayload = IRelayerWithdrawalPayload | IGenericPaymasterWithdrawalPayload;
336
356
  interface TCPrivateOperation<Mode extends IWithdrawalPayload['mode'] = 'relayer' | 'paymaster'> extends PrivateOperation {
337
357
  withdrawals: (IWithdrawalPayload & {
338
358
  mode: Mode;
@@ -346,7 +366,7 @@ interface ITornadoArtifacts {
346
366
  provingKey: ArrayBuffer;
347
367
  }
348
368
  type TCProtocolConfig = Omit<ProtocolConfigState, 'chainId'>;
349
- interface PrivacyPoolsV1ProtocolParams {
369
+ interface TCProtocolParams {
350
370
  accountIndex?: number;
351
371
  paymasterConfig: IChainsPaymastersConfig;
352
372
  secretManagerFactory: (params: SecretManagerParams) => Promise<ISecretManager>;
@@ -355,7 +375,6 @@ interface PrivacyPoolsV1ProtocolParams {
355
375
  protocolConfig: TCProtocolConfig;
356
376
  relayerConfig?: IRelayerFeeConfig;
357
377
  artifactsLoader?: () => Promise<ITornadoArtifacts>;
358
- proverFactory?: () => Promise<ITornadoProver>;
359
378
  initialState?: () => Promise<Record<string, PublicRootState>>;
360
379
  stateManagerWorkerUrl?: string;
361
380
  }
@@ -379,6 +398,15 @@ interface IPaymasterWithdrawParams extends IWithdrawBaseParams {
379
398
  delegation?: DelegationConfig;
380
399
  }
381
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
+ };
382
410
  type StoreKey = `${string}-${string}`;
383
411
  type StoreStorageKey = `tornado-cash-state-${StoreKey}`;
384
412
  interface IStateManager {
@@ -399,6 +427,12 @@ interface IStateManager {
399
427
  * All assets if not specified.
400
428
  */
401
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[]>;
402
436
  dumpState: () => Record<StoreStorageKey, PublicRootState>;
403
437
  }
404
438
 
@@ -411,12 +445,11 @@ type TCBroadcaster = Broadcaster<TCPrivateOperation, ITornadoWithdrawResponse[]>
411
445
  interface TCBaseCredential {
412
446
  accountIndex: number;
413
447
  }
414
- interface TCPluginParameters extends TCBroadcasterParameters, TCBaseCredential {
448
+ interface TCPluginParameters extends TCBroadcasterParameters, TCBaseCredential, Pick<TCProtocolParams, 'initialState'> {
415
449
  protocolConfig: TCProtocolConfig;
416
450
  relayerConfig?: IRelayerFeeConfig;
417
- initialState?: PrivacyPoolsV1ProtocolParams['initialState'];
418
- artifacts: ITornadoArtifacts;
419
451
  stateManagerWorkerUrl?: string;
452
+ artifactsLoader?: () => Promise<ITornadoArtifacts>;
420
453
  }
421
454
  type TCAddress = Address$1;
422
455
  type TCAssetAmount<Tag extends string | undefined = undefined> = AssetAmount<ERC20AssetId, bigint, Tag>;
@@ -444,6 +477,7 @@ type TCInstance = PluginInstance<TCAddress, {
444
477
  output: TCAssetAmount;
445
478
  read: TCAssetBalance;
446
479
  };
480
+ note: TCNote;
447
481
  extras: {
448
482
  sync(): Promise<void>;
449
483
  prepareShield(asset: TCAssetAmount, options: TCPrepareShieldOptions): Promise<TCPublicOperation>;
@@ -461,7 +495,7 @@ type RequireOnly<T, Keys extends keyof T> = Partial<T> & Pick<T, Keys>;
461
495
  declare class TornadoCashProtocol implements TCInstance {
462
496
  readonly host: Host;
463
497
  private stateManager;
464
- constructor(host: Host, { accountIndex, initialState, protocolConfig, artifactsLoader, stateManagerWorkerUrl, relayerConfig, paymasterConfig, relayerClientFactory }: RequireOnly<PrivacyPoolsV1ProtocolParams, 'protocolConfig'>);
498
+ constructor(host: Host, { accountIndex, initialState, protocolConfig, artifactsLoader, stateManagerWorkerUrl, relayerConfig, paymasterConfig, relayerClientFactory, }: RequireOnly<TCProtocolParams, 'protocolConfig'>);
465
499
  instanceId: () => Promise<"0x1">;
466
500
  /**
467
501
  * Only process supported assets or error out?
@@ -469,6 +503,12 @@ declare class TornadoCashProtocol implements TCInstance {
469
503
  * The assets retain the provided order. If an asset is not supported its balance will be 0
470
504
  */
471
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[]>;
472
512
  prepareShield(assets: TCAssetAmount, options?: TCPrepareShieldOptions | `0x${string}`): Promise<TCPublicOperation>;
473
513
  prepareUnshield(assets: AssetAmount, to: AccountId, options?: TCRelayerUnshieldOptions): Promise<TCPrivateOperation<'relayer'>>;
474
514
  prepareUnshield(assets: AssetAmount, to: AccountId, options?: TCPaymasterUnshieldOptions): Promise<TCPrivateOperation<'paymaster'>>;
@@ -490,6 +530,19 @@ interface Nullifier {
490
530
  }
491
531
 
492
532
  declare const E_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
533
+ declare const TornadoPaymasterConfigs: {
534
+ readonly 11155111: {
535
+ readonly bundlerUrl: "https://public.pimlico.io/v2/11155111/rpc";
536
+ readonly entryPointAddress: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108";
537
+ readonly paymasterAddress: "0xA0e2667AcdECb9bCDa6Fcf87638a962e2E9dB20D";
538
+ readonly poolsAccountsMap: {
539
+ readonly '0x8c4a04d872a6c1be37964a21ba3a138525dff50b': "0x8A70E3dE493B8599447013f08d8b35719C8ED0ec";
540
+ readonly '0x8cc930096b4df705a007c4a039bdfa1320ed2508': "0x191e3De3cF7f61de7EbEf4Bf45cfBA4f652d1C6e";
541
+ readonly '0x6921fd1a97441dd603a997ed6ddf388658daf754': "0x060d053A6595630851ab873d6C95401b0C964d26";
542
+ };
543
+ };
544
+ readonly 1: never;
545
+ };
493
546
  declare const TornadoCashConfigs: {
494
547
  readonly 1: {
495
548
  readonly ensSubdomainKey: "mainnet-tornado";
@@ -525,4 +578,4 @@ declare const TornadoCashConfigs: {
525
578
  };
526
579
  };
527
580
 
528
- 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, 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
 
@@ -409,7 +407,7 @@ async function loadCircuitFiles(circuitUrl, provingKeyUrl) {
409
407
 
410
408
  // src/utils/default-artifacts-loader.ts
411
409
  var TC_CIRCUIT_URL = "https://raw.githubusercontent.com/tornadocash/tornado-cli/refs/heads/master/build/circuits/tornado.json";
412
- var TC_PROVING_KEY_URL = "https://github.com/tornadocash/tornado-cli/raw/refs/heads/master/build/circuits/tornadoProvingKey.bin";
410
+ var TC_PROVING_KEY_URL = "https://raw.githubusercontent.com/tornadocash/tornado-cli/refs/heads/master/build/circuits/tornadoProvingKey.bin";
413
411
  var defaultArtifactsLoader = () => loadCircuitFiles(TC_CIRCUIT_URL, TC_PROVING_KEY_URL);
414
412
 
415
413
  // src/plugin/base.ts
@@ -448,6 +446,7 @@ var TornadoCashProtocol = class {
448
446
  return {
449
447
  sync: () => remote.sync(),
450
448
  getBalances: ((assets) => remote.getBalances(assets)),
449
+ getNotes: (params) => remote.getNotes(params),
451
450
  getDepositPayload: (params) => remote.getDepositPayload(params),
452
451
  getWithdrawalPayloads: (params) => remote.getWithdrawalPayloads(params),
453
452
  dumpState: (() => remote.dumpState())
@@ -486,6 +485,23 @@ var TornadoCashProtocol = class {
486
485
  };
487
486
  });
488
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
+ }
489
505
  async prepareShield(assets, options) {
490
506
  const { asset, amount } = assets;
491
507
  const strategy = typeof options === "string" ? 1 /* MinFee */ : options?.strategy || 1 /* MinFee */;
@@ -580,10 +596,7 @@ var PaymasterBroadcaster = class _PaymasterBroadcaster {
580
596
  async broadcast(withdrawals) {
581
597
  const chainId = Number(await this.provider.getChainId());
582
598
  const {
583
- poolsAccountsMap: rawPoolsAccountsMap,
584
- bundlerUrl,
585
- paymasterAddress,
586
- entryPointAddress
599
+ poolsAccountsMap: rawPoolsAccountsMap
587
600
  } = this.options[chainId];
588
601
  const poolAcountsMap = new Map(
589
602
  Object.entries(rawPoolsAccountsMap).map(([poolAccount, tornadoAccount]) => [
@@ -594,9 +607,6 @@ var PaymasterBroadcaster = class _PaymasterBroadcaster {
594
607
  const results = await Promise.allSettled(
595
608
  withdrawals.map((w) => _PaymasterBroadcaster.broadcastOne({
596
609
  ...w,
597
- bundlerUrl,
598
- paymasterAddress,
599
- entryPointAddress,
600
610
  accountAddress: poolAcountsMap.get(w.poolAddress)
601
611
  }, this.provider))
602
612
  );
@@ -775,4 +785,4 @@ function tcPath({ accountIndex, secretType, depositIndex }) {
775
785
  return `${TORNADO_CASH_PATH}/${accountIndex}'/${_secretType}'/${depositIndex}'`;
776
786
  }
777
787
 
778
- export { DepositStrategy, E_ADDRESS, SecretManager, TornadoCashConfigs, TornadoCashProtocol, createTCBroadcaster, createTCPlugin };
788
+ export { DepositStrategy, E_ADDRESS, SecretManager, TornadoCashConfigs, TornadoCashProtocol, TornadoPaymasterConfigs, createTCBroadcaster, createTCPlugin };