Overview
Theprimitives.headers() function generates HTTP Signature headers (RFC 9421) for authenticating requests. Unlike agent.headers(), this is a low-level primitive that requires explicit credentials (no .env fallback).
For most use cases, use
agent.headers() instead, which automatically reads credentials from .env. Use primitives.headers() when you need full control over credential management.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
required
The agent’s unique identifier. This will be used in the
Signature-Agent header.string
required
The agent’s private JWK as a JSON string.
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 Output
Example with Nonce
Example with Custom Tag
Complete Workflow
Error Handling
Common Errors
- Missing UID: Thrown when
uidis not provided or is empty - Missing Private JWK: Thrown when
privateJwkis not provided or is empty - Invalid Private JWK: Thrown when
privateJwkis not valid JSON or doesn’t contain required fields
Signature Components
The generated signature covers these HTTP message components:@method- The HTTP method (GET, POST, etc.)@authority- The authority component of the URI (host + optional port)
httpMethod and uri parameters and included in the signature base string according to RFC 9421.
Custom Discovery Hostname
By default, theSignature-Agent header uses api.vestauth.com as the discovery hostname. You can customize this with the AGENT_HOSTNAME environment variable:
Related Methods
- agent.headers() - Higher-level version that reads from
.env - primitives.keypair() - Generate a keypair for signing
- primitives.verify() - Verify signed requests