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

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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.");

オリジンシーダー

匿名