import { GumletError } from '../core/error'; import { type HeadersLike, type HeadersProtocol } from './headers'; export { hmacSha256, sha256 } from './hmac'; /** * The headers, replay window and algorithm a delivery is verified with. Every field is optional: what * an API leaves out falls back to the Standard Webhooks defaults in {@link DEFAULT_SCHEME}. */ export type WebhookSignatureScheme = { /** Header carrying the message id. */ readonly idHeader?: string; /** Header carrying the unix-seconds timestamp. */ readonly timestampHeader?: string; /** Header carrying the space-separated `v1,` signatures. */ readonly signatureHeader?: string; /** How far, in seconds, a delivery's timestamp may sit from now in either direction. */ readonly toleranceSeconds?: number; /** The MAC the API signs with. Only `hmac-sha256` is implemented. */ readonly algorithm?: string; /** * The helper's decode-only method as generated, named when `algorithm` is one this verifier cannot * check; absent when the SDK has none. */ readonly decodeOnly?: string; }; /** * Thrown when a delivery fails verification: a missing header, a timestamp outside the window, no * matching signature, or a signature algorithm the SDK cannot check. The name and messages are * stable, so callers can match on them. * * SDKs that verified through the `standardwebhooks` package let that library's class of the same name * escape, so callers wrote `err.name === 'WebhookVerificationError'` or `err instanceof * WebhookVerificationError`. The name is kept, and the package root exports this class, so both checks * keep working once the import points at the SDK. It extends the SDK's base error, so * `instanceof GumletError` covers a refused delivery too. Where the application has * loaded `standardwebhooks` itself, an `instanceof` against that library's class matches a refusal as * well (see {@link bridgeLibraryError}). A helper configured with an algorithm the verifier does not * implement throws it on every call; a missing or malformed secret, and a header the companions find * missing, still throw plain `Error`s. */ export declare class WebhookVerificationError extends GumletError { constructor(message: string); } /** * Verifies a Standard Webhooks delivery, throwing when it is not authentic. * * The HMAC-SHA256 of `{id}.{timestamp}.{payload}`, keyed with the base64-decoded secret, must equal one * of the space-separated `v1,` entries in the signature header, and the timestamp must be * within the scheme's window of now. `nowSeconds` exists for tests. * * `headers` may be any shape a request handler holds: a fetch `Headers`, a Node header record whose * values may be arrays, or entry pairs. They are read through the runtime's one header lookup, so every * webhook method reads a delivery's headers the same way. */ export declare const verifyWebhookSignature: (payload: string, headers: HeadersLike | HeadersProtocol, secret: string, scheme?: WebhookSignatureScheme, nowSeconds?: number) => void; //# sourceMappingURL=webhook-verify.d.ts.map