@ghostlytools/cli 1.12.1 → 1.13.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 (91) hide show
  1. package/README.md +8 -7
  2. package/dist/assets/{api-jRUXnBdX.js → api-DF36rBJK.js} +2 -2
  3. package/dist/assets/{api-BwEgbvvK.js → api-Dnq86JAA.js} +139 -41
  4. package/dist/assets/api-Dnq86JAA.js.map +1 -0
  5. package/dist/assets/{apiKit-BlsNk-Cx.js → apiKit-nLK4jeTq.js} +3 -3
  6. package/dist/assets/{apiKit-BlsNk-Cx.js.map → apiKit-nLK4jeTq.js.map} +1 -1
  7. package/dist/assets/{appFetch-CW9fJPHh.js → appFetch-wqBWi3Ry.js} +2 -2
  8. package/dist/assets/{appFetch-CW9fJPHh.js.map → appFetch-wqBWi3Ry.js.map} +1 -1
  9. package/dist/assets/{apps-CL8TXHhu.js → apps-DBVhKpfe.js} +10 -10
  10. package/dist/assets/apps-DBVhKpfe.js.map +1 -0
  11. package/dist/assets/{apps-BcG4u6SM.js → apps-nLtyhC2f.js} +1 -1
  12. package/dist/assets/{backup-BA41EDvh.js → backup-Bczllmzf.js} +4 -4
  13. package/dist/assets/{backup-BA41EDvh.js.map → backup-Bczllmzf.js.map} +1 -1
  14. package/dist/assets/{backup-xZfV-ytw.js → backup-D6s0LQdg.js} +1 -1
  15. package/dist/assets/{bitcoind-Dh7n9amb.js → bitcoind-DML_-Xbv.js} +2 -2
  16. package/dist/assets/{bitcoind-Dh7n9amb.js.map → bitcoind-DML_-Xbv.js.map} +1 -1
  17. package/dist/assets/{buttons-SH1tNRh7.js → buttons-B3C3vdhH.js} +30 -9
  18. package/dist/assets/buttons-B3C3vdhH.js.map +1 -0
  19. package/dist/assets/buttons-DaY5FYlV.js +1 -0
  20. package/dist/assets/{client-DGS-atRu.js → client-B7jRrSnb.js} +3 -3
  21. package/dist/assets/{client-DGS-atRu.js.map → client-B7jRrSnb.js.map} +1 -1
  22. package/dist/assets/{domainProofs-BDNP1dIy.js → domainProofs-b3Y1Gj9g.js} +6 -2
  23. package/dist/assets/{domainProofs-BDNP1dIy.js.map → domainProofs-b3Y1Gj9g.js.map} +1 -1
  24. package/dist/assets/{errors-DDLFO4Gf.js → errors-JVJsO8Iu.js} +18 -2
  25. package/dist/assets/errors-JVJsO8Iu.js.map +1 -0
  26. package/dist/assets/{fixedHosts-CPSsGOI2.js → fixedHosts-H3i6o9Iy.js} +2 -2
  27. package/dist/assets/{fixedHosts-CPSsGOI2.js.map → fixedHosts-H3i6o9Iy.js.map} +1 -1
  28. package/dist/assets/{ghostly_iroh_web-DIj5xGmR.js → ghostly_iroh_web-9VOwZcJQ.js} +30 -35
  29. package/dist/assets/ghostly_iroh_web-9VOwZcJQ.js.map +1 -0
  30. package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
  31. package/dist/assets/{groupMeta-DxuJzko_.js → groupMeta--fxSh792.js} +165 -20
  32. package/dist/assets/groupMeta--fxSh792.js.map +1 -0
  33. package/dist/assets/{host-BxM-HMr0.js → host-CGzVFfMz.js} +211 -58
  34. package/dist/assets/host-CGzVFfMz.js.map +1 -0
  35. package/dist/assets/{hyperdhtRelay-bjNGacf5.js → hyperdhtRelay-B4_wdCtx.js} +2 -2
  36. package/dist/assets/{hyperdhtRelay-bjNGacf5.js.map → hyperdhtRelay-B4_wdCtx.js.map} +1 -1
  37. package/dist/assets/{hyperdhtRelay-DLUiwfnt.js → hyperdhtRelay-Ce-gWsRY.js} +2 -2
  38. package/dist/assets/{hyperdhtRelay-DLUiwfnt.js.map → hyperdhtRelay-Ce-gWsRY.js.map} +1 -1
  39. package/dist/assets/{irohWeb-CbnGtUo6.js → irohWeb-Dp1i8v6n.js} +13 -12
  40. package/dist/assets/irohWeb-Dp1i8v6n.js.map +1 -0
  41. package/dist/assets/{main-CwTaepxR.js → main-C8J53SwH.js} +68 -63
  42. package/dist/assets/main-C8J53SwH.js.map +1 -0
  43. package/dist/assets/{mainline-CVrd0C1n.js → mainline-DY95WbuK.js} +2 -2
  44. package/dist/assets/{mainline-CVrd0C1n.js.map → mainline-DY95WbuK.js.map} +1 -1
  45. package/dist/assets/{ownDid-DY3rYqDI.js → ownDid-oa-T2vmZ.js} +9 -5
  46. package/dist/assets/ownDid-oa-T2vmZ.js.map +1 -0
  47. package/dist/assets/{ownStatus-DtzIllg2.js → ownStatus-Bc08eNJY.js} +7 -6
  48. package/dist/assets/ownStatus-Bc08eNJY.js.map +1 -0
  49. package/dist/assets/{pairedTransports-BKmvlKz1.js → pairedTransports-Dppn8lUN.js} +3 -3
  50. package/dist/assets/pairedTransports-Dppn8lUN.js.map +1 -0
  51. package/dist/assets/{profiles-BOYGlmu2.js → profiles-B2uy04ph.js} +3 -3
  52. package/dist/assets/{profiles-BOYGlmu2.js.map → profiles-B2uy04ph.js.map} +1 -1
  53. package/dist/assets/{registry-Bep4umOM.js → registry-DbTLLs3y.js} +9 -5
  54. package/dist/assets/registry-DbTLLs3y.js.map +1 -0
  55. package/dist/assets/{registry-4W1LGlCF.js → registry-bLIfG619.js} +1 -1
  56. package/dist/assets/{relay-Cjfmdec0.js → relay-CHWg5hpZ.js} +73 -11
  57. package/dist/assets/relay-CHWg5hpZ.js.map +1 -0
  58. package/dist/assets/{resolve-CIc3KZMV.js → resolve-DNX-eecG.js} +9 -4
  59. package/dist/assets/resolve-DNX-eecG.js.map +1 -0
  60. package/dist/assets/secretGuard-Bh11MPdI.js +1 -0
  61. package/dist/assets/{secretGuard-BrATm_gl.js → secretGuard-oz_3hBfW.js} +19 -2
  62. package/dist/assets/{secretGuard-BrATm_gl.js.map → secretGuard-oz_3hBfW.js.map} +1 -1
  63. package/dist/assets/{server-D4gf-LnD.js → server-DWJ4RzJn.js} +748 -222
  64. package/dist/assets/server-DWJ4RzJn.js.map +1 -0
  65. package/dist/assets/{translate-BcbSWkuq.js → translate-CHj_PdLg.js} +13 -8
  66. package/dist/assets/translate-CHj_PdLg.js.map +1 -0
  67. package/dist/assets/{waitNotice-DQvZgz2T.js → waitNotice-Cvz5CiKR.js} +57 -3
  68. package/dist/assets/waitNotice-Cvz5CiKR.js.map +1 -0
  69. package/dist/ghostly.mjs +1 -1
  70. package/npm-shrinkwrap.json +2 -2
  71. package/package.json +1 -1
  72. package/dist/assets/api-BwEgbvvK.js.map +0 -1
  73. package/dist/assets/apps-CL8TXHhu.js.map +0 -1
  74. package/dist/assets/buttons-CsGdQNnR.js +0 -1
  75. package/dist/assets/buttons-SH1tNRh7.js.map +0 -1
  76. package/dist/assets/errors-DDLFO4Gf.js.map +0 -1
  77. package/dist/assets/ghostly_iroh_web-DIj5xGmR.js.map +0 -1
  78. package/dist/assets/groupMeta-DxuJzko_.js.map +0 -1
  79. package/dist/assets/host-BxM-HMr0.js.map +0 -1
  80. package/dist/assets/irohWeb-CbnGtUo6.js.map +0 -1
  81. package/dist/assets/main-CwTaepxR.js.map +0 -1
  82. package/dist/assets/ownDid-DY3rYqDI.js.map +0 -1
  83. package/dist/assets/ownStatus-DtzIllg2.js.map +0 -1
  84. package/dist/assets/pairedTransports-BKmvlKz1.js.map +0 -1
  85. package/dist/assets/registry-Bep4umOM.js.map +0 -1
  86. package/dist/assets/relay-Cjfmdec0.js.map +0 -1
  87. package/dist/assets/resolve-CIc3KZMV.js.map +0 -1
  88. package/dist/assets/secretGuard-Bm6nci0I.js +0 -1
  89. package/dist/assets/server-D4gf-LnD.js.map +0 -1
  90. package/dist/assets/translate-BcbSWkuq.js.map +0 -1
  91. package/dist/assets/waitNotice-DQvZgz2T.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { d as relayUrlTooLong, u as relayUrl } from "./pairedTransports-BKmvlKz1.js";
