Skip to main content

@rtorcato/api-common v1.0.0

Interfaces​

WebhookOptions​

Defined in: hono/index.ts:6

Extends​

  • SignatureOptions

Properties​

secret​

secret: string

Defined in: hono/index.ts:8

Shared secret used to compute the expected HMAC.

optional header?: string

Defined in: hono/index.ts:10

Request header carrying the signature. Default: 'x-signature'.

algorithm?​

optional algorithm?: string

Defined in: index.ts:5

HMAC hash algorithm. Default: 'sha256'.

Inherited from​

SignatureOptions.algorithm

prefix?​

optional prefix?: string

Defined in: index.ts:10

Prefix carried on the signature header value (included in both the computed and the compared value), e.g. GitHub's 'sha256='. Default: ''.

Inherited from​

SignatureOptions.prefix

Functions​

webhookMiddleware()​

webhookMiddleware(options): MiddlewareHandler

Defined in: hono/index.ts:32

Hono webhook middleware: verifies the HMAC signature over the raw request body. Responds 401 with the standard @rtorcato/api-common/errors envelope on a missing/invalid signature.

Hono buffers the request body, so a downstream handler can still call c.req.json() after this middleware has read it as text:

app.post('/webhooks/github', webhookMiddleware({
secret: env.WEBHOOK_SECRET,
header: 'x-hub-signature-256',
prefix: 'sha256=',
}), async (c) => {
const payload = await c.req.json()
return c.body(null, 204)
})

Parameters​

options​

WebhookOptions

Returns​

MiddlewareHandler