示例
standardwebhooks 1.3.0
已验证示例 — npm standardwebhooks 1.3.0. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: Webhook.sign produces a v1,<base64> signature that Webhook.verify…
sha256:d00633d08c57eac08c22e983238e595527db41237de4dd0576da2ffa4e3a855d
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-11-28 |
案例
HOW- 目标
- verify pkg:npm/standardwebhooks@1.3.0
- 环境
- node 22.23.2
- 创建时间
- 2026-11-28T05:21:33Z
契约
- Webhook.sign produces a v1,<base64> signature that Webhook.verify accepts across base64 and { format: "raw" } key formats with case-insensitive headers and returns parsed JSON
- Webhook.verify accepts space-separated multiple signatures for key rotation
- Webhook.verify accepts raw Uint8Array payloads with { jsonParse: false } and empty payloads, returning undefined
- Webhook.verify throws WebhookVerificationError for tampered payloads, invalid signatures, missing required headers, and timestamps older than the 5-minute tolerance
- Webhook.endpointVerificationResponse produces a v1,<base64> response validated by Webhook.verifyEndpointVerificationResponse, which throws WebhookVerificationError on mismatch
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
源代码
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:npm/standardwebhooks@1.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/standardwebhooks@1.3.0
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:8daf44686648e61c20b44738d9df7d08d2057e4f592983bf3688454af6735079","constraints":{"executionContext":"node"},"contract":["Webhook.sign produces a v1,\u003cbase64\u003e signature that Webhook.verify accepts across base64 and { format: \"raw\" } key formats with case-insensitive headers and returns parsed JSON","Webhook.verify accepts space-separated multiple signatures for key rotation","Webhook.verify accepts raw Uint8Array payloads with { jsonParse: false } and empty payloads, returning undefined","Webhook.verify throws WebhookVerificationError for tampered payloads, invalid signatures, missing required headers, and timestamps older than the 5-minute tolerance","Webhook.endpointVerificationResponse produces a v1,\u003cbase64\u003e response validated by Webhook.verifyEndpointVerificationResponse, which throws WebhookVerificationError on mismatch"],"goal":"verify pkg:npm/standardwebhooks@1.3.0","kind":"HOW","packages":["pkg:npm/standardwebhooks@1.3.0"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/standardwebhooks@1.3.0"],"schemaVersion":1,"subject":"pkg:npm/standardwebhooks@1.3.0","verifierAdapter":"node-typescript@1"}
{
"name": "standardwebhooks-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "standardwebhooks-sample",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"standardwebhooks": "1.3.0"
}
},
"node_modules/@stablelib/base64": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@stablelib/base64/-/base64-1.0.1.tgz",
"integrity": "sha512-1bnPQqSxSuc3Ii6MhBysoWCg58j97aUjuCSZrGSmDxNqtytIi0k8utUenAwTZN4V5mXXYGsVUI9zeBqy+jBOSQ==",
"license": "MIT"
},
"node_modules/fast-sha256": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/fast-sha256/-/fast-sha256-1.3.0.tgz",
"integrity": "sha512-n11RGP/lrWEFI/bWdygLxhI+pVeo1ZYIVwvvPkW7azl/rOy+F3HYRZ2K5zeE9mmkhQppyv9sQFx0JM9UabnpPQ==",
"license": "Unlicense"
},
"node_modules/standardwebhooks": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/standardwebhooks/-/standardwebhooks-1.3.0.tgz",
"integrity": "sha512-5W9skHjqAm2dlA9wWvglTP+oX47JX4lFXVk1aJV7+TG1snvTR4QXaVgPscEzvOw9GRreeavMwbqEeL+MGhZHCg==",
"license": "MIT",
"dependencies": {
"@stablelib/base64": "^1.0.0",
"fast-sha256": "^1.3.0"
}
}
}
}
{
"name": "standardwebhooks-sample",
"version": "1.0.0",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"standardwebhooks": "1.3.0"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/standardwebhooks@1.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/standardwebhooks@1.3.0"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
"use strict";
const { Webhook, WebhookVerificationError } = require("standardwebhooks");
function createSignedDelivery(keyBytes, msgId, timestamp, payload) {
const base64Key = Buffer.from(keyBytes).toString("base64");
const signer = new Webhook(base64Key);
const signature = signer.sign(msgId, timestamp, payload);
const unixSeconds = String(Math.floor(timestamp.getTime() / 1000));
return {
signature,
headers: {
"webhook-id": msgId,
"webhook-timestamp": unixSeconds,
"webhook-signature": signature,
},
};
}
function verifyDelivery(keyBytes, payload, headers, options) {
const verifier = new Webhook(keyBytes, { format: "raw" });
return verifier.verify(payload, headers, options);
}
function createAndVerifyChallenge(keyBytes, challenge) {
const base64Key = Buffer.from(keyBytes).toString("base64");
const wh = new Webhook(base64Key);
const response = wh.endpointVerificationResponse(challenge);
wh.verifyEndpointVerificationResponse(challenge, response);
return response;
}
module.exports = {
Webhook,
WebhookVerificationError,
createSignedDelivery,
verifyDelivery,
createAndVerifyChallenge,
};
"use strict";
const assert = require("node:assert/strict");
const {
Webhook,
WebhookVerificationError,
createSignedDelivery,
verifyDelivery,
createAndVerifyChallenge,
} = require("../src/index");
const keyBytes = Uint8Array.from({ length: 24 }, (_, idx) => (idx * 7 + 11) & 0xff);
const now = new Date();
const msgId = "msg_0123456789abcdef";
const payloadObj = { type: "item.created", data: { id: 42, active: true } };
const payloadStr = JSON.stringify(payloadObj);
// 1. Base64-key sign and raw-key verify round-trip with case-insensitive headers
const delivery = createSignedDelivery(keyBytes, msgId, now, payloadStr);
assert.match(delivery.signature, /^v1,[A-Za-z0-9+/]+=*$/);
const mixedCaseHeaders = {
"Webhook-Id": delivery.headers["webhook-id"],
"Webhook-Timestamp": delivery.headers["webhook-timestamp"],
"Webhook-Signature": delivery.headers["webhook-signature"],
};
const parsed = verifyDelivery(keyBytes, payloadStr, mixedCaseHeaders);
assert.deepEqual(parsed, payloadObj);
// 2. Multiple space-separated signatures (key rotation)
const rotatedHeaders = {
...delivery.headers,
"webhook-signature": `v1,AAAAAAAAAAAAAAAA ${delivery.signature}`,
};
assert.deepEqual(verifyDelivery(keyBytes, payloadStr, rotatedHeaders), payloadObj);
// 3. Binary Uint8Array payload with jsonParse: false and empty payload
const rawBytes = new Uint8Array([0x00, 0x01, 0xfe, 0xff]);
const binaryDelivery = createSignedDelivery(keyBytes, "msg_binary", now, rawBytes);
const binaryResult = verifyDelivery(keyBytes, rawBytes, binaryDelivery.headers, {
jsonParse: false,
});
assert.equal(binaryResult, undefined);
const emptyDelivery = createSignedDelivery(keyBytes, "msg_empty", now, "");
assert.equal(verifyDelivery(keyBytes, "", emptyDelivery.headers), undefined);
// 4. Error conditions throw WebhookVerificationError
assert.throws(
() => verifyDelivery(keyBytes, '{"type":"tampered"}', delivery.headers),
(err) => err instanceof WebhookVerificationError && /No matching signature/i.test(err.message)
);
assert.throws(
() =>
verifyDelivery(keyBytes, payloadStr, {
...delivery.headers,
"webhook-signature": "v1,invalid",
}),
(err) => err instanceof WebhookVerificationError && /No matching signature/i.test(err.message)
);
assert.throws(
() => verifyDelivery(keyBytes, payloadStr, { "webhook-id": msgId }),
(err) => err instanceof WebhookVerificationError && /Missing required headers/i.test(err.message)
);
const staleTime = new Date(now.getTime() - 10 * 60 * 1000);
const staleDelivery = createSignedDelivery(keyBytes, "msg_stale", staleTime, payloadStr);
assert.throws(
() => verifyDelivery(keyBytes, payloadStr, staleDelivery.headers),
(err) => err instanceof WebhookVerificationError && /too old/i.test(err.message)
);
// 5. Endpoint verification challenge response and mismatch rejection
const challenge = "challenge_token_sample";
const challengeResponse = createAndVerifyChallenge(keyBytes, challenge);
assert.match(challengeResponse, /^v1,[A-Za-z0-9+/]+=*$/);
const rawVerifier = new Webhook(keyBytes, { format: "raw" });
assert.throws(
() => rawVerifier.verifyEndpointVerificationResponse(challenge, "v1,invalid"),
(err) => err instanceof WebhookVerificationError && /No matching signature/i.test(err.message)
);
console.log("standardwebhooks@1.3.0 contract passed");
原始种子者
匿名