Skip to content

AuthorizationTempo.getSignPayload

Computes the sign payload for an AuthorizationTempo.AuthorizationTempo in EIP-7702 format: keccak256('0x05' || rlp([chain_id, address, nonce])).

Imports

Named
import { AuthorizationTempo } from 'ox/tempo'

Examples

Secp256k1

Standard Ethereum ECDSA signature using the secp256k1 curve.

import { Secp256k1 } from 'ox'
import { AuthorizationTempo } from 'ox/tempo'
 
const privateKey = Secp256k1.randomPrivateKey()
 
const authorization = AuthorizationTempo.from({
  address: '0x1234567890abcdef1234567890abcdef12345678',
  chainId: 1,
  nonce: 69n,
})
 
const payload = AuthorizationTempo.getSignPayload(authorization)
 
const signature = Secp256k1.sign({ payload, privateKey })
const authorization_signed = AuthorizationTempo.from(
  authorization,
  { signature }
)

P256

ECDSA signature using the P-256 (secp256r1) curve. Requires embedding the public key and a prehash flag indicating whether the payload was hashed before signing.

import { P256 } from 'ox'
import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo'
 
const { privateKey, publicKey } = P256.createKeyPair()
 
const authorization = AuthorizationTempo.from({
  address: '0x1234567890abcdef1234567890abcdef12345678',
  chainId: 1,
  nonce: 69n,
})
 
const payload = AuthorizationTempo.getSignPayload(authorization)
 
const signature = P256.sign({ payload, privateKey })
const signatureEnvelope = SignatureEnvelope.from({
  prehash: false,
  publicKey,
  signature,
})
const authorization_signed = AuthorizationTempo.from(
  authorization,
  { signature: signatureEnvelope }
)

P256 (WebCrypto)

When using WebCrypto keys, prehash must be true since WebCrypto always hashes the payload internally before signing.

import { WebCryptoP256 } from 'ox'
import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo'
 
const { privateKey, publicKey } = await WebCryptoP256.createKeyPair()
 
const authorization = AuthorizationTempo.from({
  address: '0x1234567890abcdef1234567890abcdef12345678',
  chainId: 1,
  nonce: 69n,
})
 
const payload = AuthorizationTempo.getSignPayload(authorization)
 
const signature = await WebCryptoP256.sign({ payload, privateKey })
const signatureEnvelope = SignatureEnvelope.from({
  prehash: true,
  publicKey,
  signature,
})
const authorization_signed = AuthorizationTempo.from(
  authorization,
  { signature: signatureEnvelope }
)

WebAuthn

Passkey-based signature using WebAuthn. Includes authenticator metadata (authenticatorData and clientDataJSON) along with the P-256 signature and public key.

import { WebAuthnP256 } from 'ox'
import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo'
 
const credential = await WebAuthnP256.createCredential({ name: 'Example' })
 
const authorization = AuthorizationTempo.from({
  address: '0x1234567890abcdef1234567890abcdef12345678',
  chainId: 1,
  nonce: 69n,
})
 
const challenge = AuthorizationTempo.getSignPayload(authorization)
 
const { metadata, signature } = await WebAuthnP256.sign({
  challenge,
  credentialId: credential.id,
})
const signatureEnvelope = SignatureEnvelope.from({
  signature,
  publicKey: credential.publicKey,
  metadata,
})
const authorization_signed = AuthorizationTempo.from(
  authorization,
  { signature: signatureEnvelope }
)

Definition

function getSignPayload(
  authorization: AuthorizationTempo.AuthorizationTempo,
): Hex.Hex

Source: src/tempo/AuthorizationTempo.ts

Parameters

authorization

  • Type: AuthorizationTempo.AuthorizationTempo

The AuthorizationTempo.AuthorizationTempo.

authorization.address

  • Type: abitype_Address

Address of the contract to set as code for the Authority.

authorization.chainId

  • Type: numberType

Chain ID to authorize.

authorization.nonce

  • Type: bigintType

Nonce of the Authority to authorize.

authorization.signature

  • Type: SignatureEnvelope
  • Optional

Return Type

The sign payload.

Hex.Hex