@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,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node backend — `node:crypto`.
|
|
3
|
+
*
|
|
4
|
+
* The default wherever `node:crypto` is reachable: the CLI, the test suite and
|
|
5
|
+
* the conformance harness run on these primitives, and the Web backend is held
|
|
6
|
+
* to the same acceptance and rejection conditions by the equivalence test.
|
|
7
|
+
*/
|
|
8
|
+
import { createHash, createPublicKey, verify as cryptoVerify } from "node:crypto";
|
|
9
|
+
import { concatBytes, fromHex } from "./bytes.js";
|
|
10
|
+
// SPKI DER prefix that wraps a raw 32-byte Ed25519 public key.
|
|
11
|
+
const ED25519_SPKI_PREFIX = fromHex("302a300506032b6570032100");
|
|
12
|
+
function importEd25519PublicKey(pubKeyBytes) {
|
|
13
|
+
// SPKI DER first; a raw 32-byte key is the documented fallback.
|
|
14
|
+
try {
|
|
15
|
+
return createPublicKey({
|
|
16
|
+
key: Buffer.from(pubKeyBytes),
|
|
17
|
+
format: "der",
|
|
18
|
+
type: "spki",
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
if (pubKeyBytes.length === 32) {
|
|
23
|
+
return createPublicKey({
|
|
24
|
+
key: Buffer.from(concatBytes(ED25519_SPKI_PREFIX, pubKeyBytes)),
|
|
25
|
+
format: "der",
|
|
26
|
+
type: "spki",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`Ed25519 public key must be 32 bytes (raw) or valid SPKI DER, got ${pubKeyBytes.length} bytes`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// The P-256 AlgorithmIdentifier (id-ecPublicKey + prime256v1), constant across
|
|
33
|
+
// point encodings. Only the outer SEQUENCE length and BIT STRING length change
|
|
34
|
+
// with the point size (33B compressed / 65B uncompressed).
|
|
35
|
+
const P256_ALG_ID = fromHex("301306072a8648ce3d020106082a8648ce3d030107");
|
|
36
|
+
/** Build the SPKI DER prefix for a SEC1 point of `pointLen` bytes (33 or 65). */
|
|
37
|
+
function p256SpkiPrefix(pointLen) {
|
|
38
|
+
// BIT STRING: tag 0x03, len = pointLen + 1 (the unused-bits octet 0x00), then 0x00.
|
|
39
|
+
const bitString = new Uint8Array([0x03, pointLen + 1, 0x00]);
|
|
40
|
+
const body = concatBytes(P256_ALG_ID, bitString);
|
|
41
|
+
// Outer SEQUENCE: tag 0x30, len = body.length + pointLen.
|
|
42
|
+
return concatBytes(new Uint8Array([0x30, body.length + pointLen]), body);
|
|
43
|
+
}
|
|
44
|
+
function importP256PublicKey(pubKeyBytes) {
|
|
45
|
+
// SPKI DER first.
|
|
46
|
+
try {
|
|
47
|
+
return createPublicKey({
|
|
48
|
+
key: Buffer.from(pubKeyBytes),
|
|
49
|
+
format: "der",
|
|
50
|
+
type: "spki",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Raw SEC1 point: compressed (33B, 0x02/0x03) or uncompressed (65B, 0x04).
|
|
55
|
+
const first = pubKeyBytes[0];
|
|
56
|
+
const isCompressed = pubKeyBytes.length === 33 && (first === 0x02 || first === 0x03);
|
|
57
|
+
const isUncompressed = pubKeyBytes.length === 65 && first === 0x04;
|
|
58
|
+
if (isUncompressed || isCompressed) {
|
|
59
|
+
// node's OpenSSL decompresses a compressed point on import.
|
|
60
|
+
return createPublicKey({
|
|
61
|
+
key: Buffer.from(concatBytes(p256SpkiPrefix(pubKeyBytes.length), pubKeyBytes)),
|
|
62
|
+
format: "der",
|
|
63
|
+
type: "spki",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`ECDSA-P256 public key must be SEC1 uncompressed (65B) or SPKI DER, got ${pubKeyBytes.length} bytes`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export const nodeProvider = {
|
|
70
|
+
backend: "node",
|
|
71
|
+
sha3_256(data) {
|
|
72
|
+
return new Uint8Array(createHash("sha3-256").update(data).digest());
|
|
73
|
+
},
|
|
74
|
+
sha3_256_stream() {
|
|
75
|
+
// Same primitive as the one-shot form above, so a streamed digest and a whole-buffer
|
|
76
|
+
// digest of the same bytes are the same value by construction rather than by agreement.
|
|
77
|
+
const h = createHash("sha3-256");
|
|
78
|
+
return {
|
|
79
|
+
update: (chunk) => {
|
|
80
|
+
h.update(chunk);
|
|
81
|
+
},
|
|
82
|
+
digest: () => new Uint8Array(h.digest())
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
verifyEd25519(publicKey, message, signature) {
|
|
86
|
+
const keyObject = importEd25519PublicKey(publicKey);
|
|
87
|
+
return cryptoVerify(null, Buffer.from(message), keyObject, Buffer.from(signature));
|
|
88
|
+
},
|
|
89
|
+
verifyEcdsaP256Sha3(publicKey, message, signature) {
|
|
90
|
+
const keyObject = importP256PublicKey(publicKey);
|
|
91
|
+
// "sha3-256" — matches the reference signer's digest. "sha256" would be SHA-2 and
|
|
92
|
+
// never match; a manual prehash with a null algorithm does not interoperate.
|
|
93
|
+
return cryptoVerify("sha3-256", Buffer.from(message), { key: keyObject, dsaEncoding: "ieee-p1363" }, Buffer.from(signature));
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../../../core/crypto/provider/node.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AAElF,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAElD,+DAA+D;AAC/D,MAAM,mBAAmB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAEhE,SAAS,sBAAsB,CAAC,WAAuB;IACrD,gEAAgE;IAChE,IAAI,CAAC;QACH,OAAO,eAAe,CAAC;YACrB,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;YAC7B,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,MAAM;SACb,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,WAAW,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YAC9B,OAAO,eAAe,CAAC;gBACrB,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;gBAC/D,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,MAAM;aACb,CAAC,CAAC;QACL,CAAC;QACD,MAAM,IAAI,KAAK,CACb,oEAAoE,WAAW,CAAC,MAAM,QAAQ,CAC/F,CAAC;IACJ,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,+EAA+E;AAC/E,2DAA2D;AAC3D,MAAM,WAAW,GAAG,OAAO,CAAC,4CAA4C,CAAC,CAAC;AAE1E,iFAAiF;AACjF,SAAS,cAAc,CAAC,QAAgB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imported by `core/verify-node.ts` (and by the tests and the CLI). Keeping the
|
|
5
|
+
* `node:crypto` import behind this module — rather than inside the selector —
|
|
6
|
+
* is what lets a browser bundle exclude it entirely: nothing a browser imports
|
|
7
|
+
* ever reaches this file, so `node:crypto` never enters the module graph.
|
|
8
|
+
*/
|
|
9
|
+
import { nodeProvider } from "./node.js";
|
|
10
|
+
import "../../input/register-node-fs.js";
|
|
11
|
+
export { nodeProvider };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side-effect module that installs the Node backend.
|
|
3
|
+
*
|
|
4
|
+
* Imported by `core/verify-node.ts` (and by the tests and the CLI). Keeping the
|
|
5
|
+
* `node:crypto` import behind this module — rather than inside the selector —
|
|
6
|
+
* is what lets a browser bundle exclude it entirely: nothing a browser imports
|
|
7
|
+
* ever reaches this file, so `node:crypto` never enters the module graph.
|
|
8
|
+
*/
|
|
9
|
+
import { nodeProvider } from "./node.js";
|
|
10
|
+
import { registerNodeProvider } from "./index.js";
|
|
11
|
+
// The filesystem bridge travels with the Node backend: anything running under
|
|
12
|
+
// Node (CLI, tests, conformance harness) can read artifacts by path.
|
|
13
|
+
import "../../input/register-node-fs.js";
|
|
14
|
+
registerNodeProvider(nodeProvider);
|
|
15
|
+
export { nodeProvider };
|
|
16
|
+
//# sourceMappingURL=register-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-node.js","sourceRoot":"","sources":["../../../../core/crypto/provider/register-node.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,8EAA8E;AAC9E,qEAAqE;AACrE,OAAO,iCAAiC,CAAC;AAEzC,oBAAoB,CAAC,YAAY,CAAC,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cryptographic surface the verification core depends on.
|
|
3
|
+
*
|
|
4
|
+
* Every primitive the toolkit needs is a VERIFICATION operation: hashing, and
|
|
5
|
+
* checking a signature against a PUBLIC key. There is deliberately no signing,
|
|
6
|
+
* no key generation, and no randomness in this interface — the toolkit evaluates
|
|
7
|
+
* artifacts under public rules and holds no secrets, so a backend that could
|
|
8
|
+
* produce a signature would be a backend that exceeds the toolkit's role.
|
|
9
|
+
*
|
|
10
|
+
* Two backends implement it: `node.ts` (node:crypto, the default under Node) and
|
|
11
|
+
* `web.ts` (@noble, for browsers and any runtime without node:crypto). Both are
|
|
12
|
+
* exercised by the same conformance vectors, so the browser path is audited
|
|
13
|
+
* rather than assumed.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* An in-progress SHA3-256. Single-use: `digest()` finalizes it and the instance must not be
|
|
17
|
+
* updated again — mirroring what both backends enforce underneath.
|
|
18
|
+
*/
|
|
19
|
+
export interface Sha3Stream {
|
|
20
|
+
update(chunk: Uint8Array): void;
|
|
21
|
+
digest(): Uint8Array;
|
|
22
|
+
}
|
|
23
|
+
export interface CryptoProvider {
|
|
24
|
+
/** Which backend is active — surfaced in diagnostics, never used for logic. */
|
|
25
|
+
readonly backend: "node" | "web";
|
|
26
|
+
/** SHA3-256 over raw bytes. */
|
|
27
|
+
sha3_256(data: Uint8Array): Uint8Array;
|
|
28
|
+
/**
|
|
29
|
+
* An incremental SHA3-256, for material too large to hold in memory at once.
|
|
30
|
+
*
|
|
31
|
+
* Exists because the one-shot form forces the caller to materialize the whole input, and a
|
|
32
|
+
* browser cannot: `file.arrayBuffer()` on a multi-gigabyte file dies without a catchable
|
|
33
|
+
* error — the OS hands out virtual memory lazily, so neither the allocation nor the first
|
|
34
|
+
* write fails, and the tab is simply killed later by memory pressure. Chunked reading plus
|
|
35
|
+
* this is the only way a large file can be verified client-side at all.
|
|
36
|
+
*
|
|
37
|
+
* Both backends already support it: node's `createHash("sha3-256")` and noble's
|
|
38
|
+
* `sha3_256.create()`, verified to produce byte-identical digests to the one-shot form.
|
|
39
|
+
*
|
|
40
|
+
* ONLY valid where canonical_bytes are the input bytes — i.e. `subject.binary/1`. The text,
|
|
41
|
+
* email and JSON-object profiles canonicalize before hashing (line endings, header
|
|
42
|
+
* unfolding, JCS), and canonicalization is not chunk-local: a CRLF or a folded header can
|
|
43
|
+
* be split across a boundary, and JCS needs the parsed value. Callers must not stream those.
|
|
44
|
+
*/
|
|
45
|
+
sha3_256_stream(): Sha3Stream;
|
|
46
|
+
/**
|
|
47
|
+
* Verify an Ed25519 signature.
|
|
48
|
+
*
|
|
49
|
+
* @param publicKey raw 32-byte key, or SPKI DER
|
|
50
|
+
* @param message the exact bytes that were signed
|
|
51
|
+
* @param signature the 64-byte signature
|
|
52
|
+
* @returns true iff the signature is valid; false on any verification failure
|
|
53
|
+
* @throws only on malformed key material, never on a merely-invalid signature
|
|
54
|
+
*/
|
|
55
|
+
verifyEd25519(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Verify an ECDSA P-256 signature, the classical component of
|
|
58
|
+
* `certcrypt-composite-p256-mldsa65-v1`.
|
|
59
|
+
*
|
|
60
|
+
* The digest is **SHA3-256**, not SHA-2 — CERTCRYPT's stack-wide hash, and
|
|
61
|
+
* ECDSA is hash-agnostic. A backend that quietly used SHA-256 here would
|
|
62
|
+
* reject every valid signature.
|
|
63
|
+
*
|
|
64
|
+
* The backend hashes `message` itself rather than accepting a digest: node's
|
|
65
|
+
* prehash path (null algorithm) reduces the digest differently from the
|
|
66
|
+
* reference signer and does not interoperate.
|
|
67
|
+
*
|
|
68
|
+
* Signature form is `raw-rs-64` (IEEE P1363 r||s). Low-s enforcement is NOT a
|
|
69
|
+
* backend concern — the caller gates it before reaching here, so the rule is
|
|
70
|
+
* applied identically on every runtime.
|
|
71
|
+
*
|
|
72
|
+
* @param publicKey SEC1 compressed (33B) / uncompressed (65B), or SPKI DER
|
|
73
|
+
* @param message the exact message bytes that were signed
|
|
74
|
+
* @param signature 64-byte r||s
|
|
75
|
+
*/
|
|
76
|
+
verifyEcdsaP256Sha3(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
|
|
77
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cryptographic surface the verification core depends on.
|
|
3
|
+
*
|
|
4
|
+
* Every primitive the toolkit needs is a VERIFICATION operation: hashing, and
|
|
5
|
+
* checking a signature against a PUBLIC key. There is deliberately no signing,
|
|
6
|
+
* no key generation, and no randomness in this interface — the toolkit evaluates
|
|
7
|
+
* artifacts under public rules and holds no secrets, so a backend that could
|
|
8
|
+
* produce a signature would be a backend that exceeds the toolkit's role.
|
|
9
|
+
*
|
|
10
|
+
* Two backends implement it: `node.ts` (node:crypto, the default under Node) and
|
|
11
|
+
* `web.ts` (@noble, for browsers and any runtime without node:crypto). Both are
|
|
12
|
+
* exercised by the same conformance vectors, so the browser path is audited
|
|
13
|
+
* rather than assumed.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../core/crypto/provider/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web backend — `@noble/hashes` + `@noble/curves`.
|
|
3
|
+
*
|
|
4
|
+
* For runtimes without `node:crypto`: browsers, Deno, edge workers. The reason
|
|
5
|
+
* this exists is not portability for its own sake — it is that computing an
|
|
6
|
+
* artifact's commitment requires the ORIGINAL MATERIAL, and sending that to a
|
|
7
|
+
* server would transmit exactly the private content the protocol is designed
|
|
8
|
+
* never to require. A verifier that runs in the browser keeps the material on
|
|
9
|
+
* the user's machine.
|
|
10
|
+
*
|
|
11
|
+
* WebCrypto is not sufficient here: it has no SHA-3 at all, and SHA3-256 is the
|
|
12
|
+
* digest under every commitment in the spec. Hence @noble, which the toolkit
|
|
13
|
+
* already depends on for ML-DSA-65.
|
|
14
|
+
*
|
|
15
|
+
* Equivalence with the Node backend is not assumed — `provider.equivalence.test.ts`
|
|
16
|
+
* asserts it primitive by primitive, and the conformance suite runs against both.
|
|
17
|
+
*/
|
|
18
|
+
import { sha3_256 as nobleSha3_256 } from "@noble/hashes/sha3.js";
|
|
19
|
+
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
20
|
+
import { p256 } from "@noble/curves/nist.js";
|
|
21
|
+
import { ecdsa } from "@noble/curves/abstract/weierstrass.js";
|
|
22
|
+
/**
|
|
23
|
+
* P-256 with SHA3-256 as the ECDSA hash.
|
|
24
|
+
*
|
|
25
|
+
* noble's stock `p256` is bound to SHA-256, and its API gives no way to verify
|
|
26
|
+
* a signature over a foreign digest: passing a pre-computed hash as the message
|
|
27
|
+
* makes it hash AGAIN, so a valid signature is rejected. Rebuilding the curve
|
|
28
|
+
* over `sha3_256` is what makes `prehash: true` apply the right digest — and it
|
|
29
|
+
* is what interoperates with node's `verify("sha3-256", …)` and the reference signer,
|
|
30
|
+
* verified in both directions by `provider.equivalence.test.ts`.
|
|
31
|
+
*/
|
|
32
|
+
const p256Sha3 = ecdsa(p256.Point, nobleSha3_256);
|
|
33
|
+
/**
|
|
34
|
+
* Ed25519 keys arrive raw (32 bytes) or SPKI DER (44 bytes, the 12-byte prefix
|
|
35
|
+
* then the key). noble takes the raw point, so DER is unwrapped by length —
|
|
36
|
+
* the prefix is fixed for Ed25519, so there is nothing to parse.
|
|
37
|
+
*/
|
|
38
|
+
function ed25519RawKey(publicKey) {
|
|
39
|
+
if (publicKey.length === 32)
|
|
40
|
+
return publicKey;
|
|
41
|
+
if (publicKey.length === 44)
|
|
42
|
+
return publicKey.subarray(12);
|
|
43
|
+
throw new Error(`Ed25519 public key must be 32 bytes (raw) or valid SPKI DER, got ${publicKey.length} bytes`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* P-256 keys arrive as a raw SEC1 point — uncompressed (65B, 0x04) or compressed
|
|
47
|
+
* (33B, 0x02/0x03) — or wrapped in SPKI DER. noble accepts either point form
|
|
48
|
+
* directly and decompresses internally, so DER is unwrapped by taking the
|
|
49
|
+
* trailing point: the AlgorithmIdentifier prefix is fixed for P-256, and the
|
|
50
|
+
* point length is what varies (91 = 26 + 65 uncompressed, 59 = 26 + 33 compressed).
|
|
51
|
+
*/
|
|
52
|
+
function p256RawKey(publicKey) {
|
|
53
|
+
const first = publicKey[0];
|
|
54
|
+
if (publicKey.length === 65 && first === 0x04)
|
|
55
|
+
return publicKey;
|
|
56
|
+
if (publicKey.length === 33 && (first === 0x02 || first === 0x03)) {
|
|
57
|
+
return publicKey;
|
|
58
|
+
}
|
|
59
|
+
if (publicKey.length === 91) {
|
|
60
|
+
const point = publicKey.subarray(publicKey.length - 65);
|
|
61
|
+
if (point[0] === 0x04)
|
|
62
|
+
return point;
|
|
63
|
+
}
|
|
64
|
+
if (publicKey.length === 59) {
|
|
65
|
+
const point = publicKey.subarray(publicKey.length - 33);
|
|
66
|
+
if (point[0] === 0x02 || point[0] === 0x03)
|
|
67
|
+
return point;
|
|
68
|
+
}
|
|
69
|
+
throw new Error(`ECDSA-P256 public key must be SEC1 uncompressed (65B) or SPKI DER, got ${publicKey.length} bytes`);
|
|
70
|
+
}
|
|
71
|
+
export const webProvider = {
|
|
72
|
+
backend: "web",
|
|
73
|
+
sha3_256(data) {
|
|
74
|
+
return nobleSha3_256(data);
|
|
75
|
+
},
|
|
76
|
+
sha3_256_stream() {
|
|
77
|
+
// noble's `create()` runs the same permutation as the one-shot call above, so a streamed
|
|
78
|
+
// digest and a whole-buffer digest of the same bytes are equal by construction; the
|
|
79
|
+
// equivalence test pins it against node's backend as well.
|
|
80
|
+
const h = nobleSha3_256.create();
|
|
81
|
+
return {
|
|
82
|
+
update: (chunk) => {
|
|
83
|
+
h.update(chunk);
|
|
84
|
+
},
|
|
85
|
+
digest: () => new Uint8Array(h.digest())
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
verifyEd25519(publicKey, message, signature) {
|
|
89
|
+
const key = ed25519RawKey(publicKey);
|
|
90
|
+
// A malformed signature must be a false verdict, not a throw — the Node
|
|
91
|
+
// backend returns false for these, and the two must agree.
|
|
92
|
+
try {
|
|
93
|
+
return ed25519.verify(signature, message, key);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
verifyEcdsaP256Sha3(publicKey, message, signature) {
|
|
100
|
+
const key = p256RawKey(publicKey);
|
|
101
|
+
try {
|
|
102
|
+
// `lowS: false` is REQUIRED for parity, not a relaxation. noble rejects
|
|
103
|
+
// high-s by default while node:crypto does not, so leaving the default on
|
|
104
|
+
// would make this backend reject signatures the Node backend accepts —
|
|
105
|
+
// half of all signatures, since s is high roughly half the time.
|
|
106
|
+
//
|
|
107
|
+
// The low-s rule is still enforced, and more visibly: `ecdsa-p256.ts`
|
|
108
|
+
// gates it before calling any backend, so the normative anti-malleability
|
|
109
|
+
// check lives in ONE place and applies identically on every runtime.
|
|
110
|
+
// Enforcing it here as well would hide the rule inside a dependency's
|
|
111
|
+
// default.
|
|
112
|
+
return p256Sha3.verify(signature, message, key, {
|
|
113
|
+
prehash: true,
|
|
114
|
+
lowS: false,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../../../core/crypto/provider/web.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,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C1E,qEAAqE;YACrE,sEAAsE;YACtE,WAAW;YACX,OAAO,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE;gBAC9C,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,KAAK;aACZ,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation-scoped pseudonyms — byte-for-byte with the reference producer, as
|
|
3
|
+
* pinned by the conformance `pseudonym` vectors.
|
|
4
|
+
*
|
|
5
|
+
* pseudonym(field) = SHA3-256( frame(operation_salt) || frame(domain_tag) || frame(stable_id) )
|
|
6
|
+
*
|
|
7
|
+
* Each field is absorbed with an 8-byte big-endian length prefix (framing) so
|
|
8
|
+
* field boundaries are unambiguous — without this, ("ab","c") and ("a","bc")
|
|
9
|
+
* would collide. 32-byte output, lowercase hex.
|
|
10
|
+
*
|
|
11
|
+
* Hash: SHA3-256 (FIPS 202 fixed-output), not SHAKE-256. The output is a fixed
|
|
12
|
+
* 32 bytes, so the XOF buys nothing and carries a domain-prefix hazard; SHA3-256
|
|
13
|
+
* is the conventional fixed-length choice and aligns with CCCP/1.
|
|
14
|
+
*
|
|
15
|
+
* Parity is pinned by the conformance vectors at
|
|
16
|
+
* `certcrypt-conformance/fixtures/primitives/pseudonym/vectors.json`.
|
|
17
|
+
*/
|
|
18
|
+
export type PseudonymDomain = "holder" | "pool" | "authorization";
|
|
19
|
+
/**
|
|
20
|
+
* Derive an operation-scoped pseudonym. `operationSalt` is the public
|
|
21
|
+
* per-operation salt carried in the package; `domain` separates namespaces;
|
|
22
|
+
* `stableId` is the identifier being projected (it never appears in the
|
|
23
|
+
* capacity evidence; only its pseudonym does).
|
|
24
|
+
*/
|
|
25
|
+
export declare function derivePseudonym(operationSalt: Uint8Array, domain: PseudonymDomain, stableId: string): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation-scoped pseudonyms — byte-for-byte with the reference producer, as
|
|
3
|
+
* pinned by the conformance `pseudonym` vectors.
|
|
4
|
+
*
|
|
5
|
+
* pseudonym(field) = SHA3-256( frame(operation_salt) || frame(domain_tag) || frame(stable_id) )
|
|
6
|
+
*
|
|
7
|
+
* Each field is absorbed with an 8-byte big-endian length prefix (framing) so
|
|
8
|
+
* field boundaries are unambiguous — without this, ("ab","c") and ("a","bc")
|
|
9
|
+
* would collide. 32-byte output, lowercase hex.
|
|
10
|
+
*
|
|
11
|
+
* Hash: SHA3-256 (FIPS 202 fixed-output), not SHAKE-256. The output is a fixed
|
|
12
|
+
* 32 bytes, so the XOF buys nothing and carries a domain-prefix hazard; SHA3-256
|
|
13
|
+
* is the conventional fixed-length choice and aligns with CCCP/1.
|
|
14
|
+
*
|
|
15
|
+
* Parity is pinned by the conformance vectors at
|
|
16
|
+
* `certcrypt-conformance/fixtures/primitives/pseudonym/vectors.json`.
|
|
17
|
+
*/
|
|
18
|
+
import { digestHexBytes } from "./digest.js";
|
|
19
|
+
import { concatBytes, utf8Bytes } from "./provider/bytes.js";
|
|
20
|
+
/** Absorb a field with an 8-byte big-endian length prefix. */
|
|
21
|
+
function frame(field) {
|
|
22
|
+
const len = new Uint8Array(8);
|
|
23
|
+
new DataView(len.buffer).setBigUint64(0, BigInt(field.length), false);
|
|
24
|
+
return concatBytes(len, field);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Derive an operation-scoped pseudonym. `operationSalt` is the public
|
|
28
|
+
* per-operation salt carried in the package; `domain` separates namespaces;
|
|
29
|
+
* `stableId` is the identifier being projected (it never appears in the
|
|
30
|
+
* capacity evidence; only its pseudonym does).
|
|
31
|
+
*/
|
|
32
|
+
export function derivePseudonym(operationSalt, domain, stableId) {
|
|
33
|
+
// One absorb over the concatenated framed fields — identical bytes, and
|
|
34
|
+
// therefore an identical digest, to the streaming update() form.
|
|
35
|
+
return digestHexBytes(concatBytes(frame(operationSalt), frame(utf8Bytes(domain)), frame(utf8Bytes(stableId))));
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=pseudonym.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pseudonym.js","sourceRoot":"","sources":["../../../core/crypto/pseudonym.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAI7D,8DAA8D;AAC9D,SAAS,KAAK,CAAC,KAAiB;IAC9B,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;IACtE,OAAO,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,aAAyB,EACzB,MAAuB,EACvB,QAAgB;IAEhB,wEAAwE;IACxE,iEAAiE;IACjE,OAAO,cAAc,CACnB,WAAW,CACT,KAAK,CAAC,aAAa,CAAC,EACpB,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EACxB,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAC3B,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 declare class SubjectPreconditionError extends Error {
|
|
23
|
+
readonly profile: string;
|
|
24
|
+
constructor(profile: string, detail: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* subject.collection/1: exactly four members — `commitment_scheme`, `root`,
|
|
28
|
+
* `declared_cardinality` and the `leaves[]` array, whose entries each declare their
|
|
29
|
+
* own `profile` and `commitment_digest_hex`. Also checks the commitment-scheme-specific
|
|
30
|
+
* `root` shape, the `declared_cardinality` grammar, and that the cardinality agrees
|
|
31
|
+
* with the number of leaves.
|
|
32
|
+
*/
|
|
33
|
+
export declare function assertCollectionPrecondition(value: unknown): void;
|
|
34
|
+
/** Profiles an AI-decision part may declare. */
|
|
35
|
+
export declare const AI_DECISION_IO_PROFILES: readonly string[];
|
|
36
|
+
/**
|
|
37
|
+
* subject.ai-decision/1: exact record and part shapes, bounded flat parameters,
|
|
38
|
+
* string-only values, part ids unique within the record, and a Gregorian UTC timestamp.
|
|
39
|
+
*/
|
|
40
|
+
export declare function assertAiDecisionPrecondition(value: unknown): void;
|
|
41
|
+
/**
|
|
42
|
+
* subject.context-snapshot/1: the only precondition this profile fixes at
|
|
43
|
+
* the canonicalization boundary is that the value is a JSON object with no JSON
|
|
44
|
+
* number at any depth (booleans and nulls are permitted). It does not fix a member set — the snapshot
|
|
45
|
+
* shape is governed by the higher-layer protocol (CCVP/1), not this profile.
|
|
46
|
+
*/
|
|
47
|
+
export declare function assertContextSnapshotPrecondition(value: unknown): void;
|