CodeSampleX

샘플

@peculiar/utils 2.0.3

검증된 샘플 — npm @peculiar/utils 2.0.3. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: assert bytes provides stateless byte sequence comparison…

sha256:99946f294654a7ad6be6d3fd27ce89f1d2b2ff3bc9d1e52a3faef46a07f0296a

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-21

케이스

HOW
목표
verify pkg:npm/%40peculiar/utils@2.0.3
패키지
생성일
2026-08-21T07:10:40Z

컨트랙트

  1. assert bytes provides stateless byte sequence comparison, equality check, prefix/suffix inspection, search, and slicing operations
  2. assert hex provides encoding and decoding with preset formats and style-preserving parse and format operations
  3. assert base64, base64url, and utf8 encode and decode binary and text representations bidirectionally
  4. assert pem encodes and decodes labeled PEM containers and searches multiple blocks
  5. assert convert facade supports direct transcoding, format detection, and safe decoding
  6. assert legacy compatibility layer provides Convert and BufferSourceConverter utilities

파일

  • PROMPT.md
  • csx.json
  • 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 pkg:npm/%40peculiar/utils@2.0.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40peculiar/utils@2.0.3

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:baccceaea4951fc96a29dc8d703661ec1e66896233cfeb8f19048ca2e61b96b7","contract":["assert bytes provides stateless byte sequence comparison, equality check, prefix/suffix inspection, search, and slicing operations","assert hex provides encoding and decoding with preset formats and style-preserving parse and format operations","assert base64, base64url, and utf8 encode and decode binary and text representations bidirectionally","assert pem encodes and decodes labeled PEM containers and searches multiple blocks","assert convert facade supports direct transcoding, format detection, and safe decoding","assert legacy compatibility layer provides Convert and BufferSourceConverter utilities"],"goal":"verify pkg:npm/%40peculiar/utils@2.0.3","kind":"HOW","packages":["pkg:npm/%40peculiar/utils@2.0.3"],"schemaVersion":1,"symbols":["BufferSourceConverter.toUint8Array","Convert.FromBase64","Convert.FromHex","Convert.FromString","Convert.ToBase64","Convert.ToHex","Convert.ToString","base64.decode","base64.encode","base64url.decode","base64url.encode","bytes.compare","bytes.concat","bytes.concatToUint8Array","bytes.endsWith","bytes.equal","bytes.indexOf","bytes.lastIndexOf","bytes.startsWith","bytes.tail","convert.detect","convert.transcode","convert.tryDecode","hex.decode","hex.encode","hex.format","hex.parse","isEqual","pem.decode","pem.encode","pem.encodeMany","pem.find","pem.findAll","utf8.decode","utf8.encode"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40peculiar/utils@2.0.3"],"schemaVersion":1,"subject":"pkg:npm/%40peculiar/utils@2.0.3","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-peculiar-utils",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-peculiar-utils",
      "version": "1.0.0",
      "dependencies": {
        "@peculiar/utils": "2.0.3"
      }
    },
    "node_modules/@peculiar/utils": {
      "version": "2.0.3",
      "resolved": "https://registry.npmjs.org/@peculiar/utils/-/utils-2.0.3.tgz",
      "integrity": "sha512-+oL3HPFRIZ1St2K50lWCXiioIgSoxzz7R1J3uF6neO2yl1sgmpgY6XXJH4BdpoDkMWznQTeYF6oWNDZLCdQ4eQ==",
      "license": "MIT",
      "dependencies": {
        "tslib": "^2.8.1"
      }
    },
    "node_modules/tslib": {
      "version": "2.8.1",
      "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
      "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
      "license": "0BSD"
    }
  }
}
package.json
{
  "name": "sample-peculiar-utils",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "@peculiar/utils": "2.0.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40peculiar/utils@2.0.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40peculiar/utils@2.0.3"
  ]
}
test/contract.mjs
import assert from "node:assert/strict";
import {
  bytes,
  hex,
  base64,
  base64url,
  utf8,
  pem,
  convert,
  Convert,
  BufferSourceConverter,
  isEqual,
} from "@peculiar/utils";

// Contract 1: bytes provides stateless byte sequence comparison, equality check, prefix/suffix inspection, search, and slicing operations
const u1 = new Uint8Array([1, 2, 3]);
const u2 = new Uint8Array([1, 2, 3]);
const u3 = new Uint8Array([1, 2, 4]);

assert.equal(bytes.equal(u1, u2), true);
assert.equal(bytes.equal(u1, u3), false);
assert.equal(bytes.compare(u1, u2), 0);
assert.ok(bytes.compare(u1, u3) < 0);

const joinedBuffer = bytes.concat(u1, new Uint8Array([4, 5]));
assert.deepEqual(Array.from(new Uint8Array(joinedBuffer)), [1, 2, 3, 4, 5]);

