Overview
Theagent.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 callinginit(), the following variables are written to your .env file:
AGENT_UID- The agent’s unique identifierAGENT_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
- Keypair Creation: If
AGENT_PRIVATE_JWKexists in.env, it will be reused. Otherwise, a new Ed25519 keypair is generated. - Registration: The agent is registered with the Vestauth API at
https://api.vestauth.com(or a custom hostname if configured). - Persistence: All credentials are written to
.envusingdotenvxfor secure storage. - Idempotency: Safe to call multiple times - will reuse existing keys if found.
Error Handling
Related Methods
- agent.headers() - Generate signature headers for requests
- agent.rotate() - Rotate the agent’s keypair
- primitives.keypair() - Create a keypair without registration