Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.shadowfeed.app/llms.txt

Use this file to discover all available pages before exploring further.

HMAC Integration Guide

This guide adds HMAC request authentication to your API so it accepts signed requests from ShadowFeed and skips x402 payment for those calls.
If you’re using Hosted Mirror mode (we host your data, no API server on your side), skip this entire guide. HMAC is only needed for Partner Bridge mode.

TL;DR — 3 things to do

1

Grab your HMAC secret

From the provider dashboard or the success screen after onboarding.
2

Set it on your server

SHADOWFEED_PARTNER_SECRET=... as env var on your API server — not on ShadowFeed.
3

Paste the middleware

Copy the snippet for your stack below. Mount BEFORE your x402 middleware.

How HMAC fits into the request flow

Agent buys data
    │ pays STX

ShadowFeed
    │ signs canonical string with shared secret
    │ adds 4 headers:
    │   X-Sf-Partner:   shadowfeed
    │   X-Sf-Timestamp: 1715616000
    │   X-Sf-Nonce:     <uuid>
    │   X-Sf-Signature: <hmac-hex>


Your API
    │ middleware checks:
    │   ✓ timestamp within ±5 min
    │   ✓ nonce not seen before
    │   ✓ HMAC signature matches recomputed value


Skip x402 payment requirement, serve data
The signature is computed from a canonical string:
{METHOD}\n{PATH}\n{TIMESTAMP}\n{NONCE}\n{SHA256(BODY)}
Both sides must derive the same canonical string for the signature to verify. The body hash is empty string "" for GET requests.

Setup checklist

  • HMAC secret saved (from onboarding success screen or Rotate secret button)
  • Decided which server hosts your partner_endpoint
  • Set SHADOWFEED_PARTNER_SECRET=your-secret as env var on that server
  • Confirmed your API can read the env var (process.env, c.env, os.environ, etc.)

Verifier middleware

Pick the language tab matching your stack. All three implementations use the same canonical string format and are mutually compatible.
import { Hono } from 'hono';

// Replace with your existing route file.
const app = new Hono<{ Bindings: { SHADOWFEED_PARTNER_SECRET: string } }>();

// Add this middleware BEFORE any x402 payment middleware so signed
// requests bypass the payment requirement.
app.use('*', async (c, next) => {
  if (c.req.header('X-Sf-Partner') !== 'shadowfeed') {
    return next();  // not a ShadowFeed call → continue normal x402 flow
  }
  const ok = await verifyShadowfeedHmac(c.req.raw, c.env.SHADOWFEED_PARTNER_SECRET);
  if (!ok) return c.json({ error: 'invalid HMAC signature' }, 401);
  c.set('skipX402', true);   // your x402 middleware reads this flag
  return next();
});

