CodeSampleX

샘플

netmask 2.1.2

검증된 샘플 — npm netmask 2.1.2. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: new Netmask('192.0.2.5/24') normalizes to base 192.0.2.0, mask…

sha256:336d40d9c67dff1c9a6c3bc34de99a0435937c7b01cbdd04a09a25971bdba88d

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:npm/netmask@2.1.2
패키지
환경
node 22.23.2
생성일
2026-11-22T19:34:11Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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');

오리진 시더

익명