Exemplo
@noble/hashes 2.3.0: shake256
Amostra verificada para npm @noble/hashes 2.3.0: shake256. O contrato rodou em node 22 · linux debian/x64 · docker e passou: shake256 is exported as a…
sha256:0c879df512c4462795ab9add7098b0ed6eb502bb493a93a9833ddb652c5dbf1e
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-10-12 |
Caso
HOW- Objetivo
- verify @noble/hashes.shake256 in pkg:npm/%40noble/hashes@2.3.0
- Pacotes
- Símbolos
-
- @noble/hashes.shake256
- Ambiente
- node 22.23.2
- Criado
- 2026-10-12T04:42:56Z
Contrato
- shake256 is exported as a callable function from @noble/hashes/sha3.js
- shake256 strictly requires Uint8Array inputs and throws TypeError on string inputs
- shake256 default output produces exact 32-byte digest matching standard test vectors for empty, ASCII, and multi-block byte inputs
- shake256 with dkLen option produces exact variable-length output matching NIST test vectors
- shake256 exposes outputLen as 32 bytes, blockLen as 136 bytes, and canXOF as true
- shake256.create supports incremental streaming hash updates via update and digest with Uint8Array inputs
- shake256 incremental hash instance supports xof to squeeze continuous variable-length output
- shake256 incremental hash instance supports clone to independently branch hash computation
- shake256 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array
- shake256 incremental hash instance supports destroy which cleans state and prevents further updates
- module wrapper helpers hashShake256, hashShake256Hex, 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
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.shake256 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.shake256
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:3257642447e8c3903eb37743b8dfe5e08bc1c6a5f512fa944107b1fd3a7912fd","contract":["shake256 is exported as a callable function from @noble/hashes/sha3.js","shake256 strictly requires Uint8Array inputs and throws TypeError on string inputs","shake256 default output produces exact 32-byte digest matching standard test vectors for empty, ASCII, and multi-block byte inputs","shake256 with dkLen option produces exact variable-length output matching NIST test vectors","shake256 exposes outputLen as 32 bytes, blockLen as 136 bytes, and canXOF as true","shake256.create supports incremental streaming hash updates via update and digest with Uint8Array inputs","shake256 incremental hash instance supports xof to squeeze continuous variable-length output","shake256 incremental hash instance supports clone to independently branch hash computation","shake256 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array","shake256 incremental hash instance supports destroy which cleans state and prevents further updates","module wrapper helpers hashShake256, hashShake256Hex, and hashChunksHex accept string and Uint8Array inputs to compute correct digests"],"goal":"verify @noble/hashes.shake256 in pkg:npm/%40noble/hashes@2.3.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@2.3.0"],"schemaVersion":1,"symbols":["@noble/hashes.shake256"]},"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.shake256"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-noble-hashes-shake256",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-noble-hashes-shake256",
"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/"
}
}
}
}
{
"name": "sample-noble-hashes-shake256",
"version": "1.0.0",
"private": true,
"type": "module",
"description": "Clean-room code sample for @noble/hashes shake256",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@noble/hashes": "2.3.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify @noble/hashes.shake256 in pkg:npm/%40noble/hashes@2.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40noble/hashes@2.3.0"
],
"symbols": [
"@noble/hashes.shake256"
]
}
import { shake256 } from '@noble/hashes/sha3.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 SHAKE256 hash of a string or Uint8Array and returns the raw Uint8Array digest.
* @param {string | Uint8Array} input
* @param {{ dkLen?: number }} [opts]
* @returns {Uint8Array}
*/
export function hashShake256(input, opts) {
return shake256(toBytes(input), opts);
}
/**
* Computes the SHAKE256 hash of a string or Uint8Array and returns a lowercase hex string.
* @param {string | Uint8Array} input
* @param {{ dkLen?: number }} [opts]
* @returns {string}
*/
export function hashShake256Hex(input, opts) {
return bytesToHex(hashShake256(input, opts));
}
/**
* Creates an incremental SHAKE256 hasher instance.
* @param {{ dkLen?: number }} [opts]
* @returns {ReturnType<typeof shake256.create>}
*/
export function createShake256Hasher(opts) {
return shake256.create(opts);
}
/**
* Computes SHAKE256 hash over an array of sequential chunks.
* @param {Array<string | Uint8Array>} chunks
* @param {{ dkLen?: number }} [opts]
* @returns {string}
*/
export function hashChunksHex(chunks, opts) {
const hasher = shake256.create(opts);
for (const chunk of chunks) {
hasher.update(toBytes(chunk));
}
return bytesToHex(hasher.digest());
}
export { shake256, bytesToHex, utf8ToBytes };
import assert from 'node:assert/strict';
import { shake256 as directShake256 } from '@noble/hashes/sha3.js';
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';
import {
shake256,
toBytes,
hashShake256,
hashShake256Hex,
createShake256Hasher,
hashChunksHex,
} from '../src/index.js';
// 1. shake256 is exported as a callable function from @noble/hashes/sha3.js
assert.equal(typeof directShake256, 'function', 'shake256 must be a function');
assert.equal(typeof shake256, 'function', 're-exported shake256 must be a function');
// 2. shake256 strictly requires Uint8Array inputs and throws TypeError on string inputs
{
assert.throws(
() => directShake256('string-input'),
{
name: 'TypeError',
message: /expected Uint8Array/,
},
'shake256 must throw TypeError when given a string'
);
assert.throws(
() => {
const hasher = directShake256.create();
hasher.update('string-input');
},
{
name: 'TypeError',
message: /expected Uint8Array/,
},
'hasher.update must throw TypeError when given a string'
);
}
// 3. shake256 default output produces exact 32-byte digest matching standard test vectors for empty, ASCII, and multi-block byte inputs
{
const emptyBytes = new Uint8Array(0);
const emptyDigest = directShake256(emptyBytes);
assert.equal(emptyDigest.length, 32, 'Empty input digest length must be 32 bytes');
assert.equal(
bytesToHex(emptyDigest),
'46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f',
'Empty input digest must match SHAKE256 vector'
);
const abcBytes = utf8ToBytes('abc');
const abcDigest = directShake256(abcBytes);
assert.equal(abcDigest.length, 32, 'abc digest length must be 32 bytes');
assert.equal(
bytesToHex(abcDigest),
'483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739',
'abc digest must match SHAKE256 vector'
);
const foxMsg = 'The quick brown fox jumps over the lazy dog';
const foxDigest = directShake256(utf8ToBytes(foxMsg));
assert.equal(foxDigest.length, 32, 'fox digest length must be 32 bytes');
assert.equal(
bytesToHex(foxDigest),
'2f671343d9b2e1604dc9dcf0753e5fe15c7c64a0d283cbbf722d411a0e36f6ca',
'fox message digest must match SHAKE256 vector'
);
}
// 4. shake256 with dkLen option produces exact variable-length output matching NIST test vectors
{
const empty64 = directShake256(new Uint8Array(0), { dkLen: 64 });
assert.equal(empty64.length, 64, 'Empty input 64-byte digest length must be 64');
assert.equal(
bytesToHex(empty64),
'46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be',
'Empty input 64-byte digest must match SHAKE256 vector'
);
const abc64 = directShake256(utf8ToBytes('abc'), { dkLen: 64 });
assert.equal(abc64.length, 64, 'abc 64-byte digest length must be 64');
assert.equal(
bytesToHex(abc64),
'483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4',
'abc 64-byte digest must match SHAKE256 vector'
);
const fox64 = directShake256(utf8ToBytes('The quick brown fox jumps over the lazy dog'), { dkLen: 64 });
assert.equal(fox64.length, 64, 'fox 64-byte digest length must be 64');
assert.equal(
bytesToHex(fox64),
'2f671343d9b2e1604dc9dcf0753e5fe15c7c64a0d283cbbf722d411a0e36f6ca1d01d1369a23539cd80f7c054b6e5daf9c962cad5b8ed5bd11998b40d5734442',
'fox 64-byte digest must match SHAKE256 vector'
);
assert.deepEqual(abc64.subarray(0, 32), directShake256(utf8ToBytes('abc')));
}
// 5. shake256 exposes outputLen as 32 bytes, blockLen as 136 bytes, and canXOF as true
assert.equal(directShake256.outputLen, 32, 'shake256.outputLen must be 32 bytes');
assert.equal(directShake256.blockLen, 136, 'shake256.blockLen must be 136 bytes');
assert.equal(directShake256.canXOF, true, 'shake256.canXOF must be true');
// 6. shake256.create supports incremental streaming hash updates via update and digest with Uint8Array inputs
{
const hasher = directShake256.create({ dkLen: 64 });
hasher.update(utf8ToBytes('The quick '));
hasher.update(utf8ToBytes('brown fox '));
hasher.update(utf8ToBytes('jumps over the lazy dog'));
const digestHex = bytesToHex(hasher.digest());
assert.equal(
digestHex,
'2f671343d9b2e1604dc9dcf0753e5fe15c7c64a0d283cbbf722d411a0e36f6ca1d01d1369a23539cd80f7c054b6e5daf9c962cad5b8ed5bd11998b40d5734442',
'Incremental shake256 stream must match expected multi-part digest'
);
assert.throws(
() => hasher.digest(),
/already called/,
'Calling digest after completion must throw'
);
}
// 7. shake256 incremental hash instance supports xof to squeeze continuous variable-length output
{
const hasher = directShake256.create();
hasher.update(utf8ToBytes('abc'));
const chunk1 = hasher.xof(32);
const chunk2 = hasher.xof(32);
assert.equal(chunk1.length, 32);
assert.equal(chunk2.length, 32);
assert.equal(
bytesToHex(chunk1) + bytesToHex(chunk2),
'483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4',
'Sequential xof calls must stream continuous XOF output'
);
}
// 8. shake256 incremental hash instance supports clone to independently branch hash computation
{
const base = directShake256.create({ dkLen: 32 });
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(directShake256(utf8ToBytes('common prefix: action_alpha'), { dkLen: 32 })),
'Cloned branch A must compute independent digest'
);
assert.equal(
bytesToHex(branchB.digest()),
bytesToHex(directShake256(utf8ToBytes('common prefix: action_beta'), { dkLen: 32 })),
'Cloned branch B must compute independent digest'
);
}
// 9. shake256 incremental hash instance supports digestInto to write digest into pre-allocated Uint8Array
{
const outBuf = new Uint8Array(32);
const hasher = directShake256.create();
hasher.update(utf8ToBytes('abc'));
hasher.digestInto(outBuf);
assert.equal(
bytesToHex(outBuf),
'483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739',
'digestInto must write digest into target Uint8Array buffer'
);
}
// 10. shake256 incremental hash instance supports destroy which cleans state and prevents further updates
{
const hasher = directShake256.create();
hasher.update(utf8ToBytes('sensitive data'));
hasher.destroy();
assert.throws(
() => hasher.update(utf8ToBytes('more data')),
/destroyed/,
'Calling update after destroy must throw'
);
}
// 11. module wrapper helpers hashShake256, hashShake256Hex, and hashChunksHex accept string and Uint8Array inputs to compute correct digests
{
const rawFromStr = hashShake256('abc');
const rawFromBytes = hashShake256(utf8ToBytes('abc'));
assert(rawFromStr instanceof Uint8Array, 'hashShake256 must return Uint8Array');
assert.equal(rawFromStr.length, 32, 'hashShake256 length must be 32');
assert.equal(bytesToHex(rawFromStr), bytesToHex(rawFromBytes), 'String and byte input must produce identical hash');
assert.equal(
hashShake256Hex('abc', { dkLen: 64 }),
'483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4',
'hashShake256Hex must return correct lowercase hex string'
);
const chunksHex = hashChunksHex(['The quick ', 'brown fox ', utf8ToBytes('jumps over the lazy dog')], { dkLen: 64 });
assert.equal(
chunksHex,
'2f671343d9b2e1604dc9dcf0753e5fe15c7c64a0d283cbbf722d411a0e36f6ca1d01d1369a23539cd80f7c054b6e5daf9c962cad5b8ed5bd11998b40d5734442',
'hashChunksHex must match expected multi-part digest'
);
}
console.log('All @noble/hashes.shake256 contract assertions passed.');
Seeder de origem
anônimo