Skip to main content

Overview

The Agent API provides methods for creating agent identities, generating signed request headers, and rotating cryptographic keys. It reads credentials from environment variables (.env) when not explicitly provided.

agent.init()

Creates (or reuses) an Ed25519 keypair, registers the agent with the Vestauth server, and writes credentials to .env.

Signature

Parameters

string
The Vestauth server hostname. Defaults to AGENT_HOSTNAME environment variable, then api.vestauth.com.
  • Use https:// scheme for production servers
  • Use http://localhost:3000 for local development
  • If no scheme provided, https:// is assumed

Returns

string
required
The unique agent identifier (e.g., agent-4b94ccd425e939fac5016b6b)
PublicJwk
required
The agent’s public key in JWK format
string
required
Path to the .env file where credentials were written (typically .env)
boolean
required
true if a new agent was created, false if existing keys were reused

Example

Custom Hostname

Environment Variables Written

This method writes the following to .env:
.env
Never commit .env files containing AGENT_PRIVATE_JWK to version control. Add .env to your .gitignore.

agent.headers()

Generates RFC 9421 HTTP Message Signature headers for authenticating requests.

Signature

Parameters

string
required
The HTTP method (e.g., GET, POST, PUT, DELETE)
string
required
The full request URI including scheme, host, and path (e.g., https://api.example.com/data)
string
Agent UID. If not provided, reads from AGENT_UID environment variable.
string
Private JWK as JSON string. If not provided, reads from AGENT_PRIVATE_JWK environment variable.
string
default:"web-bot-auth"
Signature tag for the request. Use web-bot-auth for agent authentication.
string
Custom nonce value. If not provided, a random nonce is generated.

Returns

string
required
The signature header value (e.g., sig1=:UW6A7j8jo+gQxd+EeVgD...==:)
string
required
The signature input parameters including algorithm, key ID, timestamps, and nonce
string
required
The agent discovery URL (e.g., sig1="https://agent-609a4fd2ebf4e6347108c517.api.vestauth.com")

Example

Making HTTP Requests

Custom Credentials


agent.rotate()

Rotates the agent’s keypair by generating new keys and updating the Vestauth server.

Signature

Parameters

string
required
The agent UID to rotate keys for
string
required
Current private JWK as JSON string (used to authenticate the rotation request)
string
default:"web-bot-auth"
Signature tag for the rotation request
string
Custom nonce value for the rotation request

Returns

PublicJwk
required
The new public key in JWK format
string
required
The agent UID (unchanged)
string
required
Path to the .env file where new credentials were written

Example

When to Rotate Keys

Rotate your agent’s keys when:
  • You suspect the private key has been compromised
  • Following security best practices (e.g., quarterly rotation)
  • Migrating to new infrastructure
  • After a security incident
Key rotation is seamless - the agent UID remains the same, only the cryptographic keys change.

Environment Variables Updated

This method updates the following in .env:
.env

Type Definitions

Error Handling

See Also