示例
@noble/hashes 2.3.0: scryptAsync
已验证示例 — npm @noble/hashes 2.3.0: scryptAsync. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: scryptAsync derives a deterministic key from string or…
sha256:6257bf1db885e9114f90bd512063571c82aa2b4bfe59394f6ddd29f27027f5f9
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- verify @noble/hashes.scryptAsync in pkg:npm/%40noble/hashes@2.3.0
- 符号
-
- @noble/hashes.scryptAsync
- 环境
- node 22.23.2
- 创建时间
- 2026-09-07T03:38:35Z
契约
- scryptAsync derives a deterministic key from string or byte password and salt matching RFC 7914 test vectors
- scryptAsync matches synchronous scrypt output for identical cost parameters and custom dkLen
- scryptAsync yields execution and invokes onProgress callback with fractional completion from 0 to 1
- scryptAsync respects asyncTick parameter for scheduler yielding without altering the output
- scryptAsync rejects when maxmem budget is insufficient for temporary memory allocations
- scryptAsync validates work factors and rejects invalid N, r, p, or dkLen parameters
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
源代码
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.scryptAsync 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.scryptAsync
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:5260a137de1c96ba9180e76c1aaf095f0ad305ba5ba7e199001f07aba23a6c2a","contract":["scryptAsync derives a deterministic key from string or byte password and salt matching RFC 7914 test vectors","scryptAsync matches synchronous scrypt output for identical cost parameters and custom dkLen","scryptAsync yields execution and invokes onProgress callback with fractional completion from 0 to 1","scryptAsync respects asyncTick parameter for scheduler yielding without altering the output","scryptAsync rejects when maxmem budget is insufficient for temporary memory allocations","scryptAsync validates work factors and rejects invalid N, r, p, or dkLen parameters"],"goal":"verify @noble/hashes.scryptAsync in pkg:npm/%40noble/hashes@2.3.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@2.3.0"],"schemaVersion":1,"symbols":["@noble/hashes.scryptAsync"]},"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.scryptAsync"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-noble-hashes-scrypt-async",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-noble-hashes-scrypt-async",
"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-scrypt-async",
"version": "1.0.0",
"type": "module",
"description": "verify @noble/hashes.scryptAsync in pkg:npm/%40noble/hashes@2.3.0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@noble/hashes": "2.3.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify @noble/hashes.scryptAsync in pkg:npm/%40noble/hashes@2.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40noble/hashes@2.3.0"
],
"symbols": [
"@noble/hashes.scryptAsync"
]
}
import { scrypt, scryptAsync } from '@noble/hashes/scrypt.js';
import { bytesToHex, hexToBytes, utf8ToBytes } from '@noble/hashes/utils.js';
export { scrypt, scryptAsync, bytesToHex, hexToBytes, utf8ToBytes };
/**
* Derives a key using Scrypt asynchronously.
* @param {string|Uint8Array} password
* @param {string|Uint8Array} salt
* @param {import('@noble/hashes/scrypt.js').ScryptOpts} opts
* @returns {Promise<Uint8Array>}
*/
export async function deriveScryptAsync(password, salt, opts) {
return await scryptAsync(password, salt, opts);
}
/**
* Derives a key with progress tracking using Scrypt asynchronously.
* @param {string|Uint8Array} password
* @param {string|Uint8Array} salt
* @param {import('@noble/hashes/scrypt.js').ScryptOpts} opts
* @param {(progress: number) => void} onProgress
* @returns {Promise<Uint8Array>}
*/
export async function deriveScryptWithProgress(password, salt, opts, onProgress) {
return await scryptAsync(password, salt, { ...opts, onProgress });
}
import assert from 'node:assert';
import {
scrypt,
scryptAsync,
bytesToHex,
utf8ToBytes,
deriveScryptAsync,
deriveScryptWithProgress
} from '../src/index.mjs';
async function testRfcVectorAndInputTypes() {
// RFC 7914 test vector: password='password', salt='salt', N=1024, r=8, p=1, dkLen=32
const expectedHex = '16dbc8906763c7f048977a68f9d305f7710e068ca2cd95dab372125bb3f19608';
const keyFromString = await scryptAsync('password', 'salt', { N: 1024, r: 8, p: 1, dkLen: 32 });
assert.strictEqual(keyFromString.length, 32);
assert.strictEqual(bytesToHex(keyFromString), expectedHex);
const keyFromBytes = await scryptAsync(utf8ToBytes('password'), utf8ToBytes('salt'), {
N: 1024,
r: 8,
p: 1,
dkLen: 32
});
assert.strictEqual(bytesToHex(keyFromBytes), expectedHex);
const keyFromHelper = await deriveScryptAsync('password', 'salt', {
N: 1024,
r: 8,
p: 1,
dkLen: 32
});
assert.strictEqual(bytesToHex(keyFromHelper), expectedHex);
}
async function testSyncEquivalenceAndDkLen() {
const opts = { N: 16, r: 8, p: 1, dkLen: 64 };
const asyncResult = await scryptAsync('passphrase', 'unique-salt', opts);
const syncResult = scrypt('passphrase', 'unique-salt', opts);
assert.strictEqual(asyncResult.length, 64);
assert.strictEqual(syncResult.length, 64);
assert.strictEqual(bytesToHex(asyncResult), bytesToHex(syncResult));
}
async function testProgressCallback() {
const progressUpdates = [];
const onProgress = (p) => {
progressUpdates.push(p);
};
const key = await deriveScryptWithProgress('progress-pass', 'salt', { N: 32, r: 8, p: 1, dkLen: 32 }, onProgress);
assert.strictEqual(key.length, 32);
assert.ok(progressUpdates.length > 0, 'onProgress should be called at least once');
for (let i = 0; i < progressUpdates.length; i++) {
const val = progressUpdates[i];
assert.ok(val >= 0 && val <= 1, `progress value ${val} must be within [0, 1]`);
if (i > 0) {
assert.ok(val >= progressUpdates[i - 1], 'progress values should be monotonically non-decreasing');
}
}
assert.strictEqual(progressUpdates[progressUpdates.length - 1], 1, 'final progress must be 1');
}
async function testAsyncTickYielding() {
const keyDefault = await scryptAsync('tick-test', 'salt', { N: 32, r: 8, p: 1, dkLen: 32 });
const keyCustomTick = await scryptAsync('tick-test', 'salt', { N: 32, r: 8, p: 1, dkLen: 32, asyncTick: 1 });
assert.strictEqual(bytesToHex(keyDefault), bytesToHex(keyCustomTick));
}
async function testMaxmemConstraint() {
await assert.rejects(
async () => {
await scryptAsync('password', 'salt', { N: 1024, r: 8, p: 1, maxmem: 100 });
},
(err) => {
assert.match(err.message, /"maxmem" limit was hit/);
return true;
}
);
}
async function testInvalidParameters() {
// N must be a power of 2
await assert.rejects(
async () => {
await scryptAsync('password', 'salt', { N: 3, r: 8, p: 1 });
},
(err) => {
assert.match(err.message, /"N" expected a power of 2/);
return true;
}
);
// r must be >= 1
await assert.rejects(
async () => {
await scryptAsync('password', 'salt', { N: 16, r: 0, p: 1 });
},
(err) => {
assert.match(err.message, /"r" expected integer >= 1/);
return true;
}
);
// p must be >= 1
await assert.rejects(
async () => {
await scryptAsync('password', 'salt', { N: 16, r: 8, p: 0 });
},
(err) => {
assert.match(err.message, /"p" expected integer/);
return true;
}
);
// dkLen must be >= 1
await assert.rejects(
async () => {
await scryptAsync('password', 'salt', { N: 16, r: 8, p: 1, dkLen: 0 });
},
(err) => {
assert.match(err.message, /"dkLen" expected integer/);
return true;
}
);
// onProgress must be a function if defined
await assert.rejects(
async () => {
await scryptAsync('password', 'salt', { N: 16, r: 8, p: 1, onProgress: 'not-a-function' });
},
(err) => {
assert.match(err.message, /"onProgress" must be a function/);
return true;
}
);
}
async function runAll() {
await testRfcVectorAndInputTypes();
await testSyncEquivalenceAndDkLen();
await testProgressCallback();
await testAsyncTickYielding();
await testMaxmemConstraint();
await testInvalidParameters();
console.log('Contract tests passed successfully.');
}
await runAll();
原始种子者
匿名