Skip to content

Documentation

Key rotation

Authorize, rotate and revoke operational signing keys, and understand exactly when a key stops counting — including after an ownership transfer.

The key model

Signing keys live in the AgentKeyRegistry, separate from the owner wallet. A key is authorized for one agent, by the owner (or an approved operator) that held the agent at the time, after the key proved possession of itself with an EIP-712 signature checked onchain.

Each agent has an epoch and a bound owner. A key record stores the epoch and owner it was granted under. isAuthorized(agentId, key) is true only when all of these hold:

  • a record exists and has not been revoked;
  • the record's epoch equals the agent's current epoch;
  • the record's owner equals the agent's current owner in the ERC-8004 registry.

isAuthorized never reverts; it returns false for unknown agents.

Operations

FunctionWhoEffect
authorizeKeyowner / approved / operatorAdds a key, given the key's proof (deadline ≤ 1 day; each proof usable once)
rotateKeyowner / approved / operatorRevokes the old key and authorizes the new one atomically
revokeKeyowner / approved / operatorRevokes one key immediately
revokeAllKeysowner / approved / operatorAdvances the epoch: every existing key stops counting
syncanyoneBinds the current owner; advances the epoch if the owner changed

Records always store the owner, even when an operator submits. The SDK simulates every write first, so contract errors such as KeyAlreadyActive or SignatureExpired are decoded before your wallet prompts.

Rotating and revoking

rotate.ts
import { signKeyAuthorization } from "@agentid/sdk";
import { privateKeyToAccount } from "viem/accounts";

const oldKey = "0xOldSigningKeyAddress";
const newSigner = privateKeyToAccount(process.env.NEW_SIGNING_KEY as `0x${string}`);

// In the agent runtime: the NEW key proves possession
const typedData = await agentid.buildKeyAuthorization({ agentId: 42n, key: newSigner.address });
const signature = await signKeyAuthorization({ signer: newSigner, typedData });

// Owner: revoke the old key and authorize the new one in one transaction
await agentid.rotateSigningKey({
  walletClient: owner,
  agentId: 42n,
  oldKey,
  newKey: newSigner.address,
  deadline: typedData.message.deadline,
  signature,
});
revoke.ts
await agentid.revokeSigningKey({ walletClient: owner, agentId: 42n, key: compromisedKey });

// Emergency: invalidate every key of the agent at once (advances the epoch)
await agentid.revokeAllSigningKeys({ walletClient: owner, agentId: 42n });

The default proof deadline is the latest block time plus 30 minutes; the contract rejects deadlines more than one day ahead (DeadlineTooFar) and reuse of the same proof (SignatureAlreadyUsed).

What revocation changes

  • New records signed by a revoked key are rejected by the API with 403 SIGNER_NOT_AUTHORIZED.
  • Existing records keep their history: with anchor or AgentID receipt evidence from before the revocation, Signing key authorized at record time is PASS; if only the self-declared timestamp predates the revocation, it is UNKNOWN, because a holder of a revoked key could backdate. Signing key currently authorized reports INFO.
  • Rotation is recorded as such in the history (end.reason = "rotated") when the same transaction authorizes another key.

Ownership transfers

Keys are bound to the owner that granted them. When the agent is transferred, every key stops counting immediately (the record's owner no longer matches). The first sync, authorizeKey or revokeKey by the new owner advances the epoch, so those keys can never come back.

The A → B → A edge case#

If the agent goes from A to B and back to A with no key-registry interaction in between, A's old keys match again (same owner, same epoch). Anyone can close this by calling the permissionless sync(agentId) while B owns the agent — or afterwards with revokeAllKeys.

Call agentid.syncKeyOwner({ walletClient, agentId }) right after transferring an agent away. Verification models this case exactly: authorization history marks such windows as owner_restored.

Inspecting key state

inspect.ts
await agentid.isAuthorizedSigner(42n, key); // live isAuthorized()
await agentid.getKeyRecord(42n, key);       // { epoch, authorizedAt, revokedAt, owner, exists }
await agentid.getKeyState(42n);             // { epoch, boundOwner, currentOwner, expectedEpoch, blockNumber }

// Windows in which the key was authorized, rebuilt from chain logs
const intervals = await agentid.getAuthorizationHistory(42n, key);
// [{ key, owner, epoch,
//    start: { blockNumber, logIndex, txHash, timestamp, reason: "authorized" | "owner_restored" },
//    end:   { …, reason: "revoked" | "rotated" | "all_revoked" | "owner_changed" } | null }]

Contract-level details are in Smart contract architecture.