@ghostlytools/cli 1.12.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +5 -5
  2. package/dist/assets/{api-DLzCtePC.js → api-BwEgbvvK.js} +49 -23
  3. package/dist/assets/api-BwEgbvvK.js.map +1 -0
  4. package/dist/assets/{api-DYMKyb1k.js → api-jRUXnBdX.js} +2 -2
  5. package/dist/assets/{apiKit-CVaEzKWQ.js → apiKit-BlsNk-Cx.js} +2 -2
  6. package/dist/assets/{apiKit-CVaEzKWQ.js.map → apiKit-BlsNk-Cx.js.map} +1 -1
  7. package/dist/assets/{appFetch-D56GsYuq.js → appFetch-CW9fJPHh.js} +2 -2
  8. package/dist/assets/{appFetch-D56GsYuq.js.map → appFetch-CW9fJPHh.js.map} +1 -1
  9. package/dist/assets/{apps-BPFW19Wc.js → apps-BcG4u6SM.js} +1 -1
  10. package/dist/assets/{apps-XnZ8VEuj.js → apps-CL8TXHhu.js} +6 -6
  11. package/dist/assets/{apps-XnZ8VEuj.js.map → apps-CL8TXHhu.js.map} +1 -1
  12. package/dist/assets/{backup-DpyvT9Z6.js → backup-BA41EDvh.js} +47 -8
  13. package/dist/assets/backup-BA41EDvh.js.map +1 -0
  14. package/dist/assets/{backup-COX6j1_W.js → backup-xZfV-ytw.js} +1 -1
  15. package/dist/assets/{bitcoind-DTsrd7TF.js → bitcoind-Dh7n9amb.js} +2 -2
  16. package/dist/assets/{bitcoind-DTsrd7TF.js.map → bitcoind-Dh7n9amb.js.map} +1 -1
  17. package/dist/assets/buttons-CsGdQNnR.js +1 -0
  18. package/dist/assets/{buttons-BvWqHJeh.js → buttons-SH1tNRh7.js} +6 -6
  19. package/dist/assets/buttons-SH1tNRh7.js.map +1 -0
  20. package/dist/assets/{client-kGZ3ZdUW.js → client-DGS-atRu.js} +2 -2
  21. package/dist/assets/{client-kGZ3ZdUW.js.map → client-DGS-atRu.js.map} +1 -1
  22. package/dist/assets/{endpoint-B0vE5ojY.js → endpoint-Cvu-taMs.js} +42 -5
  23. package/dist/assets/{endpoint-B0vE5ojY.js.map → endpoint-Cvu-taMs.js.map} +1 -1
  24. package/dist/assets/{groupMeta-DTQAJG50.js → groupMeta-DxuJzko_.js} +49 -28
  25. package/dist/assets/groupMeta-DxuJzko_.js.map +1 -0
  26. package/dist/assets/{host-z0FAHP9Z.js → host-BxM-HMr0.js} +62 -9
  27. package/dist/assets/host-BxM-HMr0.js.map +1 -0
  28. package/dist/assets/{hyperdhtRelay-CvsAfQRQ.js → hyperdhtRelay-DLUiwfnt.js} +32 -4
  29. package/dist/assets/hyperdhtRelay-DLUiwfnt.js.map +1 -0
  30. package/dist/assets/{irohWeb-CLBx5MIv.js → irohWeb-CbnGtUo6.js} +175 -6
  31. package/dist/assets/irohWeb-CbnGtUo6.js.map +1 -0
  32. package/dist/assets/{main-CVqkvuIo.js → main-CwTaepxR.js} +48 -31
  33. package/dist/assets/main-CwTaepxR.js.map +1 -0
  34. package/dist/assets/{ownStatus-DMEhrpkd.js → ownStatus-DtzIllg2.js} +4 -3
  35. package/dist/assets/ownStatus-DtzIllg2.js.map +1 -0
  36. package/dist/assets/{profiles-BFSGqDFC.js → profiles-BOYGlmu2.js} +2 -2
  37. package/dist/assets/{profiles-BFSGqDFC.js.map → profiles-BOYGlmu2.js.map} +1 -1
  38. package/dist/assets/{registry-B15Yg_1C.js → registry-4W1LGlCF.js} +1 -1
  39. package/dist/assets/{registry-rXgaZeNn.js → registry-Bep4umOM.js} +36 -28
  40. package/dist/assets/registry-Bep4umOM.js.map +1 -0
  41. package/dist/assets/secretGuard-Bm6nci0I.js +1 -0
  42. package/dist/assets/{secretGuard-B4-LlMjv.js → secretGuard-BrATm_gl.js} +33 -9
  43. package/dist/assets/{secretGuard-B4-LlMjv.js.map → secretGuard-BrATm_gl.js.map} +1 -1
  44. package/dist/assets/{server-CQR7NLCz.js → server-D4gf-LnD.js} +257 -43
  45. package/dist/assets/server-D4gf-LnD.js.map +1 -0
  46. package/dist/assets/{waitNotice-BGM0QOS2.js → waitNotice-DQvZgz2T.js} +2 -2
  47. package/dist/assets/{waitNotice-BGM0QOS2.js.map → waitNotice-DQvZgz2T.js.map} +1 -1
  48. package/dist/ghostly.mjs +1 -1
  49. package/npm-shrinkwrap.json +2 -2
  50. package/package.json +1 -1
  51. package/dist/assets/api-DLzCtePC.js.map +0 -1
  52. package/dist/assets/backup-DpyvT9Z6.js.map +0 -1
  53. package/dist/assets/buttons-Bq7pTXqF.js +0 -1
  54. package/dist/assets/buttons-BvWqHJeh.js.map +0 -1
  55. package/dist/assets/groupMeta-DTQAJG50.js.map +0 -1
  56. package/dist/assets/host-z0FAHP9Z.js.map +0 -1
  57. package/dist/assets/hyperdhtRelay-CvsAfQRQ.js.map +0 -1
  58. package/dist/assets/irohWeb-CLBx5MIv.js.map +0 -1
  59. package/dist/assets/main-CVqkvuIo.js.map +0 -1
  60. package/dist/assets/ownStatus-DMEhrpkd.js.map +0 -1
  61. package/dist/assets/registry-rXgaZeNn.js.map +0 -1
  62. package/dist/assets/secretGuard-BmmnEbYf.js +0 -1
  63. package/dist/assets/server-CQR7NLCz.js.map +0 -1
