# @provenanceauth/rails/deals

@provenanceauth/rails/deals in the Rails: 20 methods. `@provenanceauth/rails/deals`, agent-to-agent commerce.

## Methods

### [decodeJws](https://provenanceauth.com/docs/sdks/rails/deals/decode-jws.md)

```ts
decodeJws<P = Record<string, unknown>>(jws: string): DecodedJws<P> | null
```

Split and parse a compact JWS (no signature check).

### [offerHash](https://provenanceauth.com/docs/sdks/rails/deals/offer-hash.md)

```ts
offerHash(payload: OfferPayload | Record<string, unknown>): Promise<string>
```

Sha256 (hex) of the offer's canonical JSON payload: the value the acceptance token binds.

### [itemsTotal](https://provenanceauth.com/docs/sdks/rails/deals/items-total.md)

```ts
itemsTotal(items: Pick<OfferItem, "quantity" | "unit_price">[], currency: string): number
```

The total of an offer's items, rounded to the currency's minor unit.

### [offerShapeError](https://provenanceauth.com/docs/sdks/rails/deals/offer-shape-error.md)

```ts
offerShapeError(p: unknown, now?: unknown): string | null
```

Shape-check an offer payload.

### [signOffer](https://provenanceauth.com/docs/sdks/rails/deals/sign-offer.md)

```ts
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](https://provenanceauth.com/docs/sdks/rails/deals/verify-offer.md)

```ts
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](https://provenanceauth.com/docs/sdks/rails/deals/offer-payload-of.md)

```ts
offerPayloadOf(offer: string | OfferPayload): OfferPayload | null
```

The offer payload from a signed offer or a payload object (no checks).

### [confirmationCovers](https://provenanceauth.com/docs/sdks/rails/deals/confirmation-covers.md)

```ts
confirmationCovers(sc: SellerConfirmation, offer: Pick<OfferPayload, "total" | "items">): boolean
```

Does the seller's policy offer a person's confirmation on this order?

### [contentHash](https://provenanceauth.com/docs/sdks/rails/deals/content-hash.md)

```ts
contentHash(content: string | Uint8Array): Promise<string>
```

Sha256 (hex) of delivered bytes or text.

### [signDelivery](https://provenanceauth.com/docs/sdks/rails/deals/sign-delivery.md)

```ts
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](https://provenanceauth.com/docs/sdks/rails/deals/delivery-shape-error.md)

```ts
deliveryShapeError(p: unknown): string | null
```

### [verifyDelivery](https://provenanceauth.com/docs/sdks/rails/deals/verify-delivery.md)

```ts
verifyDelivery(receipt: string, opts: { keys: SellerKey[]; seller?: string }): Promise<DeliveryVerifyResult>
```

Verify a delivery receipt against the seller's registered keys.

### [verifyDealAcceptance](https://provenanceauth.com/docs/sdks/rails/deals/verify-deal-acceptance.md)

```ts
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](https://provenanceauth.com/docs/sdks/rails/deals/verify-counterparty.md)

```ts
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](https://provenanceauth.com/docs/sdks/rails/deals/clear-counterparty-cache.md)

```ts
clearCounterpartyCache(): void
```

Forget cached counterparty answers (tests, or after you learn a key was revoked).

### [acceptOffer](https://provenanceauth.com/docs/sdks/rails/deals/accept-offer.md)

```ts
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](https://provenanceauth.com/docs/sdks/rails/deals/x402-offer-required.md)

```ts
x402OfferRequired(opts: { resource: X402ResourceInfo | string; accepts: X402PaymentRequirements[]; offer: string; error?: string }): void
```

Seller side: the 402 for a resource sold under a signed offer.

### [x402OfferOf](https://provenanceauth.com/docs/sdks/rails/deals/x402-offer-of.md)

```ts
x402OfferOf(challenge: Pick<X402IntentChallenge, "extension">): string | null
```

Buyer side: the signed offer a 402 carries, or null.

### [dealTokenGetter](https://provenanceauth.com/docs/sdks/rails/deals/deal-token-getter.md)

```ts
dealTokenGetter(accept: (offer: string, challenge: X402IntentChallenge) => Promise<{ status: string; intent_token?: string } | null>): void
```

Buyer side: a `getToken` for `intentPaymentFetch` that accepts the 402's offer through `accept` (usually ) and pays with the acceptance token.

### [verifyX402DealPayment](https://provenanceauth.com/docs/sdks/rails/deals/verify-x402-deal-payment.md)

```ts
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 ).
