Exemplo
bare-buffer 3.7.0: Buffer.prototype.writeInt32LE
Amostra verificada para npm bare-buffer 3.7.0: Buffer.prototype.writeInt32LE. O contrato rodou em node 22 · linux alpine/x64 · docker e passou.
sha256:dcd8ae08bd124bb69487506d4e2706f156c445ddd1321ae2a98469e6867e4463
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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-27 |
Caso
HOW- Objetivo
- verify Buffer.prototype.writeInt32LE in pkg:npm/bare-buffer@3.7.0
- Pacotes
- Símbolos
-
- Buffer.prototype.writeInt32LE
- Ambiente
- node 22.23.2
- Criado
- 2026-08-27T05:44:26Z
Contrato
- writeInt32LE writes positive 32-bit signed integers in little-endian order and returns the offset after write
- writeInt32LE writes negative 32-bit signed integers using two's complement encoding in little-endian byte order
- writeInt32LE defaults offset to zero when offset parameter is omitted
- writeInt32LE serializes maximum and minimum 32-bit signed integer boundary values accurately
- writeInt32LE allows sequential multi-value writes into a single buffer using returned offset positions
- writeInt32LE throws RangeError when write offset exceeds buffer boundary
Arquivos
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código-fonte
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 Buffer.prototype.writeInt32LE in pkg:npm/bare-buffer@3.7.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/bare-buffer@3.7.0
Demonstrate these symbols/APIs:
- Buffer.prototype.writeInt32LE
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.
{"case":{"caseId":"case:sha256:38461e917a14b49eabed125f26ab482d02d0c5bf5a2113bba404aeb3402da368","contract":["writeInt32LE writes positive 32-bit signed integers in little-endian order and returns the offset after write","writeInt32LE writes negative 32-bit signed integers using two's complement encoding in little-endian byte order","writeInt32LE defaults offset to zero when offset parameter is omitted","writeInt32LE serializes maximum and minimum 32-bit signed integer boundary values accurately","writeInt32LE allows sequential multi-value writes into a single buffer using returned offset positions","writeInt32LE throws RangeError when write offset exceeds buffer boundary"],"goal":"verify Buffer.prototype.writeInt32LE in pkg:npm/bare-buffer@3.7.0","kind":"HOW","packages":["pkg:npm/bare-buffer@3.7.0"],"schemaVersion":1,"symbols":["Buffer.prototype.writeInt32LE"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/bare-buffer@3.7.0"],"schemaVersion":1,"subject":"pkg:npm/bare-buffer@3.7.0","symbols":["Buffer.prototype.writeInt32LE"],"verifierAdapter":"node-typescript@1"}
import { createRequire } from 'node:module';
import path from 'node:path';
const require = createRequire(import.meta.url);
if (typeof Bare === 'undefined') {
const nodeBuffer = globalThis.Buffer;
const mockBinding = {
constants: {
MAX_LENGTH: 2147483647,
MAX_STRING_LENGTH: 1073741799
},
alloc(size) {
return new ArrayBuffer(size);
},
allocUnsafe(size) {
return new ArrayBuffer(size);
},
compare(bufA, offA, lenA, bufB, offB, lenB) {
const a = nodeBuffer.from(bufA, offA, lenA);
const b = nodeBuffer.from(bufB, offB, lenB);
return a.compare(b);
},
toStringHex(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('hex');
},
writeHex(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'hex');
},
toStringBase64(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('base64');
},
writeBase64(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'base64');
},
toStringBase64URL(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('base64url');
},
writeBase64URL(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'base64url');
},
toStringUTF8(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('utf8');
},
writeUTF8(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'utf8');
},
validateUTF8(buf, offset, len) {
return nodeBuffer.isUtf8 ? nodeBuffer.isUtf8(nodeBuffer.from(buf, offset, len)) : true;
},
byteLengthUTF8(string) {
return nodeBuffer.byteLength(string, 'utf8');
},
toStringUTF16LE(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('utf16le');
},
writeUTF16LE(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'utf16le');
},
toStringLatin1(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('latin1');
},
writeLatin1(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'latin1');
},
indexOf(bufA, offA, lenA, bufB, offB, lenB, byteOffset) {
const a = nodeBuffer.from(bufA, offA, lenA);
const b = nodeBuffer.from(bufB, offB, lenB);
return a.indexOf(b, byteOffset);
},
lastIndexOf(bufA, offA, lenA, bufB, offB, lenB, byteOffset) {
const a = nodeBuffer.from(bufA, offA, lenA);
const b = nodeBuffer.from(bufB, offB, lenB);
return a.lastIndexOf(b, byteOffset);
},
swap16(buf, offset, len) {
nodeBuffer.from(buf, offset, len).swap16();
},
swap32(buf, offset, len) {
nodeBuffer.from(buf, offset, len).swap32();
},
swap64(buf, offset, len) {
nodeBuffer.from(buf, offset, len).swap64();
}
};
const mainPath = require.resolve('bare-buffer');
const bindingPath = path.join(path.dirname(mainPath), 'binding.js');
require.cache[bindingPath] = {
id: bindingPath,
filename: bindingPath,
loaded: true,
exports: mockBinding
};
}
const Buffer = require('bare-buffer');
export function writeInt32LE(buffer, value, offset = 0) {
return buffer.writeInt32LE(value, offset);
}
export function readInt32LE(buffer, offset = 0) {
return buffer.readInt32LE(offset);
}
export { Buffer };
export default Buffer;
{
"name": "sample-bare-buffer-write-int32-le",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-bare-buffer-write-int32-le",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"bare-buffer": "3.7.0"
}
},
"node_modules/bare-buffer": {
"version": "3.7.0",
"resolved": "https://registry.npmjs.org/bare-buffer/-/bare-buffer-3.7.0.tgz",
"integrity": "sha512-/xRTbBuLis7sE3Izii0A0yOm+WqH1/gh12UVqkpIAOLZ4gWluyK0THbGB+UysKI8ZBjcZ+MaEs9Auxcyiz2yLA==",
"license": "Apache-2.0",
"engines": {
"bare": ">=1.20.0"
}
}
}
}
{
"name": "sample-bare-buffer-write-int32-le",
"version": "1.0.0",
"type": "module",
"private": true,
"description": "Clean-room verification of Buffer.prototype.writeInt32LE in bare-buffer",
"license": "MIT-0",
"dependencies": {
"bare-buffer": "3.7.0"
}
}
{
"schemaVersion": 1,
"goal": "verify Buffer.prototype.writeInt32LE in pkg:npm/bare-buffer@3.7.0",
"kind": "HOW",
"packages": [
"pkg:npm/bare-buffer@3.7.0"
],
"symbols": [
"Buffer.prototype.writeInt32LE"
]
}
import assert from 'node:assert/strict';
import Buffer, { writeInt32LE, readInt32LE } from '../index.js';
// 1. writeInt32LE writes positive 32-bit signed integers in little-endian order and returns the offset after write
{
const buf = Buffer.alloc(8, 0);
const nextOffset = buf.writeInt32LE(0x12345678, 2);
assert.strictEqual(nextOffset, 6, 'writeInt32LE should return the offset immediately following written bytes (2 + 4)');
assert.strictEqual(buf[2], 0x78, 'Least significant byte at offset 2');
assert.strictEqual(buf[3], 0x56, 'Byte at offset 3');
assert.strictEqual(buf[4], 0x34, 'Byte at offset 4');
assert.strictEqual(buf[5], 0x12, 'Most significant byte at offset 5');
assert.strictEqual(buf.readInt32LE(2), 0x12345678, 'readInt32LE at offset 2 should recover written positive value');
assert.strictEqual(buf[0], 0, 'Byte before write region must remain untouched');
assert.strictEqual(buf[1], 0, 'Byte before write region must remain untouched');
assert.strictEqual(buf[6], 0, 'Byte after write region must remain untouched');
assert.strictEqual(buf[7], 0, 'Byte after write region must remain untouched');
}
// 2. writeInt32LE writes negative 32-bit signed integers using two's complement encoding in little-endian byte order
{
const buf = Buffer.alloc(8, 0);
const nextOffset = buf.writeInt32LE(-1, 0);
assert.strictEqual(nextOffset, 4, 'Writing -1 at offset 0 should return next offset 4');
assert.deepStrictEqual(Array.from(buf.subarray(0, 4)), [0xff, 0xff, 0xff, 0xff], '-1 is represented as all 0xFF bytes');
assert.strictEqual(buf.readInt32LE(0), -1, 'readInt32LE should recover -1');
buf.writeInt32LE(-123456, 4);
assert.deepStrictEqual(Array.from(buf.subarray(4, 8)), [0xc0, 0x1d, 0xfe, 0xff], '-123456 correctly serialized in little-endian');
assert.strictEqual(buf.readInt32LE(4), -123456, 'readInt32LE should recover -123456');
}
// 3. writeInt32LE defaults offset to zero when offset parameter is omitted
{
const buf = Buffer.alloc(4, 0);
const nextOffset = buf.writeInt32LE(42);
assert.strictEqual(nextOffset, 4, 'Omitted offset should default to 0 and return 4');
assert.strictEqual(buf.readInt32LE(0), 42, 'readInt32LE at offset 0 should recover written value');
assert.strictEqual(buf[0], 42, 'First byte contains value 42');
assert.strictEqual(buf[1], 0, 'Second byte is 0');
assert.strictEqual(buf[2], 0, 'Third byte is 0');
assert.strictEqual(buf[3], 0, 'Fourth byte is 0');
}
// 4. writeInt32LE serializes maximum and minimum 32-bit signed integer boundary values accurately
{
const buf = Buffer.alloc(8, 0);
// Max signed 32-bit int: 2147483647 (0x7FFFFFFF) -> LE: [0xFF, 0xFF, 0xFF, 0x7F]
buf.writeInt32LE(2147483647, 0);
assert.strictEqual(buf.readInt32LE(0), 2147483647, 'Max 32-bit signed integer recovered');
assert.deepStrictEqual(Array.from(buf.subarray(0, 4)), [0xff, 0xff, 0xff, 0x7f], 'Max int32 byte layout in little-endian');
// Min signed 32-bit int: -2147483648 (-0x80000000) -> LE: [0x00, 0x00, 0x00, 0x80]
buf.writeInt32LE(-2147483648, 4);
assert.strictEqual(buf.readInt32LE(4), -2147483648, 'Min 32-bit signed integer recovered');
assert.deepStrictEqual(Array.from(buf.subarray(4, 8)), [0x00, 0x00, 0x00, 0x80], 'Min int32 byte layout in little-endian');
}
// 5. writeInt32LE allows sequential multi-value writes into a single buffer using returned offset positions
{
const buf = Buffer.alloc(12, 0);
let pos = 0;
pos = writeInt32LE(buf, 1000, pos);
assert.strictEqual(pos, 4, 'First write advances position to 4');
pos = writeInt32LE(buf, -2000, pos);
assert.strictEqual(pos, 8, 'Second write advances position to 8');
pos = writeInt32LE(buf, 3000, pos);
assert.strictEqual(pos, 12, 'Third write advances position to 12');
assert.strictEqual(readInt32LE(buf, 0), 1000, 'First value matches');
assert.strictEqual(readInt32LE(buf, 4), -2000, 'Second value matches');
assert.strictEqual(readInt32LE(buf, 8), 3000, 'Third value matches');
}
// 6. writeInt32LE throws RangeError when write offset exceeds buffer boundary
{
const buf = Buffer.alloc(4, 0);
assert.throws(
() => buf.writeInt32LE(1, 1),
{ name: 'RangeError' },
'Writing 4 bytes at offset 1 in 4-byte buffer exceeds bound and must throw RangeError'
);
assert.throws(
() => buf.writeInt32LE(1, 4),
{ name: 'RangeError' },
'Writing at offset equal to length must throw RangeError'
);
assert.throws(
() => buf.writeInt32LE(1, -1),
{ name: 'RangeError' },
'Writing at negative offset must throw RangeError'
);
assert.throws(
() => buf.writeInt32LE(1, 'invalid'),
{ name: 'TypeError' },
'Non-number offset must throw TypeError'
);
}
console.log('All contract assertions for Buffer.prototype.writeInt32LE passed successfully.');
Seeder de origem
anônimo