CodeSampleX

Ejemplo

@noble/hashes 1.4.0

Muestra verificada para npm @noble/hashes 1.4.0. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: assert BLAKE2b computes standard…

sha256:64a6ea730bda36623699d5294d496435f317a208c3b61fa6b5ee69e239fc0608

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-28

Caso

HOW
Objetivo
verify pkg:npm/%40noble/hashes@1.4.0
Paquetes
Entorno
node 22.23.2
Creado
2026-08-28T05:22:44Z

Contrato

  1. assert BLAKE2b computes standard 512-bit digest, custom 256-bit output length, and keyed MAC
  2. assert BLAKE2s computes standard 256-bit digest and keyed MAC
  3. assert BLAKE3 computes standard 256-bit digest and extended 512-bit output
  4. assert RIPEMD-160 computes 160-bit hash digest
  5. assert scrypt key derivation produces deterministic derived key with configured cost parameters
  6. assert Argon2id computes password hash with configured memory and time cost parameters
  7. assert SHAKE-256 computes extendable-output function digest with specified output length

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 pkg:npm/%40noble/hashes@1.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40noble/hashes@1.4.0

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:af01ee1c36b9f163a3e6490d5554f1f962bd86c83cfcee01075e1345e0ccf10c","contract":["assert BLAKE2b computes standard 512-bit digest, custom 256-bit output length, and keyed MAC","assert BLAKE2s computes standard 256-bit digest and keyed MAC","assert BLAKE3 computes standard 256-bit digest and extended 512-bit output","assert RIPEMD-160 computes 160-bit hash digest","assert scrypt key derivation produces deterministic derived key with configured cost parameters","assert Argon2id computes password hash with configured memory and time cost parameters","assert SHAKE-256 computes extendable-output function digest with specified output length"],"goal":"verify pkg:npm/%40noble/hashes@1.4.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@1.4.0"],"schemaVersion":1},"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","verifierAdapter":"node-typescript@1"}
index.js
const { blake2b } = require('@noble/hashes/blake2b');
const { blake2s } = require('@noble/hashes/blake2s');
const { blake3 } = require('@noble/hashes/blake3');
const { ripemd160 } = require('@noble/hashes/ripemd160');
const { scrypt } = require('@noble/hashes/scrypt');
const { argon2id, argon2i, argon2d } = require('@noble/hashes/argon2');
const { shake256, sha3_512 } = require('@noble/hashes/sha3');
const { bytesToHex, hexToBytes, utf8ToBytes } = require('@noble/hashes/utils');

function toBytes(data) {
  if (typeof data === 'string') return utf8ToBytes(data);
  return data;
}

function hashBlake2b(input, options = {}) {
  const bytes = toBytes(input);
  const opts = {};
  if (options.dkLen !== undefined) opts.dkLen = options.dkLen;
  if (options.key !== undefined) opts.key = toBytes(options.key);
  return bytesToHex(blake2b(bytes, opts));
}

function hashBlake2s(input, options = {}) {
  const bytes = toBytes(input);
  const opts = {};
  if (options.dkLen !== undefined) opts.dkLen = options.dkLen;
  if (options.key !== undefined) opts.key = toBytes(options.key);
  return bytesToHex(blake2s(bytes, opts));
}

function hashBlake3(input, options = {}) {
  const bytes = toBytes(input);
  const opts = {};
  if (options.dkLen !== undefined) opts.dkLen = options.dkLen;
  if (options.key !== undefined) opts.key = toBytes(options.key);
  if (options.context !== undefined) opts.context = toBytes(options.context);
  return bytesToHex(blake3(bytes, opts));
}

function hashRipemd160(input) {
  const bytes = toBytes(input);
  return bytesToHex(ripemd160(bytes));
}

function deriveScrypt(password, salt, options = {}) {
  const passBytes = toBytes(password);
  const saltBytes = toBytes(salt);
  const N = options.N || 1024;
  const r = options.r || 8;
  const p = options.p || 1;
  const dkLen = options.dkLen || 32;
  return bytesToHex(scrypt(passBytes, saltBytes, { N, r, p, dkLen }));
}

function hashArgon2id(password, salt, options = {}) {
  const passBytes = toBytes(password);
  const saltBytes = toBytes(salt);
  const t = options.t || 2;
  const m = options.m || 256;
  const p = options.p || 1;
  const dkLen = options.dkLen || 32;
  return bytesToHex(argon2id(passBytes, saltBytes, { t, m, p, dkLen }));
}

function hashShake256(input, options = {}) {
  const bytes = toBytes(input);
  const dkLen = options.dkLen || 32;
  return bytesToHex(shake256(bytes, { dkLen }));
}

