CodeSampleX

サンプル

socks-proxy-agent 8.0.5: SocksProxyAgent

検証済みサンプル — npm socks-proxy-agent 8.0.5: SocksProxyAgent. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: SocksProxyAgent static protocols…

sha256:60b500a40bda83f4d547fed19f8b807e43c2f8c1db7d401f628397a080c5c5c3

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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-27

ケース

HOW
ゴール
verify socks-proxy-agent.SocksProxyAgent in pkg:npm/socks-proxy-agent@8.0.5
パッケージ
シンボル
  • socks-proxy-agent.SocksProxyAgent
作成日
2026-08-27T10:25:14Z

コントラクト

  1. SocksProxyAgent static protocols property includes supported SOCKS protocol schemes
  2. SocksProxyAgent constructor initializes agent instance with SOCKS5 URI string and defaults port to 1080
  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 agent options including timeout and socketOptions
  6. SocksProxyAgent throws TypeError when initialized with unsupported protocol
  7. SocksProxyAgent connects through SOCKS5 proxy server and routes HTTP client request offline

ファイル

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

ソースアーティファクトをダウンロード (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 socks-proxy-agent.SocksProxyAgent in pkg:npm/socks-proxy-agent@8.0.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/socks-proxy-agent@8.0.5
Demonstrate these symbols/APIs:
  - socks-proxy-agent.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:2f57e63681a9a966cf106c03382d2c56c61f73c443161ac8817106be703f4084","contract":["SocksProxyAgent static protocols property includes supported SOCKS protocol schemes","SocksProxyAgent constructor initializes agent instance with SOCKS5 URI string and defaults port to 1080","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 agent options including timeout and socketOptions","SocksProxyAgent throws TypeError when initialized with unsupported protocol","SocksProxyAgent connects through SOCKS5 proxy server and routes HTTP client request offline"],"goal":"verify socks-proxy-agent.SocksProxyAgent in pkg:npm/socks-proxy-agent@8.0.5","kind":"HOW","packages":["pkg:npm/socks-proxy-agent@8.0.5"],"schemaVersion":1,"symbols":["socks-proxy-agent.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@8.0.5"],"schemaVersion":1,"subject":"pkg:npm/socks-proxy-agent@8.0.5","symbols":["socks-proxy-agent.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": "8.0.5"
      }
    },
    "node_modules/agent-base": {
      "version": "7.1.4",
      "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz",
      "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 14"
      }
    },
    "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": "8.0.5",
      "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.5.tgz",
      "integrity": "sha512-HehCEsotFqbPW9sJ8WVYB6UbmIMv7kUUORIF2Nncq4VQvBfNBLibW9YZR5dlYCSUhwcD628pRllm7n+E+YTzJw==",
      "license": "MIT",
      "dependencies": {
        "agent-base": "^7.1.2",
        "debug": "^4.3.4",
        "socks": "^2.8.3"
      },
      "engines": {
        "node": ">= 14"
      }
    }
  }
}
package.json
{
  "name": "sample-socks-proxy-agent",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "socks-proxy-agent": "8.0.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify socks-proxy-agent.SocksProxyAgent in pkg:npm/socks-proxy-agent@8.0.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/socks-proxy-agent@8.0.5"
  ],
  "symbols": [
    "socks-proxy-agent.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 static protocols property includes supported SOCKS protocol schemes
assert.ok(Array.isArray(SocksProxyAgent.protocols));
assert.deepEqual([...SocksProxyAgent.protocols], ['socks', 'socks4', 'socks4a', 'socks5', 'socks5h']);

// 2. SocksProxyAgent constructor initializes agent instance with SOCKS5 URI string and defaults port to 1080
const agentDefaultPort = new SocksProxyAgent('socks5://localhost');
assert.ok(agentDefaultPort instanceof SocksProxyAgent);
assert.equal(agentDefaultPort.proxy.host, 'localhost');
assert.equal(agentDefaultPort.proxy.port, 1080);
assert.equal(agentDefaultPort.proxy.type, 5);
assert.equal(agentDefaultPort.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 agent options including timeout and socketOptions
const agentWithOptions = new SocksProxyAgent('socks5://localhost:1080', {
  timeout: 5000,
  socketOptions: {
    keepAlive: true,
  },
  keepAlive: true,
});
assert.equal(agentWithOptions.timeout, 5000);
assert.deepEqual(agentWithOptions.socketOptions, { keepAlive: true });

// 6. SocksProxyAgent throws TypeError when initialized with unsupported protocol
assert.throws(
  () => new SocksProxyAgent('http://localhost:8080'),
  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;
        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));
}

オリジンシーダー

匿名