@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,970 @@
|
|
|
1
|
+
import { l as toBase64Url, o as isZ32Key } from "./bytes-C1DNGY18.js";
|
|
2
|
+
import { t as DEFAULT_RELAYS } from "./relay-Cjfmdec0.js";
|
|
3
|
+
import { c as nip05RootKey, d as recordsFromWellKnown, f as recordsName, l as normalizeDomain, m as wellKnownUrl, n as decodeDnsResponse, o as encodeDnsQuery, p as txtValue, r as dnsProofName, s as isPublicAddress, t as DOMAIN_FILE_MAX_BYTES, u as recordsFromTxt } from "./domainProofs-BDNP1dIy.js";
|
|
4
|
+
import { s as IdentityCheckUnavailable } from "./identityProofs-Cksc_K7_.js";
|
|
5
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
6
|
+
import { base58 } from "@scure/base";
|
|
7
|
+
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
8
|
+
import { p256 } from "@noble/curves/nist.js";
|
|
9
|
+
// ../core/src/atprotoRepo.ts
|
|
10
|
+
/**
|
|
11
|
+
* Checking one record of an AT Protocol repository without trusting the server that serves it: the
|
|
12
|
+
* CAR file `com.atproto.sync.getRecord` returns holds the signed commit, the Merkle Search Tree nodes
|
|
13
|
+
* from the commit's root down to the record, and the record itself. Every block is checked against its
|
|
14
|
+
* hash, the commit's signature against the DID's signing key, and the path through the tree to the key
|
|
15
|
+
* `collection/rkey`. Only what atproto's data model uses is accepted (DAG-CBOR without floats or
|
|
16
|
+
* undefined, CIDv1 with SHA-256), strictly: canonical lengths and map order, so re-encoding the unsigned
|
|
17
|
+
* commit gives exactly the bytes that were signed.
|
|
18
|
+
*
|
|
19
|
+
* Specs: https://atproto.com/specs/repository, https://atproto.com/specs/data-model,
|
|
20
|
+
* https://atproto.com/specs/cryptography. No network here: the caller fetches, bounded.
|
|
21
|
+
*/
|
|
22
|
+
var AtprotoProofError = class extends Error {};
|
|
23
|
+
var fail = (message) => {
|
|
24
|
+
throw new AtprotoProofError(message);
|
|
25
|
+
};
|
|
26
|
+
var CODEC_DAG_CBOR = 113;
|
|
27
|
+
var CODEC_RAW = 85;
|
|
28
|
+
var HASH_SHA256 = 18;
|
|
29
|
+
/** A CIDv1 as atproto uses it: dag-cbor or raw, SHA-256. */
|
|
30
|
+
var AtprotoCid = class {
|
|
31
|
+
bytes;
|
|
32
|
+
codec;
|
|
33
|
+
digest;
|
|
34
|
+
constructor(bytes, codec, digest) {
|
|
35
|
+
this.bytes = bytes;
|
|
36
|
+
this.codec = codec;
|
|
37
|
+
this.digest = digest;
|
|
38
|
+
}
|
|
39
|
+
/** Stable key for maps: the CID's bytes in hex. */
|
|
40
|
+
get key() {
|
|
41
|
+
return toHex(this.bytes);
|
|
42
|
+
}
|
|
43
|
+
equals(other) {
|
|
44
|
+
return this.key === other.key;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var toHex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
48
|
+
function readVarint(bytes, offset) {
|
|
49
|
+
let value = 0, shift = 0, i = offset;
|
|
50
|
+
for (;;) {
|
|
51
|
+
if (i >= bytes.length) fail("Truncated varint");
|
|
52
|
+
const b = bytes[i++];
|
|
53
|
+
if (shift === 49 && b > 15) fail("Varint too large");
|
|
54
|
+
value += (b & 127) * 2 ** shift;
|
|
55
|
+
if (!(b & 128)) {
|
|
56
|
+
if (b === 0 && i - offset > 1) fail("Varint not minimal");
|
|
57
|
+
return [value, i];
|
|
58
|
+
}
|
|
59
|
+
shift += 7;
|
|
60
|
+
if (shift > 49) fail("Varint too large");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** A binary CID at `offset`; returns it and where it ends. */
|
|
64
|
+
function readAtprotoCid(bytes, offset = 0) {
|
|
65
|
+
const [version, a] = readVarint(bytes, offset);
|
|
66
|
+
if (version !== 1) fail("Only CIDv1 is accepted");
|
|
67
|
+
const [codec, b] = readVarint(bytes, a);
|
|
68
|
+
if (codec !== CODEC_DAG_CBOR && codec !== CODEC_RAW) fail("Unknown CID codec");
|
|
69
|
+
const [hash, c] = readVarint(bytes, b);
|
|
70
|
+
if (hash !== HASH_SHA256) fail("Only SHA-256 CIDs are accepted");
|
|
71
|
+
const [length, d] = readVarint(bytes, c);
|
|
72
|
+
if (length !== 32 || d + 32 > bytes.length) fail("Bad CID digest");
|
|
73
|
+
return [new AtprotoCid(bytes.slice(offset, d + 32), codec, bytes.slice(d, d + 32)), d + 32];
|
|
74
|
+
}
|
|
75
|
+
var MAX_DEPTH = 32;
|
|
76
|
+
var textDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
77
|
+
var textEncoder = new TextEncoder();
|
|
78
|
+
/** DAG-CBOR key order: shorter first, then bytewise. */
|
|
79
|
+
function compareKeys(a, b) {
|
|
80
|
+
if (a.length !== b.length) return a.length - b.length;
|
|
81
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return a[i] - b[i];
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
/** Decodes exactly one DAG-CBOR value filling all of `bytes`. */
|
|
85
|
+
function decodeDagCbor(bytes) {
|
|
86
|
+
let offset = 0;
|
|
87
|
+
const need = (n) => {
|
|
88
|
+
if (offset + n > bytes.length) fail("Truncated CBOR");
|
|
89
|
+
};
|
|
90
|
+
const head = () => {
|
|
91
|
+
need(1);
|
|
92
|
+
const b = bytes[offset++], major = b >> 5, info = b & 31;
|
|
93
|
+
if (info < 24) return [major, info];
|
|
94
|
+
if (info === 24) {
|
|
95
|
+
need(1);
|
|
96
|
+
const v = bytes[offset++];
|
|
97
|
+
if (v < 24) fail("CBOR length not minimal");
|
|
98
|
+
return [major, v];
|
|
99
|
+
}
|
|
100
|
+
if (info === 25) {
|
|
101
|
+
need(2);
|
|
102
|
+
const v = bytes[offset] << 8 | bytes[offset + 1];
|
|
103
|
+
offset += 2;
|
|
104
|
+
if (v < 256) fail("CBOR length not minimal");
|
|
105
|
+
return [major, v];
|
|
106
|
+
}
|
|
107
|
+
if (info === 26) {
|
|
108
|
+
need(4);
|
|
109
|
+
const v = (bytes[offset] << 24 >>> 0) + (bytes[offset + 1] << 16) + (bytes[offset + 2] << 8) + bytes[offset + 3];
|
|
110
|
+
offset += 4;
|
|
111
|
+
if (v < 65536) fail("CBOR length not minimal");
|
|
112
|
+
return [major, v];
|
|
113
|
+
}
|
|
114
|
+
if (info === 27) {
|
|
115
|
+
need(8);
|
|
116
|
+
const hi = (bytes[offset] << 24 >>> 0) + (bytes[offset + 1] << 16) + (bytes[offset + 2] << 8) + bytes[offset + 3];
|
|
117
|
+
const lo = (bytes[offset + 4] << 24 >>> 0) + (bytes[offset + 5] << 16) + (bytes[offset + 6] << 8) + bytes[offset + 7];
|
|
118
|
+
offset += 8;
|
|
119
|
+
if (hi === 0) fail("CBOR length not minimal");
|
|
120
|
+
if (hi > 2097151) fail("CBOR integer too large");
|
|
121
|
+
return [major, hi * 2 ** 32 + lo];
|
|
122
|
+
}
|
|
123
|
+
return fail(info === 31 ? "Indefinite-length CBOR is not DAG-CBOR" : "Reserved CBOR value");
|
|
124
|
+
};
|
|
125
|
+
const item = (depth) => {
|
|
126
|
+
if (depth > MAX_DEPTH) fail("CBOR nested too deeply");
|
|
127
|
+
const [major, value] = head();
|
|
128
|
+
switch (major) {
|
|
129
|
+
case 0: return value;
|
|
130
|
+
case 1: return -1 - value;
|
|
131
|
+
case 2: {
|
|
132
|
+
need(value);
|
|
133
|
+
const out = bytes.slice(offset, offset + value);
|
|
134
|
+
offset += value;
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
case 3: {
|
|
138
|
+
need(value);
|
|
139
|
+
let text;
|
|
140
|
+
try {
|
|
141
|
+
text = textDecoder.decode(bytes.subarray(offset, offset + value));
|
|
142
|
+
} catch {
|
|
143
|
+
return fail("CBOR text is not UTF-8");
|
|
144
|
+
}
|
|
145
|
+
offset += value;
|
|
146
|
+
return text;
|
|
147
|
+
}
|
|
148
|
+
case 4: {
|
|
149
|
+
if (value > bytes.length - offset) fail("Truncated CBOR");
|
|
150
|
+
const out = [];
|
|
151
|
+
for (let i = 0; i < value; i++) out.push(item(depth + 1));
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
case 5: {
|
|
155
|
+
if (value * 2 > bytes.length - offset) fail("Truncated CBOR");
|
|
156
|
+
const out = Object.create(null);
|
|
157
|
+
let previous = null;
|
|
158
|
+
for (let i = 0; i < value; i++) {
|
|
159
|
+
const [keyMajor, keyLength] = head();
|
|
160
|
+
if (keyMajor !== 3) fail("CBOR map keys must be text");
|
|
161
|
+
need(keyLength);
|
|
162
|
+
const raw = bytes.subarray(offset, offset + keyLength);
|
|
163
|
+
if (previous && compareKeys(previous, raw) >= 0) fail("CBOR map keys out of order or repeated");
|
|
164
|
+
previous = raw;
|
|
165
|
+
let key;
|
|
166
|
+
try {
|
|
167
|
+
key = textDecoder.decode(raw);
|
|
168
|
+
} catch {
|
|
169
|
+
return fail("CBOR text is not UTF-8");
|
|
170
|
+
}
|
|
171
|
+
offset += keyLength;
|
|
172
|
+
out[key] = item(depth + 1);
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
case 6: {
|
|
177
|
+
if (value !== 42) fail("Only CID links (tag 42) are allowed");
|
|
178
|
+
const [inner, length] = head();
|
|
179
|
+
if (inner !== 2) fail("A CID link must be bytes");
|
|
180
|
+
need(length);
|
|
181
|
+
if (length < 2 || bytes[offset] !== 0) fail("Bad CID link");
|
|
182
|
+
const [cid, end] = readAtprotoCid(bytes.subarray(offset + 1, offset + length));
|
|
183
|
+
if (end !== length - 1) fail("Bad CID link");
|
|
184
|
+
offset += length;
|
|
185
|
+
return cid;
|
|
186
|
+
}
|
|
187
|
+
default:
|
|
188
|
+
if (value === 20) return false;
|
|
189
|
+
if (value === 21) return true;
|
|
190
|
+
if (value === 22) return null;
|
|
191
|
+
return fail("Floats and undefined are not in atproto's data model");
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
const out = item(0);
|
|
195
|
+
if (offset !== bytes.length) fail("Trailing bytes after CBOR");
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
/** Encodes a value as DAG-CBOR (canonical: minimal lengths, sorted keys). */
|
|
199
|
+
function encodeDagCbor(value) {
|
|
200
|
+
const out = [];
|
|
201
|
+
const head = (major, n) => {
|
|
202
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new AtprotoProofError("Cannot encode this number");
|
|
203
|
+
const m = major << 5;
|
|
204
|
+
if (n < 24) out.push(m | n);
|
|
205
|
+
else if (n < 256) out.push(m | 24, n);
|
|
206
|
+
else if (n < 65536) out.push(m | 25, n >> 8, n & 255);
|
|
207
|
+
else if (n < 4294967296) out.push(m | 26, n >>> 24 & 255, n >> 16 & 255, n >> 8 & 255, n & 255);
|
|
208
|
+
else {
|
|
209
|
+
const hi = Math.floor(n / 2 ** 32), lo = n >>> 0;
|
|
210
|
+
out.push(m | 27, hi >>> 24 & 255, hi >> 16 & 255, hi >> 8 & 255, hi & 255, lo >>> 24 & 255, lo >> 16 & 255, lo >> 8 & 255, lo & 255);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const bytesOut = (b) => {
|
|
214
|
+
for (const x of b) out.push(x);
|
|
215
|
+
};
|
|
216
|
+
const item = (v) => {
|
|
217
|
+
if (v === null) out.push(246);
|
|
218
|
+
else if (v === true) out.push(245);
|
|
219
|
+
else if (v === false) out.push(244);
|
|
220
|
+
else if (typeof v === "number") {
|
|
221
|
+
if (!Number.isSafeInteger(v)) throw new AtprotoProofError("Only integers are in atproto's data model");
|
|
222
|
+
if (v >= 0) head(0, v);
|
|
223
|
+
else head(1, -1 - v);
|
|
224
|
+
} else if (typeof v === "string") {
|
|
225
|
+
const b = textEncoder.encode(v);
|
|
226
|
+
head(3, b.length);
|
|
227
|
+
bytesOut(b);
|
|
228
|
+
} else if (v instanceof Uint8Array) {
|
|
229
|
+
head(2, v.length);
|
|
230
|
+
bytesOut(v);
|
|
231
|
+
} else if (v instanceof AtprotoCid) {
|
|
232
|
+
head(6, 42);
|
|
233
|
+
head(2, v.bytes.length + 1);
|
|
234
|
+
out.push(0);
|
|
235
|
+
bytesOut(v.bytes);
|
|
236
|
+
} else if (Array.isArray(v)) {
|
|
237
|
+
head(4, v.length);
|
|
238
|
+
v.forEach(item);
|
|
239
|
+
} else {
|
|
240
|
+
const entries = Object.keys(v).map((k) => [textEncoder.encode(k), v[k]]).sort((a, b) => compareKeys(a[0], b[0]));
|
|
241
|
+
head(5, entries.length);
|
|
242
|
+
for (const [k, x] of entries) {
|
|
243
|
+
head(3, k.length);
|
|
244
|
+
bytesOut(k);
|
|
245
|
+
item(x);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
item(value);
|
|
250
|
+
return new Uint8Array(out);
|
|
251
|
+
}
|
|
252
|
+
var isMap = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && !(v instanceof Uint8Array) && !(v instanceof AtprotoCid);
|
|
253
|
+
function exactKeys(v, required, optional = []) {
|
|
254
|
+
if (!isMap(v)) fail("Expected a map");
|
|
255
|
+
const obj = v;
|
|
256
|
+
for (const k of required) if (!(k in obj)) fail(`Missing field ${k}`);
|
|
257
|
+
for (const k of Object.keys(obj)) if (!required.includes(k) && !optional.includes(k)) fail(`Unexpected field ${k}`);
|
|
258
|
+
return obj;
|
|
259
|
+
}
|
|
260
|
+
/** Parses a CARv1 file and checks every block against its CID. */
|
|
261
|
+
function parseAtprotoCar(bytes, { maxBlocks = 1024 } = {}) {
|
|
262
|
+
const [headerLength, start] = readVarint(bytes, 0);
|
|
263
|
+
if (headerLength === 0 || start + headerLength > bytes.length) fail("Bad CAR header");
|
|
264
|
+
const header = exactKeys(decodeDagCbor(bytes.subarray(start, start + headerLength)), ["roots", "version"]);
|
|
265
|
+
if (header.version !== 1) fail("Only CAR v1 is accepted");
|
|
266
|
+
const roots = header.roots;
|
|
267
|
+
if (!Array.isArray(roots) || roots.length < 1 || !roots.every((r) => r instanceof AtprotoCid)) fail("Bad CAR roots");
|
|
268
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
269
|
+
let offset = start + headerLength;
|
|
270
|
+
while (offset < bytes.length) {
|
|
271
|
+
const [length, next] = readVarint(bytes, offset);
|
|
272
|
+
if (length === 0 || next + length > bytes.length) fail("Truncated CAR block");
|
|
273
|
+
const section = bytes.subarray(next, next + length);
|
|
274
|
+
const [cid, dataStart] = readAtprotoCid(section);
|
|
275
|
+
const data = section.slice(dataStart);
|
|
276
|
+
if (toHex(sha256(data)) !== toHex(cid.digest)) fail("A block does not match its hash");
|
|
277
|
+
blocks.set(cid.key, {
|
|
278
|
+
cid,
|
|
279
|
+
data
|
|
280
|
+
});
|
|
281
|
+
if (blocks.size > maxBlocks) fail("Too many blocks in the CAR");
|
|
282
|
+
offset = next + length;
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
roots,
|
|
286
|
+
blocks
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
var MULTICODEC_K256 = [231, 1];
|
|
290
|
+
var MULTICODEC_P256 = [128, 36];
|
|
291
|
+
function compress(type, key) {
|
|
292
|
+
const curve = type === "secp256k1" ? secp256k1 : p256;
|
|
293
|
+
try {
|
|
294
|
+
return curve.Point.fromBytes(key).toBytes(true);
|
|
295
|
+
} catch {
|
|
296
|
+
return fail("Invalid public key");
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* The atproto signing key of a DID document's verification method: `Multikey` (multicodec-prefixed,
|
|
301
|
+
* compressed) or the legacy `EcdsaSecp256k1VerificationKey2019` / `EcdsaSecp256r1VerificationKey2019`
|
|
302
|
+
* (the bare point). Both are base58btc multibase ("z…").
|
|
303
|
+
*/
|
|
304
|
+
function parseAtprotoVerificationKey(type, publicKeyMultibase) {
|
|
305
|
+
if (typeof publicKeyMultibase !== "string" || !publicKeyMultibase.startsWith("z") || publicKeyMultibase.length > 200) fail("Unsupported key encoding");
|
|
306
|
+
let raw;
|
|
307
|
+
try {
|
|
308
|
+
raw = base58.decode(publicKeyMultibase.slice(1));
|
|
309
|
+
} catch {
|
|
310
|
+
return fail("Unsupported key encoding");
|
|
311
|
+
}
|
|
312
|
+
if (type === "Multikey") {
|
|
313
|
+
if (raw[0] === MULTICODEC_K256[0] && raw[1] === MULTICODEC_K256[1]) return {
|
|
314
|
+
type: "secp256k1",
|
|
315
|
+
key: compress("secp256k1", raw.subarray(2))
|
|
316
|
+
};
|
|
317
|
+
if (raw[0] === MULTICODEC_P256[0] && raw[1] === MULTICODEC_P256[1]) return {
|
|
318
|
+
type: "p256",
|
|
319
|
+
key: compress("p256", raw.subarray(2))
|
|
320
|
+
};
|
|
321
|
+
return fail("Unsupported key type");
|
|
322
|
+
}
|
|
323
|
+
const legacy = type === "EcdsaSecp256k1VerificationKey2019" ? "secp256k1" : type === "EcdsaSecp256r1VerificationKey2019" ? "p256" : null;
|
|
324
|
+
if (!legacy) return fail("Unsupported key type");
|
|
325
|
+
return {
|
|
326
|
+
type: legacy,
|
|
327
|
+
key: compress(legacy, raw)
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/** atproto signatures: ECDSA over SHA-256 of the bytes, 64-byte compact r‖s, low-S only. */
|
|
331
|
+
function verifyAtprotoSignature(key, data, sig) {
|
|
332
|
+
if (sig.length !== 64) return false;
|
|
333
|
+
const curve = key.type === "secp256k1" ? secp256k1 : p256;
|
|
334
|
+
try {
|
|
335
|
+
return curve.verify(sig, sha256(data), key.key, {
|
|
336
|
+
prehash: false,
|
|
337
|
+
lowS: true,
|
|
338
|
+
format: "compact"
|
|
339
|
+
});
|
|
340
|
+
} catch {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function decodeAtprotoCommit(data) {
|
|
345
|
+
const c = exactKeys(decodeDagCbor(data), [
|
|
346
|
+
"data",
|
|
347
|
+
"did",
|
|
348
|
+
"rev",
|
|
349
|
+
"sig",
|
|
350
|
+
"version"
|
|
351
|
+
], ["prev"]);
|
|
352
|
+
if (c.version !== 3) fail("Unsupported commit version");
|
|
353
|
+
if (typeof c.did !== "string" || !(c.data instanceof AtprotoCid) || typeof c.rev !== "string" || !(c.sig instanceof Uint8Array)) fail("Malformed commit");
|
|
354
|
+
const prev = c.prev ?? null;
|
|
355
|
+
if (prev !== null && !(prev instanceof AtprotoCid)) fail("Malformed commit");
|
|
356
|
+
return {
|
|
357
|
+
did: c.did,
|
|
358
|
+
version: 3,
|
|
359
|
+
data: c.data,
|
|
360
|
+
rev: c.rev,
|
|
361
|
+
prev,
|
|
362
|
+
sig: c.sig
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
/** The bytes a commit's signature covers: the commit without `sig`, re-encoded. */
|
|
366
|
+
function unsignedCommitBytes(data) {
|
|
367
|
+
const { sig: _sig, ...unsigned } = decodeDagCbor(data);
|
|
368
|
+
return encodeDagCbor(unsigned);
|
|
369
|
+
}
|
|
370
|
+
function decodeMstNode(data) {
|
|
371
|
+
const node = exactKeys(decodeDagCbor(data), ["e", "l"]);
|
|
372
|
+
if (node.l !== null && !(node.l instanceof AtprotoCid)) fail("Malformed tree node");
|
|
373
|
+
if (!Array.isArray(node.e)) fail("Malformed tree node");
|
|
374
|
+
const entries = [];
|
|
375
|
+
let previous = /* @__PURE__ */ new Uint8Array(0);
|
|
376
|
+
for (const raw of node.e) {
|
|
377
|
+
const e = exactKeys(raw, [
|
|
378
|
+
"k",
|
|
379
|
+
"p",
|
|
380
|
+
"t",
|
|
381
|
+
"v"
|
|
382
|
+
]);
|
|
383
|
+
if (typeof e.p !== "number" || !Number.isSafeInteger(e.p) || e.p < 0 || e.p > previous.length || !(e.k instanceof Uint8Array) || !(e.v instanceof AtprotoCid) || e.t !== null && !(e.t instanceof AtprotoCid)) fail("Malformed tree entry");
|
|
384
|
+
const key = new Uint8Array(e.p + e.k.length);
|
|
385
|
+
key.set(previous.subarray(0, e.p));
|
|
386
|
+
key.set(e.k, e.p);
|
|
387
|
+
if (key.length > 1024) fail("Tree key too long");
|
|
388
|
+
if (entries.length && compareBytes(entries[entries.length - 1].key, key) >= 0) fail("Tree keys out of order");
|
|
389
|
+
entries.push({
|
|
390
|
+
key,
|
|
391
|
+
value: e.v,
|
|
392
|
+
right: e.t
|
|
393
|
+
});
|
|
394
|
+
previous = key;
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
left: node.l,
|
|
398
|
+
entries
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function compareBytes(a, b) {
|
|
402
|
+
const n = Math.min(a.length, b.length);
|
|
403
|
+
for (let i = 0; i < n; i++) if (a[i] !== b[i]) return a[i] - b[i];
|
|
404
|
+
return a.length - b.length;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Walks the tree from `root` to `key`. Returns the value's CID, or null when the blocks prove the key is
|
|
408
|
+
* absent. Throws when a block on the path is missing: the CAR proves neither.
|
|
409
|
+
*/
|
|
410
|
+
function findInMst(blocks, root, key, { maxDepth = 64 } = {}) {
|
|
411
|
+
const target = textEncoder.encode(key);
|
|
412
|
+
let current = root;
|
|
413
|
+
for (let depth = 0; current; depth++) {
|
|
414
|
+
if (depth > maxDepth) fail("Tree too deep");
|
|
415
|
+
const block = blocks.get(current.key);
|
|
416
|
+
if (!block) return fail("The proof is missing part of the repository tree");
|
|
417
|
+
if (block.cid.codec !== CODEC_DAG_CBOR) fail("Malformed tree node");
|
|
418
|
+
const node = decodeMstNode(block.data);
|
|
419
|
+
let next = node.left;
|
|
420
|
+
let descended = false;
|
|
421
|
+
for (let i = 0; i < node.entries.length; i++) {
|
|
422
|
+
const order = compareBytes(target, node.entries[i].key);
|
|
423
|
+
if (order === 0) return node.entries[i].value;
|
|
424
|
+
if (order < 0) {
|
|
425
|
+
next = i === 0 ? node.left : node.entries[i - 1].right;
|
|
426
|
+
descended = true;
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (!descended) next = node.entries.length ? node.entries[node.entries.length - 1].right : node.left;
|
|
431
|
+
current = next;
|
|
432
|
+
}
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Verifies a `com.atproto.sync.getRecord` CAR for `did`'s `collection/rkey`, signed by `key` (from the DID
|
|
437
|
+
* document, never from the CAR or the server). Throws AtprotoProofError on any mismatch.
|
|
438
|
+
*/
|
|
439
|
+
function verifyAtprotoRecordProof(car, options) {
|
|
440
|
+
const parsed = parseAtprotoCar(car);
|
|
441
|
+
const root = parsed.roots[0];
|
|
442
|
+
const commitBlock = parsed.blocks.get(root.key);
|
|
443
|
+
if (!commitBlock || root.codec !== CODEC_DAG_CBOR) fail("The proof has no commit");
|
|
444
|
+
const commit = decodeAtprotoCommit(commitBlock.data);
|
|
445
|
+
if (commit.did !== options.did) fail("The commit is for another account");
|
|
446
|
+
if (!verifyAtprotoSignature(options.key, unsignedCommitBytes(commitBlock.data), commit.sig)) fail("The commit is not signed by the account's key");
|
|
447
|
+
const cid = findInMst(parsed.blocks, commit.data, `${options.collection}/${options.rkey}`);
|
|
448
|
+
if (!cid) return {
|
|
449
|
+
commit,
|
|
450
|
+
record: null
|
|
451
|
+
};
|
|
452
|
+
const block = parsed.blocks.get(cid.key);
|
|
453
|
+
if (!block) return fail("The proof is missing the record");
|
|
454
|
+
if (cid.codec !== CODEC_DAG_CBOR) fail("The record is not DAG-CBOR");
|
|
455
|
+
const value = decodeDagCbor(block.data);
|
|
456
|
+
if (!isMap(value)) fail("The record is not an object");
|
|
457
|
+
return {
|
|
458
|
+
commit,
|
|
459
|
+
record: {
|
|
460
|
+
cid,
|
|
461
|
+
value
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
// ../core/src/atprotoIdentity.ts
|
|
466
|
+
/**
|
|
467
|
+
* AT Protocol identity, the pure half (no network): handle and DID syntax, what a DID document says
|
|
468
|
+
* (the signing key, the PDS, the handle it claims), and the Ghostly proof record. Specs:
|
|
469
|
+
* https://atproto.com/specs/handle, https://atproto.com/specs/did, https://atproto.com/specs/record-key.
|
|
470
|
+
*/
|
|
471
|
+
/** The Ghostly proof record's collection (NSID under ghostly.tools). Lexicon: docs/lexicons/tools.ghostly.proof.json. */
|
|
472
|
+
var ATPROTO_PROOF_COLLECTION = "tools.ghostly.proof";
|
|
473
|
+
/**
|
|
474
|
+
* What the OAuth sign-in asks for. `atproto` is required by every server; the granular repo scope lets
|
|
475
|
+
* Ghostly create and delete records of its own collection only: no posts, no DMs, no profile edits.
|
|
476
|
+
* Servers that predate granular permissions only know `transition:generic` (full access to the account's
|
|
477
|
+
* repository); Ghostly asks for it only when the person picks that option, after being told.
|
|
478
|
+
*/
|
|
479
|
+
var ATPROTO_PROOF_SCOPE = `atproto repo:${ATPROTO_PROOF_COLLECTION}?action=create&action=delete`;
|
|
480
|
+
var ATPROTO_FULL_SCOPE = "atproto transition:generic";
|
|
481
|
+
/** Every scope the client metadata declares (a request may only use declared scopes). */
|
|
482
|
+
var ATPROTO_DECLARED_SCOPE = `atproto repo:${ATPROTO_PROOF_COLLECTION}?action=create&action=delete transition:generic`;
|
|
483
|
+
var LABEL = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
|
|
484
|
+
var HANDLE = new RegExp(`^(?:${LABEL}\\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$`);
|
|
485
|
+
/** TLDs the handle spec disallows. `.test` stays allowed: it is how local networks (and the e2e suite) name accounts. */
|
|
486
|
+
var DISALLOWED_TLDS = /* @__PURE__ */ new Set([
|
|
487
|
+
"alt",
|
|
488
|
+
"arpa",
|
|
489
|
+
"example",
|
|
490
|
+
"internal",
|
|
491
|
+
"invalid",
|
|
492
|
+
"local",
|
|
493
|
+
"localhost",
|
|
494
|
+
"onion"
|
|
495
|
+
]);
|
|
496
|
+
/** A handle as people type it ("@Alice.bsky.social", "alice.bsky.social") → canonical, or null. */
|
|
497
|
+
function normalizeAtprotoHandle(input) {
|
|
498
|
+
const handle = input.trim().replace(/^@/, "").toLowerCase();
|
|
499
|
+
if (handle.length > 253 || !HANDLE.test(handle)) return null;
|
|
500
|
+
if (DISALLOWED_TLDS.has(handle.slice(handle.lastIndexOf(".") + 1))) return null;
|
|
501
|
+
return handle;
|
|
502
|
+
}
|
|
503
|
+
var DID_PLC = /^did:plc:[a-z2-7]{24}$/;
|
|
504
|
+
/** did:web at hostname level only (atproto does not use paths or ports). */
|
|
505
|
+
var DID_WEB = new RegExp(`^did:web:(?:${LABEL}\\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$`);
|
|
506
|
+
function atprotoDidMethod(did) {
|
|
507
|
+
if (DID_PLC.test(did)) return "plc";
|
|
508
|
+
if (did.length <= 261 && DID_WEB.test(did)) return "web";
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
var isAtprotoDid = (did) => atprotoDidMethod(did) !== null;
|
|
512
|
+
/** "did:plc:ab12cd…wxyz": the method, the first six and the last four characters. */
|
|
513
|
+
function shortAtprotoDid(did) {
|
|
514
|
+
const m = /^(did:[a-z]+:)(.*)$/.exec(did);
|
|
515
|
+
if (!m || m[2].length <= 14) return did;
|
|
516
|
+
return `${m[1]}${m[2].slice(0, 6)}…${m[2].slice(-4)}`;
|
|
517
|
+
}
|
|
518
|
+
/** The record key of a proof: its proof key (z-base-32, already a valid record key), so removal finds it. */
|
|
519
|
+
function atprotoProofRkey(proofKey) {
|
|
520
|
+
if (!isZ32Key(proofKey)) throw new Error("Invalid proof key");
|
|
521
|
+
return proofKey;
|
|
522
|
+
}
|
|
523
|
+
var fragment = (id, did, name) => id === `#${name}` || id === `${did}#${name}`;
|
|
524
|
+
/** A DID document (JSON already parsed) for `did`, strictly enough for atproto. Throws a message people can read. */
|
|
525
|
+
function parseAtprotoDidDocument(doc, did) {
|
|
526
|
+
if (!doc || typeof doc !== "object" || Array.isArray(doc)) throw new Error("The account's DID document is malformed");
|
|
527
|
+
const d = doc;
|
|
528
|
+
if (d.id !== did) throw new Error("The DID document is for another account");
|
|
529
|
+
const method = (Array.isArray(d.verificationMethod) ? d.verificationMethod : []).find((m) => m && typeof m === "object" && fragment(m.id, did, "atproto"));
|
|
530
|
+
if (!method || typeof method.type !== "string" || typeof method.publicKeyMultibase !== "string") throw new Error("The account has no atproto signing key");
|
|
531
|
+
let key;
|
|
532
|
+
try {
|
|
533
|
+
key = parseAtprotoVerificationKey(method.type, method.publicKeyMultibase);
|
|
534
|
+
} catch {
|
|
535
|
+
throw new Error("The account's signing key is not supported");
|
|
536
|
+
}
|
|
537
|
+
const service = (Array.isArray(d.service) ? d.service : []).find((s) => s && typeof s === "object" && fragment(s.id, did, "atproto_pds"));
|
|
538
|
+
if (!service || service.type !== "AtprotoPersonalDataServer" || typeof service.serviceEndpoint !== "string") throw new Error("The account names no server (PDS)");
|
|
539
|
+
let pds;
|
|
540
|
+
try {
|
|
541
|
+
pds = new URL(service.serviceEndpoint);
|
|
542
|
+
} catch {
|
|
543
|
+
throw new Error("The account's server address is malformed");
|
|
544
|
+
}
|
|
545
|
+
if (pds.protocol !== "https:" || pds.username || pds.password || pds.search || pds.hash || pds.pathname !== "/" && pds.pathname !== "") throw new Error("The account's server must be an https address");
|
|
546
|
+
const aka = Array.isArray(d.alsoKnownAs) ? d.alsoKnownAs : [];
|
|
547
|
+
let handle;
|
|
548
|
+
for (const entry of aka) {
|
|
549
|
+
if (typeof entry !== "string" || !entry.startsWith("at://")) continue;
|
|
550
|
+
handle = normalizeAtprotoHandle(entry.slice(5)) ?? void 0;
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
return {
|
|
554
|
+
did,
|
|
555
|
+
key,
|
|
556
|
+
pds: pds.origin,
|
|
557
|
+
...handle ? { handle } : {}
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
/** The record Ghostly writes: the statement, exactly, and when. */
|
|
561
|
+
function atprotoProofRecord(statement, createdAt) {
|
|
562
|
+
return {
|
|
563
|
+
$type: ATPROTO_PROOF_COLLECTION,
|
|
564
|
+
statement: statement.text,
|
|
565
|
+
createdAt: createdAt.toISOString()
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
/** Checks a record read from a repository against the statement it must carry. */
|
|
569
|
+
function checkAtprotoProofRecord(value, statement) {
|
|
570
|
+
if (Object.keys(value).sort().join(",") !== "$type,createdAt,statement") throw new Error("The record is not a Ghostly proof");
|
|
571
|
+
if (value.$type !== "tools.ghostly.proof") throw new Error("The record is not a Ghostly proof");
|
|
572
|
+
if (typeof value.createdAt !== "string" || value.createdAt.length > 64) throw new Error("The record is not a Ghostly proof");
|
|
573
|
+
if (value.statement !== statement.text) throw new Error("The record carries another statement");
|
|
574
|
+
}
|
|
575
|
+
// ../browser/src/proofs/pkarrRelays.ts
|
|
576
|
+
/**
|
|
577
|
+
* The profile's Pkarr relays (Network settings), which a did:dht proof is read from, as every other Pkarr read: a
|
|
578
|
+
* person who replaced the list is never read from the defaults. The UI and the engine each set where to read it. Here,
|
|
579
|
+
* not in the provider, so setting it does not load the providers.
|
|
580
|
+
*/
|
|
581
|
+
var source = () => void 0;
|
|
582
|
+
function setPkarrRelaySource(read) {
|
|
583
|
+
source = read;
|
|
584
|
+
}
|
|
585
|
+
function pkarrRelays() {
|
|
586
|
+
const relays = source();
|
|
587
|
+
return relays?.length ? [...relays] : [...DEFAULT_RELAYS];
|
|
588
|
+
}
|
|
589
|
+
// ../browser/src/proofs/domain.ts
|
|
590
|
+
/** Public resolvers that answer RFC 8484 wire-format GETs with CORS (checked 2026-09-23). */
|
|
591
|
+
var DOH_RESOLVERS = [
|
|
592
|
+
{
|
|
593
|
+
id: "quad9",
|
|
594
|
+
name: "Quad9",
|
|
595
|
+
url: "https://dns.quad9.net/dns-query"
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
id: "cloudflare",
|
|
599
|
+
name: "Cloudflare",
|
|
600
|
+
url: "https://cloudflare-dns.com/dns-query"
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
id: "google",
|
|
604
|
+
name: "Google",
|
|
605
|
+
url: "https://dns.google/dns-query"
|
|
606
|
+
}
|
|
607
|
+
];
|
|
608
|
+
var resolverById = (id) => DOH_RESOLVERS.find((r) => r.id === id) ?? DOH_RESOLVERS.find((r) => r.id === "quad9");
|
|
609
|
+
/** The person's resolver choice, per browser profile (UI and engine share the origin). */
|
|
610
|
+
var RESOLVER_SETTING = "ghostly-doh-resolver";
|
|
611
|
+
function chosenResolver() {
|
|
612
|
+
try {
|
|
613
|
+
return resolverById(globalThis.localStorage?.getItem(RESOLVER_SETTING));
|
|
614
|
+
} catch {
|
|
615
|
+
return resolverById(void 0);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
var DNS_MAX_BYTES = 16384;
|
|
619
|
+
/**
|
|
620
|
+
* Lookups are shared between checks for the DNS TTL, capped: never staler than the resolver itself would
|
|
621
|
+
* be, so a re-check sees a removal as soon as DNS does. Files have no TTL and are only shared in flight.
|
|
622
|
+
*/
|
|
623
|
+
var CACHE_MAX_MS = 3e4;
|
|
624
|
+
var CACHE_FILE_MS = 0;
|
|
625
|
+
/** A check that did not confirm the record, with a message for people. */
|
|
626
|
+
var DomainCheckError = class extends Error {};
|
|
627
|
+
/** A resolver that gave no DNS answer at all: not reached, or it refused the request. The next one may answer. */
|
|
628
|
+
var ResolverUnavailable = class extends IdentityCheckUnavailable {};
|
|
629
|
+
/** One RFC 8484 GET to one resolver. The query has ID 0 and a client subnet of 0/0, so it carries only the name and
|
|
630
|
+
* the resolver passes no part of this device's address on to the name's servers. */
|
|
631
|
+
async function askResolver(resolver, name, type, options) {
|
|
632
|
+
let response;
|
|
633
|
+
try {
|
|
634
|
+
response = await options.fetch(`${resolver.url}?dns=${toBase64Url(encodeDnsQuery(name, type))}`, {
|
|
635
|
+
headers: { accept: "application/dns-message" },
|
|
636
|
+
maxBytes: DNS_MAX_BYTES,
|
|
637
|
+
signal: options.signal,
|
|
638
|
+
redirect: "error"
|
|
639
|
+
});
|
|
640
|
+
} catch (e) {
|
|
641
|
+
throw /too large/i.test(String(e)) ? new IdentityCheckUnavailable(`${resolver.name} sent an answer that is too large`) : new ResolverUnavailable(`${resolver.name} could not be reached`);
|
|
642
|
+
}
|
|
643
|
+
if (response.status !== 200 || !/^application\/dns-message\b/i.test(response.contentType)) throw new ResolverUnavailable(`${resolver.name} refused the lookup`);
|
|
644
|
+
let answer;
|
|
645
|
+
try {
|
|
646
|
+
answer = decodeDnsResponse(response.bytes, name, type);
|
|
647
|
+
} catch {
|
|
648
|
+
throw new IdentityCheckUnavailable(`${resolver.name} sent an unusable answer`);
|
|
649
|
+
}
|
|
650
|
+
if (answer.rcode !== 0 && answer.rcode !== 3) throw new IdentityCheckUnavailable(`${resolver.name} could not resolve ${name}`);
|
|
651
|
+
return answer;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* A lookup through the chosen resolver, and through the others in turn (in list order) only when it gives no DNS
|
|
655
|
+
* answer at all. Quad9, for one, cannot be read from WebKit (the Mac desktop app, Safari): its HTTP/3 answers carry
|
|
656
|
+
* no CORS header. An answer, even "no such name" or a failure, is never asked again elsewhere. `resolver`: who answered.
|
|
657
|
+
*/
|
|
658
|
+
async function dohQuery(name, type, options) {
|
|
659
|
+
const chosen = resolverById(options.resolver);
|
|
660
|
+
let first;
|
|
661
|
+
for (const resolver of [chosen, ...DOH_RESOLVERS.filter((r) => r !== chosen)]) try {
|
|
662
|
+
return {
|
|
663
|
+
...await askResolver(resolver, name, type, options),
|
|
664
|
+
resolver: resolver.id
|
|
665
|
+
};
|
|
666
|
+
} catch (e) {
|
|
667
|
+
if (!(e instanceof ResolverUnavailable) || options.signal?.aborted) throw e;
|
|
668
|
+
first ??= e;
|
|
669
|
+
}
|
|
670
|
+
throw first;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Refuses a domain whose addresses are not all public before its web server is
|
|
674
|
+
* contacted, so a proof cannot make a contact's app probe their own network.
|
|
675
|
+
* The browser resolves again when it fetches; a name that changes its answer in
|
|
676
|
+
* between (rebinding) is not fully excluded by this check — see the draft.
|
|
677
|
+
* No address at all (the name does not exist, or has no A or AAAA record) is the resolver's answer about the
|
|
678
|
+
* domain, not something this side's network did: a DomainCheckError, so a re-check stops confirming the proof.
|
|
679
|
+
*/
|
|
680
|
+
async function assertPublicHost(domain, options) {
|
|
681
|
+
const [v4, v6] = await Promise.all([dohQuery(domain, "A", options), dohQuery(domain, "AAAA", options)]);
|
|
682
|
+
const addresses = [...v4.answers, ...v6.answers].map((a) => a.data);
|
|
683
|
+
if (!addresses.length) throw new DomainCheckError(`${domain} has no address`);
|
|
684
|
+
if (!addresses.every(isPublicAddress)) throw new IdentityCheckUnavailable(`${domain} points to a private network address, so it was not contacted`);
|
|
685
|
+
}
|
|
686
|
+
/** A well-known file: https only, no redirects, bounded. `undefined` when the server says it is not there. */
|
|
687
|
+
async function fetchWellKnown(domain, method, options) {
|
|
688
|
+
await assertPublicHost(domain, options);
|
|
689
|
+
const url = wellKnownUrl(domain, method);
|
|
690
|
+
let response;
|
|
691
|
+
try {
|
|
692
|
+
response = await options.fetch(url, {
|
|
693
|
+
headers: { accept: "application/json" },
|
|
694
|
+
maxBytes: DOMAIN_FILE_MAX_BYTES,
|
|
695
|
+
signal: options.signal,
|
|
696
|
+
redirect: "error"
|
|
697
|
+
});
|
|
698
|
+
} catch (e) {
|
|
699
|
+
if (/too large/i.test(String(e))) throw new DomainCheckError(`${url} is too large`);
|
|
700
|
+
throw new IdentityCheckUnavailable(`${domain} could not be reached. The file must be served at exactly this address, without a redirect, with the header Access-Control-Allow-Origin: *`);
|
|
701
|
+
}
|
|
702
|
+
if (response.status === 404 || response.status === 410) return;
|
|
703
|
+
if (response.status >= 300 && response.status < 400) throw new IdentityCheckUnavailable(`${domain} answered with a redirect; the file must be served at exactly ${url}`);
|
|
704
|
+
if (response.status !== 200) throw new IdentityCheckUnavailable(`${domain} answered ${response.status}`);
|
|
705
|
+
try {
|
|
706
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(response.bytes);
|
|
707
|
+
} catch {
|
|
708
|
+
throw new DomainCheckError(`${url} is not text`);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
async function lookup(domain, method, options) {
|
|
712
|
+
const resolver = resolverById(options.resolver).id;
|
|
713
|
+
if (method === "dns") {
|
|
714
|
+
const answer = await dohQuery(dnsProofName(domain), "TXT", options);
|
|
715
|
+
const values = [];
|
|
716
|
+
for (const record of answer.answers.slice(0, 32)) try {
|
|
717
|
+
values.push(txtValue(record.data));
|
|
718
|
+
} catch {}
|
|
719
|
+
const ttlMs = answer.answers.length ? Math.min(...answer.answers.map((a) => a.ttl)) * 1e3 : 0;
|
|
720
|
+
return {
|
|
721
|
+
domain,
|
|
722
|
+
method,
|
|
723
|
+
resolver: answer.resolver,
|
|
724
|
+
records: recordsFromTxt(values),
|
|
725
|
+
found: answer.answers.length > 0,
|
|
726
|
+
dnssec: answer.authenticated,
|
|
727
|
+
ttlMs
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
const text = await fetchWellKnown(domain, method, options);
|
|
731
|
+
const base = {
|
|
732
|
+
domain,
|
|
733
|
+
method,
|
|
734
|
+
resolver,
|
|
735
|
+
dnssec: false,
|
|
736
|
+
records: [],
|
|
737
|
+
ttlMs: CACHE_FILE_MS
|
|
738
|
+
};
|
|
739
|
+
if (text === void 0) return {
|
|
740
|
+
...base,
|
|
741
|
+
found: false
|
|
742
|
+
};
|
|
743
|
+
try {
|
|
744
|
+
return method === "nip05" ? {
|
|
745
|
+
...base,
|
|
746
|
+
found: true,
|
|
747
|
+
nostrKey: nip05RootKey(text)
|
|
748
|
+
} : {
|
|
749
|
+
...base,
|
|
750
|
+
found: true,
|
|
751
|
+
records: recordsFromWellKnown(text)
|
|
752
|
+
};
|
|
753
|
+
} catch {
|
|
754
|
+
throw new DomainCheckError(`${wellKnownUrl(domain, method)} is not a valid ${method === "nip05" ? "NIP-05" : "Ghostly"} file`);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
var cache = /* @__PURE__ */ new Map();
|
|
758
|
+
/** What a domain publishes by one method. Concurrent and back-to-back checks share one lookup. */
|
|
759
|
+
async function lookupDomain(domainInput, method, options) {
|
|
760
|
+
const domain = normalizeDomain(domainInput), now = options.now ?? Date.now, resolver = resolverById(options.resolver).id;
|
|
761
|
+
const id = `${resolver}|${method}|${domain}`;
|
|
762
|
+
const hit = cache.get(id);
|
|
763
|
+
if (hit && hit.until > now()) {
|
|
764
|
+
const { ttlMs: _ttl, ...result } = await hit.result;
|
|
765
|
+
return result;
|
|
766
|
+
}
|
|
767
|
+
const started = now();
|
|
768
|
+
const entry = {
|
|
769
|
+
until: started + CACHE_MAX_MS,
|
|
770
|
+
result: lookup(domain, method, {
|
|
771
|
+
...options,
|
|
772
|
+
resolver
|
|
773
|
+
})
|
|
774
|
+
};
|
|
775
|
+
cache.set(id, entry);
|
|
776
|
+
if (cache.size > 128) cache.delete(cache.keys().next().value);
|
|
777
|
+
try {
|
|
778
|
+
const { ttlMs, ...result } = await entry.result;
|
|
779
|
+
entry.until = started + Math.min(CACHE_MAX_MS, ttlMs);
|
|
780
|
+
return result;
|
|
781
|
+
} catch (e) {
|
|
782
|
+
if (cache.get(id) === entry) cache.delete(id);
|
|
783
|
+
throw e;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
/** Throws unless `domain` publishes `record` by `method` (DNS or HTTPS). Returns what was found. */
|
|
787
|
+
async function assertDomainRecord(domain, method, record, options) {
|
|
788
|
+
const found = await lookupDomain(domain, method, options);
|
|
789
|
+
if (recordsName(found.records, record)) return found;
|
|
790
|
+
const where = method === "dns" ? `The TXT record at ${dnsProofName(domain)}` : wellKnownUrl(domain);
|
|
791
|
+
if (found.records.some((r) => r.key === record.key)) throw new DomainCheckError(`${where} is for another proof of this key`);
|
|
792
|
+
if (found.records.length) throw new DomainCheckError(`${where} names another Ghostly key: this proof was replaced or removed`);
|
|
793
|
+
throw new DomainCheckError(method === "dns" ? `No Ghostly TXT record at ${dnsProofName(domain)}${found.found ? "" : " (DNS changes can take a few minutes)"}` : found.found ? `${wellKnownUrl(domain)} names no Ghostly proof` : `${wellKnownUrl(domain)} was not found`);
|
|
794
|
+
}
|
|
795
|
+
/** Throws unless the domain's NIP-05 root name is `nostrKey`. */
|
|
796
|
+
async function assertNip05(domain, nostrKey, options) {
|
|
797
|
+
const found = await lookupDomain(domain, "nip05", options);
|
|
798
|
+
if (found.nostrKey === nostrKey) return found;
|
|
799
|
+
const url = wellKnownUrl(domain, "nip05");
|
|
800
|
+
throw new DomainCheckError(!found.found ? `${url} was not found` : found.nostrKey ? `${url} names another Nostr key for ${domain}` : `${url} has no root name "_" for ${domain}`);
|
|
801
|
+
}
|
|
802
|
+
// ../browser/src/proofs/atproto/resolve.ts
|
|
803
|
+
/**
|
|
804
|
+
* AT Protocol identity resolution, the network half: a DID to its document (the PLC directory for
|
|
805
|
+
* did:plc, the host's `/.well-known/did.json` for did:web), and a handle to a DID (DNS TXT
|
|
806
|
+
* `_atproto.<handle>` through the person's DNS-over-HTTPS resolver, then
|
|
807
|
+
* `https://<handle>/.well-known/atproto-did`). Every request goes through the contract's bounded
|
|
808
|
+
* fetch: HTTPS only, no redirects, a size cap, a time-out. URLs are built here from the DID or the
|
|
809
|
+
* handle, never taken from a proof.
|
|
810
|
+
*/
|
|
811
|
+
var PLC_DIRECTORY = "https://plc.directory";
|
|
812
|
+
/** DID documents are small; a large answer is not one. */
|
|
813
|
+
var DID_DOCUMENT_MAX_BYTES = 32768;
|
|
814
|
+
var HANDLE_DID_MAX_BYTES = 2048;
|
|
815
|
+
/**
|
|
816
|
+
* The PLC directory. A build made for the e2e suite with VITE_ATPROTO_TEST_PLC may point it at a
|
|
817
|
+
* `.test` host (a name reserved for testing); a release build always uses plc.directory.
|
|
818
|
+
*/
|
|
819
|
+
function plcDirectory() {
|
|
820
|
+
try {
|
|
821
|
+
return PLC_DIRECTORY;
|
|
822
|
+
} catch {
|
|
823
|
+
return PLC_DIRECTORY;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/** Where a DID's document lives. */
|
|
827
|
+
function didDocumentUrl(did, plc = plcDirectory()) {
|
|
828
|
+
const method = atprotoDidMethod(did);
|
|
829
|
+
if (method === "plc") return `${plc}/${did}`;
|
|
830
|
+
if (method === "web") return `https://${did.slice(8)}/.well-known/did.json`;
|
|
831
|
+
throw new Error("Not an AT Protocol DID");
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Refuses a host the account chose (a did:web host, the PDS its document names) that points to a private
|
|
835
|
+
* network address: a contact's app never knocks on its own local network for someone else's proof.
|
|
836
|
+
* A host with no address is "could not run" too, except for a did:web host (`isDid`): that domain is the
|
|
837
|
+
* identity, so the resolver's answer that it has none says the DID no longer resolves (as for did:web proofs).
|
|
838
|
+
* A PDS name that is gone is its operator's, like a Pubky homeserver's: the check could not run.
|
|
839
|
+
*/
|
|
840
|
+
async function assertPublicServer(host, options, isDid = false) {
|
|
841
|
+
try {
|
|
842
|
+
await assertPublicHost(host, {
|
|
843
|
+
fetch: options.fetch,
|
|
844
|
+
signal: options.signal,
|
|
845
|
+
resolver: options.resolver
|
|
846
|
+
});
|
|
847
|
+
} catch (e) {
|
|
848
|
+
if (isDid && e instanceof DomainCheckError) throw new Error(`The account's DID no longer resolves: ${e.message}`);
|
|
849
|
+
throw new IdentityCheckUnavailable(`The account's server ${host} was not contacted: ${e instanceof Error ? e.message : String(e)}`);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
/** A DID's document, checked (parseAtprotoDidDocument). Throws a message people can read. */
|
|
853
|
+
async function resolveAtprotoDid(did, options) {
|
|
854
|
+
const url = didDocumentUrl(did, options.plc);
|
|
855
|
+
if (atprotoDidMethod(did) === "web") await assertPublicServer(did.slice(8), options, true);
|
|
856
|
+
let response;
|
|
857
|
+
try {
|
|
858
|
+
response = await options.fetch(url, {
|
|
859
|
+
headers: { accept: "application/did+ld+json, application/json" },
|
|
860
|
+
maxBytes: DID_DOCUMENT_MAX_BYTES,
|
|
861
|
+
signal: options.signal,
|
|
862
|
+
redirect: "error"
|
|
863
|
+
});
|
|
864
|
+
} catch (e) {
|
|
865
|
+
if (/too large/i.test(String(e))) throw new Error("The account's DID document is too large");
|
|
866
|
+
throw new IdentityCheckUnavailable("The account's DID could not be resolved");
|
|
867
|
+
}
|
|
868
|
+
if (response.status === 404 || response.status === 410) throw new Error("The account's DID is not registered, or was deactivated");
|
|
869
|
+
if (response.status !== 200) throw new IdentityCheckUnavailable("The account's DID could not be resolved");
|
|
870
|
+
let doc;
|
|
871
|
+
try {
|
|
872
|
+
doc = JSON.parse(response.text);
|
|
873
|
+
} catch {
|
|
874
|
+
throw new Error("The account's DID document is malformed");
|
|
875
|
+
}
|
|
876
|
+
return parseAtprotoDidDocument(doc, did);
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* The DID a handle points to, or null when it points nowhere (or to two different DIDs). DNS first,
|
|
880
|
+
* then HTTPS, as the handle spec says. The HTTPS lookup first checks the handle's addresses are public,
|
|
881
|
+
* so a handle cannot make a contact's app knock on its local network.
|
|
882
|
+
*/
|
|
883
|
+
async function resolveAtprotoHandle(handle, options) {
|
|
884
|
+
return (await lookupAtprotoHandle(handle, options)).did;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* resolveAtprotoHandle, and whether the answer is one: `checked` is false when a lookup failed on the way (the
|
|
888
|
+
* resolver or the handle's website could not be reached) so the handle may point somewhere after all. A cancel
|
|
889
|
+
* throws.
|
|
890
|
+
*/
|
|
891
|
+
async function lookupAtprotoHandle(handle, options) {
|
|
892
|
+
options.signal?.throwIfAborted();
|
|
893
|
+
const lookup = {
|
|
894
|
+
fetch: options.fetch,
|
|
895
|
+
signal: options.signal,
|
|
896
|
+
resolver: options.resolver
|
|
897
|
+
};
|
|
898
|
+
let dnsAnswered = false;
|
|
899
|
+
try {
|
|
900
|
+
const answer = await dohQuery(`_atproto.${handle}`, "TXT", lookup);
|
|
901
|
+
dnsAnswered = true;
|
|
902
|
+
const dids = /* @__PURE__ */ new Set();
|
|
903
|
+
for (const a of answer.answers) {
|
|
904
|
+
if (a.type !== 16) continue;
|
|
905
|
+
let text;
|
|
906
|
+
try {
|
|
907
|
+
text = txtValue(a.data);
|
|
908
|
+
} catch {
|
|
909
|
+
continue;
|
|
910
|
+
}
|
|
911
|
+
if (text.startsWith("did=")) dids.add(text.slice(4));
|
|
912
|
+
}
|
|
913
|
+
if (dids.size > 1) return {
|
|
914
|
+
did: null,
|
|
915
|
+
checked: true
|
|
916
|
+
};
|
|
917
|
+
const [did] = dids;
|
|
918
|
+
if (did) return {
|
|
919
|
+
did: isAtprotoDid(did) ? did : null,
|
|
920
|
+
checked: true
|
|
921
|
+
};
|
|
922
|
+
} catch {
|
|
923
|
+
options.signal?.throwIfAborted();
|
|
924
|
+
}
|
|
925
|
+
try {
|
|
926
|
+
await assertPublicHost(handle, lookup);
|
|
927
|
+
} catch {
|
|
928
|
+
options.signal?.throwIfAborted();
|
|
929
|
+
return {
|
|
930
|
+
did: null,
|
|
931
|
+
checked: dnsAnswered
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
let response;
|
|
935
|
+
try {
|
|
936
|
+
response = await options.fetch(`https://${handle}/.well-known/atproto-did`, {
|
|
937
|
+
headers: { accept: "text/plain" },
|
|
938
|
+
maxBytes: HANDLE_DID_MAX_BYTES,
|
|
939
|
+
signal: options.signal,
|
|
940
|
+
redirect: "error"
|
|
941
|
+
});
|
|
942
|
+
} catch {
|
|
943
|
+
options.signal?.throwIfAborted();
|
|
944
|
+
return {
|
|
945
|
+
did: null,
|
|
946
|
+
checked: false
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
const did = response.status === 200 ? response.text.trim() : "";
|
|
950
|
+
return isAtprotoDid(did) ? {
|
|
951
|
+
did,
|
|
952
|
+
checked: true
|
|
953
|
+
} : {
|
|
954
|
+
did: null,
|
|
955
|
+
checked: dnsAnswered
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* The handle to show for a DID: the one its document claims, and only if that handle resolves back to
|
|
960
|
+
* the same DID. Otherwise the reason: the card shows the DID. Throws only when cancelled.
|
|
961
|
+
*/
|
|
962
|
+
async function verifiedAtprotoHandle(doc, options) {
|
|
963
|
+
if (!doc.handle) return { missing: "none" };
|
|
964
|
+
const found = await lookupAtprotoHandle(doc.handle, options);
|
|
965
|
+
if (found.did === doc.did) return { handle: doc.handle };
|
|
966
|
+
return { missing: found.did || found.checked ? "elsewhere" : "unchecked" };
|
|
967
|
+
}
|
|
968
|
+
export { normalizeAtprotoHandle as C, verifyAtprotoRecordProof as E, isAtprotoDid as S, AtprotoProofError as T, ATPROTO_PROOF_COLLECTION as _, verifiedAtprotoHandle as a, atprotoProofRkey as b, assertDomainRecord as c, chosenResolver as d, resolverById as f, ATPROTO_FULL_SCOPE as g, ATPROTO_DECLARED_SCOPE as h, resolveAtprotoHandle as i, assertNip05 as l, setPkarrRelaySource as m, plcDirectory as n, DOH_RESOLVERS as o, pkarrRelays as p, resolveAtprotoDid as r, DomainCheckError as s, assertPublicServer as t, assertPublicHost as u, ATPROTO_PROOF_SCOPE as v, shortAtprotoDid as w, checkAtprotoProofRecord as x, atprotoProofRecord as y };
|
|
969
|
+
|
|
970
|
+
//# sourceMappingURL=resolve-CIc3KZMV.js.map
|