CodeSampleX

Exemplo

@noble/hashes 2.3.0: ripemd160

Amostra verificada para npm @noble/hashes 2.3.0: ripemd160. O contrato rodou em node 22 · linux debian/x64 · docker e passou: ripemd160 is exported as a…

sha256:7655875e1442305b6a265d3f81e5e674827f4146fc4e50a58612be259645d14b

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 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

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-07

Caso

HOW
Objetivo
verify @noble/hashes.ripemd160 in pkg:npm/%40noble/hashes@2.3.0
Pacotes
Símbolos
  • @noble/hashes.ripemd160
Ambiente
node 22.23.2
Criado
2026-09-07T02:26:52Z

Contrato

  1. ripemd160 is exported as a callable function from @noble/hashes/legacy.js
  2. ripemd160 strictly requires Uint8Array inputs and throws TypeError on string inputs
  3. ripemd160 produces exact 20-byte digest matching standard test vectors for empty, ASCII, and multi-block byte inputs
  4. ripemd160 exposes outputLen as 20 bytes and blockLen as 64 bytes
  5. ripemd160.create supports incremental streaming hash updates via update and digest with Uint8Array inputs
  6. ripemd160 incremental hash instance supports clone to independently branch hash computation
  7. ripemd160 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array
  8. ripemd160 incremental hash instance supports destroy which cleans state and prevents further updates
  9. module wrapper helpers hashRipemd160, hashRipemd160Hex, and hashChunksHex accept string and Uint8Array inputs to compute correct digests

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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.ripemd160 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.ripemd160

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:214065b574d189f614844c5dbc17070608b2c952d3103b5aa2951672608d1236","contract":["ripemd160 is exported as a callable function from @noble/hashes/legacy.js","ripemd160 strictly requires Uint8Array inputs and throws TypeError on string inputs","ripemd160 produces exact 20-byte digest matching standard test vectors for empty, ASCII, and multi-block byte inputs","ripemd160 exposes outputLen as 20 bytes and blockLen as 64 bytes","ripemd160.create supports incremental streaming hash updates via update and digest with Uint8Array inputs","ripemd160 incremental hash instance supports clone to independently branch hash computation","ripemd160 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array","ripemd160 incremental hash instance supports destroy which cleans state and prevents further updates","module wrapper helpers hashRipemd160, hashRipemd160Hex, and hashChunksHex accept string and Uint8Array inputs to compute correct digests"],"goal":"verify @noble/hashes.ripemd160 in pkg:npm/%40noble/hashes@2.3.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@2.3.0"],"schemaVersion":1,"symbols":["@noble/hashes.ripemd160"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","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@2.3.0"],"schemaVersion":1,"subject":"pkg:npm/%40noble/hashes@2.3.0","symbols":["@noble/hashes.ripemd160"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-noble-hashes-ripemd160",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-noble-hashes-ripemd160",
      "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/"
      }
    }
  }
}
package.json
{
  "name": "sample-noble-hashes-ripemd160",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "description": "Clean-room code sample for @noble/hashes ripemd160",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@noble/hashes": "2.3.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @noble/hashes.ripemd160 in pkg:npm/%40noble/hashes@2.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40noble/hashes@2.3.0"
  ],
  "symbols": [
    "@noble/hashes.ripemd160"
  ]
}
src/index.js
import { ripemd160 } from '@noble/hashes/legacy.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 RIPEMD-160 hash of a string or Uint8Array and returns the raw 20-byte Uint8Array digest.
 * @param {string | Uint8Array} input
 * @returns {Uint8Array}
 */
export function hashRipemd160(input) {
  return ripemd160(toBytes(input));
}

/**
 * Computes the RIPEMD-160 hash of a string or Uint8Array and returns a lowercase hex string.
 * @param {string | Uint8Array} input
 * @returns {string}
 */
export function hashRipemd160Hex(input) {
  return bytesToHex(ripemd160(toBytes(input)));
}

/**
 * Creates an incremental RIPEMD-160 hasher.
 * @returns {ReturnType<typeof ripemd160.create>}
 */
export function createRipemd160Hasher() {
  return ripemd160.create();
}

/**
 * Computes RIPEMD-160 hash over an array of sequential chunks.
 * @param {Array<string | Uint8Array>} chunks
 * @returns {string}
 */
export function hashChunksHex(chunks) {
  const hasher = ripemd160.create();
  for (const chunk of chunks) {
    hasher.update(toBytes(chunk));
  }
  return bytesToHex(hasher.digest());
}

export { ripemd160, bytesToHex, utf8ToBytes };
test/contract.mjs
import assert from 'node:assert/strict';
import { ripemd160 as directRipemd160 } from '@noble/hashes/legacy.js';
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';
import {
  ripemd160,
  toBytes,
  hashRipemd160,
  hashRipemd160Hex,
  createRipemd160Hasher,
  hashChunksHex,
} from '../src/index.js';

// 1. ripemd160 is exported as a callable function from @noble/hashes/legacy.js
assert.equal(typeof directRipemd160, 'function', 'ripemd160 must be a function');
assert.equal(typeof ripemd160, 'function', 're-exported ripemd160 must be a function');

