CodeSampleX

샘플

ip-address 10.7.3

검증된 샘플 — npm ip-address 10.7.3. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: Address4 parses IPv4 CIDR notation, computes startAddress and…

sha256:c8304ae129269c8e05baf0d38db62a7213965958166f4830f35ddda1f74ada5b

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

실행 증거

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

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

검증 실행 환경

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

케이스

HOW
목표
verify pkg:npm/ip-address@10.7.3
패키지
생성일
2026-11-03T21:49:09Z

컨트랙트

  1. Address4 parses IPv4 CIDR notation, computes startAddress and endAddress boundaries, and converts to/from BigInt
  2. Address4.prototype.isInSubnet and Address4.isValid check IPv4 subnet membership and syntax validity
  3. Address6 parses IPv6 CIDR notation, formats canonicalForm and correctForm strings, and computes subnet boundaries
  4. Address6.fromAddress4, to4in6, reverseForm, and fromArpa handle IPv4-mapped IPv6 and ip6.arpa reverse DNS
  5. Address4 and Address6 throw AddressError instances when instantiated with invalid address strings

파일

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

소스 아티팩트 내려받기 (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/ip-address@10.7.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/ip-address@10.7.3

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:635441be5c2821d4d61fd41c7126fd6c5196b8ff512d0708ecde863b0980e184","contract":["Address4 parses IPv4 CIDR notation, computes startAddress and endAddress boundaries, and converts to/from BigInt","Address4.prototype.isInSubnet and Address4.isValid check IPv4 subnet membership and syntax validity","Address6 parses IPv6 CIDR notation, formats canonicalForm and correctForm strings, and computes subnet boundaries","Address6.fromAddress4, to4in6, reverseForm, and fromArpa handle IPv4-mapped IPv6 and ip6.arpa reverse DNS","Address4 and Address6 throw AddressError instances when instantiated with invalid address strings"],"goal":"verify pkg:npm/ip-address@10.7.3","kind":"HOW","packages":["pkg:npm/ip-address@10.7.3"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/ip-address@10.7.3"],"schemaVersion":1,"subject":"pkg:npm/ip-address@10.7.3","verifierAdapter":"node-typescript@1"}
index.mjs
import { Address4, Address6, AddressError } from 'ip-address';

export function inspectIpv4Subnet(cidr) {
  const addr = new Address4(cidr);
  return {
    correctForm: addr.correctForm(),
    subnetMask: addr.subnetMask,
    startAddress: addr.startAddress().correctForm(),
    endAddress: addr.endAddress().correctForm(),
    bigInt: addr.bigInt()
  };
}

export function checkIpv4InSubnet(candidate, subnetCidr) {
  const host = new Address4(candidate);
  const net = new Address4(subnetCidr);
  return host.isInSubnet(net);
}

export function inspectIpv6Subnet(cidr) {
  const addr = new Address6(cidr);
  return {
    correctForm: addr.correctForm(),
    canonicalForm: addr.canonicalForm(),
    networkForm: addr.networkForm(),
    startAddress: addr.startAddress().correctForm(),
    endAddress: addr.endAddress().correctForm(),
    subnetMaskAddress: addr.subnetMaskAddress().correctForm(),
    bigInt: addr.bigInt()
  };
}

export function mapIpv4AndReverseIpv6(ipv4Str, ipv6Str) {
  const mapped = Address6.fromAddress4(ipv4Str);
  const v6 = new Address6(ipv6Str);
  const arpa = v6.reverseForm();
  const roundtripArpa = Address6.fromArpa(arpa);
  return {
    mappedCorrect: mapped.correctForm(),
    mapped4in6: mapped.to4in6(),
    arpa,
    roundtripArpa: roundtripArpa.correctForm()
  };
}

