@orangecheck/chat-core 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{channel-D8aOo4eI.d.mts → channel-ChK3AAvd.d.mts} +8 -3
- package/dist/{channel-D8aOo4eI.d.ts → channel-ChK3AAvd.d.ts} +8 -3
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +26 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -8
- package/dist/index.mjs.map +1 -1
- package/dist/io.d.mts +13 -14
- package/dist/io.d.ts +13 -14
- package/dist/io.js +45 -23
- package/dist/io.js.map +1 -1
- package/dist/io.mjs +45 -24
- package/dist/io.mjs.map +1 -1
- package/package.json +2 -2
- package/src/channel.test.ts +121 -7
- package/src/channel.ts +48 -12
- package/src/directory.test.ts +59 -0
- package/src/directory.ts +15 -5
- package/src/io.test.ts +97 -51
- package/src/io.ts +95 -50
package/dist/index.mjs
CHANGED
|
@@ -514,6 +514,9 @@ async function checkWritePermission(content, descriptor, role, pid, opts, verify
|
|
|
514
514
|
if (!content.write_proof) return "E_CHAN_FLOOR";
|
|
515
515
|
if (!opts.controlSig) return "E_CHAN_FLOOR";
|
|
516
516
|
if (!isBitcoinAddress(content.author_address)) return "E_CHAN_FLOOR";
|
|
517
|
+
if (opts.tipHeight === "unanswered") {
|
|
518
|
+
throw new UnansweredReadError("the chain tip could not be read");
|
|
519
|
+
}
|
|
517
520
|
const v = evaluateWriteProof(content.write_proof, w, opts.tipHeight);
|
|
518
521
|
if (v.verdict !== "accept") return "E_CHAN_FLOOR";
|
|
519
522
|
const sigOk = await verify({
|
|
@@ -855,15 +858,25 @@ function orderChannelPosts(posts) {
|
|
|
855
858
|
async function verifyChannelPosts(events, descriptor, opts) {
|
|
856
859
|
const removed = /* @__PURE__ */ new Set();
|
|
857
860
|
const byPostId = /* @__PURE__ */ new Map();
|
|
861
|
+
const unchecked = /* @__PURE__ */ new Set();
|
|
862
|
+
let removalsUnread = false;
|
|
858
863
|
for (const ev of events) {
|
|
859
864
|
const content = parsePost(ev);
|
|
860
865
|
if (!content || content.channel_id !== descriptor.channel_id) continue;
|
|
861
866
|
const controlSig = ev.tags.find((t) => t[0] === "control_sig")?.[1];
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
+
let v;
|
|
868
|
+
try {
|
|
869
|
+
v = await verifyPost(content, descriptor, {
|
|
870
|
+
...opts,
|
|
871
|
+
event: ev,
|
|
872
|
+
...controlSig ? { controlSig } : {}
|
|
873
|
+
});
|
|
874
|
+
} catch (e) {
|
|
875
|
+
if (!(e instanceof UnansweredReadError)) throw e;
|
|
876
|
+
unchecked.add(postId(content));
|
|
877
|
+
if (typeof content.removes === "string") removalsUnread = true;
|
|
878
|
+
continue;
|
|
879
|
+
}
|
|
867
880
|
if (!v.ok) continue;
|
|
868
881
|
if (v.isTombstone && content.removes) {
|
|
869
882
|
removed.add(content.removes);
|
|
@@ -874,7 +887,11 @@ async function verifyChannelPosts(events, descriptor, opts) {
|
|
|
874
887
|
byPostId.set(v.postId, { post: content, postId: v.postId, event: ev });
|
|
875
888
|
}
|
|
876
889
|
}
|
|
877
|
-
return
|
|
890
|
+
return {
|
|
891
|
+
posts: orderChannelPosts([...byPostId.values()].filter((a) => !removed.has(a.postId))),
|
|
892
|
+
unchecked: [...unchecked].filter((id) => !byPostId.has(id)).length,
|
|
893
|
+
removalsChecked: !removalsUnread
|
|
894
|
+
};
|
|
878
895
|
}
|
|
879
896
|
|
|
880
897
|
// src/directory-legacy.json
|
|
@@ -903,6 +920,7 @@ var PAGE = 200;
|
|
|
903
920
|
var MAX_DIRECTORY_PAGES = 25;
|
|
904
921
|
var AUDIT_PAGES = 2;
|
|
905
922
|
var HEADER_BUDGET = 128;
|
|
923
|
+
var sentOn = (got) => Math.max(got.sent ?? 0, got.events.length);
|
|
906
924
|
var REFERENCE_LEGACY_CLAIMS = directory_legacy_default;
|
|
907
925
|
var legacyIndex = (entries) => new Map(entries.map((e) => [e.listing_event_id, e]));
|
|
908
926
|
async function readAll(page, relay, d, maxPages) {
|
|
@@ -924,7 +942,7 @@ async function readAll(page, relay, d, maxPages) {
|
|
|
924
942
|
}
|
|
925
943
|
until = until === void 0 ? ev.created_at : Math.min(until, ev.created_at);
|
|
926
944
|
}
|
|
927
|
-
if (got
|
|
945
|
+
if (sentOn(got) < PAGE) return [...seen.values()];
|
|
928
946
|
if (added === 0) return null;
|
|
929
947
|
}
|
|
930
948
|
return null;
|
|
@@ -948,7 +966,7 @@ async function readSome(page, relay, d, pages) {
|
|
|
948
966
|
seen.set(ev.id, ev);
|
|
949
967
|
until = until === void 0 ? ev.created_at : Math.min(until, ev.created_at);
|
|
950
968
|
}
|
|
951
|
-
if (!got.complete || got
|
|
969
|
+
if (!got.complete || sentOn(got) < PAGE) break;
|
|
952
970
|
}
|
|
953
971
|
return [...seen.values()];
|
|
954
972
|
}
|