@orangecheck/chat-core 0.1.1 → 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/{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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +23 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -6
- 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/io.test.ts +97 -51
- package/src/io.ts +95 -50
|
@@ -223,7 +223,7 @@ declare function verifyDescriptor(content: DescriptorContent, event: NostrEvent,
|
|
|
223
223
|
isBound: IsBound;
|
|
224
224
|
}): Promise<DescriptorVerify>;
|
|
225
225
|
interface VerifyPostOpts {
|
|
226
|
-
tipHeight: number;
|
|
226
|
+
tipHeight: number | 'unanswered';
|
|
227
227
|
controlSig?: string;
|
|
228
228
|
allowlist?: string[];
|
|
229
229
|
event?: NostrEvent;
|
|
@@ -293,9 +293,14 @@ interface ChannelPost {
|
|
|
293
293
|
postId: string;
|
|
294
294
|
event: NostrEvent;
|
|
295
295
|
}
|
|
296
|
+
interface ChannelPosts {
|
|
297
|
+
posts: ChannelPost[];
|
|
298
|
+
unchecked: number;
|
|
299
|
+
removalsChecked: boolean;
|
|
300
|
+
}
|
|
296
301
|
declare function orderChannelPosts(posts: ChannelPost[]): ChannelPost[];
|
|
297
302
|
declare function verifyChannelPosts(events: readonly NostrEvent[], descriptor: DescriptorContent, opts: Pick<VerifyPostOpts, 'tipHeight' | 'verifyBip322' | 'verifyOnChain'> & {
|
|
298
303
|
isBound: IsBound;
|
|
299
|
-
}): Promise<
|
|
304
|
+
}): Promise<ChannelPosts>;
|
|
300
305
|
|
|
301
|
-
export {
|
|
306
|
+
export { hasBindingTag as $, type AuthHostKey as A, type BindingVerifiers as B, CHANNEL_DESCRIPTOR_KIND as C, DEVICE_RECORD_RELAYS as D, type WritePolicy as E, type WriteProof as F, type WriteProofVerdict as G, allowlistRoot as H, type IsBound as I, answeredEvents as J, authorizedCopy as K, type Liveness as L, MAX_ATTACHMENT_BYTES as M, btcBindingLive as N, channelId as O, type ParsedSessionDeviceEvent as P, type Query as Q, REVOCATION_JWS_TYP as R, type SessionRevocations as S, checkWritePolicy as T, UnansweredReadError as U, type VerifyBip322 as V, WRITE_QUORUM as W, completeAnswers as X, descriptorDtag as Y, descriptorId as Z, evaluateWriteProof as _, type VersionBinding as a, isBitcoinAddress as a0, isRootedPolicy as a1, isValidAttachment as a2, isValidSlug as a3, liveSessionDevices as a4, meetsReadFloor as a5, orderChannelPosts as a6, parseDescriptor as a7, parsePost as a8, parseSessionDeviceEvent as a9, policyRootedMatches as aa, postDtag as ab, postId as ac, publishToQuorum as ad, readChannelVersions as ae, readFloor as af, readVersionBinding as ag, recordBinding as ah, resolveChannelChain as ai, roleOf as aj, sessionBindingRevoked as ak, sessionDeviceDtag as al, sessionDeviceRevoked as am, sessionKeysEverBound as an, sessionRevocations as ao, verifyChannelPosts as ap, verifyDescriptor as aq, verifyHostRevocation as ar, verifyPost as as, verifySessionVouch as at, versionDtag as au, vouchIssuedAt as av, vouchRequestStatement as aw, vouchedSessionDevices as ax, AUTH_HOST_JWKS_URL as b, type Attachment as c, CHANNEL_POST_KIND as d, CHAT_RELAYS as e, type ChainReads as f, type ChannelError as g, type ChannelPost as h, type ChannelPosts as i, type ChannelWrite as j, type CopyStanding as k, type DescriptorContent as l, type DescriptorVerify as m, type PostContent as n, type PostVerify as o, type QueryAnswer as p, type ResolvedChannel as q, type ResolvedVersion as r, type Role as s, VOUCH_JWS_TYP as t, type VerifyOnChain as u, type VerifyPostOpts as v, type VersionReads as w, type VouchSubject as x, type WriteAck as y, type WriteOutcome as z };
|
|
@@ -223,7 +223,7 @@ declare function verifyDescriptor(content: DescriptorContent, event: NostrEvent,
|
|
|
223
223
|
isBound: IsBound;
|
|
224
224
|
}): Promise<DescriptorVerify>;
|
|
225
225
|
interface VerifyPostOpts {
|
|
226
|
-
tipHeight: number;
|
|
226
|
+
tipHeight: number | 'unanswered';
|
|
227
227
|
controlSig?: string;
|
|
228
228
|
allowlist?: string[];
|
|
229
229
|
event?: NostrEvent;
|
|
@@ -293,9 +293,14 @@ interface ChannelPost {
|
|
|
293
293
|
postId: string;
|
|
294
294
|
event: NostrEvent;
|
|
295
295
|
}
|
|
296
|
+
interface ChannelPosts {
|
|
297
|
+
posts: ChannelPost[];
|
|
298
|
+
unchecked: number;
|
|
299
|
+
removalsChecked: boolean;
|
|
300
|
+
}
|
|
296
301
|
declare function orderChannelPosts(posts: ChannelPost[]): ChannelPost[];
|
|
297
302
|
declare function verifyChannelPosts(events: readonly NostrEvent[], descriptor: DescriptorContent, opts: Pick<VerifyPostOpts, 'tipHeight' | 'verifyBip322' | 'verifyOnChain'> & {
|
|
298
303
|
isBound: IsBound;
|
|
299
|
-
}): Promise<
|
|
304
|
+
}): Promise<ChannelPosts>;
|
|
300
305
|
|
|
301
|
-
export {
|
|
306
|
+
export { hasBindingTag as $, type AuthHostKey as A, type BindingVerifiers as B, CHANNEL_DESCRIPTOR_KIND as C, DEVICE_RECORD_RELAYS as D, type WritePolicy as E, type WriteProof as F, type WriteProofVerdict as G, allowlistRoot as H, type IsBound as I, answeredEvents as J, authorizedCopy as K, type Liveness as L, MAX_ATTACHMENT_BYTES as M, btcBindingLive as N, channelId as O, type ParsedSessionDeviceEvent as P, type Query as Q, REVOCATION_JWS_TYP as R, type SessionRevocations as S, checkWritePolicy as T, UnansweredReadError as U, type VerifyBip322 as V, WRITE_QUORUM as W, completeAnswers as X, descriptorDtag as Y, descriptorId as Z, evaluateWriteProof as _, type VersionBinding as a, isBitcoinAddress as a0, isRootedPolicy as a1, isValidAttachment as a2, isValidSlug as a3, liveSessionDevices as a4, meetsReadFloor as a5, orderChannelPosts as a6, parseDescriptor as a7, parsePost as a8, parseSessionDeviceEvent as a9, policyRootedMatches as aa, postDtag as ab, postId as ac, publishToQuorum as ad, readChannelVersions as ae, readFloor as af, readVersionBinding as ag, recordBinding as ah, resolveChannelChain as ai, roleOf as aj, sessionBindingRevoked as ak, sessionDeviceDtag as al, sessionDeviceRevoked as am, sessionKeysEverBound as an, sessionRevocations as ao, verifyChannelPosts as ap, verifyDescriptor as aq, verifyHostRevocation as ar, verifyPost as as, verifySessionVouch as at, versionDtag as au, vouchIssuedAt as av, vouchRequestStatement as aw, vouchedSessionDevices as ax, AUTH_HOST_JWKS_URL as b, type Attachment as c, CHANNEL_POST_KIND as d, CHAT_RELAYS as e, type ChainReads as f, type ChannelError as g, type ChannelPost as h, type ChannelPosts as i, type ChannelWrite as j, type CopyStanding as k, type DescriptorContent as l, type DescriptorVerify as m, type PostContent as n, type PostVerify as o, type QueryAnswer as p, type ResolvedChannel as q, type ResolvedVersion as r, type Role as s, VOUCH_JWS_TYP as t, type VerifyOnChain as u, type VerifyPostOpts as v, type VersionReads as w, type VouchSubject as x, type WriteAck as y, type WriteOutcome as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as AuthHostKey, V as VerifyBip322, I as IsBound, a as VersionBinding, L as Liveness } from './channel-
|
|
2
|
-
export { b as AUTH_HOST_JWKS_URL, c as Attachment, B as BindingVerifiers, C as CHANNEL_DESCRIPTOR_KIND, d as CHANNEL_POST_KIND, e as CHAT_RELAYS, f as ChainReads, g as ChannelError, h as ChannelPost, i as
|
|
1
|
+
import { A as AuthHostKey, V as VerifyBip322, I as IsBound, a as VersionBinding, L as Liveness } from './channel-ChK3AAvd.mjs';
|
|
2
|
+
export { b as AUTH_HOST_JWKS_URL, c as Attachment, B as BindingVerifiers, C as CHANNEL_DESCRIPTOR_KIND, d as CHANNEL_POST_KIND, e as CHAT_RELAYS, f as ChainReads, g as ChannelError, h as ChannelPost, i as ChannelPosts, j as ChannelWrite, k as CopyStanding, D as DEVICE_RECORD_RELAYS, l as DescriptorContent, m as DescriptorVerify, M as MAX_ATTACHMENT_BYTES, P as ParsedSessionDeviceEvent, n as PostContent, o as PostVerify, Q as Query, p as QueryAnswer, R as REVOCATION_JWS_TYP, q as ResolvedChannel, r as ResolvedVersion, s as Role, S as SessionRevocations, U as UnansweredReadError, t as VOUCH_JWS_TYP, u as VerifyOnChain, v as VerifyPostOpts, w as VersionReads, x as VouchSubject, W as WRITE_QUORUM, y as WriteAck, z as WriteOutcome, E as WritePolicy, F as WriteProof, G as WriteProofVerdict, H as allowlistRoot, J as answeredEvents, K as authorizedCopy, N as btcBindingLive, O as channelId, T as checkWritePolicy, X as completeAnswers, Y as descriptorDtag, Z as descriptorId, _ as evaluateWriteProof, $ as hasBindingTag, a0 as isBitcoinAddress, a1 as isRootedPolicy, a2 as isValidAttachment, a3 as isValidSlug, a4 as liveSessionDevices, a5 as meetsReadFloor, a6 as orderChannelPosts, a7 as parseDescriptor, a8 as parsePost, a9 as parseSessionDeviceEvent, aa as policyRootedMatches, ab as postDtag, ac as postId, ad as publishToQuorum, ae as readChannelVersions, af as readFloor, ag as readVersionBinding, ah as recordBinding, ai as resolveChannelChain, aj as roleOf, ak as sessionBindingRevoked, al as sessionDeviceDtag, am as sessionDeviceRevoked, an as sessionKeysEverBound, ao as sessionRevocations, ap as verifyChannelPosts, aq as verifyDescriptor, ar as verifyHostRevocation, as as verifyPost, at as verifySessionVouch, au as versionDtag, av as vouchIssuedAt, aw as vouchRequestStatement, ax as vouchedSessionDevices } from './channel-ChK3AAvd.mjs';
|
|
3
3
|
import { CoinFacts, DirectoryRecord } from '@orangecheck/lock-core/directory';
|
|
4
4
|
import { NostrEvent, ParsedDeviceEvent } from '@orangecheck/lock-device';
|
|
5
5
|
export { NostrEvent, verifyNostrEvent } from '@orangecheck/lock-device';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as AuthHostKey, V as VerifyBip322, I as IsBound, a as VersionBinding, L as Liveness } from './channel-
|
|
2
|
-
export { b as AUTH_HOST_JWKS_URL, c as Attachment, B as BindingVerifiers, C as CHANNEL_DESCRIPTOR_KIND, d as CHANNEL_POST_KIND, e as CHAT_RELAYS, f as ChainReads, g as ChannelError, h as ChannelPost, i as
|
|
1
|
+
import { A as AuthHostKey, V as VerifyBip322, I as IsBound, a as VersionBinding, L as Liveness } from './channel-ChK3AAvd.js';
|
|
2
|
+
export { b as AUTH_HOST_JWKS_URL, c as Attachment, B as BindingVerifiers, C as CHANNEL_DESCRIPTOR_KIND, d as CHANNEL_POST_KIND, e as CHAT_RELAYS, f as ChainReads, g as ChannelError, h as ChannelPost, i as ChannelPosts, j as ChannelWrite, k as CopyStanding, D as DEVICE_RECORD_RELAYS, l as DescriptorContent, m as DescriptorVerify, M as MAX_ATTACHMENT_BYTES, P as ParsedSessionDeviceEvent, n as PostContent, o as PostVerify, Q as Query, p as QueryAnswer, R as REVOCATION_JWS_TYP, q as ResolvedChannel, r as ResolvedVersion, s as Role, S as SessionRevocations, U as UnansweredReadError, t as VOUCH_JWS_TYP, u as VerifyOnChain, v as VerifyPostOpts, w as VersionReads, x as VouchSubject, W as WRITE_QUORUM, y as WriteAck, z as WriteOutcome, E as WritePolicy, F as WriteProof, G as WriteProofVerdict, H as allowlistRoot, J as answeredEvents, K as authorizedCopy, N as btcBindingLive, O as channelId, T as checkWritePolicy, X as completeAnswers, Y as descriptorDtag, Z as descriptorId, _ as evaluateWriteProof, $ as hasBindingTag, a0 as isBitcoinAddress, a1 as isRootedPolicy, a2 as isValidAttachment, a3 as isValidSlug, a4 as liveSessionDevices, a5 as meetsReadFloor, a6 as orderChannelPosts, a7 as parseDescriptor, a8 as parsePost, a9 as parseSessionDeviceEvent, aa as policyRootedMatches, ab as postDtag, ac as postId, ad as publishToQuorum, ae as readChannelVersions, af as readFloor, ag as readVersionBinding, ah as recordBinding, ai as resolveChannelChain, aj as roleOf, ak as sessionBindingRevoked, al as sessionDeviceDtag, am as sessionDeviceRevoked, an as sessionKeysEverBound, ao as sessionRevocations, ap as verifyChannelPosts, aq as verifyDescriptor, ar as verifyHostRevocation, as as verifyPost, at as verifySessionVouch, au as versionDtag, av as vouchIssuedAt, aw as vouchRequestStatement, ax as vouchedSessionDevices } from './channel-ChK3AAvd.js';
|
|
3
3
|
import { CoinFacts, DirectoryRecord } from '@orangecheck/lock-core/directory';
|
|
4
4
|
import { NostrEvent, ParsedDeviceEvent } from '@orangecheck/lock-device';
|
|
5
5
|
export { NostrEvent, verifyNostrEvent } from '@orangecheck/lock-device';
|
package/dist/index.js
CHANGED
|
@@ -513,6 +513,9 @@ async function checkWritePermission(content, descriptor, role, pid, opts, verify
|
|
|
513
513
|
if (!content.write_proof) return "E_CHAN_FLOOR";
|
|
514
514
|
if (!opts.controlSig) return "E_CHAN_FLOOR";
|
|
515
515
|
if (!isBitcoinAddress(content.author_address)) return "E_CHAN_FLOOR";
|
|
516
|
+
if (opts.tipHeight === "unanswered") {
|
|
517
|
+
throw new chunkGFFQSF75_js.UnansweredReadError("the chain tip could not be read");
|
|
518
|
+
}
|
|
516
519
|
const v = evaluateWriteProof(content.write_proof, w, opts.tipHeight);
|
|
517
520
|
if (v.verdict !== "accept") return "E_CHAN_FLOOR";
|
|
518
521
|
const sigOk = await verify({
|
|
@@ -854,15 +857,25 @@ function orderChannelPosts(posts) {
|
|
|
854
857
|
async function verifyChannelPosts(events, descriptor, opts) {
|
|
855
858
|
const removed = /* @__PURE__ */ new Set();
|
|
856
859
|
const byPostId = /* @__PURE__ */ new Map();
|
|
860
|
+
const unchecked = /* @__PURE__ */ new Set();
|
|
861
|
+
let removalsUnread = false;
|
|
857
862
|
for (const ev of events) {
|
|
858
863
|
const content = parsePost(ev);
|
|
859
864
|
if (!content || content.channel_id !== descriptor.channel_id) continue;
|
|
860
865
|
const controlSig = ev.tags.find((t) => t[0] === "control_sig")?.[1];
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
+
let v;
|
|
867
|
+
try {
|
|
868
|
+
v = await verifyPost(content, descriptor, {
|
|
869
|
+
...opts,
|
|
870
|
+
event: ev,
|
|
871
|
+
...controlSig ? { controlSig } : {}
|
|
872
|
+
});
|
|
873
|
+
} catch (e) {
|
|
874
|
+
if (!(e instanceof chunkGFFQSF75_js.UnansweredReadError)) throw e;
|
|
875
|
+
unchecked.add(postId(content));
|
|
876
|
+
if (typeof content.removes === "string") removalsUnread = true;
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
866
879
|
if (!v.ok) continue;
|
|
867
880
|
if (v.isTombstone && content.removes) {
|
|
868
881
|
removed.add(content.removes);
|
|
@@ -873,7 +886,11 @@ async function verifyChannelPosts(events, descriptor, opts) {
|
|
|
873
886
|
byPostId.set(v.postId, { post: content, postId: v.postId, event: ev });
|
|
874
887
|
}
|
|
875
888
|
}
|
|
876
|
-
return
|
|
889
|
+
return {
|
|
890
|
+
posts: orderChannelPosts([...byPostId.values()].filter((a) => !removed.has(a.postId))),
|
|
891
|
+
unchecked: [...unchecked].filter((id) => !byPostId.has(id)).length,
|
|
892
|
+
removalsChecked: !removalsUnread
|
|
893
|
+
};
|
|
877
894
|
}
|
|
878
895
|
|
|
879
896
|
// src/directory-legacy.json
|