CodeSampleX

Ejemplo

ieee754 1.2.1: write

Muestra verificada para npm ieee754 1.2.1: write. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: write encodes 32-bit floating point…

sha256:b4cb1c5bf65e4101595678372b594a70d4f4d8b5a6dee6494bf72f40c94815f4

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

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-06

Caso

HOW
Objetivo
verify ieee754.write in pkg:npm/ieee754@1.2.1
Paquetes
Símbolos
  • ieee754.write
Entorno
node 22.23.2
Creado
2026-09-06T12:19:59Z

Contrato

  1. write encodes 32-bit floating point numbers in little-endian and big-endian byte order
  2. write encodes 64-bit double-precision floating point numbers matching IEEE 754 representations
  3. write encodes special values including positive zero, negative zero, infinity, and NaN
  4. write writes values into target buffers at arbitrary valid offsets without disturbing adjacent bytes
  5. write operates directly on standard Uint8Array and Node.js Buffer instances

Archivos

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

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 ieee754.write in pkg:npm/ieee754@1.2.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/ieee754@1.2.1
Demonstrate these symbols/APIs:
  - ieee754.write

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:98e1513d4ac0764f782b7011021f853fe3d86e9d682da70b8c7fbf0b4bb3dfdb","contract":["write encodes 32-bit floating point numbers in little-endian and big-endian byte order","write encodes 64-bit double-precision floating point numbers matching IEEE 754 representations","write encodes special values including positive zero, negative zero, infinity, and NaN","write writes values into target buffers at arbitrary valid offsets without disturbing adjacent bytes","write operates directly on standard Uint8Array and Node.js Buffer instances"],"goal":"verify ieee754.write in pkg:npm/ieee754@1.2.1","kind":"HOW","packages":["pkg:npm/ieee754@1.2.1"],"schemaVersion":1,"symbols":["ieee754.write"]},"contractCommand":["node","test/contract.js"],"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/ieee754@1.2.1"],"schemaVersion":1,"subject":"pkg:npm/ieee754@1.2.1","symbols":["ieee754.write"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-ieee754-write",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ieee754-write",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "ieee754": "1.2.1"
      }
    },
    "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": "sample-ieee754-write",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for ieee754.write",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "ieee754": "1.2.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify ieee754.write in pkg:npm/ieee754@1.2.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ieee754@1.2.1"
  ],
  "symbols": [
    "ieee754.write"
  ]
}
src/index.js
const ieee754 = require('ieee754');

/**
 * Writes a 32-bit single-precision floating point number into a buffer.
 * @param {Uint8Array|Buffer} buffer Target buffer
 * @param {number} value Value to write
 * @param {number} [offset=0] Byte offset
 * @param {boolean} [isLE=true] True for little-endian, false for big-endian
 */
function writeFloat32(buffer, value, offset = 0, isLE = true) {
  ieee754.write(buffer, value, offset, isLE, 23, 4);
}

/**
 * Writes a 64-bit double-precision floating point number into a buffer.
 * @param {Uint8Array|Buffer} buffer Target buffer
 * @param {number} value Value to write
 * @param {number} [offset=0] Byte offset
 * @param {boolean} [isLE=true] True for little-endian, false for big-endian
 */
function writeFloat64(buffer, value, offset = 0, isLE = true) {
  ieee754.write(buffer, value, offset, isLE, 52, 8);
}

/**
 * Allocates a new buffer and encodes a floating point number into it.
 * @param {number} value Floating point number
 * @param {'single'|'double'} [precision='double'] Precision mode
 * @param {boolean} [isLE=true] Endianness
 * @returns {Buffer} Encoded buffer
 */
function encodeFloatingPoint(value, precision = 'double', isLE = true) {
  const isSingle = precision === 'single';
  const size = isSingle ? 4 : 8;
  const mLen = isSingle ? 23 : 52;
  const buffer = Buffer.alloc(size);
  ieee754.write(buffer, value, 0, isLE, mLen, size);
  return buffer;
}

module.exports = {
  ieee754,
  write: ieee754.write,
  read: ieee754.read,
  writeFloat32,
  writeFloat64,
  encodeFloatingPoint,
};
test/contract.js
const assert = require('node:assert');
const {
  ieee754,
  write,
  read,
  writeFloat32,
  writeFloat64,
  encodeFloatingPoint,
} = require('../src/index.js');

