@solarpunkltd/swarm-chat-js 8.1.0 → 9.0.0
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/README.md +134 -64
- package/dist/chat.d.ts +8 -6
- package/dist/index.cjs +1 -1
- package/dist/index.js +96 -96
- package/dist/message/binding.d.ts +6 -0
- package/dist/message/entry.d.ts +14 -6
- package/dist/message/index.d.ts +1 -0
- package/dist/message/message.d.ts +28 -10
- package/dist/message/ownFeed.d.ts +2 -2
- package/dist/message/personalSign.d.ts +7 -0
- package/dist/message/walletLink.d.ts +45 -0
- package/dist/message-DBi9VeRs.cjs +4 -0
- package/dist/message-DQda4_Ge.js +555 -0
- package/dist/message.cjs +1 -1
- package/dist/message.js +2 -2
- package/dist/sender.d.ts +4 -7
- package/package.json +1 -1
- package/dist/message-Bmwh3SCs.cjs +0 -3
- package/dist/message-Dbh8qrpg.js +0 -455
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
import { Bytes as e, EthAddress as t, Identifier as n, PrivateKey as r, Reference as i, Signature as a } from "@ethersphere/bee-js";
|
|
2
|
+
import { z as o } from "zod";
|
|
3
|
+
import { publicKeyToAddress as s, recoverPublicKey as c } from "@ethersphere/core-sdk/crypto";
|
|
4
|
+
//#region src/message/canonicalSignature.ts
|
|
5
|
+
var l = 115792089237316195423570985008687907852837564279074904382605163141518161494337n, ee = l / 2n;
|
|
6
|
+
function te(e, t) {
|
|
7
|
+
let n = BigInt(`0x${e}`), r = BigInt(`0x${t}`);
|
|
8
|
+
return n > 0n && n < l && r > 0n && r <= ee;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/message/personalSign.ts
|
|
12
|
+
var ne = "Ethereum Signed Message:\n", re = /* @__PURE__ */ new Set([27, 28]), ie = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/, u = new TextEncoder();
|
|
13
|
+
function ae(e) {
|
|
14
|
+
let t = u.encode(e), n = u.encode(`${ne}${t.length}`), r = new Uint8Array(n.length + t.length);
|
|
15
|
+
return r.set(n), r.set(t, n.length), r;
|
|
16
|
+
}
|
|
17
|
+
function oe(e) {
|
|
18
|
+
return Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
19
|
+
}
|
|
20
|
+
function d(e, t) {
|
|
21
|
+
let n = t.slice(2, 66), r = t.slice(66, 130), i = parseInt(t.slice(130), 16);
|
|
22
|
+
if (!re.has(i) || !te(n, r)) return null;
|
|
23
|
+
try {
|
|
24
|
+
let t = c(ae(e), BigInt(`0x${n}`), BigInt(`0x${r}`), BigInt(i));
|
|
25
|
+
return `0x${oe(s(t))}`;
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function f(e) {
|
|
31
|
+
if (!ie.test(e)) return !1;
|
|
32
|
+
let t = Date.parse(e);
|
|
33
|
+
return !Number.isNaN(t) && new Date(t).toISOString() === e;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/message/binding.ts
|
|
37
|
+
var p = "Swarm ID chat binding v1", se = 512, ce = "Site: ", le = "Chat address: ", ue = "Date: ", de = "\n", fe = 4, pe = /^0x[0-9a-f]{40}$/, me = /^[a-z0-9-]+(\.[a-z0-9-]+)*$/, he = /* @__PURE__ */ new Set([
|
|
38
|
+
"localhost",
|
|
39
|
+
"127.0.0.1",
|
|
40
|
+
"[::1]"
|
|
41
|
+
]), m = o.strictObject({
|
|
42
|
+
msg: o.string().max(512),
|
|
43
|
+
sig: o.string().regex(/^0x[0-9a-f]{130}$/, "expected 0x and 130 lowercase hex characters")
|
|
44
|
+
});
|
|
45
|
+
function ge(e, t) {
|
|
46
|
+
let n;
|
|
47
|
+
try {
|
|
48
|
+
n = new URL(e);
|
|
49
|
+
} catch {
|
|
50
|
+
return !1;
|
|
51
|
+
}
|
|
52
|
+
let r = n.protocol === "https:", i = t && n.protocol === "http:" && he.has(n.hostname);
|
|
53
|
+
return !r && !i || !i && !me.test(n.hostname) ? !1 : n.host !== "" && n.username === "" && n.password === "" && n.origin === e;
|
|
54
|
+
}
|
|
55
|
+
function h(e, t) {
|
|
56
|
+
return e.startsWith(t) ? e.slice(t.length) : null;
|
|
57
|
+
}
|
|
58
|
+
function g(e, t, n = {}) {
|
|
59
|
+
if (!m.safeParse(e).success) return {
|
|
60
|
+
ok: !1,
|
|
61
|
+
detail: "not a binding of a text and a 65 byte signature"
|
|
62
|
+
};
|
|
63
|
+
let r = e.msg.split(de);
|
|
64
|
+
if (r.length !== fe || r[0] !== "Swarm ID chat binding v1") return {
|
|
65
|
+
ok: !1,
|
|
66
|
+
detail: `not the ${fe} lines of a ${p}`
|
|
67
|
+
};
|
|
68
|
+
let i = h(r[1], ce), a = h(r[2], le), o = h(r[3], ue);
|
|
69
|
+
if (i === null || !ge(i, n.allowLocalHttp === !0)) return {
|
|
70
|
+
ok: !1,
|
|
71
|
+
detail: "the binding does not name a clean site origin"
|
|
72
|
+
};
|
|
73
|
+
if (a === null || !pe.test(a)) return {
|
|
74
|
+
ok: !1,
|
|
75
|
+
detail: "the binding does not name a chat address as 0x and 40 lowercase hex characters"
|
|
76
|
+
};
|
|
77
|
+
if (o === null || !f(o)) return {
|
|
78
|
+
ok: !1,
|
|
79
|
+
detail: "the binding date is not ISO 8601 UTC with milliseconds"
|
|
80
|
+
};
|
|
81
|
+
if (a !== `0x${t}`) return {
|
|
82
|
+
ok: !1,
|
|
83
|
+
detail: "the binding is for another chat address than addr"
|
|
84
|
+
};
|
|
85
|
+
if (n.origin !== void 0 && i !== n.origin) return {
|
|
86
|
+
ok: !1,
|
|
87
|
+
detail: `the binding is for ${i}, not ${n.origin}`
|
|
88
|
+
};
|
|
89
|
+
let s = d(e.msg, e.sig);
|
|
90
|
+
return s === null ? {
|
|
91
|
+
ok: !1,
|
|
92
|
+
detail: "the binding signature recovers no account"
|
|
93
|
+
} : {
|
|
94
|
+
ok: !0,
|
|
95
|
+
identity: {
|
|
96
|
+
account: s,
|
|
97
|
+
site: i,
|
|
98
|
+
date: o
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/message/walletLink.ts
|
|
104
|
+
var _ = "Swarm ID wallet link v1", _e = "I link this wallet to the Swarm ID account below, so sites may show my ENS name beside its messages.", ve = 320, ye = "Account: ", be = "Wallet: ", xe = "Date: ", Se = "\n", v = 5, y = /^0x[0-9a-f]{40}$/, b = o.string().regex(/^0x[0-9a-f]{130}$/, "expected 0x and 130 lowercase hex characters"), x = o.strictObject({
|
|
105
|
+
msg: o.string().max(320),
|
|
106
|
+
wsig: b,
|
|
107
|
+
asig: b
|
|
108
|
+
});
|
|
109
|
+
function S(e, t) {
|
|
110
|
+
return e.startsWith(t) ? e.slice(t.length) : null;
|
|
111
|
+
}
|
|
112
|
+
function C(e, t) {
|
|
113
|
+
if (!x.safeParse(e).success) return {
|
|
114
|
+
ok: !1,
|
|
115
|
+
detail: "not a wallet link of a text and two 65 byte signatures"
|
|
116
|
+
};
|
|
117
|
+
let n = e.msg.split(Se);
|
|
118
|
+
if (n.length !== v || n[0] !== "Swarm ID wallet link v1") return {
|
|
119
|
+
ok: !1,
|
|
120
|
+
detail: `not the ${v} lines of a ${_}`
|
|
121
|
+
};
|
|
122
|
+
if (n[1] !== "I link this wallet to the Swarm ID account below, so sites may show my ENS name beside its messages.") return {
|
|
123
|
+
ok: !1,
|
|
124
|
+
detail: `the wallet link's second line is not the ${_} statement`
|
|
125
|
+
};
|
|
126
|
+
let r = S(n[2], ye), i = S(n[3], be), a = S(n[4], xe);
|
|
127
|
+
return r === null || !y.test(r) ? {
|
|
128
|
+
ok: !1,
|
|
129
|
+
detail: "the wallet link does not name an account as 0x and 40 lowercase hex characters"
|
|
130
|
+
} : i === null || !y.test(i) ? {
|
|
131
|
+
ok: !1,
|
|
132
|
+
detail: "the wallet link does not name a wallet as 0x and 40 lowercase hex characters"
|
|
133
|
+
} : a === null || !f(a) ? {
|
|
134
|
+
ok: !1,
|
|
135
|
+
detail: "the wallet link date is not ISO 8601 UTC with milliseconds"
|
|
136
|
+
} : r === t ? d(e.msg, e.wsig) === i ? d(e.msg, e.asig) === r ? {
|
|
137
|
+
ok: !0,
|
|
138
|
+
wallet: i,
|
|
139
|
+
account: r,
|
|
140
|
+
date: a
|
|
141
|
+
} : {
|
|
142
|
+
ok: !1,
|
|
143
|
+
detail: "the account signature does not recover the account the link names"
|
|
144
|
+
} : {
|
|
145
|
+
ok: !1,
|
|
146
|
+
detail: "the wallet signature does not recover the wallet the link names"
|
|
147
|
+
} : {
|
|
148
|
+
ok: !1,
|
|
149
|
+
detail: `the wallet link is for ${r}, not the binding's account ${t}`
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/message/message.ts
|
|
154
|
+
var Ce = 9, w = 3072, we = 128, Te = 500, Ee = 20, T = {
|
|
155
|
+
TEXT: "text",
|
|
156
|
+
THREAD: "thread",
|
|
157
|
+
REACTION: "reaction"
|
|
158
|
+
}, E = {
|
|
159
|
+
GATEWAY: "gateway",
|
|
160
|
+
OWN_STAMP: "own-stamp"
|
|
161
|
+
};
|
|
162
|
+
function D(e) {
|
|
163
|
+
let t = 0;
|
|
164
|
+
for (let n of e) t++;
|
|
165
|
+
return t;
|
|
166
|
+
}
|
|
167
|
+
function O(e) {
|
|
168
|
+
return o.string().regex(RegExp(`^[0-9a-f]{${e}}$`), `expected ${e} lowercase hex characters`);
|
|
169
|
+
}
|
|
170
|
+
function k(e, t) {
|
|
171
|
+
return o.string().refine((n) => {
|
|
172
|
+
let r = D(n);
|
|
173
|
+
return r >= e && r <= t;
|
|
174
|
+
}, `expected ${e} to ${t} characters`);
|
|
175
|
+
}
|
|
176
|
+
var A = /(?![\u200c\u200d])[\p{Cf}\p{Cc}\u2800\u115f\u1160\u3164\uffa0]|\u034f|\u17b4|\u17b5/u, De = /[\p{Default_Ignorable_Code_Point}\p{Mn}\p{Me}\u2800]/gu, j = Object.fromEntries([
|
|
177
|
+
...[..."℮ꬲеҽ⋿ΕЕⴹᎬꗋꓰ𑢦𑢮𐊆"].map((e) => [e, "e"]),
|
|
178
|
+
...[..."⊤⟙🝨𝍳ΤⲦТтߠᎢꔋㄒꓔ𖼊𑢼𐊗𐊱𐌕丅"].map((e) => [e, "t"]),
|
|
179
|
+
...[..."һҺႹհᏂΗⲎНнᎻᕼꓧ𐋏"].map((e) => [e, "h"])
|
|
180
|
+
]), Oe = RegExp(`[${Object.keys(j).join("")}]`, "gu"), ke = /[\u3002\u0660\u06f0\u0701\u0702\ua4f8\ua60e\uabec\u{10a50}\u{1d16d}\u{1ecae}]/gu, Ae = /[\p{Z}.]+$/u, M = ".eth";
|
|
181
|
+
function je(e) {
|
|
182
|
+
return e.normalize("NFKD").replace(ke, ".").replace(De, "").replace(Oe, (e) => j[e] ?? e).toLowerCase().trim().replace(Ae, "");
|
|
183
|
+
}
|
|
184
|
+
function N(e) {
|
|
185
|
+
return je(e).endsWith(M);
|
|
186
|
+
}
|
|
187
|
+
function Me(e, t) {
|
|
188
|
+
return k(e, t).refine((e) => !A.test(e), "expected no format or control characters").refine((e) => !N(e), `expected a name not ending in ${M}, which ENS names keep`);
|
|
189
|
+
}
|
|
190
|
+
function Ne(e) {
|
|
191
|
+
let t = D(e);
|
|
192
|
+
return t < 1 || t > 20 ? "length" : A.test(e) ? "invisible" : N(e) ? "ens-like" : null;
|
|
193
|
+
}
|
|
194
|
+
var P = O(32), F = o.strictObject({
|
|
195
|
+
v: o.literal(9),
|
|
196
|
+
topic: k(1, 128),
|
|
197
|
+
id: P,
|
|
198
|
+
type: o.enum([
|
|
199
|
+
T.TEXT,
|
|
200
|
+
T.THREAD,
|
|
201
|
+
T.REACTION
|
|
202
|
+
]),
|
|
203
|
+
target: o.union([o.literal(""), P]),
|
|
204
|
+
text: k(1, 500),
|
|
205
|
+
name: Me(1, 20),
|
|
206
|
+
addr: O(40),
|
|
207
|
+
ts: o.number().int().nonnegative().max(2 ** 53 - 1),
|
|
208
|
+
via: o.enum([E.GATEWAY, E.OWN_STAMP]),
|
|
209
|
+
idb: m.optional(),
|
|
210
|
+
wl: x.optional(),
|
|
211
|
+
sig: O(130)
|
|
212
|
+
}).refine((e) => e.type === T.TEXT == (e.target === ""), {
|
|
213
|
+
message: "a text message has no target, a thread reply or a reaction names one",
|
|
214
|
+
path: ["target"]
|
|
215
|
+
}).refine((e) => e.wl === void 0 || e.idb !== void 0, {
|
|
216
|
+
message: "a wallet link is carried only beside a chat binding, whose account it names",
|
|
217
|
+
path: ["wl"]
|
|
218
|
+
}), I = class extends Error {
|
|
219
|
+
constructor(e, t) {
|
|
220
|
+
super(`chat message refused (${e}): ${t}`), this.reason = e, this.name = "ChatMessageError";
|
|
221
|
+
}
|
|
222
|
+
}, L = new TextEncoder(), Pe = "1b", Fe = "1c", Ie = new TextDecoder("utf-8", { fatal: !0 });
|
|
223
|
+
function R(e) {
|
|
224
|
+
return L.encode(JSON.stringify([
|
|
225
|
+
e.v,
|
|
226
|
+
e.topic,
|
|
227
|
+
e.id,
|
|
228
|
+
e.type,
|
|
229
|
+
e.target,
|
|
230
|
+
e.text,
|
|
231
|
+
e.name,
|
|
232
|
+
e.addr,
|
|
233
|
+
e.ts,
|
|
234
|
+
e.via,
|
|
235
|
+
e.idb?.msg ?? "",
|
|
236
|
+
e.idb?.sig ?? "",
|
|
237
|
+
...e.wl ? [
|
|
238
|
+
e.wl.msg,
|
|
239
|
+
e.wl.wsig,
|
|
240
|
+
e.wl.asig
|
|
241
|
+
] : []
|
|
242
|
+
]));
|
|
243
|
+
}
|
|
244
|
+
function z(e) {
|
|
245
|
+
let t = {
|
|
246
|
+
v: e.v,
|
|
247
|
+
topic: e.topic,
|
|
248
|
+
id: e.id,
|
|
249
|
+
type: e.type,
|
|
250
|
+
target: e.target,
|
|
251
|
+
text: e.text,
|
|
252
|
+
name: e.name,
|
|
253
|
+
addr: e.addr,
|
|
254
|
+
ts: e.ts,
|
|
255
|
+
via: e.via,
|
|
256
|
+
...e.idb ? { idb: {
|
|
257
|
+
msg: e.idb.msg,
|
|
258
|
+
sig: e.idb.sig
|
|
259
|
+
} } : {},
|
|
260
|
+
...e.wl ? { wl: {
|
|
261
|
+
msg: e.wl.msg,
|
|
262
|
+
wsig: e.wl.wsig,
|
|
263
|
+
asig: e.wl.asig
|
|
264
|
+
} } : {},
|
|
265
|
+
sig: e.sig
|
|
266
|
+
};
|
|
267
|
+
return L.encode(JSON.stringify(t));
|
|
268
|
+
}
|
|
269
|
+
function B() {
|
|
270
|
+
let e = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
271
|
+
return Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
272
|
+
}
|
|
273
|
+
function V(e) {
|
|
274
|
+
return e.issues.map((e) => `${e.path.join(".") || "message"}: ${e.message}`).join(", ");
|
|
275
|
+
}
|
|
276
|
+
function Le(e, t) {
|
|
277
|
+
let n = e instanceof r ? e : new r(e), i = {
|
|
278
|
+
v: 9,
|
|
279
|
+
topic: t.topic,
|
|
280
|
+
id: t.id ?? B(),
|
|
281
|
+
type: t.type,
|
|
282
|
+
target: t.target ?? "",
|
|
283
|
+
text: t.text,
|
|
284
|
+
name: t.name,
|
|
285
|
+
addr: n.publicKey().address().toHex(),
|
|
286
|
+
ts: t.ts ?? Date.now(),
|
|
287
|
+
via: t.via,
|
|
288
|
+
...t.idb ? { idb: t.idb } : {},
|
|
289
|
+
...t.wl ? { wl: t.wl } : {}
|
|
290
|
+
}, a = {
|
|
291
|
+
...i,
|
|
292
|
+
sig: "0".repeat(130)
|
|
293
|
+
}, o = F.safeParse(a);
|
|
294
|
+
if (!o.success) throw new I("shape", V(o.error));
|
|
295
|
+
let s = z(a).byteLength;
|
|
296
|
+
if (s > 3072) throw new I("too-large", `${s} bytes, the cap is ${w}`);
|
|
297
|
+
if (i.idb) {
|
|
298
|
+
let e = g(i.idb, i.addr, { allowLocalHttp: !0 });
|
|
299
|
+
if (!e.ok) throw new I("binding", e.detail);
|
|
300
|
+
if (i.wl) {
|
|
301
|
+
let t = C(i.wl, e.identity.account);
|
|
302
|
+
if (!t.ok) throw new I("binding", `wallet link: ${t.detail}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
let c = {
|
|
306
|
+
...i,
|
|
307
|
+
sig: n.sign(R(i)).toHex()
|
|
308
|
+
};
|
|
309
|
+
return {
|
|
310
|
+
message: c,
|
|
311
|
+
bytes: z(c)
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
function H(e) {
|
|
315
|
+
let t = e.sig.slice(128);
|
|
316
|
+
if (t !== Pe && t !== Fe || !te(e.sig.slice(0, 64), e.sig.slice(64, 128))) return !1;
|
|
317
|
+
try {
|
|
318
|
+
return new a(e.sig).recoverPublicKey(R(e)).address().toHex() === e.addr;
|
|
319
|
+
} catch {
|
|
320
|
+
return !1;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function U(e, t) {
|
|
324
|
+
let n = F.safeParse(e);
|
|
325
|
+
if (!n.success) return {
|
|
326
|
+
ok: !1,
|
|
327
|
+
reason: "shape",
|
|
328
|
+
detail: V(n.error)
|
|
329
|
+
};
|
|
330
|
+
let r = n.data;
|
|
331
|
+
if (!H(r)) return {
|
|
332
|
+
ok: !1,
|
|
333
|
+
reason: "signature",
|
|
334
|
+
detail: "the signature was not made by addr over these fields"
|
|
335
|
+
};
|
|
336
|
+
if (!r.idb) return {
|
|
337
|
+
ok: !0,
|
|
338
|
+
message: r,
|
|
339
|
+
identity: null
|
|
340
|
+
};
|
|
341
|
+
if (typeof t?.origin != "string") return {
|
|
342
|
+
ok: !1,
|
|
343
|
+
reason: "binding",
|
|
344
|
+
detail: "no origin was given to check the binding against"
|
|
345
|
+
};
|
|
346
|
+
let i = g(r.idb, r.addr, t);
|
|
347
|
+
if (!i.ok) return {
|
|
348
|
+
ok: !1,
|
|
349
|
+
reason: "binding",
|
|
350
|
+
detail: i.detail
|
|
351
|
+
};
|
|
352
|
+
if (!r.wl) return {
|
|
353
|
+
ok: !0,
|
|
354
|
+
message: r,
|
|
355
|
+
identity: i.identity
|
|
356
|
+
};
|
|
357
|
+
let a = C(r.wl, i.identity.account);
|
|
358
|
+
return a.ok ? {
|
|
359
|
+
ok: !0,
|
|
360
|
+
message: r,
|
|
361
|
+
identity: {
|
|
362
|
+
...i.identity,
|
|
363
|
+
wallet: a.wallet
|
|
364
|
+
}
|
|
365
|
+
} : {
|
|
366
|
+
ok: !1,
|
|
367
|
+
reason: "binding",
|
|
368
|
+
detail: `wallet link: ${a.detail}`
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function Re(e, t) {
|
|
372
|
+
if (e.byteLength > 3072) return {
|
|
373
|
+
ok: !1,
|
|
374
|
+
reason: "too-large",
|
|
375
|
+
detail: `${e.byteLength} bytes, the cap is ${w}`
|
|
376
|
+
};
|
|
377
|
+
let n;
|
|
378
|
+
try {
|
|
379
|
+
n = Ie.decode(e);
|
|
380
|
+
} catch {
|
|
381
|
+
return {
|
|
382
|
+
ok: !1,
|
|
383
|
+
reason: "not-utf8",
|
|
384
|
+
detail: "the payload is not valid UTF-8"
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
let r;
|
|
388
|
+
try {
|
|
389
|
+
r = JSON.parse(n);
|
|
390
|
+
} catch {
|
|
391
|
+
return {
|
|
392
|
+
ok: !1,
|
|
393
|
+
reason: "not-json",
|
|
394
|
+
detail: "the payload is not JSON"
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
return U(r, t);
|
|
398
|
+
}
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region src/message/ownFeed.ts
|
|
401
|
+
var W = "swarm-chat-own-feed-v1:";
|
|
402
|
+
function ze(e) {
|
|
403
|
+
return `${W}${e}`;
|
|
404
|
+
}
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region src/message/entry.ts
|
|
407
|
+
var Be = 4096, Ve = o.string().regex(/^[0-9a-f]{64}([0-9a-f]{64})?$/, "expected a 64 or 128 hex character reference"), G = o.number().int().nonnegative().max(2 ** 53 - 1), K = o.strictObject({
|
|
408
|
+
ref: Ve,
|
|
409
|
+
toSeq: G
|
|
410
|
+
}), q = o.strictObject({
|
|
411
|
+
v: o.literal(9),
|
|
412
|
+
seq: G,
|
|
413
|
+
at: G,
|
|
414
|
+
msg: F,
|
|
415
|
+
history: K.nullable()
|
|
416
|
+
}), J = o.strictObject({
|
|
417
|
+
seq: G,
|
|
418
|
+
at: G,
|
|
419
|
+
msg: F
|
|
420
|
+
}), Y = o.strictObject({
|
|
421
|
+
v: o.literal(9),
|
|
422
|
+
topic: o.string().min(1),
|
|
423
|
+
fromSeq: G,
|
|
424
|
+
toSeq: G,
|
|
425
|
+
messages: o.array(o.unknown()),
|
|
426
|
+
prev: K.nullable()
|
|
427
|
+
}).refine((e) => e.fromSeq <= e.toSeq, {
|
|
428
|
+
message: "fromSeq is after toSeq",
|
|
429
|
+
path: ["fromSeq"]
|
|
430
|
+
}), He = new TextDecoder("utf-8", { fatal: !0 });
|
|
431
|
+
function X(e) {
|
|
432
|
+
let t;
|
|
433
|
+
try {
|
|
434
|
+
t = He.decode(e);
|
|
435
|
+
} catch {
|
|
436
|
+
return {
|
|
437
|
+
ok: !1,
|
|
438
|
+
reason: "not-utf8",
|
|
439
|
+
detail: "the payload is not valid UTF-8"
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
try {
|
|
443
|
+
return {
|
|
444
|
+
ok: !0,
|
|
445
|
+
value: JSON.parse(t)
|
|
446
|
+
};
|
|
447
|
+
} catch {
|
|
448
|
+
return {
|
|
449
|
+
ok: !1,
|
|
450
|
+
reason: "not-json",
|
|
451
|
+
detail: "the payload is not JSON"
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function Z(e) {
|
|
456
|
+
return e.issues.map((e) => `${e.path.join(".") || "value"}: ${e.message}`).join(", ");
|
|
457
|
+
}
|
|
458
|
+
function Ue(e, t, n) {
|
|
459
|
+
let r = X(e);
|
|
460
|
+
if (!r.ok) return r;
|
|
461
|
+
let i = q.safeParse(r.value);
|
|
462
|
+
return i.success ? i.data.seq === t ? i.data.msg.topic === n ? {
|
|
463
|
+
ok: !0,
|
|
464
|
+
value: i.data
|
|
465
|
+
} : {
|
|
466
|
+
ok: !1,
|
|
467
|
+
reason: "mismatch",
|
|
468
|
+
detail: "the message belongs to another chat"
|
|
469
|
+
} : {
|
|
470
|
+
ok: !1,
|
|
471
|
+
reason: "mismatch",
|
|
472
|
+
detail: `seq ${i.data.seq} at index ${t}`
|
|
473
|
+
} : {
|
|
474
|
+
ok: !1,
|
|
475
|
+
reason: "shape",
|
|
476
|
+
detail: Z(i.error)
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
function We(e, t, n) {
|
|
480
|
+
let r = X(e);
|
|
481
|
+
if (!r.ok) return r;
|
|
482
|
+
let i = Y.safeParse(r.value);
|
|
483
|
+
if (!i.success) return {
|
|
484
|
+
ok: !1,
|
|
485
|
+
reason: "shape",
|
|
486
|
+
detail: Z(i.error)
|
|
487
|
+
};
|
|
488
|
+
if (i.data.topic !== t || i.data.toSeq !== n.toSeq) return {
|
|
489
|
+
ok: !1,
|
|
490
|
+
reason: "mismatch",
|
|
491
|
+
detail: "the file is not the one its link names"
|
|
492
|
+
};
|
|
493
|
+
let { fromSeq: a, toSeq: o, prev: s } = i.data, c = [], l = 0;
|
|
494
|
+
for (let e of i.data.messages) {
|
|
495
|
+
let n = J.safeParse(e);
|
|
496
|
+
n.success && n.data.seq >= a && n.data.seq <= o && n.data.msg.topic === t ? c.push(n.data) : l++;
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
ok: !0,
|
|
500
|
+
value: {
|
|
501
|
+
topic: t,
|
|
502
|
+
fromSeq: a,
|
|
503
|
+
toSeq: o,
|
|
504
|
+
rows: c,
|
|
505
|
+
prev: s,
|
|
506
|
+
skipped: l
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/message/note.ts
|
|
512
|
+
var Ge = 1, Ke = 2e3, qe = 3e4, Je = 256, Ye = o.strictObject({
|
|
513
|
+
v: o.literal(1),
|
|
514
|
+
newest: o.number().int().min(-1).max(2 ** 53 - 1),
|
|
515
|
+
writtenAt: o.number().int().nonnegative().max(2 ** 53 - 1)
|
|
516
|
+
});
|
|
517
|
+
function Q(e) {
|
|
518
|
+
if (!Number.isInteger(e) || e <= 0) throw RangeError(`a note slot is a positive whole number of milliseconds, not ${e}`);
|
|
519
|
+
}
|
|
520
|
+
function Xe(e, t) {
|
|
521
|
+
return Q(t), Math.floor(e / t);
|
|
522
|
+
}
|
|
523
|
+
function Ze(e, t) {
|
|
524
|
+
return Q(t), (e + 1) * t;
|
|
525
|
+
}
|
|
526
|
+
function Qe(e, t, n) {
|
|
527
|
+
return `${e}/note/${t}/${n}`;
|
|
528
|
+
}
|
|
529
|
+
function $(e, t, r) {
|
|
530
|
+
return n.fromString(Qe(e, t, r));
|
|
531
|
+
}
|
|
532
|
+
function $e(n, r, a, o) {
|
|
533
|
+
let s = $(n, r, a);
|
|
534
|
+
return new i(e.keccak256(e.concat(s.toUint8Array(), new t(o).toUint8Array())));
|
|
535
|
+
}
|
|
536
|
+
var et = new TextEncoder(), tt = new TextDecoder("utf-8", { fatal: !0 });
|
|
537
|
+
function nt(e) {
|
|
538
|
+
let t = {
|
|
539
|
+
v: 1,
|
|
540
|
+
newest: e.newest,
|
|
541
|
+
writtenAt: e.writtenAt
|
|
542
|
+
};
|
|
543
|
+
return et.encode(JSON.stringify(t));
|
|
544
|
+
}
|
|
545
|
+
function rt(e) {
|
|
546
|
+
if (e.length > 256) return null;
|
|
547
|
+
try {
|
|
548
|
+
let t = Ye.safeParse(JSON.parse(tt.decode(e)));
|
|
549
|
+
return t.success ? t.data : null;
|
|
550
|
+
} catch {
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
//#endregion
|
|
555
|
+
export { F as A, ve as B, w as C, Ce as D, we as E, H as F, p as G, _ as H, B as I, g as J, se as K, Re as L, Le as M, Ne as N, T as O, z as P, R, I as S, Te as T, C as U, _e as V, x as W, J as _, nt as a, W as b, Qe as c, rt as d, Ye as f, K as g, Y as h, Ge as i, D as j, E as k, Ze as l, q as m, Ke as n, $e as o, Be as p, m as q, Je as r, $ as s, qe as t, Xe as u, Ue as v, Ee as w, ze as x, We as y, U as z };
|
package/dist/message.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./message-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./message-DBi9VeRs.cjs");exports.CHAT_BINDING_TITLE=e.G,exports.ChatMessageError=e.S,exports.DEFAULT_NOTE_HEARTBEAT_MS=e.t,exports.DEFAULT_NOTE_SLOT_MS=e.n,exports.MAX_BINDING_CHARACTERS=e.K,exports.MAX_ENTRY_BYTES=e.p,exports.MAX_MESSAGE_BYTES=e.C,exports.MAX_NAME_CHARACTERS=e.w,exports.MAX_NOTE_BYTES=e.r,exports.MAX_TEXT_CHARACTERS=e.T,exports.MAX_TOPIC_CHARACTERS=e.E,exports.MAX_WALLET_LINK_CHARACTERS=e.B,exports.MESSAGE_VERSION=e.D,exports.MessageType=e.O,exports.MessageVia=e.k,exports.NOTE_VERSION=e.i,exports.OWN_FEED_TOPIC_PREFIX=e.b,exports.WALLET_LINK_STATEMENT=e.V,exports.WALLET_LINK_TITLE=e.H,exports.chatBindingSchema=e.q,exports.chatMessageSchema=e.A,exports.checkChatBinding=e.J,exports.checkWalletLink=e.U,exports.countCharacters=e.j,exports.createChatMessage=e.M,exports.displayNameProblem=e.N,exports.encodeChatMessage=e.P,exports.encodeSlotNote=e.a,exports.feedEntrySchema=e.m,exports.hasValidSignature=e.F,exports.historyFileSchema=e.h,exports.historyLinkSchema=e.g,exports.historyRowSchema=e._,exports.newMessageId=e.I,exports.noteAddress=e.o,exports.noteIdentifier=e.s,exports.noteIdentifierText=e.c,exports.noteSlotEnd=e.l,exports.noteSlotOf=e.u,exports.ownFeedTopic=e.x,exports.parseChatMessage=e.L,exports.parseFeedEntry=e.v,exports.parseHistoryFile=e.y,exports.parseSlotNote=e.d,exports.signedBytes=e.R,exports.slotNoteSchema=e.f,exports.verifyChatMessage=e.z,exports.walletLinkSchema=e.W;
|
package/dist/message.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as e, B as t, C as n, D as r, E as i, F as a,
|
|
2
|
-
export {
|
|
1
|
+
import { A as e, B as t, C as n, D as r, E as i, F as a, G as o, H as s, I as c, J as l, K as u, L as d, M as f, N as p, O as m, P as h, R as g, S as _, T as v, U as y, V as b, W as x, _ as S, a as C, b as w, c as T, d as E, f as D, g as O, h as k, i as A, j, k as M, l as N, m as P, n as F, o as I, p as L, q as R, r as z, s as B, t as V, u as H, v as U, w as W, x as G, y as K, z as q } from "./message-DQda4_Ge.js";
|
|
2
|
+
export { o as CHAT_BINDING_TITLE, _ as ChatMessageError, V as DEFAULT_NOTE_HEARTBEAT_MS, F as DEFAULT_NOTE_SLOT_MS, u as MAX_BINDING_CHARACTERS, L as MAX_ENTRY_BYTES, n as MAX_MESSAGE_BYTES, W as MAX_NAME_CHARACTERS, z as MAX_NOTE_BYTES, v as MAX_TEXT_CHARACTERS, i as MAX_TOPIC_CHARACTERS, t as MAX_WALLET_LINK_CHARACTERS, r as MESSAGE_VERSION, m as MessageType, M as MessageVia, A as NOTE_VERSION, w as OWN_FEED_TOPIC_PREFIX, b as WALLET_LINK_STATEMENT, s as WALLET_LINK_TITLE, R as chatBindingSchema, e as chatMessageSchema, l as checkChatBinding, y as checkWalletLink, j as countCharacters, f as createChatMessage, p as displayNameProblem, h as encodeChatMessage, C as encodeSlotNote, P as feedEntrySchema, a as hasValidSignature, k as historyFileSchema, O as historyLinkSchema, S as historyRowSchema, c as newMessageId, I as noteAddress, B as noteIdentifier, T as noteIdentifierText, N as noteSlotEnd, H as noteSlotOf, G as ownFeedTopic, d as parseChatMessage, U as parseFeedEntry, K as parseHistoryFile, E as parseSlotNote, g as signedBytes, D as slotNoteSchema, q as verifyChatMessage, x as walletLinkSchema };
|
package/dist/sender.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PrivateKey } from '@ethersphere/bee-js';
|
|
2
|
-
import { type ChatBinding, type ChatMessage, type ChatMessageDraft, type MessageVia } from './message/index.js';
|
|
2
|
+
import { type ChatBinding, type ChatMessage, type ChatMessageDraft, type MessageVia, type WalletLink } from './message/index.js';
|
|
3
3
|
/** Writes one payload to the chat's GSOC address. Rejects when the write did not reach the node. */
|
|
4
4
|
export type GsocWrite = (payload: Uint8Array) => Promise<void>;
|
|
5
5
|
export interface SenderSettings {
|
|
@@ -26,18 +26,15 @@ export interface SenderEvents {
|
|
|
26
26
|
/** Read back from the chat feed. */
|
|
27
27
|
confirmed(message: ChatMessage): void;
|
|
28
28
|
}
|
|
29
|
-
export type SendDraft = Omit<ChatMessageDraft, 'name' | 'ts' | 'id' | 'via' | '
|
|
29
|
+
export type SendDraft = Omit<ChatMessageDraft, 'name' | 'ts' | 'id' | 'via' | 'idb' | 'wl'>;
|
|
30
30
|
/** What every message this sender signs says about who sent it and how. */
|
|
31
31
|
export interface SenderProfile {
|
|
32
32
|
name: string;
|
|
33
33
|
via: MessageVia;
|
|
34
34
|
/** The sender's Swarm ID chat binding, for a signed-in sender only. */
|
|
35
35
|
idb?: ChatBinding;
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
* the `GsocWrite` that keeps one stores it from the payload it is handed, before or after the inbox write.
|
|
39
|
-
*/
|
|
40
|
-
own?: boolean;
|
|
36
|
+
/** The sender's Swarm ID wallet link, beside `idb`, for a sender who shows an ENS name. */
|
|
37
|
+
wl?: WalletLink;
|
|
41
38
|
}
|
|
42
39
|
/**
|
|
43
40
|
* Sends signed messages as GSOC writes and keeps each one pending until the chat feed shows it. A pending message is
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
let e=require("@ethersphere/bee-js"),t=require("zod"),n=require("@ethersphere/core-sdk/crypto");var r=115792089237316195423570985008687907852837564279074904382605163141518161494337n,i=r/2n;function a(e,t){let n=BigInt(`0x${e}`),a=BigInt(`0x${t}`);return n>0n&&n<r&&a>0n&&a<=i}var o=`Swarm ID chat binding v1`,s=512,c=`Site: `,l=`Chat address: `,ee=`Date: `,te=`
|
|
2
|
-
`,u=4,d=`Ethereum Signed Message:
|
|
3
|
-
`,ne=new Set([27,28]),f=/^0x[0-9a-f]{40}$/,p=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/,m=/^[a-z0-9-]+(\.[a-z0-9-]+)*$/,re=new Set([`localhost`,`127.0.0.1`,`[::1]`]),h=t.z.strictObject({msg:t.z.string().max(512),sig:t.z.string().regex(/^0x[0-9a-f]{130}$/,`expected 0x and 130 lowercase hex characters`)}),g=new TextEncoder;function ie(e,t){let n;try{n=new URL(e)}catch{return!1}let r=n.protocol===`https:`,i=t&&n.protocol===`http:`&&re.has(n.hostname);return!r&&!i||!i&&!m.test(n.hostname)?!1:n.host!==``&&n.username===``&&n.password===``&&n.origin===e}function _(e){if(!p.test(e))return!1;let t=Date.parse(e);return!Number.isNaN(t)&&new Date(t).toISOString()===e}function v(e,t){return e.startsWith(t)?e.slice(t.length):null}function ae(e){let t=g.encode(e),n=g.encode(`${d}${t.length}`),r=new Uint8Array(n.length+t.length);return r.set(n),r.set(t,n.length),r}function oe(e){return Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}function y(e,t){let r=t.slice(2,66),i=t.slice(66,130),o=parseInt(t.slice(130),16);if(!ne.has(o)||!a(r,i))return null;try{let t=(0,n.recoverPublicKey)(ae(e),BigInt(`0x${r}`),BigInt(`0x${i}`),BigInt(o));return`0x${oe((0,n.publicKeyToAddress)(t))}`}catch{return null}}function b(e,t,n={}){if(!h.safeParse(e).success)return{ok:!1,detail:`not a binding of a text and a 65 byte signature`};let r=e.msg.split(te);if(r.length!==u||r[0]!==`Swarm ID chat binding v1`)return{ok:!1,detail:`not the ${u} lines of a ${o}`};let i=v(r[1],c),a=v(r[2],l),s=v(r[3],ee);if(i===null||!ie(i,n.allowLocalHttp===!0))return{ok:!1,detail:`the binding does not name a clean site origin`};if(a===null||!f.test(a))return{ok:!1,detail:`the binding does not name a chat address as 0x and 40 lowercase hex characters`};if(s===null||!_(s))return{ok:!1,detail:`the binding date is not ISO 8601 UTC with milliseconds`};if(a!==`0x${t}`)return{ok:!1,detail:`the binding is for another chat address than addr`};if(n.origin!==void 0&&i!==n.origin)return{ok:!1,detail:`the binding is for ${i}, not ${n.origin}`};let d=y(e.msg,e.sig);return d===null?{ok:!1,detail:`the binding signature recovers no account`}:{ok:!0,identity:{account:d,site:i,date:s}}}var x=8,S=3072,se=128,ce=500,C=20,w={TEXT:`text`,THREAD:`thread`,REACTION:`reaction`},T={GATEWAY:`gateway`,OWN_STAMP:`own-stamp`};function E(e){let t=0;for(let n of e)t++;return t}function D(e){return t.z.string().regex(RegExp(`^[0-9a-f]{${e}}$`),`expected ${e} lowercase hex characters`)}function O(e,n){return t.z.string().refine(t=>{let r=E(t);return r>=e&&r<=n},`expected ${e} to ${n} characters`)}var k=D(32),A=t.z.strictObject({v:t.z.literal(8),topic:O(1,128),id:k,type:t.z.enum([w.TEXT,w.THREAD,w.REACTION]),target:t.z.union([t.z.literal(``),k]),text:O(1,500),name:O(1,20),addr:D(40),ts:t.z.number().int().nonnegative().max(2**53-1),via:t.z.enum([T.GATEWAY,T.OWN_STAMP]),own:t.z.boolean(),idb:h.optional(),sig:D(130)}).refine(e=>e.type===w.TEXT==(e.target===``),{message:`a text message has no target, a thread reply or a reaction names one`,path:[`target`]}),j=class extends Error{constructor(e,t){super(`chat message refused (${e}): ${t}`),this.reason=e,this.name=`ChatMessageError`}},M=new TextEncoder,le=`1b`,ue=`1c`,de=new TextDecoder(`utf-8`,{fatal:!0});function N(e){return M.encode(JSON.stringify([e.v,e.topic,e.id,e.type,e.target,e.text,e.name,e.addr,e.ts,e.via,e.own,e.idb?.msg??``,e.idb?.sig??``]))}function P(e){let t={v:e.v,topic:e.topic,id:e.id,type:e.type,target:e.target,text:e.text,name:e.name,addr:e.addr,ts:e.ts,via:e.via,own:e.own,...e.idb?{idb:{msg:e.idb.msg,sig:e.idb.sig}}:{},sig:e.sig};return M.encode(JSON.stringify(t))}function F(){let e=crypto.getRandomValues(new Uint8Array(16));return Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}function I(e){return e.issues.map(e=>`${e.path.join(`.`)||`message`}: ${e.message}`).join(`, `)}function L(t,n){let r=t instanceof e.PrivateKey?t:new e.PrivateKey(t),i={v:8,topic:n.topic,id:n.id??F(),type:n.type,target:n.target??``,text:n.text,name:n.name,addr:r.publicKey().address().toHex(),ts:n.ts??Date.now(),via:n.via,own:n.own??!1,...n.idb?{idb:n.idb}:{}},a={...i,sig:`0`.repeat(130)},o=A.safeParse(a);if(!o.success)throw new j(`shape`,I(o.error));let s=P(a).byteLength;if(s>3072)throw new j(`too-large`,`${s} bytes, the cap is ${S}`);if(i.idb){let e=b(i.idb,i.addr,{allowLocalHttp:!0});if(!e.ok)throw new j(`binding`,e.detail)}let c={...i,sig:r.sign(N(i)).toHex()};return{message:c,bytes:P(c)}}function R(t){let n=t.sig.slice(128);if(n!==le&&n!==ue||!a(t.sig.slice(0,64),t.sig.slice(64,128)))return!1;try{return new e.Signature(t.sig).recoverPublicKey(N(t)).address().toHex()===t.addr}catch{return!1}}function z(e,t){let n=A.safeParse(e);if(!n.success)return{ok:!1,reason:`shape`,detail:I(n.error)};let r=n.data;if(!R(r))return{ok:!1,reason:`signature`,detail:`the signature was not made by addr over these fields`};if(!r.idb)return{ok:!0,message:r,identity:null};if(typeof t?.origin!=`string`)return{ok:!1,reason:`binding`,detail:`no origin was given to check the binding against`};let i=b(r.idb,r.addr,t);return i.ok?{ok:!0,message:r,identity:i.identity}:{ok:!1,reason:`binding`,detail:i.detail}}function B(e,t){if(e.byteLength>3072)return{ok:!1,reason:`too-large`,detail:`${e.byteLength} bytes, the cap is ${S}`};let n;try{n=de.decode(e)}catch{return{ok:!1,reason:`not-utf8`,detail:`the payload is not valid UTF-8`}}let r;try{r=JSON.parse(n)}catch{return{ok:!1,reason:`not-json`,detail:`the payload is not JSON`}}return z(r,t)}var V=`swarm-chat-own-feed-v1:`;function H(e){return`${V}${e}`}var fe=4096,pe=t.z.string().regex(/^[0-9a-f]{64}([0-9a-f]{64})?$/,`expected a 64 or 128 hex character reference`),U=t.z.number().int().nonnegative().max(2**53-1),W=t.z.strictObject({ref:pe,toSeq:U}),G=t.z.strictObject({v:t.z.literal(8),seq:U,at:U,msg:A,history:W.nullable()}),K=t.z.strictObject({seq:U,at:U,msg:A}),q=t.z.strictObject({v:t.z.literal(8),topic:t.z.string().min(1),fromSeq:U,toSeq:U,messages:t.z.array(t.z.unknown()),prev:W.nullable()}).refine(e=>e.fromSeq<=e.toSeq,{message:`fromSeq is after toSeq`,path:[`fromSeq`]}),me=new TextDecoder(`utf-8`,{fatal:!0});function J(e){let t;try{t=me.decode(e)}catch{return{ok:!1,reason:`not-utf8`,detail:`the payload is not valid UTF-8`}}try{return{ok:!0,value:JSON.parse(t)}}catch{return{ok:!1,reason:`not-json`,detail:`the payload is not JSON`}}}function Y(e){return e.issues.map(e=>`${e.path.join(`.`)||`value`}: ${e.message}`).join(`, `)}function he(e,t,n){let r=J(e);if(!r.ok)return r;let i=G.safeParse(r.value);return i.success?i.data.seq===t?i.data.msg.topic===n?{ok:!0,value:i.data}:{ok:!1,reason:`mismatch`,detail:`the message belongs to another chat`}:{ok:!1,reason:`mismatch`,detail:`seq ${i.data.seq} at index ${t}`}:{ok:!1,reason:`shape`,detail:Y(i.error)}}function ge(e,t,n){let r=J(e);if(!r.ok)return r;let i=q.safeParse(r.value);if(!i.success)return{ok:!1,reason:`shape`,detail:Y(i.error)};if(i.data.topic!==t||i.data.toSeq!==n.toSeq)return{ok:!1,reason:`mismatch`,detail:`the file is not the one its link names`};let{fromSeq:a,toSeq:o,prev:s}=i.data,c=[],l=0;for(let e of i.data.messages){let n=K.safeParse(e);n.success&&n.data.seq>=a&&n.data.seq<=o&&n.data.msg.topic===t?c.push(n.data):l++}return{ok:!0,value:{topic:t,fromSeq:a,toSeq:o,rows:c,prev:s,skipped:l}}}var _e=1,ve=2e3,ye=3e4,be=256,X=t.z.strictObject({v:t.z.literal(1),newest:t.z.number().int().min(-1).max(2**53-1),writtenAt:t.z.number().int().nonnegative().max(2**53-1)});function Z(e){if(!Number.isInteger(e)||e<=0)throw RangeError(`a note slot is a positive whole number of milliseconds, not ${e}`)}function xe(e,t){return Z(t),Math.floor(e/t)}function Se(e,t){return Z(t),(e+1)*t}function Q(e,t,n){return`${e}/note/${t}/${n}`}function $(t,n,r){return e.Identifier.fromString(Q(t,n,r))}function Ce(t,n,r,i){let a=$(t,n,r);return new e.Reference(e.Bytes.keccak256(e.Bytes.concat(a.toUint8Array(),new e.EthAddress(i).toUint8Array())))}var we=new TextEncoder,Te=new TextDecoder(`utf-8`,{fatal:!0});function Ee(e){let t={v:1,newest:e.newest,writtenAt:e.writtenAt};return we.encode(JSON.stringify(t))}function De(e){if(e.length>256)return null;try{let t=X.safeParse(JSON.parse(Te.decode(e)));return t.success?t.data:null}catch{return null}}Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return De}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return o}});
|