@ghostlytools/cli 1.11.4 → 1.12.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 +28 -11
- package/dist/assets/{api-MYc6QNRs.js → api-DLzCtePC.js} +363 -125
- package/dist/assets/api-DLzCtePC.js.map +1 -0
- package/dist/assets/{api-BwyFq4lA.js → api-DYMKyb1k.js} +2 -2
- package/dist/assets/{apiKit-CfsNx9ZR.js → apiKit-CVaEzKWQ.js} +48 -11
- package/dist/assets/apiKit-CVaEzKWQ.js.map +1 -0
- package/dist/assets/appFetch-D56GsYuq.js +602 -0
- package/dist/assets/appFetch-D56GsYuq.js.map +1 -0
- package/dist/assets/apps-BPFW19Wc.js +1 -0
- package/dist/assets/{apps-h12II1us.js → apps-XnZ8VEuj.js} +20 -14
- package/dist/assets/apps-XnZ8VEuj.js.map +1 -0
- package/dist/assets/{argon2id-088uQfnH.js → argon2id-B9wFdSj6.js} +2 -3
- package/dist/assets/{argon2id-088uQfnH.js.map → argon2id-B9wFdSj6.js.map} +1 -1
- package/dist/assets/{arkade-Bw_4PZRG.js → arkade-DryM-q5n.js} +6 -7
- package/dist/assets/arkade-DryM-q5n.js.map +1 -0
- package/dist/assets/backup-COX6j1_W.js +1 -0
- package/dist/assets/{backup-Chvy79SN.js → backup-DpyvT9Z6.js} +66 -21
- package/dist/assets/backup-DpyvT9Z6.js.map +1 -0
- package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js +5 -0
- package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js.map +1 -0
- package/dist/assets/{bark_ffi_wasm_bg-Bxru_BVW.wasm → bark_ffi_wasm_bg-VNmaJsc9.wasm} +0 -0
- package/dist/assets/{bitcoind-CdSmvy2y.js → bitcoind-DTsrd7TF.js} +4 -5
- package/dist/assets/{bitcoind-CdSmvy2y.js.map → bitcoind-DTsrd7TF.js.map} +1 -1
- package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js +5 -0
- package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js.map +1 -0
- package/dist/assets/bitcoindevkit_bg-DXil67yS.wasm +0 -0
- package/dist/assets/{blobFiles-BmsrvZc3.js → blobFiles-DDs34n0r.js} +4 -5
- package/dist/assets/{blobFiles-BmsrvZc3.js.map → blobFiles-DDs34n0r.js.map} +1 -1
- package/dist/assets/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/dist/assets/buttons-Bq7pTXqF.js +1 -0
- package/dist/assets/{buttons-BgoExb4E.js → buttons-BvWqHJeh.js} +45 -23
- package/dist/assets/buttons-BvWqHJeh.js.map +1 -0
- package/dist/assets/bytes-C1DNGY18.js +132 -0
- package/dist/assets/bytes-C1DNGY18.js.map +1 -0
- package/dist/assets/{childEnv-K_IzUqQx.js → childEnv-C-99hdbL.js} +2 -3
- package/dist/assets/{childEnv-K_IzUqQx.js.map → childEnv-C-99hdbL.js.map} +1 -1
- package/dist/assets/{client-DY8tZZWi.js → client-kGZ3ZdUW.js} +5 -8
- package/dist/assets/{client-DY8tZZWi.js.map → client-kGZ3ZdUW.js.map} +1 -1
- package/dist/assets/{codec-BnMg-Grj.js → codec-B2rH1mfx.js} +2 -4
- package/dist/assets/{codec-BnMg-Grj.js.map → codec-B2rH1mfx.js.map} +1 -1
- package/dist/assets/domainProofs-BDNP1dIy.js +280 -0
- package/dist/assets/domainProofs-BDNP1dIy.js.map +1 -0
- package/dist/assets/{endpoint-DarqblYE.js → endpoint-B0vE5ojY.js} +421 -420
- package/dist/assets/endpoint-B0vE5ojY.js.map +1 -0
- package/dist/assets/engineErrors--9hfgKlK.js +150 -0
- package/dist/assets/engineErrors--9hfgKlK.js.map +1 -0
- package/dist/assets/{envelope-CdV7vHVZ.js → envelope-Bi2kMqbp.js} +3 -4
- package/dist/assets/{envelope-CdV7vHVZ.js.map → envelope-Bi2kMqbp.js.map} +1 -1
- package/dist/assets/{errors-CAh6GLJZ.js → errors-DDLFO4Gf.js} +5 -4
- package/dist/assets/errors-DDLFO4Gf.js.map +1 -0
- package/dist/assets/{fedimintSdk-CPFfVK-G.js → fedimintSdk-D-6H9Pe7.js} +4 -5
- package/dist/assets/{fedimintSdk-CPFfVK-G.js.map → fedimintSdk-D-6H9Pe7.js.map} +1 -1
- package/dist/assets/fedimint_client_wasm_bg-Cr5xGD-w.js +5 -0
- package/dist/assets/{fedimint_client_wasm_bg-BtHHlFpp.js.map → fedimint_client_wasm_bg-Cr5xGD-w.js.map} +1 -1
- package/dist/assets/fileBytes-CCKbwqG_.js +1 -0
- package/dist/assets/{fileBytes-BLPZq9YU.js → fileBytes-CfvUXdSy.js} +5 -7
- package/dist/assets/fileBytes-CfvUXdSy.js.map +1 -0
- package/dist/assets/{fileBytes-B0z9A6Le.js → fileBytes-tj6-VZcB.js} +3 -4
- package/dist/assets/{fileBytes-B0z9A6Le.js.map → fileBytes-tj6-VZcB.js.map} +1 -1
- package/dist/assets/fileBytesIdb-B0zzJ6p7.js +1 -0
- package/dist/assets/{fileBytesIdb-Bmlrl9EO.js → fileBytesIdb-BJirUAjI.js} +4 -5
- package/dist/assets/{fileBytesIdb-Bmlrl9EO.js.map → fileBytesIdb-BJirUAjI.js.map} +1 -1
- package/dist/assets/{fileBytesOpfs-DBS0kbPT.js → fileBytesOpfs-DRUYLER4.js} +4 -5
- package/dist/assets/{fileBytesOpfs-DBS0kbPT.js.map → fileBytesOpfs-DRUYLER4.js.map} +1 -1
- package/dist/assets/{fixedHosts-CbgqrIKs.js → fixedHosts-CPSsGOI2.js} +4 -5
- package/dist/assets/{fixedHosts-CbgqrIKs.js.map → fixedHosts-CPSsGOI2.js.map} +1 -1
- package/dist/assets/{ghostly_iroh_web-BzAXJUYH.js → ghostly_iroh_web-DIj5xGmR.js} +2 -3
- package/dist/assets/{ghostly_iroh_web-BzAXJUYH.js.map → ghostly_iroh_web-DIj5xGmR.js.map} +1 -1
- package/dist/assets/{src-DJe-OYxd.js → groupMeta-DTQAJG50.js} +4693 -24241
- package/dist/assets/groupMeta-DTQAJG50.js.map +1 -0
- package/dist/assets/{host-C0NMNQLl.js → host-z0FAHP9Z.js} +209 -134
- package/dist/assets/host-z0FAHP9Z.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-Dz7pvcBA.js → hyperdhtRelay-CvsAfQRQ.js} +5 -6
- package/dist/assets/hyperdhtRelay-CvsAfQRQ.js.map +1 -0
- package/dist/assets/hyperdhtRelay-bjNGacf5.js +32 -0
- package/dist/assets/hyperdhtRelay-bjNGacf5.js.map +1 -0
- package/dist/assets/{idb-CEuoNsTv.js → idb-ewvbqyDI.js} +2 -3
- package/dist/assets/{idb-CEuoNsTv.js.map → idb-ewvbqyDI.js.map} +1 -1
- package/dist/assets/identityProofs-Cksc_K7_.js +940 -0
- package/dist/assets/identityProofs-Cksc_K7_.js.map +1 -0
- package/dist/assets/{irohWeb-caAj4Dms.js → irohWeb-CLBx5MIv.js} +3061 -86
- package/dist/assets/irohWeb-CLBx5MIv.js.map +1 -0
- package/dist/assets/joinTrace-CBr1jbch.js +1 -0
- package/dist/assets/{joinTrace-CjRDFy85.js → joinTrace-xKBe73j9.js} +2 -3
- package/dist/assets/{joinTrace-CjRDFy85.js.map → joinTrace-xKBe73j9.js.map} +1 -1
- package/dist/assets/{legacy_ciphers-JJOu0JXL.js → legacy_ciphers-BnYATjxo.js} +2 -3
- package/dist/assets/{legacy_ciphers-JJOu0JXL.js.map → legacy_ciphers-BnYATjxo.js.map} +1 -1
- package/dist/assets/linkPreview-DdMf-YAc.js +252 -0
- package/dist/assets/linkPreview-DdMf-YAc.js.map +1 -0
- package/dist/assets/{main-C6t5zrD5.js → main-CVqkvuIo.js} +268 -111
- package/dist/assets/main-CVqkvuIo.js.map +1 -0
- package/dist/assets/{mainline-DCuGUSZF.js → mainline-CVrd0C1n.js} +72 -18
- package/dist/assets/mainline-CVrd0C1n.js.map +1 -0
- package/dist/assets/mints-BcBODVVW.js +1 -0
- package/dist/assets/{mints-j5XAOk4f.js → mints-CMDLbMeH.js} +8 -6
- package/dist/assets/mints-CMDLbMeH.js.map +1 -0
- package/dist/assets/{nacl-fast-CDhNCYHs.js → nacl-fast-B1ThWvuM.js} +2 -3
- package/dist/assets/{nacl-fast-CDhNCYHs.js.map → nacl-fast-B1ThWvuM.js.map} +1 -1
- package/dist/assets/{networkReason-BbQW1Xpc.js → networkReason-Be-hMghr.js} +10 -14
- package/dist/assets/{networkReason-BbQW1Xpc.js.map → networkReason-Be-hMghr.js.map} +1 -1
- package/dist/assets/{noble_curves-DDWn5AH0.js → noble_curves-DqpNlhAU.js} +3 -4
- package/dist/assets/{noble_curves-DDWn5AH0.js.map → noble_curves-DqpNlhAU.js.map} +1 -1
- package/dist/assets/{noble_hashes-B7AZyFyS.js → noble_hashes-LFe1N2xt.js} +3 -4
- package/dist/assets/{noble_hashes-B7AZyFyS.js.map → noble_hashes-LFe1N2xt.js.map} +1 -1
- package/dist/assets/{nwc-CSDRMZ0e.js → nwc-DKE2FXr6.js} +5 -6
- package/dist/assets/{nwc-CSDRMZ0e.js.map → nwc-DKE2FXr6.js.map} +1 -1
- package/dist/assets/nwcProvider-pL2XqSbW.js +208 -0
- package/dist/assets/nwcProvider-pL2XqSbW.js.map +1 -0
- package/dist/assets/{openpgp-BBFr-zHQ.js → openpgp-LkR_Zof0.js} +14 -15
- package/dist/assets/{openpgp-BBFr-zHQ.js.map → openpgp-LkR_Zof0.js.map} +1 -1
- package/dist/assets/ownDid-DY3rYqDI.js +862 -0
- package/dist/assets/ownDid-DY3rYqDI.js.map +1 -0
- package/dist/assets/{ownStatus-BoTf5WqQ.js → ownStatus-DMEhrpkd.js} +69 -20
- package/dist/assets/ownStatus-DMEhrpkd.js.map +1 -0
- package/dist/assets/pairedTransports-BKmvlKz1.js +581 -0
- package/dist/assets/pairedTransports-BKmvlKz1.js.map +1 -0
- package/dist/assets/paymentIntent-DySU3Ajm.js +349 -0
- package/dist/assets/paymentIntent-DySU3Ajm.js.map +1 -0
- package/dist/assets/pkarr-BQo4PcCg.js +367 -0
- package/dist/assets/pkarr-BQo4PcCg.js.map +1 -0
- package/dist/assets/{profiles-DszHjEJi.js → profiles-BFSGqDFC.js} +9 -10
- package/dist/assets/profiles-BFSGqDFC.js.map +1 -0
- package/dist/assets/registry-B15Yg_1C.js +1 -0
- package/dist/assets/{registry-Da-r6eC3.js → registry-rXgaZeNn.js} +1261 -53
- package/dist/assets/registry-rXgaZeNn.js.map +1 -0
- package/dist/assets/relay-Cjfmdec0.js +2219 -0
- package/dist/assets/relay-Cjfmdec0.js.map +1 -0
- package/dist/assets/resolve-CIc3KZMV.js +970 -0
- package/dist/assets/resolve-CIc3KZMV.js.map +1 -0
- package/dist/assets/{restoredRows-C3LcxmOw.js → restoredRows-D_WSHE7H.js} +3 -4
- package/dist/assets/{restoredRows-C3LcxmOw.js.map → restoredRows-D_WSHE7H.js.map} +1 -1
- package/dist/assets/{secretGuard-CsVHDdYk.js → secretGuard-B4-LlMjv.js} +11 -14
- package/dist/assets/{secretGuard-CsVHDdYk.js.map → secretGuard-B4-LlMjv.js.map} +1 -1
- package/dist/assets/secretGuard-BmmnEbYf.js +1 -0
- package/dist/assets/{server-C1jZZ61O.js → server-CQR7NLCz.js} +9565 -461
- package/dist/assets/server-CQR7NLCz.js.map +1 -0
- package/dist/assets/{sha512-BYId-G-T.js → sha512-DST9fbWH.js} +2 -3
- package/dist/assets/{sha512-BYId-G-T.js.map → sha512-DST9fbWH.js.map} +1 -1
- package/dist/assets/sshForges-BnvwmNj-.js +539 -0
- package/dist/assets/sshForges-BnvwmNj-.js.map +1 -0
- package/dist/assets/{storage-Bya5b2Xt.js → storage-BpjdxvO2.js} +243 -34
- package/dist/assets/storage-BpjdxvO2.js.map +1 -0
- package/dist/assets/text-li76pThX.js +106 -0
- package/dist/assets/text-li76pThX.js.map +1 -0
- package/dist/assets/{translate-CUuC5szR.js → translate-BcbSWkuq.js} +21 -26
- package/dist/assets/{translate-CUuC5szR.js.map → translate-BcbSWkuq.js.map} +1 -1
- package/dist/assets/{tree-store-N362nuzZ.js → tree-store-CAchkO_l.js} +22 -6
- package/dist/assets/tree-store-CAchkO_l.js.map +1 -0
- package/dist/assets/{types-Clyb52K2.js → types-CdWwgvyt.js} +2 -3
- package/dist/assets/{types-Clyb52K2.js.map → types-CdWwgvyt.js.map} +1 -1
- package/dist/assets/{unbzip2-stream-B1C-JX9L.js → unbzip2-stream-BtkYGpC5.js} +2 -3
- package/dist/assets/{unbzip2-stream-B1C-JX9L.js.map → unbzip2-stream-BtkYGpC5.js.map} +1 -1
- package/dist/assets/{usdt-DI51znt-.js → usdt-CBJ4Q5Ji.js} +7 -7
- package/dist/assets/usdt-CBJ4Q5Ji.js.map +1 -0
- package/dist/assets/{waitNotice-Cn0WJ-He.js → waitNotice-BGM0QOS2.js} +27 -4
- package/dist/assets/waitNotice-BGM0QOS2.js.map +1 -0
- package/dist/assets/{web-DwgdhfcY.js → web-68CYFCl9.js} +314 -91
- package/dist/assets/web-68CYFCl9.js.map +1 -0
- package/dist/ghostly.mjs +3 -5
- package/dist/ghostly.mjs.map +1 -1
- package/npm-shrinkwrap.json +225 -200
- package/package.json +16 -16
- package/dist/assets/api-MYc6QNRs.js.map +0 -1
- package/dist/assets/apiKit-CfsNx9ZR.js.map +0 -1
- package/dist/assets/appFetch-DVYZOZFw.js +0 -194
- package/dist/assets/appFetch-DVYZOZFw.js.map +0 -1
- package/dist/assets/apps-Dbw2Hcko.js +0 -2
- package/dist/assets/apps-h12II1us.js.map +0 -1
- package/dist/assets/arkade-Bw_4PZRG.js.map +0 -1
- package/dist/assets/backup-CdEzTq5C.js +0 -2
- package/dist/assets/backup-Chvy79SN.js.map +0 -1
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js +0 -6
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +0 -1
- package/dist/assets/bitcoindProvider-BvoRh0D5.js +0 -97
- package/dist/assets/bitcoindProvider-BvoRh0D5.js.map +0 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js +0 -6
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +0 -1
- package/dist/assets/bitcoindevkit_bg-CRkZTSbO.wasm +0 -0
- package/dist/assets/buttons-BgoExb4E.js.map +0 -1
- package/dist/assets/buttons-DK2aAGat.js +0 -2
- package/dist/assets/endpoint-DarqblYE.js.map +0 -1
- package/dist/assets/errors-CAh6GLJZ.js.map +0 -1
- package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js +0 -6
- package/dist/assets/fileBytes-BLPZq9YU.js.map +0 -1
- package/dist/assets/fileBytes-BtIyoDF2.js +0 -2
- package/dist/assets/fileBytesIdb-D8mAK4pF.js +0 -2
- package/dist/assets/host-C0NMNQLl.js.map +0 -1
- package/dist/assets/hyperdhtRelay-1wzya_0L.js +0 -25
- package/dist/assets/hyperdhtRelay-1wzya_0L.js.map +0 -1
- package/dist/assets/hyperdhtRelay-Dz7pvcBA.js.map +0 -1
- package/dist/assets/irohWeb-caAj4Dms.js.map +0 -1
- package/dist/assets/joinTrace-D-fnt2p3.js +0 -2
- package/dist/assets/jsonOut-POtMBS_V.js +0 -16
- package/dist/assets/jsonOut-POtMBS_V.js.map +0 -1
- package/dist/assets/main-C6t5zrD5.js.map +0 -1
- package/dist/assets/mainline-DCuGUSZF.js.map +0 -1
- package/dist/assets/mints-BaOmx517.js +0 -2
- package/dist/assets/mints-j5XAOk4f.js.map +0 -1
- package/dist/assets/nwcProvider-PE0wli8n.js +0 -88
- package/dist/assets/nwcProvider-PE0wli8n.js.map +0 -1
- package/dist/assets/ownDid-C1R5Kd8q.js +0 -282
- package/dist/assets/ownDid-C1R5Kd8q.js.map +0 -1
- package/dist/assets/ownStatus-BoTf5WqQ.js.map +0 -1
- package/dist/assets/profiles-DszHjEJi.js.map +0 -1
- package/dist/assets/registry-Da-r6eC3.js.map +0 -1
- package/dist/assets/registry-zUZBSHYv.js +0 -2
- package/dist/assets/resolve-tUzh4lHh.js +0 -400
- package/dist/assets/resolve-tUzh4lHh.js.map +0 -1
- package/dist/assets/secretGuard-DCb1I0_B.js +0 -2
- package/dist/assets/server-C1jZZ61O.js.map +0 -1
- package/dist/assets/src-DJe-OYxd.js.map +0 -1
- package/dist/assets/sshForges-C9zTO72R.js +0 -261
- package/dist/assets/sshForges-C9zTO72R.js.map +0 -1
- package/dist/assets/storage-Bya5b2Xt.js.map +0 -1
- package/dist/assets/tree-store-N362nuzZ.js.map +0 -1
- package/dist/assets/usdt-DI51znt-.js.map +0 -1
- package/dist/assets/waitNotice-Cn0WJ-He.js.map +0 -1
- package/dist/assets/web-DwgdhfcY.js.map +0 -1
|
@@ -0,0 +1,862 @@
|
|
|
1
|
+
import { a as fromZ32, f as utf8Encode, i as fromBase64Url, l as toBase64Url, s as randomBytes, t as bytesEqual, u as toZ32 } from "./bytes-C1DNGY18.js";
|
|
2
|
+
import { c as openRelayPayload, d as signRelayPayload, m as encodeTxtPacket, p as decodeTxtPacket, r as PacketTooLargeError, t as MAX_DNS_PACKET_BYTES } from "./pkarr-BQo4PcCg.js";
|
|
3
|
+
import { c as normalizeRelayUrl, t as DEFAULT_RELAYS } from "./relay-Cjfmdec0.js";
|
|
4
|
+
import { s as IdentityCheckUnavailable, u as boundVerifiedIdentity } from "./identityProofs-Cksc_K7_.js";
|
|
5
|
+
import { l as providerDescriptorProblems } from "./types-CdWwgvyt.js";
|
|
6
|
+
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
7
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
8
|
+
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
9
|
+
import { p256 } from "@noble/curves/nist.js";
|
|
10
|
+
// ../core/src/pubkyProofs.ts
|
|
11
|
+
/**
|
|
12
|
+
* A Pubky identity proof, by publication (WISP 302, docs/wisps/302-pubky.md). Neither Pubky Ring nor Pubky
|
|
13
|
+
* Passport signs arbitrary text: they approve standard Pubky auth requests. So Ghostly asks, through one of them,
|
|
14
|
+
* for write access to ONE fresh folder of the key's homeserver, `/pub/ghostly.app/proofs/<folder>/`, and writes the
|
|
15
|
+
* identity statement there (the #80 statement: the Pubky key authorizes this profile's per-proof key). A contact's
|
|
16
|
+
* app reads the file back, finding the homeserver through the key's own signed PKDNS records (pkdns.ts), never
|
|
17
|
+
* through a host or URL from the proof. The folder is random, so the path says nothing about the profile.
|
|
18
|
+
*/
|
|
19
|
+
var PUBKY_PROOF_ROOT = "/pub/ghostly.app/proofs/";
|
|
20
|
+
/** The file is the statement, a few hundred bytes: anything larger is not ours. */
|
|
21
|
+
var PUBKY_PROOF_MAX_BYTES = 1024;
|
|
22
|
+
var Z32 = /^[ybndrfg8ejkmcpqxot1uwisza345h769]{52}$/;
|
|
23
|
+
var FOLDER = /^[a-f0-9]{64}$/;
|
|
24
|
+
var STATEMENT_ID = /^[a-f0-9]{64}$/;
|
|
25
|
+
/** A canonical Pubky key: 52 characters of z-base-32 that decode to 32 bytes and back. */
|
|
26
|
+
function isPubkyKey(value) {
|
|
27
|
+
if (typeof value !== "string" || !Z32.test(value)) return false;
|
|
28
|
+
try {
|
|
29
|
+
return toZ32(fromZ32(value)) === value;
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** The z-base-32 key for what a person typed or pasted: the bare key, `pubky<key>`, `pk:<key>` or `pubky://<key>`. */
|
|
35
|
+
function normalizePubkyKey(input) {
|
|
36
|
+
const key = /^(?:pubky:\/\/|pubky|pk:)?([a-z0-9]{52})\/?$/i.exec(typeof input === "string" ? input.trim() : "")?.[1].toLowerCase();
|
|
37
|
+
if (!key || !isPubkyKey(key)) throw new Error("That is not a Pubky key: 52 characters, like the one Pubky Ring shows");
|
|
38
|
+
return key;
|
|
39
|
+
}
|
|
40
|
+
var isPubkyProofFolder = (value) => typeof value === "string" && FOLDER.test(value);
|
|
41
|
+
/** A fresh folder name: 32 random bytes, hex. One per proof, so two proofs never share a path. */
|
|
42
|
+
var newPubkyProofFolder = () => Array.from(randomBytes(32), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
43
|
+
/** The only capability Ghostly ever asks for: write access to one proof folder. */
|
|
44
|
+
function pubkyProofCapability(folder) {
|
|
45
|
+
if (!isPubkyProofFolder(folder)) throw new Error("Invalid Pubky proof folder");
|
|
46
|
+
return `${PUBKY_PROOF_ROOT}${folder}/:w`;
|
|
47
|
+
}
|
|
48
|
+
/** Where the statement goes: in its folder, named by the statement id. */
|
|
49
|
+
function pubkyProofPath(folder, statementId) {
|
|
50
|
+
if (!isPubkyProofFolder(folder) || !STATEMENT_ID.test(statementId)) throw new Error("Invalid Pubky proof path");
|
|
51
|
+
return `${PUBKY_PROOF_ROOT}${folder}/${statementId}.txt`;
|
|
52
|
+
}
|
|
53
|
+
/** The file's exact contents: the statement's one line, nothing added. The verifier compares bytes. */
|
|
54
|
+
var pubkyProofFile = (statement) => statement.text;
|
|
55
|
+
// ../core/src/didDht.ts
|
|
56
|
+
/**
|
|
57
|
+
* did:dht (the DIF method, https://github.com/decentralized-identity/did-dht/blob/main/spec/spec.md): a W3C DID document written as DNS records into the
|
|
58
|
+
* Pkarr packet of an Ed25519 key, the BEP44 mutable item Ghostly already publishes chats under. This
|
|
59
|
+
* module maps a document to that packet and back (strictly: a malformed packet is an error, never a
|
|
60
|
+
* guess) and resolves a did:dht through Pkarr relays. WISP 310-did-dht describes Ghostly's use.
|
|
61
|
+
*/
|
|
62
|
+
var DID_DHT_PREFIX = "did:dht:";
|
|
63
|
+
/** The TTL the spec recommends: Mainline's default record lifetime. */
|
|
64
|
+
var DID_DHT_TTL = 7200;
|
|
65
|
+
/** A relay answer: 64 bytes of signature, 8 of sequence number, then at most 1000 of DNS packet. */
|
|
66
|
+
var DID_DHT_MAX_PAYLOAD = 72 + MAX_DNS_PACKET_BYTES;
|
|
67
|
+
/** Why a did:dht could not be read: the message is meant for a person. */
|
|
68
|
+
var DidDhtError = class extends Error {
|
|
69
|
+
code;
|
|
70
|
+
constructor(message, code) {
|
|
71
|
+
super(message);
|
|
72
|
+
this.code = code;
|
|
73
|
+
this.name = "DidDhtError";
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var malformed = (detail) => new DidDhtError(`The did:dht document is malformed: ${detail}`, "malformed");
|
|
77
|
+
/** `did:dht:<z-base-32 of the Ed25519 public key>`. */
|
|
78
|
+
function didDhtFromPublicKey(publicKey) {
|
|
79
|
+
if (publicKey.length !== 32) throw new Error("A did:dht identity key is 32 bytes of Ed25519 public key");
|
|
80
|
+
return DID_DHT_PREFIX + toZ32(publicKey);
|
|
81
|
+
}
|
|
82
|
+
/** The identity key of a did:dht. Only the exact DID: no path, query or fragment, canonical z-base-32. */
|
|
83
|
+
function didDhtKey(did) {
|
|
84
|
+
const invalid = () => new DidDhtError("This is not a valid did:dht", "invalid-did");
|
|
85
|
+
if (typeof did !== "string" || !did.startsWith("did:dht:")) throw invalid();
|
|
86
|
+
const z32 = did.slice(8);
|
|
87
|
+
if (!/^[ybndrfg8ejkmcpqxot1uwisza345h769]{52}$/.test(z32)) throw invalid();
|
|
88
|
+
const publicKey = fromZ32(z32);
|
|
89
|
+
if (toZ32(publicKey) !== z32) throw invalid();
|
|
90
|
+
let fit;
|
|
91
|
+
try {
|
|
92
|
+
fit = !ed25519.Point.fromBytes(publicKey).isSmallOrder();
|
|
93
|
+
} catch {
|
|
94
|
+
fit = false;
|
|
95
|
+
}
|
|
96
|
+
if (!fit) throw invalid();
|
|
97
|
+
return {
|
|
98
|
+
z32,
|
|
99
|
+
publicKey
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
var KEY_TYPES = [
|
|
103
|
+
{
|
|
104
|
+
kty: "OKP",
|
|
105
|
+
crv: "Ed25519",
|
|
106
|
+
alg: "EdDSA"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
kty: "EC",
|
|
110
|
+
crv: "secp256k1",
|
|
111
|
+
alg: "ES256K"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
kty: "EC",
|
|
115
|
+
crv: "P-256",
|
|
116
|
+
alg: "ES256"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
kty: "OKP",
|
|
120
|
+
crv: "X25519",
|
|
121
|
+
alg: "ECDH-ES+A256KW"
|
|
122
|
+
}
|
|
123
|
+
];
|
|
124
|
+
var RELATIONSHIPS = [
|
|
125
|
+
["auth", "authentication"],
|
|
126
|
+
["asm", "assertionMethod"],
|
|
127
|
+
["agm", "keyAgreement"],
|
|
128
|
+
["inv", "capabilityInvocation"],
|
|
129
|
+
["del", "capabilityDelegation"]
|
|
130
|
+
];
|
|
131
|
+
/**
|
|
132
|
+
* The document of an identity key alone, as the spec's Create step makes it: the key as `#0`, with the
|
|
133
|
+
* four relationships it requires (authentication, assertion, capability invocation and delegation).
|
|
134
|
+
* `alsoKnownAs` adds other identifiers of the same subject (URIs), which the document makes public.
|
|
135
|
+
*/
|
|
136
|
+
function didDhtDocument(publicKey, options = {}) {
|
|
137
|
+
const id = didDhtFromPublicKey(publicKey);
|
|
138
|
+
const key = `${id}#0`;
|
|
139
|
+
return {
|
|
140
|
+
id,
|
|
141
|
+
...options.alsoKnownAs?.length ? { alsoKnownAs: [...options.alsoKnownAs] } : {},
|
|
142
|
+
verificationMethod: [{
|
|
143
|
+
id: key,
|
|
144
|
+
type: "JsonWebKey",
|
|
145
|
+
controller: id,
|
|
146
|
+
publicKeyJwk: {
|
|
147
|
+
kty: "OKP",
|
|
148
|
+
crv: "Ed25519",
|
|
149
|
+
x: toBase64Url(publicKey),
|
|
150
|
+
alg: "EdDSA",
|
|
151
|
+
kid: "0"
|
|
152
|
+
}
|
|
153
|
+
}],
|
|
154
|
+
authentication: [key],
|
|
155
|
+
assertionMethod: [key],
|
|
156
|
+
capabilityInvocation: [key],
|
|
157
|
+
capabilityDelegation: [key]
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/** RFC 7638 thumbprint: SHA-256 of the required members in lexicographic order. */
|
|
161
|
+
function jwkThumbprint(jwk) {
|
|
162
|
+
const members = jwk.kty === "EC" ? {
|
|
163
|
+
crv: jwk.crv,
|
|
164
|
+
kty: jwk.kty,
|
|
165
|
+
x: jwk.x,
|
|
166
|
+
y: jwk.y
|
|
167
|
+
} : {
|
|
168
|
+
crv: jwk.crv,
|
|
169
|
+
kty: jwk.kty,
|
|
170
|
+
x: jwk.x
|
|
171
|
+
};
|
|
172
|
+
return toBase64Url(sha256(utf8Encode(JSON.stringify(members))));
|
|
173
|
+
}
|
|
174
|
+
function publicKeyBytes(type, jwk) {
|
|
175
|
+
const x = fromBase64Url(jwk.x);
|
|
176
|
+
if (type === 0 || type === 3) return x;
|
|
177
|
+
return (type === 1 ? secp256k1 : p256).Point.fromAffine({
|
|
178
|
+
x: bigintOf(x),
|
|
179
|
+
y: bigintOf(fromBase64Url(jwk.y ?? ""))
|
|
180
|
+
}).toBytes(true);
|
|
181
|
+
}
|
|
182
|
+
function bigintOf(bytes) {
|
|
183
|
+
let n = 0n;
|
|
184
|
+
for (const b of bytes) n = n << 8n | BigInt(b);
|
|
185
|
+
return n;
|
|
186
|
+
}
|
|
187
|
+
function jwkOf(type, bytes, alg, kid) {
|
|
188
|
+
const kind = KEY_TYPES[type];
|
|
189
|
+
if (type === 0) {
|
|
190
|
+
if (bytes.length !== 32) throw malformed("an Ed25519 key is not 32 bytes");
|
|
191
|
+
let smallOrder;
|
|
192
|
+
try {
|
|
193
|
+
smallOrder = ed25519.Point.fromBytes(bytes).isSmallOrder();
|
|
194
|
+
} catch {
|
|
195
|
+
throw malformed("an Ed25519 key is not a point of the curve");
|
|
196
|
+
}
|
|
197
|
+
if (smallOrder) throw malformed("an Ed25519 key is a point of small order, which no secret key goes with");
|
|
198
|
+
return {
|
|
199
|
+
kty: "OKP",
|
|
200
|
+
crv: "Ed25519",
|
|
201
|
+
x: toBase64Url(bytes),
|
|
202
|
+
alg,
|
|
203
|
+
kid
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (type === 3) {
|
|
207
|
+
if (bytes.length !== 32) throw malformed("an X25519 key is not 32 bytes");
|
|
208
|
+
return {
|
|
209
|
+
kty: "OKP",
|
|
210
|
+
crv: "X25519",
|
|
211
|
+
x: toBase64Url(bytes),
|
|
212
|
+
alg,
|
|
213
|
+
kid
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
if (bytes.length !== 33 && bytes.length !== 65) throw malformed(`a ${kind.crv} key is neither a compressed nor an uncompressed point`);
|
|
217
|
+
let raw;
|
|
218
|
+
try {
|
|
219
|
+
raw = (type === 1 ? secp256k1 : p256).Point.fromBytes(bytes).toBytes(false);
|
|
220
|
+
} catch {
|
|
221
|
+
throw malformed(`a ${kind.crv} key is not a point of the curve`);
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
kty: "EC",
|
|
225
|
+
crv: kind.crv,
|
|
226
|
+
x: toBase64Url(raw.subarray(1, 33)),
|
|
227
|
+
y: toBase64Url(raw.subarray(33)),
|
|
228
|
+
alg,
|
|
229
|
+
kid
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
var fragmentOf = (documentId, ref, what) => {
|
|
233
|
+
if (!ref.startsWith(`${documentId}#`)) throw new Error(`${what} ${ref} is not a fragment of ${documentId}`);
|
|
234
|
+
const fragment = ref.slice(documentId.length + 1);
|
|
235
|
+
if (!FRAGMENT.test(fragment)) throw new Error(`${what} ${ref} has an unusable fragment`);
|
|
236
|
+
return fragment;
|
|
237
|
+
};
|
|
238
|
+
var listValue = (values, what) => {
|
|
239
|
+
for (const v of values) if (!v || /[,;\s]/.test(v)) throw new Error(`${what} ${JSON.stringify(v)} cannot be written into a did:dht record`);
|
|
240
|
+
return values.join(",");
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* The DNS records of a document, in the spec's layout (names `_did.<ID>.` and `_kN._did.`). The root
|
|
244
|
+
* record comes after the records it names, gateways last: the order @web5/dids writes, and the only one
|
|
245
|
+
* it reads correctly (it resolves `vm`/`auth` references in packet order). Order-free readers don't mind.
|
|
246
|
+
*/
|
|
247
|
+
function didDhtRecords(document, options = {}) {
|
|
248
|
+
const { z32, publicKey } = didDhtKey(document.id);
|
|
249
|
+
const methods = document.verificationMethod;
|
|
250
|
+
const first = methods[0];
|
|
251
|
+
if (!first || first.id !== `${document.id}#0` || first.publicKeyJwk.crv !== "Ed25519" || !bytesEqual(fromBase64Url(first.publicKeyJwk.x), publicKey)) throw new Error("The first verification method of a did:dht document is its identity key, #0");
|
|
252
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
253
|
+
const keyRecords = methods.map((method, index) => {
|
|
254
|
+
const alias = `k${index}`;
|
|
255
|
+
if (aliases.has(method.id)) throw new Error(`Verification method ${method.id} appears twice`);
|
|
256
|
+
aliases.set(method.id, alias);
|
|
257
|
+
const fragment = fragmentOf(document.id, method.id, "Verification method");
|
|
258
|
+
const type = KEY_TYPES.findIndex((k) => k.crv === method.publicKeyJwk.crv);
|
|
259
|
+
if (type < 0) throw new Error(`Key type ${method.publicKeyJwk.crv} has no did:dht index`);
|
|
260
|
+
const jwk = method.publicKeyJwk;
|
|
261
|
+
const parts = [];
|
|
262
|
+
if (index > 0 && fragment !== jwkThumbprint(jwk)) parts.push(`id=${fragment}`);
|
|
263
|
+
parts.push(`t=${type}`, `k=${toBase64Url(publicKeyBytes(type, jwk))}`);
|
|
264
|
+
if (jwk.alg !== KEY_TYPES[type].alg) parts.push(`a=${jwk.alg}`);
|
|
265
|
+
if (method.controller !== document.id) parts.push(`c=${listValue([method.controller], "Controller")}`);
|
|
266
|
+
return {
|
|
267
|
+
name: `_${alias}._did.`,
|
|
268
|
+
value: parts.join(";"),
|
|
269
|
+
ttl: DID_DHT_TTL
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
const serviceRecords = (document.service ?? []).map((service, index) => {
|
|
273
|
+
const parts = [
|
|
274
|
+
`id=${fragmentOf(document.id, service.id, "Service")}`,
|
|
275
|
+
`t=${listValue([service.type], "Service type")}`,
|
|
276
|
+
`se=${listValue(service.serviceEndpoint, "Service endpoint")}`
|
|
277
|
+
];
|
|
278
|
+
for (const extra of ["sig", "enc"]) {
|
|
279
|
+
const v = service[extra];
|
|
280
|
+
if (v !== void 0) parts.push(`${extra}=${listValue(Array.isArray(v) ? v : [v], `Service ${extra}`)}`);
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
name: `_s${index}._did.`,
|
|
284
|
+
value: parts.join(";"),
|
|
285
|
+
ttl: DID_DHT_TTL
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
const root = [`v=0`, `vm=${keyRecords.map((_, i) => `k${i}`).join(",")}`];
|
|
289
|
+
for (const [short, property] of RELATIONSHIPS) {
|
|
290
|
+
const refs = document[property] ?? [];
|
|
291
|
+
if (refs.length === 0) continue;
|
|
292
|
+
root.push(`${short}=${refs.map((ref) => {
|
|
293
|
+
const alias = aliases.get(ref);
|
|
294
|
+
if (!alias) throw new Error(`${property} refers to ${ref}, which is not a verification method of the document`);
|
|
295
|
+
return alias;
|
|
296
|
+
}).join(",")}`);
|
|
297
|
+
}
|
|
298
|
+
if (serviceRecords.length) root.push(`svc=${serviceRecords.map((_, i) => `s${i}`).join(",")}`);
|
|
299
|
+
const records = [];
|
|
300
|
+
if (document.alsoKnownAs?.length) records.push({
|
|
301
|
+
name: "_aka._did.",
|
|
302
|
+
value: listValue(document.alsoKnownAs, "Also-known-as"),
|
|
303
|
+
ttl: DID_DHT_TTL
|
|
304
|
+
});
|
|
305
|
+
if (document.controller !== void 0) {
|
|
306
|
+
const controllers = Array.isArray(document.controller) ? document.controller : [document.controller];
|
|
307
|
+
records.push({
|
|
308
|
+
name: "_cnt._did.",
|
|
309
|
+
value: listValue(controllers, "Controller"),
|
|
310
|
+
ttl: DID_DHT_TTL
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
records.push(...keyRecords, ...serviceRecords);
|
|
314
|
+
if (options.types?.length) {
|
|
315
|
+
for (const t of options.types) if (!Number.isSafeInteger(t) || t < 0) throw new Error(`Type ${t} is not a registry integer`);
|
|
316
|
+
records.push({
|
|
317
|
+
name: "_typ._did.",
|
|
318
|
+
value: `id=${options.types.join(",")}`,
|
|
319
|
+
ttl: DID_DHT_TTL
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
records.push({
|
|
323
|
+
name: `_did.${z32}.`,
|
|
324
|
+
value: root.join(";"),
|
|
325
|
+
ttl: DID_DHT_TTL
|
|
326
|
+
});
|
|
327
|
+
for (const host of options.gateways ?? []) records.push({
|
|
328
|
+
type: "NS",
|
|
329
|
+
name: `_did.${z32}.`,
|
|
330
|
+
host,
|
|
331
|
+
ttl: DID_DHT_TTL
|
|
332
|
+
});
|
|
333
|
+
records.push(...options.extra ?? []);
|
|
334
|
+
return records;
|
|
335
|
+
}
|
|
336
|
+
/** The compressed, authoritative DNS packet of a document. Throws `PacketTooLargeError` past 1000 bytes. */
|
|
337
|
+
function encodeDidDhtPacket(document, options = {}) {
|
|
338
|
+
const packet = encodeTxtPacket(didDhtRecords(document, options), { authoritative: true });
|
|
339
|
+
if (packet.length > 1e3) throw new PacketTooLargeError(packet.length);
|
|
340
|
+
return packet;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* The packet that ends a DID: its root record alone, reading `deactivated`. Resolvers then answer with
|
|
344
|
+
* `deactivated: true` and a document holding the id alone, until the record leaves the DHT.
|
|
345
|
+
*/
|
|
346
|
+
function encodeDidDhtDeactivated(publicKey) {
|
|
347
|
+
const { z32 } = didDhtKey(didDhtFromPublicKey(publicKey));
|
|
348
|
+
return encodeTxtPacket([{
|
|
349
|
+
name: `_did.${z32}.`,
|
|
350
|
+
value: "deactivated",
|
|
351
|
+
ttl: DID_DHT_TTL
|
|
352
|
+
}], { authoritative: true });
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* The relay payload of a document: its packet, signed by the identity key. `seq` is the BEP44 sequence
|
|
356
|
+
* number, which did:dht defines as the UNIX time in seconds (Ghostly's chat records use microseconds).
|
|
357
|
+
*/
|
|
358
|
+
function signDidDhtPacket(identity, dnsPacket, seq) {
|
|
359
|
+
if (!Number.isSafeInteger(seq) || seq < 0) throw new Error("A did:dht sequence number is a UNIX time in seconds");
|
|
360
|
+
return signRelayPayload(identity, dnsPacket, BigInt(seq));
|
|
361
|
+
}
|
|
362
|
+
var FRAGMENT = /^[A-Za-z0-9._~-]{1,64}$/;
|
|
363
|
+
var ALG = /^[A-Za-z0-9+._-]{1,32}$/;
|
|
364
|
+
var DID = /^did:[a-z0-9]+:[A-Za-z0-9._:%-]+$/;
|
|
365
|
+
var URI = /^[A-Za-z][A-Za-z0-9+.-]*:[^\s,;]+$/;
|
|
366
|
+
/** `a=1;b=x,y`: each property once, names in lower case. */
|
|
367
|
+
function properties(value, where) {
|
|
368
|
+
const out = /* @__PURE__ */ new Map();
|
|
369
|
+
for (const pair of value.split(";")) {
|
|
370
|
+
const at = pair.indexOf("=");
|
|
371
|
+
const name = pair.slice(0, at);
|
|
372
|
+
if (at <= 0 || !/^[a-z]+$/.test(name)) throw malformed(`${where} has a property that is not name=value`);
|
|
373
|
+
if (out.has(name)) throw malformed(`${where} has ${name} twice`);
|
|
374
|
+
out.set(name, pair.slice(at + 1));
|
|
375
|
+
}
|
|
376
|
+
return out;
|
|
377
|
+
}
|
|
378
|
+
function list(value, where, item) {
|
|
379
|
+
if (value === void 0) return [];
|
|
380
|
+
const items = value.split(",");
|
|
381
|
+
for (const v of items) if (!item.test(v)) throw malformed(`${where} has an unexpected value`);
|
|
382
|
+
return items;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* The document in a did:dht DNS packet. Other records of the key (anything not ending in `_did`) are
|
|
386
|
+
* ignored, and so are did:dht records this version does not know (`_prv`, future ones); everything it
|
|
387
|
+
* does know must be well formed and consistent, or the packet is refused.
|
|
388
|
+
*/
|
|
389
|
+
function decodeDidDhtPacket(did, dnsPacket) {
|
|
390
|
+
const { z32, publicKey } = didDhtKey(did);
|
|
391
|
+
let txt;
|
|
392
|
+
try {
|
|
393
|
+
txt = decodeTxtPacket(dnsPacket);
|
|
394
|
+
} catch (error) {
|
|
395
|
+
throw malformed(`not a DNS packet (${error instanceof Error ? error.message : String(error)})`);
|
|
396
|
+
}
|
|
397
|
+
const byName = /* @__PURE__ */ new Map();
|
|
398
|
+
let rootValue;
|
|
399
|
+
for (const record of txt) {
|
|
400
|
+
const name = record.name.toLowerCase().replace(/\.$/, "");
|
|
401
|
+
if (name === `_did.${z32}`) {
|
|
402
|
+
if (rootValue !== void 0) throw malformed("two root records");
|
|
403
|
+
rootValue = record.value;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
const match = /^(_[a-z0-9]+)\._did(?:\.([a-z0-9]+))?$/.exec(name);
|
|
407
|
+
if (!match || match[2] !== void 0 && match[2] !== z32) continue;
|
|
408
|
+
if (byName.has(match[1])) throw malformed(`two ${match[1]} records`);
|
|
409
|
+
byName.set(match[1], record.value);
|
|
410
|
+
}
|
|
411
|
+
if (rootValue === void 0) throw malformed("no root record");
|
|
412
|
+
if (rootValue === "deactivated") return {
|
|
413
|
+
document: {
|
|
414
|
+
id: did,
|
|
415
|
+
verificationMethod: []
|
|
416
|
+
},
|
|
417
|
+
deactivated: true
|
|
418
|
+
};
|
|
419
|
+
const root = properties(rootValue, "the root record");
|
|
420
|
+
if (root.get("v") !== "0") throw malformed(`version ${root.get("v") ?? "(none)"} is not supported`);
|
|
421
|
+
const vm = list(root.get("vm"), "the root record's vm", /^k\d{1,3}$/);
|
|
422
|
+
if (!vm.includes("k0")) throw malformed("the identity key k0 is not listed");
|
|
423
|
+
if (new Set(vm).size !== vm.length) throw malformed("a key is listed twice");
|
|
424
|
+
const document = {
|
|
425
|
+
id: did,
|
|
426
|
+
verificationMethod: []
|
|
427
|
+
};
|
|
428
|
+
const methodIds = /* @__PURE__ */ new Map();
|
|
429
|
+
for (const alias of vm) {
|
|
430
|
+
const value = byName.get(`_${alias}`);
|
|
431
|
+
if (value === void 0) throw malformed(`the key ${alias} has no record`);
|
|
432
|
+
const props = properties(value, `the key ${alias}`);
|
|
433
|
+
const type = Number(props.get("t"));
|
|
434
|
+
if (!/^[0-3]$/.test(props.get("t") ?? "")) throw malformed(`the key ${alias} has an unknown type`);
|
|
435
|
+
const alg = props.get("a") ?? KEY_TYPES[type].alg;
|
|
436
|
+
if (!ALG.test(alg)) throw malformed(`the key ${alias} has an unusable algorithm`);
|
|
437
|
+
const k = props.get("k") ?? "";
|
|
438
|
+
const bytes = /^[A-Za-z0-9_-]+$/.test(k) && k.length % 4 !== 1 ? fromBase64Url(k) : /* @__PURE__ */ new Uint8Array();
|
|
439
|
+
if (bytes.length === 0 || toBase64Url(bytes) !== k) throw malformed(`the key ${alias} is not unpadded base64url`);
|
|
440
|
+
const controller = props.get("c") ?? did;
|
|
441
|
+
if (!DID.test(controller)) throw malformed(`the key ${alias} has a controller that is not a DID`);
|
|
442
|
+
let fragment;
|
|
443
|
+
let jwk;
|
|
444
|
+
if (alias === "k0") {
|
|
445
|
+
if (type !== 0 || !bytesEqual(bytes, publicKey)) throw malformed("k0 is not the DID's identity key");
|
|
446
|
+
if (props.has("id") && props.get("id") !== "0") throw malformed("the identity key's id is not 0");
|
|
447
|
+
fragment = "0";
|
|
448
|
+
jwk = jwkOf(type, bytes, alg, fragment);
|
|
449
|
+
} else {
|
|
450
|
+
const provisional = jwkOf(type, bytes, alg, "");
|
|
451
|
+
fragment = props.get("id") ?? jwkThumbprint(provisional);
|
|
452
|
+
if (!FRAGMENT.test(fragment)) throw malformed(`the key ${alias} has an unusable id`);
|
|
453
|
+
jwk = {
|
|
454
|
+
...provisional,
|
|
455
|
+
kid: fragment
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
const id = `${did}#${fragment}`;
|
|
459
|
+
if ([...methodIds.values()].includes(id)) throw malformed(`two keys have the id ${fragment}`);
|
|
460
|
+
methodIds.set(alias, id);
|
|
461
|
+
document.verificationMethod.push({
|
|
462
|
+
id,
|
|
463
|
+
type: "JsonWebKey",
|
|
464
|
+
controller,
|
|
465
|
+
publicKeyJwk: jwk
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
for (const [short, property] of RELATIONSHIPS) {
|
|
469
|
+
const refs = list(root.get(short), `the root record's ${short}`, /^k\d{1,3}$/);
|
|
470
|
+
if (refs.length === 0) continue;
|
|
471
|
+
document[property] = refs.map((alias) => {
|
|
472
|
+
const id = methodIds.get(alias);
|
|
473
|
+
if (!id) throw malformed(`${short} names ${alias}, which is not a listed key`);
|
|
474
|
+
return id;
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
const services = list(root.get("svc"), "the root record's svc", /^s\d{1,3}$/);
|
|
478
|
+
if (new Set(services).size !== services.length) throw malformed("a service is listed twice");
|
|
479
|
+
for (const alias of services) {
|
|
480
|
+
const value = byName.get(`_${alias}`);
|
|
481
|
+
if (value === void 0) throw malformed(`the service ${alias} has no record`);
|
|
482
|
+
const props = properties(value, `the service ${alias}`);
|
|
483
|
+
const fragment = props.get("id") ?? "";
|
|
484
|
+
const type = props.get("t") ?? "";
|
|
485
|
+
if (!FRAGMENT.test(fragment)) throw malformed(`the service ${alias} has an unusable id`);
|
|
486
|
+
if (!/^[A-Za-z0-9._:/-]{1,64}$/.test(type)) throw malformed(`the service ${alias} has an unusable type`);
|
|
487
|
+
const service = {
|
|
488
|
+
id: `${did}#${fragment}`,
|
|
489
|
+
type,
|
|
490
|
+
serviceEndpoint: list(props.get("se") ?? "", `the service ${alias}'s endpoint`, URI)
|
|
491
|
+
};
|
|
492
|
+
for (const extra of ["sig", "enc"]) {
|
|
493
|
+
const v = props.get(extra);
|
|
494
|
+
if (v !== void 0) service[extra] = v.includes(",") ? list(v, `the service ${alias}'s ${extra}`, /^[^\s,;]+$/) : v;
|
|
495
|
+
}
|
|
496
|
+
if (document.service?.some((s) => s.id === service.id)) throw malformed(`two services have the id ${fragment}`);
|
|
497
|
+
(document.service ??= []).push(service);
|
|
498
|
+
}
|
|
499
|
+
const controller = byName.get("_cnt");
|
|
500
|
+
if (controller !== void 0) {
|
|
501
|
+
const controllers = list(controller, "the controller record", DID);
|
|
502
|
+
document.controller = controllers.length === 1 ? controllers[0] : controllers;
|
|
503
|
+
}
|
|
504
|
+
const aka = byName.get("_aka");
|
|
505
|
+
if (aka !== void 0) document.alsoKnownAs = list(aka, "the also-known-as record", URI);
|
|
506
|
+
const decoded = {
|
|
507
|
+
document,
|
|
508
|
+
deactivated: false
|
|
509
|
+
};
|
|
510
|
+
const typ = byName.get("_typ");
|
|
511
|
+
if (typ !== void 0) decoded.types = list(properties(typ, "the type record").get("id"), "the type record", /^\d{1,9}$/).map(Number);
|
|
512
|
+
return decoded;
|
|
513
|
+
}
|
|
514
|
+
/** A packet opened and decoded: the signature is the identity key's, the document well formed. */
|
|
515
|
+
function openDidDhtPayload(did, payload) {
|
|
516
|
+
const { z32 } = didDhtKey(did);
|
|
517
|
+
let opened;
|
|
518
|
+
try {
|
|
519
|
+
opened = openRelayPayload(z32, payload);
|
|
520
|
+
} catch (error) {
|
|
521
|
+
if (error instanceof Error && error.message === "Invalid signature") throw new DidDhtError("The did:dht record is not signed by the DID's key", "invalid-signature");
|
|
522
|
+
throw malformed(error instanceof Error ? error.message : String(error));
|
|
523
|
+
}
|
|
524
|
+
return {
|
|
525
|
+
...decodeDidDhtPacket(did, opened.dnsPacket),
|
|
526
|
+
seq: opened.seq
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
/** The spec's `seq` is in seconds; Pkarr clients write microseconds. Either way, a date. */
|
|
530
|
+
function seqDate(seq) {
|
|
531
|
+
const n = Number(seq);
|
|
532
|
+
const ms = n < 1e11 ? n * 1e3 : n < 0x5af3107a4000 ? n : n / 1e3;
|
|
533
|
+
const date = new Date(ms);
|
|
534
|
+
return Number.isNaN(date.getTime()) ? (/* @__PURE__ */ new Date(0)).toISOString() : date.toISOString();
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Resolves a did:dht through Pkarr relays: one GET to each, all at once, and the newest packet that
|
|
538
|
+
* checks out wins (the highest sequence number; on a tie, the relay listed first), so a relay holding
|
|
539
|
+
* an older version cannot bring back a removed key or undo a deactivation. Each answer is bounded to
|
|
540
|
+
* a BEP44 item, its signature checked against the DID's key and its records parsed strictly; a relay
|
|
541
|
+
* that has nothing, fails or serves a packet that does not check out does not count. A deactivated DID
|
|
542
|
+
* resolves (`metadata.deactivated`); everything else that goes wrong throws a `DidDhtError`.
|
|
543
|
+
*/
|
|
544
|
+
async function resolveDidDht(did, options) {
|
|
545
|
+
const { z32 } = didDhtKey(did);
|
|
546
|
+
const relays = [...new Set((options.relays ?? DEFAULT_RELAYS).map(normalizeRelayUrl).filter((r) => r !== null))];
|
|
547
|
+
if (relays.length === 0) throw new DidDhtError("No Pkarr relay to ask", "unreachable");
|
|
548
|
+
options.signal?.throwIfAborted();
|
|
549
|
+
const responses = await Promise.all(relays.map((relay) => options.fetch(`${relay}/${z32}`, {
|
|
550
|
+
maxBytes: DID_DHT_MAX_PAYLOAD,
|
|
551
|
+
signal: options.signal,
|
|
552
|
+
redirect: "error"
|
|
553
|
+
}).catch(() => void 0)));
|
|
554
|
+
options.signal?.throwIfAborted();
|
|
555
|
+
let notFound = false;
|
|
556
|
+
let refused;
|
|
557
|
+
let newest;
|
|
558
|
+
for (const [i, relay] of relays.entries()) {
|
|
559
|
+
const response = responses[i];
|
|
560
|
+
if (response?.status === 404) notFound = true;
|
|
561
|
+
if (response?.status !== 200) continue;
|
|
562
|
+
try {
|
|
563
|
+
const opened = openDidDhtPayload(did, response.bytes);
|
|
564
|
+
if (!newest || opened.seq > newest.seq) newest = {
|
|
565
|
+
...opened,
|
|
566
|
+
relay
|
|
567
|
+
};
|
|
568
|
+
} catch (error) {
|
|
569
|
+
if (!(error instanceof DidDhtError)) throw error;
|
|
570
|
+
refused = error;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (newest) return {
|
|
574
|
+
document: newest.document,
|
|
575
|
+
metadata: {
|
|
576
|
+
versionId: newest.seq.toString(),
|
|
577
|
+
updated: seqDate(newest.seq),
|
|
578
|
+
...newest.deactivated ? { deactivated: true } : {},
|
|
579
|
+
...newest.types ? { types: newest.types } : {}
|
|
580
|
+
},
|
|
581
|
+
relay: newest.relay
|
|
582
|
+
};
|
|
583
|
+
if (refused) throw refused;
|
|
584
|
+
if (notFound) throw new DidDhtError("No document is published for this did:dht", "not-found");
|
|
585
|
+
throw new DidDhtError("No Pkarr relay answered for this did:dht", "unreachable");
|
|
586
|
+
}
|
|
587
|
+
// ../browser/src/shared/features.ts
|
|
588
|
+
/**
|
|
589
|
+
* A build that may be put into test mode: a development build (`import.meta.env.DEV`, which vitest also sets) or the
|
|
590
|
+
* e2e suite's build (`VITE_APPS_TEST`, fixed when the build is made, as the mini-app switch is). A release build is
|
|
591
|
+
* neither: Vite folds this to `false` there, so the storage flags the test fakes answer to are ignored. The fakes
|
|
592
|
+
* themselves are still in the bundle (the registries import them); plugins may still pass fakes to the registry.
|
|
593
|
+
*/
|
|
594
|
+
var testBuild = () => {
|
|
595
|
+
try {
|
|
596
|
+
return false;
|
|
597
|
+
} catch {
|
|
598
|
+
return false;
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
/**
|
|
602
|
+
* A suite's switch in the page's storage (`localStorage["ghostly-test-…"]`), read only in a test build (`testBuild`): a
|
|
603
|
+
* release build reads none, so a leftover or pasted key changes nothing there. Null when unset, unreadable or released.
|
|
604
|
+
*/
|
|
605
|
+
var testSwitch = (key) => {
|
|
606
|
+
if (!testBuild()) return null;
|
|
607
|
+
try {
|
|
608
|
+
return globalThis.localStorage?.getItem(key) ?? null;
|
|
609
|
+
} catch {
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
// ../browser/src/proofs/verify.ts
|
|
614
|
+
var DAY = 86400;
|
|
615
|
+
/**
|
|
616
|
+
* The checks every proof goes through, whatever its provider: known provider, validity within the
|
|
617
|
+
* provider's limit, bounded evidence, strict parsing, the provider's own check, and the category rule
|
|
618
|
+
* (a self-custodied proof proves exactly the subject it names; an attested one says who attests it).
|
|
619
|
+
* The engine verifies a contact's proof, and the person's own proof before saving it, only through this.
|
|
620
|
+
*/
|
|
621
|
+
async function verifyIdentity(providers, statement, evidence, ctx) {
|
|
622
|
+
const { binding } = statement;
|
|
623
|
+
const provider = providers.find((p) => p.id === binding.provider);
|
|
624
|
+
if (!provider) throw new Error("This app cannot verify this kind of identity");
|
|
625
|
+
if (binding.expiresAt - binding.issuedAt > Math.min(provider.validity.maxDays * DAY, 3456e4)) throw new Error("The proof lasts longer than this kind of identity allows");
|
|
626
|
+
if (JSON.stringify(evidence ?? null).length > 16384) throw new Error("Evidence too large");
|
|
627
|
+
const parsed = provider.parseEvidence(evidence);
|
|
628
|
+
const verified = boundVerifiedIdentity(await provider.verify(statement, parsed, ctx));
|
|
629
|
+
if (provider.category === "self-custodied" && verified.subject !== binding.subject) throw new Error("The evidence is for another identity");
|
|
630
|
+
if (provider.category === "provider-attested" && !verified.attester) throw new Error("The evidence does not say who attests it");
|
|
631
|
+
return verified;
|
|
632
|
+
}
|
|
633
|
+
/** Problems with a provider's descriptor, empty when it is well-formed. The registry and the contract suite use it. */
|
|
634
|
+
function descriptorProblems(p) {
|
|
635
|
+
const problems = [];
|
|
636
|
+
if (!/^[a-z][a-z0-9-]{0,31}$/.test(p.id)) problems.push("id must match ^[a-z][a-z0-9-]{0,31}$");
|
|
637
|
+
if (!p.label?.trim()) problems.push("label is empty");
|
|
638
|
+
if (!p.description?.trim()) problems.push("description is empty");
|
|
639
|
+
if (!p.privacy?.trim()) problems.push("privacy is empty: say what verify contacts");
|
|
640
|
+
if (p.category !== "self-custodied" && p.category !== "provider-attested") problems.push("category is unknown");
|
|
641
|
+
if (!p.platforms.length) problems.push("no platforms");
|
|
642
|
+
const { defaultDays, maxDays } = p.validity;
|
|
643
|
+
if (!(Number.isInteger(defaultDays) && Number.isInteger(maxDays) && defaultDays >= 1 && defaultDays <= maxDays && maxDays * DAY <= 3456e4)) problems.push("validity must be whole days, 1 ≤ default ≤ max ≤ 400");
|
|
644
|
+
if (p.recheck && !(Number.isInteger(p.recheck.afterSeconds) && p.recheck.afterSeconds >= 60)) problems.push("recheck.afterSeconds must be at least 60");
|
|
645
|
+
if (p.recheck?.perHour !== void 0 && !(Number.isInteger(p.recheck.perHour) && p.recheck.perHour >= 1)) problems.push("recheck.perHour must be a whole number, at least 1");
|
|
646
|
+
if (!p.signers.length) problems.push("no signers");
|
|
647
|
+
const ids = p.signers.map((s) => s.id);
|
|
648
|
+
if (new Set(ids).size !== ids.length) problems.push("signer ids are not unique");
|
|
649
|
+
for (const s of p.signers) {
|
|
650
|
+
if (![
|
|
651
|
+
"in-app",
|
|
652
|
+
"external-tool",
|
|
653
|
+
"redirect",
|
|
654
|
+
"publish"
|
|
655
|
+
].includes(s.kind)) problems.push(`signer ${s.id} has an unknown kind`);
|
|
656
|
+
if (s.kind === "in-app" && typeof s.run !== "function") problems.push(`signer ${s.id} has no run()`);
|
|
657
|
+
if (s.kind === "external-tool" && (typeof s.instructions !== "function" || typeof s.parse !== "function")) problems.push(`signer ${s.id} needs instructions() and parse()`);
|
|
658
|
+
if (s.kind === "redirect" && typeof s.start !== "function") problems.push(`signer ${s.id} has no start()`);
|
|
659
|
+
if (s.kind === "publish" && (typeof s.instructions !== "function" || typeof s.evidence !== "function")) problems.push(`signer ${s.id} needs instructions() and evidence()`);
|
|
660
|
+
}
|
|
661
|
+
return problems;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* The engine's `ctx.fetch`: HTTPS GET only, no credentials or referrer, a time-out, a size cap,
|
|
665
|
+
* redirects refused unless asked for.
|
|
666
|
+
* `online` false refuses everything (the person turned the network off).
|
|
667
|
+
*/
|
|
668
|
+
function boundedIdentityFetch(options = { online: () => true }) {
|
|
669
|
+
return async (url, { headers, maxBytes = 65536, signal, redirect = "error" } = {}) => {
|
|
670
|
+
if (!options.online()) throw new IdentityCheckUnavailable("Offline: this identity cannot be checked now");
|
|
671
|
+
const target = new URL(url);
|
|
672
|
+
if (target.protocol !== "https:" || target.username || target.password) throw new Error("Identity checks use HTTPS only");
|
|
673
|
+
const timeout = AbortSignal.timeout(options.timeoutMs ?? 1e4);
|
|
674
|
+
const response = await (options.fetcher ?? fetch)(target.href, {
|
|
675
|
+
headers,
|
|
676
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
677
|
+
credentials: "omit",
|
|
678
|
+
referrerPolicy: "no-referrer",
|
|
679
|
+
cache: "no-store",
|
|
680
|
+
redirect
|
|
681
|
+
});
|
|
682
|
+
if (Number(response.headers.get("content-length")) > maxBytes) throw new Error("Identity check response too large");
|
|
683
|
+
const reader = response.body?.getReader();
|
|
684
|
+
const parts = [];
|
|
685
|
+
let length = 0;
|
|
686
|
+
if (reader) try {
|
|
687
|
+
for (;;) {
|
|
688
|
+
const { done, value } = await reader.read();
|
|
689
|
+
if (done) break;
|
|
690
|
+
length += value.length;
|
|
691
|
+
if (length > maxBytes) throw new Error("Identity check response too large");
|
|
692
|
+
parts.push(value);
|
|
693
|
+
}
|
|
694
|
+
} finally {
|
|
695
|
+
await reader.cancel().catch(() => {});
|
|
696
|
+
}
|
|
697
|
+
const bytes = new Uint8Array(length);
|
|
698
|
+
let offset = 0;
|
|
699
|
+
for (const part of parts) {
|
|
700
|
+
bytes.set(part, offset);
|
|
701
|
+
offset += part.length;
|
|
702
|
+
}
|
|
703
|
+
return {
|
|
704
|
+
status: response.status,
|
|
705
|
+
contentType: response.headers.get("content-type") ?? "",
|
|
706
|
+
text: new TextDecoder().decode(bytes),
|
|
707
|
+
bytes
|
|
708
|
+
};
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
// ../browser/src/plugins/bundled.ts
|
|
712
|
+
/**
|
|
713
|
+
* The adapter plugins compiled into this build. Empty unless the build lists some: `GHOSTLY_PLUGINS`
|
|
714
|
+
* names their modules (comma-separated paths from the repository root, each default-exporting a
|
|
715
|
+
* `GhostlyAdapterPlugin`), and the Vite plugin in `packages/browser/vite-plugin.ts` swaps this module
|
|
716
|
+
* for one that imports them. Release builds never set it; the e2e build carries the SDK example.
|
|
717
|
+
*/
|
|
718
|
+
var BUNDLED_PLUGINS = [];
|
|
719
|
+
var PLUGIN_ID = /^[a-z][a-z0-9-]{0,63}$/;
|
|
720
|
+
var KEY = Symbol.for("ghostly.adapters/1");
|
|
721
|
+
function store() {
|
|
722
|
+
const g = globalThis;
|
|
723
|
+
return g[KEY] ??= {
|
|
724
|
+
plugins: /* @__PURE__ */ new Map(),
|
|
725
|
+
reserved: {
|
|
726
|
+
lightning: /* @__PURE__ */ new Set(),
|
|
727
|
+
onchain: /* @__PURE__ */ new Set(),
|
|
728
|
+
identity: /* @__PURE__ */ new Set()
|
|
729
|
+
},
|
|
730
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
731
|
+
seeded: false
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
var ids = (kind, plugin) => {
|
|
735
|
+
const list = kind === "identity" ? plugin.identities : kind === "lightning" ? plugin.lightning : plugin.onchain;
|
|
736
|
+
return Array.isArray(list) ? list.map((a) => a?.id) : [];
|
|
737
|
+
};
|
|
738
|
+
var KINDS = [
|
|
739
|
+
"lightning",
|
|
740
|
+
"onchain",
|
|
741
|
+
"identity"
|
|
742
|
+
];
|
|
743
|
+
/** Problems with a plugin, empty when it can be registered. Does not look at what is already registered. */
|
|
744
|
+
function pluginProblems(plugin) {
|
|
745
|
+
const problems = [];
|
|
746
|
+
if (!plugin || typeof plugin !== "object") return ["not a plugin object"];
|
|
747
|
+
if (!PLUGIN_ID.test(plugin.id ?? "")) problems.push("plugin id must match ^[a-z][a-z0-9-]{0,63}$");
|
|
748
|
+
if (plugin.sdk !== 1) problems.push(`plugin was written for SDK API ${String(plugin.sdk)}; this app speaks 1`);
|
|
749
|
+
if (plugin.version !== void 0 && (typeof plugin.version !== "string" || plugin.version.length > 64)) problems.push("version must be a short string");
|
|
750
|
+
for (const kind of ["lightning", "onchain"]) {
|
|
751
|
+
const list = plugin[kind];
|
|
752
|
+
if (list === void 0) continue;
|
|
753
|
+
if (!Array.isArray(list)) {
|
|
754
|
+
problems.push(`${kind} must be a list of descriptors`);
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
for (const d of list) {
|
|
758
|
+
if (!d || typeof d !== "object") {
|
|
759
|
+
problems.push(`${kind} ${String(d)}: not a descriptor`);
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
762
|
+
const own = providerDescriptorProblems(d);
|
|
763
|
+
if (d?.kind && d.kind !== kind) own.push(`is listed under ${kind} but says kind ${String(d.kind)}`);
|
|
764
|
+
problems.push(...own.map((p) => `${kind} ${String(d?.id)}: ${p}`));
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (plugin.identities !== void 0) {
|
|
768
|
+
if (!Array.isArray(plugin.identities)) problems.push("identities must be a list of providers");
|
|
769
|
+
else for (const p of plugin.identities) if (!p || typeof p !== "object") problems.push(`identity ${String(p)}: not a provider`);
|
|
770
|
+
else problems.push(...descriptorProblems(p).map((m) => `identity ${String(p.id)}: ${m}`));
|
|
771
|
+
}
|
|
772
|
+
for (const kind of KINDS) {
|
|
773
|
+
const list = ids(kind, plugin);
|
|
774
|
+
if (new Set(list).size !== list.length) problems.push(`${kind} ids are not unique within the plugin`);
|
|
775
|
+
}
|
|
776
|
+
if (!KINDS.some((kind) => ids(kind, plugin).length)) problems.push("the plugin brings no adapter");
|
|
777
|
+
return problems;
|
|
778
|
+
}
|
|
779
|
+
/** The built-in registries say which ids are theirs. A plugin using one is refused. */
|
|
780
|
+
function reserveAdapterIds(kind, list) {
|
|
781
|
+
const s = store();
|
|
782
|
+
for (const id of list) s.reserved[kind].add(id);
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Registers a plugin's adapters. Throws, registering nothing, when the plugin is malformed, its id or
|
|
786
|
+
* one of its adapters' ids is taken (by a built-in or by another plugin), or its contract generation
|
|
787
|
+
* is another one. Returns the function that unregisters it.
|
|
788
|
+
*/
|
|
789
|
+
function registerAdapters(plugin) {
|
|
790
|
+
const problems = pluginProblems(plugin);
|
|
791
|
+
const s = store();
|
|
792
|
+
if (!problems.length) {
|
|
793
|
+
if (s.plugins.has(plugin.id)) problems.push(`a plugin with id ${plugin.id} is already registered`);
|
|
794
|
+
for (const kind of KINDS) for (const id of ids(kind, plugin)) {
|
|
795
|
+
if (s.reserved[kind].has(id)) problems.push(`${kind} ${id} is a built-in of this app`);
|
|
796
|
+
for (const other of s.plugins.values()) if (ids(kind, other).includes(id)) problems.push(`${kind} ${id} is already registered by plugin ${other.id}`);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (problems.length) throw new Error(`Cannot register plugin ${String(plugin?.id)}: ${problems.join("; ")}`);
|
|
800
|
+
s.plugins.set(plugin.id, plugin);
|
|
801
|
+
notify(s);
|
|
802
|
+
return () => {
|
|
803
|
+
if (s.plugins.get(plugin.id) === plugin) {
|
|
804
|
+
s.plugins.delete(plugin.id);
|
|
805
|
+
notify(s);
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
function notify(s) {
|
|
810
|
+
for (const listener of s.listeners) try {
|
|
811
|
+
listener();
|
|
812
|
+
} catch {}
|
|
813
|
+
}
|
|
814
|
+
/** Called when a plugin registers or unregisters: the engine re-reads the lists. */
|
|
815
|
+
function onAdaptersChanged(listener) {
|
|
816
|
+
const s = store();
|
|
817
|
+
s.listeners.add(listener);
|
|
818
|
+
return () => {
|
|
819
|
+
s.listeners.delete(listener);
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
/** Every registered plugin, in registration order (bundled ones first). */
|
|
823
|
+
function registeredPlugins() {
|
|
824
|
+
seed();
|
|
825
|
+
return [...store().plugins.values()];
|
|
826
|
+
}
|
|
827
|
+
function registeredLightningProviders() {
|
|
828
|
+
return registeredPlugins().flatMap((p) => p.lightning ?? []);
|
|
829
|
+
}
|
|
830
|
+
function registeredOnchainProviders() {
|
|
831
|
+
return registeredPlugins().flatMap((p) => p.onchain ?? []);
|
|
832
|
+
}
|
|
833
|
+
function registeredIdentityProviders() {
|
|
834
|
+
return registeredPlugins().flatMap((p) => p.identities ?? []);
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* The plugins compiled into this build register once, when they are first asked for. A broken one is
|
|
838
|
+
* reported and skipped rather than taking the app down with it; the e2e that expects it fails instead.
|
|
839
|
+
*/
|
|
840
|
+
function seed() {
|
|
841
|
+
const s = store();
|
|
842
|
+
if (s.seeded) return;
|
|
843
|
+
s.seeded = true;
|
|
844
|
+
for (const plugin of BUNDLED_PLUGINS) try {
|
|
845
|
+
registerAdapters(plugin);
|
|
846
|
+
} catch (error) {
|
|
847
|
+
console.error(`[ghostly] a bundled adapter plugin was not loaded: ${error instanceof Error ? error.message : String(error)}`);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
// ../browser/src/proofs/ownDid.ts
|
|
851
|
+
/**
|
|
852
|
+
* The profile's own Ghostly did:dht, which the DID provider refuses as an external identity. The UI and the engine each
|
|
853
|
+
* set where to read it. Here, not in the provider, so setting it does not load the providers.
|
|
854
|
+
*/
|
|
855
|
+
var source = () => void 0;
|
|
856
|
+
function setOwnDidSource(read) {
|
|
857
|
+
source = read;
|
|
858
|
+
}
|
|
859
|
+
var ownDid = () => source();
|
|
860
|
+
export { normalizePubkyKey as C, pubkyProofPath as E, newPubkyProofFolder as S, pubkyProofFile as T, resolveDidDht as _, registeredLightningProviders as a, isPubkyKey as b, boundedIdentityFetch as c, testSwitch as d, DidDhtError as f, encodeDidDhtPacket as g, encodeDidDhtDeactivated as h, registeredIdentityProviders as i, verifyIdentity as l, didDhtFromPublicKey as m, setOwnDidSource as n, registeredOnchainProviders as o, didDhtDocument as p, onAdaptersChanged as r, reserveAdapterIds as s, ownDid as t, testBuild as u, signDidDhtPacket as v, pubkyProofCapability as w, isPubkyProofFolder as x, PUBKY_PROOF_MAX_BYTES as y };
|
|
861
|
+
|
|
862
|
+
//# sourceMappingURL=ownDid-DY3rYqDI.js.map
|