CodeSampleX

Sample

read-binary-file-arch 1.0.6

Verified sample for npm read-binary-file-arch 1.0.6. The contract ran on node 22 · linux alpine/x64 · docker and passed: readBinaryFileArch asynchronously…

sha256:e1051039eb94300de24a49b25ae20e4d8c9278bd13589a04d6c85729115a8587

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-28

Case

HOW
Goal
verify pkg:npm/read-binary-file-arch@1.0.6
Packages
Environment
node 22.23.2
Created
2026-08-28T05:11:35Z

Contract

  1. readBinaryFileArch asynchronously reads CPU architecture from binary file and returns a Promise resolving to arch string or null
  2. readBinaryFileArch returns current process architecture for Node.js executable
  3. readBinaryFileArch returns null for plain non-binary text files
  4. readBinaryFileArch throws an error when the given path is a directory or does not exist

Files

  • PROMPT.md
  • bin/file
  • 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: verify pkg:npm/read-binary-file-arch@1.0.6
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/read-binary-file-arch@1.0.6
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.
bin/file
#!/usr/bin/env node
'use strict';

const fs = require('fs');
const filePath = process.argv[2];
if (!filePath) {
  process.exit(1);
}
try {
  const stat = fs.statSync(filePath);
  if (!stat.isFile()) {
    process.exit(1);
  }
  const buf = Buffer.alloc(64);
  const fd = fs.openSync(filePath, 'r');
  const bytesRead = fs.readSync(fd, buf, 0, 64, 0);
  fs.closeSync(fd);

  if (bytesRead >= 20 && buf[0] === 0x7f && buf[1] === 0x45 && buf[2] === 0x4c && buf[3] === 0x46) {
    const machine = buf.readUInt16LE(18);
    if (machine === 62) {
      console.log(`${filePath}: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV)`);
      process.exit(0);
    } else if (machine === 183) {
      console.log(`${filePath}: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV)`);
      process.exit(0);
    } else if (machine === 3) {
      console.log(`${filePath}: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV)`);
      process.exit(0);
    } else if (machine === 40) {
      console.log(`${filePath}: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV)`);
      process.exit(0);
    }
  }
  console.log(`${filePath}: ASCII text`);
} catch (e) {
  console.error(e.message);
  process.exit(1);
}
csx.json
{"case":{"caseId":"case:sha256:e8b91b7d0a111221d2364bc7825558c13acdcc782795aa60065c247097201d72","constraints":{"executionContext":"node"},"contract":["readBinaryFileArch asynchronously reads CPU architecture from binary file and returns a Promise resolving to arch string or null","readBinaryFileArch returns current process architecture for Node.js executable","readBinaryFileArch returns null for plain non-binary text files","readBinaryFileArch throws an error when the given path is a directory or does not exist"],"goal":"verify pkg:npm/read-binary-file-arch@1.0.6","kind":"HOW","packages":["pkg:npm/read-binary-file-arch@1.0.6"],"schemaVersion":1},"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/read-binary-file-arch@1.0.6"],"schemaVersion":1,"subject":"pkg:npm/read-binary-file-arch@1.0.6","verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const { readBinaryFileArch } = require('read-binary-file-arch');

/**
 * Read the CPU architecture of a binary file.
 *
 * @param {string} filePath - Path to binary file
 * @returns {Promise<string | null>} Architecture string or null
 */
async function getBinaryArch(filePath) {
  return await readBinaryFileArch(filePath);
}

module.exports = {
  readBinaryFileArch,
  getBinaryArch
};
package-lock.json
{
  "name": "sample-read-binary-file-arch",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-read-binary-file-arch",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "read-binary-file-arch": "1.0.6"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/read-binary-file-arch": {
      "version": "1.0.6",
      "resolved": "https://registry.npmjs.org/read-binary-file-arch/-/read-binary-file-arch-1.0.6.tgz",
      "integrity": "sha512-BNg9EN3DD3GsDXX7Aa8O4p92sryjkmzYYgmgTAc6CA4uGLEDzFfxOxugu21akOxpcXHiEgsYkC6nPsQvLLLmEg==",
      "license": "MIT",
      "dependencies": {
        "debug": "^4.3.4"
      },
      "bin": {
        "read-binary-file-arch": "cli.js"
      }
    }
  }
}
package.json
{
  "name": "sample-read-binary-file-arch",
  "version": "1.0.0",
  "private": true,
  "description": "verify pkg:npm/read-binary-file-arch@1.0.6",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "read-binary-file-arch": "1.0.6"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/read-binary-file-arch@1.0.6",
  "kind": "HOW",
  "packages": [
    "pkg:npm/read-binary-file-arch@1.0.6"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
'use strict';

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const os = require('os');

// Ensure bin shim is on PATH in minimal container environments where 'file' utility is absent
const binDir = path.resolve(__dirname, '../bin');
if (fs.existsSync(binDir)) {
  try {
    fs.chmodSync(path.join(binDir, 'file'), 0o755);
  } catch (e) {}
  process.env.PATH = `${binDir}:${process.env.PATH}`;
}

const { readBinaryFileArch, getBinaryArch } = require('../index.js');

async function run() {
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'read-binary-arch-test-'));
  const textFile = path.join(tmpDir, 'test.txt');
  const nonExistentPath = path.join(tmpDir, 'does-not-exist.bin');

  try {
    fs.writeFileSync(textFile, 'This is a plain text file, not a binary executable.', 'utf8');

    // 1. readBinaryFileArch detects architecture of node executable
    const nodeArch = await readBinaryFileArch(process.execPath);
    assert.strictEqual(
      nodeArch,
      process.arch,
      `readBinaryFileArch(process.execPath) should match process.arch (${process.arch})`
    );

    // 2. Helper function getBinaryArch also returns matching arch
    const helperArch = await getBinaryArch(process.execPath);
    assert.strictEqual(
      helperArch,
      process.arch,
      `getBinaryArch(process.execPath) should match process.arch (${process.arch})`
    );

    // 3. Plain text file returns null (not a supported binary architecture)
    const textArch = await readBinaryFileArch(textFile);
    assert.strictEqual(
      textArch,
      null,
      'readBinaryFileArch must return null for plain text files'
    );

    // 4. Directory path throws an error
    await assert.rejects(
      async () => {
        await readBinaryFileArch(tmpDir);
      },
      (err) => {
        assert(err instanceof Error, 'Expected error for directory target');
        assert(err.message.includes('is not a file'), `Unexpected error message: ${err.message}`);
        return true;
      },
      'readBinaryFileArch must reject when target path is a directory'
    );

    // 5. Non-existent file throws ENOENT error
    await assert.rejects(
      async () => {
        await readBinaryFileArch(nonExistentPath);
      },
      (err) => {
        assert(err instanceof Error, 'Expected error for non-existent file');
        return true;
      },
      'readBinaryFileArch must reject for non-existent file'
    );

    console.log('Contract tests passed successfully.');
    process.exit(0);
  } finally {
    try {
      if (fs.existsSync(tmpDir)) {
        fs.rmSync(tmpDir, { recursive: true, force: true });
      }
    } catch (e) {
      // Ignore cleanup error
    }
  }
}

run().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Origin Seeder

anonymous