CodeSampleX

Exemple

cookie-signature 1.2.2

Échantillon vérifié pour npm cookie-signature 1.2.2. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:5a9400f0796dc83957921d83e1eea8f6054d4c32a6d9d991342d1fd71dd76b1b

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:npm/cookie-signature@1.2.2
Paquets
Créé
2026-08-20T13:43:52Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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.'
);

Seeder d'origine

anonyme