Exemple
resolve-alpn 1.2.1: resolveALPN
Échantillon vérifié pour npm resolve-alpn 1.2.1: resolveALPN. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.
sha256:9d8478c46389e83ed999bbaf4a0365b62e3edd03153d3a79f1b27c7b44523fa5
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux 24 · ubuntu · glibc 2.39 x64 npm
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify pkg:npm/resolve-alpn@1.2.1
- Paquets
- Symboles
-
- resolveALPN
- Créé
- 2026-08-28T05:15:57Z
Contrat
- resolveALPN negotiates and returns the selected ALPN protocol from a TLS server
- resolveALPN destroys the socket by default and resolves with alpnProtocol and timeout status
- resolveALPN with resolveSocket enabled returns the active TLSSocket alongside alpnProtocol
- resolveALPN supports custom connect functions for custom socket factory integration
- resolveALPN rejects when the socket connection encounters an error
- resolveALPN sets timeout to true when socket times out
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Code source
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/resolve-alpn@1.2.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/resolve-alpn@1.2.1
Demonstrate these symbols/APIs:
- resolveALPN
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:5a4b964526a99aead63da98fffff8579189d84fe9c4719f967eebc9d4c6dce2a","contract":["resolveALPN negotiates and returns the selected ALPN protocol from a TLS server","resolveALPN destroys the socket by default and resolves with alpnProtocol and timeout status","resolveALPN with resolveSocket enabled returns the active TLSSocket alongside alpnProtocol","resolveALPN supports custom connect functions for custom socket factory integration","resolveALPN rejects when the socket connection encounters an error","resolveALPN sets timeout to true when socket times out"],"goal":"verify pkg:npm/resolve-alpn@1.2.1","kind":"HOW","packages":["pkg:npm/resolve-alpn@1.2.1"],"schemaVersion":1,"symbols":["resolveALPN"]},"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/resolve-alpn@1.2.1"],"schemaVersion":1,"subject":"pkg:npm/resolve-alpn@1.2.1","symbols":["resolveALPN"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-resolve-alpn",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-resolve-alpn",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"resolve-alpn": "1.2.1"
}
},
"node_modules/resolve-alpn": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.2.1.tgz",
"integrity": "sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==",
"license": "MIT"
}
}
}
{
"name": "sample-resolve-alpn",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of pkg:npm/resolve-alpn@1.2.1",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"resolve-alpn": "1.2.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/resolve-alpn@1.2.1",
"kind": "HOW",
"packages": [
"pkg:npm/resolve-alpn@1.2.1"
],
"symbols": [
"resolveALPN"
]
}
const resolveALPN = require('resolve-alpn');
/**
* Resolves the ALPN protocol for a given target.
* @param {import('tls').ConnectionOptions & { resolveSocket?: boolean }} options
* @param {Function} [connect]
* @returns {Promise<{ alpnProtocol: string | false | null, socket?: import('tls').TLSSocket, timeout: boolean }>}
*/
async function detectAlpnProtocol(options, connect) {
return resolveALPN(options, connect);
}
module.exports = {
resolveALPN,
detectAlpnProtocol
};
import assert from 'node:assert';
import { EventEmitter } from 'node:events';
import { createRequire } from 'node:module';
import tls from 'node:tls';
const require = createRequire(import.meta.url);
const { resolveALPN, detectAlpnProtocol } = require('../src/index.js');
const keyB64 = "LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2UUlCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktjd2dnU2pBZ0VBQW9JQkFRQy9tNHhJdEhXcWFSbDEKeVdvYjJLa2hJenlUdU82MmhtWnpwS0sveE9XK2xZUDk2VEVGeEpPb1N2enp1cUtKSnRhSTF3Z1FrUGZMNjZvVQpvZlBpK1F5enEvTTlseU9GQzVvQmtZNEN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jMEJ4R0FaalZBYnJvdkw1WUhwOE90d0JaOVpzYitVNnYzS3YKWDREQ0x3eFpSZWpOWlFscVhOcUtka0FMSkdCTkhITDBPNk5KdG01SGdIU2FBSE11M2VPd2Zha0FxQVI2UXRqQQpMMGRjMFQycytaMFhkNWNFUUFkZHJIV0QyY0l3WUhwcUtoWDdzQmtFS3k5RnpyTmwzOE9ma0tVYU0wWkIvUmxnCjNuWnhqM3ZqeFJQM1g3a1FKY2x1UU5Dd2wwQ3ZleXp3dFJyelNhOVg1WTRUY1BoR25RQUxNV2RMdFZ5Vnh4U00KZFdrZXZ4a01jYithWTRsbnBRPT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=";
const key = Buffer.from(keyB64, 'base64').toString('utf8');
const cert = Buffer.from(certB64, 'base64').toString('utf8');
async function runTests() {
const server = tls.createServer({
key,
cert,
ALPNProtocols: ['h2', 'http/1.1']
}, (socket) => {
socket.end();
});
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const port = server.address().port;
try {
// 1. resolveALPN negotiates and returns the selected ALPN protocol from a TLS server
const r1 = await resolveALPN({
host: '127.0.0.1',
port,
ALPNProtocols: ['h2'],
rejectUnauthorized: false
});
assert.strictEqual(r1.alpnProtocol, 'h2');
assert.strictEqual(r1.timeout, false);
// 2. resolveALPN destroys the socket by default and resolves with alpnProtocol and timeout status
const r2 = await detectAlpnProtocol({
host: '127.0.0.1',
port,
ALPNProtocols: ['http/1.1'],
rejectUnauthorized: false
});
assert.strictEqual(r2.alpnProtocol, 'http/1.1');
assert.strictEqual(r2.socket, undefined);
assert.strictEqual(r2.timeout, false);
// 3. resolveALPN with resolveSocket enabled returns the active TLSSocket alongside alpnProtocol
const r3 = await resolveALPN({
host: '127.0.0.1',
port,
ALPNProtocols: ['h2'],
resolveSocket: true,
rejectUnauthorized: false
});
assert.strictEqual(r3.alpnProtocol, 'h2');
assert.ok(r3.socket);
assert.strictEqual(r3.socket.destroyed, false);
r3.socket.destroy();
// 4. resolveALPN supports custom connect functions for custom socket factory integration
const fakeSocket = new EventEmitter();
fakeSocket.alpnProtocol = 'custom-proto';
fakeSocket.destroy = () => {
fakeSocket.destroyed = true;
};
fakeSocket.off = fakeSocket.removeListener;
const customConnect = (opts, cb) => {
setImmediate(cb);
return fakeSocket;
};
const r4 = await resolveALPN({ resolveSocket: true }, customConnect);
assert.strictEqual(r4.alpnProtocol, 'custom-proto');
assert.strictEqual(r4.socket, fakeSocket);
assert.strictEqual(fakeSocket.destroyed, undefined);
// 5. resolveALPN rejects when the socket connection encounters an error
const errorSocket = new EventEmitter();
errorSocket.off = errorSocket.removeListener;
const errorConnect = (opts, cb) => {
setImmediate(() => errorSocket.emit('error', new Error('TLS connection failed')));
return errorSocket;
};
await assert.rejects(resolveALPN({}, errorConnect), /TLS connection failed/);
// 6. resolveALPN sets timeout to true when socket times out
const timeoutSocket = new EventEmitter();
timeoutSocket.alpnProtocol = 'h2';
timeoutSocket.off = timeoutSocket.removeListener;
timeoutSocket.destroy = () => {
timeoutSocket.destroyed = true;
};
const timeoutConnect = (opts, cb) => {
setImmediate(() => {
timeoutSocket.emit('timeout');
});
return timeoutSocket;
};
const r6 = await resolveALPN({}, timeoutConnect);
assert.strictEqual(r6.timeout, true);
assert.strictEqual(r6.alpnProtocol, 'h2');
console.log('All contract tests passed successfully.');
} finally {
server.close();
}
}
runTests().catch((error) => {
console.error(error);
process.exit(1);
});
Seeder d'origine
anonyme