sec-hmac-sign Edge Function — Security
SecuritySigns a string payload with HMAC-SHA256 or HMAC-SHA512 using Web Crypto — outputs a hex-encoded signature.
Edge function sec-hmac-sign Signs a string payload with HMAC-SHA256 or HMAC-SHA512 using Web Crypto — outputs a hex-encoded signature.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.
npx aerostack add navin/sec-hmac-sign Use with AI Assistants
MCPConnect Claude, Cursor, or any MCP-compatible client — then call this function by slug
① Add MCP Server
Add this once — access all Aerostack functions from your AI tool.
{
"mcpServers": {
"aerostack": {
"url": "https://mcp.aerostack.dev",
"type": "http"
}
}
} ② Call this function
Ask your AI to use the call_function tool with this slug:
call_function({
slug: "sec-hmac-sign",
args: {
"payload": "example_payload",
"secret": "example_secret",
"algorithm": "SHA-256"
}
}) sec-hmac-sign — Sign payloads with HMAC
Creates an HMAC-SHA256 or HMAC-SHA512 signature for any string payload using the Web Crypto API — output is hex-encoded.
API
POST /api/sec-hmac-sign
Request body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
payload |
string | ✅ | — | The string to sign |
secret |
string | ✅ | — | Shared HMAC secret |
algorithm |
"SHA-256" | "SHA-512" |
❌ | "SHA-256" |
Hash algorithm |
Success response (200)
{
"success": true,
"data": {
"signature": "b94d27b9934d3e08a52e52d7da7dabfac484efe04294e576e9caefd1b8..."
}
}
Error responses
| Code | HTTP | When |
|---|---|---|
INVALID_INPUT |
400 | Missing payload or secret |
INTERNAL_ERROR |
500 | Unexpected error |
Usage
cURL
curl -X POST "$FUNCTION_URL" \
-H "Content-Type: application/json" \
-d '{"payload": "{\"event\":\"order.created\",\"id\":\"ord_123\"}", "secret": "webhook-secret"}'
TypeScript / JavaScript (HTTP)
const body = JSON.stringify(webhookPayload);
const response = await fetch(FUNCTION_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ payload: body, secret: WEBHOOK_SECRET }),
});
const { data } = await response.json();
// Attach data.signature as X-Signature header
Direct import (Node / Bun / Deno)
import { hmacSign } from '@aerostack/functions/sec-hmac-sign';
const { signature } = await hmacSign({ payload: body, secret: process.env.HMAC_SECRET! });
Use Cases
- Signing outbound webhook payloads so receivers can verify authenticity
- Creating request signatures for API authentication (like AWS SigV4 style)
- Generating tokens to verify email links or password reset URLs
- Signing data before storing it to detect tampering on read
Notes
- SHA-256 produces 64 hex characters (32 bytes); SHA-512 produces 128 hex characters (64 bytes)
- Deterministic — same payload + secret always yields the same signature
- Use
sec-hmac-verifyfor timing-safe verification on the receiver side - Never use string equality for signature comparison — always use
sec-hmac-verify
Metadata
Tags
Publisher
@navin verified
Build and publish your own functions
Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.
More Security Functions
Browse Security Functions →sec-api-key-generate
by @navin
Generates a cryptographically random API key with a custom prefix using a base62 alphabet — no ambiguous characters, URL-safe.
sec-cors-validate
by @navin
Validates a request Origin against an allow list and returns the correct CORS response headers to set — supports wildcards and credentials.
sec-csp-generate
by @navin
Generates a Content-Security-Policy header value from a structured directives object — supports report-only mode and report-uri.
sec-decrypt-aes
by @navin
Decrypts an AES-256-GCM encrypted bundle produced by sec-encrypt-aes — key is derived via SHA-256, auth tag is verified automatically.
sec-encrypt-aes
by @navin
Encrypts a string with AES-256-GCM using Web Crypto — key is derived via SHA-256, output is a portable IV:ciphertext bundle.
sec-hash-sha256
by @navin
Hashes a string using SHA-256 via the Web Crypto API. Supports hex and base64 output. Zero dependencies.
Frequently asked questions
What does the sec-hmac-sign function do? +
sec-hmac-sign is a serverless edge function for security automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.
How do I deploy the sec-hmac-sign function? +
Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/sec-hmac-sign ``` It will be live on Cloudflare Workers in seconds.
What runtime does sec-hmac-sign use? +
sec-hmac-sign runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.
Can I customise the sec-hmac-sign function? +
Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.