@@ -24,6 +24,11 @@ var RELAY_OPEN_MS = 1e4;
24
24
  var LISTEN_MS = 2e4;
25
25
  var MAX_CHANNELS = 2;
26
26
  /**
27
+ * Streams dialled in that have not sent the preface yet. They hold none of the MAX_CHANNELS: a new one past this many
28
+ * drops the oldest of them, so streams that stall can never keep the contact's out.
29
+ */
30
+ var MAX_UNPREFACED = 4;
31
+ /**
27
32
  * How the relay client is always made: never custodial. dht-relay's default is custodial, which sends every
28
33
  * secret key to the relay so it can run the handshake and the stream itself. Nothing here takes this from
29
34
  * settings or options; test/hyperdhtRelay.test.ts fails if a secret key ever reaches the relay's wire.
@@ -190,14 +195,23 @@ function writeFrame(socket, payload, binary = false) {
190
195
  * Waits for the peer's preface on an authenticated stream (sending ours as soon as the handshake is
191
196
  * done), then hands the channel over with the binding the stream itself gives. A frame of the wrong size,
192
197
  * bytes that are not UTF-8 or another protocol close the stream.
198
+ *
199
+ * `dialledIn`: the stream was dialled in, and takes one of its MAX_CHANNELS only once its preface came. This side's own
200
+ * dials are not counted: one always goes out.
193
201
  */
