샘플
@noble/hashes 1.4.0: toBytes
검증된 샘플 — npm @noble/hashes 1.4.0: toBytes. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: assert toBytes converts UTF-8 strings to Uint8Array…
sha256:67a8ed982345740d2158637d023cf67688a7b58f378fb5aaa9a2f57643bc3329
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-06 |
케이스
HOW- 목표
- verify toBytes in pkg:npm/%40noble/hashes@1.4.0
- 심벌
-
- toBytes
- 환경
- node 22.23.2
- 생성일
- 2026-09-06T11:33:08Z
컨트랙트
- assert toBytes converts UTF-8 strings to Uint8Array matching standard TextEncoder encoding
- assert toBytes converts multi-byte Unicode strings to correct UTF-8 byte sequences
- assert toBytes converts empty string to zero-length Uint8Array
- assert toBytes returns existing Uint8Array instances directly without copying reference
- assert toBytes accepts and preserves Uint8Array subclasses including Buffer
- assert toBytes throws an Error when invoked with non-string and non-byte values
파일
- 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 toBytes 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:
- toBytes
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:54f830e6b51500357f19aca704abac169103aa603e943350a6a8d73494d556ca","contract":["assert toBytes converts UTF-8 strings to Uint8Array matching standard TextEncoder encoding","assert toBytes converts multi-byte Unicode strings to correct UTF-8 byte sequences","assert toBytes converts empty string to zero-length Uint8Array","assert toBytes returns existing Uint8Array instances directly without copying reference","assert toBytes accepts and preserves Uint8Array subclasses including Buffer","assert toBytes throws an Error when invoked with non-string and non-byte values"],"goal":"verify toBytes in pkg:npm/%40noble/hashes@1.4.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@1.4.0"],"schemaVersion":1,"symbols":["toBytes"]},"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":["toBytes"],"verifierAdapter":"node-typescript@1"}
const { toBytes } = require('@noble/hashes/utils');
/**
* Normalizes input to Uint8Array.
* - Converts UTF-8 string input to a Uint8Array byte sequence.
* - Passes existing Uint8Array input through without copying the instance.
* - Throws an Error if input is neither a string nor a Uint8Array.
*
* @param {string | Uint8Array} data
* @returns {Uint8Array}
*/
function normalizeToBytes(data) {
return toBytes(data);
}
/**
* Normalizes input to Uint8Array and returns the byte length.
*
* @param {string | Uint8Array} data
* @returns {number}
*/
function byteLength(data) {
return toBytes(data).length;
}
module.exports = {
toBytes,
normalizeToBytes,
byteLength,
};
{
"name": "sample-noble-hashes-tobytes",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-noble-hashes-tobytes",
"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-tobytes",
"version": "1.0.0",
"private": true,
"description": "verify toBytes 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 toBytes in pkg:npm/%40noble/hashes@1.4.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40noble/hashes@1.4.0"
],
"symbols": [
"toBytes"
]
}
import assert from 'node:assert';
import { toBytes } from '@noble/hashes/utils';
import { normalizeToBytes, byteLength } from '../index.js';
// 1. toBytes converts UTF-8 strings to Uint8Array matching standard TextEncoder encoding
const asciiText = 'hello world';
const expectedAsciiBytes = new TextEncoder().encode(asciiText);
const convertedAscii = toBytes(asciiText);
assert.ok(convertedAscii instanceof Uint8Array, 'toBytes must return a Uint8Array instance');
assert.deepStrictEqual(convertedAscii, expectedAsciiBytes, 'ASCII string must match TextEncoder bytes');
// 2. toBytes converts multi-byte Unicode strings to correct UTF-8 byte sequences
const unicodeText = 'cryptography 🔐 검증';
const expectedUnicodeBytes = new TextEncoder().encode(unicodeText);
const convertedUnicode = toBytes(unicodeText);
assert.deepStrictEqual(convertedUnicode, expectedUnicodeBytes, 'Unicode string must match TextEncoder UTF-8 bytes');
// 3. toBytes converts empty string to zero-length Uint8Array
const emptyBytes = toBytes('');
assert.ok(emptyBytes instanceof Uint8Array, 'Empty string must return a Uint8Array instance');
assert.strictEqual(emptyBytes.length, 0, 'Empty string must return a Uint8Array of length 0');
// 4. toBytes returns existing Uint8Array instances directly without copying reference
const existingBytes = new Uint8Array([10, 20, 30, 40, 50]);
const returnedBytes = toBytes(existingBytes);
assert.strictEqual(returnedBytes, existingBytes, 'Existing Uint8Array must be returned by reference without copy');
// 5. toBytes accepts and preserves Uint8Array subclasses including Buffer
const bufferData = Buffer.from([1, 2, 3, 4]);
const returnedBuffer = toBytes(bufferData);
assert.strictEqual(returnedBuffer, bufferData, 'Buffer instance must be returned by reference');
// 6. toBytes throws an Error when invoked with non-string and non-byte values
assert.throws(() => toBytes(42), /Uint8Array expected/, 'Number input must throw Uint8Array expected');
assert.throws(() => toBytes(null), /Uint8Array expected/, 'null input must throw Uint8Array expected');
assert.throws(() => toBytes(undefined), /Uint8Array expected/, 'undefined input must throw Uint8Array expected');
assert.throws(() => toBytes([1, 2, 3]), /Uint8Array expected/, 'Array input must throw Uint8Array expected');
assert.throws(() => toBytes({}), /Uint8Array expected/, 'Object input must throw Uint8Array expected');
assert.throws(() => toBytes(false), /Uint8Array expected/, 'Boolean input must throw Uint8Array expected');
// 7. Helper functions from index.js work correctly
assert.deepStrictEqual(normalizeToBytes('sample'), new TextEncoder().encode('sample'));
assert.strictEqual(byteLength('sample'), 6);
assert.strictEqual(byteLength(new Uint8Array(12)), 12);
console.log('All toBytes contract assertions passed.');
오리진 시더
익명