Skip to content
Integra Protocol
API

@integraledger/lcp/evm

The exports of @integraledger/lcp/evm.

Classes

ReaderError

Extends

  • Error

Constructors

Constructor

new ReaderError(kind, message?): ReaderError

Parameters
ParameterType
kind"transport" | "timeout" | "too-large" | "malformed"
message?string
Returns

ReaderError

Overrides

Error.constructor

Properties

PropertyModifierTypeDescriptionInherited from
cause?publicunknown-Error.cause
kindreadonly"transport" | "timeout" | "too-large" | "malformed"--
messagepublicstring-Error.message
namepublicstring-Error.name
stack?publicstring-Error.stack
stackTraceLimitstaticnumberThe Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames.Error.stackTraceLimit

Methods

captureStackTrace()

static captureStackTrace(targetObject, constructorOpt?): void

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
Parameters
ParameterType
targetObjectobject
constructorOpt?Function
Returns

void

Inherited from

Error.captureStackTrace

prepareStackTrace()

static prepareStackTrace(err, stackTraces): any

Parameters
ParameterType
errError
stackTracesCallSite[]
Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from

Error.prepareStackTrace

Interfaces

Delegation

Properties

PropertyType
authority`0x${string}`
caveatsobject[]
delegate`0x${string}`
delegator`0x${string}`
salt`0x${string}`
signature`0x${string}`

Eip3009TypedData

Properties

PropertyType
domainobject
domain.chainIdnumber
domain.namestring
domain.verifyingContract`0x${string}`
domain.versionstring
messageobject
message.from`0x${string}`
message.nonce`0x${string}`
message.to`0x${string}`
message.validAfterbigint
message.validBeforebigint
message.valuebigint
primaryType"TransferWithAuthorization"
typesobject
types.EIP712DomainField[]
types.TransferWithAuthorizationField[]

EvmLog

One receipt log: the emitter, its topics and its data.

Properties

PropertyType
address`0x${string}`
data`0x${string}`
topicsreadonly `0x${string}`[]

EvmReader

Bounded, read-only calls against one network's endpoint. Every failure rejects with ReaderError.

Properties

PropertyModifierType
networkreadonly`eip155:${string}` | HederaNetwork

Methods

blockNumber()

blockNumber(tag): Promise<bigint>

eth_getBlockByNumber(tag, false).number.

Parameters
ParameterType
tag"safe" | "finalized"
Returns

Promise<bigint>

receipt()

receipt(tx): Promise<EvmReceipt | null>

eth_getTransactionReceipt; null when the node holds none.

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

Promise<EvmReceipt | null>

transaction()

transaction(tx): Promise<EvmTransaction | null>

eth_getTransactionByHash: the recipient (null for a contract creation) and the calldata; null when none.

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

Promise<EvmTransaction | null>


EvmReceipt

Properties

PropertyType
blockNumberbigint
logsreadonly EvmLog[]
status0 | 1

EvmRef

What the issuer records at claim for an EVM payment: read keys only.

Extended by

Properties

PropertyTypeDescription
bindingLog?{ address: `0x${string}`; topic0: `0x${string}`; value: `0x${string}`; } & ({ index: 2 | 1 | 3; } | { dataWord: number; })The log carrying H or its commitment: in topic index, or in 32-byte data word dataWord.
network`eip155:${string}` | HederaNetwork-
search?objectThe log filter that finds the transaction when none is named; absent, only a named transaction is read.
search.address`0x${string}`-
search.topicsreadonly (`0x${string}` | null)[]-
settleBy?stringDecimal Unix seconds after which the payment can no longer execute.
transferLog?objectThe token transfer this payment made, identified by the digest of the named fields.
transferLog.address`0x${string}`-
transferLog.digest`0x${string}`-
transferLog.identityTransferIdentity-
transferLog.topic0`0x${string}`-

EvmTransaction

A transaction as eth_getTransactionByHash gives it: to and input.

Properties

PropertyType
input`0x${string}`
to`0x${string}` | null

EvmTxRef

Properties

PropertyType
asset`0x${string}`
network`eip155:${string}`
transaction`0x${string}`

Field

Properties

PropertyType
namestring
typestring

PaymentInfo

Properties

PropertyType
authorizationExpirybigint
feeReceiver`0x${string}`
maxAmountbigint
maxFeeBpsnumber
minFeeBpsnumber
operator`0x${string}`
payer`0x${string}`
preApprovalExpirybigint
receiver`0x${string}`
refundExpirybigint
salt`0x${string}`
token`0x${string}`