export { Address4, Address6, AddressError };
package-lock.json
{
  "name": "ip-address-verify-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "ip-address-verify-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "ip-address": "10.7.3"
      }
    },
    "node_modules/ip-address": {
      "version": "10.7.3",
      "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.3.tgz",
      "integrity": "sha512-A1kdq/tSb5QjvKvAMgIoEvDBIgL7qaqVP/jkvSwYYRZ9iEzvPpopxp2wQfu3SuZRHtpHNxMn8Fs0bS+gf5Xmwg==",
      "license": "MIT",
      "engines": {
        "node": ">= 12"
      }
    }
  }
}
package.json
{
  "name": "ip-address-verify-sample",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "ip-address": "10.7.3"
  },
  "scripts": {
    "test": "node test/contract.mjs"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/ip-address@10.7.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ip-address@10.7.3"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  Address4,
  Address6,
  AddressError,
  inspectIpv4Subnet,
  checkIpv4InSubnet,
  inspectIpv6Subnet,
  mapIpv4AndReverseIpv6
} from '../index.mjs';

// 1. Address4 parses IPv4 CIDR notation, computes start/end boundaries, and converts to/from BigInt
{
  const info = inspectIpv4Subnet('192.168.10.42/24');
  assert.equal(info.correctForm, '192.168.10.42');
  assert.equal(info.subnetMask, 24);
  assert.equal(info.startAddress, '192.168.10.0');
  assert.equal(info.endAddress, '192.168.10.255');
  assert.equal(info.bigInt, 3232238122n);

  const restored4 = Address4.fromBigInt(info.bigInt);
  assert.equal(restored4.correctForm(), '192.168.10.42');

  const masked = Address4.fromAddressAndMask('10.20.30.40', '255.255.0.0');
  assert.equal(masked.correctForm(), '10.20.30.40');
  assert.equal(masked.subnetMask, 16);
}

// 2. Address4.prototype.isInSubnet and Address4.isValid check subnet membership and syntax validity
{
  assert.equal(checkIpv4InSubnet('192.168.10.99', '192.168.10.0/24'), true);
  assert.equal(checkIpv4InSubnet('192.168.11.1', '192.168.10.0/24'), false);
  assert.equal(Address4.isValid('127.0.0.1'), true);
  assert.equal(Address4.isValid('999.0.0.1'), false);
}

// 3. Address6 parses IPv6 CIDR notation, formats canonical/compressed strings, and computes subnet boundaries
{
  const v6 = inspectIpv6Subnet('2001:0db8:0000:0042::0001/64');
  assert.equal(v6.correctForm, '2001:db8:0:42::1');
  assert.equal(v6.canonicalForm, '2001:0db8:0000:0042:0000:0000:0000:0001');
  assert.equal(v6.networkForm, '2001:db8:0:42::/64');
  assert.equal(v6.startAddress, '2001:db8:0:42::');
  assert.equal(v6.endAddress, '2001:db8:0:42:ffff:ffff:ffff:ffff');
  assert.equal(v6.subnetMaskAddress, 'ffff:ffff:ffff:ffff::');

  const restored6 = Address6.fromBigInt(v6.bigInt);
  assert.equal(restored6.correctForm(), '2001:db8:0:42::1');
  assert.equal(new Address6('2001:db8:0:42::cafe').isInSubnet(new Address6('2001:db8:0:42::/64')), true);
  assert.equal(new Address6('2001:db8:0:43::1').isInSubnet(new Address6('2001:db8:0:42::/64')), false);
}

// 4. Address6.fromAddress4, to4in6, reverseForm, and fromArpa handle IPv4-mapped IPv6 and ip6.arpa reverse DNS
{
  const res = mapIpv4AndReverseIpv6('172.16.0.5', '2001:db8::abcd');
  assert.equal(res.mappedCorrect, '::ffff:ac10:5');
  assert.equal(res.mapped4in6, '::ffff:172.16.0.5');
  assert.equal(res.arpa, 'd.c.b.a.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.');
  assert.equal(res.roundtripArpa, '2001:db8::abcd');
}

// 5. Address4 and Address6 throw AddressError on invalid address strings
{
  assert.throws(
    () => new Address4('256.300.1.1'),
    (err) => err instanceof AddressError && err.name === 'AddressError'
  );
  assert.throws(
    () => new Address6('2001:::1'),
    (err) => err instanceof AddressError && err.name === 'AddressError' && typeof err.parseMessage === 'string'
  );
}

오리진 시더

익명