@chec/webhook-verifier
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Webhook verifier

A lightweight JavaScript tool for verifying the validity of incoming webhook payloads from the Chec API. This script is designed to run in a Node.js context, e.g. a serverless function/Lambda.

CI status Version Downloads/week License
commercejs.com | @commercejs | Slack

Installation

npm install @chec/webhook-verifier
# or
yarn add @chec/webhook-verifier

Usage

Import verifyWebhook and use it at the start of your handler method. Provide your Chec webhook signing key as the second argument (available in your Chec Dashboard):

import { verifyWebhook } from '@chec/webhook-verifier';

module.exports = function (request) {
    verifyWebhook(request, process.env.CHEC_WEBHOOK_SIGNING_KEY);

    // ... continue with your logic
}

The verifyWebhook method signature is:

interface Payload {
    signature?: string,
    created: number,
}

export function verifyWebhook(data: Payload, signingKey: string, maxAgeSeconds: number = 300): void {
    // ...
}

The verifyWebhook method will throw an error if any checks fail:

  • The webhook signature is missing, or the signing key is missing
  • The webhook signature was invalid
  • The request is older than 5 minutes (by default)

License

This repository is available under a BSD-3-Clause license.

Readme

Keywords

none

Package Sidebar

Install

npm i @chec/webhook-verifier

Weekly Downloads

1

Version

1.0.2

License

BSD-3-Clause

Unpacked Size

10.4 kB

Total Files

14

Last publish

Collaborators

  • checplatform
  • dvnkshl
  • robbieaverill
  • scopey
  • notrab
  • kvisca
  • jaeriahtay