import { J as Jwk } from './jwk-BoWfRJfF.js'; export { C as Cnf, a as JwkEc, b as JwkOkp, c as JwkRsa } from './jwk-BoWfRJfF.js'; import { z } from 'zod'; import { CryptoKey, JWTHeaderParameters, JWTPayload, JWTVerifyResult } from 'jose'; export { JWTHeaderParameters, JWTPayload, JWTVerifyResult, CryptoKey as JoseCryptoKey } from 'jose'; declare const CurrencyCode: z.ZodString; type CurrencyCode = z.infer; declare const Amount: z.ZodObject<{ amount: z.ZodNumber; currency: z.ZodString; }, z.core.$strip>; type Amount = z.infer; declare const ZERO_DECIMAL_CURRENCIES: Set<"CLP" | "PYG" | "JPY" | "KRW" | "VND" | "UGX" | "RWF" | "ISK" | "HUF">; declare function divisorFor(currency: string): number; declare const Merchant: z.ZodObject<{ id: z.ZodString; name: z.ZodOptional; website: z.ZodOptional; }, z.core.$strip>; type Merchant = z.infer; declare const PaymentInstrument: z.ZodObject<{ id: z.ZodString; type: z.ZodString; description: z.ZodOptional; metadata: z.ZodOptional>; }, z.core.$strip>; type PaymentInstrument = z.infer; declare const Pisp: z.ZodObject<{ id: z.ZodString; legal_name: z.ZodOptional; brand_name: z.ZodOptional; domain_name: z.ZodOptional; }, z.core.$strip>; type Pisp = z.infer; declare const Item: z.ZodObject<{ id: z.ZodString; name: z.ZodOptional; unit_amount: z.ZodOptional; }, z.core.$strip>; type Item = z.infer; declare const Frequency: z.ZodEnum<{ ON_DEMAND: "ON_DEMAND"; DAILY: "DAILY"; WEEKLY: "WEEKLY"; BIWEEKLY: "BIWEEKLY"; MONTHLY: "MONTHLY"; QUARTERLY: "QUARTERLY"; ANNUALLY: "ANNUALLY"; }>; type Frequency = z.infer; /** `checkout.allowed_merchants` — Open Checkout Mandate may restrict which * merchants the closed checkout can name as `payee`. The `allowed` list is * selectively-disclosable (the verifier sees only the revealed entries). */ declare const ConstraintAllowedMerchants: z.ZodObject<{ type: z.ZodLiteral<"checkout.allowed_merchants">; allowed: z.ZodArray; website: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>; type ConstraintAllowedMerchants = z.infer; /** `checkout.line_items` — bounds the closed checkout's line items. Each * constraint item names `acceptable_items` (selectively-disclosable) and * a `quantity` cap. The closed checkout must satisfy a max-flow match. */ declare const LineItemConstraintEntry: z.ZodObject<{ id: z.ZodString; acceptable_items: z.ZodArray; unit_amount: z.ZodOptional; }, z.core.$strip>>; quantity: z.ZodNumber; }, z.core.$strip>; type LineItemConstraintEntry = z.infer; declare const ConstraintLineItems: z.ZodObject<{ type: z.ZodLiteral<"checkout.line_items">; items: z.ZodArray; unit_amount: z.ZodOptional; }, z.core.$strip>>; quantity: z.ZodNumber; }, z.core.$strip>>; }, z.core.$strip>; type ConstraintLineItems = z.infer; /** `payment.amount_range` — caps the closed payment's `payment_amount`. * `min` is optional. Currency must match. */ declare const ConstraintAmountRange: z.ZodObject<{ type: z.ZodLiteral<"payment.amount_range">; currency: z.ZodString; max: z.ZodNumber; min: z.ZodOptional; }, z.core.$strip>; type ConstraintAmountRange = z.infer; /** `payment.allowed_payees` — restricts which merchants can be paid. */ declare const ConstraintAllowedPayees: z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_payees">; allowed: z.ZodArray; website: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>; type ConstraintAllowedPayees = z.infer; /** `payment.allowed_payment_instruments` — restricts which instruments. */ declare const ConstraintAllowedPaymentInstruments: z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_payment_instruments">; allowed: z.ZodArray; metadata: z.ZodOptional>; }, z.core.$strip>>; }, z.core.$strip>; type ConstraintAllowedPaymentInstruments = z.infer; /** `payment.allowed_pisps` — restricts which Payment Initiation Service * Providers can route the payment (EU PSD2 / LATAM Open Finance). */ declare const ConstraintAllowedPisps: z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_pisps">; allowed: z.ZodArray; brand_name: z.ZodOptional; domain_name: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>; type ConstraintAllowedPisps = z.infer; /** `payment.budget` — paired with `payment.agent_recurrence`. The verifier * is responsible for tracking past presentations and rejecting if the * running sum + this charge would exceed `max`. (Stateful evaluator; * Phase 2.2 ships a tracker.) */ declare const ConstraintBudget: z.ZodObject<{ type: z.ZodLiteral<"payment.budget">; max: z.ZodNumber; currency: z.ZodString; }, z.core.$strip>; type ConstraintBudget = z.infer; /** `payment.agent_recurrence` — paired with `payment.budget`. Caps total * occurrences and frequency window. */ declare const ConstraintAgentRecurrence: z.ZodObject<{ type: z.ZodLiteral<"payment.agent_recurrence">; frequency: z.ZodEnum<{ ON_DEMAND: "ON_DEMAND"; DAILY: "DAILY"; WEEKLY: "WEEKLY"; BIWEEKLY: "BIWEEKLY"; MONTHLY: "MONTHLY"; QUARTERLY: "QUARTERLY"; ANNUALLY: "ANNUALLY"; }>; max_occurrences: z.ZodNumber; }, z.core.$strip>; type ConstraintAgentRecurrence = z.infer; /** `payment.execution_date` — caps when the payment can execute. */ declare const ConstraintExecutionDate: z.ZodObject<{ type: z.ZodLiteral<"payment.execution_date">; not_before: z.ZodOptional; not_after: z.ZodOptional; }, z.core.$strip>; type ConstraintExecutionDate = z.infer; /** `payment.reference` — REQUIRED on every Open Payment Mandate. Carries * the digest of the linked Open Checkout Mandate (binds the payment to a * checkout family). */ declare const ConstraintPaymentReference: z.ZodObject<{ type: z.ZodLiteral<"payment.reference">; conditional_transaction_id: z.ZodString; }, z.core.$strip>; type ConstraintPaymentReference = z.infer; declare const Constraint: z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodLiteral<"checkout.allowed_merchants">; allowed: z.ZodArray; website: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"checkout.line_items">; items: z.ZodArray; unit_amount: z.ZodOptional; }, z.core.$strip>>; quantity: z.ZodNumber; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.amount_range">; currency: z.ZodString; max: z.ZodNumber; min: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_payees">; allowed: z.ZodArray; website: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_payment_instruments">; allowed: z.ZodArray; metadata: z.ZodOptional>; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_pisps">; allowed: z.ZodArray; brand_name: z.ZodOptional; domain_name: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.budget">; max: z.ZodNumber; currency: z.ZodString; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.agent_recurrence">; frequency: z.ZodEnum<{ ON_DEMAND: "ON_DEMAND"; DAILY: "DAILY"; WEEKLY: "WEEKLY"; BIWEEKLY: "BIWEEKLY"; MONTHLY: "MONTHLY"; QUARTERLY: "QUARTERLY"; ANNUALLY: "ANNUALLY"; }>; max_occurrences: z.ZodNumber; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.execution_date">; not_before: z.ZodOptional; not_after: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.reference">; conditional_transaction_id: z.ZodString; }, z.core.$strip>], "type">; type Constraint = z.infer; declare const KNOWN_CONSTRAINT_TYPES: ReadonlyArray; declare const OpenCheckoutMandate: z.ZodObject<{ vct: z.ZodLiteral<"mandate.checkout.open.1">; constraints: z.ZodArray; allowed: z.ZodArray; website: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"checkout.line_items">; items: z.ZodArray; unit_amount: z.ZodOptional; }, z.core.$strip>>; quantity: z.ZodNumber; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.amount_range">; currency: z.ZodString; max: z.ZodNumber; min: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_payees">; allowed: z.ZodArray; website: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_payment_instruments">; allowed: z.ZodArray; metadata: z.ZodOptional>; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_pisps">; allowed: z.ZodArray; brand_name: z.ZodOptional; domain_name: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.budget">; max: z.ZodNumber; currency: z.ZodString; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.agent_recurrence">; frequency: z.ZodEnum<{ ON_DEMAND: "ON_DEMAND"; DAILY: "DAILY"; WEEKLY: "WEEKLY"; BIWEEKLY: "BIWEEKLY"; MONTHLY: "MONTHLY"; QUARTERLY: "QUARTERLY"; ANNUALLY: "ANNUALLY"; }>; max_occurrences: z.ZodNumber; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.execution_date">; not_before: z.ZodOptional; not_after: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.reference">; conditional_transaction_id: z.ZodString; }, z.core.$strip>], "type">>; cnf: z.ZodObject<{ jwk: z.ZodDiscriminatedUnion<[z.ZodObject<{ kty: z.ZodLiteral<"EC">; crv: z.ZodEnum<{ "P-256": "P-256"; "P-384": "P-384"; "P-521": "P-521"; }>; x: z.ZodString; y: z.ZodString; d: z.ZodOptional; alg: z.ZodOptional; kid: z.ZodOptional; use: z.ZodOptional>; key_ops: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ kty: z.ZodLiteral<"OKP">; crv: z.ZodEnum<{ Ed25519: "Ed25519"; Ed448: "Ed448"; }>; x: z.ZodString; d: z.ZodOptional; alg: z.ZodOptional; kid: z.ZodOptional; use: z.ZodOptional>; key_ops: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ kty: z.ZodLiteral<"RSA">; n: z.ZodString; e: z.ZodString; d: z.ZodOptional; p: z.ZodOptional; q: z.ZodOptional; dp: z.ZodOptional; dq: z.ZodOptional; qi: z.ZodOptional; alg: z.ZodOptional; kid: z.ZodOptional; use: z.ZodOptional>; key_ops: z.ZodOptional>; }, z.core.$strip>], "kty">; }, z.core.$strip>; iat: z.ZodOptional; exp: z.ZodOptional; }, z.core.$strip>; type OpenCheckoutMandate = z.infer; declare const ClosedCheckoutMandate: z.ZodObject<{ vct: z.ZodLiteral<"mandate.checkout.1">; checkout_jwt: z.ZodString; checkout_hash: z.ZodString; iat: z.ZodOptional; exp: z.ZodOptional; }, z.core.$strip>; type ClosedCheckoutMandate = z.infer; declare const CheckoutJwtPayload: z.ZodObject<{ order_id: z.ZodString; merchant: z.ZodObject<{ id: z.ZodString; name: z.ZodOptional; website: z.ZodOptional; }, z.core.$strip>; line_items: z.ZodArray; quantity: z.ZodNumber; }, z.core.$strip>>; total_price: z.ZodNumber; currency: z.ZodString; shipping_policy: z.ZodOptional; return_policy: z.ZodOptional; metadata: z.ZodOptional>; }, z.core.$strip>; type CheckoutJwtPayload = z.infer; declare const ClosedPaymentMandate: z.ZodObject<{ vct: z.ZodLiteral<"mandate.payment.1">; transaction_id: z.ZodString; payee: z.ZodObject<{ id: z.ZodString; name: z.ZodOptional; website: z.ZodOptional; }, z.core.$strip>; pisp: z.ZodOptional; brand_name: z.ZodOptional; domain_name: z.ZodOptional; }, z.core.$strip>>; payment_amount: z.ZodObject<{ amount: z.ZodNumber; currency: z.ZodString; }, z.core.$strip>; payment_instrument: z.ZodObject<{ id: z.ZodString; type: z.ZodString; description: z.ZodOptional; metadata: z.ZodOptional>; }, z.core.$strip>; execution_date: z.ZodOptional; risk_data: z.ZodOptional>; iat: z.ZodOptional; exp: z.ZodOptional; }, z.core.$strip>; type ClosedPaymentMandate = z.infer; declare const OpenPaymentMandate: z.ZodObject<{ vct: z.ZodLiteral<"mandate.payment.open.1">; constraints: z.ZodArray; allowed: z.ZodArray; website: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"checkout.line_items">; items: z.ZodArray; unit_amount: z.ZodOptional; }, z.core.$strip>>; quantity: z.ZodNumber; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.amount_range">; currency: z.ZodString; max: z.ZodNumber; min: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_payees">; allowed: z.ZodArray; website: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_payment_instruments">; allowed: z.ZodArray; metadata: z.ZodOptional>; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.allowed_pisps">; allowed: z.ZodArray; brand_name: z.ZodOptional; domain_name: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.budget">; max: z.ZodNumber; currency: z.ZodString; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.agent_recurrence">; frequency: z.ZodEnum<{ ON_DEMAND: "ON_DEMAND"; DAILY: "DAILY"; WEEKLY: "WEEKLY"; BIWEEKLY: "BIWEEKLY"; MONTHLY: "MONTHLY"; QUARTERLY: "QUARTERLY"; ANNUALLY: "ANNUALLY"; }>; max_occurrences: z.ZodNumber; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.execution_date">; not_before: z.ZodOptional; not_after: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"payment.reference">; conditional_transaction_id: z.ZodString; }, z.core.$strip>], "type">>; cnf: z.ZodObject<{ jwk: z.ZodDiscriminatedUnion<[z.ZodObject<{ kty: z.ZodLiteral<"EC">; crv: z.ZodEnum<{ "P-256": "P-256"; "P-384": "P-384"; "P-521": "P-521"; }>; x: z.ZodString; y: z.ZodString; d: z.ZodOptional; alg: z.ZodOptional; kid: z.ZodOptional; use: z.ZodOptional>; key_ops: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ kty: z.ZodLiteral<"OKP">; crv: z.ZodEnum<{ Ed25519: "Ed25519"; Ed448: "Ed448"; }>; x: z.ZodString; d: z.ZodOptional; alg: z.ZodOptional; kid: z.ZodOptional; use: z.ZodOptional>; key_ops: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ kty: z.ZodLiteral<"RSA">; n: z.ZodString; e: z.ZodString; d: z.ZodOptional; p: z.ZodOptional; q: z.ZodOptional; dp: z.ZodOptional; dq: z.ZodOptional; qi: z.ZodOptional; alg: z.ZodOptional; kid: z.ZodOptional; use: z.ZodOptional>; key_ops: z.ZodOptional>; }, z.core.$strip>], "kty">; }, z.core.$strip>; iat: z.ZodOptional; exp: z.ZodOptional; }, z.core.$strip>; type OpenPaymentMandate = z.infer; declare const ReceiptStatus: z.ZodEnum<{ Success: "Success"; Error: "Error"; }>; type ReceiptStatus = z.infer; declare const ReceiptErrorCode: z.ZodEnum<{ invalid_credential: "invalid_credential"; invalid_mandate: "invalid_mandate"; unresolved_constraint: "unresolved_constraint"; mandates_not_supported: "mandates_not_supported"; }>; type ReceiptErrorCode = z.infer; declare const CheckoutReceipt: z.ZodObject<{ status: z.ZodEnum<{ Success: "Success"; Error: "Error"; }>; iss: z.ZodString; iat: z.ZodNumber; reference: z.ZodString; order_id: z.ZodOptional; error: z.ZodOptional, z.ZodString]>>; error_description: z.ZodOptional; }, z.core.$strip>; type CheckoutReceipt = z.infer; declare const PaymentReceipt: z.ZodObject<{ status: z.ZodEnum<{ Success: "Success"; Error: "Error"; }>; iss: z.ZodString; iat: z.ZodNumber; reference: z.ZodString; payment_id: z.ZodString; psp_confirmation_id: z.ZodOptional; network_confirmation_id: z.ZodOptional; error: z.ZodOptional, z.ZodString]>>; error_description: z.ZodOptional; }, z.core.$strip>; type PaymentReceipt = z.infer; declare class SdJwtError extends Error { constructor(message: string); } declare function base64urlEncode(input: Uint8Array | string): string; declare function base64urlDecode(input: string): Uint8Array; declare function base64urlDecodeToString(input: string): string; declare function sha256(input: string | Uint8Array): Promise; declare function sha256Base64url(input: string | Uint8Array): Promise; /** AP2 algorithm choices. ES256 is the canonical reference. */ declare const AP2_ALGS: readonly ["ES256", "ES384", "ES512", "RS256", "EdDSA"]; type Ap2Alg = (typeof AP2_ALGS)[number]; /** ES256 / ES384 / ES512 are the canonical "non-deterministic" schemes * AP2 mandates for the inner `checkout_jwt`. EdDSA is forbidden there. */ declare const NON_DETERMINISTIC_ALGS: readonly ["ES256", "ES384", "ES512"]; interface Ap2KeyPair { /** The signing private key (jose CryptoKey reference). */ privateKey: CryptoKey; /** The verification public key. */ publicKey: CryptoKey; /** Public JWK (suitable for `cnf.jwk`, JWKS, etc.). */ publicJwk: Jwk; /** The algorithm bound to this key. */ alg: Ap2Alg; } /** * Generate a fresh keypair for AP2 signing. Defaults to ES256 (the canonical * spec algorithm). Returns CryptoKey handles + a public JWK ready to use as * `cnf.jwk`. */ declare function generateAp2KeyPair(alg?: Ap2Alg): Promise; /** Resolve a `cnf.jwk` to a verification key. */ declare function importPublicJwk(jwk: Jwk, alg: string): Promise; /** Resolve a private JWK (with `d`) to a signing key. */ declare function importPrivateJwk(jwk: Jwk & { d: string; }, alg: string): Promise; interface SignOptions { alg: string; /** Header `typ`. AP2 uses several values: `JWT` (inner checkout_jwt), * `dc+sd-jwt` (DC-API SD-JWT VC), `example+sd-jwt` (issuer SD-JWT), * `kb+sd-jwt` (terminal KB-JWT), `kb+sd-jwt+kb` (intermediate). */ typ?: string; /** Optional key id reference. */ kid?: string; /** Optional cert chain for `x5c` validation. */ x5c?: string[]; } /** * Sign an arbitrary JSON payload using ES256 (or another configured alg) as a * compact JWS. Used for the inner `checkout_jwt`, KB-JWTs, and receipts. * * **Spec-critical:** if `payload` is a checkout payload destined for the * inner `checkout_jwt`, `options.alg` MUST be in `NON_DETERMINISTIC_ALGS`. * Use `signCheckoutJwt()` (in `checkout-jwt.ts`) for that path — it enforces * the rule at construction time. */ declare function signCompactJws(payload: JWTPayload, signingKey: CryptoKey, options: SignOptions): Promise; interface VerifyOptions { /** Acceptable algorithms. Default: AP2_ALGS. */ algorithms?: string[]; /** Expected audience. Validated against `aud` claim if set. */ audience?: string; /** Expected issuer. Validated against `iss` claim if set. */ issuer?: string; /** Clock skew in seconds for iat/exp validation. Default 30. */ clockTolerance?: number; /** Override "now" for deterministic tests. Unix seconds. */ currentDate?: Date; } /** * Verify a compact JWS, returning the parsed payload + protected header. * Throws on signature failure / time-claim violation / aud-iss mismatch. */ declare function verifyCompactJws(jws: string, verificationKey: CryptoKey, options?: VerifyOptions): Promise; interface DecodedJws { protectedHeader: JWTHeaderParameters; payload: JWTPayload; signature: string; } declare function decodeJwsUnverified(jws: string): DecodedJws; declare class CheckoutJwtAlgError extends Error { constructor(alg: string); } interface SignCheckoutJwtOptions { /** Algorithm. Default `ES256`. MUST be non-deterministic ECDSA. */ alg?: "ES256" | "ES384" | "ES512" | "RS256"; /** Optional kid. */ kid?: string; /** Optional issuance time (Unix seconds). Default `Math.floor(Date.now()/1000)`. */ iat?: number; /** Optional expiration (Unix seconds). */ exp?: number; } /** * Sign a checkout payload as the inner `checkout_jwt`. Returns the compact * JWS string (suitable for stuffing into `ClosedCheckoutMandate.checkout_jwt`). * * Pairs with `computeCheckoutHash` — the closed mandate must carry both. */ declare function signCheckoutJwt(payload: unknown, signingKey: CryptoKey, options?: SignCheckoutJwtOptions): Promise; /** * Compute `checkout_hash` per spec: `base64url(sha-256(checkout_jwt))`. * * The closed Checkout Mandate's `checkout_hash` MUST equal this value, AND * the closed Payment Mandate's `transaction_id` MUST equal this value. */ declare function computeCheckoutHash(checkoutJwt: string): Promise; /** * Verify the inner `checkout_jwt` signature. Use this when receiving a * Closed Checkout Mandate — after extracting `checkout_jwt`, hash it to * confirm `checkout_hash` matches, then call this to verify the merchant * actually signed the cart payload. */ declare function verifyCheckoutJwt(checkoutJwt: string, verificationKey: CryptoKey, options?: VerifyOptions): Promise<{ payload: unknown; alg: string; }>; /** * Decode the inner Checkout JWT WITHOUT signature verification. Useful when * the merchant is serving a hosted JWKS and a separate verifier needs to * resolve the header `kid` before verification. */ declare function decodeCheckoutJwt(checkoutJwt: string): { header: ReturnType["protectedHeader"]; payload: unknown; }; interface ObjectDisclosure { /** base64url-encoded random salt (>= 16 bytes recommended). */ salt: string; /** Property name being disclosed. */ name: string; value: unknown; } interface ArrayDisclosure { salt: string; value: unknown; } type Disclosure = ObjectDisclosure | ArrayDisclosure; /** * Encode a disclosure to its compact base64url(JSON([...])) form. * - Object-property: `[salt, name, value]` * - Array-element: `[salt, value]` */ declare function encodeDisclosure(disclosure: Disclosure): string; /** Decode a disclosure string back into its tuple form. */ declare function decodeDisclosure(encoded: string): Disclosure; /** * Generate a fresh salt — base64url-encoded 16 random bytes (RFC 9901 §11.3 * recommendation). */ declare function generateSalt(): string; /** * Compute the digest of a disclosure — `base64url(sha-256(encoded))` per * RFC 9901 §4.1.1. The digest array `_sd` in the SD-JWT issuer payload * holds these. */ declare function digestOfDisclosure(encoded: string, alg?: string): Promise; interface ParsedSdJwt { /** The issuer-side compact JWS (header.payload.signature). */ issuerJwt: string; /** Encoded disclosure strings (in the order they appeared on the wire). */ disclosures: string[]; /** Optional terminal KB-JWT (compact JWS) signed by holder's cnf.jwk. */ kbJwt: string | undefined; } /** * Parse a single-hop SD-JWT compact serialization. Per RFC 9901 §3, the * format is `~~...~~[]` where the * trailing `~` is REQUIRED and the kb-jwt is OPTIONAL. */ declare function parseSdJwt(input: string): ParsedSdJwt; /** * Serialize an SD-JWT to its compact tilde-separated form. * Trailing tilde is included per RFC 9901. */ declare function serializeSdJwt(parts: ParsedSdJwt): string; declare function computeSdHash(parts: { issuerJwt: string; disclosures: string[]; }, alg?: string): Promise; interface ResolveOptions { /** Required `_sd_alg` claim from issuer payload. Default sha-256. */ sdAlg?: string; } /** * Walk the issuer payload, replacing `_sd` digest arrays with their * disclosed values. Throws if a disclosure doesn't match any digest in the * payload (per RFC 9901 §6.1 — unmatched disclosures are an error). */ declare function resolveDisclosures(issuerPayload: Record, encodedDisclosures: string[], options?: ResolveOptions): Promise>; interface IssueSdJwtOptions { /** Fields to make selectively-disclosable (object-property level). */ disclosablePaths: string[]; /** The plaintext payload (full data). */ payload: Record; /** The `vct` claim (e.g. `mandate.checkout.open.1`). */ vct: string; /** Optional iat/exp + custom claims. */ iat?: number; exp?: number; extraClaims?: Record; /** `_sd_alg`. Default sha-256. */ sdAlg?: string; } /** * Build the issuer payload for an SD-JWT VC by replacing each * `disclosablePaths` top-level key with a digest in `_sd`. Returns both the * payload to sign and the encoded disclosures the issuer must include * alongside. * * **Phase 2.1 limitation:** only top-level object-property disclosure is * supported. Nested-path / array-element disclosure ships in Phase 2.2. */ declare function buildIssuerPayload(options: IssueSdJwtOptions): Promise<{ issuerPayload: Record; encodedDisclosures: string[]; }>; interface BuildKbJwtOptions { audience: string; nonce: string; iat?: number; /** sd_hash of the SD-JWT presentation this KB-JWT binds to. */ sdHash: string; /** Header `typ`. Per AP2: `kb+sd-jwt` (terminal) or `kb+sd-jwt+kb` (intermediate). */ typ?: "kb+sd-jwt" | "kb+sd-jwt+kb"; /** Algorithm for the KB-JWT signature. */ alg: string; /** Optional kid. */ kid?: string; /** Optional `cnf.jwk` for next-hop binding (intermediate hops only). */ cnfJwk?: object; } declare function buildKbJwt(signingKey: CryptoKey, options: BuildKbJwtOptions): Promise; interface IssuerVerification { protectedHeader: JWTHeaderParameters; payload: JWTPayload; } declare function verifyIssuerJwt(issuerJwt: string, verificationKey: CryptoKey, options?: VerifyOptions): Promise; interface KbJwtVerification { protectedHeader: JWTHeaderParameters; payload: { aud: string; nonce: string; iat: number; sd_hash: string; }; } /** * Verify a KB-JWT and check `aud`, `nonce`, and `sd_hash` match the * expected values. */ declare function verifyKbJwt(kbJwt: string, verificationKey: CryptoKey, expected: { audience: string; nonce: string; sdHash: string; }, options?: VerifyOptions): Promise; interface BudgetTracker { inspect(openMandateDigest: string): Promise; /** * Record a successful presentation. Called by the verifier AFTER all * non-stateful checks pass and the closed mandate is about to be * authorized for execution. Implementations MUST be atomic. */ recordPresentation(args: RecordPresentationArgs): Promise; /** Optional: clear all state for a digest (e.g. when the open mandate expires). */ clear?(openMandateDigest: string): Promise; } interface TrackerSnapshot { totalSpentMinor: number; occurrences: number; /** Last execution as Unix seconds. */ lastExecutedAt?: number; } interface RecordPresentationArgs { openMandateDigest: string; amountMinor: number; /** ISO 4217 (uppercase). */ currency: string; /** Optional execution time. Default Unix-now-seconds. */ executedAt?: number; } /** * Returns true if the recurrence interval has elapsed since `lastExecutedAt`. * `ON_DEMAND` always passes. */ declare function isWithinRecurrenceWindow(frequency: Frequency, lastExecutedAt: number | undefined, nowSeconds: number): boolean; /** * In-memory BudgetTracker. Suitable for single-process tests, dev demos, * and small deployments. NOT durable — state is lost on process restart. * * Production implementations should back this with Redis / Postgres / a * queue. The interface is stable so swapping is a one-line change. */ declare class InMemoryBudgetTracker implements BudgetTracker { private state; inspect(openMandateDigest: string): Promise; recordPresentation(args: RecordPresentationArgs): Promise; clear(openMandateDigest: string): Promise; } interface BudgetEvaluationInput { tracker: BudgetTracker; openMandateDigest: string; /** Closed payment mandate's amount, in minor units. */ amountMinor: number; /** Closed payment mandate's currency, uppercase ISO 4217. */ currency: string; /** From the open mandate's `payment.budget` constraint. Major units. */ budget: { max: number; currency: string; }; /** From the open mandate's `payment.agent_recurrence` constraint. */ recurrence?: { frequency: Frequency; max_occurrences: number; }; /** Major-unit divisor for `currency`. Caller computes via `divisorFor`. */ divisor: number; /** Override "now" for tests. */ nowSeconds?: number; } type BudgetEvaluationResult = { ok: true; } | { ok: false; code: "invalid_mandate"; reason: string; details?: Record; }; /** * Evaluate a budget + (optional) recurrence constraint against a tracker * snapshot. The verifier should call this BEFORE authorizing the payment; * if it returns `ok: true`, the verifier then calls * `tracker.recordPresentation(...)` to mark the spend. * * This function is pure — it doesn't mutate the tracker. */ declare function evaluateBudgetWithRecurrence(input: BudgetEvaluationInput): Promise; type EvaluationResult = { ok: true; } | { ok: false; reason: string; code: "invalid_mandate" | "unresolved_constraint"; }; interface CheckoutConstraintContext { /** Inner checkout payload (already verified + parsed). */ checkoutPayload: CheckoutJwtPayload; /** The closed mandate object. */ closedMandate: ClosedCheckoutMandate; } interface PaymentConstraintContext { closedMandate: ClosedPaymentMandate; /** * sd_hash digest of the linked Open Checkout Mandate. Required when * evaluating `payment.reference`. `undefined` if the verifier cannot * resolve it (verifier MUST then fail with `unresolved_constraint`). */ linkedCheckoutMandateDigest?: string; /** * Stateful tracker for budget + agent_recurrence constraints. When present, * `payment.budget` (and its paired `payment.agent_recurrence`) are evaluated * against the tracker snapshot via `evaluateBudgetWithRecurrence`. When * absent, those constraints pass as a documented no-op (caller is * responsible for supplying a tracker in production). */ tracker?: BudgetTracker; /** * Stable digest keying tracker state for this Open Payment Mandate * (typically its sd_hash). Required when `tracker` is supplied — without it * budget/recurrence cannot be evaluated and fail with * `unresolved_constraint`. */ openMandateDigest?: string; /** * The paired `payment.agent_recurrence` bound from the same Open Payment * Mandate, if any. `payment.budget` and `payment.agent_recurrence` are * evaluated together (the recurrence cap is meaningless without the budget), * so the caller resolves the recurrence constraint alongside the budget one. */ budgetRecurrence?: { frequency: Frequency; max_occurrences: number; }; /** Override "now" (Unix seconds) for deterministic recurrence tests. */ nowSeconds?: number; } /** * Evaluate a single constraint against a Closed Checkout Mandate context. * Throws `EvaluationError` on unknown constraint types per spec. */ declare function evaluateCheckoutConstraint(constraint: Constraint, context: CheckoutConstraintContext): EvaluationResult; /** * Evaluate a single constraint against a Closed Payment Mandate context. * Returns `unresolved_constraint` for unknown types. For `payment.budget` + * `payment.agent_recurrence` requires `context.tracker` if present. */ declare function evaluatePaymentConstraint(constraint: Constraint, context: PaymentConstraintContext): Promise; interface IssuerSigningCtx { /** Issuer's signing key (JWS root). */ privateKey: CryptoKey; /** JWS algorithm (ES256 default). */ alg: string; /** Header `kid` (optional). */ kid?: string; /** Header `typ` for the issuer JWS. Default `example+sd-jwt`. */ typ?: string; } interface KeyBindingCtx { /** Holder's signing key for the KB-JWT (matching `cnf.jwk`). */ privateKey: CryptoKey; /** Algorithm. ES256 default. */ alg: string; /** Optional kid. */ kid?: string; /** Audience the KB-JWT binds to ("merchant" / "credential-provider" / etc.). */ audience: string; /** Verifier-supplied nonce. */ nonce: string; } interface IssueOpenCheckoutOptions { mandate: OpenCheckoutMandate; signingCtx: IssuerSigningCtx; /** Optional Key Binding hop. If set, the SD-JWT terminates with a KB-JWT. */ keyBinding?: KeyBindingCtx; /** Override sd_alg. Default sha-256. */ sdAlg?: string; } declare function issueOpenCheckoutMandate(options: IssueOpenCheckoutOptions): Promise; interface IssueClosedCheckoutOptions { mandate: ClosedCheckoutMandate; signingCtx: IssuerSigningCtx; keyBinding?: KeyBindingCtx; sdAlg?: string; } declare function issueClosedCheckoutMandate(options: IssueClosedCheckoutOptions): Promise; interface IssueOpenPaymentOptions { mandate: OpenPaymentMandate; signingCtx: IssuerSigningCtx; keyBinding?: KeyBindingCtx; sdAlg?: string; } declare function issueOpenPaymentMandate(options: IssueOpenPaymentOptions): Promise; interface IssueClosedPaymentOptions { mandate: ClosedPaymentMandate; signingCtx: IssuerSigningCtx; keyBinding?: KeyBindingCtx; sdAlg?: string; } declare function issueClosedPaymentMandate(options: IssueClosedPaymentOptions): Promise; type VerificationOutcome = { ok: true; mandate: T; /** sd_hash of the verified presentation — useful for receipts. */ sdHash: string; } | { ok: false; code: "invalid_credential" | "invalid_mandate" | "unresolved_constraint" | "mandates_not_supported"; reason: string; }; interface CommonVerifyOptions { /** Issuer public key, as JWK or already-imported CryptoKey. */ issuerKey: Jwk | CryptoKey; /** Algorithm declared by the issuer key. Default ES256. */ issuerAlg?: string; /** Optional iss claim to validate. */ issuer?: string; /** Clock tolerance for iat/exp (seconds). Default 30. */ clockTolerance?: number; /** Override "now" for deterministic tests. */ currentDate?: Date; } interface KeyBindingVerifyOptions { /** Verifier-issued audience. */ audience: string; /** Verifier-issued nonce — must equal the KB-JWT's `nonce`. */ nonce: string; } interface VerifyClosedCheckoutOptions extends CommonVerifyOptions { /** Merchant key that signed the inner `checkout_jwt`. */ checkoutJwtKey: Jwk | CryptoKey; /** Algorithm of the inner `checkout_jwt`. ES256 default. */ checkoutJwtAlg?: string; /** Required when the SD-JWT terminates with a KB-JWT. */ keyBinding?: KeyBindingVerifyOptions; } interface VerifiedClosedCheckout { closed: ClosedCheckoutMandate; /** The verified inner checkout payload. */ checkout: CheckoutJwtPayload; /** sd_hash of the SD-JWT presentation (used as receipt `reference`). */ sdHash: string; } declare function verifyClosedCheckoutMandate(presentation: string, options: VerifyClosedCheckoutOptions): Promise>; interface VerifyOpenCheckoutOptions extends CommonVerifyOptions { /** The closed mandate's verified inner checkout payload. */ closedCheckout: CheckoutJwtPayload; closedMandate: ClosedCheckoutMandate; keyBinding?: KeyBindingVerifyOptions; } declare function verifyOpenCheckoutMandate(presentation: string, options: VerifyOpenCheckoutOptions): Promise>; interface VerifyClosedPaymentOptions extends CommonVerifyOptions { /** * `checkout_hash` of the linked Closed Checkout Mandate. Required — * `transaction_id` MUST equal this value. */ expectedTransactionId: string; keyBinding?: KeyBindingVerifyOptions; } interface VerifiedClosedPayment { closed: ClosedPaymentMandate; sdHash: string; } declare function verifyClosedPaymentMandate(presentation: string, options: VerifyClosedPaymentOptions): Promise>; interface VerifyOpenPaymentOptions extends CommonVerifyOptions { closedMandate: ClosedPaymentMandate; /** sd_hash of the linked Open Checkout Mandate (for `payment.reference`). */ linkedCheckoutMandateDigest?: string; /** Optional stateful tracker for `payment.budget` / `payment.agent_recurrence`. */ tracker?: BudgetTracker; keyBinding?: KeyBindingVerifyOptions; } declare function verifyOpenPaymentMandate(presentation: string, options: VerifyOpenPaymentOptions): Promise>; interface BuildCheckoutReceiptOptions { receipt: CheckoutReceipt; signingKey: CryptoKey; alg?: string; kid?: string; } declare function buildCheckoutReceipt(options: BuildCheckoutReceiptOptions): Promise; interface BuildPaymentReceiptOptions { receipt: PaymentReceipt; signingKey: CryptoKey; alg?: string; kid?: string; } declare function buildPaymentReceipt(options: BuildPaymentReceiptOptions): Promise; interface VerifyReceiptOptions extends VerifyOptions { /** Expected issuer (`iss` claim). */ expectedIssuer?: string; /** Expected reference (sd_hash of the closed mandate). */ expectedReference?: string; } declare function verifyCheckoutReceipt(jws: string, verificationKey: CryptoKey, options?: VerifyReceiptOptions): Promise; declare function verifyPaymentReceipt(jws: string, verificationKey: CryptoKey, options?: VerifyReceiptOptions): Promise; /** Wire-level separator between hops. */ declare const CHAIN_SEPARATOR = "~~"; type AnyOpenMandate = OpenCheckoutMandate | OpenPaymentMandate; type AnyClosedMandate = ClosedCheckoutMandate | ClosedPaymentMandate; interface DsdJwtChain { /** Original compact serialization. */ presentation: string; /** * Parsed hops in order — `hops[0]` is the root issuer SD-JWT, the last * element is the terminal KB-SD-JWT carrying the closed mandate. */ hops: ParsedSdJwt[]; } /** * Parse a dSD-JWT chain into its constituent hops. Each hop's KB-JWT (if * present) ends up in `hops[i].kbJwt` per the underlying single-hop parser. * * NOTE: AP2 chains use `~~` between SD-JWTs, where each chunk independently * uses `~` for disclosures. We split on the literal `~~` substring; this * is unambiguous because a single hop's wire format ends in EITHER a * KB-JWT or a single trailing `~`, never two — and `~~` is * always a chain boundary. */ declare function parseDsdJwtChain(presentation: string): DsdJwtChain; /** Serialize a parsed chain back to compact form. */ declare function serializeDsdJwtChain(chain: DsdJwtChain): string; interface ChainVerifyOptions { /** Trusted issuer key for the root hop (hop[0]). */ rootIssuerKey: Jwk | CryptoKey; /** Algorithm of root issuer key. Default ES256. */ rootIssuerAlg?: string; /** Algorithms accepted on hop signatures. Default `[ES256, ES384, ES512, RS256, EdDSA]`. */ hopAlgs?: string[]; /** Audience the terminal hop binds to. */ expectedAudience: string; /** Verifier-issued nonce — must equal terminal hop's `nonce`. */ expectedNonce: string; /** Optional `iss` constraint on the root JWS. */ expectedRootIssuer?: string; /** Clock tolerance for `iat` / `exp`. Default 30s. */ clockTolerance?: number; /** Override "now" for tests. */ currentDate?: Date; /** * Optional stateful tracker for `payment.budget` / `payment.agent_recurrence` * constraints carried by Open Payment Mandates in the chain. When omitted, * those constraints pass as a documented no-op (caller responsibility). */ tracker?: BudgetTracker; /** * sd_hash of the linked Open Checkout Mandate — required to evaluate a * `payment.reference` constraint. When omitted, `payment.reference` fails * with `unresolved_constraint`. */ linkedCheckoutMandateDigest?: string; } interface ChainHopVerification { /** Position in the chain (0 = root). */ index: number; /** Decoded protected header. */ header: JWTHeaderParameters; /** Decoded full JWS payload. */ payload: JWTPayload; /** * Resolved `delegate_payload` items — the things this hop is "delegating". * For an open-mandate hop: a single open-mandate object. * For an intermediate cnf-binding-only hop: a single object with `cnf.jwk`. * For the terminal hop: the closed mandate. */ delegatePayload: unknown[]; /** sd_hash of this hop's presentation. */ sdHash: string; /** PoP key for the next hop, when this hop is not terminal. */ nextCnfJwk: Jwk | undefined; /** True if this hop's typ is `kb+sd-jwt` (terminal-only hop). */ isTerminal: boolean; /** True if this hop's typ is `kb+sd-jwt+kb` (intermediate hop). */ isIntermediate: boolean; } type ChainVerificationOutcome = { ok: true; hops: ChainHopVerification[]; /** Open mandates extracted from non-terminal hops. */ openMandates: AnyOpenMandate[]; /** Closed mandate from the terminal hop. */ closedMandate: AnyClosedMandate; /** sd_hash of the terminal hop — receipt `reference`. */ terminalSdHash: string; } | { ok: false; hops: ChainHopVerification[]; code: "invalid_credential" | "invalid_mandate" | "unresolved_constraint"; reason: string; }; declare function verifyDsdJwtChain(presentation: string, options: ChainVerifyOptions): Promise; export { AP2_ALGS, Amount, type AnyClosedMandate, type AnyOpenMandate, type Ap2Alg, type Ap2KeyPair, type ArrayDisclosure, type BudgetEvaluationInput, type BudgetEvaluationResult, type BudgetTracker, type BudgetTracker as BudgetTrackerInterface, type BuildCheckoutReceiptOptions, type BuildKbJwtOptions, type BuildPaymentReceiptOptions, CHAIN_SEPARATOR, type ChainHopVerification, type ChainVerificationOutcome, type ChainVerifyOptions, type CheckoutConstraintContext, CheckoutJwtAlgError, CheckoutJwtPayload, CheckoutReceipt, ClosedCheckoutMandate, ClosedPaymentMandate, type CommonVerifyOptions, Constraint, ConstraintAgentRecurrence, ConstraintAllowedMerchants, ConstraintAllowedPayees, ConstraintAllowedPaymentInstruments, ConstraintAllowedPisps, ConstraintAmountRange, ConstraintBudget, ConstraintExecutionDate, ConstraintLineItems, ConstraintPaymentReference, CurrencyCode, type DecodedJws, type Disclosure, type DsdJwtChain, type EvaluationResult, Frequency, InMemoryBudgetTracker, type IssueClosedCheckoutOptions, type IssueClosedPaymentOptions, type IssueOpenCheckoutOptions, type IssueOpenPaymentOptions, type IssueSdJwtOptions, type IssuerSigningCtx, type IssuerVerification, Item, Jwk, KNOWN_CONSTRAINT_TYPES, type KbJwtVerification, type KeyBindingCtx, type KeyBindingVerifyOptions, LineItemConstraintEntry, Merchant, NON_DETERMINISTIC_ALGS, type ObjectDisclosure, OpenCheckoutMandate, OpenPaymentMandate, type ParsedSdJwt, type PaymentConstraintContext, PaymentInstrument, PaymentReceipt, Pisp, ReceiptErrorCode, ReceiptStatus, type RecordPresentationArgs, type ResolveOptions, SdJwtError, type SignCheckoutJwtOptions, type SignOptions, type TrackerSnapshot, type VerificationOutcome, type VerifiedClosedCheckout, type VerifiedClosedPayment, type VerifyClosedCheckoutOptions, type VerifyClosedPaymentOptions, type VerifyOpenCheckoutOptions, type VerifyOpenPaymentOptions, type VerifyOptions, type VerifyReceiptOptions, ZERO_DECIMAL_CURRENCIES, base64urlDecode, base64urlDecodeToString, base64urlEncode, buildCheckoutReceipt, buildIssuerPayload, buildKbJwt, buildPaymentReceipt, computeCheckoutHash, computeSdHash, decodeCheckoutJwt, decodeDisclosure, decodeJwsUnverified, digestOfDisclosure, divisorFor, encodeDisclosure, evaluateBudgetWithRecurrence, evaluateCheckoutConstraint, evaluatePaymentConstraint, generateAp2KeyPair, generateSalt, importPrivateJwk, importPublicJwk, isWithinRecurrenceWindow, issueClosedCheckoutMandate, issueClosedPaymentMandate, issueOpenCheckoutMandate, issueOpenPaymentMandate, parseDsdJwtChain, parseSdJwt, resolveDisclosures, serializeDsdJwtChain, serializeSdJwt, sha256, sha256Base64url, signCheckoutJwt, signCompactJws, verifyCheckoutJwt, verifyCheckoutReceipt, verifyClosedCheckoutMandate, verifyClosedPaymentMandate, verifyCompactJws, verifyDsdJwtChain, verifyIssuerJwt, verifyKbJwt, verifyOpenCheckoutMandate, verifyOpenPaymentMandate, verifyPaymentReceipt };