CodeSampleX

示例

ip-address 10.3.1: Address4

已验证示例 — npm ip-address 10.3.1: Address4. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: Address4.isValid validates valid IPv4 addresses and rejects…

sha256:71e025d6192c023d96e5183443349ea48708b1ad50535058c0eb3ba8d1300ffb

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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-09-02

案例

HOW
目标
verify Address4 in pkg:npm/ip-address@10.3.1
包
符号
  • Address4
环境
node 22.23.2
创建时间
2026-09-02T01:39:10Z

契约

  1. Address4.isValid validates valid IPv4 addresses and rejects invalid strings
  2. Address4 constructor parses IPv4 address and CIDR subnet mask correctly
  3. Address4 calculates startAddress, endAddress, and host boundaries for a given subnet
  4. Address4.isInSubnet determines whether an address belongs to a specified subnet
  5. Address4.fromAddressAndMask parses dotted-decimal subnet masks into CIDR prefix length
  6. Address4 bigInt and fromBigInt convert IPv4 addresses to and from 32-bit integers
  7. Address4 fromHex and toHex convert between hex string and Address4
  8. Address4 correctForm returns the normalized dotted-decimal IP address string
  9. Address4 throws AddressError when instantiated with an invalid IP address string

文件

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

下载源代码构件 (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 Address4 in pkg:npm/ip-address@10.3.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/ip-address@10.3.1
Demonstrate these symbols/APIs:
  - 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.
csx.json
{"case":{"caseId":"case:sha256:a7125e4289ac372feb06dbe385a4a0b9a5cd3afbe4159321ceedc85a82891b73","constraints":{"executionContext":"node"},"contract":["Address4.isValid validates valid IPv4 addresses and rejects invalid strings","Address4 constructor parses IPv4 address and CIDR subnet mask correctly","Address4 calculates startAddress, endAddress, and host boundaries for a given subnet","Address4.isInSubnet determines whether an address belongs to a specified subnet","Address4.fromAddressAndMask parses dotted-decimal subnet masks into CIDR prefix length","Address4 bigInt and fromBigInt convert IPv4 addresses to and from 32-bit integers","Address4 fromHex and toHex convert between hex string and Address4","Address4 correctForm returns the normalized dotted-decimal IP address string","Address4 throws AddressError when instantiated with an invalid IP address string"],"goal":"verify Address4 in pkg:npm/ip-address@10.3.1","kind":"HOW","packages":["pkg:npm/ip-address@10.3.1"],"schemaVersion":1,"symbols":["Address4"]},"contractCommand":["node","test/contract.cjs"],"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.3.1"],"schemaVersion":1,"subject":"pkg:npm/ip-address@10.3.1","symbols":["Address4"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "ip-address-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "ip-address-sample",
      "version": "1.0.0",
      "dependencies": {
        "ip-address": "10.3.1"
      }
    },
    "node_modules/ip-address": {
      "version": "10.3.1",
      "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.3.1.tgz",
      "integrity": "sha512-1e9d3kb97NHJTIJDZW9rKqW2h6+dFa50Dy0fpPSMQp2ADje5gvKsXmdiK6dwY5t76TaTt5+P5N1Y/LoToIxP6g==",
      "license": "MIT",
      "engines": {
        "node": ">= 12"
      }
    }
  }
}
package.json
{
  "name": "ip-address-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Verification sample for Address4 in ip-address 10.3.1",
  "dependencies": {
    "ip-address": "10.3.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify Address4 in pkg:npm/ip-address@10.3.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ip-address@10.3.1"
  ],
  "symbols": [
    "Address4"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require("node:assert/strict");
const { Address4, AddressError } = require("ip-address");

// 1. Address4.isValid validates valid IPv4 addresses and rejects invalid strings
assert.equal(Address4.isValid("192.168.1.100"), true);
assert.equal(Address4.isValid("10.0.0.1"), true);
assert.equal(Address4.isValid("127.0.0.1"), true);
assert.equal(Address4.isValid("999.1.1.1"), false);
assert.equal(Address4.isValid("256.0.0.1"), false);
assert.equal(Address4.isValid("invalid-ip"), false);
assert.equal(Address4.isValid(""), false);

// 2. Address4 constructor parses IPv4 address and CIDR subnet mask correctly
const ipv4 = new Address4("192.168.1.100/24");
assert.equal(ipv4.address, "192.168.1.100/24");
assert.equal(ipv4.subnet, "/24");
assert.equal(ipv4.subnetMask, 24);
assert.deepEqual(ipv4.parsedAddress, ["192", "168", "1", "100"]);

// 3. Address4 calculates startAddress, endAddress, and host boundaries for a given subnet
assert.equal(ipv4.startAddress().correctForm(), "192.168.1.0");
assert.equal(ipv4.endAddress().correctForm(), "192.168.1.255");
assert.equal(ipv4.startAddressExclusive().correctForm(), "192.168.1.1");
assert.equal(ipv4.endAddressExclusive().correctForm(), "192.168.1.254");

// 4. Address4.isInSubnet determines whether an address belongs to a specified subnet
const member4 = new Address4("192.168.1.50");
const nonMember4 = new Address4("192.168.2.1");
assert.equal(member4.isInSubnet(ipv4), true);
assert.equal(nonMember4.isInSubnet(ipv4), false);

// 5. Address4.fromAddressAndMask parses dotted-decimal subnet masks into CIDR prefix length
const v4FromMask = Address4.fromAddressAndMask("10.0.0.1", "255.255.0.0");
assert.equal(v4FromMask.subnetMask, 16);
assert.equal(v4FromMask.startAddress().correctForm(), "10.0.0.0");
assert.equal(v4FromMask.endAddress().correctForm(), "10.0.255.255");

// 6. Address4 bigInt and fromBigInt convert IPv4 addresses to and from 32-bit integers
const v4BigInt = ipv4.bigInt();
assert.equal(typeof v4BigInt, "bigint");
assert.equal(Address4.fromBigInt(v4BigInt).correctForm(), "192.168.1.100");

// 7. Address4 fromHex and toHex convert between hex string and Address4
const hex4 = ipv4.toHex();
const fromHex4 = Address4.fromHex(hex4);
assert.equal(fromHex4.correctForm(), "192.168.1.100");

// 8. Address4 correctForm returns the normalized dotted-decimal IP address string
const addrWithSubnet = new Address4("192.168.1.1/24");
assert.equal(addrWithSubnet.correctForm(), "192.168.1.1");
assert.equal(addrWithSubnet.isCorrect(), true);
const plainAddr = new Address4("10.0.0.1");
assert.equal(plainAddr.correctForm(), "10.0.0.1");

// 9. Address4 throws AddressError when instantiated with an invalid IP address string
assert.throws(
  () => new Address4("not-an-ip"),
  (err) => {
    return err instanceof AddressError || err.name === "AddressError" || /Invalid/i.test(err.message);
  }
);
assert.throws(
  () => new Address4("300.1.1.1"),
  (err) => {
    return err instanceof AddressError || err.name === "AddressError" || /Invalid/i.test(err.message);
  }
);
assert.throws(
  () => new Address4("192.168.001.001"),
  (err) => {
    return err instanceof AddressError || err.name === "AddressError" || /zeroes/i.test(err.message);
  }
);

console.log("Contract verified successfully.");

原始种子者

匿名