샘플
@noble/hashes 1.4.0: sha256
검증된 샘플 — npm @noble/hashes 1.4.0: sha256. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: assert sha256 produces exact 32-byte hash matching NIST…
sha256:9a1431fc71f0e3fce5cae7dafe1a9aaf1300e4114af2b80604a3cb9cb590b57c
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-01 |
케이스
HOW- 목표
- verify sha256 in pkg:npm/%40noble/hashes@1.4.0
- 심벌
-
- sha256
- 환경
- node 22.23.2
- 생성일
- 2026-09-01T19:54:45Z
컨트랙트
- assert sha256 produces exact 32-byte hash matching NIST standard test vectors for empty, single-block, and multi-block inputs
- assert sha256 accepts both UTF-8 string and Uint8Array byte inputs interchangeably
- assert sha256 exposes outputLen as 32 bytes and blockLen as 64 bytes
- assert sha256.create supports incremental streaming hash updates via update and digest
- assert sha256 incremental hash instance supports clone to fork hash state into independent streams
- assert sha256 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array
- assert sha256 incremental hash instance supports destroy to clean up internal buffer state
파일
- PROMPT.md
- csx.json
- index.js
- 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: verify sha256 in pkg:npm/%40noble/hashes@1.4.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40noble/hashes@1.4.0
Demonstrate these symbols/APIs:
- sha256
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:a3197134058ab315b18f1a6326e44b167f02105b00e9c6e931ebd1bcef7d61ce","contract":["assert sha256 produces exact 32-byte hash matching NIST standard test vectors for empty, single-block, and multi-block inputs","assert sha256 accepts both UTF-8 string and Uint8Array byte inputs interchangeably","assert sha256 exposes outputLen as 32 bytes and blockLen as 64 bytes","assert sha256.create supports incremental streaming hash updates via update and digest","assert sha256 incremental hash instance supports clone to fork hash state into independent streams","assert sha256 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array","assert sha256 incremental hash instance supports destroy to clean up internal buffer state"],"goal":"verify sha256 in pkg:npm/%40noble/hashes@1.4.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@1.4.0"],"schemaVersion":1,"symbols":["sha256"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40noble/hashes@1.4.0"],"schemaVersion":1,"subject":"pkg:npm/%40noble/hashes@1.4.0","symbols":["sha256"],"verifierAdapter":"node-typescript@1"}
const { sha256 } = require('@noble/hashes/sha256');
const { bytesToHex, utf8ToBytes, toBytes } = require('@noble/hashes/utils');
/**
* Computes the SHA-256 hash of a string or Uint8Array and returns the raw Uint8Array digest.
* @param {string | Uint8Array} input
* @returns {Uint8Array}
*/
function hashSha256(input) {
return sha256(input);
}
/**
* Computes the SHA-256 hash of a string or Uint8Array and returns a lowercase hex string.
* @param {string | Uint8Array} input
* @returns {string}
*/
function hashSha256Hex(input) {
return bytesToHex(sha256(input));
}
/**
* Creates an incremental SHA-256 hasher.
* @returns {import('@noble/hashes/utils').Hash<any>}
*/
function createSha256Hasher() {
return sha256.create();
}
/**
* Computes SHA-256 over multiple chunks in sequence and returns hex digest.
* @param {Array<string | Uint8Array>} chunks
* @returns {string}
*/
function hashChunksHex(chunks) {
const hasher = sha256.create();
for (const chunk of chunks) {
hasher.update(typeof chunk === 'string' ? utf8ToBytes(chunk) : chunk);
}
return bytesToHex(hasher.digest());
}
module.exports = {
sha256,
hashSha256,
hashSha256Hex,
createSha256Hasher,
hashChunksHex,
bytesToHex,
utf8ToBytes,
toBytes,
};
{
"name": "sample-noble-hashes-sha256",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-noble-hashes-sha256",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@noble/hashes": "1.4.0"
}
},
"node_modules/@noble/hashes": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz",
"integrity": "sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==",
"license": "MIT",
"engines": {
"node": ">= 16"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
}
}
}
{
"name": "sample-noble-hashes-sha256",
"version": "1.0.0",
"private": true,
"description": "verify sha256 in pkg:npm/%40noble/hashes@1.4.0",
"main": "index.js",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@noble/hashes": "1.4.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify sha256 in pkg:npm/%40noble/hashes@1.4.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40noble/hashes@1.4.0"
],
"symbols": [
"sha256"
]
}
import assert from 'node:assert';
import { sha256 } from '@noble/hashes/sha256';
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils';
import {
hashSha256,
hashSha256Hex,
createSha256Hasher,
hashChunksHex,
} from '../index.js';
// 1. One-shot hashing of empty input matches standard NIST vector
const emptyHashBytes = sha256('');
const emptyHashHex = bytesToHex(emptyHashBytes);
assert.strictEqual(
emptyHashHex,
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
'Empty string sha256 must match standard NIST digest'
);
assert.strictEqual(emptyHashBytes.length, 32, 'Digest byte length must be 32');
// 2. One-shot hashing with known test vectors (string and Uint8Array)
const abcHashHex = bytesToHex(sha256('abc'));
const abcHashFromBytes = bytesToHex(sha256(utf8ToBytes('abc')));
assert.strictEqual(
abcHashHex,
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad',
'sha256("abc") must match standard test vector'
);
assert.strictEqual(
abcHashHex,
abcHashFromBytes,
'String and Uint8Array utf8 byte inputs must produce identical digests'
);
// 3. Multi-block message hash verification
const multiBlockMsg = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq';
const multiBlockHash = bytesToHex(sha256(multiBlockMsg));
assert.strictEqual(
multiBlockHash,
'248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1',
'Multi-block message sha256 must match standard NIST digest'
);
// 4. Algorithm properties: outputLen and blockLen
assert.strictEqual(sha256.outputLen, 32, 'sha256.outputLen must be 32 bytes');
assert.strictEqual(sha256.blockLen, 64, 'sha256.blockLen must be 64 bytes');
// 5. Incremental streaming updates with sha256.create()
const streamHasher = sha256.create();
streamHasher.update(utf8ToBytes('abc'));
streamHasher.update('dbcd');
streamHasher.update(utf8ToBytes('ecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'));
const streamDigest = bytesToHex(streamHasher.digest());
assert.strictEqual(
streamDigest,
'248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1',
'Incremental sha256.create() stream must match one-shot hash'
);
// 6. Cloning hash state mid-stream to branch computations
const baseHasher = sha256.create();
baseHasher.update('common prefix: ');
const branchA = baseHasher.clone();
const branchB = baseHasher.clone();
branchA.update('action_alpha');
branchB.update('action_beta');
assert.strictEqual(
bytesToHex(branchA.digest()),
bytesToHex(sha256('common prefix: action_alpha')),
'Cloned branch A must compute independent digest'
);
assert.strictEqual(
bytesToHex(branchB.digest()),
bytesToHex(sha256('common prefix: action_beta')),
'Cloned branch B must compute independent digest'
);
// 7. digestInto pre-allocated Uint8Array buffer
const outputBuffer = new Uint8Array(32);
const directHasher = sha256.create();
directHasher.update('abc');
directHasher.digestInto(outputBuffer);
assert.strictEqual(
bytesToHex(outputBuffer),
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad',
'digestInto must write digest into target buffer'
);
// 8. State cleanup with destroy()
const destroyHasher = sha256.create();
destroyHasher.update('transient data');
destroyHasher.destroy();
// 9. Module wrapper helpers
assert.strictEqual(
hashSha256Hex('abc'),
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad',
'hashSha256Hex helper must match expected hex digest'
);
assert.strictEqual(
hashChunksHex(['abc', 'dbcd', 'ecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq']),
'248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1',
'hashChunksHex helper must correctly stream array of chunks'
);
console.log('All sha256 contract assertions passed.');
오리진 시더
익명