Skip to content
Integra Protocol
API

@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

PropertyModifierTypeDescription
accountreadonly`0x${string}`-
allowancereadonlystringA uint160.
endreadonlystringA uint48, a Unix time in seconds.
extraDatareadonly`0x${string}`-
periodreadonlystringA uint48, in seconds.
saltreadonlystringA uint256: H, as a decimal.
spenderreadonly`0x${string}`-
startreadonlystringA uint48, a Unix time in seconds.
tokenreadonly`0x${string}`-

SpendPermissionBody

The 402 body: the offer, and on a refused return the code that refused it.

Properties

PropertyModifierType
error?readonlySpendPermissionError
spendPermissionreadonlySpendPermissionOffer

SpendPermissionChoice

The buyer's inputs to build: the offer as read gave it, and the account that approves.

Properties

PropertyModifierType
accountreadonly`0x${string}`
offerreadonlySpendPermissionOffer

SpendPermissionOffer

The offer the 402 body's spendPermission member holds.

Properties

PropertyModifierTypeDescription
acceptsreadonlyreadonly SpendPermissionRoute[]The routes the resource server takes, each once.
legalContextreadonlyobject-
legalContext.legalContextUrlreadonlystring-
legalContext.typereadonly"sha256"-
legalContext.valuereadonly`0x${string}`-
managerreadonly`0x${string}`The SpendPermissionManager's address on network.
networkreadonly`eip155:${string}`-
permissionreadonlyOfferedPermissionEvery 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

PropertyModifierType
acceptsreadonlyreadonly SpendPermissionRoute[]
managerreadonly`0x${string}`
networkreadonly`eip155:${string}`
permissionreadonlyOmit<OfferedPermission, "salt"> & object

SpendPermissionRef

The reference the read takes: the option's payee is the permission's spender.

Extends

Properties

PropertyModifierTypeDescriptionOverridesInherited from
hreadonly`0x${string}`H, the permission's salt.--
hashreadonly`0x${string}`The permission's hash, the search key.--
managerreadonly`0x${string}`The SpendPermissionManager the permission is approved on.--
networkreadonly`eip155:${string}`-EvmReadRefBase.network-
payeereadonlystring--EvmReadRefBase.payee
permissionreadonlySpendPermissionThe 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

PropertyModifierType
domainreadonlyobject
domain.chainIdreadonlynumber
domain.namereadonlystring
domain.verifyingContractreadonly`0x${string}`
domain.versionreadonlystring
messagereadonlyobject
message.accountreadonly`0x${string}`
message.allowancereadonlybigint
message.endreadonlybigint
message.extraDatareadonly`0x${string}`
message.periodreadonlybigint
message.saltreadonlybigint
message.spenderreadonly`0x${string}`
message.startreadonlybigint
message.tokenreadonly`0x${string}`
primaryTypereadonly"SpendPermission"
typesreadonlyobject
types.SpendPermissionreadonlyreadonly 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

PropertyModifierType
approvereadonlyobject
approve.datareadonly`0x${string}`
approve.toreadonly`0x${string}`
hashreadonly`0x${string}`
permissionreadonlySpendPermission
typedDatareadonlySpendPermissionTypedData

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

NameType
managerHex
networkEip155
permissionSpendPermission

SpendPermissionRoute

SpendPermissionRoute = "signature" | "transaction"

The route the account's act took: its signature, or its own transaction.

Variables

APPROVE_SELECTOR

const APPROVE_SELECTOR: `0x${string}`

approve(SpendPermission).


APPROVE_WITH_SIGNATURE_SELECTOR

const APPROVE_WITH_SIGNATURE_SELECTOR: `0x${string}`

approveWithSignature(SpendPermission,bytes).


IS_APPROVED_SELECTOR

const IS_APPROVED_SELECTOR: `0x${string}`

isApproved(SpendPermission).


IS_REVOKED_SELECTOR

const IS_REVOKED_SELECTOR: `0x${string}`

isRevoked(SpendPermission).


SPEND_PERMISSION_APPROVED_TOPIC

const SPEND_PERMISSION_APPROVED_TOPIC: `0x${string}`

SpendPermissionApproved(bytes32,SpendPermission)'s topic.


SPEND_PERMISSION_DOMAIN

const SPEND_PERMISSION_DOMAIN: Readonly<{ name: "Spend Permission Manager"; version: "1"; }>

The manager's EIP-712 domain name and version.


SPEND_PERMISSION_HEADER

const SPEND_PERMISSION_HEADER: "Spend-Permission" = "Spend-Permission"

The request header field that carries the return.


SPEND_PERMISSION_REVOKED_TOPIC

const SPEND_PERMISSION_REVOKED_TOPIC: `0x${string}`

SpendPermissionRevoked(bytes32,SpendPermission)'s topic.


SPEND_PERMISSION_TYPEHASH

const SPEND_PERMISSION_TYPEHASH: `0x${string}`

keccak256 of the manager's SpendPermission type (SPEND_PERMISSION_TYPEHASH).


spendPermissionsEip155

const spendPermissionsEip155: 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

ParameterType
presentedunknown
readerEvmReader
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

ParameterType
presentedunknown
offerSpendPermissionOffer
nownumber

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

ParameterType
headerunknown

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

ParameterType
valueSpendPermissionReturn

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

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

ParameterType
permissionSpendPermission
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

ParameterType
offerSpendPermissionOffer

Returns

["spendPermission", SpendPermissionOffer]

References

Broadcaster

Re-exports Broadcaster


EvmMark

Re-exports EvmMark


EvmQuery

Re-exports EvmQuery


EvmReadRefBase

Re-exports EvmReadRefBase

Last updated on

On this page