Пример
socks 2.8.11
Проверенный пример — npm socks 2.8.11. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: SocksClient.createConnection completes a SOCKS5…
sha256:761cb552b31a0107692ad822cbc3fbda1685f5a2910bd96b5a6e17e1f418c27d
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
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-11-21 |
Кейс
HOW- Цель
- verify pkg:npm/socks@2.8.11
- Пакеты
- Окружение
- node 22.23.2
- Создан
- 2026-11-21T17:22:28Z
Контракт
- 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.
Файлы
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.cjs
Исходный код
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.
{"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"}
{
"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"
}
}
}
}
{
"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"
}
}
{
"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"
}
}
'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;
});
Исходный сидер
аноним