Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
signRequest – ERC-8128
Skip to content

signRequest

Signs an HTTP Request and returns a new Request with RFC 9421 signature headers.

Usage

Sign a request by passing the URL (or Request object), an optional RequestInit, a signer, and optional sign options. The function returns a new Request with RFC 9421 signature headers attached.

import { signRequest } from '@slicekit/erc8128'
 
// Simple: just input and signer
const signedRequest = await signRequest(
  'https://api.example.com/resource',
  signer
)
 
// With RequestInit
const signedRequest = await signRequest(
  'https://api.example.com/resource',
  { method: 'POST', body: '{"data": "value"}' },
  signer
)
 
// With options
const signedRequest = await signRequest(
  'https://api.example.com/resource',
  { method: 'POST', body: '{"data": "value"}' },
  signer,
  { ttlSeconds: 15 }
)

Returns

Promise<Request>

A new Request object with these headers added:

  • Signature-Input — Components and parameters per RFC 9421
  • Signature — Base64-encoded Ethereum signature
  • Content-Digest — SHA-256 hash of body (if body is present)

Parameters

Overload 1: Simple

When no RequestInit is needed, pass the input and signer directly.

signRequest(input: RequestInfo, signer: EthHttpSigner, opts?: SignOptions): Promise<Request>

Overload 2: With RequestInit

When you need to specify method, headers, or body, pass a RequestInit as the second argument.

signRequest(input: RequestInfo, init: RequestInit | undefined, signer: EthHttpSigner, opts?: SignOptions): Promise<Request>

input

  • Type: RequestInfo

URL string or Request object to sign.

init (optional)

  • Type: RequestInit

Optional RequestInit (method, headers, body, etc.).

signer

The signer that provides the Ethereum address and signing function.

opts (optional)

Options for customizing the signature.

ttlSeconds supplies the default validity window only when expires is omitted. An explicit expires value is preserved; signer clients clamp it only when a discovered max_validity_sec or an authorization expiry imposes an earlier ceiling.

Examples

Common signing patterns showing TTL customization, custom nonces, and replayable signatures.

Custom TTL
const signedRequest = await signRequest(
  'https://api.example.com/resource',
  signer,
  { ttlSeconds: 15 } // Prefer the shortest delivery-safe window
)