Ejemplo
json-buffer 3.0.1: serialize and deserialize Buffer objects with JSON using json-buffer
Muestra verificada para npm json-buffer 3.0.1: serialize and deserialize Buffer objects with JSON using json-buffer. El contrato se ejecutó en node 22 …
sha256:441b61e50fa3fc504caaedc3fd2188513fd4fa8dbe4a7ef9794dcc083d866438
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux 24 · ubuntu · glibc 2.39 x64 npm
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- serialize and deserialize Buffer objects with JSON using json-buffer
- Paquetes
- Símbolos
-
- parse
- stringify
- Creado
- 2026-08-28T03:19:07Z
Contrato
- 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
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código fuente
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.
{"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"}
{
"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"
}
}
}
{
"name": "json-buffer-verification",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification for json-buffer",
"dependencies": {
"json-buffer": "3.0.1"
}
}
{
"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"
]
}
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');
Seeder de origen
anónimo