Skip to content
Integra Protocol
API

@integraledger/lcp/x402

The exports of @integraledger/lcp/x402.

Interfaces

HttpRequest

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

Properties

PropertyType
bodyUint8Array
methodstring
targetstring

Unsigned

Properties

PropertyType
typedDataEip3009TypedData

Methods

complete()

complete(signature): Refusal | PaymentPayload

Parameters
ParameterType
signature`0x${string}`
Returns

Refusal | PaymentPayload


X402Choice

Extended by

Properties

PropertyType
acceptedPaymentRequirements
from`0x${string}`
nownumber
requiredPaymentRequired

X402Offer

Properties

PropertyType
optionsreadonly PaymentRequirements[]
requiredPaymentRequired

X402Read

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

Properties

PropertyType
agreement?string
h`0x${string}`
linkstring
offerX402Offer

Type Aliases

Eip3009Authorization

Eip3009Authorization = object

Properties

PropertyType
fromstring
noncestring
tostring
validAfterstring
validBeforestring
valuestring

Eip3009Payment

Eip3009Payment = PaymentPayload & object

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

Type Declaration

NameType
payloadobject
payload.authorizationEip3009Authorization
payload.signatureHex

LcpPattern

LcpPattern = object

Properties

PropertyTypeDescription
buyerSignsboolean-
canonicalboolean-
forwardIndexableboolean-
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.
onChainboolean-
pattern"native-field" | "overlay-contract" | "sidecar-attestation" | "opaque-challenge" | "id-reuse" | "protocol-extension" | "http-advisory" | "truncated-field"-
profile?string-
provesstring-
publicProofboolean-
zeroPartyRecoverableboolean-

OptionFilter

OptionFilter = (option) => true | 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

ParameterType
optionPaymentRequirements

Returns

true | Refusal | undefined


PaymentPayload

PaymentPayload = object

Properties

PropertyType
acceptedPaymentRequirements
extensions?PaymentRequired["extensions"]
payloadX402SchemePayload
resource?PaymentRequired["resource"]
x402Version2

PaymentRequired

PaymentRequired = object

Properties

PropertyType
acceptsPaymentRequirements[]
error?string
extensions?object
resourceobject
resource.urlstring
x402Version2

PaymentRequirements

PaymentRequirements = object

Properties

PropertyType
amountstring
assetstring
extra?object
maxTimeoutSecondsnumber
networkstring
payTostring
schemestring

Permit2Authorization

Permit2Authorization = object

Properties

PropertyType
deadlinestring
fromstring
noncestring
permittedobject
permitted.amountstring
permitted.tokenstring
spenderstring
witness?object

RequestCommitment

RequestCommitment = object

Properties

PropertyType
bodyDigestAtrHash
methodstring
pathstring
querystring

X402Advertise

X402Advertise = (doc, h, link, offer, agreementUrl?) => PaymentRequired | Refusal

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

Parameters

ParameterType
docPaymentRequired
hAtrHash
linkstring
offerPaymentRequirements
agreementUrl?string

Returns

PaymentRequired | 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, "payload"> & object

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

Type Declaration

NameType
payloadP

Type Parameters

Type Parameter
P

X402SchemePayload

X402SchemePayload = { authorization: Eip3009Authorization; signature: Hex; } | { permit2Authorization: Permit2Authorization; signature: Hex; } | { delegationManager: string; delegator: string; permissionContext: string; } | { authorization: Eip3009Authorization; salt: string; saltNonce?: string; signature: Hex; } | { permit2Authorization: Permit2Authorization; salt: string; saltNonce?: string; signature: Hex; }

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


X402Unsigned

X402Unsigned = { request: { kind: "eip712"; typedData: Permit2TypedData | Eip3009TypedData | ReceiveTypedData; }; complete: Refusal | PaymentPayload; } | { request: { amount: bigint; chainId: number; kind: "erc7710"; payTo: Hex; salt: AtrHash; token: Hex; }; complete: Refusal | 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; bound: (presented) => Promise<`0x${string}` | Refusal>; build: (choice, h) => Promise<Refusal | Unsigned>; claims: boolean; id: "x402/exact/eip155/eip3009"; pattern: LcpPattern; read: (doc) => Refusal | X402Read; recover: (ref, reader) => Promise<`0x${string}` | Refusal>; reference: (presented) => Promise<Refusal | Eip3009Ref>; status: (ref, reader) => Promise<EvmStatus>; tie: (accepts, request) => ["x402", { accepts: readonly PaymentRequirements[]; request: RequestCommitment; }]; unplaced: (option) => 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">


const LEGAL_CONTEXT: "legalContext" = "legalContext"


const LEGAL_CONTEXT_SCHEMA: Json


uptoPermit2

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

Functions

advertiseFor()

advertiseFor(filter): 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

ParameterType
filterOptionFilter

Returns

X402Advertise


chosen()

chosen(required, accepted, filter): true | 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

ParameterType
requiredunknown
acceptedunknown
filterOptionFilter

Returns

true | Refusal


filterOf()

filterOf(pairs, payable?): 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

ParameterType
pairs(option) => boolean
payable?(option) => boolean

Returns

OptionFilter


issuedDigest()

issuedDigest(v): Promise<`0x${string}` | Refusal>

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

Parameters

Returns

Promise<`0x${string}` | Refusal>


legalContextOf()

legalContextOf(extensions): 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

ParameterType
extensionsunknown

Returns

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

ParameterType
acceptsreadonly PaymentRequirements[]
offerPaymentRequirements

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

ParameterType
pairingstring

Returns

string


pairingOfPayment()

pairingOfPayment(p): 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

ParameterType
pPaymentPayload

Returns

X402PairingId | undefined


paymentWith()

paymentWith<P>(required, accepted, payload): X402Payment<P>

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

Type Parameters

Type Parameter
P

Parameters

ParameterType
requiredPaymentRequired
acceptedPaymentRequirements
payloadP

Returns

X402Payment<P>


presentedWith()

presentedWith(presented, filter): Refusal | { accepted: PaymentRequirements; extensions: unknown; payload: Record<string, unknown>; }

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

Parameters

ParameterType
presentedunknown
filterOptionFilter

Returns

Refusal | { accepted: PaymentRequirements; extensions: unknown; payload: Record<string, unknown>; }


readFor()

readFor(filter): (doc) => Refusal | 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

ParameterType
filterOptionFilter

Returns

(doc) => Refusal | X402Read


requestCommitment()

requestCommitment(r): Promise<Refusal | 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

ParameterType
rHttpRequest

Returns

Promise<Refusal | RequestCommitment>


tie()

tie(accepts, request): ["x402", { accepts: readonly PaymentRequirements[]; request: RequestCommitment; }]

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

Parameters

ParameterType
acceptsreadonly PaymentRequirements[]
requestRequestCommitment

Returns

["x402", { accepts: readonly PaymentRequirements[]; request: RequestCommitment; }]


withExtra()

withExtra(option, key, value): PaymentRequirements

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

Parameters

ParameterType
optionPaymentRequirements
keystring
valueJson

Returns

PaymentRequirements


withOption()

withOption(doc, at, option): PaymentRequired

The document with option at replaced.

Parameters

ParameterType
docPaymentRequired
atnumber
optionPaymentRequirements

Returns

PaymentRequired


withoutExtra()

withoutExtra(option, key): PaymentRequirements

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

Parameters

ParameterType
optionPaymentRequirements
keystring

Returns

PaymentRequirements

References

Eip3009TypedData

Re-exports Eip3009TypedData

Last updated on

On this page