@certcrypt/sdk 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/sdk might be problematic. Click here for more details.
- package/CHANGELOG.md +74 -0
- package/LICENSE +178 -0
- package/README.md +557 -2
- package/SECURITY.md +55 -0
- package/dist/src/artifacts/base-certificate.d.ts +336 -0
- package/dist/src/artifacts/base-certificate.js +373 -0
- package/dist/src/artifacts/base-certificate.js.map +1 -0
- package/dist/src/artifacts/capacity-evidence.d.ts +195 -0
- package/dist/src/artifacts/capacity-evidence.js +202 -0
- package/dist/src/artifacts/capacity-evidence.js.map +1 -0
- package/dist/src/artifacts/commitment-inclusion.d.ts +23 -0
- package/dist/src/artifacts/commitment-inclusion.js +91 -0
- package/dist/src/artifacts/commitment-inclusion.js.map +1 -0
- package/dist/src/artifacts/holder-keyset.d.ts +67 -0
- package/dist/src/artifacts/holder-keyset.js +149 -0
- package/dist/src/artifacts/holder-keyset.js.map +1 -0
- package/dist/src/artifacts/rfc3339.d.ts +9 -0
- package/dist/src/artifacts/rfc3339.js +39 -0
- package/dist/src/artifacts/rfc3339.js.map +1 -0
- package/dist/src/client.d.ts +552 -0
- package/dist/src/client.js +1347 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/crypto/ai-decision.d.ts +73 -0
- package/dist/src/crypto/ai-decision.js +94 -0
- package/dist/src/crypto/ai-decision.js.map +1 -0
- package/dist/src/crypto/canonical-subject.d.ts +33 -0
- package/dist/src/crypto/canonical-subject.js +240 -0
- package/dist/src/crypto/canonical-subject.js.map +1 -0
- package/dist/src/crypto/collection-merkle.d.ts +58 -0
- package/dist/src/crypto/collection-merkle.js +164 -0
- package/dist/src/crypto/collection-merkle.js.map +1 -0
- package/dist/src/crypto/composite.d.ts +53 -0
- package/dist/src/crypto/composite.js +69 -0
- package/dist/src/crypto/composite.js.map +1 -0
- package/dist/src/crypto/digest.d.ts +3 -0
- package/dist/src/crypto/digest.js +31 -0
- package/dist/src/crypto/digest.js.map +1 -0
- package/dist/src/crypto/ecdsa-p256.d.ts +79 -0
- package/dist/src/crypto/ecdsa-p256.js +277 -0
- package/dist/src/crypto/ecdsa-p256.js.map +1 -0
- package/dist/src/crypto/jcs.d.ts +13 -0
- package/dist/src/crypto/jcs.js +65 -0
- package/dist/src/crypto/jcs.js.map +1 -0
- package/dist/src/crypto/merkle.d.ts +18 -0
- package/dist/src/crypto/merkle.js +150 -0
- package/dist/src/crypto/merkle.js.map +1 -0
- package/dist/src/crypto/ml-dsa.d.ts +28 -0
- package/dist/src/crypto/ml-dsa.js +60 -0
- package/dist/src/crypto/ml-dsa.js.map +1 -0
- package/dist/src/crypto/pseudonym.d.ts +8 -0
- package/dist/src/crypto/pseudonym.js +50 -0
- package/dist/src/crypto/pseudonym.js.map +1 -0
- package/dist/src/crypto/strict-json.d.ts +25 -0
- package/dist/src/crypto/strict-json.js +180 -0
- package/dist/src/crypto/strict-json.js.map +1 -0
- package/dist/src/crypto/subject-json-preconditions.d.ts +46 -0
- package/dist/src/crypto/subject-json-preconditions.js +381 -0
- package/dist/src/crypto/subject-json-preconditions.js.map +1 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.js +80 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/issuer.d.ts +668 -0
- package/dist/src/issuer.js +1066 -0
- package/dist/src/issuer.js.map +1 -0
- package/dist/src/retry.d.ts +67 -0
- package/dist/src/retry.js +78 -0
- package/dist/src/retry.js.map +1 -0
- package/dist/src/types.d.ts +297 -0
- package/dist/src/types.js +15 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +62 -4
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// Copyright © 2025-2026 CERTCRYPT, Inc., its affiliates or licensors. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
/**
|
|
15
|
+
* Issuer-side minter of the CCSP/1 `base_certificate` with a verifiable subject
|
|
16
|
+
* anchor — the object the verifier's Issued plane validates.
|
|
17
|
+
*
|
|
18
|
+
* NO CUSTODY: the issuer builds and SIGNS the `base_certificate` with its own
|
|
19
|
+
* issuer key, client-side. CERTCRYPT never holds the key and never signs on the
|
|
20
|
+
* issuer's behalf. This module builds the anchor + payload (CCCP/1
|
|
21
|
+
* per-subject and anchor commitments) and, given a signer, produces the
|
|
22
|
+
* signed certificate and its `certificate_commitment_digest = SHA3(JCS(cert))`.
|
|
23
|
+
*
|
|
24
|
+
* Byte parity is load-bearing and pinned by the conformance vectors — both the
|
|
25
|
+
* per-subject commitments and whole certificates.
|
|
26
|
+
* A one-byte divergence in the anchor JCS, the per-subject and anchor concatenation, or the
|
|
27
|
+
* payload JCS breaks verification cross-language.
|
|
28
|
+
*/
|
|
29
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
30
|
+
import { digestHexText, digestHexBytes } from "../crypto/digest.js";
|
|
31
|
+
import { jcsCanonicalizeString, jcsCanonicalizeBytes } from "../crypto/jcs.js";
|
|
32
|
+
import { canonicalBytesForSubject } from "../crypto/canonical-subject.js";
|
|
33
|
+
import { buildCollection } from "../crypto/collection-merkle.js";
|
|
34
|
+
import { compositeSignP256, } from "../crypto/composite.js";
|
|
35
|
+
import { generateEcdsaP256KeyPair, privateKeyFromScalar, scalarFromSeedMaterial, publicKeyB64FromPrivate, } from "../crypto/ecdsa-p256.js";
|
|
36
|
+
import { keygenMlDsa65 } from "../crypto/ml-dsa.js";
|
|
37
|
+
import { toRfc3339Seconds } from "./rfc3339.js";
|
|
38
|
+
const HEX64_RE = /^[0-9a-f]{64}$/;
|
|
39
|
+
const CERTIFICATE_SCHEMA = "certcrypt-certificate";
|
|
40
|
+
/**
|
|
41
|
+
* CCCP/1 per-subject commitment:
|
|
42
|
+
* commitment_digest_hex = SHA3-256(ASCII(nonce_hex) || ASCII(subject_local_digest_hex))
|
|
43
|
+
* where subject_local_digest_hex = SHA3-256(canonical_bytes). The hex
|
|
44
|
+
* strings are concatenated as ASCII bytes and NOT decoded first (the most common
|
|
45
|
+
* cross-language error). `digestHexText` hashes the UTF-8/ASCII bytes of the
|
|
46
|
+
* string, which is exactly this.
|
|
47
|
+
*/
|
|
48
|
+
export function computeSubjectCommitment(nonce_hex, subjectLocalDigestHex) {
|
|
49
|
+
return digestHexText(nonce_hex + subjectLocalDigestHex);
|
|
50
|
+
}
|
|
51
|
+
/** `subject_local_digest_hex = SHA3-256(canonical_bytes(subject))` (CCCP/1). */
|
|
52
|
+
export function subjectLocalDigestHex(subject) {
|
|
53
|
+
if (subject.material === undefined) {
|
|
54
|
+
throw new Error(`subject of profile ${subject.profile} has no material: a collection declared via ` +
|
|
55
|
+
`\`leaves\` must be resolved with resolveCollectionSubjects() first`);
|
|
56
|
+
}
|
|
57
|
+
return digestHexBytes(canonicalBytesForSubject(subject.profile, subject.material));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Turn every `leaves`-declared collection subject into a concrete descriptor,
|
|
61
|
+
* salted with this certificate's nonce.
|
|
62
|
+
*
|
|
63
|
+
* Returns the resolved subjects plus, per collection, the descriptor and leaf hashes.
|
|
64
|
+
* Both ship signed inside the certificate and are readable from there, ordered — so an
|
|
65
|
+
* inclusion proof can be rebuilt from the certificate alone. What the certificate does
|
|
66
|
+
* NOT carry is the leaf MATERIAL: each leaf is a salted digest, and no party can
|
|
67
|
+
* recover the bytes behind it. Proving a member still requires holding that member.
|
|
68
|
+
*/
|
|
69
|
+
export function resolveCollectionSubjects(subjects, nonceHex) {
|
|
70
|
+
const salt = new TextEncoder().encode(nonceHex);
|
|
71
|
+
const collections = [];
|
|
72
|
+
const resolved = subjects.map((s, i) => {
|
|
73
|
+
if (!s.leaves)
|
|
74
|
+
return s;
|
|
75
|
+
if (s.material !== undefined) {
|
|
76
|
+
throw new Error(`subject ${i}: pass either \`material\` or \`leaves\`, not both`);
|
|
77
|
+
}
|
|
78
|
+
const built = buildCollection(salt, s.leaves);
|
|
79
|
+
collections.push({
|
|
80
|
+
subjectIndex: i,
|
|
81
|
+
descriptor: built.descriptor,
|
|
82
|
+
leafHashes: built.leafHashes,
|
|
83
|
+
});
|
|
84
|
+
// The descriptor is the subject's material AND rides in the subject object itself:
|
|
85
|
+
// the same bytes serve as what the commitment digests and as what the verifier
|
|
86
|
+
// reads without needing a delivered file.
|
|
87
|
+
return {
|
|
88
|
+
profile: s.profile,
|
|
89
|
+
material: jcsCanonicalizeBytes(built.descriptor),
|
|
90
|
+
collection: built.descriptor,
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
return { subjects: resolved, collections };
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* CCCP/1 anchor commitment:
|
|
97
|
+
* anchor_commitment_digest_hex =
|
|
98
|
+
* SHA3-256(ASCII(nonce_hex) || ASCII(SHA3-256(RFC8785(anchor))))
|
|
99
|
+
* Published in `payload.anchor_commitment_digest_hex`.
|
|
100
|
+
*/
|
|
101
|
+
export function computeAnchorCommitment(anchor) {
|
|
102
|
+
const anchorCanonHex = digestHexBytes(jcsCanonicalizeBytes(anchor));
|
|
103
|
+
return digestHexText(anchor.nonce_hex + anchorCanonHex);
|
|
104
|
+
}
|
|
105
|
+
/** 256-bit CSPRNG nonce as 64 lowercase hex chars. Non-reuse is the caller's invariant. */
|
|
106
|
+
export function generateNonceHex() {
|
|
107
|
+
return Buffer.from(randomBytes(32)).toString("hex");
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Derive the evidence `expires_at = issued_at + ttl` (capacity.commitment/1),
|
|
111
|
+
* keeping RFC 3339 second precision (byte-parity with the canonical bytes).
|
|
112
|
+
*
|
|
113
|
+
* The TTL is NOT chosen here: it comes from the active rules-domain registry, and
|
|
114
|
+
* the value it yields is the signed settlement-bound deadline a verifier evaluates
|
|
115
|
+
* under the dual temporal condition. This function takes it as a parameter — a
|
|
116
|
+
* wrong value fails verification closed.
|
|
117
|
+
*
|
|
118
|
+
* `issued_at` MUST be RFC 3339 UTC second precision (…Z); `ttl_seconds` MUST be a
|
|
119
|
+
* positive whole number of seconds.
|
|
120
|
+
*/
|
|
121
|
+
export function computeExpiresAt(issued_at, ttl_seconds) {
|
|
122
|
+
const normalizedIssued = toRfc3339Seconds(issued_at);
|
|
123
|
+
if (!Number.isInteger(ttl_seconds) || ttl_seconds <= 0) {
|
|
124
|
+
throw new Error(`ttl_seconds must be a positive whole number of seconds (got ${ttl_seconds})`);
|
|
125
|
+
}
|
|
126
|
+
const expires = new Date(Date.parse(normalizedIssued) + ttl_seconds * 1000);
|
|
127
|
+
return toRfc3339Seconds(expires);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build the unsigned CCSP/1 payload with a verifiable subject anchor. Computes
|
|
131
|
+
* each subject's commitment from its material (subject_local_digest never
|
|
132
|
+
* leaves this process), assembles the anchor, and computes the anchor
|
|
133
|
+
* commitment. The subject order is preserved (CCSP/1 — order is
|
|
134
|
+
* significant and the normative subject count).
|
|
135
|
+
*
|
|
136
|
+
* Throws on a malformed nonce or an empty subject set (fail-fast; the verifier
|
|
137
|
+
* would reject these downstream).
|
|
138
|
+
*/
|
|
139
|
+
export function assembleUnsignedPayload(input) {
|
|
140
|
+
if (!HEX64_RE.test(input.nonce_hex)) {
|
|
141
|
+
throw new Error(`nonce_hex must be 64 lowercase hex chars (got ${JSON.stringify(input.nonce_hex)})`);
|
|
142
|
+
}
|
|
143
|
+
if (input.subjects.length === 0) {
|
|
144
|
+
throw new Error("at least one subject is required (CCSP/1)");
|
|
145
|
+
}
|
|
146
|
+
if (input.root_id !== undefined && !HEX64_RE.test(input.root_id)) {
|
|
147
|
+
throw new Error(`root_id must be 64 lowercase hex chars when present (got ${JSON.stringify(input.root_id)})`);
|
|
148
|
+
}
|
|
149
|
+
if (input.context !== undefined)
|
|
150
|
+
assertConsistencyContext(input.context);
|
|
151
|
+
const subjects = input.subjects.map((s) => ({
|
|
152
|
+
profile: s.profile,
|
|
153
|
+
commitment_digest_hex: computeSubjectCommitment(input.nonce_hex, subjectLocalDigestHex(s)),
|
|
154
|
+
...(s.collection !== undefined ? { collection: s.collection } : {}),
|
|
155
|
+
}));
|
|
156
|
+
const anchor = {
|
|
157
|
+
issued_at: input.issued_at,
|
|
158
|
+
nonce_hex: input.nonce_hex,
|
|
159
|
+
...(input.root_id !== undefined ? { root_id: input.root_id } : {}),
|
|
160
|
+
subjects,
|
|
161
|
+
};
|
|
162
|
+
return {
|
|
163
|
+
anchor,
|
|
164
|
+
anchor_commitment_digest_hex: computeAnchorCommitment(anchor),
|
|
165
|
+
system_id: input.system_id,
|
|
166
|
+
rules_version: input.rules_version,
|
|
167
|
+
...(input.context !== undefined ? { context: { ...input.context } } : {}),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function assertConsistencyContext(ctx) {
|
|
171
|
+
if (typeof ctx.snapshot_issuer_id !== "string") {
|
|
172
|
+
throw new Error("context.snapshot_issuer_id must be a string (CCVP/1 §5.2)");
|
|
173
|
+
}
|
|
174
|
+
if (!HEX64_RE.test(ctx.snapshot_issuer_fingerprint_digest_hex)) {
|
|
175
|
+
throw new Error("context.snapshot_issuer_fingerprint_digest_hex must be 64 lowercase hex chars (CCVP/1 §5.2)");
|
|
176
|
+
}
|
|
177
|
+
if (typeof ctx.context_set_id !== "string" || ctx.context_set_id.length === 0) {
|
|
178
|
+
throw new Error("context.context_set_id must be a non-empty string (CCVP/1 §5.2)");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** `payload_canon_digest_hex = SHA3-256(RFC8785(payload))`, lowercase hex. */
|
|
182
|
+
export function payloadCanonDigestHex(payload) {
|
|
183
|
+
return digestHexText(jcsCanonicalizeString(payload));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Generate a fresh, random issuer composite key (P-256 + ML-DSA-65) for
|
|
187
|
+
* development and tests. Issuance derives the key from the seed
|
|
188
|
+
* (`deriveIssuerKey`) or takes an injected one (e.g. KMS-backed); a random key
|
|
189
|
+
* cannot be re-derived from the seed, so do NOT use this to mint production
|
|
190
|
+
* certificates.
|
|
191
|
+
*/
|
|
192
|
+
export function generateIssuerKey(id) {
|
|
193
|
+
const p256 = generateEcdsaP256KeyPair();
|
|
194
|
+
const mldsa = keygenMlDsa65();
|
|
195
|
+
return {
|
|
196
|
+
id,
|
|
197
|
+
p256Private: p256.privateKey,
|
|
198
|
+
mldsaSecret: mldsa.secretKey,
|
|
199
|
+
pub_p256_b64: p256.publicKeyB64,
|
|
200
|
+
pub_mldsa_b64: Buffer.from(mldsa.publicKey).toString("base64"),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Derive the issuer's composite signing key DETERMINISTICALLY from the same
|
|
205
|
+
* 32-byte master seed the SDK already holds (the one `HolderKeySet.fromMasterSeed`
|
|
206
|
+
* uses for the operation-key tree). The issuer therefore provisions ONE secret —
|
|
207
|
+
* the seed it supplies — and the SDK derives from it:
|
|
208
|
+
* - the operation-key tree (signs capacity evidence), via `op-key/<i>`, and
|
|
209
|
+
* - THIS composite cert-signing key, via a DISTINCT domain label.
|
|
210
|
+
*
|
|
211
|
+
* The two derivations are domain-separated (different SHA3 labels) so the cert key
|
|
212
|
+
* is cryptographically independent of the operation keys — a design invariant, not
|
|
213
|
+
* a convenience. The issuer NEVER handles this key; it is reconstructed from the
|
|
214
|
+
* seed each run, so it is stable across restarts (same seed → same issuer identity)
|
|
215
|
+
* with no stored key material and no KMS in the "first certificate" path.
|
|
216
|
+
*
|
|
217
|
+
* Self-contained: the public halves are carried inside every base_certificate, so
|
|
218
|
+
* a verifier reaches INDEPENDENT_VALID without any registry lookup.
|
|
219
|
+
*
|
|
220
|
+
* (A KMS-backed IssuerKey can be injected instead of deriving — a deliberate
|
|
221
|
+
* hardening, not a requirement for issuance.)
|
|
222
|
+
*
|
|
223
|
+
* @param masterSeed 32-byte seed (Uint8Array or 64-hex string), same as the keyset.
|
|
224
|
+
* @param id the issuer key id stamped into the certificate's signer block.
|
|
225
|
+
*/
|
|
226
|
+
export function deriveIssuerKey(masterSeed, id) {
|
|
227
|
+
const seed = typeof masterSeed === "string" ? Buffer.from(masterSeed, "hex") : Buffer.from(masterSeed);
|
|
228
|
+
if (seed.length !== 32) {
|
|
229
|
+
throw new Error("issuer key master seed must be 32 bytes (64 hex chars)");
|
|
230
|
+
}
|
|
231
|
+
// Domain-separated derivations (distinct labels → independent of op-key/<i>).
|
|
232
|
+
const p256Material = createHash("sha3-256")
|
|
233
|
+
.update(seed)
|
|
234
|
+
.update(Buffer.from("issuer-cert-key/p256", "utf8"))
|
|
235
|
+
.digest();
|
|
236
|
+
const mldsaSeed = createHash("sha3-256")
|
|
237
|
+
.update(seed)
|
|
238
|
+
.update(Buffer.from("issuer-cert-key/mldsa", "utf8"))
|
|
239
|
+
.digest();
|
|
240
|
+
const p256Private = privateKeyFromScalar(scalarFromSeedMaterial(p256Material));
|
|
241
|
+
const mldsa = keygenMlDsa65(mldsaSeed);
|
|
242
|
+
return {
|
|
243
|
+
id,
|
|
244
|
+
p256Private,
|
|
245
|
+
mldsaSecret: mldsa.secretKey,
|
|
246
|
+
pub_p256_b64: publicKeyB64FromPrivate(p256Private),
|
|
247
|
+
pub_mldsa_b64: Buffer.from(mldsa.publicKey).toString("base64"),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Mint a signed CCSP/1 base certificate with a verifiable subject anchor
|
|
252
|
+
* (the issuer signs client-side). Builds the payload, composite-signs
|
|
253
|
+
* `payload_canon_digest_hex` with the issuer key, and returns the
|
|
254
|
+
* certificate plus `certificate_commitment_digest = SHA3(JCS(cert))`.
|
|
255
|
+
*
|
|
256
|
+
* The result verifies under the toolkit's Issued plane (structure → composite
|
|
257
|
+
* issuer signature → original-material).
|
|
258
|
+
*/
|
|
259
|
+
export function assembleBaseCertificate(input) {
|
|
260
|
+
return signPayload(assembleUnsignedPayload(input), input.issuerKey);
|
|
261
|
+
}
|
|
262
|
+
/** Composite-sign a finished payload into a CCSP/1 base certificate. */
|
|
263
|
+
function signPayload(payload, issuerKey) {
|
|
264
|
+
const canonDigest = payloadCanonDigestHex(payload);
|
|
265
|
+
const composite = compositeSignP256(canonDigest, {
|
|
266
|
+
p256Private: issuerKey.p256Private,
|
|
267
|
+
mldsaSecret: issuerKey.mldsaSecret,
|
|
268
|
+
});
|
|
269
|
+
const signature = {
|
|
270
|
+
role: "issuer",
|
|
271
|
+
sig_target: "payload_canon_digest_hex",
|
|
272
|
+
alg: composite.alg,
|
|
273
|
+
mode: composite.mode,
|
|
274
|
+
signatures: composite.signatures,
|
|
275
|
+
signer: {
|
|
276
|
+
id: issuerKey.id,
|
|
277
|
+
pub_p256_b64: issuerKey.pub_p256_b64,
|
|
278
|
+
pub_mldsa_b64: issuerKey.pub_mldsa_b64,
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
const base_certificate = {
|
|
282
|
+
schema: CERTIFICATE_SCHEMA,
|
|
283
|
+
payload,
|
|
284
|
+
payload_canon_digest_hex: canonDigest,
|
|
285
|
+
signatures: [signature],
|
|
286
|
+
};
|
|
287
|
+
return {
|
|
288
|
+
base_certificate,
|
|
289
|
+
certificate_commitment_digest: digestHexText(jcsCanonicalizeString(base_certificate)),
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* The composite key fingerprint of an issuer key (CCVP/1 §8.1):
|
|
294
|
+
* `SHA3-256(pub_p256_bytes || pub_mldsa_bytes)` over the decoded keys, classical
|
|
295
|
+
* first — the construction of composite-signature/1 §10. It is the value a
|
|
296
|
+
* context snapshot entry names in `pub_fingerprint_digest_hex`, and the value a
|
|
297
|
+
* certificate names in `context.snapshot_issuer_fingerprint_digest_hex` for the
|
|
298
|
+
* key that signs its snapshots.
|
|
299
|
+
*/
|
|
300
|
+
export function issuerKeyFingerprintHex(key) {
|
|
301
|
+
return digestHexBytes(Buffer.concat([
|
|
302
|
+
Buffer.from(key.pub_p256_b64, "base64"),
|
|
303
|
+
Buffer.from(key.pub_mldsa_b64, "base64"),
|
|
304
|
+
]));
|
|
305
|
+
}
|
|
306
|
+
/** CCSP/1 §7.3.1 form, which CCVP/1 §6.3 adopts for every timestamp. */
|
|
307
|
+
const CCVP_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?Z$/;
|
|
308
|
+
function assertSnapshotShape(snapshot) {
|
|
309
|
+
const fail = (what) => {
|
|
310
|
+
throw new Error(`context snapshot: ${what} (CCVP/1 §6, §7.1)`);
|
|
311
|
+
};
|
|
312
|
+
if (typeof snapshot !== "object" || snapshot === null || Array.isArray(snapshot)) {
|
|
313
|
+
fail("the snapshot must be a JSON object");
|
|
314
|
+
}
|
|
315
|
+
for (const k of ["context_set_id", "snapshot_id"]) {
|
|
316
|
+
const v = snapshot[k];
|
|
317
|
+
if (typeof v !== "string" || v.length === 0)
|
|
318
|
+
fail(`${k} must be a non-empty string`);
|
|
319
|
+
}
|
|
320
|
+
const ts = (v) => typeof v === "string" && CCVP_TIMESTAMP_RE.test(v);
|
|
321
|
+
if (!ts(snapshot.issued_at))
|
|
322
|
+
fail("issued_at must be an RFC 3339 UTC timestamp ending in Z");
|
|
323
|
+
if (!Array.isArray(snapshot.entries))
|
|
324
|
+
fail("entries must be an array");
|
|
325
|
+
snapshot.entries.forEach((e, i) => {
|
|
326
|
+
if (typeof e !== "object" || e === null || Array.isArray(e))
|
|
327
|
+
fail(`entries[${i}] must be an object`);
|
|
328
|
+
const entry = e;
|
|
329
|
+
if (typeof entry.issuer_id !== "string" || entry.issuer_id.length === 0) {
|
|
330
|
+
fail(`entries[${i}].issuer_id must be a non-empty string`);
|
|
331
|
+
}
|
|
332
|
+
if (typeof entry.pub_fingerprint_digest_hex !== "string" || !HEX64_RE.test(entry.pub_fingerprint_digest_hex)) {
|
|
333
|
+
fail(`entries[${i}].pub_fingerprint_digest_hex must be 64 lowercase hex chars`);
|
|
334
|
+
}
|
|
335
|
+
if (typeof entry.status !== "string")
|
|
336
|
+
fail(`entries[${i}].status must be a string`);
|
|
337
|
+
if (!ts(entry.valid_from))
|
|
338
|
+
fail(`entries[${i}].valid_from must be an RFC 3339 UTC timestamp`);
|
|
339
|
+
for (const k of ["valid_to", "revoked_at"]) {
|
|
340
|
+
if (k in entry && entry[k] !== null && !ts(entry[k])) {
|
|
341
|
+
fail(`entries[${i}].${k} must be null or an RFC 3339 UTC timestamp`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Mint a CCVP/1 context snapshot certificate: a CCSP/1 certificate carrying
|
|
348
|
+
* `snapshot` as `payload.snapshot` and exactly one `subject.context-snapshot/1`
|
|
349
|
+
* subject committing to it (CCVP/1 §5.1). The snapshot issuer is the key that
|
|
350
|
+
* signs it; verifiers derive it from the signature, never from the snapshot.
|
|
351
|
+
*
|
|
352
|
+
* The snapshot is checked against the CCVP/1 shape and the profile's own
|
|
353
|
+
* preconditions (no JSON number at any depth) before anything is signed. It is
|
|
354
|
+
* an ordinary Issued certificate, with no root participation reference.
|
|
355
|
+
*/
|
|
356
|
+
export function assembleContextSnapshotCertificate(input) {
|
|
357
|
+
assertSnapshotShape(input.snapshot);
|
|
358
|
+
const payload = assembleUnsignedPayload({
|
|
359
|
+
subjects: [
|
|
360
|
+
{
|
|
361
|
+
profile: "subject.context-snapshot/1",
|
|
362
|
+
material: new TextEncoder().encode(JSON.stringify(input.snapshot)),
|
|
363
|
+
},
|
|
364
|
+
],
|
|
365
|
+
nonce_hex: input.nonce_hex,
|
|
366
|
+
issued_at: input.issued_at,
|
|
367
|
+
system_id: input.system_id,
|
|
368
|
+
rules_version: input.rules_version,
|
|
369
|
+
});
|
|
370
|
+
payload.snapshot = structuredClone(input.snapshot);
|
|
371
|
+
return signPayload(payload, input.issuerKey);
|
|
372
|
+
}
|
|
373
|
+
//# sourceMappingURL=base-certificate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-certificate.js","sourceRoot":"","sources":["../../../src/artifacts/base-certificate.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAA4B,MAAM,gCAAgC,CAAC;AAC3F,OAAO,EACL,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,QAAQ,GAAG,gBAAgB,CAAC;AAClC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C,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;aACnE;SACF;QACD,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,aAAa,EAAE,KAAK,CAAC,aAAa;KACnC,CAAC,CAAC;IACH,OAAO,CAAC,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACnD,OAAO,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { HolderKeySet, type OperationKeyDisclosure } from "./holder-keyset.js";
|
|
2
|
+
/**
|
|
3
|
+
* The exact Level-1 binding the system-domain signed, with its signature.
|
|
4
|
+
* Produced during activation and passed in
|
|
5
|
+
* verbatim — the SDK never recomputes or re-signs it. Field order is the
|
|
6
|
+
* signing-bytes order and is load-bearing.
|
|
7
|
+
*/
|
|
8
|
+
export interface Level1AuthorizationBinding {
|
|
9
|
+
system_id: string;
|
|
10
|
+
rules_version: string;
|
|
11
|
+
system_root_fingerprint: string;
|
|
12
|
+
authorized_role: string;
|
|
13
|
+
authorization_issuer_kid: string;
|
|
14
|
+
valid_from: string;
|
|
15
|
+
valid_until: string;
|
|
16
|
+
holder_key_set_root: string;
|
|
17
|
+
}
|
|
18
|
+
/** One detached component signature of a composite. `encoding`/`low_s` are
|
|
19
|
+
* present only for ECDSA; omitted for ML-DSA/Ed25519. */
|
|
20
|
+
export interface ComponentSignature {
|
|
21
|
+
alg: string;
|
|
22
|
+
encoding?: string;
|
|
23
|
+
low_s?: boolean;
|
|
24
|
+
sig_b64: string;
|
|
25
|
+
}
|
|
26
|
+
/** The Level-1 signature as it appears on the wire: a PQ/T COMPOSITE,
|
|
27
|
+
* AND over all components. The SDK
|
|
28
|
+
* carries it VERBATIM from activation into the projected
|
|
29
|
+
* authorization — it never re-signs or reshapes it (the exact bytes/field order
|
|
30
|
+
* are load-bearing for the verifier's composite check). */
|
|
31
|
+
export interface CompositeSignatureWire {
|
|
32
|
+
alg: string;
|
|
33
|
+
mode: string;
|
|
34
|
+
signatures: ComponentSignature[];
|
|
35
|
+
}
|
|
36
|
+
/** The pre-signed Level-1 anchor handed to the issuer at activation.
|
|
37
|
+
* The signature is a PQ/T composite carried verbatim. */
|
|
38
|
+
export interface SignedLevel1Binding {
|
|
39
|
+
level1_binding: Level1AuthorizationBinding;
|
|
40
|
+
level1_signature: CompositeSignatureWire;
|
|
41
|
+
}
|
|
42
|
+
export interface ProjectedCommitment {
|
|
43
|
+
commitment_version: string;
|
|
44
|
+
system_id: string;
|
|
45
|
+
system_root_fingerprint: string;
|
|
46
|
+
rules_version: string;
|
|
47
|
+
authorization_pseudonym: string;
|
|
48
|
+
holder_pseudonym: string;
|
|
49
|
+
pool_pseudonym: string;
|
|
50
|
+
certificate_commitment_digest: string;
|
|
51
|
+
consumed_quantity: string;
|
|
52
|
+
/**
|
|
53
|
+
* Issuer-declared per-subject effective units (`submission-set/1`):
|
|
54
|
+
* non-collection subject → "1", collection → its `declared_cardinality`.
|
|
55
|
+
* Distinct from `consumed_quantity`, and part of the signed view.
|
|
56
|
+
*/
|
|
57
|
+
declared_effective_units: string;
|
|
58
|
+
issued_at: string;
|
|
59
|
+
expires_at: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ProjectedAuthorization {
|
|
62
|
+
system_id: string;
|
|
63
|
+
rules_version: string;
|
|
64
|
+
system_root_fingerprint: string;
|
|
65
|
+
authorized_role: string;
|
|
66
|
+
authorization_issuer_kid: string;
|
|
67
|
+
valid_from: string;
|
|
68
|
+
valid_until: string;
|
|
69
|
+
holder_key_set_root: string;
|
|
70
|
+
level1_binding: Level1AuthorizationBinding;
|
|
71
|
+
level1_signature: CompositeSignatureWire;
|
|
72
|
+
authorization_pseudonym: string;
|
|
73
|
+
holder_pseudonym: string;
|
|
74
|
+
}
|
|
75
|
+
export interface CapacityEvidence {
|
|
76
|
+
profile: string;
|
|
77
|
+
operation_salt_hex: string;
|
|
78
|
+
projected_authorization: ProjectedAuthorization;
|
|
79
|
+
projected_commitment: ProjectedCommitment;
|
|
80
|
+
operation_key: OperationKeyDisclosure;
|
|
81
|
+
commitment_signature_b64: string;
|
|
82
|
+
}
|
|
83
|
+
export declare const ZERO_DATA_PROFILE = "zero-data.unlinkable";
|
|
84
|
+
/** The stable identifiers the issuer holds privately and projects to pseudonyms. */
|
|
85
|
+
export interface StableIdentifiers {
|
|
86
|
+
holder_id: string;
|
|
87
|
+
pool_id: string;
|
|
88
|
+
authorization_id: string;
|
|
89
|
+
}
|
|
90
|
+
export interface EvidenceInputs {
|
|
91
|
+
/** The pre-signed Level-1 anchor from activation. */
|
|
92
|
+
signedLevel1: SignedLevel1Binding;
|
|
93
|
+
certificate_commitment_digest: string;
|
|
94
|
+
consumed_quantity: string;
|
|
95
|
+
/**
|
|
96
|
+
* Issuer-declared per-subject effective units (`submission-set/1`):
|
|
97
|
+
* non-collection subject → "1", collection → its declared_cardinality.
|
|
98
|
+
*/
|
|
99
|
+
declared_effective_units: string;
|
|
100
|
+
issued_at: string;
|
|
101
|
+
expires_at: string;
|
|
102
|
+
stable: StableIdentifiers;
|
|
103
|
+
/** The holder's authorized operation-key tree. Its root MUST equal the binding's. */
|
|
104
|
+
keySet: HolderKeySet;
|
|
105
|
+
/** Which leaf signs this commitment. MUST NOT be reused across commitments. */
|
|
106
|
+
leafIndex: number;
|
|
107
|
+
/** Fresh public per-operation salt. MUST be unique per operation. */
|
|
108
|
+
operationSalt: Uint8Array;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The bytes the per-operation leaf key signs: the projected commitment in its
|
|
112
|
+
* exact declared field order (insertion order, NOT JCS).
|
|
113
|
+
*/
|
|
114
|
+
export declare function projectedCommitmentSigningBytes(pc: ProjectedCommitment): Uint8Array;
|
|
115
|
+
/**
|
|
116
|
+
* The canonical evidence digest bound into `independence.proof/1`: JCS (sorted
|
|
117
|
+
* keys) + SHA3-256, lowercase hex.
|
|
118
|
+
*/
|
|
119
|
+
export declare function evidenceDigestHex(evidence: CapacityEvidence): string;
|
|
120
|
+
/**
|
|
121
|
+
* Assemble zero-data capacity evidence for one commitment: project the
|
|
122
|
+
* identifiers to operation-scoped pseudonyms, sign the projected commitment with
|
|
123
|
+
* the disclosed leaf key, and carry the pre-signed Level-1 anchor verbatim.
|
|
124
|
+
*
|
|
125
|
+
* Throws if `keySet.root` does not equal the binding's `holder_key_set_root`
|
|
126
|
+
* (the leaf membership the verifier checks would fail otherwise — fail early),
|
|
127
|
+
* or if `leafIndex` is out of range.
|
|
128
|
+
*/
|
|
129
|
+
export declare function assembleEvidence(inputs: EvidenceInputs): CapacityEvidence;
|
|
130
|
+
/** Operative routing context for one certificate. Never part of the signed
|
|
131
|
+
* evidence and never surfaced to a verifier. */
|
|
132
|
+
export interface OperativeContext {
|
|
133
|
+
holder_id: string;
|
|
134
|
+
pool_id: string;
|
|
135
|
+
}
|
|
136
|
+
/** The canonical member: exactly these two fields (submission-set/1 §7.1). Both
|
|
137
|
+
* are covered by the `submission_set_id` digest. */
|
|
138
|
+
export interface ZeroDataSubmissionSetCertificateV1 {
|
|
139
|
+
capacity_evidence: CapacityEvidence;
|
|
140
|
+
operative: OperativeContext;
|
|
141
|
+
}
|
|
142
|
+
export interface ZeroDataSubmissionSetV1 {
|
|
143
|
+
schema: string;
|
|
144
|
+
system_id: string;
|
|
145
|
+
rules_version: string;
|
|
146
|
+
system_root_fingerprint: string;
|
|
147
|
+
submission_set_id: string;
|
|
148
|
+
closure_time: string;
|
|
149
|
+
certificates: ZeroDataSubmissionSetCertificateV1[];
|
|
150
|
+
}
|
|
151
|
+
export declare const ZERO_DATA_SUBMISSION_SET_VERSION = "submission-set/1";
|
|
152
|
+
/**
|
|
153
|
+
* Maximum number of members a conforming `submission-set/1` may contain
|
|
154
|
+
* (submission-set/1). Normative, fail-closed protocol constant. The issuer
|
|
155
|
+
* SDK runs IN the client process, so this is the fail-fast, ergonomic guard: a
|
|
156
|
+
* caller who checks a count with `assertSubmissionSetWithinBound` (as the set
|
|
157
|
+
* assembler, `Certcrypt.submit()` and `CertcryptNodeClient.issue()` do) gets a
|
|
158
|
+
* typed error before any network call — it is not a security boundary (a client controls its own
|
|
159
|
+
* process). The authoritative enforcement is the node assembler and the CERTCRYPT
|
|
160
|
+
* submit endpoint, which reject an over-cardinality set fail-closed.
|
|
161
|
+
*
|
|
162
|
+
* The value is 64, pinned by the conformance contract
|
|
163
|
+
* (`fixtures/primitives/submission-set-limits`). It keeps a set of zero-data
|
|
164
|
+
* members within request sizes common transports accept (submission-set/1
|
|
165
|
+
* §8.1); per-member size is independent of subject count / collection
|
|
166
|
+
* cardinality.
|
|
167
|
+
*/
|
|
168
|
+
export declare const MAX_SUBMISSION_SET_MEMBERS = 64;
|
|
169
|
+
/** Thrown when a submission set would exceed `MAX_SUBMISSION_SET_MEMBERS`. */
|
|
170
|
+
export declare class SubmissionSetTooLargeError extends Error {
|
|
171
|
+
readonly count: number;
|
|
172
|
+
readonly max: number;
|
|
173
|
+
constructor(count: number);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Assert a member count is within the submission-set/1 cardinality bound.
|
|
177
|
+
* Fail-fast guard for any path that builds a multi-member set — a caller that
|
|
178
|
+
* groups prepared commitments, or hand-builds a `ZeroDataSubmissionSetV1`.
|
|
179
|
+
* `Certcrypt.submit()` and `CertcryptNodeClient.issue()` call it before
|
|
180
|
+
* sending, so an over-bound set is refused locally; the node and the submit
|
|
181
|
+
* endpoint refuse one independently.
|
|
182
|
+
*/
|
|
183
|
+
export declare function assertSubmissionSetWithinBound(memberCount: number): void;
|
|
184
|
+
export interface AssembleZeroDataSubmissionSetOptions {
|
|
185
|
+
rules_version: string;
|
|
186
|
+
system_root_fingerprint: string;
|
|
187
|
+
/** RFC 3339 second precision 'Z'; Date is normalized (millis must be 0). */
|
|
188
|
+
closure_time: Date | string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Assemble a single-certificate zero-data submission set from one assembled
|
|
192
|
+
* `CapacityEvidence` and its operative context. The `submission_set_id` is
|
|
193
|
+
* computed deterministically over the set without the id (JCS + SHA3).
|
|
194
|
+
*/
|
|
195
|
+
export declare function assembleZeroDataSubmissionSet(evidence: CapacityEvidence, operative: OperativeContext, opts: AssembleZeroDataSubmissionSetOptions): ZeroDataSubmissionSetV1;
|