@synonymdev/pubky 0.4.0-rc3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -103,11 +103,13 @@ await client.signout(publicKey)
103
103
 
104
104
  #### authRequest
105
105
  ```js
106
- let [pubkyauthUrl, sessionPromise] = client.authRequest(relay, capabilities);
106
+ let pubkyAuthRequest = client.authRequest(relay, capabilities);
107
+
108
+ let pubkyauthUrl= pubkyAuthRequest.url();
107
109
 
108
110
  showQr(pubkyauthUrl);
109
111
 
110
- let pubky = await sessionPromise;
112
+ let pubky = await pubkyAuthRequest.response();
111
113
  ```
112
114
 
113
115
  Sign in to a user's Homeserver, without access to their [Keypair](#keypair), nor even [PublicKey](#publickey),
@@ -116,10 +118,6 @@ instead request permissions (showing the user pubkyauthUrl), and await a Session
116
118
  - relay: A URL to an [HTTP relay](https://httprelay.io/features/link/) endpoint.
117
119
  - capabilities: A list of capabilities required for the app for example `/pub/pubky.app/:rw,/pub/example.com/:r`.
118
120
 
119
- Returns:
120
- - pubkyauthUrl: A url to show to the user to scan or paste into an Authenticator app holding the user [Keypair](#keypair)
121
- - sessionPromise: A promise that resolves into a [PublicKey](#publickey) on success, which you can use in `client.session(pubky)` to resolve more information about the Session.
122
-
123
121
  #### sendAuthToken
124
122
  ```js
125
123
  await client.sendAuthToken(keypair, pubkyauthUrl);
package/index.cjs CHANGED
@@ -52,6 +52,11 @@ function handleError(f, args) {
52
52
  }
53
53
  }
54
54
 
55
+ function getArrayU8FromWasm0(ptr, len) {
56
+ ptr = ptr >>> 0;
57
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
58
+ }
59
+
55
60
  function dropObject(idx) {
56
61
  if (idx < 132) return;
57
62
  heap[idx] = heap_next;
@@ -228,6 +233,16 @@ function debugString(val) {
228
233
  // TODO we could test for more things here, like `Set`s and `Map`s.
229
234
  return className;
230
235
  }
236
+
237
+ function getArrayJsValueFromWasm0(ptr, len) {
238
+ ptr = ptr >>> 0;
239
+ const mem = getDataViewMemory0();
240
+ const result = [];
241
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
242
+ result.push(takeObject(mem.getUint32(i, true)));
243
+ }
244
+ return result;
245
+ }
231
246
  /**
232
247
  * @param {string} level
233
248
  */
@@ -260,22 +275,11 @@ function _assertClass(instance, klass) {
260
275
  * @returns {Uint8Array}
261
276
  */
262
277
  module.exports.createRecoveryFile = function(keypair, passphrase) {
263
- try {
264
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
265
- _assertClass(keypair, Keypair);
266
- const ptr0 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
267
- const len0 = WASM_VECTOR_LEN;
268
- wasm.createRecoveryFile(retptr, keypair.__wbg_ptr, ptr0, len0);
269
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
270
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
271
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
272
- if (r2) {
273
- throw takeObject(r1);
274
- }
275
- return takeObject(r0);
276
- } finally {
277
- wasm.__wbindgen_add_to_stack_pointer(16);
278
- }
278
+ _assertClass(keypair, Keypair);
279
+ const ptr0 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
280
+ const len0 = WASM_VECTOR_LEN;
281
+ const ret = wasm.createRecoveryFile(keypair.__wbg_ptr, ptr0, len0);
282
+ return takeObject(ret);
279
283
  };
280
284
 
281
285
  function passArray8ToWasm0(arg, malloc) {
@@ -311,33 +315,85 @@ module.exports.decryptRecoveryFile = function(recovery_file, passphrase) {
311
315
  }
312
316
  };
313
317
 
314
- function getArrayJsValueFromWasm0(ptr, len) {
315
- ptr = ptr >>> 0;
316
- const mem = getDataViewMemory0();
317
- const result = [];
318
- for (let i = ptr; i < ptr + 4 * len; i += 4) {
319
- result.push(takeObject(mem.getUint32(i, true)));
320
- }
321
- return result;
322
- }
323
318
  function __wbg_adapter_28(arg0, arg1, arg2) {
324
- wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h3377896d609abf0a(arg0, arg1, addHeapObject(arg2));
319
+ wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h39e5fd1911bc8420(arg0, arg1, addHeapObject(arg2));
325
320
  }
326
321
 
327
- function __wbg_adapter_153(arg0, arg1, arg2, arg3) {
328
- wasm.wasm_bindgen__convert__closures__invoke2_mut__h53c3869863f2beff(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
322
+ function __wbg_adapter_155(arg0, arg1, arg2, arg3) {
323
+ wasm.wasm_bindgen__convert__closures__invoke2_mut__h93832735ab1a1a6b(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
329
324
  }
330
325
 
331
326
  const __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
332
327
 
333
328
  const __wbindgen_enum_RequestMode = ["same-origin", "no-cors", "cors", "navigate"];
334
329
 
330
+ const AuthRequestFinalization = (typeof FinalizationRegistry === 'undefined')
331
+ ? { register: () => {}, unregister: () => {} }
332
+ : new FinalizationRegistry(ptr => wasm.__wbg_authrequest_free(ptr >>> 0, 1));
333
+
334
+ class AuthRequest {
335
+
336
+ static __wrap(ptr) {
337
+ ptr = ptr >>> 0;
338
+ const obj = Object.create(AuthRequest.prototype);
339
+ obj.__wbg_ptr = ptr;
340
+ AuthRequestFinalization.register(obj, obj.__wbg_ptr, obj);
341
+ return obj;
342
+ }
343
+
344
+ __destroy_into_raw() {
345
+ const ptr = this.__wbg_ptr;
346
+ this.__wbg_ptr = 0;
347
+ AuthRequestFinalization.unregister(this);
348
+ return ptr;
349
+ }
350
+
351
+ free() {
352
+ const ptr = this.__destroy_into_raw();
353
+ wasm.__wbg_authrequest_free(ptr, 0);
354
+ }
355
+ /**
356
+ * Returns the Pubky Auth url, which you should show to the user
357
+ * to request an authentication or authorization token.
358
+ *
359
+ * Wait for this token using `this.response()`.
360
+ * @returns {string}
361
+ */
362
+ url() {
363
+ let deferred1_0;
364
+ let deferred1_1;
365
+ try {
366
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
367
+ wasm.authrequest_url(retptr, this.__wbg_ptr);
368
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
369
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
370
+ deferred1_0 = r0;
371
+ deferred1_1 = r1;
372
+ return getStringFromWasm0(r0, r1);
373
+ } finally {
374
+ wasm.__wbindgen_add_to_stack_pointer(16);
375
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
376
+ }
377
+ }
378
+ /**
379
+ * Wait for the user to send an authentication or authorization proof.
380
+ *
381
+ * If successful, you should expect an instance of [PublicKey]
382
+ *
383
+ * Otherwise it will throw an error.
384
+ * @returns {Promise<PublicKey>}
385
+ */
386
+ response() {
387
+ const ret = wasm.authrequest_response(this.__wbg_ptr);
388
+ return takeObject(ret);
389
+ }
390
+ }
391
+ module.exports.AuthRequest = AuthRequest;
392
+
335
393
  const ClientFinalization = (typeof FinalizationRegistry === 'undefined')
336
394
  ? { register: () => {}, unregister: () => {} }
337
395
  : new FinalizationRegistry(ptr => wasm.__wbg_client_free(ptr >>> 0, 1));
338
- /**
339
- * A client for Pubky homeserver API, as well as generic HTTP requests to Pubky urls.
340
- */
396
+
341
397
  class Client {
342
398
 
343
399
  static __wrap(ptr) {
@@ -379,6 +435,41 @@ class Client {
379
435
  const ret = wasm.client_testnet();
380
436
  return Client.__wrap(ret);
381
437
  }
438
+ /**
439
+ * @param {string} url
440
+ * @param {any | null} [request_init]
441
+ * @returns {Promise<Promise<any>>}
442
+ */
443
+ fetch(url, request_init) {
444
+ const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
445
+ const len0 = WASM_VECTOR_LEN;
446
+ const ret = wasm.client_fetch(this.__wbg_ptr, ptr0, len0, isLikeNone(request_init) ? 0 : addHeapObject(request_init));
447
+ return takeObject(ret);
448
+ }
449
+ /**
450
+ * Returns a list of Pubky urls (as strings).
451
+ *
452
+ * - `url`: The Pubky url (string) to the directory you want to list its content.
453
+ * - `cursor`: Either a full `pubky://` Url (from previous list response),
454
+ * or a path (to a file or directory) relative to the `url`
455
+ * - `reverse`: List in reverse order
456
+ * - `limit` Limit the number of urls in the response
457
+ * - `shallow`: List directories and files, instead of flat list of files.
458
+ * @param {string} url
459
+ * @param {string | null} [cursor]
460
+ * @param {boolean | null} [reverse]
461
+ * @param {number | null} [limit]
462
+ * @param {boolean | null} [shallow]
463
+ * @returns {Promise<Array<any>>}
464
+ */
465
+ list(url, cursor, reverse, limit, shallow) {
466
+ const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
467
+ const len0 = WASM_VECTOR_LEN;
468
+ var ptr1 = isLikeNone(cursor) ? 0 : passStringToWasm0(cursor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
469
+ var len1 = WASM_VECTOR_LEN;
470
+ 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);
471
+ return takeObject(ret);
472
+ }
382
473
  /**
383
474
  * Signup to a homeserver and update Pkarr accordingly.
384
475
  *
@@ -395,10 +486,10 @@ class Client {
395
486
  return takeObject(ret);
396
487
  }
397
488
  /**
398
- * Check the current sesison for a given Pubky in its homeserver.
489
+ * Check the current session for a given Pubky in its homeserver.
399
490
  *
400
- * Returns [Session] or `None` (if recieved `404 NOT_FOUND`),
401
- * or throws the recieved error if the response has any other `>=400` status code.
491
+ * Returns [Session] or `None` (if received `404 NOT_FOUND`),
492
+ * or throws the received error if the response has any other `>=400` status code.
402
493
  * @param {PublicKey} pubky
403
494
  * @returns {Promise<Session | undefined>}
404
495
  */
@@ -432,10 +523,10 @@ class Client {
432
523
  * verifying that AuthToken, and if capabilities were requested, signing in to
433
524
  * the Pubky's homeserver and returning the [Session] information.
434
525
  *
435
- * Returns a tuple of [pubkyAuthUrl, Promise<Session>]
526
+ * Returns a [AuthRequest]
436
527
  * @param {string} relay
437
528
  * @param {string} capabilities
438
- * @returns {Array<any>}
529
+ * @returns {AuthRequest}
439
530
  */
440
531
  authRequest(relay, capabilities) {
441
532
  try {
@@ -451,7 +542,7 @@ class Client {
451
542
  if (r2) {
452
543
  throw takeObject(r1);
453
544
  }
454
- return takeObject(r0);
545
+ return AuthRequest.__wrap(r0);
455
546
  } finally {
456
547
  wasm.__wbindgen_add_to_stack_pointer(16);
457
548
  }
@@ -470,41 +561,6 @@ class Client {
470
561
  const ret = wasm.client_sendAuthToken(this.__wbg_ptr, keypair.__wbg_ptr, ptr0, len0);
471
562
  return takeObject(ret);
472
563
  }
473
- /**
474
- * Returns a list of Pubky urls (as strings).
475
- *
476
- * - `url`: The Pubky url (string) to the directory you want to list its content.
477
- * - `cursor`: Either a full `pubky://` Url (from previous list response),
478
- * or a path (to a file or directory) relative to the `url`
479
- * - `reverse`: List in reverse order
480
- * - `limit` Limit the number of urls in the response
481
- * - `shallow`: List directories and files, instead of flat list of files.
482
- * @param {string} url
483
- * @param {string | null} [cursor]
484
- * @param {boolean | null} [reverse]
485
- * @param {number | null} [limit]
486
- * @param {boolean | null} [shallow]
487
- * @returns {Promise<Array<any>>}
488
- */
489
- list(url, cursor, reverse, limit, shallow) {
490
- const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
491
- const len0 = WASM_VECTOR_LEN;
492
- var ptr1 = isLikeNone(cursor) ? 0 : passStringToWasm0(cursor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
493
- var len1 = WASM_VECTOR_LEN;
494
- 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);
495
- return takeObject(ret);
496
- }
497
- /**
498
- * @param {string} url
499
- * @param {any | null} [request_init]
500
- * @returns {Promise<Promise<any>>}
501
- */
502
- fetch(url, request_init) {
503
- const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
504
- const len0 = WASM_VECTOR_LEN;
505
- const ret = wasm.client_fetch(this.__wbg_ptr, ptr0, len0, isLikeNone(request_init) ? 0 : addHeapObject(request_init));
506
- return takeObject(ret);
507
- }
508
564
  }
509
565
  module.exports.Client = Client;
510
566
 
@@ -760,11 +816,6 @@ module.exports.__wbg_error_80de38b3f7cc3c3c = function(arg0, arg1, arg2, arg3) {
760
816
  console.error(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
761
817
  };
762
818
 
763
- module.exports.__wbg_fetch_408fc9f7fddb9d4e = function(arg0) {
764
- const ret = fetch(getObject(arg0));
765
- return addHeapObject(ret);
766
- };
767
-
768
819
  module.exports.__wbg_fetch_4465c2b10f21a927 = function(arg0) {
769
820
  const ret = fetch(getObject(arg0));
770
821
  return addHeapObject(ret);
@@ -775,6 +826,15 @@ module.exports.__wbg_fetch_509096533071c657 = function(arg0, arg1) {
775
826
  return addHeapObject(ret);
776
827
  };
777
828
 
829
+ module.exports.__wbg_fetch_dd5ce2b90da36779 = function(arg0) {
830
+ const ret = fetch(getObject(arg0));
831
+ return addHeapObject(ret);
832
+ };
833
+
834
+ module.exports.__wbg_getRandomValues_78e016fdd1d721cf = function() { return handleError(function (arg0, arg1) {
835
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
836
+ }, arguments) };
837
+
778
838
  module.exports.__wbg_getRandomValues_bcb4912f16000dc4 = function() { return handleError(function (arg0, arg1) {
779
839
  getObject(arg0).getRandomValues(getObject(arg1));
780
840
  }, arguments) };
@@ -856,7 +916,7 @@ module.exports.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
856
916
  const a = state0.a;
857
917
  state0.a = 0;
858
918
  try {
859
- return __wbg_adapter_153(a, state0.b, arg0, arg1);
919
+ return __wbg_adapter_155(a, state0.b, arg0, arg1);
860
920
  } finally {
861
921
  state0.a = a;
862
922
  }
@@ -1086,8 +1146,8 @@ module.exports.__wbindgen_cb_drop = function(arg0) {
1086
1146
  return ret;
1087
1147
  };
1088
1148
 
1089
- module.exports.__wbindgen_closure_wrapper2728 = function(arg0, arg1, arg2) {
1090
- const ret = makeMutClosure(arg0, arg1, 534, __wbg_adapter_28);
1149
+ module.exports.__wbindgen_closure_wrapper2845 = function(arg0, arg1, arg2) {
1150
+ const ret = makeMutClosure(arg0, arg1, 515, __wbg_adapter_28);
1091
1151
  return addHeapObject(ret);
1092
1152
  };
1093
1153