Permit2TypedData

Properties

PropertyType
domainobject
domain.chainIdnumber
domain.name"Permit2"
domain.verifyingContract`0x${string}`
messageobject
message.deadlinebigint
message.noncebigint
message.permitted{ amount: bigint; token: `0x${string}`; } | object[]
message.spender`0x${string}`
message.witness?object
primaryType"PermitTransferFrom" | "PermitWitnessTransferFrom" | "PermitBatchWitnessTransferFrom"
typesobject
types.EIP712DomainField[]
types.TokenPermissionsField[]

Type Aliases

Eip155

Eip155 = `eip155:${string}`

CAIP-2 for EVM chains; the reference is the decimal chain id.


Eip3009Ref

Eip3009Ref = EvmRef & object

What a settlement reference holds for an EIP-3009 payment: read keys only. It is an EvmRef naming the AuthorizationUsed log and the transfer's identity, with the token, validBefore and the transfer digest.

Type Declaration

NameTypeDescription
assetHex-
idDigestHex-
maxTimeoutSecondsnumberThe option's maxTimeoutSeconds: the authorization was signed no earlier than validBefore less this.
networkEip155-
validBeforestring-

EvmBreadthStatus

EvmBreadthStatus = EvmStatus | { state: "failed"; why: "binding-log-not-found" | "transfer-not-found" | "receive-policy-blocked"; }


EvmStatus

EvmStatus = { blockNumber: bigint; finality: "latest" | "safe" | "finalized"; state: "settled"; } | { state: "pending"; why: "not-found" | "unreadable"; } | { state: "failed"; why: "reverted" | "authorization-not-used"; }


Hex

Hex = `0x${string}`


ReceiveTypedData

ReceiveTypedData = Omit<Eip3009TypedData, "primaryType" | "types"> & object

EIP-3009's ReceiveWithAuthorization: the same fields as TransferWithAuthorization, for a payee contract.

Type Declaration

NameType
primaryType"ReceiveWithAuthorization"
typesobject
types.EIP712DomainField[]
types.ReceiveWithAuthorizationField[]

TransferIdentity

TransferIdentity = "from,to,value" | "from,to" | "from" | "to,value" | "to"

Variables

AUTHORIZATION_USED_TOPIC

const AUTHORIZATION_USED_TOPIC: "0x98de503528ee59b575ef0c0a2576a82497bfc029a5685b209e9ec333479b10a5"

keccak256("AuthorizationUsed(address,bytes32)")


DELEGATION_MANAGER

const DELEGATION_MANAGER: "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3"

MetaMask's reference DelegationManager, v1.3.0, at one CREATE2 address.


DELEGATION_MANAGER_CHAINS

const DELEGATION_MANAGER_CHAINS: readonly number[]

The chain ids whose deployment record holds a DelegationManager at DELEGATION_MANAGER.


ESCROW

const ESCROW: { readonly [d in "v1.1" | "v1.0"]: { chargedTopic: Hex; eip3009Collector: Hex; escrow: Hex; permit2Collector: Hex } }

The commerce-payments escrow's two deployments: the escrow, its two token collectors, and PaymentCharged's topic.


EXACT_PERMIT2_PROXY

const EXACT_PERMIT2_PROXY: "0x402085c248EeA27D92E8b30b2C58ed07f9E20001"


PAYMENT_AUTHORIZED_TOPIC

const PAYMENT_AUTHORIZED_TOPIC: "0x1c81fb2e3bab27f6bb09bee9a0dddf61600b7cbaf2c12683e4864e0cbdb9d284"


PAYMENT_INFO_TYPEHASH

const PAYMENT_INFO_TYPEHASH: "0xae68ac7ce30c86ece8196b61a7c486d8f0061f575037fbd34e7fe4e2820c6591"


PERMIT2

const PERMIT2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"


RECEIVE_POLICY_GUARD

const RECEIVE_POLICY_GUARD: "0xb10c000000000000000000000000000000000000"

Where a Tempo receive policy sends a blocked transfer.


REDEEMED_DELEGATION_TOPIC

const REDEEMED_DELEGATION_TOPIC: "0x40dadaa36c6c2e3d7317e24757451ffb2d603d875f0ad5e92c5dd156573b1873"


SALT_BINDING_TYPEHASH

const SALT_BINDING_TYPEHASH: "0x8a2a7e41a0bda000ded071ff38b79401d2603e1826516ff2635b11fe9e30877f"


