SDK reference · Rails
@provenanceauth/rails/ap2
@provenanceauth/rails/ap2 in the Rails: 17 methods. AP2 (Agent Payments Protocol) mapping + verification.
Methods
ap2Hash
ap2Hash(value: string, sdAlg?: string): stringBase64url(hash(ascii value)), the way AP2 and SD-JWT hash strings.
ap2CheckoutHash
ap2CheckoutHash(checkoutJwt: string, sdAlg?: string): stringThe checkout_hash (and Payment Mandate transaction_id) of a merchant-signed Checkout JWT.
decodeAp2SdJwt
decodeAp2SdJwt(serialized: string): Ap2SdJwt[]Parse an SD-JWT, or a ~~-joined chain of them as AP2's delegate examples print, into its parts, and resolve the disclosed content.
ap2MandatesOf
ap2MandatesOf(sdJwt: Ap2SdJwt): Array<Record<string, unknown>>The mandate content an SD-JWT discloses in delegate_payload (AP2's delegate format).
provenanceMandateToAp2OpenPayment
provenanceMandateToAp2OpenPayment(m: ProvenanceMandateView, opts: Ap2OpenPaymentOptions): { mandate: Ap2OpenPaymentMandate; not_mapped: string[] }A Provenance mandate → open Payment Mandate CONTENT (mandate.payment.open.1), unsigned: the Shopping Agent hands it to its Trusted Surface to sign.
ap2OpenPaymentToProvenance
ap2OpenPaymentToProvenance(content: Ap2OpenPaymentMandate): { constraints: ProvenanceMandateConstraints; currency: string | null; mandate_token: string | null; checkout_reference: string | null; unresolved: string[]; }Open Payment Mandate content → the Provenance mandate fields it expresses.
ap2BindingPayload
ap2BindingPayload(input: { checkout_jwt?: string; checkout_hash?: string; payee: Pick<Ap2Merchant, "id"> | string; payment_amount: Ap2Amount; }): Ap2BindingThe exact object to pass as action_payload to POST /v1/mandate/intents, so the token binds this Checkout (by hash), the payee and the amount.
ap2BindingHash
ap2BindingHash(b: Ap2Binding): Promise<string>Sha256(canonical JSON) of the binding: the value a bound token carries as payload_hash.
ap2CheckoutMandateContent
ap2CheckoutMandateContent(checkoutJwt: string, intentToken: string, opts?: { jwksUrl?: string; iat?: number; exp?: number }): Ap2CheckoutMandateClosed Checkout Mandate CONTENT (mandate.checkout.1) for a merchant-signed Checkout JWT, with the intent token in.
ap2PaymentMandateContent
ap2PaymentMandateContent(input: { checkout_jwt?: string; checkout_hash?: string; payee: Ap2Merchant; payment_amount: Ap2Amount; payment_instrument: Ap2PaymentInstrument; execution_date?: string; }, intentToken: string, opts?: { jwksUrl?: string; mandateToken?: string; iat?: number; exp?: number }): Ap2PaymentMandateClosed Payment Mandate CONTENT (mandate.payment.1) for the same Checkout, with the intent token in.
ap2ContentForCart
ap2ContentForCart(order: { total: number; currency: string; merchant_id: string; origin?: string }, opts: { checkoutJwt?: string | null; merchantName?: string; intentToken?: string; jwksUrl?: string }): { content: Ap2CartContent; reason?: undefined } | { content: null; reason: "checkout_jwt_missing" | "checkout_jwt_malformed" }Goal 7: AP2 checkout content for a store's cart, for an AP2 agent that arrived without a Checkout Mandate (or with one that doesn't cover this cart).
verifyAp2Mandate
verifyAp2Mandate(closed: Ap2ClosedMandate | Record<string, unknown>, opts: Ap2VerifyOptions): Promise<Ap2VerifyResult>Verify a closed AP2 Checkout or Payment Mandate (its content, as your AP2 stack returns it after checking the SD-JWT) against the Provenance intent token it carries: 1.
ap2ReceiptClaims
ap2ReceiptClaims(result: Ap2VerifyResult, opts: { iss: string; reference: string; iat?: number; order_id?: string; payment_id?: string; psp_confirmation_id?: string; network_confirmation_id?: string; }): Record<string, unknown>The claims of the Checkout or Payment Receipt a verifier returns (AP2 checkout_receipt.json / payment_receipt.json).
verifyAp2AppKeyAttestation
verifyAp2AppKeyAttestation(jws: string, issuers: Ap2UserMandateOptions["issuers"], now?: number): | { ok: true; issuer: string; jwk: Record<string, unknown>; sub: string | null; approval_id: string | null; exp: number | null } | { ok: false; reason: "issuer_not_trusted" | "signature_invalid" | "expired"; detail: string }Verify an app-key attestation (com.provenanceauth.app_key) against the listed issuers: ES256, typ ap2-app-key+jwt, a key of a listed issuer, unexpired, with a P-256 jwk.
verifyAp2UserMandate
verifyAp2UserMandate(serialized: string, opts: Ap2UserMandateOptions): Ap2UserMandateResultVerify a closed AP2 0.2 Checkout or Payment Mandate SD-JWT that the person signed on their own trusted surface (a wallet), as a confirmation of the verifier's cart: 1.
closeAp2OpenMandate
closeAp2OpenMandate(openSdJwt: string, input: { holderKey: { kty?: string; crv?: string; x: string; y: string; d: string }; content: Record<string, unknown>; aud: string; nonce?: string; iat?: number; }): Promise<string>Slice 2: the agent closes an open mandate for one transaction (AP2's Human Not Present mode): an SD-JWT signed with the agent's private key (the open mandate's cnf.jwk), disclosing the closed mandate, naming the verifier's origin (aud) and binding the open SD-JWT by sd_hash.
verifyAp2UserMandateOnline
verifyAp2UserMandateOnline(serialized: string, opts: Ap2UserMandateOptions & { onlineStatus: (jti: string, token: string) => Promise<{ revoked: boolean; reason?: string }> }): Promise<Ap2UserMandateResult>Then the revocation of the intent token the mandate carries (com.provenanceauth.intent), through your online status check (e.g.