@bpinternal/signature-verification

中文文档
0.2.0发布于 2026/02/050BSDTypeScriptESM + CJS零依赖近 30 天下载 1.1万

Library to verify the signature of incoming webhook requests

原始使用文档
文档目录7 节
  1. Disclaimer ⚠️
  2. Features
  3. Installation
  4. Quick Start
  5. Usage
  6. Secret Rotation (Zero-Downtime)
  7. Express Middleware Example

Botpress Webhook Authentication Library

A TypeScript library for verifying Botpress webhook signatures. This should only be used for self-hosted integrations and bots, since Botpress Cloud handles signature verification automatically.

Disclaimer ⚠️

[!IMPORTANT] This package is published under the @bpinternal organization and is primarily intended for internal use by the Botpress team. As such, it may have unstable APIs, breaking changes without notice, and limited documentation or support. That said, we've made it public because we love open source! Feel free to use or fork it, but we recommend pinning to specific versions.

— The Botpress Engineering team

Features

  • HMAC-SHA256 Signature Verification: Validates signatures against shared secrets
  • Timestamp Validation: Rejects requests outside a ±5 minute time window
  • Secret Rotation: Supports multiple secrets for zero-downtime rotation
  • Resource Management: Automatic cleanup using Disposable interface

Installation

npm install --save @bpinternal/signature-verification

Quick Start

import { createSignatureVerifier } from '@bpinternal/signature-verification'

// Create a verifier with your shared secret:
using verifier = createSignatureVerifier({
  sharedSecrets: [process.env.WEBHOOK_SECRET],
})

// Verify a webhook request:
const isValid = await verifier.verify({
  headers: req.headers,
  rawBody: req.rawBody,
  method: req.method,
})

if (!isValid) {
  throw new Error('Invalid signature')
}

// Else, process the webhook...

Usage

Secret Rotation (Zero-Downtime)

Support multiple secrets to enable gradual rotation:

using verifier = createSignatureVerifier({
  sharedSecrets: [
    process.env.OLD_SECRET, // Still accepting old signatures
    process.env.NEW_SECRET, // Now also accepting new signatures
  ],
})

Secrets are tried in order until a match is found.

Express Middleware Example

import express from 'express'
import { createSignatureVerifier } from '@bpinternal/signature-verification'

const app = express()

// IMPORTANT: Capture raw body before parsing
app.use(
  express.json({
    verify: (req, res, buf) => {
      req.rawBody = buf.toString('utf8')
    },
  })
)

using requestVerifier = createSignatureVerifier({
  sharedSecrets: [process.env.WEBHOOK_SECRET],
})

// Create a reusable middleware:
const verifySignature = async (req, res, next) => {
  const isValid = await requestVerifier.verify({
    headers: req.headers,
    rawBody: req.rawBody,
    method: req.method,
  })

  if (!isValid) {
    return res.status(401).json({ error: 'Invalid signature' })
  }

  next()
}

// Use the middleware in your routes:
app.post('/webhook', verifySignature, (req, res) => {
  // Process webhook...
  res.status(200).json({ message: 'Webhook received' })
})

版本与发布记录

@bpinternal/signature-verification 共发布 3 个版本,首次发布于 2026/02/05;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.2.0latest2026/02/059 个月前
0.1.12026/02/059 个月前
0.1.02026/02/059 个月前

关于 @bpinternal/signature-verification 的常见问题

@bpinternal/signature-verification 是什么?

Library to verify the signature of incoming webhook requests

如何安装 @bpinternal/signature-verification?

在项目目录运行 npm install @bpinternal/signature-verification,或使用 pnpm add / yarn add / bun add。

@bpinternal/signature-verification 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bpinternal/signature-verification 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bpinternal/signature-verification 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=19.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bpinternal/signature-verification 可以商用吗?

@bpinternal/signature-verification 使用 0BSD 许可。几乎没有限制:可自由使用、修改和分发,连保留版权声明也不要求。以上为概括,不构成法律意见,请以许可原文为准。

@bpinternal/signature-verification 的下载量有多少?

根据 npm 官方下载统计,@bpinternal/signature-verification 在 2026/10/09 – 2026/11/07 这 30 天内被下载 10,610 次,日均约 354 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bpinternal/signature-verification 还在维护吗?

最新版本 0.2.0 发布于 2026/02/05(9 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/02/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。