SDK reference · Rails
@provenanceauth/rails/deals
@provenanceauth/rails/deals in the Rails: 20 methods. @provenanceauth/rails/deals, agent-to-agent commerce.
Methods
decodeJws
decodeJws<P = Record<string, unknown>>(jws: string): DecodedJws<P> | nullSplit and parse a compact JWS (no signature check).
offerHash
offerHash(payload: OfferPayload | Record<string, unknown>): Promise<string>Sha256 (hex) of the offer's canonical JSON payload: the value the acceptance token binds.
itemsTotal
itemsTotal(items: Pick<OfferItem, "quantity" | "unit_price">[], currency: string): numberThe total of an offer's items, rounded to the currency's minor unit.
offerShapeError
offerShapeError(p: unknown, now?: unknown): string | nullShape-check an offer payload.
signOffer
signOffer(input: OfferInput, privateKey: Ed25519PrivateJwk, opts?: { now?: number; ttlSeconds?: number }): Promise<{ offer: string; payload: OfferPayload; offer_hash: string }>Sign an offer with the seller agent's Ed25519 private key (the one whose public half is registered at POST /v1/identify/agents/:id/signing_keys).
verifyOffer
verifyOffer(offer: string, opts: { keys: SellerKey[]; now?: number; buyerAgentId?: string; seller?: string }): Promise<OfferVerifyResult>Verify a signed offer against the seller's REGISTERED keys (never a key inside the offer): the signature, the key's status, expiry, the totals, the size, and aud when you pass the buyer.
offerPayloadOf
offerPayloadOf(offer: string | OfferPayload): OfferPayload | nullThe offer payload from a signed offer or a payload object (no checks).
confirmationCovers
confirmationCovers(sc: SellerConfirmation, offer: Pick<OfferPayload, "total" | "items">): booleanDoes the seller's policy offer a person's confirmation on this order?
contentHash
contentHash(content: string | Uint8Array): Promise<string>Sha256 (hex) of delivered bytes or text.
signDelivery
signDelivery(input: Omit<DeliveryPayload, "iat" | "kid" | "delivered_at"> & Partial<Pick<DeliveryPayload, "iat" | "kid" | "delivered_at">>, privateKey: Ed25519PrivateJwk): Promise<{ receipt: string; payload: DeliveryPayload }>Sign a delivery receipt with the seller's key (delivery+jwt).
deliveryShapeError
deliveryShapeError(p: unknown): string | nullverifyDelivery
verifyDelivery(receipt: string, opts: { keys: SellerKey[]; seller?: string }): Promise<DeliveryVerifyResult>Verify a delivery receipt against the seller's registered keys.
verifyDealAcceptance
verifyDealAcceptance(token: string, offer: string | OfferPayload, opts: { jwks: Jwks; seller?: string; revocations?: DealRevocations }): Promise<AcceptanceResult>The seller's offline check of a buyer's acceptance token: our ES256 signature against the JWKS you fetched, expiry, deal.offer_hash equal to YOUR offer's hash, the seller being you, aud, the revocation list you pass, and that every person the offer (or the buyer) required approved, with at least the method and tier asked for, over these exact terms.
verifyCounterparty
verifyCounterparty(query: { kid: string } | { agent_id: string; origin: string }, opts: { apiBase: string; fetch?: typeof fetch; cacheMs?: number; now?: number }): Promise<Counterparty>GET /v1/public/counterparties/check (keyless), cached for 5 minutes per query.
clearCounterpartyCache
clearCounterpartyCache(): voidForget cached counterparty answers (tests, or after you learn a key was revoked).
acceptOffer
acceptOffer(offer: string, opts: { apiBase: string; apiKey: string; agent_session_id: string; agent_id?: string; grant_id?: string; mandate_token?: string; purpose?: string; require_seller_person?: boolean; fetch?: typeof fetch; idempotencyKey?: string; }): Promise<{ object: "deal"; id: string; status: string; intent_token?: string; [k: string]: unknown }>The buyer's acceptance call: POST /v1/authorize/deals with the offer; resolves to the deal.
x402OfferRequired
x402OfferRequired(opts: { resource: X402ResourceInfo | string; accepts: X402PaymentRequirements[]; offer: string; error?: string }): voidSeller side: the 402 for a resource sold under a signed offer.
x402OfferOf
x402OfferOf(challenge: Pick<X402IntentChallenge, "extension">): string | nullBuyer side: the signed offer a 402 carries, or null.
dealTokenGetter
dealTokenGetter(accept: (offer: string, challenge: X402IntentChallenge) => Promise<{ status: string; intent_token?: string } | null>): voidBuyer side: a getToken for intentPaymentFetch that accepts the 402's offer through accept (usually ) and pays with the acceptance token.
verifyX402DealPayment
verifyX402DealPayment(paymentSignature: string | null | undefined, offer: string | OfferPayload, opts: { jwks: Jwks; seller?: string; revocations?: DealRevocations }): Promise<AcceptanceResult & { detail?: string }>Seller side: verify the acceptance token in a PAYMENT-SIGNATURE header against your offer (see ).