Skip to content

KeyAuthorization

Tempo key authorization utilities for provisioning and signing access keys.

Access keys allow a root key (e.g., a passkey) to delegate transaction signing to secondary keys with customizable permissions including expiry timestamps and per-TIP-20 token spending limits. This enables a user to sign transactions without repeated passkey prompts.

Access Keys Specification

Examples

import { KeyAuthorization, SignatureEnvelope } from 'ox/tempo'
import { Address, Secp256k1, WebCryptoP256, Value } from 'ox'
 
const keyPair = await WebCryptoP256.createKeyPair()
const address = Address.fromPublicKey(keyPair.publicKey)
 
const authorization = KeyAuthorization.from({
  address,
  chainId: 4217n,
  expiry: 1234567890,
  type: 'p256',
  limits: [{
    token: 'tempox0x20c0000000000000000000000000000000000001',
    limit: Value.from('10', 6),
  }],
})
 
const privateKey = '0x...'
const payload = KeyAuthorization.getSignPayload(authorization)
const signature = SignatureEnvelope.from(
  Secp256k1.sign({ payload, privateKey }),
)
 
KeyAuthorization.from(authorization, { signature })

Functions

NameDescription
KeyAuthorization.deserializeDeserializes an RLP-encoded KeyAuthorization.KeyAuthorization.
KeyAuthorization.fromConverts a Key Authorization object into a typed KeyAuthorization.KeyAuthorization.
KeyAuthorization.fromRpcConverts an AuthorizationTempo.Rpc to an AuthorizationTempo.AuthorizationTempo.
KeyAuthorization.fromRpcUnsignedConverts unsigned RPC fields before owner signing.
KeyAuthorization.fromTupleConverts an KeyAuthorization.Tuple to an KeyAuthorization.KeyAuthorization.
KeyAuthorization.getSignPayloadComputes the sign payload for an KeyAuthorization.KeyAuthorization.
KeyAuthorization.hashComputes the hash for an KeyAuthorization.KeyAuthorization.
KeyAuthorization.serializeSerializes a KeyAuthorization.KeyAuthorization to RLP-encoded hex.
KeyAuthorization.toRpcConverts an KeyAuthorization.KeyAuthorization to an KeyAuthorization.Rpc.
KeyAuthorization.toRpcUnsignedConverts unsigned authorization fields to RPC before owner signing.
KeyAuthorization.toTupleConverts an KeyAuthorization.KeyAuthorization to an KeyAuthorization.Tuple.

Errors

NameDescription
KeyAuthorization.InvalidAdminMarkerErrorThrown when a TIP-1049 admin marker has any value other than 0x01.
KeyAuthorization.InvalidSignatureTypeErrorThrown when a key authorization contains a keychain signature.
KeyAuthorization.InvalidWitnessSizeErrorThrown when a witness field is not exactly 32 bytes.
KeyAuthorization.MissingAccountErrorThrown when a multisig key grant omits its parent account binding.

Types

NameDescription
KeyAuthorization.InputInput type for a Key Authorization.
KeyAuthorization.KeyAuthorizationKey authorization for provisioning access keys.
KeyAuthorization.RpcRPC representation matching the node's wire format.
KeyAuthorization.RpcCallScopeRPC representation of a call scope (matches node's CallScope serde).
KeyAuthorization.RpcSelectorRuleRPC representation of a selector rule (matches node's SelectorRule serde).
KeyAuthorization.RpcTokenLimitRPC representation of a token limit (matches node's TokenLimit serde).
KeyAuthorization.ScopeCall scope entry restricting which contract, selector, and recipients an access key can use.
KeyAuthorization.SignatureSignature that can authorize an access key.
KeyAuthorization.SignatureRpcRPC-formatted signature that can authorize an access key.
KeyAuthorization.SignedSigned representation of a Key Authorization.
KeyAuthorization.TokenLimitToken spending limit for access keys.
KeyAuthorization.TupleTuple representation of a Key Authorization.
KeyAuthorization.UnsignedAuthorization fields before owner signing.
KeyAuthorization.UnsignedRpcUnsigned RPC authorization used before owner signing.