CodeSampleX

샘플

@noble/hashes 1.4.0: argon2id

검증된 샘플 — npm @noble/hashes 1.4.0: argon2id. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: assert argon2id produces exact 32-byte tag matching…

sha256:3157b161c9d3c4fb0503c47b0e4c313645a7c79ac17180d72c9b88393732087d

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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.argon2id in pkg:npm/%40noble/hashes@1.4.0
패키지
심벌
  • @noble/hashes.argon2id
환경
node 22.23.2
생성일
2026-09-06T12:17:31Z

컨트랙트

  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

파일

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

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.');

오리진 시더

익명