サンプル
crc-32 1.2.2: compute CRC32 checksum for strings and buffers using crc-32
検証済みサンプル — npm crc-32 1.2.2: compute CRC32 checksum for strings and buffers using crc-32. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました.
sha256:87b90caeeaec71c7c6a8217f509f874ef902f909d3cdff3cc76073993d850b54
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。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@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-28 |
ケース
HOW- ゴール
- compute CRC32 checksum for strings and buffers using crc-32
- パッケージ
- シンボル
-
- CRC32.bstr
- CRC32.buf
- CRC32.str
- 作成日
- 2026-08-28T08:13:17Z
コントラクト
- CRC32.str(str) computes 32-bit signed integer CRC-32 checksum for ASCII and UTF-8 strings
- CRC32.str('') returns 0 for empty string input
- CRC32.buf(buf) computes CRC-32 checksum for Buffer and Uint8Array byte sequences
- CRC32.bstr(binaryStr) computes CRC-32 checksum for 8-bit binary strings matching buffer CRC
- CRC32.str(part2, seed) and CRC32.buf(part2, seed) support incremental CRC-32 chaining with seed
ファイル
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
ソース
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: compute CRC32 checksum for strings and buffers using crc-32
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/crc-32@1.2.2
Demonstrate these symbols/APIs:
- CRC32.bstr
- CRC32.buf
- CRC32.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.
{"case":{"caseId":"case:sha256:26527bb7866278813502aecb35dfcb41356fd2401c488e950cb741f18396f86c","contract":["CRC32.str(str) computes 32-bit signed integer CRC-32 checksum for ASCII and UTF-8 strings","CRC32.str('') returns 0 for empty string input","CRC32.buf(buf) computes CRC-32 checksum for Buffer and Uint8Array byte sequences","CRC32.bstr(binaryStr) computes CRC-32 checksum for 8-bit binary strings matching buffer CRC","CRC32.str(part2, seed) and CRC32.buf(part2, seed) support incremental CRC-32 chaining with seed"],"goal":"compute CRC32 checksum for strings and buffers using crc-32","kind":"HOW","packages":["pkg:npm/crc-32@1.2.2"],"schemaVersion":1,"symbols":["CRC32.bstr","CRC32.buf","CRC32.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":["CRC32.bstr","CRC32.buf","CRC32.str"],"verifierAdapter":"node-typescript@1"}
import CRC32 from 'crc-32';
/**
* Computes CRC-32 checksum of a UTF-8 string.
* @param {string} str - The string to compute checksum for.
* @param {number} [seed] - Optional starting CRC value for incremental computation.
* @returns {number} 32-bit signed integer CRC-32 checksum.
*/
export function checksumString(str, seed) {
return CRC32.str(str, seed);
}
/**
* Computes CRC-32 checksum of a binary Buffer or Uint8Array.
* @param {Uint8Array|Buffer|number[]} buf - The byte buffer.
* @param {number} [seed] - Optional starting CRC value for incremental computation.
* @returns {number} 32-bit signed integer CRC-32 checksum.
*/
export function checksumBuffer(buf, seed) {
return CRC32.buf(buf, seed);
}
/**
* Computes CRC-32 checksum of an 8-bit binary string.
* @param {string} bstr - Binary string of 8-bit character codes (0-255).
* @param {number} [seed] - Optional starting CRC value for incremental computation.
* @returns {number} 32-bit signed integer CRC-32 checksum.
*/
export function checksumBinaryString(bstr, seed) {
return CRC32.bstr(bstr, seed);
}
/**
* Converts signed 32-bit CRC integer to unsigned 32-bit representation.
* @param {number} crc - 32-bit signed integer CRC.
* @returns {number} 32-bit unsigned integer CRC.
*/
export function toUnsignedCrc32(crc) {
return crc >>> 0;
}
/**
* Formats CRC integer as 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 toHexCrc32(crc) {
return (crc >>> 0).toString(16).padStart(8, '0');
}
{
"name": "sample-crc-32",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-crc-32",
"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"
}
}
}
}
{
"name": "sample-crc-32",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"crc-32": "1.2.2"
}
}
{
"schemaVersion": 1,
"goal": "compute CRC32 checksum for strings and buffers using crc-32",
"kind": "HOW",
"packages": [
"pkg:npm/crc-32@1.2.2"
],
"symbols": [
"CRC32.bstr",
"CRC32.buf",
"CRC32.str"
]
}
import assert from 'node:assert/strict';
import CRC32 from 'crc-32';
import {
checksumString,
checksumBuffer,
checksumBinaryString,
toUnsignedCrc32,
toHexCrc32,
} from '../index.mjs';
// 1. Verify CRC32.str computation on standard test vectors
const foxText = 'The quick brown fox jumps over the lazy dog';
const foxCrc = CRC32.str(foxText);
assert.equal(typeof foxCrc, 'number');
assert.equal(toUnsignedCrc32(foxCrc), 0x414fa339);
assert.equal(toHexCrc32(foxCrc), '414fa339');
assert.equal(checksumString(foxText), foxCrc);
// Empty string yields 0
assert.equal(CRC32.str(''), 0);
assert.equal(checksumString(''), 0);
// 2. Verify UTF-8 multi-byte string handling with CRC32.str
const unicodeText = 'Hello, 世界! 🌍';
const unicodeCrc = CRC32.str(unicodeText);
assert.equal(typeof unicodeCrc, 'number');
assert.equal(checksumString(unicodeText), unicodeCrc);
// 3. Verify CRC32.buf on Uint8Array and Buffer matches UTF-8 string encoding
const utf8Bytes = Buffer.from(unicodeText, 'utf8');
const bufCrc = CRC32.buf(utf8Bytes);
assert.equal(bufCrc, unicodeCrc);
assert.equal(checksumBuffer(utf8Bytes), unicodeCrc);
const uint8Array = new Uint8Array(utf8Bytes);
assert.equal(CRC32.buf(uint8Array), unicodeCrc);
assert.equal(checksumBuffer(uint8Array), unicodeCrc);
// 4. Verify CRC32.bstr on 8-bit binary string
const binaryData = [0x00, 0x01, 0x7f, 0x80, 0xff];
const binaryStr = String.fromCharCode(...binaryData);
const bstrCrc = CRC32.bstr(binaryStr);
const bbufCrc = CRC32.buf(new Uint8Array(binaryData));
assert.equal(bstrCrc, bbufCrc);
assert.equal(checksumBinaryString(binaryStr), bstrCrc);
// 5. Verify incremental / chained CRC32 calculation with seed
const part1 = 'The quick brown fox ';
const part2 = 'jumps over the lazy dog';
const seed1 = CRC32.str(part1);
const combinedCrc = CRC32.str(part2, seed1);
assert.equal(combinedCrc, foxCrc);
// Incremental computation across buffers
const part1Buf = Buffer.from(part1, 'utf8');
const part2Buf = Buffer.from(part2, 'utf8');
const seedBuf = CRC32.buf(part1Buf);
const combinedBufCrc = CRC32.buf(part2Buf, seedBuf);
assert.equal(combinedBufCrc, foxCrc);
console.log('Contract assertions passed successfully.');
オリジンシーダー
匿名