CodeSampleX

Sample

@noble/hashes 2.3.0: blake2s

Verified sample for npm @noble/hashes 2.3.0: blake2s. The contract ran on node 22 · linux debian/x64 · docker and passed: blake2s exports function with…

sha256:efdc7ec46cce7ad59b35e504932f9e1b5a5cdb289aff094ddc8cb142d06d263f

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify @noble/hashes.blake2s in pkg:npm/%40noble/hashes@2.3.0
Packages
Symbols
  • @noble/hashes.blake2s
Environment
node 22.23.2
Created
2026-09-06T11:39:06Z

Contract

  1. blake2s exports function with outputLen 32 blockLen 64 and canXOF false
  2. blake2s computes standard 32-byte hash from Uint8Array matching RFC 7693 test vectors
  3. blake2s supports incremental hashing via create update and digest yielding identical output to one-shot
  4. blake2s supports optional key up to 32 bytes for keyed MAC computation
  5. blake2s supports optional dkLen from 1 to 32 bytes for variable-length digest output
  6. blake2s supports optional salt and personalization parameters of up to 8 bytes each
  7. blake2s throws TypeError or Error when input is not Uint8Array or when dkLen or key exceeds limits

Files

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

Download the source artifact (tar.gz)

Source

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

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:e6da84d434eb064b0af01f6678b2d966f721dd7d24d0134e332282d5dac56eff","contract":["blake2s exports function with outputLen 32 blockLen 64 and canXOF false","blake2s computes standard 32-byte hash from Uint8Array matching RFC 7693 test vectors","blake2s supports incremental hashing via create update and digest yielding identical output to one-shot","blake2s supports optional key up to 32 bytes for keyed MAC computation","blake2s supports optional dkLen from 1 to 32 bytes for variable-length digest output","blake2s supports optional salt and personalization parameters of up to 8 bytes each","blake2s throws TypeError or Error when input is not Uint8Array or when dkLen or key exceeds limits"],"goal":"verify @noble/hashes.blake2s in pkg:npm/%40noble/hashes@2.3.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@2.3.0"],"schemaVersion":1,"symbols":["@noble/hashes.blake2s"]},"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.blake2s"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { blake2s } from '@noble/hashes/blake2.js';

/**
 * Computes a BLAKE2s hash of the given data.
 *
 * @param {Uint8Array} data
 * @param {object} [opts]
 * @returns {Uint8Array}
 */
export function hashBlake2s(data, opts) {
  return blake2s(data, opts);
}

/**
 * Creates an incremental BLAKE2s hasher instance.
 *
 * @param {object} [opts]
 * @returns {object}
 */
export function createBlake2s(opts) {
  return blake2s.create(opts);
}

export { blake2s };
export default blake2s;
package-lock.json
{
  "name": "sample-noble-hashes-blake2s",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-noble-hashes-blake2s",
      "version": "1.0.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-blake2s",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "@noble/hashes": "2.3.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @noble/hashes.blake2s in pkg:npm/%40noble/hashes@2.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40noble/hashes@2.3.0"
  ],
  "symbols": [
    "@noble/hashes.blake2s"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { blake2s, hashBlake2s, createBlake2s } from '../index.mjs';

function toHex(bytes) {
  return Buffer.from(bytes).toString('hex');
}

// 1. blake2s exports function with outputLen 32 blockLen 64 and canXOF false
{
  assert.strictEqual(typeof blake2s, 'function', 'blake2s should be a function');
  assert.strictEqual(blake2s.outputLen, 32, 'outputLen should be 32');
  assert.strictEqual(blake2s.blockLen, 64, 'blockLen should be 64');
  assert.strictEqual(blake2s.canXOF, false, 'canXOF should be false');
  assert.strictEqual(typeof blake2s.create, 'function', 'blake2s.create should be a function');
}

// 2. blake2s computes standard 32-byte hash from Uint8Array matching RFC 7693 test vectors
{
  const emptyHash = blake2s(new Uint8Array(0));
  assert.strictEqual(emptyHash instanceof Uint8Array, true);
  assert.strictEqual(emptyHash.length, 32);
  assert.strictEqual(
    toHex(emptyHash),
    '69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9',
    'empty input hash must match RFC 7693'
  );

  const abc = new Uint8Array([0x61, 0x62, 0x63]);
  const abcHash = hashBlake2s(abc);
  assert.strictEqual(
    toHex(abcHash),
    '508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982',
    'abc hash must match RFC 7693'
  );
}

// 3. blake2s supports incremental hashing via create update and digest yielding identical output to one-shot
{
  const part1 = new Uint8Array([1, 2, 3, 4, 5]);
  const part2 = new Uint8Array([6, 7, 8, 9, 10]);
  const full = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

  const hasher = createBlake2s();
  hasher.update(part1);
  hasher.update(part2);
  const digest = hasher.digest();

  const oneShot = blake2s(full);
  assert.deepStrictEqual(digest, oneShot, 'incremental hash must equal one-shot hash');
}

// 4. blake2s supports optional key up to 32 bytes for keyed MAC computation
{
  const msg = new Uint8Array([10, 20, 30, 40]);
  const key = new Uint8Array(32).fill(0x42);

  const keyed1 = blake2s(msg, { key });
  const unkeyed = blake2s(msg);

  assert.strictEqual(keyed1.length, 32);
  assert.notDeepStrictEqual(keyed1, unkeyed, 'keyed hash must differ from unkeyed hash');

  const keyedHasher = blake2s.create({ key });
  keyedHasher.update(msg);
  assert.deepStrictEqual(keyedHasher.digest(), keyed1, 'incremental keyed hash must match one-shot keyed hash');
}

// 5. blake2s supports optional dkLen from 1 to 32 bytes for variable-length digest output
{
  const msg = new Uint8Array([1, 2, 3]);

  for (const dkLen of [1, 16, 24, 32]) {
    const out = blake2s(msg, { dkLen });
    assert.strictEqual(out.length, dkLen, `digest length must match dkLen ${dkLen}`);
  }

  const custom16 = blake2s(msg, { dkLen: 16 });
  assert.strictEqual(custom16.length, 16);
}

// 6. blake2s supports optional salt and personalization parameters of up to 8 bytes each
{
  const msg = new Uint8Array([1, 2, 3]);
  const salt = new Uint8Array(8).fill(0x01);
  const personalization = new Uint8Array(8).fill(0x02);

  const salted = blake2s(msg, { salt, personalization });
  const plain = blake2s(msg);

  assert.strictEqual(salted.length, 32);
  assert.notDeepStrictEqual(salted, plain, 'salted/personalized hash must differ from default');
}

// 7. blake2s throws TypeError or Error when input is not Uint8Array or when dkLen or key exceeds limits
{
  assert.throws(
    () => blake2s('not uint8array'),
    /expected Uint8Array/i,
    'should throw when input is string'
  );

  assert.throws(
    () => blake2s([1, 2, 3]),
    /expected Uint8Array/i,
    'should throw when input is array'
  );

  assert.throws(
    () => blake2s(new Uint8Array(4), { dkLen: 0 }),
    /"dkLen" must be 1\.\.32/,
    'should throw when dkLen is 0'
  );

  assert.throws(
    () => blake2s(new Uint8Array(4), { dkLen: 33 }),
    /"dkLen" must be 1\.\.32/,
    'should throw when dkLen > 32'
  );

  assert.throws(
    () => blake2s(new Uint8Array(4), { key: new Uint8Array(33) }),
    /"key" expected to be undefined or of length=1\.\.32/,
    'should throw when key > 32 bytes'
  );
}

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

Origin Seeder

anonymous