CodeSampleX

Ejemplo

buffer-from 1.1.2: bufferFrom

Muestra verificada para npm buffer-from 1.1.2: bufferFrom. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:fe4ea08ad3f6850bcff5e2a6b9dbc13ed00d62d500f2c98d6cad96d16ab5a6c0

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
2
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-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

Caso

HOW
Objetivo
verify pkg:npm/buffer-from@1.1.2
Paquetes
Símbolos
  • bufferFrom
Creado
2026-08-26T09:14:34Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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');

Seeder de origen

anónimo