@zanii/blackbox 0.2.0 → 0.4.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.
Files changed (94) hide show
  1. package/README.md +26 -1
  2. package/dist/a2a/index.d.ts +77 -0
  3. package/dist/a2a/index.js +305 -0
  4. package/dist/agents/index.d.ts +8 -0
  5. package/dist/analysis/accuracy.d.ts +24 -0
  6. package/dist/analysis/accuracy.js +45 -0
  7. package/dist/analysis/credential.d.ts +101 -0
  8. package/dist/analysis/credential.js +142 -0
  9. package/dist/analysis/faults.js +115 -0
  10. package/dist/analysis/grounding.d.ts +122 -0
  11. package/dist/analysis/grounding.js +445 -0
  12. package/dist/analysis/hallucination.d.ts +32 -0
  13. package/dist/analysis/hallucination.js +357 -0
  14. package/dist/analysis/index.d.ts +23 -0
  15. package/dist/analysis/index.js +93 -0
  16. package/dist/analysis/memory.d.ts +8 -0
  17. package/dist/analysis/memory.js +35 -8
  18. package/dist/analysis/reference.d.ts +49 -0
  19. package/dist/analysis/reference.js +164 -0
  20. package/dist/analysis/taxonomy.d.ts +18 -0
  21. package/dist/analysis/taxonomy.js +66 -0
  22. package/dist/approvals/index.d.ts +23 -0
  23. package/dist/approvals/index.js +48 -0
  24. package/dist/archive/index.d.ts +39 -0
  25. package/dist/archive/index.js +96 -0
  26. package/dist/archive/parquet.d.ts +2 -0
  27. package/dist/archive/parquet.js +185 -0
  28. package/dist/badge/index.d.ts +16 -0
  29. package/dist/badge/index.js +48 -0
  30. package/dist/bom/index.d.ts +14 -0
  31. package/dist/bom/index.js +152 -0
  32. package/dist/cli.js +114 -10
  33. package/dist/compliance/art12.d.ts +35 -0
  34. package/dist/compliance/art12.js +190 -0
  35. package/dist/compliance/index.d.ts +36 -2
  36. package/dist/compliance/index.js +78 -11
  37. package/dist/compliance/zanii.d.ts +29 -0
  38. package/dist/compliance/zanii.js +84 -0
  39. package/dist/constitution/index.d.ts +57 -0
  40. package/dist/constitution/index.js +131 -0
  41. package/dist/cv/index.d.ts +39 -0
  42. package/dist/cv/index.js +108 -0
  43. package/dist/disclosure/index.d.ts +31 -0
  44. package/dist/disclosure/index.js +113 -0
  45. package/dist/encryption/index.d.ts +9 -0
  46. package/dist/encryption/index.js +31 -0
  47. package/dist/evidence/index.d.ts +60 -0
  48. package/dist/evidence/index.js +151 -0
  49. package/dist/federation/index.d.ts +35 -0
  50. package/dist/federation/index.js +102 -0
  51. package/dist/finance/index.d.ts +126 -0
  52. package/dist/finance/index.js +320 -0
  53. package/dist/fleet/index.js +9 -0
  54. package/dist/gov/index.d.ts +108 -0
  55. package/dist/gov/index.js +225 -0
  56. package/dist/health/index.d.ts +120 -0
  57. package/dist/health/index.js +233 -0
  58. package/dist/index.d.ts +34 -5
  59. package/dist/index.js +34 -5
  60. package/dist/memory/index.d.ts +36 -0
  61. package/dist/memory/index.js +85 -0
  62. package/dist/occurrence/index.d.ts +11 -0
  63. package/dist/occurrence/index.js +18 -0
  64. package/dist/ocsf/index.d.ts +1 -1
  65. package/dist/ocsf/index.js +36 -3
  66. package/dist/otlp/index.d.ts +8 -1
  67. package/dist/otlp/index.js +258 -1
  68. package/dist/packs/index.js +44 -4
  69. package/dist/policy/delta.js +7 -1
  70. package/dist/policy/index.d.ts +40 -6
  71. package/dist/policy/index.js +186 -8
  72. package/dist/policy/zanii.d.ts +31 -0
  73. package/dist/policy/zanii.js +87 -0
  74. package/dist/pq/index.d.ts +23 -0
  75. package/dist/pq/index.js +104 -0
  76. package/dist/search/index.d.ts +23 -0
  77. package/dist/search/index.js +69 -0
  78. package/dist/session/index.d.ts +107 -1
  79. package/dist/session/index.js +189 -11
  80. package/dist/sla/index.d.ts +61 -0
  81. package/dist/sla/index.js +197 -0
  82. package/dist/succession/index.d.ts +50 -0
  83. package/dist/succession/index.js +123 -0
  84. package/dist/timestamp/index.d.ts +24 -0
  85. package/dist/timestamp/index.js +274 -0
  86. package/dist/tokens/index.d.ts +6 -0
  87. package/dist/tokens/index.js +46 -0
  88. package/dist/transparency/index.d.ts +188 -0
  89. package/dist/transparency/index.js +712 -0
  90. package/dist/version.d.ts +1 -1
  91. package/dist/version.js +1 -1
  92. package/dist/walls/index.d.ts +31 -0
  93. package/dist/walls/index.js +119 -0
  94. package/package.json +1 -1
