@peac/audit 0.10.9

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,111 @@
1
+ /**
2
+ * JSONL Formatting and Parsing (v0.9.27+)
3
+ *
4
+ * JSONL (JSON Lines) is the normative format for PEAC audit logs.
5
+ * Each line is a complete, valid JSON object representing one audit entry.
6
+ *
7
+ * @see https://jsonlines.org/
8
+ */
9
+ import type { AuditEntry, JsonlOptions, JsonlParseOptions } from './types.js';
10
+ /**
11
+ * Format an audit entry to a single JSONL line.
12
+ *
13
+ * @param entry - Audit entry to format
14
+ * @param options - Formatting options
15
+ * @returns JSON string (single line unless pretty=true)
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const line = formatJsonlLine(entry);
20
+ * // '{"version":"peac.audit/0.9","id":"01ARZ...","event_type":"receipt_issued",...}'
21
+ * ```
22
+ */
23
+ export declare function formatJsonlLine(entry: AuditEntry, options?: JsonlOptions): string;
24
+ /**
25
+ * Format multiple audit entries to JSONL format.
26
+ *
27
+ * @param entries - Array of audit entries
28
+ * @param options - Formatting options
29
+ * @returns JSONL string (one entry per line)
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const jsonl = formatJsonl(entries);
34
+ * // '{"version":"peac.audit/0.9",...}\n{"version":"peac.audit/0.9",...}'
35
+ * ```
36
+ */
37
+ export declare function formatJsonl(entries: AuditEntry[], options?: JsonlOptions): string;
38
+ /**
39
+ * Parse result for a single JSONL line.
40
+ */
41
+ export interface JsonlParseLineResult {
42
+ ok: true;
43
+ entry: AuditEntry;
44
+ lineNumber: number;
45
+ }
46
+ /**
47
+ * Parse error for a single JSONL line.
48
+ */
49
+ export interface JsonlParseLineError {
50
+ ok: false;
51
+ error: string;
52
+ lineNumber: number;
53
+ raw?: string;
54
+ }
55
+ /**
56
+ * Parse a single JSONL line.
57
+ *
58
+ * @param line - JSON string to parse
59
+ * @param lineNumber - Line number for error reporting
60
+ * @returns Parse result with entry or error
61
+ */
62
+ export declare function parseJsonlLine(line: string, lineNumber?: number): JsonlParseLineResult | JsonlParseLineError;
63
+ /**
64
+ * Parse result for JSONL content.
65
+ */
66
+ export interface JsonlParseResult {
67
+ /** Successfully parsed entries */
68
+ entries: AuditEntry[];
69
+ /** Parse errors (if skipInvalid=true) */
70
+ errors: JsonlParseLineError[];
71
+ /** Total lines processed */
72
+ totalLines: number;
73
+ /** Lines successfully parsed */
74
+ successCount: number;
75
+ /** Lines that failed to parse */
76
+ errorCount: number;
77
+ }
78
+ /**
79
+ * Parse JSONL content to audit entries.
80
+ *
81
+ * @param content - JSONL string content
82
+ * @param options - Parsing options
83
+ * @returns Parse result with entries and errors
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const result = parseJsonl(jsonlContent, { skipInvalid: true });
88
+ * console.log(`Parsed ${result.successCount}/${result.totalLines} entries`);
89
+ * ```
90
+ */
91
+ export declare function parseJsonl(content: string, options?: JsonlParseOptions): JsonlParseResult;
92
+ /**
93
+ * Stream-friendly JSONL line appender.
94
+ *
95
+ * Creates a function that appends audit entries to a string buffer
96
+ * in JSONL format, suitable for streaming to files or network.
97
+ *
98
+ * @param options - Formatting options
99
+ * @returns Appender function
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const appender = createJsonlAppender();
104
+ * for (const entry of entries) {
105
+ * const line = appender(entry);
106
+ * await stream.write(line);
107
+ * }
108
+ * ```
109
+ */
110
+ export declare function createJsonlAppender(options?: JsonlOptions): (entry: AuditEntry) => string;
111
+ //# sourceMappingURL=jsonl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonl.d.ts","sourceRoot":"","sources":["../src/jsonl.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG9E;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,OA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* JSONL (JSON Lines) is the normative format for PEAC audit logs.
6
+ * Each line is a complete, valid JSON object representing one audit entry.
7
+ *
8
+ * @see https://jsonlines.org/
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.formatJsonlLine = formatJsonlLine;
12
+ exports.formatJsonl = formatJsonl;
13
+ exports.parseJsonlLine = parseJsonlLine;
14
+ exports.parseJsonl = parseJsonl;
15
+ exports.createJsonlAppender = createJsonlAppender;
16
+ const entry_js_1 = require("./entry.js");
17
+ /**
18
+ * Format an audit entry to a single JSONL line.
19
+ *
20
+ * @param entry - Audit entry to format
21
+ * @param options - Formatting options
22
+ * @returns JSON string (single line unless pretty=true)
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const line = formatJsonlLine(entry);
27
+ * // '{"version":"peac.audit/0.9","id":"01ARZ...","event_type":"receipt_issued",...}'
28
+ * ```
29
+ */
30
+ function formatJsonlLine(entry, options) {
31
+ if (options?.pretty) {
32
+ return JSON.stringify(entry, null, 2);
33
+ }
34
+ return JSON.stringify(entry);
35
+ }
36
+ /**
37
+ * Format multiple audit entries to JSONL format.
38
+ *
39
+ * @param entries - Array of audit entries
40
+ * @param options - Formatting options
41
+ * @returns JSONL string (one entry per line)
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const jsonl = formatJsonl(entries);
46
+ * // '{"version":"peac.audit/0.9",...}\n{"version":"peac.audit/0.9",...}'
47
+ * ```
48
+ */
49
+ function formatJsonl(entries, options) {
50
+ const lines = entries.map((entry) => formatJsonlLine(entry, { pretty: false }));
51
+ const result = lines.join('\n');
52
+ if (options?.trailingNewline && result.length > 0) {
53
+ return result + '\n';
54
+ }
55
+ return result;
56
+ }
57
+ /**
58
+ * Parse a single JSONL line.
59
+ *
60
+ * @param line - JSON string to parse
61
+ * @param lineNumber - Line number for error reporting
62
+ * @returns Parse result with entry or error
63
+ */
64
+ function parseJsonlLine(line, lineNumber = 1) {
65
+ const trimmed = line.trim();
66
+ // Skip empty lines
67
+ if (trimmed.length === 0) {
68
+ return {
69
+ ok: false,
70
+ error: 'Empty line',
71
+ lineNumber,
72
+ };
73
+ }
74
+ try {
75
+ const parsed = JSON.parse(trimmed);
76
+ if (!(0, entry_js_1.isValidAuditEntry)(parsed)) {
77
+ return {
78
+ ok: false,
79
+ error: 'Invalid audit entry structure',
80
+ lineNumber,
81
+ raw: trimmed.length > 100 ? trimmed.substring(0, 100) + '...' : trimmed,
82
+ };
83
+ }
84
+ return {
85
+ ok: true,
86
+ entry: parsed,
87
+ lineNumber,
88
+ };
89
+ }
90
+ catch (e) {
91
+ return {
92
+ ok: false,
93
+ error: e instanceof Error ? e.message : 'JSON parse error',
94
+ lineNumber,
95
+ raw: trimmed.length > 100 ? trimmed.substring(0, 100) + '...' : trimmed,
96
+ };
97
+ }
98
+ }
99
+ /**
100
+ * Parse JSONL content to audit entries.
101
+ *
102
+ * @param content - JSONL string content
103
+ * @param options - Parsing options
104
+ * @returns Parse result with entries and errors
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const result = parseJsonl(jsonlContent, { skipInvalid: true });
109
+ * console.log(`Parsed ${result.successCount}/${result.totalLines} entries`);
110
+ * ```
111
+ */
112
+ function parseJsonl(content, options) {
113
+ const lines = content.split('\n');
114
+ const entries = [];
115
+ const errors = [];
116
+ const maxLines = options?.maxLines ?? 0;
117
+ let processed = 0;
118
+ for (let i = 0; i < lines.length; i++) {
119
+ const line = lines[i];
120
+ const lineNumber = i + 1;
121
+ // Skip empty lines
122
+ if (line.trim().length === 0) {
123
+ continue;
124
+ }
125
+ // Check max lines limit
126
+ if (maxLines > 0 && processed >= maxLines) {
127
+ break;
128
+ }
129
+ processed++;
130
+ const result = parseJsonlLine(line, lineNumber);
131
+ if (result.ok) {
132
+ entries.push(result.entry);
133
+ }
134
+ else {
135
+ if (options?.skipInvalid) {
136
+ errors.push(result);
137
+ }
138
+ else {
139
+ // Return immediately on first error if not skipping
140
+ return {
141
+ entries,
142
+ errors: [result],
143
+ totalLines: processed,
144
+ successCount: entries.length,
145
+ errorCount: 1,
146
+ };
147
+ }
148
+ }
149
+ }
150
+ return {
151
+ entries,
152
+ errors,
153
+ totalLines: processed,
154
+ successCount: entries.length,
155
+ errorCount: errors.length,
156
+ };
157
+ }
158
+ /**
159
+ * Stream-friendly JSONL line appender.
160
+ *
161
+ * Creates a function that appends audit entries to a string buffer
162
+ * in JSONL format, suitable for streaming to files or network.
163
+ *
164
+ * @param options - Formatting options
165
+ * @returns Appender function
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const appender = createJsonlAppender();
170
+ * for (const entry of entries) {
171
+ * const line = appender(entry);
172
+ * await stream.write(line);
173
+ * }
174
+ * ```
175
+ */
176
+ function createJsonlAppender(options) {
177
+ return (entry) => {
178
+ const line = formatJsonlLine(entry, { pretty: false });
179
+ return line + '\n';
180
+ };
181
+ }
182
+ //# sourceMappingURL=jsonl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonl.js","sourceRoot":"","sources":["../src/jsonl.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAkBH,0CAKC;AAeD,kCASC;AA4BD,wCAwCC;AAmCD,gCAkDC;AAoBD,kDAKC;AA9ND,yCAA+C;AAE/C;;;;;;;;;;;;GAYG;AACH,SAAgB,eAAe,CAAC,KAAiB,EAAE,OAAsB;IACvE,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CAAC,OAAqB,EAAE,OAAsB;IACvE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,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L,OAAO;oBACP,MAAM,EAAE,CAAC,MAAM,CAAC;oBAChB,UAAU,EAAE,SAAS;oBACrB,YAAY,EAAE,OAAO,CAAC,MAAM;oBAC5B,UAAU,EAAE,CAAC;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO;QACP,MAAM;QACN,UAAU,EAAE,SAAS;QACrB,YAAY,EAAE,OAAO,CAAC,MAAM;QAC5B,UAAU,EAAE,MAAM,CAAC,MAAM;KAC1B,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,mBAAmB,CAAC,OAAsB;IACxD,OAAO,CAAC,KAAiB,EAAU,EAAE;QACnC,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACvD,OAAO,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,191 @@
1
+ /**
2
+ * PEAC Audit Types (v0.9.27+)
3
+ *
4
+ * Type definitions for audit logging and case bundle generation.
5
+ * These types define the normative JSONL audit log format.
6
+ */
7
+ /**
8
+ * Audit event categories aligned with PEAC operations.
9
+ */
10
+ export type AuditEventType = 'receipt_issued' | 'receipt_verified' | 'receipt_denied' | 'access_decision' | 'dispute_filed' | 'dispute_acknowledged' | 'dispute_resolved' | 'dispute_rejected' | 'dispute_appealed' | 'dispute_final' | 'attribution_created' | 'attribution_verified' | 'identity_verified' | 'identity_rejected' | 'policy_evaluated';
11
+ /**
12
+ * Audit event severity levels.
13
+ */
14
+ export type AuditSeverity = 'info' | 'warn' | 'error' | 'critical';
15
+ /**
16
+ * W3C Trace Context for correlation.
17
+ *
18
+ * @see https://www.w3.org/TR/trace-context/
19
+ */
20
+ export interface TraceContext {
21
+ /** Trace ID (32 hex characters) */
22
+ trace_id: string;
23
+ /** Span ID (16 hex characters) */
24
+ span_id: string;
25
+ /** Parent span ID (optional) */
26
+ parent_span_id?: string;
27
+ /** Trace flags (optional, default 00) */
28
+ trace_flags?: string;
29
+ }
30
+ /**
31
+ * Actor information for audit entries.
32
+ * May be a user, agent, or system component.
33
+ */
34
+ export interface AuditActor {
35
+ /** Actor type */
36
+ type: 'user' | 'agent' | 'system';
37
+ /** Actor identifier (URI, DID, or opaque ID) */
38
+ id: string;
39
+ /** Human-readable name (optional) */
40
+ name?: string;
41
+ }
42
+ /**
43
+ * Resource affected by the audit event.
44
+ */
45
+ export interface AuditResource {
46
+ /** Resource type */
47
+ type: 'receipt' | 'attribution' | 'identity' | 'policy' | 'dispute' | 'content';
48
+ /** Resource identifier (jti, URL, ref, etc.) */
49
+ id: string;
50
+ /** Resource URI (optional) */
51
+ uri?: string;
52
+ }
53
+ /**
54
+ * Outcome of the audited operation.
55
+ */
56
+ export interface AuditOutcome {
57
+ /** Whether the operation succeeded */
58
+ success: boolean;
59
+ /** Result code (e.g., 'allowed', 'denied', 'upheld') */
60
+ result?: string;
61
+ /** Error code if failed */
62
+ error_code?: string;
63
+ /** Human-readable message */
64
+ message?: string;
65
+ }
66
+ /**
67
+ * Core audit entry structure (JSONL normative format).
68
+ *
69
+ * Each line in a JSONL audit log is one AuditEntry serialized as JSON.
70
+ * Fields are ordered for consistent serialization.
71
+ */
72
+ export interface AuditEntry {
73
+ /** PEAC audit format version */
74
+ version: 'peac.audit/0.9';
75
+ /** Unique entry identifier (ULID recommended) */
76
+ id: string;
77
+ /** Event type from controlled vocabulary */
78
+ event_type: AuditEventType;
79
+ /** ISO 8601 timestamp with timezone */
80
+ timestamp: string;
81
+ /** Event severity level */
82
+ severity: AuditSeverity;
83
+ /** Optional trace context for distributed tracing */
84
+ trace?: TraceContext;
85
+ /** Actor who triggered the event */
86
+ actor: AuditActor;
87
+ /** Resource affected by the event */
88
+ resource: AuditResource;
89
+ /** Outcome of the operation */
90
+ outcome: AuditOutcome;
91
+ /** Additional context (privacy-safe, no PII) */
92
+ context?: Record<string, unknown>;
93
+ /** Dispute reference if related to a dispute (ULID format) */
94
+ dispute_ref?: string;
95
+ }
96
+ /**
97
+ * Case bundle containing related audit entries for a dispute.
98
+ *
99
+ * A case bundle gathers all relevant events for dispute resolution,
100
+ * organized chronologically with trace correlation.
101
+ */
102
+ export interface CaseBundle {
103
+ /** PEAC case bundle format version */
104
+ version: 'peac.bundle/0.9';
105
+ /** Dispute reference this bundle is for (ULID) */
106
+ dispute_ref: string;
107
+ /** When the bundle was generated */
108
+ generated_at: string;
109
+ /** Who generated the bundle */
110
+ generated_by: string;
111
+ /** Audit entries in chronological order */
112
+ entries: AuditEntry[];
113
+ /** Unique trace IDs involved in this case */
114
+ trace_ids: string[];
115
+ /** Summary statistics */
116
+ summary: CaseBundleSummary;
117
+ }
118
+ /**
119
+ * Summary statistics for a case bundle.
120
+ */
121
+ export interface CaseBundleSummary {
122
+ /** Total number of entries */
123
+ entry_count: number;
124
+ /** Count by event type */
125
+ by_event_type: Record<string, number>;
126
+ /** Count by severity */
127
+ by_severity: Record<AuditSeverity, number>;
128
+ /** Earliest event timestamp */
129
+ first_event: string;
130
+ /** Latest event timestamp */
131
+ last_event: string;
132
+ /** Unique actors involved */
133
+ actor_count: number;
134
+ /** Unique resources affected */
135
+ resource_count: number;
136
+ }
137
+ /**
138
+ * Options for creating audit entries.
139
+ */
140
+ export interface CreateAuditEntryOptions {
141
+ /** Optional ID (generated if not provided) */
142
+ id?: string;
143
+ /** Event type */
144
+ event_type: AuditEventType;
145
+ /** Severity level (defaults to 'info') */
146
+ severity?: AuditSeverity;
147
+ /** Trace context for correlation */
148
+ trace?: TraceContext;
149
+ /** Actor information */
150
+ actor: AuditActor;
151
+ /** Resource affected */
152
+ resource: AuditResource;
153
+ /** Operation outcome */
154
+ outcome: AuditOutcome;
155
+ /** Additional context */
156
+ context?: Record<string, unknown>;
157
+ /** Dispute reference if applicable */
158
+ dispute_ref?: string;
159
+ /** Timestamp (current time if not provided) */
160
+ timestamp?: string;
161
+ }
162
+ /**
163
+ * Options for creating a case bundle.
164
+ */
165
+ export interface CreateCaseBundleOptions {
166
+ /** Dispute reference (ULID) */
167
+ dispute_ref: string;
168
+ /** Who is generating the bundle */
169
+ generated_by: string;
170
+ /** Audit entries to include */
171
+ entries: AuditEntry[];
172
+ }
173
+ /**
174
+ * JSONL formatting options.
175
+ */
176
+ export interface JsonlOptions {
177
+ /** Pretty print each entry (for debugging, not production) */
178
+ pretty?: boolean;
179
+ /** Include newline at end of output */
180
+ trailingNewline?: boolean;
181
+ }
182
+ /**
183
+ * JSONL parsing options.
184
+ */
185
+ export interface JsonlParseOptions {
186
+ /** Skip invalid lines instead of throwing */
187
+ skipInvalid?: boolean;
188
+ /** Maximum lines to parse (0 = unlimited) */
189
+ maxLines?: number;
190
+ }
191
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,gBAAgB,GAChB,kBAAkB,GAClB,gBAAgB,GAChB,iBAAiB,GACjB,eAAe,GACf,sBAAsB,GACtB,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,GAClB,eAAe,GACf,qBAAqB,GACrB,sBAAsB,GACtB,mBAAmB,GACnB,mBAAmB,GACnB,kBAAkB,CAAC;AAEvB;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;AAEnE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,iBAAiB;IACjB,I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AAM,EAAE,OAAO,CAAC,CAAC;IAElC,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,+BAA+B;IAC/B,WAAW,EAAE,MAAM,CAAC;IAEpB,mCAAmC;IACnC,YAAY,EAAE,MAAM,CAAC;IAErB,+BAA+B;IAC/B,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,8DAA8D;IAC9D,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,uCAAuC;IACvC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * PEAC Audit Types (v0.9.27+)
4
+ *
5
+ * Type definitions for audit logging and case bundle generation.
6
+ * These types define the normative JSONL audit log format.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Verification Report (v0.9.30+)
3
+ *
4
+ * Deterministic verification of dispute bundles with JCS-canonicalized reports.
5
+ * The report_hash enables cross-language parity: TS and Go implementations
6
+ * must produce identical hashes for the same bundle verification.
7
+ *
8
+ * Key design principles:
9
+ * 1. Real Ed25519 signature verification using @peac/crypto
10
+ * 2. No timestamps in deterministic output
11
+ * 3. All arrays sorted by stable keys for reproducibility
12
+ */
13
+ import type { BundleResult, VerificationReport, VerifyBundleOptions } from './dispute-bundle-types.js';
14
+ /**
15
+ * Verify all receipts in a dispute bundle and generate a deterministic report.
16
+ *
17
+ * @param zipBuffer - Buffer containing the ZIP archive
18
+ * @param options - Verification options
19
+ * @returns Promise resolving to a deterministic verification report
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const zipData = fs.readFileSync('dispute-bundle.zip');
24
+ * const result = await verifyBundle(zipData, { offline: true });
25
+ *
26
+ * if (result.ok) {
27
+ * console.log('Report hash:', result.value.report_hash);
28
+ * console.log('Summary:', result.value.auditor_summary.headline);
29
+ * }
30
+ * ```
31
+ */
32
+ export declare function verifyBundle(zipBuffer: Buffer, options: VerifyBundleOptions): Promise<BundleResult<VerificationReport>>;
33
+ /**
34
+ * Serialize a verification report to JSON.
35
+ *
36
+ * @param report - Verification report
37
+ * @param pretty - Pretty print (default: false)
38
+ * @returns JSON string
39
+ */
40
+ export declare function serializeReport(report: VerificationReport, pretty?: boolean): string;
41
+ /**
42
+ * Format verification report as human-readable text.
43
+ *
44
+ * @param report - Verification report
45
+ * @returns Human-readable text summary
46
+ */
47
+ export declare function formatReportText(report: VerificationReport): string;
48
+ //# 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;;;;;;;;;;;GAWG;AAOH,OAAO,KAAK,EAGV,YAAY,EAMZ,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,2BAA2B,CAAC;AA8anC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CA4E3C;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAE,OAAe,GAAG,MAAM,CAK3F;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAuEnE"}