Overview
Theagent.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 callingrotate(), 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)
AGENT_UID and AGENT_HOSTNAME remain unchanged.
Example
Example Output
Rotation Flow
- Generate New Keypair: A fresh Ed25519 keypair is created
- Sign Request: The rotation request is signed with the current (old) private key
- API Call: The signed request is sent to Vestauth’s
/rotateendpoint - Update .env: The new keys are written to
.env, replacing the old ones - Complete: The old keys are now invalid; only the new keys will work
Security Considerations
Example with Error Handling
Scheduled Rotation
Related Methods
- agent.init() - Initialize a new agent
- agent.headers() - Generate signature headers with current credentials
- primitives.keypair() - Generate a keypair without registration