CodeSampleX

Sample

buffer-from 1.1.2: bufferFrom

Verified sample for npm buffer-from 1.1.2: bufferFrom. The contract ran on node 22 · linux alpine/x64 · docker and passed: bufferFrom creates Buffer from…

sha256:fe4ea08ad3f6850bcff5e2a6b9dbc13ed00d62d500f2c98d6cad96d16ab5a6c0

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 linux 24 · ubuntu · glibc 2.39 x64 npm

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-26
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-07

Case

HOW
Goal
verify pkg:npm/buffer-from@1.1.2
Packages
Symbols
  • bufferFrom
Created
2026-08-26T09:14:34Z

Contract

  1. bufferFrom creates Buffer from string with default utf-8 encoding
  2. bufferFrom creates Buffer from string with custom encoding like hex and base64
  3. bufferFrom creates Buffer from array of byte values
  4. bufferFrom creates Buffer from existing Buffer making a copy
  5. bufferFrom creates Buffer from ArrayBuffer with offset and length slicing
  6. bufferFrom throws TypeError when value is a number
  7. bufferFrom throws TypeError when encoding is invalid
  8. bufferFrom throws RangeError when ArrayBuffer offset or length is out of bounds

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • 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/buffer-from@1.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/buffer-from@1.1.2
Demonstrate these symbols/APIs:
  - bufferFrom

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:b6013ceeb11829d4e3316de54d4782829f32fe434f115fb36b42507b597f7c0a","contract":["bufferFrom creates Buffer from string with default utf-8 encoding","bufferFrom creates Buffer from string with custom encoding like hex and base64","bufferFrom creates Buffer from array of byte values","bufferFrom creates Buffer from existing Buffer making a copy","bufferFrom creates Buffer from ArrayBuffer with offset and length slicing","bufferFrom throws TypeError when value is a number","bufferFrom throws TypeError when encoding is invalid","bufferFrom throws RangeError when ArrayBuffer offset or length is out of bounds"],"goal":"verify pkg:npm/buffer-from@1.1.2","kind":"HOW","packages":["pkg:npm/buffer-from@1.1.2"],"schemaVersion":1,"symbols":["bufferFrom"]},"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/buffer-from@1.1.2"],"schemaVersion":1,"subject":"pkg:npm/buffer-from@1.1.2","symbols":["bufferFrom"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "buffer-from-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "buffer-from-verification",
      "version": "1.0.0",
      "dependencies": {
        "buffer-from": "1.1.2"
      }
    },
    "node_modules/buffer-from": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
      "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "buffer-from-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for buffer-from",
  "dependencies": {
    "buffer-from": "1.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/buffer-from@1.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/buffer-from@1.1.2"
  ],
  "symbols": [
    "bufferFrom"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import bufferFrom from 'buffer-from';

// 1. bufferFrom creates Buffer from string with default utf-8 encoding
const strBuf = bufferFrom('hello world');
assert.ok(Buffer.isBuffer(strBuf));
assert.strictEqual(strBuf.toString('utf8'), 'hello world');
assert.strictEqual(strBuf.length, 11);

// 2. bufferFrom creates Buffer from string with custom encoding like hex and base64
const hexBuf = bufferFrom('68656c6c6f', 'hex');
assert.strictEqual(hexBuf.toString('utf8'), 'hello');
const b64Buf = bufferFrom('aGVsbG8=', 'base64');
assert.strictEqual(b64Buf.toString('utf8'), 'hello');

// 3. bufferFrom creates Buffer from array of byte values
const arrBuf = bufferFrom([104, 101, 108, 108, 111]);
assert.ok(Buffer.isBuffer(arrBuf));
assert.strictEqual(arrBuf.toString('utf8'), 'hello');
assert.strictEqual(arrBuf.length, 5);

// 4. bufferFrom creates Buffer from existing Buffer making a copy
const original = Buffer.from('copy-test');
const copied = bufferFrom(original);
assert.ok(Buffer.isBuffer(copied));
assert.strictEqual(copied.toString('utf8'), 'copy-test');
original[0] = 0x78; // mutate original to ensure independent copy
assert.strictEqual(copied.toString('utf8'), 'copy-test');

// 5. bufferFrom creates Buffer from ArrayBuffer with offset and length slicing
const ab = new Uint8Array([1, 2, 3, 4, 5, 6]).buffer;
const abBuf = bufferFrom(ab, 2, 3);
assert.ok(Buffer.isBuffer(abBuf));
assert.strictEqual(abBuf.length, 3);
assert.deepStrictEqual(Array.from(abBuf), [3, 4, 5]);

// 6. bufferFrom throws TypeError when value is a number
assert.throws(
  () => bufferFrom(123),
  {
    name: 'TypeError',
    message: '"value" argument must not be a number'
  }
);

// 7. bufferFrom throws TypeError when encoding is invalid
assert.throws(
  () => bufferFrom('test', 'invalid-encoding-xyz'),
  {
    name: 'TypeError',
    message: '"encoding" must be a valid string encoding'
  }
);

// 8. bufferFrom throws RangeError when ArrayBuffer offset or length is out of bounds
assert.throws(
  () => bufferFrom(new ArrayBuffer(8), 10),
  {
    name: 'RangeError',
    message: "'offset' is out of bounds"
  }
);
assert.throws(
  () => bufferFrom(new ArrayBuffer(8), 2, 10),
  {
    name: 'RangeError',
    message: "'length' is out of bounds"
  }
);

console.log('Contract passed');

Origin Seeder

anonymous