AuthorizationTempo.from
Converts an EIP-7702 Authorization object into a typed AuthorizationTempo.AuthorizationTempo.
Tempo extends EIP-7702 to support secp256k1, P256, and WebAuthn signature types.
Tempo Authorization Specification
Imports
import { AuthorizationTempo } from 'ox/tempo'Examples
An Authorization can be instantiated from an EIP-7702 Authorization tuple in object format.
import { AuthorizationTempo } from 'ox/tempo'
const authorization = AuthorizationTempo.from({
address: '0x1234567890abcdef1234567890abcdef12345678',
chainId: 1,
nonce: 69n,
})Attaching Signatures (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: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
chainId: 1,
nonce: 40n,
})
const signature = Secp256k1.sign({
payload: AuthorizationTempo.getSignPayload(authorization),
privateKey,
})
const authorization_signed = AuthorizationTempo.from(
authorization,
{ signature },
)Attaching Signatures (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: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
chainId: 1,
nonce: 40n,
})
const signature = P256.sign({
payload: AuthorizationTempo.getSignPayload(authorization),
privateKey,
})
const signatureEnvelope = SignatureEnvelope.from({
signature,
publicKey,
prehash: false,
})
const authorization_signed = AuthorizationTempo.from(
authorization,
{ signature: signatureEnvelope },
)Attaching Signatures (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: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
chainId: 1,
nonce: 40n,
})
const signature = await WebCryptoP256.sign({
payload: AuthorizationTempo.getSignPayload(authorization),
privateKey,
})
const signatureEnvelope = SignatureEnvelope.from({
signature,
publicKey,
prehash: true,
})
const authorization_signed = AuthorizationTempo.from(
authorization,
{ signature: signatureEnvelope },
)Attaching Signatures (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: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
chainId: 1,
nonce: 40n,
})
const { metadata, signature } = await WebAuthnP256.sign({
challenge: AuthorizationTempo.getSignPayload(authorization),
credentialId: credential.id,
})
const signatureEnvelope = SignatureEnvelope.from({
signature,
publicKey: credential.publicKey,
metadata,
})
const authorization_signed = AuthorizationTempo.from(
authorization,
{ signature: signatureEnvelope },
)Definition
function from<authorization, signature>(
authorization: authorization | AuthorizationTempo,
options?: from.Options<signature>,
): from.ReturnType<authorization, signature>Source: src/tempo/AuthorizationTempo.ts
Parameters
authorization
- Type:
authorization | AuthorizationTempo
An EIP-7702 AA Authorization tuple in object format.
options
- Type:
from.Options<signature> - Optional
AA Authorization options.
options.signature
- Type:
signature | SignatureEnvelope - Optional
The SignatureEnvelope.SignatureEnvelope to attach to the AA Authorization.
Return Type
The AuthorizationTempo.AuthorizationTempo.
from.ReturnType<authorization, signature>

