@ghostlytools/cli 1.11.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{api-B-52sVYp.js → api-D89ubgas.js} +2 -2
- package/dist/assets/{api-CTqIcdu7.js → api-DL0Uazf6.js} +23 -19
- package/dist/assets/api-DL0Uazf6.js.map +1 -0
- package/dist/assets/{apiKit-CZq4Lq4f.js → apiKit-D78MXTrk.js} +2 -2
- package/dist/assets/{apiKit-CZq4Lq4f.js.map → apiKit-D78MXTrk.js.map} +1 -1
- package/dist/assets/{apps-C_X0zgSG.js → apps--pAqmfgQ.js} +3 -3
- package/dist/assets/{apps-C_X0zgSG.js.map → apps--pAqmfgQ.js.map} +1 -1
- package/dist/assets/{apps-kRsY9S2S.js → apps-BlSl1nGn.js} +1 -1
- package/dist/assets/{arkade-_aaB7VbW.js → arkade-DxB-MR43.js} +2 -2
- package/dist/assets/{arkade-_aaB7VbW.js.map → arkade-DxB-MR43.js.map} +1 -1
- package/dist/assets/{backup-OTvrmk-w.js → backup-B3JJd75o.js} +6 -6
- package/dist/assets/{backup-OTvrmk-w.js.map → backup-B3JJd75o.js.map} +1 -1
- package/dist/assets/{backup-DBg388Ke.js → backup-T7gFpU80.js} +1 -1
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/{buttons-DUu7hxxT.js → buttons-C1VbDihe.js} +3 -3
- package/dist/assets/{buttons-DUu7hxxT.js.map → buttons-C1VbDihe.js.map} +1 -1
- package/dist/assets/buttons-DwWuK_uN.js +2 -0
- package/dist/assets/{client-DDpZP1R1.js → client-CGLuWFRV.js} +2 -2
- package/dist/assets/{client-DDpZP1R1.js.map → client-CGLuWFRV.js.map} +1 -1
- package/dist/assets/{codec-DrryGcPT.js → codec-YGJDr7uH.js} +2 -2
- package/dist/assets/{codec-DrryGcPT.js.map → codec-YGJDr7uH.js.map} +1 -1
- package/dist/assets/{envelope-Q_rMgoE9.js → envelope-Dwq8EN8x.js} +2 -2
- package/dist/assets/{envelope-Q_rMgoE9.js.map → envelope-Dwq8EN8x.js.map} +1 -1
- package/dist/assets/{fixedHosts-BV5GDiTU.js → fixedHosts-CINXidpd.js} +3 -3
- package/dist/assets/{fixedHosts-BV5GDiTU.js.map → fixedHosts-CINXidpd.js.map} +1 -1
- package/dist/assets/{host-BlUzZgQL.js → host-CGlHkiQv.js} +10 -10
- package/dist/assets/{host-BlUzZgQL.js.map → host-CGlHkiQv.js.map} +1 -1
- package/dist/assets/{hyperdhtRelay-BvI_uNZO.js → hyperdhtRelay-Bj5jJT5w.js} +2 -2
- package/dist/assets/{hyperdhtRelay-BvI_uNZO.js.map → hyperdhtRelay-Bj5jJT5w.js.map} +1 -1
- package/dist/assets/{irohWeb-CqPN8VPY.js → irohWeb-CYn0uB_A.js} +9 -9
- package/dist/assets/irohWeb-CYn0uB_A.js.map +1 -0
- package/dist/assets/{main-vQjlgEnt.js → main-CgLW_Gyx.js} +19 -19
- package/dist/assets/{main-vQjlgEnt.js.map → main-CgLW_Gyx.js.map} +1 -1
- package/dist/assets/{mainline-p6HOW7sb.js → mainline-B0h8RchD.js} +2 -2
- package/dist/assets/{mainline-p6HOW7sb.js.map → mainline-B0h8RchD.js.map} +1 -1
- package/dist/assets/{networkReason-DMffkiJ6.js → networkReason-BBosp2KG.js} +3 -3
- package/dist/assets/{networkReason-DMffkiJ6.js.map → networkReason-BBosp2KG.js.map} +1 -1
- package/dist/assets/{nwc-2vH18oNy.js → nwc-SSNS1aJ-.js} +3 -3
- package/dist/assets/{nwc-2vH18oNy.js.map → nwc-SSNS1aJ-.js.map} +1 -1
- package/dist/assets/{nwcProvider-DpeDy0bV.js → nwcProvider-BXqJmM98.js} +2 -2
- package/dist/assets/{nwcProvider-DpeDy0bV.js.map → nwcProvider-BXqJmM98.js.map} +1 -1
- package/dist/assets/{ownDid-iKz8u_fM.js → ownDid--DtH_Jdi.js} +2 -2
- package/dist/assets/{ownDid-iKz8u_fM.js.map → ownDid--DtH_Jdi.js.map} +1 -1
- package/dist/assets/{ownStatus-BlRKnM5F.js → ownStatus-CQPGjCUR.js} +3 -3
- package/dist/assets/{ownStatus-BlRKnM5F.js.map → ownStatus-CQPGjCUR.js.map} +1 -1
- package/dist/assets/{profiles-B5e0TyvS.js → profiles-4UQ1Hsds.js} +3 -3
- package/dist/assets/{profiles-B5e0TyvS.js.map → profiles-4UQ1Hsds.js.map} +1 -1
- package/dist/assets/{registry-Cc_PQb3k.js → registry-B6BXKv6Q.js} +1 -1
- package/dist/assets/{registry-CnFO2Pp5.js → registry-BKCFTEYp.js} +5 -5
- package/dist/assets/{registry-CnFO2Pp5.js.map → registry-BKCFTEYp.js.map} +1 -1
- package/dist/assets/{resolve-DI8uAM_Y.js → resolve-MFeFljsN.js} +2 -2
- package/dist/assets/{resolve-DI8uAM_Y.js.map → resolve-MFeFljsN.js.map} +1 -1
- package/dist/assets/{server-DdtPxkqI.js → server-rHKhnog1.js} +55 -42
- package/dist/assets/server-rHKhnog1.js.map +1 -0
- package/dist/assets/{src-BnpEQqzk.js → src-BzsyAvPf.js} +795 -165
- package/dist/assets/src-BzsyAvPf.js.map +1 -0
- package/dist/assets/{sshForges-cdIAraDw.js → sshForges-qITn-RoV.js} +2 -2
- package/dist/assets/{sshForges-cdIAraDw.js.map → sshForges-qITn-RoV.js.map} +1 -1
- package/dist/assets/{translate-kNopA04L.js → translate-Bkr_iDgp.js} +9 -7
- package/dist/assets/translate-Bkr_iDgp.js.map +1 -0
- package/dist/assets/{usdt-CDaLhEYh.js → usdt-Bp7T2iqt.js} +3 -3
- package/dist/assets/{usdt-CDaLhEYh.js.map → usdt-Bp7T2iqt.js.map} +1 -1
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-CTqIcdu7.js.map +0 -1
- package/dist/assets/buttons-4EKtQl-7.js +0 -2
- package/dist/assets/irohWeb-CqPN8VPY.js.map +0 -1
- package/dist/assets/server-DdtPxkqI.js.map +0 -1
- package/dist/assets/src-BnpEQqzk.js.map +0 -1
- package/dist/assets/translate-kNopA04L.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hd as fromBase64Url } from "./src-BzsyAvPf.js";
|
|
2
2
|
import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-1wzya_0L.js";
|
|
3
3
|
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
4
4
|
//#region ../browser/src/platform/hyperdhtRelay.ts
|
|
@@ -377,4 +377,4 @@ async function createRelayedHyperEndpoint(seedB64, url, options = {}) {
|
|
|
377
377
|
//#endregion
|
|
378
378
|
export { createRelayedHyperEndpoint };
|
|
379
379
|
|
|
380
|
-
//# sourceMappingURL=hyperdhtRelay-
|
|
380
|
+
//# sourceMappingURL=hyperdhtRelay-Bj5jJT5w.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hyperdhtRelay-BvI_uNZO.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 } 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 * 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 */\nfunction attach(socket: SecretSocket, channels: Set<RelayedChannel>): Promise<BoundChannel> {\n if (channels.size >= MAX_CHANNELS) { socket.destroy(); return Promise.reject(new Error(\"Native connection limit reached\")); }\n const channel = new RelayedChannel(socket);\n channels.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);\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 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 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).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: 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,I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AK,MAAM,SAAS,QAAQ,OAAO,CAAC,GAAG,MAAM,KAAK;EAAG;EAC3G,MAAM,QAAQ,SAAS;GACrB,MAAM,YAAa,SAA4C;GAC/D,IAAI,WAAW,OAAO,cAAc,YAAY,CAAC,iBAAiB,KAAK,SAAS,GAAG,MAAM,IAAI,MAAM,2BAA2B;GAC9H,OAAO,OAAO,OAAO,KAAK,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-Bj5jJT5w.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 } 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 * 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 */\nfunction attach(socket: SecretSocket, channels: Set<RelayedChannel>): Promise<BoundChannel> {\n if (channels.size >= MAX_CHANNELS) { socket.destroy(); return Promise.reject(new Error(\"Native connection limit reached\")); }\n const channel = new RelayedChannel(socket);\n channels.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);\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 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 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).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: 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;;;;;;AAMrB,IAAM,gBAAgB,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M,YAAa,SAA4C;GAC/D,IAAI,WAAW,OAAO,cAAc,YAAY,CAAC,iBAAiB,KAAK,SAAS,GAAG,MAAM,IAAI,MAAM,2BAA2B;GAC9H,OAAO,OAAO,OAAO,KAAK,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,11 +1,11 @@
|
|
|
1
|
-
import { $
|
|
1
|
+
import { $i as revokesIdentity, Bi as IDENTITY_MAX_VALIDITY, Dn as requestLnurlInvoice, Ga as fileMessageText, Hi as IdentityCheckUnavailable, J as meshMessageRef, Ji as identityRevocationValue, Jr as transferEnded, Ki as emptyIdentityLedger, Kr as FileUplink, On as resolveLightningDestination, Qi as receivedIdentityStatus, Ui as IdentityExchange, Vi as IDENTITY_REVOCATION_LABEL, Wi as boundIdentityDisplay, Wr as ChatFiles, Xi as isIdentityBinding, Xu as isDiscoveryBudgetError, Yi as identityStatement, Yu as budgetRetryMs, Zi as newIdentityBinding, _d as randomBytes, an as WALLET_NETWORKS, ar as GROUP_FILE_LIMITS, bo as replySnippet, ca as irohRelayUrl, cr as GROUP_WANT_NO_FRAME, dn as walletNetworkOf, dr as isGroupMessageId, eo as RateWindow, hd as fromBase64Url, hr as readGroupWantNo, kn as decodeBolt11, lr as fetchesByItself, mr as readGroupWant, nr as engineError, oa as dialableIrohRelay, or as GROUP_HAVE_FRAME, pr as readGroupHave, qi as identityRefusal, rr as engineText, sa as irohDescriptor, ur as groupFileFallback, vd as toBase64Url } from "./src-BzsyAvPf.js";
|
|
2
2
|
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-C4_KafL_.js";
|
|
3
|
-
import { r as nwcWalletName, t as nwc } from "./nwcProvider-
|
|
3
|
+
import { r as nwcWalletName, t as nwc } from "./nwcProvider-BXqJmM98.js";
|
|
4
4
|
import { b as transact, p as fileStore, s as STORES, u as databaseName, x as wrap, y as store } from "./idb-CEuoNsTv.js";
|
|
5
|
-
import { a as sealSeed, g as whenDataKeyDropped, h as sealSecret, i as newDeviceKey, m as openSecret, o as unsealSeed, t as networkReason } from "./networkReason-
|
|
5
|
+
import { a as sealSeed, g as whenDataKeyDropped, h as sealSecret, i as newDeviceKey, m as openSecret, o as unsealSeed, t as networkReason } from "./networkReason-BBosp2KG.js";
|
|
6
6
|
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-BLPZq9YU.js";
|
|
7
7
|
import { t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-j5XAOk4f.js";
|
|
8
|
-
import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid
|
|
8
|
+
import { c as boundedIdentityFetch, l as verifyIdentity } from "./ownDid--DtH_Jdi.js";
|
|
9
9
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
10
10
|
import { validateMnemonic } from "@scure/bip39";
|
|
11
11
|
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
@@ -2200,7 +2200,7 @@ var registry;
|
|
|
2200
2200
|
var loading;
|
|
2201
2201
|
var listeners = /* @__PURE__ */ new Set();
|
|
2202
2202
|
function loadIdentityProviders() {
|
|
2203
|
-
return loading ??= import("./registry-
|
|
2203
|
+
return loading ??= import("./registry-B6BXKv6Q.js").then((m) => {
|
|
2204
2204
|
registry = m;
|
|
2205
2205
|
for (const listener of listeners) listener();
|
|
2206
2206
|
return m;
|
|
@@ -2470,7 +2470,7 @@ var IdentityProofs = class {
|
|
|
2470
2470
|
let refused;
|
|
2471
2471
|
let fetch = this.fetch;
|
|
2472
2472
|
if (this.host.relayOnly?.()) {
|
|
2473
|
-
const { fixedIdentityHosts } = await import("./fixedHosts-
|
|
2473
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-CINXidpd.js");
|
|
2474
2474
|
const fixed = fixedIdentityHosts();
|
|
2475
2475
|
fetch = async (url, options) => {
|
|
2476
2476
|
const host = new URL(url).host;
|
|
@@ -3004,8 +3004,8 @@ var IdentityProofs = class {
|
|
|
3004
3004
|
verified: r.verified,
|
|
3005
3005
|
display: r.display,
|
|
3006
3006
|
status,
|
|
3007
|
-
verifiedAt: r.verifiedAt,
|
|
3008
|
-
checkedAt: r.checkedAt,
|
|
3007
|
+
verifiedAt: Math.min(r.verifiedAt, t),
|
|
3008
|
+
checkedAt: Math.min(r.checkedAt, t),
|
|
3009
3009
|
expiresAt: Math.min(r.binding.expiresAt, r.verified.expiresAt ?? Infinity),
|
|
3010
3010
|
error: r.error,
|
|
3011
3011
|
recheckDue: !!provider?.recheck && (r.checkedAt > t || t - r.checkedAt >= provider.recheck.afterSeconds),
|
|
@@ -5071,4 +5071,4 @@ async function createIrohWebEndpoint(seedB64, options = {}) {
|
|
|
5071
5071
|
//#endregion
|
|
5072
5072
|
export { iceServerProblem as $, storedSize as A, journaledPayment as B, paymentNetworksOf as C, FileAppender as D, WALLET_TYPES as E, CASHU_CARD as F, sourceKey as G, INVOICE_PACE as H, LightningCards as I, AskBackoff as J, CASHU_MINT_SOURCE as K, cardsKey as L, waitingGroupFile as M, IDENTITY_DRAFT_TTL_MS as N, readStored as O, IdentityProofs as P, dropBreezDatabase as Q, isRecoveryPhrase as R, paymentNetwork as S, MESSAGE_DETAILS_MAX_BYTES as T, nextInvoiceAsk as U, lightningPaying as V, ProviderSources as W, breezDatabaseInUse as X, breezDatabase as Y, breezDatabasesFor as Z, WALLET_NAMES as _, GroupFileDesk as a, networkLabel as at, createTiming as b, groupOfFile as c, requireTurn as ct, pairedWireReply as d, iceServerSetting as et, receivedPairedReply as f, paymentWireId as g, paymentAlias as h, onPublicIrohRelay as i, WrongNetworkError as it, streamStored as j, removeStored as k, storedGroupFiles as l, setAwayWallets as lt, replyTo as m, createIrohWebEndpoint as n, ModeChanged as nt, groupFileId as o, awayFrom as ot, replyRef as p, cashuMint as q, irohRelayProblem as r, ModeGate as rt, groupFileText as s, refuseAway as st, DEFAULT_IROH_RELAYS as t, relayOnlyProblem as tt, groupReply as u, setSingleWriterGate as ut, assertConfirmedReal as v, walletInstances as w, crossNetwork as x, createFailure as y, normalizePhrase as z };
|
|
5073
5073
|
|
|
5074
|
-
//# sourceMappingURL=irohWeb-
|
|
5074
|
+
//# sourceMappingURL=irohWeb-CYn0uB_A.js.map
|