@certcrypt/verifier-toolkit 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @certcrypt/verifier-toolkit might be problematic. Click here for more details.
- package/CHANGELOG.md +72 -0
- package/LICENSE +178 -0
- package/README.md +563 -2
- package/SECURITY.md +77 -0
- package/dist/cli/certcrypt-verify.d.ts +2 -0
- package/dist/cli/certcrypt-verify.js +174 -0
- package/dist/cli/certcrypt-verify.js.map +1 -0
- package/dist/core/config/certcrypt-foundation.d.ts +13 -0
- package/dist/core/config/certcrypt-foundation.js +123 -0
- package/dist/core/config/certcrypt-foundation.js.map +1 -0
- package/dist/core/config/default.d.ts +47 -0
- package/dist/core/config/default.js +93 -0
- package/dist/core/config/default.js.map +1 -0
- package/dist/core/config/test-keys.d.ts +40 -0
- package/dist/core/config/test-keys.js +41 -0
- package/dist/core/config/test-keys.js.map +1 -0
- package/dist/core/conformance/attestation.d.ts +4 -0
- package/dist/core/conformance/attestation.js +4 -0
- package/dist/core/conformance/attestation.js.map +1 -0
- package/dist/core/consistency/verify-consistency.d.ts +92 -0
- package/dist/core/consistency/verify-consistency.js +353 -0
- package/dist/core/consistency/verify-consistency.js.map +1 -0
- package/dist/core/crypto/canonical-json.d.ts +14 -0
- package/dist/core/crypto/canonical-json.js +13 -0
- package/dist/core/crypto/canonical-json.js.map +1 -0
- package/dist/core/crypto/canonical-subject.d.ts +76 -0
- package/dist/core/crypto/canonical-subject.js +248 -0
- package/dist/core/crypto/canonical-subject.js.map +1 -0
- package/dist/core/crypto/collection-merkle.d.ts +91 -0
- package/dist/core/crypto/collection-merkle.js +243 -0
- package/dist/core/crypto/collection-merkle.js.map +1 -0
- package/dist/core/crypto/composite.d.ts +73 -0
- package/dist/core/crypto/composite.js +206 -0
- package/dist/core/crypto/composite.js.map +1 -0
- package/dist/core/crypto/digest.d.ts +18 -0
- package/dist/core/crypto/digest.js +37 -0
- package/dist/core/crypto/digest.js.map +1 -0
- package/dist/core/crypto/ecdsa-p256.d.ts +12 -0
- package/dist/core/crypto/ecdsa-p256.js +70 -0
- package/dist/core/crypto/ecdsa-p256.js.map +1 -0
- package/dist/core/crypto/ed25519.d.ts +10 -0
- package/dist/core/crypto/ed25519.js +28 -0
- package/dist/core/crypto/ed25519.js.map +1 -0
- package/dist/core/crypto/holder-keyset.d.ts +23 -0
- package/dist/core/crypto/holder-keyset.js +64 -0
- package/dist/core/crypto/holder-keyset.js.map +1 -0
- package/dist/core/crypto/jcs.d.ts +9 -0
- package/dist/core/crypto/jcs.js +59 -0
- package/dist/core/crypto/jcs.js.map +1 -0
- package/dist/core/crypto/merkle.d.ts +34 -0
- package/dist/core/crypto/merkle.js +147 -0
- package/dist/core/crypto/merkle.js.map +1 -0
- package/dist/core/crypto/ml-dsa.d.ts +25 -0
- package/dist/core/crypto/ml-dsa.js +104 -0
- package/dist/core/crypto/ml-dsa.js.map +1 -0
- package/dist/core/crypto/provider/bytes.d.ts +31 -0
- package/dist/core/crypto/provider/bytes.js +106 -0
- package/dist/core/crypto/provider/bytes.js.map +1 -0
- package/dist/core/crypto/provider/index.d.ts +45 -0
- package/dist/core/crypto/provider/index.js +60 -0
- package/dist/core/crypto/provider/index.js.map +1 -0
- package/dist/core/crypto/provider/node.d.ts +2 -0
- package/dist/core/crypto/provider/node.js +96 -0
- package/dist/core/crypto/provider/node.js.map +1 -0
- package/dist/core/crypto/provider/register-node.d.ts +11 -0
- package/dist/core/crypto/provider/register-node.js +16 -0
- package/dist/core/crypto/provider/register-node.js.map +1 -0
- package/dist/core/crypto/provider/types.d.ts +77 -0
- package/dist/core/crypto/provider/types.js +16 -0
- package/dist/core/crypto/provider/types.js.map +1 -0
- package/dist/core/crypto/provider/web.d.ts +2 -0
- package/dist/core/crypto/provider/web.js +122 -0
- package/dist/core/crypto/provider/web.js.map +1 -0
- package/dist/core/crypto/pseudonym.d.ts +25 -0
- package/dist/core/crypto/pseudonym.js +37 -0
- package/dist/core/crypto/pseudonym.js.map +1 -0
- package/dist/core/crypto/subject-json-preconditions.d.ts +47 -0
- package/dist/core/crypto/subject-json-preconditions.js +373 -0
- package/dist/core/crypto/subject-json-preconditions.js.map +1 -0
- package/dist/core/domain/verify-domain.d.ts +13 -0
- package/dist/core/domain/verify-domain.js +39 -0
- package/dist/core/domain/verify-domain.js.map +1 -0
- package/dist/core/foundation/anti-equivocation.d.ts +87 -0
- package/dist/core/foundation/anti-equivocation.js +0 -0
- package/dist/core/foundation/anti-equivocation.js.map +1 -0
- package/dist/core/foundation/verify-foundation.d.ts +36 -0
- package/dist/core/foundation/verify-foundation.js +559 -0
- package/dist/core/foundation/verify-foundation.js.map +1 -0
- package/dist/core/independent/anti-replay.d.ts +15 -0
- package/dist/core/independent/anti-replay.js +27 -0
- package/dist/core/independent/anti-replay.js.map +1 -0
- package/dist/core/independent/anti-splicing.d.ts +16 -0
- package/dist/core/independent/anti-splicing.js +54 -0
- package/dist/core/independent/anti-splicing.js.map +1 -0
- package/dist/core/independent/capacity-binding.d.ts +26 -0
- package/dist/core/independent/capacity-binding.js +57 -0
- package/dist/core/independent/capacity-binding.js.map +1 -0
- package/dist/core/independent/capacity-evidence.d.ts +38 -0
- package/dist/core/independent/capacity-evidence.js +286 -0
- package/dist/core/independent/capacity-evidence.js.map +1 -0
- package/dist/core/independent/effective-units.d.ts +42 -0
- package/dist/core/independent/effective-units.js +147 -0
- package/dist/core/independent/effective-units.js.map +1 -0
- package/dist/core/independent/issuance-participation.d.ts +13 -0
- package/dist/core/independent/issuance-participation.js +24 -0
- package/dist/core/independent/issuance-participation.js.map +1 -0
- package/dist/core/independent/leaf-binding.d.ts +5 -0
- package/dist/core/independent/leaf-binding.js +135 -0
- package/dist/core/independent/leaf-binding.js.map +1 -0
- package/dist/core/independent/operator-recognition-registry.d.ts +33 -0
- package/dist/core/independent/operator-recognition-registry.js +116 -0
- package/dist/core/independent/operator-recognition-registry.js.map +1 -0
- package/dist/core/independent/proof-structure.d.ts +8 -0
- package/dist/core/independent/proof-structure.js +167 -0
- package/dist/core/independent/proof-structure.js.map +1 -0
- package/dist/core/independent/proof-views.d.ts +26 -0
- package/dist/core/independent/proof-views.js +58 -0
- package/dist/core/independent/proof-views.js.map +1 -0
- package/dist/core/independent/settlement.d.ts +18 -0
- package/dist/core/independent/settlement.js +548 -0
- package/dist/core/independent/settlement.js.map +1 -0
- package/dist/core/independent/verify-independent.d.ts +30 -0
- package/dist/core/independent/verify-independent.js +123 -0
- package/dist/core/independent/verify-independent.js.map +1 -0
- package/dist/core/independent/verify-operator-recognition.d.ts +26 -0
- package/dist/core/independent/verify-operator-recognition.js +60 -0
- package/dist/core/independent/verify-operator-recognition.js.map +1 -0
- package/dist/core/independent/verify-proof-signature.d.ts +20 -0
- package/dist/core/independent/verify-proof-signature.js +97 -0
- package/dist/core/independent/verify-proof-signature.js.map +1 -0
- package/dist/core/input/fs-bridge.d.ts +30 -0
- package/dist/core/input/fs-bridge.js +35 -0
- package/dist/core/input/fs-bridge.js.map +1 -0
- package/dist/core/input/load-artifacts.d.ts +2 -0
- package/dist/core/input/load-artifacts.js +80 -0
- package/dist/core/input/load-artifacts.js.map +1 -0
- package/dist/core/input/load-original-material.d.ts +11 -0
- package/dist/core/input/load-original-material.js +126 -0
- package/dist/core/input/load-original-material.js.map +1 -0
- package/dist/core/input/register-node-fs.d.ts +1 -0
- package/dist/core/input/register-node-fs.js +24 -0
- package/dist/core/input/register-node-fs.js.map +1 -0
- package/dist/core/input/resolve-target.d.ts +16 -0
- package/dist/core/input/resolve-target.js +43 -0
- package/dist/core/input/resolve-target.js.map +1 -0
- package/dist/core/input/strict-json.d.ts +25 -0
- package/dist/core/input/strict-json.js +167 -0
- package/dist/core/input/strict-json.js.map +1 -0
- package/dist/core/input/validate.d.ts +7 -0
- package/dist/core/input/validate.js +83 -0
- package/dist/core/input/validate.js.map +1 -0
- package/dist/core/issued/verify-collection-element.d.ts +66 -0
- package/dist/core/issued/verify-collection-element.js +137 -0
- package/dist/core/issued/verify-collection-element.js.map +1 -0
- package/dist/core/issued/verify-issued.d.ts +15 -0
- package/dist/core/issued/verify-issued.js +361 -0
- package/dist/core/issued/verify-issued.js.map +1 -0
- package/dist/core/issued/verify-original-material.d.ts +35 -0
- package/dist/core/issued/verify-original-material.js +418 -0
- package/dist/core/issued/verify-original-material.js.map +1 -0
- package/dist/core/package/verify-package.d.ts +34 -0
- package/dist/core/package/verify-package.js +109 -0
- package/dist/core/package/verify-package.js.map +1 -0
- package/dist/core/public-api.d.ts +178 -0
- package/dist/core/public-api.js +182 -0
- package/dist/core/public-api.js.map +1 -0
- package/dist/core/result/builder.d.ts +92 -0
- package/dist/core/result/builder.js +408 -0
- package/dist/core/result/builder.js.map +1 -0
- package/dist/core/rules/verify-corpus.d.ts +88 -0
- package/dist/core/rules/verify-corpus.js +165 -0
- package/dist/core/rules/verify-corpus.js.map +1 -0
- package/dist/core/rules/verify-rules.d.ts +14 -0
- package/dist/core/rules/verify-rules.js +62 -0
- package/dist/core/rules/verify-rules.js.map +1 -0
- package/dist/core/testing/validate-against-schema.d.ts +31 -0
- package/dist/core/testing/validate-against-schema.js +93 -0
- package/dist/core/testing/validate-against-schema.js.map +1 -0
- package/dist/core/types/artifacts.d.ts +224 -0
- package/dist/core/types/artifacts.js +2 -0
- package/dist/core/types/artifacts.js.map +1 -0
- package/dist/core/types/capacity-evidence.d.ts +85 -0
- package/dist/core/types/capacity-evidence.js +51 -0
- package/dist/core/types/capacity-evidence.js.map +1 -0
- package/dist/core/types/check.d.ts +61 -0
- package/dist/core/types/check.js +2 -0
- package/dist/core/types/check.js.map +1 -0
- package/dist/core/types/config.d.ts +97 -0
- package/dist/core/types/config.js +2 -0
- package/dist/core/types/config.js.map +1 -0
- package/dist/core/types/foundation.d.ts +121 -0
- package/dist/core/types/foundation.js +25 -0
- package/dist/core/types/foundation.js.map +1 -0
- package/dist/core/types/index.d.ts +9 -0
- package/dist/core/types/index.js +2 -0
- package/dist/core/types/index.js.map +1 -0
- package/dist/core/types/operator-recognition.d.ts +71 -0
- package/dist/core/types/operator-recognition.js +24 -0
- package/dist/core/types/operator-recognition.js.map +1 -0
- package/dist/core/types/proof.d.ts +94 -0
- package/dist/core/types/proof.js +2 -0
- package/dist/core/types/proof.js.map +1 -0
- package/dist/core/types/request.d.ts +59 -0
- package/dist/core/types/request.js +2 -0
- package/dist/core/types/request.js.map +1 -0
- package/dist/core/types/result.d.ts +164 -0
- package/dist/core/types/result.js +2 -0
- package/dist/core/types/result.js.map +1 -0
- package/dist/core/types/settlement-material.d.ts +130 -0
- package/dist/core/types/settlement-material.js +2 -0
- package/dist/core/types/settlement-material.js.map +1 -0
- package/dist/core/verify-node.d.ts +14 -0
- package/dist/core/verify-node.js +17 -0
- package/dist/core/verify-node.js.map +1 -0
- package/dist/core/verify-web.d.ts +1 -0
- package/dist/core/verify-web.js +25 -0
- package/dist/core/verify-web.js.map +1 -0
- package/dist/core/verify.d.ts +18 -0
- package/dist/core/verify.js +183 -0
- package/dist/core/verify.js.map +1 -0
- package/package.json +71 -4
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field-set / value-discipline preconditions for the JSON-object subject
|
|
3
|
+
* profiles, enforced BEFORE canonicalization.
|
|
4
|
+
*
|
|
5
|
+
* Each profile spec states that structural conformance is a *precondition of
|
|
6
|
+
* canonicalization*, not a separable later check: `canonical_bytes(subject)` is
|
|
7
|
+
* defined ONLY for an object satisfying the profile in full, and for any
|
|
8
|
+
* other object the profile does not apply and the implementation MUST fail
|
|
9
|
+
* closed (subject.collection/1, subject.ai-decision/1, and the no-number
|
|
10
|
+
* discipline of subject.context-snapshot/1).
|
|
11
|
+
*
|
|
12
|
+
* The verifier already rejects a non-conformant object downstream via commitment
|
|
13
|
+
* mismatch, so this does not change which objects are accepted; it makes the reject happen at the
|
|
14
|
+
* boundary with the correct reason (the profile does not apply) rather than as an
|
|
15
|
+
* opaque digest mismatch, and it removes the only RFC 8785 divergence vector
|
|
16
|
+
* (JSON numbers) that the string-only discipline exists to eliminate.
|
|
17
|
+
*
|
|
18
|
+
* A precondition failure throws `SubjectPreconditionError`; the caller maps it to
|
|
19
|
+
* a fail-closed outcome exactly as it does `UnsupportedProfileError`.
|
|
20
|
+
*/
|
|
21
|
+
/** Thrown when a JSON-object subject violates its profile precondition. */
|
|
22
|
+
export class SubjectPreconditionError extends Error {
|
|
23
|
+
profile;
|
|
24
|
+
constructor(profile, detail) {
|
|
25
|
+
super(`subject precondition failed for ${profile}: ${detail}`);
|
|
26
|
+
this.name = "SubjectPreconditionError";
|
|
27
|
+
this.profile = profile;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function isPlainObject(v) {
|
|
31
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Recursively assert the string-only value discipline of the two JSON-object
|
|
35
|
+
* profiles with closed, string-valued member sets (subject.collection/1 and
|
|
36
|
+
* subject.ai-decision/1): every value at any depth (object members, array
|
|
37
|
+
* elements) MUST be a JSON string, object, or array. A JSON number, boolean, or
|
|
38
|
+
* null token anywhere is non-conformant. This is what keeps RFC 8785 free of
|
|
39
|
+
* number serialization. subject.context-snapshot/1 uses the narrower
|
|
40
|
+
* `assertNoJsonNumber` below.
|
|
41
|
+
*/
|
|
42
|
+
function assertStringOnly(profile, value, path) {
|
|
43
|
+
if (typeof value === "string")
|
|
44
|
+
return;
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
value.forEach((el, i) => assertStringOnly(profile, el, `${path}[${i}]`));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (isPlainObject(value)) {
|
|
50
|
+
for (const k of Object.keys(value)) {
|
|
51
|
+
assertStringOnly(profile, value[k], path ? `${path}.${k}` : k);
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// number, boolean, null, or undefined — all forbidden.
|
|
56
|
+
const kind = value === null ? "null" : typeof value;
|
|
57
|
+
throw new SubjectPreconditionError(profile, `value at ${path || "(root)"} is a JSON ${kind}; every value must be a string, object, or array (no numbers/booleans/nulls)`);
|
|
58
|
+
}
|
|
59
|
+
const CARDINALITY_MAX = 18446744073709551615n; // 2^64 − 1
|
|
60
|
+
/**
|
|
61
|
+
* subject.collection/1: exactly four members — `commitment_scheme`, `root`,
|
|
62
|
+
* `declared_cardinality` and the `leaves[]` array, whose entries each declare their
|
|
63
|
+
* own `profile` and `commitment_digest_hex`. Also checks the commitment-scheme-specific
|
|
64
|
+
* `root` shape, the `declared_cardinality` grammar, and that the cardinality agrees
|
|
65
|
+
* with the number of leaves.
|
|
66
|
+
*/
|
|
67
|
+
export function assertCollectionPrecondition(value) {
|
|
68
|
+
const P = "subject.collection/1";
|
|
69
|
+
if (!isPlainObject(value)) {
|
|
70
|
+
throw new SubjectPreconditionError(P, "subject is not a JSON object");
|
|
71
|
+
}
|
|
72
|
+
const REQUIRED = ["commitment_scheme", "root", "declared_cardinality", "leaves"];
|
|
73
|
+
const STRING_MEMBERS = ["commitment_scheme", "root", "declared_cardinality"];
|
|
74
|
+
const keys = Object.keys(value);
|
|
75
|
+
for (const k of REQUIRED) {
|
|
76
|
+
if (!(k in value))
|
|
77
|
+
throw new SubjectPreconditionError(P, `missing member "${k}"`);
|
|
78
|
+
}
|
|
79
|
+
for (const k of keys) {
|
|
80
|
+
if (!REQUIRED.includes(k)) {
|
|
81
|
+
throw new SubjectPreconditionError(P, `unexpected member "${k}" (exactly four members allowed)`);
|
|
82
|
+
}
|
|
83
|
+
if (STRING_MEMBERS.includes(k) && typeof value[k] !== "string") {
|
|
84
|
+
throw new SubjectPreconditionError(P, `member "${k}" must be a string`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// `leaves` is the one non-string member: an ordered array where each entry declares
|
|
88
|
+
// its own profile and commitment (subject.collection/1 §7.4). Its position IS the
|
|
89
|
+
// leaf index, so the array is load-bearing, not decorative.
|
|
90
|
+
const leaves = value.leaves;
|
|
91
|
+
if (!Array.isArray(leaves) || leaves.length === 0) {
|
|
92
|
+
throw new SubjectPreconditionError(P, `"leaves" must be a non-empty array`);
|
|
93
|
+
}
|
|
94
|
+
for (let i = 0; i < leaves.length; i++) {
|
|
95
|
+
const leaf = leaves[i];
|
|
96
|
+
if (typeof leaf !== "object" || leaf === null || Array.isArray(leaf)) {
|
|
97
|
+
throw new SubjectPreconditionError(P, `"leaves[${i}]" must be an object`);
|
|
98
|
+
}
|
|
99
|
+
const lk = Object.keys(leaf);
|
|
100
|
+
if (lk.length !== 2 || !("profile" in leaf) || !("commitment_digest_hex" in leaf)) {
|
|
101
|
+
throw new SubjectPreconditionError(P, `"leaves[${i}]" must contain exactly "profile" and "commitment_digest_hex"`);
|
|
102
|
+
}
|
|
103
|
+
for (const k of lk) {
|
|
104
|
+
if (typeof leaf[k] !== "string") {
|
|
105
|
+
throw new SubjectPreconditionError(P, `"leaves[${i}].${k}" must be a string`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (!/^[0-9a-f]{64}$/.test(leaf.commitment_digest_hex)) {
|
|
109
|
+
throw new SubjectPreconditionError(P, `"leaves[${i}].commitment_digest_hex" must be 64 lowercase hex characters`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// §7.4.3: the economic layer reads declared_cardinality, so it must agree with the
|
|
113
|
+
// array rather than be derived from it.
|
|
114
|
+
if (String(leaves.length) !== value.declared_cardinality) {
|
|
115
|
+
throw new SubjectPreconditionError(P, `"declared_cardinality" (${String(value.declared_cardinality)}) does not equal the number of leaves (${leaves.length})`);
|
|
116
|
+
}
|
|
117
|
+
// declared_cardinality: canonical unsigned base-10, no sign, no leading
|
|
118
|
+
// zeros, > 0, ≤ 2^64 − 1.
|
|
119
|
+
const dc = value.declared_cardinality;
|
|
120
|
+
if (!/^[1-9][0-9]*$/.test(dc)) {
|
|
121
|
+
throw new SubjectPreconditionError(P, `"declared_cardinality" must be a canonical unsigned base-10 integer with no sign and no leading zeros`);
|
|
122
|
+
}
|
|
123
|
+
if (BigInt(dc) > CARDINALITY_MAX) {
|
|
124
|
+
throw new SubjectPreconditionError(P, `"declared_cardinality" exceeds 2^64 − 1`);
|
|
125
|
+
}
|
|
126
|
+
// for the sha3-256 merkle scheme, root is 64 lowercase hex chars.
|
|
127
|
+
if (value.commitment_scheme === "collection.merkle-sha3-256/1") {
|
|
128
|
+
if (!/^[0-9a-f]{64}$/.test(value.root)) {
|
|
129
|
+
throw new SubjectPreconditionError(P, `"root" must be a 64-character lowercase hex string under collection.merkle-sha3-256/1`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
assertStringOnly(P, value, "");
|
|
133
|
+
}
|
|
134
|
+
/** Profiles an AI-decision part may declare. */
|
|
135
|
+
export const AI_DECISION_IO_PROFILES = [
|
|
136
|
+
"subject.text/1",
|
|
137
|
+
"subject.binary/1",
|
|
138
|
+
"subject.email/1",
|
|
139
|
+
"subject.ai-decision/1",
|
|
140
|
+
];
|
|
141
|
+
const HEX64 = /^[0-9a-f]{64}$/;
|
|
142
|
+
const AI_PART_ID = /^[a-z][a-z0-9._-]{0,63}$/;
|
|
143
|
+
const MIME_ESSENCE = /^[a-z0-9!#$%&'*+.^_`|~-]+\/[a-z0-9!#$%&'*+.^_`|~-]+$/;
|
|
144
|
+
const AI_PART_KEYS = [
|
|
145
|
+
"id", "role", "media_type", "profile", "material_nonce_hex", "commitment_digest_hex",
|
|
146
|
+
];
|
|
147
|
+
const AI_PART_MAX = 256;
|
|
148
|
+
const AI_PARAMETERS_MAX = 128;
|
|
149
|
+
/**
|
|
150
|
+
* UTC, millisecond timestamp spelling required by subject.ai-decision/1.
|
|
151
|
+
*/
|
|
152
|
+
const DECIDED_AT = /^([0-9]{4})-(0[1-9]|1[0-2])-([0-2][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\.([0-9]{3})Z$/;
|
|
153
|
+
function isValidGregorianUtcMillisecond(value) {
|
|
154
|
+
const match = DECIDED_AT.exec(value);
|
|
155
|
+
if (!match)
|
|
156
|
+
return false;
|
|
157
|
+
const year = Number(match[1]);
|
|
158
|
+
const month = Number(match[2]);
|
|
159
|
+
const day = Number(match[3]);
|
|
160
|
+
if (year === 0 || day === 0)
|
|
161
|
+
return false;
|
|
162
|
+
const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
163
|
+
const days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
164
|
+
return day <= days[month - 1];
|
|
165
|
+
}
|
|
166
|
+
function assertAiPart(profile, part, path, ids, materialNonces) {
|
|
167
|
+
if (!isPlainObject(part)) {
|
|
168
|
+
throw new SubjectPreconditionError(profile, `"${path}" must be an object`);
|
|
169
|
+
}
|
|
170
|
+
const keys = Object.keys(part);
|
|
171
|
+
if (keys.length !== AI_PART_KEYS.length || AI_PART_KEYS.some((key) => !(key in part))) {
|
|
172
|
+
throw new SubjectPreconditionError(profile, `"${path}" must contain exactly ${AI_PART_KEYS.map((key) => `"${key}"`).join(", ")}`);
|
|
173
|
+
}
|
|
174
|
+
for (const key of keys) {
|
|
175
|
+
if (!AI_PART_KEYS.includes(key)) {
|
|
176
|
+
throw new SubjectPreconditionError(profile, `"${path}" has unexpected member "${key}"`);
|
|
177
|
+
}
|
|
178
|
+
if (typeof part[key] !== "string") {
|
|
179
|
+
throw new SubjectPreconditionError(profile, `"${path}.${key}" must be a string`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const p = part;
|
|
183
|
+
if (!AI_PART_ID.test(p.id)) {
|
|
184
|
+
throw new SubjectPreconditionError(profile, `"${path}.id" is not a valid material id`);
|
|
185
|
+
}
|
|
186
|
+
if (ids.has(p.id)) {
|
|
187
|
+
throw new SubjectPreconditionError(profile, `material id ${JSON.stringify(p.id)} is duplicated`);
|
|
188
|
+
}
|
|
189
|
+
ids.add(p.id);
|
|
190
|
+
if (p.role.length === 0) {
|
|
191
|
+
throw new SubjectPreconditionError(profile, `"${path}.role" must be non-empty`);
|
|
192
|
+
}
|
|
193
|
+
if (!MIME_ESSENCE.test(p.media_type)) {
|
|
194
|
+
throw new SubjectPreconditionError(profile, `"${path}.media_type" must be a lowercase MIME essence without parameters`);
|
|
195
|
+
}
|
|
196
|
+
if (!AI_DECISION_IO_PROFILES.includes(p.profile)) {
|
|
197
|
+
throw new SubjectPreconditionError(profile, `"${path}.profile" is not an admitted part profile`);
|
|
198
|
+
}
|
|
199
|
+
if (!HEX64.test(p.material_nonce_hex)) {
|
|
200
|
+
throw new SubjectPreconditionError(profile, `"${path}.material_nonce_hex" must be 64 lowercase hex characters`);
|
|
201
|
+
}
|
|
202
|
+
if (materialNonces.has(p.material_nonce_hex)) {
|
|
203
|
+
throw new SubjectPreconditionError(profile, `material nonce ${JSON.stringify(p.material_nonce_hex)} is duplicated`);
|
|
204
|
+
}
|
|
205
|
+
materialNonces.add(p.material_nonce_hex);
|
|
206
|
+
if (!HEX64.test(p.commitment_digest_hex)) {
|
|
207
|
+
throw new SubjectPreconditionError(profile, `"${path}.commitment_digest_hex" must be 64 lowercase hex characters`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* subject.ai-decision/1: exact record and part shapes, bounded flat parameters,
|
|
212
|
+
* string-only values, part ids unique within the record, and a Gregorian UTC timestamp.
|
|
213
|
+
*/
|
|
214
|
+
export function assertAiDecisionPrecondition(value) {
|
|
215
|
+
const P = "subject.ai-decision/1";
|
|
216
|
+
if (!isPlainObject(value)) {
|
|
217
|
+
throw new SubjectPreconditionError(P, "record is not a JSON object");
|
|
218
|
+
}
|
|
219
|
+
const REQUIRED = ["profile", "decision_id", "decided_at", "model", "observation_scope", "input", "output", "decision"];
|
|
220
|
+
const OPTIONAL = ["parameters", "context", "started_at", "actor_id", "policy_ref"];
|
|
221
|
+
const allowed = new Set([...REQUIRED, ...OPTIONAL]);
|
|
222
|
+
for (const k of REQUIRED) {
|
|
223
|
+
if (!(k in value))
|
|
224
|
+
throw new SubjectPreconditionError(P, `missing required member "${k}"`);
|
|
225
|
+
}
|
|
226
|
+
for (const k of Object.keys(value)) {
|
|
227
|
+
if (!allowed.has(k)) {
|
|
228
|
+
throw new SubjectPreconditionError(P, `unexpected member "${k}"`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (value.profile !== P) {
|
|
232
|
+
throw new SubjectPreconditionError(P, `"profile" must equal "${P}"`);
|
|
233
|
+
}
|
|
234
|
+
for (const k of ["profile", "decision_id", "decided_at", "observation_scope", "decision"]) {
|
|
235
|
+
if (typeof value[k] !== "string") {
|
|
236
|
+
throw new SubjectPreconditionError(P, `member "${k}" must be a string`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (!AI_PART_ID.test(value.decision_id)) {
|
|
240
|
+
throw new SubjectPreconditionError(P, `"decision_id" is not a valid canonical token`);
|
|
241
|
+
}
|
|
242
|
+
if (value.decision.length === 0) {
|
|
243
|
+
throw new SubjectPreconditionError(P, `"decision" must be non-empty`);
|
|
244
|
+
}
|
|
245
|
+
if (!isValidGregorianUtcMillisecond(value.decided_at)) {
|
|
246
|
+
throw new SubjectPreconditionError(P, `"decided_at" must be a valid Gregorian UTC timestamp at millisecond precision`);
|
|
247
|
+
}
|
|
248
|
+
if ("started_at" in value) {
|
|
249
|
+
if (typeof value.started_at !== "string" || !isValidGregorianUtcMillisecond(value.started_at)) {
|
|
250
|
+
throw new SubjectPreconditionError(P, `"started_at" must be a valid Gregorian UTC timestamp at millisecond precision`);
|
|
251
|
+
}
|
|
252
|
+
if (value.started_at > value.decided_at) {
|
|
253
|
+
throw new SubjectPreconditionError(P, `"started_at" must not be later than "decided_at"`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// model: object with string id + provider, optional string version, no other members.
|
|
257
|
+
assertNestedStringObject(P, value.model, "model", ["id", "provider"], ["version"]);
|
|
258
|
+
for (const [key, member] of Object.entries(value.model)) {
|
|
259
|
+
if (member.length === 0) {
|
|
260
|
+
throw new SubjectPreconditionError(P, `"model.${key}" must be non-empty`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const ids = new Set();
|
|
264
|
+
const materialNonces = new Set();
|
|
265
|
+
let total = 0;
|
|
266
|
+
for (const side of ["input", "output"]) {
|
|
267
|
+
const parts = value[side];
|
|
268
|
+
if (!Array.isArray(parts)) {
|
|
269
|
+
throw new SubjectPreconditionError(P, `member "${side}" must be an array`);
|
|
270
|
+
}
|
|
271
|
+
if (parts.length === 0) {
|
|
272
|
+
throw new SubjectPreconditionError(P, `member "${side}" must be a non-empty array`);
|
|
273
|
+
}
|
|
274
|
+
total += parts.length;
|
|
275
|
+
parts.forEach((part, index) => assertAiPart(P, part, `${side}[${index}]`, ids, materialNonces));
|
|
276
|
+
}
|
|
277
|
+
if (total < 1 || total > AI_PART_MAX) {
|
|
278
|
+
throw new SubjectPreconditionError(P, `input and output must contain 1..${AI_PART_MAX} parts in total`);
|
|
279
|
+
}
|
|
280
|
+
// parameters (optional): opaque, issuer-defined names, but every member is a
|
|
281
|
+
// string — no nested object or array.
|
|
282
|
+
for (const mapName of ["parameters", "context"]) {
|
|
283
|
+
if (!(mapName in value))
|
|
284
|
+
continue;
|
|
285
|
+
const map = value[mapName];
|
|
286
|
+
if (!isPlainObject(map)) {
|
|
287
|
+
throw new SubjectPreconditionError(P, `"${mapName}" must be an object when present`);
|
|
288
|
+
}
|
|
289
|
+
const entries = Object.entries(map);
|
|
290
|
+
if (entries.length > AI_PARAMETERS_MAX) {
|
|
291
|
+
throw new SubjectPreconditionError(P, `"${mapName}" must contain at most ${AI_PARAMETERS_MAX} members`);
|
|
292
|
+
}
|
|
293
|
+
for (const [k, v] of entries) {
|
|
294
|
+
if (typeof v !== "string") {
|
|
295
|
+
throw new SubjectPreconditionError(P, `"${mapName}.${k}" must be a string (${mapName} members are flat strings)`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
for (const k of ["actor_id", "policy_ref"]) {
|
|
300
|
+
if (k in value && typeof value[k] !== "string") {
|
|
301
|
+
throw new SubjectPreconditionError(P, `optional member "${k}" must be a string`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// The only arrays permitted by the closed shape are input and output. Every
|
|
305
|
+
// remaining leaf is a string, which keeps JCS free of number serialization.
|
|
306
|
+
assertStringOnly(P, value, "");
|
|
307
|
+
}
|
|
308
|
+
function assertNestedStringObject(profile, obj, name, required, optional) {
|
|
309
|
+
if (!isPlainObject(obj)) {
|
|
310
|
+
throw new SubjectPreconditionError(profile, `member "${name}" must be an object`);
|
|
311
|
+
}
|
|
312
|
+
const allowed = new Set([...required, ...optional]);
|
|
313
|
+
for (const k of required) {
|
|
314
|
+
if (!(k in obj))
|
|
315
|
+
throw new SubjectPreconditionError(profile, `"${name}" missing member "${k}"`);
|
|
316
|
+
}
|
|
317
|
+
for (const k of Object.keys(obj)) {
|
|
318
|
+
if (!allowed.has(k)) {
|
|
319
|
+
throw new SubjectPreconditionError(profile, `"${name}" has unexpected member "${k}"`);
|
|
320
|
+
}
|
|
321
|
+
if (typeof obj[k] !== "string") {
|
|
322
|
+
throw new SubjectPreconditionError(profile, `"${name}.${k}" must be a string`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* subject.context-snapshot/1: the only precondition this profile fixes at
|
|
328
|
+
* the canonicalization boundary is that the value is a JSON object with no JSON
|
|
329
|
+
* number at any depth (booleans and nulls are permitted). It does not fix a member set — the snapshot
|
|
330
|
+
* shape is governed by the higher-layer protocol (CCVP/1), not this profile.
|
|
331
|
+
*/
|
|
332
|
+
export function assertContextSnapshotPrecondition(value) {
|
|
333
|
+
const P = "subject.context-snapshot/1";
|
|
334
|
+
if (!isPlainObject(value)) {
|
|
335
|
+
throw new SubjectPreconditionError(P, "snapshot is not a JSON object");
|
|
336
|
+
}
|
|
337
|
+
assertNoJsonNumber(P, value, "");
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* `subject.context-snapshot/1` §7.1: no JSON NUMBER at any depth. Booleans and
|
|
341
|
+
* nulls are permitted.
|
|
342
|
+
*
|
|
343
|
+
* Narrower than `assertStringOnly` on purpose, and the difference is normative.
|
|
344
|
+
* That function serves `subject.collection/1` and `subject.ai-decision/1`, whose
|
|
345
|
+
* member sets are closed and entirely string-valued. This profile fixes no member
|
|
346
|
+
* set — the snapshot shape belongs to CCVP/1 — and §7 requires preserving "the
|
|
347
|
+
* exact string, boolean, array, object, and null semantics of the input", while
|
|
348
|
+
* §8 forbids coercing "booleans or nulls into strings". CCVP/1 §7.1 relies on
|
|
349
|
+
* this: its normative entry example carries `valid_to: null` for an open-ended
|
|
350
|
+
* eligibility window, and `revoked_at: null` for one never revoked.
|
|
351
|
+
*
|
|
352
|
+
* Rejecting nulls here would make the governing protocol's own example
|
|
353
|
+
* non-conformant, and would force an open window to be spelled as a string —
|
|
354
|
+
* exactly the coercion §8 prohibits. Only numbers are excluded, because number
|
|
355
|
+
* serialization is the one RFC 8785 divergence vector across languages.
|
|
356
|
+
*/
|
|
357
|
+
function assertNoJsonNumber(profile, value, path) {
|
|
358
|
+
if (typeof value === "number") {
|
|
359
|
+
throw new SubjectPreconditionError(profile, `value at ${path || "(root)"} is a JSON number; every numeric-looking value ` +
|
|
360
|
+
`must be carried as a JSON string so RFC 8785 canonicalization converges ` +
|
|
361
|
+
`across languages`);
|
|
362
|
+
}
|
|
363
|
+
if (Array.isArray(value)) {
|
|
364
|
+
value.forEach((el, i) => assertNoJsonNumber(profile, el, `${path}[${i}]`));
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (isPlainObject(value)) {
|
|
368
|
+
for (const k of Object.keys(value)) {
|
|
369
|
+
assertNoJsonNumber(profile, value[k], path ? `${path}.${k}` : k);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
//# sourceMappingURL=subject-json-preconditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subject-json-preconditions.js","sourceRoot":"","sources":["../../../core/crypto/subject-json-preconditions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,2EAA2E;AAC3E,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACxC,OAAO,CAAS;IACzB,YAAY,OAAe,EAAE,MAAc;QACzC,KAAK,CAAC,mCAAmC,OAAO,KAAK,MAAM,EAAE,CAAC,CAAC;QAC/D,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED,SAAS,aAAa,CAAC,CAAU;IAC/B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CAAC,OAAe,EAAE,KAAc,EAAE,IAAY;IACrE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO;IACtC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACzE,OAAO;IACT,CAAC;IACD,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAA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IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,wBAAwB,CAAC,CAAC,EAAE,+BAA+B,CAAC,CAAC;IACzE,CAAC;IACD,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,kBAAkB,CAAC,OAAe,EAAE,KAAc,EAAE,IAAY;IACvE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,wBAAwB,CAChC,OAAO,EACP,YAAY,IAAI,IAAI,QAAQ,iDAAiD;YAC3E,0EAA0E;YAC1E,kBAAkB,CACrB,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3E,OAAO;IACT,CAAC;IACD,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IndependenceProof, SystemDomainConfig } from "../types/index.js";
|
|
2
|
+
import { ResultBuilder } from "../result/builder.js";
|
|
3
|
+
/**
|
|
4
|
+
* Verify system-domain attribution.
|
|
5
|
+
*
|
|
6
|
+
* Checks: SYSTEM_DOMAIN_EXACT, SYSTEM_ROOT_BINDING_VALID, CLONE_OR_FORK_REJECTED
|
|
7
|
+
*
|
|
8
|
+
* Per system-domain/1:
|
|
9
|
+
* - system_id must equal the configured CERTCRYPT system identity
|
|
10
|
+
* - system_root_fingerprint must match the exact published bootstrap root
|
|
11
|
+
* - Bare system_id without valid root fingerprint is always rejected
|
|
12
|
+
*/
|
|
13
|
+
export declare function verifySystemDomain(proof: IndependenceProof, config: SystemDomainConfig, builder: ResultBuilder): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verify system-domain attribution.
|
|
3
|
+
*
|
|
4
|
+
* Checks: SYSTEM_DOMAIN_EXACT, SYSTEM_ROOT_BINDING_VALID, CLONE_OR_FORK_REJECTED
|
|
5
|
+
*
|
|
6
|
+
* Per system-domain/1:
|
|
7
|
+
* - system_id must equal the configured CERTCRYPT system identity
|
|
8
|
+
* - system_root_fingerprint must match the exact published bootstrap root
|
|
9
|
+
* - Bare system_id without valid root fingerprint is always rejected
|
|
10
|
+
*/
|
|
11
|
+
export function verifySystemDomain(proof, config, builder) {
|
|
12
|
+
// SYSTEM_DOMAIN_EXACT
|
|
13
|
+
if (!proof.system_id || proof.system_id !== config.system_id) {
|
|
14
|
+
builder.fail("SYSTEM_DOMAIN_EXACT", "INDEPENDENT_INVALID", `system_id mismatch: expected "${config.system_id}", got "${proof.system_id ?? "(missing)"}"`);
|
|
15
|
+
// A proof that does not carry THIS domain's system_id is a foreign context,
|
|
16
|
+
// whether it names another domain or names none at all. Both are reported as
|
|
17
|
+
// the clone/fork rejection: an absent identifier is not a lesser case than a
|
|
18
|
+
// wrong one, and neither is attributable to this domain.
|
|
19
|
+
builder.fail("CLONE_OR_FORK_REJECTED", "INDEPENDENT_INVALID", proof.system_id
|
|
20
|
+
? `Proof system_id "${proof.system_id}" does not match CERTCRYPT domain`
|
|
21
|
+
: "Proof carries no system_id; it is not attributable to the CERTCRYPT domain");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
builder.pass("SYSTEM_DOMAIN_EXACT");
|
|
25
|
+
builder.addDiagnostic("info", `system_id=${proof.system_id}`, "SYSTEM_DOMAIN_EXACT");
|
|
26
|
+
// SYSTEM_ROOT_BINDING_VALID
|
|
27
|
+
if (!proof.system_root_fingerprint ||
|
|
28
|
+
proof.system_root_fingerprint !== config.system_root_fingerprint) {
|
|
29
|
+
builder.fail("SYSTEM_ROOT_BINDING_VALID", "INDEPENDENT_INVALID", `system_root_fingerprint mismatch: expected "${config.system_root_fingerprint}", got "${proof.system_root_fingerprint ?? "(missing)"}"`);
|
|
30
|
+
// Correct system_id but wrong root → clone/fork
|
|
31
|
+
builder.fail("CLONE_OR_FORK_REJECTED", "INDEPENDENT_INVALID", `system_id is "certcrypt" but system_root_fingerprint does not match published root`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
builder.pass("SYSTEM_ROOT_BINDING_VALID");
|
|
35
|
+
builder.addDiagnostic("info", `root=${proof.system_root_fingerprint}`, "SYSTEM_ROOT_BINDING_VALID");
|
|
36
|
+
// CLONE_OR_FORK_REJECTED — passed if we reached here
|
|
37
|
+
builder.pass("CLONE_OR_FORK_REJECTED");
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=verify-domain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-domain.js","sourceRoot":"","sources":["../../../core/domain/verify-domain.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAwB,EACxB,MAA0B,EAC1B,OAAsB;IAEtB,sBAAsB;IACtB,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;QAC7D,OAAO,CAAC,IAAI,CACV,qBAAqB,EACrB,qBAAqB,EACrB,iCAAiC,MAAM,CAAC,SAAS,WAAW,KAAK,CAAC,SAAS,IAAI,WAAW,GAAG,CAC9F,CAAC;QACF,4EAA4E;QAC5E,6EAA6E;QAC7E,6EAA6E;QAC7E,yDAAyD;QACzD,OAAO,CAAC,IAAI,CACV,wBAAwB,EACxB,qBAAqB,EACrB,KAAK,CAAC,SAAS;YACb,CAAC,CAAC,oBAAoB,KAAK,CAAC,SAAS,mCAAmC;YACxE,CAAC,CAAC,4EAA4E,CACjF,CAAC;QACF,OAAO;IACT,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACpC,OAAO,CAAC,aAAa,CACnB,MAAM,EACN,aAAa,KAAK,CAAC,SAAS,EAAE,EAC9B,qBAAqB,CACtB,CAAC;IAEF,4BAA4B;IAC5B,IACE,CAAC,KAAK,CAAC,uBAAuB;QAC9B,KAAK,CAAC,uBAAuB,KAAK,MAAM,CAAC,uBAAuB,EAChE,CAAC;QACD,OAAO,CAAC,IAAI,CACV,2BAA2B,EAC3B,qBAAqB,EACrB,+CAA+C,MAAM,CAAC,uBAAuB,WAAW,KAAK,CAAC,uBAAuB,IAAI,WAAW,GAAG,CACxI,CAAC;QACF,gDAAgD;QAChD,OAAO,CAAC,IAAI,CACV,wBAAwB,EACxB,qBAAqB,EACrB,oFAAoF,CACrF,CAAC;QACF,OAAO;IACT,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAC1C,OAAO,CAAC,aAAa,CACnB,MAAM,EACN,QAAQ,KAAK,CAAC,uBAAuB,EAAE,EACvC,2BAA2B,CAC5B,CAAC;IAEF,qDAAqD;IACrD,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anti-equivocation detection for `system-manifest/1` rotation.
|
|
3
|
+
*
|
|
4
|
+
* Equivocation is a COMPROMISED predecessor entry signing two or more conflicting
|
|
5
|
+
* successor-bindings over the same predecessor manifest state. It cannot be
|
|
6
|
+
* prevented cryptographically (both signatures verify); `/1` converts it into
|
|
7
|
+
* DETECTABLE, fail-closed evidence: a verifier persists every successor-binding
|
|
8
|
+
* observation it accepts, and rejects any later observation that conflicts with a
|
|
9
|
+
* persisted one under the same index tuple.
|
|
10
|
+
*
|
|
11
|
+
* This module provides:
|
|
12
|
+
* - the observation record + its index key;
|
|
13
|
+
* - an `ObservationStore` interface so persistence is pluggable (a durable store
|
|
14
|
+
* is REQUIRED for the cross-session guarantee; the in-memory default
|
|
15
|
+
* gives intra-session detection out of the box with zero integrator setup);
|
|
16
|
+
* - `checkAndRecord`, the comparison rule + fail-closed verdict.
|
|
17
|
+
*
|
|
18
|
+
* SCOPE: detection operates on observations that CONVERGE at one
|
|
19
|
+
* verifier. Disjoint verifiers that never exchange observations do not detect
|
|
20
|
+
* equivocation between themselves; `/1` does not promise that. An in-memory store
|
|
21
|
+
* only detects WITHIN one process lifetime — inject a durable store for the full
|
|
22
|
+
* cross-session guarantee.
|
|
23
|
+
*/
|
|
24
|
+
/** One successor-binding observation, as persisted. */
|
|
25
|
+
export interface SuccessorBindingObservation {
|
|
26
|
+
system_id: string;
|
|
27
|
+
predecessor_manifest_fingerprint: string;
|
|
28
|
+
predecessor_manifest_sequence: number;
|
|
29
|
+
predecessor_kid: string;
|
|
30
|
+
successor_kid: string;
|
|
31
|
+
successor_algorithm: string;
|
|
32
|
+
successor_public_key_p256_b64: string;
|
|
33
|
+
successor_public_key_mldsa_b64: string;
|
|
34
|
+
successor_valid_from: string;
|
|
35
|
+
/** Exact predecessor composite signature bytes/object (canonical evidence). */
|
|
36
|
+
predecessor_signature: unknown;
|
|
37
|
+
}
|
|
38
|
+
/** The canonical index key for an observation. */
|
|
39
|
+
export declare function observationIndexKey(o: SuccessorBindingObservation): string;
|
|
40
|
+
/**
|
|
41
|
+
* Pluggable persistence for successor-binding observations.
|
|
42
|
+
*
|
|
43
|
+
* Implementations MUST persist across sessions fully. The
|
|
44
|
+
* methods are keyed by `observationIndexKey`. `getByIndex` returns all
|
|
45
|
+
* observations previously recorded under one index tuple (normally zero or one in
|
|
46
|
+
* the honest case; more than one already implies equivocation).
|
|
47
|
+
*/
|
|
48
|
+
export interface ObservationStore {
|
|
49
|
+
getByIndex(indexKey: string): SuccessorBindingObservation[];
|
|
50
|
+
put(indexKey: string, observation: SuccessorBindingObservation): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* In-memory store — the zero-config default. Detects equivocation WITHIN a single
|
|
54
|
+
* verifier process. NOT durable: a fresh process starts with no memory, so it does
|
|
55
|
+
* NOT provide the cross-session guarantee. Production verifiers SHOULD
|
|
56
|
+
* inject a durable store (file, IndexedDB, KV, …) implementing `ObservationStore`.
|
|
57
|
+
*/
|
|
58
|
+
export declare class InMemoryObservationStore implements ObservationStore {
|
|
59
|
+
private readonly map;
|
|
60
|
+
getByIndex(indexKey: string): SuccessorBindingObservation[];
|
|
61
|
+
put(indexKey: string, observation: SuccessorBindingObservation): void;
|
|
62
|
+
}
|
|
63
|
+
export interface EquivocationVerdict {
|
|
64
|
+
/** True iff a conflicting prior observation was found. */
|
|
65
|
+
equivocation: boolean;
|
|
66
|
+
/** When equivocation: the prior + new observations that conflict (evidence). */
|
|
67
|
+
conflict?: {
|
|
68
|
+
prior: SuccessorBindingObservation;
|
|
69
|
+
incoming: SuccessorBindingObservation;
|
|
70
|
+
fields: string[];
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Comparison rule + fail-closed evidence.
|
|
75
|
+
*
|
|
76
|
+
* Call this for each successor-binding being validated, AFTER its
|
|
77
|
+
* `predecessor_signature` has been verified — only validly-signed
|
|
78
|
+
* observations are recorded/compared. Behavior:
|
|
79
|
+
* - If a persisted observation under the same index tuple differs in any conflict
|
|
80
|
+
* field → returns `{ equivocation: true, conflict }`. The caller MUST treat the
|
|
81
|
+
* implicated manifest versions as terminally invalid and MUST NOT
|
|
82
|
+
* accept the manifest/extension. The conflicting observations are RETAINED
|
|
83
|
+
* (both kept in the store) as canonical evidence.
|
|
84
|
+
* - Otherwise the observation is persisted (if not already present identically)
|
|
85
|
+
* and `{ equivocation: false }` is returned.
|
|
86
|
+
*/
|
|
87
|
+
export declare function checkAndRecord(store: ObservationStore, incoming: SuccessorBindingObservation): EquivocationVerdict;
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anti-equivocation.js","sourceRoot":"","sources":["../../../core/foundation/anti-equivocation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAmBH,kDAAkD;AAClD,MAAM,UAAU,mBAAmB,CAAC,CAA8B;IAChE,gEAAgE;IAChE,OAAO;QACL,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,gCAAgC;QAClC,MAAM,CAAC,CAAC,CAAC,6BAA6B,CAAC;QACvC,CAAC,CAAC,eAAe;KAClB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACd,CAAC;AAeD;;;;;GAKG;AACH,MAAM,OAAO,wBAAwB;IAClB,GAAG,GAAG,IAAI,GAAG,EAAyC,CAAC;IAExE,UAAU,CAAC,QAAgB;QACzB,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;IAED,GAAG,CAAC,QAAgB,EAAE,WAAwC;QAC5D,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACpC,IAAI,IAAI;YAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;;YAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAED,8EAA8E;AAC9E,MAAM,eAAe,GAA0C;IAC7D,eAAe;IACf,qBAAqB;IACrB,+BAA+B;IAC/B,gCAAgC;IAChC,sBAAsB;CACvB,CAAC;AAaF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAuB,EACvB,QAAqC;IAErC,MAAM,GAAG,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAEpC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACnE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,4DAA4D;YAC5D,8DAA8D;YAC9D,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YACzB,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC;QAC1E,CAAC;IACH,CAAC;IAED,+EAA+E;IAC/E,4EAA4E;IAC5E,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACpC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CACnD,CAAC;IACF,IAAI,CAAC,YAAY;QAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC5C,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SystemFoundation, SystemDomainConfig } from "../types/index.js";
|
|
2
|
+
import { ResultBuilder } from "../result/builder.js";
|
|
3
|
+
/**
|
|
4
|
+
* SHA3-256(UTF-8(JCS(payload))) of the canonical unsigned statement payload
|
|
5
|
+
* (system-foundation/1 §9): the digest the bootstrap quorum signs, and the
|
|
6
|
+
* value a registry entry pins as `foundation_payload_digest`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function foundationPayloadDigest(foundation: SystemFoundation): string;
|
|
9
|
+
/**
|
|
10
|
+
* Verify a system-foundation/1 statement under the k-of-n quorum model.
|
|
11
|
+
*
|
|
12
|
+
* Per system-foundation/1, validation sequence:
|
|
13
|
+
* 1. foundation_profile_id
|
|
14
|
+
* 2. system_id
|
|
15
|
+
* 3. root_fingerprint_derivation = "sha3-256-system-manifest-jcs-v1"
|
|
16
|
+
* 4. embedded system_manifest is a conforming BOOTSTRAP manifest (sequence 0,
|
|
17
|
+
* one entry, 2 ≤ k ≤ n, members length n, unique member_kids, correct key
|
|
18
|
+
* byte lengths)
|
|
19
|
+
* 5. recompute system_root_fingerprint = SHA3-256(JCS(system_manifest)) and
|
|
20
|
+
* compare to the carried value
|
|
21
|
+
* 6. system_domain_capacity_key_{p256,mldsa}_b64 present and decode
|
|
22
|
+
* 7. statement_signatures meet the bootstrap entry's quorum (≥ k distinct
|
|
23
|
+
* members each producing a verifying composite signature over the payload,
|
|
24
|
+
* system-manifest/1 counting rule)
|
|
25
|
+
* 8. successor-binding observations, when supplied: each authorized by ≥ k
|
|
26
|
+
* distinct bootstrap-entry members over its system-manifest/1 §9 payload,
|
|
27
|
+
* then compared for equivocation → terminal invalidity
|
|
28
|
+
* 9. publication_refs only as provenance
|
|
29
|
+
*
|
|
30
|
+
* `published_rules_versions` is metadata, never a gate (system-foundation/1
|
|
31
|
+
* §6): the statement is produced once, so a rules version registered later is
|
|
32
|
+
* absent from it by construction.
|
|
33
|
+
*
|
|
34
|
+
* @returns The validated system_root_fingerprint, or null if validation failed.
|
|
35
|
+
*/
|
|
36
|
+
export declare function verifyFoundation(foundation: SystemFoundation, config: SystemDomainConfig, builder: ResultBuilder): string | null;
|