Skip to main content

Overview

The agent.rotate() method generates a new Ed25519 keypair for your agent, registers it with Vestauth, and updates your .env file. This is useful for security best practices and key rotation policies.

Signature

Parameters

string
required
The agent’s current unique identifier. Used to authenticate the rotation request.
string
required
The agent’s current private JWK as a JSON string. Used to sign the rotation request.
string
default:"web-bot-auth"
The signature tag to use when signing the rotation request.
string | null
default:"null"
An optional nonce value for additional security during rotation.

Return Value

Returns a Promise that resolves to an object with the following properties:
PublicJwk
required
The new public JWK (JSON Web Key) for the agent.
string
required
The agent’s UID (unchanged after rotation).
string
required
The path to the .env file where new credentials were written.

Environment Variables

After calling rotate(), the following variables are updated in your .env file:
  • AGENT_PUBLIC_JWK - The agent’s new public key (JSON string)
  • AGENT_PRIVATE_JWK - The agent’s new private key (JSON string)
The AGENT_UID and AGENT_HOSTNAME remain unchanged.

Example

Example Output

Rotation Flow

  1. Generate New Keypair: A fresh Ed25519 keypair is created
  2. Sign Request: The rotation request is signed with the current (old) private key
  3. API Call: The signed request is sent to Vestauth’s /rotate endpoint
  4. Update .env: The new keys are written to .env, replacing the old ones
  5. Complete: The old keys are now invalid; only the new keys will work

Security Considerations

After rotation, the old private key is immediately invalidated. Ensure you:
  • Have successfully written the new credentials to .env
  • Have restarted any services using the old credentials
  • Have verified the rotation was successful before discarding the old key

Example with Error Handling

Scheduled Rotation