Exemple
@noble/hashes 1.4.0: blake2b
Échantillon vérifié pour npm @noble/hashes 1.4.0: blake2b. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.
sha256:a0004f50e723e56a9a78a675a4a9b2cfba61134619efc015ea159b1c582b1dec
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify @noble/hashes.blake2b in pkg:npm/%40noble/hashes@1.4.0
- Paquets
- Symboles
-
- @noble/hashes.blake2b
- Environnement
- node 22.23.2
- Créé
- 2026-09-06T12:46:17Z
Contrat
- assert blake2b produces exact 64-byte hash matching RFC 7693 standard test vectors for empty and standard inputs
- assert blake2b accepts both UTF-8 string and Uint8Array byte inputs interchangeably
- assert blake2b exposes outputLen as 64 bytes and blockLen as 128 bytes
- assert blake2b supports variable output digest lengths via dkLen option
- assert blake2b supports keyed hashing for MAC generation via key option
- assert blake2b.create supports incremental streaming hash updates via update and digest
- assert blake2b incremental hash instance supports clone to branch hash computation
- assert blake2b incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array
- assert blake2b incremental hash instance supports destroy to clean up internal buffer state
- assert blake2b throws error when dkLen exceeds maximum keyLen limit
Fichiers
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Code source
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.blake2b 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.blake2b
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:449cbc4e05a928cfe9c4ff8462ffa499a33f38930deb9b155a1b39c0f26b0416","contract":["assert blake2b produces exact 64-byte hash matching RFC 7693 standard test vectors for empty and standard inputs","assert blake2b accepts both UTF-8 string and Uint8Array byte inputs interchangeably","assert blake2b exposes outputLen as 64 bytes and blockLen as 128 bytes","assert blake2b supports variable output digest lengths via dkLen option","assert blake2b supports keyed hashing for MAC generation via key option","assert blake2b.create supports incremental streaming hash updates via update and digest","assert blake2b incremental hash instance supports clone to branch hash computation","assert blake2b incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array","assert blake2b incremental hash instance supports destroy to clean up internal buffer state","assert blake2b throws error when dkLen exceeds maximum keyLen limit"],"goal":"verify @noble/hashes.blake2b in pkg:npm/%40noble/hashes@1.4.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@1.4.0"],"schemaVersion":1,"symbols":["@noble/hashes.blake2b"]},"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","symbols":["@noble/hashes.blake2b"],"verifierAdapter":"node-typescript@1"}
const { blake2b } = require('@noble/hashes/blake2b');
const { bytesToHex, utf8ToBytes, toBytes } = require('@noble/hashes/utils');
/**
* Computes BLAKE2b hash of an input.
* @param {string | Uint8Array} input
* @param {object} [opts]
* @returns {Uint8Array}
*/
function hashBlake2b(input, opts) {
return blake2b(input, opts);
}
/**
* Computes BLAKE2b hash and returns lowercase hex string.
* @param {string | Uint8Array} input
* @param {object} [opts]
* @returns {string}
*/
function hashBlake2bHex(input, opts) {
return bytesToHex(blake2b(input, opts));
}
/**
* Creates an incremental BLAKE2b hasher.
* @param {object} [opts]
* @returns {import('@noble/hashes/utils').Hash<any>}
*/
function createBlake2bHasher(opts) {
return blake2b.create(opts);
}
/**
* Computes BLAKE2b over chunks and returns hex digest.
* @param {Array<string | Uint8Array>} chunks
* @param {object} [opts]
* @returns {string}
*/
function hashChunksHex(chunks, opts) {
const hasher = blake2b.create(opts);
for (const chunk of chunks) {
hasher.update(typeof chunk === 'string' ? utf8ToBytes(chunk) : chunk);
}
return bytesToHex(hasher.digest());
}
module.exports = {
blake2b,
hashBlake2b,
hashBlake2bHex,
createBlake2bHasher,
hashChunksHex,
bytesToHex,
utf8ToBytes,
toBytes,
};
{
"name": "sample-noble-hashes-blake2b",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-noble-hashes-blake2b",
"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-blake2b",
"version": "1.0.0",
"private": true,
"description": "verify @noble/hashes.blake2b in pkg:npm/%40noble/hashes@1.4.0",
"main": "index.js",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@noble/hashes": "1.4.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify @noble/hashes.blake2b in pkg:npm/%40noble/hashes@1.4.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40noble/hashes@1.4.0"
],
"symbols": [
"@noble/hashes.blake2b"
]
}
import assert from 'node:assert';
import { blake2b } from '@noble/hashes/blake2b';
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils';
import {
hashBlake2b,
hashBlake2bHex,
createBlake2bHasher,
hashChunksHex,
} from '../index.js';
// 1. One-shot hashing of empty input matches RFC 7693 standard vector
const emptyHashBytes = blake2b('');
const emptyHashHex = bytesToHex(emptyHashBytes);
assert.strictEqual(
emptyHashHex,
'786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce',
'Empty string blake2b must match RFC 7693 standard vector'
);
assert.strictEqual(emptyHashBytes.length, 64, 'Default digest byte length must be 64');
// 2. One-shot hashing with known test vector (string and Uint8Array)
const abcHashHex = bytesToHex(blake2b('abc'));
const abcHashFromBytes = bytesToHex(blake2b(utf8ToBytes('abc')));
assert.strictEqual(
abcHashHex,
'ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923',
'blake2b("abc") must match RFC 7693 test vector'
);
assert.strictEqual(
abcHashHex,
abcHashFromBytes,
'String and Uint8Array byte inputs must produce identical digests'
);
// 3. Algorithm properties: outputLen and blockLen
assert.strictEqual(blake2b.outputLen, 64, 'blake2b.outputLen must be 64 bytes');
assert.strictEqual(blake2b.blockLen, 128, 'blake2b.blockLen must be 128 bytes');
// 4. Variable output digest length (dkLen)
const hash32Bytes = blake2b('abc', { dkLen: 32 });
assert.strictEqual(hash32Bytes.length, 32, 'Digest length with dkLen: 32 must be 32 bytes');
assert.strictEqual(
bytesToHex(hash32Bytes),
'bddd813c634239723171ef3fee98579b94964e3bb1cb3e427262c8c068d52319',
'blake2b("abc", { dkLen: 32 }) must match expected BLAKE2b-256 output'
);
// 5. Keyed hashing for MAC generation
const key = utf8ToBytes('secret-key-for-mac');
const keyedHash = blake2b('authenticated payload', { key });
assert.strictEqual(keyedHash.length, 64, 'Keyed hash output must be 64 bytes');
const unkeyedHash = blake2b('authenticated payload');
assert.notStrictEqual(
bytesToHex(keyedHash),
bytesToHex(unkeyedHash),
'Keyed hash must differ from unkeyed hash'
);
// 6. Incremental streaming updates with blake2b.create()
const streamHasher = blake2b.create({ dkLen: 32 });
streamHasher.update(utf8ToBytes('a'));
streamHasher.update('bc');
const streamDigest = bytesToHex(streamHasher.digest());
assert.strictEqual(
streamDigest,
bytesToHex(hash32Bytes),
'Incremental blake2b.create() stream must match one-shot hash'
);
// 7. Cloning hash state mid-stream to branch computations
const baseHasher = blake2b.create();
baseHasher.update('common prefix: ');
const branchA = baseHasher.clone();
const branchB = baseHasher.clone();
branchA.update('branch_alpha');
branchB.update('branch_beta');
assert.strictEqual(
bytesToHex(branchA.digest()),
bytesToHex(blake2b('common prefix: branch_alpha')),
'Cloned branch A must compute independent digest matching one-shot hash'
);
assert.strictEqual(
bytesToHex(branchB.digest()),
bytesToHex(blake2b('common prefix: branch_beta')),
'Cloned branch B must compute independent digest matching one-shot hash'
);
// 8. digestInto pre-allocated Uint8Array buffer
const outputBuffer = new Uint8Array(64);
const directHasher = blake2b.create();
directHasher.update('abc');
directHasher.digestInto(outputBuffer);
assert.strictEqual(
bytesToHex(outputBuffer),
abcHashHex,
'digestInto must write digest into target buffer'
);
// 9. State cleanup with destroy()
const destroyHasher = blake2b.create();
destroyHasher.update('transient data');
destroyHasher.destroy();
// 10. Error on invalid dkLen
assert.throws(
() => {
blake2b('abc', { dkLen: 65 });
},
/outputLen|keyLen/,
'blake2b must throw when dkLen exceeds maximum limit'
);
// 11. Module wrapper helpers
assert.strictEqual(
hashBlake2bHex('abc'),
abcHashHex,
'hashBlake2bHex helper must match expected hex digest'
);
assert.strictEqual(
hashChunksHex(['a', 'bc'], { dkLen: 32 }),
bytesToHex(hash32Bytes),
'hashChunksHex helper must correctly stream array of chunks'
);
console.log('All blake2b contract assertions passed.');
Seeder d'origine
anonyme