CodeSampleX

Пример

uuid 8.3.2: v3

Проверенный пример — npm uuid 8.3.2: v3. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: uuid.v3.DNS equals…

sha256:8b159cc7b4683ae7031ffb047e23027c82b9d46479c8fd210c97932b2f4688b8

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. 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-11-26

Кейс

HOW
Цель
verify uuid.v3 in pkg:npm/uuid@8.3.2
Пакеты
Символы
  • uuid.v3
Окружение
node 22.23.2
Создан
2026-11-26T23:52:14Z

Контракт

  1. uuid.v3.DNS equals 6ba7b810-9dad-11d1-80b4-00c04fd430c8 and uuid.v3.URL equals 6ba7b811-9dad-11d1-80b4-00c04fd430c8
  2. uuid.v3 returns deterministic RFC 4122 version-3 UUID strings for DNS and URL namespaces
  3. uuid.v3 accepts both UUID string and 16-byte array namespaces and both UTF-8 string and byte buffer names with identical output
  4. uuid.v3 writes 16 bytes into a caller-supplied Uint8Array at a non-zero offset and returns the same buffer without modifying surrounding bytes
  5. uuid.v3 throws TypeError for an invalid namespace string, wrong-length namespace byte array, or null name

Файлы

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

Скачать артефакт с исходным кодом (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 uuid.v3 in pkg:npm/uuid@8.3.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/uuid@8.3.2
Demonstrate these symbols/APIs:
  - uuid.v3
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:57390678ef4bb048d0969f1d059dad8a268a56d2830a467307fb584c701afe7f","constraints":{"executionContext":"node"},"contract":["uuid.v3.DNS equals 6ba7b810-9dad-11d1-80b4-00c04fd430c8 and uuid.v3.URL equals 6ba7b811-9dad-11d1-80b4-00c04fd430c8","uuid.v3 returns deterministic RFC 4122 version-3 UUID strings for DNS and URL namespaces","uuid.v3 accepts both UUID string and 16-byte array namespaces and both UTF-8 string and byte buffer names with identical output","uuid.v3 writes 16 bytes into a caller-supplied Uint8Array at a non-zero offset and returns the same buffer without modifying surrounding bytes","uuid.v3 throws TypeError for an invalid namespace string, wrong-length namespace byte array, or null name"],"goal":"verify uuid.v3 in pkg:npm/uuid@8.3.2","kind":"HOW","packages":["pkg:npm/uuid@8.3.2"],"schemaVersion":1,"symbols":["uuid.v3"]},"contractCommand":["node","test/contract.js"],"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/uuid@8.3.2"],"schemaVersion":1,"subject":"pkg:npm/uuid@8.3.2","symbols":["uuid.v3"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "uuid-v3-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "uuid-v3-sample",
      "version": "1.0.0",
      "dependencies": {
        "uuid": "8.3.2"
      }
    },
    "node_modules/uuid": {
      "version": "8.3.2",
      "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
      "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
      "deprecated": "uuid@10 and below is no longer supported.  For ESM codebases, update to uuid@latest.  For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).",
      "license": "MIT",
      "bin": {
        "uuid": "dist/bin/uuid"
      }
    }
  }
}
package.json
{
  "name": "uuid-v3-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Minimal CommonJS sample verifying uuid.v3 in uuid@8.3.2",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "uuid": "8.3.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify uuid.v3 in pkg:npm/uuid@8.3.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/uuid@8.3.2"
  ],
  "symbols": [
    "uuid.v3"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const uuid = require('uuid');

function generateDnsUuid(name) {
  return uuid.v3(name, uuid.v3.DNS);
}

function generateUrlUuid(name) {
  return uuid.v3(name, uuid.v3.URL);
}

function generateCustomUuid(name, namespace) {
  return uuid.v3(name, namespace);
}

function generateUuidIntoBuffer(name, namespace, buffer, offset = 0) {
  return uuid.v3(name, namespace, buffer, offset);
}

module.exports = {
  generateDnsUuid,
  generateUrlUuid,
  generateCustomUuid,
  generateUuidIntoBuffer,
};
test/contract.js
'use strict';

const assert = require('assert');
const uuid = require('uuid');
const {
  generateDnsUuid,
  generateUrlUuid,
  generateCustomUuid,
  generateUuidIntoBuffer,
} = require('../src/index.js');

const V3_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;

// 1. Built-in RFC 4122 namespaces on uuid.v3
assert.strictEqual(uuid.v3.DNS, '6ba7b810-9dad-11d1-80b4-00c04fd430c8');
assert.strictEqual(uuid.v3.URL, '6ba7b811-9dad-11d1-80b4-00c04fd430c8');

// 2. Known deterministic MD5 v3 vectors with DNS and URL namespaces
const dnsId = generateDnsUuid('hello.example.com');
assert.strictEqual(dnsId, '9125a8dc-52ee-365b-a5aa-81b0b3681cf6');
assert.match(dnsId, V3_REGEX);
assert.strictEqual(generateDnsUuid('hello.example.com'), dnsId);

const urlId = generateUrlUuid('http://example.com/hello');
assert.strictEqual(urlId, 'c6235813-3ba4-3801-ae84-e0a6ebb7d138');
assert.match(urlId, V3_REGEX);
assert.notStrictEqual(urlId, dnsId);

// 3. Custom namespace as UUID string and as 16-byte array produce identical output
const customNs = '1b671a64-40d5-491e-99b0-da01ff1f3341';
const customNsBytes = uuid.parse(customNs);
const fromStringNs = generateCustomUuid('example-name', customNs);
const fromBytesNs = generateCustomUuid('example-name', customNsBytes);
const fromByteName = generateCustomUuid(Buffer.from('example-name', 'utf8'), customNs);

assert.match(fromStringNs, V3_REGEX);
assert.strictEqual(fromBytesNs, fromStringNs);
assert.strictEqual(fromByteName, fromStringNs);
assert.notStrictEqual(generateCustomUuid('other-name', customNs), fromStringNs);

// 4. Writing into a target buffer at a non-zero offset
const buf = new Uint8Array(20);
buf.fill(0xaa);
const returned = generateUuidIntoBuffer('hello.example.com', uuid.v3.DNS, buf, 2);
assert.strictEqual(returned, buf);
assert.strictEqual(buf[0], 0xaa);
assert.strictEqual(buf[1], 0xaa);
assert.strictEqual(buf[18], 0xaa);
assert.strictEqual(buf[19], 0xaa);
assert.strictEqual(uuid.stringify(buf, 2), dnsId);

// 5. Validation errors for invalid arguments
assert.throws(() => uuid.v3('hello', 'not-a-valid-uuid'), TypeError);
assert.throws(() => uuid.v3('hello', new Uint8Array(8)), TypeError);
assert.throws(() => uuid.v3(null, uuid.v3.DNS), TypeError);

console.log('uuid.v3 contract passed');

Исходный сидер

аноним