CodeSampleX

サンプル

json-buffer 3.0.1: serialize and deserialize Buffer objects with JSON using json-buffer

検証済みサンプル — npm json-buffer 3.0.1: serialize and deserialize Buffer objects with JSON using json-buffer. node 22 · linux alpine/x64 · docker で contract…

sha256:441b61e50fa3fc504caaedc3fd2188513fd4fa8dbe4a7ef9794dcc083d866438

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-28

ケース

HOW
ゴール
serialize and deserialize Buffer objects with JSON using json-buffer
パッケージ
シンボル
  • parse
  • stringify
作成日
2026-08-28T03:19:07Z

コントラクト

  1. stringify encodes Buffer as base64 string prefixed with colon
  2. parse decodes colon base64 prefixed string back to Buffer
  3. stringify and parse round-trip nested objects containing Buffer instances
  4. stringify and parse round-trip arrays containing Buffer instances
  5. stringify escapes strings starting with colon by prepending an extra colon
  6. stringify returns undefined for undefined input and omits undefined object properties
  7. stringify serializes undefined elements in arrays as null
  8. parse throws SyntaxError on invalid JSON input

ファイル

  • 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: serialize and deserialize Buffer objects with JSON using json-buffer
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/json-buffer@3.0.1
Demonstrate these symbols/APIs:
  - parse
  - stringify

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:65bc682cfd3a132b0f0bc5522f7a41c9492fbef768383b77dc5b3b077727c199","contract":["stringify encodes Buffer as base64 string prefixed with colon","parse decodes colon base64 prefixed string back to Buffer","stringify and parse round-trip nested objects containing Buffer instances","stringify and parse round-trip arrays containing Buffer instances","stringify escapes strings starting with colon by prepending an extra colon","stringify returns undefined for undefined input and omits undefined object properties","stringify serializes undefined elements in arrays as null","parse throws SyntaxError on invalid JSON input"],"goal":"serialize and deserialize Buffer objects with JSON using json-buffer","kind":"HOW","packages":["pkg:npm/json-buffer@3.0.1"],"schemaVersion":1,"symbols":["parse","stringify"]},"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/json-buffer@3.0.1"],"schemaVersion":1,"subject":"pkg:npm/json-buffer@3.0.1","symbols":["parse","stringify"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "json-buffer-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "json-buffer-verification",
      "version": "1.0.0",
      "dependencies": {
        "json-buffer": "3.0.1"
      }
    },
    "node_modules/json-buffer": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
      "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "json-buffer-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for json-buffer",
  "dependencies": {
    "json-buffer": "3.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "serialize and deserialize Buffer objects with JSON using json-buffer",
  "kind": "HOW",
  "packages": [
    "pkg:npm/json-buffer@3.0.1"
  ],
  "symbols": [
    "parse",
    "stringify"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import { parse, stringify } from 'json-buffer';

// 1. stringify encodes Buffer as base64 string prefixed with colon
const buf = Buffer.from('hello', 'utf8');
const json = stringify(buf);
assert.strictEqual(json, JSON.stringify(':base64:' + buf.toString('base64')));

// 2. parse decodes colon base64 prefixed string back to Buffer
const parsed = parse(json);
assert.ok(Buffer.isBuffer(parsed));
assert.strictEqual(parsed.toString('utf8'), 'hello');

// 3. stringify and parse round-trip nested objects containing Buffer instances
const obj = { id: 42, buf: Buffer.from([0xde, 0xad, 0xbe, 0xef]), text: 'sample' };
const encoded = stringify(obj);
const decoded = parse(encoded);
assert.strictEqual(decoded.id, 42);
assert.strictEqual(decoded.text, 'sample');
assert.ok(Buffer.isBuffer(decoded.buf));
assert.deepStrictEqual(Array.from(decoded.buf), [0xde, 0xad, 0xbe, 0xef]);

// 4. stringify and parse round-trip arrays containing Buffer instances
const arr = [Buffer.from('first'), 123, Buffer.from('second')];
const encodedArr = stringify(arr);
const decodedArr = parse(encodedArr);
assert.strictEqual(decodedArr.length, 3);
assert.ok(Buffer.isBuffer(decodedArr[0]));
assert.strictEqual(decodedArr[0].toString('utf8'), 'first');
assert.strictEqual(decodedArr[1], 123);
assert.ok(Buffer.isBuffer(decodedArr[2]));
assert.strictEqual(decodedArr[2].toString('utf8'), 'second');

// 5. stringify escapes strings starting with colon by prepending an extra colon
const colonStr = ':my-colon-string';
const encodedStr = stringify(colonStr);
assert.strictEqual(encodedStr, JSON.stringify('::my-colon-string'));
assert.strictEqual(parse(encodedStr), colonStr);

// 6. stringify returns undefined for undefined input and omits undefined object properties
assert.strictEqual(stringify(undefined), undefined);
const objWithUndef = { keep: 1, remove: undefined };
assert.strictEqual(stringify(objWithUndef), '{"keep":1}');

// 7. stringify serializes undefined elements in arrays as null
const arrWithUndef = [1, undefined, 3];
const encUndef = stringify(arrWithUndef);
assert.strictEqual(encUndef, '[1,null,3]');
assert.deepStrictEqual(parse(encUndef), [1, null, 3]);

// 8. parse throws SyntaxError on invalid JSON input
assert.throws(
  () => parse('{ malformed json }'),
  { name: 'SyntaxError' }
);

console.log('Contract passed');

オリジンシーダー

匿名