CodeSampleX

Sample

node-abi 4.33.0: getAbi, getTarget

Verified sample for npm node-abi 4.33.0: getAbi, getTarget. The contract ran on node 22 · linux alpine/x64 · docker and passed.

sha256:ef8e9917d74c4a1a694ad2b73a6eed2ce779a0785dea81198969eb81a7166e86

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/node-abi@4.33.0
Packages
Symbols
  • node-abi.getAbi
  • node-abi.getTarget
Environment
node 22.23.2
Created
2026-08-28T05:39:31Z

Contract

  1. getAbi resolves Node.js target version to corresponding ABI version string
  2. getAbi resolves Electron target version to corresponding ABI version string
  3. getAbi returns numeric ABI string input directly and strips leading v prefix from version string
  4. getAbi throws an Error for unsupported or unknown version ranges
  5. getTarget resolves Node.js ABI version string to target version
  6. getTarget resolves Electron ABI version string to target version
  7. getTarget returns non-numeric version string input directly
  8. getTarget throws an Error for unknown ABI versions
  9. allTargets and supportedTargets export target registry entries with runtime, target, abi, and lts properties

Files

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

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/node-abi@4.33.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/node-abi@4.33.0
Demonstrate these symbols/APIs:
  - node-abi.getAbi
  - node-abi.getTarget

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:857c4b43d4194ddfc41ee5a22d9dabb8061595b3d725788c5a401f8674acd79e","contract":["getAbi resolves Node.js target version to corresponding ABI version string","getAbi resolves Electron target version to corresponding ABI version string","getAbi returns numeric ABI string input directly and strips leading v prefix from version string","getAbi throws an Error for unsupported or unknown version ranges","getTarget resolves Node.js ABI version string to target version","getTarget resolves Electron ABI version string to target version","getTarget returns non-numeric version string input directly","getTarget throws an Error for unknown ABI versions","allTargets and supportedTargets export target registry entries with runtime, target, abi, and lts properties"],"goal":"verify pkg:npm/node-abi@4.33.0","kind":"HOW","packages":["pkg:npm/node-abi@4.33.0"],"schemaVersion":1,"symbols":["node-abi.getAbi","node-abi.getTarget"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","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/node-abi@4.33.0"],"schemaVersion":1,"subject":"pkg:npm/node-abi@4.33.0","symbols":["node-abi.getAbi","node-abi.getTarget"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-node-abi",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-node-abi",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "node-abi": "4.33.0"
      }
    },
    "node_modules/node-abi": {
      "version": "4.33.0",
      "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-4.33.0.tgz",
      "integrity": "sha512-vLBWCKb+7LWsX+TbfzWOkw0W81m377tyx3hOweBTjO43CXZnRGS1/JPWs20fr0PgZyDXk6ROYrylsEycK8raDA==",
      "license": "MIT",
      "dependencies": {
        "semver": "^7.6.3"
      },
      "engines": {
        "node": ">=22.12.0"
      }
    },
    "node_modules/semver": {
      "version": "7.8.5",
      "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
      "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    }
  }
}
package.json
{
  "name": "sample-node-abi",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for node-abi",
  "type": "module",
  "main": "src/index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "node-abi": "4.33.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/node-abi@4.33.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/node-abi@4.33.0"
  ],
  "symbols": [
    "node-abi.getAbi",
    "node-abi.getTarget"
  ]
}
src/index.mjs
import {
  getAbi,
  getTarget,
  allTargets,
  supportedTargets,
  deprecatedTargets,
  additionalTargets,
  futureTargets
} from 'node-abi';

export function getNodeAbi(target) {
  return getAbi(target, 'node');
}

export function getElectronAbi(target) {
  return getAbi(target, 'electron');
}

export function getNodeTarget(abi) {
  return getTarget(abi, 'node');
}

export function getElectronTarget(abi) {
  return getTarget(abi, 'electron');
}

export function isTargetSupported(target, runtime = 'node') {
  const normalized = target.replace(/^v/, '');
  return supportedTargets.some((t) => t.runtime === runtime && t.target === normalized);
}

export function getTargetInfo(abi, runtime = 'node') {
  return allTargets.find((t) => t.runtime === runtime && t.abi === String(abi)) || null;
}

export {
  getAbi,
  getTarget,
  allTargets,
  supportedTargets,
  deprecatedTargets,
  additionalTargets,
  futureTargets
};
test/contract.mjs
import assert from 'node:assert';
import {
  getAbi,
  getTarget,
  allTargets,
  supportedTargets,
  deprecatedTargets,
  additionalTargets,
  futureTargets,
  getNodeAbi,
  getElectronAbi,
  getNodeTarget,
  getElectronTarget,
  isTargetSupported,
  getTargetInfo
} from '../src/index.mjs';

