@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.

Files changed (71) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/LICENSE +178 -0
  3. package/README.md +557 -2
  4. package/SECURITY.md +55 -0
  5. package/dist/src/artifacts/base-certificate.d.ts +336 -0
  6. package/dist/src/artifacts/base-certificate.js +373 -0
  7. package/dist/src/artifacts/base-certificate.js.map +1 -0
  8. package/dist/src/artifacts/capacity-evidence.d.ts +195 -0
  9. package/dist/src/artifacts/capacity-evidence.js +202 -0
  10. package/dist/src/artifacts/capacity-evidence.js.map +1 -0
  11. package/dist/src/artifacts/commitment-inclusion.d.ts +23 -0
  12. package/dist/src/artifacts/commitment-inclusion.js +91 -0
  13. package/dist/src/artifacts/commitment-inclusion.js.map +1 -0
  14. package/dist/src/artifacts/holder-keyset.d.ts +67 -0
  15. package/dist/src/artifacts/holder-keyset.js +149 -0
  16. package/dist/src/artifacts/holder-keyset.js.map +1 -0
  17. package/dist/src/artifacts/rfc3339.d.ts +9 -0
  18. package/dist/src/artifacts/rfc3339.js +39 -0
  19. package/dist/src/artifacts/rfc3339.js.map +1 -0
  20. package/dist/src/client.d.ts +552 -0
  21. package/dist/src/client.js +1347 -0
  22. package/dist/src/client.js.map +1 -0
  23. package/dist/src/crypto/ai-decision.d.ts +73 -0
  24. package/dist/src/crypto/ai-decision.js +94 -0
  25. package/dist/src/crypto/ai-decision.js.map +1 -0
  26. package/dist/src/crypto/canonical-subject.d.ts +33 -0
  27. package/dist/src/crypto/canonical-subject.js +240 -0
  28. package/dist/src/crypto/canonical-subject.js.map +1 -0
  29. package/dist/src/crypto/collection-merkle.d.ts +58 -0
  30. package/dist/src/crypto/collection-merkle.js +164 -0
  31. package/dist/src/crypto/collection-merkle.js.map +1 -0
  32. package/dist/src/crypto/composite.d.ts +53 -0
  33. package/dist/src/crypto/composite.js +69 -0
  34. package/dist/src/crypto/composite.js.map +1 -0
  35. package/dist/src/crypto/digest.d.ts +3 -0
  36. package/dist/src/crypto/digest.js +31 -0
  37. package/dist/src/crypto/digest.js.map +1 -0
  38. package/dist/src/crypto/ecdsa-p256.d.ts +79 -0
  39. package/dist/src/crypto/ecdsa-p256.js +277 -0
  40. package/dist/src/crypto/ecdsa-p256.js.map +1 -0
  41. package/dist/src/crypto/jcs.d.ts +13 -0
  42. package/dist/src/crypto/jcs.js +65 -0
  43. package/dist/src/crypto/jcs.js.map +1 -0
  44. package/dist/src/crypto/merkle.d.ts +18 -0
  45. package/dist/src/crypto/merkle.js +150 -0
  46. package/dist/src/crypto/merkle.js.map +1 -0
  47. package/dist/src/crypto/ml-dsa.d.ts +28 -0
  48. package/dist/src/crypto/ml-dsa.js +60 -0
  49. package/dist/src/crypto/ml-dsa.js.map +1 -0
  50. package/dist/src/crypto/pseudonym.d.ts +8 -0
  51. package/dist/src/crypto/pseudonym.js +50 -0
  52. package/dist/src/crypto/pseudonym.js.map +1 -0
  53. package/dist/src/crypto/strict-json.d.ts +25 -0
  54. package/dist/src/crypto/strict-json.js +180 -0
  55. package/dist/src/crypto/strict-json.js.map +1 -0
  56. package/dist/src/crypto/subject-json-preconditions.d.ts +46 -0
  57. package/dist/src/crypto/subject-json-preconditions.js +381 -0
  58. package/dist/src/crypto/subject-json-preconditions.js.map +1 -0
  59. package/dist/src/index.d.ts +18 -0
  60. package/dist/src/index.js +80 -0
  61. package/dist/src/index.js.map +1 -0
  62. package/dist/src/issuer.d.ts +668 -0
  63. package/dist/src/issuer.js +1066 -0
  64. package/dist/src/issuer.js.map +1 -0
  65. package/dist/src/retry.d.ts +67 -0
  66. package/dist/src/retry.js +78 -0
  67. package/dist/src/retry.js.map +1 -0
  68. package/dist/src/types.d.ts +297 -0
  69. package/dist/src/types.js +15 -0
  70. package/dist/src/types.js.map +1 -0
  71. package/package.json +62 -4
