@ghostlytools/cli 1.11.4 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/README.md +31 -14
  2. package/dist/assets/{api-MYc6QNRs.js → api-BwEgbvvK.js} +395 -131
  3. package/dist/assets/api-BwEgbvvK.js.map +1 -0
  4. package/dist/assets/{api-BwyFq4lA.js → api-jRUXnBdX.js} +2 -2
  5. package/dist/assets/{apiKit-CfsNx9ZR.js → apiKit-BlsNk-Cx.js} +48 -11
  6. package/dist/assets/apiKit-BlsNk-Cx.js.map +1 -0
  7. package/dist/assets/appFetch-CW9fJPHh.js +602 -0
  8. package/dist/assets/appFetch-CW9fJPHh.js.map +1 -0
  9. package/dist/assets/apps-BcG4u6SM.js +1 -0
  10. package/dist/assets/{apps-h12II1us.js → apps-CL8TXHhu.js} +20 -14
  11. package/dist/assets/apps-CL8TXHhu.js.map +1 -0
  12. package/dist/assets/{argon2id-088uQfnH.js → argon2id-B9wFdSj6.js} +2 -3
  13. package/dist/assets/{argon2id-088uQfnH.js.map → argon2id-B9wFdSj6.js.map} +1 -1
  14. package/dist/assets/{arkade-Bw_4PZRG.js → arkade-DryM-q5n.js} +6 -7
  15. package/dist/assets/arkade-DryM-q5n.js.map +1 -0
  16. package/dist/assets/{backup-Chvy79SN.js → backup-BA41EDvh.js} +110 -26
  17. package/dist/assets/backup-BA41EDvh.js.map +1 -0
  18. package/dist/assets/backup-xZfV-ytw.js +1 -0
  19. package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js +5 -0
  20. package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js.map +1 -0
  21. package/dist/assets/{bark_ffi_wasm_bg-Bxru_BVW.wasm → bark_ffi_wasm_bg-VNmaJsc9.wasm} +0 -0
  22. package/dist/assets/{bitcoind-CdSmvy2y.js → bitcoind-Dh7n9amb.js} +4 -5
  23. package/dist/assets/{bitcoind-CdSmvy2y.js.map → bitcoind-Dh7n9amb.js.map} +1 -1
  24. package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js +5 -0
  25. package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js.map +1 -0
  26. package/dist/assets/bitcoindevkit_bg-DXil67yS.wasm +0 -0
  27. package/dist/assets/{blobFiles-BmsrvZc3.js → blobFiles-DDs34n0r.js} +4 -5
  28. package/dist/assets/{blobFiles-BmsrvZc3.js.map → blobFiles-DDs34n0r.js.map} +1 -1
  29. package/dist/assets/breez_sdk_spark_wasm_bg.wasm +0 -0
  30. package/dist/assets/buttons-CsGdQNnR.js +1 -0
  31. package/dist/assets/{buttons-BgoExb4E.js → buttons-SH1tNRh7.js} +45 -23
  32. package/dist/assets/buttons-SH1tNRh7.js.map +1 -0
  33. package/dist/assets/bytes-C1DNGY18.js +132 -0
  34. package/dist/assets/bytes-C1DNGY18.js.map +1 -0
  35. package/dist/assets/{childEnv-K_IzUqQx.js → childEnv-C-99hdbL.js} +2 -3
  36. package/dist/assets/{childEnv-K_IzUqQx.js.map → childEnv-C-99hdbL.js.map} +1 -1
  37. package/dist/assets/{client-DY8tZZWi.js → client-DGS-atRu.js} +5 -8
  38. package/dist/assets/{client-DY8tZZWi.js.map → client-DGS-atRu.js.map} +1 -1
  39. package/dist/assets/{codec-BnMg-Grj.js → codec-B2rH1mfx.js} +2 -4
  40. package/dist/assets/{codec-BnMg-Grj.js.map → codec-B2rH1mfx.js.map} +1 -1
  41. package/dist/assets/domainProofs-BDNP1dIy.js +280 -0
  42. package/dist/assets/domainProofs-BDNP1dIy.js.map +1 -0
  43. package/dist/assets/{endpoint-DarqblYE.js → endpoint-Cvu-taMs.js} +462 -424
  44. package/dist/assets/endpoint-Cvu-taMs.js.map +1 -0
  45. package/dist/assets/engineErrors--9hfgKlK.js +150 -0
  46. package/dist/assets/engineErrors--9hfgKlK.js.map +1 -0
  47. package/dist/assets/{envelope-CdV7vHVZ.js → envelope-Bi2kMqbp.js} +3 -4
  48. package/dist/assets/{envelope-CdV7vHVZ.js.map → envelope-Bi2kMqbp.js.map} +1 -1
  49. package/dist/assets/{errors-CAh6GLJZ.js → errors-DDLFO4Gf.js} +5 -4
  50. package/dist/assets/errors-DDLFO4Gf.js.map +1 -0
  51. package/dist/assets/{fedimintSdk-CPFfVK-G.js → fedimintSdk-D-6H9Pe7.js} +4 -5
  52. package/dist/assets/{fedimintSdk-CPFfVK-G.js.map → fedimintSdk-D-6H9Pe7.js.map} +1 -1
  53. package/dist/assets/fedimint_client_wasm_bg-Cr5xGD-w.js +5 -0
  54. package/dist/assets/{fedimint_client_wasm_bg-BtHHlFpp.js.map → fedimint_client_wasm_bg-Cr5xGD-w.js.map} +1 -1
  55. package/dist/assets/fileBytes-CCKbwqG_.js +1 -0
  56. package/dist/assets/{fileBytes-BLPZq9YU.js → fileBytes-CfvUXdSy.js} +5 -7
  57. package/dist/assets/fileBytes-CfvUXdSy.js.map +1 -0
  58. package/dist/assets/{fileBytes-B0z9A6Le.js → fileBytes-tj6-VZcB.js} +3 -4
  59. package/dist/assets/{fileBytes-B0z9A6Le.js.map → fileBytes-tj6-VZcB.js.map} +1 -1
  60. package/dist/assets/fileBytesIdb-B0zzJ6p7.js +1 -0
  61. package/dist/assets/{fileBytesIdb-Bmlrl9EO.js → fileBytesIdb-BJirUAjI.js} +4 -5
  62. package/dist/assets/{fileBytesIdb-Bmlrl9EO.js.map → fileBytesIdb-BJirUAjI.js.map} +1 -1
  63. package/dist/assets/{fileBytesOpfs-DBS0kbPT.js → fileBytesOpfs-DRUYLER4.js} +4 -5
  64. package/dist/assets/{fileBytesOpfs-DBS0kbPT.js.map → fileBytesOpfs-DRUYLER4.js.map} +1 -1
  65. package/dist/assets/{fixedHosts-CbgqrIKs.js → fixedHosts-CPSsGOI2.js} +4 -5
  66. package/dist/assets/{fixedHosts-CbgqrIKs.js.map → fixedHosts-CPSsGOI2.js.map} +1 -1
  67. package/dist/assets/{ghostly_iroh_web-BzAXJUYH.js → ghostly_iroh_web-DIj5xGmR.js} +2 -3
  68. package/dist/assets/{ghostly_iroh_web-BzAXJUYH.js.map → ghostly_iroh_web-DIj5xGmR.js.map} +1 -1
  69. package/dist/assets/{src-DJe-OYxd.js → groupMeta-DxuJzko_.js} +6009 -25536
  70. package/dist/assets/groupMeta-DxuJzko_.js.map +1 -0
  71. package/dist/assets/{host-C0NMNQLl.js → host-BxM-HMr0.js} +262 -134
  72. package/dist/assets/host-BxM-HMr0.js.map +1 -0
  73. package/dist/assets/{hyperdhtRelay-Dz7pvcBA.js → hyperdhtRelay-DLUiwfnt.js} +36 -9
  74. package/dist/assets/hyperdhtRelay-DLUiwfnt.js.map +1 -0
  75. package/dist/assets/hyperdhtRelay-bjNGacf5.js +32 -0
  76. package/dist/assets/hyperdhtRelay-bjNGacf5.js.map +1 -0
  77. package/dist/assets/{idb-CEuoNsTv.js → idb-ewvbqyDI.js} +2 -3
  78. package/dist/assets/{idb-CEuoNsTv.js.map → idb-ewvbqyDI.js.map} +1 -1
  79. package/dist/assets/identityProofs-Cksc_K7_.js +940 -0
  80. package/dist/assets/identityProofs-Cksc_K7_.js.map +1 -0
  81. package/dist/assets/{irohWeb-caAj4Dms.js → irohWeb-CbnGtUo6.js} +3231 -87
  82. package/dist/assets/irohWeb-CbnGtUo6.js.map +1 -0
  83. package/dist/assets/joinTrace-CBr1jbch.js +1 -0
  84. package/dist/assets/{joinTrace-CjRDFy85.js → joinTrace-xKBe73j9.js} +2 -3
  85. package/dist/assets/{joinTrace-CjRDFy85.js.map → joinTrace-xKBe73j9.js.map} +1 -1
  86. package/dist/assets/{legacy_ciphers-JJOu0JXL.js → legacy_ciphers-BnYATjxo.js} +2 -3
  87. package/dist/assets/{legacy_ciphers-JJOu0JXL.js.map → legacy_ciphers-BnYATjxo.js.map} +1 -1
  88. package/dist/assets/linkPreview-DdMf-YAc.js +252 -0
  89. package/dist/assets/linkPreview-DdMf-YAc.js.map +1 -0
  90. package/dist/assets/{main-C6t5zrD5.js → main-CwTaepxR.js} +296 -122
  91. package/dist/assets/main-CwTaepxR.js.map +1 -0
  92. package/dist/assets/{mainline-DCuGUSZF.js → mainline-CVrd0C1n.js} +72 -18
  93. package/dist/assets/mainline-CVrd0C1n.js.map +1 -0
  94. package/dist/assets/mints-BcBODVVW.js +1 -0
  95. package/dist/assets/{mints-j5XAOk4f.js → mints-CMDLbMeH.js} +8 -6
  96. package/dist/assets/mints-CMDLbMeH.js.map +1 -0
  97. package/dist/assets/{nacl-fast-CDhNCYHs.js → nacl-fast-B1ThWvuM.js} +2 -3
  98. package/dist/assets/{nacl-fast-CDhNCYHs.js.map → nacl-fast-B1ThWvuM.js.map} +1 -1
  99. package/dist/assets/{networkReason-BbQW1Xpc.js → networkReason-Be-hMghr.js} +10 -14
  100. package/dist/assets/{networkReason-BbQW1Xpc.js.map → networkReason-Be-hMghr.js.map} +1 -1
  101. package/dist/assets/{noble_curves-DDWn5AH0.js → noble_curves-DqpNlhAU.js} +3 -4
  102. package/dist/assets/{noble_curves-DDWn5AH0.js.map → noble_curves-DqpNlhAU.js.map} +1 -1
  103. package/dist/assets/{noble_hashes-B7AZyFyS.js → noble_hashes-LFe1N2xt.js} +3 -4
  104. package/dist/assets/{noble_hashes-B7AZyFyS.js.map → noble_hashes-LFe1N2xt.js.map} +1 -1
  105. package/dist/assets/{nwc-CSDRMZ0e.js → nwc-DKE2FXr6.js} +5 -6
  106. package/dist/assets/{nwc-CSDRMZ0e.js.map → nwc-DKE2FXr6.js.map} +1 -1
  107. package/dist/assets/nwcProvider-pL2XqSbW.js +208 -0
  108. package/dist/assets/nwcProvider-pL2XqSbW.js.map +1 -0
  109. package/dist/assets/{openpgp-BBFr-zHQ.js → openpgp-LkR_Zof0.js} +14 -15
  110. package/dist/assets/{openpgp-BBFr-zHQ.js.map → openpgp-LkR_Zof0.js.map} +1 -1
  111. package/dist/assets/ownDid-DY3rYqDI.js +862 -0
  112. package/dist/assets/ownDid-DY3rYqDI.js.map +1 -0
  113. package/dist/assets/{ownStatus-BoTf5WqQ.js → ownStatus-DtzIllg2.js} +70 -20
  114. package/dist/assets/ownStatus-DtzIllg2.js.map +1 -0
  115. package/dist/assets/pairedTransports-BKmvlKz1.js +581 -0
  116. package/dist/assets/pairedTransports-BKmvlKz1.js.map +1 -0
  117. package/dist/assets/paymentIntent-DySU3Ajm.js +349 -0
  118. package/dist/assets/paymentIntent-DySU3Ajm.js.map +1 -0
  119. package/dist/assets/pkarr-BQo4PcCg.js +367 -0
  120. package/dist/assets/pkarr-BQo4PcCg.js.map +1 -0
  121. package/dist/assets/{profiles-DszHjEJi.js → profiles-BOYGlmu2.js} +9 -10
  122. package/dist/assets/profiles-BOYGlmu2.js.map +1 -0
  123. package/dist/assets/registry-4W1LGlCF.js +1 -0
  124. package/dist/assets/{registry-Da-r6eC3.js → registry-Bep4umOM.js} +1296 -80
  125. package/dist/assets/registry-Bep4umOM.js.map +1 -0
  126. package/dist/assets/relay-Cjfmdec0.js +2219 -0
  127. package/dist/assets/relay-Cjfmdec0.js.map +1 -0
  128. package/dist/assets/resolve-CIc3KZMV.js +970 -0
  129. package/dist/assets/resolve-CIc3KZMV.js.map +1 -0
  130. package/dist/assets/{restoredRows-C3LcxmOw.js → restoredRows-D_WSHE7H.js} +3 -4
  131. package/dist/assets/{restoredRows-C3LcxmOw.js.map → restoredRows-D_WSHE7H.js.map} +1 -1
  132. package/dist/assets/secretGuard-Bm6nci0I.js +1 -0
  133. package/dist/assets/{secretGuard-CsVHDdYk.js → secretGuard-BrATm_gl.js} +43 -22
  134. package/dist/assets/{secretGuard-CsVHDdYk.js.map → secretGuard-BrATm_gl.js.map} +1 -1
  135. package/dist/assets/{server-C1jZZ61O.js → server-D4gf-LnD.js} +9797 -479
  136. package/dist/assets/server-D4gf-LnD.js.map +1 -0
  137. package/dist/assets/{sha512-BYId-G-T.js → sha512-DST9fbWH.js} +2 -3
  138. package/dist/assets/{sha512-BYId-G-T.js.map → sha512-DST9fbWH.js.map} +1 -1
  139. package/dist/assets/sshForges-BnvwmNj-.js +539 -0
  140. package/dist/assets/sshForges-BnvwmNj-.js.map +1 -0
  141. package/dist/assets/{storage-Bya5b2Xt.js → storage-BpjdxvO2.js} +243 -34
  142. package/dist/assets/storage-BpjdxvO2.js.map +1 -0
  143. package/dist/assets/text-li76pThX.js +106 -0
  144. package/dist/assets/text-li76pThX.js.map +1 -0
  145. package/dist/assets/{translate-CUuC5szR.js → translate-BcbSWkuq.js} +21 -26
  146. package/dist/assets/{translate-CUuC5szR.js.map → translate-BcbSWkuq.js.map} +1 -1
  147. package/dist/assets/{tree-store-N362nuzZ.js → tree-store-CAchkO_l.js} +22 -6
  148. package/dist/assets/tree-store-CAchkO_l.js.map +1 -0
  149. package/dist/assets/{types-Clyb52K2.js → types-CdWwgvyt.js} +2 -3
  150. package/dist/assets/{types-Clyb52K2.js.map → types-CdWwgvyt.js.map} +1 -1
  151. package/dist/assets/{unbzip2-stream-B1C-JX9L.js → unbzip2-stream-BtkYGpC5.js} +2 -3
  152. package/dist/assets/{unbzip2-stream-B1C-JX9L.js.map → unbzip2-stream-BtkYGpC5.js.map} +1 -1
  153. package/dist/assets/{usdt-DI51znt-.js → usdt-CBJ4Q5Ji.js} +7 -7
  154. package/dist/assets/usdt-CBJ4Q5Ji.js.map +1 -0
  155. package/dist/assets/{waitNotice-Cn0WJ-He.js → waitNotice-DQvZgz2T.js} +27 -4
  156. package/dist/assets/waitNotice-DQvZgz2T.js.map +1 -0
  157. package/dist/assets/{web-DwgdhfcY.js → web-68CYFCl9.js} +314 -91
  158. package/dist/assets/web-68CYFCl9.js.map +1 -0
  159. package/dist/ghostly.mjs +3 -5
  160. package/dist/ghostly.mjs.map +1 -1
  161. package/npm-shrinkwrap.json +225 -200
  162. package/package.json +16 -16
  163. package/dist/assets/api-MYc6QNRs.js.map +0 -1
  164. package/dist/assets/apiKit-CfsNx9ZR.js.map +0 -1
  165. package/dist/assets/appFetch-DVYZOZFw.js +0 -194
  166. package/dist/assets/appFetch-DVYZOZFw.js.map +0 -1
  167. package/dist/assets/apps-Dbw2Hcko.js +0 -2
  168. package/dist/assets/apps-h12II1us.js.map +0 -1
  169. package/dist/assets/arkade-Bw_4PZRG.js.map +0 -1
  170. package/dist/assets/backup-CdEzTq5C.js +0 -2
  171. package/dist/assets/backup-Chvy79SN.js.map +0 -1
  172. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js +0 -6
  173. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +0 -1
  174. package/dist/assets/bitcoindProvider-BvoRh0D5.js +0 -97
  175. package/dist/assets/bitcoindProvider-BvoRh0D5.js.map +0 -1
  176. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js +0 -6
  177. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +0 -1
  178. package/dist/assets/bitcoindevkit_bg-CRkZTSbO.wasm +0 -0
  179. package/dist/assets/buttons-BgoExb4E.js.map +0 -1
  180. package/dist/assets/buttons-DK2aAGat.js +0 -2
  181. package/dist/assets/endpoint-DarqblYE.js.map +0 -1
  182. package/dist/assets/errors-CAh6GLJZ.js.map +0 -1
  183. package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js +0 -6
  184. package/dist/assets/fileBytes-BLPZq9YU.js.map +0 -1
  185. package/dist/assets/fileBytes-BtIyoDF2.js +0 -2
  186. package/dist/assets/fileBytesIdb-D8mAK4pF.js +0 -2
  187. package/dist/assets/host-C0NMNQLl.js.map +0 -1
  188. package/dist/assets/hyperdhtRelay-1wzya_0L.js +0 -25
  189. package/dist/assets/hyperdhtRelay-1wzya_0L.js.map +0 -1
  190. package/dist/assets/hyperdhtRelay-Dz7pvcBA.js.map +0 -1
  191. package/dist/assets/irohWeb-caAj4Dms.js.map +0 -1
  192. package/dist/assets/joinTrace-D-fnt2p3.js +0 -2
  193. package/dist/assets/jsonOut-POtMBS_V.js +0 -16
  194. package/dist/assets/jsonOut-POtMBS_V.js.map +0 -1
  195. package/dist/assets/main-C6t5zrD5.js.map +0 -1
  196. package/dist/assets/mainline-DCuGUSZF.js.map +0 -1
  197. package/dist/assets/mints-BaOmx517.js +0 -2
  198. package/dist/assets/mints-j5XAOk4f.js.map +0 -1
  199. package/dist/assets/nwcProvider-PE0wli8n.js +0 -88
  200. package/dist/assets/nwcProvider-PE0wli8n.js.map +0 -1
  201. package/dist/assets/ownDid-C1R5Kd8q.js +0 -282
  202. package/dist/assets/ownDid-C1R5Kd8q.js.map +0 -1
  203. package/dist/assets/ownStatus-BoTf5WqQ.js.map +0 -1
  204. package/dist/assets/profiles-DszHjEJi.js.map +0 -1
  205. package/dist/assets/registry-Da-r6eC3.js.map +0 -1
  206. package/dist/assets/registry-zUZBSHYv.js +0 -2
  207. package/dist/assets/resolve-tUzh4lHh.js +0 -400
  208. package/dist/assets/resolve-tUzh4lHh.js.map +0 -1
  209. package/dist/assets/secretGuard-DCb1I0_B.js +0 -2
  210. package/dist/assets/server-C1jZZ61O.js.map +0 -1
  211. package/dist/assets/src-DJe-OYxd.js.map +0 -1
  212. package/dist/assets/sshForges-C9zTO72R.js +0 -261
  213. package/dist/assets/sshForges-C9zTO72R.js.map +0 -1
  214. package/dist/assets/storage-Bya5b2Xt.js.map +0 -1
  215. package/dist/assets/tree-store-N362nuzZ.js.map +0 -1
  216. package/dist/assets/usdt-DI51znt-.js.map +0 -1
  217. package/dist/assets/waitNotice-Cn0WJ-He.js.map +0 -1
  218. package/dist/assets/web-DwgdhfcY.js.map +0 -1
