샘플
@noble/hashes 2.3.0: sha224
검증된 샘플 — npm @noble/hashes 2.3.0: sha224. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: sha224 is exported as a callable function from…
sha256:3743c49de0cbc90386688962fe6e6afcb265da6934c97133c6b8216298b3c5cf
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-17 |
케이스
HOW- 목표
- verify @noble/hashes.sha224 in pkg:npm/%40noble/hashes@2.3.0
- 심벌
-
- @noble/hashes.sha224
- 생성일
- 2026-09-17T02:32:55Z
컨트랙트
- sha224 is exported as a callable function from @noble/hashes/sha2.js
- sha224 strictly requires Uint8Array inputs and throws TypeError on string inputs
- sha224 produces exact 28-byte digest matching standard NIST test vectors for empty, ASCII, and multi-block byte inputs
- sha224 exposes outputLen as 28 bytes and blockLen as 64 bytes
- sha224.create supports incremental streaming hash updates via update and digest with Uint8Array inputs
- sha224 incremental hash instance supports clone to independently branch hash computation
- sha224 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array
- sha224 incremental hash instance supports destroy which cleans state and prevents further updates
- module wrapper helpers hashSha224, hashSha224Hex, and hashChunksHex accept string and Uint8Array inputs to compute correct digests
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- 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 @noble/hashes.sha224 in pkg:npm/%40noble/hashes@2.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40noble/hashes@2.3.0
Demonstrate these symbols/APIs:
- @noble/hashes.sha224
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:4ef3e6f89a0d97e7ed7e3bfdd9bf83bb9cae92441f625def88aa1803464cbb60","contract":["sha224 is exported as a callable function from @noble/hashes/sha2.js","sha224 strictly requires Uint8Array inputs and throws TypeError on string inputs","sha224 produces exact 28-byte digest matching standard NIST test vectors for empty, ASCII, and multi-block byte inputs","sha224 exposes outputLen as 28 bytes and blockLen as 64 bytes","sha224.create supports incremental streaming hash updates via update and digest with Uint8Array inputs","sha224 incremental hash instance supports clone to independently branch hash computation","sha224 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array","sha224 incremental hash instance supports destroy which cleans state and prevents further updates","module wrapper helpers hashSha224, hashSha224Hex, and hashChunksHex accept string and Uint8Array inputs to compute correct digests"],"goal":"verify @noble/hashes.sha224 in pkg:npm/%40noble/hashes@2.3.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@2.3.0"],"schemaVersion":1,"symbols":["@noble/hashes.sha224"]},"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/%40noble/hashes@2.3.0"],"schemaVersion":1,"subject":"pkg:npm/%40noble/hashes@2.3.0","symbols":["@noble/hashes.sha224"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-noble-hashes-sha224",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-noble-hashes-sha224",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@noble/hashes": "2.3.0"
}
},
"node_modules/@noble/hashes": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.3.0.tgz",
"integrity": "sha512-oN+QwyX7VSHotibwubG3kpzbwKrfnyR6OOO+3Nk/53ADL7FmgHHz4TgrbaYKvvOw09u6QTx0oiH1cNCIOuN0CQ==",
"license": "MIT",
"engines": {
"node": ">= 20.19.0"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
}
}
}
{
"name": "sample-noble-hashes-sha224",
"version": "1.0.0",
"private": true,
"type": "module",
"description": "Clean-room code sample for @noble/hashes sha224",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@noble/hashes": "2.3.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify @noble/hashes.sha224 in pkg:npm/%40noble/hashes@2.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40noble/hashes@2.3.0"
],
"symbols": [
"@noble/hashes.sha224"
]
}
import { sha224 } from '@noble/hashes/sha2.js';
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';
/**
* Normalizes input to Uint8Array, encoding strings as UTF-8.
* In @noble/hashes v2, functions strictly require Uint8Array inputs.
* @param {string | Uint8Array} input
* @returns {Uint8Array}
*/
export function toBytes(input) {
if (typeof input === 'string') {
return utf8ToBytes(input);
}
return input;
}
/**
* Computes the SHA-224 hash of a string or Uint8Array and returns the raw 28-byte Uint8Array digest.
* @param {string | Uint8Array} input
* @returns {Uint8Array}
*/
export function hashSha224(input) {
return sha224(toBytes(input));
}
/**
* Computes the SHA-224 hash of a string or Uint8Array and returns a lowercase hex string.
* @param {string | Uint8Array} input
* @returns {string}
*/
export function hashSha224Hex(input) {
return bytesToHex(sha224(toBytes(input)));
}
/**
* Creates an incremental SHA-224 hasher.
* @returns {ReturnType<typeof sha224.create>}
*/
export function createSha224Hasher() {
return sha224.create();
}
/**
* Computes SHA-224 hash over an array of sequential chunks.
* @param {Array<string | Uint8Array>} chunks
* @returns {string}
*/
export function hashChunksHex(chunks) {
const hasher = sha224.create();
for (const chunk of chunks) {
hasher.update(toBytes(chunk));
}
return bytesToHex(hasher.digest());
}
export { sha224, bytesToHex, utf8ToBytes };
import assert from 'node:assert/strict';
import { sha224 as directSha224 } from '@noble/hashes/sha2.js';
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';
import {
sha224,
toBytes,
hashSha224,
hashSha224Hex,
createSha224Hasher,
hashChunksHex,
} from '../src/index.js';
// 1. sha224 is exported as a callable function from @noble/hashes/sha2.js
assert.equal(typeof directSha224, 'function', 'sha224 must be a function');
assert.equal(typeof sha224, 'function', 're-exported sha224 must be a function');
// 2. sha224 strictly requires Uint8Array inputs and throws TypeError on string inputs
{
assert.throws(
() => directSha224('string-input'),
{
name: 'TypeError',
message: /expected Uint8Array/,
},
'sha224 must throw TypeError when given a string'
);
assert.throws(
() => {
const hasher = directSha224.create();
hasher.update('string-input');
},
{
name: 'TypeError',
message: /expected Uint8Array/,
},
'hasher.update must throw TypeError when given a string'
);
}
// 3. sha224 produces exact 28-byte digest matching standard NIST test vectors for empty, ASCII, and multi-block byte inputs
{
const emptyBytes = new Uint8Array(0);
const emptyDigest = directSha224(emptyBytes);
assert.equal(emptyDigest.length, 28, 'Empty input digest length must be 28 bytes');
assert.equal(
bytesToHex(emptyDigest),
'd14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f',
'Empty input digest must match NIST vector'
);
const abcBytes = utf8ToBytes('abc');
const abcDigest = directSha224(abcBytes);
assert.equal(abcDigest.length, 28, 'abc digest length must be 28 bytes');
assert.equal(
bytesToHex(abcDigest),
'23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7',
'abc digest must match NIST vector'
);
const multiBlockMsg = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq';
const multiBlockDigest = directSha224(utf8ToBytes(multiBlockMsg));
assert.equal(multiBlockDigest.length, 28, 'multi-block digest length must be 28 bytes');
assert.equal(
bytesToHex(multiBlockDigest),
'75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525',
'multi-block digest must match NIST vector'
);
}
// 4. sha224 exposes outputLen as 28 bytes and blockLen as 64 bytes
assert.equal(directSha224.outputLen, 28, 'sha224.outputLen must be 28 bytes');
assert.equal(directSha224.blockLen, 64, 'sha224.blockLen must be 64 bytes');
// 5. sha224.create supports incremental streaming hash updates via update and digest with Uint8Array inputs
{
const hasher = directSha224.create();
hasher.update(utf8ToBytes('abc'));
hasher.update(utf8ToBytes('dbcd'));
hasher.update(utf8ToBytes('ecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'));
const digestHex = bytesToHex(hasher.digest());
assert.equal(
digestHex,
'75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525',
'Incremental sha224 stream must match expected multi-block digest'
);
}
// 6. sha224 incremental hash instance supports clone to independently branch hash computation
{
const base = directSha224.create();
base.update(utf8ToBytes('common prefix: '));
const branchA = base.clone();
const branchB = base.clone();
branchA.update(utf8ToBytes('action_alpha'));
branchB.update(utf8ToBytes('action_beta'));
assert.equal(
bytesToHex(branchA.digest()),
bytesToHex(directSha224(utf8ToBytes('common prefix: action_alpha'))),
'Cloned branch A must compute independent digest'
);
assert.equal(
bytesToHex(branchB.digest()),
bytesToHex(directSha224(utf8ToBytes('common prefix: action_beta'))),
'Cloned branch B must compute independent digest'
);
}
// 7. sha224 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array
{
const outBuf = new Uint8Array(28);
const hasher = directSha224.create();
hasher.update(utf8ToBytes('abc'));
hasher.digestInto(outBuf);
assert.equal(
bytesToHex(outBuf),
'23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7',
'digestInto must write digest into target Uint8Array buffer'
);
}
// 8. sha224 incremental hash instance supports destroy which cleans state and prevents further updates
{
const hasher = directSha224.create();
hasher.update(utf8ToBytes('sensitive data'));
hasher.destroy();
assert.throws(
() => hasher.update(utf8ToBytes('more data')),
/destroyed/,
'Calling update after destroy must throw'
);
}
// 9. module wrapper helpers hashSha224, hashSha224Hex, and hashChunksHex accept string and Uint8Array inputs to compute correct digests
{
const rawFromStr = hashSha224('abc');
const rawFromBytes = hashSha224(utf8ToBytes('abc'));
assert(rawFromStr instanceof Uint8Array, 'hashSha224 must return Uint8Array');
assert.equal(rawFromStr.length, 28, 'hashSha224 length must be 28');
assert.equal(bytesToHex(rawFromStr), bytesToHex(rawFromBytes), 'String and byte input must produce identical hash');
assert.equal(
hashSha224Hex('abc'),
'23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7',
'hashSha224Hex must return correct lowercase hex string'
);
const chunksHex = hashChunksHex(['abc', 'dbcd', utf8ToBytes('ecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')]);
assert.equal(
chunksHex,
'75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525',
'hashChunksHex must match expected multi-block digest'
);
}
console.log('All @noble/hashes.sha224 contract assertions passed.');
오리진 시더
익명