@synonymdev/pubky 0.16.0 → 0.16.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.
package/README.md CHANGED
@@ -237,6 +237,20 @@ for compatibility and expiry behavior.
237
237
  await signer.approveAuthRequest("pubkyauth://signin?caps=...&secret=...&relay=...");
238
238
  ```
239
239
 
240
+ `approveAuthRequest()` approves every requested capability. To approve fewer
241
+ scopes or actions, pass a capabilities string to `approveAuthWithCapabilities()`:
242
+
243
+ ```js
244
+ // The request includes `/pub/example.app/:rwe`; the user approves only read.
245
+ await signer.approveAuthWithCapabilities(authUrl, "/pub/example.app/:r");
246
+ ```
247
+
248
+ See [selecting capabilities on the signing device][select-capabilities] for
249
+ validation rules, empty approvals, and encryption key delivery.
250
+
251
+ [select-capabilities]:
252
+ ../../../../docs/scoped-encryption-keys.md#select-capabilities-on-the-signing-device
253
+
240
254
  **Handle a pubkyauth deep link**
241
255
 
242
256
  General entry point for any supported `pubkyauth://` link. Auth request links
package/index.cjs CHANGED
@@ -5,6 +5,22 @@ globalThis.fetch = makeFetchCookie(originalFetch);
5
5
 
6
6
  /* @ts-self-types="./pubky.d.ts" */
7
7
 
8
+ function __pubkyRecoveredEncryptionKeys(publicKey, grantId, keys) {
9
+ return { publicKey, grantId, keys };
10
+ }
11
+
12
+ async function __pubkyImportEncryptionCryptoKey(bytes) {
13
+ try {
14
+ if (!globalThis.crypto?.subtle) {
15
+ throw new Error("WebCrypto is unavailable; use a secure context.");
16
+ }
17
+ return await globalThis.crypto.subtle.importKey(
18
+ "raw", bytes, "AES-GCM", false, ["encrypt", "decrypt"]);
19
+ } finally {
20
+ bytes.fill(0);
21
+ }
22
+ }
23
+
8
24
  const PUBKY_SESSIONS_DB_NAME = "pubky-auth";
9
25
  const PUBKY_SESSIONS_DB_VERSION = 1;
10
26
  const PUBKY_SESSIONS_STORE_NAME = "storedSessions";
@@ -553,22 +569,6 @@ async function __pubkyGrantDelegatedSign(keyId, signingInput) {
553
569
  }
554
570
 
555
571
 
556
- function __pubkyRecoveredEncryptionKeys(publicKey, grantId, keys) {
557
- return { publicKey, grantId, keys };
558
- }
559
-
560
- async function __pubkyImportEncryptionCryptoKey(bytes) {
561
- try {
562
- if (!globalThis.crypto?.subtle) {
563
- throw new Error("WebCrypto is unavailable; use a secure context.");
564
- }
565
- return await globalThis.crypto.subtle.importKey(
566
- "raw", bytes, "AES-GCM", false, ["encrypt", "decrypt"]);
567
- } finally {
568
- bytes.fill(0);
569
- }
570
- }
571
-
572
572
  /**
573
573
  * Start and control a pubkyauth authorization flow.
574
574
  *
@@ -3997,8 +3997,10 @@ class SessionStorage {
3997
3997
  * @param {Uint8Array} body
3998
3998
  * @returns {Promise<void>}
3999
3999
  * @throws {PubkyError} A lock that has expired or was unlocked rejects with
4000
- * `RequestError` and status `412`; take a new one and read the file again.
4001
- * Otherwise as {@link SessionStorage.putBytes}.
4000
+ * `RequestError` and status `412`; take a new one and read the file again. A file
4001
+ * that changed since the write was prepared rejects with status `409`, which can
4002
+ * happen when an earlier change the storage backend ran late lands first; read it
4003
+ * again and retry. Otherwise as {@link SessionStorage.putBytes}.
4002
4004
  * @param {StorageLock} lock
4003
4005
  * @param {Uint8Array} body
4004
4006
  * @returns {Promise<void>}
@@ -4054,8 +4056,10 @@ class SessionStorage {
4054
4056
  * @param {string} body
4055
4057
  * @returns {Promise<void>}
4056
4058
  * @throws {PubkyError} A lock that has expired or was unlocked rejects with
4057
- * `RequestError` and status `412`; take a new one and read the file again.
4058
- * Otherwise as {@link SessionStorage.putText}.
4059
+ * `RequestError` and status `412`; take a new one and read the file again. A file
4060
+ * that changed since the write was prepared rejects with status `409`, which can
4061
+ * happen when an earlier change the storage backend ran late lands first; read it
4062
+ * again and retry. Otherwise as {@link SessionStorage.putText}.
4059
4063
  * @param {StorageLock} lock
4060
4064
  * @param {string} body
4061
4065
  * @returns {Promise<void>}
@@ -4170,7 +4174,7 @@ class Signer {
4170
4174
  wasm.__wbg_signer_free(ptr, 0);
4171
4175
  }
4172
4176
  /**
4173
- * Approve a `pubkyauth://` request URL (encrypts & POSTs the signed AuthToken).
4177
+ * Approve all capabilities in a `pubkyauth://` auth request URL.
4174
4178
  * @param {string} pubkyauth_url
4175
4179
  * @returns {Promise<void>}
4176
4180
  */
