CodeSampleX

샘플

ip-address 10.7.0

검증된 샘플 — npm ip-address 10.7.0. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: Address6.prototype.isInSubnet checks whether an IPv6 address…

sha256:b358959130ee3d79a180962ea4ffd49636e8a2cae5409b97da43eb5a76889157

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

케이스

HOW
목표
verify pkg:npm/ip-address@10.7.0
패키지
생성일
2026-09-07T00:32:50Z

컨트랙트

  1. Address6.prototype.isInSubnet checks whether an IPv6 address falls within a target subnet network
  2. Address6 subnet methods startAddress, endAddress, networkForm, and subnetMaskAddress compute network boundaries
  3. Address6.fromAddress4 converts an IPv4 address to an IPv6-mapped address and to4in6 formats it as dotted-decimal
  4. Address6.fromBigInt and bigInt perform lossless two-way conversion between 128-bit integers and IPv6 addresses
  5. Address6.reverseForm generates standard ip6.arpa domain names and Address6.fromArpa parses them back to Address6
  6. Address6.isValid validates full IPv6 addresses and CIDR subnets while rejecting invalid syntax and IPv4 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.0
Kind: HOW

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

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:36763bf9b4d3e14382b9624e95eeabc8401da4131e8b309d49fd3c0a2c1d8c3b","contract":["Address6.prototype.isInSubnet checks whether an IPv6 address falls within a target subnet network","Address6 subnet methods startAddress, endAddress, networkForm, and subnetMaskAddress compute network boundaries","Address6.fromAddress4 converts an IPv4 address to an IPv6-mapped address and to4in6 formats it as dotted-decimal","Address6.fromBigInt and bigInt perform lossless two-way conversion between 128-bit integers and IPv6 addresses","Address6.reverseForm generates standard ip6.arpa domain names and Address6.fromArpa parses them back to Address6","Address6.isValid validates full IPv6 addresses and CIDR subnets while rejecting invalid syntax and IPv4 strings"],"goal":"verify pkg:npm/ip-address@10.7.0","kind":"HOW","packages":["pkg:npm/ip-address@10.7.0"],"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.0"],"schemaVersion":1,"subject":"pkg:npm/ip-address@10.7.0","verifierAdapter":"node-typescript@1"}
index.mjs
import { Address6 } from 'ip-address';

/**
 * Checks if a candidate IPv6 address falls within a target subnet.
 *
 * @param {string} address - IPv6 address string.
 * @param {string} subnet - IPv6 network CIDR string.
 * @returns {boolean}
 */
export function isAddressInSubnet(address, subnet) {
  const addr = new Address6(address);
  const sub = new Address6(subnet);
  return addr.isInSubnet(sub);
}

/**
 * Calculates network boundaries for an IPv6 CIDR prefix.
 *
 * @param {string} cidrString - IPv6 CIDR string.
 * @returns {{ start: string, end: string, network: string, mask: string, wildcard: string }}
 */
export function getSubnetBoundaries(cidrString) {
  const addr = new Address6(cidrString);
  return {
    start: addr.startAddress().correctForm(),
    end: addr.endAddress().correctForm(),
    network: addr.networkForm(),
    mask: addr.subnetMaskAddress().correctForm(),
    wildcard: addr.wildcardMask().correctForm()
  };
}

/**
 * Maps an IPv4 address string to an IPv6-mapped address and formats it.
 *
 * @param {string} ipv4String - IPv4 dotted-decimal string.
 * @returns {{ mapped: string, dotted: string }}
 */
export function mapIpv4ToIpv6(ipv4String) {
  const addr6 = Address6.fromAddress4(ipv4String);
  return {
    mapped: addr6.correctForm(),
    dotted: addr6.to4in6()
  };
}

/**
 * Converts between a BigInt and an Address6 instance.
 *
 * @param {string | bigint} value
 * @returns {{ bigInt: bigint, correctForm: string }}
 */
export function convertBigIntIpv6(value) {
  if (typeof value === 'bigint') {
    const addr = Address6.fromBigInt(value);
    return { bigInt: value, correctForm: addr.correctForm() };
  }
  const addr = new Address6(value);
  return { bigInt: addr.bigInt(), correctForm: addr.correctForm() };
}

/**
 * Formats an IPv6 address as an ip6.arpa reverse DNS domain and parses it back.
 *
 * @param {string} address - IPv6 address string.
 * @returns {{ reverse: string, parsed: string }}
 */
export function handleReverseDns(address) {
  const addr = new Address6(address);
  const reverse = addr.reverseForm();
  const parsed = Address6.fromArpa(reverse);
  return {
    reverse,
    parsed: parsed.correctForm()
  };
}

/**
 * Validates whether the given string is a valid IPv6 address or CIDR notation.
 *
 * @param {string} input - Address string to validate.
 * @returns {boolean}
 */
export function validateIpv6(input) {
  return Address6.isValid(input);
}

