Skip to main content

Overview

The agent.headers() method generates HTTP Signature headers (RFC 9421) for authenticating outbound requests. It automatically reads credentials from .env if not provided.

Signature

Parameters

HttpMethod
required
The HTTP method for the request being signed.Valid values: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD', or any custom string.
string
required
The full URI of the request being signed (e.g., https://api.example.com/users).
string | null
default:"from .env"
The agent’s unique identifier. If not provided, reads AGENT_UID from .env.
string | null
default:"from .env"
The agent’s private JWK as a JSON string. If not provided, reads AGENT_PRIVATE_JWK from .env.
string
default:"web-bot-auth"
The signature tag to use in the Signature-Input header.
string | null
default:"null"
An optional nonce value to include in the signature for additional security.

Return Value

Returns a Promise that resolves to a SignatureHeaders object:
string
required
The RFC 9421 signature value in the format sig1=:base64_signature:.
string
required
The signature input parameters including keyid, tag, created, and optionally nonce.Example: sig1=("@method" "@authority");keyid="...";tag="web-bot-auth";created=1234567890
string
required
The agent discovery URL in the format sig1="https://uid.api.vestauth.com".

Example

Example with Custom Credentials

Example Output

Example with Nonce

Error Handling

Common Errors

  • Missing UID: Thrown when uid is not provided and AGENT_UID is not in .env
  • Missing Private JWK: Thrown when privateJwk is not provided and AGENT_PRIVATE_JWK is not in .env
  • Invalid Private JWK: Thrown when the provided privateJwk is not valid JSON or not a proper JWK