@@ -4180,6 +4184,28 @@ class Signer {
4180
4184
  const ret = wasm.signer_approveAuthRequest(this.__wbg_ptr, ptr0, len0);
4181
4185
  return ret;
4182
4186
  }
4187
+ /**
4188
+ * Approve selected capabilities in a `pubkyauth://` auth request URL.
4189
+ *
4190
+ * Scopes and actions must be covered by the request. An empty string
4191
+ * approves no capabilities. V1 grants deliver keys only for approved `e`
4192
+ * scopes. Supports grant and legacy signin/signup requests.
4193
+ * Invalid capabilities or approvals exceeding the request fail before POST.
4194
+ *
4195
+ * @example
4196
+ * await signer.approveAuthWithCapabilities(authUrl, "/pub/example.app/:r");
4197
+ * @param {string} pubkyauth_url
4198
+ * @param {string} approved_capabilities
4199
+ * @returns {Promise<void>}
4200
+ */
4201
+ approveAuthWithCapabilities(pubkyauth_url, approved_capabilities) {
4202
+ const ptr0 = passStringToWasm0(pubkyauth_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
4203
+ const len0 = WASM_VECTOR_LEN;
4204
+ const ptr1 = passStringToWasm0(approved_capabilities, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
4205
+ const len1 = WASM_VECTOR_LEN;
4206
+ const ret = wasm.signer_approveAuthWithCapabilities(this.__wbg_ptr, ptr0, len0, ptr1, len1);
4207
+ return ret;
4208
+ }
4183
4209
  /**
4184
4210
  * Create a signer from a `Keypair` (prefer `pubky.signer(kp)`).
4185
4211
  *
@@ -5383,7 +5409,7 @@ function __wbg_get_imports() {
5383
5409
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
5384
5410
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
5385
5411
  },
5386
- __wbg___pubkyGrantDelegatedSign_45b22729433b1c79: function(arg0, arg1, arg2, arg3) {
5412
+ __wbg___pubkyGrantDelegatedSign_1a62bf8388fed293: function(arg0, arg1, arg2, arg3) {
5387
5413
  let deferred0_0;
5388
5414
  let deferred0_1;
5389
5415
  let deferred1_0;
@@ -5400,7 +5426,7 @@ function __wbg_get_imports() {
5400
5426
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
5401
5427
  }
5402
5428
  },
5403
- __wbg___pubkyGrantEnsureDelegatedKey_4f1cc4ccb5acf4e8: function(arg0, arg1) {
5429
+ __wbg___pubkyGrantEnsureDelegatedKey_555c8876d02a11aa: function(arg0, arg1) {
5404
5430
  let v0;
5405
5431
  if (arg0 !== 0) {
5406
5432
  v0 = getStringFromWasm0(arg0, arg1);
@@ -5409,7 +5435,7 @@ function __wbg_get_imports() {
5409
5435
  const ret = __pubkyGrantEnsureDelegatedKey(v0);
5410
5436
  return ret;
5411
5437
  },
5412
- __wbg___pubkyGrantLoadDelegatedPublicKey_6591f0667321395a: function(arg0, arg1) {
5438
+ __wbg___pubkyGrantLoadDelegatedPublicKey_f1b34a21ea0cde6e: function(arg0, arg1) {
5413
5439
  let deferred0_0;
5414
5440
  let deferred0_1;
5415
5441
  try {
@@ -5421,18 +5447,18 @@ function __wbg_get_imports() {
5421
5447
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
5422
5448
  }
5423
5449
  },
5424
- __wbg___pubkyRecoveredEncryptionKeys_7375e79d20b5b126: function(arg0, arg1, arg2, arg3, arg4) {
5450
+ __wbg___pubkyRecoveredEncryptionKeys_e9143429efc3030f: function(arg0, arg1, arg2, arg3, arg4) {
5425
5451
  const ret = __pubkyRecoveredEncryptionKeys(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), EncryptionKeys.__wrap(arg4));
5426
5452
  return ret;
5427
5453
  },
5428
- __wbg___pubkySessionAcquire_356f865b2001b846: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
5454
+ __wbg___pubkySessionAcquire_2270c91b242c47dd: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
5429
5455
  const ret = __pubkySessionAcquire(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), arg4 !== 0);
5430
5456
  return ret;
5431
5457
  }, arguments); },
5432
- __wbg___pubkySessionRelease_3195014f66dee6ac: function(arg0) {
5458
+ __wbg___pubkySessionRelease_eea4e4e2e0b6f186: function(arg0) {
5433
5459
  __pubkySessionRelease(arg0 >>> 0);
5434
5460
  },
5435
- __wbg___pubkySessionStoreGet_618e59d7f6ad6c2a: function(arg0, arg1) {
5461
+ __wbg___pubkySessionStoreGet_a2bf2ae3f6833d1e: function(arg0, arg1) {
5436
5462
  let deferred0_0;
5437
5463
  let deferred0_1;
5438
5464
  try {
@@ -5444,7 +5470,7 @@ function __wbg_get_imports() {
5444
5470
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
5445
5471
  }
5446
5472
  },
5447
- __wbg___pubkySessionStoreMetadata_a69b8b6778109b6e: function(arg0, arg1) {
5473
+ __wbg___pubkySessionStoreMetadata_50fe94d8b9c3f08d: function(arg0, arg1) {
5448
5474
  let deferred0_0;
5449
5475
  let deferred0_1;
5450
5476
  try {
@@ -5456,23 +5482,23 @@ function __wbg_get_imports() {
5456
5482
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
5457
5483
  }
5458
5484
  },
5459
- __wbg___pubkySessionStorePut_aa2189e6e7fdc513: function(arg0, arg1) {
5485
+ __wbg___pubkySessionStorePut_832a775a63a9bd6a: function(arg0, arg1) {
5460
5486
  const ret = __pubkySessionStorePut(arg0, arg1 >>> 0);
5461
5487
  return ret;
5462
5488
  },
5463
- __wbg___pubkySessionWait_a67a8077a61d91d1: function(arg0) {
5489
+ __wbg___pubkySessionWait_5fd2b82f5655b4f2: function(arg0) {
5464
5490
  const ret = __pubkySessionWait(arg0 >>> 0);
5465
5491
  return ret;
5466
5492
  },
5467
- __wbg___pubkySharedSessionLoad_4190e716399b75e0: function(arg0) {
5493
+ __wbg___pubkySharedSessionLoad_c69d86a0a8d83739: function(arg0) {
5468
5494
  const ret = __pubkySharedSessionLoad(arg0 >>> 0);
5469
5495
  return ret;
5470
5496
  },
5471
- __wbg___pubkySharedSessionRemove_f037c015c530dc4d: function(arg0) {
5497
+ __wbg___pubkySharedSessionRemove_2d46ed7e88cf9aea: function(arg0) {
5472
5498
  const ret = __pubkySharedSessionRemove(arg0 >>> 0);
5473
5499
  return ret;
5474
5500
  },
5475
- __wbg___pubkySharedSessionStore_3e370536d89738a5: function(arg0, arg1) {
5501
+ __wbg___pubkySharedSessionStore_7de3e1f4d6897d65: function(arg0, arg1) {
5476
5502
  const ret = __pubkySharedSessionStore(arg0 >>> 0, arg1);
5477
5503
  return ret;
5478
5504
  },
@@ -5647,11 +5673,11 @@ function __wbg_get_imports() {
5647
5673
  const ret = Event.__wrap(arg0);
5648
5674
  return ret;
5649
5675
  },
5650
- __wbg_fetch_7a37768ab67c5bd8: function(arg0) {
5676
+ __wbg_fetch_5aa263e0c14b0c5f: function(arg0) {
5651
5677
  const ret = fetch(arg0);
5652
5678
  return ret;
5653
5679
  },
5654
- __wbg_fetch_8ce5bc1de67f3146: function(arg0) {
5680
+ __wbg_fetch_7a37768ab67c5bd8: function(arg0) {
5655
5681
  const ret = fetch(arg0);
5656
5682
  return ret;
5657
5683
  },
@@ -6116,12 +6142,12 @@ function __wbg_get_imports() {
6116
6142
  return ret;
6117
6143
  },
6118
6144
  __wbindgen_generic_0000000000000002: function(arg0, arg1) {
6119
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 284, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
6145
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 281, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
6120
6146
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_6fb33c0245079662___convert__closures_____invoke___wasm_bindgen_6fb33c0245079662___JsValue______true_);
6121
6147
  return ret;
6122
6148
  },
6123
6149
  __wbindgen_generic_0000000000000003: function(arg0, arg1) {
6124
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 282, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
6150
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 279, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
6125
6151
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_6fb33c0245079662___convert__closures_____invoke_______true_);
6126
6152
  return ret;
6127
6153
  },
@@ -6160,14 +6186,14 @@ function __wbg_get_imports() {
6160
6186
  __wbindgen_generic_000000000000000a: function(arg0, arg1) {
6161
6187
  var v0 = getArrayJsValueFromWasm0(arg0, arg1);
6162
6188
  wasm.__wbindgen_free(arg0, arg1 * 4, 4);
6163
- // Cast intrinsic for `Vector(RustStruct { name: "GrantInfo", unique_crate_identifier: "pubky-wasm-a72b7beb1b0b81b7" }) -> Externref`.
6189
+ // Cast intrinsic for `Vector(RustStruct { name: "GrantInfo", unique_crate_identifier: "pubky-wasm-de62feec958b8982" }) -> Externref`.
6164
6190
  const ret = v0;
6165
6191
  return ret;
6166
6192
  },
6167
6193
  __wbindgen_generic_000000000000000b: function(arg0, arg1) {
6168
6194
  var v0 = getArrayJsValueFromWasm0(arg0, arg1);
6169
6195
  wasm.__wbindgen_free(arg0, arg1 * 4, 4);
6170
- // Cast intrinsic for `Vector(RustStruct { name: "StoredSessionInfo", unique_crate_identifier: "pubky-wasm-a72b7beb1b0b81b7" }) -> Externref`.
6196
+ // Cast intrinsic for `Vector(RustStruct { name: "StoredSessionInfo", unique_crate_identifier: "pubky-wasm-de62feec958b8982" }) -> Externref`.
6171
6197
  const ret = v0;
6172
6198
  return ret;
6173
6199
  },
@@ -6184,13 +6210,13 @@ function __wbg_get_imports() {
6184
6210
  return {
6185
6211
  __proto__: null,
6186
6212
  "./pubky_bg.js": import0,
6187
- "./snippets/pubky-wasm-a72b7beb1b0b81b7/inline0.js": import1,
6188
- "./snippets/pubky-wasm-a72b7beb1b0b81b7/inline0.js": import2,
6189
- "./snippets/pubky-wasm-a72b7beb1b0b81b7/inline0.js": import3,
6190
- "./snippets/pubky-wasm-a72b7beb1b0b81b7/inline0.js": import4,
6191
- "./snippets/pubky-wasm-a72b7beb1b0b81b7/inline1.js": import5,
6192
- "./snippets/pubky-wasm-a72b7beb1b0b81b7/inline2.js": import6,
6193
- "./snippets/pubky-wasm-a72b7beb1b0b81b7/inline1.js": import7,
6213
+ "./snippets/pubky-wasm-de62feec958b8982/inline1.js": import1,
6214
+ "./snippets/pubky-wasm-de62feec958b8982/inline1.js": import2,
6215
+ "./snippets/pubky-wasm-de62feec958b8982/inline1.js": import3,
6216
+ "./snippets/pubky-wasm-de62feec958b8982/inline1.js": import4,
6217
+ "./snippets/pubky-wasm-de62feec958b8982/inline2.js": import5,
6218
+ "./snippets/pubky-wasm-de62feec958b8982/inline0.js": import6,
6219
+ "./snippets/pubky-wasm-de62feec958b8982/inline2.js": import7,
6194
6220
  };
6195
6221
  }
6196
6222