// 1. getAbi resolves Node.js target version to corresponding ABI version string
{
  assert.strictEqual(getAbi('20.0.0', 'node'), '115');
  assert.strictEqual(getAbi('22.0.0', 'node'), '127');
  assert.strictEqual(getAbi('18.16.0', 'node'), '108');
  assert.strictEqual(getAbi('20.0.0'), '115');
  assert.strictEqual(getNodeAbi('20.0.0'), '115');
  assert.strictEqual(getNodeAbi('22.0.0'), '127');
}

// 2. getAbi resolves Electron target version to corresponding ABI version string
{
  assert.strictEqual(getAbi('25.0.0', 'electron'), '116');
  assert.strictEqual(getAbi('28.0.0', 'electron'), '119');
  assert.strictEqual(getAbi('30.0.0', 'electron'), '123');
  assert.strictEqual(getElectronAbi('25.0.0'), '116');
  assert.strictEqual(getElectronAbi('28.0.0'), '119');
}

// 3. getAbi returns numeric ABI string input directly and strips leading v prefix from version string
{
  assert.strictEqual(getAbi('115', 'node'), '115');
  assert.strictEqual(getAbi('116', 'electron'), '116');
  assert.strictEqual(getAbi('v20.0.0', 'node'), '115');
  assert.strictEqual(getAbi('v25.0.0', 'electron'), '116');
  assert.strictEqual(getNodeAbi('v22.0.0'), '127');
}

// 4. getAbi throws an Error for unsupported or unknown version ranges
{
  assert.throws(
    () => getAbi('999.0.0', 'node'),
    /Could not detect abi for version 999.0.0 and runtime node/
  );
  assert.throws(
    () => getAbi('999.0.0', 'electron'),
    /Could not detect abi for version 999.0.0 and runtime electron/
  );
  assert.throws(
    () => getNodeAbi('999.0.0'),
    /Could not detect abi for version 999.0.0 and runtime node/
  );
}

// 5. getTarget resolves Node.js ABI version string to target version
{
  assert.strictEqual(getTarget('115', 'node'), '20.0.0');
  assert.strictEqual(getTarget('127', 'node'), '22.0.0');
  assert.strictEqual(getTarget('108'), '18.0.0');
  assert.strictEqual(getNodeTarget('115'), '20.0.0');
  assert.strictEqual(getNodeTarget('127'), '22.0.0');
}

// 6. getTarget resolves Electron ABI version string to target version
{
  assert.strictEqual(getTarget('116', 'electron'), '25.0.0');
  assert.strictEqual(getTarget('119', 'electron'), '28.0.0');
  assert.strictEqual(getElectronTarget('116'), '25.0.0');
  assert.strictEqual(getElectronTarget('119'), '28.0.0');
}

// 7. getTarget returns non-numeric version string input directly
{
  assert.strictEqual(getTarget('20.0.0', 'node'), '20.0.0');
  assert.strictEqual(getTarget('25.0.0', 'electron'), '25.0.0');
  assert.strictEqual(getNodeTarget('20.0.0'), '20.0.0');
}

// 8. getTarget throws an Error for unknown ABI versions
{
  assert.throws(
    () => getTarget('99999', 'node'),
    /Could not detect target for abi 99999 and runtime node/
  );
  assert.throws(
    () => getTarget('99999', 'electron'),
    /Could not detect target for abi 99999 and runtime electron/
  );
  assert.throws(
    () => getNodeTarget('99999'),
    /Could not detect target for abi 99999 and runtime node/
  );
}

// 9. allTargets and supportedTargets export target registry entries with runtime, target, abi, and lts properties
{
  assert.ok(Array.isArray(allTargets) && allTargets.length > 0);
  assert.ok(Array.isArray(supportedTargets) && supportedTargets.length > 0);
  assert.ok(Array.isArray(deprecatedTargets) && deprecatedTargets.length > 0);
  assert.ok(Array.isArray(additionalTargets));
  assert.ok(Array.isArray(futureTargets));

  const targetNode20 = supportedTargets.find((t) => t.runtime === 'node' && t.abi === '115');
  assert.ok(targetNode20);
  assert.strictEqual(targetNode20.target, '20.0.0');
  assert.strictEqual(typeof targetNode20.lts, 'boolean');

  assert.strictEqual(isTargetSupported('20.0.0', 'node'), true);
  assert.strictEqual(isTargetSupported('v20.0.0', 'node'), true);
  assert.strictEqual(isTargetSupported('999.0.0', 'node'), false);

  const info = getTargetInfo('115', 'node');
  assert.ok(info);
  assert.strictEqual(info.target, '20.0.0');
  assert.strictEqual(info.abi, '115');
  assert.strictEqual(getTargetInfo('99999', 'node'), null);
}

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

Origin Seeder

anonymous