@candypoets/nipworker 0.91.2 → 0.91.3

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.
@@ -1,20 +1,20 @@
1
- import * as A from "flatbuffers";
2
- import { WebSocketServer as w, WebSocket as m } from "ws";
1
+ import * as E from "flatbuffers";
2
+ import { WebSocketServer as h, WebSocket as S } from "ws";
3
3
  import { SocksProxyAgent as v } from "socks-proxy-agent";
4
- import { C as T, W as E, M as k, G as M, R as F, N as C, S as N } from "./worker-message.js";
4
+ import { C as T, W as k, M, G as A, R as F, N, S as C } from "./worker-message.js";
5
5
  function q(t = {}) {
6
- const r = t.host ?? "127.0.0.1", n = t.port ?? 7777, e = t.path ?? "/", s = t.logger ?? console, o = t.torSocksProxy;
6
+ const n = t.host ?? "127.0.0.1", r = t.port ?? 7777, e = t.path ?? "/", s = t.logger ?? console, o = t.torSocksProxy;
7
7
  let f;
8
8
  try {
9
- f = new w({
10
- host: r,
11
- port: n,
9
+ f = new h({
10
+ host: n,
11
+ port: r,
12
12
  path: e
13
13
  });
14
14
  } catch (i) {
15
15
  throw s.error(`[relay-proxy] failed to create WebSocketServer: ${String(i)}`), i;
16
16
  }
17
- let a = n;
17
+ let a = r;
18
18
  const c = f.address();
19
19
  return c && typeof c == "object" && (a = c.port), f.on("error", (i) => {
20
20
  s.error(`[relay-proxy] WebSocketServer error: ${String(i)}`);
@@ -24,24 +24,23 @@ function q(t = {}) {
24
24
  pendingFrames: /* @__PURE__ */ new Map(),
25
25
  dedupBySubId: /* @__PURE__ */ new Map(),
26
26
  lastSubIdByRelay: /* @__PURE__ */ new Map(),
27
- torSocksProxy: o,
28
- lastAuthChallenge: /* @__PURE__ */ new Map()
27
+ torSocksProxy: o
29
28
  };
30
- i.on("message", (y, p) => {
31
- if (p) {
32
- const d = $(y);
33
- if (!d) return;
34
- x(u, i, d, s);
29
+ i.on("message", (y, d) => {
30
+ if (d) {
31
+ const p = $(y);
32
+ if (!p) return;
33
+ x(u, i, p, s);
35
34
  return;
36
35
  }
37
- const l = h(y);
36
+ const l = w(y);
38
37
  l && b(u, l, s);
39
38
  }), i.on("close", () => {
40
39
  g(u, s);
41
40
  }), i.on("error", () => {
42
41
  g(u, s);
43
42
  });
44
- }), s.info(`[relay-proxy] listening on ws://${r}:${a}${e}`), {
43
+ }), s.info(`[relay-proxy] listening on ws://${n}:${a}${e}`), {
45
44
  port: a,
46
45
  close: () => new Promise((i, u) => {
47
46
  f.close((y) => {
@@ -55,7 +54,7 @@ function q(t = {}) {
55
54
  };
56
55
  }
57
56
  function X(t) {
58
- const r = t.path ?? "/", n = t.logger ?? console, e = t.torSocksProxy, s = new w({
57
+ const n = t.path ?? "/", r = t.logger ?? console, e = t.torSocksProxy, s = new h({
59
58
  noServer: true
60
59
  }), o = /* @__PURE__ */ new Map();
61
60
  return s.on("connection", (a) => {
@@ -72,22 +71,22 @@ function X(t) {
72
71
  if (u) {
73
72
  const l = $(i);
74
73
  if (!l) return;
75
- x(y, a, l, n);
74
+ x(y, a, l, r);
76
75
  return;
77
76
  }
78
- const p = h(i);
79
- p && b(y, p, n);
77
+ const d = w(i);
78
+ d && b(y, d, r);
80
79
  }), a.on("close", () => {
81
80
  const i = o.get(a);
82
- i && (g(i, n), o.delete(a));
81
+ i && (g(i, r), o.delete(a));
83
82
  }), a.on("error", () => {
84
83
  const i = o.get(a);
85
- i && (g(i, n), o.delete(a));
84
+ i && (g(i, r), o.delete(a));
86
85
  });
87
86
  }), {
88
87
  wss: s,
89
88
  close: () => new Promise((a, c) => {
90
- o.forEach((i) => g(i, n)), o.clear(), s.close((i) => {
89
+ o.forEach((i) => g(i, r)), o.clear(), s.close((i) => {
91
90
  if (i) {
92
91
  c(i);
93
92
  return;
@@ -96,16 +95,16 @@ function X(t) {
96
95
  });
97
96
  }),
98
97
  handleUpgrade: (a, c, i) => {
99
- (a.url ?? "").startsWith(r) && s.handleUpgrade(a, c, i, (y) => {
98
+ (a.url ?? "").startsWith(n) && s.handleUpgrade(a, c, i, (y) => {
100
99
  s.emit("connection", y, a);
101
100
  });
102
101
  }
103
102
  };
104
103
  }
105
104
  function Y(t) {
106
- const { server: r, path: n = "/", logger: e = console, torSocksProxy: s } = t, o = new w({
107
- server: r,
108
- path: n
105
+ const { server: n, path: r = "/", logger: e = console, torSocksProxy: s } = t, o = new h({
106
+ server: n,
107
+ path: r
109
108
  });
110
109
  return o.on("connection", (f) => {
111
110
  const a = {
@@ -122,14 +121,14 @@ function Y(t) {
122
121
  x(a, f, y, e);
123
122
  return;
124
123
  }
125
- const u = h(c);
124
+ const u = w(c);
126
125
  u && b(a, u, e);
127
126
  }), f.on("close", () => {
128
127
  g(a, e);
129
128
  }), f.on("error", () => {
130
129
  g(a, e);
131
130
  });
132
- }), e.info(`[relay-proxy] attached to server at path: ${n}`), {
131
+ }), e.info(`[relay-proxy] attached to server at path: ${r}`), {
133
132
  close: () => new Promise((f, a) => {
134
133
  o.close((c) => {
135
134
  if (c) {
@@ -141,15 +140,15 @@ function Y(t) {
141
140
  })
142
141
  };
143
142
  }
144
- function Z(t, r) {
145
- const n = r.path ?? "/ws-proxy", e = r.logger ?? console, s = r.torSocksProxy;
143
+ function Z(t, n) {
144
+ const r = n.path ?? "/ws-proxy", e = n.logger ?? console, s = n.torSocksProxy;
146
145
  let o = null;
147
146
  const f = /* @__PURE__ */ new Map(), a = t.listen.bind(t);
148
147
  return t.listen = (...c) => {
149
148
  const i = a(...c);
150
- return o = new w({
149
+ return o = new h({
151
150
  server: i,
152
- path: n
151
+ path: r
153
152
  }), o.on("connection", (u) => {
154
153
  const y = {
155
154
  relaySockets: /* @__PURE__ */ new Map(),
@@ -158,25 +157,25 @@ function Z(t, r) {
158
157
  lastSubIdByRelay: /* @__PURE__ */ new Map(),
159
158
  torSocksProxy: s
160
159
  };
161
- f.set(u, y), u.on("message", (p, l) => {
162
- const d = f.get(u);
163
- if (!d) return;
160
+ f.set(u, y), u.on("message", (d, l) => {
161
+ const p = f.get(u);
162
+ if (!p) return;
164
163
  if (l) {
165
- const B = $(p);
164
+ const B = $(d);
166
165
  if (!B) return;
167
- x(d, u, B, e);
166
+ x(p, u, B, e);
168
167
  return;
169
168
  }
170
- const I = h(p);
171
- I && b(d, I, e);
169
+ const I = w(d);
170
+ I && b(p, I, e);
172
171
  }), u.on("close", () => {
173
- const p = f.get(u);
174
- p && (g(p, e), f.delete(u));
172
+ const d = f.get(u);
173
+ d && (g(d, e), f.delete(u));
175
174
  }), u.on("error", () => {
176
- const p = f.get(u);
177
- p && (g(p, e), f.delete(u));
175
+ const d = f.get(u);
176
+ d && (g(d, e), f.delete(u));
178
177
  });
179
- }), e.info(`[relay-proxy] attached to Express server at path: ${n}`), i;
178
+ }), e.info(`[relay-proxy] attached to Express server at path: ${r}`), i;
180
179
  }, {
181
180
  close: () => new Promise((c, i) => {
182
181
  if (!o) {
@@ -193,36 +192,36 @@ function Z(t, r) {
193
192
  })
194
193
  };
195
194
  }
196
- function b(t, r, n) {
197
- n.info(`[relay-proxy] handleClientCommand: ${r.slice(0, 200)}`);
195
+ function b(t, n, r) {
196
+ r.info(`[relay-proxy] handleClientCommand: ${n.slice(0, 200)}`);
198
197
  let e;
199
198
  try {
200
- e = JSON.parse(r);
199
+ e = JSON.parse(n);
201
200
  } catch (s) {
202
- n.warn(`[relay-proxy] failed to parse command JSON: ${s}`);
201
+ r.warn(`[relay-proxy] failed to parse command JSON: ${s}`);
203
202
  return;
204
203
  }
205
- if (j(e)) {
206
- n.info(`[relay-proxy] received auth_response for relay: ${e.relay}`);
204
+ if (H(e)) {
205
+ r.info(`[relay-proxy] received auth_response for relay: ${e.relay}`);
207
206
  const s = JSON.stringify(["AUTH", e.event]);
208
- n.info(`[relay-proxy] sending AUTH frame to relay: ${e.relay}`), P(t, e.relay, s, n);
207
+ r.info(`[relay-proxy] sending AUTH frame to relay: ${e.relay}`), P(t, e.relay, s, r);
209
208
  return;
210
209
  }
211
210
  if (G(e)) {
212
211
  t.dedupBySubId.delete(e.subscription_id);
213
212
  for (const [s, o] of t.relaySockets.entries())
214
- o.readyState === m.OPEN && o.send(JSON.stringify(["CLOSE", e.subscription_id])), t.lastSubIdByRelay.set(s, e.subscription_id);
213
+ o.readyState === S.OPEN && o.send(JSON.stringify(["CLOSE", e.subscription_id])), t.lastSubIdByRelay.set(s, e.subscription_id);
215
214
  }
216
215
  }
217
- function x(t, r, n, e) {
218
- e.info(`[relay-proxy] handleEnvelope: ${n.relays.length} relays, ${n.frames.length} frames`), e.info(`[relay-proxy] relays: ${n.relays.join(", ")}`);
219
- const s = n.frames.map((o) => ({
216
+ function x(t, n, r, e) {
217
+ e.info(`[relay-proxy] handleEnvelope: ${r.relays.length} relays, ${r.frames.length} frames`), e.info(`[relay-proxy] relays: ${r.relays.join(", ")}`);
218
+ const s = r.frames.map((o) => ({
220
219
  frame: o,
221
220
  state: L(o)
222
221
  }));
223
222
  e.info(`[relay-proxy] tracked ${s.length} frames`);
224
- for (const o of n.relays) {
225
- e.info(`[relay-proxy] processing relay: ${o}`), W(t, r, o, e);
223
+ for (const o of r.relays) {
224
+ e.info(`[relay-proxy] processing relay: ${o}`), W(t, n, o, e);
226
225
  for (const f of s) {
227
226
  _(t, o, f.state);
228
227
  const a = f.frame;
@@ -230,202 +229,195 @@ function x(t, r, n, e) {
230
229
  }
231
230
  }
232
231
  }
233
- function W(t, r, n, e) {
234
- const s = t.relaySockets.get(n);
235
- if (s && s.readyState !== m.CLOSED) {
236
- e.info(`[relay-proxy] reusing existing connection to ${n}`);
232
+ function W(t, n, r, e) {
233
+ const s = t.relaySockets.get(r);
234
+ if (s && s.readyState !== S.CLOSED) {
235
+ e.info(`[relay-proxy] reusing existing connection to ${r}`);
237
236
  return;
238
237
  }
239
- e.info(`[relay-proxy] creating new WebSocket connection to ${n}`);
240
- const o = new URL(n), f = `${o.protocol}//${o.host}`, a = o.hostname.endsWith(".onion"), c = {
238
+ e.info(`[relay-proxy] creating new WebSocket connection to ${r}`);
239
+ const o = new URL(r), f = `${o.protocol}//${o.host}`, a = o.hostname.endsWith(".onion"), c = {
241
240
  headers: {
242
241
  Origin: f,
243
242
  "User-Agent": "nipworker/0.91.0"
244
243
  }
245
244
  };
246
- a && t.torSocksProxy && (e.info(`[relay-proxy] using Tor SOCKS proxy ${t.torSocksProxy} for ${n}`), c.agent = new v(t.torSocksProxy));
247
- const i = new m(n, c);
248
- t.relaySockets.set(n, i), t.pendingFrames.set(n, []);
245
+ a && t.torSocksProxy && (e.info(`[relay-proxy] using Tor SOCKS proxy ${t.torSocksProxy} for ${r}`), c.agent = new v(t.torSocksProxy));
246
+ const i = new S(r, c);
247
+ t.relaySockets.set(r, i), t.pendingFrames.set(r, []);
249
248
  const u = Date.now();
250
249
  i.on("open", () => {
251
- e.info(`[relay-proxy] connected to ${n}`);
252
- const y = t.pendingFrames.get(n);
250
+ e.info(`[relay-proxy] connected to ${r}`);
251
+ const y = t.pendingFrames.get(r);
253
252
  if (y) {
254
- e.info(`[relay-proxy] sending ${y.length} pending frames to ${n}`);
255
- for (const p of y)
256
- i.send(p);
257
- t.pendingFrames.set(n, []);
253
+ e.info(`[relay-proxy] sending ${y.length} pending frames to ${r}`);
254
+ for (const d of y)
255
+ i.send(d);
256
+ t.pendingFrames.set(r, []);
258
257
  }
259
258
  }), i.on("message", (y) => {
260
- const p = h(y);
261
- if (e.info(`[relay-proxy] received from ${n}: ${p == null ? void 0 : p.slice(0, 100)}`), !p || r.readyState !== m.OPEN) {
262
- e.warn(`[relay-proxy] cannot forward message: raw=${!!p}, clientOpen=${r.readyState === m.OPEN}`);
259
+ const d = w(y);
260
+ if (e.info(`[relay-proxy] received from ${r}: ${d == null ? void 0 : d.slice(0, 100)}`), !d || n.readyState !== S.OPEN) {
261
+ e.warn(`[relay-proxy] cannot forward message: raw=${!!d}, clientOpen=${n.readyState === S.OPEN}`);
263
262
  return;
264
263
  }
265
- const l = t.lastSubIdByRelay.get(n), d = H(t, n, p, l, e);
266
- if (!d) {
264
+ const l = t.lastSubIdByRelay.get(r), p = J(t, r, d, l, e);
265
+ if (!p) {
267
266
  e.warn("[relay-proxy] failed to convert relay frame to worker message");
268
267
  return;
269
268
  }
270
- e.info(`[relay-proxy] forwarding ${d.length} bytes to client`), r.send(d, { binary: true });
271
- }), i.on("close", (y, p) => {
269
+ e.info(`[relay-proxy] forwarding ${p.length} bytes to client`), n.send(p, { binary: true });
270
+ }), i.on("close", (y, d) => {
272
271
  var _a, _b;
273
- if (e.info(`[relay-proxy] connection closed to ${n} (code: ${y}, reason: ${p})`), t.pendingFrames.has(n) && ((_a = t.pendingFrames.get(n)) == null ? void 0 : _a.length) > 0) {
274
- const l = ((_b = t.pendingFrames.get(n)) == null ? void 0 : _b.length) ?? 0;
275
- if (e.warn(`[relay-proxy] connection to ${n} closed with ${l} pending frames - subscription may fail`), r.readyState === m.OPEN) {
276
- const d = S(
277
- t.lastSubIdByRelay.get(n) ?? "",
278
- n,
272
+ if (e.info(`[relay-proxy] connection closed to ${r} (code: ${y}, reason: ${d})`), t.pendingFrames.has(r) && ((_a = t.pendingFrames.get(r)) == null ? void 0 : _a.length) > 0) {
273
+ const l = ((_b = t.pendingFrames.get(r)) == null ? void 0 : _b.length) ?? 0;
274
+ if (e.warn(`[relay-proxy] connection to ${r} closed with ${l} pending frames - subscription may fail`), n.readyState === S.OPEN) {
275
+ const p = m(
276
+ t.lastSubIdByRelay.get(r) ?? "",
277
+ r,
279
278
  "failed",
280
- `Connection failed: ${y} ${p}`
279
+ `Connection failed: ${y} ${d}`
281
280
  );
282
- r.send(d, { binary: true });
281
+ n.send(p, { binary: true });
283
282
  }
284
283
  }
285
- t.pendingFrames.delete(n);
284
+ t.pendingFrames.delete(r);
286
285
  }), i.on("error", (y) => {
287
- if (!t.pendingFrames.has(n)) return;
288
- const p = String(y), l = Date.now() - u;
289
- e.warn(`[relay-proxy] relay socket error for ${n} after ${l}ms: ${p}`), p.includes("403") && e.warn(`[relay-proxy] 403 Forbidden from ${n} - relay may require NIP-42 auth or block this connection`), t.pendingFrames.delete(n);
286
+ if (!t.pendingFrames.has(r)) return;
287
+ const d = String(y), l = Date.now() - u;
288
+ e.warn(`[relay-proxy] relay socket error for ${r} after ${l}ms: ${d}`), d.includes("403") && e.warn(`[relay-proxy] 403 Forbidden from ${r} - relay may require NIP-42 auth or block this connection`), t.pendingFrames.delete(r);
290
289
  });
291
290
  }
292
- function _(t, r, n) {
293
- if (n) {
294
- if (t.lastSubIdByRelay.set(r, n.subId), n.type === "REQ") {
295
- const e = n.subId;
291
+ function _(t, n, r) {
292
+ if (r) {
293
+ if (t.lastSubIdByRelay.set(n, r.subId), r.type === "REQ") {
294
+ const e = r.subId;
296
295
  t.dedupBySubId.has(e) || t.dedupBySubId.set(e, /* @__PURE__ */ new Set());
297
296
  return;
298
297
  }
299
- t.dedupBySubId.delete(n.subId);
298
+ t.dedupBySubId.delete(r.subId);
300
299
  }
301
300
  }
302
301
  function L(t) {
303
- const r = R(t);
304
- if (!r) return null;
305
- const n = r[0];
306
- if (n !== "REQ" && n !== "CLOSE") return null;
307
- const e = typeof r[1] == "string" ? r[1] : null;
308
- return e ? { type: n, subId: e } : null;
302
+ const n = R(t);
303
+ if (!n) return null;
304
+ const r = n[0];
305
+ if (r !== "REQ" && r !== "CLOSE") return null;
306
+ const e = typeof n[1] == "string" ? n[1] : null;
307
+ return e ? { type: r, subId: e } : null;
309
308
  }
310
- function P(t, r, n, e) {
311
- const s = t.relaySockets.get(r);
309
+ function P(t, n, r, e) {
310
+ const s = t.relaySockets.get(n);
312
311
  if (!s) {
313
- e.warn(`[relay-proxy] no relay socket for ${r}`);
312
+ e.warn(`[relay-proxy] no relay socket for ${n}`);
314
313
  return;
315
314
  }
316
- if (s.readyState === m.OPEN) {
317
- e.info(`[relay-proxy] sending frame to ${r} (OPEN): ${n.slice(0, 100)}`), s.send(n);
315
+ if (s.readyState === S.OPEN) {
316
+ e.info(`[relay-proxy] sending frame to ${n} (OPEN): ${r.slice(0, 100)}`), s.send(r);
318
317
  return;
319
318
  }
320
- if (s.readyState === m.CONNECTING) {
321
- e.info(`[relay-proxy] queueing frame for ${r} (CONNECTING)`);
322
- const o = t.pendingFrames.get(r) ?? [];
323
- o.push(n), t.pendingFrames.set(r, o);
319
+ if (s.readyState === S.CONNECTING) {
320
+ e.info(`[relay-proxy] queueing frame for ${n} (CONNECTING)`);
321
+ const o = t.pendingFrames.get(n) ?? [];
322
+ o.push(r), t.pendingFrames.set(n, o);
324
323
  return;
325
324
  }
326
- e.warn(`[relay-proxy] dropping frame for closed relay socket ${r} (state: ${s.readyState})`);
325
+ e.warn(`[relay-proxy] dropping frame for closed relay socket ${n} (state: ${s.readyState})`);
327
326
  }
328
- function H(t, r, n, e, s) {
329
- const o = R(n);
327
+ function J(t, n, r, e, s) {
328
+ const o = R(r);
330
329
  if (!o || o.length < 1 || typeof o[0] != "string")
331
- return O(e ?? "", r, n);
330
+ return O(e ?? "", n, r);
332
331
  const f = o[0];
333
332
  if (f === "EVENT") {
334
- const a = typeof o[1] == "string" ? o[1] : "", c = J(o[2]);
333
+ const a = typeof o[1] == "string" ? o[1] : "", c = j(o[2]);
335
334
  if (!a || !c)
336
- return O(a, r, n);
335
+ return O(a, n, r);
337
336
  const i = t.dedupBySubId.get(a);
338
- return i && i.has(c.id) ? null : (i && i.add(c.id), D(a, r, c));
337
+ return i && i.has(c.id) ? null : (i && i.add(c.id), V(a, n, c));
339
338
  }
340
339
  if (f === "NOTICE") {
341
340
  const a = o[1] === void 0 ? null : String(o[1]);
342
- return S("", r, "NOTICE", a);
341
+ return m("", n, "NOTICE", a);
343
342
  }
344
343
  if (f === "AUTH") {
345
- const a = o[1] === void 0 ? null : String(o[1]), c = Date.now(), i = t.lastAuthChallenge.get(r);
346
- if (i) {
347
- const y = c - i.timestamp;
348
- if (i.challenge === a && y < 5e3)
349
- return s == null ? void 0 : s.info(`[relay-proxy] dropping duplicate AUTH from ${r} (${y}ms ago)`), null;
350
- if (y < 1e3)
351
- return s == null ? void 0 : s.info(`[relay-proxy] rate limiting AUTH from ${r} (${y}ms since last)`), null;
352
- }
353
- t.lastAuthChallenge.set(r, { challenge: a, timestamp: c }), s == null ? void 0 : s.info(`[relay-proxy] received AUTH challenge from ${r}: ${a}`);
354
- const u = S(e ?? "", r, "AUTH", a);
355
- return s == null ? void 0 : s.info(`[relay-proxy] built AUTH worker message (${u.length} bytes)`), u;
344
+ const a = o[1] === void 0 ? null : String(o[1]);
345
+ s == null ? void 0 : s.info(`[relay-proxy] received AUTH challenge from ${n}: ${a}`);
346
+ const c = m(e ?? "", n, "AUTH", a);
347
+ return s == null ? void 0 : s.info(`[relay-proxy] built AUTH worker message (${c.length} bytes)`), c;
356
348
  }
357
349
  if (f === "CLOSED") {
358
350
  const a = typeof o[1] == "string" ? o[1] : "", c = o[2] === void 0 ? null : String(o[2]);
359
- return S(a, r, "CLOSED", c);
351
+ return m(a, n, "CLOSED", c);
360
352
  }
361
353
  if (f === "OK") {
362
354
  const a = typeof o[1] == "string" ? o[1] : "", c = o[2] === void 0 ? "false" : String(o[2]), i = o[3] === void 0 ? null : String(o[3]);
363
- return S(a, r, c, i);
355
+ return m(a, n, c, i);
364
356
  }
365
357
  if (f === "EOSE") {
366
358
  const a = typeof o[1] == "string" ? o[1] : "";
367
- return S(a, r, "EOSE", null);
359
+ return m(a, n, "EOSE", null);
368
360
  }
369
- return O(e ?? "", r, n);
361
+ return O(e ?? "", n, r);
370
362
  }
371
- function D(t, r, n) {
372
- const e = new A.Builder(1024), s = t ? e.createString(t) : 0, o = e.createString(r), f = e.createString(n.id), a = e.createString(n.pubkey), c = e.createString(n.content), i = e.createString(n.sig), u = new Array(n.tags.length);
373
- for (let d = 0; d < n.tags.length; d++)
374
- u[d] = V(e, n.tags[d]);
375
- const y = C.createTagsVector(e, u), p = C.createNostrEvent(
363
+ function V(t, n, r) {
364
+ const e = new E.Builder(1024), s = t ? e.createString(t) : 0, o = e.createString(n), f = e.createString(r.id), a = e.createString(r.pubkey), c = e.createString(r.content), i = e.createString(r.sig), u = new Array(r.tags.length);
365
+ for (let p = 0; p < r.tags.length; p++)
366
+ u[p] = D(e, r.tags[p]);
367
+ const y = N.createTagsVector(e, u), d = N.createNostrEvent(
376
368
  e,
377
369
  f,
378
370
  a,
379
- n.kind,
371
+ r.kind,
380
372
  c,
381
373
  y,
382
- n.created_at,
374
+ r.created_at,
383
375
  i
384
- ), l = E.createWorkerMessage(
376
+ ), l = k.createWorkerMessage(
385
377
  e,
386
378
  s,
387
379
  o,
388
- k.NostrEvent,
389
380
  M.NostrEvent,
390
- p
381
+ A.NostrEvent,
382
+ d
391
383
  );
392
384
  return e.finish(l), e.asUint8Array();
393
385
  }
394
- function S(t, r, n, e) {
395
- const s = new A.Builder(256), o = t ? s.createString(t) : 0, f = s.createString(r), a = s.createString(n), c = e === null ? 0 : s.createString(e), i = T.createConnectionStatus(
386
+ function m(t, n, r, e) {
387
+ const s = new E.Builder(256), o = t ? s.createString(t) : 0, f = s.createString(n), a = s.createString(r), c = e === null ? 0 : s.createString(e), i = T.createConnectionStatus(
396
388
  s,
397
389
  f,
398
390
  a,
399
391
  c
400
- ), u = E.createWorkerMessage(
392
+ ), u = k.createWorkerMessage(
401
393
  s,
402
394
  o,
403
395
  f,
404
- k.ConnectionStatus,
405
396
  M.ConnectionStatus,
397
+ A.ConnectionStatus,
406
398
  i
407
399
  );
408
400
  return s.finish(u), s.asUint8Array();
409
401
  }
410
- function O(t, r, n) {
411
- const e = new A.Builder(256), s = t ? e.createString(t) : 0, o = e.createString(r), f = e.createString(n), a = F.createRaw(e, f), c = E.createWorkerMessage(
402
+ function O(t, n, r) {
403
+ const e = new E.Builder(256), s = t ? e.createString(t) : 0, o = e.createString(n), f = e.createString(r), a = F.createRaw(e, f), c = k.createWorkerMessage(
412
404
  e,
413
405
  s,
414
406
  o,
415
- k.Raw,
416
407
  M.Raw,
408
+ A.Raw,
417
409
  a
418
410
  );
419
411
  return e.finish(c), e.asUint8Array();
420
412
  }
421
- function J(t) {
413
+ function j(t) {
422
414
  if (!t || typeof t != "object") return null;
423
- const r = t;
424
- if (typeof r.id != "string" || typeof r.pubkey != "string" || typeof r.kind != "number" || typeof r.content != "string" || typeof r.created_at != "number" || typeof r.sig != "string" || !Array.isArray(r.tags))
415
+ const n = t;
416
+ if (typeof n.id != "string" || typeof n.pubkey != "string" || typeof n.kind != "number" || typeof n.content != "string" || typeof n.created_at != "number" || typeof n.sig != "string" || !Array.isArray(n.tags))
425
417
  return null;
426
- const n = r.tags;
418
+ const r = n.tags;
427
419
  let e = false;
428
- for (const o of n) {
420
+ for (const o of r) {
429
421
  if (!Array.isArray(o) || o.length === 0) {
430
422
  e = true;
431
423
  continue;
@@ -438,10 +430,10 @@ function J(t) {
438
430
  }
439
431
  let s;
440
432
  if (!e)
441
- s = n;
433
+ s = r;
442
434
  else {
443
435
  s = [];
444
- for (const o of n) {
436
+ for (const o of r) {
445
437
  if (!Array.isArray(o)) continue;
446
438
  const f = [];
447
439
  for (const a of o)
@@ -450,62 +442,62 @@ function J(t) {
450
442
  }
451
443
  }
452
444
  return {
453
- id: r.id,
454
- pubkey: r.pubkey,
455
- kind: r.kind,
456
- content: r.content,
457
- created_at: r.created_at,
458
- sig: r.sig,
445
+ id: n.id,
446
+ pubkey: n.pubkey,
447
+ kind: n.kind,
448
+ content: n.content,
449
+ created_at: n.created_at,
450
+ sig: n.sig,
459
451
  tags: s
460
452
  };
461
453
  }
462
- function V(t, r) {
463
- const n = new Array(r.length);
464
- for (let s = 0; s < r.length; s++)
465
- n[s] = t.createString(r[s]);
466
- const e = N.createItemsVector(t, n);
467
- return N.createStringVec(t, e);
454
+ function D(t, n) {
455
+ const r = new Array(n.length);
456
+ for (let s = 0; s < n.length; s++)
457
+ r[s] = t.createString(n[s]);
458
+ const e = C.createItemsVector(t, r);
459
+ return C.createStringVec(t, e);
468
460
  }
469
461
  function R(t) {
470
462
  try {
471
- const r = JSON.parse(t);
472
- return Array.isArray(r) ? r : null;
463
+ const n = JSON.parse(t);
464
+ return Array.isArray(n) ? n : null;
473
465
  } catch {
474
466
  return null;
475
467
  }
476
468
  }
477
- function $(t, r) {
478
- const n = h(t);
479
- if (!n)
469
+ function $(t, n) {
470
+ const r = w(t);
471
+ if (!r)
480
472
  return null;
481
473
  try {
482
- const e = JSON.parse(n);
474
+ const e = JSON.parse(r);
483
475
  if (!Array.isArray(e.relays) || !Array.isArray(e.frames))
484
- return r == null ? void 0 : r.warn(`[relay-proxy] parseEnvelope: invalid structure (relays: ${Array.isArray(e.relays)}, frames: ${Array.isArray(e.frames)})`), null;
476
+ return n == null ? void 0 : n.warn(`[relay-proxy] parseEnvelope: invalid structure (relays: ${Array.isArray(e.relays)}, frames: ${Array.isArray(e.frames)})`), null;
485
477
  const s = e.relays.filter((f) => typeof f == "string"), o = e.frames.filter((f) => typeof f == "string");
486
- return r == null ? void 0 : r.info(`[relay-proxy] parseEnvelope: ${s.length} relays, ${o.length} frames`), s.length === 0 || o.length === 0 ? (r == null ? void 0 : r.warn("[relay-proxy] parseEnvelope: empty relays or frames after filter"), null) : { relays: s, frames: o };
478
+ return n == null ? void 0 : n.info(`[relay-proxy] parseEnvelope: ${s.length} relays, ${o.length} frames`), s.length === 0 || o.length === 0 ? (n == null ? void 0 : n.warn("[relay-proxy] parseEnvelope: empty relays or frames after filter"), null) : { relays: s, frames: o };
487
479
  } catch {
488
480
  return null;
489
481
  }
490
482
  }
491
- function h(t) {
492
- return typeof t == "string" ? t : t instanceof ArrayBuffer ? Buffer.from(t).toString("utf8") : Buffer.isBuffer(t) ? t.toString("utf8") : t instanceof Uint8Array ? Buffer.from(t).toString("utf8") : Array.isArray(t) ? Buffer.concat(t.filter((r) => Buffer.isBuffer(r))).toString("utf8") : "";
483
+ function w(t) {
484
+ return typeof t == "string" ? t : t instanceof ArrayBuffer ? Buffer.from(t).toString("utf8") : Buffer.isBuffer(t) ? t.toString("utf8") : t instanceof Uint8Array ? Buffer.from(t).toString("utf8") : Array.isArray(t) ? Buffer.concat(t.filter((n) => Buffer.isBuffer(n))).toString("utf8") : "";
493
485
  }
494
- function j(t) {
486
+ function H(t) {
495
487
  if (!t || typeof t != "object") return false;
496
- const r = t;
497
- return r.type === "auth_response" && typeof r.relay == "string" && r.event !== void 0;
488
+ const n = t;
489
+ return n.type === "auth_response" && typeof n.relay == "string" && n.event !== void 0;
498
490
  }
499
491
  function G(t) {
500
492
  if (!t || typeof t != "object") return false;
501
- const r = t;
502
- return r.type === "close_sub" && typeof r.subscription_id == "string";
493
+ const n = t;
494
+ return n.type === "close_sub" && typeof n.subscription_id == "string";
503
495
  }
504
- function g(t, r) {
505
- r == null ? void 0 : r.info("[relay-proxy] closing session"), t.dedupBySubId.clear(), t.lastSubIdByRelay.clear();
506
- for (const [n, e] of t.relaySockets.entries())
496
+ function g(t, n) {
497
+ n == null ? void 0 : n.info("[relay-proxy] closing session"), t.dedupBySubId.clear(), t.lastSubIdByRelay.clear();
498
+ for (const [r, e] of t.relaySockets.entries())
507
499
  try {
508
- r == null ? void 0 : r.info(`[relay-proxy] closing socket to ${n}`), e.close();
500
+ n == null ? void 0 : n.info(`[relay-proxy] closing socket to ${r}`), e.close();
509
501
  } catch {
510
502
  }
511
503
  t.relaySockets.clear(), t.pendingFrames.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@candypoets/nipworker",
3
- "version": "0.91.2",
3
+ "version": "0.91.3",
4
4
  "description": "Nostr client library with worker-based architecture using Rust WASM",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",