CodeSampleX

Sample

safe-buffer 5.2.1

Verified sample for npm safe-buffer 5.2.1. The contract ran on node 22 · linux alpine/x64 · docker and passed: Buffer.alloc allocates zero-filled buffer of…

sha256:24681094b1cfd935fd30d14b50dffdb980ecbb408fd291c7b039f45ad39c02d6

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
2
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 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-23
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-08

Case

HOW
Goal
verify pkg:npm/safe-buffer@5.2.1
Packages
Environment
node 22.23.2
Created
2026-08-23T07:02:18Z

Contract

  1. Buffer.alloc allocates zero-filled buffer of requested size or filled with specified value
  2. Buffer.from creates buffer from string with specified encoding
  3. Buffer.from creates buffer from array of byte values
  4. Buffer.from creates buffer copy from existing buffer or arrayBuffer slice
  5. Buffer.allocUnsafe allocates buffer of requested size
  6. Buffer.concat joins multiple buffer instances into a single buffer
  7. Buffer.isBuffer correctly identifies buffer instances and rejects non-buffers
  8. Buffer.byteLength accurately measures string byte lengths for various encodings
  9. SlowBuffer creates un-pooled buffer instance of requested size

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/safe-buffer@5.2.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/safe-buffer@5.2.1
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:0e396fc6c34f1a8bab21063471f04074857bbb097edc0cf5aa2ac2b80c87266c","constraints":{"executionContext":"node"},"contract":["Buffer.alloc allocates zero-filled buffer of requested size or filled with specified value","Buffer.from creates buffer from string with specified encoding","Buffer.from creates buffer from array of byte values","Buffer.from creates buffer copy from existing buffer or arrayBuffer slice","Buffer.allocUnsafe allocates buffer of requested size","Buffer.concat joins multiple buffer instances into a single buffer","Buffer.isBuffer correctly identifies buffer instances and rejects non-buffers","Buffer.byteLength accurately measures string byte lengths for various encodings","SlowBuffer creates un-pooled buffer instance of requested size"],"goal":"verify pkg:npm/safe-buffer@5.2.1","kind":"HOW","packages":["pkg:npm/safe-buffer@5.2.1"],"schemaVersion":1},"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/safe-buffer@5.2.1"],"schemaVersion":1,"subject":"pkg:npm/safe-buffer@5.2.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-safe-buffer",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-safe-buffer",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "safe-buffer": "5.2.1"
      }
    },
    "node_modules/safe-buffer": {
      "version": "5.2.1",
      "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
      "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/feross"
        },
        {
          "type": "patreon",
          "url": "https://www.patreon.com/feross"
        },
        {
          "type": "consulting",
          "url": "https://feross.org/support"
        }
      ],
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-safe-buffer",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for safe-buffer@5.2.1",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "safe-buffer": "5.2.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/safe-buffer@5.2.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/safe-buffer@5.2.1"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { Buffer, SlowBuffer } = require('safe-buffer');

/**
 * Creates a zero-filled or custom-filled Buffer of the specified size.
 *
 * @param {number} size - Number of bytes to allocate.
 * @param {string|Buffer|number} [fill=0] - Value to pre-fill the buffer with.
 * @param {string} [encoding='utf8'] - The encoding if fill is a string.
 * @returns {Buffer} The allocated Buffer instance.
 */
function createAllocatedBuffer(size, fill, encoding) {
  return Buffer.alloc(size, fill, encoding);
}

/**
 * Creates a Buffer from a string, array, ArrayBuffer, or existing Buffer.
 *
 * @param {string|Array|ArrayBuffer|Buffer} value - The input value to copy into a Buffer.
 * @param {string|number} [encodingOrOffset] - Encoding (if string) or offset (if ArrayBuffer).
 * @param {number} [length] - Length (if ArrayBuffer).
 * @returns {Buffer} The newly created Buffer instance.
 */
function createBufferFrom(value, encodingOrOffset, length) {
  return Buffer.from(value, encodingOrOffset, length);
}

/**
 * Creates an uninitialized Buffer of the specified size.
 *
 * @param {number} size - Number of bytes to allocate.
 * @returns {Buffer} The allocated Buffer instance.
 */
function createUnsafeBuffer(size) {
  return Buffer.allocUnsafe(size);
}

/**
 * Concatenates a list of Buffer instances into a single Buffer.
 *
 * @param {Buffer[]} list - Array of Buffer instances to concatenate.
 * @param {number} [totalLength] - Total length of the concatenated Buffer.
 * @returns {Buffer} The concatenated Buffer.
 */
function concatBuffers(list, totalLength) {
  return Buffer.concat(list, totalLength);
}

/**
 * Checks whether an object is a Buffer.
 *
 * @param {*} value - The value to test.
 * @returns {boolean} True if the value is a Buffer, false otherwise.
 */
function checkIsBuffer(value) {
  return Buffer.isBuffer(value);
}

