CodeSampleX

Exemple

pkce-challenge 5.0.2

Échantillon vérifié pour npm pkce-challenge 5.0.2. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:f4140b4c0d3e880fa07c11b03499283bd60b898920d607fe790986a35ca14911

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é node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-28

Cas

HOW
Objectif
verify pkg:npm/pkce-challenge@5.0.2
Paquets
Environnement
node 22.23.2
Créé
2026-11-28T03:46:43Z

Contrat

  1. require('pkce-challenge') in CommonJS exposes default (pkceChallenge), generateChallenge, and verifyChallenge functions
  2. pkceChallenge() defaults to a 43-character RFC 7636 unreserved code_verifier and its 43-character unpadded base64url SHA-256 code_challenge
  3. pkceChallenge(length) accepts lengths from 43 through 128 inclusive and produces matching SHA-256 base64url challenges
  4. pkceChallenge(length) rejects with a string message when length is below 43 or above 128
  5. generateChallenge computes the RFC 7636 Appendix B test vector challenge for the reference verifier
  6. verifyChallenge resolves to true for matching verifier/challenge pairs and false when either value is altered

Fichiers

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js

Télécharger l’artefact source (tar.gz)

Code source

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/pkce-challenge@5.0.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/pkce-challenge@5.0.2
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:c50b3db2eb54e05b9600dc8a7ab56541f402eb70b7d62b48392fc99bae42c103","constraints":{"executionContext":"node"},"contract":["require('pkce-challenge') in CommonJS exposes default (pkceChallenge), generateChallenge, and verifyChallenge functions","pkceChallenge() defaults to a 43-character RFC 7636 unreserved code_verifier and its 43-character unpadded base64url SHA-256 code_challenge","pkceChallenge(length) accepts lengths from 43 through 128 inclusive and produces matching SHA-256 base64url challenges","pkceChallenge(length) rejects with a string message when length is below 43 or above 128","generateChallenge computes the RFC 7636 Appendix B test vector challenge for the reference verifier","verifyChallenge resolves to true for matching verifier/challenge pairs and false when either value is altered"],"goal":"verify pkg:npm/pkce-challenge@5.0.2","kind":"HOW","packages":["pkg:npm/pkce-challenge@5.0.2"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/pkce-challenge@5.0.2"],"schemaVersion":1,"subject":"pkg:npm/pkce-challenge@5.0.2","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "pkce-challenge-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "pkce-challenge-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "pkce-challenge": "5.0.2"
      }
    },
    "node_modules/pkce-challenge": {
      "version": "5.0.2",
      "resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.2.tgz",
      "integrity": "sha512-vCc54+qyIfKC5e2UN28AZKElwqjLINgiIV3RKI8pDu93TjaAJoB3QrgMzEBouy8yOKsXVXdAinO1QArJf9x5WA==",
      "license": "MIT",
      "engines": {
        "node": ">=16.20.0"
      }
    }
  }
}
package.json
{
  "name": "pkce-challenge-sample",
  "version": "1.0.0",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "pkce-challenge": "5.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/pkce-challenge@5.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pkce-challenge@5.0.2"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
"use strict";

const {
  default: pkceChallenge,
  generateChallenge,
  verifyChallenge,
} = require("pkce-challenge");

async function createPkcePair(length) {
  return pkceChallenge(length);
}

async function computePkceChallenge(verifier) {
  return generateChallenge(verifier);
}

async function checkPkcePair(verifier, challenge) {
  return verifyChallenge(verifier, challenge);
}

module.exports = {
  createPkcePair,
  computePkceChallenge,
  checkPkcePair,
};
test/contract.js
"use strict";

const assert = require("node:assert/strict");
const crypto = require("node:crypto");
const pkg = require("pkce-challenge");
const {
  createPkcePair,
  computePkceChallenge,
  checkPkcePair,
} = require("../src/index.js");

const UNRESERVED_RE = /^[A-Za-z0-9\-._~]+$/;
const BASE64URL_SHA256_RE = /^[A-Za-z0-9\-_]{43}$/;

function sha256Base64Url(input) {
  return crypto.createHash("sha256").update(input, "utf8").digest("base64url");
}

async function main() {
  // 1. CommonJS exports expose default (pkceChallenge), generateChallenge, and verifyChallenge
  assert.equal(typeof pkg.default, "function");
  assert.equal(typeof pkg.generateChallenge, "function");
  assert.equal(typeof pkg.verifyChallenge, "function");

  // 2. Default length generates a 43-character unreserved verifier and matching 43-char base64url challenge
  const defaultPair = await createPkcePair();
  assert.equal(defaultPair.code_verifier.length, 43);
  assert.match(defaultPair.code_verifier, UNRESERVED_RE);
  assert.match(defaultPair.code_challenge, BASE64URL_SHA256_RE);
  assert.equal(defaultPair.code_challenge, sha256Base64Url(defaultPair.code_verifier));

  // 3. Explicit boundary lengths (43 and 128) succeed and match SHA-256 base64url digest
  for (const len of [43, 64, 128]) {
    const pair = await createPkcePair(len);
    assert.equal(pair.code_verifier.length, len);
    assert.match(pair.code_verifier, UNRESERVED_RE);
    assert.equal(pair.code_challenge, sha256Base64Url(pair.code_verifier));
  }

  // 4. Out-of-range lengths (< 43 or > 128) reject with a string message
  for (const badLen of [42, 129]) {
    let rejected;
    try {
      await createPkcePair(badLen);
      assert.fail(`Expected rejection for length ${badLen}`);
    } catch (err) {
      rejected = err;
    }
    assert.equal(typeof rejected, "string");
    assert.equal(rejected, `Expected a length between 43 and 128. Received ${badLen}.`);
  }

  // 5. generateChallenge matches RFC 7636 Appendix B test vector
  const rfcVerifier = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk";
  const rfcChallenge = "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM";
  const computedRfc = await computePkceChallenge(rfcVerifier);
  assert.equal(computedRfc, rfcChallenge);
  assert.equal(computedRfc, sha256Base64Url(rfcVerifier));

  // 6. verifyChallenge returns true for matching pairs and false for mismatched verifier or challenge
  assert.strictEqual(await checkPkcePair(rfcVerifier, rfcChallenge), true);
  assert.strictEqual(
    await checkPkcePair(defaultPair.code_verifier, defaultPair.code_challenge),
    true
  );
  assert.strictEqual(await checkPkcePair(rfcVerifier, "wrong_challenge"), false);
  assert.strictEqual(await checkPkcePair(`${rfcVerifier}x`, rfcChallenge), false);
}

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

Seeder d'origine

anonyme