// 1. write encodes 32-bit floating point numbers in little-endian and big-endian byte order
{
  const bufLE = Buffer.alloc(4);
  const bufBE = Buffer.alloc(4);
  write(bufLE, 42.5, 0, true, 23, 4);
  write(bufBE, 42.5, 0, false, 23, 4);

  const expectedBE = Buffer.from([0x42, 0x2a, 0x00, 0x00]);
  const expectedLE = Buffer.from([0x00, 0x00, 0x2a, 0x42]);
  assert(bufLE.equals(expectedLE), '32-bit LE mismatch');
  assert(bufBE.equals(expectedBE), '32-bit BE mismatch');

  const refLE = Buffer.alloc(4);
  refLE.writeFloatLE(42.5, 0);
  assert(bufLE.equals(refLE), '32-bit LE ref mismatch');

  const helperBuf = Buffer.alloc(4);
  writeFloat32(helperBuf, 42.5, 0, true);
  assert(helperBuf.equals(expectedLE), 'writeFloat32 LE mismatch');
}

// 2. write encodes 64-bit double-precision floating point numbers matching IEEE 754 representations
{
  const testValues = [1.0, -0.5, Math.PI, 12345.6789];
  for (const v of testValues) {
    const bufLE = Buffer.alloc(8);
    const bufBE = Buffer.alloc(8);
    write(bufLE, v, 0, true, 52, 8);
    write(bufBE, v, 0, false, 52, 8);

    const refLE = Buffer.alloc(8);
    const refBE = Buffer.alloc(8);
    refLE.writeDoubleLE(v, 0);
    refBE.writeDoubleBE(v, 0);

    assert(bufLE.equals(refLE), `64-bit LE ref mismatch for ${v}`);
    assert(bufBE.equals(refBE), `64-bit BE ref mismatch for ${v}`);

    const encoded = encodeFloatingPoint(v, 'double', true);
    assert(encoded.equals(refLE), `encodeFloatingPoint mismatch for ${v}`);
  }
}

// 3. write encodes special values including positive zero, negative zero, infinity, and NaN
{
  const posZero = Buffer.alloc(8);
  const negZero = Buffer.alloc(8);
  write(posZero, 0, 0, false, 52, 8);
  write(negZero, -0, 0, false, 52, 8);
  assert.strictEqual(posZero[0] & 0x80, 0x00, '+0 must not have sign bit set');
  assert.strictEqual(negZero[0] & 0x80, 0x80, '-0 must have sign bit set');

  const infBuf = Buffer.alloc(8);
  const negInfBuf = Buffer.alloc(8);
  write(infBuf, Infinity, 0, false, 52, 8);
  write(negInfBuf, -Infinity, 0, false, 52, 8);
  assert.strictEqual(read(infBuf, 0, false, 52, 8), Infinity);
  assert.strictEqual(read(negInfBuf, 0, false, 52, 8), -Infinity);

  const nanBuf = Buffer.alloc(8);
  write(nanBuf, NaN, 0, true, 52, 8);
  assert(Number.isNaN(read(nanBuf, 0, true, 52, 8)), 'NaN must decode to NaN');
}

// 4. write writes values into target buffers at arbitrary valid offsets without disturbing adjacent bytes
{
  const sentinel = 0xee;
  const buf = Buffer.alloc(16, sentinel);
  write(buf, 42.5, 2, true, 23, 4);
  assert.strictEqual(buf[0], sentinel);
  assert.strictEqual(buf[1], sentinel);
  assert.strictEqual(buf[6], sentinel);
  assert.strictEqual(buf[15], sentinel);

  const decoded = read(buf, 2, true, 23, 4);
  assert.strictEqual(decoded, 42.5);
}

// 5. write operates directly on standard Uint8Array and Node.js Buffer instances
{
  const uint8 = new Uint8Array(8);
  write(uint8, 987.654, 0, true, 52, 8);
  const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);
  assert.strictEqual(view.getFloat64(0, true), 987.654);
}

console.log('All contract assertions passed successfully.');

Seeder de origen

anónimo