export { Address6 };
package-lock.json
{
  "name": "ip-address-ipv6-subnet-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "ip-address-ipv6-subnet-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "ip-address": "10.7.0"
      }
    },
    "node_modules/ip-address": {
      "version": "10.7.0",
      "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.0.tgz",
      "integrity": "sha512-BGFsyJd5mpXp3rK6jIdADLNgpJUK1jnjzvYF8lK+VyDab9JAmqN0YOKDdP17HlgKb2+ehPgDc8EtnRLbGCAMhA==",
      "license": "MIT",
      "engines": {
        "node": ">= 12"
      }
    }
  }
}
package.json
{
  "name": "ip-address-ipv6-subnet-sample",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "ip-address": "10.7.0"
  },
  "scripts": {
    "test": "node test/contract.mjs"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/ip-address@10.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ip-address@10.7.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  Address6,
  isAddressInSubnet,
  getSubnetBoundaries,
  mapIpv4ToIpv6,
  convertBigIntIpv6,
  handleReverseDns,
  validateIpv6
} from '../index.mjs';

// Contract 1: Address6.prototype.isInSubnet checks whether an IPv6 address falls within a target subnet network
{
  const targetSubnet = new Address6('2001:db8::/32');
  const insideHost = new Address6('2001:db8:abcd::1');
  const edgeHost = new Address6('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff');
  const outsideHost = new Address6('2001:db9::1');

  assert.equal(insideHost.isInSubnet(targetSubnet), true);
  assert.equal(edgeHost.isInSubnet(targetSubnet), true);
  assert.equal(outsideHost.isInSubnet(targetSubnet), false);

  assert.equal(isAddressInSubnet('2001:db8:1234::1', '2001:db8::/32'), true);
  assert.equal(isAddressInSubnet('fe80::1', '2001:db8::/32'), false);
}

// Contract 2: Address6 subnet methods startAddress, endAddress, networkForm, and subnetMaskAddress compute network boundaries
{
  const cidr = new Address6('2001:db8:abcd:1234::5/64');
  assert.equal(cidr.startAddress().correctForm(), '2001:db8:abcd:1234::');
  assert.equal(cidr.endAddress().correctForm(), '2001:db8:abcd:1234:ffff:ffff:ffff:ffff');
  assert.equal(cidr.networkForm(), '2001:db8:abcd:1234::/64');
  assert.equal(cidr.subnetMaskAddress().correctForm(), 'ffff:ffff:ffff:ffff::');
  assert.equal(cidr.wildcardMask().correctForm(), '::ffff:ffff:ffff:ffff');

  const bounds = getSubnetBoundaries('2001:db8:abcd:1234::5/64');
  assert.equal(bounds.start, '2001:db8:abcd:1234::');
  assert.equal(bounds.end, '2001:db8:abcd:1234:ffff:ffff:ffff:ffff');
  assert.equal(bounds.network, '2001:db8:abcd:1234::/64');
  assert.equal(bounds.mask, 'ffff:ffff:ffff:ffff::');
  assert.equal(bounds.wildcard, '::ffff:ffff:ffff:ffff');
}

// Contract 3: Address6.fromAddress4 converts an IPv4 address to an IPv6-mapped address and to4in6 formats it as dotted-decimal
{
  const v4Str = '192.168.1.100';
  const mapped = Address6.fromAddress4(v4Str);
  assert.equal(mapped.correctForm(), '::ffff:c0a8:164');
  assert.equal(mapped.to4in6(), '::ffff:192.168.1.100');

  const helperRes = mapIpv4ToIpv6('10.0.0.1');
  assert.equal(helperRes.mapped, '::ffff:a00:1');
  assert.equal(helperRes.dotted, '::ffff:10.0.0.1');
}

// Contract 4: Address6.fromBigInt and bigInt perform lossless two-way conversion between 128-bit integers and IPv6 addresses
{
  const original = new Address6('2001:db8::1');
  const bi = original.bigInt();
  assert.equal(bi, 42540766411282592856903984951653826561n);

  const restored = Address6.fromBigInt(bi);
  assert.equal(restored.correctForm(), '2001:db8::1');

  const helper = convertBigIntIpv6('::1');
  assert.equal(helper.bigInt, 1n);
  assert.equal(helper.correctForm, '::1');

  const helperFromBi = convertBigIntIpv6(1n);
  assert.equal(helperFromBi.bigInt, 1n);
  assert.equal(helperFromBi.correctForm, '::1');
}

// Contract 5: Address6.reverseForm generates standard ip6.arpa domain names and Address6.fromArpa parses them back to Address6
{
  const addr = new Address6('2001:db8::1');
  const reverseStr = addr.reverseForm();
  assert.equal(reverseStr, '1.0.0.0.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.');

  const parsedBack = Address6.fromArpa(reverseStr);
  assert.equal(parsedBack.correctForm(), '2001:db8::1');

  const dnsHelper = handleReverseDns('2001:db8::abcd');
  assert.equal(dnsHelper.reverse, '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(dnsHelper.parsed, '2001:db8::abcd');
}

// Contract 6: Address6.isValid validates full IPv6 addresses and CIDR subnets while rejecting invalid syntax and IPv4 strings
{
  assert.equal(validateIpv6('2001:db8::1'), true);
  assert.equal(validateIpv6('2001:db8::/32'), true);
  assert.equal(validateIpv6('::1'), true);
  assert.equal(validateIpv6('fe80::1ff:fe23:4567:890a'), true);

  assert.equal(validateIpv6('192.168.1.1'), false);
  assert.equal(validateIpv6('2001:::1'), false);
  assert.equal(validateIpv6('invalid-ip-string'), false);
  assert.equal(validateIpv6(''), false);
}

console.log('All contract assertions verified successfully.');

오리진 시더

익명