Overview
Theprimitives.verify() function verifies HTTP Signature (RFC 9421) on incoming requests. It can either use a provided public key or automatically discover it via the Signature-Agent header.
For tool providers, consider using
tool.verify() instead, which adds FQDN trust validation. Use primitives.verify() when you need low-level verification control or custom trust logic.Signature
Parameters
HttpMethod
required
The HTTP method of the request being verified.Valid values:
'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD', or any custom string.string
required
The full URI of the request being verified (e.g.,
https://api.example.com/users).HeaderBag
default:"{}"
The HTTP headers from the incoming request. Should include
Signature, Signature-Input, and optionally Signature-Agent.PublicJwk
default:"undefined"
The public key to use for verification. If not provided, the key will be discovered via the
Signature-Agent header.Return Value
Returns a Promise that resolves to aVerifyResult object:
string
The unique identifier of the agent that signed the request (extracted from
Signature-Agent).string
The key ID (thumbprint) of the public key used to verify the signature.
PublicJwk
The public JWK that was used to verify the signature.
string
The well-known URL where the public key was discovered (only present if auto-discovered).
Example - Auto-Discovery
Example - With Provided Public Key
Example Output
Public Key Discovery
WhenpublicJwk is not provided, the verification process:
- Parses Signature-Agent: Extracts the agent’s discovery URL from the
Signature-Agentheader - Builds Well-Known URL: Constructs
https://{uid}.{host}/.well-known/http-message-signatures-directory - Fetches Keys: Makes a GET request to the well-known endpoint
- Selects Key: Finds the key matching the
keyidfromSignature-Input - Verifies: Uses the discovered key to verify the signature
Signature Expiration
If theSignature-Input includes an expires parameter, the signature is checked for expiration:
Error Handling
Common Errors
- Missing Signature-Input: The
Signature-Inputheader is missing or malformed - Expired Signature: The signature’s
expirestimestamp is in the past - Missing Public JWK: No public key provided and auto-discovery failed
- Invalid Signature: The cryptographic signature verification failed (tampered request or wrong key)
Verification Flow
- Parse Headers: Extract and parse
Signature,Signature-Input, andSignature-Agent - Check Expiration: Validate the signature hasn’t expired (if
expiresis present) - Resolve Public Key:
- Use provided
publicJwkif given - Otherwise, discover via
Signature-Agentwell-known endpoint
- Use provided
- Build Signature Base: Reconstruct the signature base string from the request
- Verify: Use Ed25519 to verify the signature against the public key
- Return Result: Return agent info and verification details
Localhost Support
When theSignature-Agent hostname is localhost or 127.0.0.1, the verification automatically handles port mapping:
Related Methods
- tool.verify() - Higher-level verification with FQDN trust validation
- primitives.headers() - Generate signature headers
- agent.headers() - Generate headers using .env credentials