@zanii/status-feed 0.0.0-stage → 0.1.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/LICENSE +159 -0
- package/README.md +57 -2
- package/dist/index.d.ts +124 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +231 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -3
- package/src/index.ts +268 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work; and
|
|
103
|
+
|
|
104
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
105
|
+
distribution, then any Derivative Works that You distribute must
|
|
106
|
+
include a readable copy of the attribution notices contained
|
|
107
|
+
within such NOTICE file.
|
|
108
|
+
|
|
109
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
110
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
111
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
112
|
+
this License, without any additional terms or conditions.
|
|
113
|
+
|
|
114
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
115
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
116
|
+
except as required for reasonable and customary use in describing the
|
|
117
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
118
|
+
|
|
119
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
120
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
121
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
122
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
123
|
+
without limitation, any warranties or conditions of TITLE,
|
|
124
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
|
125
|
+
|
|
126
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
127
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
128
|
+
unless required by applicable law (such as deliberate and grossly
|
|
129
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
130
|
+
liable to You for damages, including any direct, indirect, special,
|
|
131
|
+
incidental, or consequential damages of any character arising as a
|
|
132
|
+
result of this License or out of the use or inability to use the
|
|
133
|
+
Work.
|
|
134
|
+
|
|
135
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
136
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
137
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
138
|
+
or other liability obligations and/or rights consistent with this
|
|
139
|
+
License. However, in accepting such obligations, You may act only
|
|
140
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
141
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
142
|
+
defend, and hold each Contributor harmless for any liability
|
|
143
|
+
incurred by, or claims asserted against, such Contributor.
|
|
144
|
+
|
|
145
|
+
END OF TERMS AND CONDITIONS
|
|
146
|
+
|
|
147
|
+
Copyright 2026 Zanii
|
|
148
|
+
|
|
149
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
150
|
+
you may not use this file except in compliance with the License.
|
|
151
|
+
You may obtain a copy of the License at
|
|
152
|
+
|
|
153
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
154
|
+
|
|
155
|
+
Unless required by applicable law or agreed to in writing, software
|
|
156
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
157
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
158
|
+
See the License for the specific language governing permissions and
|
|
159
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zanii/status-feed
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**One signed, append-only, hash-chained feed of status events per jurisdiction, each event with its evidence.**
|
|
4
|
+
|
|
5
|
+
A regulator (or the Ledger operator) publishes what changed for the AI agents in its sector: delegation revocations, Certify certificate suspensions, revocations and reinstatements, incidents opened and closed, jurisdiction bindings issued and expired. Each entry names the previous entry's hash and its sequence number and is signed by the feed signer. Readers verify the whole chain, or catch up from a head they already trust.
|
|
6
|
+
|
|
7
|
+
- **`appendEvent(feed, event, signerKey)`** returns `{ entry, head }`, the next signed entry and the new head `{ seq, hash }`. It is pure: store `entry` yourself. It refuses a malformed event and an event dated before the head.
|
|
8
|
+
- **`verifyFeed(entries, { signers, jurisdiction?, after? })`** returns `{ ok, reasons, head }`. It checks the entry shape, signatures by allowed signers, one jurisdiction, sequence numbers from 1 with no gaps, the `prev` hash chain, non-decreasing time and well-formed events. `after` is a trusted earlier head for verifying a suffix.
|
|
9
|
+
- **`feedSince(entries, seq)`** returns the entries after `seq`.
|
|
10
|
+
- **`toAtom(entries, opts)`** (Atom 1.0, RFC 4287) and **`toJsonFeed(entries, opts)`** (JSON Feed 1.1) are for publishing. Each item carries the entry's canonical JSON, so a reader can verify what it fetched.
|
|
11
|
+
- **`anchorFeedHead(entries)`** returns `{ target: 'regulator.status_feed.head', payload }` for `agent.record(...)` (`@zanii/sdk`). The receipt's payload hash commits to the head and the log's inclusion proof dates it. No new server routes.
|
|
12
|
+
- Event builders derive `ref` and `evidence` from the record: `revocationEvent(record)` (a `@zanii/core` revocation, which must verify), `certificateStatusEvent({ certificate, holder, action, reason, since, statusDocument })`, `incidentEvent({ action, incident, subject, report, ts })`, `jurisdictionEvent(binding, 'issued' | 'expired')`.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { appendEvent, revocationEvent, certificateStatusEvent, verifyFeed, toAtom, anchorFeedHead } from '@zanii/status-feed';
|
|
16
|
+
|
|
17
|
+
const feed = { jurisdiction: 'AE-DIFC', entries: [] as FeedEntry[] };
|
|
18
|
+
feed.entries.push(appendEvent(feed, revocationEvent(revocationRecord), operatorKey).entry);
|
|
19
|
+
feed.entries.push(appendEvent(feed, certificateStatusEvent({
|
|
20
|
+
certificate: certHash, holder: agentDid, action: 'suspend', reason: 'FALSE_DECLARATION',
|
|
21
|
+
since: '2026-10-29T08:00:00.000Z', statusDocument, // the signed certify.status document, or its hash
|
|
22
|
+
}), operatorKey).entry);
|
|
23
|
+
|
|
24
|
+
verifyFeed(feed.entries, { signers: [operatorDid] }); // { ok: true, reasons: [], head: { seq: 2, hash } }
|
|
25
|
+
const atom = toAtom(feed.entries, { link: 'https://example.org/feeds/ae-difc.atom' });
|
|
26
|
+
await agent.record(anchorFeedHead(feed.entries)); // anchor the head on the Ledger
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Feed format
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"v": 1, "type": "zanii.status_feed", "jurisdiction": "AE-DIFC", "seq": 2, "prev": "sha256:<hash of entry 1>",
|
|
34
|
+
"event": { "kind": "certificate.suspended", "subject": "did:key:...", "ref": "sha256:<certificate hash>",
|
|
35
|
+
"ts": "2026-10-29T08:00:00.000Z", "reason": "FALSE_DECLARATION", "evidence": ["sha256:<status document hash>"] },
|
|
36
|
+
"signer": "did:key:...", "sig": "ed25519:..."
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The entry is a `@zanii/core` signed object. An entry's hash is `jcsHash` of the whole signed entry, and the first entry has `prev: null`, `seq: 1`.
|
|
41
|
+
|
|
42
|
+
| `kind` | `ref` | `evidence` | `reason` |
|
|
43
|
+
|---|---|---|---|
|
|
44
|
+
| `delegation.revoked` | delegation cert hash (`certHash`) | revocation record hash | null or text |
|
|
45
|
+
| `certificate.suspended`, `certificate.revoked` | certificate hash | `certify.status` document hash | Certify reason code, versions 1 to 3, e.g. `FALSE_DECLARATION`, `EVIDENCE_LAPSED` (Certify `spec/status.md`) |
|
|
46
|
+
| `certificate.reinstated` | certificate hash | status document hash | null |
|
|
47
|
+
| `incident.opened`, `incident.closed` | incident id | incident report hash | null or text |
|
|
48
|
+
| `jurisdiction.issued`, `jurisdiction.expired` | binding hash | binding hash | null |
|
|
49
|
+
|
|
50
|
+
**Honest limits:** the feed proves that its signer published these events in this order. It does not make them true, so check the evidence each hash names. Without an anchored head, an operator could serve different feeds to different readers. Anchor heads regularly and compare them.
|
|
51
|
+
|
|
52
|
+
## Changelog
|
|
53
|
+
|
|
54
|
+
- **0.1.0**: initial release. Append, verify, since, Atom and JSON Feed rendering, Ledger head anchoring and event builders. Python twin `zanii.status_feed`, checked by shared vectors.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zanii/status-feed: one signed, append-only, hash-chained feed of status events per
|
|
3
|
+
* jurisdiction. Each entry names the previous entry's hash and its sequence number, is
|
|
4
|
+
* signed by the feed operator (a regulator or the Ledger operator) and carries the hashes
|
|
5
|
+
* of the evidence behind the event: a delegation revocation, a Certify status document,
|
|
6
|
+
* an incident report, a jurisdiction binding.
|
|
7
|
+
*
|
|
8
|
+
* The feed says that its signer published these events in this order. It does not make
|
|
9
|
+
* the events true: a verifier checks the evidence the hashes name. Anchoring the head as
|
|
10
|
+
* a Ledger receipt (`anchorFeedHead`) fixes the feed's history in the transparency log so
|
|
11
|
+
* the operator cannot rewrite it unseen.
|
|
12
|
+
*/
|
|
13
|
+
import { type RevocationRecord, type SignedObject } from '@zanii/core';
|
|
14
|
+
export declare const FEED_TYPE: "zanii.status_feed";
|
|
15
|
+
export declare const EVENT_KINDS: readonly ["delegation.revoked", "certificate.suspended", "certificate.revoked", "certificate.reinstated", "incident.opened", "incident.closed", "jurisdiction.issued", "jurisdiction.expired"];
|
|
16
|
+
export type EventKind = (typeof EVENT_KINDS)[number];
|
|
17
|
+
/** Certify status reason codes, versions 1 to 3 (Certify spec/status.md sections 2, 6, 7). */
|
|
18
|
+
export declare const CERTIFY_REASONS: readonly ["FINGERPRINT_MISMATCH", "RETEST_OVERDUE", "RETEST_FAILED", "INCIDENT", "APPLICANT_REQUEST", "ISSUER_ERROR", "LICENCE_WITHDRAWN", "AUDIT_EXPIRED", "MARK_MISUSE", "FALSE_DECLARATION", "EVIDENCE_LAPSED"];
|
|
19
|
+
export interface StatusEvent {
|
|
20
|
+
kind: EventKind;
|
|
21
|
+
/** The did:key the event is about (usually the agent). */
|
|
22
|
+
subject: string;
|
|
23
|
+
/** What the event names: a delegation cert hash, a certificate hash, an incident id, a binding hash. */
|
|
24
|
+
ref: string;
|
|
25
|
+
ts: string;
|
|
26
|
+
/** Certify reason code for certificate suspend and revoke; null for reinstate; free text or null otherwise. */
|
|
27
|
+
reason: string | null;
|
|
28
|
+
/** `sha256:` hashes of the evidence; sorted and distinct in the entry. */
|
|
29
|
+
evidence: string[];
|
|
30
|
+
}
|
|
31
|
+
export type FeedEntry = SignedObject<{
|
|
32
|
+
v: 1;
|
|
33
|
+
type: typeof FEED_TYPE;
|
|
34
|
+
jurisdiction: string;
|
|
35
|
+
seq: number;
|
|
36
|
+
prev: string | null;
|
|
37
|
+
event: StatusEvent;
|
|
38
|
+
}>;
|
|
39
|
+
export interface FeedHead {
|
|
40
|
+
seq: number;
|
|
41
|
+
hash: string;
|
|
42
|
+
}
|
|
43
|
+
export interface Feed {
|
|
44
|
+
jurisdiction: string;
|
|
45
|
+
entries: FeedEntry[];
|
|
46
|
+
}
|
|
47
|
+
/** The hash later entries chain to: `jcsHash` of the whole signed entry. */
|
|
48
|
+
export declare function entryHash(entry: FeedEntry): string;
|
|
49
|
+
/** Why an event is malformed; empty when it is well formed. */
|
|
50
|
+
export declare function eventReasons(e: unknown): string[];
|
|
51
|
+
/** The last entry's position, or null for an empty feed. */
|
|
52
|
+
export declare function feedHead(entries: FeedEntry[]): FeedHead | null;
|
|
53
|
+
/**
|
|
54
|
+
* Sign the next entry of `feed` and return it with the new head. Pure: the caller appends
|
|
55
|
+
* `entry` to its stored feed. Refuses a malformed event and an event dated before the head.
|
|
56
|
+
*/
|
|
57
|
+
export declare function appendEvent(feed: Feed, event: StatusEvent, signerKey: Uint8Array): {
|
|
58
|
+
entry: FeedEntry;
|
|
59
|
+
head: FeedHead;
|
|
60
|
+
};
|
|
61
|
+
export interface VerifyFeedOptions {
|
|
62
|
+
/** The DIDs allowed to sign entries (key rotation: list old and new). */
|
|
63
|
+
signers: string[];
|
|
64
|
+
/** Expected jurisdiction; defaults to the first entry's. */
|
|
65
|
+
jurisdiction?: string;
|
|
66
|
+
/** A trusted earlier head, to verify a suffix such as `feedSince(entries, after.seq)`. */
|
|
67
|
+
after?: FeedHead;
|
|
68
|
+
}
|
|
69
|
+
export interface VerifyFeedResult {
|
|
70
|
+
ok: boolean;
|
|
71
|
+
reasons: string[];
|
|
72
|
+
head: FeedHead | null;
|
|
73
|
+
}
|
|
74
|
+
/** Chain continuity, sequence without gaps, signatures by allowed signers, non-decreasing time, well-formed events. */
|
|
75
|
+
export declare function verifyFeed(entries: FeedEntry[], opts: VerifyFeedOptions): VerifyFeedResult;
|
|
76
|
+
/** Entries after sequence number `seq` (0 = all), for a reader catching up. */
|
|
77
|
+
export declare function feedSince(entries: FeedEntry[], seq: number): FeedEntry[];
|
|
78
|
+
/** A Ledger delegation revocation (`createRevocation` / `submitRevocation`). The record must verify. */
|
|
79
|
+
export declare function revocationEvent(record: RevocationRecord, opts?: {
|
|
80
|
+
reason?: string | null;
|
|
81
|
+
}): StatusEvent;
|
|
82
|
+
/** A Certify status change. `statusDocument` is the signed `certify.status` document (or its hash) that carries it. */
|
|
83
|
+
export declare function certificateStatusEvent(c: {
|
|
84
|
+
certificate: string;
|
|
85
|
+
holder: string;
|
|
86
|
+
action: 'suspend' | 'revoke' | 'reinstate';
|
|
87
|
+
reason: string | null;
|
|
88
|
+
since: string;
|
|
89
|
+
statusDocument: string | object;
|
|
90
|
+
}): StatusEvent;
|
|
91
|
+
/** An incident opened or closed, citing the incident report (or its hash). */
|
|
92
|
+
export declare function incidentEvent(i: {
|
|
93
|
+
action: 'opened' | 'closed';
|
|
94
|
+
incident: string;
|
|
95
|
+
subject: string;
|
|
96
|
+
report: string | object;
|
|
97
|
+
ts: string;
|
|
98
|
+
reason?: string | null;
|
|
99
|
+
}): StatusEvent;
|
|
100
|
+
/** A `zanii.jurisdiction` binding issued or expired; `ts` defaults to its `issued_at` / `expires_at`. */
|
|
101
|
+
export declare function jurisdictionEvent(binding: {
|
|
102
|
+
subject: string;
|
|
103
|
+
issued_at: string;
|
|
104
|
+
expires_at: string;
|
|
105
|
+
}, action: 'issued' | 'expired', ts?: string): StatusEvent;
|
|
106
|
+
export interface RenderOptions {
|
|
107
|
+
title?: string;
|
|
108
|
+
id?: string;
|
|
109
|
+
link?: string;
|
|
110
|
+
updated?: string;
|
|
111
|
+
}
|
|
112
|
+
/** Atom 1.0 (RFC 4287). Each entry's content is its canonical JSON, so a reader can verify it. */
|
|
113
|
+
export declare function toAtom(entries: FeedEntry[], opts?: RenderOptions): string;
|
|
114
|
+
/** JSON Feed 1.1. `_zanii_status_feed` carries the signed entry unchanged. */
|
|
115
|
+
export declare function toJsonFeed(entries: FeedEntry[], opts?: RenderOptions): Record<string, unknown>;
|
|
116
|
+
/**
|
|
117
|
+
* The feed head as a Ledger receipt: pass to `agent.record({ target, payload })` (`@zanii/sdk`).
|
|
118
|
+
* The receipt's payload hash then commits to the head, and the log's inclusion proof dates it.
|
|
119
|
+
*/
|
|
120
|
+
export declare function anchorFeedHead(entries: FeedEntry[]): {
|
|
121
|
+
target: string;
|
|
122
|
+
payload: Record<string, unknown>;
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAuF,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5J,eAAO,MAAM,SAAS,EAAG,mBAA4B,CAAC;AAEtD,eAAO,MAAM,WAAW,gMASd,CAAC;AACX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,8FAA8F;AAC9F,eAAO,MAAM,eAAe,oNAGlB,CAAC;AAEX,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,wGAAwG;IACxG,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,+GAA+G;IAC/G,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,MAAM,SAAS,GAAG,YAAY,CAAC;IACnC,CAAC,EAAE,CAAC,CAAC;IACL,IAAI,EAAE,OAAO,SAAS,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC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EAAE,MAAM,CAAA;CAAE;AAM/F,kGAAkG;AAClG,wBAAgB,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,IAAI,GAAE,aAAkB,GAAG,MAAM,CAyB7E;AAED,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,IAAI,GAAE,aAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASlG;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAIzG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zanii/status-feed: one signed, append-only, hash-chained feed of status events per
|
|
3
|
+
* jurisdiction. Each entry names the previous entry's hash and its sequence number, is
|
|
4
|
+
* signed by the feed operator (a regulator or the Ledger operator) and carries the hashes
|
|
5
|
+
* of the evidence behind the event: a delegation revocation, a Certify status document,
|
|
6
|
+
* an incident report, a jurisdiction binding.
|
|
7
|
+
*
|
|
8
|
+
* The feed says that its signer published these events in this order. It does not make
|
|
9
|
+
* the events true: a verifier checks the evidence the hashes name. Anchoring the head as
|
|
10
|
+
* a Ledger receipt (`anchorFeedHead`) fixes the feed's history in the transparency log so
|
|
11
|
+
* the operator cannot rewrite it unseen.
|
|
12
|
+
*/
|
|
13
|
+
import { canonicalBytes, certHash, jcsHash, verifyRevocation, signObject, verifySignedObject } from '@zanii/core';
|
|
14
|
+
export const FEED_TYPE = 'zanii.status_feed';
|
|
15
|
+
export const EVENT_KINDS = [
|
|
16
|
+
'delegation.revoked',
|
|
17
|
+
'certificate.suspended',
|
|
18
|
+
'certificate.revoked',
|
|
19
|
+
'certificate.reinstated',
|
|
20
|
+
'incident.opened',
|
|
21
|
+
'incident.closed',
|
|
22
|
+
'jurisdiction.issued',
|
|
23
|
+
'jurisdiction.expired',
|
|
24
|
+
];
|
|
25
|
+
/** Certify status reason codes, versions 1 to 3 (Certify spec/status.md sections 2, 6, 7). */
|
|
26
|
+
export const CERTIFY_REASONS = [
|
|
27
|
+
'FINGERPRINT_MISMATCH', 'RETEST_OVERDUE', 'RETEST_FAILED', 'INCIDENT', 'APPLICANT_REQUEST',
|
|
28
|
+
'ISSUER_ERROR', 'LICENCE_WITHDRAWN', 'AUDIT_EXPIRED', 'MARK_MISUSE', 'FALSE_DECLARATION', 'EVIDENCE_LAPSED',
|
|
29
|
+
];
|
|
30
|
+
const HASH = /^sha256:[0-9a-f]{64}$/;
|
|
31
|
+
const ISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/;
|
|
32
|
+
/** Epoch ms of a strict ISO 8601 UTC-or-offset timestamp, or NaN. */
|
|
33
|
+
function ms(ts) {
|
|
34
|
+
return typeof ts === 'string' && ISO.test(ts) ? Date.parse(ts) : NaN;
|
|
35
|
+
}
|
|
36
|
+
const canonicalJson = (x) => new TextDecoder().decode(canonicalBytes(x));
|
|
37
|
+
/** The hash later entries chain to: `jcsHash` of the whole signed entry. */
|
|
38
|
+
export function entryHash(entry) {
|
|
39
|
+
return jcsHash(entry);
|
|
40
|
+
}
|
|
41
|
+
/** Why an event is malformed; empty when it is well formed. */
|
|
42
|
+
export function eventReasons(e) {
|
|
43
|
+
if (!e || typeof e !== 'object' || Array.isArray(e))
|
|
44
|
+
return ['event is not an object'];
|
|
45
|
+
const ev = e;
|
|
46
|
+
const out = [];
|
|
47
|
+
const keys = Object.keys(ev).sort().join(',');
|
|
48
|
+
if (keys !== 'evidence,kind,reason,ref,subject,ts')
|
|
49
|
+
out.push('event has unexpected or missing fields');
|
|
50
|
+
if (!EVENT_KINDS.includes(ev.kind))
|
|
51
|
+
out.push('unknown event kind');
|
|
52
|
+
if (typeof ev.subject !== 'string' || !ev.subject.startsWith('did:'))
|
|
53
|
+
out.push('event subject is not a DID');
|
|
54
|
+
if (typeof ev.ref !== 'string' || !ev.ref)
|
|
55
|
+
out.push('event ref is empty');
|
|
56
|
+
if (Number.isNaN(ms(ev.ts)))
|
|
57
|
+
out.push('event ts is not an ISO timestamp');
|
|
58
|
+
const ok = Array.isArray(ev.evidence) && ev.evidence.length > 0 && ev.evidence.every((h) => typeof h === 'string' && HASH.test(h));
|
|
59
|
+
if (!ok)
|
|
60
|
+
out.push('event evidence must be a non-empty list of sha256 hashes');
|
|
61
|
+
else if (new Set(ev.evidence).size !== ev.evidence.length || [...ev.evidence].sort().join() !== ev.evidence.join())
|
|
62
|
+
out.push('event evidence is not sorted and distinct');
|
|
63
|
+
if (ev.kind === 'certificate.suspended' || ev.kind === 'certificate.revoked') {
|
|
64
|
+
if (!CERTIFY_REASONS.includes(ev.reason))
|
|
65
|
+
out.push('certificate suspend or revoke needs a Certify reason code');
|
|
66
|
+
}
|
|
67
|
+
else if (ev.kind === 'certificate.reinstated') {
|
|
68
|
+
if (ev.reason !== null)
|
|
69
|
+
out.push('certificate reinstatement carries no reason');
|
|
70
|
+
}
|
|
71
|
+
else if (ev.reason !== null && (typeof ev.reason !== 'string' || !ev.reason))
|
|
72
|
+
out.push('event reason must be null or a non-empty string');
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
function normalize(e) {
|
|
76
|
+
return {
|
|
77
|
+
kind: e.kind, subject: e.subject, ref: e.ref, ts: e.ts, reason: e.reason ?? null,
|
|
78
|
+
evidence: Array.isArray(e.evidence) ? [...new Set(e.evidence)].sort() : e.evidence,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** The last entry's position, or null for an empty feed. */
|
|
82
|
+
export function feedHead(entries) {
|
|
83
|
+
const last = entries[entries.length - 1];
|
|
84
|
+
return last ? { seq: last.seq, hash: entryHash(last) } : null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Sign the next entry of `feed` and return it with the new head. Pure: the caller appends
|
|
88
|
+
* `entry` to its stored feed. Refuses a malformed event and an event dated before the head.
|
|
89
|
+
*/
|
|
90
|
+
export function appendEvent(feed, event, signerKey) {
|
|
91
|
+
if (typeof feed?.jurisdiction !== 'string' || !feed.jurisdiction)
|
|
92
|
+
throw new Error('status-feed: feed.jurisdiction is required');
|
|
93
|
+
const ev = normalize(event);
|
|
94
|
+
const reasons = eventReasons(ev);
|
|
95
|
+
if (reasons.length)
|
|
96
|
+
throw new Error(`status-feed: ${reasons.join('; ')}`);
|
|
97
|
+
const last = feed.entries[feed.entries.length - 1];
|
|
98
|
+
if (last && last.jurisdiction !== feed.jurisdiction)
|
|
99
|
+
throw new Error('status-feed: the feed holds another jurisdiction');
|
|
100
|
+
if (last && ms(ev.ts) < ms(last.event.ts))
|
|
101
|
+
throw new Error('status-feed: event is dated before the feed head');
|
|
102
|
+
const entry = signObject({
|
|
103
|
+
v: 1, type: FEED_TYPE, jurisdiction: feed.jurisdiction,
|
|
104
|
+
seq: last ? last.seq + 1 : 1, prev: last ? entryHash(last) : null, event: ev,
|
|
105
|
+
}, signerKey);
|
|
106
|
+
return { entry, head: { seq: entry.seq, hash: entryHash(entry) } };
|
|
107
|
+
}
|
|
108
|
+
/** Chain continuity, sequence without gaps, signatures by allowed signers, non-decreasing time, well-formed events. */
|
|
109
|
+
export function verifyFeed(entries, opts) {
|
|
110
|
+
const reasons = [];
|
|
111
|
+
if (!Array.isArray(entries))
|
|
112
|
+
return { ok: false, reasons: ['feed is not a list'], head: null };
|
|
113
|
+
if (!Array.isArray(opts?.signers) || !opts.signers.length)
|
|
114
|
+
reasons.push('no signers supplied: signer NOT checked');
|
|
115
|
+
const jurisdiction = opts?.jurisdiction ?? entries[0]?.jurisdiction;
|
|
116
|
+
let prevHash = opts?.after?.hash ?? null;
|
|
117
|
+
let prevSeq = opts?.after?.seq ?? 0;
|
|
118
|
+
let prevTs = NaN;
|
|
119
|
+
entries.forEach((e, i) => {
|
|
120
|
+
const r = (m) => reasons.push(`entry ${i}: ${m}`);
|
|
121
|
+
if (!e || typeof e !== 'object' || e.v !== 1 || e.type !== FEED_TYPE) {
|
|
122
|
+
r('not a status feed entry (v1)');
|
|
123
|
+
prevHash = null;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const keys = Object.keys(e).sort().join(',');
|
|
127
|
+
if (keys !== 'event,jurisdiction,prev,seq,sig,signer,type,v')
|
|
128
|
+
r('entry has unexpected or missing fields');
|
|
129
|
+
if (!verifySignedObject(e))
|
|
130
|
+
r('bad signature');
|
|
131
|
+
else if (opts?.signers?.length && !opts.signers.includes(e.signer))
|
|
132
|
+
r('signed by a key that is not an allowed feed signer');
|
|
133
|
+
if (e.jurisdiction !== jurisdiction)
|
|
134
|
+
r('entry is for another jurisdiction');
|
|
135
|
+
if (e.seq !== prevSeq + 1)
|
|
136
|
+
r(`sequence gap: expected ${prevSeq + 1}, got ${String(e.seq)}`);
|
|
137
|
+
if (e.prev !== prevHash)
|
|
138
|
+
r('chain break: prev does not match the previous entry');
|
|
139
|
+
for (const m of eventReasons(e.event))
|
|
140
|
+
r(m);
|
|
141
|
+
const t = ms(e.event?.ts);
|
|
142
|
+
if (t < prevTs)
|
|
143
|
+
r('time goes backwards');
|
|
144
|
+
if (!Number.isNaN(t))
|
|
145
|
+
prevTs = t;
|
|
146
|
+
prevSeq = typeof e.seq === 'number' ? e.seq : prevSeq + 1;
|
|
147
|
+
prevHash = entryHash(e);
|
|
148
|
+
});
|
|
149
|
+
const head = entries.length ? feedHead(entries) : opts?.after ?? null;
|
|
150
|
+
return { ok: reasons.length === 0, reasons, head };
|
|
151
|
+
}
|
|
152
|
+
/** Entries after sequence number `seq` (0 = all), for a reader catching up. */
|
|
153
|
+
export function feedSince(entries, seq) {
|
|
154
|
+
return entries.filter((e) => e.seq > seq);
|
|
155
|
+
}
|
|
156
|
+
// ---------------------------------------------------------------------------------- //
|
|
157
|
+
// Event builders: each derives `ref` and `evidence` from the record it reports
|
|
158
|
+
// ---------------------------------------------------------------------------------- //
|
|
159
|
+
/** A Ledger delegation revocation (`createRevocation` / `submitRevocation`). The record must verify. */
|
|
160
|
+
export function revocationEvent(record, opts = {}) {
|
|
161
|
+
if (!verifyRevocation(record))
|
|
162
|
+
throw new Error('status-feed: the revocation record does not verify');
|
|
163
|
+
return normalize({ kind: 'delegation.revoked', subject: record.cert.subject, ref: certHash(record.cert), ts: record.ts, reason: opts.reason ?? null, evidence: [jcsHash(record)] });
|
|
164
|
+
}
|
|
165
|
+
const hashOf = (x) => (typeof x === 'string' ? x : jcsHash(x));
|
|
166
|
+
/** A Certify status change. `statusDocument` is the signed `certify.status` document (or its hash) that carries it. */
|
|
167
|
+
export function certificateStatusEvent(c) {
|
|
168
|
+
const kind = { suspend: 'certificate.suspended', revoke: 'certificate.revoked', reinstate: 'certificate.reinstated' }[c.action];
|
|
169
|
+
if (!kind)
|
|
170
|
+
throw new Error('status-feed: action must be suspend, revoke or reinstate');
|
|
171
|
+
return normalize({ kind, subject: c.holder, ref: c.certificate, ts: c.since, reason: c.reason, evidence: [hashOf(c.statusDocument)] });
|
|
172
|
+
}
|
|
173
|
+
/** An incident opened or closed, citing the incident report (or its hash). */
|
|
174
|
+
export function incidentEvent(i) {
|
|
175
|
+
if (i.action !== 'opened' && i.action !== 'closed')
|
|
176
|
+
throw new Error('status-feed: action must be opened or closed');
|
|
177
|
+
return normalize({ kind: `incident.${i.action}`, subject: i.subject, ref: i.incident, ts: i.ts, reason: i.reason ?? null, evidence: [hashOf(i.report)] });
|
|
178
|
+
}
|
|
179
|
+
/** A `zanii.jurisdiction` binding issued or expired; `ts` defaults to its `issued_at` / `expires_at`. */
|
|
180
|
+
export function jurisdictionEvent(binding, action, ts) {
|
|
181
|
+
if (action !== 'issued' && action !== 'expired')
|
|
182
|
+
throw new Error('status-feed: action must be issued or expired');
|
|
183
|
+
const h = jcsHash(binding);
|
|
184
|
+
return normalize({ kind: `jurisdiction.${action}`, subject: binding.subject, ref: h, ts: ts ?? (action === 'issued' ? binding.issued_at : binding.expires_at), reason: null, evidence: [h] });
|
|
185
|
+
}
|
|
186
|
+
const xml = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
187
|
+
const feedId = (j) => `urn:zanii:status-feed:${encodeURIComponent(j)}`;
|
|
188
|
+
const titleOf = (e) => `${e.event.kind} ${e.event.subject}`;
|
|
189
|
+
/** Atom 1.0 (RFC 4287). Each entry's content is its canonical JSON, so a reader can verify it. */
|
|
190
|
+
export function toAtom(entries, opts = {}) {
|
|
191
|
+
const j = entries[0]?.jurisdiction ?? '';
|
|
192
|
+
const id = opts.id ?? feedId(j);
|
|
193
|
+
const updated = opts.updated ?? entries[entries.length - 1]?.event.ts ?? '1970-01-01T00:00:00Z';
|
|
194
|
+
const lines = [
|
|
195
|
+
'<?xml version="1.0" encoding="utf-8"?>',
|
|
196
|
+
'<feed xmlns="http://www.w3.org/2005/Atom">',
|
|
197
|
+
` <id>${xml(id)}</id>`,
|
|
198
|
+
` <title>${xml(opts.title ?? `Zanii status feed ${j}`)}</title>`,
|
|
199
|
+
` <updated>${xml(updated)}</updated>`,
|
|
200
|
+
];
|
|
201
|
+
if (opts.link)
|
|
202
|
+
lines.push(` <link rel="self" href="${xml(opts.link)}"/>`);
|
|
203
|
+
for (const e of entries) {
|
|
204
|
+
lines.push(' <entry>', ` <id>${xml(`${feedId(e.jurisdiction)}:${e.seq}`)}</id>`, ` <title>${xml(titleOf(e))}</title>`, ` <updated>${xml(e.event.ts)}</updated>`, ` <author><name>${xml(e.signer)}</name></author>`, ` <content type="application/json">${xml(canonicalJson(e))}</content>`, ' </entry>');
|
|
205
|
+
}
|
|
206
|
+
lines.push('</feed>', '');
|
|
207
|
+
return lines.join('\n');
|
|
208
|
+
}
|
|
209
|
+
/** JSON Feed 1.1. `_zanii_status_feed` carries the signed entry unchanged. */
|
|
210
|
+
export function toJsonFeed(entries, opts = {}) {
|
|
211
|
+
const j = entries[0]?.jurisdiction ?? '';
|
|
212
|
+
const out = { version: 'https://jsonfeed.org/version/1.1', title: opts.title ?? `Zanii status feed ${j}` };
|
|
213
|
+
if (opts.link)
|
|
214
|
+
out.feed_url = opts.link;
|
|
215
|
+
out.items = entries.map((e) => ({
|
|
216
|
+
id: `${feedId(e.jurisdiction)}:${e.seq}`, title: titleOf(e), date_published: e.event.ts,
|
|
217
|
+
content_text: canonicalJson(e), _zanii_status_feed: e,
|
|
218
|
+
}));
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The feed head as a Ledger receipt: pass to `agent.record({ target, payload })` (`@zanii/sdk`).
|
|
223
|
+
* The receipt's payload hash then commits to the head, and the log's inclusion proof dates it.
|
|
224
|
+
*/
|
|
225
|
+
export function anchorFeedHead(entries) {
|
|
226
|
+
const head = feedHead(entries);
|
|
227
|
+
if (!head)
|
|
228
|
+
throw new Error('status-feed: an empty feed has no head to anchor');
|
|
229
|
+
return { target: 'regulator.status_feed.head', payload: { _zr_kind: 'status_feed', v: 1, jurisdiction: entries[0].jurisdiction, seq: head.seq, head: head.hash } };
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,kBAAkB,EAA4C,MAAM,aAAa,CAAC;AAE5J,MAAM,CAAC,MAAM,SAAS,GAAG,mBAA4B,CAAC;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,oBAAoB;IACpB,uBAAuB;IACvB,qBAAqB;IACrB,wBAAwB;IACxB,iBAAiB;IACjB,iBAAiB;IACjB,qBAAqB;IACrB,sBAAsB;CACd,CAAC;AAGX,8FAA8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,EAAE,IAAI,CAAC,KAAK,IAAI,qBAAqB,CAAC,EAAE,EAAE,CAAC;IACpI,IAAI,IAAI,CAAC,IAAI;QAAE,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;IACxC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC9B,EAAE,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE;QACvF,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC;KACtD,CAAC,CAAC,CAAC;IACJ,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAAoB;IACjD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IAC/E,OAAO,EAAE,MAAM,EAAE,4BAA4B,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAE,CAAC,YAAY,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;AACtK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zanii/status-feed",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "One signed, append-only, hash-chained status feed per jurisdiction: delegation revocations, Certify certificate suspensions, revocations and reinstatements, incident references and jurisdiction bindings, each with evidence hashes. Append, verify (chain, signatures, time, gaps), read since a sequence number, render as Atom or JSON Feed, and anchor the head as a Ledger receipt payload.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://ledger.zanii.agency",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@zanii/core": "^0.5.6"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@noble/curves": "^1.8.1",
|
|
33
|
+
"@types/node": "^26.1.0",
|
|
34
|
+
"typescript": "^5.8.2",
|
|
35
|
+
"vitest": "^3.0.9"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -p tsconfig.build.json",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"test": "vitest run"
|
|
41
|
+
}
|
|
6
42
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zanii/status-feed: one signed, append-only, hash-chained feed of status events per
|
|
3
|
+
* jurisdiction. Each entry names the previous entry's hash and its sequence number, is
|
|
4
|
+
* signed by the feed operator (a regulator or the Ledger operator) and carries the hashes
|
|
5
|
+
* of the evidence behind the event: a delegation revocation, a Certify status document,
|
|
6
|
+
* an incident report, a jurisdiction binding.
|
|
7
|
+
*
|
|
8
|
+
* The feed says that its signer published these events in this order. It does not make
|
|
9
|
+
* the events true: a verifier checks the evidence the hashes name. Anchoring the head as
|
|
10
|
+
* a Ledger receipt (`anchorFeedHead`) fixes the feed's history in the transparency log so
|
|
11
|
+
* the operator cannot rewrite it unseen.
|
|
12
|
+
*/
|
|
13
|
+
import { canonicalBytes, certHash, jcsHash, verifyRevocation, signObject, verifySignedObject, type RevocationRecord, type SignedObject } from '@zanii/core';
|
|
14
|
+
|
|
15
|
+
export const FEED_TYPE = 'zanii.status_feed' as const;
|
|
16
|
+
|
|
17
|
+
export const EVENT_KINDS = [
|
|
18
|
+
'delegation.revoked',
|
|
19
|
+
'certificate.suspended',
|
|
20
|
+
'certificate.revoked',
|
|
21
|
+
'certificate.reinstated',
|
|
22
|
+
'incident.opened',
|
|
23
|
+
'incident.closed',
|
|
24
|
+
'jurisdiction.issued',
|
|
25
|
+
'jurisdiction.expired',
|
|
26
|
+
] as const;
|
|
27
|
+
export type EventKind = (typeof EVENT_KINDS)[number];
|
|
28
|
+
|
|
29
|
+
/** Certify status reason codes, versions 1 to 3 (Certify spec/status.md sections 2, 6, 7). */
|
|
30
|
+
export const CERTIFY_REASONS = [
|
|
31
|
+
'FINGERPRINT_MISMATCH', 'RETEST_OVERDUE', 'RETEST_FAILED', 'INCIDENT', 'APPLICANT_REQUEST',
|
|
32
|
+
'ISSUER_ERROR', 'LICENCE_WITHDRAWN', 'AUDIT_EXPIRED', 'MARK_MISUSE', 'FALSE_DECLARATION', 'EVIDENCE_LAPSED',
|
|
33
|
+
] as const;
|
|
34
|
+
|
|
35
|
+
export interface StatusEvent {
|
|
36
|
+
kind: EventKind;
|
|
37
|
+
/** The did:key the event is about (usually the agent). */
|
|
38
|
+
subject: string;
|
|
39
|
+
/** What the event names: a delegation cert hash, a certificate hash, an incident id, a binding hash. */
|
|
40
|
+
ref: string;
|
|
41
|
+
ts: string;
|
|
42
|
+
/** Certify reason code for certificate suspend and revoke; null for reinstate; free text or null otherwise. */
|
|
43
|
+
reason: string | null;
|
|
44
|
+
/** `sha256:` hashes of the evidence; sorted and distinct in the entry. */
|
|
45
|
+
evidence: string[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type FeedEntry = SignedObject<{
|
|
49
|
+
v: 1;
|
|
50
|
+
type: typeof FEED_TYPE;
|
|
51
|
+
jurisdiction: string;
|
|
52
|
+
seq: number;
|
|
53
|
+
prev: string | null;
|
|
54
|
+
event: StatusEvent;
|
|
55
|
+
}>;
|
|
56
|
+
|
|
57
|
+
export interface FeedHead { seq: number; hash: string }
|
|
58
|
+
export interface Feed { jurisdiction: string; entries: FeedEntry[] }
|
|
59
|
+
|
|
60
|
+
const HASH = /^sha256:[0-9a-f]{64}$/;
|
|
61
|
+
const ISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/;
|
|
62
|
+
|
|
63
|
+
/** Epoch ms of a strict ISO 8601 UTC-or-offset timestamp, or NaN. */
|
|
64
|
+
function ms(ts: unknown): number {
|
|
65
|
+
return typeof ts === 'string' && ISO.test(ts) ? Date.parse(ts) : NaN;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const canonicalJson = (x: unknown): string => new TextDecoder().decode(canonicalBytes(x));
|
|
69
|
+
|
|
70
|
+
/** The hash later entries chain to: `jcsHash` of the whole signed entry. */
|
|
71
|
+
export function entryHash(entry: FeedEntry): string {
|
|
72
|
+
return jcsHash(entry);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Why an event is malformed; empty when it is well formed. */
|
|
76
|
+
export function eventReasons(e: unknown): string[] {
|
|
77
|
+
if (!e || typeof e !== 'object' || Array.isArray(e)) return ['event is not an object'];
|
|
78
|
+
const ev = e as Record<string, unknown>;
|
|
79
|
+
const out: string[] = [];
|
|
80
|
+
const keys = Object.keys(ev).sort().join(',');
|
|
81
|
+
if (keys !== 'evidence,kind,reason,ref,subject,ts') out.push('event has unexpected or missing fields');
|
|
82
|
+
if (!(EVENT_KINDS as readonly unknown[]).includes(ev.kind)) out.push('unknown event kind');
|
|
83
|
+
if (typeof ev.subject !== 'string' || !ev.subject.startsWith('did:')) out.push('event subject is not a DID');
|
|
84
|
+
if (typeof ev.ref !== 'string' || !ev.ref) out.push('event ref is empty');
|
|
85
|
+
if (Number.isNaN(ms(ev.ts))) out.push('event ts is not an ISO timestamp');
|
|
86
|
+
const ok = Array.isArray(ev.evidence) && ev.evidence.length > 0 && ev.evidence.every((h) => typeof h === 'string' && HASH.test(h));
|
|
87
|
+
if (!ok) out.push('event evidence must be a non-empty list of sha256 hashes');
|
|
88
|
+
else if (new Set(ev.evidence as string[]).size !== (ev.evidence as string[]).length || [...(ev.evidence as string[])].sort().join() !== (ev.evidence as string[]).join()) out.push('event evidence is not sorted and distinct');
|
|
89
|
+
if (ev.kind === 'certificate.suspended' || ev.kind === 'certificate.revoked') {
|
|
90
|
+
if (!(CERTIFY_REASONS as readonly unknown[]).includes(ev.reason)) out.push('certificate suspend or revoke needs a Certify reason code');
|
|
91
|
+
} else if (ev.kind === 'certificate.reinstated') {
|
|
92
|
+
if (ev.reason !== null) out.push('certificate reinstatement carries no reason');
|
|
93
|
+
} else if (ev.reason !== null && (typeof ev.reason !== 'string' || !ev.reason)) out.push('event reason must be null or a non-empty string');
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function normalize(e: StatusEvent): StatusEvent {
|
|
98
|
+
return {
|
|
99
|
+
kind: e.kind, subject: e.subject, ref: e.ref, ts: e.ts, reason: e.reason ?? null,
|
|
100
|
+
evidence: Array.isArray(e.evidence) ? [...new Set(e.evidence)].sort() : e.evidence,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The last entry's position, or null for an empty feed. */
|
|
105
|
+
export function feedHead(entries: FeedEntry[]): FeedHead | null {
|
|
106
|
+
const last = entries[entries.length - 1];
|
|
107
|
+
return last ? { seq: last.seq, hash: entryHash(last) } : null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Sign the next entry of `feed` and return it with the new head. Pure: the caller appends
|
|
112
|
+
* `entry` to its stored feed. Refuses a malformed event and an event dated before the head.
|
|
113
|
+
*/
|
|
114
|
+
export function appendEvent(feed: Feed, event: StatusEvent, signerKey: Uint8Array): { entry: FeedEntry; head: FeedHead } {
|
|
115
|
+
if (typeof feed?.jurisdiction !== 'string' || !feed.jurisdiction) throw new Error('status-feed: feed.jurisdiction is required');
|
|
116
|
+
const ev = normalize(event);
|
|
117
|
+
const reasons = eventReasons(ev);
|
|
118
|
+
if (reasons.length) throw new Error(`status-feed: ${reasons.join('; ')}`);
|
|
119
|
+
const last = feed.entries[feed.entries.length - 1];
|
|
120
|
+
if (last && last.jurisdiction !== feed.jurisdiction) throw new Error('status-feed: the feed holds another jurisdiction');
|
|
121
|
+
if (last && ms(ev.ts) < ms(last.event.ts)) throw new Error('status-feed: event is dated before the feed head');
|
|
122
|
+
const entry = signObject({
|
|
123
|
+
v: 1 as const, type: FEED_TYPE, jurisdiction: feed.jurisdiction,
|
|
124
|
+
seq: last ? last.seq + 1 : 1, prev: last ? entryHash(last) : null, event: ev,
|
|
125
|
+
}, signerKey);
|
|
126
|
+
return { entry, head: { seq: entry.seq, hash: entryHash(entry) } };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface VerifyFeedOptions {
|
|
130
|
+
/** The DIDs allowed to sign entries (key rotation: list old and new). */
|
|
131
|
+
signers: string[];
|
|
132
|
+
/** Expected jurisdiction; defaults to the first entry's. */
|
|
133
|
+
jurisdiction?: string;
|
|
134
|
+
/** A trusted earlier head, to verify a suffix such as `feedSince(entries, after.seq)`. */
|
|
135
|
+
after?: FeedHead;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface VerifyFeedResult { ok: boolean; reasons: string[]; head: FeedHead | null }
|
|
139
|
+
|
|
140
|
+
/** Chain continuity, sequence without gaps, signatures by allowed signers, non-decreasing time, well-formed events. */
|
|
141
|
+
export function verifyFeed(entries: FeedEntry[], opts: VerifyFeedOptions): VerifyFeedResult {
|
|
142
|
+
const reasons: string[] = [];
|
|
143
|
+
if (!Array.isArray(entries)) return { ok: false, reasons: ['feed is not a list'], head: null };
|
|
144
|
+
if (!Array.isArray(opts?.signers) || !opts.signers.length) reasons.push('no signers supplied: signer NOT checked');
|
|
145
|
+
const jurisdiction = opts?.jurisdiction ?? (entries[0] as FeedEntry | undefined)?.jurisdiction;
|
|
146
|
+
let prevHash: string | null = opts?.after?.hash ?? null;
|
|
147
|
+
let prevSeq = opts?.after?.seq ?? 0;
|
|
148
|
+
let prevTs = NaN;
|
|
149
|
+
entries.forEach((e, i) => {
|
|
150
|
+
const r = (m: string) => reasons.push(`entry ${i}: ${m}`);
|
|
151
|
+
if (!e || typeof e !== 'object' || e.v !== 1 || e.type !== FEED_TYPE) { r('not a status feed entry (v1)'); prevHash = null; return; }
|
|
152
|
+
const keys = Object.keys(e).sort().join(',');
|
|
153
|
+
if (keys !== 'event,jurisdiction,prev,seq,sig,signer,type,v') r('entry has unexpected or missing fields');
|
|
154
|
+
if (!verifySignedObject(e)) r('bad signature');
|
|
155
|
+
else if (opts?.signers?.length && !opts.signers.includes(e.signer)) r('signed by a key that is not an allowed feed signer');
|
|
156
|
+
if (e.jurisdiction !== jurisdiction) r('entry is for another jurisdiction');
|
|
157
|
+
if (e.seq !== prevSeq + 1) r(`sequence gap: expected ${prevSeq + 1}, got ${String(e.seq)}`);
|
|
158
|
+
if (e.prev !== prevHash) r('chain break: prev does not match the previous entry');
|
|
159
|
+
for (const m of eventReasons(e.event)) r(m);
|
|
160
|
+
const t = ms(e.event?.ts);
|
|
161
|
+
if (t < prevTs) r('time goes backwards');
|
|
162
|
+
if (!Number.isNaN(t)) prevTs = t;
|
|
163
|
+
prevSeq = typeof e.seq === 'number' ? e.seq : prevSeq + 1;
|
|
164
|
+
prevHash = entryHash(e);
|
|
165
|
+
});
|
|
166
|
+
const head = entries.length ? feedHead(entries) : opts?.after ?? null;
|
|
167
|
+
return { ok: reasons.length === 0, reasons, head };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Entries after sequence number `seq` (0 = all), for a reader catching up. */
|
|
171
|
+
export function feedSince(entries: FeedEntry[], seq: number): FeedEntry[] {
|
|
172
|
+
return entries.filter((e) => e.seq > seq);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ---------------------------------------------------------------------------------- //
|
|
176
|
+
// Event builders: each derives `ref` and `evidence` from the record it reports
|
|
177
|
+
// ---------------------------------------------------------------------------------- //
|
|
178
|
+
|
|
179
|
+
/** A Ledger delegation revocation (`createRevocation` / `submitRevocation`). The record must verify. */
|
|
180
|
+
export function revocationEvent(record: RevocationRecord, opts: { reason?: string | null } = {}): StatusEvent {
|
|
181
|
+
if (!verifyRevocation(record)) throw new Error('status-feed: the revocation record does not verify');
|
|
182
|
+
return normalize({ kind: 'delegation.revoked', subject: record.cert.subject, ref: certHash(record.cert), ts: record.ts, reason: opts.reason ?? null, evidence: [jcsHash(record)] });
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const hashOf = (x: string | object): string => (typeof x === 'string' ? x : jcsHash(x));
|
|
186
|
+
|
|
187
|
+
/** A Certify status change. `statusDocument` is the signed `certify.status` document (or its hash) that carries it. */
|
|
188
|
+
export function certificateStatusEvent(c: {
|
|
189
|
+
certificate: string; holder: string; action: 'suspend' | 'revoke' | 'reinstate';
|
|
190
|
+
reason: string | null; since: string; statusDocument: string | object;
|
|
191
|
+
}): StatusEvent {
|
|
192
|
+
const kind = ({ suspend: 'certificate.suspended', revoke: 'certificate.revoked', reinstate: 'certificate.reinstated' } as const)[c.action];
|
|
193
|
+
if (!kind) throw new Error('status-feed: action must be suspend, revoke or reinstate');
|
|
194
|
+
return normalize({ kind, subject: c.holder, ref: c.certificate, ts: c.since, reason: c.reason, evidence: [hashOf(c.statusDocument)] });
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** An incident opened or closed, citing the incident report (or its hash). */
|
|
198
|
+
export function incidentEvent(i: { action: 'opened' | 'closed'; incident: string; subject: string; report: string | object; ts: string; reason?: string | null }): StatusEvent {
|
|
199
|
+
if (i.action !== 'opened' && i.action !== 'closed') throw new Error('status-feed: action must be opened or closed');
|
|
200
|
+
return normalize({ kind: `incident.${i.action}`, subject: i.subject, ref: i.incident, ts: i.ts, reason: i.reason ?? null, evidence: [hashOf(i.report)] });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** A `zanii.jurisdiction` binding issued or expired; `ts` defaults to its `issued_at` / `expires_at`. */
|
|
204
|
+
export function jurisdictionEvent(binding: { subject: string; issued_at: string; expires_at: string }, action: 'issued' | 'expired', ts?: string): StatusEvent {
|
|
205
|
+
if (action !== 'issued' && action !== 'expired') throw new Error('status-feed: action must be issued or expired');
|
|
206
|
+
const h = jcsHash(binding);
|
|
207
|
+
return normalize({ kind: `jurisdiction.${action}`, subject: binding.subject, ref: h, ts: ts ?? (action === 'issued' ? binding.issued_at : binding.expires_at), reason: null, evidence: [h] });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ---------------------------------------------------------------------------------- //
|
|
211
|
+
// Publishing
|
|
212
|
+
// ---------------------------------------------------------------------------------- //
|
|
213
|
+
|
|
214
|
+
export interface RenderOptions { title?: string; id?: string; link?: string; updated?: string }
|
|
215
|
+
|
|
216
|
+
const xml = (s: string) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
217
|
+
const feedId = (j: string) => `urn:zanii:status-feed:${encodeURIComponent(j)}`;
|
|
218
|
+
const titleOf = (e: FeedEntry) => `${e.event.kind} ${e.event.subject}`;
|
|
219
|
+
|
|
220
|
+
/** Atom 1.0 (RFC 4287). Each entry's content is its canonical JSON, so a reader can verify it. */
|
|
221
|
+
export function toAtom(entries: FeedEntry[], opts: RenderOptions = {}): string {
|
|
222
|
+
const j = entries[0]?.jurisdiction ?? '';
|
|
223
|
+
const id = opts.id ?? feedId(j);
|
|
224
|
+
const updated = opts.updated ?? entries[entries.length - 1]?.event.ts ?? '1970-01-01T00:00:00Z';
|
|
225
|
+
const lines = [
|
|
226
|
+
'<?xml version="1.0" encoding="utf-8"?>',
|
|
227
|
+
'<feed xmlns="http://www.w3.org/2005/Atom">',
|
|
228
|
+
` <id>${xml(id)}</id>`,
|
|
229
|
+
` <title>${xml(opts.title ?? `Zanii status feed ${j}`)}</title>`,
|
|
230
|
+
` <updated>${xml(updated)}</updated>`,
|
|
231
|
+
];
|
|
232
|
+
if (opts.link) lines.push(` <link rel="self" href="${xml(opts.link)}"/>`);
|
|
233
|
+
for (const e of entries) {
|
|
234
|
+
lines.push(
|
|
235
|
+
' <entry>',
|
|
236
|
+
` <id>${xml(`${feedId(e.jurisdiction)}:${e.seq}`)}</id>`,
|
|
237
|
+
` <title>${xml(titleOf(e))}</title>`,
|
|
238
|
+
` <updated>${xml(e.event.ts)}</updated>`,
|
|
239
|
+
` <author><name>${xml(e.signer)}</name></author>`,
|
|
240
|
+
` <content type="application/json">${xml(canonicalJson(e))}</content>`,
|
|
241
|
+
' </entry>',
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
lines.push('</feed>', '');
|
|
245
|
+
return lines.join('\n');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** JSON Feed 1.1. `_zanii_status_feed` carries the signed entry unchanged. */
|
|
249
|
+
export function toJsonFeed(entries: FeedEntry[], opts: RenderOptions = {}): Record<string, unknown> {
|
|
250
|
+
const j = entries[0]?.jurisdiction ?? '';
|
|
251
|
+
const out: Record<string, unknown> = { version: 'https://jsonfeed.org/version/1.1', title: opts.title ?? `Zanii status feed ${j}` };
|
|
252
|
+
if (opts.link) out.feed_url = opts.link;
|
|
253
|
+
out.items = entries.map((e) => ({
|
|
254
|
+
id: `${feedId(e.jurisdiction)}:${e.seq}`, title: titleOf(e), date_published: e.event.ts,
|
|
255
|
+
content_text: canonicalJson(e), _zanii_status_feed: e,
|
|
256
|
+
}));
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* The feed head as a Ledger receipt: pass to `agent.record({ target, payload })` (`@zanii/sdk`).
|
|
262
|
+
* The receipt's payload hash then commits to the head, and the log's inclusion proof dates it.
|
|
263
|
+
*/
|
|
264
|
+
export function anchorFeedHead(entries: FeedEntry[]): { target: string; payload: Record<string, unknown> } {
|
|
265
|
+
const head = feedHead(entries);
|
|
266
|
+
if (!head) throw new Error('status-feed: an empty feed has no head to anchor');
|
|
267
|
+
return { target: 'regulator.status_feed.head', payload: { _zr_kind: 'status_feed', v: 1, jurisdiction: entries[0]!.jurisdiction, seq: head.seq, head: head.hash } };
|
|
268
|
+
}
|