@kohaku-eth/tornado-cash 0.0.2-alpha.8 → 0.1.0-alpha.26
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/README.md +12 -0
- package/dist/index.d.ts +343 -63
- package/dist/index.js +276 -136
- 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 +2838 -0
- package/dist/msm-worker.js +2853 -0
- package/dist/state-manager.worker.js +21484 -24825
- package/dist/{state-manager.worker.node.cjs → state-manager.worker.node.js} +21165 -23096
- package/dist/worker-loader.browser.d.ts +171 -18
- package/dist/worker-loader.node.d.ts +171 -18
- package/dist/worker-loader.node.js +1 -6
- package/package.json +17 -16
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @kohaku-eth/tornado-cash
|
|
2
|
+
|
|
3
|
+
> [!IMPORTANT]
|
|
4
|
+
> THIS PACKAGE IS NOT READY FOR PRODUCTION USE AND CONTAINS UNAUDITED CODE. USE WITH CAUTION AND ENTIRELY AT YOUR OWN RISK. POSSIBILITY OF BREAKING CHANGES IN SUBSEQUENT VERSIONS.
|
|
5
|
+
|
|
6
|
+
Cross-platform Tornado Cash Typescript SDK with support for kohaku's standard interfaces.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pnpm add @kohaku-eth/tornado-cash
|
|
12
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Broadcaster } from '@kohaku-eth/plugins/broadcaster';
|
|
2
|
-
import { Host, ChainId, Storage, PrivateOperation, PublicOperation, AssetAmount, ERC20AssetId, PluginInstance,
|
|
3
|
-
import { combineReducers } from '@reduxjs/toolkit';
|
|
4
|
-
import { ParseAbiItem, SignedAuthorization, Hash, Address as Address$2 } from 'viem';
|
|
2
|
+
import { Host, ExternalRawEvent, ChainId, Storage, PrivateOperation, PublicOperation, AccountId, AssetAmount, ERC20AssetId, PluginInstance, UnshieldOptions, Keystore } from '@kohaku-eth/plugins';
|
|
5
3
|
import { TxData } from '@kohaku-eth/provider';
|
|
4
|
+
import { combineReducers } from '@reduxjs/toolkit';
|
|
5
|
+
import { ParseAbiItem, SignedAuthorization, Hash, TypedDataDomain, Hex as Hex$1, Address as Address$2 } from 'viem';
|
|
6
6
|
import { Address as Address$1 } from 'ox/Address';
|
|
7
|
+
import { Hex } from 'ox/Hex';
|
|
7
8
|
|
|
8
9
|
type Nullifier$1 = bigint & {};
|
|
9
10
|
type NullifierHash = bigint & {};
|
|
@@ -29,50 +30,47 @@ type BaseDeriveSecretParams = {
|
|
|
29
30
|
type DeriveDepositSecretParams = BaseDeriveSecretParams & {
|
|
30
31
|
depositIndex: number;
|
|
31
32
|
};
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
/** Global nonce plus the pool mixed in after the signature. */
|
|
34
|
+
type SignatureDeriveParams = BaseDeriveSecretParams & {
|
|
35
|
+
nonce: number;
|
|
36
|
+
};
|
|
37
|
+
/** BIP-32 HD derivation. Still scanned so notes created before signature
|
|
38
|
+
* secrets remain spendable. New deposits use {@link SignatureDeriveParams}. */
|
|
39
|
+
interface LegacySecretManager {
|
|
40
|
+
getLegacyDepositSecrets: (params: DeriveDepositSecretParams) => Promise<Secret>;
|
|
34
41
|
deriveEphemeralSigner: (params: DeriveDepositSecretParams) => Promise<`0x${string}`>;
|
|
42
|
+
/**
|
|
43
|
+
* Derives a delegator key from a classical wallet BIP-32 `path`, WITHOUT the
|
|
44
|
+
* `coalesceSecret` privacy transform, so it resolves to a recoverable,
|
|
45
|
+
* classical Ethereum address. Used for the tail-call batch delegator when the
|
|
46
|
+
* integrator supplies a wallet path (see `paymasterWithdrawThunk`).
|
|
47
|
+
*/
|
|
48
|
+
deriveDelegatorSigner: (params: {
|
|
49
|
+
path: string;
|
|
50
|
+
}) => Promise<`0x${string}`>;
|
|
51
|
+
/**
|
|
52
|
+
* Derives the ephemeral signer for an imported legacy note. Legacy secrets
|
|
53
|
+
* have no keystore-derived `depositIndex`, so this is a pure function of
|
|
54
|
+
* the note's own nullifier instead of a BIP-32 derivation.
|
|
55
|
+
*/
|
|
56
|
+
deriveLegacyEphemeralSigner: (params: {
|
|
57
|
+
nullifier: Nullifier$1;
|
|
58
|
+
}) => Promise<`0x${string}`>;
|
|
59
|
+
}
|
|
60
|
+
interface ISecretManager extends LegacySecretManager {
|
|
61
|
+
getSignatureSecrets: (params: SignatureDeriveParams) => Promise<Secret>;
|
|
62
|
+
deriveSignatureEphemeralSigner: (params: SignatureDeriveParams) => Promise<`0x${string}`>;
|
|
35
63
|
}
|
|
36
64
|
interface SecretManagerParams {
|
|
37
65
|
host: Pick<Host, 'keystore'>;
|
|
38
66
|
accountIndex?: number;
|
|
39
67
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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'>;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Legacy BIP-32 HD secret derivation. New deposits use
|
|
70
|
+
* {@link SignatureSecretManager}. Kept so notes created under this scheme are
|
|
71
|
+
* still discovered; the protocol default composes both.
|
|
72
|
+
*/
|
|
73
|
+
declare function SecretManager({ host: { keystore }, accountIndex }: SecretManagerParams): Promise<LegacySecretManager>;
|
|
76
74
|
|
|
77
75
|
interface IBaseEvent {
|
|
78
76
|
blockNumber: bigint;
|
|
@@ -86,6 +84,17 @@ interface IDepositEvent extends IPoolEvent {
|
|
|
86
84
|
leafIndex: number;
|
|
87
85
|
timestamp: bigint;
|
|
88
86
|
}
|
|
87
|
+
interface IIndexedDepositEvent extends IDepositEvent {
|
|
88
|
+
index: number;
|
|
89
|
+
/** Signature-scheme nonce. Set only for signature-derived notes. */
|
|
90
|
+
nonce?: number;
|
|
91
|
+
}
|
|
92
|
+
interface IDepositWithAsset extends IIndexedDepositEvent {
|
|
93
|
+
assetAddress: Address;
|
|
94
|
+
}
|
|
95
|
+
interface IDepositWithBalance extends IDepositWithAsset {
|
|
96
|
+
balance: bigint;
|
|
97
|
+
}
|
|
89
98
|
interface IWithdrawalEvent extends IPoolEvent {
|
|
90
99
|
to: Address;
|
|
91
100
|
nullifierHash: NullifierHash;
|
|
@@ -111,6 +120,42 @@ interface IAsset {
|
|
|
111
120
|
symbol: string;
|
|
112
121
|
}
|
|
113
122
|
|
|
123
|
+
interface IRelayerStatusResponse {
|
|
124
|
+
currentQueue: number;
|
|
125
|
+
netId: number;
|
|
126
|
+
rewardAccount: string;
|
|
127
|
+
version: string;
|
|
128
|
+
tornadoServiceFee: number;
|
|
129
|
+
ethPrices: Record<string, string>;
|
|
130
|
+
}
|
|
131
|
+
interface ITornadoWithdrawRequest {
|
|
132
|
+
proof: `0x${string}`;
|
|
133
|
+
args: [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`];
|
|
134
|
+
contract: `0x${string}`;
|
|
135
|
+
}
|
|
136
|
+
interface ITornadoWithdrawResponse {
|
|
137
|
+
id: string;
|
|
138
|
+
}
|
|
139
|
+
interface IRelayerClient {
|
|
140
|
+
getStatus(hostname: string): Promise<IRelayerStatusResponse>;
|
|
141
|
+
withdraw(relayerUrl: string, body: ITornadoWithdrawRequest): Promise<ITornadoWithdrawResponse>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface InstanceRegistryConfig extends IScrapeableContract {
|
|
145
|
+
lastDeployedOnBlock?: bigint;
|
|
146
|
+
}
|
|
147
|
+
interface ProtocolConfigState {
|
|
148
|
+
chainId: bigint;
|
|
149
|
+
ensSubdomainKey: string;
|
|
150
|
+
instanceRegistry: InstanceRegistryConfig;
|
|
151
|
+
relayerRegistry: IScrapeableContract;
|
|
152
|
+
aggregator: IContract;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type RootState = ReturnType<ReturnType<typeof combineReducers<typeof reducers>>>;
|
|
156
|
+
/** HD and signature secrets are re-derived on sync, so they stay out of snapshots. */
|
|
157
|
+
type PublicRootState = Omit<RootState, 'userSecrets' | 'signatureSecrets'>;
|
|
158
|
+
|
|
114
159
|
declare const POOL_EVENTS_SIGNATURES: {
|
|
115
160
|
readonly Deposited: {
|
|
116
161
|
readonly name: "Deposit";
|
|
@@ -181,7 +226,7 @@ declare const INSTANCE_REGISTRY_EVENT_SIGNATURES: {
|
|
|
181
226
|
};
|
|
182
227
|
|
|
183
228
|
type IEventsMap = Record<string, ParseAbiItem<string>>;
|
|
184
|
-
interface IGetEventsParams<T> {
|
|
229
|
+
interface IGetEventsParams$1<T> {
|
|
185
230
|
events: T | T[];
|
|
186
231
|
fromBlock: bigint;
|
|
187
232
|
toBlock?: bigint;
|
|
@@ -202,7 +247,7 @@ type IGroupedEvents<NamesTable extends Record<string, unknown>> = {
|
|
|
202
247
|
};
|
|
203
248
|
type GetEventsFn<EventsMap extends IEventsMap, ParsedEvents extends {
|
|
204
249
|
[key in keyof EventsMap]: unknown;
|
|
205
|
-
}> = <const T extends keyof ParsedEvents = never>(params: IGetEventsParams<T>) => Promise<Pick<IGroupedEvents<ParsedEvents>, T> & {
|
|
250
|
+
}> = <const T extends keyof ParsedEvents = never>(params: IGetEventsParams$1<T>) => Promise<Pick<IGroupedEvents<ParsedEvents>, T> & {
|
|
206
251
|
fromBlock: bigint;
|
|
207
252
|
toBlock: bigint;
|
|
208
253
|
}>;
|
|
@@ -211,7 +256,6 @@ interface IPoolConfig {
|
|
|
211
256
|
isERC20: boolean;
|
|
212
257
|
token: Address;
|
|
213
258
|
state: 0 | 1;
|
|
214
|
-
uniswapPoolSwappingFee: number;
|
|
215
259
|
protocolFeePercentage: number;
|
|
216
260
|
denomination: bigint;
|
|
217
261
|
rootHistorySize: number;
|
|
@@ -224,6 +268,14 @@ interface IRelayerAggregatorData {
|
|
|
224
268
|
}
|
|
225
269
|
interface IDataService {
|
|
226
270
|
getPoolEvents: GetEventsFn<typeof POOL_EVENTS_SIGNATURES, IPoolEvents>;
|
|
271
|
+
getBlockNumber(): Promise<bigint>;
|
|
272
|
+
parsePoolEvents(events: ExternalRawEvent[]): {
|
|
273
|
+
Deposited: IRawDepositEvent[];
|
|
274
|
+
Withdrawn: IRawWithdrawalEvent[];
|
|
275
|
+
};
|
|
276
|
+
parseRelayerRegistryEvents(events: ExternalRawEvent[]): {
|
|
277
|
+
RelayerRegistered: IRelayerRegisteredEvent[];
|
|
278
|
+
};
|
|
227
279
|
getRelayerRegistryEvents: GetEventsFn<typeof RELAYER_REGISTRY_EVENTS_SIGNATURES, IRelayerRegistryEvents>;
|
|
228
280
|
getInstanceRegistryEvents: GetEventsFn<typeof INSTANCE_REGISTRY_EVENT_SIGNATURES, IInstanceRegistryEvents>;
|
|
229
281
|
getAsset(assetAddress: Address): Promise<IAsset>;
|
|
@@ -240,7 +292,47 @@ interface IDataService {
|
|
|
240
292
|
getLatestBlockTimestamp(): Promise<bigint>;
|
|
241
293
|
getRelayerData(aggregatorAddress: Address, relayerNameHashes: bigint[], subdomains: string[]): Promise<IRelayerAggregatorData[]>;
|
|
242
294
|
getAccountNonce(accountAddress: Address): Promise<number>;
|
|
243
|
-
|
|
295
|
+
quoteWeiInToken(paymasterAddress: Address, feeToken: Address, weiAmount: bigint): Promise<bigint>;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Identifies one contract to sync from a given block. */
|
|
299
|
+
interface IGetEventsParams {
|
|
300
|
+
chainId: bigint;
|
|
301
|
+
address: Address;
|
|
302
|
+
fromBlock: bigint;
|
|
303
|
+
}
|
|
304
|
+
interface IGetPoolEventsResult {
|
|
305
|
+
Deposited: IRawDepositEvent[];
|
|
306
|
+
Withdrawn: IRawWithdrawalEvent[];
|
|
307
|
+
/** Highest block the returned events are synced up to. */
|
|
308
|
+
toBlock: bigint;
|
|
309
|
+
}
|
|
310
|
+
interface IGetRelayerRegistryEventsResult {
|
|
311
|
+
RelayerRegistered: IRelayerRegisteredEvent[];
|
|
312
|
+
/** Highest block the returned events are synced up to. */
|
|
313
|
+
toBlock: bigint;
|
|
314
|
+
}
|
|
315
|
+
interface ISyncService {
|
|
316
|
+
/**
|
|
317
|
+
* Fetches a single pool's `Deposited`/`Withdrawn` events from `fromBlock`.
|
|
318
|
+
* Uses the external sync provider for the bulk of a large range and the chain
|
|
319
|
+
* for the remaining tail; falls back to a chain-only fetch otherwise.
|
|
320
|
+
*/
|
|
321
|
+
getPoolEvents(params: IGetEventsParams): Promise<IGetPoolEventsResult>;
|
|
322
|
+
/**
|
|
323
|
+
* Fetches the relayer registry's `RelayerRegistered` events from `fromBlock`,
|
|
324
|
+
* with the same external-then-chain strategy as {@link getPoolEvents}.
|
|
325
|
+
*/
|
|
326
|
+
getRelayerRegistryEvents(params: IGetEventsParams): Promise<IGetRelayerRegistryEventsResult>;
|
|
327
|
+
/**
|
|
328
|
+
* Resolves a pool's scan-start block. Uses the external provider's first
|
|
329
|
+
* covered block when available (an O(1) lookup), else falls back to the
|
|
330
|
+
* on-chain deployment-block binary search.
|
|
331
|
+
*/
|
|
332
|
+
getPoolDeploymentBlock(params: {
|
|
333
|
+
chainId: bigint;
|
|
334
|
+
address: Address;
|
|
335
|
+
}): Promise<bigint>;
|
|
244
336
|
}
|
|
245
337
|
|
|
246
338
|
type SpecificAssetBalanceFn<isAsync extends boolean = false> = <const Adresses extends Address | Address[] = Address[], ReturnType = Adresses extends unknown[] ? Map<Address, bigint> : bigint>(assetAddress?: Adresses) => isAsync extends true ? Promise<ReturnType> : ReturnType;
|
|
@@ -280,6 +372,7 @@ interface IRelayerFeeConfig {
|
|
|
280
372
|
interface StoreFactoryParams {
|
|
281
373
|
secretManagerFactory: () => Promise<ISecretManager>;
|
|
282
374
|
dataService: IDataService;
|
|
375
|
+
syncService: ISyncService;
|
|
283
376
|
relayerClient: IRelayerClient;
|
|
284
377
|
paymasterConfig: IChainsPaymastersConfig;
|
|
285
378
|
storageToSyncTo?: Storage;
|
|
@@ -294,6 +387,66 @@ declare enum DepositStrategy {
|
|
|
294
387
|
MinFee = 1
|
|
295
388
|
}
|
|
296
389
|
|
|
390
|
+
type ImportNoteResult = {
|
|
391
|
+
note: string;
|
|
392
|
+
status: 'imported';
|
|
393
|
+
poolAddress: Address;
|
|
394
|
+
} | {
|
|
395
|
+
note: string;
|
|
396
|
+
status: 'wrong-chain';
|
|
397
|
+
} | {
|
|
398
|
+
note: string;
|
|
399
|
+
status: 'not-found';
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* How the batch delegator for a tail-call paymaster withdrawal is produced.
|
|
404
|
+
* Only honored when `tailCalls` are present (see `paymasterWithdrawThunk`).
|
|
405
|
+
*
|
|
406
|
+
* - `deterministic` (default): recoverable. With `path`, the delegator is a
|
|
407
|
+
* classical wallet-path address; without `path`, an ephemeral address keyed by
|
|
408
|
+
* the batch's first deposit.
|
|
409
|
+
* - `random`: a throwaway, unrecoverable EOA — an explicit opt-out of
|
|
410
|
+
* recoverability. Never the default, because in the tail-call path the
|
|
411
|
+
* delegator holds the withdrawn funds.
|
|
412
|
+
*/
|
|
413
|
+
type DelegationConfig = {
|
|
414
|
+
mode: 'deterministic';
|
|
415
|
+
path?: string;
|
|
416
|
+
} | {
|
|
417
|
+
mode: 'random';
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
interface SerializedAuth {
|
|
421
|
+
address: Address$1;
|
|
422
|
+
chainId: Hex;
|
|
423
|
+
nonce: Hex;
|
|
424
|
+
r: Hex;
|
|
425
|
+
s: Hex;
|
|
426
|
+
yParity: Hex;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* A userOp serialized to the hex shape expected by `eth_sendUserOperation`, so
|
|
430
|
+
* it can be carried as plain (JSON-serializable) data from the prepare phase
|
|
431
|
+
* (thunk) to the broadcast phase.
|
|
432
|
+
*/
|
|
433
|
+
interface SerializedUserOperation {
|
|
434
|
+
sender: `0x${string}`;
|
|
435
|
+
nonce: `0x${string}`;
|
|
436
|
+
callData: `0x${string}`;
|
|
437
|
+
callGasLimit: `0x${string}`;
|
|
438
|
+
verificationGasLimit: `0x${string}`;
|
|
439
|
+
preVerificationGas: `0x${string}`;
|
|
440
|
+
maxFeePerGas: `0x${string}`;
|
|
441
|
+
maxPriorityFeePerGas: `0x${string}`;
|
|
442
|
+
paymaster?: `0x${string}`;
|
|
443
|
+
paymasterVerificationGasLimit?: `0x${string}`;
|
|
444
|
+
paymasterPostOpGasLimit?: `0x${string}`;
|
|
445
|
+
paymasterData?: `0x${string}`;
|
|
446
|
+
signature: `0x${string}`;
|
|
447
|
+
eip7702Auth?: SerializedAuth;
|
|
448
|
+
}
|
|
449
|
+
|
|
297
450
|
interface SignedDelegation {
|
|
298
451
|
senderAddress: `0x${string}`;
|
|
299
452
|
authorization: SignedAuthorization;
|
|
@@ -305,6 +458,16 @@ interface IPaymasterWithdrawalPayload {
|
|
|
305
458
|
isERC20: boolean;
|
|
306
459
|
delegation?: SignedDelegation;
|
|
307
460
|
}
|
|
461
|
+
interface IGenericPaymasterWithdrawalPayload {
|
|
462
|
+
mode: 'paymaster';
|
|
463
|
+
proof: TornadoProveOutput;
|
|
464
|
+
poolAddress: Address;
|
|
465
|
+
isERC20: boolean;
|
|
466
|
+
paymasterAddress: `0x${string}`;
|
|
467
|
+
entryPointAddress: `0x${string}`;
|
|
468
|
+
bundlerUrl: string;
|
|
469
|
+
userOperation: SerializedUserOperation;
|
|
470
|
+
}
|
|
308
471
|
interface PaymasterBroadcastResult {
|
|
309
472
|
userOpHash: Hash;
|
|
310
473
|
}
|
|
@@ -312,12 +475,6 @@ interface IPaymasterBroadcasterClient {
|
|
|
312
475
|
broadcast(withdrawals: IPaymasterWithdrawalPayload[]): Promise<PaymasterBroadcastResult[]>;
|
|
313
476
|
}
|
|
314
477
|
|
|
315
|
-
type DelegationConfig = {
|
|
316
|
-
mode: 'deterministic';
|
|
317
|
-
path?: string;
|
|
318
|
-
} | {
|
|
319
|
-
mode: 'random';
|
|
320
|
-
};
|
|
321
478
|
type StringAddress = `0x${string}`;
|
|
322
479
|
interface IPaymasterConfig {
|
|
323
480
|
paymasterAddress: StringAddress;
|
|
@@ -332,7 +489,7 @@ interface IRelayerWithdrawalPayload {
|
|
|
332
489
|
poolAddress: Address;
|
|
333
490
|
relayerUrl: string;
|
|
334
491
|
}
|
|
335
|
-
type IWithdrawalPayload = IRelayerWithdrawalPayload |
|
|
492
|
+
type IWithdrawalPayload = IRelayerWithdrawalPayload | IGenericPaymasterWithdrawalPayload;
|
|
336
493
|
interface TCPrivateOperation<Mode extends IWithdrawalPayload['mode'] = 'relayer' | 'paymaster'> extends PrivateOperation {
|
|
337
494
|
withdrawals: (IWithdrawalPayload & {
|
|
338
495
|
mode: Mode;
|
|
@@ -346,7 +503,7 @@ interface ITornadoArtifacts {
|
|
|
346
503
|
provingKey: ArrayBuffer;
|
|
347
504
|
}
|
|
348
505
|
type TCProtocolConfig = Omit<ProtocolConfigState, 'chainId'>;
|
|
349
|
-
interface
|
|
506
|
+
interface TCProtocolParams {
|
|
350
507
|
accountIndex?: number;
|
|
351
508
|
paymasterConfig: IChainsPaymastersConfig;
|
|
352
509
|
secretManagerFactory: (params: SecretManagerParams) => Promise<ISecretManager>;
|
|
@@ -355,9 +512,14 @@ interface PrivacyPoolsV1ProtocolParams {
|
|
|
355
512
|
protocolConfig: TCProtocolConfig;
|
|
356
513
|
relayerConfig?: IRelayerFeeConfig;
|
|
357
514
|
artifactsLoader?: () => Promise<ITornadoArtifacts>;
|
|
358
|
-
proverFactory?: () => Promise<ITornadoProver>;
|
|
359
515
|
initialState?: () => Promise<Record<string, PublicRootState>>;
|
|
360
516
|
stateManagerWorkerUrl?: string;
|
|
517
|
+
/**
|
|
518
|
+
* When a pool is at least this many blocks behind, use the host's
|
|
519
|
+
* `externalSyncProvider` (if any) for the bulk of the sync instead of the
|
|
520
|
+
* chain. Omit to always sync from the chain.
|
|
521
|
+
*/
|
|
522
|
+
minExternalSyncBlocksAmount?: number;
|
|
361
523
|
}
|
|
362
524
|
interface IBaseOperationParams {
|
|
363
525
|
}
|
|
@@ -377,8 +539,27 @@ interface IRelayerWithdrawParams extends IWithdrawBaseParams {
|
|
|
377
539
|
interface IPaymasterWithdrawParams extends IWithdrawBaseParams {
|
|
378
540
|
mode: 'paymaster';
|
|
379
541
|
delegation?: DelegationConfig;
|
|
542
|
+
tailCalls?: (address: AccountId) => Promise<TxData[]>;
|
|
543
|
+
/**
|
|
544
|
+
* Optional baseline for the execution-phase gas of user `tailCalls` (not
|
|
545
|
+
* including per-note direct withdraws). Used when bundler estimation fails;
|
|
546
|
+
* when estimation succeeds the bundler estimate still wins.
|
|
547
|
+
*/
|
|
548
|
+
tailCallsGasEstimate?: bigint;
|
|
380
549
|
}
|
|
381
550
|
type IWithdrawapOperationParams = IRelayerWithdrawParams | IPaymasterWithdrawParams;
|
|
551
|
+
interface IGetNotesParams extends IBaseOperationParams {
|
|
552
|
+
includeSpent?: boolean;
|
|
553
|
+
assets?: Address[];
|
|
554
|
+
}
|
|
555
|
+
type TCNote = Pick<IDepositWithBalance, 'commitment' | 'balance' | 'assetAddress' | 'timestamp' | 'leafIndex' | 'pool'> & {
|
|
556
|
+
/** Fixed pool denomination for this note. */
|
|
557
|
+
amount: bigint;
|
|
558
|
+
/** HD deposit index, or -1 for imported and signature-derived notes. */
|
|
559
|
+
depositIndex: number;
|
|
560
|
+
/** Global signature-scheme nonce. Present only for signature-derived notes. */
|
|
561
|
+
nonce?: number;
|
|
562
|
+
};
|
|
382
563
|
type StoreKey = `${string}-${string}`;
|
|
383
564
|
type StoreStorageKey = `tornado-cash-state-${StoreKey}`;
|
|
384
565
|
interface IStateManager {
|
|
@@ -399,6 +580,20 @@ interface IStateManager {
|
|
|
399
580
|
* All assets if not specified.
|
|
400
581
|
*/
|
|
401
582
|
getBalances: SpecificAssetBalanceFn<true>;
|
|
583
|
+
/**
|
|
584
|
+
* Gets all notes for the account.
|
|
585
|
+
* @param includeSpent - If true, include notes with zero balance
|
|
586
|
+
* @param assets - Optional filter by specific assets
|
|
587
|
+
*/
|
|
588
|
+
getNotes: (params: IGetNotesParams) => Promise<TCNote[]>;
|
|
589
|
+
/**
|
|
590
|
+
* Parses legacy (pre-SDK) Tornado Cash note strings and, for any that match
|
|
591
|
+
* a synced on-chain deposit on the current chain, registers them as
|
|
592
|
+
* importable user secrets.
|
|
593
|
+
*/
|
|
594
|
+
importNotes: (params: {
|
|
595
|
+
notes: string[];
|
|
596
|
+
}) => Promise<ImportNoteResult[]>;
|
|
402
597
|
dumpState: () => Record<StoreStorageKey, PublicRootState>;
|
|
403
598
|
}
|
|
404
599
|
|
|
@@ -411,23 +606,30 @@ type TCBroadcaster = Broadcaster<TCPrivateOperation, ITornadoWithdrawResponse[]>
|
|
|
411
606
|
interface TCBaseCredential {
|
|
412
607
|
accountIndex: number;
|
|
413
608
|
}
|
|
414
|
-
interface TCPluginParameters extends TCBroadcasterParameters, TCBaseCredential {
|
|
609
|
+
interface TCPluginParameters extends TCBroadcasterParameters, TCBaseCredential, Pick<TCProtocolParams, 'initialState' | 'minExternalSyncBlocksAmount'> {
|
|
610
|
+
secretManagerFactory?: TCProtocolParams['secretManagerFactory'];
|
|
415
611
|
protocolConfig: TCProtocolConfig;
|
|
416
612
|
relayerConfig?: IRelayerFeeConfig;
|
|
417
|
-
initialState?: PrivacyPoolsV1ProtocolParams['initialState'];
|
|
418
|
-
artifacts: ITornadoArtifacts;
|
|
419
613
|
stateManagerWorkerUrl?: string;
|
|
614
|
+
artifactsLoader?: () => Promise<ITornadoArtifacts>;
|
|
420
615
|
}
|
|
421
616
|
type TCAddress = Address$1;
|
|
422
617
|
type TCAssetAmount<Tag extends string | undefined = undefined> = AssetAmount<ERC20AssetId, bigint, Tag>;
|
|
423
618
|
type TCAssetBalance = TCAssetAmount;
|
|
424
|
-
interface TCRelayerUnshieldOptions {
|
|
619
|
+
interface TCRelayerUnshieldOptions extends UnshieldOptions {
|
|
425
620
|
mode: 'relayer';
|
|
426
621
|
preferredRelayersEns?: string[];
|
|
427
622
|
}
|
|
428
|
-
interface TCPaymasterUnshieldOptions {
|
|
623
|
+
interface TCPaymasterUnshieldOptions extends UnshieldOptions {
|
|
429
624
|
mode: 'paymaster';
|
|
430
625
|
delegation?: DelegationConfig;
|
|
626
|
+
/**
|
|
627
|
+
* Optional baseline for the execution-phase gas of user `tailCalls` (not
|
|
628
|
+
* including per-note direct withdraws). Used as the batch execution-tail
|
|
629
|
+
* baseline when bundler estimation fails; when estimation succeeds the
|
|
630
|
+
* bundler estimate still wins. Defaults to the SDK's static callGasLimit.
|
|
631
|
+
*/
|
|
632
|
+
tailCallsGasEstimate?: bigint;
|
|
431
633
|
}
|
|
432
634
|
type TCPrepareUnshieldOptions = TCRelayerUnshieldOptions | TCPaymasterUnshieldOptions;
|
|
433
635
|
interface TCPrepareShieldOptions {
|
|
@@ -444,11 +646,13 @@ type TCInstance = PluginInstance<TCAddress, {
|
|
|
444
646
|
output: TCAssetAmount;
|
|
445
647
|
read: TCAssetBalance;
|
|
446
648
|
};
|
|
649
|
+
note: TCNote;
|
|
447
650
|
extras: {
|
|
448
651
|
sync(): Promise<void>;
|
|
449
652
|
prepareShield(asset: TCAssetAmount, options: TCPrepareShieldOptions): Promise<TCPublicOperation>;
|
|
450
653
|
prepareUnshield(asset: TCAssetAmount, to: Address$1, options: TCRelayerUnshieldOptions): Promise<TCPrivateOperation<'relayer'>>;
|
|
451
654
|
prepareUnshield(asset: TCAssetAmount, to: Address$1, options: TCPaymasterUnshieldOptions): Promise<TCPrivateOperation<'paymaster'>>;
|
|
655
|
+
importNotes(notes: string | string[]): Promise<ImportNoteResult[]>;
|
|
452
656
|
};
|
|
453
657
|
publicOp: TCPublicOperation;
|
|
454
658
|
privateOp: TCPrivateOperation;
|
|
@@ -461,7 +665,7 @@ type RequireOnly<T, Keys extends keyof T> = Partial<T> & Pick<T, Keys>;
|
|
|
461
665
|
declare class TornadoCashProtocol implements TCInstance {
|
|
462
666
|
readonly host: Host;
|
|
463
667
|
private stateManager;
|
|
464
|
-
constructor(host: Host, { accountIndex, initialState, protocolConfig, artifactsLoader, stateManagerWorkerUrl, relayerConfig, paymasterConfig, relayerClientFactory }: RequireOnly<
|
|
668
|
+
constructor(host: Host, { accountIndex, initialState, protocolConfig, artifactsLoader, stateManagerWorkerUrl, relayerConfig, paymasterConfig, relayerClientFactory, minExternalSyncBlocksAmount, secretManagerFactory, }: RequireOnly<TCProtocolParams, 'protocolConfig'>);
|
|
465
669
|
instanceId: () => Promise<"0x1">;
|
|
466
670
|
/**
|
|
467
671
|
* Only process supported assets or error out?
|
|
@@ -469,13 +673,57 @@ declare class TornadoCashProtocol implements TCInstance {
|
|
|
469
673
|
* The assets retain the provided order. If an asset is not supported its balance will be 0
|
|
470
674
|
*/
|
|
471
675
|
balance(assets?: ERC20AssetId[]): Promise<TCAssetBalance[]>;
|
|
676
|
+
/**
|
|
677
|
+
* Returns all notes for the account.
|
|
678
|
+
* @param assets - Filter by specific assets (optional, if empty returns all)
|
|
679
|
+
* @param includeSpent - Include notes with zero balance (default: false)
|
|
680
|
+
*/
|
|
681
|
+
notes(assets?: ERC20AssetId[], includeSpent?: boolean): Promise<TCNote[]>;
|
|
682
|
+
/**
|
|
683
|
+
* Parses legacy (pre-SDK) Tornado Cash note strings and registers any that
|
|
684
|
+
* match a synced on-chain deposit on the current chain as user secrets.
|
|
685
|
+
*/
|
|
686
|
+
importNotes(notes: string | string[]): Promise<ImportNoteResult[]>;
|
|
472
687
|
prepareShield(assets: TCAssetAmount, options?: TCPrepareShieldOptions | `0x${string}`): Promise<TCPublicOperation>;
|
|
688
|
+
prepareUnshield(assets: AssetAmount, to: AccountId): Promise<TCPrivateOperation<'relayer'>>;
|
|
473
689
|
prepareUnshield(assets: AssetAmount, to: AccountId, options?: TCRelayerUnshieldOptions): Promise<TCPrivateOperation<'relayer'>>;
|
|
474
690
|
prepareUnshield(assets: AssetAmount, to: AccountId, options?: TCPaymasterUnshieldOptions): Promise<TCPrivateOperation<'paymaster'>>;
|
|
475
691
|
sync(): Promise<void>;
|
|
476
692
|
dumpState(): Promise<Record<`tornado-cash-state-${string}-${string}`, PublicRootState>>;
|
|
477
693
|
}
|
|
478
694
|
|
|
695
|
+
declare const NOTE_TYPES: {
|
|
696
|
+
readonly TornadoCashNote: readonly [{
|
|
697
|
+
readonly name: "nonce";
|
|
698
|
+
readonly type: "uint64";
|
|
699
|
+
}];
|
|
700
|
+
};
|
|
701
|
+
interface NoteEnvelope {
|
|
702
|
+
domain: TypedDataDomain;
|
|
703
|
+
types: typeof NOTE_TYPES;
|
|
704
|
+
primaryType: 'TornadoCashNote';
|
|
705
|
+
message: {
|
|
706
|
+
nonce: bigint;
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
interface EnvelopeSigner {
|
|
710
|
+
signEnvelope(envelope: NoteEnvelope): Promise<Hex$1>;
|
|
711
|
+
}
|
|
712
|
+
declare class KeystoreEnvelopeSigner implements EnvelopeSigner {
|
|
713
|
+
private readonly keystore;
|
|
714
|
+
private readonly accountIndex;
|
|
715
|
+
constructor(keystore: Keystore, accountIndex: number);
|
|
716
|
+
signEnvelope(envelope: NoteEnvelope): Promise<Hex$1>;
|
|
717
|
+
}
|
|
718
|
+
interface SignatureSecretManagerParams extends SecretManagerParams {
|
|
719
|
+
signer?: EnvelopeSigner;
|
|
720
|
+
}
|
|
721
|
+
interface SignatureSecretSource {
|
|
722
|
+
getSignatureSecrets: (params: SignatureDeriveParams) => Promise<Secret>;
|
|
723
|
+
deriveSignatureEphemeralSigner: (params: SignatureDeriveParams) => Promise<`0x${string}`>;
|
|
724
|
+
}
|
|
725
|
+
declare function SignatureSecretManager({ host, accountIndex, signer, }: SignatureSecretManagerParams): Promise<SignatureSecretSource>;
|
|
726
|
+
|
|
479
727
|
interface Commitment {
|
|
480
728
|
hash: string;
|
|
481
729
|
token: Address$2;
|
|
@@ -490,6 +738,40 @@ interface Nullifier {
|
|
|
490
738
|
}
|
|
491
739
|
|
|
492
740
|
declare const E_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
741
|
+
declare const TornadoPaymasterConfigs: {
|
|
742
|
+
readonly 11155111: {
|
|
743
|
+
readonly bundlerUrl: "https://public.pimlico.io/v2/11155111/rpc";
|
|
744
|
+
readonly entryPointAddress: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108";
|
|
745
|
+
readonly paymasterAddress: "0x1c5aCCb9c09D72945b79EC986776136bE01d7B2F";
|
|
746
|
+
readonly poolsAccountsMap: {
|
|
747
|
+
readonly '0x8c4a04d872a6c1be37964a21ba3a138525dff50b': "0xa616aAE443FCCABfc2F1EA2Afe001E5046FFDCe0";
|
|
748
|
+
readonly '0x8cc930096b4df705a007c4a039bdfa1320ed2508': "0x67a898343F32641206d0f30CB3367944a8919A3A";
|
|
749
|
+
readonly '0x6921fd1a97441dd603a997ed6ddf388658daf754': "0xbF0a7969dacF8337716d0F283df0574dF56b0479";
|
|
750
|
+
};
|
|
751
|
+
};
|
|
752
|
+
readonly 1: {
|
|
753
|
+
readonly bundlerUrl: "https://public.pimlico.io/v2/1/rpc";
|
|
754
|
+
readonly entryPointAddress: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108";
|
|
755
|
+
readonly paymasterAddress: "0xe06CB96C57D2442f8F60F5017354BC08F7e91308";
|
|
756
|
+
readonly poolsAccountsMap: {
|
|
757
|
+
readonly '0x12d66f87a04a9e220743712ce6d9bb1b5616b8fc': "0x4a3F73a23563bB467Aa034d0fAB61e7BcDf26161";
|
|
758
|
+
readonly '0x47ce0c6ed5b0ce3d3a51fdb1c52dc66a7c3c2936': "0xC086b50Dd859Bb15D553327178DEdbC347B5b905";
|
|
759
|
+
readonly '0x910cbd523d972eb0a6f4cae4618ad62622b39dbf': "0x08d1103bff53CBdC9DB1e81B79475CEad2e35870";
|
|
760
|
+
readonly '0xa160cdab225685da1d56aa342ad8841c3b53f291': "0x3aF851f9BeEeE6E9fa06022f34Dc4C453D265aE5";
|
|
761
|
+
readonly '0xd4b88df4d29f5cedd6857912842cff3b20c8cfa3': "0xe6be288aeCa9FAB56D9792686Ec571Fb1AF37F55";
|
|
762
|
+
readonly '0xfd8610d20aa15b7b2e3be39b396a1bc3516c7144': "0xf6f35246EbDA061bB17b6C7ED7B7049065eD61f3";
|
|
763
|
+
readonly '0x07687e702b410Fa43f4cB4Af7FA097918ffD2730': "0x36A5b4bCE77700B9C52cFEE53Fc8cA3B58eb7E35";
|
|
764
|
+
readonly '0x23773e65ed146a459791799d01336db287f25334': "0x83Ff713F0939409E1c6023bc8aaB3E49eD968c8D";
|
|
765
|
+
readonly '0x4736dcf1b7a3d580672cce6e7c65cd5cc9cfba9d': "0xB1C7e712AF153073979AdC5ef8B1Cc5A7b0cf031";
|
|
766
|
+
readonly '0xd96f2b1c14db8458374d9aca76e26c3d18364307': "0x44336242f9766b4c751F6958499C5cc18325e25B";
|
|
767
|
+
readonly '0x169ad27a470d064dede56a2d3ff727986b15d52b': "0xF006862cCa4829D3f3ddD52d93fC49C03D380a5F";
|
|
768
|
+
readonly '0x0836222F2B2B24A3F36f98668Ed8F0B38D1a872f': "0x5DF524b6c9303eD94A7767c2eD787ee223c9bC54";
|
|
769
|
+
readonly '0x178169b423a011fff22b9e3f3abea13414ddd0f1': "0x0fdF2f686B600523F9752aEca0abb6AD9603A22C";
|
|
770
|
+
readonly '0x610b717796ad172b316836ac95a2ffad065ceab4': "0xec3Cca694EEe55808B3f5EFEDd0bC03E52e47834";
|
|
771
|
+
readonly '0xbb93e510bbcd0b7beb5a853875f9ec60275cf498': "0xC2C427E6ADF66F412921C17958CeDD9C7710F521";
|
|
772
|
+
};
|
|
773
|
+
};
|
|
774
|
+
};
|
|
493
775
|
declare const TornadoCashConfigs: {
|
|
494
776
|
readonly 1: {
|
|
495
777
|
readonly ensSubdomainKey: "mainnet-tornado";
|
|
@@ -505,7 +787,6 @@ declare const TornadoCashConfigs: {
|
|
|
505
787
|
readonly address: 1329937909414098670091808248270266272594403334985n;
|
|
506
788
|
};
|
|
507
789
|
readonly weth: 1097077688018008265106216665536940668749033598146n;
|
|
508
|
-
readonly uniswapQuoterV2: 559478315000592720989748010348495519536007655966n;
|
|
509
790
|
};
|
|
510
791
|
readonly 11155111: {
|
|
511
792
|
readonly ensSubdomainKey: "sepolia-tornado";
|
|
@@ -521,8 +802,7 @@ declare const TornadoCashConfigs: {
|
|
|
521
802
|
readonly address: 368418168928372787409224158240737522620871644738n;
|
|
522
803
|
};
|
|
523
804
|
readonly weth: 1461358721292675304620367034492138750323989506836n;
|
|
524
|
-
readonly uniswapQuoterV2: 1353730886217084326490181093487957540173111046067n;
|
|
525
805
|
};
|
|
526
806
|
};
|
|
527
807
|
|
|
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 };
|
|
808
|
+
export { type Commitment, DepositStrategy, E_ADDRESS, type EnvelopeSigner, type ISecretManager, type ImportNoteResult, KeystoreEnvelopeSigner, type LegacySecretManager, type NoteEnvelope, type Nullifier, SecretManager, type SecretManagerParams, SignatureSecretManager, type SignatureSecretManagerParams, 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 };
|