module.exports = {
  Buffer,
  SlowBuffer,
  createAllocatedBuffer,
  createBufferFrom,
  createUnsafeBuffer,
  concatBuffers,
  checkIsBuffer
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  Buffer,
  SlowBuffer,
  createAllocatedBuffer,
  createBufferFrom,
  createUnsafeBuffer,
  concatBuffers,
  checkIsBuffer
} = require('../src/index.js');

async function testAll() {
  // 1. Buffer.alloc allocates zero-filled buffer of requested size or filled with specified value
  const zeroBuf = createAllocatedBuffer(5);
  assert.equal(zeroBuf.length, 5, 'Buffer.alloc length must equal requested size');
  assert.deepEqual(Array.from(zeroBuf), [0, 0, 0, 0, 0], 'Buffer.alloc default fill must be 0');

  const filledBuf = createAllocatedBuffer(4, 0xa5);
  assert.equal(filledBuf.length, 4);
  assert.deepEqual(Array.from(filledBuf), [0xa5, 0xa5, 0xa5, 0xa5], 'Buffer.alloc must fill with specified byte');

  const stringFilledBuf = createAllocatedBuffer(6, 'ab', 'utf8');
  assert.equal(stringFilledBuf.toString('utf8'), 'ababab', 'Buffer.alloc must fill with repeated pattern');

  // 2. Buffer.from creates buffer from string with specified encoding
  const utf8Buf = createBufferFrom('hello world', 'utf8');
  assert.equal(utf8Buf.toString('utf8'), 'hello world');
  assert.equal(utf8Buf.length, 11);

  const hexBuf = createBufferFrom('deadbeef', 'hex');
  assert.equal(hexBuf.length, 4);
  assert.deepEqual(Array.from(hexBuf), [0xde, 0xad, 0xbe, 0xef]);

  const base64Buf = createBufferFrom('aGVsbG8=', 'base64');
  assert.equal(base64Buf.toString('utf8'), 'hello');

  // 3. Buffer.from creates buffer from array of byte values
  const arrayBuf = createBufferFrom([10, 20, 30, 40]);
  assert.equal(arrayBuf.length, 4);
  assert.equal(arrayBuf[0], 10);
  assert.equal(arrayBuf[3], 40);

  // 4. Buffer.from creates buffer copy from existing buffer or arrayBuffer slice
  const sourceBuf = createBufferFrom('original');
  const copyBuf = createBufferFrom(sourceBuf);
  assert.equal(copyBuf.toString(), 'original');
  copyBuf[0] = 0x58; // 'X'
  assert.equal(sourceBuf.toString(), 'original', 'copied buffer modification must not mutate source');

  const ab = new ArrayBuffer(8);
  const u8View = new Uint8Array(ab);
  u8View.set([1, 2, 3, 4, 5, 6, 7, 8]);
  const slicedFromAb = createBufferFrom(ab, 2, 4);
  assert.equal(slicedFromAb.length, 4);
  assert.deepEqual(Array.from(slicedFromAb), [3, 4, 5, 6]);

  // 5. Buffer.allocUnsafe allocates buffer of requested size
  const unsafeBuf = createUnsafeBuffer(16);
  assert.equal(unsafeBuf.length, 16);
  assert.ok(checkIsBuffer(unsafeBuf));

  // 6. Buffer.concat joins multiple buffer instances into a single buffer
  const b1 = createBufferFrom('part1-');
  const b2 = createBufferFrom('part2');
  const merged = concatBuffers([b1, b2]);
  assert.equal(merged.toString('utf8'), 'part1-part2');
  assert.equal(merged.length, 11);

  const truncatedConcat = concatBuffers([b1, b2], 5);
  assert.equal(truncatedConcat.length, 5);
  assert.equal(truncatedConcat.toString('utf8'), 'part1');

  // 7. Buffer.isBuffer correctly identifies buffer instances and rejects non-buffers
  assert.equal(checkIsBuffer(createAllocatedBuffer(1)), true);
  assert.equal(checkIsBuffer(createBufferFrom('abc')), true);
  assert.equal(checkIsBuffer(new Uint8Array(4)), false);
  assert.equal(checkIsBuffer('string'), false);
  assert.equal(checkIsBuffer({}), false);
  assert.equal(checkIsBuffer(null), false);
  assert.equal(checkIsBuffer(undefined), false);

  // 8. Buffer.byteLength accurately measures string byte lengths for various encodings
  assert.equal(Buffer.byteLength('hello', 'utf8'), 5);
  assert.equal(Buffer.byteLength('안녕하세요', 'utf8'), 15);
  assert.equal(Buffer.byteLength('deadbeef', 'hex'), 4);
  assert.equal(Buffer.byteLength('aGVsbG8=', 'base64'), 5);

  // 9. SlowBuffer creates un-pooled buffer instance of requested size
  const slow = new SlowBuffer(8);
  assert.equal(slow.length, 8);
  assert.ok(checkIsBuffer(slow));

  console.log('All safe-buffer contract tests passed successfully.');
}

testAll().catch((err) => {
  console.error('Contract test failure:', err);
  process.exit(1);
});

Origin Seeder

anonymous