@orangecheck/chat-core 0.1.0 → 0.2.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/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({
@@ -754,8 +757,11 @@ async function readChannelVersions(cid, reads, founderHint) {
754
757
  });
755
758
  const fresh = add(res);
756
759
  for (const e of res.events ?? []) until = Math.min(until ?? Infinity, e.created_at);
757
- if ((res.events ?? []).length < VERSION_PAGE_LIMIT || fresh === 0) break;
758
- if (page === VERSION_MAX_PAGES - 1) truncated = true;
760
+ if ((res.events ?? []).length < VERSION_PAGE_LIMIT) break;
761
+ if (fresh === 0 || page === VERSION_MAX_PAGES - 1) {
762
+ truncated = true;
763
+ break;
764
+ }
759
765
  }
760
766
  add(await legacy);
761
767
  let incomplete = false;
@@ -852,15 +858,25 @@ function orderChannelPosts(posts) {
852
858
  async function verifyChannelPosts(events, descriptor, opts) {
853
859
  const removed = /* @__PURE__ */ new Set();
854
860
  const byPostId = /* @__PURE__ */ new Map();
861
+ const unchecked = /* @__PURE__ */ new Set();
862
+ let removalsUnread = false;
855
863
  for (const ev of events) {
856
864
  const content = parsePost(ev);
857
865
  if (!content || content.channel_id !== descriptor.channel_id) continue;
858
866
  const controlSig = ev.tags.find((t) => t[0] === "control_sig")?.[1];
859
- const v = await verifyPost(content, descriptor, {
860
- ...opts,
861
- event: ev,
862
- ...controlSig ? { controlSig } : {}
863
- });
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
+ }
864
880
  if (!v.ok) continue;
865
881
  if (v.isTombstone && content.removes) {
866
882
  removed.add(content.removes);
@@ -871,7 +887,11 @@ async function verifyChannelPosts(events, descriptor, opts) {
871
887
  byPostId.set(v.postId, { post: content, postId: v.postId, event: ev });
872
888
  }
873
889
  }
874
- return orderChannelPosts([...byPostId.values()].filter((a) => !removed.has(a.postId)));
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
+ };
875
895
  }
876
896
 
877
897
  // src/directory-legacy.json