const joinedTyped = bytes.concatToUint8Array([u1, new Uint8Array([4, 5])]);
assert.deepEqual(Array.from(joinedTyped), [1, 2, 3, 4, 5]);

const textBuf = utf8.encode("Hello, World!");
assert.equal(bytes.indexOf(textBuf, "World", { encoding: "utf8" }), 7);
assert.equal(bytes.lastIndexOf(textBuf, "o", { encoding: "utf8" }), 8);
assert.equal(bytes.startsWith(textBuf, "Hello", { encoding: "utf8" }), true);
assert.equal(bytes.endsWith(textBuf, "World!", { encoding: "utf8" }), true);

const tailed = bytes.tail(textBuf, 6);
assert.equal(utf8.decode(tailed), "World!");

// Contract 2: hex provides encoding and decoding with preset formats and style-preserving parse and format operations
const raw = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);
assert.equal(hex.encode(raw), "deadbeef");
assert.equal(hex.encode(raw, hex.formats.upper), "DEADBEEF");
assert.equal(hex.encode(raw, hex.formats.colonUpper), "DE:AD:BE:EF");
assert.deepEqual(hex.decode("DE:AD:BE:EF"), raw);

const parsedHex = hex.parse("01:02:03:04");
assert.deepEqual(parsedHex.bytes, new Uint8Array([1, 2, 3, 4]));
const formattedHex = hex.format(new Uint8Array([0xaa, 0xbb, 0xcc, 0xdd]), parsedHex.format);
assert.equal(formattedHex, "aa:bb:cc:dd");

// Contract 3: base64, base64url, and utf8 encode and decode binary and text representations bidirectionally
const b64 = base64.encode(raw);
assert.equal(b64, "3q2+7w==");
assert.deepEqual(base64.decode(b64), raw);

const b64url = base64url.encode(raw);
assert.equal(b64url, "3q2-7w");
assert.deepEqual(base64url.decode(b64url), raw);

const sampleText = "Sample Payload 123";
const encodedUtf8 = utf8.encode(sampleText);
assert.equal(utf8.decode(encodedUtf8), sampleText);

// Contract 4: pem encodes and decodes labeled PEM containers and searches multiple blocks
const pemText = pem.encode("CERTIFICATE", raw);
assert.ok(pemText.includes("-----BEGIN CERTIFICATE-----"));
assert.ok(pemText.includes("-----END CERTIFICATE-----"));

const blocks = pem.decode(pemText);
assert.equal(blocks.length, 1);
assert.equal(blocks[0].label, "CERTIFICATE");
assert.deepEqual(blocks[0].data, raw);

const found = pem.find(pemText, "CERTIFICATE");
assert.ok(found);
assert.deepEqual(found.data, raw);

const multiPem = pem.encodeMany([
  { label: "CERTIFICATE", data: raw },
  { label: "PUBLIC KEY", data: new Uint8Array([1, 2, 3]) },
]);
const allCerts = pem.findAll(multiPem, "CERTIFICATE");
assert.equal(allCerts.length, 1);
assert.deepEqual(allCerts[0].data, raw);

// Contract 5: convert facade supports direct transcoding, format detection, and safe decoding
const transcoded = convert.transcode("AQIDBA==", {
  from: "base64",
  to: "hex",
  toOptions: { case: "upper" },
});
assert.equal(transcoded, "01020304");

const tryDecSuccess = convert.tryDecode("hex", "01020304");
assert.equal(tryDecSuccess.ok, true);
assert.deepEqual(tryDecSuccess.bytes, new Uint8Array([1, 2, 3, 4]));

const tryDecFail = convert.tryDecode("hex", "invalid-hex-data");
assert.equal(tryDecFail.ok, false);

const detected = convert.detect(pemText);
assert.ok(detected.some((d) => d.format === "pem"));

// Contract 6: legacy compatibility layer provides Convert and BufferSourceConverter utilities
assert.equal(Convert.ToHex(raw), "deadbeef");
assert.deepEqual(new Uint8Array(Convert.FromHex("deadbeef")), raw);
assert.equal(Convert.ToBase64(raw), "3q2+7w==");
assert.deepEqual(new Uint8Array(Convert.FromBase64("3q2+7w==")), raw);
assert.equal(Convert.ToString(textBuf, "utf8"), "Hello, World!");
assert.deepEqual(new Uint8Array(Convert.FromString("Hello, World!", "utf8")), textBuf);
assert.equal(isEqual(u1, u2), true);
assert.equal(isEqual(u1, u3), false);

const convertedUint8 = BufferSourceConverter.toUint8Array(raw.buffer);
assert.deepEqual(convertedUint8, raw);

console.log("Contract verified: all assertions passed.");

오리진 시더

익명