TRANSFER_TOPIC

const TRANSFER_TOPIC: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"

keccak256("Transfer(address,address,uint256)")


TRANSFER_WITH_AUTHORIZATION_TYPEHASH

const TRANSFER_WITH_AUTHORIZATION_TYPEHASH: "0x7c7c6cdb67a18743f49ec6fa9b35f50d52ed05cbed4cc592e13b44501c1a2267"

keccak256("TransferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)")


UPTO_PERMIT2_PROXY

const UPTO_PERMIT2_PROXY: "0x4020A4f3b7b90ccA423B9fabCc0CE57C6C240002"

Functions

authorizationIdDigest()

authorizationIdDigest(from, to, value): Promise<`0x${string}` | Refusal>

SHA-256 over the 72 bytes of abi.encodePacked(address from, address to, uint256 value): the identity of one transfer, which a Transfer(from, to, value) log in the settlement transaction reproduces.

Parameters

ParameterType
from`0x${string}`
to`0x${string}`
valuestring | bigint

Returns

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


bindSalt()

bindSalt(receiverAuthorizer, policy, h): `0x${string}` | Refusal

keccak256(abi.encode(SALT_BINDING_TYPEHASH, receiverAuthorizer, policy, h)).

Parameters

ParameterType
receiverAuthorizer`0x${string}`
policy`0x${string}`
h`0x${string}`

Returns

`0x${string}` | Refusal


carriesBinding()

carriesBinding(log, b): boolean

A log from address whose topic index, or data word dataWord, equals value by bytes, under topic0.

Parameters

ParameterType
logEvmLog
bNonNullable<{ address: `0x${string}`; topic0: `0x${string}`; value: `0x${string}`; } & ({ index: 2 | 1 | 3; } | { dataWord: number; }) | undefined>

Returns

boolean


decodePermissionContext()

decodePermissionContext(ctx): Refusal | Delegation[]

Decodes abi.encode(Delegation[]), strictly: every offset and length lies inside the input and is 32-byte aligned, address words carry 12 zero bytes, and there are at most 8 delegations, 16 caveats each, and 8 KiB per bytes. The array is returned in the input's order, leaf first. An empty array decodes to [].

Parameters

ParameterType
ctx`0x${string}`

Returns

Refusal | Delegation[]


eip3009Recover()

eip3009Recover(ref, reader): Promise<`0x${string}` | Refusal>

Recovers the hash from a settlement transaction alone: the one distinct nonce among the AuthorizationUsed logs that asset emitted in it. One call.

Parameters

ParameterType
refEvmTxRef
readerEvmReader

Returns

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


eip3009Status()

eip3009Status(ref, reader): Promise<EvmStatus>

Reads the named transaction. Settled when its receipt succeeded and holds a log from asset with exactly three topics, the first AuthorizationUsed and the third equal to h; the finality is the highest block mark at or above the receipt's block. A failed read, or a reader for another network, is pending, never failed. At most three calls.

Parameters

ParameterType
refEvmTxRef & object
readerEvmReader

Returns

Promise<EvmStatus>


eip3009TypedData()

eip3009TypedData(a): Refusal | Eip3009TypedData

The EIP-712 typed data for TransferWithAuthorization, with the field lists in ERC-3009's order. The domain's verifyingContract is the token.

Parameters

ParameterType
a{ asset: `0x${string}`; from: `0x${string}`; name: string; network: `eip155:${string}`; nonce: `0x${string}`; to: `0x${string}`; validAfter: bigint; validBefore: bigint; value: string; version: string; }
a.asset`0x${string}`
a.from`0x${string}`
a.namestring
a.network`eip155:${string}`
a.nonce`0x${string}`
a.to`0x${string}`
a.validAfterbigint
a.validBeforebigint
a.valuestring
a.versionstring

Returns

Refusal | Eip3009TypedData


evmStatus()

evmStatus(ref, reader): Promise<EvmBreadthStatus>

Reads the named transaction. A reader for another network, or a failed read, is pending; no receipt is pending not-found; a revert is failed. On success each log the ref names must be present, emitted by the named contract: the binding log with value in its topic or data word, and the transfer log whose from, to and value hash to the digest. Settled carries the highest finality mark reached. At most three calls.

Parameters

ParameterType
refEvmRef & object
readerEvmReader

Returns

Promise<EvmBreadthStatus>


isLog()

isLog(l): l is EvmLog

