CodeSampleX

Sample

@webassemblyjs/leb128 1.13.2: encode and decode unsigned and signed leb128 integers with @webassemblyjs/leb128

Verified sample for npm @webassemblyjs/leb128 1.13.2: encode and decode unsigned and signed leb128 integers with @webassemblyjs/leb128. The contract ran on…

sha256:ebb02c65d559064be5ef36039fc408a5a19247e4266c2d960f503293794c1d43

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
encode and decode unsigned and signed leb128 integers with @webassemblyjs/leb128
Packages
Symbols
  • decodeInt32
  • decodeUInt32
  • encodeI32
  • encodeU32
Environment
node 22.23.2
Created
2026-08-27T23:26:08Z

Contract

  1. encodeU32 encodes an unsigned 32-bit integer into a Uint8Array using LEB128 encoding
  2. decodeUInt32 decodes LEB128 encoded bytes into an unsigned 32-bit integer value and returns nextIndex
  3. encodeI32 encodes a signed 32-bit integer into a Uint8Array using LEB128 encoding
  4. decodeInt32 decodes LEB128 encoded bytes into a signed 32-bit integer value and returns nextIndex

Files

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

Download the source artifact (tar.gz)

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: encode and decode unsigned and signed leb128 integers with @webassemblyjs/leb128
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40webassemblyjs/leb128@1.13.2
Demonstrate these symbols/APIs:
  - decodeInt32
  - decodeUInt32
  - encodeI32
  - encodeU32

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:fa0f54f4c4bb811fc998a8ba5f60520ea4bbf13b0e81655dc831c5edcf619ba7","contract":["encodeU32 encodes an unsigned 32-bit integer into a Uint8Array using LEB128 encoding","decodeUInt32 decodes LEB128 encoded bytes into an unsigned 32-bit integer value and returns nextIndex","encodeI32 encodes a signed 32-bit integer into a Uint8Array using LEB128 encoding","decodeInt32 decodes LEB128 encoded bytes into a signed 32-bit integer value and returns nextIndex"],"goal":"encode and decode unsigned and signed leb128 integers with @webassemblyjs/leb128","kind":"HOW","packages":["pkg:npm/%40webassemblyjs/leb128@1.13.2"],"schemaVersion":1,"symbols":["decodeInt32","decodeUInt32","encodeI32","encodeU32"]},"contractCommand":["node","test/contract.cjs"],"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/%40webassemblyjs/leb128@1.13.2"],"schemaVersion":1,"subject":"pkg:npm/%40webassemblyjs/leb128@1.13.2","symbols":["decodeInt32","decodeUInt32","encodeI32","encodeU32"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const leb128 = require('@webassemblyjs/leb128');

function encodeUnsigned32(value) {
  return leb128.encodeU32(value);
}

function decodeUnsigned32(buffer, index = 0) {
  return leb128.decodeUInt32(buffer, index);
}

function encodeSigned32(value) {
  return leb128.encodeI32(value);
}

function decodeSigned32(buffer, index = 0) {
  return leb128.decodeInt32(buffer, index);
}

module.exports = {
  encodeUnsigned32,
  decodeUnsigned32,
  encodeSigned32,
  decodeSigned32,
  encodeU32: leb128.encodeU32,
  decodeUInt32: leb128.decodeUInt32,
  encodeI32: leb128.encodeI32,
  decodeInt32: leb128.decodeInt32
};
package-lock.json
{
  "name": "sample-webassemblyjs-leb128",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-webassemblyjs-leb128",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@webassemblyjs/leb128": "1.13.2"
      }
    },
    "node_modules/@webassemblyjs/leb128": {
      "version": "1.13.2",
      "resolved": "https://registry.npmjs.org/@webassemblyjs/leb128/-/leb128-1.13.2.tgz",
      "integrity": "sha512-Lde1oNoIdzVzdkNEAWZ1dZ5orIbff80YPdHx20mrHwHrVNNTjNr8E3xz9BdpcGqRQbAEa+fkrCb+fRFTl/6sQw==",
      "license": "Apache-2.0",
      "dependencies": {
        "@xtuc/long": "4.2.2"
      }
    },
    "node_modules/@xtuc/long": {
      "version": "4.2.2",
      "resolved": "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz",
      "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==",
      "license": "Apache-2.0"
    }
  }
}
package.json
{
  "name": "sample-webassemblyjs-leb128",
  "version": "1.0.0",
  "private": true,
  "description": "encode and decode unsigned and signed leb128 integers with @webassemblyjs/leb128",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "@webassemblyjs/leb128": "1.13.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "encode and decode unsigned and signed leb128 integers with @webassemblyjs/leb128",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40webassemblyjs/leb128@1.13.2"
  ],
  "symbols": [
    "decodeInt32",
    "decodeUInt32",
    "encodeI32",
    "encodeU32"
  ]
}
test/contract.cjs
'use strict';

