Skip to main content

Overview

The agent.init() method initializes a new Vestauth agent by creating (or reusing) an Ed25519 keypair, registering it with the Vestauth API, and persisting the credentials to your .env file.

Signature

Parameters

This method takes no parameters. It automatically reads existing credentials from .env if available.

Return Value

Returns a Promise that resolves to an object with the following properties:
PublicJwk
required
The public JWK (JSON Web Key) for the agent. This is an Ed25519 OKP key.
string
required
The unique identifier (UID) assigned to this agent by Vestauth.
string
required
The path to the .env file where credentials were written (defaults to .env).
boolean
required
Indicates whether this is a newly created agent (true) or an existing agent that was re-registered (false).

Environment Variables

After calling init(), the following variables are written to your .env file:
  • AGENT_UID - The agent’s unique identifier
  • AGENT_PUBLIC_JWK - The agent’s public key (JSON string)
  • AGENT_PRIVATE_JWK - The agent’s private key (JSON string)
  • AGENT_HOSTNAME - The Vestauth API hostname (only if non-default)

Example

Example Output

Behavior

  1. Keypair Creation: If AGENT_PRIVATE_JWK exists in .env, it will be reused. Otherwise, a new Ed25519 keypair is generated.
  2. Registration: The agent is registered with the Vestauth API at https://api.vestauth.com (or a custom hostname if configured).
  3. Persistence: All credentials are written to .env using dotenvx for secure storage.
  4. Idempotency: Safe to call multiple times - will reuse existing keys if found.

Error Handling