1
+ import { d as relayUrlTooLong, u as relayUrl } from "./pairedTransports-Dppn8lUN.js";
2
2
  // ../browser/src/shared/hyperdhtRelay.ts
3
3
  /**
4
4
  * Only `wss://`, or `ws://` to this machine (a relay for tests or development). Nothing but the server's address, as
@@ -29,4 +29,4 @@ function hyperdhtRelayProblem(url) {
29
29
  var hyperdhtRelayUrl = (url) => url.replace(/^[a-z]+:/i, (scheme) => scheme.toLowerCase());
30
30
  export { hyperdhtRelayUrl as n, hyperdhtRelayProblem as t };
31
31
 
32
- //# sourceMappingURL=hyperdhtRelay-bjNGacf5.js.map
32
+ //# sourceMappingURL=hyperdhtRelay-B4_wdCtx.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hyperdhtRelay-bjNGacf5.js","names":[],"sources":["../../../browser/src/shared/hyperdhtRelay.ts"],"sourcesContent":["import { relayUrl, relayUrlTooLong } from \"@ghostly/core\";\n\n/**\n * The HyperDHT relay a browser reaches the HyperDHT through (WISP 103, browser profile). Empty: none, so a\n * browser offers no HyperDHT. Nobody runs a public one for Ghostly yet; this becomes Ghostly's own relay\n * once it is deployed.\n */\nexport const DEFAULT_HYPERDHT_RELAY = \"\";\n\n/**\n * Only `wss://`, or `ws://` to this machine (a relay for tests or development). Nothing but the server's address, as\n * an Iroh relay (irohWeb.ts `irohRelayProblem`): the endpoint names this URL as its descriptor's relay, which every\n * contact is told, so a login, a password, a query or a fragment in it would go to them all.\n */\nexport function hyperdhtRelayProblem(url: string): string | null {\n let parsed: URL;\n try { parsed = new URL(url); } catch { return \"Enter a relay address (wss://…)\"; }\n if (parsed.protocol !== \"wss:\" && !(parsed.protocol === \"ws:\" && [\"127.0.0.1\", \"localhost\", \"[::1]\"].includes(parsed.hostname))) return \"Use a wss:// relay address\";\n if (parsed.username || parsed.password || /[?#]/.test(url)) return `Not a relay address: ${url}`;\n // Nor one a contact would drop with the whole descriptor (`relayUrl`: a space in it, past 126 characters, a capital in\n // `localhost`), leaving the relay unused for reaching this browser without a word. One refused for its length alone\n // is a relay address all the same: what to do is said instead.\n const named = hyperdhtRelayUrl(url);\n if (url.length > 256 || !relayUrl(named)) return relayUrlTooLong(named) ? `Use a shorter relay address: ${url}` : `Not a relay address: ${url}`;\n return null;\n}\n\n/**\n * The relay as the endpoint names it to contacts: its scheme in lower case, as `relayUrl` reads it (`WSS://relay.example`\n * pasted is wss://relay.example), the rest as typed.\n */\nexport const hyperdhtRelayUrl = (url: string): string => url.replace(/^[a-z]+:/i, scheme => scheme.toLowerCase());\n"],"mappings":";;;;;;;AAcA,SAAgB,qBAAqB,KAA4B;CAC/D,IAAI;CACJ,IAAI;EAAE,SAAS,IAAI,IAAI,GAAG;CAAG,QAAQ;EAAE,OAAO;CAAmC;CACjF,IAAI,OAAO,aAAa,UAAU,EAAE,OAAO,aAAa,SAAS;EAAC;EAAa;EAAa;CAAO,CAAC,CAAC,SAAS,OAAO,QAAQ,IAAI,OAAO;CACxI,IAAI,OAAO,YAAY,OAAO,YAAY,OAAO,KAAK,GAAG,GAAG,OAAO,wBAAwB;CAI3F,MAAM,QAAQ,iBAAiB,GAAG;CAClC,IAAI,IAAI,SAAS,OAAO,CAAC,SAAS,KAAK,GAAG,OAAO,gBAAgB,KAAK,IAAI,gCAAgC,QAAQ,wBAAwB;CAC1I,OAAO;AACT;;;;;AAMA,IAAa,oBAAoB,QAAwB,IAAI,QAAQ,cAAa,WAAU,OAAO,YAAY,CAAC"}
1
+ {"version":3,"file":"hyperdhtRelay-B4_wdCtx.js","names":[],"sources":["../../../browser/src/shared/hyperdhtRelay.ts"],"sourcesContent":["import { relayUrl, relayUrlTooLong } from \"@ghostly/core\";\n\n/**\n * The HyperDHT relay a browser reaches the HyperDHT through (WISP 103, browser profile). Empty: none, so a\n * browser offers no HyperDHT. Nobody runs a public one for Ghostly yet; this becomes Ghostly's own relay\n * once it is deployed.\n */\nexport const DEFAULT_HYPERDHT_RELAY = \"\";\n\n/**\n * Only `wss://`, or `ws://` to this machine (a relay for tests or development). Nothing but the server's address, as\n * an Iroh relay (irohWeb.ts `irohRelayProblem`): the endpoint names this URL as its descriptor's relay, which every\n * contact is told, so a login, a password, a query or a fragment in it would go to them all.\n */\nexport function hyperdhtRelayProblem(url: string): string | null {\n let parsed: URL;\n try { parsed = new URL(url); } catch { return \"Enter a relay address (wss://…)\"; }\n if (parsed.protocol !== \"wss:\" && !(parsed.protocol === \"ws:\" && [\"127.0.0.1\", \"localhost\", \"[::1]\"].includes(parsed.hostname))) return \"Use a wss:// relay address\";\n if (parsed.username || parsed.password || /[?#]/.test(url)) return `Not a relay address: ${url}`;\n // Nor one a contact would drop with the whole descriptor (`relayUrl`: a space in it, past 126 characters, a capital in\n // `localhost`), leaving the relay unused for reaching this browser without a word. One refused for its length alone\n // is a relay address all the same: what to do is said instead.\n const named = hyperdhtRelayUrl(url);\n if (url.length > 256 || !relayUrl(named)) return relayUrlTooLong(named) ? `Use a shorter relay address: ${url}` : `Not a relay address: ${url}`;\n return null;\n}\n\n/**\n * The relay as the endpoint names it to contacts: its scheme in lower case, as `relayUrl` reads it (`WSS://relay.example`\n * pasted is wss://relay.example), the rest as typed.\n */\nexport const hyperdhtRelayUrl = (url: string): string => url.replace(/^[a-z]+:/i, scheme => scheme.toLowerCase());\n"],"mappings":";;;;;;;AAcA,SAAgB,qBAAqB,KAA4B;CAC/D,IAAI;CACJ,IAAI;EAAE,SAAS,IAAI,IAAI,GAAG;CAAG,QAAQ;EAAE,OAAO;CAAmC;CACjF,IAAI,OAAO,aAAa,UAAU,EAAE,OAAO,aAAa,SAAS;EAAC;EAAa;EAAa;CAAO,CAAC,CAAC,SAAS,OAAO,QAAQ,IAAI,OAAO;CACxI,IAAI,OAAO,YAAY,OAAO,YAAY,OAAO,KAAK,GAAG,GAAG,OAAO,wBAAwB;CAI3F,MAAM,QAAQ,iBAAiB,GAAG;CAClC,IAAI,IAAI,SAAS,OAAO,CAAC,SAAS,KAAK,GAAG,OAAO,gBAAgB,KAAK,IAAI,gCAAgC,QAAQ,wBAAwB;CAC1I,OAAO;AACT;;;;;AAMA,IAAa,oBAAoB,QAAwB,IAAI,QAAQ,cAAa,WAAU,OAAO,YAAY,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { i as fromBase64Url } from "./bytes-C1DNGY18.js";
2
- import { n as hyperdhtRelayUrl, t as hyperdhtRelayProblem } from "./hyperdhtRelay-bjNGacf5.js";
2
+ import { n as hyperdhtRelayUrl, t as hyperdhtRelayProblem } from "./hyperdhtRelay-B4_wdCtx.js";
3
3
  import { ed25519 } from "@noble/curves/ed25519.js";
4
4
  // ../browser/src/platform/hyperdhtRelay.ts
5
5
  /**
@@ -404,4 +404,4 @@ async function createRelayedHyperEndpoint(seedB64, url, options = {}) {
404
404
  }
405
405
  export { createRelayedHyperEndpoint };
406
406
 
407
- //# sourceMappingURL=hyperdhtRelay-DLUiwfnt.js.map
407
+ //# sourceMappingURL=hyperdhtRelay-Ce-gWsRY.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hyperdhtRelay-DLUiwfnt.js","names":[],"sources":["../../../browser/src/platform/hyperdhtRelay.ts"],"sourcesContent":["import { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { fromBase64Url, type BoundChannel, type FrameChannel, type NativeEndpoint } from \"@ghostly/core\";\nimport { hyperdhtRelayProblem, hyperdhtRelayUrl } from \"../shared/hyperdhtRelay\";\n\nexport { hyperdhtRelayProblem as relayUrlProblem };\n\n/**\n * HyperDHT (WISP 103) for a browser, through a dht-relay: a server that runs the UDP half of HyperDHT and\n * talks to the browser over one WebSocket. It runs non-custodial: the browser keeps its keys, runs the\n * Noise handshake and the encrypted stream itself, and the relay moves handshake messages and ciphertext.\n * The binding (the handshake hash and both keys) is computed here, at the endpoint, as the Desktop does.\n *\n * What the relay sees: this browser's address, the HyperDHT keys it listens on and dials, and when and how\n * much it sends. Not the frames, not the keys' secrets, not the handshake hash.\n *\n * The wire is the Desktop's (native/transports/hyperdht/endpoint.mjs): the same preface, u32 length-prefixed\n * UTF-8 frames of at most 60 KiB, so a browser and a Desktop talk HyperDHT to each other.\n */\n\nconst PREFACE = \"ghostly/paired-chat/1\";\nconst MAX_FRAME = 60 * 1024;\n/** The top bit of a frame's length word: the frame is a binary message, not UTF-8 text (WISP 103). */\nconst BINARY = 0x80000000;\nconst SEND_BUDGET = 120 * 1024;\nconst HANDSHAKE_MS = 20_000;\nconst RELAY_OPEN_MS = 10_000;\nconst LISTEN_MS = 20_000;\nconst MAX_CHANNELS = 2;\n/**\n * Streams dialled in that have not sent the preface yet. They hold none of the MAX_CHANNELS: a new one past this many\n * drops the oldest of them, so streams that stall can never keep the contact's out.\n */\nconst MAX_UNPREFACED = 4;\n/** The places of the streams dialled in: those whose preface came, and those still waiting for it (oldest first). */\ninterface DialledIn { live: Set<RelayedChannel>; unprefaced: Set<RelayedChannel> }\n/**\n * How the relay client is always made: never custodial. dht-relay's default is custodial, which sends every\n * secret key to the relay so it can run the handshake and the stream itself. Nothing here takes this from\n * settings or options; test/hyperdhtRelay.test.ts fails if a secret key ever reaches the relay's wire.\n */\nconst NON_CUSTODIAL = Object.freeze({ custodial: false as const });\n\n/**\n * The descriptor a browser's HyperDHT endpoint gives out: its key, that it is reached only through a relay, and\n * which one (the connection panel names its host; a Desktop dialling it ignores both).\n */\nexport interface RelayedHyperDescriptor { publicKey: string; relayed: true; relay: string }\n\n/** The parts of dht-relay and its streams this adapter uses. */\ninterface SecretSocket {\n handshakeHash: Uint8Array | null;\n publicKey: Uint8Array;\n remotePublicKey: Uint8Array;\n opened?: Promise<boolean>;\n destroyed?: boolean;\n write(data: Uint8Array): boolean;\n destroy(error?: Error): void;\n on(event: string, listener: (...args: never[]) => void): unknown;\n once(event: string, listener: (...args: never[]) => void): unknown;\n off(event: string, listener: (...args: never[]) => void): unknown;\n}\ninterface RelayedServer {\n listen(keyPair: KeyPair): Promise<void>;\n /** Where the relay's node listens for it, as the relay said; port 0 when the relay refused the listen. */\n address(): { port: number } | null;\n close(): Promise<void>;\n once(event: \"close\", listener: () => void): unknown;\n}\ninterface RelayedNode {\n ready(): Promise<void>;\n connect(remotePublicKey: Uint8Array, options: { keyPair: KeyPair }): SecretSocket;\n createServer(options: object, onconnection: (socket: SecretSocket) => void): RelayedServer;\n destroy(): Promise<void>;\n}\ninterface KeyPair { publicKey: Uint8Array; secretKey: Uint8Array }\n\nconst hex = (bytes: Uint8Array) => Array.from(bytes, b => b.toString(16).padStart(2, \"0\")).join(\"\");\nconst fromHex = (text: string) => Uint8Array.from(text.match(/../g)!, byte => parseInt(byte, 16));\n\n/** HyperDHT's key pair for a seed: libsodium's layout (the seed, then the public key). */\nexport function hyperKeyPair(seed: Uint8Array): KeyPair {\n if (seed.length !== 32) throw new Error(\"Invalid HyperDHT seed\");\n const publicKey = ed25519.getPublicKey(seed);\n const secretKey = new Uint8Array(64);\n secretKey.set(seed); secretKey.set(publicKey, 32);\n return { publicKey, secretKey };\n}\n\n/**\n * One WebSocket per relay for the whole app, shared by every chat's endpoint (each listens on its own\n * key). It closes when the last endpoint does. When the relay goes away, every endpoint on it says it is\n * unavailable, and the next one to start opens a new connection.\n */\ninterface RelayClient {\n node: RelayedNode;\n endpoints: Set<{ unavailable(): void }>;\n gone: boolean;\n}\nconst clients = new Map<string, Promise<RelayClient>>();\n\nasync function relayClient(url: string, createSocket: (url: string) => WebSocket): Promise<RelayClient> {\n const existing = clients.get(url);\n if (existing) {\n const client = await existing.catch(() => null);\n if (client && !client.gone) return client;\n if (clients.get(url) === existing) clients.delete(url);\n }\n const opening = (async () => {\n const [{ default: RelayedDHT }, { default: WebSocketStream }] = await Promise.all([\n // @ts-expect-error dht-relay ships no types: RelayedNode and SecretSocket above describe what this uses.\n import(\"@hyperswarm/dht-relay\"),\n // @ts-expect-error The same package's WebSocket stream, untyped too.\n import(\"@hyperswarm/dht-relay/ws\"),\n ]);\n const socket = createSocket(url);\n socket.binaryType = \"arraybuffer\";\n await new Promise<void>((resolve, reject) => {\n const timer = setTimeout(() => { socket.close(); reject(new Error(\"The HyperDHT relay did not answer\")); }, RELAY_OPEN_MS);\n socket.addEventListener(\"open\", () => { clearTimeout(timer); resolve(); }, { once: true });\n socket.addEventListener(\"error\", () => { clearTimeout(timer); reject(new Error(\"Could not reach the HyperDHT relay\")); }, { once: true });\n socket.addEventListener(\"close\", () => { clearTimeout(timer); reject(new Error(\"The HyperDHT relay closed the connection\")); }, { once: true });\n });\n // Non-custodial: the relay is told public keys only, never a secret key (dht-relay's default sends them).\n // The node's own key is never used to listen or dial: a random one says nothing about this app.\n const node = new RelayedDHT(new WebSocketStream(true, socket), { ...NON_CUSTODIAL, keyPair: hyperKeyPair(crypto.getRandomValues(new Uint8Array(32))) }) as RelayedNode;\n const client: RelayClient = { node, endpoints: new Set(), gone: false };\n socket.addEventListener(\"close\", () => {\n client.gone = true;\n if (clients.get(url) === opening) clients.delete(url);\n for (const endpoint of [...client.endpoints]) endpoint.unavailable();\n });\n return client;\n })();\n clients.set(url, opening);\n opening.catch(() => { if (clients.get(url) === opening) clients.delete(url); });\n return opening;\n}\n\n/**\n * dht-relay 0.4.3's server waits for the relay connection to close (to close itself) and never stops waiting once it has\n * closed, so every listener ever opened on the connection, closed or refused, stayed in memory with its chat's endpoint\n * until the connection went. The relay forgets its own side the same way (infra/services/hyperdht-relay `Servers`).\n */\nfunction forgetServer(server: RelayedServer): void {\n const internal = server as unknown as { _protocol?: { _stream?: { off(event: string, listener: () => void): unknown } }; _onStreamClose?: () => void };\n if (internal._onStreamClose) internal._protocol?._stream?.off(\"close\", internal._onStreamClose);\n}\n\nfunction release(url: string, client: RelayClient, endpoint: { unavailable(): void }): void {\n client.endpoints.delete(endpoint);\n if (client.endpoints.size || client.gone) return;\n client.gone = true;\n void clients.get(url)?.then(current => { if (current === client) clients.delete(url); }).catch(() => {});\n void client.node.destroy().catch(() => {});\n}\n\n/** One authenticated stream as a frame channel, with a bounded queue before the session installs its reader. */\nclass RelayedChannel implements FrameChannel {\n private reader: FrameChannel[\"onMessage\"] = null;\n private buffered: (string | Uint8Array)[] = [];\n private closed = false;\n private pendingBytes = 0;\n /** It carries binary messages (WISP 100 § Text and binary messages), as the Desktop's own HyperDHT does. */\n readonly binary = true;\n onClose: FrameChannel[\"onClose\"] = null;\n constructor(private readonly socket: SecretSocket) {\n socket.on(\"drain\", () => { this.pendingBytes = 0; });\n }\n get bufferedAmount(): number { return this.pendingBytes; }\n readonly sendBudget = SEND_BUDGET;\n get onMessage() { return this.reader; }\n set onMessage(reader: FrameChannel[\"onMessage\"]) {\n this.reader = reader;\n if (reader) for (const text of this.buffered.splice(0)) reader(text);\n }\n receive(text: string | Uint8Array): boolean {\n if (this.closed) return true;\n if (this.reader) this.reader(text);\n else if (this.buffered.length < 64) this.buffered.push(text);\n else return false;\n return true;\n }\n send(data: string | Uint8Array): void {\n if (this.closed || !data.length) throw new Error(\"Native channel is closed or exceeds its frame budget\");\n const binary = typeof data !== \"string\";\n const payload = binary ? data : new TextEncoder().encode(data);\n if (payload.length > MAX_FRAME || this.pendingBytes + payload.length > SEND_BUDGET) throw new Error(\"Native channel is closed or exceeds its frame budget\");\n // The stream takes every write; past its high-water mark it says so until it drains.\n if (!writeFrame(this.socket, payload, binary) || this.pendingBytes) this.pendingBytes += payload.length + 4;\n }\n drained(): Promise<void> {\n if (!this.pendingBytes) return Promise.resolve();\n return new Promise((resolve, reject) => {\n const done = () => { this.socket.off(\"close\", gone); resolve(); };\n const gone = () => { this.socket.off(\"drain\", done); reject(new Error(\"Native channel closed\")); };\n this.socket.once(\"drain\", done); this.socket.once(\"close\", gone);\n });\n }\n closedByPeer(): void {\n if (this.closed) return;\n this.closed = true; this.buffered = [];\n this.onClose?.();\n }\n close(): void {\n if (this.closed) return;\n this.socket.destroy();\n this.closedByPeer();\n }\n}\n\nfunction writeFrame(socket: SecretSocket, payload: Uint8Array, binary = false): boolean {\n const frame = new Uint8Array(4 + payload.length);\n new DataView(frame.buffer).setUint32(0, (binary ? BINARY : 0) + payload.length);\n frame.set(payload, 4);\n return socket.write(frame);\n}\n\n/**\n * Waits for the peer's preface on an authenticated stream (sending ours as soon as the handshake is\n * done), then hands the channel over with the binding the stream itself gives. A frame of the wrong size,\n * bytes that are not UTF-8 or another protocol close the stream.\n *\n * `dialledIn`: the stream was dialled in, and takes one of its MAX_CHANNELS only once its preface came. This side's own\n * dials are not counted: one always goes out.\n */\nfunction attach(socket: SecretSocket, channels: Set<RelayedChannel>, dialledIn?: DialledIn): Promise<BoundChannel> {\n if (dialledIn && dialledIn.live.size >= MAX_CHANNELS) { socket.destroy(); return Promise.reject(new Error(\"Native connection limit reached\")); }\n if (dialledIn && dialledIn.unprefaced.size >= MAX_UNPREFACED) {\n const [oldest] = dialledIn.unprefaced;\n dialledIn.unprefaced.delete(oldest); oldest.close();\n }\n const channel = new RelayedChannel(socket);\n channels.add(channel); dialledIn?.unprefaced.add(channel);\n return new Promise<BoundChannel>((resolve, reject) => {\n let buffer = new Uint8Array(0);\n let prefaced = false;\n const decoder = new TextDecoder(\"utf-8\", { fatal: true });\n const timer = setTimeout(() => socket.destroy(new Error(\"HyperDHT handshake timed out\")), HANDSHAKE_MS);\n const fail = (error: Error) => { socket.destroy(error); };\n socket.on(\"error\", (error: Error) => reject(error));\n socket.on(\"close\", () => {\n clearTimeout(timer); channels.delete(channel); dialledIn?.live.delete(channel); dialledIn?.unprefaced.delete(channel);\n reject(new Error(\"Native channel closed\"));\n channel.closedByPeer();\n });\n const opened = () => {\n if (socket.handshakeHash?.length !== 64 || socket.publicKey?.length !== 32 || socket.remotePublicKey?.length !== 32) {\n fail(new Error(\"Noise session binding unavailable\")); return;\n }\n writeFrame(socket, new TextEncoder().encode(PREFACE));\n };\n if (socket.opened) void socket.opened.then(ok => { if (ok) opened(); else reject(new Error(\"Noise handshake failed\")); });\n else socket.once(\"open\", opened);\n socket.on(\"data\", (chunk: Uint8Array) => {\n // Frames are read by offset and only the partial one left is kept (a copy, once per chunk), as on the\n // Desktop: copying the rest of the buffer per frame made a burst of tiny frames cost quadratic time.\n let joined = chunk;\n if (buffer.length) {\n joined = new Uint8Array(buffer.length + chunk.length);\n joined.set(buffer); joined.set(chunk, buffer.length);\n }\n let offset = 0;\n while (joined.length - offset >= 4) {\n const word = new DataView(joined.buffer, joined.byteOffset + offset, 4).getUint32(0);\n const binary = word >= BINARY, length = word % BINARY;\n // A binary frame before the preface is another protocol.\n if (length === 0 || length > MAX_FRAME || (binary && !prefaced)) { fail(new Error(\"Invalid frame length\")); return; }\n if (joined.length - offset < 4 + length) break;\n const payload = joined.subarray(offset + 4, offset + 4 + length);\n offset += 4 + length;\n if (binary) {\n if (!channel.receive(new Uint8Array(payload))) { fail(new Error(\"Receive queue exceeded\")); return; }\n continue;\n }\n let text: string;\n try { text = decoder.decode(payload); }\n catch { fail(new Error(\"Invalid UTF-8 frame\")); return; }\n if (!prefaced) {\n if (text !== PREFACE) { fail(new Error(\"Unexpected application protocol\")); return; }\n prefaced = true; clearTimeout(timer);\n if (dialledIn) {\n dialledIn.unprefaced.delete(channel);\n if (dialledIn.live.size >= MAX_CHANNELS) { fail(new Error(\"Native connection limit reached\")); return; }\n dialledIn.live.add(channel);\n }\n resolve({ channel, binding: { transport: \"hyperdht/1\", context: hex(socket.handshakeHash!),\n identities: [hex(socket.publicKey), hex(socket.remotePublicKey)].sort() as [string, string] } });\n } else if (!channel.receive(text)) { fail(new Error(\"Receive queue exceeded\")); return; }\n }\n buffer = new Uint8Array(joined.subarray(offset));\n });\n });\n}\n\nexport interface RelayedHyperOptions {\n /** How to open the WebSocket (tests pass Node's `ws`). Default: the browser's. */\n createSocket?: (url: string) => WebSocket;\n}\n\n/**\n * A chat's HyperDHT endpoint through the relay at `url`: it listens on the key of `seedB64` (the chat's\n * own transport seed, as on the Desktop) and dials a contact's descriptor. Fails, and so is not offered,\n * when the relay cannot be reached or does not let it listen.\n *\n * dht-relay 0.4.3 has no message for a refused listen (the relay's node refuses a key it already listens on, for\n * another client or an old connection of this one), and its client drops a `closed` for a server that has not had\n * `listening`. So the relay answers a refusal with `listening` at no address (port 0), then `closed`: that fails here\n * at once. A relay that answers nothing leaves the listen to LISTEN_MS. A server the relay closes later says the\n * endpoint is unavailable, as when the whole connection goes.\n */\nexport async function createRelayedHyperEndpoint(seedB64: string, url: string, options: RelayedHyperOptions = {}): Promise<NativeEndpoint> {\n const problem = hyperdhtRelayProblem(url);\n if (problem) throw new Error(problem);\n const keyPair = hyperKeyPair(fromBase64Url(seedB64));\n const client = await relayClient(url, options.createSocket ?? (address => new WebSocket(address)));\n const channels = new Set<RelayedChannel>();\n const dialledIn: DialledIn = { live: new Set(), unprefaced: new Set() };\n let stopped = false;\n let handler: NativeEndpoint[\"onConnection\"] = null;\n const waiting: BoundChannel[] = [];\n let endpoint: NativeEndpoint | null = null;\n // Fails the listen below when the relay connection closes while it waits.\n let relayClosed: (() => void) | null = null;\n const member = {\n unavailable() {\n if (client.gone) relayClosed?.();\n if (stopped) return;\n stopped = true;\n for (const channel of channels) channel.close();\n endpoint?.onUnavailable?.();\n },\n };\n client.endpoints.add(member);\n const server = client.node.createServer({}, socket => {\n void attach(socket, channels, dialledIn).then(bound => {\n if (stopped) bound.channel.close();\n else if (handler) handler(bound);\n else if (waiting.length < MAX_CHANNELS) waiting.push(bound);\n else bound.channel.close();\n }).catch(() => {});\n });\n let serverClosed = false;\n server.once(\"close\", () => { serverClosed = true; forgetServer(server); member.unavailable(); });\n // Neither wait outlasts the listen: one on `client.closed` stayed there, holding this endpoint, closed or refused, for as\n // long as the relay connection stayed open.\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n await Promise.race([\n server.listen(keyPair),\n new Promise((_, reject) => {\n relayClosed = () => reject(new Error(\"The HyperDHT relay closed the connection\"));\n if (client.gone) relayClosed();\n timer = setTimeout(() => reject(new Error(\"The HyperDHT relay did not let this chat listen\")), LISTEN_MS);\n }),\n ]);\n if (client.gone) throw new Error(\"The HyperDHT relay closed the connection\");\n if (serverClosed || !server.address()?.port) throw new Error(\"The HyperDHT relay did not let this chat listen\");\n } catch (error) {\n stopped = true;\n void server.close().catch(() => {});\n release(url, client, member);\n throw error;\n } finally {\n clearTimeout(timer);\n relayClosed = null;\n }\n const descriptor: RelayedHyperDescriptor = { publicKey: hex(keyPair.publicKey), relayed: true, relay: hyperdhtRelayUrl(url) };\n endpoint = {\n transport: \"hyperdht/1\", descriptor, onDescriptor: null, onUnavailable: null,\n get onConnection() { return handler; },\n set onConnection(value) { handler = value; if (value) for (const bound of waiting.splice(0)) value(bound); },\n async connect(address) {\n const publicKey = (address as { publicKey?: unknown } | null)?.publicKey;\n if (stopped || typeof publicKey !== \"string\" || !/^[a-f0-9]{64}$/.test(publicKey)) throw new Error(\"Invalid HyperDHT endpoint\");\n return attach(client.node.connect(fromHex(publicKey), { keyPair }), channels);\n },\n async close() {\n stopped = true;\n for (const channel of channels) channel.close();\n waiting.length = 0;\n await server.close().catch(() => {});\n release(url, client, member);\n },\n };\n return endpoint;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,IAAM,UAAU;AAChB,IAAM,YAAY;;AAElB,IAAM,SAAS;AACf,IAAM,cAAc;AACpB,IAAM,eAAe;AACrB,IAAM,gBAAgB;AACtB,IAAM,YAAY;AAClB,IAAM,eAAe;;;;;AAKrB,IAAM,iBAAiB;;;;;;AAQvB,IAAM,gBAAgB,OAAO,OAAO,EAAE,WAAW,MAAe,CAAC;AAoCjE,IAAM,OAAO,UAAsB,MAAM,KAAK,QAAO,MAAK,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE;AAClG,IAAM,WAAW,SAAiB,WAAW,KAAK,KAAK,MAAM,KAAK,IAAI,SAAQ,SAAS,MAAM,EAAE,CAAC;;AAGhG,SAAgB,aAAa,MAA2B;CACtD,IAAI,KAAK,WAAW,IAAI,MAAM,IAAI,MAAM,uBAAuB;CAC/D,MAAM,YAAY,QAAQ,aAAa,IAAI;CAC3C,MAAM,4BAAY,IAAI,WAAW,EAAE;CACnC,UAAU,IAAI,IAAI;CAAG,UAAU,IAAI,WAAW,EAAE;CAChD,OAAO;EAAE;EAAW;CAAU;AAChC;AAYA,IAAM,0BAAU,IAAI,IAAkC;AAEtD,eAAe,YAAY,KAAa,cAAgE;CACtG,MAAM,WAAW,QAAQ,IAAI,GAAG;CAChC,IAAI,UAAU;EACZ,MAAM,SAAS,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K,QAAQ,QAAQ,SAAS,GAAG,EAAE,QAAQ,CAAC,GAAG,QAAQ;EAC9E;EACA,MAAM,QAAQ;GACZ,UAAU;GACV,KAAK,MAAM,WAAW,UAAU,QAAQ,MAAM;GAC9C,QAAQ,SAAS;GACjB,MAAM,OAAO,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;GACnC,QAAQ,KAAK,QAAQ,MAAM;EAC7B;CACF;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"hyperdhtRelay-Ce-gWsRY.js","names":[],"sources":["../../../browser/src/platform/hyperdhtRelay.ts"],"sourcesContent":["import { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { fromBase64Url, type BoundChannel, type FrameChannel, type NativeEndpoint } from \"@ghostly/core\";\nimport { hyperdhtRelayProblem, hyperdhtRelayUrl } from \"../shared/hyperdhtRelay\";\n\nexport { hyperdhtRelayProblem as relayUrlProblem };\n\n/**\n * HyperDHT (WISP 103) for a browser, through a dht-relay: a server that runs the UDP half of HyperDHT and\n * talks to the browser over one WebSocket. It runs non-custodial: the browser keeps its keys, runs the\n * Noise handshake and the encrypted stream itself, and the relay moves handshake messages and ciphertext.\n * The binding (the handshake hash and both keys) is computed here, at the endpoint, as the Desktop does.\n *\n * What the relay sees: this browser's address, the HyperDHT keys it listens on and dials, and when and how\n * much it sends. Not the frames, not the keys' secrets, not the handshake hash.\n *\n * The wire is the Desktop's (native/transports/hyperdht/endpoint.mjs): the same preface, u32 length-prefixed\n * UTF-8 frames of at most 60 KiB, so a browser and a Desktop talk HyperDHT to each other.\n */\n\nconst PREFACE = \"ghostly/paired-chat/1\";\nconst MAX_FRAME = 60 * 1024;\n/** The top bit of a frame's length word: the frame is a binary message, not UTF-8 text (WISP 103). */\nconst BINARY = 0x80000000;\nconst SEND_BUDGET = 120 * 1024;\nconst HANDSHAKE_MS = 20_000;\nconst RELAY_OPEN_MS = 10_000;\nconst LISTEN_MS = 20_000;\nconst MAX_CHANNELS = 2;\n/**\n * Streams dialled in that have not sent the preface yet. They hold none of the MAX_CHANNELS: a new one past this many\n * drops the oldest of them, so streams that stall can never keep the contact's out.\n */\nconst MAX_UNPREFACED = 4;\n/** The places of the streams dialled in: those whose preface came, and those still waiting for it (oldest first). */\ninterface DialledIn { live: Set<RelayedChannel>; unprefaced: Set<RelayedChannel> }\n/**\n * How the relay client is always made: never custodial. dht-relay's default is custodial, which sends every\n * secret key to the relay so it can run the handshake and the stream itself. Nothing here takes this from\n * settings or options; test/hyperdhtRelay.test.ts fails if a secret key ever reaches the relay's wire.\n */\nconst NON_CUSTODIAL = Object.freeze({ custodial: false as const });\n\n/**\n * The descriptor a browser's HyperDHT endpoint gives out: its key, that it is reached only through a relay, and\n * which one (the connection panel names its host; a Desktop dialling it ignores both).\n */\nexport interface RelayedHyperDescriptor { publicKey: string; relayed: true; relay: string }\n\n/** The parts of dht-relay and its streams this adapter uses. */\ninterface SecretSocket {\n handshakeHash: Uint8Array | null;\n publicKey: Uint8Array;\n remotePublicKey: Uint8Array;\n opened?: Promise<boolean>;\n destroyed?: boolean;\n write(data: Uint8Array): boolean;\n destroy(error?: Error): void;\n on(event: string, listener: (...args: never[]) => void): unknown;\n once(event: string, listener: (...args: never[]) => void): unknown;\n off(event: string, listener: (...args: never[]) => void): unknown;\n}\ninterface RelayedServer {\n listen(keyPair: KeyPair): Promise<void>;\n /** Where the relay's node listens for it, as the relay said; port 0 when the relay refused the listen. */\n address(): { port: number } | null;\n close(): Promise<void>;\n once(event: \"close\", listener: () => void): unknown;\n}\ninterface RelayedNode {\n ready(): Promise<void>;\n connect(remotePublicKey: Uint8Array, options: { keyPair: KeyPair }): SecretSocket;\n createServer(options: object, onconnection: (socket: SecretSocket) => void): RelayedServer;\n destroy(): Promise<void>;\n}\ninterface KeyPair { publicKey: Uint8Array; secretKey: Uint8Array }\n\nconst hex = (bytes: Uint8Array) => Array.from(bytes, b => b.toString(16).padStart(2, \"0\")).join(\"\");\nconst fromHex = (text: string) => Uint8Array.from(text.match(/../g)!, byte => parseInt(byte, 16));\n\n/** HyperDHT's key pair for a seed: libsodium's layout (the seed, then the public key). */\nexport function hyperKeyPair(seed: Uint8Array): KeyPair {\n if (seed.length !== 32) throw new Error(\"Invalid HyperDHT seed\");\n const publicKey = ed25519.getPublicKey(seed);\n const secretKey = new Uint8Array(64);\n secretKey.set(seed); secretKey.set(publicKey, 32);\n return { publicKey, secretKey };\n}\n\n/**\n * One WebSocket per relay for the whole app, shared by every chat's endpoint (each listens on its own\n * key). It closes when the last endpoint does. When the relay goes away, every endpoint on it says it is\n * unavailable, and the next one to start opens a new connection.\n */\ninterface RelayClient {\n node: RelayedNode;\n endpoints: Set<{ unavailable(): void }>;\n gone: boolean;\n}\nconst clients = new Map<string, Promise<RelayClient>>();\n\nasync function relayClient(url: string, createSocket: (url: string) => WebSocket): Promise<RelayClient> {\n const existing = clients.get(url);\n if (existing) {\n const client = await existing.catch(() => null);\n if (client && !client.gone) return client;\n if (clients.get(url) === existing) clients.delete(url);\n }\n const opening = (async () => {\n const [{ default: RelayedDHT }, { default: WebSocketStream }] = await Promise.all([\n // @ts-expect-error dht-relay ships no types: RelayedNode and SecretSocket above describe what this uses.\n import(\"@hyperswarm/dht-relay\"),\n // @ts-expect-error The same package's WebSocket stream, untyped too.\n import(\"@hyperswarm/dht-relay/ws\"),\n ]);\n const socket = createSocket(url);\n socket.binaryType = \"arraybuffer\";\n await new Promise<void>((resolve, reject) => {\n const timer = setTimeout(() => { socket.close(); reject(new Error(\"The HyperDHT relay did not answer\")); }, RELAY_OPEN_MS);\n socket.addEventListener(\"open\", () => { clearTimeout(timer); resolve(); }, { once: true });\n socket.addEventListener(\"error\", () => { clearTimeout(timer); reject(new Error(\"Could not reach the HyperDHT relay\")); }, { once: true });\n socket.addEventListener(\"close\", () => { clearTimeout(timer); reject(new Error(\"The HyperDHT relay closed the connection\")); }, { once: true });\n });\n // Non-custodial: the relay is told public keys only, never a secret key (dht-relay's default sends them).\n // The node's own key is never used to listen or dial: a random one says nothing about this app.\n const node = new RelayedDHT(new WebSocketStream(true, socket), { ...NON_CUSTODIAL, keyPair: hyperKeyPair(crypto.getRandomValues(new Uint8Array(32))) }) as RelayedNode;\n const client: RelayClient = { node, endpoints: new Set(), gone: false };\n socket.addEventListener(\"close\", () => {\n client.gone = true;\n if (clients.get(url) === opening) clients.delete(url);\n for (const endpoint of [...client.endpoints]) endpoint.unavailable();\n });\n return client;\n })();\n clients.set(url, opening);\n opening.catch(() => { if (clients.get(url) === opening) clients.delete(url); });\n return opening;\n}\n\n/**\n * dht-relay 0.4.3's server waits for the relay connection to close (to close itself) and never stops waiting once it has\n * closed, so every listener ever opened on the connection, closed or refused, stayed in memory with its chat's endpoint\n * until the connection went. The relay forgets its own side the same way (infra/services/hyperdht-relay `Servers`).\n */\nfunction forgetServer(server: RelayedServer): void {\n const internal = server as unknown as { _protocol?: { _stream?: { off(event: string, listener: () => void): unknown } }; _onStreamClose?: () => void };\n if (internal._onStreamClose) internal._protocol?._stream?.off(\"close\", internal._onStreamClose);\n}\n\nfunction release(url: string, client: RelayClient, endpoint: { unavailable(): void }): void {\n client.endpoints.delete(endpoint);\n if (client.endpoints.size || client.gone) return;\n client.gone = true;\n void clients.get(url)?.then(current => { if (current === client) clients.delete(url); }).catch(() => {});\n void client.node.destroy().catch(() => {});\n}\n\n/** One authenticated stream as a frame channel, with a bounded queue before the session installs its reader. */\nclass RelayedChannel implements FrameChannel {\n private reader: FrameChannel[\"onMessage\"] = null;\n private buffered: (string | Uint8Array)[] = [];\n private closed = false;\n private pendingBytes = 0;\n /** It carries binary messages (WISP 100 § Text and binary messages), as the Desktop's own HyperDHT does. */\n readonly binary = true;\n onClose: FrameChannel[\"onClose\"] = null;\n constructor(private readonly socket: SecretSocket) {\n socket.on(\"drain\", () => { this.pendingBytes = 0; });\n }\n get bufferedAmount(): number { return this.pendingBytes; }\n readonly sendBudget = SEND_BUDGET;\n get onMessage() { return this.reader; }\n set onMessage(reader: FrameChannel[\"onMessage\"]) {\n this.reader = reader;\n if (reader) for (const text of this.buffered.splice(0)) reader(text);\n }\n receive(text: string | Uint8Array): boolean {\n if (this.closed) return true;\n if (this.reader) this.reader(text);\n else if (this.buffered.length < 64) this.buffered.push(text);\n else return false;\n return true;\n }\n send(data: string | Uint8Array): void {\n if (this.closed || !data.length) throw new Error(\"Native channel is closed or exceeds its frame budget\");\n const binary = typeof data !== \"string\";\n const payload = binary ? data : new TextEncoder().encode(data);\n if (payload.length > MAX_FRAME || this.pendingBytes + payload.length > SEND_BUDGET) throw new Error(\"Native channel is closed or exceeds its frame budget\");\n // The stream takes every write; past its high-water mark it says so until it drains.\n if (!writeFrame(this.socket, payload, binary) || this.pendingBytes) this.pendingBytes += payload.length + 4;\n }\n drained(): Promise<void> {\n if (!this.pendingBytes) return Promise.resolve();\n return new Promise((resolve, reject) => {\n const done = () => { this.socket.off(\"close\", gone); resolve(); };\n const gone = () => { this.socket.off(\"drain\", done); reject(new Error(\"Native channel closed\")); };\n this.socket.once(\"drain\", done); this.socket.once(\"close\", gone);\n });\n }\n closedByPeer(): void {\n if (this.closed) return;\n this.closed = true; this.buffered = [];\n this.onClose?.();\n }\n close(): void {\n if (this.closed) return;\n this.socket.destroy();\n this.closedByPeer();\n }\n}\n\nfunction writeFrame(socket: SecretSocket, payload: Uint8Array, binary = false): boolean {\n const frame = new Uint8Array(4 + payload.length);\n new DataView(frame.buffer).setUint32(0, (binary ? BINARY : 0) + payload.length);\n frame.set(payload, 4);\n return socket.write(frame);\n}\n\n/**\n * Waits for the peer's preface on an authenticated stream (sending ours as soon as the handshake is\n * done), then hands the channel over with the binding the stream itself gives. A frame of the wrong size,\n * bytes that are not UTF-8 or another protocol close the stream.\n *\n * `dialledIn`: the stream was dialled in, and takes one of its MAX_CHANNELS only once its preface came. This side's own\n * dials are not counted: one always goes out.\n */\nfunction attach(socket: SecretSocket, channels: Set<RelayedChannel>, dialledIn?: DialledIn): Promise<BoundChannel> {\n if (dialledIn && dialledIn.live.size >= MAX_CHANNELS) { socket.destroy(); return Promise.reject(new Error(\"Native connection limit reached\")); }\n if (dialledIn && dialledIn.unprefaced.size >= MAX_UNPREFACED) {\n const [oldest] = dialledIn.unprefaced;\n dialledIn.unprefaced.delete(oldest); oldest.close();\n }\n const channel = new RelayedChannel(socket);\n channels.add(channel); dialledIn?.unprefaced.add(channel);\n return new Promise<BoundChannel>((resolve, reject) => {\n let buffer = new Uint8Array(0);\n let prefaced = false;\n const decoder = new TextDecoder(\"utf-8\", { fatal: true });\n const timer = setTimeout(() => socket.destroy(new Error(\"HyperDHT handshake timed out\")), HANDSHAKE_MS);\n const fail = (error: Error) => { socket.destroy(error); };\n socket.on(\"error\", (error: Error) => reject(error));\n socket.on(\"close\", () => {\n clearTimeout(timer); channels.delete(channel); dialledIn?.live.delete(channel); dialledIn?.unprefaced.delete(channel);\n reject(new Error(\"Native channel closed\"));\n channel.closedByPeer();\n });\n const opened = () => {\n if (socket.handshakeHash?.length !== 64 || socket.publicKey?.length !== 32 || socket.remotePublicKey?.length !== 32) {\n fail(new Error(\"Noise session binding unavailable\")); return;\n }\n writeFrame(socket, new TextEncoder().encode(PREFACE));\n };\n if (socket.opened) void socket.opened.then(ok => { if (ok) opened(); else reject(new Error(\"Noise handshake failed\")); });\n else socket.once(\"open\", opened);\n socket.on(\"data\", (chunk: Uint8Array) => {\n // Frames are read by offset and only the partial one left is kept (a copy, once per chunk), as on the\n // Desktop: copying the rest of the buffer per frame made a burst of tiny frames cost quadratic time.\n let joined = chunk;\n if (buffer.length) {\n joined = new Uint8Array(buffer.length + chunk.length);\n joined.set(buffer); joined.set(chunk, buffer.length);\n }\n let offset = 0;\n while (joined.length - offset >= 4) {\n const word = new DataView(joined.buffer, joined.byteOffset + offset, 4).getUint32(0);\n const binary = word >= BINARY, length = word % BINARY;\n // A binary frame before the preface is another protocol.\n if (length === 0 || length > MAX_FRAME || (binary && !prefaced)) { fail(new Error(\"Invalid frame length\")); return; }\n if (joined.length - offset < 4 + length) break;\n const payload = joined.subarray(offset + 4, offset + 4 + length);\n offset += 4 + length;\n if (binary) {\n if (!channel.receive(new Uint8Array(payload))) { fail(new Error(\"Receive queue exceeded\")); return; }\n continue;\n }\n let text: string;\n try { text = decoder.decode(payload); }\n catch { fail(new Error(\"Invalid UTF-8 frame\")); return; }\n if (!prefaced) {\n if (text !== PREFACE) { fail(new Error(\"Unexpected application protocol\")); return; }\n prefaced = true; clearTimeout(timer);\n if (dialledIn) {\n dialledIn.unprefaced.delete(channel);\n if (dialledIn.live.size >= MAX_CHANNELS) { fail(new Error(\"Native connection limit reached\")); return; }\n dialledIn.live.add(channel);\n }\n resolve({ channel, binding: { transport: \"hyperdht/1\", context: hex(socket.handshakeHash!),\n identities: [hex(socket.publicKey), hex(socket.remotePublicKey)].sort() as [string, string] } });\n } else if (!channel.receive(text)) { fail(new Error(\"Receive queue exceeded\")); return; }\n }\n buffer = new Uint8Array(joined.subarray(offset));\n });\n });\n}\n\nexport interface RelayedHyperOptions {\n /** How to open the WebSocket (tests pass Node's `ws`). Default: the browser's. */\n createSocket?: (url: string) => WebSocket;\n}\n\n/**\n * A chat's HyperDHT endpoint through the relay at `url`: it listens on the key of `seedB64` (the chat's\n * own transport seed, as on the Desktop) and dials a contact's descriptor. Fails, and so is not offered,\n * when the relay cannot be reached or does not let it listen.\n *\n * dht-relay 0.4.3 has no message for a refused listen (the relay's node refuses a key it already listens on, for\n * another client or an old connection of this one), and its client drops a `closed` for a server that has not had\n * `listening`. So the relay answers a refusal with `listening` at no address (port 0), then `closed`: that fails here\n * at once. A relay that answers nothing leaves the listen to LISTEN_MS. A server the relay closes later says the\n * endpoint is unavailable, as when the whole connection goes.\n */\nexport async function createRelayedHyperEndpoint(seedB64: string, url: string, options: RelayedHyperOptions = {}): Promise<NativeEndpoint> {\n const problem = hyperdhtRelayProblem(url);\n if (problem) throw new Error(problem);\n const keyPair = hyperKeyPair(fromBase64Url(seedB64));\n const client = await relayClient(url, options.createSocket ?? (address => new WebSocket(address)));\n const channels = new Set<RelayedChannel>();\n const dialledIn: DialledIn = { live: new Set(), unprefaced: new Set() };\n let stopped = false;\n let handler: NativeEndpoint[\"onConnection\"] = null;\n const waiting: BoundChannel[] = [];\n let endpoint: NativeEndpoint | null = null;\n // Fails the listen below when the relay connection closes while it waits.\n let relayClosed: (() => void) | null = null;\n const member = {\n unavailable() {\n if (client.gone) relayClosed?.();\n if (stopped) return;\n stopped = true;\n for (const channel of channels) channel.close();\n endpoint?.onUnavailable?.();\n },\n };\n client.endpoints.add(member);\n const server = client.node.createServer({}, socket => {\n void attach(socket, channels, dialledIn).then(bound => {\n if (stopped) bound.channel.close();\n else if (handler) handler(bound);\n else if (waiting.length < MAX_CHANNELS) waiting.push(bound);\n else bound.channel.close();\n }).catch(() => {});\n });\n let serverClosed = false;\n server.once(\"close\", () => { serverClosed = true; forgetServer(server); member.unavailable(); });\n // Neither wait outlasts the listen: one on `client.closed` stayed there, holding this endpoint, closed or refused, for as\n // long as the relay connection stayed open.\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n await Promise.race([\n server.listen(keyPair),\n new Promise((_, reject) => {\n relayClosed = () => reject(new Error(\"The HyperDHT relay closed the connection\"));\n if (client.gone) relayClosed();\n timer = setTimeout(() => reject(new Error(\"The HyperDHT relay did not let this chat listen\")), LISTEN_MS);\n }),\n ]);\n if (client.gone) throw new Error(\"The HyperDHT relay closed the connection\");\n if (serverClosed || !server.address()?.port) throw new Error(\"The HyperDHT relay did not let this chat listen\");\n } catch (error) {\n stopped = true;\n void server.close().catch(() => {});\n release(url, client, member);\n throw error;\n } finally {\n clearTimeout(timer);\n relayClosed = null;\n }\n const descriptor: RelayedHyperDescriptor = { publicKey: hex(keyPair.publicKey), relayed: true, relay: hyperdhtRelayUrl(url) };\n endpoint = {\n transport: \"hyperdht/1\", descriptor, onDescriptor: null, onUnavailable: null,\n get onConnection() { return handler; },\n set onConnection(value) { handler = value; if (value) for (const bound of waiting.splice(0)) value(bound); },\n async connect(address) {\n const publicKey = (address as { publicKey?: unknown } | null)?.publicKey;\n if (stopped || typeof publicKey !== \"string\" || !/^[a-f0-9]{64}$/.test(publicKey)) throw new Error(\"Invalid HyperDHT endpoint\");\n return attach(client.node.connect(fromHex(publicKey), { keyPair }), channels);\n },\n async close() {\n stopped = true;\n for (const channel of channels) channel.close();\n waiting.length = 0;\n await server.close().catch(() => {});\n release(url, client, member);\n },\n };\n return endpoint;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,IAAM,UAAU;AAChB,IAAM,YAAY;;AAElB,IAAM,SAAS;AACf,IAAM,cAAc;AACpB,IAAM,eAAe;AACrB,IAAM,gBAAgB;AACtB,IAAM,YAAY;AAClB,IAAM,eAAe;;;;;AAKrB,IAAM,iBAAiB;;;;;;AAQvB,IAAM,gBAAgB,OAAO,OAAO,EAAE,WAAW,MAAe,CAAC;AAoCjE,IAAM,OAAO,UAAsB,MAAM,KAAK,QAAO,MAAK,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE;AAClG,IAAM,WAAW,SAAiB,WAAW,KAAK,KAAK,MAAM,KAAK,IAAI,SAAQ,SAAS,MAAM,EAAE,CAAC;;AAGhG,SAAgB,aAAa,MAA2B;CACtD,IAAI,KAAK,WAAW,IAAI,MAAM,IAAI,MAAM,uBAAuB;CAC/D,MAAM,YAAY,QAAQ,aAAa,IAAI;CAC3C,MAAM,4BAAY,IAAI,WAAW,EAAE;CACnC,UAAU,IAAI,IAAI;CAAG,UAAU,IAAI,WAAW,EAAE;CAChD,OAAO;EAAE;EAAW;CAAU;AAChC;AAYA,IAAM,0BAAU,IAAI,IAAkC;AAEtD,eAAe,YAAY,KAAa,cAAgE;CACtG,MAAM,WAAW,QAAQ,IAAI,GAAG;CAChC,IAAI,UAAU;EACZ,MAAM,SAAS,MAAM,SAAS,YAAY,IAAI;EAC9C,IAAI,UAAU,CAAC,OAAO,MAAM,OAAO;EACnC,IAAI,QAAQ,IAAI,GAAG,MAAM,UA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K,MAAM,WAAW,UAAU,QAAQ,MAAM;GAC9C,QAAQ,SAAS;GACjB,MAAM,OAAO,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;GACnC,QAAQ,KAAK,QAAQ,MAAM;EAC7B;CACF;CACA,OAAO;AACT"}
@@ -1,14 +1,14 @@
1
1
  import { d as utf8Decode, f as utf8Encode, i as fromBase64Url, l as toBase64Url, n as concatBytes, s as randomBytes } from "./bytes-C1DNGY18.js";
2
2
  import { a as stripHidden, n as hasVisible, s as unwrapPasted, t as dropLoneJoiners } from "./text-li76pThX.js";
3
- import { c as irohRelayUrl, d as relayUrlTooLong, o as dialableIrohRelay, s as irohDescriptor, u as relayUrl } from "./pairedTransports-BKmvlKz1.js";
3
+ import { c as irohRelayUrl, d as relayUrlTooLong, o as dialableIrohRelay, s as irohDescriptor, u as relayUrl } from "./pairedTransports-Dppn8lUN.js";
4
4
  import { _ as identityFromSeed, y as publicKeyFromZ32 } from "./pkarr-BQo4PcCg.js";
5
- import { m as isDiscoveryBudgetError, p as budgetRetryMs } from "./relay-Cjfmdec0.js";
6
- import { A as GROUP_WANT_NO_FRAME, An as fileMessageText, D as GROUP_FILE_LIMITS, F as readGroupHave, Hn as validRemovalNumber, I as readGroupWant, Ir as GROUP_ID, L as readGroupWantNo, M as groupFileFallback, N as isGroupMessageId, O as GROUP_HAVE_FRAME, On as baseMime, Tr as readStatusCard, Vn as validEditNumber, gt as FileUplink, ii as edgeParams, j as fetchesByItself, mt as ChatFiles, or as replySnippet, qa as exifOrientation, vt as transferEnded, xr as cardEditNumber, zn as RateWindow, zr as MEMBER_KEY } from "./groupMeta-DxuJzko_.js";
5
+ import { m as isDiscoveryBudgetError, p as budgetRetryMs } from "./relay-CHWg5hpZ.js";
6
+ import { An as baseMime, Cr as cardEditNumber, Dr as readStatusCard, Hr as MEMBER_KEY, I as readGroupHave, L as readGroupWant, M as fetchesByItself, Mn as fileMessageText, N as groupFileFallback, O as GROUP_FILE_LIMITS, P as isGroupMessageId, R as readGroupWantNo, Un as validEditNumber, Vn as RateWindow, Wn as validRemovalNumber, Xa as exifOrientation, _t as FileUplink, cr as replySnippet, ht as ChatFiles, j as GROUP_WANT_NO_FRAME, k as GROUP_HAVE_FRAME, si as edgeParams, yt as transferEnded, zr as GROUP_ID } from "./groupMeta--fxSh792.js";
7
7
  import { _ as receivedIdentityStatus, c as IdentityExchange, d as emptyIdentityLedger, f as identityRefusal, g as newIdentityBinding, h as isIdentityBinding, i as IDENTITY_MAX_VALIDITY, l as boundIdentityDisplay, m as identityStatement, o as IDENTITY_REVOCATION_LABEL, p as identityRevocationValue, s as IdentityCheckUnavailable, v as revokesIdentity } from "./identityProofs-Cksc_K7_.js";
8
8
  import { n as engineError, r as engineText } from "./engineErrors--9hfgKlK.js";
9
9
  import { g as walletNetworkOf, l as WALLET_NETWORKS } from "./paymentIntent-DySU3Ajm.js";
10
10
  import { a as decodeBolt11, r as nwcWalletName, t as nwc } from "./nwcProvider-pL2XqSbW.js";
11
- import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid-DY3rYqDI.js";
11
+ import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid-oa-T2vmZ.js";
12
12
  import { a as describeProvider, c as offeredIn, d as sourceProblem, n as PROVIDER_PLATFORMS, o as isNothingSpentError, s as networkMode, t as NothingSpentError, u as redact } from "./types-CdWwgvyt.js";
13
13
  import { b as transact, f as errorLine, p as fileStore, s as STORES, u as databaseName, x as wrap, y as store } from "./idb-ewvbqyDI.js";
14
14
  import { a as sealSeed, g as whenDataKeyDropped, h as sealSecret, i as newDeviceKey, m as openSecret, o as unsealSeed, t as networkReason } from "./networkReason-Be-hMghr.js";
@@ -2584,10 +2584,10 @@ var REDIRECTS = [
2584
2584
  /**
2585
2585
  * A host that is not on the public internet, as far as its name tells: this machine, a single label, `.local` and its
2586
2586
  * kin, private and reserved IP addresses. (What a public name resolves to is checked where the client resolves names
2587
- * itself, as Ghostly Desktop does.)
2587
+ * itself, as Ghostly Desktop and the CLI do.)
2588
2588
  */
2589
2589
  function isLocalHost(hostname) {
2590
- const host = hostname.toLowerCase().replace(/\.$/, "").replace(/^\[|\]$/g, "");
2590
+ const host = hostname.toLowerCase().replace(/\.+$/, "").replace(/^\[|\]$/g, "");
2591
2591
  if (!host.includes(".") && !host.includes(":")) return true;
2592
2592
  if (/(^|\.)(localhost|local|internal|lan|home\.arpa)$/.test(host)) return true;
2593
2593
  const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
@@ -2595,7 +2595,7 @@ function isLocalHost(hostname) {
2595
2595
  const [a, b] = [Number(v4[1]), Number(v4[2])];
2596
2596
  return a === 0 || a === 10 || a === 127 || a >= 224 || a === 169 && b === 254 || a === 172 && b >= 16 && b < 32 || a === 192 && b === 168 || a === 100 && b >= 64 && b < 128 || a === 198 && (b === 18 || b === 19) || a === 192 && b === 0;
2597
2597
  }
2598
- if (host.includes(":")) return !/^[23][0-9a-f]{0,3}:/.test(host) || host.includes(".") || /^2001:0?db8:/.test(host);
2598
+ if (host.includes(":")) return !/^[23][0-9a-f]{3}:/.test(host) || host.includes(".") || host.startsWith("2002:") || /^2001:(0{0,4}|0{0,3}db8):/.test(host);
2599
2599
  return false;
2600
2600
  }
2601
2601
  var isLoopback = (hostname) => [
@@ -5742,7 +5742,7 @@ var registry;
5742
5742
  var loading;
5743
5743
  var listeners = /* @__PURE__ */ new Set();
5744
5744
  function loadIdentityProviders() {
5745
- return loading ??= import("./registry-4W1LGlCF.js").then((m) => {
5745
+ return loading ??= import("./registry-bLIfG619.js").then((m) => {
5746
5746
  registry = m;
5747
5747
  for (const listener of listeners) listener();
5748
5748
  return m;
@@ -5897,7 +5897,8 @@ var IdentityProofs = class {
5897
5897
  this.providers = providers;
5898
5898
  this.fetch = boundedIdentityFetch({
5899
5899
  online: host.online,
5900
- ...host.fetcher && { fetcher: host.fetcher }
5900
+ ...host.fetcher && { fetcher: host.fetcher },
5901
+ ...host.relayFetcher && { relayFetcher: host.relayFetcher }
5901
5902
  });
5902
5903
  }
5903
5904
  /** The profile's proofs, and the providers that check and show them: loaded here, not with the app. */
@@ -6020,7 +6021,7 @@ var IdentityProofs = class {
6020
6021
  let refused;
6021
6022
  let fetch = this.fetch;
6022
6023
  if (this.host.relayOnly?.()) {
6023
- const { fixedIdentityHosts } = await import("./fixedHosts-CPSsGOI2.js");
6024
+ const { fixedIdentityHosts } = await import("./fixedHosts-H3i6o9Iy.js");
6024
6025
  const fixed = fixedIdentityHosts();
6025
6026
  fetch = async (url, options) => {
6026
6027
  const host = new URL(url).host;
@@ -8581,7 +8582,7 @@ function irohRelayProblem(value) {
8581
8582
  var loaded = null;
8582
8583
  /** Loads the wasm once per page. Tests pass their own `load` (Node reads the file). */
8583
8584
  function loadIrohWasm() {
8584
- loaded ??= import("./ghostly_iroh_web-DIj5xGmR.js").then(async (module) => {
8585
+ loaded ??= import("./ghostly_iroh_web-9VOwZcJQ.js").then(async (module) => {
8585
8586
  await module.default();
8586
8587
  return module;
8587
8588
  }).catch((error) => {
@@ -8877,4 +8878,4 @@ async function createIrohWebEndpoint(seedB64, options = {}) {
8877
8878
  }
8878
8879
  export { lightningPaying as $, paymentNetworksOf as A, mergeKnocks as At, removeStored as B, validEditText as Bt, paymentWireId as C, setSingleWriterGate as Ct, createTiming as D, entryParams as Dt, createFailure as E, encodeGroupEntryLink as Et, copyForForward as F, carryMentions as Ft, IdentityProofs as G, wireMentions as Gt, streamStored as H, mentionsBytes as Ht, forwardError as I, communityEditFrame as It, cardsKey as J, NO_VIDEO_METADATA as Jt, CASHU_CARD as K, NO_AUDIO_METADATA as Kt, forwardKind as L, communityMessageAuthor as Lt, MESSAGE_DETAILS_MAX_BYTES as M, COMMUNITY_EDIT_FRAME as Mt, WALLET_TYPES as N, GROUP_EDIT_FRAME as Nt, crossNetwork as O, knockIdentity as Ot, FORWARD_MESSAGE_GONE as P, GROUP_EDIT_TEXT_BYTES as Pt, journaledPayment as Q, withoutPictureMetadata as Qt, FileAppender as R, meshMessageRef as Rt, paymentAlias as S, setAwayWallets as St, assertConfirmedReal as T, decodeGroupEntryLink as Tt, waitingGroupFile as U, mentionsMember as Ut, storedSize as V, MENTION_LIMITS as Vt, IDENTITY_DRAFT_TTL_MS as W, validMentions as Wt, breez as X, NO_PICTURE_METADATA as Xt, BREEZ_SOURCE as Y, withoutVideoMetadata as Yt, normalizePhrase as Z, stripPictureMetadata as Zt, groupReply as _, WrongNetworkError as _t, groupMemberOfLink as a, cashuMint as at, replyRef as b, refuseAway as bt, groupPayTwin as c, loadBreezSdk as ct, parsePayLink as d, breezDatabasesFor as dt, INVOICE_PACE as et, GroupFileDesk as f, iceServerProblem as ft, storedGroupFiles as g, ModeGate as gt, groupOfFile as h, ModeChanged as ht, onPublicIrohRelay as i, CASHU_MINT_SOURCE as it, walletInstances as j, readKnocks as jt, paymentNetwork as k, knockRecords as kt, groupLinkId as l, openBreez as lt, groupFileText as m, relayOnlyProblem as mt, createIrohWebEndpoint as n, ProviderSources as nt, groupPayLineId as o, AskBackoff as ot, groupFileId as p, iceServerSetting as pt, LightningCards as q, withoutAudioMetadata as qt, irohRelayProblem as r, sourceKey as rt, groupPayNoteId as s, forgetBreez as st, DEFAULT_IROH_RELAYS as t, nextInvoiceAsk as tt, pairLinkId as u, breezDatabaseInUse as ut, pairedWireReply as v, networkLabel as vt, WALLET_NAMES as w, KNOCK_TTL_MS as wt, replyTo as x, requireTurn as xt, receivedPairedReply as y, awayFrom as yt, readStored as z, parseCommunityEdit as zt };
8879
8880
 
8880
- //# sourceMappingURL=irohWeb-CbnGtUo6.js.map
8881
+ //# sourceMappingURL=irohWeb-Dp1i8v6n.js.map