@candypoets/nipworker 0.91.0 → 0.91.2
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/NarrowTypes.js +279 -1
- package/dist/cache/index.js +431 -2
- package/dist/cache/pkg/cache.d.ts +3 -3
- package/dist/cache/pkg/cache_bg.wasm.d.ts +3 -3
- package/dist/connections/index.js +442 -2
- package/dist/connections/pkg/connections.d.ts +3 -3
- package/dist/connections/pkg/connections_bg.wasm.d.ts +3 -3
- package/dist/connections/proxy.js +2 -1
- package/dist/connections/proxy.js.map +7 -1
- package/dist/connections/types.d.ts +12 -0
- package/dist/connections/types.d.ts.map +1 -1
- package/dist/crypto/index.js +785 -2
- package/dist/hooks.js +94 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +231 -1
- package/dist/index2.js +2614 -1
- package/dist/parser/index.js +565 -2
- package/dist/proxy/relayProxyServer.d.ts +4 -0
- package/dist/proxy/relayProxyServer.d.ts.map +1 -1
- package/dist/proxy/server.js +7 -1
- package/dist/proxy/vite.d.ts.map +1 -1
- package/dist/proxy/vite.js +43 -2
- package/dist/relayProxyServer.js +518 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils.js +357 -4
- package/dist/worker-message.js +6866 -1
- package/package.json +3 -1
- package/dist/NarrowTypes.js.map +0 -1
- package/dist/cache/index.js.map +0 -1
- package/dist/connections/index.js.map +0 -1
- package/dist/crypto/index.js.map +0 -1
- package/dist/hooks.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index2.js.map +0 -1
- package/dist/parser/index.js.map +0 -1
- package/dist/proxy/index.js.map +0 -1
- package/dist/proxy/server.js.map +0 -1
- package/dist/proxy/vite.js.map +0 -1
- package/dist/relayProxyServer.js.map +0 -1
- package/dist/signer-response.js +0 -1
- package/dist/signer-response.js.map +0 -1
- package/dist/utils.js.map +0 -1
- package/dist/worker-message.js.map +0 -1
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,357 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { nip19 as $, generateSecretKey as B, getPublicKey as A } from "nostr-tools";
|
|
2
|
+
import { g as G } from "./index2.js";
|
|
3
|
+
import { b as N } from "./NarrowTypes.js";
|
|
4
|
+
import { l as ee, a0 as te, _ as ne, f as se, j as ae, g as oe, $ as ie, a1 as re, p as ce, r as de, H as le, J as ue, D as pe, F as ge, B as he, L as fe, t as ye, v as we, x as ke, z as me, N as Ke, P as ve, R as De, T as Se, V as xe, a5 as Ce, a3 as be, X as Me, a4 as Te, e as Be, d as Ae, Z as Ie, n as Pe, a2 as Re, k as Ee, h as $e, c as Ge, o as Ne, q as Le, G as Ve, I as ze, C as Ze, E as _e, A as He, K as Oe, s as Ue, u as Qe, w as Fe, y as We, M as je, O as Je, Q as Xe, S as Ye, U as qe, W as et, a as tt, i as nt, Y as st, m as at } from "./NarrowTypes.js";
|
|
5
|
+
import { J as h, t as d, O as m, Q as M, T, U as I, X as L, Y as V, Z as z, _ as Z, $ as _ } from "./worker-message.js";
|
|
6
|
+
class F {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.knownRelays = /* @__PURE__ */ new Map(), this.incomingCount = 0, this.resolvedCount = 0;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Feed a new message into the tracker
|
|
12
|
+
*/
|
|
13
|
+
handleMessage(i) {
|
|
14
|
+
const r = N(i);
|
|
15
|
+
if (!r) return;
|
|
16
|
+
const l = r.relayUrl();
|
|
17
|
+
l && !this.knownRelays.has(l) && (this.incomingCount++, this.knownRelays.set(l, r)), this.isResolved(r) && this.resolvedCount++;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Define what counts as a "resolved" connection.
|
|
21
|
+
* Adjust based on your real ConnectionStatus enum/shape.
|
|
22
|
+
*/
|
|
23
|
+
isResolved(i) {
|
|
24
|
+
var _a;
|
|
25
|
+
return ((_a = i.status()) == null ? void 0 : _a.toString()) === "EOSE";
|
|
26
|
+
}
|
|
27
|
+
/** Total connection attempts processed */
|
|
28
|
+
get totalIncoming() {
|
|
29
|
+
return this.incomingCount;
|
|
30
|
+
}
|
|
31
|
+
/** How many actually resolved */
|
|
32
|
+
get totalResolved() {
|
|
33
|
+
return this.resolvedCount;
|
|
34
|
+
}
|
|
35
|
+
/** Quick ratio (0...1) of resolved vs incoming */
|
|
36
|
+
get resolutionRate() {
|
|
37
|
+
return this.incomingCount === 0 ? 0 : this.resolvedCount / this.incomingCount;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const t = new TextEncoder();
|
|
41
|
+
async function W(c) {
|
|
42
|
+
var _a, _b, _c, _d, _e2, _f, _g, _h, _i;
|
|
43
|
+
const i = [], r = (e) => new h(t.encode("text"), t.encode(e), d.NONE, null), l = (e) => new h(
|
|
44
|
+
t.encode("image"),
|
|
45
|
+
t.encode(e),
|
|
46
|
+
d.ImageData,
|
|
47
|
+
new M(t.encode(e), null)
|
|
48
|
+
), f = (e) => new h(
|
|
49
|
+
t.encode("video"),
|
|
50
|
+
t.encode(e),
|
|
51
|
+
d.VideoData,
|
|
52
|
+
new T(t.encode(e), null)
|
|
53
|
+
), w = (e, s) => {
|
|
54
|
+
const n = e.indexOf(`
|
|
55
|
+
`);
|
|
56
|
+
let p = null, a = e;
|
|
57
|
+
if (n !== -1) {
|
|
58
|
+
const g = e.slice(0, n).trim(), S = e.slice(n + 1);
|
|
59
|
+
g && /^[a-zA-Z0-9+#\.\-_]+$/.test(g) && (p = g, a = S);
|
|
60
|
+
}
|
|
61
|
+
return new h(
|
|
62
|
+
t.encode("code"),
|
|
63
|
+
t.encode(s),
|
|
64
|
+
d.CodeData,
|
|
65
|
+
new L(t.encode(p || ""), t.encode(a))
|
|
66
|
+
);
|
|
67
|
+
}, y = (e) => new h(
|
|
68
|
+
t.encode("cashu"),
|
|
69
|
+
t.encode(e),
|
|
70
|
+
d.CashuData,
|
|
71
|
+
new V(t.encode(e))
|
|
72
|
+
), K = (e) => new h(
|
|
73
|
+
t.encode("hashtag"),
|
|
74
|
+
t.encode(`#${e}`),
|
|
75
|
+
d.HashtagData,
|
|
76
|
+
new z(t.encode(e))
|
|
77
|
+
), v = (e) => new h(
|
|
78
|
+
t.encode("link"),
|
|
79
|
+
t.encode(e),
|
|
80
|
+
d.LinkPreviewData,
|
|
81
|
+
new Z(t.encode(e), null, null, null)
|
|
82
|
+
), P = (e, s) => {
|
|
83
|
+
try {
|
|
84
|
+
const n = $.decode(e), p = n.type;
|
|
85
|
+
let a = null, g = [], S = null, b = BigInt(0);
|
|
86
|
+
const o = n.data;
|
|
87
|
+
switch (p) {
|
|
88
|
+
case "npub":
|
|
89
|
+
a = o;
|
|
90
|
+
break;
|
|
91
|
+
case "nprofile":
|
|
92
|
+
a = o.pubkey, g = Array.isArray(o.relays) ? o.relays : [];
|
|
93
|
+
break;
|
|
94
|
+
case "note":
|
|
95
|
+
a = o;
|
|
96
|
+
break;
|
|
97
|
+
case "nevent":
|
|
98
|
+
a = o.id, g = Array.isArray(o.relays) ? o.relays : [], S = typeof o.author == "string" ? o.author : null, typeof o.kind == "number" && (b = BigInt(o.kind));
|
|
99
|
+
break;
|
|
100
|
+
case "naddr":
|
|
101
|
+
a = `${o.kind}:${o.pubkey}:${o.identifier}`, g = Array.isArray(o.relays) ? o.relays : [], typeof o.kind == "number" && (b = BigInt(o.kind)), S = typeof o.pubkey == "string" ? o.pubkey : null;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return a || (a = e), new h(
|
|
105
|
+
t.encode(p),
|
|
106
|
+
t.encode(s),
|
|
107
|
+
d.NostrData,
|
|
108
|
+
new _(
|
|
109
|
+
t.encode(a),
|
|
110
|
+
t.encode(e),
|
|
111
|
+
g,
|
|
112
|
+
t.encode(S || ""),
|
|
113
|
+
b
|
|
114
|
+
)
|
|
115
|
+
);
|
|
116
|
+
} catch {
|
|
117
|
+
return r(s);
|
|
118
|
+
}
|
|
119
|
+
}, R = [
|
|
120
|
+
{
|
|
121
|
+
type: "code",
|
|
122
|
+
regex: /```([\s\S]*?)```/g,
|
|
123
|
+
processMatch: (e) => w(e[1] || "", e[0])
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
type: "cashu",
|
|
127
|
+
regex: /(cashuA[A-Za-z0-9_-]+)/g,
|
|
128
|
+
processMatch: (e) => y(e[0])
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
type: "hashtag",
|
|
132
|
+
// Match hashtags that are not part of a URL
|
|
133
|
+
regex: new RegExp(`(?<![^\\s"'(])(#[a-zA-Z0-9_]+)(?![a-zA-Z0-9_])`, "g"),
|
|
134
|
+
processMatch: (e) => K(e[0].substring(1))
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: "image",
|
|
138
|
+
regex: /(https?:\/\/\S+\.(?:jpg|jpeg|png|gif|webp|svg|ico)(?:\?\S*)?)/gi,
|
|
139
|
+
processMatch: (e) => l(e[0])
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
type: "video",
|
|
143
|
+
regex: /(https?:\/\/\S+\.(?:mp4|mov|avi|mkv|webm|m4v)(?:\?\S*)?)/gi,
|
|
144
|
+
processMatch: (e) => f(e[0])
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
type: "nostr",
|
|
148
|
+
regex: /nostr:([a-z0-9]+)/gi,
|
|
149
|
+
processMatch: (e) => {
|
|
150
|
+
const s = e[1];
|
|
151
|
+
return P(s || "", e[0]);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
type: "link",
|
|
156
|
+
regex: /(https?:\/\/\S+)(?![\)])/gi,
|
|
157
|
+
processMatch: async (e) => v(e[0])
|
|
158
|
+
}
|
|
159
|
+
], C = [];
|
|
160
|
+
for (const e of R) {
|
|
161
|
+
let s;
|
|
162
|
+
for (e.regex.lastIndex = 0; (s = e.regex.exec(c)) !== null; ) {
|
|
163
|
+
const n = s.index, p = n + s[0].length, a = await e.processMatch(s);
|
|
164
|
+
C.push({ start: n, end: p, block: a });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
C.sort((e, s) => e.start - s.start);
|
|
168
|
+
const x = [];
|
|
169
|
+
for (const e of C)
|
|
170
|
+
x.some(
|
|
171
|
+
(n) => e.start >= n.start && e.start < n.end || e.end > n.start && e.end <= n.end || e.start <= n.start && e.end >= n.end
|
|
172
|
+
) || x.push(e);
|
|
173
|
+
x.sort((e, s) => e.start - s.start);
|
|
174
|
+
let D = 0;
|
|
175
|
+
for (const { start: e, end: s, block: n } of x)
|
|
176
|
+
e > D && i.push(r(c.substring(D, e))), i.push(n), D = s;
|
|
177
|
+
D < c.length && i.push(r(c.substring(D)));
|
|
178
|
+
const k = [];
|
|
179
|
+
let u = [];
|
|
180
|
+
const E = (e) => /^\s+$/.test(e);
|
|
181
|
+
for (let e = 0; e < i.length; e++) {
|
|
182
|
+
const s = i[e];
|
|
183
|
+
if (((_a = s == null ? void 0 : s.type) == null ? void 0 : _a.toString()) === "image" || ((_b = s == null ? void 0 : s.type) == null ? void 0 : _b.toString()) === "video") {
|
|
184
|
+
u.push(s);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (!(((_c = s == null ? void 0 : s.type) == null ? void 0 : _c.toString()) === "text" && typeof ((_d = s == null ? void 0 : s.text) == null ? void 0 : _d.toString()) == "string" && E((_e2 = s.text) == null ? void 0 : _e2.toString()) && u.length > 0 && e + 1 < i.length && (((_g = (_f = i[e + 1]) == null ? void 0 : _f.type) == null ? void 0 : _g.toString()) === "image" || ((_i = (_h = i[e + 1]) == null ? void 0 : _h.type) == null ? void 0 : _i.toString()) === "video"))) {
|
|
188
|
+
if (u.length > 0) {
|
|
189
|
+
if (u.length > 1) {
|
|
190
|
+
const n = u.map((a) => {
|
|
191
|
+
if (a.dataType === d.ImageData) {
|
|
192
|
+
const g = a.data;
|
|
193
|
+
return new m(
|
|
194
|
+
new M(t.encode(g.url ?? a.text), null),
|
|
195
|
+
null
|
|
196
|
+
);
|
|
197
|
+
} else if (a.dataType === d.VideoData) {
|
|
198
|
+
const g = a.data;
|
|
199
|
+
return new m(
|
|
200
|
+
null,
|
|
201
|
+
new T(t.encode(g.url ?? a.text), null)
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return new m(null, null);
|
|
205
|
+
}), p = u.map((a) => String(a.text ?? "")).join(`
|
|
206
|
+
`);
|
|
207
|
+
k.push(
|
|
208
|
+
new h(
|
|
209
|
+
t.encode("mediaGrid"),
|
|
210
|
+
t.encode(p),
|
|
211
|
+
d.MediaGroupData,
|
|
212
|
+
new I(n)
|
|
213
|
+
)
|
|
214
|
+
);
|
|
215
|
+
} else
|
|
216
|
+
k.push(u[0]);
|
|
217
|
+
u = [];
|
|
218
|
+
}
|
|
219
|
+
k.push(s);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (u.length > 0)
|
|
223
|
+
if (u.length > 1) {
|
|
224
|
+
const e = u.map((n) => {
|
|
225
|
+
if (n.dataType === d.ImageData) {
|
|
226
|
+
const p = n.data;
|
|
227
|
+
return new m(
|
|
228
|
+
new M(t.encode(p.url ?? n.text), null),
|
|
229
|
+
null
|
|
230
|
+
);
|
|
231
|
+
} else if (n.dataType === d.VideoData) {
|
|
232
|
+
const p = n.data;
|
|
233
|
+
return new m(
|
|
234
|
+
null,
|
|
235
|
+
new T(t.encode(p.url ?? n.text), null)
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
return new m(null, null);
|
|
239
|
+
}), s = u.map((n) => String(n.text ?? "")).join(`
|
|
240
|
+
`);
|
|
241
|
+
k.push(
|
|
242
|
+
new h(
|
|
243
|
+
t.encode("mediaGrid"),
|
|
244
|
+
t.encode(s),
|
|
245
|
+
d.MediaGroupData,
|
|
246
|
+
new I(e)
|
|
247
|
+
)
|
|
248
|
+
);
|
|
249
|
+
} else
|
|
250
|
+
k.push(u[0]);
|
|
251
|
+
return k;
|
|
252
|
+
}
|
|
253
|
+
function j(c, i) {
|
|
254
|
+
const r = c[`${String(i)}Length`]();
|
|
255
|
+
return {
|
|
256
|
+
[Symbol.iterator]() {
|
|
257
|
+
let l = 0;
|
|
258
|
+
return {
|
|
259
|
+
next() {
|
|
260
|
+
for (; l < r; ) {
|
|
261
|
+
const f = c[i](l);
|
|
262
|
+
if (l++, f != null)
|
|
263
|
+
return { value: f, done: false };
|
|
264
|
+
}
|
|
265
|
+
return { value: void 0, done: true };
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function J(c, i) {
|
|
272
|
+
var _a;
|
|
273
|
+
if (!c) return [];
|
|
274
|
+
const r = (_a = c[`${String(i)}Length`]) == null ? void 0 : _a.bind(c);
|
|
275
|
+
if (!r) return [];
|
|
276
|
+
const l = r(), f = [];
|
|
277
|
+
for (let w = 0; w < l; w++) {
|
|
278
|
+
const y = c[i](w);
|
|
279
|
+
y != null && f.push(y);
|
|
280
|
+
}
|
|
281
|
+
return f;
|
|
282
|
+
}
|
|
283
|
+
async function X(c, i) {
|
|
284
|
+
const r = B(), l = A(r), f = Array.from(r).map((v) => v.toString(16).padStart(2, "0")).join(""), w = A(B()), y = new URLSearchParams();
|
|
285
|
+
for (const v of i)
|
|
286
|
+
y.append("relay", v);
|
|
287
|
+
y.set("secret", w), y.set("name", c);
|
|
288
|
+
const K = `nostrconnect://${l}?${y.toString()}`;
|
|
289
|
+
return console.log("connect url:", K), G().setNip46QR(K, f), K;
|
|
290
|
+
}
|
|
291
|
+
export {
|
|
292
|
+
F as ConnectionTracker,
|
|
293
|
+
ee as asBufferFull,
|
|
294
|
+
te as asCashuData,
|
|
295
|
+
ne as asCodeData,
|
|
296
|
+
se as asConnectionStatus,
|
|
297
|
+
ae as asCountResponse,
|
|
298
|
+
oe as asEoce,
|
|
299
|
+
ie as asHashtagData,
|
|
300
|
+
re as asImageData,
|
|
301
|
+
ce as asKind0,
|
|
302
|
+
de as asKind1,
|
|
303
|
+
le as asKind10002,
|
|
304
|
+
ue as asKind10019,
|
|
305
|
+
pe as asKind1111,
|
|
306
|
+
ge as asKind1311,
|
|
307
|
+
he as asKind17,
|
|
308
|
+
fe as asKind17375,
|
|
309
|
+
ye as asKind3,
|
|
310
|
+
we as asKind4,
|
|
311
|
+
ke as asKind6,
|
|
312
|
+
me as asKind7,
|
|
313
|
+
Ke as asKind7374,
|
|
314
|
+
ve as asKind7375,
|
|
315
|
+
De as asKind7376,
|
|
316
|
+
Se as asKind9321,
|
|
317
|
+
xe as asKind9735,
|
|
318
|
+
Ce as asLinkPreview,
|
|
319
|
+
be as asMediaGroupData,
|
|
320
|
+
Me as asNip51,
|
|
321
|
+
Te as asNostrData,
|
|
322
|
+
Be as asNostrEvent,
|
|
323
|
+
Ae as asParsedEvent,
|
|
324
|
+
Ie as asPreGeneric,
|
|
325
|
+
Pe as asValidProofs,
|
|
326
|
+
Re as asVideoData,
|
|
327
|
+
X as connectWithQRCode,
|
|
328
|
+
J as fbArray,
|
|
329
|
+
j as fbIterable,
|
|
330
|
+
Ee as isBufferFull,
|
|
331
|
+
N as isConnectionStatus,
|
|
332
|
+
$e as isCountResponse,
|
|
333
|
+
Ge as isEoce,
|
|
334
|
+
Ne as isKind0,
|
|
335
|
+
Le as isKind1,
|
|
336
|
+
Ve as isKind10002,
|
|
337
|
+
ze as isKind10019,
|
|
338
|
+
Ze as isKind1111,
|
|
339
|
+
_e as isKind1311,
|
|
340
|
+
He as isKind17,
|
|
341
|
+
Oe as isKind17375,
|
|
342
|
+
Ue as isKind3,
|
|
343
|
+
Qe as isKind4,
|
|
344
|
+
Fe as isKind6,
|
|
345
|
+
We as isKind7,
|
|
346
|
+
je as isKind7374,
|
|
347
|
+
Je as isKind7375,
|
|
348
|
+
Xe as isKind7376,
|
|
349
|
+
Ye as isKind9321,
|
|
350
|
+
qe as isKind9735,
|
|
351
|
+
et as isNip51,
|
|
352
|
+
tt as isNostrEvent,
|
|
353
|
+
nt as isParsedEvent,
|
|
354
|
+
st as isPreGeneric,
|
|
355
|
+
at as isValidProofs,
|
|
356
|
+
W as parseContent
|
|
357
|
+
};
|