@@ -0,0 +1,581 @@
1
+ import { c as toBase64, d as utf8Decode, f as utf8Encode, i as fromBase64Url, l as toBase64Url, n as concatBytes, r as fromBase64, s as randomBytes } from "./bytes-C1DNGY18.js";
2
+ import { s as isPublicAddress } from "./domainProofs-BDNP1dIy.js";
3
+ import { S as verify, _ as identityFromSeed, o as measureRecords, v as identityFromSeedB64, x as sign, y as publicKeyFromZ32 } from "./pkarr-BQo4PcCg.js";
4
+ import { xsalsa20poly1305 } from "@noble/ciphers/salsa.js";
5
+ import { ed25519, x25519 } from "@noble/curves/ed25519.js";
6
+ import { sha256 } from "@noble/hashes/sha2.js";
7
+ import { hkdf } from "@noble/hashes/hkdf.js";
8
+ // ../core/src/crypto.ts
9
+ var NONCE_LENGTH = 24;
10
+ var KEY_LENGTH = 32;
11
+ function generateEncryptionKey() {
12
+ return randomBytes(KEY_LENGTH);
13
+ }
14
+ /**
15
+ * NaCl secretbox (XSalsa20-Poly1305). Wire format matches the Rust
16
+ * implementation in `apps/desktop/src/crypto.rs`: base64(nonce || box).
17
+ */
18
+ function encrypt(plaintext, key) {
19
+ if (key.length !== KEY_LENGTH) throw new Error("Invalid key length: expected 32 bytes");
20
+ const nonce = randomBytes(NONCE_LENGTH);
21
+ const box = xsalsa20poly1305(key, nonce).encrypt(utf8Encode(plaintext));
22
+ return toBase64(concatBytes(nonce, box));
23
+ }
24
+ /** The length of what `encrypt` returns for a plaintext of this many UTF-8 bytes: base64 of nonce, box and 16-byte tag. */
25
+ function sealedLength(plaintextBytes) {
26
+ return 4 * Math.ceil((40 + plaintextBytes) / 3);
27
+ }
28
+ function decrypt(encoded, key) {
29
+ if (key.length !== KEY_LENGTH) throw new Error("Invalid key length: expected 32 bytes");
30
+ const combined = fromBase64(encoded);
31
+ if (combined.length < 25) throw new Error("Invalid ciphertext: too short");
32
+ const nonce = combined.subarray(0, NONCE_LENGTH);
33
+ const box = combined.subarray(NONCE_LENGTH);
34
+ return utf8Decode(xsalsa20poly1305(key, nonce).decrypt(box));
35
+ }
36
+ function tryDecrypt(encoded, key) {
37
+ try {
38
+ return decrypt(encoded, key);
39
+ } catch {
40
+ return null;
41
+ }
42
+ }
43
+ // ../core/src/storeForward.ts
44
+ /**
45
+ * Store-and-forward for an away contact (WISP 404 draft, `hold/1`).
46
+ *
47
+ * What a person sends while the contact is away is sealed into a *bundle* (signed by the sender's
48
+ * participation key, then encrypted to a key only the two of them can derive), put in the sender's
49
+ * own storage (WISP 1000), and named in a *manifest* the storage also holds. A small signed, encrypted
50
+ * *pointer* record on a per-link Pkarr key tells the contact where the manifest is (a URL that expires)
51
+ * and which of the contact's own bundles have been received. Storage and relays see ciphertext, sizes
52
+ * and timing only. Nothing here promises forward secrecy or retention beyond the bounds below.
53
+ */
54
+ var HOLD_CAPABILITY = "hold/1";
55
+ var HOLD_LIMITS = {
56
+ /** One bundle, ciphertext and header included: a picture, not a video. */
57
+ maxBundleBytes: 8388608,
58
+ /** All bundles held for one contact at once. */
59
+ maxMailboxBytes: 67108864,
60
+ maxMailboxBundles: 64,
61
+ /** A bundle not picked up by then is dropped by its sender. The longest a presigned URL lives, too. */
62
+ ttlMs: 6048e5,
63
+ maxTextBytes: 16384,
64
+ maxPaymentRequestBytes: 65536,
65
+ maxManifestBytes: 65536,
66
+ /**
67
+ * How far past one lifetime from now an expiry may reach by the reader's clock: the sender's clock may be ahead, and
68
+ * a day covers any clock that is merely wrong. Nothing else about a pointer or a bundle is held against this clock.
69
+ */
70
+ clockSkewMs: 864e5
71
+ };
72
+ /**
73
+ * How far before its own clock a sender dates its pointer and its manifest, and ends the lifetimes it gives. A reader
74
+ * refuses nothing for those dates: `rev` orders pointers and `seq` orders items, both kept by the reader. Apps up to
75
+ * 1.0.2 refuse a pointer or a manifest dated more than a minute past their clock, and an expiry more than a minute
76
+ * past one lifetime from now, each without a word: the items of a sender whose clock ran two minutes fast were never
77
+ * fetched. Dated back, a sender up to about eleven minutes ahead is read by them.
78
+ */
79
+ var HOLD_DATED_BACK_MS = 6e5;
80
+ var KINDS = [
81
+ "text",
82
+ "file",
83
+ "pay-req",
84
+ "manifest"
85
+ ];
86
+ var WIRE_ID = /^[A-Za-z0-9_-]{8,64}$/;
87
+ var MAILBOX = /^[A-Za-z0-9_-]{22}$/;
88
+ var SIG = /^[A-Za-z0-9_-]{86}$/;
89
+ var MAGIC = utf8Encode("GHLD");
90
+ var VERSION = 1;
91
+ var NONCE = 24;
92
+ /** A bundle sealed by the chat's ratchet (WISP 4xx § Held items). */
93
+ var RATCHETED = 2;
94
+ /** Why a bundle, manifest or pointer was refused. Never a reason to trust it a little. */
95
+ var HoldRefusedError = class extends Error {
96
+ reason;
97
+ /** The bytes the chat's ratchet opened, when it opened them before the item was refused: the caller commits them. */
98
+ ratcheted;
99
+ constructor(reason, message) {
100
+ super(message);
101
+ this.reason = reason;
102
+ }
103
+ };
104
+ var bodyDigest = (body) => toBase64Url(sha256(body));
105
+ var newMailbox = () => toBase64Url(randomBytes(16)).slice(0, 22);
106
+ /**
107
+ * Everything derived once per link for this feature: my pointer key, the contact's pointer address and
108
+ * the key that seals bundles and pointers between the two participation keys. Needs a pinned contact.
109
+ */
110
+ var HoldKeys = class {
111
+ from;
112
+ to;
113
+ me;
114
+ peer;
115
+ /** Publishes my pointer. */
116
+ identity;
117
+ /** Where the contact publishes its pointer. */
118
+ peerAddress;
119
+ seed;
120
+ sealKey;
121
+ constructor(params, participationSeedB64, peerKey) {
122
+ this.from = identityFromSeedB64(params.seedB64).pubKeyZ32;
123
+ this.to = params.peerPubKeyZ32;
124
+ const mine = identityFromSeedB64(participationSeedB64);
125
+ this.seed = mine.seed;
126
+ this.me = mine.pubKeyZ32;
127
+ this.peer = peerKey;
128
+ const secret = fromBase64Url(params.encKeyB64);
129
+ const context = JSON.stringify(["ghostly-hold/1", [this.from, this.to].sort()]);
130
+ const derive = (label) => hkdf(sha256, secret, utf8Encode(context), utf8Encode(label), 32);
131
+ this.identity = identityFromSeed(derive(`pointer:${this.from}`));
132
+ this.peerAddress = identityFromSeed(derive(`pointer:${this.to}`)).pubKeyZ32;
133
+ const shared = x25519.getSharedSecret(ed25519.utils.toMontgomerySecret(this.seed), ed25519.utils.toMontgomery(publicKeyFromZ32(peerKey)));
134
+ this.sealKey = hkdf(sha256, shared, derive("envelope"), utf8Encode("ghostly-hold-envelope/1"), 32);
135
+ }
136
+ /** Seals one item for the contact: signed with my participation key, encrypted to our shared key. */
137
+ seal(item, body) {
138
+ const nonce = randomBytes(NONCE);
139
+ const box = xsalsa20poly1305(this.sealKey, nonce).encrypt(this.inner(item, body));
140
+ return concatBytes(MAGIC, new Uint8Array([VERSION]), nonce, box);
141
+ }
142
+ /**
143
+ * The same item as a version-2 bundle (WISP 4xx § Held items): the same plaintext, sealed by the chat's ratchet
144
+ * (`seal`, which saves the ratchet's state before it returns), so the bundle can be uploaded once this returns.
145
+ */
146
+ async sealRatcheted(item, body, seal) {
147
+ return concatBytes(MAGIC, new Uint8Array([RATCHETED]), await seal(this.inner(item, body)));
148
+ }
149
+ /** What a bundle seals: the header's length, the signed header, the body. */
150
+ inner(item, body) {
151
+ const fields = [
152
+ VERSION,
153
+ this.from,
154
+ this.to,
155
+ this.me,
156
+ this.peer,
157
+ item.mailbox,
158
+ item.seq,
159
+ item.id,
160
+ item.ts,
161
+ item.kind,
162
+ item.meta ?? null,
163
+ bodyDigest(body),
164
+ item.expires
165
+ ];
166
+ const signature = toBase64Url(sign(utf8Encode(JSON.stringify(["ghostly-hold-bundle", fields])), this.seed));
167
+ const header = utf8Encode(JSON.stringify([fields, signature]));
168
+ const length = /* @__PURE__ */ new Uint8Array(4);
169
+ new DataView(length.buffer).setUint32(0, header.length);
170
+ return concatBytes(length, header, body);
171
+ }
172
+ /**
173
+ * Opens a bundle the contact sealed for me. Everything is checked before anything is returned: the
174
+ * authenticated encryption, the header's shape, that it names this link, this contact and me, the
175
+ * signature, the body digest and the limits of its kind. `loopback`: see `isHoldUrl`.
176
+ */
177
+ /**
178
+ * `ratchet`: opens a version-2 bundle's sealed bytes (WISP 4xx), without keeping anything; absent, one is from a newer
179
+ * Ghostly. `refusePlain`: a ratcheted item from this contact opened here, so a version-1 item other than the manifest is
180
+ * refused (WISP 4xx § Downgrade). `ratcheted` in the result: the bytes the ratchet opened, for the caller to commit once
181
+ * the item is stored.
182
+ */
183
+ open(bytes, expect = {}) {
184
+ const now = expect.now ?? Date.now();
185
+ if (bytes.length > (expect.maxBytes ?? HOLD_LIMITS.maxBundleBytes)) throw new HoldRefusedError("size", "The held item is larger than allowed");
186
+ if (bytes.length < MAGIC.length + 1 + 16 + 4 || !MAGIC.every((b, i) => bytes[i] === b)) throw new HoldRefusedError("format", "Not a held item");
187
+ const version = bytes[MAGIC.length];
188
+ if (version !== VERSION && (version !== RATCHETED || !expect.ratchet)) throw new HoldRefusedError("format", "Held item from a newer Ghostly");
189
+ let plain, ratcheted;
190
+ if (version === RATCHETED) {
191
+ ratcheted = bytes.subarray(MAGIC.length + 1);
192
+ try {
193
+ plain = expect.ratchet(ratcheted);
194
+ } catch {
195
+ plain = null;
196
+ }
197
+ if (!plain) throw new HoldRefusedError("tampered", "The held item was changed, is not for this chat, or was opened already");
198
+ } else {
199
+ if (bytes.length < MAGIC.length + 1 + NONCE + 16 + 4) throw new HoldRefusedError("format", "Not a held item");
200
+ try {
201
+ plain = xsalsa20poly1305(this.sealKey, bytes.subarray(MAGIC.length + 1, MAGIC.length + 1 + NONCE)).decrypt(bytes.subarray(MAGIC.length + 1 + NONCE));
202
+ } catch {
203
+ throw new HoldRefusedError("tampered", "The held item was changed or is not for this chat");
204
+ }
205
+ }
206
+ try {
207
+ return this.read(plain, ratcheted, expect, now);
208
+ } catch (error) {
209
+ if (error instanceof HoldRefusedError && ratcheted) error.ratcheted = ratcheted;
210
+ throw error;
211
+ }
212
+ }
213
+ /** The checks of `open` once the bundle is decrypted. */
214
+ read(plain, ratcheted, expect, now) {
215
+ if (plain.length < 4) throw new HoldRefusedError("format", "Not a held item");
216
+ const headerLength = new DataView(plain.buffer, plain.byteOffset, 4).getUint32(0);
217
+ if (headerLength > 131072 || 4 + headerLength > plain.length) throw new HoldRefusedError("format", "Not a held item");
218
+ let parsed;
219
+ try {
220
+ parsed = JSON.parse(utf8Decode(plain.subarray(4, 4 + headerLength)));
221
+ } catch {
222
+ throw new HoldRefusedError("format", "Not a held item");
223
+ }
224
+ if (!Array.isArray(parsed) || parsed.length !== 2 || !Array.isArray(parsed[0]) || parsed[0].length !== 13 || typeof parsed[1] !== "string" || !SIG.test(parsed[1])) throw new HoldRefusedError("format", "Not a held item");
225
+ const [fields, signature] = parsed;
226
+ const [v, from, to, author, recipient, mailbox, seq, id, ts, kind, meta, digest, expires] = fields;
227
+ if (v !== VERSION || typeof from !== "string" || typeof to !== "string" || typeof author !== "string" || typeof recipient !== "string" || typeof mailbox !== "string" || !MAILBOX.test(mailbox) || !Number.isSafeInteger(seq) || seq < 0 || typeof id !== "string" || !WIRE_ID.test(id) || !Number.isSafeInteger(ts) || ts <= 0 || typeof kind !== "string" || !KINDS.includes(kind) || typeof digest !== "string" || !Number.isSafeInteger(expires)) throw new HoldRefusedError("format", "Not a held item");
228
+ if (from !== this.to || to !== this.from || recipient !== this.me) throw new HoldRefusedError("not-for-me", "The held item is for another chat");
229
+ if (author !== this.peer) throw new HoldRefusedError("author", "The held item was not signed by this contact");
230
+ if (expect.mailbox && mailbox !== expect.mailbox) throw new HoldRefusedError("not-for-me", "The held item is from another mailbox");
231
+ let valid;
232
+ try {
233
+ valid = verify(fromBase64Url(signature), utf8Encode(JSON.stringify(["ghostly-hold-bundle", fields])), publicKeyFromZ32(author));
234
+ } catch {
235
+ valid = false;
236
+ }
237
+ if (!valid) throw new HoldRefusedError("signature", "The held item's signature does not check out");
238
+ const body = plain.subarray(4 + headerLength);
239
+ if (bodyDigest(body) !== digest) throw new HoldRefusedError("digest", "The held item's content does not match its header");
240
+ if (expires <= ts || expires > now + HOLD_LIMITS.ttlMs + HOLD_LIMITS.clockSkewMs) throw new HoldRefusedError("limits", "The held item's lifetime is out of bounds");
241
+ const header = {
242
+ v: 1,
243
+ from,
244
+ to,
245
+ author,
246
+ recipient,
247
+ mailbox,
248
+ seq,
249
+ id,
250
+ ts,
251
+ kind,
252
+ meta,
253
+ digest,
254
+ expires
255
+ };
256
+ if (!ratcheted && expect.refusePlain && kind !== "manifest") throw new HoldRefusedError("plain", "The held item was sealed without forward secrecy, which this chat no longer takes");
257
+ checkKind(header, body, expect.loopback);
258
+ return {
259
+ header,
260
+ body,
261
+ ...ratcheted && { ratcheted }
262
+ };
263
+ }
264
+ /** My pointer, as records to publish under `identity`. Throws when it cannot fit a packet. */
265
+ pointerRecords(pointer, now = Date.now()) {
266
+ const body = [
267
+ VERSION,
268
+ pointer.rev,
269
+ pointer.issued,
270
+ pointer.expires,
271
+ pointer.manifestUrl,
272
+ pointer.top,
273
+ pointer.ack,
274
+ pointer.count,
275
+ pointer.bytes,
276
+ pointer.refused.slice(-32)
277
+ ];
278
+ const signature = toBase64Url(sign(utf8Encode(JSON.stringify([
279
+ "ghostly-hold-pointer",
280
+ this.from,
281
+ this.to,
282
+ body
283
+ ])), this.seed));
284
+ const ttl = Math.min(86400, Math.max(60, Math.ceil((pointer.expires - now) / 1e3)));
285
+ const records = [{
286
+ label: "_hold",
287
+ value: encrypt(JSON.stringify([body, signature]), this.sealKey),
288
+ ttl
289
+ }];
290
+ if (measureRecords(this.identity.pubKeyZ32, records) > 1e3) throw new Error("The storage address is too long for a DHT packet. Use a shorter endpoint or prefix.");
291
+ return records;
292
+ }
293
+ /**
294
+ * The contact's pointer out of its packet, or null when the packet is not one of its pointers. Its `issued` is the
295
+ * contact's clock and refuses nothing: an older pointer cannot take a newer one's place because of `rev`. The
296
+ * manifest's address is held to what an item's is (`isHoldUrl`): it is fetched as soon as the pointer is read.
297
+ */
298
+ readPointer(packet, loopback = false) {
299
+ if (packet.pubKeyZ32 !== this.peerAddress || measureRecords(packet.pubKeyZ32, packet.records) > 1e3) return null;
300
+ const records = packet.records.filter((r) => r.label === "_hold");
301
+ if (records.length !== 1) return null;
302
+ const plain = tryDecrypt(records[0].value, this.sealKey);
303
+ if (!plain) return null;
304
+ let parsed;
305
+ try {
306
+ parsed = JSON.parse(plain);
307
+ } catch {
308
+ return null;
309
+ }
310
+ if (!Array.isArray(parsed) || parsed.length !== 2 || !Array.isArray(parsed[0]) || parsed[0].length !== 9 && parsed[0].length !== 10 || typeof parsed[1] !== "string" || !SIG.test(parsed[1])) return null;
311
+ const [body, signature] = parsed;
312
+ const [v, rev, issued, expires, manifestUrl, top, ack, count, bytes, refused = []] = body;
313
+ if (v !== VERSION || ![
314
+ rev,
315
+ issued,
316
+ expires,
317
+ top,
318
+ ack,
319
+ count,
320
+ bytes
321
+ ].every((n) => Number.isSafeInteger(n) && n >= 0) || manifestUrl !== null && !isHoldUrl(manifestUrl, loopback) || !Array.isArray(refused) || refused.length > 32 || !refused.every((n) => Number.isSafeInteger(n) && n > 0)) return null;
322
+ try {
323
+ if (!verify(fromBase64Url(signature), utf8Encode(JSON.stringify([
324
+ "ghostly-hold-pointer",
325
+ this.to,
326
+ this.from,
327
+ body
328
+ ])), publicKeyFromZ32(this.peer))) return null;
329
+ } catch {
330
+ return null;
331
+ }
332
+ return {
333
+ rev,
334
+ issued,
335
+ expires,
336
+ manifestUrl,
337
+ top,
338
+ ack,
339
+ count,
340
+ bytes,
341
+ refused
342
+ };
343
+ }
344
+ };
345
+ /** Names only a local network answers (RFC 6762, RFC 8375, ICANN's .internal, and the usual router ones). */
346
+ var LOCAL_SUFFIXES = [
347
+ "localhost",
348
+ "local",
349
+ "internal",
350
+ "lan",
351
+ "home",
352
+ "home.arpa",
353
+ "localdomain",
354
+ "intranet",
355
+ "corp"
356
+ ];
357
+ /**
358
+ * A URL a bundle or manifest may be fetched from. The contact chose it and this device fetches it on its own, so it
359
+ * is HTTPS, without a user or password, at a public name or a public IPv4 address: never this machine or its network.
360
+ * A name with no dot or under a local suffix is a local one. A public name may still resolve to a local address:
361
+ * where the host can resolve, its `fetch` refuses that too (the CLI's, packages/cli/src/runtime/holdFetch.ts, and
362
+ * Desktop's, apps/desktop/src/hold_fetch.rs).
363
+ * `loopback` adds plain HTTP to this machine, for a test against a local server; no shipped app passes it.
364
+ */
365
+ function isHoldUrl(value, loopback = false) {
366
+ if (typeof value !== "string" || value.length > 2048) return false;
367
+ let url;
368
+ try {
369
+ url = new URL(value);
370
+ } catch {
371
+ return false;
372
+ }
373
+ if (url.username || url.password) return false;
374
+ const host = url.hostname.toLowerCase().replace(/\.$/, "");
375
+ if (loopback && url.protocol === "http:" && [
376
+ "localhost",
377
+ "127.0.0.1",
378
+ "[::1]"
379
+ ].includes(host)) return true;
380
+ if (url.protocol !== "https:" || !host.includes(".") || host.startsWith("[") || LOCAL_SUFFIXES.some((s) => host === s || host.endsWith(`.${s}`))) return false;
381
+ return !/^\d+\.\d+\.\d+\.\d+$/.test(host) || isPublicAddress(Uint8Array.from(host.split("."), Number));
382
+ }
383
+ /** The limits of each kind, on the way in. */
384
+ function checkKind(header, body, loopback = false) {
385
+ const bad = (message) => new HoldRefusedError("limits", message);
386
+ switch (header.kind) {
387
+ case "text":
388
+ if (body.length > HOLD_LIMITS.maxTextBytes) throw bad("The held text is too long");
389
+ try {
390
+ utf8Decode(body);
391
+ } catch {
392
+ throw bad("The held text is not text");
393
+ }
394
+ return;
395
+ case "pay-req":
396
+ if (body.length > HOLD_LIMITS.maxPaymentRequestBytes) throw bad("The held payment request is too large");
397
+ return;
398
+ case "file": {
399
+ const meta = header.meta;
400
+ if (!meta || typeof meta !== "object" || typeof meta.name !== "string" || meta.name.length > 255 || typeof meta.mime !== "string" || meta.mime.length > 255 || meta.size !== body.length) throw bad("The held file does not match its description");
401
+ return;
402
+ }
403
+ case "manifest":
404
+ if (body.length !== 0) throw bad("A manifest carries no body");
405
+ readManifest(header.meta, loopback);
406
+ return;
407
+ }
408
+ }
409
+ /** The entries of a manifest, checked: strictly increasing sequences, bounded sizes, fetchable URLs. */
410
+ function readManifest(meta, loopback = false) {
411
+ const bad = (message) => new HoldRefusedError("limits", message);
412
+ const entries = meta?.entries;
413
+ if (!Array.isArray(entries) || entries.length > HOLD_LIMITS.maxMailboxBundles) throw bad("The manifest lists too many items");
414
+ let last = 0, total = 0;
415
+ const out = [];
416
+ for (const entry of entries) {
417
+ if (!Array.isArray(entry) || entry.length !== 6) throw bad("The manifest is malformed");
418
+ const [seq, id, kind, bytes, url, expires] = entry;
419
+ if (!Number.isSafeInteger(seq) || seq <= last || typeof id !== "string" || !WIRE_ID.test(id) || typeof kind !== "string" || !KINDS.includes(kind) || kind === "manifest" || !Number.isSafeInteger(bytes) || bytes < 0 || bytes > HOLD_LIMITS.maxBundleBytes || !isHoldUrl(url, loopback) || !Number.isSafeInteger(expires)) throw bad("The manifest is malformed");
420
+ last = seq;
421
+ total += bytes;
422
+ if (total > HOLD_LIMITS.maxMailboxBytes) throw bad("The manifest lists more than a mailbox may hold");
423
+ out.push([
424
+ seq,
425
+ id,
426
+ kind,
427
+ bytes,
428
+ url,
429
+ expires
430
+ ]);
431
+ }
432
+ return out;
433
+ }
434
+ // ../core/src/pairedTransports.ts
435
+ var TRANSPORTS = [
436
+ "iroh/1",
437
+ "hyperdht/1",
438
+ "webrtc/1"
439
+ ];
440
+ function irohRelayUrl(value, spelling = "dotted") {
441
+ let url;
442
+ try {
443
+ url = new URL(value);
444
+ } catch {
445
+ return value;
446
+ }
447
+ const host = url.hostname, name = host.replace(/\.$/, "");
448
+ if (!name.includes(".") && name !== "localhost") return value;
449
+ if (name.startsWith("[") || /^\d+(\.\d+){3}$/.test(name)) return value;
450
+ const wanted = spelling === "dotted" && /(^|\.)iroh\.link$/.test(name) ? `${name}.` : name;
451
+ if (wanted === host) return value;
452
+ url.hostname = wanted;
453
+ return url.href;
454
+ }
455
+ /** An Iroh descriptor with its relay in one spelling (`irohRelayUrl`); anything else as it is. */
456
+ function irohDescriptor(descriptor, spelling = "dotted") {
457
+ const relay = descriptor?.relay;
458
+ if (typeof relay !== "string") return descriptor;
459
+ const canonical = irohRelayUrl(relay, spelling);
460
+ return canonical === relay ? descriptor : {
461
+ ...descriptor,
462
+ relay: canonical
463
+ };
464
+ }
465
+ /**
466
+ * A relay server's URL, short: https, or wss for a browser's relay; plain http or ws only on this machine's loopback,
467
+ * as a test relay is (the same rule as the relay settings).
468
+ */
469
+ var RELAY_URL = /^((https|wss):\/\/[^\s]{1,120}|(http|ws):\/\/(127\.0\.0\.1|localhost|\[::1\])(:\d{1,5})?(\/[^\s]{0,100})?)$/;
470
+ /**
471
+ * A relay URL with more than its server's address in it: a login, a query or a fragment, which no relay setting takes
472
+ * (irohWeb.ts `irohRelayProblem`, hyperdhtRelay.ts `hyperdhtRelayProblem`). An older app named its HyperDHT relay as
473
+ * set, with them; such a descriptor is not dialed or kept, and the rest of what the contact told still is.
474
+ */
475
+ var RELAY_WITH_SECRETS = /^[a-z]+:\/\/[^/?#]*@|[?#]/i;
476
+ /** A relay URL a descriptor may name: `RELAY_URL`, with nothing but the server's address in it. */
477
+ var relayUrl = (value) => typeof value === "string" && RELAY_URL.test(value) && !RELAY_WITH_SECRETS.test(value);
478
+ /** `RELAY_URL` at any length. */
479
+ var RELAY_URL_ANY_LENGTH = /^((https|wss):\/\/[^\s]+|(http|ws):\/\/(127\.0\.0\.1|localhost|\[::1\])(:\d{1,5})?(\/[^\s]*)?)$/;
480
+ /**
481
+ * A relay URL `relayUrl` refuses for its length alone (past 120 characters, a loopback path past 100): a relay setting
482
+ * asks for a shorter one, where "not a relay address" sent the person looking for a typo in it.
483
+ */
484
+ var relayUrlTooLong = (value) => !relayUrl(value) && !RELAY_WITH_SECRETS.test(value) && RELAY_URL_ANY_LENGTH.test(value);
485
+ /**
486
+ * Whether an Iroh endpoint may dial a contact through the relay its descriptor names (none: a direct address alone).
487
+ * The contact chose that relay and this device opens it on its own, again on each redial, so it is held to what a held
488
+ * item's address is (`isHoldUrl`): https at a public name or a public address, never this machine or its network.
489
+ * One of the endpoint's own relays (`own`: the person's settings, a private network's or a test's) is dialled as well,
490
+ * in either spelling: this device opens it anyway.
491
+ */
492
+ function dialableIrohRelay(relay, own) {
493
+ if (relay === null || relay === void 0) return true;
494
+ if (!relayUrl(relay)) return false;
495
+ const same = (a, b) => {
496
+ try {
497
+ return new URL(irohRelayUrl(a, "plain")).href === new URL(irohRelayUrl(b, "plain")).href;
498
+ } catch {
499
+ return false;
500
+ }
501
+ };
502
+ return own.some((mine) => same(mine, relay)) || isHoldUrl(relay);
503
+ }
504
+ var HEX_KEY = /^[0-9a-f]{64}$/;
505
+ /** An Iroh direct address as the adapters parse it: an IPv4 or bracketed IPv6 address and its port. */
506
+ var SOCKET_ADDRESS = /^(\d{1,3}(\.\d{1,3}){3}|\[[0-9A-Fa-f:.]{2,45}(%[A-Za-z0-9._-]{1,16})?\]):\d{1,5}$/;
507
+ var MAX_ADDRESSES = 8;
508
+ /**
509
+ * A contact's native descriptors as it tells them on a session (`paired-policy`, `paired-adapters`) or as this app
510
+ * kept them: only what the adapters dial, each field in the shape its adapter makes. The keys are 64 hex characters,
511
+ * a relay passes `relayUrl` (the rule its capability record is read by), an Iroh descriptor lists at most eight
512
+ * socket addresses. A descriptor that is anything else is left out, as one the contact never told; a field this app
513
+ * does not know is not kept.
514
+ */
515
+ function checkedDescriptors(value) {
516
+ const out = {};
517
+ if (!value || typeof value !== "object" || Array.isArray(value)) return out;
518
+ const raw = value;
519
+ const relayed = (v) => v === void 0 || typeof v === "boolean";
520
+ const iroh = raw["iroh/1"];
521
+ if (iroh && typeof iroh === "object" && typeof iroh.id === "string" && HEX_KEY.test(iroh.id) && (iroh.relay === void 0 || iroh.relay === null || relayUrl(iroh.relay)) && relayed(iroh.relayed) && Array.isArray(iroh.addresses) && iroh.addresses.length <= MAX_ADDRESSES && iroh.addresses.every((a) => typeof a === "string" && SOCKET_ADDRESS.test(a))) out["iroh/1"] = {
522
+ id: iroh.id,
523
+ relay: iroh.relay ?? null,
524
+ addresses: [...iroh.addresses],
525
+ ...iroh.relayed !== void 0 ? { relayed: iroh.relayed } : {}
526
+ };
527
+ const hyper = raw["hyperdht/1"];
528
+ if (hyper && typeof hyper === "object" && typeof hyper.publicKey === "string" && HEX_KEY.test(hyper.publicKey) && (hyper.relay === void 0 || relayUrl(hyper.relay)) && relayed(hyper.relayed)) out["hyperdht/1"] = {
529
+ publicKey: hyper.publicKey,
530
+ ...hyper.relay !== void 0 ? { relay: hyper.relay } : {},
531
+ ...hyper.relayed !== void 0 ? { relayed: hyper.relayed } : {}
532
+ };
533
+ return out;
534
+ }
535
+ /**
536
+ * Relay only (WISP 100, "Relayed"): the transport reaches this contact only through a relay server, never
537
+ * directly. A descriptor says so with `relayed: true`, and an Iroh descriptor with no direct address is relayed
538
+ * too (a browser's, WISP 102). Either side being relay only makes the whole path relayed. Both sides hold both
539
+ * descriptors after the exchange, so they agree, and the rank stays symmetric.
540
+ */
541
+ function relayedTransports(local, remote) {
542
+ const relayOnly = (transport, descriptor) => {
543
+ if (!descriptor || typeof descriptor !== "object") return false;
544
+ const d = descriptor;
545
+ return d.relayed === true || transport === "iroh/1" && Array.isArray(d.addresses) && d.addresses.length === 0;
546
+ };
547
+ return ["iroh/1", "hyperdht/1"].filter((t) => relayOnly(t, local[t]) || relayOnly(t, remote[t]));
548
+ }
549
+ /** Symmetric rank sum; the fixed order breaks ties deterministically. Neither
550
+ * a remote list nor a preference can add an unavailable local adapter. A
551
+ * relayed transport ranks after every direct one: it is where a failed direct
552
+ * path goes, never ahead of one that works. Iroh through its relay is the
553
+ * exception (WISP 100, revision 2026-11-08): it comes back almost at once after
554
+ * the app was away, and a browser's Iroh is never anything else. */
555
+ function rankTransports(local, remote, relayed = []) {
556
+ const penalty = (t) => t !== "iroh/1" && relayed.includes(t) ? 1 : 0;
557
+ return TRANSPORTS.filter((t) => local.includes(t) && remote.includes(t)).sort((a, b) => penalty(a) - penalty(b) || local.indexOf(a) + remote.indexOf(a) - (local.indexOf(b) + remote.indexOf(b)) || TRANSPORTS.indexOf(a) - TRANSPORTS.indexOf(b));
558
+ }
559
+ /**
560
+ * What a chat prefers when nobody chose (Automatic): Iroh where the app has it, then WebRTC, then HyperDHT (WISP 100,
561
+ * revision 2026-11-08). Every app puts Iroh first, so the rank sum of two apps that both run it puts it first on both
562
+ * sides. With nothing at all, WebRTC, which the offer then leaves out.
563
+ * With Fallback off the chat may use only that one transport, and nothing moves it off a relayed Iroh then: WebRTC
564
+ * where the app has it, else the first transport it has (a Linux Desktop: WebKitGTK has no WebRTC), as before.
565
+ */
566
+ var AUTOMATIC_ORDER = [
567
+ "iroh/1",
568
+ "webrtc/1",
569
+ "hyperdht/1"
570
+ ];
571
+ function automaticTransport(available, fallback = true) {
572
+ if (!fallback) return available.includes("webrtc/1") ? "webrtc/1" : TRANSPORTS.find((t) => available.includes(t)) ?? "webrtc/1";
573
+ return AUTOMATIC_ORDER.find((t) => available.includes(t)) ?? "webrtc/1";
574
+ }
575
+ function transportOrder(available, preferred, fallback) {
576
+ const rest = TRANSPORTS.filter((t) => available.includes(t) && t !== preferred);
577
+ return [...available.includes(preferred) ? [preferred] : [], ...fallback ? rest : []];
578
+ }
579
+ export { generateEncryptionKey as C, encrypt as S, tryDecrypt as T, HoldKeys as _, checkedDescriptors as a, newMailbox as b, irohRelayUrl as c, relayUrlTooLong as d, relayedTransports as f, HOLD_LIMITS as g, HOLD_DATED_BACK_MS as h, automaticTransport as i, rankTransports as l, HOLD_CAPABILITY as m, RELAY_WITH_SECRETS as n, dialableIrohRelay as o, transportOrder as p, TRANSPORTS as r, irohDescriptor as s, RELAY_URL as t, relayUrl as u, HoldRefusedError as v, sealedLength as w, readManifest as x, isHoldUrl as y };
580
+
581
+ //# sourceMappingURL=pairedTransports-BKmvlKz1.js.map