샘플
ip-address 10.7.7: Address4
검증된 샘플 — npm ip-address 10.7.7: Address4. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: Address4.isValid accepts valid IPv4 addresses with…
sha256:635bd579e67d1863ec5de0134629f0e3138df1c106351266445b91a19af73ebc
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-29 |
케이스
HOW- 목표
- verify ip-address.Address4 in pkg:npm/ip-address@10.7.7
- 심벌
-
- ip-address.Address4
- 환경
- node 22.23.2
- 생성일
- 2026-11-29T21:29:38Z
컨트랙트
- Address4.isValid accepts valid IPv4 addresses with optional CIDR suffixes and rejects out-of-range octets, invalid prefixes, leading zeroes, and malformed strings
- new Address4 parses CIDR and bare IPv4 addresses, computes networkForm, startAddress, endAddress, host bounds, subnetMaskAddress, and wildcardMask, and rejects leading zeroes with AddressError
- Address4.fromAddressAndMask, fromAddressAndWildcardMask, and fromWildcard build CIDR subnets from masks or trailing wildcards and throw AddressError on non-contiguous masks
- Address4.isInSubnet checks full subnet containment while isHostInSubnet checks host-bit containment ignoring the receiver's own CIDR suffix
- Address4.offset and nextNetwork shift addresses and advance to the next network while preserving the subnet mask
- Address4 round-trips via bigInt/fromBigInt, fromInteger, toHex/fromHex, toArray/fromByteArray, and reverseForm/fromArpa
- Address4 classification predicates (isPrivate, isLoopback, isDocumentation, isMulticast, isGlobal) accurately classify RFC IPv4 blocks
- Address4 throws AddressError on invalid address strings, out-of-range BigInt values, and invalid byte-array lengths
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
소스
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 ip-address.Address4 in pkg:npm/ip-address@10.7.7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ip-address@10.7.7
Demonstrate these symbols/APIs:
- ip-address.Address4
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.
{"case":{"caseId":"case:sha256:d6cf422d7adce39d05bff0c7e05bd83a2a532f5cb1d4e38b176a4ae72bae62ab","constraints":{"executionContext":"node"},"contract":["Address4.isValid accepts valid IPv4 addresses with optional CIDR suffixes and rejects out-of-range octets, invalid prefixes, leading zeroes, and malformed strings","new Address4 parses CIDR and bare IPv4 addresses, computes networkForm, startAddress, endAddress, host bounds, subnetMaskAddress, and wildcardMask, and rejects leading zeroes with AddressError","Address4.fromAddressAndMask, fromAddressAndWildcardMask, and fromWildcard build CIDR subnets from masks or trailing wildcards and throw AddressError on non-contiguous masks","Address4.isInSubnet checks full subnet containment while isHostInSubnet checks host-bit containment ignoring the receiver's own CIDR suffix","Address4.offset and nextNetwork shift addresses and advance to the next network while preserving the subnet mask","Address4 round-trips via bigInt/fromBigInt, fromInteger, toHex/fromHex, toArray/fromByteArray, and reverseForm/fromArpa","Address4 classification predicates (isPrivate, isLoopback, isDocumentation, isMulticast, isGlobal) accurately classify RFC IPv4 blocks","Address4 throws AddressError on invalid address strings, out-of-range BigInt values, and invalid byte-array lengths"],"goal":"verify ip-address.Address4 in pkg:npm/ip-address@10.7.7","kind":"HOW","packages":["pkg:npm/ip-address@10.7.7"],"schemaVersion":1,"symbols":["ip-address.Address4"]},"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/ip-address@10.7.7"],"schemaVersion":1,"subject":"pkg:npm/ip-address@10.7.7","symbols":["ip-address.Address4"],"verifierAdapter":"node-typescript@1"}
{
"name": "ip-address-address4-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ip-address-address4-sample",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"ip-address": "10.7.7"
}
},
"node_modules/ip-address": {
"version": "10.7.7",
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.7.tgz",
"integrity": "sha512-He15rAs4jip5AEAz7XM9L+S6Y8LBMIDj6YewbYuJfmDnOCKWb+3TLOGnHFBTAIW7wpm5ohtZ+Xyo5PEaG+O2vQ==",
"license": "MIT",
"engines": {
"node": ">= 12"
}
}
}
}
{
"name": "ip-address-address4-sample",
"version": "1.0.0",
"private": true,
"description": "Minimal verification sample for ip-address.Address4",
"license": "MIT-0",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"ip-address": "10.7.7"
}
}
{
"schemaVersion": 1,
"goal": "verify ip-address.Address4 in pkg:npm/ip-address@10.7.7",
"kind": "HOW",
"packages": [
"pkg:npm/ip-address@10.7.7"
],
"symbols": [
"ip-address.Address4"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const { Address4, AddressError } = require('ip-address');
function describeSubnet(cidr) {
const addr = new Address4(cidr);
return {
address: addr.correctForm(),
network: addr.networkForm(),
subnetMask: addr.subnetMask,
maskAddress: addr.subnetMaskAddress().correctForm(),
wildcardAddress: addr.wildcardMask().correctForm(),
start: addr.startAddress().correctForm(),
end: addr.endAddress().correctForm(),
firstHost: addr.startAddressExclusive().correctForm(),
lastHost: addr.endAddressExclusive().correctForm(),
};
}
function classifyAddress(input) {
const addr = new Address4(input);
return {
private: addr.isPrivate(),
loopback: addr.isLoopback(),
documentation: addr.isDocumentation(),
multicast: addr.isMulticast(),
global: addr.isGlobal(),
};
}
module.exports = {
Address4,
AddressError,
describeSubnet,
classifyAddress,
};
'use strict';
const assert = require('node:assert/strict');
const { Address4, AddressError } = require('ip-address');
const { describeSubnet, classifyAddress } = require('../src/index.js');
// 1. Address4.isValid validates IPv4 strings with optional CIDR and rejects invalid inputs
assert.equal(Address4.isValid('192.0.2.42'), true);
assert.equal(Address4.isValid('192.0.2.42/24'), true);
assert.equal(Address4.isValid('256.0.0.1'), false);
assert.equal(Address4.isValid('192.0.2.1/33'), false);
assert.equal(Address4.isValid('010.000.000.001'), false);
assert.equal(Address4.isValid('not-an-ip'), false);
// 2. Constructor parsing, canonical form, subnet boundaries, and mask forms
const summary = describeSubnet('192.0.2.42/24');
assert.equal(summary.address, '192.0.2.42');
assert.equal(summary.network, '192.0.2.0/24');
assert.equal(summary.subnetMask, 24);
assert.equal(summary.maskAddress, '255.255.255.0');
assert.equal(summary.wildcardAddress, '0.0.0.255');
assert.equal(summary.start, '192.0.2.0');
assert.equal(summary.end, '192.0.2.255');
assert.equal(summary.firstHost, '192.0.2.1');
assert.equal(summary.lastHost, '192.0.2.254');
const bareAddress = new Address4('10.0.0.1');
assert.equal(bareAddress.correctForm(), '10.0.0.1');
assert.equal(bareAddress.networkForm(), '10.0.0.1/32');
assert.throws(() => new Address4('010.000.000.001'), AddressError);
// 3. Alternative subnet constructors: dotted mask, wildcard mask, and wildcard pattern
const fromMask = Address4.fromAddressAndMask('198.51.100.17', '255.255.255.240');
assert.equal(fromMask.subnetMask, 28);
assert.equal(fromMask.networkForm(), '198.51.100.16/28');
const fromWildcardMask = Address4.fromAddressAndWildcardMask('10.20.30.1', '0.0.0.255');
assert.equal(fromWildcardMask.subnetMask, 24);
assert.equal(fromWildcardMask.networkForm(), '10.20.30.0/24');
const fromWildcard = Address4.fromWildcard('203.0.113.*');
assert.equal(fromWildcard.subnet, '/24');
assert.equal(fromWildcard.networkForm(), '203.0.113.0/24');
assert.throws(
() => Address4.fromAddressAndMask('192.0.2.1', '255.0.255.0'),
AddressError
);
// 4. Subnet membership: isInSubnet vs isHostInSubnet
const subnet24 = new Address4('192.0.2.0/24');
const hostInSubnet = new Address4('192.0.2.99');
const outsideSubnet = new Address4('198.51.100.1');
const broaderRange = new Address4('192.0.2.99/16');
assert.equal(hostInSubnet.isInSubnet(subnet24), true);
assert.equal(outsideSubnet.isInSubnet(subnet24), false);
assert.equal(broaderRange.isInSubnet(subnet24), false);
assert.equal(broaderRange.isHostInSubnet(subnet24), true);
// 5. Address arithmetic: offset and nextNetwork preserve subnet mask
const baseNet = new Address4('10.0.0.0/24');
assert.equal(baseNet.offset(5).correctForm(), '10.0.0.5');
assert.equal(baseNet.offset(5).subnetMask, 24);
assert.equal(baseNet.nextNetwork().networkForm(), '10.0.1.0/24');
// 6. Round-trip conversions: BigInt, integer, hex, byte array, and in-addr.arpa
const sample = new Address4('192.0.2.42');
const asBigInt = sample.bigInt();
assert.equal(asBigInt, 3221226026n);
assert.equal(Address4.fromBigInt(asBigInt).correctForm(), '192.0.2.42');
assert.equal(Address4.fromInteger(3221226026).correctForm(), '192.0.2.42');
const hex = sample.toHex();
assert.equal(hex, 'c0:00:02:2a');
assert.equal(Address4.fromHex(hex).correctForm(), '192.0.2.42');
const bytes = sample.toArray();
assert.deepEqual(bytes, [192, 0, 2, 42]);
assert.equal(Address4.fromByteArray(bytes).correctForm(), '192.0.2.42');
const arpa = sample.reverseForm();
assert.equal(arpa, '42.2.0.192.in-addr.arpa.');
assert.equal(Address4.fromArpa(arpa).correctForm(), '192.0.2.42');
// 7. Classification predicates for RFC special-purpose and global ranges
assert.deepEqual(classifyAddress('10.0.0.1'), {
private: true,
loopback: false,
documentation: false,
multicast: false,
global: false,
});
assert.deepEqual(classifyAddress('127.0.0.1'), {
private: false,
loopback: true,
documentation: false,
multicast: false,
global: false,
});
assert.deepEqual(classifyAddress('192.0.2.1'), {
private: false,
loopback: false,
documentation: true,
multicast: false,
global: false,
});
assert.deepEqual(classifyAddress('224.0.0.1'), {
private: false,
loopback: false,
documentation: false,
multicast: true,
global: false,
});
assert.deepEqual(classifyAddress('1.1.1.1'), {
private: false,
loopback: false,
documentation: false,
multicast: false,
global: true,
});
// 8. Invalid inputs throw AddressError
assert.throws(() => new Address4('999.999.999.999'), AddressError);
assert.throws(() => Address4.fromBigInt(-1n), AddressError);
assert.throws(() => Address4.fromByteArray([192, 0, 2]), AddressError);
오리진 시더
익명