CodeSampleX

Ejemplo

buffer 5.7.1: Buffer

Muestra verificada para npm buffer 5.7.1: Buffer. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: Buffer.from creates Buffer from…

sha256:82a6b293fbe5f339c46db7e941f423b9ea17e4b66f0ffbe3633dfaf90c6271f0

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
verify pkg:npm/buffer@5.7.1
Paquetes
Símbolos
  • Buffer
Creado
2026-08-28T08:08:47Z

Contrato

  1. Buffer.from creates Buffer from string with default utf8 encoding
  2. Buffer.from creates Buffer from string with hex and base64 encodings
  3. Buffer.from creates Buffer from byte array
  4. Buffer.from creates Buffer copy from existing Buffer
  5. Buffer.from creates Buffer from ArrayBuffer with byteOffset and length
  6. Buffer.alloc creates zero-filled buffer of specified size
  7. Buffer.alloc creates filled buffer with custom fill value
  8. Buffer.allocUnsafe creates uninitialized buffer of specified size
  9. Buffer.isBuffer returns true for Buffer instances and false for non-buffers
  10. Buffer.isEncoding returns true for valid encodings and false for invalid encodings
  11. Buffer.concat joins multiple Buffer instances into a single Buffer
  12. Buffer.byteLength returns byte length of strings across different encodings
  13. Buffer.compare orders buffers lexicographically
  14. Buffer instance supports write, toString, toJSON, slice, and binary read/write methods
  15. Buffer.from throws TypeError when value is a number
  16. Buffer.from throws TypeError when encoding is unknown
  17. Buffer.alloc throws RangeError when size is negative
  18. Buffer.alloc throws TypeError when size is not a number
  19. Buffer.concat throws TypeError when list is not an Array

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@5.7.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/buffer@5.7.1
Demonstrate these symbols/APIs:
  - Buffer

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:f3f44a1f94fef86bed3048696a554c8ffe9cbfc5c5e2a3db793015475a8eda25","contract":["Buffer.from creates Buffer from string with default utf8 encoding","Buffer.from creates Buffer from string with hex and base64 encodings","Buffer.from creates Buffer from byte array","Buffer.from creates Buffer copy from existing Buffer","Buffer.from creates Buffer from ArrayBuffer with byteOffset and length","Buffer.alloc creates zero-filled buffer of specified size","Buffer.alloc creates filled buffer with custom fill value","Buffer.allocUnsafe creates uninitialized buffer of specified size","Buffer.isBuffer returns true for Buffer instances and false for non-buffers","Buffer.isEncoding returns true for valid encodings and false for invalid encodings","Buffer.concat joins multiple Buffer instances into a single Buffer","Buffer.byteLength returns byte length of strings across different encodings","Buffer.compare orders buffers lexicographically","Buffer instance supports write, toString, toJSON, slice, and binary read/write methods","Buffer.from throws TypeError when value is a number","Buffer.from throws TypeError when encoding is unknown","Buffer.alloc throws RangeError when size is negative","Buffer.alloc throws TypeError when size is not a number","Buffer.concat throws TypeError when list is not an Array"],"goal":"verify pkg:npm/buffer@5.7.1","kind":"HOW","packages":["pkg:npm/buffer@5.7.1"],"schemaVersion":1,"symbols":["Buffer"]},"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@5.7.1"],"schemaVersion":1,"subject":"pkg:npm/buffer@5.7.1","symbols":["Buffer"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "buffer-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "buffer-verification",
      "version": "1.0.0",
      "dependencies": {
        "buffer": "5.7.1"
      }
    },
    "node_modules/base64-js": {
      "version": "1.5.1",
      "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
      "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
      "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"
    },
    "node_modules/buffer": {
      "version": "5.7.1",
      "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
      "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
      "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",
      "dependencies": {
        "base64-js": "^1.3.1",
        "ieee754": "^1.1.13"
      }
    },
    "node_modules/ieee754": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
      "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
      "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": "BSD-3-Clause"
    }
  }
}
package.json
{
  "name": "buffer-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for buffer",
  "dependencies": {
    "buffer": "5.7.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/buffer@5.7.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/buffer@5.7.1"
  ],
  "symbols": [
    "Buffer"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { Buffer } = require('buffer/');

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

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

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

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

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

// 6. Buffer.alloc creates zero-filled buffer of specified size
const zeroBuf = Buffer.alloc(10);
assert.ok(Buffer.isBuffer(zeroBuf));
assert.strictEqual(zeroBuf.length, 10);
assert.deepStrictEqual(Array.from(zeroBuf), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);

// 7. Buffer.alloc creates filled buffer with custom fill value
const filledBuf = Buffer.alloc(5, 'a');
assert.strictEqual(filledBuf.toString('utf8'), 'aaaaa');

// 8. Buffer.allocUnsafe creates uninitialized buffer of specified size
const unsafeBuf = Buffer.allocUnsafe(8);
assert.ok(Buffer.isBuffer(unsafeBuf));
assert.strictEqual(unsafeBuf.length, 8);

// 9. Buffer.isBuffer returns true for Buffer instances and false for non-buffers
assert.strictEqual(Buffer.isBuffer(Buffer.alloc(4)), true);
assert.strictEqual(Buffer.isBuffer(new Uint8Array(4)), false);
assert.strictEqual(Buffer.isBuffer('string'), false);
assert.strictEqual(Buffer.isBuffer(null), false);

// 10. Buffer.isEncoding returns true for valid encodings and false for invalid encodings
assert.strictEqual(Buffer.isEncoding('utf8'), true);
assert.strictEqual(Buffer.isEncoding('hex'), true);
assert.strictEqual(Buffer.isEncoding('base64'), true);
assert.strictEqual(Buffer.isEncoding('utf-8'), true);
assert.strictEqual(Buffer.isEncoding('invalid-enc'), false);

// 11. Buffer.concat joins multiple Buffer instances into a single Buffer
const c1 = Buffer.from('hello ');
const c2 = Buffer.from('world');
const concatenated = Buffer.concat([c1, c2]);
assert.strictEqual(concatenated.toString('utf8'), 'hello world');
assert.strictEqual(concatenated.length, 11);

// 12. Buffer.byteLength returns byte length of strings across different encodings
assert.strictEqual(Buffer.byteLength('hello', 'utf8'), 5);
assert.strictEqual(Buffer.byteLength('€', 'utf8'), 3);
assert.strictEqual(Buffer.byteLength('68656c6c6f', 'hex'), 5);

// 13. Buffer.compare orders buffers lexicographically
const cmpA = Buffer.from('abc');
const cmpB = Buffer.from('abd');
assert.strictEqual(Buffer.compare(cmpA, cmpB), -1);
assert.strictEqual(Buffer.compare(cmpB, cmpA), 1);
assert.strictEqual(Buffer.compare(cmpA, cmpA), 0);
assert.strictEqual(cmpA.compare(cmpB), -1);

// 14. Buffer instance supports write, toString, toJSON, slice, and binary read/write methods
const instanceBuf = Buffer.alloc(10);
instanceBuf.write('test', 0, 4, 'utf8');
assert.strictEqual(instanceBuf.toString('utf8', 0, 4), 'test');
const jsonRep = instanceBuf.toJSON();
assert.strictEqual(jsonRep.type, 'Buffer');
assert.ok(Array.isArray(jsonRep.data));
const sliced = instanceBuf.slice(0, 4);
assert.strictEqual(sliced.toString('utf8'), 'test');
const numBuf = Buffer.alloc(4);
numBuf.writeUInt16BE(0x1234, 0);
assert.strictEqual(numBuf.readUInt16BE(0), 0x1234);

// 15. Buffer.from throws TypeError when value is a number
assert.throws(
  () => Buffer.from(123),
  {
    name: 'TypeError',
    message: 'The "value" argument must not be of type number. Received type number'
  }
);

// 16. Buffer.from throws TypeError when encoding is unknown
assert.throws(
  () => Buffer.from('abc', 'invalid-encoding'),
  {
    name: 'TypeError',
    message: 'Unknown encoding: invalid-encoding'
  }
);

// 17. Buffer.alloc throws RangeError when size is negative
assert.throws(
  () => Buffer.alloc(-1),
  {
    name: 'RangeError',
    message: 'The value "-1" is invalid for option "size"'
  }
);

// 18. Buffer.alloc throws TypeError when size is not a number
assert.throws(
  () => Buffer.alloc('invalid'),
  {
    name: 'TypeError',
    message: '"size" argument must be of type number'
  }
);

// 19. Buffer.concat throws TypeError when list is not an Array
assert.throws(
  () => Buffer.concat('not-an-array'),
  {
    name: 'TypeError',
    message: '"list" argument must be an Array of Buffers'
  }
);

console.log('Contract passed');

Seeder de origen

anónimo