CodeSampleX

샘플

@noble/hashes 1.4.0: bytesToHex

검증된 샘플 — npm @noble/hashes 1.4.0: bytesToHex. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: bytesToHex is exported as a function from…

sha256:e268f60fd2507b6b38425df6e267b040d6b4523327e92ff5bffa679172570a8d

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-04

케이스

HOW
목표
verify @noble/hashes.bytesToHex in pkg:npm/%40noble/hashes@1.4.0
패키지
심벌
  • @noble/hashes.bytesToHex
생성일
2026-09-04T11:24:08Z

컨트랙트

  1. bytesToHex is exported as a function from @noble/hashes/utils
  2. bytesToHex converts an empty Uint8Array to an empty string
  3. bytesToHex converts byte arrays to lowercase hexadecimal strings preserving leading zeros
  4. bytesToHex encodes multi-byte sequences and byte patterns correctly
  5. bytesToHex throws an error when input is not a Uint8Array
  6. bytesToHex output round-trips with hexToBytes

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
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.bytesToHex 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:
  - @noble/hashes.bytesToHex

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.
csx.json
{"case":{"caseId":"case:sha256:12f2447d7f3a6e0370e74508ffbb5f129cbb6ab33292758b499f4cdf7a763625","contract":["bytesToHex is exported as a function from @noble/hashes/utils","bytesToHex converts an empty Uint8Array to an empty string","bytesToHex converts byte arrays to lowercase hexadecimal strings preserving leading zeros","bytesToHex encodes multi-byte sequences and byte patterns correctly","bytesToHex throws an error when input is not a Uint8Array","bytesToHex output round-trips with hexToBytes"],"goal":"verify @noble/hashes.bytesToHex in pkg:npm/%40noble/hashes@1.4.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@1.4.0"],"schemaVersion":1,"symbols":["@noble/hashes.bytesToHex"]},"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@1.4.0"],"schemaVersion":1,"subject":"pkg:npm/%40noble/hashes@1.4.0","symbols":["@noble/hashes.bytesToHex"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-noble-hashes-bytes-to-hex",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-noble-hashes-bytes-to-hex",
      "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/"
      }
    }
  }
}
package.json
{
  "name": "sample-noble-hashes-bytes-to-hex",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for @noble/hashes bytesToHex",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "@noble/hashes": "1.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @noble/hashes.bytesToHex in pkg:npm/%40noble/hashes@1.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40noble/hashes@1.4.0"
  ],
  "symbols": [
    "@noble/hashes.bytesToHex"
  ]
}
src/index.js
'use strict';

const { bytesToHex, hexToBytes } = require('@noble/hashes/utils');

/**
 * Converts a Uint8Array byte sequence to a lowercase hexadecimal string.
 *
 * @param {Uint8Array} bytes - The byte array to convert.
 * @returns {string} Hexadecimal string representation.
 */
function toHex(bytes) {
  return bytesToHex(bytes);
}

/**
 * Converts a hexadecimal string back to a Uint8Array byte sequence.
 *
 * @param {string} hex - The hexadecimal string to convert.
 * @returns {Uint8Array} Byte array representation.
 */
function fromHex(hex) {
  return hexToBytes(hex);
}

module.exports = {
  bytesToHex,
  hexToBytes,
  toHex,
  fromHex
};
test/contract.mjs
import assert from 'node:assert/strict';
import { bytesToHex, hexToBytes, toHex, fromHex } from '../src/index.js';
import * as utils from '@noble/hashes/utils';

// 1. Export verification
assert.equal(typeof utils.bytesToHex, 'function', 'bytesToHex must be exported from @noble/hashes/utils');
assert.equal(typeof bytesToHex, 'function', 'bytesToHex helper must be a function');
assert.equal(typeof toHex, 'function', 'toHex helper must be a function');
assert.equal(typeof fromHex, 'function', 'fromHex helper must be a function');

// 2. Empty byte array conversion
assert.equal(bytesToHex(new Uint8Array([])), '', 'empty Uint8Array must produce empty string');
assert.equal(toHex(new Uint8Array([])), '', 'toHex helper on empty Uint8Array must produce empty string');

// 3. Byte arrays to lowercase hex with leading zero preservation
assert.equal(bytesToHex(new Uint8Array([0])), '00', 'single zero byte must be two hex digits 00');
assert.equal(bytesToHex(new Uint8Array([1])), '01', 'single byte 1 must be 01');
assert.equal(bytesToHex(new Uint8Array([15])), '0f', 'single byte 15 must be 0f');
assert.equal(bytesToHex(new Uint8Array([16])), '10', 'single byte 16 must be 10');
assert.equal(bytesToHex(new Uint8Array([255])), 'ff', 'single byte 255 must be ff');
assert.equal(
  bytesToHex(new Uint8Array([0x00, 0x01, 0x0a, 0x0f, 0x10, 0xff])),
  '00010a0f10ff',
  'byte sequence must format with leading zeros and lowercase hex'
);

// 4. Multi-byte sequences and known vectors
const sample = new Uint8Array([0xca, 0xfe, 0xba, 0xbe, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]);
assert.equal(
  bytesToHex(sample),
  'cafebabe0123456789abcdef',
  'multi-byte array must convert to expected hex string'
);
assert.equal(
  toHex(sample),
  'cafebabe0123456789abcdef',
  'toHex helper must match bytesToHex output'
);

// 5. Non-Uint8Array input rejection
const invalidInputs = [
  'not bytes',
  12345,
  null,
  undefined,
  [0, 1, 2],
  { length: 0 },
  new ArrayBuffer(4)
];

for (const input of invalidInputs) {
  assert.throws(
    () => bytesToHex(input),
    {
      name: 'Error',
      message: 'Uint8Array expected'
    },
    `bytesToHex must reject non-Uint8Array input: ${String(input)}`
  );
}

// 6. Round-trip conversion with hexToBytes
const originalBytes = new Uint8Array([0x00, 0x7f, 0x80, 0xff, 0x12, 0x34]);
const hexStr = bytesToHex(originalBytes);
const decodedBytes = hexToBytes(hexStr);
assert.deepEqual(
  decodedBytes,
  originalBytes,
  'hexToBytes(bytesToHex(b)) must equal b'
);

const roundTripHelper = fromHex(toHex(originalBytes));
assert.deepEqual(
  roundTripHelper,
  originalBytes,
  'fromHex(toHex(b)) must equal b'
);

console.log('All @noble/hashes.bytesToHex contract tests passed.');

오리진 시더

익명