CodeSampleX

Beispiel

netmask 2.1.2: ip2long

Verifiziertes Beispiel für npm netmask 2.1.2: ip2long. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand: ip2long converts dotted-quad…

sha256:0999423696f12df1d2bf676045613ffb056f05acfcf94735bcc948efb1b29873

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-23

Fall

HOW
Ziel
verify netmask.ip2long in pkg:npm/netmask@2.1.2
Pakete
Symbole
  • netmask.ip2long
Umgebung
node 22.23.2
Erstellt
2026-11-23T16:02:53Z

Contract

  1. ip2long converts dotted-quad IPv4 strings (0.0.0.0, 127.0.0.1, 192.0.2.1, 255.255.255.255) into unsigned 32-bit integers (0 through 4294967295)
  2. ip2long supports shorthand 1-, 2-, and 3-part inet_aton IPv4 forms (2130706433, 127.1, 192.0.513)
  3. ip2long parses hexadecimal (0x/0X) and leading-zero octal octets (0xc0.0x00.0x02.0x01, 0x7F000001, 0177.0.0.1)
  4. ip2long throws Error('Invalid IP') for out-of-range octets (256.0.0.1), >4 parts (1.2.3.4.5), empty strings, CIDR suffixes (192.0.2.1/24), and trailing invalid octal digits (018.0.0.1)
  5. ip2long throws Error('empty octet') for invalid leading-zero octets (08.0.0.1), trailing dots (192.0.2.), and IPv6 strings (::1)

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js

Quellartefakt herunterladen (tar.gz)

Quelltext

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 netmask.ip2long in pkg:npm/netmask@2.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/netmask@2.1.2
Demonstrate these symbols/APIs:
  - netmask.ip2long
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:bf9cedb3b07fb7830cd2fda6fd09a66fa11b4f68ccb0495423e921df5ad85052","constraints":{"executionContext":"node"},"contract":["ip2long converts dotted-quad IPv4 strings (0.0.0.0, 127.0.0.1, 192.0.2.1, 255.255.255.255) into unsigned 32-bit integers (0 through 4294967295)","ip2long supports shorthand 1-, 2-, and 3-part inet_aton IPv4 forms (2130706433, 127.1, 192.0.513)","ip2long parses hexadecimal (0x/0X) and leading-zero octal octets (0xc0.0x00.0x02.0x01, 0x7F000001, 0177.0.0.1)","ip2long throws Error('Invalid IP') for out-of-range octets (256.0.0.1), \u003e4 parts (1.2.3.4.5), empty strings, CIDR suffixes (192.0.2.1/24), and trailing invalid octal digits (018.0.0.1)","ip2long throws Error('empty octet') for invalid leading-zero octets (08.0.0.1), trailing dots (192.0.2.), and IPv6 strings (::1)"],"goal":"verify netmask.ip2long in pkg:npm/netmask@2.1.2","kind":"HOW","packages":["pkg:npm/netmask@2.1.2"],"schemaVersion":1,"symbols":["netmask.ip2long"]},"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/netmask@2.1.2"],"schemaVersion":1,"subject":"pkg:npm/netmask@2.1.2","symbols":["netmask.ip2long"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-netmask-ip2long",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-netmask-ip2long",
      "version": "1.0.0",
      "dependencies": {
        "netmask": "2.1.2"
      }
    },
    "node_modules/netmask": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/netmask/-/netmask-2.1.2.tgz",
      "integrity": "sha512-In/qjEgPWP3EEKRBrATKSHRCcempKN/gUl97rrB1mTreVQfvPGthTJVwNXwbQHtIzzLf1bYyh8M50xpeYk0r6Q==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4.0"
      }
    }
  }
}
package.json
{
  "name": "sample-netmask-ip2long",
  "version": "1.0.0",
  "private": true,
  "description": "Verify netmask.ip2long in netmask 2.1.2",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "netmask": "2.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify netmask.ip2long in pkg:npm/netmask@2.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/netmask@2.1.2"
  ],
  "symbols": [
    "netmask.ip2long"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const { ip2long } = require('netmask');

/**
 * Convert an IPv4 address string into an unsigned 32-bit integer using netmask.ip2long.
 * @param {string} ip
 * @returns {number}
 */
function parseIpv4(ip) {
  return ip2long(ip);
}

/**
 * Compare two IPv4 addresses by their unsigned 32-bit integer values.
 * @param {string} a
 * @param {string} b
 * @returns {number}
 */
function compareIpv4(a, b) {
  return ip2long(a) - ip2long(b);
}

module.exports = {
  parseIpv4,
  compareIpv4,
};
test/contract.js
'use strict';

const assert = require('node:assert/strict');
const { ip2long } = require('netmask');
const { parseIpv4, compareIpv4 } = require('../src/index');

// 1. Standard dotted-quad IPv4 addresses convert to unsigned 32-bit integers
assert.equal(ip2long('0.0.0.0'), 0);
assert.equal(ip2long('127.0.0.1'), 2130706433);
assert.equal(ip2long('192.0.2.1'), 3221225985);
assert.equal(ip2long('255.255.255.255'), 4294967295);
assert.equal(parseIpv4('198.51.100.1'), 3325256705);
assert.ok(compareIpv4('192.0.2.1', '203.0.113.1') < 0);

// 2. Shorthand 1-, 2-, and 3-part IPv4 forms are parsed per inet_aton rules
assert.equal(ip2long('2130706433'), 2130706433);
assert.equal(ip2long('127.1'), 2130706433);
assert.equal(ip2long('192.0.513'), 3221225985);

// 3. Hexadecimal (0x/0X) and octal (leading 0) octet encodings are supported
assert.equal(ip2long('0xc0.0x00.0x02.0x01'), 3221225985);
assert.equal(ip2long('0x7F000001'), 2130706433);
assert.equal(ip2long('0177.0.0.1'), 2130706433);

// 4. Invalid inputs, out-of-range octets, CIDR suffixes, and IPv6 addresses throw Error
assert.throws(() => ip2long('256.0.0.1'), { message: 'Invalid IP' });
assert.throws(() => ip2long('1.2.3.4.5'), { message: 'Invalid IP' });
assert.throws(() => ip2long(''), { message: 'Invalid IP' });
assert.throws(() => ip2long('192.0.2.1/24'), { message: 'Invalid IP' });
assert.throws(() => ip2long('018.0.0.1'), { message: 'Invalid IP' });
assert.throws(() => ip2long('08.0.0.1'), { message: 'empty octet' });
assert.throws(() => ip2long('192.0.2.'), { message: 'empty octet' });
assert.throws(() => ip2long('::1'), { message: 'empty octet' });

console.log('PASS: netmask.ip2long contract verified');

Ursprungs-Seeder

anonym