Authorization
Utility functions for working with EIP-7702 Authorization lists & tuples.
Examples
Below are some examples demonstrating common usages of the Authorization
module:
Instantiating Authorizations
An Authorization can be instantiated using Authorization.from
:
import { Authorization } from 'ox'
const authorization = Authorization.from({
address: '0x1234567890abcdef1234567890abcdef12345678',
chainId: 1,
nonce: 69n,
})
Computing Sign Payload
A signing payload can be computed using Authorization.getSignPayload
. The result can then be passed to signing functions like Secp256k1.sign
.
import { Authorization, Secp256k1 } from 'ox'
const authorization = Authorization.from({
address: '0x1234567890abcdef1234567890abcdef12345678',
chainId: 1,
nonce: 69n,
})
const payload = Authorization.getSignPayload(authorization)
const signature = Secp256k1.sign({
payload,
privateKey: '0x...',
})
Attaching Signatures to Authorizations
A signature can be attached to an Authorization using Authorization.from
:
import { Authorization, Secp256k1, TransactionEnvelopeEip7702, Value } from 'ox'
const authorization = Authorization.from({
address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
chainId: 1,
nonce: 40n,
})
const signature = Secp256k1.sign({
payload: Authorization.getSignPayload(authorization),
privateKey: '0x...',
})
const authorization_signed = Authorization.from(authorization, { signature })
const envelope = TransactionEnvelopeEip7702.from({
authorizationList: [authorization_signed],
chainId: 1,
maxFeePerGas: Value.fromGwei('10'),
to: '0x0000000000000000000000000000000000000000',
value: Value.fromEther('1'),
})
Functions
Types
Name | Description |
---|---|
Authorization.Authorization | Root type for an EIP-7702 Authorization. |
Authorization.List | List of Authorization.Authorization . |
Authorization.ListRpc | RPC representation of an Authorization.List . |
Authorization.ListSigned | Signed representation of a list of Authorization.Authorization . |
Authorization.Rpc | RPC representation of an Authorization.Authorization . |
Authorization.Signed | Signed representation of an Authorization.Authorization . |
Authorization.Tuple | Tuple representation of an Authorization.Authorization . |
Authorization.TupleList | Tuple representation of a list of Authorization.Authorization . |
Authorization.TupleListSigned | Tuple representation of a list of signed Authorization.Authorization . |
Authorization.TupleSigned | Tuple representation of a signed Authorization.Authorization . |