CodeSampleX

샘플

standardwebhooks 1.3.0

검증된 샘플 — npm standardwebhooks 1.3.0. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: Webhook.sign produces a v1,<base64> signature that…

sha256:d00633d08c57eac08c22e983238e595527db41237de4dd0576da2ffa4e3a855d

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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

컨트랙트

  1. 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
  2. Webhook.verify accepts space-separated multiple signatures for key rotation
  3. Webhook.verify accepts raw Uint8Array payloads with { jsonParse: false } and empty payloads, returning undefined
  4. Webhook.verify throws WebhookVerificationError for tampered payloads, invalid signatures, missing required headers, and timestamps older than the 5-minute tolerance
  5. 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

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
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.
csx.json
{"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"}
package-lock.json
{
  "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"
      }
    }
  }
}
package.json
{
  "name": "standardwebhooks-sample",
  "version": "1.0.0",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "standardwebhooks": "1.3.0"
  }
}
spec.json
{
  "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"
  }
}
src/index.js
"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,
};
test/contract.js
"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");

오리진 시더

익명