module.exports = {
  hashBlake2b,
  hashBlake2s,
  hashBlake3,
  hashRipemd160,
  deriveScrypt,
  hashArgon2id,
  hashShake256,
  blake2b,
  blake2s,
  blake3,
  ripemd160,
  scrypt,
  argon2id,
  argon2i,
  argon2d,
  shake256,
  sha3_512,
  bytesToHex,
  hexToBytes,
  utf8ToBytes,
};
package-lock.json
{
  "name": "sample-noble-hashes-ciphers",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-noble-hashes-ciphers",
      "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-ciphers",
  "version": "1.0.0",
  "description": "Minimal clean-room sample verifying @noble/hashes BLAKE2, BLAKE3, RIPEMD-160, scrypt, Argon2, and SHAKE256 cryptographic functions",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "@noble/hashes": "1.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40noble/hashes@1.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40noble/hashes@1.4.0"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import {
  hashBlake2b,
  hashBlake2s,
  hashBlake3,
  hashRipemd160,
  deriveScrypt,
  hashArgon2id,
  hashShake256,
} from '../index.js';

// 1. BLAKE2b
const b2bHello = hashBlake2b('hello');
assert.strictEqual(
  b2bHello,
  'e4cfa39a3d37be31c59609e807970799caa68a19bfaa15135f165085e01d41a65ba1e1b146aeb6bd0092b49eac214c103ccfa3a365954bbbe52f74a2b3620c94',
  'BLAKE2b-512 digest of hello matches expected value'
);
const b2b32 = hashBlake2b('hello', { dkLen: 32 });
assert.strictEqual(
  b2b32,
  '324dcf027dd4a30a932c441f365a25e86b173defa4b8e58948253471b81b72cf',
  'BLAKE2b with dkLen=32 matches expected 32-byte digest'
);
const b2bKeyed = hashBlake2b('hello', { key: 'key' });
assert.strictEqual(
  b2bKeyed,
  '06e1f610c028164793739c6b8c430763a34d331f1f802bce261b772e82fe2880808c542f15bb4d38dc639d7266e7c75ecadc8ea973d6007fc4aa18a52004c866',
  'BLAKE2b keyed MAC matches expected output'
);

// 2. BLAKE2s
const b2sHello = hashBlake2s('hello');
assert.strictEqual(
  b2sHello,
  '19213bacc58dee6dbde3ceb9a47cbb330b3d86f8cca8997eb00be456f140ca25',
  'BLAKE2s-256 digest of hello matches expected value'
);
const b2sKeyed = hashBlake2s('hello', { key: 'key' });
assert.strictEqual(
  b2sKeyed,
  'f3400892fd799ac07396701cabc0c4aab892dc320645ed106c66b6ae5e681181',
  'BLAKE2s keyed MAC matches expected output'
);

// 3. BLAKE3
const b3Hello = hashBlake3('hello');
assert.strictEqual(
  b3Hello,
  'ea8f163db38682925e4491c5e58d4bb3506ef8c14eb78a86e908c5624a67200f',
  'BLAKE3-256 digest of hello matches expected value'
);
const b3Extended = hashBlake3('hello', { dkLen: 64 });
assert.strictEqual(
  b3Extended,
  'ea8f163db38682925e4491c5e58d4bb3506ef8c14eb78a86e908c5624a67200fe992405f0d785b599a2e3387f6d34d01faccfeb22fb697ef3fd53541241a338c',
  'BLAKE3 with dkLen=64 produces extended 64-byte digest'
);

// 4. RIPEMD-160
const ripemdHello = hashRipemd160('hello');
assert.strictEqual(
  ripemdHello,
  '108f07b8382412612c048d07d13f814118445acd',
  'RIPEMD-160 digest of hello matches expected 160-bit output'
);

// 5. scrypt
const scryptRes = deriveScrypt('password', 'salt', { N: 1024, r: 8, p: 1, dkLen: 32 });
assert.strictEqual(
  scryptRes,
  '16dbc8906763c7f048977a68f9d305f7710e068ca2cd95dab372125bb3f19608',
  'scrypt KDF produces deterministic 32-byte derived key'
);

// 6. Argon2id
const argonRes = hashArgon2id('password', 'somesalt12345678', { t: 2, m: 256, p: 1, dkLen: 32 });
assert.strictEqual(
  argonRes,
  '8110e1165eb0e1114ee37d5ff017573ba0084b8366b4108db44749954b8d9871',
  'Argon2id password hashing produces expected 32-byte hash'
);

// 7. SHAKE-256
const shakeRes = hashShake256('hello', { dkLen: 64 });
assert.strictEqual(
  shakeRes,
  '1234075ae4a1e77316cf2d8000974581a343b9ebbca7e3d1db83394c30f221626f594e4f0de63902349a5ea5781213215813919f92a4d86d127466e3d07e8be3',
  'SHAKE-256 extendable-output function produces expected 64-byte digest'
);

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

Seeder de origen

anónimo