CodeSampleX

Exemple

crc-32 1.2.2: bstr

Échantillon vérifié pour npm crc-32 1.2.2: bstr. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:fac6a21f7d1986f3cd51e6a9e225f97dd5ad59de25e451c2af9cc7270f1de0a8

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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-04

Cas

HOW
Objectif
verify crc-32.bstr in pkg:npm/crc-32@1.2.2
Paquets
Symboles
  • crc-32.bstr
Créé
2026-09-04T12:56:27Z

Contrat

  1. CRC32.bstr(binaryStr) computes 32-bit signed integer CRC-32 checksum for 8-bit binary strings
  2. CRC32.bstr('') returns 0 for empty binary string
  3. CRC32.bstr(binaryStr) matches CRC32.buf(bytes) for identical byte sequences
  4. CRC32.bstr(part2, seed) supports incremental CRC-32 computation chaining with seed

Fichiers

  • PROMPT.md
  • csx.json
  • index.mjs
  • 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 crc-32.bstr in pkg:npm/crc-32@1.2.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/crc-32@1.2.2
Demonstrate these symbols/APIs:
  - crc-32.bstr

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:4c47c50ecfc83b2a5bfb7d76cdda9462f091ee52033d676ff66f2ebc5da83db7","contract":["CRC32.bstr(binaryStr) computes 32-bit signed integer CRC-32 checksum for 8-bit binary strings","CRC32.bstr('') returns 0 for empty binary string","CRC32.bstr(binaryStr) matches CRC32.buf(bytes) for identical byte sequences","CRC32.bstr(part2, seed) supports incremental CRC-32 computation chaining with seed"],"goal":"verify crc-32.bstr in pkg:npm/crc-32@1.2.2","kind":"HOW","packages":["pkg:npm/crc-32@1.2.2"],"schemaVersion":1,"symbols":["crc-32.bstr"]},"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/crc-32@1.2.2"],"schemaVersion":1,"subject":"pkg:npm/crc-32@1.2.2","symbols":["crc-32.bstr"],"verifierAdapter":"node-typescript@1"}
index.mjs
import CRC32 from 'crc-32';

/**
 * Computes the 32-bit signed CRC-32 checksum of an 8-bit binary string.
 * Each character code is treated as a single byte (0-255).
 *
 * @param {string} bstr - Binary string of 8-bit characters.
 * @param {number} [seed] - Optional previous CRC-32 value for incremental calculation.
 * @returns {number} 32-bit signed integer CRC-32 checksum.
 */
export function crc32BinaryString(bstr, seed) {
  return CRC32.bstr(bstr, seed);
}

/**
 * Converts a signed 32-bit CRC integer to an unsigned 32-bit integer.
 *
 * @param {number} crc - 32-bit signed integer CRC.
 * @returns {number} 32-bit unsigned integer.
 */
export function toUnsigned(crc) {
  return crc >>> 0;
}

/**
 * Formats a 32-bit CRC checksum as an 8-character zero-padded lowercase hexadecimal string.
 *
 * @param {number} crc - 32-bit signed or unsigned integer CRC.
 * @returns {string} 8-character hex string.
 */
export function toHex(crc) {
  return (crc >>> 0).toString(16).padStart(8, '0');
}
package-lock.json
{
  "name": "sample-crc-32-bstr",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-crc-32-bstr",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "crc-32": "1.2.2"
      }
    },
    "node_modules/crc-32": {
      "version": "1.2.2",
      "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz",
      "integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==",
      "license": "Apache-2.0",
      "bin": {
        "crc32": "bin/crc32.njs"
      },
      "engines": {
        "node": ">=0.8"
      }
    }
  }
}
package.json
{
  "name": "sample-crc-32-bstr",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "crc-32": "1.2.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify crc-32.bstr in pkg:npm/crc-32@1.2.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/crc-32@1.2.2"
  ],
  "symbols": [
    "crc-32.bstr"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import CRC32 from 'crc-32';
import { crc32BinaryString, toUnsigned, toHex } from '../index.mjs';

// 1. Verify CRC32.bstr computes 32-bit signed integer CRC-32 checksum for 8-bit binary strings
const binaryData = [0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64];
const binaryStr = String.fromCharCode(...binaryData);
const checksum = CRC32.bstr(binaryStr);

assert.equal(typeof checksum, 'number');
assert.equal(checksum, 0x4a17b156 | 0);
assert.equal(toUnsigned(checksum), 0x4a17b156);
assert.equal(toHex(checksum), '4a17b156');
assert.equal(crc32BinaryString(binaryStr), checksum);

// 2. Verify CRC32.bstr('') returns 0 for empty binary string
assert.equal(CRC32.bstr(''), 0);
assert.equal(crc32BinaryString(''), 0);

// 3. Verify CRC32.bstr matches CRC32.buf for identical byte sequences
const highByteData = [0x00, 0x01, 0x7f, 0x80, 0xaa, 0xfe, 0xff];
const highByteStr = String.fromCharCode(...highByteData);
const highByteBuf = Buffer.from(highByteData);

const bstrResult = CRC32.bstr(highByteStr);
const bufResult = CRC32.buf(highByteBuf);

assert.equal(bstrResult, bufResult);
assert.equal(crc32BinaryString(highByteStr), bufResult);

// 4. Verify CRC32.bstr(part2, seed) supports incremental CRC-32 chaining with seed
const chunk1 = String.fromCharCode(0x01, 0x02, 0x03);
const chunk2 = String.fromCharCode(0x04, 0x05, 0x06);
const whole = String.fromCharCode(0x01, 0x02, 0x03, 0x04, 0x05, 0x06);

const wholeCrc = CRC32.bstr(whole);
const seed1 = CRC32.bstr(chunk1);
const chainedCrc = CRC32.bstr(chunk2, seed1);

assert.equal(chainedCrc, wholeCrc);
assert.equal(crc32BinaryString(chunk2, crc32BinaryString(chunk1)), wholeCrc);

console.log('Contract assertions passed successfully.');

Seeder d'origine

anonyme