@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,552 @@
1
+ import type { EmissionHandleRecord, LooseCommitment, IssueRequest, IssueResponse, OperationRecord, SettlementProgress, SettlementWindowEstimate, UnresolvedEmissions } from "./types.js";
2
+ import { type SignedLevel1Binding } from "./artifacts/capacity-evidence.js";
3
+ import { HolderKeySet } from "./artifacts/holder-keyset.js";
4
+ import { type SubjectInput, type IssuerKey, type MintedCertificate, type IssuanceTarget } from "./artifacts/base-certificate.js";
5
+ import { type CommitmentInclusionProof } from "./artifacts/commitment-inclusion.js";
6
+ export declare class CertcryptNodeError extends Error {
7
+ readonly status: number | null;
8
+ readonly body: string | null;
9
+ /**
10
+ * The wait the node asked for, in ms, when it refused with 503 or 429 and a
11
+ * usable `Retry-After` — a restart, an outbox it could not write. `null`
12
+ * otherwise. Read by the retry policy; surfaced so a caller that gives up can
13
+ * still tell "come back in 10 s" from "broken".
14
+ */
15
+ readonly retryAfterMs: number | null;
16
+ /**
17
+ * The machine-readable reason the node gave, when its body carries one: the
18
+ * `error` code of a `{error, message, request_id}` answer (a request the node
19
+ * refused before submitting it), or the whole-request `state` of an
20
+ * `IssueResponse` (e.g. `submission_failed`). `null` otherwise.
21
+ *
22
+ * `integration_key_replaced` (HTTP 409, on activation): the integration key
23
+ * in this configuration was replaced by a newer one — regenerating the key in
24
+ * the console invalidates every previous key at once. Not retryable: update
25
+ * the configuration with the latest integration key and start again.
26
+ */
27
+ readonly code: string | null;
28
+ /**
29
+ * For a `submission_failed` the node answered with HTTP 422: the HTTP status
30
+ * with which the CERTCRYPT service definitively refused the request. Nothing
31
+ * was queued; resending the same request gets the same answer, so fix the
32
+ * cause before submitting anew. `null` otherwise.
33
+ */
34
+ readonly upstreamStatus: number | null;
35
+ constructor(message: string, status: number | null, body: string | null, retryAfterMs?: number | null);
36
+ }
37
+ /** What `POST /v1/activate` returns, parsed. */
38
+ export interface ActivationResult {
39
+ signedLevel1: SignedLevel1Binding;
40
+ poolId: string;
41
+ holderId: string;
42
+ /** `redeemed` or `already_consumed_same_root`; both are success. */
43
+ status: string;
44
+ }
45
+ /** The request an issuer proof is made for: what the node binds it to. */
46
+ export interface IssuerAuthRequest {
47
+ method: string;
48
+ /** Absolute URL, as fetched. */
49
+ url: string;
50
+ /** The exact body sent, if any. */
51
+ body?: string;
52
+ }
53
+ /** Signing domain of the issuer's per-request proof to a node. */
54
+ export declare const ISSUER_AUTH_DOMAIN = "certcrypt:issuer-auth:1";
55
+ /**
56
+ * The bytes the issuer's leaf signs for `challenge` on `request`:
57
+ * `certcrypt:issuer-auth:1|<challenge>|<host>|<METHOD> <path?query>|<sha3-256
58
+ * hex of the body>`. The node rebuilds it from the request it receives, so a
59
+ * proof captured in transit is good only for repeating that very request — not
60
+ * another route, body or node. `host` is the URL's host with a non-default port.
61
+ */
62
+ export declare function issuerAuthMessage(challenge: string, request: IssuerAuthRequest): string;
63
+ /** A submission the node gave up delivering. */
64
+ export interface DeadLetter {
65
+ requestId: string;
66
+ attempts: number;
67
+ createdAtMs: number;
68
+ lastError: string | null;
69
+ }
70
+ export interface NodeClientOptions {
71
+ /** Base URL of the node, e.g. `https://node.example`. */
72
+ baseUrl: string;
73
+ /**
74
+ * The integration's `pool_id`, from onboarding.
75
+ *
76
+ * A property of THIS SDK instance, not a per-call choice: one integration is one
77
+ * SDK instance and one pool. When set, every commitment is stamped with it and
78
+ * no per-call `pool_id` is accepted, so an integration cannot emit outside its
79
+ * own pool even by mistake — a commitment naming a different pool is rejected on
80
+ * submit.
81
+ */
82
+ pool_id?: string;
83
+ /** Optional fetch implementation (defaults to global fetch). */
84
+ fetch?: typeof fetch;
85
+ /**
86
+ * Self-verifying issuer-auth proof provider. Returns the base64(JSON) value for
87
+ * the `x-certcrypt-issuer-auth` header (a fresh proof per call: the Level-1
88
+ * binding + a leaf disclosure + a possession signature over a fresh challenge
89
+ * bound to `request` — see {@link issuerAuthMessage}), or null if the issuer
90
+ * is not yet activated. Set by the `Certcrypt` issuer.
91
+ */
92
+ issuerAuthProof?: (request: IssuerAuthRequest) => string | null;
93
+ /** Builds the issuer's half of a READ chain: a Level-1 binding + a leaf
94
+ * signature over `certcrypt:read:2|<challenge>|<resource>` (a PRIVATE signing
95
+ * domain, not a public protocol id). The challenge is fresh per call and the
96
+ * server accepts it once, so it is called again for every attempt. The server requires it because a
97
+ * read carries no signed artifact of its own, so the scope must derive from who
98
+ * SIGNED the request rather than from whoever transported it. */
99
+ issuerReadProof?: (resource: string) => string | null;
100
+ /**
101
+ * Called when a read reveals the upstream id of a node-local operation the
102
+ * caller did not know it for — a member the node delivered after answering
103
+ * `accepted_for_retry`. The `Certcrypt` issuer uses it to sign later reads
104
+ * over the id the server routes on.
105
+ */
106
+ onUpstreamOperationId?: (operationId: string, upstreamOperationId: string) => void;
107
+ /**
108
+ * Retry policy for transient submit failures (timeout, 5xx, connection
109
+ * refused, node `submission_failed`, a node restarting). Reuses the SAME
110
+ * stable `request_id` across attempts, so the server deduplicates
111
+ * idempotently — a retry never re-signs and never double-submits.
112
+ * Non-retryable verdicts (rejected, insufficient_capacity, replay_detected)
113
+ * fail fast, never retried. See `./retry.ts` for the full policy.
114
+ */
115
+ retry?: RetryOptions;
116
+ /**
117
+ * Clock and sleep, injectable for tests and simulations. Defaults: `Date.now`
118
+ * and a `setTimeout` sleep.
119
+ */
120
+ /** Injected time and randomness, for tests. `random` spreads scheduled settlement checks. */
121
+ clock?: {
122
+ now: () => number;
123
+ sleep: (ms: number) => Promise<void>;
124
+ random?: () => number;
125
+ };
126
+ }
127
+ /**
128
+ * Retry policy for transient submit failures. Retrying ends on TIME, not on a
129
+ * count of quick failures: a node that restarts in 20 s is waited out however
130
+ * many times the connection was refused meanwhile. A `Retry-After` the node
131
+ * sends is honored exactly and never counted as an attempt.
132
+ */
133
+ export interface RetryOptions {
134
+ /** Total time budget in ms, from the first attempt. Default 120_000. */
135
+ maxElapsedMs?: number;
136
+ /**
137
+ * Max COUNTED attempts (incl. the first). Default: no limit — the time budget
138
+ * bounds the retrying. 1 disables retry.
139
+ */
140
+ maxAttempts?: number;
141
+ /** Base backoff in ms (attempt n waits a draw under base*2^(n-1)). Default 200. */
142
+ baseMs?: number;
143
+ /** Cap on a single backoff wait in ms. Default 30_000. */
144
+ capMs?: number;
145
+ }
146
+ /** What a poll tick is currently waiting on — reported to `onProgress`. */
147
+ export interface WaitProgress {
148
+ /** 1-based poll number. */
149
+ attempt: number;
150
+ /** The node's last reported state (e.g. `processing`). */
151
+ nodeState: string;
152
+ /** Ms this tick will sleep before the next check. */
153
+ nextCheckInMs: number;
154
+ /** Total ms elapsed since the wait began. */
155
+ elapsedMs: number;
156
+ /** The window the node expects to settle in, when it reported one. Lets an
157
+ * issuer log/render "still alive, expected to close at HH:MM". */
158
+ window?: SettlementWindowEstimate;
159
+ /** True once the operator's `expected_settled_by` has passed (or, when the node
160
+ * reports no such instant, once `target_close_by` has passed) and the operation
161
+ * is still not terminal — the operation is running LATE. The poller has fallen
162
+ * back to backoff. */
163
+ overdue: boolean;
164
+ /** How far the settlement has come, when the operator reported it. Lets a caller
165
+ * tell "still queued behind a window" from "on chain, waiting for
166
+ * irreversibility" — the difference between a wait that has not started and one
167
+ * that is nearly over. Advisory: never treat `finality_pending` as evidence. */
168
+ settlement?: SettlementProgress;
169
+ /**
170
+ * A ready-to-log line describing what the wait is doing and why, so an
171
+ * integrator gets a useful message without composing one from the fields.
172
+ * A long sleep (waiting for a window) is indistinguishable from a hang unless
173
+ * something says so — this is that something.
174
+ */
175
+ message: string;
176
+ }
177
+ export interface WaitOptions {
178
+ /**
179
+ * Fixed poll interval in ms. Setting it selects the fixed-interval strategy
180
+ * (see `strategy`).
181
+ */
182
+ intervalMs?: number;
183
+ /** Max attempts before giving up (default 60 in fixed-interval mode). */
184
+ maxAttempts?: number;
185
+ /**
186
+ * How to space the polls. Default `"auto"`:
187
+ * - if the node reports when it expects the settlement to be final, sleep
188
+ * UNTIL `expected_settled_by` (plus a small clock-skew margin) and check once
189
+ * on arrival;
190
+ * - else, if it reports only the window's close, sleep until `target_close_by`
191
+ * (plus a small settling margin);
192
+ * - otherwise, exponential backoff with a cap.
193
+ * `"fixed"` polls every `intervalMs`.
194
+ *
195
+ * Defaults to `"fixed"` when `intervalMs` or `maxAttempts` is supplied.
196
+ */
197
+ strategy?: "auto" | "fixed";
198
+ /**
199
+ * Wall-clock bound on the whole wait. This is what an integrator actually knows
200
+ * how to express — `maxAttempts` only means something once you also know the
201
+ * interval. When both are given, whichever trips first ends the wait.
202
+ * Default in `auto` mode: 15 minutes.
203
+ */
204
+ maxWaitMs?: number;
205
+ /** First backoff step in ms when there is no window estimate (default 1000). */
206
+ backoffBaseMs?: number;
207
+ /** Cap on a single backoff sleep in ms (default 30_000). */
208
+ backoffCapMs?: number;
209
+ /**
210
+ * Called before each sleep, so the issuer can log or render that the operation
211
+ * is alive and which window it is waiting on. Never throws into the poll: an
212
+ * exception from the callback is swallowed.
213
+ */
214
+ onProgress?: (p: WaitProgress) => void;
215
+ }
216
+ /**
217
+ * True when the operation is running late at `now`: the operator's
218
+ * `expected_settled_by` has passed, or — when the node reports no such instant —
219
+ * the window's `target_close_by` has. False when the window names neither.
220
+ */
221
+ export declare function isSettlementOverdue(window: SettlementWindowEstimate | undefined, now: number): boolean;
222
+ /**
223
+ * Choose how long to sleep before the next poll.
224
+ *
225
+ * Exported for testing: the scheduling decision is the whole point of the
226
+ * until-window mode, and it is far easier to pin as a pure function than through
227
+ * a live poll loop.
228
+ */
229
+ export declare function nextPollDelayMs(args: {
230
+ attempt: number;
231
+ now: number;
232
+ window?: SettlementWindowEstimate;
233
+ backoffBaseMs: number;
234
+ backoffCapMs: number;
235
+ /** Source of the 0..1 s spread added to a scheduled check; `Math.random` by default. */
236
+ random?: () => number;
237
+ }): {
238
+ delayMs: number;
239
+ overdue: boolean;
240
+ };
241
+ /** A `verification_package` (verification-package/1): one object with a closed member
242
+ * set, read by an offline verifier in package mode. `base_certificate` and
243
+ * `verification_context` are always present; nothing outside these members is. */
244
+ export interface VerificationPackage {
245
+ base_certificate: unknown;
246
+ independence_proof: unknown;
247
+ verification_context: {
248
+ rules_version: string;
249
+ system_id: string;
250
+ };
251
+ capacity_evidence?: unknown;
252
+ commitment_inclusion_proof?: CommitmentInclusionProof;
253
+ settlement_material?: unknown;
254
+ settlement_reference?: string;
255
+ }
256
+ /** Client-held inputs for `buildVerificationPackage` — the two artifacts the
257
+ * issuer produces locally (never returned by the node) plus the context. */
258
+ export interface BuildPackageOptions {
259
+ /** The signed base_certificate from `mintVerifiableCertificate().minted`. */
260
+ baseCertificate: unknown;
261
+ /** The `capacity.evidence/1` from the issue call's `commitment.capacity_evidence`. */
262
+ capacityEvidence: unknown;
263
+ /** Published profile values (issuer config: CERTCRYPT_RULES_VERSION + system id). */
264
+ verificationContext: {
265
+ rules_version: string;
266
+ system_id: string;
267
+ };
268
+ /** This commitment's index in the accepted set (MemberResult.commitment_index). */
269
+ commitmentIndex: number;
270
+ /** Poll options while awaiting independent_ready. */
271
+ wait?: WaitOptions;
272
+ }
273
+ /**
274
+ * True for a terminal state name: polling stops there. `accepted_for_retry` and
275
+ * `accepted` are not terminal — the first means the node holds the set and will
276
+ * deliver it, the second that a member was accepted for processing, not settled.
277
+ */
278
+ export declare function isTerminalState(state: string): boolean;
279
+ /**
280
+ * How long every request (issue, activate, reads, health) waits for the
281
+ * node before giving up on that attempt, in ms: 30 s. An attempt that times out
282
+ * is a transport failure, retried under the transport-retry policy where the
283
+ * request is retried at all.
284
+ */
285
+ export declare const REQUEST_TIMEOUT_MS = 30000;
286
+ export declare class CertcryptNodeClient {
287
+ /** The node base URL every request goes to, without a trailing slash. */
288
+ readonly baseUrl: string;
289
+ private readonly poolId;
290
+ private readonly fetchImpl;
291
+ private readonly retryPolicy;
292
+ private readonly now;
293
+ private readonly sleepMs;
294
+ private readonly random;
295
+ private readonly issuerAuthProof;
296
+ private readonly issuerReadProof;
297
+ private readonly onUpstreamOperationId;
298
+ constructor(opts: NodeClientOptions);
299
+ /**
300
+ * Headers for authenticated requests (issue, operations, emission lookups,
301
+ * dead letters). `/health` and `/v1/activate` need
302
+ * no issuer proof.
303
+ *
304
+ * Zero-trust auth: the node authenticates an issuer ONLY by the self-verifying
305
+ * proof in `x-certcrypt-issuer-auth` — the system-domain-signed binding over the
306
+ * holder_key_set_root + a leaf disclosure + a possession signature over a fresh
307
+ * challenge, built anew for every request. The node verifies it offline, with
308
+ * no token lookup. No `Authorization` header is sent: the node would ignore it,
309
+ * and a bearer credential handed to a node buys nothing but exposure. Your scope
310
+ * derives from the proof, never from the request body.
311
+ */
312
+ private authHeaders;
313
+ /**
314
+ * One fetch bounded by {@link REQUEST_TIMEOUT_MS}: a node that accepts the
315
+ * connection and never answers must not hold the caller forever. The timeout
316
+ * surfaces as a rejected promise, which every caller treats as a transport
317
+ * failure.
318
+ */
319
+ private fetchWithTimeout;
320
+ /** The issuer's half of a read chain over `resource`, minted anew on every call
321
+ * (its challenge is single-use). Empty before activation. */
322
+ private issuerReadHeaders;
323
+ /**
324
+ * A GET under the transport-retry policy, the same decisions `issue()` makes:
325
+ * a transport failure or a retryable status (408, 425, 429, 5xx) is retried
326
+ * until the time budget runs out, a `Retry-After` on 503/429 is honored
327
+ * without counting as an attempt, and any other answer is returned for the
328
+ * caller to read. Safe because a read changes nothing.
329
+ *
330
+ * Returns the response's status, body and `Retry-After`; throws only when it
331
+ * gives up, naming `label` and how long it tried.
332
+ */
333
+ private readWithRetry;
334
+ /**
335
+ * Liveness check. True when the node answers /health with a 2xx.
336
+ *
337
+ * One request, never retried, bounded at 30 s, and it never throws: a
338
+ * transport failure (refused, reset, no answer in time) and an error status
339
+ * both report false. A liveness probe that waited out a restart would report
340
+ * the node alive minutes late instead of reporting it down.
341
+ */
342
+ health(): Promise<boolean>;
343
+ /**
344
+ * Submit a closed submission set for issuance. Returns the node-local
345
+ * operation and its initial state. The happy path is `processing`
346
+ * (finalization is asynchronous); poll [`getOperation`] /
347
+ * [`waitForOperation`].
348
+ *
349
+ * More than `MAX_SUBMISSION_SET_MEMBERS` (64) commitments throw
350
+ * `SubmissionSetTooLargeError` before anything is sent (submission-set/1 §8.1).
351
+ */
352
+ issue(req: IssueRequest): Promise<IssueResponse>;
353
+ /** One POST attempt. Throws on transport error; returns status, body and the
354
+ * node's `Retry-After`. */
355
+ private issueOnce;
356
+ /**
357
+ * A response is FINAL (stop retrying) when every member reached a terminal
358
+ * verdict and there is no whole-request transient failure. A whole-request
359
+ * `submission_failed` (the node could not reach the server) is retryable.
360
+ */
361
+ private isResponseFinal;
362
+ /**
363
+ * Convenience: issue 1..N already-built loose commitments in one call, under a
364
+ * request_id this client generates. The node wraps them into one submission-set. All
365
+ * commitments MUST share issuer + authorization. Use for a batch the
366
+ * caller already has signed on hand (e.g. a nightly import).
367
+ */
368
+ issueCommitments(commitments: LooseCommitment[]): Promise<IssueResponse>;
369
+ /**
370
+ * Activate an integration by redeeming a one-time activation code (OTP, TOFU).
371
+ * The node forwards this to the server's `POST /v1/activate`; the server redeems the
372
+ * code, mints the Level-1 authorization over `holderKeySetRoot`, and returns
373
+ * the signed binding INLINE. The caller (usually `Certcrypt`) caches the
374
+ * returned binding as its `signedLevel1` and stops presenting the code.
375
+ *
376
+ * The SDK talks ONLY to the node; this is the node route, not the server.
377
+ * `rulesVersion` and `systemRootFingerprint` come from the issuer's onboarding
378
+ * config (the server validates the fingerprint matches its own domain).
379
+ */
380
+ activate(params: {
381
+ code: string;
382
+ holderKeySetRoot: string;
383
+ /** A leaf of `holderKeySetRoot` + its inclusion path. Proves the root is ours
384
+ * and not one a transporting node substituted. */
385
+ keySetDisclosure: unknown;
386
+ /** Base64 ML-DSA signature by that leaf over
387
+ * `certcrypt:activate:1|<code>|<holderKeySetRoot>`. */
388
+ keySetPossessionB64: string;
389
+ rulesVersion: string;
390
+ systemRootFingerprint: string;
391
+ validUntil: string;
392
+ }): Promise<ActivationResult>;
393
+ /**
394
+ * Mint + sign one verifiable certificate and its loose commitment WITHOUT
395
+ * sending anything: the ONE place a certificate is minted and signed.
396
+ *
397
+ * Exists so N certificates can be prepared and then submitted in ONE `issue()`
398
+ * request (grouping amortizes the per-submission overhead across all N).
399
+ * Synchronous: no request is made, nothing is awaited.
400
+ *
401
+ * Everything irreversible happens HERE — the base_certificate is signed and
402
+ * `leafIndex`/`operationSalt` are spent. A commitment that is minted and never
403
+ * sent leaves its leaf spent; a retry re-sends this exact commitment rather than
404
+ * minting a new one.
405
+ */
406
+ mintVerifiableCertificate(params: {
407
+ subjects: SubjectInput[];
408
+ issuerKey: IssuerKey;
409
+ target: IssuanceTarget;
410
+ anchor: {
411
+ issued_at: string;
412
+ nonce_hex: string;
413
+ system_id: string;
414
+ rules_version: string;
415
+ };
416
+ signedLevel1: SignedLevel1Binding;
417
+ holderId: string;
418
+ /**
419
+ * The pool to stamp, when the caller resolved it after this client was
420
+ * built (the `Certcrypt` issuer learns it at activation). Defaults to the
421
+ * client's configured `pool_id`. A client configured with a pool refuses any
422
+ * other: one integration is one pool.
423
+ */
424
+ poolId?: string;
425
+ authorizationId: string;
426
+ evidenceFields: {
427
+ consumed_quantity: string;
428
+ declared_effective_units: string;
429
+ issued_at: string;
430
+ expires_at: string;
431
+ };
432
+ keySet: HolderKeySet;
433
+ leafIndex: number;
434
+ operationSalt: Uint8Array;
435
+ }): {
436
+ commitment: LooseCommitment;
437
+ minted: MintedCertificate;
438
+ };
439
+ /**
440
+ * Read one emission by the digest of the capacity evidence that produced it.
441
+ *
442
+ * The lookup that outlives the node. A node's operation id lives in THAT node's
443
+ * journal, so a restart with an in-memory journal — or moving to another node,
444
+ * which the model treats as changing a URL — leaves the issuer unable to ask
445
+ * about an emission the issuance service still holds. The digest has no such
446
+ * problem: the issuer recomputes it from evidence it signed itself.
447
+ *
448
+ * The read chain is unchanged, and the signed resource is the digest. That is
449
+ * stronger than signing an id the node handed over: the issuer can check what
450
+ * the digest means, because it produced it.
451
+ */
452
+ getEmissionByCommitment(independenceRef: string): Promise<EmissionHandleRecord>;
453
+ /**
454
+ * This integration's submissions the node gave up delivering (dead-lettered).
455
+ *
456
+ * A node keeps retrying an unreachable or unavailable server for as long as
457
+ * it takes; what lands here is a refusal about the request or the node's own
458
+ * credentials, which retrying unchanged cannot fix. Empty is the healthy
459
+ * answer. Delivery metadata only — never the stored set.
460
+ */
461
+ listDeadLetters(): Promise<DeadLetter[]>;
462
+ /**
463
+ * Put one dead-lettered submission back in the node's delivery queue, once
464
+ * whatever refused it has been fixed. The node resends the SAME signed set
465
+ * under the same `request_id` — nothing is re-signed, and the server
466
+ * deduplicates. Throws 404 for an id this integration does not own.
467
+ */
468
+ redriveDeadLetter(requestId: string): Promise<void>;
469
+ /**
470
+ * Fetch the current state of a node-local operation. Retried under the
471
+ * transport-retry policy, like every read; a 404 (unknown id) is not.
472
+ */
473
+ getOperation(operationId: string): Promise<OperationRecord>;
474
+ /** One operation read; `retry` false sends exactly one request (the wait loop
475
+ * owns its own retrying). */
476
+ private readOperation;
477
+ /**
478
+ * List the emissions this integration has in flight — neither independently
479
+ * verifiable yet nor terminally refused.
480
+ *
481
+ * `getOperation` requires an id, and an issuer that lost its handles lost the
482
+ * ids with them: they travel only in the emission response. This endpoint lets
483
+ * such an issuer enumerate its in-flight emissions instead of re-emitting,
484
+ * which would open a second node operation for the same certificate — the
485
+ * outcome the handle exists to prevent.
486
+ *
487
+ * Scope is this integration, resolved upstream from the key-set root proven by
488
+ * the read chain, not from any credential of the node that relays it.
489
+ *
490
+ * The response carries no handle material. Each entry states what exists and
491
+ * when to poll again; fetch the recoverable half one emission at a time.
492
+ *
493
+ * `truncated` means the page hit the server cap: narrow `since` rather than
494
+ * treat the list as complete. A reconciler needs to distinguish a full listing
495
+ * from a first page.
496
+ */
497
+ listUnresolvedEmissions(since: string, limit?: number): Promise<UnresolvedEmissions>;
498
+ /**
499
+ * Poll an operation until it reaches a terminal state (independent_ready,
500
+ * rejected, expired, replay_detected, insufficient_capacity,
501
+ * pre_evaluation_rejected, submission_failed), or throw.
502
+ *
503
+ * When the wait ends without one — attempts or `maxWaitMs` exhausted — this
504
+ * throws `CertcryptNodeError` ("did not reach a terminal state"): the
505
+ * operation is still progressing and the caller's handle stays valid, so poll
506
+ * again later. A transient poll failure does not abort the wait; five
507
+ * consecutive ones do, and a 404 (unknown id) surfaces at once. A node that
508
+ * asks for a pause (503 or 429 with `Retry-After`) is waited out without
509
+ * counting it as a failure. Each poll is one request, and time is read from
510
+ * the client's clock.
511
+ */
512
+ waitForOperation(operationId: string, opts?: WaitOptions): Promise<OperationRecord>;
513
+ /**
514
+ * Assemble the full `verification-package/1` for one operation so the issuer
515
+ * can verify its OWN Proof of Independence OFFLINE (dogfooding). No new node
516
+ * surface: the node is a non-custodian and never returns base_certificate /
517
+ * capacity_evidence / the commitment inclusion proof. This gathers:
518
+ * - base_certificate + capacity_evidence — client-held (passed in);
519
+ * - independence_proof + settlement_material — from GET /v1/operations/{id}
520
+ * once independent_ready (base64 → parsed JSON);
521
+ * - commitment_inclusion_proof — DERIVED locally from the proof's
522
+ * `consumed_commitment_ids` + this commitment's index (same Merkle
523
+ * primitive the verifier recomputes).
524
+ *
525
+ * Throws if the operation is not `independent_ready`, if the server artifacts are
526
+ * missing, or if the proof lacks `consumed_commitment_ids`.
527
+ */
528
+ buildVerificationPackage(operationId: string, opts: BuildPackageOptions): Promise<VerificationPackage>;
529
+ /**
530
+ * Assemble a `verification_package` from artifacts already in hand.
531
+ *
532
+ * Same shaping as `buildVerificationPackage`, without the polling: the caller
533
+ * recovered the proof and the settlement material some other way — by the
534
+ * capacity-evidence digest, typically, when the node that emitted no longer has
535
+ * the operation.
536
+ *
537
+ * The package is identical either way. Nothing here is node-supplied: the
538
+ * inclusion proof is derived from the proof's own `consumed_commitment_ids`, and
539
+ * the rest comes from the handle the issuer kept.
540
+ */
541
+ assembleVerificationPackageFromProof(opts: {
542
+ independenceProofB64: string;
543
+ settlementMaterialB64: string;
544
+ baseCertificate: unknown;
545
+ capacityEvidence: unknown;
546
+ verificationContext: {
547
+ rules_version: string;
548
+ system_id: string;
549
+ };
550
+ commitmentIndex: number;
551
+ }): VerificationPackage;
552
+ }