@integraledger/lcp/spend-permissions
The Spend Permission exchange and the pairing `spend-permissions/eip155`: an account's approval, on the SpendPermissionManager, of a Spend Permission whose `salt` is the ATR hash, as the sale's agreement.
For AI agents: this page as Markdown, and llms.txt, the index of every page.
The Spend Permission exchange and the pairing spend-permissions/eip155: an account's approval, on the
SpendPermissionManager, of a Spend Permission whose salt is the ATR hash, as the sale's agreement.
The offer in a 402 body, the typed data the account signs or the approve call it makes, the Spend-Permission
return header, the resource server's checks, the permission's hash as the manager computes it, and the read of the
approval by that hash, as the profile spend-permissions/eip155 states them. No key is held, nothing is signed, and
nothing is read but through the reader a caller supplies.
Interfaces
SpendPermission
A Spend Permission as the exchange writes it: its nine members, each integer a string of decimal digits with no sign
and no leading zero, each address 0x and 40 hex digits, extraData 0x and an even number of hex digits.
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
account | readonly | `0x${string}` | - |
allowance | readonly | string | A uint160. |
end | readonly | string | A uint48, a Unix time in seconds. |
extraData | readonly | `0x${string}` | - |
period | readonly | string | A uint48, in seconds. |
salt | readonly | string | A uint256: H, as a decimal. |
spender | readonly | `0x${string}` | - |
start | readonly | string | A uint48, a Unix time in seconds. |
token | readonly | `0x${string}` | - |
SpendPermissionBody
The 402 body: the offer, and on a refused return the code that refused it.
Properties
| Property | Modifier | Type |
|---|---|---|
error? | readonly | SpendPermissionError |
spendPermission | readonly | SpendPermissionOffer |
SpendPermissionChoice
The buyer's inputs to build: the offer as read gave it, and the account that approves.
Properties
| Property | Modifier | Type |
|---|---|---|
account | readonly | `0x${string}` |
offer | readonly | SpendPermissionOffer |
SpendPermissionOffer
The offer the 402 body's spendPermission member holds.
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
accepts | readonly | readonly SpendPermissionRoute[] | The routes the resource server takes, each once. |
legalContext | readonly | object | - |
legalContext.legalContextUrl | readonly | string | - |
legalContext.type | readonly | "sha256" | - |
legalContext.value | readonly | `0x${string}` | - |
manager | readonly | `0x${string}` | The SpendPermissionManager's address on network. |
network | readonly | `eip155:${string}` | - |
permission | readonly | OfferedPermission | Every member of the permission but account, salt being H. |
SpendPermissionOfferInput
What the resource server offers before H is placed: the offer without legalContext, and salt absent or H.
Properties
| Property | Modifier | Type |
|---|---|---|
accepts | readonly | readonly SpendPermissionRoute[] |
manager | readonly | `0x${string}` |
network | readonly | `eip155:${string}` |
permission | readonly | Omit<OfferedPermission, "salt"> & object |
SpendPermissionRef
The reference the read takes: the option's payee is the permission's spender.
Extends
Properties
| Property | Modifier | Type | Description | Overrides | Inherited from |
|---|---|---|---|---|---|
h | readonly | `0x${string}` | H, the permission's salt. | - | - |
hash | readonly | `0x${string}` | The permission's hash, the search key. | - | - |
manager | readonly | `0x${string}` | The SpendPermissionManager the permission is approved on. | - | - |
network | readonly | `eip155:${string}` | - | EvmReadRefBase.network | - |
payee | readonly | string | - | - | EvmReadRefBase.payee |
permission | readonly | SpendPermission | The permission whole, as presented: the members presented compares, and the argument of the value's two reads. | - | - |
transaction? | readonly | `0x${string}` | A transaction a settler or the caller named, read beside the search; never needed. | - | EvmReadRefBase.transaction |
SpendPermissionTypedData
The EIP-712 typed data of the permission in the manager's domain, as a signer takes it.
Properties
| Property | Modifier | Type |
|---|---|---|
domain | readonly | object |
domain.chainId | readonly | number |
domain.name | readonly | string |
domain.verifyingContract | readonly | `0x${string}` |
domain.version | readonly | string |
message | readonly | object |
message.account | readonly | `0x${string}` |
message.allowance | readonly | bigint |
message.end | readonly | bigint |
message.extraData | readonly | `0x${string}` |
message.period | readonly | bigint |
message.salt | readonly | bigint |
message.spender | readonly | `0x${string}` |
message.start | readonly | bigint |
message.token | readonly | `0x${string}` |
primaryType | readonly | "SpendPermission" |
types | readonly | object |
types.SpendPermission | readonly | readonly object[] |
SpendPermissionUnsigned
What build gives the account: the whole permission, its hash, the typed data it signs on "signature", and the
manager's approve call it makes on "transaction".
Properties
| Property | Modifier | Type |
|---|---|---|
approve | readonly | object |
approve.data | readonly | `0x${string}` |
approve.to | readonly | `0x${string}` |
hash | readonly | `0x${string}` |
permission | readonly | SpendPermission |
typedData | readonly | SpendPermissionTypedData |
Type Aliases
OfferedPermission
OfferedPermission =
Omit<SpendPermission,"account">
The permission as the offer writes it: every member but account.
SpendPermissionError
SpendPermissionError =
"spend-permissions/not-bound"|"spend-permissions/signature-invalid"|"spend-permissions/not-approved"|"spend-permissions/revoked"|"spend-permissions/ended"|"spend-permissions/header-malformed"|"spend-permissions/route-not-accepted"|"spend-permissions/account-is-spender"
The codes a refused return is answered with, in the 402 body's error member.
SpendPermissionReturn
SpendPermissionReturn =
object& {signature:Hex;transaction?:never; } | {signature?:never;transaction:Hex; }
The return a Spend-Permission header carries: the whole permission, and the account's signature or transaction.
Type Declaration
| Name | Type |
|---|---|
manager | Hex |
network | Eip155 |
permission | SpendPermission |
SpendPermissionRoute
SpendPermissionRoute =
"signature"|"transaction"
The route the account's act took: its signature, or its own transaction.
Variables
APPROVE_SELECTOR
constAPPROVE_SELECTOR:`0x${string}`
approve(SpendPermission).
APPROVE_WITH_SIGNATURE_SELECTOR
constAPPROVE_WITH_SIGNATURE_SELECTOR:`0x${string}`
approveWithSignature(SpendPermission,bytes).
IS_APPROVED_SELECTOR
constIS_APPROVED_SELECTOR:`0x${string}`
isApproved(SpendPermission).
IS_REVOKED_SELECTOR
constIS_REVOKED_SELECTOR:`0x${string}`
isRevoked(SpendPermission).
SPEND_PERMISSION_APPROVED_TOPIC
constSPEND_PERMISSION_APPROVED_TOPIC:`0x${string}`
SpendPermissionApproved(bytes32,SpendPermission)'s topic.
SPEND_PERMISSION_DOMAIN
constSPEND_PERMISSION_DOMAIN:Readonly<{name:"Spend Permission Manager";version:"1"; }>
The manager's EIP-712 domain name and version.
SPEND_PERMISSION_HEADER
constSPEND_PERMISSION_HEADER:"Spend-Permission"="Spend-Permission"
The request header field that carries the return.
SPEND_PERMISSION_REVOKED_TOPIC
constSPEND_PERMISSION_REVOKED_TOPIC:`0x${string}`
SpendPermissionRevoked(bytes32,SpendPermission)'s topic.
SPEND_PERMISSION_TYPEHASH
constSPEND_PERMISSION_TYPEHASH:`0x${string}`
keccak256 of the manager's SpendPermission type (SPEND_PERMISSION_TYPEHASH).
spendPermissionsEip155
constspendPermissionsEip155:Readonly<{advertise: (_doc,h,link,offer,error?) =>Refusal|SpendPermissionBody;bound: (presented,given?) =>Promise<Refusal|`0x${string}`>;broadcaster: (presented) =>Promise<Refusal|Broadcaster>;build: (choice,h) =>Promise<Refusal|SpendPermissionUnsigned>;claims:boolean;data:PairingData;id:"spend-permissions/eip155";pattern:LcpPattern;read: (doc) =>Refusal| {error?:SpendPermissionError;h:`0x${string}`;link:string;offer:SpendPermissionOffer; };reference: (presented,option,given?) =>Promise<Refusal|SpendPermissionRef>;status: (ref,reader,query) =>Promise<EvmStatus>;tie: (offer) => ["spendPermission",SpendPermissionOffer];unplaced: (option) =>Refusal|SpendPermissionOffer|SpendPermissionOfferInput; }>
spend-permissions/eip155. On "signature" the resource server submits the approval (broadcaster answers
"payee"); on "transaction" the account has already made it ("payer"). status reads the approval by the
permission's hash; approvedIn reads the transaction that should hold it.
Functions
approvedIn()
approvedIn(
presented,reader,transaction?):Promise<Refusal| {block:bigint;transaction:`0x${string}`; }>
The read of the transaction that should hold the approval: on "transaction" the one the return names, and on
"signature" the resource server's own submission of approveWithSignature, given as transaction. It gives the
block of a transaction whose receipt's status is 1 and that holds the manager's SpendPermissionApproved for the
permission's hash, the permission whole; otherwise spend-permissions/revoked where the manager reads the permission
revoked in the state after its block, and spend-permissions/not-approved. The return is read as rule 8 takes it.
evm/wrong-reader for a reader of another network, evm/not-found where the reader holds no receipt yet and
evm/unreadable where a read failed or answered out of its form, each before anything is decided.
Parameters
| Parameter | Type |
|---|---|
presented | unknown |
reader | EvmReader |
transaction? | `0x${string}` |
Returns
Promise<Refusal | { block: bigint; transaction: `0x${string}`; }>
checkReturn()
checkReturn(
presented,offer,now):Refusal|SpendPermissionReturn
The resource server's checks of a return before it submits or serves, in the profile's order (rule 9): the return
as rule 8 takes it (header-malformed, signature-invalid); network, manager and every offered member of the
permission equal to the offer's, salt being H (not-bound); a route the offer accepts (route-not-accepted);
account not spender (account-is-spender); and end later than now, the caller's clock in Unix seconds
(ended). The offer is the spendPermission the resource server issued (offer-malformed, or as read refuses its
legal context, where it is not one); a now that is not a non-negative safe integer is choice-malformed. Whether
salt is an H the resource server issued for this request and has not seen used is its own record's.
Parameters
| Parameter | Type |
|---|---|
presented | unknown |
offer | SpendPermissionOffer |
now | number |
Returns
Refusal | SpendPermissionReturn
decodeSpendPermissionHeader()
decodeSpendPermissionHeader(
header):Refusal|SpendPermissionReturn
The return a Spend-Permission header's value carries: base64url without padding in its canonical form (RFC 4648
§5), of at most MAX_HEADER_BYTES bytes, that are well-formed UTF-8 of one JSON object and nothing after it, at most
64 levels deep, holding the members rule 8 names and no other; else spend-permissions/header-malformed, or
spend-permissions/signature-invalid where only its signature is malformed. Addresses and hex come back lowercase.
Parameters
| Parameter | Type |
|---|---|
header | unknown |
Returns
Refusal | SpendPermissionReturn
encodeSpendPermissionHeader()
encodeSpendPermissionHeader(
value):string|Refusal
The Spend-Permission header's value: base64url without padding of the UTF-8 of JSON.stringify of the return,
which must be a return the profile's rule 8 takes, of at most MAX_HEADER_BYTES bytes; else
spend-permissions/header-malformed, or spend-permissions/signature-invalid for a malformed signature.
Parameters
| Parameter | Type |
|---|---|
value | SpendPermissionReturn |
Returns
string | Refusal
issuedDigest()
issuedDigest(
given):Promise<Refusal|`0x${string}`>
The digest a resource server keeps of an offer it issued (profile rule 9): SHA-256 over the RFC 8785 form of
{network, manager, permission}, permission holding spender, token, allowance, period, start, end
and extraData in the wire form, addresses and hex lowercase: the members the resource server fixes at issue alone.
It takes the offer as advertise takes it, salt absent or present; the offer the 402 body places, as read
takes it; and a return, as rule 8 takes it, on either route. It leaves out salt, which is H, account, which is
the account's, and accepts, which a return does not carry, so the offer as issued, as placed and as returned has
one digest, and an offer that differs in a member it covers has another. Any other value is
spend-permissions/option-malformed.
Parameters
| Parameter | Type |
|---|---|
given | SpendPermissionOffer | SpendPermissionOfferInput | SpendPermissionReturn |
Returns
Promise<Refusal | `0x${string}`>
permissionHash()
permissionHash(
permission,network,manager):Refusal|`0x${string}`
The permission's hash as the SpendPermissionManager's getHash computes it: the EIP-712 digest of the whole
permission in the manager's domain on the network, the digest the account signs and the approval event's topic.
spend-permissions/header-malformed where the permission, the network or the manager is not in the wire form.
Parameters
| Parameter | Type |
|---|---|
permission | SpendPermission |
network | `eip155:${string}` |
manager | `0x${string}` |
Returns
Refusal | `0x${string}`
tie()
tie(
offer): ["spendPermission",SpendPermissionOffer]
The ATR's binding slot: the offer exactly as issued.
Parameters
| Parameter | Type |
|---|---|
offer | SpendPermissionOffer |
Returns
["spendPermission", SpendPermissionOffer]
References
Broadcaster
Re-exports Broadcaster
EvmMark
Re-exports EvmMark
EvmQuery
Re-exports EvmQuery
EvmReadRefBase
Re-exports EvmReadRefBase
Last updated on
@integraledger/lcp/polkadot
Polkadot Asset Hub: the profile pairing `x402/exact/polkadot/lcp-assets-remark`, in which the payer signs one extrinsic that transfers an asset and remarks the ATR hash's LCP string.
@integraledger/lcp/stacks
Stacks rail pieces: the transaction id, the reader a read goes through, the read of a payment by its origin and the nonce the origin signed, and the zero-party recovery of the ATR hash from a mined transaction.