/** * Commerce Authorization Layer * * Unified API that normalizes authorization decisions across Stripe ACP, * Coinbase x402, Visa TAP, and Google AP2. Stripe + x402 are fully wired; * TAP + AP2 return fail-closed stubs in v0.5.0. * * Every decision carries an unsigned deterministic receipt for logging/audit. */ import type { PaymentTrustGrade, StripeACPSpendDecision, StripeACPContext, AgentPaymentVerification, TAPVerificationResult } from './types'; import type { X402VerifyDecision } from './x402'; import type { SignedReceipt, ReceiptSignerConfig } from '@bolyra/receipts'; /** Payment rail identifier. */ export type CommerceRail = 'stripe-acp' | 'x402' | 'visa-tap' | 'google-ap2'; /** What the agent wants to buy. */ export interface CommerceIntent { /** Which rail to use. */ rail: CommerceRail; /** Amount in minor units (cents, wei, etc.). */ amount: number; /** ISO 4217 or asset symbol (e.g. "USD", "USDC"). */ currency: string; /** Merchant / recipient identifier (opaque to the commerce layer). */ merchant: string; /** Optional human-readable description. */ description?: string; } /** Discriminated union of per-rail adapter results. */ export type CommerceAuthorizationInput = { intent: CommerceIntent & { rail: 'stripe-acp'; }; spendDecision: StripeACPSpendDecision; acpContext: StripeACPContext; } | { intent: CommerceIntent & { rail: 'x402'; }; adapterResult: X402VerifyDecision; } | { intent: CommerceIntent & { rail: 'visa-tap'; }; adapterResult: TAPVerificationResult; } | { intent: CommerceIntent & { rail: 'google-ap2'; }; adapterResult: AgentPaymentVerification; }; /** Normalized authorization decision — same shape for every rail. */ export interface CommerceAuthorizationDecision { /** Whether the commerce intent is authorized. */ allowed: boolean; /** Human-readable denial reason (only when allowed=false). */ reason?: string; /** Acting agent DID. */ did: string; /** Trust score (0-100). */ score: number; /** Letter grade. */ grade: PaymentTrustGrade; /** Warnings from the adapter / commerce layer. */ warnings: string[]; /** Deterministic receipt for logging. */ receipt: CommerceAuthorizationReceipt; /** Signed receipt (present when receiptSigner + receiptEvidence are provided). */ signedReceipt?: SignedReceipt; } /** Options for commerce authorization. */ export interface CommerceAuthorizationOptions { issuedAt?: number; receiptSigner?: ReceiptSignerConfig; receiptEvidence?: CommerceReceiptEvidence; } /** Evidence needed to build a signed commerce receipt. */ export interface CommerceReceiptEvidence { rootDid: string; credentialCommitment: string; effectiveCommitment: string; permissionBitmask: string; chainDepth: number; humanProof: { proof: unknown; }; agentProof: { proof: unknown; }; humanPublicSignals: string[]; agentPublicSignals: string[]; bundleVersion: 1 | 2; nonce: string; delegationChain?: unknown[]; } /** Unsigned deterministic receipt for audit logging. */ export interface CommerceAuthorizationReceipt { /** Schema version. */ v: 1; /** Deterministic receipt ID (first 16 hex chars of a SHA-256). */ id: string; /** Rail that produced this receipt. */ rail: CommerceRail; /** SHA-256 of the serialized intent. */ intentHash: string; /** Acting agent DID. */ did: string; /** Whether the intent was authorized. */ allowed: boolean; /** Unix timestamp (seconds) when the decision was issued. */ issuedAt: number; } /** * Authorize a commerce intent against a pre-computed adapter result. * * Stripe ACP and x402 are fully wired. Visa TAP and Google AP2 return * fail-closed stub denials in v0.5.0. */ export declare function authorizeCommerceIntent(input: CommerceAuthorizationInput, options?: CommerceAuthorizationOptions): CommerceAuthorizationDecision;