# @integraledger/lcp/x402

> The exports of @integraledger/lcp/x402.

Source: https://lcp.integraledger.com/reference/api/x402

## Interfaces

### HttpRequest

An HTTP request as received: the method token, the raw origin-form target and the body bytes.

#### Properties

| Property  | Type         |
| --------- | ------------ |
|  `body`   | `Uint8Array` |
|  `method` | `string`     |
|  `target` | `string`     |

***

### Unsigned

#### Properties

| Property     | Type                                                      |
| ------------ | --------------------------------------------------------- |
|  `typedData` | [`Eip3009TypedData`](https://lcp.integraledger.com/reference/api/evm#eip3009typeddata) |

#### Methods

##### complete()

> **complete**(`signature`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PaymentPayload`](#paymentpayload)

###### Parameters

| Parameter   | Type                |
| ----------- | ------------------- |
| `signature` | `` `0x${string}` `` |

###### Returns

[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PaymentPayload`](#paymentpayload)

***

### X402Choice

#### Extended by

* [`BatchEvmOpen`](https://lcp.integraledger.com/reference/api/x402-batch-settlement#batchevmopen)

#### Properties

| Property    | Type                                          |
| ----------- | --------------------------------------------- |
|  `accepted` | [`PaymentRequirements`](#paymentrequirements) |
|  `from`     | `` `0x${string}` ``                           |
|  `now`      | `number`                                      |
|  `required` | [`PaymentRequired`](#paymentrequired)         |

***

### X402Offer

#### Properties

| Property    | Type                                                      |
| ----------- | --------------------------------------------------------- |
|  `options`  | readonly [`PaymentRequirements`](#paymentrequirements)\[] |
|  `required` | [`PaymentRequired`](#paymentrequired)                     |

***

### X402Read

What a pairing's `read` returns: the hash, the link, the agreement URL when the document carries one, the offer.

#### Properties

| Property      | Type                      |
| ------------- | ------------------------- |
|  `agreement?` | `string`                  |
|  `h`          | `` `0x${string}` ``       |
|  `link`       | `string`                  |
|  `offer`      | [`X402Offer`](#x402offer) |

## Type Aliases

### Eip3009Authorization

> **Eip3009Authorization** = `object`

#### Properties

| Property       | Type     |
| -------------- | -------- |
|  `from`        | `string` |
|  `nonce`       | `string` |
|  `to`          | `string` |
|  `validAfter`  | `string` |
|  `validBefore` | `string` |
|  `value`       | `string` |

***

### Eip3009Payment

> **Eip3009Payment** = [`PaymentPayload`](#paymentpayload) & `object`

A payment of the `x402/exact/eip155/eip3009` pairing.

#### Type Declaration

| Name                    | Type                                            |
| ----------------------- | ----------------------------------------------- |
| `payload`               | `object`                                        |
| `payload.authorization` | [`Eip3009Authorization`](#eip3009authorization) |
| `payload.signature`     | [`Hex`](https://lcp.integraledger.com/reference/api/evm#hex)                 |

***

### LcpPattern

> **LcpPattern** = `object`

#### Properties

| Property                | Type                                                                                                                                                                              | Description                                                                                                                                                                                                                                                                          |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|  `buyerSigns`           | `boolean`                                                                                                                                                                         | -                                                                                                                                                                                                                                                                                    |
|  `canonical`            | `boolean`                                                                                                                                                                         | -                                                                                                                                                                                                                                                                                    |
|  `forwardIndexable`     | `boolean`                                                                                                                                                                         | -                                                                                                                                                                                                                                                                                    |
|  `instrument?`          | `"landed"`                                                                                                                                                                        | Where the buyer signs no hash, what identifies one payment. Absent: the pairing's `reference` for that payment. `"landed"`: the buyer presents standing authority, redeemed once per payment, so a payment is the transfer that lands, and the landed transaction is the instrument. |
|  `onChain`              | `boolean`                                                                                                                                                                         | -                                                                                                                                                                                                                                                                                    |
|  `pattern`              | `"native-field"` \| `"overlay-contract"` \| `"sidecar-attestation"` \| `"opaque-challenge"` \| `"id-reuse"` \| `"protocol-extension"` \| `"http-advisory"` \| `"truncated-field"` | -                                                                                                                                                                                                                                                                                    |
|  `profile?`             | `string`                                                                                                                                                                          | -                                                                                                                                                                                                                                                                                    |
|  `proves`               | `string`                                                                                                                                                                          | -                                                                                                                                                                                                                                                                                    |
|  `publicProof`          | `boolean`                                                                                                                                                                         | -                                                                                                                                                                                                                                                                                    |
|  `zeroPartyRecoverable` | `boolean`                                                                                                                                                                         | -                                                                                                                                                                                                                                                                                    |

***

### OptionFilter

> **OptionFilter** = (`option`) => `true` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | `undefined`

A pairing's option filter: `true` for an option the pairing serves, a refusal naming why an option of this pairing
cannot be served, and undefined for an option that is not this pairing's.

#### Parameters

| Parameter | Type                                          |
| --------- | --------------------------------------------- |
| `option`  | [`PaymentRequirements`](#paymentrequirements) |

#### Returns

`true` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | `undefined`

***

### PaymentPayload

> **PaymentPayload** = `object`

#### Properties

| Property       | Type                                                   |
| -------------- | ------------------------------------------------------ |
|  `accepted`    | [`PaymentRequirements`](#paymentrequirements)          |
|  `extensions?` | [`PaymentRequired`](#paymentrequired)\[`"extensions"`] |
|  `payload`     | [`X402SchemePayload`](#x402schemepayload)              |
|  `resource?`   | [`PaymentRequired`](#paymentrequired)\[`"resource"`]   |
|  `x402Version` | `2`                                                    |

***

### PaymentRequired

> **PaymentRequired** = `object`

#### Properties

| Property       | Type                                             |
| -------------- | ------------------------------------------------ |
|  `accepts`     | [`PaymentRequirements`](#paymentrequirements)\[] |
|  `error?`      | `string`                                         |
|  `extensions?` | `object`                                         |
|  `resource`    | `object`                                         |
| `resource.url` | `string`                                         |
|  `x402Version` | `2`                                              |

***

### PaymentRequirements

> **PaymentRequirements** = `object`

#### Properties

| Property             | Type     |
| -------------------- | -------- |
|  `amount`            | `string` |
|  `asset`             | `string` |
|  `extra?`            | `object` |
|  `maxTimeoutSeconds` | `number` |
|  `network`           | `string` |
|  `payTo`             | `string` |
|  `scheme`            | `string` |

***

### Permit2Authorization

> **Permit2Authorization** = `object`

#### Properties

| Property           | Type     |
| ------------------ | -------- |
|  `deadline`        | `string` |
|  `from`            | `string` |
|  `nonce`           | `string` |
|  `permitted`       | `object` |
| `permitted.amount` | `string` |
| `permitted.token`  | `string` |
|  `spender`         | `string` |
|  `witness?`        | `object` |

***

### RequestCommitment

> **RequestCommitment** = `object`

#### Properties

| Property      | Type                                |
| ------------- | ----------------------------------- |
|  `bodyDigest` | [`AtrHash`](https://lcp.integraledger.com/reference/api#atrhash) |
|  `method`     | `string`                            |
|  `path`       | `string`                            |
|  `query`      | `string`                            |

***

### X402Advertise

> **X402Advertise** = (`doc`, `h`, `link`, `offer`, `agreementUrl?`) => [`PaymentRequired`](#paymentrequired) | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)

A pairing's `advertise`: the document with the legal context placed, and the agreement URL when one is given.

#### Parameters

| Parameter       | Type                                          |
| --------------- | --------------------------------------------- |
| `doc`           | [`PaymentRequired`](#paymentrequired)         |
| `h`             | [`AtrHash`](https://lcp.integraledger.com/reference/api#atrhash)           |
| `link`          | `string`                                      |
| `offer`         | [`PaymentRequirements`](#paymentrequirements) |
| `agreementUrl?` | `string`                                      |

#### Returns

[`PaymentRequired`](#paymentrequired) | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)

***

### X402PairingId

> **X402PairingId** = *typeof* `ID` | `"x402/exact/eip155/permit2"` | `"x402/exact/eip155/erc7710"` | `"x402/exact/eip155/erc7710-salt"` | `"x402/upto/eip155/permit2"` | `"x402/auth-capture/eip155/eip3009"` | `"x402/auth-capture/eip155/permit2"`

***

### X402Payment

> **X402Payment**\<`P`> = `Omit`\<[`PaymentPayload`](#paymentpayload), `"payload"`> & `object`

An x402 v2 payment whose `payload` is the pairing's own.

#### Type Declaration

| Name      | Type |
| --------- | ---- |
| `payload` | `P`  |

#### Type Parameters

| Type Parameter |
| -------------- |
| `P`            |

***

### X402SchemePayload

> **X402SchemePayload** = \{ `authorization`: [`Eip3009Authorization`](#eip3009authorization); `signature`: [`Hex`](https://lcp.integraledger.com/reference/api/evm#hex); } | \{ `permit2Authorization`: [`Permit2Authorization`](#permit2authorization); `signature`: [`Hex`](https://lcp.integraledger.com/reference/api/evm#hex); } | \{ `delegationManager`: `string`; `delegator`: `string`; `permissionContext`: `string`; } | \{ `authorization`: [`Eip3009Authorization`](#eip3009authorization); `salt`: `string`; `saltNonce?`: `string`; `signature`: [`Hex`](https://lcp.integraledger.com/reference/api/evm#hex); } | \{ `permit2Authorization`: [`Permit2Authorization`](#permit2authorization); `salt`: `string`; `saltNonce?`: `string`; `signature`: [`Hex`](https://lcp.integraledger.com/reference/api/evm#hex); }

The payload of each x402 EVM scheme this package carries; every member is a string.

***

### X402Unsigned

> **X402Unsigned** = \{ `request`: \{ `kind`: `"eip712"`; `typedData`: [`Permit2TypedData`](https://lcp.integraledger.com/reference/api/evm#permit2typeddata) | [`Eip3009TypedData`](https://lcp.integraledger.com/reference/api/evm#eip3009typeddata) | [`ReceiveTypedData`](https://lcp.integraledger.com/reference/api/evm#receivetypeddata); }; `complete`: [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PaymentPayload`](#paymentpayload); } | \{ `request`: \{ `amount`: `bigint`; `chainId`: `number`; `kind`: `"erc7710"`; `payTo`: [`Hex`](https://lcp.integraledger.com/reference/api/evm#hex); `salt`: [`AtrHash`](https://lcp.integraledger.com/reference/api#atrhash); `token`: [`Hex`](https://lcp.integraledger.com/reference/api/evm#hex); }; `complete`: [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PaymentPayload`](#paymentpayload); }

What a breadth pairing's `build` asks the buyer's signer for, and how the answer completes the payment.

## Variables

### authCaptureEip3009

> `const` **authCaptureEip3009**: `BreadthBinding`\<`"x402/auth-capture/eip155/eip3009"`>

***

### authCapturePermit2

> `const` **authCapturePermit2**: `BreadthBinding`\<`"x402/auth-capture/eip155/permit2"`>

***

### exactEip3009

> `const` **exactEip3009**: `Readonly`\<\{ `advertise`: [`X402Advertise`](#x402advertise); `bound`: (`presented`) => `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>; `build`: (`choice`, `h`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`Unsigned`](#unsigned)>; `claims`: `boolean`; `id`: `"x402/exact/eip155/eip3009"`; `pattern`: [`LcpPattern`](#lcppattern); `read`: (`doc`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`X402Read`](#x402read); `recover`: (`ref`, `reader`) => `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>; `reference`: (`presented`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`Eip3009Ref`](https://lcp.integraledger.com/reference/api/evm#eip3009ref)>; `status`: (`ref`, `reader`) => `Promise`\<[`EvmStatus`](https://lcp.integraledger.com/reference/api/evm#evmstatus)>; `tie`: (`accepts`, `request`) => \[`"x402"`, \{ `accepts`: readonly [`PaymentRequirements`](#paymentrequirements)\[]; `request`: [`RequestCommitment`](#requestcommitment); }]; `unplaced`: (`option`) => [`PaymentRequirements`](#paymentrequirements); }>

***

### exactErc7710

> `const` **exactErc7710**: `BreadthBinding`\<`"x402/exact/eip155/erc7710"`> = `erc7710`

***

### exactErc7710Salt

> `const` **exactErc7710Salt**: `BreadthBinding`\<`"x402/exact/eip155/erc7710-salt"`>

***

### exactPermit2

> `const` **exactPermit2**: `BreadthBinding`\<`"x402/exact/eip155/permit2"`>

***

### LEGAL\_CONTEXT

> `const` **LEGAL\_CONTEXT**: `"legalContext"` = `"legalContext"`

***

### LEGAL\_CONTEXT\_SCHEMA

> `const` **LEGAL\_CONTEXT\_SCHEMA**: [`Json`](https://lcp.integraledger.com/reference/api#json)

***

### uptoPermit2

> `const` **uptoPermit2**: `BreadthBinding`\<`"x402/upto/eip155/permit2"`>

## Functions

### advertiseFor()

> **advertiseFor**(`filter`): [`X402Advertise`](#x402advertise)

The seller's placement over a pairing's filter: a copy of `doc` whose `extensions.legalContext` carries the hash, the link and, when
given, the agreement URL after the link. The legal context is one per document, so each pairing placing the same
values into it leaves it as it is. Other extensions are kept and `accepts` is untouched. It refuses an `offer` outside
`doc.accepts` or refused by the filter, a link or an agreement URL as `read` refuses it, and a legal context already
present with other values.

#### Parameters

| Parameter | Type                            |
| --------- | ------------------------------- |
| `filter`  | [`OptionFilter`](#optionfilter) |

#### Returns

[`X402Advertise`](#x402advertise)

***

### chosen()

> **chosen**(`required`, `accepted`, `filter`): `true` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)

The checks `build` makes on the buyer's choice before anything pairing-specific: the document is x402 v2 with at
most 32 options, the chosen option is one it offers, and the filter serves it.

#### Parameters

| Parameter  | Type                            |
| ---------- | ------------------------------- |
| `required` | `unknown`                       |
| `accepted` | `unknown`                       |
| `filter`   | [`OptionFilter`](#optionfilter) |

#### Returns

`true` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)

***

### filterOf()

> **filterOf**(`pairs`, `payable?`): [`OptionFilter`](#optionfilter)

The filter for the options `pairs` accepts: those that `payable` also accepts (every one, without it) are served,
and the rest are refused `x402/option-malformed`.

#### Parameters

| Parameter  | Type                    |
| ---------- | ----------------------- |
| `pairs`    | (`option`) => `boolean` |
| `payable?` | (`option`) => `boolean` |

#### Returns

[`OptionFilter`](#optionfilter)

***

### issuedDigest()

> **issuedDigest**(`v`): `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>

SHA-256 over the RFC 8785 form of an issued option or request commitment.

#### Parameters

| Parameter | Type                                                                                       |
| --------- | ------------------------------------------------------------------------------------------ |
| `v`       | [`PaymentRequirements`](#paymentrequirements) \| [`RequestCommitment`](#requestcommitment) |

#### Returns

`Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>

***

### legalContextOf()

> **legalContextOf**(`extensions`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `h`: `` `0x${string}` ``; `link`: `string`; }

The hash and link in a document's `extensions.legalContext`, or the refusal that names what is wrong.

#### Parameters

| Parameter    | Type      |
| ------------ | --------- |
| `extensions` | `unknown` |

#### Returns

[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `h`: `` `0x${string}` ``; `link`: `string`; }

***

### offeredAt()

> **offeredAt**(`accepts`, `offer`): `number`

The index of the first of `accepts` that is `offer`, by identity or by equal RFC 8785 form, or -1.

#### Parameters

| Parameter | Type                                                      |
| --------- | --------------------------------------------------------- |
| `accepts` | readonly [`PaymentRequirements`](#paymentrequirements)\[] |
| `offer`   | [`PaymentRequirements`](#paymentrequirements)             |

#### Returns

`number`

***

### optionPairingOf()

> **optionPairingOf**(`pairing`): `string`

The pairing whose option a payment through `pairing` pays: a payment at the ERC-7710 salt level pays the `erc7710`
option (both levels share it); a payment through any other pairing pays an option of its own.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `pairing` | `string` |

#### Returns

`string`

***

### pairingOfPayment()

> **pairingOfPayment**(`p`): [`X402PairingId`](#x402pairingid) | `undefined`

The pairing that serves a presented payment: `pairingOf` of its `accepted`, except that an `erc7710` payment whose
delegation manager is MetaMask's reference DelegationManager, on a chain where it is deployed, is the salt level.

#### Parameters

| Parameter | Type                                |
| --------- | ----------------------------------- |
| `p`       | [`PaymentPayload`](#paymentpayload) |

#### Returns

[`X402PairingId`](#x402pairingid) | `undefined`

***

### paymentWith()

> **paymentWith**\<`P`>(`required`, `accepted`, `payload`): [`X402Payment`](#x402payment)\<`P`>

The payment for the chosen option: the challenge's `resource` and `extensions` unchanged, omitted when absent.

#### Type Parameters

| Type Parameter |
| -------------- |
| `P`            |

#### Parameters

| Parameter  | Type                                          |
| ---------- | --------------------------------------------- |
| `required` | [`PaymentRequired`](#paymentrequired)         |
| `accepted` | [`PaymentRequirements`](#paymentrequirements) |
| `payload`  | `P`                                           |

#### Returns

[`X402Payment`](#x402payment)\<`P`>

***

### presentedWith()

> **presentedWith**(`presented`, `filter`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `accepted`: [`PaymentRequirements`](#paymentrequirements); `extensions`: `unknown`; `payload`: `Record`\<`string`, `unknown`>; }

A presented payment's `accepted`, served by the filter, its `payload` object and its `extensions`.

#### Parameters

| Parameter   | Type                            |
| ----------- | ------------------------------- |
| `presented` | `unknown`                       |
| `filter`    | [`OptionFilter`](#optionfilter) |

#### Returns

[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `accepted`: [`PaymentRequirements`](#paymentrequirements); `extensions`: `unknown`; `payload`: `Record`\<`string`, `unknown`>; }

***

### readFor()

> **readFor**(`filter`): (`doc`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`X402Read`](#x402read)

The buyer's reading over a pairing's filter: the hash, the link, the agreement URL when `extensions.legalContext` carries one, and
the options the filter serves, in document order. A link or agreement URL of at most 2048 characters that parses as
an absolute URL with a scheme other than `https` is `x402/link-not-https`; any other value that is not a link, or two
spellings that disagree, is `x402/legal-context-malformed`.

#### Parameters

| Parameter | Type                            |
| --------- | ------------------------------- |
| `filter`  | [`OptionFilter`](#optionfilter) |

#### Returns

(`doc`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`X402Read`](#x402read)

***

### requestCommitment()

> **requestCommitment**(`r`): `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`RequestCommitment`](#requestcommitment)>

The commitment to the request a challenge answers: the method as received, the target split at its first `?`, and
SHA-256 over the body bytes exactly as received.

#### Parameters

| Parameter | Type                          |
| --------- | ----------------------------- |
| `r`       | [`HttpRequest`](#httprequest) |

#### Returns

`Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`RequestCommitment`](#requestcommitment)>

***

### tie()

> **tie**(`accepts`, `request`): \[`"x402"`, \{ `accepts`: readonly [`PaymentRequirements`](#paymentrequirements)\[]; `request`: [`RequestCommitment`](#requestcommitment); }]

The binding slot: every option the challenge offers, exactly as issued, and the request they answer.

#### Parameters

| Parameter | Type                                                      |
| --------- | --------------------------------------------------------- |
| `accepts` | readonly [`PaymentRequirements`](#paymentrequirements)\[] |
| `request` | [`RequestCommitment`](#requestcommitment)                 |

#### Returns

\[`"x402"`, \{ `accepts`: readonly [`PaymentRequirements`](#paymentrequirements)\[]; `request`: [`RequestCommitment`](#requestcommitment); }]

***

### withExtra()

> **withExtra**(`option`, `key`, `value`): [`PaymentRequirements`](#paymentrequirements)

A copy of an option with `extra[key] = value`.

#### Parameters

| Parameter | Type                                          |
| --------- | --------------------------------------------- |
| `option`  | [`PaymentRequirements`](#paymentrequirements) |
| `key`     | `string`                                      |
| `value`   | [`Json`](https://lcp.integraledger.com/reference/api#json)                 |

#### Returns

[`PaymentRequirements`](#paymentrequirements)

***

### withOption()

> **withOption**(`doc`, `at`, `option`): [`PaymentRequired`](#paymentrequired)

The document with option `at` replaced.

#### Parameters

| Parameter | Type                                          |
| --------- | --------------------------------------------- |
| `doc`     | [`PaymentRequired`](#paymentrequired)         |
| `at`      | `number`                                      |
| `option`  | [`PaymentRequirements`](#paymentrequirements) |

#### Returns

[`PaymentRequired`](#paymentrequired)

***

### withoutExtra()

> **withoutExtra**(`option`, `key`): [`PaymentRequirements`](#paymentrequirements)

A copy of an option with `extra[key]` removed; `extra` itself is removed when that leaves it empty.

#### Parameters

| Parameter | Type                                          |
| --------- | --------------------------------------------- |
| `option`  | [`PaymentRequirements`](#paymentrequirements) |
| `key`     | `string`                                      |

#### Returns

[`PaymentRequirements`](#paymentrequirements)

## References

### Eip3009TypedData

Re-exports [Eip3009TypedData](https://lcp.integraledger.com/reference/api/evm#eip3009typeddata)
