Exemple
ip-address 10.7.7: Address4
Échantillon vérifié pour npm ip-address 10.7.7: Address4. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.
sha256:635bd579e67d1863ec5de0134629f0e3138df1c106351266445b91a19af73ebc
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify ip-address.Address4 in pkg:npm/ip-address@10.7.7
- Paquets
- Symboles
-
- ip-address.Address4
- Environnement
- node 22.23.2
- Créé
- 2026-11-29T21:29:38Z
Contrat
- 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
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
Code source
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);
Seeder d'origine
anonyme