Exemplo
@noble/hashes 1.4.0: bytesToHex
Amostra verificada para npm @noble/hashes 1.4.0: bytesToHex. O contrato rodou em node 22 · linux debian/x64 · docker e passou.
sha256:e268f60fd2507b6b38425df6e267b040d6b4523327e92ff5bffa679172570a8d
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
linux 24 · ubuntu · glibc 2.39 x64 npm
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify @noble/hashes.bytesToHex in pkg:npm/%40noble/hashes@1.4.0
- Pacotes
- Símbolos
-
- @noble/hashes.bytesToHex
- Criado
- 2026-09-04T11:24:08Z
Contrato
- 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
Arquivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Código-fonte
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.
{"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"}
{
"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/"
}
}
}
}
{
"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"
}
}
{
"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"
]
}
'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
};
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.');
Seeder de origem
anônimo