@peac/protocol 0.10.6 → 0.10.8

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.
@@ -0,0 +1,135 @@
1
+ /**
2
+ * PEAC Verification Report Builder
3
+ *
4
+ * Constructs deterministic verification reports per VERIFICATION-REPORT-FORMAT.md.
5
+ * Reports are designed to be portable, deterministic, safe, and policy-aware.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { CheckId, CheckStatus, ReasonCode, VerificationMeta, VerificationReport, VerifierPolicy } from './verifier-types.js';
10
+ /**
11
+ * Verification Report Builder
12
+ *
13
+ * Builds verification reports with proper check ordering and short-circuit behavior.
14
+ * Ensures reports conform to VERIFICATION-REPORT-FORMAT.md requirements.
15
+ *
16
+ * Shape-stable: Always emits all checks with pass/fail/skip status.
17
+ */
18
+ export declare class VerificationReportBuilder {
19
+ private state;
20
+ constructor(policy: VerifierPolicy);
21
+ /**
22
+ * Set the input descriptor with pre-computed digest
23
+ *
24
+ * Use this when you've already computed the SHA-256 hash.
25
+ *
26
+ * @param digestHex - SHA-256 digest as lowercase hex (64 chars)
27
+ * @param type - Input type
28
+ */
29
+ setInputWithDigest(digestHex: string, type?: 'receipt_jws' | 'bundle_entry'): this;
30
+ /**
31
+ * Set the input descriptor (async - computes SHA-256)
32
+ *
33
+ * @param receiptBytes - Raw receipt bytes
34
+ * @param type - Input type
35
+ */
36
+ setInputAsync(receiptBytes: Uint8Array, type?: 'receipt_jws' | 'bundle_entry'): Promise<this>;
37
+ /**
38
+ * Add a check result
39
+ *
40
+ * Checks can be added in any order; they will be sorted in build().
41
+ * If a previous check failed, subsequent checks should be marked as skip.
42
+ */
43
+ addCheck(id: CheckId, status: CheckStatus, detail?: Record<string, unknown>, errorCode?: string): this;
44
+ /**
45
+ * Add a passing check
46
+ */
47
+ pass(id: CheckId, detail?: Record<string, unknown>): this;
48
+ /**
49
+ * Add a failing check
50
+ */
51
+ fail(id: CheckId, errorCode: string, detail?: Record<string, unknown>): this;
52
+ /**
53
+ * Add a skipped check
54
+ */
55
+ skip(id: CheckId, detail?: Record<string, unknown>): this;
56
+ /**
57
+ * Set the final result
58
+ */
59
+ setResult(valid: boolean, reason: ReasonCode, options?: {
60
+ issuer?: string;
61
+ kid?: string;
62
+ receiptType?: string;
63
+ }): this;
64
+ /**
65
+ * Set success result
66
+ */
67
+ success(issuer: string, kid: string): this;
68
+ /**
69
+ * Set failure result
70
+ */
71
+ failure(reason: ReasonCode, issuer?: string, kid?: string): this;
72
+ /**
73
+ * Add artifacts
74
+ */
75
+ addArtifact(key: string, value: unknown): this;
76
+ /**
77
+ * Set metadata (non-deterministic fields)
78
+ */
79
+ setMeta(meta: VerificationMeta): this;
80
+ /**
81
+ * Add current timestamp to meta
82
+ */
83
+ addTimestamp(): this;
84
+ /**
85
+ * Build the final report
86
+ *
87
+ * Ensures all checks are present (shape-stable).
88
+ * Missing checks after a failure are marked as 'skip'.
89
+ * Missing checks before a failure (or in success) are marked as 'pass'.
90
+ */
91
+ build(): VerificationReport;
92
+ /**
93
+ * Build in deterministic mode (excludes meta and non-deterministic artifacts)
94
+ *
95
+ * Deterministic mode ensures that the same inputs and policy always produce
96
+ * the same report output, regardless of cache state or timing.
97
+ *
98
+ * Excludes:
99
+ * - `meta`: Contains timestamps and verifier info
100
+ * - Non-deterministic artifacts: `issuer_jwks_digest` (depends on cache state)
101
+ *
102
+ * @returns Report without meta and with only deterministic artifacts
103
+ */
104
+ buildDeterministic(): Omit<VerificationReport, 'meta'>;
105
+ }
106
+ /**
107
+ * Create a new report builder
108
+ */
109
+ export declare function createReportBuilder(policy: VerifierPolicy): VerificationReportBuilder;
110
+ /**
111
+ * Compute receipt digest for report input
112
+ *
113
+ * @param receiptBytes - Raw receipt bytes (JWS string as UTF-8)
114
+ * @returns SHA-256 digest as lowercase hex (64 chars)
115
+ */
116
+ export declare function computeReceiptDigest(receiptBytes: Uint8Array | string): Promise<string>;
117
+ /**
118
+ * Build a quick failure report without going through all checks
119
+ *
120
+ * Useful for early failures like receipt_too_large or malformed_receipt
121
+ * where most checks are skipped.
122
+ */
123
+ export declare function buildFailureReport(policy: VerifierPolicy, receiptBytes: Uint8Array | string, reason: ReasonCode, failedCheckId: CheckId, errorCode?: string, detail?: Record<string, unknown>, options?: {
124
+ issuer?: string;
125
+ kid?: string;
126
+ meta?: VerificationMeta;
127
+ }): Promise<VerificationReport>;
128
+ /**
129
+ * Build a success report
130
+ */
131
+ export declare function buildSuccessReport(policy: VerifierPolicy, receiptBytes: Uint8Array | string, issuer: string, kid: string, checkDetails?: Partial<Record<CheckId, Record<string, unknown>>>, options?: {
132
+ artifacts?: VerificationReport['artifacts'];
133
+ meta?: VerificationMeta;
134
+ }): Promise<VerificationReport>;
135
+ //# sourceMappingURL=verification-report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification-report.d.ts","sourceRoot":"","sources":["../src/verification-report.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACV,OAAO,EAEP,WAAW,EAEX,UAAU,EAGV,gBAAgB,EAChB,kBAAkB,EAElB,cAAc,EACf,MAAM,qBAAqB,CAAC;AAwB7B;;;;;;;GAOG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,KAAK,CAAqB;gBAEtB,MAAM,EAAE,cAAc;IAQlC;;;;;;;OAOG;IACH,kBAAkB,CAChB,SAAS,EAAE,MAAM,EACjB,IAAI,GAAE,aAAa,GAAG,cAA8B,GACnD,IAAI;IASP;;;;;OAKG;IACG,aAAa,CACjB,YAAY,EAAE,UAAU,EACxB,IAAI,GAAE,aAAa,GAAG,cAA8B,GACnD,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;;OAKG;IACH,QAAQ,CACN,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,WAAW,EACnB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI;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ACH,wBAAsB,oBAAoB,CAAC,YAAY,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAI7F;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,UAAU,GAAG,MAAM,EACjC,MAAM,EAAE,UAAU,EAClB,aAAa,EAAE,OAAO,EACtB,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,CAAC,EAAE;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,gBAAgB,CAAC;CACzB,GACA,OAAO,CAAC,kBAAkB,CAAC,CA0B7B;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,UAAU,GAAG,MAAM,EACjC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAChE,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAC5C,IAAI,CAAC,EAAE,gBAAgB,CAAC;CACzB,GACA,OAAO,CAAC,kBAAkB,CAAC,CAsC7B"}
@@ -0,0 +1,322 @@
1
+ "use strict";
2
+ /**
3
+ * PEAC Verification Report Builder
4
+ *
5
+ * Constructs deterministic verification reports per VERIFICATION-REPORT-FORMAT.md.
6
+ * Reports are designed to be portable, deterministic, safe, and policy-aware.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.VerificationReportBuilder = void 0;
12
+ exports.createReportBuilder = createReportBuilder;
13
+ exports.computeReceiptDigest = computeReceiptDigest;
14
+ exports.buildFailureReport = buildFailureReport;
15
+ exports.buildSuccessReport = buildSuccessReport;
16
+ const crypto_1 = require("@peac/crypto");
17
+ const kernel_1 = require("@peac/kernel");
18
+ const verifier_types_js_1 = require("./verifier-types.js");
19
+ /**
20
+ * Verification Report Builder
21
+ *
22
+ * Builds verification reports with proper check ordering and short-circuit behavior.
23
+ * Ensures reports conform to VERIFICATION-REPORT-FORMAT.md requirements.
24
+ *
25
+ * Shape-stable: Always emits all checks with pass/fail/skip status.
26
+ */
27
+ class VerificationReportBuilder {
28
+ state;
29
+ constructor(policy) {
30
+ this.state = {
31
+ policy,
32
+ checks: new Map(),
33
+ shortCircuited: false,
34
+ };
35
+ }
36
+ /**
37
+ * Set the input descriptor with pre-computed digest
38
+ *
39
+ * Use this when you've already computed the SHA-256 hash.
40
+ *
41
+ * @param digestHex - SHA-256 digest as lowercase hex (64 chars)
42
+ * @param type - Input type
43
+ */
44
+ setInputWithDigest(digestHex, type = 'receipt_jws') {
45
+ this.state.receiptDigestHex = digestHex;
46
+ this.state.input = {
47
+ type,
48
+ receipt_digest: (0, verifier_types_js_1.createDigest)(digestHex),
49
+ };
50
+ return this;
51
+ }
52
+ /**
53
+ * Set the input descriptor (async - computes SHA-256)
54
+ *
55
+ * @param receiptBytes - Raw receipt bytes
56
+ * @param type - Input type
57
+ */
58
+ async setInputAsync(receiptBytes, type = 'receipt_jws') {
59
+ const digestHex = await (0, crypto_1.sha256Hex)(receiptBytes);
60
+ return this.setInputWithDigest(digestHex, type);
61
+ }
62
+ /**
63
+ * Add a check result
64
+ *
65
+ * Checks can be added in any order; they will be sorted in build().
66
+ * If a previous check failed, subsequent checks should be marked as skip.
67
+ */
68
+ addCheck(id, status, detail, errorCode) {
69
+ const check = { id, status };
70
+ if (detail && Object.keys(detail).length > 0) {
71
+ check.detail = detail;
72
+ }
73
+ if (errorCode) {
74
+ check.error_code = errorCode;
75
+ }
76
+ this.state.checks.set(id, check);
77
+ // Track short-circuit on failure
78
+ if (status === 'fail' && !this.state.shortCircuited) {
79
+ this.state.shortCircuited = true;
80
+ this.state.failedAtCheck = id;
81
+ }
82
+ return this;
83
+ }
84
+ /**
85
+ * Add a passing check
86
+ */
87
+ pass(id, detail) {
88
+ return this.addCheck(id, 'pass', detail);
89
+ }
90
+ /**
91
+ * Add a failing check
92
+ */
93
+ fail(id, errorCode, detail) {
94
+ return this.addCheck(id, 'fail', detail, errorCode);
95
+ }
96
+ /**
97
+ * Add a skipped check
98
+ */
99
+ skip(id, detail) {
100
+ return this.addCheck(id, 'skip', detail);
101
+ }
102
+ /**
103
+ * Set the final result
104
+ */
105
+ setResult(valid, reason, options) {
106
+ this.state.result = {
107
+ valid,
108
+ reason,
109
+ severity: (0, verifier_types_js_1.reasonCodeToSeverity)(reason),
110
+ receipt_type: options?.receiptType ?? kernel_1.WIRE_TYPE,
111
+ ...(options?.issuer && { issuer: options.issuer }),
112
+ ...(options?.kid && { kid: options.kid }),
113
+ };
114
+ return this;
115
+ }
116
+ /**
117
+ * Set success result
118
+ */
119
+ success(issuer, kid) {
120
+ return this.setResult(true, 'ok', { issuer, kid });
121
+ }
122
+ /**
123
+ * Set failure result
124
+ */
125
+ failure(reason, issuer, kid) {
126
+ return this.setResult(false, reason, { issuer, kid });
127
+ }
128
+ /**
129
+ * Add artifacts
130
+ */
131
+ addArtifact(key, value) {
132
+ if (!this.state.artifacts) {
133
+ this.state.artifacts = {};
134
+ }
135
+ this.state.artifacts[key] = value;
136
+ return this;
137
+ }
138
+ /**
139
+ * Set metadata (non-deterministic fields)
140
+ */
141
+ setMeta(meta) {
142
+ this.state.meta = meta;
143
+ return this;
144
+ }
145
+ /**
146
+ * Add current timestamp to meta
147
+ */
148
+ addTimestamp() {
149
+ if (!this.state.meta) {
150
+ this.state.meta = {};
151
+ }
152
+ this.state.meta.generated_at = new Date().toISOString();
153
+ return this;
154
+ }
155
+ /**
156
+ * Build the final report
157
+ *
158
+ * Ensures all checks are present (shape-stable).
159
+ * Missing checks after a failure are marked as 'skip'.
160
+ * Missing checks before a failure (or in success) are marked as 'pass'.
161
+ */
162
+ build() {
163
+ // Validate required fields
164
+ if (!this.state.input) {
165
+ throw new Error('Input is required. Call setInputWithDigest() or setInputAsync() first.');
166
+ }
167
+ if (!this.state.result) {
168
+ throw new Error('Result is required. Call setResult() or success()/failure() first.');
169
+ }
170
+ // Build shape-stable checks array
171
+ const checks = [];
172
+ const failedIndex = this.state.failedAtCheck ? verifier_types_js_1.CHECK_IDS.indexOf(this.state.failedAtCheck) : -1;
173
+ for (let i = 0; i < verifier_types_js_1.CHECK_IDS.length; i++) {
174
+ const checkId = verifier_types_js_1.CHECK_IDS[i];
175
+ const existing = this.state.checks.get(checkId);
176
+ if (existing) {
177
+ checks.push(existing);
178
+ }
179
+ else if (this.state.shortCircuited && i > failedIndex) {
180
+ // After failure, missing checks are skipped
181
+ checks.push({ id: checkId, status: 'skip', detail: { reason: 'short_circuit' } });
182
+ }
183
+ else {
184
+ // Before failure or in success, missing checks get default status
185
+ // For optional checks like transport.profile_binding, mark as skip
186
+ if (checkId === 'transport.profile_binding') {
187
+ checks.push({ id: checkId, status: 'skip', detail: { reason: 'not_applicable' } });
188
+ }
189
+ else {
190
+ // This shouldn't happen in well-formed builds - indicates a bug
191
+ checks.push({ id: checkId, status: 'skip', detail: { reason: 'not_executed' } });
192
+ }
193
+ }
194
+ }
195
+ const report = {
196
+ report_version: kernel_1.VERIFICATION_REPORT_VERSION,
197
+ input: this.state.input,
198
+ policy: this.state.policy,
199
+ result: this.state.result,
200
+ checks,
201
+ };
202
+ if (this.state.artifacts && Object.keys(this.state.artifacts).length > 0) {
203
+ report.artifacts = this.state.artifacts;
204
+ }
205
+ if (this.state.meta) {
206
+ report.meta = this.state.meta;
207
+ }
208
+ return report;
209
+ }
210
+ /**
211
+ * Build in deterministic mode (excludes meta and non-deterministic artifacts)
212
+ *
213
+ * Deterministic mode ensures that the same inputs and policy always produce
214
+ * the same report output, regardless of cache state or timing.
215
+ *
216
+ * Excludes:
217
+ * - `meta`: Contains timestamps and verifier info
218
+ * - Non-deterministic artifacts: `issuer_jwks_digest` (depends on cache state)
219
+ *
220
+ * @returns Report without meta and with only deterministic artifacts
221
+ */
222
+ buildDeterministic() {
223
+ const report = this.build();
224
+ const { meta: _meta, ...deterministic } = report;
225
+ // Filter out non-deterministic artifacts
226
+ if (deterministic.artifacts) {
227
+ const filteredArtifacts = { ...deterministic.artifacts };
228
+ for (const key of verifier_types_js_1.NON_DETERMINISTIC_ARTIFACT_KEYS) {
229
+ delete filteredArtifacts[key];
230
+ }
231
+ // Remove artifacts object if empty after filtering
232
+ if (Object.keys(filteredArtifacts).length === 0) {
233
+ delete deterministic.artifacts;
234
+ }
235
+ else {
236
+ deterministic.artifacts = filteredArtifacts;
237
+ }
238
+ }
239
+ return deterministic;
240
+ }
241
+ }
242
+ exports.VerificationReportBuilder = VerificationReportBuilder;
243
+ /**
244
+ * Create a new report builder
245
+ */
246
+ function createReportBuilder(policy) {
247
+ return new VerificationReportBuilder(policy);
248
+ }
249
+ /**
250
+ * Compute receipt digest for report input
251
+ *
252
+ * @param receiptBytes - Raw receipt bytes (JWS string as UTF-8)
253
+ * @returns SHA-256 digest as lowercase hex (64 chars)
254
+ */
255
+ async function computeReceiptDigest(receiptBytes) {
256
+ const bytes = typeof receiptBytes === 'string' ? new TextEncoder().encode(receiptBytes) : receiptBytes;
257
+ return (0, crypto_1.sha256Hex)(bytes);
258
+ }
259
+ /**
260
+ * Build a quick failure report without going through all checks
261
+ *
262
+ * Useful for early failures like receipt_too_large or malformed_receipt
263
+ * where most checks are skipped.
264
+ */
265
+ async function buildFailureReport(policy, receiptBytes, reason, failedCheckId, errorCode, detail, options) {
266
+ const bytes = typeof receiptBytes === 'string' ? new TextEncoder().encode(receiptBytes) : receiptBytes;
267
+ const digestHex = await (0, crypto_1.sha256Hex)(bytes);
268
+ const builder = createReportBuilder(policy)
269
+ .setInputWithDigest(digestHex)
270
+ .failure(reason, options?.issuer, options?.kid);
271
+ // Add passing checks up to the failure point
272
+ const failedIndex = verifier_types_js_1.CHECK_IDS.indexOf(failedCheckId);
273
+ for (let i = 0; i < verifier_types_js_1.CHECK_IDS.length; i++) {
274
+ const checkId = verifier_types_js_1.CHECK_IDS[i];
275
+ if (i < failedIndex) {
276
+ builder.pass(checkId);
277
+ }
278
+ else if (i === failedIndex) {
279
+ builder.fail(checkId, errorCode ?? (0, verifier_types_js_1.reasonCodeToErrorCode)(reason), detail);
280
+ }
281
+ // Remaining checks will be auto-skipped by build()
282
+ }
283
+ if (options?.meta) {
284
+ builder.setMeta(options.meta);
285
+ }
286
+ return builder.build();
287
+ }
288
+ /**
289
+ * Build a success report
290
+ */
291
+ async function buildSuccessReport(policy, receiptBytes, issuer, kid, checkDetails, options) {
292
+ const bytes = typeof receiptBytes === 'string' ? new TextEncoder().encode(receiptBytes) : receiptBytes;
293
+ const digestHex = await (0, crypto_1.sha256Hex)(bytes);
294
+ const builder = createReportBuilder(policy).setInputWithDigest(digestHex).success(issuer, kid);
295
+ // Add all checks as passing (except optional ones)
296
+ for (const checkId of verifier_types_js_1.CHECK_IDS) {
297
+ // Skip issuer.discovery for offline mode
298
+ if (checkId === 'issuer.discovery' && policy.mode === 'offline_only') {
299
+ builder.skip(checkId, { reason: 'offline_mode' });
300
+ continue;
301
+ }
302
+ // transport.profile_binding is optional
303
+ if (checkId === 'transport.profile_binding') {
304
+ if (checkDetails?.[checkId]) {
305
+ builder.pass(checkId, checkDetails[checkId]);
306
+ }
307
+ // Will be marked as skip by build() if not added
308
+ continue;
309
+ }
310
+ builder.pass(checkId, checkDetails?.[checkId]);
311
+ }
312
+ if (options?.artifacts) {
313
+ for (const [key, value] of Object.entries(options.artifacts)) {
314
+ builder.addArtifact(key, value);
315
+ }
316
+ }
317
+ if (options?.meta) {
318
+ builder.setMeta(options.meta);
319
+ }
320
+ return builder.build();
321
+ }
322
+ //# sourceMappingURL=verification-report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification-report.js","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,cAAc,EAAE,CAAC,CAAC;YAClD,SAAS;QACX,CAAC;QAED,wCAAwC;QACxC,IAAI,OAAO,KAAK,2BAA2B,EAAE,CAAC;YAC5C,IAAI,YAAY,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;YAC/C,CAAC;YACD,iDAAiD;YACjD,SAAS;QACX,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,OAAO,EAAE,SAAS,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAC7D,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * PEAC Verifier Core
3
+ *
4
+ * Implements the verification flow per VERIFIER-SECURITY-MODEL.md with:
5
+ * - Ordered checks with short-circuit behavior
6
+ * - Trust pinning (issuer allowlist + RFC 7638 thumbprints)
7
+ * - SSRF-safe network fetches
8
+ * - Deterministic verification reports
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ import { PEACReceiptClaims } from '@peac/schema';
13
+ import type { VerificationReport, VerifierPolicy } from './verifier-types.js';
14
+ /**
15
+ * Verification options for verifier-core
16
+ */
17
+ export interface VerifyCoreOptions {
18
+ /** Receipt JWS (compact serialization) or raw bytes */
19
+ receipt: string | Uint8Array;
20
+ /** Verification policy */
21
+ policy?: VerifierPolicy;
22
+ /** Reference time for deterministic verification (seconds since epoch) */
23
+ referenceTime?: number;
24
+ /** Include non-deterministic metadata in report */
25
+ includeMeta?: boolean;
26
+ }
27
+ /**
28
+ * Verification result
29
+ */
30
+ export interface VerifyCoreResult {
31
+ /** Whether verification succeeded */
32
+ valid: boolean;
33
+ /** Verification report */
34
+ report: VerificationReport;
35
+ /** Parsed claims (if valid) */
36
+ claims?: PEACReceiptClaims;
37
+ }
38
+ /**
39
+ * Verify a PEAC receipt with full security checks and report emission
40
+ *
41
+ * Implements the verification flow per VERIFIER-SECURITY-MODEL.md:
42
+ * 1. jws.parse - Parse JWS structure
43
+ * 2. limits.receipt_bytes - Check receipt size
44
+ * 3. jws.protected_header - Validate protected header
45
+ * 4. claims.schema_unverified - Pre-signature schema check
46
+ * 5. issuer.trust_policy - Check issuer allowlist/pins
47
+ * 6. issuer.discovery - Fetch JWKS (if network mode)
48
+ * 7. key.resolve - Resolve signing key by kid
49
+ * 8. jws.signature - Verify signature
50
+ * 9. claims.time_window - Check iat/exp
51
+ * 10. extensions.limits - Check extension sizes
52
+ */
53
+ export declare function verifyReceiptCore(options: VerifyCoreOptions): Promise<VerifyCoreResult>;
54
+ /**
55
+ * Clear the JWKS cache
56
+ */
57
+ export declare function clearJWKSCache(): void;
58
+ /**
59
+ * Get JWKS cache size (for testing)
60
+ */
61
+ export declare function getJWKSCacheSize(): number;
62
+ //# sourceMappingURL=verifier-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifier-core.d.ts","sourceRoot":"","sources":["../src/verifier-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAWH,OAAO,EAAE,iBAAiB,EAAiB,MAAM,cAAc,CAAC;AAIhE,OAAO,KAAK,EAAa,kBAAkB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAqCzF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,0BAA0B;IAC1B,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,0EAA0E;IAC1E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mDAAmD;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qCAAqC;IACrC,KAAK,EAAE,OAAO,CAAC;IACf,0BAA0B;IAC1B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,+BAA+B;IAC/B,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B;AAmLD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAob7F;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC"}