194
- function attach(socket, channels) {
195
- if (channels.size >= MAX_CHANNELS) {
202
+ function attach(socket, channels, dialledIn) {
203
+ if (dialledIn && dialledIn.live.size >= MAX_CHANNELS) {
196
204
  socket.destroy();
197
205
  return Promise.reject(/* @__PURE__ */ new Error("Native connection limit reached"));
198
206
  }
207
+ if (dialledIn && dialledIn.unprefaced.size >= MAX_UNPREFACED) {
208
+ const [oldest] = dialledIn.unprefaced;
209
+ dialledIn.unprefaced.delete(oldest);
210
+ oldest.close();
211
+ }
199
212
  const channel = new RelayedChannel(socket);
200
213
  channels.add(channel);
214
+ dialledIn?.unprefaced.add(channel);
201
215
  return new Promise((resolve, reject) => {
202
216
  let buffer = /* @__PURE__ */ new Uint8Array(0);
203
217
  let prefaced = false;
@@ -210,6 +224,8 @@ function attach(socket, channels) {
210
224
  socket.on("close", () => {
211
225
  clearTimeout(timer);
212
226
  channels.delete(channel);
227
+ dialledIn?.live.delete(channel);
228
+ dialledIn?.unprefaced.delete(channel);
213
229
  reject(/* @__PURE__ */ new Error("Native channel closed"));
214
230
  channel.closedByPeer();
215
231
  });
@@ -264,6 +280,14 @@ function attach(socket, channels) {
264
280
  }
265
281
  prefaced = true;
266
282
  clearTimeout(timer);
283
+ if (dialledIn) {
284
+ dialledIn.unprefaced.delete(channel);
285
+ if (dialledIn.live.size >= MAX_CHANNELS) {
286
+ fail(/* @__PURE__ */ new Error("Native connection limit reached"));
287
+ return;
288
+ }
289
+ dialledIn.live.add(channel);
290
+ }
267
291
  resolve({
268
292
  channel,
269
293
  binding: {
@@ -298,6 +322,10 @@ async function createRelayedHyperEndpoint(seedB64, url, options = {}) {
298
322
  const keyPair = hyperKeyPair(fromBase64Url(seedB64));
299
323
  const client = await relayClient(url, options.createSocket ?? ((address) => new WebSocket(address)));
300
324
  const channels = /* @__PURE__ */ new Set();
325
+ const dialledIn = {
326
+ live: /* @__PURE__ */ new Set(),
327
+ unprefaced: /* @__PURE__ */ new Set()
328
+ };
301
329
  let stopped = false;
302
330
  let handler = null;
303
331
  const waiting = [];
@@ -312,7 +340,7 @@ async function createRelayedHyperEndpoint(seedB64, url, options = {}) {
312
340
  } };
313
341
  client.endpoints.add(member);
314
342
  const server = client.node.createServer({}, (socket) => {
315
- attach(socket, channels).then((bound) => {
343
+ attach(socket, channels, dialledIn).then((bound) => {
316
344
  if (stopped) bound.channel.close();
317
345
  else if (handler) handler(bound);
318
346
  else if (waiting.length < MAX_CHANNELS) waiting.push(bound);
@@ -376,4 +404,4 @@ async function createRelayedHyperEndpoint(seedB64, url, options = {}) {
376
404
  }
377
405
  export { createRelayedHyperEndpoint };
378
406
 
379
- //# sourceMappingURL=hyperdhtRelay-CvsAfQRQ.js.map
407
+ //# sourceMappingURL=hyperdhtRelay-DLUiwfnt.js.map
@@ -0,0 +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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OAAO;GAAE,UAAU;GAAO,IAAI,OAAO,KAAK,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"}
@@ -3,7 +3,7 @@ import { a as stripHidden, n as hasVisible, s as unwrapPasted, t as dropLoneJoin
3
3
  import { c as irohRelayUrl, d as relayUrlTooLong, o as dialableIrohRelay, s as irohDescriptor, u as relayUrl } from "./pairedTransports-BKmvlKz1.js";
4
4
  import { _ as identityFromSeed, y as publicKeyFromZ32 } from "./pkarr-BQo4PcCg.js";
5
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, Ka as exifOrientation, 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, vt as transferEnded, xr as cardEditNumber, zn as RateWindow, zr as MEMBER_KEY } from "./groupMeta-DTQAJG50.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";
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";
@@ -1594,7 +1594,12 @@ async function videoMetadataPatches(file, mime, audio = false) {
1594
1594
  * (its `info` strings, a marker's names in `strg`, `edct` comments, `uuid` chunks).
1595
1595
  * - WavPack: its APEv2 and ID3v1 tags at the end as an MP3's, and the source file's header and trailer each block may
1596
1596
  * keep for a lossless restore (a WAV's INFO list, an AIFF's NAME) made a sub-block that says nothing, zeroed.
1597
- * - TTA: its tags at the end (and an ID3v2 before it) as an MP3's.
1597
+ * - TTA, Monkey's Audio, Musepack (SV7 and SV8) and OptimFROG: their tags at the end (and an ID3v2 before them) as an MP3's.
1598
+ * - DSF: the ID3v2 tag its header points at emptied as an MP3's; any other byte after its sound, zeros.
1599
+ * - DSDIFF: every chunk but its sound's (`FVER`, `PROP`, `DSD `, `DST `, `DSTI`) becomes `JUNK`, zeroed (COMT, DIIN
1600
+ * with its artist and title, MANF, an `ID3 ` chunk), and any byte after its form.
1601
+ * - MIDI: the text of its meta events (a copyright, a track's name, lyrics, markers) and a sequencer's own data become
1602
+ * zeros, their lengths kept; its notes and SysEx as they are.
1598
1603
  * - Sun AU: its annotation, zeros.
1599
1604
  * - WebM and Matroska, audio or video: `Tags`, `Attachments`, `Chapters`, the title, the date, the file names and each
1600
1605
  * track's name become `Void` elements (and the SeekHead's entries for them); the muxer's and the writing app's names
@@ -2088,6 +2093,160 @@ async function wavpack(read, size, at, patches) {
2088
2093
  }
2089
2094
  return at;
2090
2095
  }
2096
+ /** A 64-bit size at `at` of `b`, little- or big-endian: one past what a file can hold is refused. */
2097
+ function u64(b, at, little) {
2098
+ const n = little ? u32le(b, at) + u32le(b, at + 4) * 2 ** 32 : u32be(b, at) * 2 ** 32 + u32be(b, at + 4);
2099
+ check(Number.isSafeInteger(n));
2100
+ return n;
2101
+ }
2102
+ /**
2103
+ * A DSF: its `DSD `, `fmt ` and `data` chunks kept, the ID3v2 tag its header's metadata pointer names emptied where it
2104
+ * is, and any byte after its data that is not that tag zeroed.
2105
+ */
2106
+ async function dsf(read, size, patches) {
2107
+ const head = await read(0, 28);
2108
+ check(u64(head, 4, true) === 28);
2109
+ const fmt = await read(28, 12);
2110
+ check(text(fmt, 0, 4) === "fmt ");
2111
+ const dataAt = 28 + u64(fmt, 4, true);
2112
+ const data = await read(dataAt, 12);
2113
+ check(text(data, 0, 4) === "data");
2114
+ let end = dataAt + u64(data, 4, true);
2115
+ check(end <= size);
2116
+ const pointer = u64(head, 20, true);
2117
+ if (pointer) {
2118
+ check(pointer >= end);
2119
+ const tag = await read(pointer, 10);
2120
+ check(isId3(tag));
2121
+ if (pointer > end) patches.push({
2122
+ start: end,
2123
+ end: pointer
2124
+ });
2125
+ end = await emptyId3(read, size, pointer, tag, patches);
2126
+ }
2127
+ if (end < size) patches.push({
2128
+ start: end,
2129
+ end: size
2130
+ });
2131
+ }
2132
+ /** The chunks a DSDIFF's sound is made of, kept; any other (COMT, DIIN with its artist and title, MANF, an `ID3 `) becomes `JUNK`, zeroed. */
2133
+ var DSDIFF_KEEPS = /* @__PURE__ */ new Set([
2134
+ "FVER",
2135
+ "PROP",
2136
+ "DSD ",
2137
+ "DST ",
2138
+ "DSTI"
2139
+ ]);
2140
+ /** A DSDIFF's chunks within its `FRM8`: big-endian 64-bit sizes, each padded to an even length; any byte after the form zeroed. */
2141
+ async function dsdiff(read, size, patches) {
2142
+ const formEnd = 12 + u64(await read(4, 8), 0, false);
2143
+ check(formEnd >= 16 && formEnd <= size);
2144
+ const count = counter();
2145
+ for (let at = 16; at < formEnd;) {
2146
+ count();
2147
+ const head = await read(at, 12);
2148
+ const id = text(head, 0, 4), length = u64(head, 4, false), end = at + 12 + length;
2149
+ check(end <= formEnd);
2150
+ if (!DSDIFF_KEEPS.has(id)) {
2151
+ patches.push({
2152
+ start: at,
2153
+ end: at + 4,
2154
+ bytes: latin("JUNK")
2155
+ });
2156
+ if (length) patches.push({
2157
+ start: at + 12,
2158
+ end
2159
+ });
2160
+ }
2161
+ at = Math.min(end + length % 2, formEnd);
2162
+ }
2163
+ if (formEnd < size) patches.push({
2164
+ start: formEnd,
2165
+ end: size
2166
+ });
2167
+ }
2168
+ /** The meta events whose data is text (a text, a copyright, a track's or an instrument's name, a lyric, a marker, a cue point, a program's or a device's name) or a sequencer's own. */
2169
+ var MIDI_TEXT = /* @__PURE__ */ new Set([
2170
+ 1,
2171
+ 2,
2172
+ 3,
2173
+ 4,
2174
+ 5,
2175
+ 6,
2176
+ 7,
2177
+ 8,
2178
+ 9,
2179
+ 127
2180
+ ]);
2181
+ /**
2182
+ * A Standard MIDI File's chunks: each track's events walked, the data of its text meta events zeroed (their lengths
2183
+ * kept, so every delta time and event stays where it was), any byte after its end of track zeroed; a chunk that is
2184
+ * neither a header nor a track zeroed.
2185
+ */
2186
+ async function midi(read, size, patches) {
2187
+ const count = counter();
2188
+ let at = 0;
2189
+ for (; at + 8 <= size;) {
2190
+ count();
2191
+ const head = await read(at, 8);
2192
+ const id = text(head, 0, 4), start = at + 8, end = start + u32be(head, 4);
2193
+ check(end <= size);
2194
+ if (id === "MTrk") {
2195
+ const b = await read(start, end - start);
2196
+ let i = 0, running = 0;
2197
+ const varlen = () => {
2198
+ let value = 0;
2199
+ for (let n = 0;; n++) {
2200
+ check(i < b.length && n < 4);
2201
+ const byte = b[i++];
2202
+ value = value * 128 + (byte & 127);
2203
+ if (!(byte & 128)) return value;
2204
+ }
2205
+ };
2206
+ while (i < b.length) {
2207
+ count();
2208
+ varlen();
2209
+ check(i < b.length);
2210
+ const status = b[i];
2211
+ if (status === 255 || status === 240 || status === 247) {
2212
+ const type = status === 255 ? b[++i] : void 0;
2213
+ i++;
2214
+ const length = varlen();
2215
+ check(i + length <= b.length);
2216
+ if (type !== void 0 && MIDI_TEXT.has(type) && length) patches.push({
2217
+ start: start + i,
2218
+ end: start + i + length
2219
+ });
2220
+ i += length;
2221
+ running = 0;
2222
+ if (type === 47) {
2223
+ if (i < b.length) patches.push({
2224
+ start: start + i,
2225
+ end
2226
+ });
2227
+ break;
2228
+ }
2229
+ } else {
2230
+ if (status & 128) {
2231
+ running = status;
2232
+ i++;
2233
+ }
2234
+ check(running >= 128 && running < 240);
2235
+ i += (running & 224) === 192 ? 1 : 2;
2236
+ check(i <= b.length);
2237
+ }
2238
+ }
2239
+ } else if (id !== "MThd" && end > start) patches.push({
2240
+ start,
2241
+ end
2242
+ });
2243
+ at = end;
2244
+ }
2245
+ if (at < size) patches.push({
2246
+ start: at,
2247
+ end: size
2248
+ });
2249
+ }
2091
2250
  /** A Sun AU's annotation: from its 24-byte header to its sound. */
2092
2251
  async function au(read, size, patches) {
2093
2252
  const offset = u32be(await read(4, 4), 0);
@@ -2355,7 +2514,14 @@ async function audioMetadataPatches(file, mime) {
2355
2514
  else if (head.length >= 8 && text(head, 0, 4) === "caff") await caf(read, size, patches);
2356
2515
  else if (head.length >= 24 && text(head, 0, 4) === ".snd") await au(read, size, patches);
2357
2516
  else if (text(head, 0, 4) === "wvpk") await trailingTags(read, size, await wavpack(read, size, 0, patches), patches);
2358
- else if (text(head, 0, 4) === "TTA1") await trailingTags(read, size, 0, patches);
2517
+ else if (text(head, 0, 4) === "TTA1" || [
2518
+ "MAC ",
2519
+ "MPCK",
2520
+ "OFR "
2521
+ ].includes(text(head, 0, 4)) || text(head, 0, 3) === "MP+") await trailingTags(read, size, 0, patches);
2522
+ else if (text(head, 0, 4) === "DSD ") await dsf(read, size, patches);
2523
+ else if (head.length >= 16 && text(head, 0, 4) === "FRM8" && text(head, 12, 4) === "DSD ") await dsdiff(read, size, patches);
2524
+ else if (head.length >= 14 && text(head, 0, 4) === "MThd") await midi(read, size, patches);
2359
2525
  else if (isAsf(head)) check(false);
2360
2526
  else if (text(head, 0, 4) === "fLaC") await trailingTags(read, size, await flac(read, size, 0, patches), patches);
2361
2527
  else if (isId3(head) || isFrame(head, 0)) {
@@ -5576,7 +5742,7 @@ var registry;
5576
5742
  var loading;
5577
5743
  var listeners = /* @__PURE__ */ new Set();
5578
5744
  function loadIdentityProviders() {
5579
- return loading ??= import("./registry-B15Yg_1C.js").then((m) => {
5745
+ return loading ??= import("./registry-4W1LGlCF.js").then((m) => {
5580
5746
  registry = m;
5581
5747
  for (const listener of listeners) listener();
5582
5748
  return m;
@@ -5729,7 +5895,10 @@ var IdentityProofs = class {
5729
5895
  constructor(host, providers = loadedIdentityProviders) {
5730
5896
  this.host = host;
5731
5897
  this.providers = providers;
5732
- this.fetch = boundedIdentityFetch({ online: host.online });
5898
+ this.fetch = boundedIdentityFetch({
5899
+ online: host.online,
5900
+ ...host.fetcher && { fetcher: host.fetcher }
5901
+ });
5733
5902
  }
5734
5903
  /** The profile's proofs, and the providers that check and show them: loaded here, not with the app. */
5735
5904
  async load() {
@@ -8708,4 +8877,4 @@ async function createIrohWebEndpoint(seedB64, options = {}) {
8708
8877
  }
8709
8878
  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 };
8710
8879
 
8711
- //# sourceMappingURL=irohWeb-CLBx5MIv.js.map
8880
+ //# sourceMappingURL=irohWeb-CbnGtUo6.js.map