@corpus-core/colibri-tor 1.1.22

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.
Files changed (93) hide show
  1. package/README.md +90 -0
  2. package/dist/browser.d.ts +48 -0
  3. package/dist/browser.js +96 -0
  4. package/dist/index.d.ts +25 -0
  5. package/dist/index.js +24 -0
  6. package/dist/node.d.ts +34 -0
  7. package/dist/node.js +275 -0
  8. package/dist/types.d.ts +39 -0
  9. package/dist/types.js +23 -0
  10. package/node_modules/tor-js/README.md +166 -0
  11. package/node_modules/tor-js/dist/Log.d.ts +24 -0
  12. package/node_modules/tor-js/dist/Log.d.ts.map +1 -0
  13. package/node_modules/tor-js/dist/TorClient.d.ts +37 -0
  14. package/node_modules/tor-js/dist/TorClient.d.ts.map +1 -0
  15. package/node_modules/tor-js/dist/commonExports.d.ts +6 -0
  16. package/node_modules/tor-js/dist/commonExports.d.ts.map +1 -0
  17. package/node_modules/tor-js/dist/entryPoints/wasm-base64/index.d.ts +3 -0
  18. package/node_modules/tor-js/dist/entryPoints/wasm-base64/index.d.ts.map +1 -0
  19. package/node_modules/tor-js/dist/entryPoints/wasm-base64/index.js +2139 -0
  20. package/node_modules/tor-js/dist/entryPoints/wasm-base64/index.js.map +1 -0
  21. package/node_modules/tor-js/dist/entryPoints/wasm-base64/singleton.d.ts +4 -0
  22. package/node_modules/tor-js/dist/entryPoints/wasm-base64/singleton.d.ts.map +1 -0
  23. package/node_modules/tor-js/dist/entryPoints/wasm-base64/singleton.js +2187 -0
  24. package/node_modules/tor-js/dist/entryPoints/wasm-base64/singleton.js.map +1 -0
  25. package/node_modules/tor-js/dist/entryPoints/wasm-cdn/index.d.ts +3 -0
  26. package/node_modules/tor-js/dist/entryPoints/wasm-cdn/index.d.ts.map +1 -0
  27. package/node_modules/tor-js/dist/entryPoints/wasm-cdn/index.js +2242 -0
  28. package/node_modules/tor-js/dist/entryPoints/wasm-cdn/index.js.map +1 -0
  29. package/node_modules/tor-js/dist/entryPoints/wasm-cdn/singleton.d.ts +4 -0
  30. package/node_modules/tor-js/dist/entryPoints/wasm-cdn/singleton.d.ts.map +1 -0
  31. package/node_modules/tor-js/dist/entryPoints/wasm-cdn/singleton.js +2290 -0
  32. package/node_modules/tor-js/dist/entryPoints/wasm-cdn/singleton.js.map +1 -0
  33. package/node_modules/tor-js/dist/entryPoints/wasm-file/index.d.ts +3 -0
  34. package/node_modules/tor-js/dist/entryPoints/wasm-file/index.d.ts.map +1 -0
  35. package/node_modules/tor-js/dist/entryPoints/wasm-file/index.js +2139 -0
  36. package/node_modules/tor-js/dist/entryPoints/wasm-file/index.js.map +1 -0
  37. package/node_modules/tor-js/dist/entryPoints/wasm-file/singleton.d.ts +4 -0
  38. package/node_modules/tor-js/dist/entryPoints/wasm-file/singleton.d.ts.map +1 -0
  39. package/node_modules/tor-js/dist/entryPoints/wasm-file/singleton.js +2187 -0
  40. package/node_modules/tor-js/dist/entryPoints/wasm-file/singleton.js.map +1 -0
  41. package/node_modules/tor-js/dist/helpers.d.ts +7 -0
  42. package/node_modules/tor-js/dist/helpers.d.ts.map +1 -0
  43. package/node_modules/tor-js/dist/polyfills.d.ts +1 -0
  44. package/node_modules/tor-js/dist/polyfills.d.ts.map +1 -0
  45. package/node_modules/tor-js/dist/singleton.d.ts +24 -0
  46. package/node_modules/tor-js/dist/singleton.d.ts.map +1 -0
  47. package/node_modules/tor-js/dist/socketProvider.d.ts +76 -0
  48. package/node_modules/tor-js/dist/socketProvider.d.ts.map +1 -0
  49. package/node_modules/tor-js/dist/storage/filesystem.d.ts +18 -0
  50. package/node_modules/tor-js/dist/storage/filesystem.d.ts.map +1 -0
  51. package/node_modules/tor-js/dist/storage/index.d.ts +7 -0
  52. package/node_modules/tor-js/dist/storage/index.d.ts.map +1 -0
  53. package/node_modules/tor-js/dist/storage/indexeddb.d.ts +14 -0
  54. package/node_modules/tor-js/dist/storage/indexeddb.d.ts.map +1 -0
  55. package/node_modules/tor-js/dist/storage/locking.d.ts +15 -0
  56. package/node_modules/tor-js/dist/storage/locking.d.ts.map +1 -0
  57. package/node_modules/tor-js/dist/storage/memory.d.ts +13 -0
  58. package/node_modules/tor-js/dist/storage/memory.d.ts.map +1 -0
  59. package/node_modules/tor-js/dist/storage/node-deps.d.ts +8 -0
  60. package/node_modules/tor-js/dist/storage/node-deps.d.ts.map +1 -0
  61. package/node_modules/tor-js/dist/tor_js_bg.wasm +0 -0
  62. package/node_modules/tor-js/dist/types.d.ts +41 -0
  63. package/node_modules/tor-js/dist/types.d.ts.map +1 -0
  64. package/node_modules/tor-js/dist/wasm-B6es-efC.d.ts +302 -0
  65. package/node_modules/tor-js/dist/wasm-pkg/tor_js.d.ts +311 -0
  66. package/node_modules/tor-js/dist/wasm-pkg/tor_js.js +1159 -0
  67. package/node_modules/tor-js/dist/wasm.d.ts +31 -0
  68. package/node_modules/tor-js/dist/wasm.d.ts.map +1 -0
  69. package/node_modules/tor-js/package.json +61 -0
  70. package/node_modules/tor-js/src/Log.ts +100 -0
  71. package/node_modules/tor-js/src/TorClient.ts +134 -0
  72. package/node_modules/tor-js/src/commonExports.ts +7 -0
  73. package/node_modules/tor-js/src/entryPoints/wasm-base64/index.ts +17 -0
  74. package/node_modules/tor-js/src/entryPoints/wasm-base64/singleton.ts +7 -0
  75. package/node_modules/tor-js/src/entryPoints/wasm-cdn/index.ts +155 -0
  76. package/node_modules/tor-js/src/entryPoints/wasm-cdn/singleton.ts +7 -0
  77. package/node_modules/tor-js/src/entryPoints/wasm-file/index.ts +19 -0
  78. package/node_modules/tor-js/src/entryPoints/wasm-file/singleton.ts +7 -0
  79. package/node_modules/tor-js/src/globals.d.ts +2 -0
  80. package/node_modules/tor-js/src/helpers.ts +20 -0
  81. package/node_modules/tor-js/src/polyfills.ts +4 -0
  82. package/node_modules/tor-js/src/singleton.ts +54 -0
  83. package/node_modules/tor-js/src/socketProvider.ts +405 -0
  84. package/node_modules/tor-js/src/storage/filesystem.ts +171 -0
  85. package/node_modules/tor-js/src/storage/index.ts +21 -0
  86. package/node_modules/tor-js/src/storage/indexeddb.ts +99 -0
  87. package/node_modules/tor-js/src/storage/locking.ts +195 -0
  88. package/node_modules/tor-js/src/storage/memory.ts +42 -0
  89. package/node_modules/tor-js/src/storage/node-deps.ts +23 -0
  90. package/node_modules/tor-js/src/types.ts +48 -0
  91. package/node_modules/tor-js/src/wasm-base64-data.d.ts +3 -0
  92. package/node_modules/tor-js/src/wasm.ts +135 -0
  93. package/package.json +67 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,kKAAkK;IAClK,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,qEAAqE;IACrE,OAAO,CAAC,EAAE,UAAU,CAAC;IAErB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB,wHAAwH;IACxH,cAAc,CAAC,EAAE,kBAAkB,CAAC;CACrC,CAAC;AAEF,YAAY,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAExC,MAAM,WAAW,SAAS;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,CAAC;IACzC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB"}
