/** * Schema Normalization * * Functions to normalize receipt claims to a canonical form for comparison. * Produces byte-identical JCS output regardless of how the receipt was created. */ import type { PEACReceiptClaims, Subject } from './types.js'; import type { ParseSuccess } from './receipt-parser.js'; /** * Normalized core claims for comparison. * * This is the minimal set of fields that represent the semantic meaning * of a receipt. All optional fields that are undefined are omitted. */ export interface CoreClaims { /** Issuer URL */ iss: string; /** Audience / resource URL */ aud: string; /** Receipt ID */ rid: string; /** Issued at timestamp */ iat: number; /** Expiry timestamp (omitted if not present) */ exp?: number; /** Amount in smallest currency unit (commerce receipts) */ amt?: number; /** Currency code (ISO 4217, commerce receipts) */ cur?: string; /** Normalized payment evidence (commerce receipts) */ payment?: NormalizedPayment; /** Subject (omitted if not present) */ subject?: Subject; /** Control block (omitted if not present) */ control?: NormalizedControl; } /** * Normalized payment evidence for comparison. * * Only includes the semantic fields, not rail-specific evidence. */ export interface NormalizedPayment { rail: string; reference: string; amount: number; currency: string; asset: string; env: 'live' | 'test'; network?: string; aggregator?: string; routing?: 'direct' | 'callback' | 'role'; } /** * Normalized control block for comparison. */ export interface NormalizedControl { chain: NormalizedControlStep[]; } /** * Normalized control step for comparison. */ export interface NormalizedControlStep { engine: string; result: string; } /** * Extract core claims from a receipt for comparison. * * Supports both commerce and attestation receipts. Accepts either a * ParseSuccess result from parseReceiptClaims() (preferred) or bare * PEACReceiptClaims (backward compat). * * For attestation receipts, maps sub -> subject.uri (normative mapping * per PEAC attestation profile -- sub is a URI identifying the * interaction target). * * The output: * - Contains only semantically meaningful fields * - Omits undefined optional fields (not null, not empty string) * - Uses consistent field ordering (JCS handles this) * - Strips rail-specific evidence details * * @param input - Parsed receipt result or bare commerce claims * @returns Normalized core claims * * @example * ```ts * import { parseReceiptClaims, toCoreClaims } from '@peac/schema'; * * const parsed = parseReceiptClaims(decodedPayload); * if (parsed.ok) { * const core = toCoreClaims(parsed); * } * ``` */ export declare function toCoreClaims(parsed: ParseSuccess): CoreClaims; export declare function toCoreClaims(claims: PEACReceiptClaims): CoreClaims; //# sourceMappingURL=normalize.d.ts.map