@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
package/README.md CHANGED
@@ -1,3 +1,558 @@
1
- # Temporary Holding Version
1
+ # CERTCRYPT SDK for JavaScript
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Official JavaScript/TypeScript SDK for integrating with CERTCRYPT infrastructure to produce certification artifacts that can reach `Independent`.
4
+
5
+ CERTCRYPT is infrastructure that makes certification independently verifiable under public rules. Selected artifacts can reach `Independent` through `Proof of Independence`, a structural result, so later verification no longer depends on the issuer's live systems.
6
+
7
+ The issuer remains responsible for issuing the base certificate and controlling the original material. CERTCRYPT does not validate semantic truth, does not decide whether document content is true, and does not custody the original material.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install @certcrypt/sdk
13
+ ```
14
+
15
+ Requires Node.js 20 or newer.
16
+
17
+ **You will need credentials to issue.** The SDK signs client-side, but an issuer's
18
+ key-set root has to be authorized before anything it emits can reach `Independent`.
19
+ Get yours at **[console.certcrypt.com](https://console.certcrypt.com)**.
20
+
21
+ ## Core idea
22
+
23
+ Most digital certificates, records, messages, and decisions remain dependent on the systems that issued them.
24
+
25
+ That dependency is fragile over time. Systems are migrated, providers change, databases are archived, credentials expire, and institutions reorganize.
26
+
27
+ CERTCRYPT addresses this by allowing selected certification artifacts to reach `Independent`: a state in which later verification can be evaluated under public rules without relying on the issuer as a live system.
28
+
29
+ ## SDK scope
30
+
31
+ This repository hosts the issuer-side SDK. It helps issuer systems:
32
+
33
+ - integrate with CERTCRYPT infrastructure
34
+ - produce certification artifacts at issuance
35
+ - support selected artifacts reaching `Independent`
36
+ - preserve separation between issuer emission and later independent verification
37
+
38
+ The SDK does not replace the issuer's own certificate issuance logic and does not make claims about the truth, legal validity, or factual correctness of the underlying content.
39
+
40
+ ### The signing key stays with the issuer
41
+
42
+ The issuer signs its own certificates, client-side, with a key derived from a seed it
43
+ holds. CERTCRYPT never receives that seed and never signs on an issuer's behalf.
44
+
45
+ That has a direct consequence for where this SDK runs: it is **server-side only**. It
46
+ requires Node.js 20 or newer, and the issuer seed must never reach a browser bundle —
47
+ anyone who obtains it can issue as that issuer.
48
+
49
+ ### The node is a transport
50
+
51
+ Your issuance goes through a CERTCRYPT node. The SDK activates through it and
52
+ hands it your submissions, and asks it for nothing else: no identity proof, no
53
+ pinned key, nothing to configure about which node you use.
54
+
55
+ That is safe because nothing the node relays is taken on its word. The node
56
+ cannot forge a certificate — you sign it here, with a key CERTCRYPT never sees —
57
+ and what comes back, the `Proof of Independence`, is signed by the CERTCRYPT
58
+ System Domain. Whether a node may submit at all is decided by the CERTCRYPT
59
+ service, which admits submissions only from nodes whose operator it recognizes.
60
+ A node that misbehaves can delay or drop a submission; it cannot alter or invent
61
+ what is signed. A dropped submission shows up as an emission that stays
62
+ pending past its expected settlement window, which `resolveEmission()` reports
63
+ as overdue.
64
+
65
+ This SDK does not verify the `Proof of Independence` itself. Any verifier checks
66
+ it offline with the verifier toolkit, and the proof also records which node
67
+ carried the submission.
68
+
69
+ ## Usage
70
+
71
+ Configuration values come from whoever operates the system domain you issue under.
72
+ Keep `CERTCRYPT_ISSUER_KEYSET_SEED` in a secret manager: it is the issuer's
73
+ identity, and everything the SDK signs derives from it.
74
+
75
+ `rulesVersion` carries one value the SDK has to know: the commitment TTL, which is
76
+ a public rule of the domain rather than an issuer setting — a verifier requires
77
+ `expires_at === issued_at + ttl`. The SDK knows the TTL for the published rules
78
+ domains and refuses any other at construction, rather than inventing an expiry
79
+ that every conformant verifier would reject. A deployment that runs under its own
80
+ rules domain registers it with `registerRulesDomain("rules/...")` before
81
+ constructing `Certcrypt`, and passes `commitmentTtlSeconds` with that domain's
82
+ value. Registering asserts that the domain forms artifacts exactly as a published
83
+ one does; an unregistered domain is still refused.
84
+
85
+ ```js
86
+ import { readFileSync } from "node:fs";
87
+ import { Certcrypt } from "@certcrypt/sdk";
88
+
89
+ const certcrypt = new Certcrypt({
90
+ nodeBaseUrl: process.env.CERTCRYPT_NODE_BASE_URL,
91
+ keysetSeed: process.env.CERTCRYPT_ISSUER_KEYSET_SEED,
92
+ integrationKey: process.env.CERTCRYPT_ISSUER_INTEGRATION_KEY,
93
+ poolId: process.env.CERTCRYPT_POOL_ID,
94
+ rulesVersion: process.env.CERTCRYPT_RULES_VERSION,
95
+ systemRootFingerprint: process.env.CERTCRYPT_SYSTEM_ROOT_FINGERPRINT,
96
+ systemId: process.env.CERTCRYPT_SYSTEM_ID,
97
+ });
98
+
99
+ // Certify the material itself. The SDK derives the signing key from the seed,
100
+ // mints a signed base certificate, and submits it toward `Independent`.
101
+ const material = readFileSync("invoice-2026-0041.pdf");
102
+
103
+ const { handle } = await certcrypt.issue({
104
+ subjects: [{ profile: "subject.binary/1", material }],
105
+ });
106
+
107
+ // Persist the handle — it identifies the operation and lets you finish the job later, even
108
+ // after a restart, without re-emitting.
109
+ saveSomewhere(handle);
110
+
111
+ // Later: assemble the package a third party can verify offline, without contacting
112
+ // you. Settlement is not instantaneous, so this reports where the emission is —
113
+ // `pending` means retry later, never that anything is wrong.
114
+ // The package records this instance's `rulesVersion` and `systemId`; pass
115
+ // `verificationContext` only to record something else.
116
+ const resolution = await certcrypt.resolveEmission(handle);
117
+
118
+ if (resolution.state === "independent") {
119
+ saveSomewhere(resolution.verificationPackage);
120
+ } else if (resolution.state === "pending") {
121
+ // Not settled yet; the handle stays valid.
122
+ } else {
123
+ // "rejected" or "expired" — terminal, and `resolution.nodeState` says why.
124
+ }
125
+ ```
126
+
127
+ ### The authorization your issuer needs
128
+
129
+ Before an issuer can emit, its **operation-key root must be authorized by a system
130
+ domain**. That authorization is a `level1_binding` the domain signs over your
131
+ key-set root, and it is what a verifier ultimately checks: everything you sign
132
+ derives its authority from it. This part is protocol — `capacity.evidence/1` fixes
133
+ the binding's exact fields and their order.
134
+
135
+ **How you obtain it is not.** Each system domain decides that for itself: a portal,
136
+ an existing PKI, an offline ceremony, or an automated exchange. The SDK supports
137
+ both shapes:
138
+
139
+ - **You already hold a binding** — pass it as `signedLevel1` (with the `holderId`
140
+ and `poolId` it was issued against). The SDK never asks how you got it.
141
+ - **The domain issues one automatically** — pass an `integrationKey` and the SDK
142
+ redeems it on first use.
143
+
144
+ The second is what CERTCRYPT's own domain does, and it is the shape the example
145
+ above uses — issue an integration key from
146
+ [console.certcrypt.com](https://console.certcrypt.com), put it in config, and the
147
+ SDK does the rest. Its properties, if your domain works that way: there is **no first-run
148
+ branch to write** — `keysetSeed` and `integrationKey` are two halves of one boot
149
+ credential, provisioned from config and kept. The key-set root is re-derived from
150
+ the seed, so re-presenting the same key is an idempotent replay answered with the
151
+ same binding. The key is "one-time" only in that its first use binds it to that
152
+ root; presenting it with a *different* root is refused, which protects you against
153
+ someone else claiming your integration, not against your own restart.
154
+
155
+ The first `issue()` redeems on the way past, so most integrations call nothing
156
+ explicitly. `activate()` exists for when the deploy and the first real certificate
157
+ are far apart.
158
+
159
+ Either way, pass a `bindingStore` to cache the binding and skip a round-trip on
160
+ start. It is a cache: omitting it, or having it fail, costs a request and never
161
+ correctness.
162
+
163
+ ### Waiting for settlement
164
+
165
+ `pending` is the normal state of a fresh emission, not a problem: the operation is
166
+ waiting to be settled, and settlement batches many operations into one window. How
167
+ long that takes depends on the window, and a window can be delayed — by congestion,
168
+ or by an incident on the settlement layer itself.
169
+
170
+ So do not block on it. The handle is a durable reference to the operation: persist it, return to the
171
+ caller, and resolve later. A process that restarts, or a different process
172
+ altogether, can resolve the same handle without re-emitting.
173
+
174
+ `resolveEmission` accepts a `wait` option for the in-line case:
175
+
176
+ ```js
177
+ const resolution = await certcrypt.resolveEmission(handle, {
178
+ wait: { maxWaitMs: 10 * 60_000 }, // wait up to ten minutes
179
+ });
180
+ ```
181
+
182
+ #### The node tells you when it expects to settle
183
+
184
+ You do not have to guess the interval. While an operation is waiting to be settled,
185
+ the node reports the settlement window it is assigned to, and the SDK schedules around
186
+ it:
187
+
188
+ ```js
189
+ const r = await certcrypt.resolveEmission(handle);
190
+
191
+ if (r.state === "pending") {
192
+ r.settlementWindow; // { window_profile, window_profile_version, target_close_by, expected_settled_by }
193
+ r.overdue; // true when expected_settled_by has already passed
194
+ }
195
+ ```
196
+
197
+ With `wait`, the SDK uses that estimate instead of polling blindly. It checks twice
198
+ before calling the operation overdue: once 60 % of the way from `target_close_by` to
199
+ `expected_settled_by`, where most settlements have already landed, and once at
200
+ `expected_settled_by` plus one second for clock skew. Each check is pushed back by a
201
+ random 0–1 s so that the operations of one window do not all ask at the same instant.
202
+ When there is no estimate — or the operation is already overdue — it falls back to
203
+ exponential backoff with a cap.
204
+
205
+ `target_close_by` is the moment the **window closes**, not the moment the package is
206
+ ready: anchoring and chain finality add more after it. `expected_settled_by` is the
207
+ operator's estimate of when that settlement is anchored and final, so that a read can
208
+ return a terminal state; it is never earlier than `target_close_by`, and it is present
209
+ exactly when `target_close_by` is. Both are operational estimates, not deadlines and
210
+ not a promise of when the operation becomes Independent. When the node reports only
211
+ `target_close_by`, the SDK sleeps until it plus three seconds and reports `overdue`
212
+ once it has passed.
213
+
214
+ #### Knowing it is still alive
215
+
216
+ A wait that sleeps for minutes looks exactly like a hang. Pass `onProgress` to report
217
+ it — every tick carries a ready-made `message`, so logging it is one line:
218
+
219
+ ```js
220
+ await certcrypt.resolveEmission(handle, {
221
+ wait: {
222
+ maxWaitMs: 10 * 60_000,
223
+ onProgress: (p) => log.info(p.message),
224
+ // "still processing after 45s — waiting for settlement window <profile> to
225
+ // close (~2026-08-16T12:00:40Z), settlement expected by ~2026-08-16T12:00:55Z;
226
+ // next check in 22s"
227
+ },
228
+ });
229
+ ```
230
+
231
+ If you pass no `onProgress` and the SDK is about to sleep for ten seconds or more, or
232
+ the window is already overdue, it writes that same line to the console
233
+ (`console.info`) rather than going quiet. An exception thrown by `onProgress` is
234
+ swallowed: reporting never breaks the wait. An operation running
235
+ late says so explicitly (`overdue`), which is what a stalled settlement layer actually
236
+ looks like from the outside.
237
+
238
+ #### Wait options
239
+
240
+ | option | meaning |
241
+ | --- | --- |
242
+ | `maxWaitMs` | wall-clock bound on the whole wait — usually the only one you need. Under `"auto"` it defaults to 15 minutes, so an omitted value bounds the wait rather than blocking forever; under `"fixed"` only the attempt count bounds the wait unless you set it |
243
+ | `strategy` | `"auto"` (default): use the window estimate, else backoff. `"fixed"`: poll every `intervalMs` |
244
+ | `backoffBaseMs` / `backoffCapMs` | backoff shape when there is no estimate (defaults 1 s / 30 s) |
245
+ | `onProgress` | called before each sleep with a `WaitProgress`: a ready-to-log `message`, plus `attempt`, `nodeState`, `nextCheckInMs`, `elapsedMs`, `overdue`, and — when the node reports them — `window` and `settlement` |
246
+ | `intervalMs` / `maxAttempts` | fixed-interval polling: a poll every `intervalMs` (default 1 s), at most `maxAttempts` polls (default 60) |
247
+
248
+ Passing `intervalMs` or `maxAttempts` selects `"fixed"` unless you also pass
249
+ `strategy`. Prefer `maxWaitMs`: an attempt count only means something once you also
250
+ know the interval.
251
+
252
+ When the wait ends without a terminal state, `waitForOperation` throws a
253
+ `CertcryptNodeError` saying the operation "did not reach a terminal state", with the
254
+ last state it saw. `resolveEmission` does not throw for that: it reports `pending`,
255
+ because the handle is still good.
256
+
257
+ #### Timeouts and retries
258
+
259
+ Every request to the node is bounded at 30 seconds. A submit and every read
260
+ (`getOperation`, `getEmissionByCommitment`, `listUnresolvedEmissions`,
261
+ `listDeadLetters`) are retried under the transport-retry policy:
262
+ a connection that fails or times out, and a 408, 425, 429 or 5xx, are retried until
263
+ the time budget runs out, and a `Retry-After` on 503 or 429 is waited out without
264
+ counting as an attempt. A submit keeps the same `request_id` on every attempt, so a
265
+ 2xx answer whose body is not JSON is retried safely too. Tune it with `retry`:
266
+
267
+ | option | meaning |
268
+ | --- | --- |
269
+ | `maxElapsedMs` | total time budget from the first attempt (default 120 s) |
270
+ | `maxAttempts` | counted attempts, the first included (default: no limit; 1 disables retry) |
271
+ | `baseMs` / `capMs` | backoff shape: attempt n waits a random draw under `baseMs × 2^(n−1)`, capped at `capMs` (defaults 200 ms / 30 s) |
272
+
273
+ `health()` is one request, never retried, and reports `false` rather than throwing
274
+ when the node does not answer.
275
+
276
+ #### What the window is — and what it is not
277
+
278
+ The window is **operational information from the operator**, in the same family as the
279
+ `settlement_preferences` you send on the way in. It is not part of the protocol:
280
+
281
+ - it never enters the submission set, the proof, or anything a verifier evaluates;
282
+ - the verifier never reads the profile catalog, and a conforming third-party
283
+ implementation reaches Independent without it.
284
+
285
+ **What is portable, and what is not.** The *shape* is generic and any implementation
286
+ can use it: an optional `{ window_profile, window_profile_version, target_close_by, expected_settled_by }`,
287
+ plus a scheduler that waits for the timestamp or falls back to backoff. A node that
288
+ sends nothing is fully supported — the SDK just backs off, and that path is covered by
289
+ tests.
290
+
291
+ The *values* belong to the rules domain. The profiles a domain admits, and its
292
+ default, are published in its public rules (for `rules/2026-01`, section 15), and
293
+ they are versioned: a later rules domain can admit a different set. A name is
294
+ something to elect on the way in with `settlementPreferences`, not something to
295
+ time a wait on. So:
296
+
297
+ ```js
298
+ // Fine: schedule on the timestamp.
299
+ const w = r.settlementWindow;
300
+ const at = w?.expected_settled_by ?? w?.target_close_by;
301
+ if (at) scheduleRetryAt(at);
302
+
303
+ // Fragile: the name is a versioned value of the rules domain — not a timing contract.
304
+ if (r.settlementWindow?.window_profile === "some_profile_name") { /* … */ }
305
+ ```
306
+
307
+ Use `expected_settled_by` (or `target_close_by` when it is absent) for timing and
308
+ `overdue` for "is it late". Treat
309
+ `window_profile` as an opaque label for logs and support, and pin nothing to it.
310
+
311
+ It is also deliberately **free of any cost figure**. There is no amount, no capacity
312
+ number, no receipt line and no billing multiplier in it, and none will be added. In
313
+ the clear on every response, an operation's cost would let an issuer's operations be
314
+ correlated over time — and restricting it to "only your own issuer" would not help,
315
+ because once such a value travels in a response it lands in logs and billing
316
+ records. The quantity an emission actually consumed is carried in the
317
+ `settlement_material` that the `independence_proof` binds — that is the
318
+ authoritative figure. Your own costs stay available to you, authenticated and off
319
+ the emission path — on CERTCRYPT that is
320
+ [console.certcrypt.com](https://console.certcrypt.com).
321
+
322
+ Knowing that a window is running late reveals nothing about who issued into it.
323
+
324
+ A certificate can commit to several subjects at once — pass more than one, and note
325
+ that the order is significant. Keep the original material: reaching `Independent`
326
+ does not need it, but a verifier who compares the material against the commitment
327
+ needs those exact bytes.
328
+
329
+ ### Certifying text an application produced
330
+
331
+ Not everything worth certifying is a file. A consent record, an audit entry, a
332
+ decision an application recorded — anything your app can serialize deterministically
333
+ is a subject. Use `subject.text/1` and it is canonicalized before being committed to:
334
+ line endings are normalized to CRLF and the trailing CRLF run collapses to exactly one, so
335
+ the same logical text certifies identically whether it was written on Windows, Linux
336
+ or macOS.
337
+
338
+ ```js
339
+ // A consent record, exactly as your application stored it.
340
+ const record = [
341
+ "consent.v1",
342
+ "user: 4f9c2a71-3e8d-4b16-9a02-7c1d5e8f0b34",
343
+ "scope: analytics,marketing",
344
+ "granted_at: 2026-08-12T09:41:00Z",
345
+ "policy: privacy-notice-2026-06",
346
+ ].join("\n");
347
+
348
+ const { handle } = await certcrypt.issue({
349
+ subjects: [{ profile: "subject.text/1", material: new TextEncoder().encode(record) }],
350
+ });
351
+ ```
352
+
353
+ Two things worth getting right, because a verifier who compares the material
354
+ recomputes the commitment from the bytes you certified:
355
+
356
+ - **Serialize deterministically.** Build the text the same way every time. Iterating
357
+ an object's keys in whatever order they happen to come out will produce a different
358
+ commitment for the same logical record.
359
+ - **Store what you certified**, not just the fields it came from. Reassembling the
360
+ text later from a database row is how a certificate stops matching its material.
361
+
362
+ If the record is structured rather than flat text, `subject.collection/1` and
363
+ `subject.ai-decision/1` take JSON and canonicalize the *value* (RFC 8785), so key
364
+ order stops mattering.
365
+
366
+ ### Handing out one element of a collection
367
+
368
+ A `subject.collection/1` binds each of its elements individually, so a holder can be
369
+ shown that ONE element belongs to the certified set without receiving the rest of it
370
+ — or the certificate. What they need is an inclusion proof, and only whoever holds
371
+ the certificate can build one: the path is folded from the collection's own leaf
372
+ digests.
373
+
374
+ The SDK exports the primitives, so you never fold the Merkle path by hand:
375
+
376
+ ```js
377
+ import {
378
+ collectionLeafHash,
379
+ collectionInclusionProof,
380
+ canonicalBytesForSubject,
381
+ COLLECTION_MERKLE_SCHEME,
382
+ } from "@certcrypt/sdk";
383
+
384
+ // Everything comes from the certificate you already hold (`baseCertificate`),
385
+ // plus the element you hand out: its bytes (`leafBytes`) and its position.
386
+ const anchor = baseCertificate.payload.anchor;
387
+ const collectionSalt = new TextEncoder().encode(anchor.nonce_hex);
388
+ const collection = anchor.subjects[subjectIndex].collection;
389
+ const leafHashes = collection.leaves.map((l) => l.commitment_digest_hex);
390
+
391
+ // Find the element by its own salted hash. Its POSITION is the leaf_index — it is
392
+ // derived, never declared, so a wrong one simply folds to a different root.
393
+ const profile = collection.leaves[leafIndex].profile;
394
+ const canonical = canonicalBytesForSubject(profile, leafBytes);
395
+ const index = leafHashes.indexOf(collectionLeafHash(collectionSalt, profile, canonical));
396
+ if (index === -1) throw new Error("not a declared leaf of this collection");
397
+
398
+ const proof = {
399
+ proof_version: COLLECTION_MERKLE_SCHEME,
400
+ leaf_index: String(index),
401
+ sibling_hashes: collectionInclusionProof(leafHashes, index),
402
+ };
403
+
404
+ console.log(JSON.stringify(proof, null, 2));
405
+ ```
406
+
407
+ `collectionInclusionProof` is the part worth not rewriting: a node that is the lone
408
+ right edge of an odd level is promoted unchanged and contributes **no** sibling. Get
409
+ that wrong and the path folds to a different root — the proof simply fails to verify,
410
+ with nothing to say why. The conformance vectors cover odd cardinalities precisely
411
+ because it is the easy mistake.
412
+
413
+ Send the holder the element, this proof, and the collection's declared `root`,
414
+ `declared_cardinality`, leaf `profile` and the anchor's `nonce_hex` (the salt).
415
+ Never the rest of the collection. `verifyCollectionInclusion` in the toolkit is what
416
+ they run against it — the reference implementation of that check is the public
417
+ verification portal.
418
+
419
+ Nothing here has to be stored at issuance: the certificate carries every leaf digest
420
+ and the salt, so any element's proof can be rebuilt whenever it is needed.
421
+
422
+ ## Building from source
423
+
424
+ ```sh
425
+ npm install
426
+ npm run build
427
+ npm run lint # typecheck, no emit
428
+ ```
429
+
430
+ The test suite checks byte-parity against the primitive vectors of
431
+ `certcrypt-conformance`. This SDK is not a verifier and returns no
432
+ `VerifierResult`, so the verdict fixtures do not apply to it; what it must
433
+ reproduce is the bytes, identically to every other implementation. State the
434
+ version you ran against when you claim parity — the value in the suite's
435
+ `VERSION` at that time. The contract is versioned independently of this package.
436
+
437
+ The ECDSA P-256 half of every signature is part of those bytes: it is RFC 6979
438
+ deterministic (conformance family `ecdsa-p256-deterministic`), so the same key
439
+ over the same message always gives the same signature. The ML-DSA-65 half is
440
+ hedged, so it differs between runs; both halves verify either way.
441
+
442
+ Running them expects `certcrypt-conformance` and `certcrypt-verifier-toolkit-js`
443
+ as sibling checkouts, already built:
444
+
445
+ ```sh
446
+ npm test
447
+ ```
448
+
449
+ **A missing sibling is a failure, by default.** A skipped test reports no
450
+ failure, so if the tests that need a sibling skipped when it was absent, `fail 0`
451
+ could describe a run that never checked parity — including the round-trip that
452
+ hands a minted certificate to the verifier. Nothing needs to be switched on:
453
+ `npm test` without a sibling fails, naming the path it looked for. Making rigor opt-in gets it backward — whoever forgets the flag is
454
+ precisely whoever needed it.
455
+
456
+ ```sh
457
+ git clone https://github.com/CERTCRYPT/certcrypt-conformance.git ../certcrypt-conformance
458
+ npm test
459
+ ```
460
+
461
+ Two escape hatches, both deliberate and neither a default:
462
+
463
+ | Variable | Effect |
464
+ | --- | --- |
465
+ | `CERTCRYPT_ALLOW_MISSING_CONFORMANCE=1` | Skip instead of failing. For working on this repo alone, knowing the parity half did not run |
466
+ | `CERTCRYPT_ALLOW_CONFORMANCE_VERSION_MISMATCH=1` | Run against a contract version this SDK does not claim, to see what a bump would break |
467
+
468
+ **The contract VERSION is checked too.** Requiring it to be present is not
469
+ enough: two implementations can each build green against a different version and
470
+ diverge anyway. This SDK is held to `EXPECTED_CONTRACT_VERSION`
471
+ (`src/test-support/siblings.ts`), and a checkout that is not that one fails.
472
+ Adopting a new contract means raising the constant and re-running.
473
+
474
+ ## CERTCRYPT boundary
475
+
476
+ - not a claim of factual truth
477
+ - not a validator of correctness
478
+ - not a custodian of documents
479
+ - not blockchain notarization
480
+ - not a trust badge
481
+
482
+ ## Boundary of this SDK
483
+
484
+ - not a replacement for the issuer's own certificate issuance logic
485
+ - not a verifier
486
+ - not a source of proof validity
487
+ - not a document custody library
488
+ - not a semantic validator of legal or factual claims
489
+
490
+ ### Trademarks
491
+
492
+ The Apache-2.0 grant covers copyright, not marks: §6 of the license grants no
493
+ permission to use CERTCRYPT trade names, trademarks, service marks or product
494
+ names beyond describing the origin of the work.
495
+
496
+ Stating that your product issues CERTCRYPT certificates, or that it is built on
497
+ this SDK, is such a use. Naming your product after CERTCRYPT is not.
498
+
499
+ The distinction matters more here than in a library that only reads: what this
500
+ SDK emits is signed under **your** issuer identity, not CERTCRYPT's. A
501
+ certificate minted with it is your act — CERTCRYPT does not review, approve or
502
+ countersign it, and presenting one as CERTCRYPT having certified the underlying
503
+ material misstates what the artifact says. What the certificate carries is a
504
+ commitment that anyone can verify against the public rules, which is the whole
505
+ point and is stronger than a badge.
506
+
507
+ ## Documentation
508
+
509
+ Technical documentation and the public specifications are published at
510
+ [docs.certcrypt.com](https://docs.certcrypt.com): the model, the terminology, the
511
+ claims boundary, the evaluation model a verifier applies, and the normative
512
+ specifications the artifacts in this SDK conform to.
513
+
514
+ ## Links
515
+
516
+ | Surface | Address |
517
+ | --- | --- |
518
+ | Website | [certcrypt.com](https://certcrypt.com) |
519
+ | Documentation | [docs.certcrypt.com](https://docs.certcrypt.com) |
520
+ | Verify an artifact | [verify.certcrypt.dev](https://verify.certcrypt.dev) |
521
+ | Blog | [blog.certcrypt.com](https://blog.certcrypt.com) |
522
+ | Support | [support.certcrypt.com](https://support.certcrypt.com) |
523
+ | Service status | [status.certcrypt.com](https://status.certcrypt.com) |
524
+ | Open source | opensource@certcrypt.com |
525
+ | Security | security@certcrypt.com — see [`SECURITY.md`](SECURITY.md) |
526
+
527
+ **The two repositories on the other side of what this SDK emits:**
528
+
529
+ | Repository | Relationship |
530
+ | --- | --- |
531
+ | [certcrypt-verifier-toolkit-js](https://github.com/CERTCRYPT/certcrypt-verifier-toolkit-js) | the verifier that evaluates what this SDK mints — this SDK's own suite round-trips its certificates through it, with every signature verified |
532
+ | [certcrypt-conformance](https://github.com/CERTCRYPT/certcrypt-conformance) | the public contract both sides are held to; this SDK checks byte parity against its primitive vectors |
533
+
534
+ Emission and verification are deliberately separate, and the contract in the
535
+ middle is data rather than code. That is what makes a certificate this SDK mints
536
+ checkable by someone who has neither your systems nor this SDK — which is the
537
+ property the whole design exists to produce.
538
+
539
+ **Verifying what this SDK produces:** [verify.certcrypt.dev](https://verify.certcrypt.dev)
540
+ is the public reference implementation of the verifier: no account, no sign-in, and
541
+ useful for checking an emission end to end during integration. It runs the toolkit in
542
+ your own browser, so original material you choose to compare is read and hashed
543
+ locally and never sent anywhere.
544
+
545
+ ## Changelog
546
+
547
+ Release notes are in [`CHANGELOG.md`](CHANGELOG.md). From 1.0.0 this package
548
+ follows semantic versioning: breaking a documented export requires a major
549
+ release. Deliberately outside that promise, because it is not API: which verdict a
550
+ given artifact receives. A check may be tightened in a minor or a patch, and an
551
+ artifact that verified before may then fail — that is a corrected verdict, and the
552
+ entry says so.
553
+
554
+ ## License
555
+
556
+ Copyright 2025-2026 CERTCRYPT, Inc., its affiliates or licensors. All rights reserved.
557
+
558
+ Licensed under the Apache License, Version 2.0. See [`LICENSE`](LICENSE) for the full text.
package/SECURITY.md ADDED
@@ -0,0 +1,55 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Security fixes land on the latest published version. Upgrading is the remediation
6
+ path — fixes are not backported to superseded versions.
7
+
8
+ | Version | Supported |
9
+ | --- | --- |
10
+ | Latest `1.x` release | Yes |
11
+ | Earlier releases | Upgrade to the latest |
12
+
13
+ ## Reporting a Vulnerability
14
+
15
+ Please do not open public issues for security vulnerabilities.
16
+
17
+ Report security concerns by email to security@certcrypt.com.
18
+
19
+ Include:
20
+
21
+ - affected repository or component
22
+ - affected version or commit, if known
23
+ - a clear description of the issue
24
+ - reproduction steps, if available
25
+ - potential impact
26
+
27
+ Please avoid including customer data, production credentials, private keys, or confidential third-party material in reports.
28
+
29
+ We will acknowledge valid reports as soon as practical and coordinate remediation before public disclosure.
30
+
31
+ ## Coordinated Disclosure
32
+
33
+ Please give us a reasonable opportunity to investigate and remediate security issues before public disclosure.
34
+
35
+ Do not publish exploit details, proof-of-concept code, or operational indicators before we have completed triage and remediation planning.
36
+
37
+ ## Scope
38
+
39
+ This repository is intended for public issuer-side SDK code.
40
+
41
+ Do not submit secrets, production credentials, private keys, customer data, or any other sensitive material in issues, pull requests, or discussions.
42
+
43
+ ## Out of Scope
44
+
45
+ The following are not handled through this repository's security process:
46
+
47
+ - general product questions
48
+ - documentation corrections without security impact
49
+ - requests for roadmap information
50
+ - reports about private CERTCRYPT systems not represented in this repository
51
+ - claims about semantic truth, legal validity, or factual correctness of certificate content
52
+
53
+ For non-security questions, use the public contact channel:
54
+
55
+ opensource@certcrypt.com