@minip2p/web 0.0.0-stage → 0.10.1

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.
@@ -0,0 +1,1100 @@
1
+ /* @ts-self-types="./minip2p_web.d.ts" */
2
+
3
+ /**
4
+ * A minip2p endpoint in the browser, dialing over WebTransport.
5
+ *
6
+ * It is driven by its TypeScript owner: every call returns at once, and
7
+ * `pump` polls the endpoint, which the owner schedules after each call, each
8
+ * `JsIo` event, and at the deadline `pump` returns.
9
+ */
10
+ export class WebEndpoint {
11
+ __destroy_into_raw() {
12
+ const ptr = this.__wbg_ptr;
13
+ this.__wbg_ptr = 0;
14
+ WebEndpointFinalization.unregister(this);
15
+ return ptr;
16
+ }
17
+ free() {
18
+ const ptr = this.__destroy_into_raw();
19
+ wasm.__wbg_webendpoint_free(ptr, 0);
20
+ }
21
+ /**
22
+ * Resets and relinquishes a stream.
23
+ * @param {bigint} conn_id
24
+ * @param {bigint} stream_id
25
+ */
26
+ abandonStream(conn_id, stream_id) {
27
+ const ret = wasm.webendpoint_abandonStream(this.__wbg_ptr, conn_id, stream_id);
28
+ if (ret[1]) {
29
+ throw takeFromExternrefTable0(ret[0]);
30
+ }
31
+ }
32
+ /**
33
+ * The relay reservation currently held, or `null`.
34
+ * @returns {any}
35
+ */
36
+ activeReservation() {
37
+ const ret = wasm.webendpoint_activeReservation(this.__wbg_ptr);
38
+ if (ret[2]) {
39
+ throw takeFromExternrefTable0(ret[1]);
40
+ }
41
+ return takeFromExternrefTable0(ret[0]);
42
+ }
43
+ /**
44
+ * Registers an application protocol.
45
+ * @param {string} protocol_id
46
+ */
47
+ addProtocol(protocol_id) {
48
+ const ptr0 = passStringToWasm0(protocol_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
49
+ const len0 = WASM_VECTOR_LEN;
50
+ const ret = wasm.webendpoint_addProtocol(this.__wbg_ptr, ptr0, len0);
51
+ if (ret[1]) {
52
+ throw takeFromExternrefTable0(ret[0]);
53
+ }
54
+ }
55
+ /**
56
+ * Cancels a Connection attempt.
57
+ * @param {bigint} id
58
+ */
59
+ cancelConnect(id) {
60
+ const ret = wasm.webendpoint_cancelConnect(this.__wbg_ptr, id);
61
+ if (ret[1]) {
62
+ throw takeFromExternrefTable0(ret[0]);
63
+ }
64
+ }
65
+ /**
66
+ * Half-closes a stream's write side.
67
+ * @param {bigint} conn_id
68
+ * @param {bigint} stream_id
69
+ */
70
+ closeStreamWrite(conn_id, stream_id) {
71
+ const ret = wasm.webendpoint_closeStreamWrite(this.__wbg_ptr, conn_id, stream_id);
72
+ if (ret[1]) {
73
+ throw takeFromExternrefTable0(ret[0]);
74
+ }
75
+ }
76
+ /**
77
+ * Closes the endpoint; `EndpointClosed` is the last event drained.
78
+ *
79
+ * The timeout is ignored in the browser: every session closes at once
80
+ * (`WebTransport.close()` sends the close capsule), so there is no
81
+ * drain for it to bound.
82
+ * @param {number} _timeout_ms
83
+ */
84
+ close(_timeout_ms) {
85
+ wasm.webendpoint_close(this.__wbg_ptr, _timeout_ms);
86
+ }
87
+ /**
88
+ * Starts one Connection attempt: a peer ID string, or an array of peer
89
+ * addresses naming one peer. Returns the Connect ID.
90
+ * @param {any} target
91
+ * @returns {bigint}
92
+ */
93
+ connect(target) {
94
+ const ret = wasm.webendpoint_connect(this.__wbg_ptr, target);
95
+ if (ret[2]) {
96
+ throw takeFromExternrefTable0(ret[1]);
97
+ }
98
+ return BigInt.asUintN(64, ret[0]);
99
+ }
100
+ /**
101
+ * Connected peer IDs.
102
+ * @returns {string[]}
103
+ */
104
+ connectedPeers() {
105
+ const ret = wasm.webendpoint_connectedPeers(this.__wbg_ptr);
106
+ if (ret[3]) {
107
+ throw takeFromExternrefTable0(ret[2]);
108
+ }
109
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
110
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
111
+ return v1;
112
+ }
113
+ /**
114
+ * A snapshot of a peer's connection, or `null`.
115
+ * @param {string} peer_id
116
+ * @returns {any}
117
+ */
118
+ connectionInfo(peer_id) {
119
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
120
+ const len0 = WASM_VECTOR_LEN;
121
+ const ret = wasm.webendpoint_connectionInfo(this.__wbg_ptr, ptr0, len0);
122
+ if (ret[2]) {
123
+ throw takeFromExternrefTable0(ret[1]);
124
+ }
125
+ return takeFromExternrefTable0(ret[0]);
126
+ }
127
+ /**
128
+ * Disconnects one peer.
129
+ * @param {string} peer_id
130
+ */
131
+ disconnect(peer_id) {
132
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
133
+ const len0 = WASM_VECTOR_LEN;
134
+ const ret = wasm.webendpoint_disconnect(this.__wbg_ptr, ptr0, len0);
135
+ if (ret[1]) {
136
+ throw takeFromExternrefTable0(ret[0]);
137
+ }
138
+ }
139
+ /**
140
+ * The discovery clock (always `null` in a browser).
141
+ * @returns {any}
142
+ */
143
+ discoveryNowMs() {
144
+ const ret = wasm.webendpoint_discoveryNowMs(this.__wbg_ptr);
145
+ if (ret[2]) {
146
+ throw takeFromExternrefTable0(ret[1]);
147
+ }
148
+ return takeFromExternrefTable0(ret[0]);
149
+ }
150
+ /**
151
+ * Pulls a bounded batch of events.
152
+ * @param {number} limit
153
+ * @returns {any}
154
+ */
155
+ drainEvents(limit) {
156
+ const ret = wasm.webendpoint_drainEvents(this.__wbg_ptr, limit);
157
+ if (ret[2]) {
158
+ throw takeFromExternrefTable0(ret[1]);
159
+ }
160
+ return takeFromExternrefTable0(ret[0]);
161
+ }
162
+ /**
163
+ * Whether Identify completed for a peer.
164
+ * @param {string} peer_id
165
+ * @returns {boolean}
166
+ */
167
+ isPeerReady(peer_id) {
168
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
169
+ const len0 = WASM_VECTOR_LEN;
170
+ const ret = wasm.webendpoint_isPeerReady(this.__wbg_ptr, ptr0, len0);
171
+ if (ret[2]) {
172
+ throw takeFromExternrefTable0(ret[1]);
173
+ }
174
+ return ret[0] !== 0;
175
+ }
176
+ /**
177
+ * Whether the endpoint is started and not closed.
178
+ * @returns {boolean}
179
+ */
180
+ isRunning() {
181
+ const ret = wasm.webendpoint_isRunning(this.__wbg_ptr);
182
+ return ret !== 0;
183
+ }
184
+ /**
185
+ * The discovery book (always empty in a browser).
186
+ * @returns {any}
187
+ */
188
+ knownPeers() {
189
+ const ret = wasm.webendpoint_knownPeers(this.__wbg_ptr);
190
+ if (ret[2]) {
191
+ throw takeFromExternrefTable0(ret[1]);
192
+ }
193
+ return takeFromExternrefTable0(ret[0]);
194
+ }
195
+ /**
196
+ * The listen set; empty, since browsers do not listen.
197
+ * @returns {string[]}
198
+ */
199
+ listenAddrs() {
200
+ const ret = wasm.webendpoint_listenAddrs(this.__wbg_ptr);
201
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
202
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
203
+ return v1;
204
+ }
205
+ /**
206
+ * Validates the key and config and builds the endpoint over `io`,
207
+ * without driving it yet.
208
+ * @param {Uint8Array} secret_key
209
+ * @param {any} config
210
+ * @param {any} io
211
+ */
212
+ constructor(secret_key, config, io) {
213
+ const ptr0 = passArray8ToWasm0(secret_key, wasm.__wbindgen_malloc);
214
+ const len0 = WASM_VECTOR_LEN;
215
+ const ret = wasm.webendpoint_new(ptr0, len0, config, io);
216
+ if (ret[2]) {
217
+ throw takeFromExternrefTable0(ret[1]);
218
+ }
219
+ this.__wbg_ptr = ret[0];
220
+ WebEndpointFinalization.register(this, this.__wbg_ptr, this);
221
+ return this;
222
+ }
223
+ /**
224
+ * Starts opening an application stream.
225
+ * @param {string} peer_id
226
+ * @param {string} protocol_id
227
+ * @returns {any}
228
+ */
229
+ openStream(peer_id, protocol_id) {
230
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
231
+ const len0 = WASM_VECTOR_LEN;
232
+ const ptr1 = passStringToWasm0(protocol_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
233
+ const len1 = WASM_VECTOR_LEN;
234
+ const ret = wasm.webendpoint_openStream(this.__wbg_ptr, ptr0, len0, ptr1, len1);
235
+ if (ret[2]) {
236
+ throw takeFromExternrefTable0(ret[1]);
237
+ }
238
+ return takeFromExternrefTable0(ret[0]);
239
+ }
240
+ /**
241
+ * The path of a peer's connection, or `null`.
242
+ * @param {string} peer_id
243
+ * @returns {any}
244
+ */
245
+ path(peer_id) {
246
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
247
+ const len0 = WASM_VECTOR_LEN;
248
+ const ret = wasm.webendpoint_path(this.__wbg_ptr, ptr0, len0);
249
+ if (ret[2]) {
250
+ throw takeFromExternrefTable0(ret[1]);
251
+ }
252
+ return takeFromExternrefTable0(ret[0]);
253
+ }
254
+ /**
255
+ * The local peer ID.
256
+ * @returns {string}
257
+ */
258
+ peerId() {
259
+ let deferred1_0;
260
+ let deferred1_1;
261
+ try {
262
+ const ret = wasm.webendpoint_peerId(this.__wbg_ptr);
263
+ deferred1_0 = ret[0];
264
+ deferred1_1 = ret[1];
265
+ return getStringFromWasm0(ret[0], ret[1]);
266
+ } finally {
267
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
268
+ }
269
+ }
270
+ /**
271
+ * The latest Identify snapshot, or `null`.
272
+ * @param {string} peer_id
273
+ * @returns {any}
274
+ */
275
+ peerInfo(peer_id) {
276
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
277
+ const len0 = WASM_VECTOR_LEN;
278
+ const ret = wasm.webendpoint_peerInfo(this.__wbg_ptr, ptr0, len0);
279
+ if (ret[2]) {
280
+ throw takeFromExternrefTable0(ret[1]);
281
+ }
282
+ return takeFromExternrefTable0(ret[0]);
283
+ }
284
+ /**
285
+ * Starts one ping.
286
+ * @param {string} peer_id
287
+ */
288
+ ping(peer_id) {
289
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
290
+ const len0 = WASM_VECTOR_LEN;
291
+ const ret = wasm.webendpoint_ping(this.__wbg_ptr, ptr0, len0);
292
+ if (ret[1]) {
293
+ throw takeFromExternrefTable0(ret[0]);
294
+ }
295
+ }
296
+ /**
297
+ * Publishes one pubsub payload.
298
+ * @param {string} topic
299
+ * @param {Uint8Array} data
300
+ */
301
+ publish(topic, data) {
302
+ const ptr0 = passStringToWasm0(topic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
303
+ const len0 = WASM_VECTOR_LEN;
304
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
305
+ const len1 = WASM_VECTOR_LEN;
306
+ const ret = wasm.webendpoint_publish(this.__wbg_ptr, ptr0, len0, ptr1, len1);
307
+ if (ret[1]) {
308
+ throw takeFromExternrefTable0(ret[0]);
309
+ }
310
+ }
311
+ /**
312
+ * Polls the endpoint once and returns the milliseconds until it needs
313
+ * polling again (`0` at once), or `undefined` when nothing is
314
+ * scheduled.
315
+ * @returns {number | undefined}
316
+ */
317
+ pump() {
318
+ const ret = wasm.webendpoint_pump(this.__wbg_ptr);
319
+ return ret[0] === 0 ? undefined : ret[1];
320
+ }
321
+ /**
322
+ * The reachability verdict (always `Unknown` in a browser).
323
+ * @returns {any}
324
+ */
325
+ reachability() {
326
+ const ret = wasm.webendpoint_reachability(this.__wbg_ptr);
327
+ if (ret[2]) {
328
+ throw takeFromExternrefTable0(ret[1]);
329
+ }
330
+ return takeFromExternrefTable0(ret[0]);
331
+ }
332
+ /**
333
+ * Resets a stream.
334
+ * @param {bigint} conn_id
335
+ * @param {bigint} stream_id
336
+ */
337
+ resetStream(conn_id, stream_id) {
338
+ const ret = wasm.webendpoint_resetStream(this.__wbg_ptr, conn_id, stream_id);
339
+ if (ret[1]) {
340
+ throw takeFromExternrefTable0(ret[0]);
341
+ }
342
+ }
343
+ /**
344
+ * Sends bytes on a stream: `true` once all are accepted, `false` while
345
+ * the tail is held and `StreamWriteAccepted` is still to come.
346
+ * @param {bigint} conn_id
347
+ * @param {bigint} stream_id
348
+ * @param {Uint8Array} data
349
+ * @returns {boolean}
350
+ */
351
+ sendStream(conn_id, stream_id, data) {
352
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
353
+ const len0 = WASM_VECTOR_LEN;
354
+ const ret = wasm.webendpoint_sendStream(this.__wbg_ptr, conn_id, stream_id, ptr0, len0);
355
+ if (ret[2]) {
356
+ throw takeFromExternrefTable0(ret[1]);
357
+ }
358
+ return ret[0] !== 0;
359
+ }
360
+ /**
361
+ * Ignored in the browser, kept for the shared SDK surface: there is no
362
+ * background driver whose cadence it could change. The page's own
363
+ * timers pump the endpoint.
364
+ * @param {boolean} _active
365
+ */
366
+ setActive(_active) {
367
+ wasm.webendpoint_setActive(this.__wbg_ptr, _active);
368
+ }
369
+ /**
370
+ * Starts driving; `doorbell` is called when events become ready to drain.
371
+ * @param {Function} doorbell
372
+ */
373
+ start(doorbell) {
374
+ const ret = wasm.webendpoint_start(this.__wbg_ptr, doorbell);
375
+ if (ret[1]) {
376
+ throw takeFromExternrefTable0(ret[0]);
377
+ }
378
+ }
379
+ /**
380
+ * Acknowledges `bytes` of a stream's received data as consumed.
381
+ * @param {bigint} conn_id
382
+ * @param {bigint} stream_id
383
+ * @param {number} bytes
384
+ */
385
+ streamConsumed(conn_id, stream_id, bytes) {
386
+ const ret = wasm.webendpoint_streamConsumed(this.__wbg_ptr, conn_id, stream_id, bytes);
387
+ if (ret[1]) {
388
+ throw takeFromExternrefTable0(ret[0]);
389
+ }
390
+ }
391
+ /**
392
+ * Subscribes to a pubsub topic.
393
+ * @param {string} topic
394
+ * @returns {boolean}
395
+ */
396
+ subscribe(topic) {
397
+ const ptr0 = passStringToWasm0(topic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
398
+ const len0 = WASM_VECTOR_LEN;
399
+ const ret = wasm.webendpoint_subscribe(this.__wbg_ptr, ptr0, len0);
400
+ if (ret[2]) {
401
+ throw takeFromExternrefTable0(ret[1]);
402
+ }
403
+ return ret[0] !== 0;
404
+ }
405
+ /**
406
+ * Unsubscribes from a pubsub topic.
407
+ * @param {string} topic
408
+ * @returns {boolean}
409
+ */
410
+ unsubscribe(topic) {
411
+ const ptr0 = passStringToWasm0(topic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
412
+ const len0 = WASM_VECTOR_LEN;
413
+ const ret = wasm.webendpoint_unsubscribe(this.__wbg_ptr, ptr0, len0);
414
+ if (ret[2]) {
415
+ throw takeFromExternrefTable0(ret[1]);
416
+ }
417
+ return ret[0] !== 0;
418
+ }
419
+ }
420
+ if (Symbol.dispose) WebEndpoint.prototype[Symbol.dispose] = WebEndpoint.prototype.free;
421
+
422
+ /**
423
+ * Builds a circuit address through a direct relay address.
424
+ * @param {string} relay_address
425
+ * @param {string} peer_id
426
+ * @returns {string}
427
+ */
428
+ export function circuitAddress(relay_address, peer_id) {
429
+ let deferred4_0;
430
+ let deferred4_1;
431
+ try {
432
+ const ptr0 = passStringToWasm0(relay_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
433
+ const len0 = WASM_VECTOR_LEN;
434
+ const ptr1 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
435
+ const len1 = WASM_VECTOR_LEN;
436
+ const ret = wasm.circuitAddress(ptr0, len0, ptr1, len1);
437
+ var ptr3 = ret[0];
438
+ var len3 = ret[1];
439
+ if (ret[3]) {
440
+ ptr3 = 0; len3 = 0;
441
+ throw takeFromExternrefTable0(ret[2]);
442
+ }
443
+ deferred4_0 = ptr3;
444
+ deferred4_1 = len3;
445
+ return getStringFromWasm0(ptr3, len3);
446
+ } finally {
447
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
448
+ }
449
+ }
450
+
451
+ /**
452
+ * Generates a 32-byte Ed25519 secret key from `crypto.getRandomValues`.
453
+ * @returns {Uint8Array}
454
+ */
455
+ export function generateSecretKey() {
456
+ const ret = wasm.generateSecretKey();
457
+ if (ret[3]) {
458
+ throw takeFromExternrefTable0(ret[2]);
459
+ }
460
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
461
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
462
+ return v1;
463
+ }
464
+
465
+ /**
466
+ * Derives a peer ID from raw Ed25519 secret key material.
467
+ * @param {Uint8Array} secret_key
468
+ * @returns {string}
469
+ */
470
+ export function peerIdFromSecretKey(secret_key) {
471
+ let deferred3_0;
472
+ let deferred3_1;
473
+ try {
474
+ const ptr0 = passArray8ToWasm0(secret_key, wasm.__wbindgen_malloc);
475
+ const len0 = WASM_VECTOR_LEN;
476
+ const ret = wasm.peerIdFromSecretKey(ptr0, len0);
477
+ var ptr2 = ret[0];
478
+ var len2 = ret[1];
479
+ if (ret[3]) {
480
+ ptr2 = 0; len2 = 0;
481
+ throw takeFromExternrefTable0(ret[2]);
482
+ }
483
+ deferred3_0 = ptr2;
484
+ deferred3_1 = len2;
485
+ return getStringFromWasm0(ptr2, len2);
486
+ } finally {
487
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
488
+ }
489
+ }
490
+ function __wbg_get_imports() {
491
+ const import0 = {
492
+ __proto__: null,
493
+ __wbg_Error_67e7344beaa85059: function(arg0, arg1) {
494
+ const ret = Error(getStringFromWasm0(arg0, arg1));
495
+ return ret;
496
+ },
497
+ __wbg_Number_c54e7112a3fa7e3e: function(arg0) {
498
+ const ret = Number(arg0);
499
+ return ret;
500
+ },
501
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
502
+ const ret = String(arg1);
503
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
504
+ const len1 = WASM_VECTOR_LEN;
505
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
506
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
507
+ },
508
+ __wbg___wbindgen_bigint_get_as_i64_b482365c149396c8: function(arg0, arg1) {
509
+ const v = arg1;
510
+ const ret = typeof(v) === 'bigint' ? v : undefined;
511
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
512
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
513
+ },
514
+ __wbg___wbindgen_boolean_get_7a12af2b3f899c5a: function(arg0) {
515
+ const v = arg0;
516
+ const ret = typeof(v) === 'boolean' ? v : undefined;
517
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
518
+ },
519
+ __wbg___wbindgen_debug_string_0e68cf47c9cbd9b0: function(arg0, arg1) {
520
+ const ret = debugString(arg1);
521
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
522
+ const len1 = WASM_VECTOR_LEN;
523
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
524
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
525
+ },
526
+ __wbg___wbindgen_in_50072d4d6e45c193: function(arg0, arg1) {
527
+ const ret = arg0 in arg1;
528
+ return ret;
529
+ },
530
+ __wbg___wbindgen_is_bigint_60fc0336cb14f5d7: function(arg0) {
531
+ const ret = typeof(arg0) === 'bigint';
532
+ return ret;
533
+ },
534
+ __wbg___wbindgen_is_function_fcda5e3902d732fe: function(arg0) {
535
+ const ret = typeof(arg0) === 'function';
536
+ return ret;
537
+ },
538
+ __wbg___wbindgen_is_null_5160b3e381865372: function(arg0) {
539
+ const ret = arg0 === null;
540
+ return ret;
541
+ },
542
+ __wbg___wbindgen_is_object_edb6b15aa3afe12e: function(arg0) {
543
+ const val = arg0;
544
+ const ret = typeof(val) === 'object' && val !== null;
545
+ return ret;
546
+ },
547
+ __wbg___wbindgen_is_undefined_8c687d0b90d5b524: function(arg0) {
548
+ const ret = arg0 === undefined;
549
+ return ret;
550
+ },
551
+ __wbg___wbindgen_jsval_eq_9fdcd3c0a860dd3b: function(arg0, arg1) {
552
+ const ret = arg0 === arg1;
553
+ return ret;
554
+ },
555
+ __wbg___wbindgen_jsval_loose_eq_3c30021c243b64cd: function(arg0, arg1) {
556
+ const ret = arg0 == arg1;
557
+ return ret;
558
+ },
559
+ __wbg___wbindgen_number_get_1dc732b810cb937c: function(arg0, arg1) {
560
+ const obj = arg1;
561
+ const ret = typeof(obj) === 'number' ? obj : undefined;
562
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
563
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
564
+ },
565
+ __wbg___wbindgen_string_get_92ab86bb19cbc12f: function(arg0, arg1) {
566
+ const obj = arg1;
567
+ const ret = typeof(obj) === 'string' ? obj : undefined;
568
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
569
+ var len1 = WASM_VECTOR_LEN;
570
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
571
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
572
+ },
573
+ __wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
574
+ throw new Error(getStringFromWasm0(arg0, arg1));
575
+ },
576
+ __wbg_call_269c5566fbede3eb: function() { return handleError(function (arg0, arg1) {
577
+ const ret = arg0.call(arg1);
578
+ return ret;
579
+ }, arguments); },
580
+ __wbg_closeWrite_564579d75455787e: function(arg0, arg1) {
581
+ arg0.closeWrite(arg1 >>> 0);
582
+ },
583
+ __wbg_close_5a09eeabaf759d61: function(arg0, arg1, arg2, arg3, arg4) {
584
+ arg0.close(arg1 >>> 0, arg2 >>> 0, getStringFromWasm0(arg3, arg4));
585
+ },
586
+ __wbg_connect_1a5ece271582f806: function() { return handleError(function (arg0, arg1, arg2, arg3) {
587
+ const ret = arg0.connect(getStringFromWasm0(arg1, arg2), arg3);
588
+ return ret;
589
+ }, arguments); },
590
+ __wbg_done_cffed884d87aa22e: function(arg0) {
591
+ const ret = arg0.done;
592
+ return ret;
593
+ },
594
+ __wbg_entries_972a87586902cf87: function(arg0) {
595
+ const ret = Object.entries(arg0);
596
+ return ret;
597
+ },
598
+ __wbg_from_a39669ce566077da: function(arg0) {
599
+ const ret = Array.from(arg0);
600
+ return ret;
601
+ },
602
+ __wbg_getRandomValues_436a51d0629d84e1: function() { return handleError(function (arg0, arg1) {
603
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
604
+ }, arguments); },
605
+ __wbg_get_6cf5a4d4d8ad3c5a: function() { return handleError(function (arg0, arg1) {
606
+ const ret = Reflect.get(arg0, arg1);
607
+ return ret;
608
+ }, arguments); },
609
+ __wbg_get_b1f0ab13c737f856: function(arg0, arg1) {
610
+ const ret = arg0[arg1 >>> 0];
611
+ return ret;
612
+ },
613
+ __wbg_get_unchecked_363572bdd397d473: function(arg0, arg1) {
614
+ const ret = arg0[arg1 >>> 0];
615
+ return ret;
616
+ },
617
+ __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
618
+ const ret = arg0[arg1];
619
+ return ret;
620
+ },
621
+ __wbg_grantRead_5663121533a592a7: function(arg0, arg1, arg2) {
622
+ arg0.grantRead(arg1 >>> 0, arg2 >>> 0);
623
+ },
624
+ __wbg_instanceof_ArrayBuffer_d4ff01f8247925ae: function(arg0) {
625
+ let result;
626
+ try {
627
+ result = arg0 instanceof ArrayBuffer;
628
+ } catch (_) {
629
+ result = false;
630
+ }
631
+ const ret = result;
632
+ return ret;
633
+ },
634
+ __wbg_instanceof_Error_fe6fa771c78ee4cf: function(arg0) {
635
+ let result;
636
+ try {
637
+ result = arg0 instanceof Error;
638
+ } catch (_) {
639
+ result = false;
640
+ }
641
+ const ret = result;
642
+ return ret;
643
+ },
644
+ __wbg_instanceof_Map_1ff6a2b54c899f0d: function(arg0) {
645
+ let result;
646
+ try {
647
+ result = arg0 instanceof Map;
648
+ } catch (_) {
649
+ result = false;
650
+ }
651
+ const ret = result;
652
+ return ret;
653
+ },
654
+ __wbg_instanceof_Uint8Array_598adc0fef426aa8: function(arg0) {
655
+ let result;
656
+ try {
657
+ result = arg0 instanceof Uint8Array;
658
+ } catch (_) {
659
+ result = false;
660
+ }
661
+ const ret = result;
662
+ return ret;
663
+ },
664
+ __wbg_isArray_5674713bb7b79043: function(arg0) {
665
+ const ret = Array.isArray(arg0);
666
+ return ret;
667
+ },
668
+ __wbg_isSafeInteger_8f51c743827d1ec5: function(arg0) {
669
+ const ret = Number.isSafeInteger(arg0);
670
+ return ret;
671
+ },
672
+ __wbg_iterator_22ddeb808cf55a6f: function() {
673
+ const ret = Symbol.iterator;
674
+ return ret;
675
+ },
676
+ __wbg_length_31bdaf014f5fbde2: function(arg0) {
677
+ const ret = arg0.length;
678
+ return ret;
679
+ },
680
+ __wbg_length_4e1adc0d42e23620: function(arg0) {
681
+ const ret = arg0.length;
682
+ return ret;
683
+ },
684
+ __wbg_message_1cbc5bc03dcf1dee: function(arg0) {
685
+ const ret = arg0.message;
686
+ return ret;
687
+ },
688
+ __wbg_new_1da3429bc3c4541c: function(arg0) {
689
+ const ret = new Uint8Array(arg0);
690
+ return ret;
691
+ },
692
+ __wbg_new_a32a1ab6c6655abe: function(arg0, arg1) {
693
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
694
+ return ret;
695
+ },
696
+ __wbg_new_bebc3f4757acf305: function() {
697
+ const ret = new Object();
698
+ return ret;
699
+ },
700
+ __wbg_new_ffa92086ea89f79c: function() {
701
+ const ret = new Array();
702
+ return ret;
703
+ },
704
+ __wbg_new_from_slice_4ee02165f9de919e: function(arg0, arg1) {
705
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
706
+ return ret;
707
+ },
708
+ __wbg_next_95053e306b1c3aed: function(arg0) {
709
+ const ret = arg0.next;
710
+ return ret;
711
+ },
712
+ __wbg_next_f31ecb8646d2c605: function() { return handleError(function (arg0) {
713
+ const ret = arg0.next();
714
+ return ret;
715
+ }, arguments); },
716
+ __wbg_now_8566e3387c4ceb67: function() {
717
+ const ret = performance.now();
718
+ return ret;
719
+ },
720
+ __wbg_now_d1fb6650485d7f3e: function() {
721
+ const ret = Date.now();
722
+ return ret;
723
+ },
724
+ __wbg_openStream_1acee348e26ae2b0: function() { return handleError(function (arg0, arg1) {
725
+ const ret = arg0.openStream(arg1 >>> 0);
726
+ return ret;
727
+ }, arguments); },
728
+ __wbg_pollEvent_4d65f1beb4fa76e3: function(arg0) {
729
+ const ret = arg0.pollEvent();
730
+ return ret;
731
+ },
732
+ __wbg_prototypesetcall_ae9f5e7459250748: function(arg0, arg1, arg2) {
733
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
734
+ },
735
+ __wbg_push_bfdf956ba476f65b: function(arg0, arg1) {
736
+ const ret = arg0.push(arg1);
737
+ return ret;
738
+ },
739
+ __wbg_reset_c0af0a71d17af46f: function(arg0, arg1, arg2) {
740
+ arg0.reset(arg1 >>> 0, arg2);
741
+ },
742
+ __wbg_set_13d25b81ab403f5e: function(arg0, arg1, arg2) {
743
+ arg0[arg1 >>> 0] = arg2;
744
+ },
745
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
746
+ arg0[arg1] = arg2;
747
+ },
748
+ __wbg_set_a377297433dfea63: function() { return handleError(function (arg0, arg1, arg2) {
749
+ const ret = Reflect.set(arg0, arg1, arg2);
750
+ return ret;
751
+ }, arguments); },
752
+ __wbg_value_c227f843d21da141: function(arg0) {
753
+ const ret = arg0.value;
754
+ return ret;
755
+ },
756
+ __wbg_write_34afb8e3d5faa499: function() { return handleError(function (arg0, arg1, arg2, arg3) {
757
+ const ret = arg0.write(arg1 >>> 0, getArrayU8FromWasm0(arg2, arg3));
758
+ return ret;
759
+ }, arguments); },
760
+ __wbindgen_generic_0000000000000001: function(arg0) {
761
+ // Cast intrinsic for `F64 -> Externref`.
762
+ const ret = arg0;
763
+ return ret;
764
+ },
765
+ __wbindgen_generic_0000000000000002: function(arg0) {
766
+ // Cast intrinsic for `I64 -> Externref`.
767
+ const ret = arg0;
768
+ return ret;
769
+ },
770
+ __wbindgen_generic_0000000000000003: function(arg0, arg1) {
771
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
772
+ const ret = getArrayU8FromWasm0(arg0, arg1);
773
+ return ret;
774
+ },
775
+ __wbindgen_generic_0000000000000004: function(arg0, arg1) {
776
+ // Cast intrinsic for `Ref(String) -> Externref`.
777
+ const ret = getStringFromWasm0(arg0, arg1);
778
+ return ret;
779
+ },
780
+ __wbindgen_generic_0000000000000005: function(arg0) {
781
+ // Cast intrinsic for `U64 -> Externref`.
782
+ const ret = BigInt.asUintN(64, arg0);
783
+ return ret;
784
+ },
785
+ __wbindgen_init_externref_table: function() {
786
+ const table = wasm.__wbindgen_externrefs;
787
+ const offset = table.grow(4);
788
+ table.set(0, undefined);
789
+ table.set(offset + 0, undefined);
790
+ table.set(offset + 1, null);
791
+ table.set(offset + 2, true);
792
+ table.set(offset + 3, false);
793
+ },
794
+ };
795
+ return {
796
+ __proto__: null,
797
+ "./minip2p_web_bg.js": import0,
798
+ };
799
+ }
800
+
801
+ const WebEndpointFinalization = (typeof FinalizationRegistry === 'undefined')
802
+ ? { register: () => {}, unregister: () => {} }
803
+ : new FinalizationRegistry(ptr => wasm.__wbg_webendpoint_free(ptr, 1));
804
+
805
+ function addToExternrefTable0(obj) {
806
+ const idx = wasm.__externref_table_alloc();
807
+ wasm.__wbindgen_externrefs.set(idx, obj);
808
+ return idx;
809
+ }
810
+
811
+ function debugString(val) {
812
+ // primitive types
813
+ const type = typeof val;
814
+ if (type == 'number' || type == 'boolean' || val == null) {
815
+ return `${val}`;
816
+ }
817
+ if (type == 'string') {
818
+ return `"${val}"`;
819
+ }
820
+ if (type == 'symbol') {
821
+ const description = val.description;
822
+ if (description == null) {
823
+ return 'Symbol';
824
+ } else {
825
+ return `Symbol(${description})`;
826
+ }
827
+ }
828
+ if (type == 'function') {
829
+ const name = val.name;
830
+ if (typeof name == 'string' && name.length > 0) {
831
+ return `Function(${name})`;
832
+ } else {
833
+ return 'Function';
834
+ }
835
+ }
836
+ // objects
837
+ if (Array.isArray(val)) {
838
+ const length = val.length;
839
+ let debug = '[';
840
+ if (length > 0) {
841
+ debug += debugString(val[0]);
842
+ }
843
+ for(let i = 1; i < length; i++) {
844
+ debug += ', ' + debugString(val[i]);
845
+ }
846
+ debug += ']';
847
+ return debug;
848
+ }
849
+ // Test for built-in
850
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
851
+ let className;
852
+ if (builtInMatches && builtInMatches.length > 1) {
853
+ className = builtInMatches[1];
854
+ } else {
855
+ // Failed to match the standard '[object ClassName]'
856
+ return toString.call(val);
857
+ }
858
+ if (className == 'Object') {
859
+ // we're a user defined class or Object
860
+ // JSON.stringify avoids problems with cycles, and is generally much
861
+ // easier than looping through ownProperties of `val`.
862
+ try {
863
+ return 'Object(' + JSON.stringify(val) + ')';
864
+ } catch (_) {
865
+ return 'Object';
866
+ }
867
+ }
868
+ // errors
869
+ if (val instanceof Error) {
870
+ return `${val.name}: ${val.message}\n${val.stack}`;
871
+ }
872
+ // TODO we could test for more things here, like `Set`s and `Map`s.
873
+ return className;
874
+ }
875
+
876
+ function getArrayJsValueFromWasm0(ptr, len) {
877
+ ptr = ptr >>> 0;
878
+ const mem = getDataViewMemory0();
879
+ const result = [];
880
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
881
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
882
+ }
883
+ wasm.__externref_drop_slice(ptr, len);
884
+ return result;
885
+ }
886
+
887
+ function getArrayU8FromWasm0(ptr, len) {
888
+ ptr = ptr >>> 0;
889
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
890
+ }
891
+
892
+ let cachedDataViewMemory0 = null;
893
+ function getDataViewMemory0() {
894
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
895
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
896
+ }
897
+ return cachedDataViewMemory0;
898
+ }
899
+
900
+ function getStringFromWasm0(ptr, len) {
901
+ return decodeText(ptr >>> 0, len);
902
+ }
903
+
904
+ let cachedUint8ArrayMemory0 = null;
905
+ function getUint8ArrayMemory0() {
906
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
907
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
908
+ }
909
+ return cachedUint8ArrayMemory0;
910
+ }
911
+
912
+ function handleError(f, args) {
913
+ try {
914
+ return f.apply(this, args);
915
+ } catch (e) {
916
+ const idx = addToExternrefTable0(e);
917
+ wasm.__wbindgen_exn_store(idx);
918
+ }
919
+ }
920
+
921
+ function isLikeNone(x) {
922
+ return x === undefined || x === null;
923
+ }
924
+
925
+ function passArray8ToWasm0(arg, malloc) {
926
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
927
+ getUint8ArrayMemory0().set(arg, ptr / 1);
928
+ WASM_VECTOR_LEN = arg.length;
929
+ return ptr;
930
+ }
931
+
932
+ function passStringToWasm0(arg, malloc, realloc) {
933
+ if (realloc === undefined) {
934
+ const buf = cachedTextEncoder.encode(arg);
935
+ const ptr = malloc(buf.length, 1) >>> 0;
936
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
937
+ WASM_VECTOR_LEN = buf.length;
938
+ return ptr;
939
+ }
940
+
941
+ let len = arg.length;
942
+ let ptr = malloc(len, 1) >>> 0;
943
+
944
+ const mem = getUint8ArrayMemory0();
945
+
946
+ let offset = 0;
947
+
948
+ for (; offset < len; offset++) {
949
+ const code = arg.charCodeAt(offset);
950
+ if (code > 0x7F) break;
951
+ mem[ptr + offset] = code;
952
+ }
953
+ if (offset !== len) {
954
+ if (offset !== 0) {
955
+ arg = arg.slice(offset);
956
+ }
957
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
958
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
959
+ const ret = cachedTextEncoder.encodeInto(arg, view);
960
+
961
+ offset += ret.written;
962
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
963
+ }
964
+
965
+ WASM_VECTOR_LEN = offset;
966
+ return ptr;
967
+ }
968
+
969
+ function takeFromExternrefTable0(idx) {
970
+ const value = wasm.__wbindgen_externrefs.get(idx);
971
+ wasm.__externref_table_dealloc(idx);
972
+ return value;
973
+ }
974
+
975
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
976
+ cachedTextDecoder.decode();
977
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
978
+ let numBytesDecoded = 0;
979
+ function decodeText(ptr, len) {
980
+ numBytesDecoded += len;
981
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
982
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
983
+ cachedTextDecoder.decode();
984
+ numBytesDecoded = len;
985
+ }
986
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
987
+ }
988
+
989
+ const cachedTextEncoder = new TextEncoder();
990
+
991
+ if (!('encodeInto' in cachedTextEncoder)) {
992
+ cachedTextEncoder.encodeInto = function (arg, view) {
993
+ const buf = cachedTextEncoder.encode(arg);
994
+ view.set(buf);
995
+ return {
996
+ read: arg.length,
997
+ written: buf.length
998
+ };
999
+ };
1000
+ }
1001
+
1002
+ let WASM_VECTOR_LEN = 0;
1003
+
1004
+ let wasmModule, wasmInstance, wasm;
1005
+ function __wbg_finalize_init(instance, module) {
1006
+ wasmInstance = instance;
1007
+ wasm = instance.exports;
1008
+ wasmModule = module;
1009
+ cachedDataViewMemory0 = null;
1010
+ cachedUint8ArrayMemory0 = null;
1011
+ wasm.__wbindgen_start();
1012
+ return wasm;
1013
+ }
1014
+
1015
+ async function __wbg_load(module, imports) {
1016
+ if (typeof Response === 'function' && module instanceof Response) {
1017
+ if (!module.ok) {
1018
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
1019
+ }
1020
+
1021
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
1022
+ try {
1023
+ return await WebAssembly.instantiateStreaming(module, imports);
1024
+ } catch (e) {
1025
+ const validResponse = expectedResponseType(module.type);
1026
+
1027
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1028
+ 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);
1029
+
1030
+ } else { throw e; }
1031
+ }
1032
+ }
1033
+
1034
+ const bytes = await module.arrayBuffer();
1035
+ return await WebAssembly.instantiate(bytes, imports);
1036
+ } else {
1037
+ const instance = await WebAssembly.instantiate(module, imports);
1038
+
1039
+ if (instance instanceof WebAssembly.Instance) {
1040
+ return { instance, module };
1041
+ } else {
1042
+ return instance;
1043
+ }
1044
+ }
1045
+
1046
+ function expectedResponseType(type) {
1047
+ switch (type) {
1048
+ case 'basic': case 'cors': case 'default': return true;
1049
+ }
1050
+ return false;
1051
+ }
1052
+ }
1053
+
1054
+ function initSync(module) {
1055
+ if (wasm !== undefined) return wasm;
1056
+
1057
+
1058
+ if (module !== undefined) {
1059
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1060
+ ({module} = module)
1061
+ } else {
1062
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1063
+ }
1064
+ }
1065
+
1066
+ const imports = __wbg_get_imports();
1067
+ if (!(module instanceof WebAssembly.Module)) {
1068
+ module = new WebAssembly.Module(module);
1069
+ }
1070
+ const instance = new WebAssembly.Instance(module, imports);
1071
+ return __wbg_finalize_init(instance, module);
1072
+ }
1073
+
1074
+ async function __wbg_init(module_or_path) {
1075
+ if (wasm !== undefined) return wasm;
1076
+
1077
+
1078
+ if (module_or_path !== undefined) {
1079
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1080
+ ({module_or_path} = module_or_path)
1081
+ } else {
1082
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1083
+ }
1084
+ }
1085
+
1086
+ if (module_or_path === undefined) {
1087
+ module_or_path = new URL('minip2p_web_bg.wasm', import.meta.url);
1088
+ }
1089
+ const imports = __wbg_get_imports();
1090
+
1091
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1092
+ module_or_path = fetch(module_or_path);
1093
+ }
1094
+
1095
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1096
+
1097
+ return __wbg_finalize_init(instance, module);
1098
+ }
1099
+
1100
+ export { initSync, __wbg_init as default };