CodeSampleX

Beispiel

netmask 2.1.2

Verifiziertes Beispiel für npm netmask 2.1.2. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand: new Netmask('192.0.2.5/24') normalizes to…

sha256:336d40d9c67dff1c9a6c3bc34de99a0435937c7b01cbdd04a09a25971bdba88d

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-11-22

Fall

HOW
Ziel
verify pkg:npm/netmask@2.1.2
Pakete
Umgebung
node 22.23.2
Erstellt
2026-11-22T19:34:11Z

Contract

  1. new Netmask('192.0.2.5/24') normalizes to base 192.0.2.0, mask 255.255.255.0, hostmask 0.0.0.255, size 256, first 192.0.2.1, last 192.0.2.254, broadcast 192.0.2.255
  2. new Netmask('198.51.100.77', '255.255.255.240') parses a separate dotted subnet mask into 198.51.100.64/28
  3. IPv4 /31 and /32 blocks have undefined broadcast and set first equal to base
  4. Netmask.contains() returns true for enclosed IPv4 addresses, CIDR strings, and Netmask instances and false for external or wider blocks
  5. Netmask.next(count) advances by count adjacent blocks for both IPv4 and IPv6
  6. Netmask.forEach() iterates usable host addresses from first to last with (ip, long, index)
  7. ip2long('192.0.2.1') and long2ip(3221225985) round-trip and ip2long throws on out-of-range octets
  8. new Netmask('2001:db8::/32') parses IPv6 CIDR blocks, checks IPv6 address/subnet containment, and computes next() blocks
  9. new Netmask() rejects missing net parameter and out-of-range IPv4 (/33) or IPv6 (/129) bitmasks

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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/netmask@2.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/netmask@2.1.2
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:9793110a900647e1888b6d57beaa0e6e176a041b651358bf2d344495d0eb2d56","constraints":{"executionContext":"node"},"contract":["new Netmask('192.0.2.5/24') normalizes to base 192.0.2.0, mask 255.255.255.0, hostmask 0.0.0.255, size 256, first 192.0.2.1, last 192.0.2.254, broadcast 192.0.2.255","new Netmask('198.51.100.77', '255.255.255.240') parses a separate dotted subnet mask into 198.51.100.64/28","IPv4 /31 and /32 blocks have undefined broadcast and set first equal to base","Netmask.contains() returns true for enclosed IPv4 addresses, CIDR strings, and Netmask instances and false for external or wider blocks","Netmask.next(count) advances by count adjacent blocks for both IPv4 and IPv6","Netmask.forEach() iterates usable host addresses from first to last with (ip, long, index)","ip2long('192.0.2.1') and long2ip(3221225985) round-trip and ip2long throws on out-of-range octets","new Netmask('2001:db8::/32') parses IPv6 CIDR blocks, checks IPv6 address/subnet containment, and computes next() blocks","new Netmask() rejects missing net parameter and out-of-range IPv4 (/33) or IPv6 (/129) bitmasks"],"goal":"verify pkg:npm/netmask@2.1.2","kind":"HOW","packages":["pkg:npm/netmask@2.1.2"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/netmask@2.1.2"],"schemaVersion":1,"subject":"pkg:npm/netmask@2.1.2","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "csx-sample-netmask",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "csx-sample-netmask",
      "version": "1.0.0",
      "dependencies": {
        "netmask": "2.1.2"
      }
    },
    "node_modules/netmask": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/netmask/-/netmask-2.1.2.tgz",
      "integrity": "sha512-In/qjEgPWP3EEKRBrATKSHRCcempKN/gUl97rrB1mTreVQfvPGthTJVwNXwbQHtIzzLf1bYyh8M50xpeYk0r6Q==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4.0"
      }
    }
  }
}
package.json
{
  "name": "csx-sample-netmask",
  "version": "1.0.0",
  "private": true,
  "description": "Minimal CommonJS sample verifying netmask@2.1.2",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "netmask": "2.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/netmask@2.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/netmask@2.1.2"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const { Netmask, ip2long, long2ip } = require('netmask');

function parseBlock(cidrOrNet, mask) {
  return mask === undefined ? new Netmask(cidrOrNet) : new Netmask(cidrOrNet, mask);
}

function summarizeBlock(block) {
  return {
    cidr: block.toString(),
    base: block.base,
    mask: block.mask,
    hostmask: block.hostmask,
    bitmask: block.bitmask,
    size: block.size,
    first: block.first,
    last: block.last,
    broadcast: block.broadcast
  };
}

function collectHosts(block) {
  const hosts = [];
  block.forEach((ip, longVal, index) => {
    hosts.push({ ip, longVal, index });
  });
  return hosts;
}

module.exports = {
  Netmask,
  ip2long,
  long2ip,
  parseBlock,
  summarizeBlock,
  collectHosts
};
test/contract.js
'use strict';

const assert = require('node:assert/strict');
const {
  Netmask,
  ip2long,
  long2ip,
  parseBlock,
  summarizeBlock,
  collectHosts
} = require('../src/index.js');

// 1. Parse IPv4 CIDR block and verify properties
const v4Block = parseBlock('192.0.2.5/24');
assert.deepEqual(summarizeBlock(v4Block), {
  cidr: '192.0.2.0/24',
  base: '192.0.2.0',
  mask: '255.255.255.0',
  hostmask: '0.0.0.255',
  bitmask: 24,
  size: 256,
  first: '192.0.2.1',
  last: '192.0.2.254',
  broadcast: '192.0.2.255'
});
assert.equal(v4Block.netLong, ip2long('192.0.2.0'));
assert.equal(v4Block.maskLong, ip2long('255.255.255.0'));

// 2. Parse IPv4 with separate dotted subnet mask
const dottedMaskBlock = parseBlock('198.51.100.77', '255.255.255.240');
assert.equal(dottedMaskBlock.toString(), '198.51.100.64/28');
assert.equal(dottedMaskBlock.size, 16);
assert.equal(dottedMaskBlock.first, '198.51.100.65');
assert.equal(dottedMaskBlock.last, '198.51.100.78');
assert.equal(dottedMaskBlock.broadcast, '198.51.100.79');

// 3. Verify /31 and /32 edge cases where broadcast is undefined
const slash31 = parseBlock('203.0.113.0/31');
assert.equal(slash31.size, 2);
assert.equal(slash31.first, '203.0.113.0');
assert.equal(slash31.last, '203.0.113.1');
assert.equal(slash31.broadcast, undefined);

const slash32 = parseBlock('203.0.113.9');
assert.equal(slash32.bitmask, 32);
assert.equal(slash32.size, 1);
assert.equal(slash32.first, '203.0.113.9');
assert.equal(slash32.last, '203.0.113.9');
assert.equal(slash32.broadcast, undefined);

// 4. Verify contains() for IPv4 addresses, CIDR strings, and Netmask instances
assert.equal(v4Block.contains('192.0.2.42'), true);
assert.equal(v4Block.contains('192.0.2.128/25'), true);
assert.equal(v4Block.contains(new Netmask('192.0.2.0/26')), true);
assert.equal(v4Block.contains('192.0.3.1'), false);
assert.equal(v4Block.contains('192.0.2.0/23'), false);

// 5. Verify next() advances to adjacent blocks
assert.equal(v4Block.next().toString(), '192.0.3.0/24');
assert.equal(v4Block.next(2).toString(), '192.0.4.0/24');

// 6. Verify forEach() iterates usable host addresses in order
const smallBlock = parseBlock('203.0.113.0/30');
const hosts = collectHosts(smallBlock);
assert.deepEqual(hosts, [
  { ip: '203.0.113.1', longVal: ip2long('203.0.113.1'), index: 0 },
  { ip: '203.0.113.2', longVal: ip2long('203.0.113.2'), index: 1 }
]);

// 7. Verify ip2long and long2ip round-trip and error on invalid IP
const numericIp = ip2long('192.0.2.1');
assert.equal(numericIp, 3221225985);
assert.equal(long2ip(numericIp), '192.0.2.1');
assert.throws(() => ip2long('999.0.0.1'), /Invalid IP/);

// 8. Verify IPv6 CIDR parsing, contains(), and next()
const v6Block = parseBlock('2001:db8::/32');
assert.equal(v6Block.toString(), '2001:db8::/32');
assert.equal(v6Block.base, '2001:db8::');
assert.equal(v6Block.bitmask, 32);
assert.equal(v6Block.first, '2001:db8::');
assert.equal(v6Block.last, '2001:db8:ffff:ffff:ffff:ffff:ffff:ffff');
assert.equal(v6Block.broadcast, undefined);
assert.equal(v6Block.contains('2001:db8::1'), true);
assert.equal(v6Block.contains('2001:db8:abcd::/48'), true);
assert.equal(v6Block.contains('2001:db9::1'), false);
assert.equal(v6Block.next().toString(), '2001:db9::/32');

// 9. Verify constructor validation errors
assert.throws(() => new Netmask(), /Missing `net' parameter/);
assert.throws(() => new Netmask('192.0.2.0/33'), /Invalid mask for ip4/);
assert.throws(() => new Netmask('2001:db8::/129'), /Invalid mask for IPv6/);

console.log('netmask@2.1.2 contract passed');

Ursprungs-Seeder

anonym