Skip to content

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

NameDescription
Authorization.fromConverts an EIP-7702 Authorization object into a typed Authorization.Authorization.
Authorization.fromRpcConverts an Authorization.Rpc to an Authorization.Authorization.
Authorization.fromRpcListConverts an Authorization.ListRpc to an Authorization.List.
Authorization.fromTupleConverts an Authorization.Tuple to an Authorization.Authorization.
Authorization.fromTupleListConverts an Authorization.TupleList to an Authorization.List.
Authorization.getSignPayloadComputes the sign payload for an Authorization.Authorization in EIP-7702 format: `keccak256('0x05'
Authorization.hashComputes the hash for an Authorization.Authorization in EIP-7702 format: `keccak256('0x05'
Authorization.toRpcConverts an Authorization.Authorization to an Authorization.Rpc.
Authorization.toRpcListConverts an Authorization.List to an Authorization.ListRpc.
Authorization.toTupleConverts an Authorization.Authorization to an Authorization.Tuple.
Authorization.toTupleListConverts an Authorization.List to an Authorization.TupleList.

Types

NameDescription
Authorization.AuthorizationRoot type for an EIP-7702 Authorization.
Authorization.ListList of Authorization.Authorization.
Authorization.ListRpcRPC representation of an Authorization.List.
Authorization.ListSignedSigned representation of a list of Authorization.Authorization.
Authorization.RpcRPC representation of an Authorization.Authorization.
Authorization.SignedSigned representation of an Authorization.Authorization.
Authorization.TupleTuple representation of an Authorization.Authorization.
Authorization.TupleListTuple representation of a list of Authorization.Authorization.
Authorization.TupleListSignedTuple representation of a list of signed Authorization.Authorization.
Authorization.TupleSignedTuple representation of a signed Authorization.Authorization.