@synonymdev/pubky 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/index.cjs +65 -43
- package/index.js +66 -44
- package/package.json +1 -1
- package/pubky.d.ts +13 -1
- package/pubky_bg.wasm +0 -0
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
|
*
|
|
@@ -4170,7 +4170,7 @@ class Signer {
|
|
|
4170
4170
|
wasm.__wbg_signer_free(ptr, 0);
|
|
4171
4171
|
}
|
|
4172
4172
|
/**
|
|
4173
|
-
* Approve a `pubkyauth://` request URL
|
|
4173
|
+
* Approve all capabilities in a `pubkyauth://` auth request URL.
|
|
4174
4174
|
* @param {string} pubkyauth_url
|
|
4175
4175
|
* @returns {Promise<void>}
|
|
4176
4176
|
*/
|
|
@@ -4180,6 +4180,28 @@ class Signer {
|
|
|
4180
4180
|
const ret = wasm.signer_approveAuthRequest(this.__wbg_ptr, ptr0, len0);
|
|
4181
4181
|
return ret;
|
|
4182
4182
|
}
|
|
4183
|
+
/**
|
|
4184
|
+
* Approve selected capabilities in a `pubkyauth://` auth request URL.
|
|
4185
|
+
*
|
|
4186
|
+
* Scopes and actions must be covered by the request. An empty string
|
|
4187
|
+
* approves no capabilities. V1 grants deliver keys only for approved `e`
|
|
4188
|
+
* scopes. Supports grant and legacy signin/signup requests.
|
|
4189
|
+
* Invalid capabilities or approvals exceeding the request fail before POST.
|
|
4190
|
+
*
|
|
4191
|
+
* @example
|
|
4192
|
+
* await signer.approveAuthWithCapabilities(authUrl, "/pub/example.app/:r");
|
|
4193
|
+
* @param {string} pubkyauth_url
|
|
4194
|
+
* @param {string} approved_capabilities
|
|
4195
|
+
* @returns {Promise<void>}
|
|
4196
|
+
*/
|
|
4197
|
+
approveAuthWithCapabilities(pubkyauth_url, approved_capabilities) {
|
|
4198
|
+
const ptr0 = passStringToWasm0(pubkyauth_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
4199
|
+
const len0 = WASM_VECTOR_LEN;
|
|
4200
|
+
const ptr1 = passStringToWasm0(approved_capabilities, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
4201
|
+
const len1 = WASM_VECTOR_LEN;
|
|
4202
|
+
const ret = wasm.signer_approveAuthWithCapabilities(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
4203
|
+
return ret;
|
|
4204
|
+
}
|
|
4183
4205
|
/**
|
|
4184
4206
|
* Create a signer from a `Keypair` (prefer `pubky.signer(kp)`).
|
|
4185
4207
|
*
|
|
@@ -5383,7 +5405,7 @@ function __wbg_get_imports() {
|
|
|
5383
5405
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
5384
5406
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
5385
5407
|
},
|
|
5386
|
-
|
|
5408
|
+
__wbg___pubkyGrantDelegatedSign_78f7f9da0ae4d1e7: function(arg0, arg1, arg2, arg3) {
|
|
5387
5409
|
let deferred0_0;
|
|
5388
5410
|
let deferred0_1;
|
|
5389
5411
|
let deferred1_0;
|
|
@@ -5400,7 +5422,7 @@ function __wbg_get_imports() {
|
|
|
5400
5422
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
5401
5423
|
}
|
|
5402
5424
|
},
|
|
5403
|
-
|
|
5425
|
+
__wbg___pubkyGrantEnsureDelegatedKey_8db39436266230bf: function(arg0, arg1) {
|
|
5404
5426
|
let v0;
|
|
5405
5427
|
if (arg0 !== 0) {
|
|
5406
5428
|
v0 = getStringFromWasm0(arg0, arg1);
|
|
@@ -5409,7 +5431,7 @@ function __wbg_get_imports() {
|
|
|
5409
5431
|
const ret = __pubkyGrantEnsureDelegatedKey(v0);
|
|
5410
5432
|
return ret;
|
|
5411
5433
|
},
|
|
5412
|
-
|
|
5434
|
+
__wbg___pubkyGrantLoadDelegatedPublicKey_e68eaea44047aa67: function(arg0, arg1) {
|
|
5413
5435
|
let deferred0_0;
|
|
5414
5436
|
let deferred0_1;
|
|
5415
5437
|
try {
|
|
@@ -5421,18 +5443,18 @@ function __wbg_get_imports() {
|
|
|
5421
5443
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
5422
5444
|
}
|
|
5423
5445
|
},
|
|
5424
|
-
|
|
5446
|
+
__wbg___pubkyRecoveredEncryptionKeys_b1fcbbfa114eb3ca: function(arg0, arg1, arg2, arg3, arg4) {
|
|
5425
5447
|
const ret = __pubkyRecoveredEncryptionKeys(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), EncryptionKeys.__wrap(arg4));
|
|
5426
5448
|
return ret;
|
|
5427
5449
|
},
|
|
5428
|
-
|
|
5450
|
+
__wbg___pubkySessionAcquire_de9717d53c8b9829: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
|
|
5429
5451
|
const ret = __pubkySessionAcquire(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), arg4 !== 0);
|
|
5430
5452
|
return ret;
|
|
5431
5453
|
}, arguments); },
|
|
5432
|
-
|
|
5454
|
+
__wbg___pubkySessionRelease_0cc80a30918c48e4: function(arg0) {
|
|
5433
5455
|
__pubkySessionRelease(arg0 >>> 0);
|
|
5434
5456
|
},
|
|
5435
|
-
|
|
5457
|
+
__wbg___pubkySessionStoreGet_4212c4496bdd7e95: function(arg0, arg1) {
|
|
5436
5458
|
let deferred0_0;
|
|
5437
5459
|
let deferred0_1;
|
|
5438
5460
|
try {
|
|
@@ -5444,7 +5466,7 @@ function __wbg_get_imports() {
|
|
|
5444
5466
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
5445
5467
|
}
|
|
5446
5468
|
},
|
|
5447
|
-
|
|
5469
|
+
__wbg___pubkySessionStoreMetadata_1ca42b0124ac7bda: function(arg0, arg1) {
|
|
5448
5470
|
let deferred0_0;
|
|
5449
5471
|
let deferred0_1;
|
|
5450
5472
|
try {
|
|
@@ -5456,23 +5478,23 @@ function __wbg_get_imports() {
|
|
|
5456
5478
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
5457
5479
|
}
|
|
5458
5480
|
},
|
|
5459
|
-
|
|
5481
|
+
__wbg___pubkySessionStorePut_950dc07537c9b99b: function(arg0, arg1) {
|
|
5460
5482
|
const ret = __pubkySessionStorePut(arg0, arg1 >>> 0);
|
|
5461
5483
|
return ret;
|
|
5462
5484
|
},
|
|
5463
|
-
|
|
5485
|
+
__wbg___pubkySessionWait_0b154edd2f3697be: function(arg0) {
|
|
5464
5486
|
const ret = __pubkySessionWait(arg0 >>> 0);
|
|
5465
5487
|
return ret;
|
|
5466
5488
|
},
|
|
5467
|
-
|
|
5489
|
+
__wbg___pubkySharedSessionLoad_e99bffd1e2cbc147: function(arg0) {
|
|
5468
5490
|
const ret = __pubkySharedSessionLoad(arg0 >>> 0);
|
|
5469
5491
|
return ret;
|
|
5470
5492
|
},
|
|
5471
|
-
|
|
5493
|
+
__wbg___pubkySharedSessionRemove_ba5487e63035a9a9: function(arg0) {
|
|
5472
5494
|
const ret = __pubkySharedSessionRemove(arg0 >>> 0);
|
|
5473
5495
|
return ret;
|
|
5474
5496
|
},
|
|
5475
|
-
|
|
5497
|
+
__wbg___pubkySharedSessionStore_507e41f8a033dcc1: function(arg0, arg1) {
|
|
5476
5498
|
const ret = __pubkySharedSessionStore(arg0 >>> 0, arg1);
|
|
5477
5499
|
return ret;
|
|
5478
5500
|
},
|
|
@@ -5647,11 +5669,11 @@ function __wbg_get_imports() {
|
|
|
5647
5669
|
const ret = Event.__wrap(arg0);
|
|
5648
5670
|
return ret;
|
|
5649
5671
|
},
|
|
5650
|
-
|
|
5672
|
+
__wbg_fetch_66895227032f0bdf: function(arg0) {
|
|
5651
5673
|
const ret = fetch(arg0);
|
|
5652
5674
|
return ret;
|
|
5653
5675
|
},
|
|
5654
|
-
|
|
5676
|
+
__wbg_fetch_7a37768ab67c5bd8: function(arg0) {
|
|
5655
5677
|
const ret = fetch(arg0);
|
|
5656
5678
|
return ret;
|
|
5657
5679
|
},
|
|
@@ -6116,12 +6138,12 @@ function __wbg_get_imports() {
|
|
|
6116
6138
|
return ret;
|
|
6117
6139
|
},
|
|
6118
6140
|
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
6119
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
6141
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 281, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
6120
6142
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_6fb33c0245079662___convert__closures_____invoke___wasm_bindgen_6fb33c0245079662___JsValue______true_);
|
|
6121
6143
|
return ret;
|
|
6122
6144
|
},
|
|
6123
6145
|
__wbindgen_generic_0000000000000003: function(arg0, arg1) {
|
|
6124
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx:
|
|
6146
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 279, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
6125
6147
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_6fb33c0245079662___convert__closures_____invoke_______true_);
|
|
6126
6148
|
return ret;
|
|
6127
6149
|
},
|
|
@@ -6160,14 +6182,14 @@ function __wbg_get_imports() {
|
|
|
6160
6182
|
__wbindgen_generic_000000000000000a: function(arg0, arg1) {
|
|
6161
6183
|
var v0 = getArrayJsValueFromWasm0(arg0, arg1);
|
|
6162
6184
|
wasm.__wbindgen_free(arg0, arg1 * 4, 4);
|
|
6163
|
-
// Cast intrinsic for `Vector(RustStruct { name: "GrantInfo", unique_crate_identifier: "pubky-wasm-
|
|
6185
|
+
// Cast intrinsic for `Vector(RustStruct { name: "GrantInfo", unique_crate_identifier: "pubky-wasm-6e41d7b4dc13a4fc" }) -> Externref`.
|
|
6164
6186
|
const ret = v0;
|
|
6165
6187
|
return ret;
|
|
6166
6188
|
},
|
|
6167
6189
|
__wbindgen_generic_000000000000000b: function(arg0, arg1) {
|
|
6168
6190
|
var v0 = getArrayJsValueFromWasm0(arg0, arg1);
|
|
6169
6191
|
wasm.__wbindgen_free(arg0, arg1 * 4, 4);
|
|
6170
|
-
// Cast intrinsic for `Vector(RustStruct { name: "StoredSessionInfo", unique_crate_identifier: "pubky-wasm-
|
|
6192
|
+
// Cast intrinsic for `Vector(RustStruct { name: "StoredSessionInfo", unique_crate_identifier: "pubky-wasm-6e41d7b4dc13a4fc" }) -> Externref`.
|
|
6171
6193
|
const ret = v0;
|
|
6172
6194
|
return ret;
|
|
6173
6195
|
},
|
|
@@ -6184,13 +6206,13 @@ function __wbg_get_imports() {
|
|
|
6184
6206
|
return {
|
|
6185
6207
|
__proto__: null,
|
|
6186
6208
|
"./pubky_bg.js": import0,
|
|
6187
|
-
"./snippets/pubky-wasm-
|
|
6188
|
-
"./snippets/pubky-wasm-
|
|
6189
|
-
"./snippets/pubky-wasm-
|
|
6190
|
-
"./snippets/pubky-wasm-
|
|
6191
|
-
"./snippets/pubky-wasm-
|
|
6192
|
-
"./snippets/pubky-wasm-
|
|
6193
|
-
"./snippets/pubky-wasm-
|
|
6209
|
+
"./snippets/pubky-wasm-6e41d7b4dc13a4fc/inline1.js": import1,
|
|
6210
|
+
"./snippets/pubky-wasm-6e41d7b4dc13a4fc/inline1.js": import2,
|
|
6211
|
+
"./snippets/pubky-wasm-6e41d7b4dc13a4fc/inline1.js": import3,
|
|
6212
|
+
"./snippets/pubky-wasm-6e41d7b4dc13a4fc/inline1.js": import4,
|
|
6213
|
+
"./snippets/pubky-wasm-6e41d7b4dc13a4fc/inline2.js": import5,
|
|
6214
|
+
"./snippets/pubky-wasm-6e41d7b4dc13a4fc/inline0.js": import6,
|
|
6215
|
+
"./snippets/pubky-wasm-6e41d7b4dc13a4fc/inline2.js": import7,
|
|
6194
6216
|
};
|
|
6195
6217
|
}
|
|
6196
6218
|
|