CodeSampleX

Sample

@noble/hashes 1.4.0: argon2id

Verified sample for npm @noble/hashes 1.4.0: argon2id. The contract ran on node 22 · linux debian/x64 · docker and passed: assert argon2id produces exact…

sha256:3157b161c9d3c4fb0503c47b0e4c313645a7c79ac17180d72c9b88393732087d

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.argon2id in pkg:npm/%40noble/hashes@1.4.0
Packages
Symbols
  • @noble/hashes.argon2id
Environment
node 22.23.2
Created
2026-09-06T12:17:31Z

Contract

  1. assert argon2id produces exact 32-byte tag matching RFC 9106 test vector
  2. assert argon2id accepts string and Uint8Array inputs interchangeably producing identical digests
  3. assert argon2id supports custom dkLen derived key length
  4. assert argon2id incorporates secret key and personalization parameters
  5. assert argon2id supports version 16 and version 19
  6. assert argon2id onProgress callback reports incremental progress
  7. assert argon2id validates salt length, iteration count, memory allocation, and dkLen bounds
  8. assert module wrapper helpers compute expected key derivations

Files

  • PROMPT.md
  • csx.json
  • index.js
  • 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.argon2id 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.argon2id

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:0b6198a35d44ddad7916bca8a8af8c68c9b9a48a694960a57efa80b49b3e8a5b","contract":["assert argon2id produces exact 32-byte tag matching RFC 9106 test vector","assert argon2id accepts string and Uint8Array inputs interchangeably producing identical digests","assert argon2id supports custom dkLen derived key length","assert argon2id incorporates secret key and personalization parameters","assert argon2id supports version 16 and version 19","assert argon2id onProgress callback reports incremental progress","assert argon2id validates salt length, iteration count, memory allocation, and dkLen bounds","assert module wrapper helpers compute expected key derivations"],"goal":"verify @noble/hashes.argon2id in pkg:npm/%40noble/hashes@1.4.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@1.4.0"],"schemaVersion":1,"symbols":["@noble/hashes.argon2id"]},"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.argon2id"],"verifierAdapter":"node-typescript@1"}
index.js
const { argon2id } = require('@noble/hashes/argon2');
const { bytesToHex, utf8ToBytes, toBytes } = require('@noble/hashes/utils');

/**
 * Derives a key using Argon2id password hashing.
 * @param {string | Uint8Array} password
 * @param {string | Uint8Array} salt
 * @param {import('@noble/hashes/argon2').ArgonOpts} opts
 * @returns {Uint8Array}
 */
function deriveArgon2id(password, salt, opts) {
  return argon2id(password, salt, opts);
}

/**
 * Derives a key using Argon2id and returns a lowercase hex string.
 * @param {string | Uint8Array} password
 * @param {string | Uint8Array} salt
 * @param {import('@noble/hashes/argon2').ArgonOpts} opts
 * @returns {string}
 */
function deriveArgon2idHex(password, salt, opts) {
  return bytesToHex(argon2id(password, salt, opts));
}

module.exports = {
  argon2id,
  deriveArgon2id,
  deriveArgon2idHex,
  bytesToHex,
  utf8ToBytes,
  toBytes,
};
package-lock.json
{
  "name": "sample-noble-hashes-argon2id",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-noble-hashes-argon2id",
      "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/"
      }
    }
  }
}
package.json
{
  "name": "sample-noble-hashes-argon2id",
  "version": "1.0.0",
  "private": true,
  "description": "verify @noble/hashes.argon2id 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"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @noble/hashes.argon2id in pkg:npm/%40noble/hashes@1.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40noble/hashes@1.4.0"
  ],
  "symbols": [
    "@noble/hashes.argon2id"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import { argon2id } from '@noble/hashes/argon2';
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils';
import {
  deriveArgon2id,
  deriveArgon2idHex,
} 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 = argon2id(pwd, salt, {
  t: 3,
  m: 32,
  p: 4,
  key: secret,
  personalization: ad,
  dkLen: 32,
  version: 19,
});
const tagHex = bytesToHex(tag);
assert.strictEqual(
  tagHex,
  '0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659',
  'Argon2id 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 = argon2id('password', 'saltsalt', { t: 2, m: 256, p: 1 });
const hashFromBytes = argon2id(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 = argon2id('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 = argon2id('password', 'saltsalt', { t: 2, m: 256, p: 1 });
const hashWithKey = argon2id('password', 'saltsalt', { t: 2, m: 256, p: 1, key: 'secret-pepper' });
const hashWithPers = argon2id('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 = argon2id('password', 'saltsalt', { t: 2, m: 256, p: 1, version: 16 });
const hashV19 = argon2id('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;
argon2id('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(
  () => argon2id('password', 'short', { t: 2, m: 256, p: 1 }),
  /salt should be at least 8 bytes/,
  'Salt shorter than 8 bytes must throw'
);
assert.throws(
  () => argon2id('password', 'saltsalt', { t: 0, m: 256, p: 1 }),
  /t \(iterations\) should be at least 1/,
  't < 1 must throw'
);
assert.throws(
  () => argon2id('password', 'saltsalt', { t: 2, m: 4, p: 1 }),
  /memory should be at least 8\*p bytes/,
  'Memory < 8*p must throw'
);
assert.throws(
  () => argon2id('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(
  deriveArgon2idHex('password', 'saltsalt', { t: 2, m: 256, p: 1 }),
  bytesToHex(argon2id('password', 'saltsalt', { t: 2, m: 256, p: 1 })),
  'deriveArgon2idHex helper must match direct bytesToHex(argon2id(...))'
);
assert.deepStrictEqual(
  deriveArgon2id('password', 'saltsalt', { t: 2, m: 256, p: 1 }),
  argon2id('password', 'saltsalt', { t: 2, m: 256, p: 1 }),
  'deriveArgon2id helper must match direct argon2id(...)'
);

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

Origin Seeder

anonymous