// 2. ripemd160 strictly requires Uint8Array inputs and throws TypeError on string inputs
{
  assert.throws(
    () => directRipemd160('string-input'),
    {
      name: 'TypeError',
      message: /expected Uint8Array/,
    },
    'ripemd160 must throw TypeError when given a string'
  );
  assert.throws(
    () => {
      const hasher = directRipemd160.create();
      hasher.update('string-input');
    },
    {
      name: 'TypeError',
      message: /expected Uint8Array/,
    },
    'hasher.update must throw TypeError when given a string'
  );
}

// 3. ripemd160 produces exact 20-byte digest matching standard test vectors for empty, ASCII, and multi-block byte inputs
{
  const emptyBytes = new Uint8Array(0);
  const emptyDigest = directRipemd160(emptyBytes);
  assert.equal(emptyDigest.length, 20, 'Empty input digest length must be 20 bytes');
  assert.equal(
    bytesToHex(emptyDigest),
    '9c1185a5c5e9fc54612808977ee8f548b2258d31',
    'Empty input digest must match RIPEMD-160 vector'
  );

  const abcBytes = utf8ToBytes('abc');
  const abcDigest = directRipemd160(abcBytes);
  assert.equal(abcDigest.length, 20, 'abc digest length must be 20 bytes');
  assert.equal(
    bytesToHex(abcDigest),
    '8eb208f7e05d987a9b044a8e98c6b087f15a0bfc',
    'abc digest must match RIPEMD-160 vector'
  );

  const multiBlockMsg = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq';
  const multiBlockDigest = directRipemd160(utf8ToBytes(multiBlockMsg));
  assert.equal(multiBlockDigest.length, 20, 'multi-block digest length must be 20 bytes');
  assert.equal(
    bytesToHex(multiBlockDigest),
    '12a053384a9c0c88e405a06c27dcf49ada62eb2b',
    'multi-block digest must match RIPEMD-160 vector'
  );
}

// 4. ripemd160 exposes outputLen as 20 bytes and blockLen as 64 bytes
assert.equal(directRipemd160.outputLen, 20, 'ripemd160.outputLen must be 20 bytes');
assert.equal(directRipemd160.blockLen, 64, 'ripemd160.blockLen must be 64 bytes');

// 5. ripemd160.create supports incremental streaming hash updates via update and digest with Uint8Array inputs
{
  const hasher = directRipemd160.create();
  hasher.update(utf8ToBytes('abc'));
  hasher.update(utf8ToBytes('dbcd'));
  hasher.update(utf8ToBytes('ecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'));
  const digestHex = bytesToHex(hasher.digest());
  assert.equal(
    digestHex,
    '12a053384a9c0c88e405a06c27dcf49ada62eb2b',
    'Incremental ripemd160 stream must match expected multi-block digest'
  );
}

// 6. ripemd160 incremental hash instance supports clone to independently branch hash computation
{
  const base = directRipemd160.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(directRipemd160(utf8ToBytes('common prefix: action_alpha'))),
    'Cloned branch A must compute independent digest'
  );
  assert.equal(
    bytesToHex(branchB.digest()),
    bytesToHex(directRipemd160(utf8ToBytes('common prefix: action_beta'))),
    'Cloned branch B must compute independent digest'
  );
}

// 7. ripemd160 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array
{
  const outBuf = new Uint8Array(20);
  const hasher = directRipemd160.create();
  hasher.update(utf8ToBytes('abc'));
  hasher.digestInto(outBuf);
  assert.equal(
    bytesToHex(outBuf),
    '8eb208f7e05d987a9b044a8e98c6b087f15a0bfc',
    'digestInto must write digest into target Uint8Array buffer'
  );
}

// 8. ripemd160 incremental hash instance supports destroy which cleans state and prevents further updates
{
  const hasher = directRipemd160.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 hashRipemd160, hashRipemd160Hex, and hashChunksHex accept string and Uint8Array inputs to compute correct digests
{
  const rawFromStr = hashRipemd160('abc');
  const rawFromBytes = hashRipemd160(utf8ToBytes('abc'));
  assert(rawFromStr instanceof Uint8Array, 'hashRipemd160 must return Uint8Array');
  assert.equal(rawFromStr.length, 20, 'hashRipemd160 length must be 20');
  assert.equal(bytesToHex(rawFromStr), bytesToHex(rawFromBytes), 'String and byte input must produce identical hash');

  assert.equal(
    hashRipemd160Hex('abc'),
    '8eb208f7e05d987a9b044a8e98c6b087f15a0bfc',
    'hashRipemd160Hex must return correct lowercase hex string'
  );

  const chunksHex = hashChunksHex(['abc', 'dbcd', utf8ToBytes('ecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')]);
  assert.equal(
    chunksHex,
    '12a053384a9c0c88e405a06c27dcf49ada62eb2b',
    'hashChunksHex must match expected multi-block digest'
  );
}

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

Seeder de origem

anônimo