Overview
Theagent.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 aSignatureHeaders 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=1234567890string
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
uidis not provided andAGENT_UIDis not in.env - Missing Private JWK: Thrown when
privateJwkis not provided andAGENT_PRIVATE_JWKis not in.env - Invalid Private JWK: Thrown when the provided
privateJwkis not valid JSON or not a proper JWK
Related Methods
- agent.init() - Initialize agent credentials
- primitives.headers() - Lower-level header generation without .env
- tool.verify() - Verify incoming signed requests