@@ -0,0 +1,46 @@
1
+ // Keyed redaction tokens (spec/data.md §12, L9): a redacted value as `<kind_tok:…>`, AES-256-GCM
2
+ // under the deployment's token key, so a tool that holds the key resolves it and nothing in between
3
+ // (the model, the gateway's memory) has the value. Deterministic: the nonce is an HMAC of the kind
4
+ // and value, so the same value always reads the same. Mirrors sdks/python/src/zanii_blackbox/
5
+ // tokens.py; pinned by spec/vectors/tokens.json.
6
+ import { createCipheriv, createDecipheriv, createHmac } from "node:crypto";
7
+ const TOKEN = /<([a-z_]{1,32})_tok:([A-Za-z0-9_-]{24,4096})>/g;
8
+ const check = (key) => {
9
+ if (key.length !== 32)
10
+ throw new Error("a token key is 32 bytes");
11
+ };
12
+ /** The token for one value: `<kind_tok:base64url(nonce ‖ AES-256-GCM(value, aad=kind))>`. */
13
+ export function tokenFor(kind, value, key) {
14
+ check(key);
15
+ if (!/^[a-z_]{1,32}$/.test(kind))
16
+ throw new Error("kind must be 1-32 of a-z _");
17
+ const nonce = createHmac("sha256", key).update(`${kind}\0${value}`).digest().subarray(0, 12);
18
+ const cipher = createCipheriv("aes-256-gcm", key, nonce);
19
+ cipher.setAAD(Buffer.from(kind));
20
+ const sealed = Buffer.concat([cipher.update(value, "utf8"), cipher.final(), cipher.getAuthTag()]);
21
+ return `<${kind}_tok:${Buffer.concat([nonce, sealed]).toString("base64url")}>`;
22
+ }
23
+ /** A token's value, or null when it isn't one, or isn't this key's. */
24
+ export function resolveToken(token, key) {
25
+ check(key);
26
+ const m = new RegExp(`^${TOKEN.source}$`).exec(token);
27
+ if (!m)
28
+ return null;
29
+ try {
30
+ const raw = Buffer.from(m[2], "base64url");
31
+ if (raw.length < 12 + 16)
32
+ return null;
33
+ const d = createDecipheriv("aes-256-gcm", key, raw.subarray(0, 12));
34
+ d.setAAD(Buffer.from(m[1]));
35
+ d.setAuthTag(raw.subarray(raw.length - 16));
36
+ return Buffer.concat([d.update(raw.subarray(12, raw.length - 16)), d.final()]).toString("utf8");
37
+ }
38
+ catch {
39
+ return null;
40
+ }
41
+ }
42
+ /** Every token in `text` this key resolves, put back; any other is left as it is. */
43
+ export function resolveTokens(text, key) {
44
+ check(key);
45
+ return text.replace(TOKEN, (t) => resolveToken(t, key) ?? t);
46
+ }
@@ -0,0 +1,188 @@
1
+ /** A CBOR value: integers, byte and text strings, arrays, maps (Map, for integer keys), tags, null and booleans. */
2
+ export type Cbor = number | string | Uint8Array | boolean | null | Cbor[] | Map<Cbor, Cbor> | {
3
+ tag: number;
4
+ value: Cbor;
5
+ };
6
+ export declare const tagged: (tag: number, value: Cbor) => Cbor;
7
+ export declare function cborEncode(v: Cbor): Buffer;
8
+ /** Decodes one deterministic CBOR item; throws on anything else (indefinite lengths, floats, extra bytes). */
9
+ export declare function cborDecode(bytes: Uint8Array): Cbor;
10
+ export declare const ed25519Sign: (seed: Uint8Array, msg: Uint8Array) => Uint8Array<ArrayBuffer>;
11
+ export declare function ed25519Verify(publicKey: Uint8Array, msg: Uint8Array, sig: Uint8Array): boolean;
12
+ export declare const ed25519PublicKey: (seed: Uint8Array) => Uint8Array<ArrayBuffer>;
13
+ export declare const ALG_ED25519 = -19;
14
+ export interface StatementInput {
15
+ /** The payload's media type. */
16
+ contentType: string;
17
+ payload: Uint8Array;
18
+ /** CWT claims (RFC 9597): who issued it and what it's about. */
19
+ iss: string;
20
+ sub: string;
21
+ /** Unix seconds. */
22
+ iat: number;
23
+ /** The key id (bstr), e.g. the first 8 bytes of SHA-256(public key). */
24
+ kid: Uint8Array;
25
+ }
26
+ /** A SCITT Signed Statement: tagged COSE_Sign1, Ed25519 (alg -19), empty unprotected header, payload attached. */
27
+ export declare function signStatement(input: StatementInput, seed: Uint8Array): Uint8Array;
28
+ export interface CoseSign1 {
29
+ protectedBytes: Uint8Array;
30
+ protected: Map<Cbor, Cbor>;
31
+ unprotected: Map<Cbor, Cbor>;
32
+ payload: Uint8Array | null;
33
+ signature: Uint8Array;
34
+ }
35
+ /** Parses a tagged COSE_Sign1; throws if it isn't one. */
36
+ export declare function parseCoseSign1(bytes: Uint8Array): CoseSign1;
37
+ /** Does a COSE_Sign1 verify with this Ed25519 key? `detached`: the payload, when it isn't attached. */
38
+ export declare function verifyCoseSign1(bytes: Uint8Array, publicKey: Uint8Array, detached?: Uint8Array): boolean;
39
+ /** The bytes a log entry is: the statement with its unprotected header emptied (RFC 9943 §6.3). */
40
+ export declare function statementEntry(statement: Uint8Array): Uint8Array;
41
+ export declare const leafHash: (entry: Uint8Array) => Uint8Array<ArrayBuffer>;
42
+ /** MTH over leaf hashes (already `leafHash`ed). */
43
+ export declare function merkleRoot(leaves: readonly Uint8Array[]): Uint8Array;
44
+ /** The audit path for leaf `m` in a tree of these leaf hashes, leaf to root. */
45
+ export declare function inclusionProof(m: number, leaves: readonly Uint8Array[]): Uint8Array[];
46
+ /** RFC 9162 §2.1.3.2: does `path` prove leaf `index` (its hash) in a tree of `size` with `root`? */
47
+ export declare function verifyInclusion(leaf: Uint8Array, index: number, size: number, path: readonly Uint8Array[], root: Uint8Array): boolean;
48
+ /** RFC 9162 §2.1.4.1: proof that the tree of the first `m` leaves is a prefix of all of them. */
49
+ export declare function consistencyProof(m: number, leaves: readonly Uint8Array[]): Uint8Array[];
50
+ /** RFC 9162 §2.1.4.2, with the trivial cases: an empty first tree, and equal sizes. */
51
+ export declare function verifyConsistency(first: number, second: number, firstRoot: Uint8Array, secondRoot: Uint8Array, proof: readonly Uint8Array[]): boolean;
52
+ export interface ReceiptSigner {
53
+ iss: string;
54
+ sub: string;
55
+ kid: Uint8Array;
56
+ seed: Uint8Array;
57
+ }
58
+ /** A receipt of inclusion (vds RFC9162_SHA256): signed over the root, payload detached. */
59
+ export declare function makeReceipt(proof: {
60
+ size: number;
61
+ index: number;
62
+ path: readonly Uint8Array[];
63
+ root: Uint8Array;
64
+ }, signer: ReceiptSigner): Uint8Array;
65
+ /** RFC 9942 §5.2.1: does the receipt prove this entry (the statement, unprotected emptied) under this key?
66
+ * Returns the tree size and leaf index it proves, or null. Accepts a size-1 tree's empty path. */
67
+ export declare function verifyReceipt(receipt: Uint8Array, entry: Uint8Array, publicKey: Uint8Array): {
68
+ size: number;
69
+ index: number;
70
+ } | null;
71
+ /** A Transparent Statement: the statement with its receipts in unprotected header 394. */
72
+ export declare function transparentStatement(statement: Uint8Array, receipts: readonly Uint8Array[]): Uint8Array;
73
+ /** c2sp.org/signed-note: SHA-256(name || "\n" || type || public key)[:4]. Type 0x01 note, 0x04 cosignature. */
74
+ export declare const noteKeyId: (name: string, type: number, publicKey: Uint8Array) => Uint8Array<ArrayBuffer>;
75
+ /** A verifier key string: `name+hex(keyID)+base64(type || public key)`. */
76
+ export declare const noteVkey: (name: string, type: number, publicKey: Uint8Array) => string;
77
+ export declare function parseVkey(vkey: string): {
78
+ name: string;
79
+ type: number;
80
+ keyId: Uint8Array;
81
+ publicKey: Uint8Array;
82
+ } | null;
83
+ /** Signs a note's text (which ends in "\n") as `name`; returns the note with its signature line. */
84
+ export declare function signNote(text: string, name: string, seed: Uint8Array): string;
85
+ /** Splits a signed note into its text and signature lines. */
86
+ export declare function splitNote(note: string): {
87
+ text: string;
88
+ signatures: Array<{
89
+ name: string;
90
+ keyId: Uint8Array;
91
+ sig: Uint8Array;
92
+ }>;
93
+ } | null;
94
+ /** Is the note signed (type 0x01) by this vkey? */
95
+ export declare function verifyNote(note: string, vkey: string): boolean;
96
+ /**
97
+ * §9: a log key rotation, as a note signed by the old key and the new one: the new key's vkey, the
98
+ * tree size it takes over at, and when. A verifier that pinned the old key follows it to the new.
99
+ */
100
+ export declare function keyRotationNote(old: {
101
+ seed: Uint8Array;
102
+ origin: string;
103
+ }, next: {
104
+ seed: Uint8Array;
105
+ origin: string;
106
+ }, size: number, time: number): string;
107
+ /** §9: the new key, size and time a rotation note names, if the old key and the new one both signed it. */
108
+ export declare function verifyKeyRotation(note: string, oldVkey: string): {
109
+ new_vkey: string;
110
+ size: number;
111
+ time: number;
112
+ } | null;
113
+ /** c2sp.org/tlog-checkpoint: origin, size, base64 root, each on its own line. */
114
+ export declare const checkpointText: (origin: string, size: number, root: Uint8Array) => string;
115
+ export declare function parseCheckpoint(text: string): {
116
+ origin: string;
117
+ size: number;
118
+ root: Uint8Array;
119
+ } | null;
120
+ /** c2sp.org/tlog-cosignature: the witness's timestamped Ed25519 cosignature (type 0x04) on a checkpoint. */
121
+ export declare function cosign(checkpoint: string, name: string, seed: Uint8Array, time: number): string;
122
+ /** The raw ML-DSA-44 public key (1312 bytes) for a 32-byte seed. Needs Node ≥ 24.6. */
123
+ export declare const mldsaPublicKey: (seed: Uint8Array) => Uint8Array;
124
+ /** Whether this runtime has ML-DSA (Node ≥ 24.6 with OpenSSL ≥ 3.5). */
125
+ export declare function mldsaAvailable(): boolean;
126
+ /** c2sp.org/tlog-cosignature v1.1 (type 0x06): what an ML-DSA-44 subtree cosignature signs. */
127
+ export declare function subtreeMessage(name: string, time: number, origin: string, start: number, end: number, hash: Uint8Array): Uint8Array;
128
+ /** An ML-DSA-44 cosignature line (type 0x06) on a checkpoint: what a log or witness adds for post-quantum. */
129
+ export declare function cosignMldsa(checkpoint: string, name: string, seed: Uint8Array, time: number): string;
130
+ /**
131
+ * The time a cosignature (in a note's signature lines) says it saw the checkpoint, or null. Takes a
132
+ * witness's Ed25519 vkey (type 0x04) or an ML-DSA-44 one (type 0x06).
133
+ */
134
+ export declare function verifyCosignature(note: string, vkey: string): number | null;
135
+ /** c2sp.org/tlog-witness: the body of `POST add-checkpoint`. */
136
+ export declare const addCheckpointBody: (old: number, proof: readonly Uint8Array[], signedCheckpoint: string) => string;
137
+ export declare function parseAddCheckpoint(body: string): {
138
+ old: number;
139
+ proof: Uint8Array[];
140
+ note: string;
141
+ } | null;
142
+ export declare const SESSION_CONTENT_TYPE = "application/vnd.zanii.blackbox.session+json";
143
+ export declare const RECEIPT_SUB = "transparency-log";
144
+ /** spec/transparency.md §1: the first 8 bytes of SHA-256(public key). */
145
+ export declare const logKid: (publicKey: Uint8Array) => Uint8Array<ArrayBuffer>;
146
+ export interface SessionHead {
147
+ session_id: string;
148
+ tenant: string;
149
+ count: number;
150
+ head: string;
151
+ closed_at: string;
152
+ }
153
+ /** spec/transparency.md §2: the Signed Statement a closed session gets. `iat` is `closed_at` in seconds. */
154
+ export declare function sessionStatement(head: SessionHead, origin: string, seed: Uint8Array): Uint8Array;
155
+ export interface TransparencyReport {
156
+ ok: boolean;
157
+ statement: boolean;
158
+ receipt: {
159
+ size: number;
160
+ index: number;
161
+ } | null;
162
+ checkpoint: {
163
+ origin: string;
164
+ size: number;
165
+ } | null;
166
+ witnessed: string[];
167
+ /** The RFC 3161 time of the checkpoint (spec/timestamp.md §3), when the bundle carries a token. */
168
+ timestamp: string | null;
169
+ /** §8: the checkpoint's ML-DSA-44 signature verifies under `logPqKey`; null when none was given. */
170
+ pq: boolean | null;
171
+ problems: string[];
172
+ }
173
+ /**
174
+ * spec/transparency.md §6: checks a bundle's `transparency` offline, against a log key the verifier
175
+ * pins (a C2SP vkey, type 0x01) and the witnesses it trusts (vkeys, type 0x04).
176
+ */
177
+ export declare function verifyTransparency(bundle: {
178
+ session: {
179
+ session_id: string;
180
+ };
181
+ lines: readonly string[];
182
+ transparency?: unknown;
183
+ }, options: {
184
+ logKey: string;
185
+ witnesses?: readonly string[];
186
+ tsaRoots?: readonly string[];
187
+ logPqKey?: string;
188
+ }): TransparencyReport;