async function verifyShadowfeedHmac(req: Request, secret: string): Promise<boolean> {
  const ts    = parseInt(req.headers.get('X-Sf-Timestamp') ?? '', 10);
  const nonce = req.headers.get('X-Sf-Nonce') ?? '';
  const sig   = req.headers.get('X-Sf-Signature') ?? '';
  if (!ts || !nonce || !sig) return false;

  // 5-minute window — rejects replays of leaked signatures.
  if (Math.abs(Date.now() / 1000 - ts) > 300) return false;

  // Replay protection — store seen nonces in KV for 5 minutes.
  // (Omit if you can't tolerate the extra KV write; the timestamp window
  // already bounds the attack to 5 min after capture.)
  //
  //   const seen = await env.NONCES.get(nonce);
  //   if (seen) return false;
  //   await env.NONCES.put(nonce, '1', { expirationTtl: 300 });

  const enc = new TextEncoder();
  const body = req.method === 'GET' ? '' : await req.clone().text();
  const bodyHash = body
    ? [...new Uint8Array(await crypto.subtle.digest('SHA-256', enc.encode(body)))]
        .map(b => b.toString(16).padStart(2, '0')).join('')
    : '';
  const canonical = [
    req.method.toUpperCase(),
    new URL(req.url).pathname,
    String(ts), nonce, bodyHash,
  ].join('\n');

  const key = await crypto.subtle.importKey(
    'raw', enc.encode(secret),
    { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'],
  );
  const expected = [...new Uint8Array(
    await crypto.subtle.sign('HMAC', key, enc.encode(canonical)),
  )].map(b => b.toString(16).padStart(2, '0')).join('');

  return sig.toLowerCase() === expected.toLowerCase();
}
Where to set the secret (Cloudflare Workers):
wrangler secret put SHADOWFEED_PARTNER_SECRET
# Paste the secret when prompted
This stores it as a Worker secret — accessible at runtime via c.env.SHADOWFEED_PARTNER_SECRET, never visible in your code or logs.

Verifying your implementation

After deploying the middleware, trigger a paid request to your feed through ShadowFeed:
# This call returns 402 — that's expected. ShadowFeed responds with x402
# payment requirements when there's no payment-signature header.
curl -i https://api.shadowfeed.app/feeds/p/your-handle/your-feed-slug
To exercise the HMAC path end-to-end, use the ShadowFeed Agent SDK:
import { ShadowFeed } from 'shadowfeed-agent';

const sf = new ShadowFeed({
  privateKey: process.env.AGENT_PRIVATE_KEY,
  network: 'mainnet',
});

const result = await sf.buy('p/your-handle/your-feed-slug');
console.log(result.data);  // Your data, returned through HMAC-authenticated path
If your verifier is correctly deployed:
  • The agent pays STX
  • ShadowFeed signs HMAC + forwards to your endpoint
  • Your middleware verifies + skips payment
  • Your route returns data
  • Agent receives the response
  • 97% of the price is credited to your pending_revenue counter
Check the dashboard or GET /providers/id/your-id/analytics to confirm the query landed.

Common pitfalls

SymptomCauseFix
Always 401 from your endpointWrong secret on either sideRe-paste secret on your server; rotate from dashboard if unsure
Some calls 401, others succeedClock drift > 5 minSync your server clock (NTP)
401 with body hash mismatchBody modified by proxy/middleware before verifier sees itVerify BEFORE any body parsing; use req.clone().text() (TS)
Pre-paid calls work, post-paid agent calls failMiddleware orderingPlace HMAC check BEFORE your x402 middleware
Worked, then suddenly all 401sSecret rotated but not deployedRe-set the env var with the new secret

Building with Claude Code

If you use Claude Code to maintain your codebase, paste this prompt to bootstrap the integration:
I want to integrate my API as a ShadowFeed external data provider. My stack is [Cloudflare Workers / FastAPI / Go / etc.]. I have the HMAC secret saved as SHADOWFEED_PARTNER_SECRET. The full integration guide is at docs.shadowfeed.app/providers/hmac-integration. Walk me through:
  1. Adding the HMAC verifier middleware to my existing routes (preserve current x402 / auth)
  2. Setting the env var on my deployment platform
  3. Testing the integration end-to-end
My API base URL is https://api.mycompany.com and the feed I want to expose is at /v1/whales.
Claude can read this doc, your codebase, and walk you through the wiring step-by-step.

Reference

Canonical string

{METHOD}\n{PATH}\n{TIMESTAMP}\n{NONCE}\n{SHA256(BODY)}
Replace each placeholder with the actual values per request.
ComponentValue
METHODUppercase HTTP verb: GET, POST, PUT, DELETE, PATCH
PATHURL pathname only — no host, no query string. Trailing slash matters.
TIMESTAMPUnix seconds (10 digits in 2026). Must be within ±300s of server clock.
NONCERandom unique string per request. Recommended: UUID v4.
SHA256(BODY)Lowercase hex SHA-256 of raw request body. Empty string "" if no body.

Headers sent by ShadowFeed

HeaderValue
X-Sf-Partnershadowfeed (constant marker)
X-Sf-TimestampUnix seconds at signing time
X-Sf-NonceRandom nonce
X-Sf-SignatureHMAC-SHA256(secret, canonical) — lowercase hex

Signature algorithm

signature = hex(HMAC_SHA256(secret_bytes, canonical_string_bytes))
Use constant-time comparison when verifying — never use plain string equality. Python: hmac.compare_digest. Go: hmac.Equal. TypeScript: compare byte-by-byte after equal-length check.

Next steps

Withdrawals & Revenue

How to cash out accumulated STX.

Troubleshooting

Debug HMAC failures, request issues.