示例
@noble/hashes 1.4.0: argon2i
已验证示例 — npm @noble/hashes 1.4.0: argon2i. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: assert argon2i produces exact 32-byte tag matching RFC 9106…
sha256:1903613ea0f425dfd7d929b0f7cc6a77197ce03a826ac49b737fe67cb1d53653
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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-06 |
案例
HOW- 目标
- verify @noble/hashes.argon2i in pkg:npm/%40noble/hashes@1.4.0
- 符号
-
- @noble/hashes.argon2i
- 环境
- node 22.23.2
- 创建时间
- 2026-09-06T11:52:18Z
契约
- assert argon2i produces exact 32-byte tag matching RFC 9106 test vector
- assert argon2i accepts string and Uint8Array inputs interchangeably producing identical digests
- assert argon2i supports custom dkLen derived key length
- assert argon2i incorporates secret key and personalization parameters
- assert argon2i supports version 16 and version 19
- assert argon2i onProgress callback reports incremental progress
- assert argon2i validates salt length, iteration count, memory allocation, and dkLen bounds
- assert module wrapper helpers compute expected key derivations
文件
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- 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.argon2i 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.argon2i
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:03e36d9afcf4325954518bb0ab73b180d33ca9fd0ee7459778af6eb0458051a2","contract":["assert argon2i produces exact 32-byte tag matching RFC 9106 test vector","assert argon2i accepts string and Uint8Array inputs interchangeably producing identical digests","assert argon2i supports custom dkLen derived key length","assert argon2i incorporates secret key and personalization parameters","assert argon2i supports version 16 and version 19","assert argon2i onProgress callback reports incremental progress","assert argon2i validates salt length, iteration count, memory allocation, and dkLen bounds","assert module wrapper helpers compute expected key derivations"],"goal":"verify @noble/hashes.argon2i in pkg:npm/%40noble/hashes@1.4.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@1.4.0"],"schemaVersion":1,"symbols":["@noble/hashes.argon2i"]},"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.argon2i"],"verifierAdapter":"node-typescript@1"}
const { argon2i } = require('@noble/hashes/argon2');
const { bytesToHex, utf8ToBytes, toBytes } = require('@noble/hashes/utils');
/**
* Derives a key using Argon2i password hashing.
* @param {string | Uint8Array} password
* @param {string | Uint8Array} salt
* @param {import('@noble/hashes/argon2').ArgonOpts} opts
* @returns {Uint8Array}
*/
function deriveArgon2i(password, salt, opts) {
return argon2i(password, salt, opts);
}
/**
* Derives a key using Argon2i and returns a lowercase hex string.
* @param {string | Uint8Array} password
* @param {string | Uint8Array} salt
* @param {import('@noble/hashes/argon2').ArgonOpts} opts
* @returns {string}
*/
function deriveArgon2iHex(password, salt, opts) {
return bytesToHex(argon2i(password, salt, opts));
}
module.exports = {
argon2i,
deriveArgon2i,
deriveArgon2iHex,
bytesToHex,
utf8ToBytes,
toBytes,
};
{
"name": "sample-noble-hashes-argon2i",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-noble-hashes-argon2i",
"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-argon2i",
"version": "1.0.0",
"private": true,
"description": "verify @noble/hashes.argon2i 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.argon2i in pkg:npm/%40noble/hashes@1.4.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40noble/hashes@1.4.0"
],
"symbols": [
"@noble/hashes.argon2i"
]
}
import assert from 'node:assert';
import { argon2i } from '@noble/hashes/argon2';
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils';
import {
deriveArgon2i,
deriveArgon2iHex,
} from '../index.js';
// 1. RFC 9106 standard test vector verification
const pwd = new Uint8Array(32).fill(1);
const salt = new Uint8Array(16).fill(2);
const secret = new Uint8Array(8).fill(3);
const ad = new Uint8Array(12).fill(4);
const tag = argon2i(pwd, salt, {
t: 3,
m: 32,
p: 4,
key: secret,
personalization: ad,
dkLen: 32,
version: 19,
});
const tagHex = bytesToHex(tag);
assert.strictEqual(
tagHex,
'c814d9d1dc7f37aa13f0d77f2494bda1c8de6b016dd388d29952a4c4672b6ce8',
'Argon2i must match official RFC 9106 test vector'
);
assert.strictEqual(tag.length, 32, 'Derived tag length must be 32 bytes');
// 2. String and Uint8Array input equivalence
const hashFromStr = argon2i('password', 'saltsalt', { t: 2, m: 256, p: 1 });
const hashFromBytes = argon2i(utf8ToBytes('password'), utf8ToBytes('saltsalt'), { t: 2, m: 256, p: 1 });
assert.strictEqual(
bytesToHex(hashFromStr),
bytesToHex(hashFromBytes),
'String and Uint8Array utf8 inputs must produce identical digests'
);
assert.strictEqual(hashFromStr.length, 32, 'Default dkLen must be 32 bytes');
// 3. Custom dkLen output length
const hash64 = argon2i('password', 'saltsalt', { t: 2, m: 256, p: 1, dkLen: 64 });
assert.strictEqual(hash64.length, 64, 'Custom dkLen of 64 bytes must produce a 64-byte digest');
// 4. Secret key and personalization differentiation
const hashBase = argon2i('password', 'saltsalt', { t: 2, m: 256, p: 1 });
const hashWithKey = argon2i('password', 'saltsalt', { t: 2, m: 256, p: 1, key: 'secret-pepper' });
const hashWithPers = argon2i('password', 'saltsalt', { t: 2, m: 256, p: 1, personalization: 'app-scope' });
assert.notStrictEqual(
bytesToHex(hashBase),
bytesToHex(hashWithKey),
'Secret key must alter derived output'
);
assert.notStrictEqual(
bytesToHex(hashBase),
bytesToHex(hashWithPers),
'Personalization must alter derived output'
);
// 5. Algorithm versions (0x10 and 0x13)
const hashV16 = argon2i('password', 'saltsalt', { t: 2, m: 256, p: 1, version: 16 });
const hashV19 = argon2i('password', 'saltsalt', { t: 2, m: 256, p: 1, version: 19 });
assert.strictEqual(
bytesToHex(hashBase),
bytesToHex(hashV19),
'Default version must match explicit version 19 (0x13)'
);
assert.notStrictEqual(
bytesToHex(hashV16),
bytesToHex(hashV19),
'Version 16 and Version 19 must produce distinct outputs'
);
// 6. onProgress callback reporting
let progressInvocations = 0;
let lastReportedProgress = 0;
argon2i('password', 'saltsalt', {
t: 2,
m: 256,
p: 1,
onProgress: (p) => {
progressInvocations++;
lastReportedProgress = p;
},
});
assert(progressInvocations > 0, 'onProgress callback must be invoked during computation');
assert(lastReportedProgress > 0.9, 'Final reported progress must be near completion');
// 7. Input validation bounds
assert.throws(
() => argon2i('password', 'short', { t: 2, m: 256, p: 1 }),
/salt should be at least 8 bytes/,
'Salt shorter than 8 bytes must throw'
);
assert.throws(
() => argon2i('password', 'saltsalt', { t: 0, m: 256, p: 1 }),
/t \(iterations\) should be at least 1/,
't < 1 must throw'
);
assert.throws(
() => argon2i('password', 'saltsalt', { t: 2, m: 4, p: 1 }),
/memory should be at least 8\*p bytes/,
'Memory < 8*p must throw'
);
assert.throws(
() => argon2i('password', 'saltsalt', { t: 2, m: 256, p: 1, dkLen: 2 }),
/dkLen should be at least 4 bytes/,
'dkLen < 4 must throw'
);
// 8. Module wrapper helpers
assert.strictEqual(
deriveArgon2iHex('password', 'saltsalt', { t: 2, m: 256, p: 1 }),
bytesToHex(argon2i('password', 'saltsalt', { t: 2, m: 256, p: 1 })),
'deriveArgon2iHex helper must match direct bytesToHex(argon2i(...))'
);
assert.deepStrictEqual(
deriveArgon2i('password', 'saltsalt', { t: 2, m: 256, p: 1 }),
argon2i('password', 'saltsalt', { t: 2, m: 256, p: 1 }),
'deriveArgon2i helper must match direct argon2i(...)'
);
console.log('All @noble/hashes.argon2i contract assertions passed.');
原始种子者
匿名