@synonymdev/pubky 0.5.2 → 0.6.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. package/README.md +193 -159
  2. package/index.cjs +1582 -401
  3. package/index.js +1680 -468
  4. package/package.json +3 -2
  5. package/pubky.d.ts +821 -0
  6. package/pubky_bg.wasm +0 -0
package/index.cjs CHANGED
@@ -9,10 +9,6 @@ imports['__wbindgen_placeholder__'] = module.exports;
9
9
  let wasm;
10
10
  const { TextDecoder, TextEncoder } = require(`util`);
11
11
 
12
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
13
-
14
- cachedTextDecoder.decode();
15
-
16
12
  let cachedUint8ArrayMemory0 = null;
17
13
 
18
14
  function getUint8ArrayMemory0() {
@@ -22,38 +18,22 @@ function getUint8ArrayMemory0() {
22
18
  return cachedUint8ArrayMemory0;
23
19
  }
24
20
 
25
- function getStringFromWasm0(ptr, len) {
26
- ptr = ptr >>> 0;
27
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
28
- }
21
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
29
22
 
30
- function addToExternrefTable0(obj) {
31
- const idx = wasm.__externref_table_alloc();
32
- wasm.__wbindgen_export_2.set(idx, obj);
33
- return idx;
34
- }
23
+ cachedTextDecoder.decode();
35
24
 
36
- function handleError(f, args) {
37
- try {
38
- return f.apply(this, args);
39
- } catch (e) {
40
- const idx = addToExternrefTable0(e);
41
- wasm.__wbindgen_exn_store(idx);
42
- }
25
+ function decodeText(ptr, len) {
26
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
43
27
  }
44
28
 
45
- function getArrayU8FromWasm0(ptr, len) {
29
+ function getStringFromWasm0(ptr, len) {
46
30
  ptr = ptr >>> 0;
47
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
48
- }
49
-
50
- function isLikeNone(x) {
51
- return x === undefined || x === null;
31
+ return decodeText(ptr, len);
52
32
  }
53
33
 
54
34
  let WASM_VECTOR_LEN = 0;
55
35
 
56
- let cachedTextEncoder = new TextEncoder('utf-8');
36
+ const cachedTextEncoder = new TextEncoder('utf-8');
57
37
 
58
38
  const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
59
39
  ? function (arg, view) {
@@ -116,6 +96,30 @@ function getDataViewMemory0() {
116
96
  return cachedDataViewMemory0;
117
97
  }
118
98
 
99
+ function addToExternrefTable0(obj) {
100
+ const idx = wasm.__externref_table_alloc();
101
+ wasm.__wbindgen_export_4.set(idx, obj);
102
+ return idx;
103
+ }
104
+
105
+ function handleError(f, args) {
106
+ try {
107
+ return f.apply(this, args);
108
+ } catch (e) {
109
+ const idx = addToExternrefTable0(e);
110
+ wasm.__wbindgen_exn_store(idx);
111
+ }
112
+ }
113
+
114
+ function getArrayU8FromWasm0(ptr, len) {
115
+ ptr = ptr >>> 0;
116
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
117
+ }
118
+
119
+ function isLikeNone(x) {
120
+ return x === undefined || x === null;
121
+ }
122
+
119
123
  const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
120
124
  ? { register: () => {}, unregister: () => {} }
121
125
  : new FinalizationRegistry(state => {
@@ -212,42 +216,17 @@ function debugString(val) {
212
216
  return className;
213
217
  }
214
218
 
215
- function takeFromExternrefTable0(idx) {
216
- const value = wasm.__wbindgen_export_2.get(idx);
217
- wasm.__externref_table_dealloc(idx);
218
- return value;
219
- }
220
- /**
221
- * @param {string} level
222
- */
223
- module.exports.setLogLevel = function(level) {
224
- const ptr0 = passStringToWasm0(level, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
225
- const len0 = WASM_VECTOR_LEN;
226
- const ret = wasm.setLogLevel(ptr0, len0);
227
- if (ret[1]) {
228
- throw takeFromExternrefTable0(ret[0]);
229
- }
230
- };
231
-
232
219
  function _assertClass(instance, klass) {
233
220
  if (!(instance instanceof klass)) {
234
221
  throw new Error(`expected instance of ${klass.name}`);
235
222
  }
236
223
  }
237
- /**
238
- * Create a recovery file of the `keypair`, containing the secret key encrypted
239
- * using the `passphrase`.
240
- * @param {Keypair} keypair
241
- * @param {string} passphrase
242
- * @returns {Uint8Array}
243
- */
244
- module.exports.createRecoveryFile = function(keypair, passphrase) {
245
- _assertClass(keypair, Keypair);
246
- const ptr0 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
247
- const len0 = WASM_VECTOR_LEN;
248
- const ret = wasm.createRecoveryFile(keypair.__wbg_ptr, ptr0, len0);
249
- return ret;
250
- };
224
+
225
+ function takeFromExternrefTable0(idx) {
226
+ const value = wasm.__wbindgen_export_4.get(idx);
227
+ wasm.__externref_table_dealloc(idx);
228
+ return value;
229
+ }
251
230
 
252
231
  function passArray8ToWasm0(arg, malloc) {
253
232
  const ptr = malloc(arg.length * 1, 1) >>> 0;
@@ -255,88 +234,185 @@ function passArray8ToWasm0(arg, malloc) {
255
234
  WASM_VECTOR_LEN = arg.length;
256
235
  return ptr;
257
236
  }
258
- /**
259
- * Create a recovery file of the `keypair`, containing the secret key encrypted
260
- * using the `passphrase`.
261
- * @param {Uint8Array} recovery_file
262
- * @param {string} passphrase
263
- * @returns {Keypair}
264
- */
265
- module.exports.decryptRecoveryFile = function(recovery_file, passphrase) {
266
- const ptr0 = passArray8ToWasm0(recovery_file, wasm.__wbindgen_malloc);
267
- const len0 = WASM_VECTOR_LEN;
268
- const ptr1 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
269
- const len1 = WASM_VECTOR_LEN;
270
- const ret = wasm.decryptRecoveryFile(ptr0, len0, ptr1, len1);
271
- if (ret[2]) {
272
- throw takeFromExternrefTable0(ret[1]);
273
- }
274
- return Keypair.__wrap(ret[0]);
275
- };
276
237
 
277
238
  function getArrayJsValueFromWasm0(ptr, len) {
278
239
  ptr = ptr >>> 0;
279
240
  const mem = getDataViewMemory0();
280
241
  const result = [];
281
242
  for (let i = ptr; i < ptr + 4 * len; i += 4) {
282
- result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true)));
243
+ result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
283
244
  }
284
245
  wasm.__externref_drop_slice(ptr, len);
285
246
  return result;
286
247
  }
287
- function __wbg_adapter_28(arg0, arg1) {
288
- wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h76b7e185a7848c9a(arg0, arg1);
248
+ /**
249
+ * Set the global logging verbosity for the WASM Pubky SDK. Routes Rust `log` output to the browser console.
250
+ *
251
+ * Accepted values (case-insensitive): "error" | "warn" | "info" | "debug" | "trace".
252
+ * Effects:
253
+ * - Initializes the logger once; subsequent calls may throw if the logger is already set.
254
+ * - Emits a single info log: `Log level set to: <level>`.
255
+ * - Messages at or above `level` are forwarded to the appropriate `console.*` method.
256
+ *
257
+ * @param {string} level
258
+ * Minimum log level to enable. One of: "error" | "warn" | "info" | "debug" | "trace".
259
+ *
260
+ * @returns {void}
261
+ *
262
+ * @throws {Error}
263
+ * If `level` is invalid ("Invalid log level") or the logger cannot be initialized
264
+ * (e.g., already initialized).
265
+ *
266
+ * Usage:
267
+ * Call once at application startup, before invoking other SDK APIs.
268
+ * @param {string} level
269
+ */
270
+ module.exports.setLogLevel = function(level) {
271
+ const ptr0 = passStringToWasm0(level, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
272
+ const len0 = WASM_VECTOR_LEN;
273
+ const ret = wasm.setLogLevel(ptr0, len0);
274
+ if (ret[1]) {
275
+ throw takeFromExternrefTable0(ret[0]);
276
+ }
277
+ };
278
+
279
+ /**
280
+ * Validate and normalize a capabilities string.
281
+ *
282
+ * - Normalizes action order (`wr` -> `rw`)
283
+ * - Throws `InvalidInput` listing malformed entries.
284
+ *
285
+ * @param {string} input
286
+ * @returns {string} Normalized string (same shape as input).
287
+ * @throws {PubkyJsError} `{ name: "InvalidInput" }` with a helpful message.
288
+ * @param {string} input
289
+ * @returns {string}
290
+ */
291
+ module.exports.validateCapabilities = function(input) {
292
+ let deferred3_0;
293
+ let deferred3_1;
294
+ try {
295
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
296
+ const len0 = WASM_VECTOR_LEN;
297
+ const ret = wasm.validateCapabilities(ptr0, len0);
298
+ var ptr2 = ret[0];
299
+ var len2 = ret[1];
300
+ if (ret[3]) {
301
+ ptr2 = 0; len2 = 0;
302
+ throw takeFromExternrefTable0(ret[2]);
303
+ }
304
+ deferred3_0 = ptr2;
305
+ deferred3_1 = len2;
306
+ return getStringFromWasm0(ptr2, len2);
307
+ } finally {
308
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
309
+ }
310
+ };
311
+
312
+ function __wbg_adapter_54(arg0, arg1) {
313
+ wasm.wasm_bindgen__convert__closures_____invoke__h1ed9ddf46f2cacfa(arg0, arg1);
289
314
  }
290
315
 
291
- function __wbg_adapter_31(arg0, arg1, arg2) {
292
- wasm.closure650_externref_shim(arg0, arg1, arg2);
316
+ function __wbg_adapter_57(arg0, arg1, arg2) {
317
+ wasm.closure170_externref_shim(arg0, arg1, arg2);
293
318
  }
294
319
 
295
- function __wbg_adapter_167(arg0, arg1, arg2, arg3) {
296
- wasm.closure767_externref_shim(arg0, arg1, arg2, arg3);
320
+ function __wbg_adapter_120(arg0, arg1, arg2, arg3) {
321
+ wasm.closure74_externref_shim(arg0, arg1, arg2, arg3);
297
322
  }
298
323
 
324
+ const __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
325
+
299
326
  const __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
300
327
 
301
328
  const __wbindgen_enum_RequestMode = ["same-origin", "no-cors", "cors", "navigate"];
302
329
 
303
- const AuthRequestFinalization = (typeof FinalizationRegistry === 'undefined')
330
+ const AuthFlowFinalization = (typeof FinalizationRegistry === 'undefined')
304
331
  ? { register: () => {}, unregister: () => {} }
305
- : new FinalizationRegistry(ptr => wasm.__wbg_authrequest_free(ptr >>> 0, 1));
306
-
307
- class AuthRequest {
332
+ : new FinalizationRegistry(ptr => wasm.__wbg_authflow_free(ptr >>> 0, 1));
333
+ /**
334
+ * Start and control a pubkyauth authorization flow.
335
+ *
336
+ * Typical flow:
337
+ * 1) `AuthFlow.start(...)` or `pubky.startAuthFlow(...)`
338
+ * 2) Show `authorizationUrl()` as QR/deeplink to the user’s signing device
339
+ * 3) `awaitApproval()` to receive a ready `Session`
340
+ */
341
+ class AuthFlow {
308
342
 
309
343
  static __wrap(ptr) {
310
344
  ptr = ptr >>> 0;
311
- const obj = Object.create(AuthRequest.prototype);
345
+ const obj = Object.create(AuthFlow.prototype);
312
346
  obj.__wbg_ptr = ptr;
313
- AuthRequestFinalization.register(obj, obj.__wbg_ptr, obj);
347
+ AuthFlowFinalization.register(obj, obj.__wbg_ptr, obj);
314
348
  return obj;
315
349
  }
316
350
 
317
351
  __destroy_into_raw() {
318
352
  const ptr = this.__wbg_ptr;
319
353
  this.__wbg_ptr = 0;
320
- AuthRequestFinalization.unregister(this);
354
+ AuthFlowFinalization.unregister(this);
321
355
  return ptr;
322
356
  }
323
357
 
324
358
  free() {
325
359
  const ptr = this.__destroy_into_raw();
326
- wasm.__wbg_authrequest_free(ptr, 0);
360
+ wasm.__wbg_authflow_free(ptr, 0);
361
+ }
362
+ /**
363
+ * Start a flow (standalone).
364
+ * Prefer `pubky.startAuthFlow()` to reuse a façade client.
365
+ *
366
+ * @param {string} capabilities
367
+ * Comma-separated capabilities, e.g. `"/pub/app/:rw,/priv/foo.txt:r"`.
368
+ * Each entry must be `"<scope>:<actions>"`, where:
369
+ * - `scope` starts with `/` (e.g. `/pub/example.app/`)
370
+ * - `actions` is any combo of `r` and/or `w` (order is normalized; `wr` -> `rw`)
371
+ * Empty string is allowed (no scopes).
372
+ *
373
+ * @param {string} [relay]
374
+ * Optional HTTP relay base, e.g. `"https://demo.httprelay.io/link/"`.
375
+ * Defaults to the default Synonym-hosted relay when omitted.
376
+ *
377
+ * @returns {AuthFlow}
378
+ * A running auth flow. Call `authorizationUrl()` to show the deep link,
379
+ * then `awaitApproval()` to receive a `Session`.
380
+ * @throws {PubkyJsError}
381
+ * - `{ name: "InvalidInput", message: string }` if any capability entry is invalid
382
+ * or for an invalid relay URL.
383
+ * @example
384
+ * const flow = AuthFlow.start("/pub/my.app/:rw,/pub/pubky.app/:w");
385
+ * renderQRCode(flow.authorizationUrl());
386
+ * const session = await flow.awaitApproval();
387
+ * @param {string} capabilities
388
+ * @param {string | null} [relay]
389
+ * @returns {AuthFlow}
390
+ */
391
+ static start(capabilities, relay) {
392
+ const ptr0 = passStringToWasm0(capabilities, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
393
+ const len0 = WASM_VECTOR_LEN;
394
+ var ptr1 = isLikeNone(relay) ? 0 : passStringToWasm0(relay, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
395
+ var len1 = WASM_VECTOR_LEN;
396
+ const ret = wasm.authflow_start(ptr0, len0, ptr1, len1);
397
+ if (ret[2]) {
398
+ throw takeFromExternrefTable0(ret[1]);
399
+ }
400
+ return AuthFlow.__wrap(ret[0]);
327
401
  }
328
402
  /**
329
- * Returns the Pubky Auth url, which you should show to the user
330
- * to request an authentication or authorization token.
403
+ * Return the authorization deep link (URL) to show as QR or open on the signer device.
404
+ *
405
+ * @returns {string} A `pubkyauth://…` or `https://…` URL with channel info.
331
406
  *
332
- * Wait for this token using `this.response()`.
407
+ * @example
408
+ * renderQr(flow.authorizationUrl());
333
409
  * @returns {string}
334
410
  */
335
- url() {
411
+ authorizationUrl() {
336
412
  let deferred1_0;
337
413
  let deferred1_1;
338
414
  try {
339
- const ret = wasm.authrequest_url(this.__wbg_ptr);
415
+ const ret = wasm.authflow_authorizationUrl(this.__wbg_ptr);
340
416
  deferred1_0 = ret[0];
341
417
  deferred1_1 = ret[1];
342
418
  return getStringFromWasm0(ret[0], ret[1]);
@@ -345,228 +421,300 @@ class AuthRequest {
345
421
  }
346
422
  }
347
423
  /**
348
- * Wait for the user to send an authentication or authorization proof.
424
+ * Block until the user approves on their signer device; returns a `Session`.
425
+ *
426
+ * @returns {Promise<Session>}
427
+ * Resolves when approved; rejects on timeout/cancel/network errors.
428
+ *
429
+ * @throws {PubkyJsError}
430
+ * - `RequestError` if relay/network fails
431
+ * - `AuthenticationError` if approval is denied/invalid
432
+ * @returns {Promise<Session>}
433
+ */
434
+ awaitApproval() {
435
+ const ptr = this.__destroy_into_raw();
436
+ const ret = wasm.authflow_awaitApproval(ptr);
437
+ return ret;
438
+ }
439
+ /**
440
+ * Block until the user approves on their signer device; returns an `AuthToken`.
441
+ *
442
+ * @returns {Promise<AuthToken>}
443
+ * Resolves when approved; rejects on timeout/cancel/network errors.
349
444
  *
350
- * If successful, you should expect an instance of [PublicKey]
445
+ * @throws {PubkyJsError}
446
+ * - `RequestError` if relay/network fails
447
+ * @returns {Promise<AuthToken>}
448
+ */
449
+ awaitToken() {
450
+ const ptr = this.__destroy_into_raw();
451
+ const ret = wasm.authflow_awaitToken(ptr);
452
+ return ret;
453
+ }
454
+ /**
455
+ * Non-blocking single poll step (advanced UIs).
351
456
  *
352
- * Otherwise it will throw an error.
353
- * @returns {Promise<PublicKey>}
457
+ * @returns {Promise<Session|null>} A session if the approval arrived, otherwise `null`.
458
+ * @returns {Promise<Session | undefined>}
354
459
  */
355
- response() {
356
- const ret = wasm.authrequest_response(this.__wbg_ptr);
460
+ tryPollOnce() {
461
+ const ret = wasm.authflow_tryPollOnce(this.__wbg_ptr);
357
462
  return ret;
358
463
  }
359
464
  }
360
- module.exports.AuthRequest = AuthRequest;
465
+ module.exports.AuthFlow = AuthFlow;
361
466
 
362
- const ClientFinalization = (typeof FinalizationRegistry === 'undefined')
467
+ const AuthTokenFinalization = (typeof FinalizationRegistry === 'undefined')
363
468
  ? { register: () => {}, unregister: () => {} }
364
- : new FinalizationRegistry(ptr => wasm.__wbg_client_free(ptr >>> 0, 1));
365
-
366
- class Client {
469
+ : new FinalizationRegistry(ptr => wasm.__wbg_authtoken_free(ptr >>> 0, 1));
470
+ /**
471
+ * AuthToken: signed, time-bound proof of key ownership.
472
+ *
473
+ * Returned by [`AuthFlow.awaitToken()`] on the 3rd-party app side when doing **authentication-only**
474
+ * flows (no homeserver session). You can inspect who authenticated and which capabilities were
475
+ * requested, or serialize the token and send it to a backend to verify.
476
+ *
477
+ * ### Typical usage
478
+ * ```js
479
+ * // Start an auth-only flow (no capabilities)
480
+ * const flow = pubky.startAuthFlow("", relay);
481
+ *
482
+ * // Wait for the signer to approve; returns an AuthToken
483
+ * const token = await flow.awaitToken();
484
+ *
485
+ * // Identify the user
486
+ * console.log(token.publicKey().z32());
487
+ *
488
+ * // Optionally forward to a server for verification:
489
+ * await fetch("/api/verify", { method: "POST", body: token.toBytes() });
490
+ * ```
491
+ *
492
+ * ### Binary format
493
+ * `AuthToken` serializes to a canonical binary (postcard) form; use [`AuthToken.toBytes()`] to get a
494
+ * `Uint8Array`, and [`AuthToken.verify()`] to parse + verify on the server.
495
+ */
496
+ class AuthToken {
367
497
 
368
498
  static __wrap(ptr) {
369
499
  ptr = ptr >>> 0;
370
- const obj = Object.create(Client.prototype);
500
+ const obj = Object.create(AuthToken.prototype);
371
501
  obj.__wbg_ptr = ptr;
372
- ClientFinalization.register(obj, obj.__wbg_ptr, obj);
502
+ AuthTokenFinalization.register(obj, obj.__wbg_ptr, obj);
373
503
  return obj;
374
504
  }
375
505
 
376
506
  __destroy_into_raw() {
377
507
  const ptr = this.__wbg_ptr;
378
508
  this.__wbg_ptr = 0;
379
- ClientFinalization.unregister(this);
509
+ AuthTokenFinalization.unregister(this);
380
510
  return ptr;
381
511
  }
382
512
 
383
513
  free() {
384
514
  const ptr = this.__destroy_into_raw();
385
- wasm.__wbg_client_free(ptr, 0);
515
+ wasm.__wbg_authtoken_free(ptr, 0);
386
516
  }
387
517
  /**
388
- * @param {string} url
389
- * @param {any | null} [init]
390
- * @returns {Promise<Promise<any>>}
518
+ * Parse and verify an `AuthToken` from its canonical bytes.
519
+ *
520
+ * - Verifies version, timestamp freshness window, and signature.
521
+ * - Throws on invalid/expired/unknown version.
522
+ *
523
+ * Use this on your server after receiving `Uint8Array` from the client.
524
+ *
525
+ * ```js
526
+ * import { AuthToken } from "@synonymdev/pubky";
527
+ *
528
+ * export async function POST(req) {
529
+ * const bytes = new Uint8Array(await req.arrayBuffer());
530
+ * const token = AuthToken.verify(bytes); // throws on failure
531
+ * return new Response(token.publicKey().z32(), { status: 200 });
532
+ * }
533
+ * ```
534
+ * @param {Uint8Array} bytes
535
+ * @returns {AuthToken}
391
536
  */
392
- fetch(url, init) {
393
- const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
394
- const len0 = WASM_VECTOR_LEN;
395
- const ret = wasm.client_fetch(this.__wbg_ptr, ptr0, len0, isLikeNone(init) ? 0 : addToExternrefTable0(init));
396
- return ret;
537
+ static verify(bytes) {
538
+ const ret = wasm.authtoken_verify(bytes);
539
+ if (ret[2]) {
540
+ throw takeFromExternrefTable0(ret[1]);
541
+ }
542
+ return AuthToken.__wrap(ret[0]);
397
543
  }
398
544
  /**
399
- * Signup to a homeserver and update Pkarr accordingly.
545
+ * Deserialize an `AuthToken` **without** verification.
400
546
  *
401
- * The homeserver is a Pkarr domain name, where the TLD is a Pkarr public key
402
- * for example "pubky.o4dksfbqk85ogzdb5osziw6befigbuxmuxkuxq8434q89uj56uyy"
403
- * @param {Keypair} keypair
404
- * @param {PublicKey} homeserver
405
- * @param {string | null} [signup_token]
406
- * @returns {Promise<Session>}
547
+ * Most apps should call [`AuthToken.verify()`]. This is provided for tooling or diagnostics
548
+ * where you want to inspect the structure first.
549
+ *
550
+ * Throws if the bytes cannot be parsed as a valid serialized token.
551
+ * @param {Uint8Array} bytes
552
+ * @returns {AuthToken}
407
553
  */
408
- signup(keypair, homeserver, signup_token) {
409
- _assertClass(keypair, Keypair);
410
- _assertClass(homeserver, PublicKey);
411
- var ptr0 = isLikeNone(signup_token) ? 0 : passStringToWasm0(signup_token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
412
- var len0 = WASM_VECTOR_LEN;
413
- const ret = wasm.client_signup(this.__wbg_ptr, keypair.__wbg_ptr, homeserver.__wbg_ptr, ptr0, len0);
414
- return ret;
554
+ static fromBytes(bytes) {
555
+ const ret = wasm.authtoken_fromBytes(bytes);
556
+ if (ret[2]) {
557
+ throw takeFromExternrefTable0(ret[1]);
558
+ }
559
+ return AuthToken.__wrap(ret[0]);
415
560
  }
416
561
  /**
417
- * Check the current session for a given Pubky in its homeserver.
562
+ * Returns the **public key** that authenticated with this token.
418
563
  *
419
- * Returns [Session] or `None` (if received `404 NOT_FOUND`),
420
- * or throws the received error if the response has any other `>=400` status code.
421
- * @param {PublicKey} pubky
422
- * @returns {Promise<Session | undefined>}
564
+ * Use `.z32()` on the returned `PublicKey` to get the string form.
565
+ *
566
+ * ```js
567
+ * const who = token.publicKey().z32();
568
+ * ```
569
+ * @returns {PublicKey}
423
570
  */
424
- session(pubky) {
425
- _assertClass(pubky, PublicKey);
426
- const ret = wasm.client_session(this.__wbg_ptr, pubky.__wbg_ptr);
427
- return ret;
571
+ publicKey() {
572
+ const ret = wasm.authtoken_publicKey(this.__wbg_ptr);
573
+ return PublicKey.__wrap(ret);
428
574
  }
429
575
  /**
430
- * Signout from a homeserver.
431
- * @param {PublicKey} pubky
432
- * @returns {Promise<void>}
576
+ * Returns the **capabilities** requested by the flow at the time this token was signed.
577
+ *
578
+ * Most auth-only flows pass an empty string to `startAuthFlow("", relay)`, so this will
579
+ * commonly be an empty array.
580
+ *
581
+ * Returns: `string[]`, where each item is the canonical entry `"<scope>:<actions>"`.
582
+ *
583
+ * Example entry: `"/pub/my.app/:rw"`
584
+ * @returns {Array<any>}
433
585
  */
434
- signout(pubky) {
435
- _assertClass(pubky, PublicKey);
436
- const ret = wasm.client_signout(this.__wbg_ptr, pubky.__wbg_ptr);
586
+ capabilities() {
587
+ const ret = wasm.authtoken_capabilities(this.__wbg_ptr);
437
588
  return ret;
438
589
  }
439
590
  /**
440
- * Signin to a homeserver using the root Keypair.
441
- * @param {Keypair} keypair
442
- * @returns {Promise<void>}
591
+ * Serialize the token to a `Uint8Array` in its **canonical** (postcard) binary format.
592
+ *
593
+ * Use this to send the token to a backend for verification.
594
+ *
595
+ * ```js
596
+ * const bytes = token.toBytes();
597
+ * await fetch("/api/verify", { method: "POST", body: bytes });
598
+ * ```
599
+ * @returns {Uint8Array}
443
600
  */
444
- signin(keypair) {
445
- _assertClass(keypair, Keypair);
446
- const ret = wasm.client_signin(this.__wbg_ptr, keypair.__wbg_ptr);
601
+ toBytes() {
602
+ const ret = wasm.authtoken_toBytes(this.__wbg_ptr);
447
603
  return ret;
448
604
  }
605
+ }
606
+ module.exports.AuthToken = AuthToken;
607
+
608
+ const ClientFinalization = (typeof FinalizationRegistry === 'undefined')
609
+ ? { register: () => {}, unregister: () => {} }
610
+ : new FinalizationRegistry(ptr => wasm.__wbg_client_free(ptr >>> 0, 1));
611
+ /**
612
+ * Low-level HTTP bridge used by the Pubky façade and actors.
613
+ *
614
+ * - Supports `pubky://<user-z32>/<abs-path>` and `http(s)://` URLs.
615
+ * - In browsers/undici, passes `credentials: "include"` to send cookies.
616
+ */
617
+ class Client {
618
+
619
+ static __wrap(ptr) {
620
+ ptr = ptr >>> 0;
621
+ const obj = Object.create(Client.prototype);
622
+ obj.__wbg_ptr = ptr;
623
+ ClientFinalization.register(obj, obj.__wbg_ptr, obj);
624
+ return obj;
625
+ }
626
+
627
+ __destroy_into_raw() {
628
+ const ptr = this.__wbg_ptr;
629
+ this.__wbg_ptr = 0;
630
+ ClientFinalization.unregister(this);
631
+ return ptr;
632
+ }
633
+
634
+ free() {
635
+ const ptr = this.__destroy_into_raw();
636
+ wasm.__wbg_client_free(ptr, 0);
637
+ }
449
638
  /**
450
- * Return `pubkyauth://` url and wait for the incoming [AuthToken]
451
- * verifying that AuthToken, and if capabilities were requested, signing in to
452
- * the Pubky's homeserver and returning the [Session] information.
639
+ * Create a Pubky HTTP client.
453
640
  *
454
- * Returns a [AuthRequest]
455
- * @param {string} relay
456
- * @param {string} capabilities
457
- * @returns {AuthRequest}
641
+ * @param {PubkyClientConfig} [config]
642
+ * Optional transport overrides:
643
+ * `{ pkarr?: { relays?: string[], request_timeout?: number } }`.
644
+ *
645
+ * @returns {Client}
646
+ * A configured low-level client. Prefer `new Pubky().client()` unless you
647
+ * need custom relays/timeouts.
648
+ *
649
+ * @throws {InvalidInput}
650
+ * If any PKARR relay URL is invalid.
651
+ *
652
+ * @example
653
+ * const client = new Client({
654
+ * pkarr: { relays: ["https://relay1/","https://relay2/"], request_timeout: 8000 }
655
+ * });
656
+ * const pubky = Pubky.withClient(client);
657
+ * @param {PubkyClientConfig | null} [config_opt]
458
658
  */
459
- authRequest(relay, capabilities) {
460
- const ptr0 = passStringToWasm0(relay, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
461
- const len0 = WASM_VECTOR_LEN;
462
- const ptr1 = passStringToWasm0(capabilities, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
463
- const len1 = WASM_VECTOR_LEN;
464
- const ret = wasm.client_authRequest(this.__wbg_ptr, ptr0, len0, ptr1, len1);
659
+ constructor(config_opt) {
660
+ const ret = wasm.client_new(isLikeNone(config_opt) ? 0 : addToExternrefTable0(config_opt));
465
661
  if (ret[2]) {
466
662
  throw takeFromExternrefTable0(ret[1]);
467
663
  }
468
- return AuthRequest.__wrap(ret[0]);
469
- }
470
- /**
471
- * Sign an [pubky_common::auth::AuthToken], encrypt it and send it to the
472
- * source of the pubkyauth request url.
473
- * @param {Keypair} keypair
474
- * @param {string} pubkyauth_url
475
- * @returns {Promise<void>}
476
- */
477
- sendAuthToken(keypair, pubkyauth_url) {
478
- _assertClass(keypair, Keypair);
479
- const ptr0 = passStringToWasm0(pubkyauth_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
480
- const len0 = WASM_VECTOR_LEN;
481
- const ret = wasm.client_sendAuthToken(this.__wbg_ptr, keypair.__wbg_ptr, ptr0, len0);
482
- return ret;
483
- }
484
- /**
485
- * Get the homeserver id for a given Pubky public key.
486
- * Looks up the pkarr packet for the given public key and returns the content of the first `_pubky` SVCB record.
487
- * Throws an error if no homeserver is found.
488
- * @param {PublicKey} public_key
489
- * @returns {Promise<PublicKey>}
490
- */
491
- getHomeserver(public_key) {
492
- _assertClass(public_key, PublicKey);
493
- const ret = wasm.client_getHomeserver(this.__wbg_ptr, public_key.__wbg_ptr);
494
- return ret;
664
+ this.__wbg_ptr = ret[0] >>> 0;
665
+ ClientFinalization.register(this, this.__wbg_ptr, this);
666
+ return this;
495
667
  }
496
668
  /**
497
- * Republish the user's PKarr record pointing to their homeserver.
669
+ * Create a client wired for **local testnet**.
498
670
  *
499
- * This method will republish the record if no record exists or if the existing record
500
- * is older than 6 hours.
671
+ * Sets PKARR relays to `http://<host>:15411/` and enables WASM `pubky://`
672
+ * mapping for that host.
501
673
  *
502
- * The method is intended for clients and key managers (e.g., pubky-ring) to
503
- * keep the records of active users fresh and available in the DHT and relays.
504
- * It is intended to be used only after failed signin due to homeserver resolution
505
- * failure. This method is lighter than performing a re-signup into the last known
506
- * homeserver, but does not return a session token, so a signin must be done after
507
- * republishing. On a failed signin due to homeserver resolution failure, a key
508
- * manager should always attempt to republish the last known homeserver.
509
- * @param {Keypair} keypair
510
- * @param {PublicKey} host
511
- * @returns {Promise<void>}
674
+ * @param {string} [host="localhost"]
675
+ * Testnet hostname or IP.
676
+ *
677
+ * @returns {Client}
678
+ * A client ready to talk to your local testnet.
679
+ *
680
+ * @example
681
+ * const client = Client.testnet(); // localhost
682
+ * const pubky = Pubky.withClient(client);
683
+ *
684
+ * @example
685
+ * const client = Client.testnet("docker0"); // custom host
686
+ * @param {string | null} [host]
687
+ * @returns {Client}
512
688
  */
513
- republishHomeserver(keypair, host) {
514
- _assertClass(keypair, Keypair);
515
- _assertClass(host, PublicKey);
516
- const ret = wasm.client_republishHomeserver(this.__wbg_ptr, keypair.__wbg_ptr, host.__wbg_ptr);
517
- return ret;
689
+ static testnet(host) {
690
+ var ptr0 = isLikeNone(host) ? 0 : passStringToWasm0(host, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
691
+ var len0 = WASM_VECTOR_LEN;
692
+ const ret = wasm.client_testnet(ptr0, len0);
693
+ if (ret[2]) {
694
+ throw takeFromExternrefTable0(ret[1]);
695
+ }
696
+ return Client.__wrap(ret[0]);
518
697
  }
519
698
  /**
520
- * Returns a list of Pubky urls (as strings).
699
+ * Perform a raw fetch. Works with `pubky://` or `http(s)://` URLs.
521
700
  *
522
- * - `url`: The Pubky url (string) to the directory you want to list its content.
523
- * - `cursor`: Either a full `pubky://` Url (from previous list response),
524
- * or a path (to a file or directory) relative to the `url`
525
- * - `reverse`: List in reverse order
526
- * - `limit` Limit the number of urls in the response
527
- * - `shallow`: List directories and files, instead of flat list of files.
528
701
  * @param {string} url
529
- * @param {string | null} [cursor]
530
- * @param {boolean | null} [reverse]
531
- * @param {number | null} [limit]
532
- * @param {boolean | null} [shallow]
533
- * @returns {Promise<Array<any>>}
702
+ * @param {RequestInit=} init Standard fetch options; `credentials: "include"` recommended for session I/O.
703
+ * @returns {Promise<Response>}
704
+ *
705
+ * @example
706
+ * const client = pubky.client();
707
+ * const res = await client.fetch(`pubky://${user}/pub/app/file.txt`, { method: "PUT", body: "hi", credentials: "include" });
708
+ * @param {string} url
709
+ * @param {any | null} [init]
710
+ * @returns {Promise<Promise<any>>}
534
711
  */
535
- list(url, cursor, reverse, limit, shallow) {
712
+ fetch(url, init) {
536
713
  const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
537
714
  const len0 = WASM_VECTOR_LEN;
538
- var ptr1 = isLikeNone(cursor) ? 0 : passStringToWasm0(cursor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
539
- var len1 = WASM_VECTOR_LEN;
540
- const ret = wasm.client_list(this.__wbg_ptr, ptr0, len0, ptr1, len1, isLikeNone(reverse) ? 0xFFFFFF : reverse ? 1 : 0, isLikeNone(limit) ? 0xFFFFFF : limit, isLikeNone(shallow) ? 0xFFFFFF : shallow ? 1 : 0);
715
+ const ret = wasm.client_fetch(this.__wbg_ptr, ptr0, len0, isLikeNone(init) ? 0 : addToExternrefTable0(init));
541
716
  return ret;
542
717
  }
543
- /**
544
- * Create a new Pubky Client with an optional configuration.
545
- * @param {PubkyClientConfig | null} [config_opt]
546
- */
547
- constructor(config_opt) {
548
- const ret = wasm.client_new(isLikeNone(config_opt) ? 0 : addToExternrefTable0(config_opt));
549
- if (ret[2]) {
550
- throw takeFromExternrefTable0(ret[1]);
551
- }
552
- this.__wbg_ptr = ret[0] >>> 0;
553
- ClientFinalization.register(this, this.__wbg_ptr, this);
554
- return this;
555
- }
556
- /**
557
- * Create a client with with configurations appropriate for local testing:
558
- * - set Pkarr relays to `http://<host>:15411` (defaults to `localhost`).
559
- * - transform `pubky://<pkarr public key>` to `http://<host>` instead of `https:`
560
- * and read the homeserver HTTP port from the PKarr record.
561
- * @param {string | null} [host]
562
- * @returns {Client}
563
- */
564
- static testnet(host) {
565
- var ptr0 = isLikeNone(host) ? 0 : passStringToWasm0(host, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
566
- var len0 = WASM_VECTOR_LEN;
567
- const ret = wasm.client_testnet(ptr0, len0);
568
- return Client.__wrap(ret);
569
- }
570
718
  }
571
719
  module.exports.Client = Client;
572
720
 
@@ -623,9 +771,7 @@ class Keypair {
623
771
  */
624
772
  secretKey() {
625
773
  const ret = wasm.keypair_secretKey(this.__wbg_ptr);
626
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
627
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
628
- return v1;
774
+ return ret;
629
775
  }
630
776
  /**
631
777
  * Returns the [PublicKey] of this keypair.
@@ -635,9 +781,345 @@ class Keypair {
635
781
  const ret = wasm.keypair_publicKey(this.__wbg_ptr);
636
782
  return PublicKey.__wrap(ret);
637
783
  }
784
+ /**
785
+ * Create a recovery file for this keypair (encrypted with the given passphrase).
786
+ * @param {string} passphrase
787
+ * @returns {Uint8Array}
788
+ */
789
+ createRecoveryFile(passphrase) {
790
+ const ptr0 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
791
+ const len0 = WASM_VECTOR_LEN;
792
+ const ret = wasm.keypair_createRecoveryFile(this.__wbg_ptr, ptr0, len0);
793
+ return ret;
794
+ }
795
+ /**
796
+ * Decrypt a recovery file and return a Keypair (decrypted with the given passphrase).
797
+ * @param {Uint8Array} recovery_file
798
+ * @param {string} passphrase
799
+ * @returns {Keypair}
800
+ */
801
+ static fromRecoveryFile(recovery_file, passphrase) {
802
+ const ptr0 = passArray8ToWasm0(recovery_file, wasm.__wbindgen_malloc);
803
+ const len0 = WASM_VECTOR_LEN;
804
+ const ptr1 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
805
+ const len1 = WASM_VECTOR_LEN;
806
+ const ret = wasm.keypair_fromRecoveryFile(ptr0, len0, ptr1, len1);
807
+ if (ret[2]) {
808
+ throw takeFromExternrefTable0(ret[1]);
809
+ }
810
+ return Keypair.__wrap(ret[0]);
811
+ }
638
812
  }
639
813
  module.exports.Keypair = Keypair;
640
814
 
815
+ const PkdnsFinalization = (typeof FinalizationRegistry === 'undefined')
816
+ ? { register: () => {}, unregister: () => {} }
817
+ : new FinalizationRegistry(ptr => wasm.__wbg_pkdns_free(ptr >>> 0, 1));
818
+ /**
819
+ * Resolve/publish `_pubky` PKDNS records (homeserver pointers).
820
+ */
821
+ class Pkdns {
822
+
823
+ static __wrap(ptr) {
824
+ ptr = ptr >>> 0;
825
+ const obj = Object.create(Pkdns.prototype);
826
+ obj.__wbg_ptr = ptr;
827
+ PkdnsFinalization.register(obj, obj.__wbg_ptr, obj);
828
+ return obj;
829
+ }
830
+
831
+ __destroy_into_raw() {
832
+ const ptr = this.__wbg_ptr;
833
+ this.__wbg_ptr = 0;
834
+ PkdnsFinalization.unregister(this);
835
+ return ptr;
836
+ }
837
+
838
+ free() {
839
+ const ptr = this.__destroy_into_raw();
840
+ wasm.__wbg_pkdns_free(ptr, 0);
841
+ }
842
+ /**
843
+ * Read-only PKDNS actor (no keypair; resolve only).
844
+ */
845
+ constructor() {
846
+ const ret = wasm.pkdns_new();
847
+ if (ret[2]) {
848
+ throw takeFromExternrefTable0(ret[1]);
849
+ }
850
+ this.__wbg_ptr = ret[0] >>> 0;
851
+ PkdnsFinalization.register(this, this.__wbg_ptr, this);
852
+ return this;
853
+ }
854
+ /**
855
+ * PKDNS actor with publishing enabled (requires a keypair).
856
+ * @param {Keypair} keypair
857
+ * @returns {Pkdns}
858
+ */
859
+ static fromKeypair(keypair) {
860
+ _assertClass(keypair, Keypair);
861
+ const ret = wasm.pkdns_fromKeypair(keypair.__wbg_ptr);
862
+ if (ret[2]) {
863
+ throw takeFromExternrefTable0(ret[1]);
864
+ }
865
+ return Pkdns.__wrap(ret[0]);
866
+ }
867
+ /**
868
+ * Resolve the homeserver for a given public key (read-only).
869
+ *
870
+ * @param {PublicKey} user
871
+ * @returns {Promise<string|undefined>} Homeserver public key (z32) or `undefined` if not found.
872
+ * @param {PublicKey} pubky
873
+ * @returns {Promise<string | undefined>}
874
+ */
875
+ getHomeserverOf(pubky) {
876
+ _assertClass(pubky, PublicKey);
877
+ const ret = wasm.pkdns_getHomeserverOf(this.__wbg_ptr, pubky.__wbg_ptr);
878
+ return ret;
879
+ }
880
+ /**
881
+ * Resolve the homeserver for **this** user (requires keypair).
882
+ *
883
+ * @returns {Promise<string|undefined>} Homeserver public key (z32) or `undefined` if not found.
884
+ * @returns {Promise<string | undefined>}
885
+ */
886
+ getHomeserver() {
887
+ const ret = wasm.pkdns_getHomeserver(this.__wbg_ptr);
888
+ return ret;
889
+ }
890
+ /**
891
+ * Republish homeserver if record is missing/stale.
892
+ *
893
+ * Requires keypair or to be signer bound.
894
+ *
895
+ * @param {PublicKey=} overrideHost Optional new homeserver to publish (migration).
896
+ * @returns {Promise<void>}
897
+ * @param {PublicKey | null} [host_override]
898
+ * @returns {Promise<void>}
899
+ */
900
+ publishHomeserverForce(host_override) {
901
+ let ptr0 = 0;
902
+ if (!isLikeNone(host_override)) {
903
+ _assertClass(host_override, PublicKey);
904
+ ptr0 = host_override.__destroy_into_raw();
905
+ }
906
+ const ret = wasm.pkdns_publishHomeserverForce(this.__wbg_ptr, ptr0);
907
+ return ret;
908
+ }
909
+ /**
910
+ * Force publish homeserver immediately (even if fresh).
911
+ *
912
+ * Requires keypair or to be signer bound.
913
+ *
914
+ * @param {PublicKey=} overrideHost Optional new homeserver to publish (migration).
915
+ * @returns {Promise<void>}
916
+ * @param {PublicKey | null} [host_override]
917
+ * @returns {Promise<void>}
918
+ */
919
+ publishHomeserverIfStale(host_override) {
920
+ let ptr0 = 0;
921
+ if (!isLikeNone(host_override)) {
922
+ _assertClass(host_override, PublicKey);
923
+ ptr0 = host_override.__destroy_into_raw();
924
+ }
925
+ const ret = wasm.pkdns_publishHomeserverIfStale(this.__wbg_ptr, ptr0);
926
+ return ret;
927
+ }
928
+ }
929
+ module.exports.Pkdns = Pkdns;
930
+
931
+ const PubkyFinalization = (typeof FinalizationRegistry === 'undefined')
932
+ ? { register: () => {}, unregister: () => {} }
933
+ : new FinalizationRegistry(ptr => wasm.__wbg_pubky_free(ptr >>> 0, 1));
934
+ /**
935
+ * High-level entrypoint to the Pubky SDK.
936
+ */
937
+ class Pubky {
938
+
939
+ static __wrap(ptr) {
940
+ ptr = ptr >>> 0;
941
+ const obj = Object.create(Pubky.prototype);
942
+ obj.__wbg_ptr = ptr;
943
+ PubkyFinalization.register(obj, obj.__wbg_ptr, obj);
944
+ return obj;
945
+ }
946
+
947
+ __destroy_into_raw() {
948
+ const ptr = this.__wbg_ptr;
949
+ this.__wbg_ptr = 0;
950
+ PubkyFinalization.unregister(this);
951
+ return ptr;
952
+ }
953
+
954
+ free() {
955
+ const ptr = this.__destroy_into_raw();
956
+ wasm.__wbg_pubky_free(ptr, 0);
957
+ }
958
+ /**
959
+ * Create a Pubky façade wired for **mainnet** defaults (public relays).
960
+ *
961
+ * @returns {Pubky}
962
+ * A new façade instance. Use this to create signers, start auth flows, etc.
963
+ *
964
+ * @example
965
+ * const pubky = new Pubky();
966
+ * const signer = pubky.signer(Keypair.random());
967
+ */
968
+ constructor() {
969
+ const ret = wasm.pubky_new();
970
+ if (ret[2]) {
971
+ throw takeFromExternrefTable0(ret[1]);
972
+ }
973
+ this.__wbg_ptr = ret[0] >>> 0;
974
+ PubkyFinalization.register(this, this.__wbg_ptr, this);
975
+ return this;
976
+ }
977
+ /**
978
+ * Create a Pubky façade preconfigured for a **local testnet**.
979
+ *
980
+ * If `host` is provided, PKARR and HTTP endpoints are derived as `http://<host>:ports/...`.
981
+ * If omitted, `"localhost"` is assumed (handy for `cargo install pubky-testnet`).
982
+ *
983
+ * @param {string=} host Optional host (e.g. `"localhost"`, `"docker-host"`, `"127.0.0.1"`).
984
+ * @returns {Pubky}
985
+ *
986
+ * @example
987
+ * const pubky = Pubky.testnet(); // localhost default
988
+ * const pubky = Pubky.testnet("docker-host"); // custom hostname/IP
989
+ * @param {string | null} [host]
990
+ * @returns {Pubky}
991
+ */
992
+ static testnet(host) {
993
+ var ptr0 = isLikeNone(host) ? 0 : passStringToWasm0(host, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
994
+ var len0 = WASM_VECTOR_LEN;
995
+ const ret = wasm.pubky_testnet(ptr0, len0);
996
+ if (ret[2]) {
997
+ throw takeFromExternrefTable0(ret[1]);
998
+ }
999
+ return Pubky.__wrap(ret[0]);
1000
+ }
1001
+ /**
1002
+ * Wrap an existing configured HTTP client into a Pubky façade.
1003
+ *
1004
+ * @param {Client} client A previously constructed client.
1005
+ * @returns {Pubky}
1006
+ *
1007
+ * @example
1008
+ * const client = Client.testnet();
1009
+ * const pubky = Pubky.withClient(client);
1010
+ * @param {Client} client
1011
+ * @returns {Pubky}
1012
+ */
1013
+ static withClient(client) {
1014
+ _assertClass(client, Client);
1015
+ const ret = wasm.pubky_withClient(client.__wbg_ptr);
1016
+ return Pubky.__wrap(ret);
1017
+ }
1018
+ /**
1019
+ * Start a **pubkyauth** flow.
1020
+ *
1021
+ * Provide a **capabilities string** and (optionally) a relay base URL.
1022
+ * The capabilities string is a comma-separated list of entries:
1023
+ * `"<scope>:<actions>"`, where:
1024
+ * - `scope` starts with `/` (e.g. `/pub/example.app/`).
1025
+ * - `actions` is any combo of `r` and/or `w` (order normalized; `wr` -> `rw`).
1026
+ * Pass `""` for no scopes (read-only public session).
1027
+ *
1028
+ * @param {string} capabilities Comma-separated caps, e.g. `"/pub/app/:rw,/pub/foo/file:r"`.
1029
+ * @param {string=} relay Optional HTTP relay base (e.g. `"https://…/link/"`).
1030
+ * @returns {AuthFlow}
1031
+ * A running auth flow. Call `authorizationUrl()` to show a QR/deeplink,
1032
+ * then `awaitApproval()` to obtain a `Session`.
1033
+ *
1034
+ * @throws {PubkyJsError}
1035
+ * - `{ name: "InvalidInput" }` for malformed capabilities or bad relay URL
1036
+ * - `{ name: "RequestError" }` if the flow cannot be started (network/relay)
1037
+ *
1038
+ * @example
1039
+ * const flow = pubky.startAuthFlow("/pub/my.app/:rw");
1040
+ * renderQr(flow.authorizationUrl());
1041
+ * const session = await flow.awaitApproval();
1042
+ * @param {string} capabilities
1043
+ * @param {string | null} [relay]
1044
+ * @returns {AuthFlow}
1045
+ */
1046
+ startAuthFlow(capabilities, relay) {
1047
+ const ptr0 = passStringToWasm0(capabilities, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1048
+ const len0 = WASM_VECTOR_LEN;
1049
+ var ptr1 = isLikeNone(relay) ? 0 : passStringToWasm0(relay, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1050
+ var len1 = WASM_VECTOR_LEN;
1051
+ const ret = wasm.pubky_startAuthFlow(this.__wbg_ptr, ptr0, len0, ptr1, len1);
1052
+ if (ret[2]) {
1053
+ throw takeFromExternrefTable0(ret[1]);
1054
+ }
1055
+ return AuthFlow.__wrap(ret[0]);
1056
+ }
1057
+ /**
1058
+ * Create a `Signer` from an existing `Keypair`.
1059
+ *
1060
+ * @param {Keypair} keypair The user’s keys.
1061
+ * @returns {Signer}
1062
+ *
1063
+ * @example
1064
+ * const signer = pubky.signer(Keypair.random());
1065
+ * const session = await signer.signup(homeserverPk, null);
1066
+ * @param {Keypair} keypair
1067
+ * @returns {Signer}
1068
+ */
1069
+ signer(keypair) {
1070
+ _assertClass(keypair, Keypair);
1071
+ var ptr0 = keypair.__destroy_into_raw();
1072
+ const ret = wasm.pubky_signer(this.__wbg_ptr, ptr0);
1073
+ return Signer.__wrap(ret);
1074
+ }
1075
+ /**
1076
+ * Public, unauthenticated storage API.
1077
+ *
1078
+ * Use for **read-only** public access via addressed paths:
1079
+ * `"<user-z32>/pub/…"`.
1080
+ *
1081
+ * @returns {PublicStorage}
1082
+ *
1083
+ * @example
1084
+ * const pub = pubky.publicStorage();
1085
+ * const text = await pub.getText(`${userPk.z32()}/pub/example.com/hello.txt`);
1086
+ * @returns {PublicStorage}
1087
+ */
1088
+ publicStorage() {
1089
+ const ret = wasm.pubky_publicStorage(this.__wbg_ptr);
1090
+ return PublicStorage.__wrap(ret);
1091
+ }
1092
+ /**
1093
+ * Read-only PKDNS (Pkarr) resolver.
1094
+ *
1095
+ * @returns {Pkdns}
1096
+ *
1097
+ * @example
1098
+ * const dns = pubky.pkdns();
1099
+ * const homeserver = await dns.getHomeserverOf(userPk);
1100
+ * @returns {Pkdns}
1101
+ */
1102
+ pkdns() {
1103
+ const ret = wasm.pubky_pkdns(this.__wbg_ptr);
1104
+ return Pkdns.__wrap(ret);
1105
+ }
1106
+ /**
1107
+ * Access the underlying HTTP client (advanced).
1108
+ *
1109
+ * @returns {Client}
1110
+ * Use this for low-level `fetch()` calls or testing with raw URLs.
1111
+ *
1112
+ * @example
1113
+ * const r = await pubky.client().fetch(`pubky://${user}/pub/app/file.txt`, { credentials: "include" });
1114
+ * @returns {Client}
1115
+ */
1116
+ client() {
1117
+ const ret = wasm.pubky_client(this.__wbg_ptr);
1118
+ return Client.__wrap(ret);
1119
+ }
1120
+ }
1121
+ module.exports.Pubky = Pubky;
1122
+
641
1123
  const PublicKeyFinalization = (typeof FinalizationRegistry === 'undefined')
642
1124
  ? { register: () => {}, unregister: () => {} }
643
1125
  : new FinalizationRegistry(ptr => wasm.__wbg_publickey_free(ptr >>> 0, 1));
@@ -665,137 +1147,667 @@ class PublicKey {
665
1147
  }
666
1148
  /**
667
1149
  * Convert the PublicKey to Uint8Array
668
- * @deprecated Use `toUint8Array` instead
669
1150
  * @returns {Uint8Array}
670
1151
  */
671
- to_uint8array() {
672
- const ret = wasm.publickey_to_uint8array(this.__wbg_ptr);
673
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
674
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
675
- return v1;
1152
+ toUint8Array() {
1153
+ const ret = wasm.publickey_toUint8Array(this.__wbg_ptr);
1154
+ return ret;
676
1155
  }
677
1156
  /**
678
- * Convert the PublicKey to Uint8Array
679
- * @returns {Uint8Array}
1157
+ * Returns the z-base32 encoding of this public key
1158
+ * @returns {string}
680
1159
  */
681
- toUint8Array() {
682
- const ret = wasm.publickey_toUint8Array(this.__wbg_ptr);
683
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
684
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1160
+ z32() {
1161
+ let deferred1_0;
1162
+ let deferred1_1;
1163
+ try {
1164
+ const ret = wasm.publickey_z32(this.__wbg_ptr);
1165
+ deferred1_0 = ret[0];
1166
+ deferred1_1 = ret[1];
1167
+ return getStringFromWasm0(ret[0], ret[1]);
1168
+ } finally {
1169
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1170
+ }
1171
+ }
1172
+ /**
1173
+ * @throws
1174
+ * @param {string} value
1175
+ * @returns {PublicKey}
1176
+ */
1177
+ static from(value) {
1178
+ const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1179
+ const len0 = WASM_VECTOR_LEN;
1180
+ const ret = wasm.publickey_from(ptr0, len0);
1181
+ if (ret[2]) {
1182
+ throw takeFromExternrefTable0(ret[1]);
1183
+ }
1184
+ return PublicKey.__wrap(ret[0]);
1185
+ }
1186
+ }
1187
+ module.exports.PublicKey = PublicKey;
1188
+
1189
+ const PublicStorageFinalization = (typeof FinalizationRegistry === 'undefined')
1190
+ ? { register: () => {}, unregister: () => {} }
1191
+ : new FinalizationRegistry(ptr => wasm.__wbg_publicstorage_free(ptr >>> 0, 1));
1192
+ /**
1193
+ * Read-only public storage using addressed paths (`"<user-z32>/pub/...")`.
1194
+ */
1195
+ class PublicStorage {
1196
+
1197
+ static __wrap(ptr) {
1198
+ ptr = ptr >>> 0;
1199
+ const obj = Object.create(PublicStorage.prototype);
1200
+ obj.__wbg_ptr = ptr;
1201
+ PublicStorageFinalization.register(obj, obj.__wbg_ptr, obj);
1202
+ return obj;
1203
+ }
1204
+
1205
+ __destroy_into_raw() {
1206
+ const ptr = this.__wbg_ptr;
1207
+ this.__wbg_ptr = 0;
1208
+ PublicStorageFinalization.unregister(this);
1209
+ return ptr;
1210
+ }
1211
+
1212
+ free() {
1213
+ const ptr = this.__destroy_into_raw();
1214
+ wasm.__wbg_publicstorage_free(ptr, 0);
1215
+ }
1216
+ /**
1217
+ * Construct PublicStorage using global client (mainline relays).
1218
+ */
1219
+ constructor() {
1220
+ const ret = wasm.publicstorage_new();
1221
+ if (ret[2]) {
1222
+ throw takeFromExternrefTable0(ret[1]);
1223
+ }
1224
+ this.__wbg_ptr = ret[0] >>> 0;
1225
+ PublicStorageFinalization.register(this, this.__wbg_ptr, this);
1226
+ return this;
1227
+ }
1228
+ /**
1229
+ * List a directory. Results are `pubky://…` absolute URLs.
1230
+ *
1231
+ * @param {string} address Addressed directory (must end with `/`).
1232
+ * @param {string|null=} cursor Optional suffix or full URL to start **after**.
1233
+ * @param {boolean=} reverse Default `false`. When `true`, newest/lexicographically-last first.
1234
+ * @param {number=} limit Optional result limit.
1235
+ * @param {boolean=} shallow Default `false`. When `true`, lists only first-level entries.
1236
+ * @returns {Promise<string[]>}
1237
+ * @param {string} address
1238
+ * @param {string | null} [cursor]
1239
+ * @param {boolean | null} [reverse]
1240
+ * @param {number | null} [limit]
1241
+ * @param {boolean | null} [shallow]
1242
+ * @returns {Promise<string[]>}
1243
+ */
1244
+ list(address, cursor, reverse, limit, shallow) {
1245
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1246
+ const len0 = WASM_VECTOR_LEN;
1247
+ var ptr1 = isLikeNone(cursor) ? 0 : passStringToWasm0(cursor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1248
+ var len1 = WASM_VECTOR_LEN;
1249
+ const ret = wasm.publicstorage_list(this.__wbg_ptr, ptr0, len0, ptr1, len1, isLikeNone(reverse) ? 0xFFFFFF : reverse ? 1 : 0, isLikeNone(limit) ? 0xFFFFFF : limit, isLikeNone(shallow) ? 0xFFFFFF : shallow ? 1 : 0);
1250
+ return ret;
1251
+ }
1252
+ /**
1253
+ * Fetch bytes from an addressed path.
1254
+ *
1255
+ * @param {string} address
1256
+ * @returns {Promise<Uint8Array>}
1257
+ * @param {string} address
1258
+ * @returns {Promise<Uint8Array>}
1259
+ */
1260
+ getBytes(address) {
1261
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1262
+ const len0 = WASM_VECTOR_LEN;
1263
+ const ret = wasm.publicstorage_getBytes(this.__wbg_ptr, ptr0, len0);
1264
+ return ret;
1265
+ }
1266
+ /**
1267
+ * Fetch text from an addressed path as UTF-8 text.
1268
+ *
1269
+ * @param {string} address
1270
+ * @returns {Promise<string>}
1271
+ * @param {string} address
1272
+ * @returns {Promise<string>}
1273
+ */
1274
+ getText(address) {
1275
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1276
+ const len0 = WASM_VECTOR_LEN;
1277
+ const ret = wasm.publicstorage_getText(this.__wbg_ptr, ptr0, len0);
1278
+ return ret;
1279
+ }
1280
+ /**
1281
+ * Fetch JSON from an addressed path.
1282
+ *
1283
+ * @param {string} address `"<user-z32>/pub/.../file.json"` or `pubky://<user>/pub/...`.
1284
+ * @returns {Promise<any>}
1285
+ * @param {string} address
1286
+ * @returns {Promise<any>}
1287
+ */
1288
+ getJson(address) {
1289
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1290
+ const len0 = WASM_VECTOR_LEN;
1291
+ const ret = wasm.publicstorage_getJson(this.__wbg_ptr, ptr0, len0);
1292
+ return ret;
1293
+ }
1294
+ /**
1295
+ * Check if a path exists.
1296
+ *
1297
+ * @param {string} address
1298
+ * @returns {Promise<boolean>}
1299
+ * @param {string} address
1300
+ * @returns {Promise<boolean>}
1301
+ */
1302
+ exists(address) {
1303
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1304
+ const len0 = WASM_VECTOR_LEN;
1305
+ const ret = wasm.publicstorage_exists(this.__wbg_ptr, ptr0, len0);
1306
+ return ret;
1307
+ }
1308
+ /**
1309
+ * Get metadata for an address
1310
+ *
1311
+ * @param {string} address `"<user-z32>/pub/.../file.json"` or `pubky://<user>/pub/...`.
1312
+ * @returns {Promise<ResourceStats|undefined>} `undefined` if the resource does not exist.
1313
+ * @throws {PubkyJsError} On invalid input or transport/server errors.
1314
+ * @param {string} address
1315
+ * @returns {Promise<ResourceStats | undefined>}
1316
+ */
1317
+ stats(address) {
1318
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1319
+ const len0 = WASM_VECTOR_LEN;
1320
+ const ret = wasm.publicstorage_stats(this.__wbg_ptr, ptr0, len0);
1321
+ return ret;
1322
+ }
1323
+ }
1324
+ module.exports.PublicStorage = PublicStorage;
1325
+
1326
+ const SessionFinalization = (typeof FinalizationRegistry === 'undefined')
1327
+ ? { register: () => {}, unregister: () => {} }
1328
+ : new FinalizationRegistry(ptr => wasm.__wbg_session_free(ptr >>> 0, 1));
1329
+ /**
1330
+ * An authenticated context “as the user”.
1331
+ * - Use `storage()` for reads/writes (absolute paths like `/pub/app/file.txt`)
1332
+ * - Cookie is managed automatically by the underlying fetch client
1333
+ */
1334
+ class Session {
1335
+
1336
+ static __wrap(ptr) {
1337
+ ptr = ptr >>> 0;
1338
+ const obj = Object.create(Session.prototype);
1339
+ obj.__wbg_ptr = ptr;
1340
+ SessionFinalization.register(obj, obj.__wbg_ptr, obj);
1341
+ return obj;
1342
+ }
1343
+
1344
+ __destroy_into_raw() {
1345
+ const ptr = this.__wbg_ptr;
1346
+ this.__wbg_ptr = 0;
1347
+ SessionFinalization.unregister(this);
1348
+ return ptr;
1349
+ }
1350
+
1351
+ free() {
1352
+ const ptr = this.__destroy_into_raw();
1353
+ wasm.__wbg_session_free(ptr, 0);
1354
+ }
1355
+ /**
1356
+ * Retrieve immutable info about this session (user & capabilities).
1357
+ *
1358
+ * @returns {SessionInfo}
1359
+ * @returns {SessionInfo}
1360
+ */
1361
+ info() {
1362
+ const ret = wasm.session_info(this.__wbg_ptr);
1363
+ return SessionInfo.__wrap(ret);
1364
+ }
1365
+ /**
1366
+ * Access the session-scoped storage API (read/write).
1367
+ *
1368
+ * @returns {SessionStorage}
1369
+ * @returns {SessionStorage}
1370
+ */
1371
+ storage() {
1372
+ const ret = wasm.session_storage(this.__wbg_ptr);
1373
+ return SessionStorage.__wrap(ret);
1374
+ }
1375
+ /**
1376
+ * Invalidate the session on the server (clears server cookie).
1377
+ * It also consumes this JS/Wasm Session. Further calls will fail.
1378
+ *
1379
+ * @returns {Promise<void>}
1380
+ * @returns {Promise<void>}
1381
+ */
1382
+ signout() {
1383
+ const ptr = this.__destroy_into_raw();
1384
+ const ret = wasm.session_signout(ptr);
1385
+ return ret;
1386
+ }
1387
+ }
1388
+ module.exports.Session = Session;
1389
+
1390
+ const SessionInfoFinalization = (typeof FinalizationRegistry === 'undefined')
1391
+ ? { register: () => {}, unregister: () => {} }
1392
+ : new FinalizationRegistry(ptr => wasm.__wbg_sessioninfo_free(ptr >>> 0, 1));
1393
+ /**
1394
+ * Static snapshot of session metadata.
1395
+ */
1396
+ class SessionInfo {
1397
+
1398
+ static __wrap(ptr) {
1399
+ ptr = ptr >>> 0;
1400
+ const obj = Object.create(SessionInfo.prototype);
1401
+ obj.__wbg_ptr = ptr;
1402
+ SessionInfoFinalization.register(obj, obj.__wbg_ptr, obj);
1403
+ return obj;
1404
+ }
1405
+
1406
+ __destroy_into_raw() {
1407
+ const ptr = this.__wbg_ptr;
1408
+ this.__wbg_ptr = 0;
1409
+ SessionInfoFinalization.unregister(this);
1410
+ return ptr;
1411
+ }
1412
+
1413
+ free() {
1414
+ const ptr = this.__destroy_into_raw();
1415
+ wasm.__wbg_sessioninfo_free(ptr, 0);
1416
+ }
1417
+ /**
1418
+ * The user’s public key for this session.
1419
+ *
1420
+ * @returns {PublicKey}
1421
+ * @returns {PublicKey}
1422
+ */
1423
+ publicKey() {
1424
+ const ret = wasm.sessioninfo_publicKey(this.__wbg_ptr);
1425
+ return PublicKey.__wrap(ret);
1426
+ }
1427
+ /**
1428
+ * Effective capabilities granted to this session.
1429
+ *
1430
+ * @returns {string[]} Normalized capability entries (e.g. `"/pub/app/:rw"`).
1431
+ * @returns {string[]}
1432
+ */
1433
+ capabilities() {
1434
+ const ret = wasm.sessioninfo_capabilities(this.__wbg_ptr);
1435
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
1436
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
685
1437
  return v1;
686
1438
  }
1439
+ }
1440
+ module.exports.SessionInfo = SessionInfo;
1441
+
1442
+ const SessionStorageFinalization = (typeof FinalizationRegistry === 'undefined')
1443
+ ? { register: () => {}, unregister: () => {} }
1444
+ : new FinalizationRegistry(ptr => wasm.__wbg_sessionstorage_free(ptr >>> 0, 1));
1445
+ /**
1446
+ * Read/write storage scoped to **your** session (absolute paths: `/pub/...`).
1447
+ */
1448
+ class SessionStorage {
1449
+
1450
+ static __wrap(ptr) {
1451
+ ptr = ptr >>> 0;
1452
+ const obj = Object.create(SessionStorage.prototype);
1453
+ obj.__wbg_ptr = ptr;
1454
+ SessionStorageFinalization.register(obj, obj.__wbg_ptr, obj);
1455
+ return obj;
1456
+ }
1457
+
1458
+ __destroy_into_raw() {
1459
+ const ptr = this.__wbg_ptr;
1460
+ this.__wbg_ptr = 0;
1461
+ SessionStorageFinalization.unregister(this);
1462
+ return ptr;
1463
+ }
1464
+
1465
+ free() {
1466
+ const ptr = this.__destroy_into_raw();
1467
+ wasm.__wbg_sessionstorage_free(ptr, 0);
1468
+ }
1469
+ /**
1470
+ * List a directory (absolute session path). Returns `pubky://…` URLs.
1471
+ *
1472
+ * @param {string} path Must end with `/`.
1473
+ * @param {string|null=} cursor Optional suffix or full URL to start **after**.
1474
+ * @param {boolean=} reverse Default `false`.
1475
+ * @param {number=} limit Optional result limit.
1476
+ * @param {boolean=} shallow Default `false`.
1477
+ * @returns {Promise<string[]>}
1478
+ * @param {string} path
1479
+ * @param {string | null} [cursor]
1480
+ * @param {boolean | null} [reverse]
1481
+ * @param {number | null} [limit]
1482
+ * @param {boolean | null} [shallow]
1483
+ * @returns {Promise<string[]>}
1484
+ */
1485
+ list(path, cursor, reverse, limit, shallow) {
1486
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1487
+ const len0 = WASM_VECTOR_LEN;
1488
+ var ptr1 = isLikeNone(cursor) ? 0 : passStringToWasm0(cursor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1489
+ var len1 = WASM_VECTOR_LEN;
1490
+ const ret = wasm.sessionstorage_list(this.__wbg_ptr, ptr0, len0, ptr1, len1, isLikeNone(reverse) ? 0xFFFFFF : reverse ? 1 : 0, isLikeNone(limit) ? 0xFFFFFF : limit, isLikeNone(shallow) ? 0xFFFFFF : shallow ? 1 : 0);
1491
+ return ret;
1492
+ }
1493
+ /**
1494
+ * GET bytes from an absolute session path.
1495
+ *
1496
+ * @param {string} path
1497
+ * @returns {Promise<Uint8Array>}
1498
+ * @param {string} path
1499
+ * @returns {Promise<Uint8Array>}
1500
+ */
1501
+ getBytes(path) {
1502
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1503
+ const len0 = WASM_VECTOR_LEN;
1504
+ const ret = wasm.sessionstorage_getBytes(this.__wbg_ptr, ptr0, len0);
1505
+ return ret;
1506
+ }
1507
+ /**
1508
+ * GET text from an absolute session path.
1509
+ *
1510
+ * @param {string} path
1511
+ * @returns {Promise<string>}
1512
+ * @param {string} path
1513
+ * @returns {Promise<string>}
1514
+ */
1515
+ getText(path) {
1516
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1517
+ const len0 = WASM_VECTOR_LEN;
1518
+ const ret = wasm.sessionstorage_getText(this.__wbg_ptr, ptr0, len0);
1519
+ return ret;
1520
+ }
1521
+ /**
1522
+ * GET JSON from an absolute session path.
1523
+ *
1524
+ * @param {string} path
1525
+ * @returns {Promise<any>}
1526
+ * @param {string} addr
1527
+ * @returns {Promise<any>}
1528
+ */
1529
+ getJson(addr) {
1530
+ const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1531
+ const len0 = WASM_VECTOR_LEN;
1532
+ const ret = wasm.sessionstorage_getJson(this.__wbg_ptr, ptr0, len0);
1533
+ return ret;
1534
+ }
1535
+ /**
1536
+ * Check existence.
1537
+ *
1538
+ * @param {string} path
1539
+ * @returns {Promise<boolean>}
1540
+ * @param {string} path
1541
+ * @returns {Promise<boolean>}
1542
+ */
1543
+ exists(path) {
1544
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1545
+ const len0 = WASM_VECTOR_LEN;
1546
+ const ret = wasm.sessionstorage_exists(this.__wbg_ptr, ptr0, len0);
1547
+ return ret;
1548
+ }
1549
+ /**
1550
+ * Get metadata for an absolute, session-scoped path (e.g. `"/pub/app/file.json"`).
1551
+ *
1552
+ * @param {string} path Absolute path under your user (starts with `/`).
1553
+ * @returns {Promise<ResourceStats|undefined>} `undefined` if the resource does not exist.
1554
+ * @throws {PubkyJsError} On invalid input or transport/server errors.
1555
+ * @param {string} path
1556
+ * @returns {Promise<ResourceStats | undefined>}
1557
+ */
1558
+ stats(path) {
1559
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1560
+ const len0 = WASM_VECTOR_LEN;
1561
+ const ret = wasm.sessionstorage_stats(this.__wbg_ptr, ptr0, len0);
1562
+ return ret;
1563
+ }
1564
+ /**
1565
+ * PUT binary at an absolute session path.
1566
+ *
1567
+ * @param {string} path
1568
+ * @param {Uint8Array} bytes
1569
+ * @returns {Promise<void>}
1570
+ * @param {string} path
1571
+ * @param {Uint8Array} body
1572
+ * @returns {Promise<void>}
1573
+ */
1574
+ putBytes(path, body) {
1575
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1576
+ const len0 = WASM_VECTOR_LEN;
1577
+ const ptr1 = passArray8ToWasm0(body, wasm.__wbindgen_malloc);
1578
+ const len1 = WASM_VECTOR_LEN;
1579
+ const ret = wasm.sessionstorage_putBytes(this.__wbg_ptr, ptr0, len0, ptr1, len1);
1580
+ return ret;
1581
+ }
1582
+ /**
1583
+ * PUT text at an absolute session path.
1584
+ *
1585
+ * @param {string} path
1586
+ * @param {string} text
1587
+ * @returns {Promise<void>}
1588
+ * @param {string} path
1589
+ * @param {string} body
1590
+ * @returns {Promise<void>}
1591
+ */
1592
+ putText(path, body) {
1593
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1594
+ const len0 = WASM_VECTOR_LEN;
1595
+ const ptr1 = passStringToWasm0(body, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1596
+ const len1 = WASM_VECTOR_LEN;
1597
+ const ret = wasm.sessionstorage_putText(this.__wbg_ptr, ptr0, len0, ptr1, len1);
1598
+ return ret;
1599
+ }
687
1600
  /**
688
- * Returns the z-base32 encoding of this public key
689
- * @returns {string}
1601
+ * PUT JSON at an absolute session path.
1602
+ *
1603
+ * @param {string} path Absolute path (e.g. `"/pub/app/data.json"`).
1604
+ * @param {any} value JSON-serializable value.
1605
+ * @returns {Promise<void>}
1606
+ * @param {string} path
1607
+ * @param {any} body
1608
+ * @returns {Promise<void>}
690
1609
  */
691
- z32() {
692
- let deferred1_0;
693
- let deferred1_1;
694
- try {
695
- const ret = wasm.publickey_z32(this.__wbg_ptr);
696
- deferred1_0 = ret[0];
697
- deferred1_1 = ret[1];
698
- return getStringFromWasm0(ret[0], ret[1]);
699
- } finally {
700
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
701
- }
1610
+ putJson(path, body) {
1611
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1612
+ const len0 = WASM_VECTOR_LEN;
1613
+ const ret = wasm.sessionstorage_putJson(this.__wbg_ptr, ptr0, len0, body);
1614
+ return ret;
702
1615
  }
703
1616
  /**
704
- * @throws
705
- * @param {string} value
706
- * @returns {PublicKey}
1617
+ * Delete a path (file or empty directory).
1618
+ *
1619
+ * @param {string} path
1620
+ * @returns {Promise<void>}
1621
+ * @param {string} path
1622
+ * @returns {Promise<void>}
707
1623
  */
708
- static from(value) {
709
- const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1624
+ delete(path) {
1625
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
710
1626
  const len0 = WASM_VECTOR_LEN;
711
- const ret = wasm.publickey_from(ptr0, len0);
712
- if (ret[2]) {
713
- throw takeFromExternrefTable0(ret[1]);
714
- }
715
- return PublicKey.__wrap(ret[0]);
1627
+ const ret = wasm.sessionstorage_delete(this.__wbg_ptr, ptr0, len0);
1628
+ return ret;
716
1629
  }
717
1630
  }
718
- module.exports.PublicKey = PublicKey;
1631
+ module.exports.SessionStorage = SessionStorage;
719
1632
 
720
- const SessionFinalization = (typeof FinalizationRegistry === 'undefined')
1633
+ const SignerFinalization = (typeof FinalizationRegistry === 'undefined')
721
1634
  ? { register: () => {}, unregister: () => {} }
722
- : new FinalizationRegistry(ptr => wasm.__wbg_session_free(ptr >>> 0, 1));
723
-
724
- class Session {
1635
+ : new FinalizationRegistry(ptr => wasm.__wbg_signer_free(ptr >>> 0, 1));
1636
+ /**
1637
+ * Holds a user’s `Keypair` and performs identity operations:
1638
+ * - `signup` creates a new homeserver user.
1639
+ * - `signin` creates a homeserver session for an existing user.
1640
+ * - Approve pubkyauth requests
1641
+ * - Publish PKDNS when signer-bound
1642
+ */
1643
+ class Signer {
725
1644
 
726
1645
  static __wrap(ptr) {
727
1646
  ptr = ptr >>> 0;
728
- const obj = Object.create(Session.prototype);
1647
+ const obj = Object.create(Signer.prototype);
729
1648
  obj.__wbg_ptr = ptr;
730
- SessionFinalization.register(obj, obj.__wbg_ptr, obj);
1649
+ SignerFinalization.register(obj, obj.__wbg_ptr, obj);
731
1650
  return obj;
732
1651
  }
733
1652
 
734
1653
  __destroy_into_raw() {
735
1654
  const ptr = this.__wbg_ptr;
736
1655
  this.__wbg_ptr = 0;
737
- SessionFinalization.unregister(this);
1656
+ SignerFinalization.unregister(this);
738
1657
  return ptr;
739
1658
  }
740
1659
 
741
1660
  free() {
742
1661
  const ptr = this.__destroy_into_raw();
743
- wasm.__wbg_session_free(ptr, 0);
1662
+ wasm.__wbg_signer_free(ptr, 0);
1663
+ }
1664
+ /**
1665
+ * Create a signer from a `Keypair` (prefer `pubky.signer(kp)`).
1666
+ *
1667
+ * @param {Keypair} keypair
1668
+ * @returns {Signer}
1669
+ * @param {Keypair} keypair
1670
+ * @returns {Signer}
1671
+ */
1672
+ static fromKeypair(keypair) {
1673
+ _assertClass(keypair, Keypair);
1674
+ const ret = wasm.signer_fromKeypair(keypair.__wbg_ptr);
1675
+ return Signer.__wrap(ret);
744
1676
  }
745
1677
  /**
746
- * Return the [PublicKey] of this session
1678
+ * Get the public key of this signer.
1679
+ *
1680
+ * @returns {PublicKey}
747
1681
  * @returns {PublicKey}
748
1682
  */
749
- pubky() {
750
- const ret = wasm.session_pubky(this.__wbg_ptr);
1683
+ publicKey() {
1684
+ const ret = wasm.signer_publicKey(this.__wbg_ptr);
751
1685
  return PublicKey.__wrap(ret);
752
1686
  }
753
1687
  /**
754
- * Return the capabilities that this session has.
755
- * @returns {string[]}
1688
+ * Sign up at a homeserver. Returns a ready `Session`.
1689
+ *
1690
+ * Creates a valid homeserver Session with root capabilities
1691
+ *
1692
+ * @param {PublicKey} homeserver The homeserver’s public key.
1693
+ * @param {string|null} signupToken Invite/registration token or `null`.
1694
+ * @returns {Promise<Session>}
1695
+ *
1696
+ * @throws {PubkyJsError}
1697
+ * - `AuthenticationError` (bad/expired token)
1698
+ * - `RequestError` (network/server)
1699
+ * @param {PublicKey} homeserver
1700
+ * @param {string | null} [signup_token]
1701
+ * @returns {Promise<Session>}
756
1702
  */
757
- capabilities() {
758
- const ret = wasm.session_capabilities(this.__wbg_ptr);
759
- var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
760
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
761
- return v1;
1703
+ signup(homeserver, signup_token) {
1704
+ _assertClass(homeserver, PublicKey);
1705
+ var ptr0 = isLikeNone(signup_token) ? 0 : passStringToWasm0(signup_token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1706
+ var len0 = WASM_VECTOR_LEN;
1707
+ const ret = wasm.signer_signup(this.__wbg_ptr, homeserver.__wbg_ptr, ptr0, len0);
1708
+ return ret;
1709
+ }
1710
+ /**
1711
+ * Fast sign-in for a returning user. Publishes PKDNS in the background.
1712
+ *
1713
+ * Creates a valid homeserver Session with root capabilities
1714
+ *
1715
+ * @returns {Promise<Session>}
1716
+ *
1717
+ * @throws {PubkyJsError}
1718
+ * @returns {Promise<Session>}
1719
+ */
1720
+ signin() {
1721
+ const ret = wasm.signer_signin(this.__wbg_ptr);
1722
+ return ret;
1723
+ }
1724
+ /**
1725
+ * Blocking sign-in. Waits for PKDNS publish to complete (slower; safer).
1726
+ *
1727
+ * Creates a valid homeserver Session with root capabilities
1728
+ *
1729
+ * @returns {Promise<Session>}
1730
+ * @returns {Promise<Session>}
1731
+ */
1732
+ signinBlocking() {
1733
+ const ret = wasm.signer_signinBlocking(this.__wbg_ptr);
1734
+ return ret;
1735
+ }
1736
+ /**
1737
+ * Approve a `pubkyauth://` request URL (encrypts & POSTs the signed AuthToken).
1738
+ * @param {string} pubkyauth_url
1739
+ * @returns {Promise<void>}
1740
+ */
1741
+ approveAuthRequest(pubkyauth_url) {
1742
+ const ptr0 = passStringToWasm0(pubkyauth_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1743
+ const len0 = WASM_VECTOR_LEN;
1744
+ const ret = wasm.signer_approveAuthRequest(this.__wbg_ptr, ptr0, len0);
1745
+ return ret;
1746
+ }
1747
+ /**
1748
+ * Get a PKDNS actor bound to this signer's client & keypair (publishing enabled).
1749
+ *
1750
+ * @returns {Pkdns}
1751
+ * @returns {Pkdns}
1752
+ */
1753
+ pkdns() {
1754
+ const ret = wasm.signer_pkdns(this.__wbg_ptr);
1755
+ return Pkdns.__wrap(ret);
762
1756
  }
763
1757
  }
764
- module.exports.Session = Session;
1758
+ module.exports.Signer = Signer;
765
1759
 
766
- module.exports.__wbg_abort_410ec47a64ac6117 = function(arg0, arg1) {
767
- arg0.abort(arg1);
1760
+ module.exports.__wbg_Error_0497d5bdba9362e5 = function(arg0, arg1) {
1761
+ const ret = Error(getStringFromWasm0(arg0, arg1));
1762
+ return ret;
768
1763
  };
769
1764
 
770
- module.exports.__wbg_abort_775ef1d17fc65868 = function(arg0) {
1765
+ module.exports.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
1766
+ const ret = String(arg1);
1767
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1768
+ const len1 = WASM_VECTOR_LEN;
1769
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1770
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1771
+ };
1772
+
1773
+ module.exports.__wbg_abort_18ba44d46e13d7fe = function(arg0) {
771
1774
  arg0.abort();
772
1775
  };
773
1776
 
774
- module.exports.__wbg_append_8c7dd8d641a5f01b = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
1777
+ module.exports.__wbg_abort_4198a1129c47f21a = function(arg0, arg1) {
1778
+ arg0.abort(arg1);
1779
+ };
1780
+
1781
+ module.exports.__wbg_append_0342728346e47425 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
775
1782
  arg0.append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
776
1783
  }, arguments) };
777
1784
 
778
- module.exports.__wbg_arrayBuffer_d1b44c4390db422f = function() { return handleError(function (arg0) {
1785
+ module.exports.__wbg_arrayBuffer_d58b858456021d7f = function() { return handleError(function (arg0) {
779
1786
  const ret = arg0.arrayBuffer();
780
1787
  return ret;
781
1788
  }, arguments) };
782
1789
 
783
- module.exports.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
1790
+ module.exports.__wbg_authtoken_new = function(arg0) {
1791
+ const ret = AuthToken.__wrap(arg0);
1792
+ return ret;
1793
+ };
1794
+
1795
+ module.exports.__wbg_buffer_a1a27a0dfa70165d = function(arg0) {
784
1796
  const ret = arg0.buffer;
785
1797
  return ret;
786
1798
  };
787
1799
 
788
- module.exports.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) {
789
- const ret = arg0.call(arg1);
1800
+ module.exports.__wbg_call_f2db6205e5c51dc8 = function() { return handleError(function (arg0, arg1, arg2) {
1801
+ const ret = arg0.call(arg1, arg2);
790
1802
  return ret;
791
1803
  }, arguments) };
792
1804
 
793
- module.exports.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) {
794
- const ret = arg0.call(arg1, arg2);
1805
+ module.exports.__wbg_call_fbe8be8bf6436ce5 = function() { return handleError(function (arg0, arg1) {
1806
+ const ret = arg0.call(arg1);
795
1807
  return ret;
796
1808
  }, arguments) };
797
1809
 
798
- module.exports.__wbg_clearTimeout_0b53d391c1b94dda = function(arg0) {
1810
+ module.exports.__wbg_clearTimeout_6222fede17abcb1a = function(arg0) {
799
1811
  const ret = clearTimeout(arg0);
800
1812
  return ret;
801
1813
  };
@@ -805,30 +1817,35 @@ module.exports.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
805
1817
  return ret;
806
1818
  };
807
1819
 
808
- module.exports.__wbg_debug_e17b51583ca6a632 = function(arg0, arg1, arg2, arg3) {
1820
+ module.exports.__wbg_debug_103948ed4c500577 = function(arg0, arg1, arg2, arg3) {
809
1821
  console.debug(arg0, arg1, arg2, arg3);
810
1822
  };
811
1823
 
812
- module.exports.__wbg_done_769e5ede4b31c67b = function(arg0) {
1824
+ module.exports.__wbg_done_4d01f352bade43b7 = function(arg0) {
813
1825
  const ret = arg0.done;
814
1826
  return ret;
815
1827
  };
816
1828
 
817
- module.exports.__wbg_error_80de38b3f7cc3c3c = function(arg0, arg1, arg2, arg3) {
1829
+ module.exports.__wbg_entries_41651c850143b957 = function(arg0) {
1830
+ const ret = Object.entries(arg0);
1831
+ return ret;
1832
+ };
1833
+
1834
+ module.exports.__wbg_error_624160881466fd69 = function(arg0, arg1, arg2, arg3) {
818
1835
  console.error(arg0, arg1, arg2, arg3);
819
1836
  };
820
1837
 
821
- module.exports.__wbg_fetch_11bff8299d0ecd2b = function(arg0) {
1838
+ module.exports.__wbg_fetch_0fde801b2e1aa024 = function(arg0) {
822
1839
  const ret = fetch(arg0);
823
1840
  return ret;
824
1841
  };
825
1842
 
826
- module.exports.__wbg_fetch_509096533071c657 = function(arg0, arg1) {
1843
+ module.exports.__wbg_fetch_a8e43a4e138dfc93 = function(arg0, arg1) {
827
1844
  const ret = arg0.fetch(arg1);
828
1845
  return ret;
829
1846
  };
830
1847
 
831
- module.exports.__wbg_fetch_de12f9389c1d3a90 = function(arg0) {
1848
+ module.exports.__wbg_fetch_f156d10be9a5c88a = function(arg0) {
832
1849
  const ret = fetch(arg0);
833
1850
  return ret;
834
1851
  };
@@ -841,26 +1858,64 @@ module.exports.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return hand
841
1858
  arg0.getRandomValues(arg1);
842
1859
  }, arguments) };
843
1860
 
844
- module.exports.__wbg_get_67b2ba62fc30de12 = function() { return handleError(function (arg0, arg1) {
1861
+ module.exports.__wbg_get_92470be87867c2e5 = function() { return handleError(function (arg0, arg1) {
845
1862
  const ret = Reflect.get(arg0, arg1);
846
1863
  return ret;
847
1864
  }, arguments) };
848
1865
 
849
- module.exports.__wbg_has_a5ea9117f258a0ec = function() { return handleError(function (arg0, arg1) {
1866
+ module.exports.__wbg_get_a131a44bd1eb6979 = function(arg0, arg1) {
1867
+ const ret = arg0[arg1 >>> 0];
1868
+ return ret;
1869
+ };
1870
+
1871
+ module.exports.__wbg_has_809e438ee9d787a7 = function() { return handleError(function (arg0, arg1) {
850
1872
  const ret = Reflect.has(arg0, arg1);
851
1873
  return ret;
852
1874
  }, arguments) };
853
1875
 
854
- module.exports.__wbg_headers_9cb51cfd2ac780a4 = function(arg0) {
1876
+ module.exports.__wbg_headers_0f0cbdc6290b6780 = function(arg0) {
855
1877
  const ret = arg0.headers;
856
1878
  return ret;
857
1879
  };
858
1880
 
859
- module.exports.__wbg_info_033d8b8a0838f1d3 = function(arg0, arg1, arg2, arg3) {
1881
+ module.exports.__wbg_info_a1cc312ecc877319 = function(arg0, arg1, arg2, arg3) {
860
1882
  console.info(arg0, arg1, arg2, arg3);
861
1883
  };
862
1884
 
863
- module.exports.__wbg_instanceof_Response_f2cc20d9f7dfd644 = function(arg0) {
1885
+ module.exports.__wbg_instanceof_ArrayBuffer_a8b6f580b363f2bc = function(arg0) {
1886
+ let result;
1887
+ try {
1888
+ result = arg0 instanceof ArrayBuffer;
1889
+ } catch (_) {
1890
+ result = false;
1891
+ }
1892
+ const ret = result;
1893
+ return ret;
1894
+ };
1895
+
1896
+ module.exports.__wbg_instanceof_Headers_8b4c0df841a5ed48 = function(arg0) {
1897
+ let result;
1898
+ try {
1899
+ result = arg0 instanceof Headers;
1900
+ } catch (_) {
1901
+ result = false;
1902
+ }
1903
+ const ret = result;
1904
+ return ret;
1905
+ };
1906
+
1907
+ module.exports.__wbg_instanceof_Map_80cc65041c96417a = function(arg0) {
1908
+ let result;
1909
+ try {
1910
+ result = arg0 instanceof Map;
1911
+ } catch (_) {
1912
+ result = false;
1913
+ }
1914
+ const ret = result;
1915
+ return ret;
1916
+ };
1917
+
1918
+ module.exports.__wbg_instanceof_Response_e80ce8b7a2b968d2 = function(arg0) {
864
1919
  let result;
865
1920
  try {
866
1921
  result = arg0 instanceof Response;
@@ -871,17 +1926,43 @@ module.exports.__wbg_instanceof_Response_f2cc20d9f7dfd644 = function(arg0) {
871
1926
  return ret;
872
1927
  };
873
1928
 
874
- module.exports.__wbg_iterator_9a24c88df860dc65 = function() {
1929
+ module.exports.__wbg_instanceof_Uint8Array_ca460677bc155827 = function(arg0) {
1930
+ let result;
1931
+ try {
1932
+ result = arg0 instanceof Uint8Array;
1933
+ } catch (_) {
1934
+ result = false;
1935
+ }
1936
+ const ret = result;
1937
+ return ret;
1938
+ };
1939
+
1940
+ module.exports.__wbg_isArray_5f090bed72bd4f89 = function(arg0) {
1941
+ const ret = Array.isArray(arg0);
1942
+ return ret;
1943
+ };
1944
+
1945
+ module.exports.__wbg_isSafeInteger_90d7c4674047d684 = function(arg0) {
1946
+ const ret = Number.isSafeInteger(arg0);
1947
+ return ret;
1948
+ };
1949
+
1950
+ module.exports.__wbg_iterator_4068add5b2aef7a6 = function() {
875
1951
  const ret = Symbol.iterator;
876
1952
  return ret;
877
1953
  };
878
1954
 
879
- module.exports.__wbg_length_a446193dc22c12f8 = function(arg0) {
1955
+ module.exports.__wbg_length_ab6d22b5ead75c72 = function(arg0) {
880
1956
  const ret = arg0.length;
881
1957
  return ret;
882
1958
  };
883
1959
 
884
- module.exports.__wbg_log_cad59bb680daec67 = function(arg0, arg1, arg2, arg3) {
1960
+ module.exports.__wbg_length_f00ec12454a5d9fd = function(arg0) {
1961
+ const ret = arg0.length;
1962
+ return ret;
1963
+ };
1964
+
1965
+ module.exports.__wbg_log_bff357b3df4db934 = function(arg0, arg1, arg2, arg3) {
885
1966
  console.log(arg0, arg1, arg2, arg3);
886
1967
  };
887
1968
 
@@ -890,19 +1971,39 @@ module.exports.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
890
1971
  return ret;
891
1972
  };
892
1973
 
893
- module.exports.__wbg_new_018dcc2d6c8c2f6a = function() { return handleError(function () {
1974
+ module.exports.__wbg_new_07b483f72211fd66 = function() {
1975
+ const ret = new Object();
1976
+ return ret;
1977
+ };
1978
+
1979
+ module.exports.__wbg_new_186abcfdff244e42 = function() { return handleError(function () {
1980
+ const ret = new AbortController();
1981
+ return ret;
1982
+ }, arguments) };
1983
+
1984
+ module.exports.__wbg_new_4796e1cd2eb9ea6d = function() { return handleError(function () {
894
1985
  const ret = new Headers();
895
1986
  return ret;
896
1987
  }, arguments) };
897
1988
 
898
- module.exports.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
1989
+ module.exports.__wbg_new_58353953ad2097cc = function() {
1990
+ const ret = new Array();
1991
+ return ret;
1992
+ };
1993
+
1994
+ module.exports.__wbg_new_a979b4b45bd55c7f = function() {
1995
+ const ret = new Map();
1996
+ return ret;
1997
+ };
1998
+
1999
+ module.exports.__wbg_new_e30c39c06edaabf2 = function(arg0, arg1) {
899
2000
  try {
900
2001
  var state0 = {a: arg0, b: arg1};
901
2002
  var cb0 = (arg0, arg1) => {
902
2003
  const a = state0.a;
903
2004
  state0.a = 0;
904
2005
  try {
905
- return __wbg_adapter_167(a, state0.b, arg0, arg1);
2006
+ return __wbg_adapter_120(a, state0.b, arg0, arg1);
906
2007
  } finally {
907
2008
  state0.a = a;
908
2009
  }
@@ -914,52 +2015,42 @@ module.exports.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
914
2015
  }
915
2016
  };
916
2017
 
917
- module.exports.__wbg_new_405e22f390576ce2 = function() {
918
- const ret = new Object();
919
- return ret;
920
- };
921
-
922
- module.exports.__wbg_new_78feb108b6472713 = function() {
923
- const ret = new Array();
924
- return ret;
925
- };
926
-
927
- module.exports.__wbg_new_a12002a7f91c75be = function(arg0) {
2018
+ module.exports.__wbg_new_e52b3efaaa774f96 = function(arg0) {
928
2019
  const ret = new Uint8Array(arg0);
929
2020
  return ret;
930
2021
  };
931
2022
 
932
- module.exports.__wbg_new_e25e5aab09ff45db = function() { return handleError(function () {
933
- const ret = new AbortController();
2023
+ module.exports.__wbg_newfromslice_7c05ab1297cb2d88 = function(arg0, arg1) {
2024
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
934
2025
  return ret;
935
- }, arguments) };
2026
+ };
936
2027
 
937
- module.exports.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
2028
+ module.exports.__wbg_newnoargs_ff528e72d35de39a = function(arg0, arg1) {
938
2029
  const ret = new Function(getStringFromWasm0(arg0, arg1));
939
2030
  return ret;
940
2031
  };
941
2032
 
942
- module.exports.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
2033
+ module.exports.__wbg_newwithbyteoffsetandlength_3b01ecda099177e8 = function(arg0, arg1, arg2) {
943
2034
  const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
944
2035
  return ret;
945
2036
  };
946
2037
 
947
- module.exports.__wbg_newwithlength_a381634e90c276d4 = function(arg0) {
2038
+ module.exports.__wbg_newwithlength_08f872dc1e3ada2e = function(arg0) {
948
2039
  const ret = new Uint8Array(arg0 >>> 0);
949
2040
  return ret;
950
2041
  };
951
2042
 
952
- module.exports.__wbg_newwithstrandinit_06c535e0a867c635 = function() { return handleError(function (arg0, arg1, arg2) {
2043
+ module.exports.__wbg_newwithstrandinit_f8a9dbe009d6be37 = function() { return handleError(function (arg0, arg1, arg2) {
953
2044
  const ret = new Request(getStringFromWasm0(arg0, arg1), arg2);
954
2045
  return ret;
955
2046
  }, arguments) };
956
2047
 
957
- module.exports.__wbg_next_25feadfc0913fea9 = function(arg0) {
2048
+ module.exports.__wbg_next_8bb824d217961b5d = function(arg0) {
958
2049
  const ret = arg0.next;
959
2050
  return ret;
960
2051
  };
961
2052
 
962
- module.exports.__wbg_next_6574e1a8a62d1055 = function() { return handleError(function (arg0) {
2053
+ module.exports.__wbg_next_e2da48d8fff7439a = function() { return handleError(function (arg0) {
963
2054
  const ret = arg0.next();
964
2055
  return ret;
965
2056
  }, arguments) };
@@ -969,31 +2060,31 @@ module.exports.__wbg_node_905d3e251edff8a2 = function(arg0) {
969
2060
  return ret;
970
2061
  };
971
2062
 
972
- module.exports.__wbg_now_807e54c39636c349 = function() {
2063
+ module.exports.__wbg_now_eb0821f3bd9f6529 = function() {
973
2064
  const ret = Date.now();
974
2065
  return ret;
975
2066
  };
976
2067
 
977
- module.exports.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
978
- const ret = arg0.process;
2068
+ module.exports.__wbg_parse_c7ba327fb6231e7f = function() { return handleError(function (arg0, arg1) {
2069
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
979
2070
  return ret;
980
- };
2071
+ }, arguments) };
981
2072
 
982
- module.exports.__wbg_publickey_new = function(arg0) {
983
- const ret = PublicKey.__wrap(arg0);
2073
+ module.exports.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
2074
+ const ret = arg0.process;
984
2075
  return ret;
985
2076
  };
986
2077
 
987
- module.exports.__wbg_push_737cfc8c1432c2c6 = function(arg0, arg1) {
2078
+ module.exports.__wbg_push_73fd7b5550ebf707 = function(arg0, arg1) {
988
2079
  const ret = arg0.push(arg1);
989
2080
  return ret;
990
2081
  };
991
2082
 
992
- module.exports.__wbg_queueMicrotask_97d92b4fcc8a61c5 = function(arg0) {
2083
+ module.exports.__wbg_queueMicrotask_46c1df247678729f = function(arg0) {
993
2084
  queueMicrotask(arg0);
994
2085
  };
995
2086
 
996
- module.exports.__wbg_queueMicrotask_d3219def82552485 = function(arg0) {
2087
+ module.exports.__wbg_queueMicrotask_8acf3ccb75ed8d11 = function(arg0) {
997
2088
  const ret = arg0.queueMicrotask;
998
2089
  return ret;
999
2090
  };
@@ -1007,7 +2098,7 @@ module.exports.__wbg_require_60cc747a6bc5215a = function() { return handleError(
1007
2098
  return ret;
1008
2099
  }, arguments) };
1009
2100
 
1010
- module.exports.__wbg_resolve_4851785c9c5f573d = function(arg0) {
2101
+ module.exports.__wbg_resolve_0dac8c580ffd4678 = function(arg0) {
1011
2102
  const ret = Promise.resolve(arg0);
1012
2103
  return ret;
1013
2104
  };
@@ -1017,95 +2108,116 @@ module.exports.__wbg_session_new = function(arg0) {
1017
2108
  return ret;
1018
2109
  };
1019
2110
 
1020
- module.exports.__wbg_setTimeout_73ce8df12de4f2f2 = function(arg0, arg1) {
2111
+ module.exports.__wbg_setTimeout_2b339866a2aa3789 = function(arg0, arg1) {
1021
2112
  const ret = setTimeout(arg0, arg1);
1022
2113
  return ret;
1023
2114
  };
1024
2115
 
1025
- module.exports.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
2116
+ module.exports.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
2117
+ arg0[arg1] = arg2;
2118
+ };
2119
+
2120
+ module.exports.__wbg_set_7422acbe992d64ab = function(arg0, arg1, arg2) {
2121
+ arg0[arg1 >>> 0] = arg2;
2122
+ };
2123
+
2124
+ module.exports.__wbg_set_b042eef31c50834d = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
2125
+ arg0.set(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
2126
+ }, arguments) };
2127
+
2128
+ module.exports.__wbg_set_d6bdfd275fb8a4ce = function(arg0, arg1, arg2) {
2129
+ const ret = arg0.set(arg1, arg2);
2130
+ return ret;
2131
+ };
2132
+
2133
+ module.exports.__wbg_set_fe4e79d1ed3b0e9b = function(arg0, arg1, arg2) {
1026
2134
  arg0.set(arg1, arg2 >>> 0);
1027
2135
  };
1028
2136
 
1029
- module.exports.__wbg_setbody_5923b78a95eedf29 = function(arg0, arg1) {
2137
+ module.exports.__wbg_setbody_971ec015fc13d6b4 = function(arg0, arg1) {
1030
2138
  arg0.body = arg1;
1031
2139
  };
1032
2140
 
1033
- module.exports.__wbg_setcredentials_c3a22f1cd105a2c6 = function(arg0, arg1) {
2141
+ module.exports.__wbg_setcache_a94cd14dc0cc72a2 = function(arg0, arg1) {
2142
+ arg0.cache = __wbindgen_enum_RequestCache[arg1];
2143
+ };
2144
+
2145
+ module.exports.__wbg_setcredentials_920d91fb5984c94a = function(arg0, arg1) {
1034
2146
  arg0.credentials = __wbindgen_enum_RequestCredentials[arg1];
1035
2147
  };
1036
2148
 
1037
- module.exports.__wbg_setheaders_834c0bdb6a8949ad = function(arg0, arg1) {
2149
+ module.exports.__wbg_setheaders_65a4eb4c0443ae61 = function(arg0, arg1) {
1038
2150
  arg0.headers = arg1;
1039
2151
  };
1040
2152
 
1041
- module.exports.__wbg_setmethod_3c5280fe5d890842 = function(arg0, arg1, arg2) {
2153
+ module.exports.__wbg_setmethod_8ce1be0b4d701b7c = function(arg0, arg1, arg2) {
1042
2154
  arg0.method = getStringFromWasm0(arg1, arg2);
1043
2155
  };
1044
2156
 
1045
- module.exports.__wbg_setmode_5dc300b865044b65 = function(arg0, arg1) {
2157
+ module.exports.__wbg_setmode_bd35f026f55b6247 = function(arg0, arg1) {
1046
2158
  arg0.mode = __wbindgen_enum_RequestMode[arg1];
1047
2159
  };
1048
2160
 
1049
- module.exports.__wbg_setsignal_75b21ef3a81de905 = function(arg0, arg1) {
2161
+ module.exports.__wbg_setsignal_8e72abfe7ee03c97 = function(arg0, arg1) {
1050
2162
  arg0.signal = arg1;
1051
2163
  };
1052
2164
 
1053
- module.exports.__wbg_signal_aaf9ad74119f20a4 = function(arg0) {
2165
+ module.exports.__wbg_signal_b96223519a041faa = function(arg0) {
1054
2166
  const ret = arg0.signal;
1055
2167
  return ret;
1056
2168
  };
1057
2169
 
1058
- module.exports.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() {
2170
+ module.exports.__wbg_static_accessor_GLOBAL_487c52c58d65314d = function() {
1059
2171
  const ret = typeof global === 'undefined' ? null : global;
1060
2172
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1061
2173
  };
1062
2174
 
1063
- module.exports.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() {
2175
+ module.exports.__wbg_static_accessor_GLOBAL_THIS_ee9704f328b6b291 = function() {
1064
2176
  const ret = typeof globalThis === 'undefined' ? null : globalThis;
1065
2177
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1066
2178
  };
1067
2179
 
1068
- module.exports.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() {
2180
+ module.exports.__wbg_static_accessor_SELF_78c9e3071b912620 = function() {
1069
2181
  const ret = typeof self === 'undefined' ? null : self;
1070
2182
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1071
2183
  };
1072
2184
 
1073
- module.exports.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
2185
+ module.exports.__wbg_static_accessor_WINDOW_a093d21393777366 = function() {
1074
2186
  const ret = typeof window === 'undefined' ? null : window;
1075
2187
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1076
2188
  };
1077
2189
 
1078
- module.exports.__wbg_status_f6360336ca686bf0 = function(arg0) {
2190
+ module.exports.__wbg_status_a54682bbe52f9058 = function(arg0) {
1079
2191
  const ret = arg0.status;
1080
2192
  return ret;
1081
2193
  };
1082
2194
 
1083
- module.exports.__wbg_stringify_f7ed6987935b4a24 = function() { return handleError(function (arg0) {
2195
+ module.exports.__wbg_stringify_c242842b97f054cc = function() { return handleError(function (arg0) {
1084
2196
  const ret = JSON.stringify(arg0);
1085
2197
  return ret;
1086
2198
  }, arguments) };
1087
2199
 
1088
- module.exports.__wbg_subarray_aa9065fa9dc5df96 = function(arg0, arg1, arg2) {
2200
+ module.exports.__wbg_subarray_dd4ade7d53bd8e26 = function(arg0, arg1, arg2) {
1089
2201
  const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
1090
2202
  return ret;
1091
2203
  };
1092
2204
 
1093
- module.exports.__wbg_text_7805bea50de2af49 = function() { return handleError(function (arg0) {
2205
+ module.exports.__wbg_text_ec0e22f60e30dd2f = function() { return handleError(function (arg0) {
1094
2206
  const ret = arg0.text();
1095
2207
  return ret;
1096
2208
  }, arguments) };
1097
2209
 
1098
- module.exports.__wbg_then_44b73946d2fb3e7d = function(arg0, arg1) {
1099
- const ret = arg0.then(arg1);
2210
+ module.exports.__wbg_then_82ab9fb4080f1707 = function(arg0, arg1, arg2) {
2211
+ const ret = arg0.then(arg1, arg2);
1100
2212
  return ret;
1101
2213
  };
1102
2214
 
1103
- module.exports.__wbg_then_48b406749878a531 = function(arg0, arg1, arg2) {
1104
- const ret = arg0.then(arg1, arg2);
2215
+ module.exports.__wbg_then_db882932c0c714c6 = function(arg0, arg1) {
2216
+ const ret = arg0.then(arg1);
1105
2217
  return ret;
1106
2218
  };
1107
2219
 
1108
- module.exports.__wbg_url_ae10c34ca209681d = function(arg0, arg1) {
2220
+ module.exports.__wbg_url_e6ed869ea05b7a71 = function(arg0, arg1) {
1109
2221
  const ret = arg1.url;
1110
2222
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1111
2223
  const len1 = WASM_VECTOR_LEN;
@@ -1113,7 +2225,7 @@ module.exports.__wbg_url_ae10c34ca209681d = function(arg0, arg1) {
1113
2225
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1114
2226
  };
1115
2227
 
1116
- module.exports.__wbg_value_cd1ffa7b1ab794f1 = function(arg0) {
2228
+ module.exports.__wbg_value_17b896954e14f896 = function(arg0) {
1117
2229
  const ret = arg0.value;
1118
2230
  return ret;
1119
2231
  };
@@ -1123,10 +2235,42 @@ module.exports.__wbg_versions_c01dfd4722a88165 = function(arg0) {
1123
2235
  return ret;
1124
2236
  };
1125
2237
 
1126
- module.exports.__wbg_warn_aaf1f4664a035bd6 = function(arg0, arg1, arg2, arg3) {
2238
+ module.exports.__wbg_warn_90607373221a6b1c = function(arg0, arg1, arg2, arg3) {
1127
2239
  console.warn(arg0, arg1, arg2, arg3);
1128
2240
  };
1129
2241
 
2242
+ module.exports.__wbindgen_array_new = function() {
2243
+ const ret = [];
2244
+ return ret;
2245
+ };
2246
+
2247
+ module.exports.__wbindgen_array_push = function(arg0, arg1) {
2248
+ arg0.push(arg1);
2249
+ };
2250
+
2251
+ module.exports.__wbindgen_bigint_from_i64 = function(arg0) {
2252
+ const ret = arg0;
2253
+ return ret;
2254
+ };
2255
+
2256
+ module.exports.__wbindgen_bigint_from_u64 = function(arg0) {
2257
+ const ret = BigInt.asUintN(64, arg0);
2258
+ return ret;
2259
+ };
2260
+
2261
+ module.exports.__wbindgen_bigint_get_as_i64 = function(arg0, arg1) {
2262
+ const v = arg1;
2263
+ const ret = typeof(v) === 'bigint' ? v : undefined;
2264
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
2265
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
2266
+ };
2267
+
2268
+ module.exports.__wbindgen_boolean_get = function(arg0) {
2269
+ const v = arg0;
2270
+ const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
2271
+ return ret;
2272
+ };
2273
+
1130
2274
  module.exports.__wbindgen_cb_drop = function(arg0) {
1131
2275
  const obj = arg0.original;
1132
2276
  if (obj.cnt-- == 1) {
@@ -1137,13 +2281,13 @@ module.exports.__wbindgen_cb_drop = function(arg0) {
1137
2281
  return ret;
1138
2282
  };
1139
2283
 
1140
- module.exports.__wbindgen_closure_wrapper1409 = function(arg0, arg1, arg2) {
1141
- const ret = makeMutClosure(arg0, arg1, 624, __wbg_adapter_28);
2284
+ module.exports.__wbindgen_closure_wrapper2747 = function(arg0, arg1, arg2) {
2285
+ const ret = makeMutClosure(arg0, arg1, 154, __wbg_adapter_54);
1142
2286
  return ret;
1143
2287
  };
1144
2288
 
1145
- module.exports.__wbindgen_closure_wrapper1514 = function(arg0, arg1, arg2) {
1146
- const ret = makeMutClosure(arg0, arg1, 651, __wbg_adapter_31);
2289
+ module.exports.__wbindgen_closure_wrapper3056 = function(arg0, arg1, arg2) {
2290
+ const ret = makeMutClosure(arg0, arg1, 154, __wbg_adapter_57);
1147
2291
  return ret;
1148
2292
  };
1149
2293
 
@@ -1155,8 +2299,13 @@ module.exports.__wbindgen_debug_string = function(arg0, arg1) {
1155
2299
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1156
2300
  };
1157
2301
 
2302
+ module.exports.__wbindgen_in = function(arg0, arg1) {
2303
+ const ret = arg0 in arg1;
2304
+ return ret;
2305
+ };
2306
+
1158
2307
  module.exports.__wbindgen_init_externref_table = function() {
1159
- const table = wasm.__wbindgen_export_2;
2308
+ const table = wasm.__wbindgen_export_4;
1160
2309
  const offset = table.grow(4);
1161
2310
  table.set(0, undefined);
1162
2311
  table.set(offset + 0, undefined);
@@ -1166,11 +2315,21 @@ module.exports.__wbindgen_init_externref_table = function() {
1166
2315
  ;
1167
2316
  };
1168
2317
 
2318
+ module.exports.__wbindgen_is_bigint = function(arg0) {
2319
+ const ret = typeof(arg0) === 'bigint';
2320
+ return ret;
2321
+ };
2322
+
1169
2323
  module.exports.__wbindgen_is_function = function(arg0) {
1170
2324
  const ret = typeof(arg0) === 'function';
1171
2325
  return ret;
1172
2326
  };
1173
2327
 
2328
+ module.exports.__wbindgen_is_null = function(arg0) {
2329
+ const ret = arg0 === null;
2330
+ return ret;
2331
+ };
2332
+
1174
2333
  module.exports.__wbindgen_is_object = function(arg0) {
1175
2334
  const val = arg0;
1176
2335
  const ret = typeof(val) === 'object' && val !== null;
@@ -1187,11 +2346,33 @@ module.exports.__wbindgen_is_undefined = function(arg0) {
1187
2346
  return ret;
1188
2347
  };
1189
2348
 
2349
+ module.exports.__wbindgen_jsval_eq = function(arg0, arg1) {
2350
+ const ret = arg0 === arg1;
2351
+ return ret;
2352
+ };
2353
+
2354
+ module.exports.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
2355
+ const ret = arg0 == arg1;
2356
+ return ret;
2357
+ };
2358
+
1190
2359
  module.exports.__wbindgen_memory = function() {
1191
2360
  const ret = wasm.memory;
1192
2361
  return ret;
1193
2362
  };
1194
2363
 
2364
+ module.exports.__wbindgen_number_get = function(arg0, arg1) {
2365
+ const obj = arg1;
2366
+ const ret = typeof(obj) === 'number' ? obj : undefined;
2367
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
2368
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
2369
+ };
2370
+
2371
+ module.exports.__wbindgen_number_new = function(arg0) {
2372
+ const ret = arg0;
2373
+ return ret;
2374
+ };
2375
+
1195
2376
  module.exports.__wbindgen_string_get = function(arg0, arg1) {
1196
2377
  const obj = arg1;
1197
2378
  const ret = typeof(obj) === 'string' ? obj : undefined;
@@ -1210,7 +2391,7 @@ module.exports.__wbindgen_throw = function(arg0, arg1) {
1210
2391
  throw new Error(getStringFromWasm0(arg0, arg1));
1211
2392
  };
1212
2393
 
1213
- const path = require('path').join(__dirname, 'pubky_wasm_bg.wasm');
2394
+ const path = require('path').join(__dirname, 'pubky_bg.wasm');
1214
2395
  const bytes = require('fs').readFileSync(path);
1215
2396
 
1216
2397
  const wasmModule = new WebAssembly.Module(bytes);