サンプル
@cacheable/utils 2.5.0: hashSync
検証済みサンプル — npm @cacheable/utils 2.5.0: hashSync. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: hashSync returns a deterministic non-empty…
sha256:e943ba4c023adecd468eb7b90182d11cdc9041a14588da583ae69bb7320d59c6
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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-05 |
ケース
HOW- ゴール
- verify hashSync in pkg:npm/%40cacheable/utils@2.5.0
- パッケージ
- シンボル
-
- hashSync
- 環境
- node 22.23.2
- 作成日
- 2026-09-05T16:45:34Z
コントラクト
- hashSync returns a deterministic non-empty string hash using the default djb2 algorithm for string and object inputs
- hashSync produces identical hashes for identical inputs and distinct hashes for different inputs
- hashSync supports non-cryptographic algorithms including fnv1, murmer, and crc32
- hashSync supports a custom serialize function to format objects before hashing
- hashSync throws an error when called with unsupported cryptographic algorithm SHA-256
ファイル
- .npmrc
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
ソース
audit=false
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 hashSync in pkg:npm/%40cacheable/utils@2.5.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40cacheable/utils@2.5.0
Demonstrate these symbols/APIs:
- hashSync
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:027f69e2bc2b2c870483a15382f384b703edd1d5cc071b96b72519aa75017bf7","contract":["hashSync returns a deterministic non-empty string hash using the default djb2 algorithm for string and object inputs","hashSync produces identical hashes for identical inputs and distinct hashes for different inputs","hashSync supports non-cryptographic algorithms including fnv1, murmer, and crc32","hashSync supports a custom serialize function to format objects before hashing","hashSync throws an error when called with unsupported cryptographic algorithm SHA-256"],"goal":"verify hashSync in pkg:npm/%40cacheable/utils@2.5.0","kind":"HOW","packages":["pkg:npm/%40cacheable/utils@2.5.0"],"schemaVersion":1,"symbols":["hashSync"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40cacheable/utils@2.5.0"],"schemaVersion":1,"subject":"pkg:npm/%40cacheable/utils@2.5.0","symbols":["hashSync"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-cacheable-utils-hash-sync",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-cacheable-utils-hash-sync",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@cacheable/utils": "2.5.0"
}
},
"node_modules/@cacheable/utils": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@cacheable/utils/-/utils-2.5.0.tgz",
"integrity": "sha512-buipgOVDkkPXNR5+xBpDw7Zk2n1EvU7qBJCNUcL7rhQ//kfpOXPAvQ511Os0vpLYJ1pZnvudNytkQt2hst3wqA==",
"license": "MIT",
"dependencies": {
"hashery": "^1.5.1",
"keyv": "^5.6.0"
}
},
"node_modules/@keyv/serialize": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@keyv/serialize/-/serialize-1.1.1.tgz",
"integrity": "sha512-dXn3FZhPv0US+7dtJsIi2R+c7qWYiReoEh5zUntWCf4oSpMNib8FDhSoed6m3QyZdx5hK7iLFkYk3rNxwt8vTA==",
"license": "MIT"
},
"node_modules/hashery": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/hashery/-/hashery-1.5.1.tgz",
"integrity": "sha512-iZyKG96/JwPz1N55vj2Ie2vXbhu440zfUfJvSwEqEbeLluk7NnapfGqa7LH0mOsnDxTF85Mx8/dyR6HfqcbmbQ==",
"license": "MIT",
"dependencies": {
"hookified": "^1.15.0"
},
"engines": {
"node": ">=20"
}
},
"node_modules/hookified": {
"version": "1.15.1",
"resolved": "https://registry.npmjs.org/hookified/-/hookified-1.15.1.tgz",
"integrity": "sha512-MvG/clsADq1GPM2KGo2nyfaWVyn9naPiXrqIe4jYjXNZQt238kWyOGrsyc/DmRAQ+Re6yeo6yX/yoNCG5KAEVg==",
"license": "MIT"
},
"node_modules/keyv": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-5.6.0.tgz",
"integrity": "sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==",
"license": "MIT",
"dependencies": {
"@keyv/serialize": "^1.1.1"
}
}
}
}
{
"name": "sample-cacheable-utils-hash-sync",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@cacheable/utils": "2.5.0"
}
}
{
"schemaVersion": 1,
"goal": "verify hashSync in pkg:npm/%40cacheable/utils@2.5.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40cacheable/utils@2.5.0"
],
"symbols": [
"hashSync"
]
}
import { hashSync, HashAlgorithm } from '@cacheable/utils';
/**
* Computes a hash synchronously for an object or primitive value.
*
* @param {any} value - The object or primitive to hash
* @param {import('@cacheable/utils').HashOptions} [options] - Hashing options
* @returns {string} The computed hash string
*/
export function computeHash(value, options) {
return hashSync(value, options);
}
export { hashSync, HashAlgorithm };
export default hashSync;
import assert from 'node:assert/strict';
import { hashSync, HashAlgorithm } from '@cacheable/utils';
import { computeHash } from '../src/index.mjs';
// 1. hashSync returns a deterministic non-empty string hash using the default djb2 algorithm for string and object inputs
{
const hashStr = hashSync('test-data');
assert.equal(typeof hashStr, 'string');
assert.ok(hashStr.length > 0);
const hashWrapped = computeHash('test-data');
assert.equal(hashWrapped, hashStr);
const hashObj = hashSync({ key: 'value', count: 42 });
assert.equal(typeof hashObj, 'string');
assert.ok(hashObj.length > 0);
}
// 2. hashSync produces identical hashes for identical inputs and distinct hashes for different inputs
{
const hashA = hashSync({ x: 1, y: 2 });
const hashB = hashSync({ x: 1, y: 2 });
const hashC = hashSync({ x: 1, y: 3 });
assert.equal(hashA, hashB);
assert.notEqual(hashA, hashC);
}
// 3. hashSync supports non-cryptographic algorithms including fnv1, murmer, and crc32
{
const fnv1 = hashSync('test-payload', { algorithm: HashAlgorithm.FNV1 });
const murmer = hashSync('test-payload', { algorithm: HashAlgorithm.MURMER });
const crc32 = hashSync('test-payload', { algorithm: HashAlgorithm.CRC32 });
const djb2 = hashSync('test-payload', { algorithm: HashAlgorithm.DJB2 });
assert.equal(typeof fnv1, 'string');
assert.equal(typeof murmer, 'string');
assert.equal(typeof crc32, 'string');
assert.equal(typeof djb2, 'string');
assert.ok(fnv1.length > 0);
assert.ok(murmer.length > 0);
assert.ok(crc32.length > 0);
assert.ok(djb2.length > 0);
}
// 4. hashSync supports a custom serialize function to format objects before hashing
{
const customHash = hashSync({ b: 2, a: 1 }, {
serialize: (obj) => Object.keys(obj).sort().map(k => `${k}=${obj[k]}`).join('&')
});
assert.equal(typeof customHash, 'string');
assert.ok(customHash.length > 0);
}
// 5. hashSync throws an error when called with unsupported cryptographic algorithm SHA-256
{
assert.throws(
() => hashSync('sample', { algorithm: HashAlgorithm.SHA256 }),
(err) => err instanceof Error && /does not support synchronous hashing/i.test(err.message)
);
}
console.log('Contract tests passed successfully.');
オリジンシーダー
匿名