CodeSampleX

Ejemplo

socks 2.8.11

Muestra verificada para npm socks 2.8.11. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: SocksClient.createConnection completes a…

sha256:761cb552b31a0107692ad822cbc3fbda1685f5a2910bd96b5a6e17e1f418c27d

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-21

Caso

HOW
Objetivo
verify pkg:npm/socks@2.8.11
Paquetes
Entorno
node 22.23.2
Creado
2026-11-21T17:22:28Z

Contrato

  1. SocksClient.createConnection completes a SOCKS5 NoAuth CONNECT handshake over an existing_socket Duplex stream and resolves with the established socket and bound remoteHost.
  2. new SocksClient(options).connect() negotiates a SOCKS4a CONNECT handshake against a local loopback server and emits an established event with an active net.Socket.
  3. SocksClient.createUDPFrame and SocksClient.parseUDPFrame round-trip IPv4, IPv6 (decoded in canonical expanded form), and hostname UDP frames preserving frameNumber, remoteHost, and Buffer data.
  4. SocksClient.createConnection rejects with SocksClientError (retaining options) for invalid commands or invalid proxy types.

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 pkg:npm/socks@2.8.11
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/socks@2.8.11
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:a97c3c0478f9f9d560225cbad564b3cedfabf6d91303e856b73b87abc6df3704","constraints":{"executionContext":"node"},"contract":["SocksClient.createConnection completes a SOCKS5 NoAuth CONNECT handshake over an existing_socket Duplex stream and resolves with the established socket and bound remoteHost.","new SocksClient(options).connect() negotiates a SOCKS4a CONNECT handshake against a local loopback server and emits an established event with an active net.Socket.","SocksClient.createUDPFrame and SocksClient.parseUDPFrame round-trip IPv4, IPv6 (decoded in canonical expanded form), and hostname UDP frames preserving frameNumber, remoteHost, and Buffer data.","SocksClient.createConnection rejects with SocksClientError (retaining options) for invalid commands or invalid proxy types."],"goal":"verify pkg:npm/socks@2.8.11","kind":"HOW","packages":["pkg:npm/socks@2.8.11"],"schemaVersion":1},"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/socks@2.8.11"],"schemaVersion":1,"subject":"pkg:npm/socks@2.8.11","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-socks-2-8-11",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-socks-2-8-11",
      "version": "1.0.0",
      "dependencies": {
        "socks": "2.8.11"
      }
    },
    "node_modules/ip-address": {
      "version": "10.7.6",
      "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.6.tgz",
      "integrity": "sha512-00LYkM6byILa9eQIx6qoaXCM40xTLd56AZ4vyaPW3YTyb49VZYPo5xsiAq4tuQ54GH4R7gVdYScJ1B7B77PuTg==",
      "license": "MIT",
      "engines": {
        "node": ">= 12"
      }
    },
    "node_modules/smart-buffer": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
      "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==",
      "license": "MIT",
      "engines": {
        "node": ">= 6.0.0",
        "npm": ">= 3.0.0"
      }
    },
    "node_modules/socks": {
      "version": "2.8.11",
      "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.11.tgz",
      "integrity": "sha512-2H/uQ7+SNP0hK16RorTak0mWrFoqo4AnAVGSUl2dT07obgWdWt9grml+VDl1LklgUOPWM4Abo0u86Cvp8vFjYw==",
      "license": "MIT",
      "dependencies": {
        "ip-address": "^10.1.1",
        "smart-buffer": "^4.2.0"
      },
      "engines": {
        "node": ">= 10.0.0",
        "npm": ">= 3.0.0"
      }
    }
  }
}
package.json
{
  "name": "verify-socks-2-8-11",
  "version": "1.0.0",
  "private": true,
  "type": "commonjs",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "socks": "2.8.11"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/socks@2.8.11",
  "kind": "HOW",
  "packages": [
    "pkg:npm/socks@2.8.11"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const net = require('node:net');
const { Duplex } = require('node:stream');
const { SocksClient, SocksClientError } = require('socks');

async function verifySocks5CreateConnection() {
  const sent = [];
  const tunnel = new Duplex({
    read() {},
    write(chunk, _encoding, callback) {
      const buf = Buffer.from(chunk);
      sent.push(buf);
      if (sent.length === 1) {
        setImmediate(() => {
          tunnel.push(Buffer.from([0x05, 0x00]));
        });
      } else if (sent.length === 2) {
        setImmediate(() => {
          tunnel.push(Buffer.from([0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x04, 0x38]));
        });
      }
      callback();
    },
  });

  const result = await SocksClient.createConnection({
    proxy: { host: '127.0.0.1', port: 1080, type: 5 },
    command: 'connect',
    destination: { host: 'example.com', port: 443 },
    existing_socket: tunnel,
  });

  assert.equal(result.socket, tunnel);
  assert.deepEqual(result.remoteHost, { host: '127.0.0.1', port: 1080 });
  assert.equal(sent.length, 2);
  assert.deepEqual(sent[0], Buffer.from([0x05, 0x01, 0x00]));
  assert.equal(sent[1][0], 0x05);
  assert.equal(sent[1][1], 0x01);
  assert.equal(sent[1][3], 0x03);
  assert.equal(sent[1].subarray(5, 5 + sent[1][4]).toString('utf8'), 'example.com');
  assert.equal(sent[1].readUInt16BE(5 + sent[1][4]), 443);
}

async function verifySocks4aEventClient() {
  let receivedRequest = Buffer.alloc(0);

  const server = net.createServer((socket) => {
    socket.on('data', (chunk) => {
      receivedRequest = Buffer.concat([receivedRequest, chunk]);
      // SOCKS4a: VN(1) CD(1) DSTPORT(2) DSTIP(4=0.0.0.1) USERID(NUL) HOSTNAME(NUL)
      if (receivedRequest.length >= 10 && receivedRequest[receivedRequest.length - 1] === 0x00) {
        // Granted reply: VN=0x00, CD=0x5a (90), port=80, ip=127.0.0.1
        socket.write(Buffer.from([0x00, 0x5a, 0x00, 0x50, 127, 0, 0, 1]));
      }
    });
  });

  await new Promise((resolve, reject) => {
    server.once('error', reject);
    server.listen(0, '127.0.0.1', resolve);
  });

  try {
    const address = server.address();
    assert.ok(address && typeof address === 'object');

    const client = new SocksClient({
      proxy: { host: '127.0.0.1', port: address.port, type: 4 },
      command: 'connect',
      destination: { host: 'example.com', port: 80 },
      timeout: 5000,
    });

    const info = await new Promise((resolve, reject) => {
      client.once('established', resolve);
      client.once('error', reject);
      client.connect();
    });

    assert.ok(info.socket instanceof net.Socket);
    assert.equal(receivedRequest[0], 0x04);
    assert.equal(receivedRequest[1], 0x01);
    assert.equal(receivedRequest.readUInt16BE(2), 80);
    assert.deepEqual(receivedRequest.subarray(4, 8), Buffer.from([0, 0, 0, 1]));
    assert.ok(receivedRequest.includes(Buffer.from('example.com\0', 'utf8')));

    info.socket.destroy();
  } finally {
    await new Promise((resolve) => server.close(resolve));
  }
}

function verifyUdpFrames() {
  const cases = [
    {
      frameNumber: 0,
      remoteHost: { host: '127.0.0.1', port: 5353 },
      data: Buffer.from('ipv4-payload'),
    },
    {
      frameNumber: 2,
      remoteHost: { host: '::1', port: 8443 },
      data: Buffer.from('ipv6-payload'),
    },
    {
      frameNumber: 5,
      remoteHost: { host: 'example.com', port: 8080 },
      data: Buffer.from('host-payload'),
    },
  ];

  for (const item of cases) {
    const encoded = SocksClient.createUDPFrame(item);
    assert.ok(Buffer.isBuffer(encoded));

    const decoded = SocksClient.parseUDPFrame(encoded);
    assert.equal(decoded.frameNumber, item.frameNumber);
    assert.equal(decoded.remoteHost.port, item.remoteHost.port);
    if (item.remoteHost.host === '::1') {
      assert.equal(decoded.remoteHost.host, '0000:0000:0000:0000:0000:0000:0000:0001');
    } else {
      assert.equal(decoded.remoteHost.host, item.remoteHost.host);
    }
    assert.deepEqual(decoded.data, item.data);
  }
}

async function verifyOptionValidation() {
  await assert.rejects(
    () =>
      SocksClient.createConnection({
        proxy: { host: '127.0.0.1', port: 1080, type: 5 },
        command: 'bind',
        destination: { host: 'example.com', port: 443 },
      }),
    (err) => {
      assert.ok(err instanceof SocksClientError);
      assert.ok(err instanceof Error);
      assert.equal(err.options.command, 'bind');
      return true;
    }
  );

  await assert.rejects(
    () =>
      SocksClient.createConnection({
        proxy: { host: '127.0.0.1', port: 1080, type: 3 },
        command: 'connect',
        destination: { host: 'example.com', port: 443 },
      }),
    (err) => {
      assert.ok(err instanceof SocksClientError);
      assert.equal(err.options.proxy.type, 3);
      return true;
    }
  );
}

async function main() {
  await verifySocks5CreateConnection();
  await verifySocks4aEventClient();
  verifyUdpFrames();
  await verifyOptionValidation();
}

main().catch((err) => {
  console.error(err);
  process.exitCode = 1;
});

Seeder de origen

anónimo