Skip to content
LogoLogo

accessKey.saveAuthorization

Saves a signed key authorization to a relay running the Key Authorization plugin. The relay attaches it to the access key's next transaction until the key is active onchain.

accessKey.signAuthorization already saves authorizations it signs through a relay. Use this action for authorizations signed elsewhere, such as on another device or with Account.signKeyAuthorization.

Usage

Standalone Action

import { Account, Actions, P256 } from 'viem/tempo'
import { client } from './viem.config'
 
const account = Account.fromSecp256k1('0x...')
const accessKey = Account.fromP256(P256.randomPrivateKey(), {
  access: account,
})
 
const keyAuthorization = await account.signKeyAuthorization(accessKey, {
  chainId: BigInt(client.chain.id),
  expiry: Math.floor(Date.now() / 1000) + 86_400,
})
 
await Actions.accessKey.saveAuthorization(client, { keyAuthorization }) 

Return Value

void

Resolves once the relay has stored the authorization, or has skipped it because the key is already active onchain.

Parameters

keyAuthorization

  • Type: KeyAuthorization.Signed

The signed key authorization to save. It must be signed by the account itself (a root key or an owner quorum), unexpired, and for the relay's chain. A pending authorization for the same key is only replaced when the new one expires later.

await Actions.accessKey.saveAuthorization(client, {
  keyAuthorization, 
})

Errors

ErrorDescription
MethodNotFoundRpcErrorThe relay does not run the Key Authorization plugin.
InvalidParamsRpcErrorThe authorization is unsigned, expired, signed by another account, below quorum, for another chain, burned, or older than the pending authorization.