True for a log with a string address, string topics and string data.

Parameters

ParameterType
lunknown

Returns

l is EvmLog


isReceipt()

isReceipt(r): r is EvmReceipt

True for a receipt with a 0 or 1 status, a bigint block number and a list of logs.

Parameters

ParameterType
runknown

Returns

r is EvmReceipt


paymentHash()

paymentHash(chainId, escrow, p): `0x${string}` | Refusal

The escrow's getHash: keccak256(abi.encode(chainId, escrow, keccak256(abi.encode(PAYMENT_INFO_TYPEHASH, p)))). With payer zero it is x402's signatureNonce.

Parameters

ParameterType
chainIdnumber
escrow`0x${string}`
pPaymentInfo

Returns

`0x${string}` | Refusal


permit2TypedData()

permit2TypedData(a): Refusal | Permit2TypedData

Permit2's typed data under its domain (name "Permit2", no version). No witness gives PermitTransferFrom; a witness gives PermitWitnessTransferFrom, or PermitBatchWitnessTransferFrom when permitted is an array.

Parameters

ParameterType
a{ chainId: number; deadline: bigint; nonce: bigint; permitted: { amount: bigint; token: `0x${string}`; } | readonly object[]; spender: `0x${string}`; verifyingContract?: `0x${string}`; witness?: { fields: readonly Field[]; type: string; value: {[k: string]: Json; }; }; }
a.chainIdnumber
a.deadlinebigint
a.noncebigint
a.permitted{ amount: bigint; token: `0x${string}`; } | readonly object[]
a.spender`0x${string}`
a.verifyingContract?`0x${string}`
a.witness?{ fields: readonly Field[]; type: string; value: {[k: string]: Json; }; }
a.witness.fieldsreadonly Field[]
a.witness.typestring
a.witness.value{[k: string]: Json; }

Returns

Refusal | Permit2TypedData


receiveTypedData()

receiveTypedData(a): Refusal | ReceiveTypedData

The EIP-712 typed data for ReceiveWithAuthorization, built as eip3009TypedData builds its transfer form.

Parameters

ParameterType
a{ asset: `0x${string}`; from: `0x${string}`; name: string; network: `eip155:${string}`; nonce: `0x${string}`; to: `0x${string}`; validAfter: bigint; validBefore: bigint; value: string; version: string; }
a.asset`0x${string}`
a.from`0x${string}`
a.namestring
a.network`eip155:${string}`
a.nonce`0x${string}`
a.to`0x${string}`
a.validAfterbigint
a.validBeforebigint
a.valuestring
a.versionstring

Returns

Refusal | ReceiveTypedData


redeemedLeafRecover()

redeemedLeafRecover(ref, reader): Promise<`0x${string}` | Refusal>

Recovers H from a settlement transaction through MetaMask's DelegationManager: among its RedeemedDelegation logs, the leaves are those whose data word 1 (the delegate) is the redeemer in topic 2 or the wildcard delegate; exactly one distinct leaf salt (data word 5) is H. One call.

Parameters

ParameterType
ref{ network: `eip155:${string}`; transaction: `0x${string}`; }
ref.network`eip155:${string}`
ref.transaction`0x${string}`
readerEvmReader

Returns

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


settledAt()

settledAt(at, reader): Promise<EvmStatus & object>

Settled at the highest finality mark whose block is at or above at; a failed mark read counts as not reached.

Parameters

ParameterType
atbigint
readerEvmReader

Returns

Promise<EvmStatus & object>


transferDigest()

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

the core's hash over the fields present, in the order from, to, value: 20, 20 and 32 bytes, the value as a big-endian uint256. authorizationIdDigest(from, to, value) equals transferDigest({from, to, value}).

Parameters

ParameterType
v{ from?: `0x${string}`; to?: `0x${string}`; value?: bigint; }
v.from?`0x${string}`
v.to?`0x${string}`
v.value?bigint

Returns

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


transferParts()

transferParts(log, address, topic0): { from: `0x${string}`; to: `0x${string}`; value: bigint; } | undefined

from and to from topics 1 and 2 (their low 20 bytes) and value from data word 0, for a log from address under topic0. An ERC-20 Transfer has exactly three topics; an event that also indexes a memo has four.

Parameters

ParameterType
logEvmLog
address`0x${string}`
topic0`0x${string}`

Returns

{ from: `0x${string}`; to: `0x${string}`; value: bigint; } | undefined

Last updated on

On this page