サンプル
ip-address 10.7.0
検証済みサンプル — npm ip-address 10.7.0. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: Address4.isInSubnet and Address4.isHostInSubnet verify IPv4…
sha256:760a5a0a98d5c16cf27a28b04723885ce6aa7ede111546309522a807f30d6ee0
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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:24:58Z
コントラクト
- Address4.isInSubnet and Address4.isHostInSubnet verify IPv4 address containment within CIDR network blocks
- Address4.startAddress and Address4.endAddress calculate IPv4 network and broadcast boundary addresses for CIDR subnets
- Address6.isInSubnet determines IPv6 address membership within IPv6 CIDR prefix blocks
- Address4.bigInt and Address6.bigInt convert IP addresses to BigInt numbers and reconstruct addresses via fromBigInt
- Address4.reverseForm and Address6.reverseForm generate in-addr.arpa and ip6.arpa reverse DNS PTR record names
ファイル
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
ソース
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.
{"case":{"caseId":"case:sha256:8f26cbdcc31726e2171356b78c5bee1d4be661ce20b1771bf957acd7c2d59aab","contract":["Address4.isInSubnet and Address4.isHostInSubnet verify IPv4 address containment within CIDR network blocks","Address4.startAddress and Address4.endAddress calculate IPv4 network and broadcast boundary addresses for CIDR subnets","Address6.isInSubnet determines IPv6 address membership within IPv6 CIDR prefix blocks","Address4.bigInt and Address6.bigInt convert IP addresses to BigInt numbers and reconstruct addresses via fromBigInt","Address4.reverseForm and Address6.reverseForm generate in-addr.arpa and ip6.arpa reverse DNS PTR record names"],"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"}
import { Address4, Address6 } from 'ip-address';
/**
* Checks whether an IPv4 address is contained in a given subnet.
* @param {string} ipString
* @param {string} subnetCidr
* @returns {{ inSubnet: boolean, isHostInSubnet: boolean }}
*/
export function checkIPv4Subnet(ipString, subnetCidr) {
const addr = new Address4(ipString);
const subnet = new Address4(subnetCidr);
return {
inSubnet: addr.isInSubnet(subnet),
isHostInSubnet: addr.isHostInSubnet(subnet)
};
}
/**
* Calculates network boundaries for an IPv4 CIDR subnet.
* @param {string} cidrString
* @returns {{ network: string, broadcast: string, firstHost: string, lastHost: string }}
*/
export function calculateIPv4Boundaries(cidrString) {
const cidr = new Address4(cidrString);
return {
network: cidr.startAddress().correctForm(),
broadcast: cidr.endAddress().correctForm(),
firstHost: cidr.startAddressExclusive().correctForm(),
lastHost: cidr.endAddressExclusive().correctForm()
};
}
/**
* Checks whether an IPv6 address is contained in a given IPv6 subnet.
* @param {string} ipString
* @param {string} subnetCidr
* @returns {{ inSubnet: boolean, startAddress: string, endAddress: string }}
*/
export function checkIPv6Subnet(ipString, subnetCidr) {
const addr = new Address6(ipString);
const subnet = new Address6(subnetCidr);
return {
inSubnet: addr.isInSubnet(subnet),
startAddress: subnet.startAddress().correctForm(),
endAddress: subnet.endAddress().correctForm()
};
}
/**
* Converts an IPv4 or IPv6 address to its BigInt numerical representation.
* @param {string} ipString
* @param {boolean} [isV6=false]
* @returns {bigint}
*/
export function ipToBigInt(ipString, isV6 = false) {
if (isV6) {
return new Address6(ipString).bigInt();
}
return new Address4(ipString).bigInt();
}
/**
* Reconstructs an address string from its BigInt numerical representation.
* @param {bigint} value
* @param {boolean} [isV6=false]
* @returns {string}
*/
export function ipFromBigInt(value, isV6 = false) {
if (isV6) {
return Address6.fromBigInt(value).correctForm();
}
return Address4.fromBigInt(value).correctForm();
}
/**
* Returns the reverse DNS ARPA domain for an IP address.
* @param {string} ipString
* @param {boolean} [isV6=false]
* @returns {string}
*/
export function getReverseDns(ipString, isV6 = false) {
if (isV6) {
return new Address6(ipString).reverseForm();
}
return new Address4(ipString).reverseForm();
}
{
"name": "ip-address-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ip-address-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"
}
}
}
}
{
"name": "ip-address-sample",
"version": "1.0.0",
"type": "module",
"license": "MIT-0",
"dependencies": {
"ip-address": "10.7.0"
},
"scripts": {
"test": "node test/contract.mjs"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/ip-address@10.7.0",
"kind": "HOW",
"packages": [
"pkg:npm/ip-address@10.7.0"
]
}
import assert from 'node:assert/strict';
import { Address4, Address6 } from 'ip-address';
import {
checkIPv4Subnet,
calculateIPv4Boundaries,
checkIPv6Subnet,
ipToBigInt,
ipFromBigInt,
getReverseDns
} from '../index.mjs';
// Contract 1: Address4.isInSubnet and Address4.isHostInSubnet verify IPv4 address containment within CIDR network blocks
{
const subnet = '192.168.1.0/24';
const inside = checkIPv4Subnet('192.168.1.42', subnet);
assert.equal(inside.inSubnet, true);
assert.equal(inside.isHostInSubnet, true);
const outside = checkIPv4Subnet('192.168.2.1', subnet);
assert.equal(outside.inSubnet, false);
assert.equal(outside.isHostInSubnet, false);
// Direct Address4 API
const cidr = new Address4('10.0.0.0/8');
const target1 = new Address4('10.254.1.1');
const target2 = new Address4('172.16.0.1');
assert.equal(target1.isInSubnet(cidr), true);
assert.equal(target1.isHostInSubnet(cidr), true);
assert.equal(target2.isInSubnet(cidr), false);
assert.equal(target2.isHostInSubnet(cidr), false);
}
// Contract 2: Address4.startAddress and Address4.endAddress calculate IPv4 network and broadcast boundary addresses for CIDR subnets
{
const bounds = calculateIPv4Boundaries('192.168.1.50/24');
assert.equal(bounds.network, '192.168.1.0');
assert.equal(bounds.broadcast, '192.168.1.255');
assert.equal(bounds.firstHost, '192.168.1.1');
assert.equal(bounds.lastHost, '192.168.1.254');
// Direct Address4 startAddress & endAddress API
const addr = new Address4('10.10.0.128/25');
assert.equal(addr.startAddress().correctForm(), '10.10.0.128');
assert.equal(addr.endAddress().correctForm(), '10.10.0.255');
assert.equal(addr.startAddressExclusive().correctForm(), '10.10.0.129');
assert.equal(addr.endAddressExclusive().correctForm(), '10.10.0.254');
}
// Contract 3: Address6.isInSubnet determines IPv6 address membership within IPv6 CIDR prefix blocks
{
const v6Subnet = '2001:db8:abcd::/48';
const v6Inside = checkIPv6Subnet('2001:db8:abcd:1234::1', v6Subnet);
assert.equal(v6Inside.inSubnet, true);
assert.equal(v6Inside.startAddress, '2001:db8:abcd::');
assert.equal(v6Inside.endAddress, '2001:db8:abcd:ffff:ffff:ffff:ffff:ffff');
const v6Outside = checkIPv6Subnet('2001:db8:cafe::1', v6Subnet);
assert.equal(v6Outside.inSubnet, false);
// Direct Address6 API
const prefix = new Address6('fe80::/10');
const linkLocal = new Address6('fe80::1');
const globalAddr = new Address6('2001:db8::1');
assert.equal(linkLocal.isInSubnet(prefix), true);
assert.equal(globalAddr.isInSubnet(prefix), false);
assert.equal(prefix.startAddress().correctForm(), 'fe80::');
}
// Contract 4: Address4.bigInt and Address6.bigInt convert IP addresses to BigInt numbers and reconstruct addresses via fromBigInt
{
const v4Str = '192.168.1.50';
const v4Big = ipToBigInt(v4Str);
assert.equal(v4Big, 3232235826n);
assert.equal(ipFromBigInt(v4Big), v4Str);
const v6Str = '2001:db8::1';
const v6Big = ipToBigInt(v6Str, true);
assert.equal(v6Big, 42540766411282592856903984951653826561n);
assert.equal(ipFromBigInt(v6Big, true), v6Str);
// Direct BigInt API
const addr4 = new Address4('127.0.0.1');
const directBig4 = addr4.bigInt();
assert.equal(directBig4, 2130706433n);
assert.equal(Address4.fromBigInt(directBig4).correctForm(), '127.0.0.1');
const addr6 = new Address6('::1');
const directBig6 = addr6.bigInt();
assert.equal(directBig6, 1n);
assert.equal(Address6.fromBigInt(directBig6).correctForm(), '::1');
}
// Contract 5: Address4.reverseForm and Address6.reverseForm generate in-addr.arpa and ip6.arpa reverse DNS PTR record names
{
const v4Arpa = getReverseDns('192.0.2.42');
assert.equal(v4Arpa, '42.2.0.192.in-addr.arpa.');
assert.equal(Address4.fromArpa(v4Arpa).correctForm(), '192.0.2.42');
const v6Arpa = getReverseDns('2001:db8::1', true);
assert.equal(v6Arpa, '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.');
assert.equal(Address6.fromArpa(v6Arpa).correctForm(), '2001:db8::1');
// Direct reverseForm API
const addr4 = new Address4('10.0.0.1');
assert.equal(addr4.reverseForm(), '1.0.0.10.in-addr.arpa.');
const addr6 = new Address6('::ffff:192.0.2.1');
assert.equal(
addr6.reverseForm(),
'1.0.2.0.0.0.0.c.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.'
);
}
console.log('All contract assertions verified successfully.');
オリジンシーダー
匿名