CodeSampleX

Sample

@keyv/serialize 1.1.1: defaultSerialize, defaultDeserialize

Verified sample for npm @keyv/serialize 1.1.1: defaultSerialize, defaultDeserialize. The contract ran on node 22 · linux debian/x64 · docker and passed.

sha256:d221d9980b86d84ad0ff995d8dc8b16aede3e150c70426f58fa2fd41955a628d

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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-09-14

Case

HOW
Goal
verify pkg:npm/%40keyv/serialize@1.1.1
Packages
Symbols
  • defaultSerialize
  • defaultDeserialize
Environment
node 22.23.2
Created
2026-09-14T03:41:14Z

Contract

  1. defaultSerialize serializes primitives and converts undefined or null to string null
  2. defaultSerialize escapes leading colons in string values
  3. defaultSerialize serializes Buffer instances with base64 prefix
  4. defaultSerialize recursively serializes nested objects and arrays
  5. defaultDeserialize restores buffers from base64 encoded strings and unescapes colon strings
  6. defaultSerialize and defaultDeserialize round-trip complex structures preserving buffers and types

Files

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

Download the source artifact (tar.gz)

Source

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/%40keyv/serialize@1.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40keyv/serialize@1.1.1

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:d8785b709fc4a8083568609b0da124dc2ec812ae4ef155c615542bd21a343e35","constraints":{"executionContext":"node"},"contract":["defaultSerialize serializes primitives and converts undefined or null to string null","defaultSerialize escapes leading colons in string values","defaultSerialize serializes Buffer instances with base64 prefix","defaultSerialize recursively serializes nested objects and arrays","defaultDeserialize restores buffers from base64 encoded strings and unescapes colon strings","defaultSerialize and defaultDeserialize round-trip complex structures preserving buffers and types"],"goal":"verify pkg:npm/%40keyv/serialize@1.1.1","kind":"HOW","packages":["pkg:npm/%40keyv/serialize@1.1.1"],"schemaVersion":1,"symbols":["defaultSerialize","defaultDeserialize"]},"contractCommand":["node","test/contract.mjs"],"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/%40keyv/serialize@1.1.1"],"schemaVersion":1,"subject":"pkg:npm/%40keyv/serialize@1.1.1","symbols":["defaultSerialize","defaultDeserialize"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-keyv-serialize",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-keyv-serialize",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@keyv/serialize": "1.1.1"
      }
    },
    "node_modules/@keyv/serialize": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/@keyv/serialize/-/serialize-1.1.1.tgz",
      "integrity": "sha512-dXn3FZhPv0US+7dtJsIi2R+c7qWYiReoEh5zUntWCf4oSpMNib8FDhSoed6m3QyZdx5hK7iLFkYk3rNxwt8vTA==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-keyv-serialize",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "description": "Clean-room verification for @keyv/serialize",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "@keyv/serialize": "1.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40keyv/serialize@1.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40keyv/serialize@1.1.1"
  ],
  "symbols": [
    "defaultSerialize",
    "defaultDeserialize"
  ]
}
src/index.js
import { defaultSerialize, defaultDeserialize } from '@keyv/serialize';

/**
 * Serializes data into a string using Keyv serialization format.
 *
 * @param {*} data - Value to serialize.
 * @returns {string} Serialized string representation.
 */
export function serialize(data) {
  return defaultSerialize(data);
}

/**
 * Deserializes a string back to its original value or structure.
 *
 * @param {string} data - Serialized JSON string.
 * @returns {*} Deserialized value.
 */
export function deserialize(data) {
  return defaultDeserialize(data);
}

export { defaultSerialize, defaultDeserialize };
test/contract.mjs
import assert from 'node:assert';
import { defaultSerialize, defaultDeserialize } from '@keyv/serialize';
import { serialize, deserialize } from '../src/index.js';

// 1. defaultSerialize serializes primitives and converts undefined or null to string null
assert.strictEqual(defaultSerialize(null), 'null');
assert.strictEqual(defaultSerialize(undefined), 'null');
assert.strictEqual(defaultSerialize(123), '123');
assert.strictEqual(defaultSerialize(true), 'true');
assert.strictEqual(defaultSerialize(false), 'false');
assert.strictEqual(defaultSerialize('simple'), '"simple"');
assert.strictEqual(serialize(null), 'null');

// 2. defaultSerialize escapes leading colons in string values
assert.strictEqual(defaultSerialize(':escaped'), '"::escaped"');
assert.strictEqual(defaultSerialize('::double'), '":::double"');
assert.strictEqual(defaultSerialize('normal:mid'), '"normal:mid"');
assert.strictEqual(serialize(':escaped'), '"::escaped"');

// 3. defaultSerialize serializes Buffer instances with base64 prefix
const buf = Buffer.from('test payload');
const serializedBuf = defaultSerialize(buf);
assert.strictEqual(serializedBuf, `":base64:${buf.toString('base64')}"`);
assert.strictEqual(serialize(buf), `":base64:${buf.toString('base64')}"`);

// 4. defaultSerialize recursively serializes nested objects and arrays
const nestedObj = {
  key: 'value',
  colon: ':start',
  count: 10,
  items: [1, ':inner', Buffer.from('raw')],
  ignoredFn: () => {},
  missingVal: undefined,
};
const serializedObj = serialize(nestedObj);
assert.strictEqual(
  serializedObj,
  `{"key":"value","colon":"::start","count":10,"items":[1,"::inner",":base64:${Buffer.from('raw').toString('base64')}"]}`
);

// 5. defaultDeserialize restores buffers from base64 encoded strings and unescapes colon strings
const originalBuf = Buffer.from('hello buffer');
const base64Encoded = `":base64:${originalBuf.toString('base64')}"`;
const restoredBuf = defaultDeserialize(base64Encoded);
assert.strictEqual(Buffer.isBuffer(restoredBuf), true);
assert.deepStrictEqual(restoredBuf, originalBuf);

const colonStringEncoded = '"::leadingColon"';
const restoredString = deserialize(colonStringEncoded);
assert.strictEqual(restoredString, ':leadingColon');

// 6. defaultSerialize and defaultDeserialize round-trip complex structures preserving buffers and types
const complexData = {
  name: 'test-entity',
  active: true,
  tags: [':tag1', ':tag2', 'normal'],
  payload: Buffer.from('verification data'),
  nested: {
    level: 2,
    subBuffer: Buffer.from('deep')
  }
};
const roundTripped = deserialize(serialize(complexData));
assert.strictEqual(roundTripped.name, complexData.name);
assert.strictEqual(roundTripped.active, true);
assert.deepStrictEqual(roundTripped.tags, complexData.tags);
assert.strictEqual(Buffer.isBuffer(roundTripped.payload), true);
assert.deepStrictEqual(roundTripped.payload, complexData.payload);
assert.strictEqual(roundTripped.nested.level, 2);
assert.strictEqual(Buffer.isBuffer(roundTripped.nested.subBuffer), true);
assert.deepStrictEqual(roundTripped.nested.subBuffer, complexData.nested.subBuffer);

console.log('Contract passed');

Origin Seeder

anonymous