CodeSampleX

Ejemplo

crc-32 1.2.2: str

Muestra verificada para npm crc-32 1.2.2: str. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: CRC32.str(str) computes 32-bit signed…

sha256:241835a6f1cc293ca35b25c637584bbbd111dcc7a4fb85f43a1665cc1a349cc2

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify crc-32.str in pkg:npm/crc-32@1.2.2
Paquetes
Símbolos
  • crc-32.str
Creado
2026-09-04T16:27:24Z

Contrato

  1. CRC32.str(str) computes 32-bit signed integer CRC-32 checksum for ASCII strings matching standard test vectors
  2. CRC32.str('') returns 0 for empty string input
  3. CRC32.str(str, seed) computes CRC-32 checksum incrementally when seeded with previous chunk checksum
  4. CRC32.str(str) computes CRC-32 checksum for UTF-8 multi-byte strings
  5. crc >>> 0 converts signed 32-bit CRC-32 result to standard 32-bit unsigned integer and hex string

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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.str 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.str

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:b572bce39518a90114a3da686fa9893e9ccf6675337e97a06b68d13bfeae6729","contract":["CRC32.str(str) computes 32-bit signed integer CRC-32 checksum for ASCII strings matching standard test vectors","CRC32.str('') returns 0 for empty string input","CRC32.str(str, seed) computes CRC-32 checksum incrementally when seeded with previous chunk checksum","CRC32.str(str) computes CRC-32 checksum for UTF-8 multi-byte strings","crc \u003e\u003e\u003e 0 converts signed 32-bit CRC-32 result to standard 32-bit unsigned integer and hex string"],"goal":"verify crc-32.str in pkg:npm/crc-32@1.2.2","kind":"HOW","packages":["pkg:npm/crc-32@1.2.2"],"schemaVersion":1,"symbols":["crc-32.str"]},"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.str"],"verifierAdapter":"node-typescript@1"}
index.mjs
import CRC32 from 'crc-32';

/**
 * Computes the 32-bit signed CRC-32 checksum of a string.
 * @param {string} str - Input string to checksum.
 * @param {number} [seed] - Optional starting CRC value for chaining.
 * @returns {number} 32-bit signed integer CRC-32 checksum.
 */
export function crc32Str(str, seed) {
  return CRC32.str(str, seed);
}

/**
 * Computes the CRC-32 checksum across multiple sequential string chunks.
 * @param {string[]} chunks - Array of string chunks.
 * @param {number} [initialSeed] - Optional starting CRC value.
 * @returns {number} 32-bit signed integer CRC-32 checksum.
 */
export function crc32Chained(chunks, initialSeed) {
  let crc = initialSeed;
  for (const chunk of chunks) {
    crc = CRC32.str(chunk, crc);
  }
  return crc !== undefined ? crc : CRC32.str('');
}

/**
 * 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 CRC.
 */
export function toUnsigned32(crc) {
  return crc >>> 0;
}

/**
 * Formats a CRC integer as an 8-character lowercase hexadecimal string.
 * @param {number} crc - 32-bit CRC integer.
 * @returns {string} 8-character hex string.
 */
export function toHex32(crc) {
  return (crc >>> 0).toString(16).padStart(8, '0');
}

export { CRC32 };
export default CRC32;
package-lock.json
{
  "name": "sample-crc-32-str",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-crc-32-str",
      "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-str",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "crc-32": "1.2.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify crc-32.str in pkg:npm/crc-32@1.2.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/crc-32@1.2.2"
  ],
  "symbols": [
    "crc-32.str"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import CRC32, { crc32Str, crc32Chained, toUnsigned32, toHex32 } from '../index.mjs';

// 1. CRC32.str(str) computes 32-bit signed integer CRC-32 checksum for ASCII strings matching standard test vectors
const standardVector = '123456789';
const standardCrc = CRC32.str(standardVector);
assert.equal(typeof standardCrc, 'number');
assert.equal(standardCrc, -873187034);
assert.equal((standardCrc >>> 0).toString(16), 'cbf43926');
assert.equal(crc32Str(standardVector), standardCrc);
assert.equal(toHex32(standardCrc), 'cbf43926');

const foxText = 'The quick brown fox jumps over the lazy dog';
const foxCrc = CRC32.str(foxText);
assert.equal(foxCrc, 1095738169);
assert.equal((foxCrc >>> 0).toString(16), '414fa339');
assert.equal(crc32Str(foxText), foxCrc);
assert.equal(toHex32(foxCrc), '414fa339');

// 2. CRC32.str('') returns 0 for empty string input
assert.equal(CRC32.str(''), 0);
assert.equal(crc32Str(''), 0);

// 3. CRC32.str(str, seed) computes CRC-32 checksum incrementally when seeded with previous chunk checksum
const part1 = 'The quick brown fox ';
const part2 = 'jumps over the lazy dog';
const seed = CRC32.str(part1);
const chainedCrc = CRC32.str(part2, seed);
assert.equal(chainedCrc, foxCrc);
assert.equal(crc32Chained([part1, part2]), foxCrc);

// 4. CRC32.str(str) computes CRC-32 checksum for UTF-8 multi-byte strings
const utf8Text = 'Hello, 世界! 🌍';
const utf8Crc = CRC32.str(utf8Text);
assert.equal(typeof utf8Crc, 'number');
assert.equal(utf8Crc, -895523342);
assert.equal((utf8Crc >>> 0).toString(16), 'ca9f65f2');
assert.equal(crc32Str(utf8Text), utf8Crc);
assert.equal(toHex32(utf8Crc), 'ca9f65f2');

// 5. crc >>> 0 converts signed 32-bit CRC-32 result to standard 32-bit unsigned integer and hex string
const unsignedVal = standardCrc >>> 0;
assert.equal(unsignedVal, 3421780262);
assert.equal(toUnsigned32(standardCrc), 3421780262);
assert.equal(unsignedVal.toString(16).padStart(8, '0'), 'cbf43926');

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

Seeder de origen

anónimo