@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.
- package/README.md +90 -0
- package/dist/browser.d.ts +48 -0
- package/dist/browser.js +96 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +24 -0
- package/dist/node.d.ts +34 -0
- package/dist/node.js +275 -0
- package/dist/types.d.ts +39 -0
- package/dist/types.js +23 -0
- package/node_modules/tor-js/README.md +166 -0
- package/node_modules/tor-js/dist/Log.d.ts +24 -0
- package/node_modules/tor-js/dist/Log.d.ts.map +1 -0
- package/node_modules/tor-js/dist/TorClient.d.ts +37 -0
- package/node_modules/tor-js/dist/TorClient.d.ts.map +1 -0
- package/node_modules/tor-js/dist/commonExports.d.ts +6 -0
- package/node_modules/tor-js/dist/commonExports.d.ts.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-base64/index.d.ts +3 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-base64/index.d.ts.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-base64/index.js +2139 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-base64/index.js.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-base64/singleton.d.ts +4 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-base64/singleton.d.ts.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-base64/singleton.js +2187 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-base64/singleton.js.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-cdn/index.d.ts +3 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-cdn/index.d.ts.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-cdn/index.js +2242 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-cdn/index.js.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-cdn/singleton.d.ts +4 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-cdn/singleton.d.ts.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-cdn/singleton.js +2290 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-cdn/singleton.js.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-file/index.d.ts +3 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-file/index.d.ts.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-file/index.js +2139 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-file/index.js.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-file/singleton.d.ts +4 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-file/singleton.d.ts.map +1 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-file/singleton.js +2187 -0
- package/node_modules/tor-js/dist/entryPoints/wasm-file/singleton.js.map +1 -0
- package/node_modules/tor-js/dist/helpers.d.ts +7 -0
- package/node_modules/tor-js/dist/helpers.d.ts.map +1 -0
- package/node_modules/tor-js/dist/polyfills.d.ts +1 -0
- package/node_modules/tor-js/dist/polyfills.d.ts.map +1 -0
- package/node_modules/tor-js/dist/singleton.d.ts +24 -0
- package/node_modules/tor-js/dist/singleton.d.ts.map +1 -0
- package/node_modules/tor-js/dist/socketProvider.d.ts +76 -0
- package/node_modules/tor-js/dist/socketProvider.d.ts.map +1 -0
- package/node_modules/tor-js/dist/storage/filesystem.d.ts +18 -0
- package/node_modules/tor-js/dist/storage/filesystem.d.ts.map +1 -0
- package/node_modules/tor-js/dist/storage/index.d.ts +7 -0
- package/node_modules/tor-js/dist/storage/index.d.ts.map +1 -0
- package/node_modules/tor-js/dist/storage/indexeddb.d.ts +14 -0
- package/node_modules/tor-js/dist/storage/indexeddb.d.ts.map +1 -0
- package/node_modules/tor-js/dist/storage/locking.d.ts +15 -0
- package/node_modules/tor-js/dist/storage/locking.d.ts.map +1 -0
- package/node_modules/tor-js/dist/storage/memory.d.ts +13 -0
- package/node_modules/tor-js/dist/storage/memory.d.ts.map +1 -0
- package/node_modules/tor-js/dist/storage/node-deps.d.ts +8 -0
- package/node_modules/tor-js/dist/storage/node-deps.d.ts.map +1 -0
- package/node_modules/tor-js/dist/tor_js_bg.wasm +0 -0
- package/node_modules/tor-js/dist/types.d.ts +41 -0
- package/node_modules/tor-js/dist/types.d.ts.map +1 -0
- package/node_modules/tor-js/dist/wasm-B6es-efC.d.ts +302 -0
- package/node_modules/tor-js/dist/wasm-pkg/tor_js.d.ts +311 -0
- package/node_modules/tor-js/dist/wasm-pkg/tor_js.js +1159 -0
- package/node_modules/tor-js/dist/wasm.d.ts +31 -0
- package/node_modules/tor-js/dist/wasm.d.ts.map +1 -0
- package/node_modules/tor-js/package.json +61 -0
- package/node_modules/tor-js/src/Log.ts +100 -0
- package/node_modules/tor-js/src/TorClient.ts +134 -0
- package/node_modules/tor-js/src/commonExports.ts +7 -0
- package/node_modules/tor-js/src/entryPoints/wasm-base64/index.ts +17 -0
- package/node_modules/tor-js/src/entryPoints/wasm-base64/singleton.ts +7 -0
- package/node_modules/tor-js/src/entryPoints/wasm-cdn/index.ts +155 -0
- package/node_modules/tor-js/src/entryPoints/wasm-cdn/singleton.ts +7 -0
- package/node_modules/tor-js/src/entryPoints/wasm-file/index.ts +19 -0
- package/node_modules/tor-js/src/entryPoints/wasm-file/singleton.ts +7 -0
- package/node_modules/tor-js/src/globals.d.ts +2 -0
- package/node_modules/tor-js/src/helpers.ts +20 -0
- package/node_modules/tor-js/src/polyfills.ts +4 -0
- package/node_modules/tor-js/src/singleton.ts +54 -0
- package/node_modules/tor-js/src/socketProvider.ts +405 -0
- package/node_modules/tor-js/src/storage/filesystem.ts +171 -0
- package/node_modules/tor-js/src/storage/index.ts +21 -0
- package/node_modules/tor-js/src/storage/indexeddb.ts +99 -0
- package/node_modules/tor-js/src/storage/locking.ts +195 -0
- package/node_modules/tor-js/src/storage/memory.ts +42 -0
- package/node_modules/tor-js/src/storage/node-deps.ts +23 -0
- package/node_modules/tor-js/src/types.ts +48 -0
- package/node_modules/tor-js/src/wasm-base64-data.d.ts +3 -0
- package/node_modules/tor-js/src/wasm.ts +135 -0
- package/package.json +67 -0
|
@@ -0,0 +1,2187 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/polyfills.ts
|
|
8
|
+
Symbol.dispose ??= /* @__PURE__ */ Symbol("Symbol.dispose");
|
|
9
|
+
|
|
10
|
+
// ../pkg/tor_js.js
|
|
11
|
+
var IntoUnderlyingByteSource = class {
|
|
12
|
+
__destroy_into_raw() {
|
|
13
|
+
const ptr = this.__wbg_ptr;
|
|
14
|
+
this.__wbg_ptr = 0;
|
|
15
|
+
IntoUnderlyingByteSourceFinalization.unregister(this);
|
|
16
|
+
return ptr;
|
|
17
|
+
}
|
|
18
|
+
free() {
|
|
19
|
+
const ptr = this.__destroy_into_raw();
|
|
20
|
+
wasm.__wbg_intounderlyingbytesource_free(ptr, 0);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @returns {number}
|
|
24
|
+
*/
|
|
25
|
+
get autoAllocateChunkSize() {
|
|
26
|
+
const ret = wasm.intounderlyingbytesource_autoAllocateChunkSize(this.__wbg_ptr);
|
|
27
|
+
return ret >>> 0;
|
|
28
|
+
}
|
|
29
|
+
cancel() {
|
|
30
|
+
const ptr = this.__destroy_into_raw();
|
|
31
|
+
wasm.intounderlyingbytesource_cancel(ptr);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @param {ReadableByteStreamController} controller
|
|
35
|
+
* @returns {Promise<any>}
|
|
36
|
+
*/
|
|
37
|
+
pull(controller) {
|
|
38
|
+
const ret = wasm.intounderlyingbytesource_pull(this.__wbg_ptr, controller);
|
|
39
|
+
return ret;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @param {ReadableByteStreamController} controller
|
|
43
|
+
*/
|
|
44
|
+
start(controller) {
|
|
45
|
+
wasm.intounderlyingbytesource_start(this.__wbg_ptr, controller);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @returns {ReadableStreamType}
|
|
49
|
+
*/
|
|
50
|
+
get type() {
|
|
51
|
+
const ret = wasm.intounderlyingbytesource_type(this.__wbg_ptr);
|
|
52
|
+
return __wbindgen_enum_ReadableStreamType[ret];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
if (Symbol.dispose) IntoUnderlyingByteSource.prototype[Symbol.dispose] = IntoUnderlyingByteSource.prototype.free;
|
|
56
|
+
var IntoUnderlyingSink = class {
|
|
57
|
+
__destroy_into_raw() {
|
|
58
|
+
const ptr = this.__wbg_ptr;
|
|
59
|
+
this.__wbg_ptr = 0;
|
|
60
|
+
IntoUnderlyingSinkFinalization.unregister(this);
|
|
61
|
+
return ptr;
|
|
62
|
+
}
|
|
63
|
+
free() {
|
|
64
|
+
const ptr = this.__destroy_into_raw();
|
|
65
|
+
wasm.__wbg_intounderlyingsink_free(ptr, 0);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @param {any} reason
|
|
69
|
+
* @returns {Promise<any>}
|
|
70
|
+
*/
|
|
71
|
+
abort(reason) {
|
|
72
|
+
const ptr = this.__destroy_into_raw();
|
|
73
|
+
const ret = wasm.intounderlyingsink_abort(ptr, reason);
|
|
74
|
+
return ret;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @returns {Promise<any>}
|
|
78
|
+
*/
|
|
79
|
+
close() {
|
|
80
|
+
const ptr = this.__destroy_into_raw();
|
|
81
|
+
const ret = wasm.intounderlyingsink_close(ptr);
|
|
82
|
+
return ret;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @param {any} chunk
|
|
86
|
+
* @returns {Promise<any>}
|
|
87
|
+
*/
|
|
88
|
+
write(chunk) {
|
|
89
|
+
const ret = wasm.intounderlyingsink_write(this.__wbg_ptr, chunk);
|
|
90
|
+
return ret;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
if (Symbol.dispose) IntoUnderlyingSink.prototype[Symbol.dispose] = IntoUnderlyingSink.prototype.free;
|
|
94
|
+
var IntoUnderlyingSource = class _IntoUnderlyingSource {
|
|
95
|
+
static __wrap(ptr) {
|
|
96
|
+
ptr = ptr >>> 0;
|
|
97
|
+
const obj = Object.create(_IntoUnderlyingSource.prototype);
|
|
98
|
+
obj.__wbg_ptr = ptr;
|
|
99
|
+
IntoUnderlyingSourceFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
100
|
+
return obj;
|
|
101
|
+
}
|
|
102
|
+
__destroy_into_raw() {
|
|
103
|
+
const ptr = this.__wbg_ptr;
|
|
104
|
+
this.__wbg_ptr = 0;
|
|
105
|
+
IntoUnderlyingSourceFinalization.unregister(this);
|
|
106
|
+
return ptr;
|
|
107
|
+
}
|
|
108
|
+
free() {
|
|
109
|
+
const ptr = this.__destroy_into_raw();
|
|
110
|
+
wasm.__wbg_intounderlyingsource_free(ptr, 0);
|
|
111
|
+
}
|
|
112
|
+
cancel() {
|
|
113
|
+
const ptr = this.__destroy_into_raw();
|
|
114
|
+
wasm.intounderlyingsource_cancel(ptr);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @param {ReadableStreamDefaultController} controller
|
|
118
|
+
* @returns {Promise<any>}
|
|
119
|
+
*/
|
|
120
|
+
pull(controller) {
|
|
121
|
+
const ret = wasm.intounderlyingsource_pull(this.__wbg_ptr, controller);
|
|
122
|
+
return ret;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
if (Symbol.dispose) IntoUnderlyingSource.prototype[Symbol.dispose] = IntoUnderlyingSource.prototype.free;
|
|
126
|
+
var TorClient = class _TorClient {
|
|
127
|
+
static __wrap(ptr) {
|
|
128
|
+
ptr = ptr >>> 0;
|
|
129
|
+
const obj = Object.create(_TorClient.prototype);
|
|
130
|
+
obj.__wbg_ptr = ptr;
|
|
131
|
+
TorClientFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
132
|
+
return obj;
|
|
133
|
+
}
|
|
134
|
+
__destroy_into_raw() {
|
|
135
|
+
const ptr = this.__wbg_ptr;
|
|
136
|
+
this.__wbg_ptr = 0;
|
|
137
|
+
TorClientFinalization.unregister(this);
|
|
138
|
+
return ptr;
|
|
139
|
+
}
|
|
140
|
+
free() {
|
|
141
|
+
const ptr = this.__destroy_into_raw();
|
|
142
|
+
wasm.__wbg_torclient_free(ptr, 0);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Close the TorClient and release resources
|
|
146
|
+
* @returns {Promise<any>}
|
|
147
|
+
*/
|
|
148
|
+
close() {
|
|
149
|
+
const ret = wasm.torclient_close(this.__wbg_ptr);
|
|
150
|
+
return ret;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Create a new TorClient with the given options.
|
|
154
|
+
*
|
|
155
|
+
* This is an async operation that returns a Promise.
|
|
156
|
+
* The client will bootstrap and establish a connection to the Tor network.
|
|
157
|
+
*
|
|
158
|
+
* Usage from JS: `const client = await TorClient.create(options);`
|
|
159
|
+
* @param {TorClientOptions} options
|
|
160
|
+
* @returns {Promise<any>}
|
|
161
|
+
*/
|
|
162
|
+
static create(options) {
|
|
163
|
+
_assertClass(options, TorClientOptions);
|
|
164
|
+
var ptr0 = options.__destroy_into_raw();
|
|
165
|
+
const ret = wasm.torclient_create(ptr0);
|
|
166
|
+
return ret;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Make an HTTP fetch request through Tor
|
|
170
|
+
*
|
|
171
|
+
* Returns a Promise that resolves to a standard browser `Response` object
|
|
172
|
+
* as soon as response headers are received. The body is a `ReadableStream`
|
|
173
|
+
* that reads from the Tor circuit on demand.
|
|
174
|
+
* @param {string} url
|
|
175
|
+
* @param {any} init
|
|
176
|
+
* @returns {Promise<any>}
|
|
177
|
+
*/
|
|
178
|
+
fetch(url, init2) {
|
|
179
|
+
const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
180
|
+
const len0 = WASM_VECTOR_LEN;
|
|
181
|
+
const ret = wasm.torclient_fetch(this.__wbg_ptr, ptr0, len0, init2);
|
|
182
|
+
return ret;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Wait until the client is ready for traffic (connection usable + valid directory).
|
|
186
|
+
* @returns {Promise<any>}
|
|
187
|
+
*/
|
|
188
|
+
ready() {
|
|
189
|
+
const ret = wasm.torclient_ready(this.__wbg_ptr);
|
|
190
|
+
return ret;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
if (Symbol.dispose) TorClient.prototype[Symbol.dispose] = TorClient.prototype.free;
|
|
194
|
+
var TorClientOptions = class _TorClientOptions {
|
|
195
|
+
static __wrap(ptr) {
|
|
196
|
+
ptr = ptr >>> 0;
|
|
197
|
+
const obj = Object.create(_TorClientOptions.prototype);
|
|
198
|
+
obj.__wbg_ptr = ptr;
|
|
199
|
+
TorClientOptionsFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
200
|
+
return obj;
|
|
201
|
+
}
|
|
202
|
+
__destroy_into_raw() {
|
|
203
|
+
const ptr = this.__wbg_ptr;
|
|
204
|
+
this.__wbg_ptr = 0;
|
|
205
|
+
TorClientOptionsFinalization.unregister(this);
|
|
206
|
+
return ptr;
|
|
207
|
+
}
|
|
208
|
+
free() {
|
|
209
|
+
const ptr = this.__destroy_into_raw();
|
|
210
|
+
wasm.__wbg_torclientoptions_free(ptr, 0);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Create options with a connect function.
|
|
214
|
+
*
|
|
215
|
+
* The connect function receives a target address string (e.g. "198.51.100.1:9001")
|
|
216
|
+
* and must return a Promise resolving to a socket object with:
|
|
217
|
+
* - `send(data: Uint8Array)` — send binary data
|
|
218
|
+
* - `onmessage: ((data: Uint8Array) => void) | null` — receive callback
|
|
219
|
+
* - `onclose: (() => void) | null` — close notification
|
|
220
|
+
* - `close()` — close the socket
|
|
221
|
+
*
|
|
222
|
+
* The TS wrapper provides this automatically via the Gateway class.
|
|
223
|
+
* @param {Function} connect
|
|
224
|
+
*/
|
|
225
|
+
constructor(connect) {
|
|
226
|
+
const ret = wasm.torclientoptions_new(connect);
|
|
227
|
+
this.__wbg_ptr = ret >>> 0;
|
|
228
|
+
TorClientOptionsFinalization.register(this, this.__wbg_ptr, this);
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Set a callback that provides bootstrap.zip bytes for fast directory pre-population.
|
|
233
|
+
*
|
|
234
|
+
* The callback should be `() => Promise<Uint8Array>` returning the uncompressed
|
|
235
|
+
* bootstrap.zip bytes (from a tor-js-gateway server).
|
|
236
|
+
*
|
|
237
|
+
* When set and storage has no cached consensus, the zip is parsed and the
|
|
238
|
+
* directory cache is pre-populated before bootstrap begins.
|
|
239
|
+
* @param {Function} callback
|
|
240
|
+
* @returns {TorClientOptions}
|
|
241
|
+
*/
|
|
242
|
+
withFastBootstrap(callback) {
|
|
243
|
+
const ptr = this.__destroy_into_raw();
|
|
244
|
+
const ret = wasm.torclientoptions_withFastBootstrap(ptr, callback);
|
|
245
|
+
return _TorClientOptions.__wrap(ret);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Set a custom storage implementation for persistent state.
|
|
249
|
+
*
|
|
250
|
+
* When set, the Tor client will persist guard selection and other state
|
|
251
|
+
* to this storage, allowing faster reconnection across page reloads.
|
|
252
|
+
*
|
|
253
|
+
* If not set, in-memory storage is used (state lost on page reload).
|
|
254
|
+
*
|
|
255
|
+
* # Arguments
|
|
256
|
+
* * `storage` - A JavaScript object implementing the TorStorage interface
|
|
257
|
+
* @param {TorStorage} storage
|
|
258
|
+
* @returns {TorClientOptions}
|
|
259
|
+
*/
|
|
260
|
+
withStorage(storage) {
|
|
261
|
+
const ptr = this.__destroy_into_raw();
|
|
262
|
+
const ret = wasm.torclientoptions_withStorage(ptr, storage);
|
|
263
|
+
return _TorClientOptions.__wrap(ret);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
if (Symbol.dispose) TorClientOptions.prototype[Symbol.dispose] = TorClientOptions.prototype.free;
|
|
267
|
+
function init(log_level) {
|
|
268
|
+
var ptr0 = isLikeNone(log_level) ? 0 : passStringToWasm0(log_level, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
269
|
+
var len0 = WASM_VECTOR_LEN;
|
|
270
|
+
const ret = wasm.init(ptr0, len0);
|
|
271
|
+
if (ret[1]) {
|
|
272
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function setLogCallback(callback) {
|
|
276
|
+
wasm.setLogCallback(callback);
|
|
277
|
+
}
|
|
278
|
+
function setLogLevel(level) {
|
|
279
|
+
const ptr0 = passStringToWasm0(level, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
280
|
+
const len0 = WASM_VECTOR_LEN;
|
|
281
|
+
const ret = wasm.setLogLevel(ptr0, len0);
|
|
282
|
+
if (ret[1]) {
|
|
283
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function __wbg_get_imports() {
|
|
287
|
+
const import0 = {
|
|
288
|
+
__proto__: null,
|
|
289
|
+
__wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
|
|
290
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
291
|
+
return ret;
|
|
292
|
+
},
|
|
293
|
+
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
294
|
+
const ret = String(arg1);
|
|
295
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
296
|
+
const len1 = WASM_VECTOR_LEN;
|
|
297
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
298
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
299
|
+
},
|
|
300
|
+
__wbg___wbindgen_boolean_get_c0f3f60bac5a78d1: function(arg0) {
|
|
301
|
+
const v = arg0;
|
|
302
|
+
const ret = typeof v === "boolean" ? v : void 0;
|
|
303
|
+
return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
|
|
304
|
+
},
|
|
305
|
+
__wbg___wbindgen_debug_string_5398f5bb970e0daa: function(arg0, arg1) {
|
|
306
|
+
const ret = debugString(arg1);
|
|
307
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
308
|
+
const len1 = WASM_VECTOR_LEN;
|
|
309
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
310
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
311
|
+
},
|
|
312
|
+
__wbg___wbindgen_in_41dbb8413020e076: function(arg0, arg1) {
|
|
313
|
+
const ret = arg0 in arg1;
|
|
314
|
+
return ret;
|
|
315
|
+
},
|
|
316
|
+
__wbg___wbindgen_is_function_3c846841762788c1: function(arg0) {
|
|
317
|
+
const ret = typeof arg0 === "function";
|
|
318
|
+
return ret;
|
|
319
|
+
},
|
|
320
|
+
__wbg___wbindgen_is_null_0b605fc6b167c56f: function(arg0) {
|
|
321
|
+
const ret = arg0 === null;
|
|
322
|
+
return ret;
|
|
323
|
+
},
|
|
324
|
+
__wbg___wbindgen_is_object_781bc9f159099513: function(arg0) {
|
|
325
|
+
const val = arg0;
|
|
326
|
+
const ret = typeof val === "object" && val !== null;
|
|
327
|
+
return ret;
|
|
328
|
+
},
|
|
329
|
+
__wbg___wbindgen_is_string_7ef6b97b02428fae: function(arg0) {
|
|
330
|
+
const ret = typeof arg0 === "string";
|
|
331
|
+
return ret;
|
|
332
|
+
},
|
|
333
|
+
__wbg___wbindgen_is_undefined_52709e72fb9f179c: function(arg0) {
|
|
334
|
+
const ret = arg0 === void 0;
|
|
335
|
+
return ret;
|
|
336
|
+
},
|
|
337
|
+
__wbg___wbindgen_jsval_loose_eq_5bcc3bed3c69e72b: function(arg0, arg1) {
|
|
338
|
+
const ret = arg0 == arg1;
|
|
339
|
+
return ret;
|
|
340
|
+
},
|
|
341
|
+
__wbg___wbindgen_number_get_34bb9d9dcfa21373: function(arg0, arg1) {
|
|
342
|
+
const obj = arg1;
|
|
343
|
+
const ret = typeof obj === "number" ? obj : void 0;
|
|
344
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
345
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
346
|
+
},
|
|
347
|
+
__wbg___wbindgen_string_get_395e606bd0ee4427: function(arg0, arg1) {
|
|
348
|
+
const obj = arg1;
|
|
349
|
+
const ret = typeof obj === "string" ? obj : void 0;
|
|
350
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
351
|
+
var len1 = WASM_VECTOR_LEN;
|
|
352
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
353
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
354
|
+
},
|
|
355
|
+
__wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
|
|
356
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
357
|
+
},
|
|
358
|
+
__wbg__wbg_cb_unref_6b5b6b8576d35cb1: function(arg0) {
|
|
359
|
+
arg0._wbg_cb_unref();
|
|
360
|
+
},
|
|
361
|
+
__wbg_aborted_4789bfb2963583fb: function(arg0) {
|
|
362
|
+
const ret = arg0.aborted;
|
|
363
|
+
return ret;
|
|
364
|
+
},
|
|
365
|
+
__wbg_all_91078ec14f01cdc8: function(arg0) {
|
|
366
|
+
const ret = Promise.all(arg0);
|
|
367
|
+
return ret;
|
|
368
|
+
},
|
|
369
|
+
__wbg_append_608dfb635ee8998f: function() {
|
|
370
|
+
return handleError(function(arg0, arg1, arg2, arg3, arg4) {
|
|
371
|
+
arg0.append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
|
|
372
|
+
}, arguments);
|
|
373
|
+
},
|
|
374
|
+
__wbg_buffer_60b8043cd926067d: function(arg0) {
|
|
375
|
+
const ret = arg0.buffer;
|
|
376
|
+
return ret;
|
|
377
|
+
},
|
|
378
|
+
__wbg_byobRequest_6342e5f2b232c0f9: function(arg0) {
|
|
379
|
+
const ret = arg0.byobRequest;
|
|
380
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
381
|
+
},
|
|
382
|
+
__wbg_byteLength_607b856aa6c5a508: function(arg0) {
|
|
383
|
+
const ret = arg0.byteLength;
|
|
384
|
+
return ret;
|
|
385
|
+
},
|
|
386
|
+
__wbg_byteOffset_b26b63681c83856c: function(arg0) {
|
|
387
|
+
const ret = arg0.byteOffset;
|
|
388
|
+
return ret;
|
|
389
|
+
},
|
|
390
|
+
__wbg_call_2d781c1f4d5c0ef8: function() {
|
|
391
|
+
return handleError(function(arg0, arg1, arg2) {
|
|
392
|
+
const ret = arg0.call(arg1, arg2);
|
|
393
|
+
return ret;
|
|
394
|
+
}, arguments);
|
|
395
|
+
},
|
|
396
|
+
__wbg_call_e133b57c9155d22c: function() {
|
|
397
|
+
return handleError(function(arg0, arg1) {
|
|
398
|
+
const ret = arg0.call(arg1);
|
|
399
|
+
return ret;
|
|
400
|
+
}, arguments);
|
|
401
|
+
},
|
|
402
|
+
__wbg_call_f858478a02f9600f: function() {
|
|
403
|
+
return handleError(function(arg0, arg1, arg2, arg3, arg4) {
|
|
404
|
+
const ret = arg0.call(arg1, arg2, arg3, arg4);
|
|
405
|
+
return ret;
|
|
406
|
+
}, arguments);
|
|
407
|
+
},
|
|
408
|
+
__wbg_clearTimeout_113b1cde814ec762: function(arg0) {
|
|
409
|
+
const ret = clearTimeout(arg0);
|
|
410
|
+
return ret;
|
|
411
|
+
},
|
|
412
|
+
__wbg_close_690d36108c557337: function() {
|
|
413
|
+
return handleError(function(arg0) {
|
|
414
|
+
arg0.close();
|
|
415
|
+
}, arguments);
|
|
416
|
+
},
|
|
417
|
+
__wbg_close_737b4b1fbc658540: function() {
|
|
418
|
+
return handleError(function(arg0) {
|
|
419
|
+
arg0.close();
|
|
420
|
+
}, arguments);
|
|
421
|
+
},
|
|
422
|
+
__wbg_crypto_38df2bab126b63dc: function(arg0) {
|
|
423
|
+
const ret = arg0.crypto;
|
|
424
|
+
return ret;
|
|
425
|
+
},
|
|
426
|
+
__wbg_delete_bddb69df015ae01b: function() {
|
|
427
|
+
return handleError(function(arg0, arg1, arg2) {
|
|
428
|
+
const ret = arg0.delete(getStringFromWasm0(arg1, arg2));
|
|
429
|
+
return ret;
|
|
430
|
+
}, arguments);
|
|
431
|
+
},
|
|
432
|
+
__wbg_digest_cb8de04aa7e6b6f1: function() {
|
|
433
|
+
return handleError(function(arg0, arg1, arg2, arg3) {
|
|
434
|
+
const ret = arg0.digest(getStringFromWasm0(arg1, arg2), arg3);
|
|
435
|
+
return ret;
|
|
436
|
+
}, arguments);
|
|
437
|
+
},
|
|
438
|
+
__wbg_done_08ce71ee07e3bd17: function(arg0) {
|
|
439
|
+
const ret = arg0.done;
|
|
440
|
+
return ret;
|
|
441
|
+
},
|
|
442
|
+
__wbg_enqueue_ec3552838b4b7fbf: function() {
|
|
443
|
+
return handleError(function(arg0, arg1) {
|
|
444
|
+
arg0.enqueue(arg1);
|
|
445
|
+
}, arguments);
|
|
446
|
+
},
|
|
447
|
+
__wbg_entries_e8a20ff8c9757101: function(arg0) {
|
|
448
|
+
const ret = Object.entries(arg0);
|
|
449
|
+
return ret;
|
|
450
|
+
},
|
|
451
|
+
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
452
|
+
let deferred0_0;
|
|
453
|
+
let deferred0_1;
|
|
454
|
+
try {
|
|
455
|
+
deferred0_0 = arg0;
|
|
456
|
+
deferred0_1 = arg1;
|
|
457
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
458
|
+
} finally {
|
|
459
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
__wbg_from_4bdf88943703fd48: function(arg0) {
|
|
463
|
+
const ret = Array.from(arg0);
|
|
464
|
+
return ret;
|
|
465
|
+
},
|
|
466
|
+
__wbg_getAll_576fde6e76c7d925: function() {
|
|
467
|
+
return handleError(function(arg0, arg1, arg2) {
|
|
468
|
+
const ret = arg0.getAll(getStringFromWasm0(arg1, arg2));
|
|
469
|
+
return ret;
|
|
470
|
+
}, arguments);
|
|
471
|
+
},
|
|
472
|
+
__wbg_getRandomValues_3f44b700395062e5: function() {
|
|
473
|
+
return handleError(function(arg0, arg1) {
|
|
474
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
475
|
+
}, arguments);
|
|
476
|
+
},
|
|
477
|
+
__wbg_getRandomValues_c44a50d8cfdaebeb: function() {
|
|
478
|
+
return handleError(function(arg0, arg1) {
|
|
479
|
+
arg0.getRandomValues(arg1);
|
|
480
|
+
}, arguments);
|
|
481
|
+
},
|
|
482
|
+
__wbg_get_326e41e095fb2575: function() {
|
|
483
|
+
return handleError(function(arg0, arg1) {
|
|
484
|
+
const ret = Reflect.get(arg0, arg1);
|
|
485
|
+
return ret;
|
|
486
|
+
}, arguments);
|
|
487
|
+
},
|
|
488
|
+
__wbg_get_3ef1eba1850ade27: function() {
|
|
489
|
+
return handleError(function(arg0, arg1) {
|
|
490
|
+
const ret = Reflect.get(arg0, arg1);
|
|
491
|
+
return ret;
|
|
492
|
+
}, arguments);
|
|
493
|
+
},
|
|
494
|
+
__wbg_get_a8ee5c45dabc1b3b: function(arg0, arg1) {
|
|
495
|
+
const ret = arg0[arg1 >>> 0];
|
|
496
|
+
return ret;
|
|
497
|
+
},
|
|
498
|
+
__wbg_get_unchecked_329cfe50afab7352: function(arg0, arg1) {
|
|
499
|
+
const ret = arg0[arg1 >>> 0];
|
|
500
|
+
return ret;
|
|
501
|
+
},
|
|
502
|
+
__wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
|
|
503
|
+
const ret = arg0[arg1];
|
|
504
|
+
return ret;
|
|
505
|
+
},
|
|
506
|
+
__wbg_instanceof_AbortSignal_0173156d14d8c44d: function(arg0) {
|
|
507
|
+
let result;
|
|
508
|
+
try {
|
|
509
|
+
result = arg0 instanceof AbortSignal;
|
|
510
|
+
} catch (_) {
|
|
511
|
+
result = false;
|
|
512
|
+
}
|
|
513
|
+
const ret = result;
|
|
514
|
+
return ret;
|
|
515
|
+
},
|
|
516
|
+
__wbg_instanceof_ArrayBuffer_101e2bf31071a9f6: function(arg0) {
|
|
517
|
+
let result;
|
|
518
|
+
try {
|
|
519
|
+
result = arg0 instanceof ArrayBuffer;
|
|
520
|
+
} catch (_) {
|
|
521
|
+
result = false;
|
|
522
|
+
}
|
|
523
|
+
const ret = result;
|
|
524
|
+
return ret;
|
|
525
|
+
},
|
|
526
|
+
__wbg_instanceof_Crypto_5c2a4c15287b0332: function(arg0) {
|
|
527
|
+
let result;
|
|
528
|
+
try {
|
|
529
|
+
result = arg0 instanceof Crypto;
|
|
530
|
+
} catch (_) {
|
|
531
|
+
result = false;
|
|
532
|
+
}
|
|
533
|
+
const ret = result;
|
|
534
|
+
return ret;
|
|
535
|
+
},
|
|
536
|
+
__wbg_instanceof_Uint8Array_740438561a5b956d: function(arg0) {
|
|
537
|
+
let result;
|
|
538
|
+
try {
|
|
539
|
+
result = arg0 instanceof Uint8Array;
|
|
540
|
+
} catch (_) {
|
|
541
|
+
result = false;
|
|
542
|
+
}
|
|
543
|
+
const ret = result;
|
|
544
|
+
return ret;
|
|
545
|
+
},
|
|
546
|
+
__wbg_iterator_d8f549ec8fb061b1: function() {
|
|
547
|
+
const ret = Symbol.iterator;
|
|
548
|
+
return ret;
|
|
549
|
+
},
|
|
550
|
+
__wbg_length_b3416cf66a5452c8: function(arg0) {
|
|
551
|
+
const ret = arg0.length;
|
|
552
|
+
return ret;
|
|
553
|
+
},
|
|
554
|
+
__wbg_length_ea16607d7b61445b: function(arg0) {
|
|
555
|
+
const ret = arg0.length;
|
|
556
|
+
return ret;
|
|
557
|
+
},
|
|
558
|
+
__wbg_log_524eedafa26daa59: function(arg0) {
|
|
559
|
+
console.log(arg0);
|
|
560
|
+
},
|
|
561
|
+
__wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
|
|
562
|
+
const ret = arg0.msCrypto;
|
|
563
|
+
return ret;
|
|
564
|
+
},
|
|
565
|
+
__wbg_new_0837727332ac86ba: function() {
|
|
566
|
+
return handleError(function() {
|
|
567
|
+
const ret = new Headers();
|
|
568
|
+
return ret;
|
|
569
|
+
}, arguments);
|
|
570
|
+
},
|
|
571
|
+
__wbg_new_227d7c05414eb861: function() {
|
|
572
|
+
const ret = new Error();
|
|
573
|
+
return ret;
|
|
574
|
+
},
|
|
575
|
+
__wbg_new_5f486cdf45a04d78: function(arg0) {
|
|
576
|
+
const ret = new Uint8Array(arg0);
|
|
577
|
+
return ret;
|
|
578
|
+
},
|
|
579
|
+
__wbg_new_ab79df5bd7c26067: function() {
|
|
580
|
+
const ret = new Object();
|
|
581
|
+
return ret;
|
|
582
|
+
},
|
|
583
|
+
__wbg_new_d15cb560a6a0e5f0: function(arg0, arg1) {
|
|
584
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
585
|
+
return ret;
|
|
586
|
+
},
|
|
587
|
+
__wbg_new_from_slice_22da9388ac046e50: function(arg0, arg1) {
|
|
588
|
+
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
589
|
+
return ret;
|
|
590
|
+
},
|
|
591
|
+
__wbg_new_typed_aaaeaf29cf802876: function(arg0, arg1) {
|
|
592
|
+
try {
|
|
593
|
+
var state0 = { a: arg0, b: arg1 };
|
|
594
|
+
var cb0 = (arg02, arg12) => {
|
|
595
|
+
const a = state0.a;
|
|
596
|
+
state0.a = 0;
|
|
597
|
+
try {
|
|
598
|
+
return wasm_bindgen__convert__closures_____invoke__hb864778e5a95f086(a, state0.b, arg02, arg12);
|
|
599
|
+
} finally {
|
|
600
|
+
state0.a = a;
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
const ret = new Promise(cb0);
|
|
604
|
+
return ret;
|
|
605
|
+
} finally {
|
|
606
|
+
state0.a = state0.b = 0;
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
__wbg_new_with_byte_offset_and_length_b2ec5bf7b2f35743: function(arg0, arg1, arg2) {
|
|
610
|
+
const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
|
|
611
|
+
return ret;
|
|
612
|
+
},
|
|
613
|
+
__wbg_new_with_into_underlying_source_b45133df5ff75afa: function(arg0, arg1) {
|
|
614
|
+
const ret = new ReadableStream(IntoUnderlyingSource.__wrap(arg0), arg1);
|
|
615
|
+
return ret;
|
|
616
|
+
},
|
|
617
|
+
__wbg_new_with_length_3259a525196bd8cc: function(arg0) {
|
|
618
|
+
const ret = new Array(arg0 >>> 0);
|
|
619
|
+
return ret;
|
|
620
|
+
},
|
|
621
|
+
__wbg_new_with_length_825018a1616e9e55: function(arg0) {
|
|
622
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
623
|
+
return ret;
|
|
624
|
+
},
|
|
625
|
+
__wbg_new_with_opt_readable_stream_and_init_15b79ab5fa39d080: function() {
|
|
626
|
+
return handleError(function(arg0, arg1) {
|
|
627
|
+
const ret = new Response(arg0, arg1);
|
|
628
|
+
return ret;
|
|
629
|
+
}, arguments);
|
|
630
|
+
},
|
|
631
|
+
__wbg_next_11b99ee6237339e3: function() {
|
|
632
|
+
return handleError(function(arg0) {
|
|
633
|
+
const ret = arg0.next();
|
|
634
|
+
return ret;
|
|
635
|
+
}, arguments);
|
|
636
|
+
},
|
|
637
|
+
__wbg_next_e01a967809d1aa68: function(arg0) {
|
|
638
|
+
const ret = arg0.next;
|
|
639
|
+
return ret;
|
|
640
|
+
},
|
|
641
|
+
__wbg_node_84ea875411254db1: function(arg0) {
|
|
642
|
+
const ret = arg0.node;
|
|
643
|
+
return ret;
|
|
644
|
+
},
|
|
645
|
+
__wbg_now_16f0c993d5dd6c27: function() {
|
|
646
|
+
const ret = Date.now();
|
|
647
|
+
return ret;
|
|
648
|
+
},
|
|
649
|
+
__wbg_now_e7c6795a7f81e10f: function(arg0) {
|
|
650
|
+
const ret = arg0.now();
|
|
651
|
+
return ret;
|
|
652
|
+
},
|
|
653
|
+
__wbg_performance_3fcf6e32a7e1ed0a: function(arg0) {
|
|
654
|
+
const ret = arg0.performance;
|
|
655
|
+
return ret;
|
|
656
|
+
},
|
|
657
|
+
__wbg_process_44c7a14e11e9f69e: function(arg0) {
|
|
658
|
+
const ret = arg0.process;
|
|
659
|
+
return ret;
|
|
660
|
+
},
|
|
661
|
+
__wbg_prototypesetcall_d62e5099504357e6: function(arg0, arg1, arg2) {
|
|
662
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
663
|
+
},
|
|
664
|
+
__wbg_queueMicrotask_0c399741342fb10f: function(arg0) {
|
|
665
|
+
const ret = arg0.queueMicrotask;
|
|
666
|
+
return ret;
|
|
667
|
+
},
|
|
668
|
+
__wbg_queueMicrotask_a082d78ce798393e: function(arg0) {
|
|
669
|
+
queueMicrotask(arg0);
|
|
670
|
+
},
|
|
671
|
+
__wbg_randomFillSync_6c25eac9869eb53c: function() {
|
|
672
|
+
return handleError(function(arg0, arg1) {
|
|
673
|
+
arg0.randomFillSync(arg1);
|
|
674
|
+
}, arguments);
|
|
675
|
+
},
|
|
676
|
+
__wbg_require_b4edbdcf3e2a1ef0: function() {
|
|
677
|
+
return handleError(function() {
|
|
678
|
+
const ret = module.require;
|
|
679
|
+
return ret;
|
|
680
|
+
}, arguments);
|
|
681
|
+
},
|
|
682
|
+
__wbg_resolve_ae8d83246e5bcc12: function(arg0) {
|
|
683
|
+
const ret = Promise.resolve(arg0);
|
|
684
|
+
return ret;
|
|
685
|
+
},
|
|
686
|
+
__wbg_respond_e286ee502e7cf7e4: function() {
|
|
687
|
+
return handleError(function(arg0, arg1) {
|
|
688
|
+
arg0.respond(arg1 >>> 0);
|
|
689
|
+
}, arguments);
|
|
690
|
+
},
|
|
691
|
+
__wbg_setTimeout_ef24d2fc3ad97385: function() {
|
|
692
|
+
return handleError(function(arg0, arg1) {
|
|
693
|
+
const ret = setTimeout(arg0, arg1);
|
|
694
|
+
return ret;
|
|
695
|
+
}, arguments);
|
|
696
|
+
},
|
|
697
|
+
__wbg_set_282384002438957f: function(arg0, arg1, arg2) {
|
|
698
|
+
arg0[arg1 >>> 0] = arg2;
|
|
699
|
+
},
|
|
700
|
+
__wbg_set_7eaa4f96924fd6b3: function() {
|
|
701
|
+
return handleError(function(arg0, arg1, arg2) {
|
|
702
|
+
const ret = Reflect.set(arg0, arg1, arg2);
|
|
703
|
+
return ret;
|
|
704
|
+
}, arguments);
|
|
705
|
+
},
|
|
706
|
+
__wbg_set_8c0b3ffcf05d61c2: function(arg0, arg1, arg2) {
|
|
707
|
+
arg0.set(getArrayU8FromWasm0(arg1, arg2));
|
|
708
|
+
},
|
|
709
|
+
__wbg_set_9b44de9403b9716a: function() {
|
|
710
|
+
return handleError(function(arg0, arg1, arg2, arg3, arg4) {
|
|
711
|
+
const ret = arg0.set(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
|
|
712
|
+
return ret;
|
|
713
|
+
}, arguments);
|
|
714
|
+
},
|
|
715
|
+
__wbg_set_headers_bf56980ea1a65acb: function(arg0, arg1) {
|
|
716
|
+
arg0.headers = arg1;
|
|
717
|
+
},
|
|
718
|
+
__wbg_set_high_water_mark_1ac059fa0566c2fc: function(arg0, arg1) {
|
|
719
|
+
arg0.highWaterMark = arg1;
|
|
720
|
+
},
|
|
721
|
+
__wbg_set_status_b80d37d9d23276c4: function(arg0, arg1) {
|
|
722
|
+
arg0.status = arg1;
|
|
723
|
+
},
|
|
724
|
+
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
725
|
+
const ret = arg1.stack;
|
|
726
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
727
|
+
const len1 = WASM_VECTOR_LEN;
|
|
728
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
729
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
730
|
+
},
|
|
731
|
+
__wbg_static_accessor_GLOBAL_8adb955bd33fac2f: function() {
|
|
732
|
+
const ret = typeof global === "undefined" ? null : global;
|
|
733
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
734
|
+
},
|
|
735
|
+
__wbg_static_accessor_GLOBAL_THIS_ad356e0db91c7913: function() {
|
|
736
|
+
const ret = typeof globalThis === "undefined" ? null : globalThis;
|
|
737
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
738
|
+
},
|
|
739
|
+
__wbg_static_accessor_SELF_f207c857566db248: function() {
|
|
740
|
+
const ret = typeof self === "undefined" ? null : self;
|
|
741
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
742
|
+
},
|
|
743
|
+
__wbg_static_accessor_WINDOW_bb9f1ba69d61b386: function() {
|
|
744
|
+
const ret = typeof window === "undefined" ? null : window;
|
|
745
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
746
|
+
},
|
|
747
|
+
__wbg_subarray_a068d24e39478a8a: function(arg0, arg1, arg2) {
|
|
748
|
+
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
749
|
+
return ret;
|
|
750
|
+
},
|
|
751
|
+
__wbg_subtle_c060fa3eb5c6248d: function(arg0) {
|
|
752
|
+
const ret = arg0.subtle;
|
|
753
|
+
return ret;
|
|
754
|
+
},
|
|
755
|
+
__wbg_then_098abe61755d12f6: function(arg0, arg1) {
|
|
756
|
+
const ret = arg0.then(arg1);
|
|
757
|
+
return ret;
|
|
758
|
+
},
|
|
759
|
+
__wbg_then_9e335f6dd892bc11: function(arg0, arg1, arg2) {
|
|
760
|
+
const ret = arg0.then(arg1, arg2);
|
|
761
|
+
return ret;
|
|
762
|
+
},
|
|
763
|
+
__wbg_torclient_new: function(arg0) {
|
|
764
|
+
const ret = TorClient.__wrap(arg0);
|
|
765
|
+
return ret;
|
|
766
|
+
},
|
|
767
|
+
__wbg_tryLock_5d7357252b3473bd: function() {
|
|
768
|
+
return handleError(function(arg0) {
|
|
769
|
+
const ret = arg0.tryLock();
|
|
770
|
+
return ret;
|
|
771
|
+
}, arguments);
|
|
772
|
+
},
|
|
773
|
+
__wbg_unlock_2d843e9896897e90: function() {
|
|
774
|
+
return handleError(function(arg0) {
|
|
775
|
+
const ret = arg0.unlock();
|
|
776
|
+
return ret;
|
|
777
|
+
}, arguments);
|
|
778
|
+
},
|
|
779
|
+
__wbg_value_21fc78aab0322612: function(arg0) {
|
|
780
|
+
const ret = arg0.value;
|
|
781
|
+
return ret;
|
|
782
|
+
},
|
|
783
|
+
__wbg_versions_276b2795b1c6a219: function(arg0) {
|
|
784
|
+
const ret = arg0.versions;
|
|
785
|
+
return ret;
|
|
786
|
+
},
|
|
787
|
+
__wbg_view_f68a712e7315f8b2: function(arg0) {
|
|
788
|
+
const ret = arg0.view;
|
|
789
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
790
|
+
},
|
|
791
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
792
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h9b79478a56146cd2, wasm_bindgen__convert__closures_____invoke__h5c591e637e5094b1);
|
|
793
|
+
return ret;
|
|
794
|
+
},
|
|
795
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
796
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h4d8dd6cb42c8a695, wasm_bindgen__convert__closures_____invoke__h69c112f8841b438b);
|
|
797
|
+
return ret;
|
|
798
|
+
},
|
|
799
|
+
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
800
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h1e3ac41672e7b2ad, wasm_bindgen__convert__closures_____invoke__hc2bcdd2c6020290d);
|
|
801
|
+
return ret;
|
|
802
|
+
},
|
|
803
|
+
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
|
|
804
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
805
|
+
return ret;
|
|
806
|
+
},
|
|
807
|
+
__wbindgen_cast_0000000000000005: function(arg0, arg1) {
|
|
808
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
809
|
+
return ret;
|
|
810
|
+
},
|
|
811
|
+
__wbindgen_init_externref_table: function() {
|
|
812
|
+
const table = wasm.__wbindgen_externrefs;
|
|
813
|
+
const offset = table.grow(4);
|
|
814
|
+
table.set(0, void 0);
|
|
815
|
+
table.set(offset + 0, void 0);
|
|
816
|
+
table.set(offset + 1, null);
|
|
817
|
+
table.set(offset + 2, true);
|
|
818
|
+
table.set(offset + 3, false);
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
return {
|
|
822
|
+
__proto__: null,
|
|
823
|
+
"./tor_js_bg.js": import0
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
function wasm_bindgen__convert__closures_____invoke__h69c112f8841b438b(arg0, arg1) {
|
|
827
|
+
wasm.wasm_bindgen__convert__closures_____invoke__h69c112f8841b438b(arg0, arg1);
|
|
828
|
+
}
|
|
829
|
+
function wasm_bindgen__convert__closures_____invoke__h5c591e637e5094b1(arg0, arg1, arg2) {
|
|
830
|
+
wasm.wasm_bindgen__convert__closures_____invoke__h5c591e637e5094b1(arg0, arg1, arg2);
|
|
831
|
+
}
|
|
832
|
+
function wasm_bindgen__convert__closures_____invoke__hc2bcdd2c6020290d(arg0, arg1, arg2) {
|
|
833
|
+
const ret = wasm.wasm_bindgen__convert__closures_____invoke__hc2bcdd2c6020290d(arg0, arg1, arg2);
|
|
834
|
+
if (ret[1]) {
|
|
835
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
function wasm_bindgen__convert__closures_____invoke__hb864778e5a95f086(arg0, arg1, arg2, arg3) {
|
|
839
|
+
wasm.wasm_bindgen__convert__closures_____invoke__hb864778e5a95f086(arg0, arg1, arg2, arg3);
|
|
840
|
+
}
|
|
841
|
+
var __wbindgen_enum_ReadableStreamType = ["bytes"];
|
|
842
|
+
var IntoUnderlyingByteSourceFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
843
|
+
}, unregister: () => {
|
|
844
|
+
} } : new FinalizationRegistry((ptr) => wasm.__wbg_intounderlyingbytesource_free(ptr >>> 0, 1));
|
|
845
|
+
var IntoUnderlyingSinkFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
846
|
+
}, unregister: () => {
|
|
847
|
+
} } : new FinalizationRegistry((ptr) => wasm.__wbg_intounderlyingsink_free(ptr >>> 0, 1));
|
|
848
|
+
var IntoUnderlyingSourceFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
849
|
+
}, unregister: () => {
|
|
850
|
+
} } : new FinalizationRegistry((ptr) => wasm.__wbg_intounderlyingsource_free(ptr >>> 0, 1));
|
|
851
|
+
var TorClientFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
852
|
+
}, unregister: () => {
|
|
853
|
+
} } : new FinalizationRegistry((ptr) => wasm.__wbg_torclient_free(ptr >>> 0, 1));
|
|
854
|
+
var TorClientOptionsFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
855
|
+
}, unregister: () => {
|
|
856
|
+
} } : new FinalizationRegistry((ptr) => wasm.__wbg_torclientoptions_free(ptr >>> 0, 1));
|
|
857
|
+
function addToExternrefTable0(obj) {
|
|
858
|
+
const idx = wasm.__externref_table_alloc();
|
|
859
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
860
|
+
return idx;
|
|
861
|
+
}
|
|
862
|
+
function _assertClass(instance, klass) {
|
|
863
|
+
if (!(instance instanceof klass)) {
|
|
864
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
var CLOSURE_DTORS = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
868
|
+
}, unregister: () => {
|
|
869
|
+
} } : new FinalizationRegistry((state) => state.dtor(state.a, state.b));
|
|
870
|
+
function debugString(val) {
|
|
871
|
+
const type = typeof val;
|
|
872
|
+
if (type == "number" || type == "boolean" || val == null) {
|
|
873
|
+
return `${val}`;
|
|
874
|
+
}
|
|
875
|
+
if (type == "string") {
|
|
876
|
+
return `"${val}"`;
|
|
877
|
+
}
|
|
878
|
+
if (type == "symbol") {
|
|
879
|
+
const description = val.description;
|
|
880
|
+
if (description == null) {
|
|
881
|
+
return "Symbol";
|
|
882
|
+
} else {
|
|
883
|
+
return `Symbol(${description})`;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (type == "function") {
|
|
887
|
+
const name = val.name;
|
|
888
|
+
if (typeof name == "string" && name.length > 0) {
|
|
889
|
+
return `Function(${name})`;
|
|
890
|
+
} else {
|
|
891
|
+
return "Function";
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (Array.isArray(val)) {
|
|
895
|
+
const length = val.length;
|
|
896
|
+
let debug = "[";
|
|
897
|
+
if (length > 0) {
|
|
898
|
+
debug += debugString(val[0]);
|
|
899
|
+
}
|
|
900
|
+
for (let i = 1; i < length; i++) {
|
|
901
|
+
debug += ", " + debugString(val[i]);
|
|
902
|
+
}
|
|
903
|
+
debug += "]";
|
|
904
|
+
return debug;
|
|
905
|
+
}
|
|
906
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
907
|
+
let className;
|
|
908
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
909
|
+
className = builtInMatches[1];
|
|
910
|
+
} else {
|
|
911
|
+
return toString.call(val);
|
|
912
|
+
}
|
|
913
|
+
if (className == "Object") {
|
|
914
|
+
try {
|
|
915
|
+
return "Object(" + JSON.stringify(val) + ")";
|
|
916
|
+
} catch (_) {
|
|
917
|
+
return "Object";
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
if (val instanceof Error) {
|
|
921
|
+
return `${val.name}: ${val.message}
|
|
922
|
+
${val.stack}`;
|
|
923
|
+
}
|
|
924
|
+
return className;
|
|
925
|
+
}
|
|
926
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
927
|
+
ptr = ptr >>> 0;
|
|
928
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
929
|
+
}
|
|
930
|
+
var cachedDataViewMemory0 = null;
|
|
931
|
+
function getDataViewMemory0() {
|
|
932
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
|
|
933
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
934
|
+
}
|
|
935
|
+
return cachedDataViewMemory0;
|
|
936
|
+
}
|
|
937
|
+
function getStringFromWasm0(ptr, len) {
|
|
938
|
+
ptr = ptr >>> 0;
|
|
939
|
+
return decodeText(ptr, len);
|
|
940
|
+
}
|
|
941
|
+
var cachedUint8ArrayMemory0 = null;
|
|
942
|
+
function getUint8ArrayMemory0() {
|
|
943
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
944
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
945
|
+
}
|
|
946
|
+
return cachedUint8ArrayMemory0;
|
|
947
|
+
}
|
|
948
|
+
function handleError(f, args) {
|
|
949
|
+
try {
|
|
950
|
+
return f.apply(this, args);
|
|
951
|
+
} catch (e) {
|
|
952
|
+
const idx = addToExternrefTable0(e);
|
|
953
|
+
wasm.__wbindgen_exn_store(idx);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
function isLikeNone(x) {
|
|
957
|
+
return x === void 0 || x === null;
|
|
958
|
+
}
|
|
959
|
+
function makeMutClosure(arg0, arg1, dtor, f) {
|
|
960
|
+
const state = { a: arg0, b: arg1, cnt: 1, dtor };
|
|
961
|
+
const real = (...args) => {
|
|
962
|
+
state.cnt++;
|
|
963
|
+
const a = state.a;
|
|
964
|
+
state.a = 0;
|
|
965
|
+
try {
|
|
966
|
+
return f(a, state.b, ...args);
|
|
967
|
+
} finally {
|
|
968
|
+
state.a = a;
|
|
969
|
+
real._wbg_cb_unref();
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
real._wbg_cb_unref = () => {
|
|
973
|
+
if (--state.cnt === 0) {
|
|
974
|
+
state.dtor(state.a, state.b);
|
|
975
|
+
state.a = 0;
|
|
976
|
+
CLOSURE_DTORS.unregister(state);
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
CLOSURE_DTORS.register(real, state, state);
|
|
980
|
+
return real;
|
|
981
|
+
}
|
|
982
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
983
|
+
if (realloc === void 0) {
|
|
984
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
985
|
+
const ptr2 = malloc(buf.length, 1) >>> 0;
|
|
986
|
+
getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
|
|
987
|
+
WASM_VECTOR_LEN = buf.length;
|
|
988
|
+
return ptr2;
|
|
989
|
+
}
|
|
990
|
+
let len = arg.length;
|
|
991
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
992
|
+
const mem = getUint8ArrayMemory0();
|
|
993
|
+
let offset = 0;
|
|
994
|
+
for (; offset < len; offset++) {
|
|
995
|
+
const code = arg.charCodeAt(offset);
|
|
996
|
+
if (code > 127) break;
|
|
997
|
+
mem[ptr + offset] = code;
|
|
998
|
+
}
|
|
999
|
+
if (offset !== len) {
|
|
1000
|
+
if (offset !== 0) {
|
|
1001
|
+
arg = arg.slice(offset);
|
|
1002
|
+
}
|
|
1003
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
1004
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
1005
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
1006
|
+
offset += ret.written;
|
|
1007
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
1008
|
+
}
|
|
1009
|
+
WASM_VECTOR_LEN = offset;
|
|
1010
|
+
return ptr;
|
|
1011
|
+
}
|
|
1012
|
+
function takeFromExternrefTable0(idx) {
|
|
1013
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
1014
|
+
wasm.__externref_table_dealloc(idx);
|
|
1015
|
+
return value;
|
|
1016
|
+
}
|
|
1017
|
+
var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
1018
|
+
cachedTextDecoder.decode();
|
|
1019
|
+
var MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
1020
|
+
var numBytesDecoded = 0;
|
|
1021
|
+
function decodeText(ptr, len) {
|
|
1022
|
+
numBytesDecoded += len;
|
|
1023
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
1024
|
+
cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
1025
|
+
cachedTextDecoder.decode();
|
|
1026
|
+
numBytesDecoded = len;
|
|
1027
|
+
}
|
|
1028
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
1029
|
+
}
|
|
1030
|
+
var cachedTextEncoder = new TextEncoder();
|
|
1031
|
+
if (!("encodeInto" in cachedTextEncoder)) {
|
|
1032
|
+
cachedTextEncoder.encodeInto = function(arg, view) {
|
|
1033
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
1034
|
+
view.set(buf);
|
|
1035
|
+
return {
|
|
1036
|
+
read: arg.length,
|
|
1037
|
+
written: buf.length
|
|
1038
|
+
};
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
var WASM_VECTOR_LEN = 0;
|
|
1042
|
+
var wasmModule;
|
|
1043
|
+
var wasm;
|
|
1044
|
+
function __wbg_finalize_init(instance, module2) {
|
|
1045
|
+
wasm = instance.exports;
|
|
1046
|
+
wasmModule = module2;
|
|
1047
|
+
cachedDataViewMemory0 = null;
|
|
1048
|
+
cachedUint8ArrayMemory0 = null;
|
|
1049
|
+
wasm.__wbindgen_start();
|
|
1050
|
+
return wasm;
|
|
1051
|
+
}
|
|
1052
|
+
async function __wbg_load(module2, imports) {
|
|
1053
|
+
if (typeof Response === "function" && module2 instanceof Response) {
|
|
1054
|
+
if (typeof WebAssembly.instantiateStreaming === "function") {
|
|
1055
|
+
try {
|
|
1056
|
+
return await WebAssembly.instantiateStreaming(module2, imports);
|
|
1057
|
+
} catch (e) {
|
|
1058
|
+
const validResponse = module2.ok && expectedResponseType(module2.type);
|
|
1059
|
+
if (validResponse && module2.headers.get("Content-Type") !== "application/wasm") {
|
|
1060
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
1061
|
+
} else {
|
|
1062
|
+
throw e;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
const bytes = await module2.arrayBuffer();
|
|
1067
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
1068
|
+
} else {
|
|
1069
|
+
const instance = await WebAssembly.instantiate(module2, imports);
|
|
1070
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
1071
|
+
return { instance, module: module2 };
|
|
1072
|
+
} else {
|
|
1073
|
+
return instance;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
function expectedResponseType(type) {
|
|
1077
|
+
switch (type) {
|
|
1078
|
+
case "basic":
|
|
1079
|
+
case "cors":
|
|
1080
|
+
case "default":
|
|
1081
|
+
return true;
|
|
1082
|
+
}
|
|
1083
|
+
return false;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
async function __wbg_init(module_or_path) {
|
|
1087
|
+
if (wasm !== void 0) return wasm;
|
|
1088
|
+
if (module_or_path !== void 0) {
|
|
1089
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
1090
|
+
({ module_or_path } = module_or_path);
|
|
1091
|
+
} else {
|
|
1092
|
+
console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
if (module_or_path === void 0) {
|
|
1096
|
+
module_or_path = new URL("tor_js_bg.wasm", import.meta.url);
|
|
1097
|
+
}
|
|
1098
|
+
const imports = __wbg_get_imports();
|
|
1099
|
+
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
|
|
1100
|
+
module_or_path = fetch(module_or_path);
|
|
1101
|
+
}
|
|
1102
|
+
const { instance, module: module2 } = await __wbg_load(await module_or_path, imports);
|
|
1103
|
+
return __wbg_finalize_init(instance, module2);
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
// src/wasm.ts
|
|
1107
|
+
var LEVEL_ORDER = ["trace", "debug", "info", "warn", "error"];
|
|
1108
|
+
function levelIndex(level) {
|
|
1109
|
+
const idx = LEVEL_ORDER.indexOf(level);
|
|
1110
|
+
return idx === -1 ? 1 : idx;
|
|
1111
|
+
}
|
|
1112
|
+
var logListeners = /* @__PURE__ */ new Map();
|
|
1113
|
+
function syncWasmLogLevel() {
|
|
1114
|
+
let broadestIdx = LEVEL_ORDER.length - 1;
|
|
1115
|
+
for (const listener of logListeners.values()) {
|
|
1116
|
+
if (listener.levelIdx < broadestIdx) {
|
|
1117
|
+
broadestIdx = listener.levelIdx;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
setLogLevel(LEVEL_ORDER[broadestIdx]);
|
|
1121
|
+
}
|
|
1122
|
+
function addLogListener(cb, level = "debug") {
|
|
1123
|
+
logListeners.set(cb, { callback: cb, levelIdx: levelIndex(level) });
|
|
1124
|
+
syncWasmLogLevel();
|
|
1125
|
+
return () => {
|
|
1126
|
+
logListeners.delete(cb);
|
|
1127
|
+
if (logListeners.size > 0) {
|
|
1128
|
+
syncWasmLogLevel();
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
function setListenerLevel(cb, level) {
|
|
1133
|
+
const listener = logListeners.get(cb);
|
|
1134
|
+
if (listener) {
|
|
1135
|
+
listener.levelIdx = levelIndex(level);
|
|
1136
|
+
syncWasmLogLevel();
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
var initPromise = null;
|
|
1140
|
+
var customWasmUrl;
|
|
1141
|
+
var wasmSourceProvider;
|
|
1142
|
+
function setWasmUrl(url) {
|
|
1143
|
+
if (initPromise) {
|
|
1144
|
+
throw new Error("setWasmUrl() must be called before any TorClient is created");
|
|
1145
|
+
}
|
|
1146
|
+
customWasmUrl = url;
|
|
1147
|
+
}
|
|
1148
|
+
function setWasmSourceProvider(provider) {
|
|
1149
|
+
if (initPromise) {
|
|
1150
|
+
throw new Error("setWasmSourceProvider() must be called before any TorClient is created");
|
|
1151
|
+
}
|
|
1152
|
+
wasmSourceProvider = provider;
|
|
1153
|
+
}
|
|
1154
|
+
async function ensureWasmInitialized() {
|
|
1155
|
+
if (initPromise) return initPromise;
|
|
1156
|
+
initPromise = doInit();
|
|
1157
|
+
return initPromise;
|
|
1158
|
+
}
|
|
1159
|
+
async function doInit() {
|
|
1160
|
+
if (customWasmUrl) {
|
|
1161
|
+
await __wbg_init({ module_or_path: customWasmUrl });
|
|
1162
|
+
} else if (wasmSourceProvider) {
|
|
1163
|
+
await __wbg_init({ module_or_path: await wasmSourceProvider() });
|
|
1164
|
+
} else {
|
|
1165
|
+
throw new Error(
|
|
1166
|
+
"No WASM source configured. Import from a specific entry point (tor-js/wasm-base64, tor-js/wasm-cdn, or tor-js/wasm-file) or call setWasmUrl() before creating a TorClient."
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
1169
|
+
init();
|
|
1170
|
+
setLogCallback((level, target, message) => {
|
|
1171
|
+
const lvl = levelIndex(level);
|
|
1172
|
+
for (const listener of logListeners.values()) {
|
|
1173
|
+
if (lvl >= listener.levelIdx) {
|
|
1174
|
+
listener.callback(level, target, message);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// src/Log.ts
|
|
1181
|
+
var Log = class _Log {
|
|
1182
|
+
rawLog;
|
|
1183
|
+
parentStartTime;
|
|
1184
|
+
namePrefix;
|
|
1185
|
+
constructor(params = {}) {
|
|
1186
|
+
this.parentStartTime = params.parentStartTime ?? Date.now();
|
|
1187
|
+
this.namePrefix = params.namePrefix ?? "";
|
|
1188
|
+
this.rawLog = params.rawLog ?? this.defaultRawLog.bind(this);
|
|
1189
|
+
}
|
|
1190
|
+
child(name) {
|
|
1191
|
+
const newPrefix = this.namePrefix ? `${this.namePrefix}.${name}` : name;
|
|
1192
|
+
return new _Log({
|
|
1193
|
+
rawLog: this.rawLog,
|
|
1194
|
+
parentStartTime: this.parentStartTime,
|
|
1195
|
+
namePrefix: newPrefix
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
trace(...args) {
|
|
1199
|
+
this.log("trace", ...args);
|
|
1200
|
+
}
|
|
1201
|
+
debug(...args) {
|
|
1202
|
+
this.log("debug", ...args);
|
|
1203
|
+
}
|
|
1204
|
+
info(...args) {
|
|
1205
|
+
this.log("info", ...args);
|
|
1206
|
+
}
|
|
1207
|
+
warn(...args) {
|
|
1208
|
+
this.log("warn", ...args);
|
|
1209
|
+
}
|
|
1210
|
+
error(...args) {
|
|
1211
|
+
this.log("error", ...args);
|
|
1212
|
+
}
|
|
1213
|
+
/** @internal Create a callback for WASM setLogCallback */
|
|
1214
|
+
_makeWasmCallback() {
|
|
1215
|
+
const levels = /* @__PURE__ */ new Set(["trace", "debug", "info", "warn", "error"]);
|
|
1216
|
+
return (level, target, message) => {
|
|
1217
|
+
if (!levels.has(level)) {
|
|
1218
|
+
this.log("error", `unexpected log level from WASM: ${JSON.stringify(level)}`);
|
|
1219
|
+
level = "debug";
|
|
1220
|
+
}
|
|
1221
|
+
this.child(target).log(level, message);
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
log(level, ...args) {
|
|
1225
|
+
const elapsed = Date.now() - this.parentStartTime;
|
|
1226
|
+
const timestamp = formatTimestamp(elapsed);
|
|
1227
|
+
if (this.namePrefix) {
|
|
1228
|
+
this.rawLog(level, `[${timestamp}]`, `[${this.namePrefix}]`, ...args);
|
|
1229
|
+
} else {
|
|
1230
|
+
this.rawLog(level, `[${timestamp}]`, ...args);
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
defaultRawLog(level, ...args) {
|
|
1234
|
+
console[level](...args);
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
function formatTimestamp(elapsedMs) {
|
|
1238
|
+
const totalSeconds = Math.floor(elapsedMs / 1e3);
|
|
1239
|
+
const milliseconds = elapsedMs % 1e3;
|
|
1240
|
+
const ms = String(milliseconds).padStart(3, "0");
|
|
1241
|
+
const days = Math.floor(totalSeconds / 86400);
|
|
1242
|
+
const hours = Math.floor(totalSeconds % 86400 / 3600);
|
|
1243
|
+
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
1244
|
+
const seconds = totalSeconds % 60;
|
|
1245
|
+
if (days > 0) {
|
|
1246
|
+
return `${days}d ${p2(hours)}:${p2(minutes)}:${p2(seconds)}.${ms}`;
|
|
1247
|
+
}
|
|
1248
|
+
if (hours > 0) {
|
|
1249
|
+
return `${p2(hours)}:${p2(minutes)}:${p2(seconds)}.${ms}`;
|
|
1250
|
+
}
|
|
1251
|
+
if (minutes > 0) {
|
|
1252
|
+
return `${p2(minutes)}:${p2(seconds)}.${ms}`;
|
|
1253
|
+
}
|
|
1254
|
+
return `${p2(seconds)}.${ms}`;
|
|
1255
|
+
}
|
|
1256
|
+
function p2(n) {
|
|
1257
|
+
return String(n).padStart(2, "0");
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
// src/storage/index.ts
|
|
1261
|
+
var storage_exports = {};
|
|
1262
|
+
__export(storage_exports, {
|
|
1263
|
+
FilesystemStorage: () => FilesystemStorage,
|
|
1264
|
+
IndexedDBStorage: () => IndexedDBStorage,
|
|
1265
|
+
MemoryStorage: () => MemoryStorage,
|
|
1266
|
+
addLocking: () => addLocking,
|
|
1267
|
+
createAutoStorage: () => createAutoStorage
|
|
1268
|
+
});
|
|
1269
|
+
|
|
1270
|
+
// src/storage/memory.ts
|
|
1271
|
+
var MemoryStorage = class {
|
|
1272
|
+
data = /* @__PURE__ */ new Map();
|
|
1273
|
+
locked = false;
|
|
1274
|
+
async get(key) {
|
|
1275
|
+
return this.data.get(key) ?? null;
|
|
1276
|
+
}
|
|
1277
|
+
async set(key, value) {
|
|
1278
|
+
this.data.set(key, value);
|
|
1279
|
+
}
|
|
1280
|
+
async delete(key) {
|
|
1281
|
+
this.data.delete(key);
|
|
1282
|
+
}
|
|
1283
|
+
async keys(prefix) {
|
|
1284
|
+
return [...this.data.keys()].filter((k) => k.startsWith(prefix)).sort();
|
|
1285
|
+
}
|
|
1286
|
+
async getAll(prefix) {
|
|
1287
|
+
const result = [];
|
|
1288
|
+
for (const [key, value] of this.data) {
|
|
1289
|
+
if (key.startsWith(prefix)) {
|
|
1290
|
+
result.push([key, value]);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
return result;
|
|
1294
|
+
}
|
|
1295
|
+
async tryLock() {
|
|
1296
|
+
if (this.locked) return false;
|
|
1297
|
+
this.locked = true;
|
|
1298
|
+
return true;
|
|
1299
|
+
}
|
|
1300
|
+
async unlock() {
|
|
1301
|
+
this.locked = false;
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
|
|
1305
|
+
// src/storage/indexeddb.ts
|
|
1306
|
+
var IndexedDBStorage = class {
|
|
1307
|
+
dbName;
|
|
1308
|
+
storeName = "keyvalue";
|
|
1309
|
+
dbPromise = null;
|
|
1310
|
+
constructor(name = "tor-js") {
|
|
1311
|
+
this.dbName = name;
|
|
1312
|
+
}
|
|
1313
|
+
getDB() {
|
|
1314
|
+
if (!this.dbPromise) {
|
|
1315
|
+
this.dbPromise = new Promise((resolve, reject) => {
|
|
1316
|
+
const request = indexedDB.open(this.dbName, 1);
|
|
1317
|
+
request.onerror = () => reject(request.error);
|
|
1318
|
+
request.onsuccess = () => resolve(request.result);
|
|
1319
|
+
request.onupgradeneeded = (event) => {
|
|
1320
|
+
const db = event.target.result;
|
|
1321
|
+
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
1322
|
+
db.createObjectStore(this.storeName);
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
return this.dbPromise;
|
|
1328
|
+
}
|
|
1329
|
+
async get(key) {
|
|
1330
|
+
const db = await this.getDB();
|
|
1331
|
+
return new Promise((resolve, reject) => {
|
|
1332
|
+
const tx = db.transaction(this.storeName, "readonly");
|
|
1333
|
+
const store = tx.objectStore(this.storeName);
|
|
1334
|
+
const request = store.get(key);
|
|
1335
|
+
request.onerror = () => reject(request.error);
|
|
1336
|
+
request.onsuccess = () => {
|
|
1337
|
+
resolve(request.result === void 0 ? null : request.result);
|
|
1338
|
+
};
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
async set(key, value) {
|
|
1342
|
+
const db = await this.getDB();
|
|
1343
|
+
return new Promise((resolve, reject) => {
|
|
1344
|
+
const tx = db.transaction(this.storeName, "readwrite");
|
|
1345
|
+
const store = tx.objectStore(this.storeName);
|
|
1346
|
+
const request = store.put(value, key);
|
|
1347
|
+
request.onerror = () => reject(request.error);
|
|
1348
|
+
request.onsuccess = () => resolve();
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
async delete(key) {
|
|
1352
|
+
const db = await this.getDB();
|
|
1353
|
+
return new Promise((resolve, reject) => {
|
|
1354
|
+
const tx = db.transaction(this.storeName, "readwrite");
|
|
1355
|
+
const store = tx.objectStore(this.storeName);
|
|
1356
|
+
const request = store.delete(key);
|
|
1357
|
+
request.onerror = () => reject(request.error);
|
|
1358
|
+
request.onsuccess = () => resolve();
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
async keys(prefix) {
|
|
1362
|
+
const db = await this.getDB();
|
|
1363
|
+
return new Promise((resolve, reject) => {
|
|
1364
|
+
const tx = db.transaction(this.storeName, "readonly");
|
|
1365
|
+
const store = tx.objectStore(this.storeName);
|
|
1366
|
+
const request = store.getAllKeys();
|
|
1367
|
+
request.onerror = () => reject(request.error);
|
|
1368
|
+
request.onsuccess = () => {
|
|
1369
|
+
const allKeys = request.result;
|
|
1370
|
+
resolve(allKeys.filter((k) => k.startsWith(prefix)).sort());
|
|
1371
|
+
};
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
async getAll(prefix) {
|
|
1375
|
+
const db = await this.getDB();
|
|
1376
|
+
return new Promise((resolve, reject) => {
|
|
1377
|
+
const tx = db.transaction(this.storeName, "readonly");
|
|
1378
|
+
const store = tx.objectStore(this.storeName);
|
|
1379
|
+
const keysReq = store.getAllKeys();
|
|
1380
|
+
const valsReq = store.getAll();
|
|
1381
|
+
tx.onerror = () => reject(tx.error);
|
|
1382
|
+
tx.oncomplete = () => {
|
|
1383
|
+
const keys = keysReq.result;
|
|
1384
|
+
const vals = valsReq.result;
|
|
1385
|
+
const result = [];
|
|
1386
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1387
|
+
if (keys[i].startsWith(prefix)) {
|
|
1388
|
+
result.push([keys[i], vals[i]]);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
resolve(result);
|
|
1392
|
+
};
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
|
|
1397
|
+
// src/storage/node-deps.ts
|
|
1398
|
+
var promise;
|
|
1399
|
+
function getNodeDeps() {
|
|
1400
|
+
if (!promise) {
|
|
1401
|
+
promise = (async () => {
|
|
1402
|
+
const [fs, fsSync, os, path] = await Promise.all([
|
|
1403
|
+
import("fs/promises").then((m) => m.default ?? m),
|
|
1404
|
+
import("fs").then((m) => m.default ?? m),
|
|
1405
|
+
import("os").then((m) => m.default ?? m),
|
|
1406
|
+
import("path").then((m) => m.default ?? m)
|
|
1407
|
+
]);
|
|
1408
|
+
return { fs, fsSync, os, path };
|
|
1409
|
+
})();
|
|
1410
|
+
}
|
|
1411
|
+
return promise;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
// src/storage/filesystem.ts
|
|
1415
|
+
function isNodeError(err) {
|
|
1416
|
+
return err instanceof Error && "code" in err;
|
|
1417
|
+
}
|
|
1418
|
+
function mangleKey(key) {
|
|
1419
|
+
let result = "";
|
|
1420
|
+
for (let i = 0; i < key.length; i++) {
|
|
1421
|
+
const code = key.charCodeAt(i);
|
|
1422
|
+
if (code >= 97 && code <= 122 || // a-z
|
|
1423
|
+
code >= 65 && code <= 90 || // A-Z
|
|
1424
|
+
code >= 48 && code <= 57) {
|
|
1425
|
+
result += key[i];
|
|
1426
|
+
} else if (code <= 255) {
|
|
1427
|
+
result += "_" + code.toString(16).padStart(2, "0") + "_";
|
|
1428
|
+
} else {
|
|
1429
|
+
result += "_" + code.toString(16).padStart(4, "0") + "_";
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
return result;
|
|
1433
|
+
}
|
|
1434
|
+
function unmangleKey(filename) {
|
|
1435
|
+
let result = "";
|
|
1436
|
+
let i = 0;
|
|
1437
|
+
while (i < filename.length) {
|
|
1438
|
+
if (filename[i] === "_") {
|
|
1439
|
+
if (i + 5 < filename.length && filename[i + 5] === "_") {
|
|
1440
|
+
const hex = filename.slice(i + 1, i + 5);
|
|
1441
|
+
if (/^[0-9a-f]{4}$/i.test(hex)) {
|
|
1442
|
+
result += String.fromCharCode(parseInt(hex, 16));
|
|
1443
|
+
i += 6;
|
|
1444
|
+
continue;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
if (i + 3 < filename.length && filename[i + 3] === "_") {
|
|
1448
|
+
const hex = filename.slice(i + 1, i + 3);
|
|
1449
|
+
if (/^[0-9a-f]{2}$/i.test(hex)) {
|
|
1450
|
+
result += String.fromCharCode(parseInt(hex, 16));
|
|
1451
|
+
i += 4;
|
|
1452
|
+
continue;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
result += "_";
|
|
1456
|
+
i++;
|
|
1457
|
+
} else {
|
|
1458
|
+
result += filename[i];
|
|
1459
|
+
i++;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
return result;
|
|
1463
|
+
}
|
|
1464
|
+
var FilesystemStorage = class _FilesystemStorage {
|
|
1465
|
+
dirPath;
|
|
1466
|
+
name;
|
|
1467
|
+
resolvedDirPath = null;
|
|
1468
|
+
initialized = false;
|
|
1469
|
+
constructor(dirPath) {
|
|
1470
|
+
this.dirPath = dirPath;
|
|
1471
|
+
this.name = null;
|
|
1472
|
+
}
|
|
1473
|
+
static localShare(name) {
|
|
1474
|
+
const s = new _FilesystemStorage("");
|
|
1475
|
+
s.dirPath = null;
|
|
1476
|
+
s.name = name;
|
|
1477
|
+
return s;
|
|
1478
|
+
}
|
|
1479
|
+
async resolvedDir() {
|
|
1480
|
+
if (!this.resolvedDirPath) {
|
|
1481
|
+
if (this.dirPath) {
|
|
1482
|
+
this.resolvedDirPath = this.dirPath;
|
|
1483
|
+
} else {
|
|
1484
|
+
const { os, path } = await getNodeDeps();
|
|
1485
|
+
this.resolvedDirPath = path.join(os.homedir(), ".local", "share", this.name);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
return this.resolvedDirPath;
|
|
1489
|
+
}
|
|
1490
|
+
async ensureDir() {
|
|
1491
|
+
if (!this.initialized) {
|
|
1492
|
+
const { fs } = await getNodeDeps();
|
|
1493
|
+
await fs.mkdir(await this.resolvedDir(), { recursive: true });
|
|
1494
|
+
this.initialized = true;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
async filePath(key) {
|
|
1498
|
+
const { path } = await getNodeDeps();
|
|
1499
|
+
return path.join(await this.resolvedDir(), mangleKey(key));
|
|
1500
|
+
}
|
|
1501
|
+
async get(key) {
|
|
1502
|
+
const { fs } = await getNodeDeps();
|
|
1503
|
+
await this.ensureDir();
|
|
1504
|
+
try {
|
|
1505
|
+
return await fs.readFile(await this.filePath(key), "utf-8");
|
|
1506
|
+
} catch (err) {
|
|
1507
|
+
if (isNodeError(err) && err.code === "ENOENT") return null;
|
|
1508
|
+
throw err;
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
async set(key, value) {
|
|
1512
|
+
const { fs } = await getNodeDeps();
|
|
1513
|
+
await this.ensureDir();
|
|
1514
|
+
await fs.writeFile(await this.filePath(key), value, "utf-8");
|
|
1515
|
+
}
|
|
1516
|
+
async delete(key) {
|
|
1517
|
+
const { fs } = await getNodeDeps();
|
|
1518
|
+
await this.ensureDir();
|
|
1519
|
+
try {
|
|
1520
|
+
await fs.unlink(await this.filePath(key));
|
|
1521
|
+
} catch (err) {
|
|
1522
|
+
if (isNodeError(err) && err.code === "ENOENT") return;
|
|
1523
|
+
throw err;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
async keys(prefix) {
|
|
1527
|
+
const { fs } = await getNodeDeps();
|
|
1528
|
+
await this.ensureDir();
|
|
1529
|
+
try {
|
|
1530
|
+
const files = await fs.readdir(await this.resolvedDir());
|
|
1531
|
+
return files.map(unmangleKey).filter((k) => k.startsWith(prefix)).sort();
|
|
1532
|
+
} catch (err) {
|
|
1533
|
+
if (isNodeError(err) && err.code === "ENOENT") return [];
|
|
1534
|
+
throw err;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
async getAll(prefix) {
|
|
1538
|
+
const { fs } = await getNodeDeps();
|
|
1539
|
+
await this.ensureDir();
|
|
1540
|
+
try {
|
|
1541
|
+
const files = await fs.readdir(await this.resolvedDir());
|
|
1542
|
+
const keys = files.map(unmangleKey).filter((k) => k.startsWith(prefix));
|
|
1543
|
+
const entries = await Promise.all(
|
|
1544
|
+
keys.map(async (key) => {
|
|
1545
|
+
const value = await this.get(key);
|
|
1546
|
+
return value !== null ? [key, value] : null;
|
|
1547
|
+
})
|
|
1548
|
+
);
|
|
1549
|
+
return entries.filter((e) => e !== null);
|
|
1550
|
+
} catch (err) {
|
|
1551
|
+
if (isNodeError(err) && err.code === "ENOENT") return [];
|
|
1552
|
+
throw err;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
// src/storage/locking.ts
|
|
1558
|
+
function isNodeError2(err) {
|
|
1559
|
+
return err instanceof Error && "code" in err;
|
|
1560
|
+
}
|
|
1561
|
+
function addLocking(inner, name) {
|
|
1562
|
+
let hasRealLock = false;
|
|
1563
|
+
let overlay = null;
|
|
1564
|
+
let releaseLock;
|
|
1565
|
+
let lockRequestDone;
|
|
1566
|
+
let lockPath = null;
|
|
1567
|
+
let exitHandler = null;
|
|
1568
|
+
let heartbeatTimer = null;
|
|
1569
|
+
const STALE_MS = 3e4;
|
|
1570
|
+
const HEARTBEAT_MS = 1e4;
|
|
1571
|
+
async function tryAcquireReal() {
|
|
1572
|
+
if (typeof navigator !== "undefined" && navigator.locks) {
|
|
1573
|
+
let resolveAcquired;
|
|
1574
|
+
const acquired = new Promise((r) => {
|
|
1575
|
+
resolveAcquired = r;
|
|
1576
|
+
});
|
|
1577
|
+
lockRequestDone = navigator.locks.request(
|
|
1578
|
+
`tor-js:${name}`,
|
|
1579
|
+
{ ifAvailable: true },
|
|
1580
|
+
(lock) => {
|
|
1581
|
+
if (lock) {
|
|
1582
|
+
resolveAcquired(true);
|
|
1583
|
+
return new Promise((r) => {
|
|
1584
|
+
releaseLock = r;
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
resolveAcquired(false);
|
|
1588
|
+
}
|
|
1589
|
+
);
|
|
1590
|
+
return acquired;
|
|
1591
|
+
}
|
|
1592
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
1593
|
+
try {
|
|
1594
|
+
const { fs, fsSync, path, os } = await getNodeDeps();
|
|
1595
|
+
const dir = path.join(os.homedir(), ".local", "share", name);
|
|
1596
|
+
await fs.mkdir(dir, { recursive: true });
|
|
1597
|
+
const lp = path.join(dir, ".lock");
|
|
1598
|
+
try {
|
|
1599
|
+
await fs.writeFile(lp, `${process.pid}`, { flag: "wx" });
|
|
1600
|
+
} catch (err) {
|
|
1601
|
+
if (!isNodeError2(err) || err.code !== "EEXIST") throw err;
|
|
1602
|
+
const stat = await fs.stat(lp);
|
|
1603
|
+
if (Date.now() - stat.mtimeMs < STALE_MS) return false;
|
|
1604
|
+
await fs.writeFile(lp, `${process.pid}`);
|
|
1605
|
+
}
|
|
1606
|
+
lockPath = lp;
|
|
1607
|
+
heartbeatTimer = setInterval(async () => {
|
|
1608
|
+
try {
|
|
1609
|
+
const now = /* @__PURE__ */ new Date();
|
|
1610
|
+
await fs.utimes(lp, now, now);
|
|
1611
|
+
} catch {
|
|
1612
|
+
}
|
|
1613
|
+
}, HEARTBEAT_MS);
|
|
1614
|
+
if (heartbeatTimer.unref) heartbeatTimer.unref();
|
|
1615
|
+
exitHandler = () => {
|
|
1616
|
+
try {
|
|
1617
|
+
fsSync.unlinkSync(lp);
|
|
1618
|
+
} catch {
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
process.on("exit", exitHandler);
|
|
1622
|
+
return true;
|
|
1623
|
+
} catch (err) {
|
|
1624
|
+
return false;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
throw new Error("Failed to detect suitable locking mechanism");
|
|
1628
|
+
}
|
|
1629
|
+
async function releaseReal() {
|
|
1630
|
+
if (releaseLock) {
|
|
1631
|
+
releaseLock();
|
|
1632
|
+
releaseLock = void 0;
|
|
1633
|
+
await lockRequestDone;
|
|
1634
|
+
lockRequestDone = void 0;
|
|
1635
|
+
}
|
|
1636
|
+
if (heartbeatTimer) {
|
|
1637
|
+
clearInterval(heartbeatTimer);
|
|
1638
|
+
heartbeatTimer = null;
|
|
1639
|
+
}
|
|
1640
|
+
if (lockPath) {
|
|
1641
|
+
const { fs } = await getNodeDeps();
|
|
1642
|
+
try {
|
|
1643
|
+
await fs.unlink(lockPath);
|
|
1644
|
+
} catch (err) {
|
|
1645
|
+
if (!isNodeError2(err) || err.code !== "ENOENT") throw err;
|
|
1646
|
+
}
|
|
1647
|
+
lockPath = null;
|
|
1648
|
+
}
|
|
1649
|
+
if (exitHandler) {
|
|
1650
|
+
process.removeListener("exit", exitHandler);
|
|
1651
|
+
exitHandler = null;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return {
|
|
1655
|
+
async get(key) {
|
|
1656
|
+
if (overlay?.has(key)) return overlay.get(key);
|
|
1657
|
+
return inner.get(key);
|
|
1658
|
+
},
|
|
1659
|
+
async set(key, value) {
|
|
1660
|
+
if (overlay) {
|
|
1661
|
+
overlay.set(key, value);
|
|
1662
|
+
return;
|
|
1663
|
+
}
|
|
1664
|
+
return inner.set(key, value);
|
|
1665
|
+
},
|
|
1666
|
+
async delete(key) {
|
|
1667
|
+
if (overlay) {
|
|
1668
|
+
overlay.set(key, null);
|
|
1669
|
+
return;
|
|
1670
|
+
}
|
|
1671
|
+
return inner.delete(key);
|
|
1672
|
+
},
|
|
1673
|
+
async keys(prefix) {
|
|
1674
|
+
const base = await inner.keys(prefix);
|
|
1675
|
+
if (!overlay) return base;
|
|
1676
|
+
const result = new Set(base);
|
|
1677
|
+
for (const [k, v] of overlay) {
|
|
1678
|
+
if (!k.startsWith(prefix)) continue;
|
|
1679
|
+
if (v !== null) result.add(k);
|
|
1680
|
+
else result.delete(k);
|
|
1681
|
+
}
|
|
1682
|
+
return [...result].sort();
|
|
1683
|
+
},
|
|
1684
|
+
async getAll(prefix) {
|
|
1685
|
+
const base = await inner.getAll(prefix);
|
|
1686
|
+
if (!overlay) return base;
|
|
1687
|
+
const merged = new Map(base);
|
|
1688
|
+
for (const [k, v] of overlay) {
|
|
1689
|
+
if (!k.startsWith(prefix)) continue;
|
|
1690
|
+
if (v !== null) merged.set(k, v);
|
|
1691
|
+
else merged.delete(k);
|
|
1692
|
+
}
|
|
1693
|
+
return [...merged.entries()];
|
|
1694
|
+
},
|
|
1695
|
+
async tryLock() {
|
|
1696
|
+
if (hasRealLock) return false;
|
|
1697
|
+
const acquired = await tryAcquireReal();
|
|
1698
|
+
hasRealLock = acquired;
|
|
1699
|
+
overlay = acquired ? null : overlay ?? /* @__PURE__ */ new Map();
|
|
1700
|
+
return true;
|
|
1701
|
+
},
|
|
1702
|
+
async unlock() {
|
|
1703
|
+
await releaseReal();
|
|
1704
|
+
hasRealLock = false;
|
|
1705
|
+
overlay = null;
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
// src/storage/index.ts
|
|
1711
|
+
function createAutoStorage(name = "tor-js") {
|
|
1712
|
+
if (typeof globalThis !== "undefined" && typeof globalThis.indexedDB !== "undefined") {
|
|
1713
|
+
return addLocking(new IndexedDBStorage(name), name);
|
|
1714
|
+
}
|
|
1715
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
1716
|
+
return addLocking(FilesystemStorage.localShare(name), name);
|
|
1717
|
+
}
|
|
1718
|
+
throw new Error(
|
|
1719
|
+
"No persistent storage available: need IndexedDB (browser) or filesystem (Node.js)"
|
|
1720
|
+
);
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
// src/socketProvider.ts
|
|
1724
|
+
var HAS_DENO = typeof globalThis.Deno !== "undefined";
|
|
1725
|
+
var HAS_NODE = typeof globalThis.process?.versions?.node !== "undefined";
|
|
1726
|
+
var HAS_RTC = typeof globalThis.RTCPeerConnection !== "undefined";
|
|
1727
|
+
var HAS_WS = typeof globalThis.WebSocket !== "undefined" || HAS_DENO || HAS_NODE;
|
|
1728
|
+
function defaultStrategies(hasUrl) {
|
|
1729
|
+
const s = [];
|
|
1730
|
+
if (HAS_DENO || HAS_NODE) s.push("direct");
|
|
1731
|
+
if (hasUrl && HAS_RTC) s.push("webrtc");
|
|
1732
|
+
if (hasUrl && HAS_WS) s.push("websocket");
|
|
1733
|
+
return s;
|
|
1734
|
+
}
|
|
1735
|
+
var ArtiSocket = class _ArtiSocket {
|
|
1736
|
+
#send;
|
|
1737
|
+
#close;
|
|
1738
|
+
#closed = false;
|
|
1739
|
+
#onclose = null;
|
|
1740
|
+
/** Set by transport on error, before onclose fires. */
|
|
1741
|
+
_error = null;
|
|
1742
|
+
/** Receive callback — transport fires this with each incoming chunk. */
|
|
1743
|
+
onmessage = null;
|
|
1744
|
+
constructor(send, close) {
|
|
1745
|
+
this.#send = send;
|
|
1746
|
+
this.#close = close;
|
|
1747
|
+
}
|
|
1748
|
+
/** Setter that fires immediately if close already happened. */
|
|
1749
|
+
set onclose(fn) {
|
|
1750
|
+
this.#onclose = fn;
|
|
1751
|
+
if (this.#closed && fn) queueMicrotask(() => fn());
|
|
1752
|
+
}
|
|
1753
|
+
get onclose() {
|
|
1754
|
+
return this.#onclose;
|
|
1755
|
+
}
|
|
1756
|
+
/** @internal — called by transport wrappers when the underlying connection closes. */
|
|
1757
|
+
_notifyClose() {
|
|
1758
|
+
if (this.#closed) return;
|
|
1759
|
+
this.#closed = true;
|
|
1760
|
+
this.#onclose?.();
|
|
1761
|
+
}
|
|
1762
|
+
send(data) {
|
|
1763
|
+
this.#send(data);
|
|
1764
|
+
}
|
|
1765
|
+
close() {
|
|
1766
|
+
this.#close();
|
|
1767
|
+
}
|
|
1768
|
+
// -- Transport factories --------------------------------------------------
|
|
1769
|
+
/** Wrap a browser WebSocket (already open). */
|
|
1770
|
+
static fromWebSocket(ws) {
|
|
1771
|
+
const sock = new _ArtiSocket(
|
|
1772
|
+
(data) => ws.send(data),
|
|
1773
|
+
() => ws.close()
|
|
1774
|
+
);
|
|
1775
|
+
ws.onmessage = (ev) => sock.onmessage?.(new Uint8Array(ev.data));
|
|
1776
|
+
ws.onclose = () => sock._notifyClose();
|
|
1777
|
+
return sock;
|
|
1778
|
+
}
|
|
1779
|
+
/** Wrap a WebRTC data channel (already open). */
|
|
1780
|
+
static fromDataChannel(dc) {
|
|
1781
|
+
const sock = new _ArtiSocket(
|
|
1782
|
+
(data) => dc.send(data),
|
|
1783
|
+
() => dc.close()
|
|
1784
|
+
);
|
|
1785
|
+
dc.onmessage = (ev) => sock.onmessage?.(new Uint8Array(ev.data));
|
|
1786
|
+
dc.onclose = () => sock._notifyClose();
|
|
1787
|
+
return sock;
|
|
1788
|
+
}
|
|
1789
|
+
/** Wrap a Node.js net.Socket (already connected). */
|
|
1790
|
+
static fromNodeSocket(socket) {
|
|
1791
|
+
const sock = new _ArtiSocket(
|
|
1792
|
+
(data) => socket.write(data),
|
|
1793
|
+
() => socket.destroy()
|
|
1794
|
+
);
|
|
1795
|
+
socket.on("data", (buf) => sock.onmessage?.(new Uint8Array(buf)));
|
|
1796
|
+
socket.on("close", () => sock._notifyClose());
|
|
1797
|
+
socket.on("error", () => {
|
|
1798
|
+
});
|
|
1799
|
+
return sock;
|
|
1800
|
+
}
|
|
1801
|
+
/** Wrap a Deno TCP connection. */
|
|
1802
|
+
static fromDenoConn(conn) {
|
|
1803
|
+
const sock = new _ArtiSocket(
|
|
1804
|
+
(data) => {
|
|
1805
|
+
const writer = conn.writable.getWriter();
|
|
1806
|
+
writer.write(data).then(() => writer.releaseLock());
|
|
1807
|
+
},
|
|
1808
|
+
() => conn.close()
|
|
1809
|
+
);
|
|
1810
|
+
(async () => {
|
|
1811
|
+
try {
|
|
1812
|
+
for await (const chunk of conn.readable) {
|
|
1813
|
+
sock.onmessage?.(new Uint8Array(chunk));
|
|
1814
|
+
}
|
|
1815
|
+
} catch {
|
|
1816
|
+
}
|
|
1817
|
+
sock._notifyClose();
|
|
1818
|
+
})();
|
|
1819
|
+
return sock;
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
var ArtiSocketProvider = class {
|
|
1823
|
+
#url;
|
|
1824
|
+
#strategies;
|
|
1825
|
+
// WebRTC state (lazily created, reused across connect() calls)
|
|
1826
|
+
#rtcPc = null;
|
|
1827
|
+
#rtcAlive = false;
|
|
1828
|
+
#signalChannel = null;
|
|
1829
|
+
// Tracked data channels: before open has reject, after open has sock.
|
|
1830
|
+
#tracked = [];
|
|
1831
|
+
constructor(options = {}) {
|
|
1832
|
+
this.#url = options.gateway ? options.gateway.replace(/\/+$/, "") : null;
|
|
1833
|
+
this.#strategies = options.strategies ?? defaultStrategies(!!this.#url);
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1836
|
+
* Open a relay socket to the given target (e.g. "198.51.100.1:9001").
|
|
1837
|
+
* Tries each configured strategy in order until one succeeds.
|
|
1838
|
+
*/
|
|
1839
|
+
async connect(target) {
|
|
1840
|
+
const errors = [];
|
|
1841
|
+
for (const strategy of this.#strategies) {
|
|
1842
|
+
try {
|
|
1843
|
+
switch (strategy) {
|
|
1844
|
+
case "direct":
|
|
1845
|
+
return await this.#connectDirect(target);
|
|
1846
|
+
case "webrtc":
|
|
1847
|
+
return await this.#connectWebRTC(target);
|
|
1848
|
+
case "websocket":
|
|
1849
|
+
return await this.#connectWebSocket(target);
|
|
1850
|
+
default:
|
|
1851
|
+
throw new Error(`unknown strategy: ${strategy}`);
|
|
1852
|
+
}
|
|
1853
|
+
} catch (e) {
|
|
1854
|
+
errors.push(`${strategy}: ${e.message}`);
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
throw new Error(`all strategies failed for ${target}: ${errors.join("; ")}`);
|
|
1858
|
+
}
|
|
1859
|
+
/** Close WebRTC peer connection and release resources. */
|
|
1860
|
+
close() {
|
|
1861
|
+
if (this.#rtcPc) {
|
|
1862
|
+
this.#rtcPc.close();
|
|
1863
|
+
this.#rtcPc = null;
|
|
1864
|
+
this.#rtcAlive = false;
|
|
1865
|
+
this.#signalChannel = null;
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
// -- Direct TCP strategy (Node.js / Deno) ---------------------------------
|
|
1869
|
+
async #connectDirect(target) {
|
|
1870
|
+
const [host, portStr] = target.split(":");
|
|
1871
|
+
const port = parseInt(portStr, 10);
|
|
1872
|
+
if (HAS_DENO) {
|
|
1873
|
+
const conn = await globalThis.Deno.connect({ hostname: host, port });
|
|
1874
|
+
return ArtiSocket.fromDenoConn(conn);
|
|
1875
|
+
}
|
|
1876
|
+
if (HAS_NODE) {
|
|
1877
|
+
const net = await import("net");
|
|
1878
|
+
const socket = net.createConnection({ host, port });
|
|
1879
|
+
await new Promise((resolve, reject) => {
|
|
1880
|
+
socket.once("connect", resolve);
|
|
1881
|
+
socket.once("error", reject);
|
|
1882
|
+
});
|
|
1883
|
+
return ArtiSocket.fromNodeSocket(socket);
|
|
1884
|
+
}
|
|
1885
|
+
throw new Error("direct TCP not available in this environment");
|
|
1886
|
+
}
|
|
1887
|
+
// -- WebSocket strategy ---------------------------------------------------
|
|
1888
|
+
async #connectWebSocket(target) {
|
|
1889
|
+
if (!this.#url) throw new Error("websocket strategy requires a gateway URL");
|
|
1890
|
+
const wsUrl = `${this.#url.replace(/^http/, "ws")}/socket/${target}`;
|
|
1891
|
+
const ws = new WebSocket(wsUrl);
|
|
1892
|
+
ws.binaryType = "arraybuffer";
|
|
1893
|
+
await new Promise((resolve, reject) => {
|
|
1894
|
+
ws.onopen = () => resolve();
|
|
1895
|
+
ws.onerror = () => reject(new Error("websocket connection failed"));
|
|
1896
|
+
});
|
|
1897
|
+
return ArtiSocket.fromWebSocket(ws);
|
|
1898
|
+
}
|
|
1899
|
+
// -- WebRTC strategy ------------------------------------------------------
|
|
1900
|
+
async #connectWebRTC(target) {
|
|
1901
|
+
if (!this.#url) throw new Error("webrtc strategy requires a gateway URL");
|
|
1902
|
+
if (typeof RTCPeerConnection === "undefined") {
|
|
1903
|
+
throw new Error("RTCPeerConnection not available");
|
|
1904
|
+
}
|
|
1905
|
+
if (!this.#rtcAlive) {
|
|
1906
|
+
if (this.#rtcPc) this.#rtcPc.close();
|
|
1907
|
+
await this.#setupRtcPeerConnection();
|
|
1908
|
+
}
|
|
1909
|
+
const dc = this.#rtcPc.createDataChannel(target);
|
|
1910
|
+
dc.binaryType = "arraybuffer";
|
|
1911
|
+
const entry = { dc, sock: null, reject: null };
|
|
1912
|
+
this.#tracked.push(entry);
|
|
1913
|
+
await new Promise((resolve, reject) => {
|
|
1914
|
+
entry.reject = reject;
|
|
1915
|
+
dc.onopen = () => resolve();
|
|
1916
|
+
dc.onerror = (e) => {
|
|
1917
|
+
this.#removeTracked(entry);
|
|
1918
|
+
reject(new Error(`data channel error: ${e.error?.message || e}`));
|
|
1919
|
+
};
|
|
1920
|
+
});
|
|
1921
|
+
entry.reject = null;
|
|
1922
|
+
const sock = ArtiSocket.fromDataChannel(dc);
|
|
1923
|
+
entry.sock = sock;
|
|
1924
|
+
dc.onclose = () => {
|
|
1925
|
+
this.#removeTracked(entry);
|
|
1926
|
+
sock._notifyClose();
|
|
1927
|
+
};
|
|
1928
|
+
return sock;
|
|
1929
|
+
}
|
|
1930
|
+
async #setupRtcPeerConnection() {
|
|
1931
|
+
const pc = new RTCPeerConnection();
|
|
1932
|
+
const signal = pc.createDataChannel("_signal");
|
|
1933
|
+
signal.onmessage = (ev) => this.#handleSignalMessage(ev.data);
|
|
1934
|
+
const offer = await pc.createOffer();
|
|
1935
|
+
await pc.setLocalDescription(offer);
|
|
1936
|
+
await new Promise((resolve) => {
|
|
1937
|
+
if (pc.iceGatheringState === "complete") return resolve();
|
|
1938
|
+
pc.addEventListener("icegatheringstatechange", () => {
|
|
1939
|
+
if (pc.iceGatheringState === "complete") resolve();
|
|
1940
|
+
});
|
|
1941
|
+
});
|
|
1942
|
+
const res = await fetch(`${this.#url}/rtc/connect`, {
|
|
1943
|
+
method: "POST",
|
|
1944
|
+
body: JSON.stringify(pc.localDescription)
|
|
1945
|
+
});
|
|
1946
|
+
if (!res.ok) {
|
|
1947
|
+
pc.close();
|
|
1948
|
+
throw new Error(`rtc signaling failed: ${res.status} ${await res.text()}`);
|
|
1949
|
+
}
|
|
1950
|
+
const answer = await res.json();
|
|
1951
|
+
await pc.setRemoteDescription(answer);
|
|
1952
|
+
await new Promise((resolve, reject) => {
|
|
1953
|
+
if (pc.connectionState === "connected") return resolve();
|
|
1954
|
+
pc.addEventListener("connectionstatechange", () => {
|
|
1955
|
+
if (pc.connectionState === "connected") resolve();
|
|
1956
|
+
if (pc.connectionState === "failed") reject(new Error("WebRTC connection failed"));
|
|
1957
|
+
});
|
|
1958
|
+
});
|
|
1959
|
+
this.#rtcPc = pc;
|
|
1960
|
+
this.#rtcAlive = true;
|
|
1961
|
+
this.#signalChannel = signal;
|
|
1962
|
+
pc.addEventListener("connectionstatechange", () => {
|
|
1963
|
+
const s = pc.connectionState;
|
|
1964
|
+
if (s === "disconnected" || s === "closed" || s === "failed") {
|
|
1965
|
+
this.#rtcAlive = false;
|
|
1966
|
+
this.#signalChannel = null;
|
|
1967
|
+
}
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1970
|
+
#findTracked(sctpId, label) {
|
|
1971
|
+
return this.#tracked.find((e) => e.dc.id != null && e.dc.id === sctpId) ?? this.#tracked.find((e) => e.dc.label === label);
|
|
1972
|
+
}
|
|
1973
|
+
#removeTracked(entry) {
|
|
1974
|
+
const i = this.#tracked.indexOf(entry);
|
|
1975
|
+
if (i !== -1) this.#tracked.splice(i, 1);
|
|
1976
|
+
}
|
|
1977
|
+
#handleSignalMessage(data) {
|
|
1978
|
+
try {
|
|
1979
|
+
const msg = JSON.parse(data);
|
|
1980
|
+
switch (msg.type) {
|
|
1981
|
+
case "rejected": {
|
|
1982
|
+
const entry = this.#findTracked(msg.sctp_id, msg.channel);
|
|
1983
|
+
if (entry) {
|
|
1984
|
+
this.#removeTracked(entry);
|
|
1985
|
+
if (entry.reject) {
|
|
1986
|
+
entry.reject(new Error(`rejected: ${msg.reason}`));
|
|
1987
|
+
} else if (entry.sock) {
|
|
1988
|
+
entry.sock._error = msg.reason;
|
|
1989
|
+
entry.sock.close();
|
|
1990
|
+
entry.sock._notifyClose();
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
break;
|
|
1994
|
+
}
|
|
1995
|
+
case "closed": {
|
|
1996
|
+
const entry = this.#findTracked(msg.sctp_id, msg.channel);
|
|
1997
|
+
if (entry) {
|
|
1998
|
+
this.#removeTracked(entry);
|
|
1999
|
+
if (entry.sock) {
|
|
2000
|
+
entry.sock.close();
|
|
2001
|
+
entry.sock._notifyClose();
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
break;
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
} catch {
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
};
|
|
2011
|
+
|
|
2012
|
+
// src/TorClient.ts
|
|
2013
|
+
var TorClient2 = class {
|
|
2014
|
+
log;
|
|
2015
|
+
clientPromise;
|
|
2016
|
+
removeLogListener = null;
|
|
2017
|
+
wasmCallback = null;
|
|
2018
|
+
closed = false;
|
|
2019
|
+
readyPromise = null;
|
|
2020
|
+
socketProvider = null;
|
|
2021
|
+
constructor(options = {}) {
|
|
2022
|
+
this.log = options.log ?? new Log({ rawLog: () => {
|
|
2023
|
+
} });
|
|
2024
|
+
this.clientPromise = this.bootstrap(options);
|
|
2025
|
+
}
|
|
2026
|
+
async bootstrap(options) {
|
|
2027
|
+
await ensureWasmInitialized();
|
|
2028
|
+
this.wasmCallback = this.log._makeWasmCallback();
|
|
2029
|
+
this.removeLogListener = addLogListener(this.wasmCallback, options.logLevel);
|
|
2030
|
+
this.socketProvider = options.socketProvider ?? new ArtiSocketProvider({ gateway: options.gateway });
|
|
2031
|
+
const sp = this.socketProvider;
|
|
2032
|
+
let wasmOptions = new TorClientOptions(
|
|
2033
|
+
(addr) => sp.connect(addr)
|
|
2034
|
+
);
|
|
2035
|
+
const storage = options.storage ?? createAutoStorage();
|
|
2036
|
+
wasmOptions = wasmOptions.withStorage(storage);
|
|
2037
|
+
if (options.gateway) {
|
|
2038
|
+
const gatewayBase = options.gateway.replace(/\/+$/, "");
|
|
2039
|
+
wasmOptions = wasmOptions.withFastBootstrap(async () => {
|
|
2040
|
+
this.log.info("Fast bootstrap: fetching bootstrap.zip.br...");
|
|
2041
|
+
const res = await fetch(`${gatewayBase}/bootstrap.zip.br`);
|
|
2042
|
+
if (!res.ok) {
|
|
2043
|
+
throw new Error(`Fast bootstrap fetch failed: ${res.status} ${res.statusText}`);
|
|
2044
|
+
}
|
|
2045
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
2046
|
+
this.log.info(`Fast bootstrap: received ${bytes.byteLength} bytes`);
|
|
2047
|
+
return bytes;
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
this.log.info("Bootstrapping...");
|
|
2051
|
+
const client2 = await TorClient.create(wasmOptions);
|
|
2052
|
+
this.log.info("Bootstrap complete");
|
|
2053
|
+
return client2;
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Make an HTTP fetch request through Tor.
|
|
2057
|
+
* Returns a standard browser Response object.
|
|
2058
|
+
*/
|
|
2059
|
+
async fetch(url, init2) {
|
|
2060
|
+
if (this.closed) throw new Error("TorClient is closed");
|
|
2061
|
+
const client2 = await this.clientPromise;
|
|
2062
|
+
await this.ready();
|
|
2063
|
+
this.log.info(`Fetching ${url}`);
|
|
2064
|
+
return client2.fetch(url, init2);
|
|
2065
|
+
}
|
|
2066
|
+
/**
|
|
2067
|
+
* Wait for the Tor client to be ready for traffic
|
|
2068
|
+
* (guard connected, usable consensus, and sufficient microdescs).
|
|
2069
|
+
*
|
|
2070
|
+
* Parallel callers share the same underlying promise — a single WS
|
|
2071
|
+
* connection failure rejects all waiters. The cached promise is cleared
|
|
2072
|
+
* on settle so the next call creates a fresh attempt.
|
|
2073
|
+
*/
|
|
2074
|
+
async ready() {
|
|
2075
|
+
if (this.closed) throw new Error("TorClient is closed");
|
|
2076
|
+
if (this.readyPromise) return this.readyPromise;
|
|
2077
|
+
const p = (async () => {
|
|
2078
|
+
const startTime = Date.now();
|
|
2079
|
+
this.log.info("Waiting for client");
|
|
2080
|
+
const client2 = await this.clientPromise;
|
|
2081
|
+
this.log.info("Waiting for client to be ready");
|
|
2082
|
+
await client2.ready();
|
|
2083
|
+
this.log.info(`Client ready in ${Date.now() - startTime}ms`);
|
|
2084
|
+
})();
|
|
2085
|
+
this.readyPromise = p;
|
|
2086
|
+
p.finally(() => {
|
|
2087
|
+
this.readyPromise = null;
|
|
2088
|
+
});
|
|
2089
|
+
return p;
|
|
2090
|
+
}
|
|
2091
|
+
/**
|
|
2092
|
+
* Change the log level for this client's listener.
|
|
2093
|
+
* Also re-syncs the global WASM filter to the broadest level across all clients.
|
|
2094
|
+
*/
|
|
2095
|
+
setLogLevel(level) {
|
|
2096
|
+
if (this.wasmCallback) {
|
|
2097
|
+
setListenerLevel(this.wasmCallback, level);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* Close the TorClient and release resources.
|
|
2102
|
+
*/
|
|
2103
|
+
close() {
|
|
2104
|
+
if (this.closed) return;
|
|
2105
|
+
this.closed = true;
|
|
2106
|
+
this.removeLogListener?.();
|
|
2107
|
+
this.removeLogListener = null;
|
|
2108
|
+
this.wasmCallback = null;
|
|
2109
|
+
this.socketProvider?.close();
|
|
2110
|
+
this.socketProvider = null;
|
|
2111
|
+
this.clientPromise.then((client2) => client2.close()).catch(() => {
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
[Symbol.dispose]() {
|
|
2115
|
+
this.close();
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
|
|
2119
|
+
// src/entryPoints/wasm-file/index.ts
|
|
2120
|
+
setWasmSourceProvider(async () => {
|
|
2121
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
2122
|
+
const { readFile } = await import("fs/promises");
|
|
2123
|
+
const { fileURLToPath } = await import("url");
|
|
2124
|
+
const wasmPath = fileURLToPath(new URL("./tor_js_bg.wasm", import.meta.url));
|
|
2125
|
+
return readFile(wasmPath);
|
|
2126
|
+
}
|
|
2127
|
+
const resp = await fetch(new URL("./tor_js_bg.wasm", import.meta.url));
|
|
2128
|
+
if (!resp.ok) throw new Error(`Failed to fetch WASM: HTTP ${resp.status}`);
|
|
2129
|
+
return new Uint8Array(await resp.arrayBuffer());
|
|
2130
|
+
});
|
|
2131
|
+
|
|
2132
|
+
// src/singleton.ts
|
|
2133
|
+
var client;
|
|
2134
|
+
var config = {
|
|
2135
|
+
gateway: "https://tor-js-gateway.voltrevo.com"
|
|
2136
|
+
};
|
|
2137
|
+
var tor = {
|
|
2138
|
+
/**
|
|
2139
|
+
* Make an HTTP fetch request through Tor.
|
|
2140
|
+
* Automatically opens the TorClient on first use.
|
|
2141
|
+
*/
|
|
2142
|
+
async fetch(url, init2) {
|
|
2143
|
+
if (!client) {
|
|
2144
|
+
this.open();
|
|
2145
|
+
}
|
|
2146
|
+
return client.fetch(url, init2);
|
|
2147
|
+
},
|
|
2148
|
+
/**
|
|
2149
|
+
* Configure the singleton TorClient.
|
|
2150
|
+
* If already open, closes and reopens with the new config.
|
|
2151
|
+
*/
|
|
2152
|
+
configure(options) {
|
|
2153
|
+
config = options;
|
|
2154
|
+
if (client) {
|
|
2155
|
+
client.close();
|
|
2156
|
+
client = void 0;
|
|
2157
|
+
this.open();
|
|
2158
|
+
}
|
|
2159
|
+
},
|
|
2160
|
+
/**
|
|
2161
|
+
* Open the singleton TorClient.
|
|
2162
|
+
* Optional — fetch() calls this automatically.
|
|
2163
|
+
* Call this early if you know you'll need Tor, to start bootstrapping sooner.
|
|
2164
|
+
*/
|
|
2165
|
+
open() {
|
|
2166
|
+
if (client) return;
|
|
2167
|
+
client = new TorClient2(config);
|
|
2168
|
+
},
|
|
2169
|
+
/**
|
|
2170
|
+
* Close the singleton TorClient and release resources.
|
|
2171
|
+
*/
|
|
2172
|
+
close() {
|
|
2173
|
+
if (client) {
|
|
2174
|
+
client.close();
|
|
2175
|
+
client = void 0;
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
};
|
|
2179
|
+
export {
|
|
2180
|
+
ArtiSocket,
|
|
2181
|
+
ArtiSocketProvider,
|
|
2182
|
+
Log,
|
|
2183
|
+
setWasmUrl,
|
|
2184
|
+
storage_exports as storage,
|
|
2185
|
+
tor
|
|
2186
|
+
};
|
|
2187
|
+
//# sourceMappingURL=singleton.js.map
|