Skip to main content

Overview

The primitives.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 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 Output

Example with Nonce

Example with Custom Tag

Complete Workflow

Error Handling

Common Errors

  • Missing UID: Thrown when uid is not provided or is empty
  • Missing Private JWK: Thrown when privateJwk is not provided or is empty
  • Invalid Private JWK: Thrown when privateJwk is 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)
These components are extracted from the httpMethod and uri parameters and included in the signature base string according to RFC 9421.

Custom Discovery Hostname

By default, the Signature-Agent header uses api.vestauth.com as the discovery hostname. You can customize this with the AGENT_HOSTNAME environment variable: