Skip to content

Authorization.from

Converts an EIP-7702 Authorization object into a typed Authorization.Authorization.

Imports

Named
import { Authorization } from 'ox'

Examples

An Authorization can be instantiated from an EIP-7702 Authorization tuple in object format.

import { Authorization } from 'ox'
 
const authorization = Authorization.from({
  address: '0x1234567890abcdef1234567890abcdef12345678',
  chainId: 1,
  nonce: 69n,
})

Attaching Signatures

A Signature.Signature can be attached with the signature option. The example below demonstrates signing an Authorization with Secp256k1.sign.

import { Authorization, Secp256k1 } 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 })

Definition

function from<authorization, signature>(
  authorization: authorization | Authorization,
  options?: from.Options<signature>,
): from.ReturnType<authorization, signature>

Source: src/Authorization.ts

Parameters

authorization

  • Type: authorization | Authorization

An EIP-7702 Authorization tuple in object format.

options

  • Type: from.Options<signature>
  • Optional

Authorization options.

options.signature

  • Type: signature | { r: bigint; s: bigint; yParity: number; }
  • Optional

The Signature.Signature to attach to the Authorization.

Return Type

The Authorization.Authorization.

from.ReturnType<authorization, signature>