CodeSampleX

サンプル

cookie-signature 1.2.2

検証済みサンプル — npm cookie-signature 1.2.2. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: assert cookieSignature.sign signs cookie string value with…

sha256:5a9400f0796dc83957921d83e1eea8f6054d4c32a6d9d991342d1fd71dd76b1b

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

ケース

HOW
ゴール
verify pkg:npm/cookie-signature@1.2.2
パッケージ
作成日
2026-08-20T13:43:52Z

コントラクト

  1. assert cookieSignature.sign signs cookie string value with HMAC SHA256 base64 digest stripped of padding
  2. assert cookieSignature.unsign recovers the original cookie value when secret matches
  3. assert cookieSignature.unsign returns false for tampered payload or mismatched secret
  4. assert cookieSignature.sign and cookieSignature.unsign throw TypeError when argument types are invalid or secret is null

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

ソースアーティファクトをダウンロード (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/cookie-signature@1.2.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/cookie-signature@1.2.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:5231ae376f805d1a6b1af7910e1cfd5bf1d23bb6f0b06d2c8aa8778f363fe0ee","contract":["assert cookieSignature.sign signs cookie string value with HMAC SHA256 base64 digest stripped of padding","assert cookieSignature.unsign recovers the original cookie value when secret matches","assert cookieSignature.unsign returns false for tampered payload or mismatched secret","assert cookieSignature.sign and cookieSignature.unsign throw TypeError when argument types are invalid or secret is null"],"goal":"verify pkg:npm/cookie-signature@1.2.2","kind":"HOW","packages":["pkg:npm/cookie-signature@1.2.2"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/cookie-signature@1.2.2"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-cookie-signature",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-cookie-signature",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "cookie-signature": "1.2.2"
      }
    },
    "node_modules/cookie-signature": {
      "version": "1.2.2",
      "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz",
      "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==",
      "license": "MIT",
      "engines": {
        "node": ">=6.6.0"
      }
    }
  }
}
package.json
{
  "name": "sample-cookie-signature",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "cookie-signature": "1.2.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/cookie-signature@1.2.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/cookie-signature@1.2.2"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const cookieSignature = require('cookie-signature');

// 1. Sign a cookie value with a secret
const secret = 'sample-secret-key';
const val = 'user-session-id';
const signed = cookieSignature.sign(val, secret);
assert.equal(typeof signed, 'string');
assert.equal(signed.startsWith(`${val}.`), true);

// 2. Unsign a valid signed cookie returns the original value
const unsigned = cookieSignature.unsign(signed, secret);
assert.equal(unsigned, val);

// 3. Unsign with wrong secret returns false
const unsignedWrongSecret = cookieSignature.unsign(signed, 'different-secret');
assert.equal(unsignedWrongSecret, false);

// 4. Unsign tampered cookie value returns false
const tampered = `${val}-tampered.${signed.split('.')[1]}`;
const unsignedTampered = cookieSignature.unsign(tampered, secret);
assert.equal(unsignedTampered, false);

// 5. Sign with non-string value or null secret throws TypeError
assert.throws(
  () => cookieSignature.sign(12345, secret),
  (err) => err instanceof TypeError && err.message === 'Cookie value must be provided as a string.'
);
assert.throws(
  () => cookieSignature.sign(val, null),
  (err) => err instanceof TypeError && err.message === 'Secret key must be provided.'
);

// 6. Unsign with non-string value or null secret throws TypeError
assert.throws(
  () => cookieSignature.unsign(12345, secret),
  (err) => err instanceof TypeError && err.message === 'Signed cookie string must be provided.'
);
assert.throws(
  () => cookieSignature.unsign(signed, null),
  (err) => err instanceof TypeError && err.message === 'Secret key must be provided.'
);

オリジンシーダー

匿名