@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
Unsigned
Properties
| Property | Type |
|---|---|
typedData | Eip3009TypedData |
Methods
complete()
complete(
signature):Refusal|PaymentPayload
Parameters
| Parameter | Type |
|---|---|
signature | `0x${string}` |
Returns
X402Choice
Extended by
Properties
| Property | Type |
|---|---|
accepted | PaymentRequirements |
from | `0x${string}` |
now | number |
required | PaymentRequired |
X402Offer
Properties
| Property | Type |
|---|---|
options | readonly PaymentRequirements[] |
required | 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 |
Type Aliases
Eip3009Authorization
Eip3009Authorization =
object
Properties
Eip3009Payment
Eip3009Payment =
PaymentPayload&object
A payment of the x402/exact/eip155/eip3009 pairing.
Type Declaration
| Name | Type |
|---|---|
payload | object |
payload.authorization | Eip3009Authorization |
payload.signature | Hex |
LcpPattern
LcpPattern =
object
Properties
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
| Parameter | Type |
|---|---|
option | PaymentRequirements |
Returns
true | Refusal | undefined
PaymentPayload
PaymentPayload =
object
Properties
| Property | Type |
|---|---|
accepted | PaymentRequirements |
extensions? | PaymentRequired["extensions"] |
payload | X402SchemePayload |
resource? | PaymentRequired["resource"] |
x402Version | 2 |
PaymentRequired
PaymentRequired =
object
Properties
| Property | Type |
|---|---|
accepts | 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 |
method | string |
path | string |
query | string |
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
| Parameter | Type |
|---|---|
doc | PaymentRequired |
h | AtrHash |
link | string |
offer | PaymentRequirements |
agreementUrl? | string |
Returns
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
| Name | Type |
|---|---|
payload | P |
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
constauthCaptureEip3009:BreadthBinding<"x402/auth-capture/eip155/eip3009">
authCapturePermit2
constauthCapturePermit2:BreadthBinding<"x402/auth-capture/eip155/permit2">
exactEip3009
constexactEip3009: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: readonlyPaymentRequirements[];request:RequestCommitment; }];unplaced: (option) =>PaymentRequirements; }>
exactErc7710
constexactErc7710:BreadthBinding<"x402/exact/eip155/erc7710"> =erc7710
exactErc7710Salt
constexactErc7710Salt:BreadthBinding<"x402/exact/eip155/erc7710-salt">
exactPermit2
constexactPermit2:BreadthBinding<"x402/exact/eip155/permit2">
LEGAL_CONTEXT
constLEGAL_CONTEXT:"legalContext"="legalContext"
LEGAL_CONTEXT_SCHEMA
constLEGAL_CONTEXT_SCHEMA:Json
uptoPermit2
constuptoPermit2: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
| Parameter | Type |
|---|---|
filter | OptionFilter |
Returns
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
| Parameter | Type |
|---|---|
required | unknown |
accepted | unknown |
filter | OptionFilter |
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
| Parameter | Type |
|---|---|
pairs | (option) => boolean |
payable? | (option) => boolean |
Returns
issuedDigest()
issuedDigest(
v):Promise<`0x${string}`|Refusal>
SHA-256 over the RFC 8785 form of an issued option or request commitment.
Parameters
| Parameter | Type |
|---|---|
v | PaymentRequirements | RequestCommitment |
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
| Parameter | Type |
|---|---|
extensions | unknown |
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
| Parameter | Type |
|---|---|
accepts | readonly PaymentRequirements[] |
offer | 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|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 |
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
| Parameter | Type |
|---|---|
required | PaymentRequired |
accepted | PaymentRequirements |
payload | P |
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
| Parameter | Type |
|---|---|
presented | unknown |
filter | OptionFilter |
Returns
Refusal | { accepted: PaymentRequirements; extensions: unknown; payload: Record<string, unknown>; }
readFor()
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 |
Returns
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
| Parameter | Type |
|---|---|
r | HttpRequest |
Returns
Promise<Refusal | RequestCommitment>
tie()
tie(
accepts,request): ["x402", {accepts: readonlyPaymentRequirements[];request:RequestCommitment; }]
The binding slot: every option the challenge offers, exactly as issued, and the request they answer.
Parameters
| Parameter | Type |
|---|---|
accepts | readonly PaymentRequirements[] |
request | RequestCommitment |
Returns
["x402", { accepts: readonly PaymentRequirements[]; request: RequestCommitment; }]
withExtra()
withExtra(
option,key,value):PaymentRequirements
A copy of an option with extra[key] = value.
Parameters
| Parameter | Type |
|---|---|
option | PaymentRequirements |
key | string |
value | Json |
Returns
withOption()
withOption(
doc,at,option):PaymentRequired
The document with option at replaced.
Parameters
| Parameter | Type |
|---|---|
doc | PaymentRequired |
at | number |
option | PaymentRequirements |
Returns
withoutExtra()
withoutExtra(
option,key):PaymentRequirements
A copy of an option with extra[key] removed; extra itself is removed when that leaves it empty.
Parameters
| Parameter | Type |
|---|---|
option | PaymentRequirements |
key | string |
Returns
References
Eip3009TypedData
Re-exports Eip3009TypedData
Last updated on