@@ -0,0 +1,164 @@
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
+ * `collection.merkle-sha3-256/1` — issuer-side mirror of
16
+ * `certcrypt-verifier-toolkit-js/core/crypto/collection-merkle.ts`, ported
17
+ * byte-for-byte so the SDK builds the exact same root and leaf hashes the verifier
18
+ * recomputes. Pinned against the shared conformance vectors
19
+ * (`collection-merkle.test.ts`): a one-byte divergence fails that test.
20
+ *
21
+ * DISTINCT from `merkle.ts` in this same directory, which implements
22
+ * `holder-keyset.merkle-sha3-256/1` (0x00/0x01 prefixes, no salt, different
23
+ * preimage). The two are not interchangeable and produce different roots.
24
+ *
25
+ * Construction:
26
+ * leaf_preimage = utf8("CERTCRYPT:collection.merkle-sha3-256/1:leaf")
27
+ * || u64be(len(collection_salt)) || collection_salt
28
+ * || u64be(len(leaf_profile)) || leaf_profile
29
+ * || u64be(len(leaf_canonical)) || leaf_canonical
30
+ * node_preimage = utf8("CERTCRYPT:collection.merkle-sha3-256/1:node") || L || R
31
+ * root: one leaf → its own hash; else pair left-to-right and promote a lone
32
+ * right-edge hash unchanged until one remains. Empty tree is invalid.
33
+ *
34
+ * The salt is what makes a collection root operation-specific: under
35
+ * `subject.collection/1` §8 it is the certificate anchor's `nonce_hex` as ASCII
36
+ * bytes, so the same leaf set yields a different root in every operation. That is
37
+ * the property that lets leaf hashes travel in a `verification_package` without
38
+ * becoming stable global identifiers of content.
39
+ */
40
+ import { digestHexBytes } from "./digest.js";
41
+ import { canonicalBytesForSubject } from "./canonical-subject.js";
42
+ export const COLLECTION_MERKLE_SCHEME = "collection.merkle-sha3-256/1";
43
+ const LEAF_TAG = new TextEncoder().encode("CERTCRYPT:collection.merkle-sha3-256/1:leaf");
44
+ const NODE_TAG = new TextEncoder().encode("CERTCRYPT:collection.merkle-sha3-256/1:node");
45
+ function u64be(n) {
46
+ const out = new Uint8Array(8);
47
+ let v = BigInt(n);
48
+ for (let i = 7; i >= 0; i--) {
49
+ out[i] = Number(v & 0xffn);
50
+ v >>= 8n;
51
+ }
52
+ return out;
53
+ }
54
+ function concat(...parts) {
55
+ const total = parts.reduce((n, p) => n + p.length, 0);
56
+ const out = new Uint8Array(total);
57
+ let off = 0;
58
+ for (const p of parts) {
59
+ out.set(p, off);
60
+ off += p.length;
61
+ }
62
+ return out;
63
+ }
64
+ function hexToBytes(hex) {
65
+ if (hex.length % 2 !== 0)
66
+ throw new Error("hex length must be even");
67
+ const out = new Uint8Array(hex.length / 2);
68
+ for (let i = 0; i < hex.length; i += 2) {
69
+ out[i / 2] = parseInt(hex.substring(i, i + 2), 16);
70
+ }
71
+ return out;
72
+ }
73
+ /**
74
+ * `leaf_hash` for one leaf, given the collection salt, the declared `leaf_profile`
75
+ * and the leaf's `canonical_bytes`. Lowercase hex.
76
+ *
77
+ * An empty salt throws: the scheme requires one, and accepting none would silently
78
+ * reproduce the unsalted construction.
79
+ */
80
+ export function collectionLeafHash(collectionSalt, leafProfile, leafCanonicalBytes) {
81
+ if (collectionSalt.length === 0) {
82
+ throw new Error("collection.merkle-sha3-256/1: a non-empty collection salt is required");
83
+ }
84
+ const profileBytes = new TextEncoder().encode(leafProfile);
85
+ return digestHexBytes(concat(LEAF_TAG, u64be(collectionSalt.length), collectionSalt, u64be(profileBytes.length), profileBytes, u64be(leafCanonicalBytes.length), leafCanonicalBytes));
86
+ }
87
+ /** `node_hash` for two child hashes (lowercase hex in, lowercase hex out). */
88
+ export function collectionNodeHash(leftHex, rightHex) {
89
+ return digestHexBytes(concat(NODE_TAG, hexToBytes(leftHex), hexToBytes(rightHex)));
90
+ }
91
+ /** One fold step: pair left-to-right, promote a lone right edge unchanged. */
92
+ function foldOnce(level) {
93
+ const out = [];
94
+ for (let i = 0; i < level.length; i += 2) {
95
+ out.push(i + 1 < level.length ? collectionNodeHash(level[i], level[i + 1]) : level[i]);
96
+ }
97
+ return out;
98
+ }
99
+ /** The collection root over an ordered list of leaf hashes. */
100
+ export function collectionMerkleRoot(leafHashes) {
101
+ if (leafHashes.length === 0) {
102
+ throw new Error("collection.merkle-sha3-256/1: empty tree is invalid");
103
+ }
104
+ let level = leafHashes;
105
+ while (level.length > 1)
106
+ level = foldOnce(level);
107
+ return level[0];
108
+ }
109
+ /**
110
+ * Sibling path for one leaf, bottom-up.
111
+ *
112
+ * A node that is the lone right edge of an odd level is promoted unchanged and
113
+ * therefore contributes NO sibling — the case a careless implementation gets wrong,
114
+ * and the reason the conformance vectors include odd cardinalities.
115
+ */
116
+ export function collectionInclusionProof(leafHashes, leafIndex) {
117
+ if (leafIndex < 0 || leafIndex >= leafHashes.length) {
118
+ throw new Error(`leaf index ${leafIndex} out of range`);
119
+ }
120
+ const siblings = [];
121
+ let level = leafHashes;
122
+ let idx = leafIndex;
123
+ while (level.length > 1) {
124
+ const lone = idx === level.length - 1 && level.length % 2 === 1;
125
+ if (!lone)
126
+ siblings.push(idx % 2 === 0 ? level[idx + 1] : level[idx - 1]);
127
+ level = foldOnce(level);
128
+ idx = Math.floor(idx / 2);
129
+ }
130
+ return siblings;
131
+ }
132
+ /**
133
+ * Build a collection subject from its ordered leaves.
134
+ *
135
+ * This is the operation an issuer cannot do before emitting: the salt is the
136
+ * certificate's own nonce, so the root is only computable once that nonce exists.
137
+ * The SDK therefore builds the collection during `prepare()` (and so `issue()`),
138
+ * not before it.
139
+ *
140
+ * Each leaf carries its OWN profile — a collection may mix texts, binaries and
141
+ * emails (`subject.collection/1` §7.4). Every leaf is canonicalized under its own
142
+ * profile before hashing, exactly as the verifier does when it recomputes the root
143
+ * from delivered material; that is why the profile must travel signed inside the
144
+ * descriptor rather than alongside it.
145
+ */
146
+ export function buildCollection(collectionSalt, leaves) {
147
+ if (leaves.length === 0) {
148
+ throw new Error("subject.collection/1: a collection needs at least one leaf");
149
+ }
150
+ const leafHashes = leaves.map((leaf) => collectionLeafHash(collectionSalt, leaf.profile, canonicalBytesForSubject(leaf.profile, leaf.bytes)));
151
+ return {
152
+ descriptor: {
153
+ commitment_scheme: COLLECTION_MERKLE_SCHEME,
154
+ root: collectionMerkleRoot(leafHashes),
155
+ declared_cardinality: String(leaves.length),
156
+ leaves: leaves.map((leaf, i) => ({
157
+ profile: leaf.profile,
158
+ commitment_digest_hex: leafHashes[i]
159
+ }))
160
+ },
161
+ leafHashes
162
+ };
163
+ }
164
+ //# sourceMappingURL=collection-merkle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection-merkle.js","sourceRoot":"","sources":["../../../src/crypto/collection-merkle.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;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,MAAM,CAAC,MAAM,wBAAwB,GAAG,8BAA8B,CAAC;AAEvE,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CACvC,6CAA6C,CAC9C,CAAC;AACF,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CACvC,6CAA6C,CAC9C,CAAC;AAEF,SAAS,KAAK,CAAC,CAAS;IACtB,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,C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;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AA2BD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe,CAC7B,cAA0B,EAC1B,MAA6B;IAE7B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAChF,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACrC,kBAAkB,CAChB,cAAc,EACd,IAAI,CAAC,OAAO,EACZ,wBAAwB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CACnD,CACF,CAAC;IACF,OAAO;QACL,UAAU,EAAE;YACV,iBAAiB,EAAE,wBAAwB;YAC3C,IAAI,EAAE,oBAAoB,CAAC,UAAU,CAAC;YACtC,oBAAoB,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;YAC3C,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC/B,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,qBAAqB,EAAE,UAAU,CAAC,CAAC,CAAC;aACrC,CAAC,CAAC;SACJ;QACD,UAAU;KACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Composite signature signing (CERTCRYPT Composite Signature Profile),
3
+ * issuer side. Signer counterpart to
4
+ * `certcrypt-verifier-toolkit-js/core/crypto/composite.ts`.
5
+ *
6
+ * Every component signs the SAME domain-separated message M', and the composite
7
+ * verifies iff ALL components verify (AND). Binding the profile id into M' stops
8
+ * a component being lifted out and replayed under another profile.
9
+ *
10
+ * M' = ASCII("CERTCRYPT-Composite-Signature-v1") || 0x00
11
+ * || ASCII(composite_alg_id) || 0x00 || ASCII(payload_canon_digest_hex)
12
+ *
13
+ * Canonical profile `certcrypt-composite-p256-mldsa65-v1`: ECDSA-P256-SHA3-256
14
+ * (classical, FIRST — order is load-bearing) + ML-DSA-65 (PQC). The ECDSA
15
+ * component signs SHA3-256(M') with an RFC 6979 deterministic nonce, so its bytes
16
+ * are pinned too (`ecdsa-p256-deterministic`); ML-DSA signs M' directly, empty
17
+ * context, no pre-hash. M' bytes are load-bearing cross-language.
18
+ */
19
+ import { type KeyObject } from "node:crypto";
20
+ export declare const COMPOSITE_DOMAIN_PREFIX = "CERTCRYPT-Composite-Signature-v1";
21
+ export declare const PROFILE_P256_MLDSA65 = "certcrypt-composite-p256-mldsa65-v1";
22
+ export declare const ALG_ECDSA_P256 = "ECDSA-P256-SHA3-256";
23
+ export declare const ALG_MLDSA65 = "ML-DSA-65";
24
+ /** One detached component signature (a `signatures[]` entry). */
25
+ export interface ComponentSignature {
26
+ alg: string;
27
+ encoding?: string;
28
+ low_s?: boolean;
29
+ sig_b64: string;
30
+ }
31
+ /** The composite signature wire object. */
32
+ export interface CompositeSignatureWire {
33
+ alg: string;
34
+ mode: string;
35
+ signatures: ComponentSignature[];
36
+ }
37
+ /** The issuer's composite signing key (P-256 classical + ML-DSA-65 PQC). */
38
+ export interface CompositeSigningKey {
39
+ p256Private: KeyObject;
40
+ mldsaSecret: Uint8Array;
41
+ }
42
+ /**
43
+ * Build the domain-separated message M' every component signs. Mirrors
44
+ * `compositeMPrime` in the toolkit exactly.
45
+ */
46
+ export declare function compositeMPrime(compositeAlgId: string, payloadCanonDigestHex: string): Uint8Array;
47
+ /**
48
+ * Produce a composite signature over `payloadCanonDigestHex` under the canonical
49
+ * P-256+ML-DSA-65 profile. Components are ordered classical-first (load-bearing).
50
+ * The ECDSA component carries `encoding:"raw-rs-64"` + `low_s:true`; ML-DSA
51
+ * carries neither.
52
+ */
53
+ export declare function compositeSignP256(payloadCanonDigestHex: string, key: CompositeSigningKey): CompositeSignatureWire;
@@ -0,0 +1,69 @@
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
+ import { signEcdsaP256Raw } from "./ecdsa-p256.js";
15
+ import { signMlDsa65 } from "./ml-dsa.js";
16
+ export const COMPOSITE_DOMAIN_PREFIX = "CERTCRYPT-Composite-Signature-v1";
17
+ export const PROFILE_P256_MLDSA65 = "certcrypt-composite-p256-mldsa65-v1";
18
+ export const ALG_ECDSA_P256 = "ECDSA-P256-SHA3-256";
19
+ export const ALG_MLDSA65 = "ML-DSA-65";
20
+ /**
21
+ * Build the domain-separated message M' every component signs. Mirrors
22
+ * `compositeMPrime` in the toolkit exactly.
23
+ */
24
+ export function compositeMPrime(compositeAlgId, payloadCanonDigestHex) {
25
+ const enc = new TextEncoder();
26
+ const prefix = enc.encode(COMPOSITE_DOMAIN_PREFIX);
27
+ const alg = enc.encode(compositeAlgId);
28
+ const digest = enc.encode(payloadCanonDigestHex);
29
+ const out = new Uint8Array(prefix.length + 1 + alg.length + 1 + digest.length);
30
+ let o = 0;
31
+ out.set(prefix, o);
32
+ o += prefix.length;
33
+ out[o++] = 0x00;
34
+ out.set(alg, o);
35
+ o += alg.length;
36
+ out[o++] = 0x00;
37
+ out.set(digest, o);
38
+ return out;
39
+ }
40
+ /**
41
+ * Produce a composite signature over `payloadCanonDigestHex` under the canonical
42
+ * P-256+ML-DSA-65 profile. Components are ordered classical-first (load-bearing).
43
+ * The ECDSA component carries `encoding:"raw-rs-64"` + `low_s:true`; ML-DSA
44
+ * carries neither.
45
+ */
46
+ export function compositeSignP256(payloadCanonDigestHex, key) {
47
+ const mPrime = compositeMPrime(PROFILE_P256_MLDSA65, payloadCanonDigestHex);
48
+ // ECDSA-P256 over SHA3-256(M'), RFC 6979 deterministic: same key + M', same bytes.
49
+ const ecdsaSig = signEcdsaP256Raw(key.p256Private, mPrime);
50
+ // ML-DSA-65 over M' directly (empty context, no pre-hash).
51
+ const mldsaSig = signMlDsa65(key.mldsaSecret, mPrime);
52
+ return {
53
+ alg: PROFILE_P256_MLDSA65,
54
+ mode: "AND",
55
+ signatures: [
56
+ {
57
+ alg: ALG_ECDSA_P256,
58
+ encoding: "raw-rs-64",
59
+ low_s: true,
60
+ sig_b64: Buffer.from(ecdsaSig).toString("base64"),
61
+ },
62
+ {
63
+ alg: ALG_MLDSA65,
64
+ sig_b64: Buffer.from(mldsaSig).toString("base64"),
65
+ },
66
+ ],
67
+ };
68
+ }
69
+ //# sourceMappingURL=composite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composite.js","sourceRoot":"","sources":["../../../src/crypto/composite.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;AAqBjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,CAAC,MAAM,uBAAuB,GAAG,kCAAkC,CAAC;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,qCAAqC,CAAC;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AACpD,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;AAuBvC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,cAAsB,EACtB,qBAA6B;IAE7B,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;IAC9B,MAAM,MAA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,EAAE,WAAW;gBACrB,KAAK,EAAE,IAAI;gBACX,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;aAClD;YACD;gBACE,GAAG,EAAE,WAAW;gBAChB,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;aAClD;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function digestHexBytes(data: Uint8Array): string;
2
+ export declare function digestHexText(text: string): string;
3
+ export declare function digestBytes(data: Uint8Array): Uint8Array;
@@ -0,0 +1,31 @@
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
+ * SHA3-256 digesting over node:crypto.
16
+ *
17
+ * Mirrors certcrypt-verifier-toolkit-js/core/crypto/digest.ts so the issuer
18
+ * computes the same deterministic identifiers (commitment_id, submission_set_id)
19
+ * the verifier and the server recompute (sha3_256_hex over JCS canonical bytes).
20
+ */
21
+ import { createHash } from "node:crypto";
22
+ export function digestHexBytes(data) {
23
+ return createHash("sha3-256").update(data).digest("hex");
24
+ }
25
+ export function digestHexText(text) {
26
+ return createHash("sha3-256").update(text, "utf-8").digest("hex");
27
+ }
28
+ export function digestBytes(data) {
29
+ return new Uint8Array(createHash("sha3-256").update(data).digest());
30
+ }
31
+ //# sourceMappingURL=digest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest.js","sourceRoot":"","sources":["../../../src/crypto/digest.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;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAgB;IAC1C,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACtE,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { type KeyObject } from "node:crypto";
2
+ /** An ECDSA P-256 keypair as node KeyObjects plus the wire public key. */
3
+ export interface EcdsaP256KeyPair {
4
+ privateKey: KeyObject;
5
+ publicKey: KeyObject;
6
+ /** SEC1 uncompressed (65B, 0x04-prefixed) public key, base64 — the wire form. */
7
+ publicKeyB64: string;
8
+ }
9
+ /** Generate a fresh ECDSA P-256 keypair (dev/test; production keys via KMS). */
10
+ export declare function generateEcdsaP256KeyPair(): EcdsaP256KeyPair;
11
+ /** Export a P-256 public KeyObject as SEC1 uncompressed (65B) base64. */
12
+ export declare function publicKeySec1UncompressedB64(publicKey: KeyObject): string;
13
+ /** Load a P-256 private key from PKCS#8 DER/PEM (for KMS-provisioned keys). */
14
+ export declare function privateKeyFromPkcs8(pkcs8: Buffer | string): KeyObject;
15
+ /**
16
+ * Build a P-256 private KeyObject DETERMINISTICALLY from a 32-byte scalar `d`
17
+ * (1 ≤ d < n). Used to derive a stable issuer key from a master seed — the same
18
+ * seed always yields the same signing identity, with no stored key material.
19
+ *
20
+ * The public point (x, y) is derived from `d` via ECDH (`crypto.createECDH`,
21
+ * which does the scalar × G multiplication), then a JWK EC private key
22
+ * {crv, d, x, y} is imported: a pure-`node:crypto` way to go from a raw scalar to
23
+ * a signing KeyObject.
24
+ *
25
+ * Callers MUST pass a scalar already reduced into [1, n): see
26
+ * `scalarFromSeedMaterial`, which folds arbitrary seed bytes into range.
27
+ */
28
+ export declare function privateKeyFromScalar(scalar: Uint8Array): KeyObject;
29
+ /**
30
+ * Domain-separation info string for deriving the P-256 half of a composite key
31
+ * from a 32-byte master seed.
32
+ *
33
+ * Load-bearing, and pinned by the conformance contract
34
+ * (`fixtures/primitives/key-derivation`): whatever derives the published key and
35
+ * every SDK MUST derive byte-identically, or the public key published in the manifest
36
+ * is not the one this seed produces.
37
+ */
38
+ export declare const P256_DERIVE_INFO = "certcrypt/composite/p256/v1";
39
+ /**
40
+ * Deterministic P-256 signing key from a 32-byte master seed.
41
+ *
42
+ * HKDF-SHA3-256 with explicit domain separation, expanded to 48 bytes and reduced
43
+ * mod n. The oversampling past the 32-byte field removes the modular bias of
44
+ * reducing exactly 256 bits; a result of 0 maps to 1, so the scalar is always in
45
+ * [1, n-1].
46
+ *
47
+ * The SAME seed also derives the ML-DSA-65 half (FIPS 204 KeyGen, seed used
48
+ * verbatim). The distinct HKDF `info` keeps the two derivations separated, so one
49
+ * custodied seed materializes the whole composite identity without either
50
+ * component leaking into the other.
51
+ *
52
+ * Note the difference from {@link scalarFromSeedMaterial}, which folds arbitrary
53
+ * bytes with `% (n-1) + 1`. That is a different reduction and yields a different
54
+ * key: it is for callers holding their own material, not for the composite
55
+ * identity. Only this function reproduces the contract's vectors.
56
+ */
57
+ export declare function signingKeyFromSeed(seed: Uint8Array): KeyObject;
58
+ /**
59
+ * Fold arbitrary seed-derived bytes into a valid P-256 scalar in [1, n). Reduces
60
+ * mod (n-1) and adds 1 so the result is never 0 and never ≥ n. Deterministic.
61
+ */
62
+ export declare function scalarFromSeedMaterial(material: Uint8Array): Uint8Array;
63
+ /** Derive the SEC1-uncompressed wire public key from a P-256 private key. */
64
+ export declare function publicKeyB64FromPrivate(privateKey: KeyObject): string;
65
+ /**
66
+ * Sign `message` with a P-256 private key, returning a `raw-rs-64` signature
67
+ * (r||s, 64 bytes) normalized to low-s (s ≤ n/2).
68
+ *
69
+ * The message is hashed once with SHA3-256 and the nonce is RFC 6979
70
+ * deterministic with HMAC-SHA3-256, so the same key and message always give the
71
+ * same 64 bytes (conformance family `ecdsa-p256-deterministic`).
72
+ */
73
+ export declare function signEcdsaP256Raw(privateKey: KeyObject, message: Uint8Array): Uint8Array;
74
+ /**
75
+ * Local self-check verify (tests / minter self-verification). The production
76
+ * trust verdict is the composite check in the verifier toolkit; this only mirrors
77
+ * its ECDSA primitive (SHA3-256, raw-rs-64, low-s enforced).
78
+ */
79
+ export declare function verifyEcdsaP256Raw(publicKeyB64: string, message: Uint8Array, sig: Uint8Array): boolean;