CodeSampleX

Exemple

chromium-pickle-js 0.2.0: createEmpty, createFromBuffer

Échantillon vérifié pour npm chromium-pickle-js 0.2.0: createEmpty, createFromBuffer. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a…

sha256:258c307b68344ed1f201fa4a1d3acd6c6b0dd7ddfdfbafca4e3bbfb2ca0e8951

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-08

Cas

HOW
Objectif
verify pkg:npm/chromium-pickle-js@0.2.0
Paquets
Symboles
  • createEmpty
  • createFromBuffer
Environnement
node 22.23.2
Créé
2026-08-26T09:11:46Z

Contrat

  1. createEmpty returns a new Pickle instance that can write bool, int, uint32, float, double, and string primitives
  2. Pickle.toBuffer returns a Buffer containing the 4-byte payload size header followed by 4-byte aligned payload data
  3. createFromBuffer initializes a Pickle instance from an existing Buffer for reading with PickleIterator
  4. PickleIterator sequentially reads bool, int, uint32, float, double, and string values in matching write order
  5. Pickle.writeInt64 and Pickle.writeUInt64 throw TypeError in Node.js because 64-bit buffer write methods are undefined on Buffer.prototype
  6. PickleIterator throws an Error when attempting to read past the payload buffer end

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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/chromium-pickle-js@0.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/chromium-pickle-js@0.2.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:2a8593e5836b43efa8f92fa1b859ef2940f790b35ad5147c877cd3218bee6c31","constraints":{"executionContext":"node"},"contract":["createEmpty returns a new Pickle instance that can write bool, int, uint32, float, double, and string primitives","Pickle.toBuffer returns a Buffer containing the 4-byte payload size header followed by 4-byte aligned payload data","createFromBuffer initializes a Pickle instance from an existing Buffer for reading with PickleIterator","PickleIterator sequentially reads bool, int, uint32, float, double, and string values in matching write order","Pickle.writeInt64 and Pickle.writeUInt64 throw TypeError in Node.js because 64-bit buffer write methods are undefined on Buffer.prototype","PickleIterator throws an Error when attempting to read past the payload buffer end"],"goal":"verify pkg:npm/chromium-pickle-js@0.2.0","kind":"HOW","packages":["pkg:npm/chromium-pickle-js@0.2.0"],"schemaVersion":1,"symbols":["createEmpty","createFromBuffer"]},"contractCommand":["node","test/contract.mjs"],"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/chromium-pickle-js@0.2.0"],"schemaVersion":1,"subject":"pkg:npm/chromium-pickle-js@0.2.0","symbols":["createEmpty","createFromBuffer"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-chromium-pickle-js",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-chromium-pickle-js",
      "version": "1.0.0",
      "dependencies": {
        "chromium-pickle-js": "0.2.0"
      }
    },
    "node_modules/chromium-pickle-js": {
      "version": "0.2.0",
      "resolved": "https://registry.npmjs.org/chromium-pickle-js/-/chromium-pickle-js-0.2.0.tgz",
      "integrity": "sha512-1R5Fho+jBq0DDydt+/vHWj5KJNJCKdARKOCwZUen84I5BreWoLqRLANH1U87eJy1tiASPtMnGqJJq0ZsLoRPOw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-chromium-pickle-js",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "chromium-pickle-js": "0.2.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/chromium-pickle-js@0.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/chromium-pickle-js@0.2.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.mjs
import pickle from 'chromium-pickle-js';

const { createEmpty, createFromBuffer } = pickle;

/**
 * Creates an empty Pickle instance for writing binary data.
 * @returns {object}
 */
export function createEmptyPickle() {
  return createEmpty();
}

/**
 * Creates a Pickle instance from an existing Buffer for reading.
 * @param {Buffer} buffer
 * @returns {object}
 */
export function createPickleFromBuffer(buffer) {
  return createFromBuffer(buffer);
}

export { createEmpty, createFromBuffer };
test/contract.mjs
import assert from 'node:assert/strict';
import {
  createEmpty,
  createFromBuffer,
  createEmptyPickle,
  createPickleFromBuffer,
} from '../src/index.mjs';

// 1. createEmpty returns a new Pickle instance that can write bool, int, uint32, float, double, and string primitives
{
  const p = createEmptyPickle();
  assert.equal(p.writeBool(true), true);
  assert.equal(p.writeBool(false), true);
  assert.equal(p.writeInt(-12345), true);
  assert.equal(p.writeUInt32(54321), true);
  assert.equal(p.writeFloat(1.5), true);
  assert.equal(p.writeDouble(3.141592653589793), true);
  assert.equal(p.writeString('chromium-pickle-sample'), true);
}

// 2. Pickle.toBuffer returns a Buffer containing the 4-byte payload size header followed by 4-byte aligned payload data
{
  const p = createEmpty();
  assert.equal(p.writeInt(42), true);
  const buf = p.toBuffer();
  assert.ok(Buffer.isBuffer(buf));
  const payloadSize = buf.readUInt32LE(0);
  assert.equal(payloadSize, 4);
  assert.equal(buf.length, 8);
  assert.equal(buf.readInt32LE(4), 42);
}

// 3. createFromBuffer initializes a Pickle instance from an existing Buffer for reading with PickleIterator
{
  const pWrite = createEmpty();
  assert.equal(pWrite.writeString('read-test'), true);
  const buf = pWrite.toBuffer();

  const pRead = createPickleFromBuffer(buf);
  const it = pRead.createIterator();
  assert.equal(it.readString(), 'read-test');
}

// 4. PickleIterator sequentially reads bool, int, uint32, float, double, and string values in matching write order
{
  const p = createEmpty();
  assert.equal(p.writeBool(true), true);
  assert.equal(p.writeBool(false), true);
  assert.equal(p.writeInt(-9876), true);
  assert.equal(p.writeUInt32(65432), true);
  assert.equal(p.writeFloat(2.5), true);
  assert.equal(p.writeDouble(2.718281828459045), true);
  assert.equal(p.writeString('sequential-test'), true);

  const buf = p.toBuffer();
  const pRead = createFromBuffer(buf);
  const it = pRead.createIterator();

  assert.equal(it.readBool(), true);
  assert.equal(it.readBool(), false);
  assert.equal(it.readInt(), -9876);
  assert.equal(it.readUInt32(), 65432);
  assert.equal(it.readFloat(), 2.5);
  assert.equal(it.readDouble(), 2.718281828459045);
  assert.equal(it.readString(), 'sequential-test');
}

// 5. Pickle.writeInt64 and Pickle.writeUInt64 throw TypeError in Node.js because 64-bit buffer write methods are undefined on Buffer.prototype
{
  const p = createEmpty();
  assert.throws(
    () => {
      p.writeInt64(100);
    },
    {
      name: 'TypeError',
    }
  );
  assert.throws(
    () => {
      p.writeUInt64(100);
    },
    {
      name: 'TypeError',
    }
  );
}

// 6. PickleIterator throws an Error when attempting to read past the payload buffer end
{
  const p = createEmpty();
  assert.equal(p.writeInt(100), true);
  const buf = p.toBuffer();

  const pRead = createFromBuffer(buf);
  const it = pRead.createIterator();
  assert.equal(it.readInt(), 100);

  assert.throws(
    () => {
      it.readInt();
    },
    {
      name: 'Error',
      message: /Failed to read data with length of/,
    }
  );
}

console.log('Contract assertions passed.');

Seeder d'origine

anonyme