@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
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as e, B as t, C as n, D as r, E as i, F as a,
|
|
2
|
-
import { Bee as
|
|
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 ee, K as l, L as te, M as u, N as ne, O as d, P as f, R as p, S as m, T as h, U as g, V as _, W as v, _ as y, a as b, b as re, c as ie, d as x, f as ae, g as oe, h as se, i as ce, j as le, k as ue, l as S, m as de, n as C, o as fe, p as pe, q as me, r as he, s as w, t as T, u as E, v as D, w as O, x as k, y as A, z as j } from "./message-DQda4_Ge.js";
|
|
2
|
+
import { Bee as M, BeeResponseError as N, Identifier as P, PrivateKey as F, Topic as I } from "@ethersphere/bee-js";
|
|
3
3
|
//#region src/events.ts
|
|
4
|
-
var
|
|
4
|
+
var L = {
|
|
5
5
|
LOADING_INIT: "loadingInit",
|
|
6
6
|
LOADING_PREVIOUS_MESSAGES: "loadingPreviousMessages",
|
|
7
7
|
MESSAGE_RECEIVED: "messageReceived",
|
|
@@ -13,13 +13,13 @@ var R = {
|
|
|
13
13
|
MESSAGE_SKIPPED: "messageSkipped",
|
|
14
14
|
ERROR: "error"
|
|
15
15
|
};
|
|
16
|
-
function
|
|
17
|
-
return
|
|
16
|
+
function R(e) {
|
|
17
|
+
return B(e, -1, e.ts);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
return
|
|
19
|
+
function z(e) {
|
|
20
|
+
return B(e.msg, e.seq, e.at);
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function B(e, t, n) {
|
|
23
23
|
return {
|
|
24
24
|
id: e.id,
|
|
25
25
|
type: e.type,
|
|
@@ -32,7 +32,7 @@ function V(e, t, n) {
|
|
|
32
32
|
signedMessage: e
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
var
|
|
35
|
+
var V = class {
|
|
36
36
|
constructor() {
|
|
37
37
|
this.listeners = /* @__PURE__ */ new Map(), this.on = (e, t) => {
|
|
38
38
|
this.listeners.set(e, [...this.listeners.get(e) ?? [], t]);
|
|
@@ -49,7 +49,7 @@ var H = class {
|
|
|
49
49
|
console.error(`a listener for ${e} threw`, t);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
},
|
|
52
|
+
}, H = 2e4, U = class {
|
|
53
53
|
constructor(e, t) {
|
|
54
54
|
this.spacingMs = e, this.now = t, this.missedAt = /* @__PURE__ */ new Map();
|
|
55
55
|
}
|
|
@@ -73,33 +73,33 @@ var H = class {
|
|
|
73
73
|
expired(e, t) {
|
|
74
74
|
return e > t || t - e >= this.spacingMs;
|
|
75
75
|
}
|
|
76
|
-
},
|
|
76
|
+
}, W = class extends Error {
|
|
77
77
|
constructor(e) {
|
|
78
78
|
super("the feed head lookup did not answer in time", e), this.name = "HeadLookupTimeoutError";
|
|
79
79
|
}
|
|
80
|
-
},
|
|
80
|
+
}, G = class extends Error {
|
|
81
81
|
constructor(e, t) {
|
|
82
82
|
super(`feed slot ${e} was served but could not be read`, t), this.index = e, this.name = "UnreadableSlotError";
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
-
function
|
|
86
|
-
return e instanceof
|
|
85
|
+
function K(e) {
|
|
86
|
+
return e instanceof N && (e.status === 404 || e.status === 500);
|
|
87
87
|
}
|
|
88
|
-
async function
|
|
88
|
+
async function q(e, t) {
|
|
89
89
|
try {
|
|
90
90
|
return await t();
|
|
91
91
|
} catch (t) {
|
|
92
|
-
if (
|
|
93
|
-
throw t instanceof
|
|
92
|
+
if (K(t)) return null;
|
|
93
|
+
throw t instanceof N ? t : new G(e, { cause: t });
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
let a =
|
|
96
|
+
function ge(e, t, n, r, i = C) {
|
|
97
|
+
let a = I.fromString(n), o = (n) => e.feed.makeReader(a, t, J(n));
|
|
98
98
|
return {
|
|
99
|
-
readNote: (a) =>
|
|
100
|
-
readSlot: (e) =>
|
|
99
|
+
readNote: (a) => q(a, async () => (await e.soc.makeReader(t, J(r.slotReadMs)).download(w(n, i, a))).payload.toUint8Array()),
|
|
100
|
+
readSlot: (e) => q(e, async () => (await o(r.slotReadMs).downloadPayload({ index: e })).payload.toUint8Array()),
|
|
101
101
|
async readHead() {
|
|
102
|
-
let n =
|
|
102
|
+
let n = J(r.feedReadMs);
|
|
103
103
|
try {
|
|
104
104
|
let { payload: r, feedIndex: i } = await e.feed.makeReader(a, t, n).downloadPayload();
|
|
105
105
|
return {
|
|
@@ -107,34 +107,34 @@ function le(e, t, n, r, i = C) {
|
|
|
107
107
|
payload: r.toUint8Array()
|
|
108
108
|
};
|
|
109
109
|
} catch (e) {
|
|
110
|
-
if (
|
|
111
|
-
throw n.signal?.aborted ? new
|
|
110
|
+
if (K(e)) return null;
|
|
111
|
+
throw n.signal?.aborted ? new W({ cause: e }) : e;
|
|
112
112
|
}
|
|
113
113
|
},
|
|
114
114
|
async readFile(t) {
|
|
115
|
-
return (await e.data.download(t, void 0,
|
|
115
|
+
return (await e.data.download(t, void 0, J(r.feedReadMs))).toUint8Array();
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function J(e) {
|
|
120
120
|
return { signal: AbortSignal.timeout(e) };
|
|
121
121
|
}
|
|
122
|
-
var
|
|
123
|
-
function
|
|
124
|
-
let a = new
|
|
122
|
+
var _e = "0123456789abcdef".repeat(4);
|
|
123
|
+
function ve(e, t, n, r, i) {
|
|
124
|
+
let a = new F(n), o = P.fromString(r);
|
|
125
125
|
return async (n) => {
|
|
126
|
-
await e.messaging.gsocSend(t, a, o, n, { deferred: !1 },
|
|
126
|
+
await e.messaging.gsocSend(t, a, o, n, { deferred: !1 }, J(i.writeMs));
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
//#endregion
|
|
130
130
|
//#region src/follower.ts
|
|
131
|
-
var
|
|
131
|
+
var Y = {
|
|
132
132
|
LIVE: "live",
|
|
133
133
|
RECONNECTING: "reconnecting",
|
|
134
134
|
STALLED: "stalled"
|
|
135
|
-
},
|
|
135
|
+
}, ye = {
|
|
136
136
|
pollIntervalMs: 1e3,
|
|
137
|
-
missingReadSpacingMs:
|
|
137
|
+
missingReadSpacingMs: H,
|
|
138
138
|
maxSlotsPerPoll: 16,
|
|
139
139
|
unservedPollsBeforeProbe: 3,
|
|
140
140
|
unreadablePollsBeforeFailure: 3,
|
|
@@ -152,16 +152,16 @@ var X = {
|
|
|
152
152
|
stallAfterMs: 8e3,
|
|
153
153
|
random: Math.random,
|
|
154
154
|
now: Date.now
|
|
155
|
-
},
|
|
155
|
+
}, X = class extends Error {
|
|
156
156
|
constructor(e) {
|
|
157
157
|
super(`the gateway keeps answering feed slot ${e} with something that is not a chunk`), this.index = e, this.name = "UnreadableGatewayError";
|
|
158
158
|
}
|
|
159
|
-
},
|
|
159
|
+
}, be = class {
|
|
160
160
|
constructor(e, t, n, r = {}, i = null) {
|
|
161
161
|
this.source = e, this.topic = t, this.events = n, this.notes = i, this.next = 0, this.ceiling = null, this.nextNoteSlot = 0, this.lastNoteFoundAt = 0, this.unservedPolls = 0, this.nextProbeAt = 0, this.unreadablePolls = 0, this.gatewayFailures = 0, this.missed = /* @__PURE__ */ new Map(), this.timer = null, this.generation = 0, this.running = !1, this.status = null, this.settings = {
|
|
162
|
-
...
|
|
162
|
+
...ye,
|
|
163
163
|
...r
|
|
164
|
-
}, this.pacer = new
|
|
164
|
+
}, this.pacer = new U(this.settings.missingReadSpacingMs, this.settings.now);
|
|
165
165
|
}
|
|
166
166
|
get nextIndex() {
|
|
167
167
|
return this.next;
|
|
@@ -223,7 +223,7 @@ var X = {
|
|
|
223
223
|
try {
|
|
224
224
|
t = await this.source.readSlot(e);
|
|
225
225
|
} catch (e) {
|
|
226
|
-
if (e instanceof
|
|
226
|
+
if (e instanceof G) return "unreadable";
|
|
227
227
|
throw e;
|
|
228
228
|
}
|
|
229
229
|
return t === null ? this.pacer.missed(e) : this.pacer.found(e), t;
|
|
@@ -247,7 +247,7 @@ var X = {
|
|
|
247
247
|
this.unreadablePolls = 0;
|
|
248
248
|
continue;
|
|
249
249
|
}
|
|
250
|
-
if (this.unreadablePolls >= this.settings.unreadablePollsBeforeFailure) throw new
|
|
250
|
+
if (this.unreadablePolls >= this.settings.unreadablePollsBeforeFailure) throw new X(n);
|
|
251
251
|
}
|
|
252
252
|
return t;
|
|
253
253
|
}
|
|
@@ -303,16 +303,16 @@ var X = {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
accept(e, t) {
|
|
306
|
-
let n =
|
|
306
|
+
let n = D(t, e, this.topic);
|
|
307
307
|
n.ok ? (this.notes?.clock.observe(n.value.at, this.settings.now()), this.events.entry(n.value)) : this.events.skipped(e, n.reason, n.detail);
|
|
308
308
|
}
|
|
309
309
|
gatewayFailed(e) {
|
|
310
|
-
this.gatewayFailures++, this.setStatus(
|
|
310
|
+
this.gatewayFailures++, this.setStatus(Y.RECONNECTING), this.events.error(e);
|
|
311
311
|
}
|
|
312
312
|
gatewayAnswered() {
|
|
313
313
|
this.gatewayFailures = 0;
|
|
314
314
|
let e = this.settings.now(), t = [...this.missed.values()].some((t) => e - t >= this.settings.stallAfterMs);
|
|
315
|
-
this.setStatus(t ?
|
|
315
|
+
this.setStatus(t ? Y.STALLED : Y.LIVE);
|
|
316
316
|
}
|
|
317
317
|
backoffMs() {
|
|
318
318
|
let { pollIntervalMs: e, backoffCapMs: t, random: n } = this.settings, r = Math.min(t, e * 2 ** this.gatewayFailures);
|
|
@@ -321,7 +321,7 @@ var X = {
|
|
|
321
321
|
setStatus(e) {
|
|
322
322
|
e !== this.status && (this.status = e, this.events.status(e));
|
|
323
323
|
}
|
|
324
|
-
},
|
|
324
|
+
}, xe = 16, Se = class {
|
|
325
325
|
constructor(e, t, n, r = null) {
|
|
326
326
|
this.source = e, this.topic = t, this.events = n, this.notes = r, this.older = null, this.loading = null;
|
|
327
327
|
}
|
|
@@ -366,7 +366,7 @@ var X = {
|
|
|
366
366
|
try {
|
|
367
367
|
return await this.source.readHead();
|
|
368
368
|
} catch (e) {
|
|
369
|
-
if (e instanceof
|
|
369
|
+
if (e instanceof W) return this.events.error(e), null;
|
|
370
370
|
throw e;
|
|
371
371
|
}
|
|
372
372
|
}
|
|
@@ -381,30 +381,30 @@ var X = {
|
|
|
381
381
|
async loadOlderOnce() {
|
|
382
382
|
let e = this.older;
|
|
383
383
|
if (e === null) return [];
|
|
384
|
-
let t = await this.source.readFile(e.ref), n =
|
|
384
|
+
let t = await this.source.readFile(e.ref), n = A(t, this.topic, e);
|
|
385
385
|
if (!n.ok) throw this.older = null, Error(`history file ${e.ref} refused (${n.reason}): ${n.detail}`);
|
|
386
386
|
return this.report(n.value.skipped), this.older = n.value.prev, n.value.rows;
|
|
387
387
|
}
|
|
388
388
|
async newestLink(e, t) {
|
|
389
389
|
let n = t === void 0 ? e : e - 1;
|
|
390
390
|
if (t !== void 0) {
|
|
391
|
-
let n =
|
|
391
|
+
let n = D(t, e, this.topic);
|
|
392
392
|
if (n.ok) return n.value.history;
|
|
393
393
|
}
|
|
394
|
-
for (let t = n; t >= Math.max(0, e -
|
|
394
|
+
for (let t = n; t >= Math.max(0, e - xe); t--) {
|
|
395
395
|
let e = await this.source.readSlot(t).catch((e) => {
|
|
396
|
-
if (e instanceof
|
|
396
|
+
if (e instanceof G) return null;
|
|
397
397
|
throw e;
|
|
398
398
|
});
|
|
399
399
|
if (e === null) continue;
|
|
400
|
-
let n =
|
|
400
|
+
let n = D(e, t, this.topic);
|
|
401
401
|
if (n.ok) return n.value.history;
|
|
402
402
|
}
|
|
403
403
|
return null;
|
|
404
404
|
}
|
|
405
405
|
async readFile(e) {
|
|
406
406
|
try {
|
|
407
|
-
let t =
|
|
407
|
+
let t = A(await this.source.readFile(e.ref), this.topic, e);
|
|
408
408
|
return t.ok ? (this.report(t.value.skipped), this.older = t.value.prev, t.value.rows) : (this.events.error(/* @__PURE__ */ Error(`history file ${e.ref} refused (${t.reason}): ${t.detail}`)), "refused");
|
|
409
409
|
} catch (t) {
|
|
410
410
|
return this.events.error(t), this.older = e, null;
|
|
@@ -413,18 +413,18 @@ var X = {
|
|
|
413
413
|
report(e) {
|
|
414
414
|
e > 0 && this.events.skipped(e);
|
|
415
415
|
}
|
|
416
|
-
},
|
|
416
|
+
}, Ce = {
|
|
417
417
|
slotMs: C,
|
|
418
|
-
heartbeatMs:
|
|
418
|
+
heartbeatMs: T,
|
|
419
419
|
marginMs: 1e3,
|
|
420
420
|
scanBatch: 4,
|
|
421
421
|
clockLimitMs: 3e5,
|
|
422
|
-
missingReadSpacingMs:
|
|
422
|
+
missingReadSpacingMs: H
|
|
423
423
|
};
|
|
424
|
-
function
|
|
424
|
+
function we(e) {
|
|
425
425
|
return typeof e.readNote == "function";
|
|
426
426
|
}
|
|
427
|
-
var
|
|
427
|
+
var Te = class {
|
|
428
428
|
constructor(e) {
|
|
429
429
|
this.limitMs = e, this.aheadAtMost = Infinity, this.trusted = !0;
|
|
430
430
|
}
|
|
@@ -441,21 +441,21 @@ var ve = class {
|
|
|
441
441
|
let e = Number.isFinite(this.aheadAtMost), t = this.trusted || !e ? Math.min(0, this.aheadAtMost) : this.aheadAtMost;
|
|
442
442
|
return Math.max(-this.limitMs, Math.min(this.limitMs, t));
|
|
443
443
|
}
|
|
444
|
-
},
|
|
444
|
+
}, Z = class {
|
|
445
445
|
constructor(e, t, n) {
|
|
446
446
|
this.source = e, this.now = n, this.counts = {
|
|
447
447
|
found: 0,
|
|
448
448
|
empty: 0
|
|
449
449
|
}, this.settings = {
|
|
450
|
-
...
|
|
450
|
+
...Ce,
|
|
451
451
|
...t
|
|
452
|
-
}, this.clock = new
|
|
452
|
+
}, this.clock = new Te(this.settings.clockLimitMs), this.pacer = new U(this.settings.missingReadSpacingMs, n);
|
|
453
453
|
}
|
|
454
454
|
lastReadableSlot(e = this.now()) {
|
|
455
|
-
return
|
|
455
|
+
return E(e - this.settings.marginMs - this.clock.ms, this.settings.slotMs) - 1;
|
|
456
456
|
}
|
|
457
457
|
readableAt(e) {
|
|
458
|
-
return
|
|
458
|
+
return S(e, this.settings.slotMs) + this.settings.marginMs + this.clock.ms;
|
|
459
459
|
}
|
|
460
460
|
get lookBackSlots() {
|
|
461
461
|
return Math.ceil(this.settings.heartbeatMs / this.settings.slotMs) + 2;
|
|
@@ -469,10 +469,10 @@ var ve = class {
|
|
|
469
469
|
try {
|
|
470
470
|
t = await this.source.readNote(e), t === null && this.pacer.missed(e);
|
|
471
471
|
} catch (e) {
|
|
472
|
-
if (!(e instanceof
|
|
472
|
+
if (!(e instanceof G)) throw e;
|
|
473
473
|
t = null;
|
|
474
474
|
}
|
|
475
|
-
let n = t === null ? null :
|
|
475
|
+
let n = t === null ? null : x(t);
|
|
476
476
|
return n === null ? (this.counts.empty++, null) : (this.counts.found++, this.clock.observe(n.writtenAt, this.now()), n);
|
|
477
477
|
}
|
|
478
478
|
async scan(e, t) {
|
|
@@ -492,7 +492,7 @@ var ve = class {
|
|
|
492
492
|
maxResends: 5,
|
|
493
493
|
reactionWindowMs: 1e3,
|
|
494
494
|
isLive: () => !0
|
|
495
|
-
},
|
|
495
|
+
}, Ee = class {
|
|
496
496
|
constructor(e, t, n, r, i = Q) {
|
|
497
497
|
this.key = e, this.profile = t, this.write = n, this.events = r, this.settings = i, this.outgoing = /* @__PURE__ */ new Map(), this.reactions = /* @__PURE__ */ new Map(), this.stopped = !1;
|
|
498
498
|
}
|
|
@@ -500,7 +500,7 @@ var ve = class {
|
|
|
500
500
|
return this.key.publicKey().address().toHex();
|
|
501
501
|
}
|
|
502
502
|
send(e) {
|
|
503
|
-
let { message: t, bytes: n } =
|
|
503
|
+
let { message: t, bytes: n } = u(this.key, {
|
|
504
504
|
...e,
|
|
505
505
|
...this.profile
|
|
506
506
|
}), r = {
|
|
@@ -528,7 +528,7 @@ var ve = class {
|
|
|
528
528
|
let i = this.reactions.get(r);
|
|
529
529
|
this.reactions.delete(r), i && i.taps % 2 == 1 && !this.stopped && this.send({
|
|
530
530
|
topic: e,
|
|
531
|
-
type:
|
|
531
|
+
type: d.REACTION,
|
|
532
532
|
target: t,
|
|
533
533
|
text: n
|
|
534
534
|
});
|
|
@@ -579,27 +579,27 @@ var ve = class {
|
|
|
579
579
|
clearTimer(e) {
|
|
580
580
|
e.timer &&= (clearTimeout(e.timer), null);
|
|
581
581
|
}
|
|
582
|
-
},
|
|
582
|
+
}, De = [
|
|
583
583
|
1e3,
|
|
584
584
|
2e3,
|
|
585
585
|
4e3,
|
|
586
586
|
8e3
|
|
587
|
-
],
|
|
587
|
+
], Oe = 3;
|
|
588
588
|
function $(e) {
|
|
589
589
|
return (e.startsWith("0x") ? e.slice(2) : e).toLowerCase();
|
|
590
590
|
}
|
|
591
|
-
var
|
|
591
|
+
var ke = class {
|
|
592
592
|
constructor(e, t = {}) {
|
|
593
|
-
this.emitter = new
|
|
593
|
+
this.emitter = new V(), this.seen = /* @__PURE__ */ new Set(), this.status = null, this.generation = 0, this.running = !1, this.starting = null, this.openTimer = null, this.wakeOpen = null;
|
|
594
594
|
let { user: n, infra: r } = e;
|
|
595
|
-
this.key = new
|
|
595
|
+
this.key = new F($(n.privateKey)), this.topic = r.chatTopic, this.profile = {
|
|
596
596
|
name: n.nickname,
|
|
597
597
|
via: r.via,
|
|
598
598
|
...n.binding ? { idb: n.binding } : {},
|
|
599
|
-
...
|
|
600
|
-
}, this.openRetryMs = t.openRetryMs ??
|
|
599
|
+
...n.walletLink ? { wl: n.walletLink } : {}
|
|
600
|
+
}, this.openRetryMs = t.openRetryMs ?? De, this.senderSettings = {
|
|
601
601
|
...Q,
|
|
602
|
-
isLive: () => this.status ===
|
|
602
|
+
isLive: () => this.status === Y.LIVE,
|
|
603
603
|
...t.sender
|
|
604
604
|
};
|
|
605
605
|
let i = {
|
|
@@ -611,28 +611,28 @@ var Ce = class {
|
|
|
611
611
|
...r.noteHeartbeatMs === void 0 ? {} : { heartbeatMs: r.noteHeartbeatMs },
|
|
612
612
|
...t.notes
|
|
613
613
|
};
|
|
614
|
-
this.source = t.source ??
|
|
614
|
+
this.source = t.source ?? ge(new M(r.beeUrl), $(r.chatAddress), r.chatTopic, i, a.slotMs), this.write = t.write ?? ve(new M(r.writeUrl ?? r.beeUrl), r.stamp ? $(r.stamp) : _e, $(r.gsocResourceId), r.gsocTopic, i);
|
|
615
615
|
let o = t.follower?.now ?? (() => Date.now()), s = {
|
|
616
616
|
pollIntervalMs: r.pollingInterval ?? 1e3,
|
|
617
617
|
...t.follower,
|
|
618
618
|
now: o
|
|
619
619
|
}, c = this.source;
|
|
620
|
-
this.notes =
|
|
620
|
+
this.notes = we(c) ? new Z(c, a, o) : null, this.follower = new be(this.source, this.topic, {
|
|
621
621
|
entry: (e) => this.show(e),
|
|
622
|
-
skipped: (e, t, n) => this.emitter.emit(
|
|
622
|
+
skipped: (e, t, n) => this.emitter.emit(L.MESSAGE_SKIPPED, {
|
|
623
623
|
index: e,
|
|
624
624
|
reason: t,
|
|
625
625
|
detail: n
|
|
626
626
|
}),
|
|
627
627
|
status: (e) => this.setStatus(e),
|
|
628
|
-
error: (e) => this.emitter.emit(
|
|
629
|
-
}, s, this.notes), this.history = new
|
|
630
|
-
skipped: (e) => this.emitter.emit(
|
|
628
|
+
error: (e) => this.emitter.emit(L.ERROR, e)
|
|
629
|
+
}, s, this.notes), this.history = new Se(this.source, this.topic, {
|
|
630
|
+
skipped: (e) => this.emitter.emit(L.MESSAGE_SKIPPED, {
|
|
631
631
|
index: -1,
|
|
632
632
|
reason: "history-row",
|
|
633
633
|
detail: `${e} rows of a history file`
|
|
634
634
|
}),
|
|
635
|
-
error: (e) => this.emitter.emit(
|
|
635
|
+
error: (e) => this.emitter.emit(L.ERROR, e)
|
|
636
636
|
}, this.notes), this.sender = this.makeSender();
|
|
637
637
|
}
|
|
638
638
|
getEmitter() {
|
|
@@ -656,11 +656,11 @@ var Ce = class {
|
|
|
656
656
|
this.running = !1, this.generation++, this.openTimer &&= (clearTimeout(this.openTimer), null), this.wakeOpen?.(), this.follower.stop(), this.sender.stop();
|
|
657
657
|
}
|
|
658
658
|
async sendMessage(e, t, n) {
|
|
659
|
-
if (t ===
|
|
659
|
+
if (t === d.REACTION) {
|
|
660
660
|
if (!n) throw Error("a reaction names the message it reacts to");
|
|
661
661
|
return this.sender.react(this.topic, n, e), null;
|
|
662
662
|
}
|
|
663
|
-
return
|
|
663
|
+
return R(this.sender.send({
|
|
664
664
|
topic: this.topic,
|
|
665
665
|
type: t,
|
|
666
666
|
target: n ?? "",
|
|
@@ -671,12 +671,12 @@ var Ce = class {
|
|
|
671
671
|
return this.sender.retry(typeof e == "string" ? e : e.id);
|
|
672
672
|
}
|
|
673
673
|
async fetchPreviousMessages() {
|
|
674
|
-
this.emitter.emit(
|
|
674
|
+
this.emitter.emit(L.LOADING_PREVIOUS_MESSAGES, !0);
|
|
675
675
|
try {
|
|
676
676
|
let e = this.generation, t = await this.history.loadOlder();
|
|
677
677
|
return e === this.generation ? this.showRows(t) : [];
|
|
678
678
|
} finally {
|
|
679
|
-
this.emitter.emit(
|
|
679
|
+
this.emitter.emit(L.LOADING_PREVIOUS_MESSAGES, !1);
|
|
680
680
|
}
|
|
681
681
|
}
|
|
682
682
|
hasPreviousMessages() {
|
|
@@ -686,16 +686,16 @@ var Ce = class {
|
|
|
686
686
|
return [...e].sort((e, t) => e.index >= 0 && t.index >= 0 ? e.index - t.index : e.index >= 0 || t.index >= 0 ? e.index >= 0 ? -1 : 1 : e.timestamp - t.timestamp);
|
|
687
687
|
}
|
|
688
688
|
async open(e) {
|
|
689
|
-
this.emitter.emit(
|
|
689
|
+
this.emitter.emit(L.LOADING_INIT, !0);
|
|
690
690
|
let t = 0;
|
|
691
691
|
for (; e === this.generation;) try {
|
|
692
692
|
let t = await this.history.open();
|
|
693
693
|
if (e !== this.generation) return;
|
|
694
|
-
this.showRows(t.rows), this.follower.start(t.startAt, t.notes), this.emitter.emit(
|
|
694
|
+
this.showRows(t.rows), this.follower.start(t.startAt, t.notes), this.emitter.emit(L.LOADING_INIT, !1);
|
|
695
695
|
return;
|
|
696
696
|
} catch (n) {
|
|
697
697
|
if (e !== this.generation) return;
|
|
698
|
-
t++, this.emitter.emit(
|
|
698
|
+
t++, this.emitter.emit(L.ERROR, n), this.setStatus(Y.RECONNECTING), t === Oe && this.emitter.emit(L.CRITICAL_ERROR, n), await this.waitToOpen(this.openRetryMs[Math.min(t, this.openRetryMs.length) - 1] ?? 8e3);
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
701
|
waitToOpen(e) {
|
|
@@ -708,31 +708,31 @@ var Ce = class {
|
|
|
708
708
|
});
|
|
709
709
|
}
|
|
710
710
|
makeSender() {
|
|
711
|
-
return new
|
|
712
|
-
pending: (e) => this.emitter.emit(
|
|
713
|
-
written: (e) => this.emitter.emit(
|
|
711
|
+
return new Ee(this.key, this.profile, this.write, {
|
|
712
|
+
pending: (e) => this.emitter.emit(L.MESSAGE_REQUEST_INITIATED, R(e)),
|
|
713
|
+
written: (e) => this.emitter.emit(L.MESSAGE_REQUEST_UPLOADED, R(e)),
|
|
714
714
|
failed: (e, t) => {
|
|
715
|
-
this.emitter.emit(
|
|
715
|
+
this.emitter.emit(L.ERROR, t), this.emitter.emit(L.MESSAGE_REQUEST_ERROR, R(e));
|
|
716
716
|
},
|
|
717
717
|
confirmed: () => {}
|
|
718
718
|
}, this.senderSettings);
|
|
719
719
|
}
|
|
720
720
|
show(e) {
|
|
721
|
-
this.seen.has(e.seq) || (this.seen.add(e.seq), this.sender.confirm(e.msg), this.emitter.emit(
|
|
721
|
+
this.seen.has(e.seq) || (this.seen.add(e.seq), this.sender.confirm(e.msg), this.emitter.emit(L.MESSAGE_RECEIVED, z(e)));
|
|
722
722
|
}
|
|
723
723
|
showRows(e) {
|
|
724
724
|
let t = [];
|
|
725
725
|
for (let n of e) {
|
|
726
726
|
if (this.seen.has(n.seq)) continue;
|
|
727
727
|
this.seen.add(n.seq), this.sender.confirm(n.msg);
|
|
728
|
-
let e =
|
|
729
|
-
t.push(e), this.emitter.emit(
|
|
728
|
+
let e = z(n);
|
|
729
|
+
t.push(e), this.emitter.emit(L.MESSAGE_RECEIVED, e);
|
|
730
730
|
}
|
|
731
731
|
return t;
|
|
732
732
|
}
|
|
733
733
|
setStatus(e) {
|
|
734
|
-
e !== this.status && (this.status = e, this.emitter.emit(
|
|
734
|
+
e !== this.status && (this.status = e, this.emitter.emit(L.STATUS, e));
|
|
735
735
|
}
|
|
736
736
|
};
|
|
737
737
|
//#endregion
|
|
738
|
-
export {
|
|
738
|
+
export { o as CHAT_BINDING_TITLE, V as ChatEmitter, m as ChatMessageError, T as DEFAULT_NOTE_HEARTBEAT_MS, C as DEFAULT_NOTE_SLOT_MS, L as EVENTS, Y as FeedStatus, W as HeadLookupTimeoutError, l as MAX_BINDING_CHARACTERS, pe as MAX_ENTRY_BYTES, n as MAX_MESSAGE_BYTES, O as MAX_NAME_CHARACTERS, he as MAX_NOTE_BYTES, h as MAX_TEXT_CHARACTERS, i as MAX_TOPIC_CHARACTERS, t as MAX_WALLET_LINK_CHARACTERS, r as MESSAGE_VERSION, d as MessageType, ue as MessageVia, ce as NOTE_VERSION, re as OWN_FEED_TOPIC_PREFIX, ke as SwarmChat, X as UnreadableGatewayError, G as UnreadableSlotError, _ as WALLET_LINK_STATEMENT, s as WALLET_LINK_TITLE, me as chatBindingSchema, e as chatMessageSchema, ee as checkChatBinding, g as checkWalletLink, le as countCharacters, u as createChatMessage, ne as displayNameProblem, f as encodeChatMessage, b as encodeSlotNote, de as feedEntrySchema, a as hasValidSignature, se as historyFileSchema, oe as historyLinkSchema, y as historyRowSchema, c as newMessageId, fe as noteAddress, w as noteIdentifier, ie as noteIdentifierText, S as noteSlotEnd, E as noteSlotOf, k as ownFeedTopic, te as parseChatMessage, D as parseFeedEntry, A as parseHistoryFile, x as parseSlotNote, p as signedBytes, ae as slotNoteSchema, j as verifyChatMessage, v as walletLinkSchema };
|
|
@@ -26,6 +26,12 @@ export interface ChatIdentity {
|
|
|
26
26
|
site: string;
|
|
27
27
|
/** When the account says it signed, ISO 8601 UTC. */
|
|
28
28
|
date: string;
|
|
29
|
+
/**
|
|
30
|
+
* The wallet the message's Swarm ID wallet link names, `0x` and 40 lowercase hex characters, present only when the
|
|
31
|
+
* message carries a link both the wallet and this account signed. A reader looks its ENS name up itself, and the
|
|
32
|
+
* fork's `resolveVerifiedEnsName` does that with both the reverse and the forward record.
|
|
33
|
+
*/
|
|
34
|
+
wallet?: string;
|
|
29
35
|
}
|
|
30
36
|
export interface BindingOptions {
|
|
31
37
|
/** The origin the reader runs on. When given, a binding for any other site is refused. */
|
package/dist/message/entry.d.ts
CHANGED
|
@@ -13,11 +13,11 @@ export declare const historyLinkSchema: z.ZodObject<{
|
|
|
13
13
|
}, z.core.$strict>;
|
|
14
14
|
export type HistoryLink = z.infer<typeof historyLinkSchema>;
|
|
15
15
|
export declare const feedEntrySchema: z.ZodObject<{
|
|
16
|
-
v: z.ZodLiteral<
|
|
16
|
+
v: z.ZodLiteral<9>;
|
|
17
17
|
seq: z.ZodNumber;
|
|
18
18
|
at: z.ZodNumber;
|
|
19
19
|
msg: z.ZodObject<{
|
|
20
|
-
v: z.ZodLiteral<
|
|
20
|
+
v: z.ZodLiteral<9>;
|
|
21
21
|
topic: z.ZodString;
|
|
22
22
|
id: z.ZodString;
|
|
23
23
|
type: z.ZodEnum<{
|
|
@@ -34,11 +34,15 @@ export declare const feedEntrySchema: z.ZodObject<{
|
|
|
34
34
|
gateway: "gateway";
|
|
35
35
|
"own-stamp": "own-stamp";
|
|
36
36
|
}>;
|
|
37
|
-
own: z.ZodBoolean;
|
|
38
37
|
idb: z.ZodOptional<z.ZodObject<{
|
|
39
38
|
msg: z.ZodString;
|
|
40
39
|
sig: z.ZodString;
|
|
41
40
|
}, z.core.$strict>>;
|
|
41
|
+
wl: z.ZodOptional<z.ZodObject<{
|
|
42
|
+
msg: z.ZodString;
|
|
43
|
+
wsig: z.ZodString;
|
|
44
|
+
asig: z.ZodString;
|
|
45
|
+
}, z.core.$strict>>;
|
|
42
46
|
sig: z.ZodString;
|
|
43
47
|
}, z.core.$strict>;
|
|
44
48
|
history: z.ZodNullable<z.ZodObject<{
|
|
@@ -51,7 +55,7 @@ export declare const historyRowSchema: z.ZodObject<{
|
|
|
51
55
|
seq: z.ZodNumber;
|
|
52
56
|
at: z.ZodNumber;
|
|
53
57
|
msg: z.ZodObject<{
|
|
54
|
-
v: z.ZodLiteral<
|
|
58
|
+
v: z.ZodLiteral<9>;
|
|
55
59
|
topic: z.ZodString;
|
|
56
60
|
id: z.ZodString;
|
|
57
61
|
type: z.ZodEnum<{
|
|
@@ -68,18 +72,22 @@ export declare const historyRowSchema: z.ZodObject<{
|
|
|
68
72
|
gateway: "gateway";
|
|
69
73
|
"own-stamp": "own-stamp";
|
|
70
74
|
}>;
|
|
71
|
-
own: z.ZodBoolean;
|
|
72
75
|
idb: z.ZodOptional<z.ZodObject<{
|
|
73
76
|
msg: z.ZodString;
|
|
74
77
|
sig: z.ZodString;
|
|
75
78
|
}, z.core.$strict>>;
|
|
79
|
+
wl: z.ZodOptional<z.ZodObject<{
|
|
80
|
+
msg: z.ZodString;
|
|
81
|
+
wsig: z.ZodString;
|
|
82
|
+
asig: z.ZodString;
|
|
83
|
+
}, z.core.$strict>>;
|
|
76
84
|
sig: z.ZodString;
|
|
77
85
|
}, z.core.$strict>;
|
|
78
86
|
}, z.core.$strict>;
|
|
79
87
|
export type HistoryRow = z.infer<typeof historyRowSchema>;
|
|
80
88
|
/** A row that fails its shape is left out and counted, so one bad row never hides the rest of the file. */
|
|
81
89
|
export declare const historyFileSchema: z.ZodObject<{
|
|
82
|
-
v: z.ZodLiteral<
|
|
90
|
+
v: z.ZodLiteral<9>;
|
|
83
91
|
topic: z.ZodString;
|
|
84
92
|
fromSeq: z.ZodNumber;
|
|
85
93
|
toSeq: z.ZodNumber;
|