const assert = require('assert');
const leb128 = require('@webassemblyjs/leb128');
const {
  encodeUnsigned32,
  decodeUnsigned32,
  encodeSigned32,
  decodeSigned32,
  encodeU32,
  decodeUInt32,
  encodeI32,
  decodeInt32
} = require('../index.js');

function runTests() {
  // 1. Test encodeU32 and decodeUInt32 with standard values
  const u32TestCases = [
    { value: 0, expectedBytes: [0x00] },
    { value: 1, expectedBytes: [0x01] },
    { value: 127, expectedBytes: [0x7f] },
    { value: 128, expectedBytes: [0x80, 0x01] },
    { value: 624485, expectedBytes: [0xe5, 0x8e, 0x26] },
    { value: 0xffffffff, expectedBytes: [0xff, 0xff, 0xff, 0xff, 0x0f] }
  ];

  for (const tc of u32TestCases) {
    const encodedDirect = encodeU32(tc.value);
    assert(encodedDirect instanceof Uint8Array, 'encodeU32 must return a Uint8Array');
    assert.deepStrictEqual(
      Array.from(encodedDirect),
      tc.expectedBytes,
      `encodeU32(${tc.value}) returned unexpected bytes`
    );

    const decodedDirect = decodeUInt32(encodedDirect);
    assert.strictEqual(
      decodedDirect.value,
      tc.value,
      `decodeUInt32 must decode value correctly for ${tc.value}`
    );
    assert.strictEqual(
      decodedDirect.nextIndex,
      tc.expectedBytes.length,
      `decodeUInt32 must return correct nextIndex for ${tc.value}`
    );

    // Test through module wrappers
    const encodedWrapped = encodeUnsigned32(tc.value);
    assert.deepStrictEqual(Array.from(encodedWrapped), tc.expectedBytes);
    const decodedWrapped = decodeUnsigned32(encodedWrapped);
    assert.strictEqual(decodedWrapped.value, tc.value);
  }

  // 2. Test decodeUInt32 with offset index
  const paddedU32Buffer = new Uint8Array([0xaa, 0xbb, 0xe5, 0x8e, 0x26, 0xcc]);
  const decodedOffsetU32 = decodeUInt32(paddedU32Buffer, 2);
  assert.strictEqual(decodedOffsetU32.value, 624485);
  assert.strictEqual(decodedOffsetU32.nextIndex, 5);

  // 3. Test encodeI32 and decodeInt32 with positive and negative signed values
  const i32TestCases = [
    { value: 0, expectedBytes: [0x00] },
    { value: 1, expectedBytes: [0x01] },
    { value: -1, expectedBytes: [0x7f] },
    { value: 63, expectedBytes: [0x3f] },
    { value: -64, expectedBytes: [0x40] },
    { value: 624485, expectedBytes: [0xe5, 0x8e, 0x26] },
    { value: -624485, expectedBytes: [0x9b, 0xf1, 0x59] },
    { value: 2147483647, expectedBytes: [0xff, 0xff, 0xff, 0xff, 0x07] },
    { value: -2147483648, expectedBytes: [0x80, 0x80, 0x80, 0x80, 0x78] }
  ];

  for (const tc of i32TestCases) {
    const encodedDirect = encodeI32(tc.value);
    assert(encodedDirect instanceof Uint8Array, 'encodeI32 must return a Uint8Array');
    assert.deepStrictEqual(
      Array.from(encodedDirect),
      tc.expectedBytes,
      `encodeI32(${tc.value}) returned unexpected bytes`
    );

    const decodedDirect = decodeInt32(encodedDirect);
    assert.strictEqual(
      decodedDirect.value,
      tc.value,
      `decodeInt32 must decode value correctly for ${tc.value}`
    );
    assert.strictEqual(
      decodedDirect.nextIndex,
      tc.expectedBytes.length,
      `decodeInt32 must return correct nextIndex for ${tc.value}`
    );

    // Test through module wrappers
    const encodedWrapped = encodeSigned32(tc.value);
    assert.deepStrictEqual(Array.from(encodedWrapped), tc.expectedBytes);
    const decodedWrapped = decodeSigned32(encodedWrapped);
    assert.strictEqual(decodedWrapped.value, tc.value);
  }

  // 4. Test decodeInt32 with offset index
  const paddedI32Buffer = new Uint8Array([0x12, 0x34, 0x9b, 0xf1, 0x59, 0x56]);
  const decodedOffsetI32 = decodeInt32(paddedI32Buffer, 2);
  assert.strictEqual(decodedOffsetI32.value, -624485);
  assert.strictEqual(decodedOffsetI32.nextIndex, 5);

  console.log('Contract tests passed successfully.');
}

try {
  runTests();
  process.exit(0);
} catch (err) {
  console.error('Contract test failed:', err);
  process.exit(1);
}

Origin Seeder

anonymous