CodeSampleX

Beispiel

socks-proxy-agent 7.0.0: SocksProxyAgent

Verifiziertes Beispiel für npm socks-proxy-agent 7.0.0: SocksProxyAgent. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:e4a256a4b8567b57773ea09728c6ddbc198427c7361764872a5e473a8914dfb0

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 linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-28

Fall

HOW
Ziel
verify SocksProxyAgent in pkg:npm/socks-proxy-agent@7.0.0
Pakete
Symbole
  • SocksProxyAgent
Erstellt
2026-08-28T07:44:30Z

Contract

  1. SocksProxyAgent is exported as a constructor class
  2. SocksProxyAgent constructor initializes agent instance with SOCKS5 URI string and port
  3. SocksProxyAgent constructor accepts WHATWG URL instance and configures DNS resolution based on protocol variant
  4. SocksProxyAgent parses URL credentials into non-enumerable userId and password properties on proxy configuration
  5. SocksProxyAgent constructor accepts options object with hostname, port, and timeout
  6. SocksProxyAgent throws TypeError when initialized without host or with unsupported protocol
  7. SocksProxyAgent connects through SOCKS5 proxy server and routes HTTP client request offline

Dateien

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

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 SocksProxyAgent in pkg:npm/socks-proxy-agent@7.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/socks-proxy-agent@7.0.0
Demonstrate these symbols/APIs:
  - SocksProxyAgent

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:be64a593a1a71b623959da82a5e7c80bb7a714284cceb889ffa59bac022d1ee6","contract":["SocksProxyAgent is exported as a constructor class","SocksProxyAgent constructor initializes agent instance with SOCKS5 URI string and port","SocksProxyAgent constructor accepts WHATWG URL instance and configures DNS resolution based on protocol variant","SocksProxyAgent parses URL credentials into non-enumerable userId and password properties on proxy configuration","SocksProxyAgent constructor accepts options object with hostname, port, and timeout","SocksProxyAgent throws TypeError when initialized without host or with unsupported protocol","SocksProxyAgent connects through SOCKS5 proxy server and routes HTTP client request offline"],"goal":"verify SocksProxyAgent in pkg:npm/socks-proxy-agent@7.0.0","kind":"HOW","packages":["pkg:npm/socks-proxy-agent@7.0.0"],"schemaVersion":1,"symbols":["SocksProxyAgent"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/socks-proxy-agent@7.0.0"],"schemaVersion":1,"subject":"pkg:npm/socks-proxy-agent@7.0.0","symbols":["SocksProxyAgent"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-socks-proxy-agent",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-socks-proxy-agent",
      "version": "1.0.0",
      "dependencies": {
        "socks-proxy-agent": "7.0.0"
      }
    },
    "node_modules/agent-base": {
      "version": "6.0.2",
      "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",
      "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",
      "license": "MIT",
      "dependencies": {
        "debug": "4"
      },
      "engines": {
        "node": ">= 6.0.0"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/ip-address": {
      "version": "10.5.0",
      "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.5.0.tgz",
      "integrity": "sha512-R5SnVLJmgYYvf2F2ZgwSBnelz5G4q5AxIC277GDfUaNbrZKNANcBC7RHqYYePlszf4kBolVkJauG0ZjHHFh55g==",
      "license": "MIT",
      "engines": {
        "node": ">= 12"
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "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.9",
      "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.9.tgz",
      "integrity": "sha512-LJhUYUvItdQ0LkJTmPeaEObWXAqFyfmP85x0tch/ez9cahmhlBBLbIqDFnvBnUJGagb0JbIQrkBs1wJ+yRYpEw==",
      "license": "MIT",
      "dependencies": {
        "ip-address": "^10.1.1",
        "smart-buffer": "^4.2.0"
      },
      "engines": {
        "node": ">= 10.0.0",
        "npm": ">= 3.0.0"
      }
    },
    "node_modules/socks-proxy-agent": {
      "version": "7.0.0",
      "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-7.0.0.tgz",
      "integrity": "sha512-Fgl0YPZ902wEsAyiQ+idGd1A7rSFx/ayC1CQVMw5P+EQx2V0SgpGtf6OKFhVjPflPUl9YMmEOnmfjCdMUsygww==",
      "license": "MIT",
      "dependencies": {
        "agent-base": "^6.0.2",
        "debug": "^4.3.3",
        "socks": "^2.6.2"
      },
      "engines": {
        "node": ">= 10"
      }
    }
  }
}
package.json
{
  "name": "sample-socks-proxy-agent",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "socks-proxy-agent": "7.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify SocksProxyAgent in pkg:npm/socks-proxy-agent@7.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/socks-proxy-agent@7.0.0"
  ],
  "symbols": [
    "SocksProxyAgent"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import net from 'node:net';
import http from 'node:http';
import { SocksProxyAgent } from 'socks-proxy-agent';

// 1. SocksProxyAgent is exported as a constructor class
assert.equal(typeof SocksProxyAgent, 'function');

// 2. SocksProxyAgent constructor initializes agent instance with SOCKS5 URI string and port
const agentSocks5 = new SocksProxyAgent('socks5://localhost:1080');
assert.ok(agentSocks5 instanceof SocksProxyAgent);
assert.equal(agentSocks5.proxy.host, 'localhost');
assert.equal(agentSocks5.proxy.port, 1080);
assert.equal(agentSocks5.proxy.type, 5);
assert.equal(agentSocks5.shouldLookup, true);

// 3. SocksProxyAgent constructor accepts WHATWG URL instance and configures DNS resolution based on protocol variant
const urlSocks5h = new URL('socks5h://proxy.example.com:9050');
const agentSocks5h = new SocksProxyAgent(urlSocks5h);
assert.equal(agentSocks5h.proxy.host, 'proxy.example.com');
assert.equal(agentSocks5h.proxy.port, 9050);
assert.equal(agentSocks5h.proxy.type, 5);
assert.equal(agentSocks5h.shouldLookup, false);

const agentSocks4 = new SocksProxyAgent('socks4://proxy.example.com:1080');
assert.equal(agentSocks4.proxy.type, 4);
assert.equal(agentSocks4.shouldLookup, true);

const agentSocks4a = new SocksProxyAgent('socks4a://proxy.example.com:1080');
assert.equal(agentSocks4a.proxy.type, 4);
assert.equal(agentSocks4a.shouldLookup, false);

// 4. SocksProxyAgent parses URL credentials into non-enumerable userId and password properties on proxy configuration
const agentWithAuth = new SocksProxyAgent('socks5://myuser:mypassword@proxy.example.com:1080');
assert.equal(agentWithAuth.proxy.userId, 'myuser');
assert.equal(agentWithAuth.proxy.password, 'mypassword');
assert.equal(Object.keys(agentWithAuth.proxy).includes('userId'), false);
assert.equal(Object.keys(agentWithAuth.proxy).includes('password'), false);

// 5. SocksProxyAgent constructor accepts options object with hostname, port, and timeout
const agentWithOptions = new SocksProxyAgent({ hostname: 'localhost', port: 1080 }, { timeout: 5000 });
assert.equal(agentWithOptions.proxy.host, 'localhost');
assert.equal(agentWithOptions.proxy.port, 1080);
assert.equal(agentWithOptions.timeout, 5000);

// 6. SocksProxyAgent throws TypeError when initialized without host or with unsupported protocol
assert.throws(
  () => new SocksProxyAgent('http://localhost:8080'),
  TypeError
);
assert.throws(
  () => new SocksProxyAgent({ port: 1080 }),
  TypeError
);

// 7. SocksProxyAgent connects through SOCKS5 proxy server and routes HTTP client request offline
const mockSocksServer = net.createServer((socket) => {
  let state = 0;
  socket.on('data', (data) => {
    if (state === 0) {
      if (data[0] === 0x05) {
        state = 1;
        socket.write(Buffer.from([0x05, 0x00])); // NO_AUTH
      }
    } else if (state === 1) {
      if (data[0] === 0x05 && data[1] === 0x01) {
        state = 2;
        // Reply success: VER=05, REP=00, RSV=00, ATYP=01 (IPv4), BND.ADDR=127.0.0.1, BND.PORT=1080
        socket.write(Buffer.from([0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x04, 0x38]));
      }
    } else if (state === 2) {
      socket.write('HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 13\r\n\r\nHello, SOCKS!');
    }
  });
});

await new Promise((resolve) => mockSocksServer.listen(0, '127.0.0.1', resolve));
const { port: proxyPort } = mockSocksServer.address();

try {
  const agent = new SocksProxyAgent(`socks5h://127.0.0.1:${proxyPort}`);
  const resBody = await new Promise((resolve, reject) => {
    http.get('http://example.com/test', { agent }, (res) => {
      let body = '';
      res.on('data', (chunk) => {
        body += chunk;
      });
      res.on('end', () => resolve(body));
    }).on('error', reject);
  });
  assert.equal(resBody, 'Hello, SOCKS!');
} finally {
  await new Promise((resolve) => mockSocksServer.close(resolve));
}

Ursprungs-Seeder

anonym