@@ -0,0 +1,302 @@
1
+ type LogLevel$1 = 'trace' | 'debug' | 'info' | 'warn' | 'error';
2
+ interface LogConstructorParams {
3
+ rawLog?: (level: LogLevel$1, ...args: unknown[]) => void;
4
+ parentStartTime?: number;
5
+ namePrefix?: string;
6
+ }
7
+ declare class Log {
8
+ private rawLog;
9
+ private parentStartTime;
10
+ private namePrefix;
11
+ constructor(params?: LogConstructorParams);
12
+ child(name: string): Log;
13
+ trace(...args: unknown[]): void;
14
+ debug(...args: unknown[]): void;
15
+ info(...args: unknown[]): void;
16
+ warn(...args: unknown[]): void;
17
+ error(...args: unknown[]): void;
18
+ /** @internal Create a callback for WASM setLogCallback */
19
+ _makeWasmCallback(): (level: string, target: string, message: string) => void;
20
+ private log;
21
+ private defaultRawLog;
22
+ }
23
+
24
+ /**
25
+ * Storage interface for persisting Tor client state.
26
+ *
27
+ * Implement this interface to provide custom storage (IndexedDB, filesystem, etc.).
28
+ * All methods must return Promises.
29
+ *
30
+ * When storage is provided, the Tor client will persist guard selection and other
31
+ * state, allowing faster reconnection across page reloads.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * class IndexedDBStorage implements TorStorage {
36
+ * async get(key: string): Promise<string | null> {
37
+ * // Load from IndexedDB
38
+ * }
39
+ * async set(key: string, value: string): Promise<void> {
40
+ * // Save to IndexedDB
41
+ * }
42
+ * async delete(key: string): Promise<void> {
43
+ * // Delete from IndexedDB
44
+ * }
45
+ * async keys(prefix: string): Promise<string[]> {
46
+ * // List keys matching prefix
47
+ * }
48
+ * async tryLock(): Promise<boolean> {
49
+ * // addLocking is available in tor-js to solve locking with in-memory
50
+ * // overlay
51
+ * // true: newly acquired
52
+ * // false: already held
53
+ * // reject: couldn't lock
54
+ * }
55
+ * async unlock(): Promise<void> {
56
+ * }
57
+ * }
58
+ *
59
+ * const options = new TorClientOptions(gatewayUrl)
60
+ * .withStorage(new IndexedDBStorage());
61
+ * const client = await TorClient.create(options);
62
+ * ```
63
+ */
64
+ interface TorStorage {
65
+ /**
66
+ * Get a value by key.
67
+ * @param key - The storage key
68
+ * @returns The stored value as a string, or null if not found
69
+ */
70
+ get(key: string): Promise<string | null>;
71
+
72
+ /**
73
+ * Get all key-value pairs matching a prefix.
74
+ * @param prefix - The key prefix to match
75
+ * @returns Array of [key, value] pairs
76
+ */
77
+ getAll(prefix: string): Promise<[string, string][]>;
78
+
79
+ /**
80
+ * Set a value by key.
81
+ * @param key - The storage key
82
+ * @param value - The value to store (JSON string)
83
+ */
84
+ set(key: string, value: string): Promise<void>;
85
+
86
+ /**
87
+ * Delete a value by key.
88
+ * @param key - The storage key
89
+ */
90
+ delete(key: string): Promise<void>;
91
+
92
+ /**
93
+ * List all keys with a given prefix.
94
+ * @param prefix - The key prefix to match
95
+ * @returns Array of matching keys
96
+ */
97
+ keys(prefix: string): Promise<string[]>;
98
+
99
+ /**
100
+ * Try to acquire an exclusive write lock.
101
+ * @returns true if newly acquired, false if already held.
102
+ * Implement using Web Locks API (browser) or lock files (Node.js).
103
+ */
104
+ tryLock(): Promise<boolean>;
105
+
106
+ /**
107
+ * Release the write lock.
108
+ */
109
+ unlock(): Promise<void>;
110
+ }
111
+
112
+ /**
113
+ * Socket provider for connecting to Tor relays via direct TCP, WebSocket,
114
+ * or WebRTC.
115
+ *
116
+ * ArtiSocketProvider auto-detects available strategies based on environment:
117
+ * - Node.js/Deno: tries direct TCP first, then WebSocket/WebRTC if a gateway URL is set
118
+ * - Browsers: tries WebRTC first (if available), then WebSocket (requires gateway URL)
119
+ *
120
+ * Each `connect(target)` call returns an {@link ArtiSocket} — a uniform
121
+ * bidirectional byte pipe regardless of transport.
122
+ */
123
+ /**
124
+ * A bidirectional byte pipe to a Tor relay.
125
+ *
126
+ * Assign `onmessage` and `onclose` after creation.
127
+ * Call `send(data)` with Uint8Array and `close()` when done.
128
+ */
129
+ declare class ArtiSocket {
130
+ #private;
131
+ /** Set by transport on error, before onclose fires. */
132
+ _error: string | null;
133
+ /** Receive callback — transport fires this with each incoming chunk. */
134
+ onmessage: ((data: Uint8Array) => void) | null;
135
+ constructor(send: (data: Uint8Array) => void, close: () => void);
136
+ /** Setter that fires immediately if close already happened. */
137
+ set onclose(fn: (() => void) | null);
138
+ get onclose(): (() => void) | null;
139
+ /** @internal — called by transport wrappers when the underlying connection closes. */
140
+ _notifyClose(): void;
141
+ send(data: Uint8Array): void;
142
+ close(): void;
143
+ /** Wrap a browser WebSocket (already open). */
144
+ static fromWebSocket(ws: WebSocket): ArtiSocket;
145
+ /** Wrap a WebRTC data channel (already open). */
146
+ static fromDataChannel(dc: RTCDataChannel): ArtiSocket;
147
+ /** Wrap a Node.js net.Socket (already connected). */
148
+ static fromNodeSocket(socket: any): ArtiSocket;
149
+ /** Wrap a Deno TCP connection. */
150
+ static fromDenoConn(conn: any): ArtiSocket;
151
+ }
152
+ /**
153
+ * Options for creating an ArtiSocketProvider.
154
+ */
155
+ interface ArtiSocketProviderOptions {
156
+ /**
157
+ * Gateway URL (e.g., `"https://tor-js-gateway.example.com"`).
158
+ * Required in browsers for WebRTC/WebSocket relay connections.
159
+ * Optional in Node.js/Deno (enables fast bootstrap when provided).
160
+ */
161
+ gateway?: string;
162
+ /**
163
+ * Ordered list of strategies to try: `"direct"`, `"webrtc"`, `"websocket"`.
164
+ * Defaults based on environment and whether a gateway URL is provided.
165
+ */
166
+ strategies?: string[];
167
+ }
168
+ /**
169
+ * Opens sockets to Tor relays via configurable strategies (direct TCP,
170
+ * WebRTC data channels, WebSocket) with automatic fallback.
171
+ *
172
+ * The gateway URL is optional — without it, only the `direct` strategy is
173
+ * available (Node.js/Deno native TCP). With a gateway URL, WebRTC and
174
+ * WebSocket strategies become available for browser environments.
175
+ */
176
+ declare class ArtiSocketProvider {
177
+ #private;
178
+ constructor(options?: ArtiSocketProviderOptions);
179
+ /**
180
+ * Open a relay socket to the given target (e.g. "198.51.100.1:9001").
181
+ * Tries each configured strategy in order until one succeeds.
182
+ */
183
+ connect(target: string): Promise<ArtiSocket>;
184
+ /** Close WebRTC peer connection and release resources. */
185
+ close(): void;
186
+ }
187
+
188
+ type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';
189
+ /**
190
+ * Options for creating a TorClient.
191
+ *
192
+ * In browsers, provide a gateway URL for WebSocket/WebRTC relay connections
193
+ * and fast bootstrap. In Node.js/Deno, the gateway connects via direct TCP
194
+ * without a URL; providing one enables fast bootstrap from that server.
195
+ */
196
+ type TorClientOptions = {
197
+ /** Gateway URL (e.g., `"https://tor-js-gateway.voltrevo.com"`). Required in browsers for relay connections; optional in Node.js/Deno (enables fast bootstrap). */
198
+ gateway?: string;
199
+ /**
200
+ * Optional logger instance.
201
+ * Note: WASM logging is global, so all TorClient instances receive all WASM
202
+ * log events, not just their own. This is because wasm-bindgen generates a
203
+ * single module-level instance (`let wasm;`), so all Rust global state
204
+ * (including the tracing subscriber) is shared.
205
+ */
206
+ log?: Log;
207
+ /** Optional storage for persistent state (implements TorStorage). */
208
+ storage?: TorStorage;
209
+ /**
210
+ * Minimum log level for this client's log listener. Defaults to 'debug'.
211
+ * Can be changed at runtime via `TorClient.setLogLevel()`.
212
+ * The WASM subscriber auto-widens to the broadest level across all clients.
213
+ */
214
+ logLevel?: LogLevel;
215
+ /** Optional custom socket provider. When set, overrides the default ArtiSocketProvider created from the gateway URL. */
216
+ socketProvider?: ArtiSocketProvider;
217
+ };
218
+
219
+ interface FetchInit {
220
+ method?: string;
221
+ headers?: Record<string, string>;
222
+ body?: string | Uint8Array | ArrayBuffer;
223
+ signal?: AbortSignal;
224
+ }
225
+
226
+ declare class MemoryStorage implements TorStorage {
227
+ private data;
228
+ private locked;
229
+ get(key: string): Promise<string | null>;
230
+ set(key: string, value: string): Promise<void>;
231
+ delete(key: string): Promise<void>;
232
+ keys(prefix: string): Promise<string[]>;
233
+ getAll(prefix: string): Promise<[string, string][]>;
234
+ tryLock(): Promise<boolean>;
235
+ unlock(): Promise<void>;
236
+ }
237
+
238
+ /** Storage interface without locking — just the CRUD methods. */
239
+ type TorStorageSimple = Omit<TorStorage, 'tryLock' | 'unlock'>;
240
+ /**
241
+ * Wrap a simple storage with platform-detected locking.
242
+ *
243
+ * - Browser: Web Locks API (`navigator.locks`)
244
+ * - Node.js: lock file at `~/.local/share/${name}/.lock`
245
+ *
246
+ * If the real lock can't be acquired (another tab/process holds it),
247
+ * the wrapper degrades gracefully: reads fall through to the inner storage,
248
+ * writes go to an in-memory overlay, and `tryLock()` still returns `true`.
249
+ */
250
+ declare function addLocking(inner: TorStorageSimple, name: string): TorStorage;
251
+
252
+ declare class IndexedDBStorage implements TorStorageSimple {
253
+ private dbName;
254
+ private storeName;
255
+ private dbPromise;
256
+ constructor(name?: string);
257
+ private getDB;
258
+ get(key: string): Promise<string | null>;
259
+ set(key: string, value: string): Promise<void>;
260
+ delete(key: string): Promise<void>;
261
+ keys(prefix: string): Promise<string[]>;
262
+ getAll(prefix: string): Promise<[string, string][]>;
263
+ }
264
+
265
+ declare class FilesystemStorage implements TorStorageSimple {
266
+ private dirPath;
267
+ private name;
268
+ private resolvedDirPath;
269
+ private initialized;
270
+ constructor(dirPath: string);
271
+ static localShare(name: string): FilesystemStorage;
272
+ private resolvedDir;
273
+ private ensureDir;
274
+ private filePath;
275
+ get(key: string): Promise<string | null>;
276
+ set(key: string, value: string): Promise<void>;
277
+ delete(key: string): Promise<void>;
278
+ keys(prefix: string): Promise<string[]>;
279
+ getAll(prefix: string): Promise<[string, string][]>;
280
+ }
281
+
282
+ declare function createAutoStorage(name?: string): TorStorage;
283
+
284
+ type index_FilesystemStorage = FilesystemStorage;
285
+ declare const index_FilesystemStorage: typeof FilesystemStorage;
286
+ type index_IndexedDBStorage = IndexedDBStorage;
287
+ declare const index_IndexedDBStorage: typeof IndexedDBStorage;
288
+ type index_MemoryStorage = MemoryStorage;
289
+ declare const index_MemoryStorage: typeof MemoryStorage;
290
+ type index_TorStorageSimple = TorStorageSimple;
291
+ declare const index_addLocking: typeof addLocking;
292
+ declare const index_createAutoStorage: typeof createAutoStorage;
293
+ declare namespace index {
294
+ export { index_FilesystemStorage as FilesystemStorage, index_IndexedDBStorage as IndexedDBStorage, index_MemoryStorage as MemoryStorage, type index_TorStorageSimple as TorStorageSimple, index_addLocking as addLocking, index_createAutoStorage as createAutoStorage };
295
+ }
296
+
297
+ /**
298
+ * Override the WASM binary URL. Must be called before any TorClient is created.
299
+ */
300
+ declare function setWasmUrl(url: string | URL): void;
301
+
302
+ export { ArtiSocket as A, type FetchInit as F, type LogLevel as L, type TorClientOptions as T, ArtiSocketProvider as a, type ArtiSocketProviderOptions as b, Log as c, type LogLevel$1 as d, type TorStorage as e, index as i, setWasmUrl as s };
@@ -0,0 +1,311 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * The `ReadableStreamType` enum.
5
+ *
6
+ * *This API requires the following crate features to be activated: `ReadableStreamType`*
7
+ */
8
+
9
+ type ReadableStreamType = "bytes";
10
+
11
+ /**
12
+ * Storage interface for persisting Tor client state.
13
+ *
14
+ * Implement this interface to provide custom storage (IndexedDB, filesystem, etc.).
15
+ * All methods must return Promises.
16
+ *
17
+ * When storage is provided, the Tor client will persist guard selection and other
18
+ * state, allowing faster reconnection across page reloads.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * class IndexedDBStorage implements TorStorage {
23
+ * async get(key: string): Promise<string | null> {
24
+ * // Load from IndexedDB
25
+ * }
26
+ * async set(key: string, value: string): Promise<void> {
27
+ * // Save to IndexedDB
28
+ * }
29
+ * async delete(key: string): Promise<void> {
30
+ * // Delete from IndexedDB
31
+ * }
32
+ * async keys(prefix: string): Promise<string[]> {
33
+ * // List keys matching prefix
34
+ * }
35
+ * async tryLock(): Promise<boolean> {
36
+ * // addLocking is available in tor-js to solve locking with in-memory
37
+ * // overlay
38
+ * // true: newly acquired
39
+ * // false: already held
40
+ * // reject: couldn't lock
41
+ * }
42
+ * async unlock(): Promise<void> {
43
+ * }
44
+ * }
45
+ *
46
+ * const options = new TorClientOptions(gatewayUrl)
47
+ * .withStorage(new IndexedDBStorage());
48
+ * const client = await TorClient.create(options);
49
+ * ```
50
+ */
51
+ export interface TorStorage {
52
+ /**
53
+ * Get a value by key.
54
+ * @param key - The storage key
55
+ * @returns The stored value as a string, or null if not found
56
+ */
57
+ get(key: string): Promise<string | null>;
58
+
59
+ /**
60
+ * Get all key-value pairs matching a prefix.
61
+ * @param prefix - The key prefix to match
62
+ * @returns Array of [key, value] pairs
63
+ */
64
+ getAll(prefix: string): Promise<[string, string][]>;
65
+
66
+ /**
67
+ * Set a value by key.
68
+ * @param key - The storage key
69
+ * @param value - The value to store (JSON string)
70
+ */
71
+ set(key: string, value: string): Promise<void>;
72
+
73
+ /**
74
+ * Delete a value by key.
75
+ * @param key - The storage key
76
+ */
77
+ delete(key: string): Promise<void>;
78
+
79
+ /**
80
+ * List all keys with a given prefix.
81
+ * @param prefix - The key prefix to match
82
+ * @returns Array of matching keys
83
+ */
84
+ keys(prefix: string): Promise<string[]>;
85
+
86
+ /**
87
+ * Try to acquire an exclusive write lock.
88
+ * @returns true if newly acquired, false if already held.
89
+ * Implement using Web Locks API (browser) or lock files (Node.js).
90
+ */
91
+ tryLock(): Promise<boolean>;
92
+
93
+ /**
94
+ * Release the write lock.
95
+ */
96
+ unlock(): Promise<void>;
97
+ }
98
+
99
+ export interface FetchInit {
100
+ method?: string;
101
+ headers?: Record<string, string>;
102
+ body?: string | Uint8Array | ArrayBuffer;
103
+ signal?: AbortSignal;
104
+ }
105
+
106
+ export interface TorClient {
107
+ /** Make an HTTP fetch request through Tor. Returns a standard Response. */
108
+ fetch(url: string, init?: FetchInit): Promise<Response>;
109
+ close(): Promise<void>;
110
+ }
111
+
112
+ export interface TorClientOptions {
113
+ /**
114
+ * Set a custom storage implementation for persistent state.
115
+ * If not provided, in-memory storage is used (state lost on page reload).
116
+ */
117
+ withStorage(storage: TorStorage): TorClientOptions;
118
+ }
119
+
120
+
121
+
122
+ export class IntoUnderlyingByteSource {
123
+ private constructor();
124
+ free(): void;
125
+ [Symbol.dispose](): void;
126
+ cancel(): void;
127
+ pull(controller: ReadableByteStreamController): Promise<any>;
128
+ start(controller: ReadableByteStreamController): void;
129
+ readonly autoAllocateChunkSize: number;
130
+ readonly type: ReadableStreamType;
131
+ }
132
+
133
+ export class IntoUnderlyingSink {
134
+ private constructor();
135
+ free(): void;
136
+ [Symbol.dispose](): void;
137
+ abort(reason: any): Promise<any>;
138
+ close(): Promise<any>;
139
+ write(chunk: any): Promise<any>;
140
+ }
141
+
142
+ export class IntoUnderlyingSource {
143
+ private constructor();
144
+ free(): void;
145
+ [Symbol.dispose](): void;
146
+ cancel(): void;
147
+ pull(controller: ReadableStreamDefaultController): Promise<any>;
148
+ }
149
+
150
+ /**
151
+ * Tor client for making HTTP requests through the Tor network
152
+ */
153
+ export class TorClient {
154
+ private constructor();
155
+ free(): void;
156
+ [Symbol.dispose](): void;
157
+ /**
158
+ * Close the TorClient and release resources
159
+ */
160
+ close(): Promise<any>;
161
+ /**
162
+ * Create a new TorClient with the given options.
163
+ *
164
+ * This is an async operation that returns a Promise.
165
+ * The client will bootstrap and establish a connection to the Tor network.
166
+ *
167
+ * Usage from JS: `const client = await TorClient.create(options);`
168
+ */
169
+ static create(options: TorClientOptions): Promise<any>;
170
+ /**
171
+ * Wait until the client is ready for traffic (connection usable + valid directory).
172
+ */
173
+ ready(): Promise<any>;
174
+ }
175
+
176
+ /**
177
+ * Options for creating a TorClient
178
+ */
179
+ export class TorClientOptions {
180
+ free(): void;
181
+ [Symbol.dispose](): void;
182
+ /**
183
+ * Create options with a connect function.
184
+ *
185
+ * The connect function receives a target address string (e.g. "198.51.100.1:9001")
186
+ * and must return a Promise resolving to a socket object with:
187
+ * - `send(data: Uint8Array)` — send binary data
188
+ * - `onmessage: ((data: Uint8Array) => void) | null` — receive callback
189
+ * - `onclose: (() => void) | null` — close notification
190
+ * - `close()` — close the socket
191
+ *
192
+ * The TS wrapper provides this automatically via the Gateway class.
193
+ */
194
+ constructor(connect: Function);
195
+ /**
196
+ * Set a callback that provides bootstrap.zip bytes for fast directory pre-population.
197
+ *
198
+ * The callback should be `() => Promise<Uint8Array>` returning the uncompressed
199
+ * bootstrap.zip bytes (from a tor-js-gateway server).
200
+ *
201
+ * When set and storage has no cached consensus, the zip is parsed and the
202
+ * directory cache is pre-populated before bootstrap begins.
203
+ */
204
+ withFastBootstrap(callback: Function): TorClientOptions;
205
+ /**
206
+ * Set a custom storage implementation for persistent state.
207
+ *
208
+ * When set, the Tor client will persist guard selection and other state
209
+ * to this storage, allowing faster reconnection across page reloads.
210
+ *
211
+ * If not set, in-memory storage is used (state lost on page reload).
212
+ *
213
+ * # Arguments
214
+ * * `storage` - A JavaScript object implementing the TorStorage interface
215
+ */
216
+ withStorage(storage: TorStorage): TorClientOptions;
217
+ }
218
+
219
+ /**
220
+ * Initialize the tor-js WASM module
221
+ *
222
+ * This must be called before creating any TorClient instances.
223
+ * Sets up panic hooks and logging infrastructure.
224
+ *
225
+ * The optional `log_level` parameter sets the initial log level:
226
+ * "trace", "debug", "info", "warn", or "error". Defaults to "debug".
227
+ * The level can be changed later with `setLogLevel()`.
228
+ */
229
+ export function init(log_level?: string | null): void;
230
+
231
+ /**
232
+ * Set a callback function to receive log messages
233
+ *
234
+ * The callback receives three arguments: (level: string, target: string, message: string)
235
+ */
236
+ export function setLogCallback(callback: Function): void;
237
+
238
+ /**
239
+ * Dynamically update the minimum log level.
240
+ *
241
+ * Called from JS when the broadest requested level across all clients changes.
242
+ */
243
+ export function setLogLevel(level: string): void;
244
+
245
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
246
+
247
+ export interface InitOutput {
248
+ readonly memory: WebAssembly.Memory;
249
+ readonly __wbg_torclient_free: (a: number, b: number) => void;
250
+ readonly __wbg_torclientoptions_free: (a: number, b: number) => void;
251
+ readonly init: (a: number, b: number) => [number, number];
252
+ readonly setLogLevel: (a: number, b: number) => [number, number];
253
+ readonly torclient_close: (a: number) => any;
254
+ readonly torclient_create: (a: number) => any;
255
+ readonly torclient_fetch: (a: number, b: number, c: number, d: any) => any;
256
+ readonly torclient_ready: (a: number) => any;
257
+ readonly torclientoptions_new: (a: any) => number;
258
+ readonly torclientoptions_withFastBootstrap: (a: number, b: any) => number;
259
+ readonly torclientoptions_withStorage: (a: number, b: any) => number;
260
+ readonly setLogCallback: (a: any) => void;
261
+ readonly __wbg_intounderlyingbytesource_free: (a: number, b: number) => void;
262
+ readonly __wbg_intounderlyingsink_free: (a: number, b: number) => void;
263
+ readonly __wbg_intounderlyingsource_free: (a: number, b: number) => void;
264
+ readonly intounderlyingbytesource_autoAllocateChunkSize: (a: number) => number;
265
+ readonly intounderlyingbytesource_cancel: (a: number) => void;
266
+ readonly intounderlyingbytesource_pull: (a: number, b: any) => any;
267
+ readonly intounderlyingbytesource_start: (a: number, b: any) => void;
268
+ readonly intounderlyingbytesource_type: (a: number) => number;
269
+ readonly intounderlyingsink_abort: (a: number, b: any) => any;
270
+ readonly intounderlyingsink_close: (a: number) => any;
271
+ readonly intounderlyingsink_write: (a: number, b: any) => any;
272
+ readonly intounderlyingsource_cancel: (a: number) => void;
273
+ readonly intounderlyingsource_pull: (a: number, b: any) => any;
274
+ readonly wasm_bindgen__closure__destroy__h9b79478a56146cd2: (a: number, b: number) => void;
275
+ readonly wasm_bindgen__closure__destroy__h4d8dd6cb42c8a695: (a: number, b: number) => void;
276
+ readonly wasm_bindgen__closure__destroy__h1e3ac41672e7b2ad: (a: number, b: number) => void;
277
+ readonly wasm_bindgen__convert__closures_____invoke__hc2bcdd2c6020290d: (a: number, b: number, c: any) => [number, number];
278
+ readonly wasm_bindgen__convert__closures_____invoke__hb864778e5a95f086: (a: number, b: number, c: any, d: any) => void;
279
+ readonly wasm_bindgen__convert__closures_____invoke__h5c591e637e5094b1: (a: number, b: number, c: any) => void;
280
+ readonly wasm_bindgen__convert__closures_____invoke__h69c112f8841b438b: (a: number, b: number) => void;
281
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
282
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
283
+ readonly __wbindgen_exn_store: (a: number) => void;
284
+ readonly __externref_table_alloc: () => number;
285
+ readonly __wbindgen_externrefs: WebAssembly.Table;
286
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
287
+ readonly __externref_table_dealloc: (a: number) => void;
288
+ readonly __wbindgen_start: () => void;
289
+ }
290
+
291
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
292
+
293
+ /**
294
+ * Instantiates the given `module`, which can either be bytes or
295
+ * a precompiled `WebAssembly.Module`.
296
+ *
297
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
298
+ *
299
+ * @returns {InitOutput}
300
+ */
301
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
302
+
303
+ /**
304
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
305
+ * for everything else, calls `WebAssembly.instantiate` directly.
306
+ *
307
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
308
+ *
309
+ * @returns {Promise<InitOutput>}
310
+ */
311
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;