Ejemplo
jose 6.2.13: SignJWT, jwtVerify, EncryptJWT
Muestra verificada para npm jose 6.2.13: SignJWT, jwtVerify, EncryptJWT. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.
sha256:be0f884b8e1ce9a9550a37e8b25fa89d432e7281b4a43cbb37bff46300b46cde
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
node linux 24 · ubuntu · glibc 2.39 x64 node npm
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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-10-21 |
Caso
HOW- Objetivo
- verify pkg:npm/jose@6.2.13
- Paquetes
- Símbolos
-
- SignJWT
- jwtVerify
- EncryptJWT
- jwtDecrypt
- generateKeyPair
- generateSecret
- exportJWK
- importJWK
- calculateJwkThumbprint
- createLocalJWKSet
- errors
- Entorno
- node
- Creado
- 2026-10-21T01:09:28Z
Contrato
- generateKeyPair('EdDSA', { crv: 'Ed25519', extractable: true }) generates keys that exportJWK serializes to OKP Ed25519 JWKs and importJWK re-imports for signing.
- SignJWT signs an EdDSA JWT with kid matching calculateJwkThumbprint, and jwtVerify resolves { payload, protectedHeader } against a createLocalJWKSet resolver.
- jwtVerify rejects mismatched issuer claims with errors.JWTClaimValidationFailed (code ERR_JWT_CLAIM_VALIDATION_FAILED, claim 'iss', reason 'check_failed').
- EncryptJWT and jwtDecrypt encrypt and decrypt a direct symmetric A256GCM JWE token created with generateSecret('A256GCM'), and jwtDecrypt rejects wrong keys with errors.JWEDecryptionFailed.
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código fuente
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/jose@6.2.13
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/jose@6.2.13
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:edbf17747d8563d905f328b85f8fc3dde9ef39c7262f2fa9db09b66675d8f14e","contract":["generateKeyPair('EdDSA', { crv: 'Ed25519', extractable: true }) generates keys that exportJWK serializes to OKP Ed25519 JWKs and importJWK re-imports for signing.","SignJWT signs an EdDSA JWT with kid matching calculateJwkThumbprint, and jwtVerify resolves { payload, protectedHeader } against a createLocalJWKSet resolver.","jwtVerify rejects mismatched issuer claims with errors.JWTClaimValidationFailed (code ERR_JWT_CLAIM_VALIDATION_FAILED, claim 'iss', reason 'check_failed').","EncryptJWT and jwtDecrypt encrypt and decrypt a direct symmetric A256GCM JWE token created with generateSecret('A256GCM'), and jwtDecrypt rejects wrong keys with errors.JWEDecryptionFailed."],"goal":"verify pkg:npm/jose@6.2.13","kind":"HOW","packages":["pkg:npm/jose@6.2.13"],"schemaVersion":1,"symbols":["SignJWT","jwtVerify","EncryptJWT","jwtDecrypt","generateKeyPair","generateSecret","exportJWK","importJWK","calculateJwkThumbprint","createLocalJWKSet","errors"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/jose@6.2.13"],"schemaVersion":1,"subject":"pkg:npm/jose@6.2.13","symbols":["SignJWT","jwtVerify","EncryptJWT","jwtDecrypt","generateKeyPair","generateSecret","exportJWK","importJWK","calculateJwkThumbprint","createLocalJWKSet","errors"],"verifierAdapter":"node-typescript@1"}
{
"name": "jose-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "jose-sample",
"version": "1.0.0",
"dependencies": {
"jose": "6.2.13"
}
},
"node_modules/jose": {
"version": "6.2.13",
"resolved": "https://registry.npmjs.org/jose/-/jose-6.2.13.tgz",
"integrity": "sha512-7TIg10ZE1x82YediN+lcrPNvGMKge9yFHQD+Qho/b8y2adfugU3AsvvHfxV0fzyFllT6l9xCjf4RWY9g/Z9PJQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/panva"
}
}
}
}
{
"name": "jose-sample",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"jose": "6.2.13"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/jose@6.2.13",
"kind": "HOW",
"packages": [
"pkg:npm/jose@6.2.13"
]
}
import assert from 'node:assert/strict';
import {
SignJWT,
jwtVerify,
EncryptJWT,
jwtDecrypt,
generateKeyPair,
generateSecret,
exportJWK,
importJWK,
calculateJwkThumbprint,
createLocalJWKSet,
errors,
} from 'jose';
// 1. Asymmetric Ed25519 key generation, JWK export/import, thumbprint, and LocalJWKSet verification
const { publicKey, privateKey } = await generateKeyPair('EdDSA', {
crv: 'Ed25519',
extractable: true,
});
const publicJwk = await exportJWK(publicKey);
const privateJwk = await exportJWK(privateKey);
assert.equal(publicJwk.kty, 'OKP');
assert.equal(publicJwk.crv, 'Ed25519');
assert.equal(typeof privateJwk.d, 'string');
const kid = await calculateJwkThumbprint(publicJwk, 'sha256');
publicJwk.kid = kid;
publicJwk.alg = 'EdDSA';
publicJwk.use = 'sig';
const importedPrivate = await importJWK(privateJwk, 'EdDSA');
const jwks = createLocalJWKSet({ keys: [publicJwk] });
const signedToken = await new SignJWT({ role: 'admin', scope: 'read:items' })
.setProtectedHeader({ alg: 'EdDSA', kid })
.setSubject('user-101')
.setIssuer('urn:example:issuer')
.setAudience('urn:example:audience')
.setIssuedAt()
.setExpirationTime('2h')
.sign(importedPrivate);
const verified = await jwtVerify(signedToken, jwks, {
issuer: 'urn:example:issuer',
audience: 'urn:example:audience',
algorithms: ['EdDSA'],
});
assert.equal(verified.payload.sub, 'user-101');
assert.equal(verified.payload.role, 'admin');
assert.equal(verified.protectedHeader.alg, 'EdDSA');
assert.equal(verified.protectedHeader.kid, kid);
// 2. Claim mismatch rejection with JWTClaimValidationFailed
await assert.rejects(
() =>
jwtVerify(signedToken, jwks, {
issuer: 'urn:example:wrong-issuer',
}),
(err) => {
assert.ok(err instanceof errors.JWTClaimValidationFailed);
assert.equal(err.code, 'ERR_JWT_CLAIM_VALIDATION_FAILED');
assert.equal(err.claim, 'iss');
assert.equal(err.reason, 'check_failed');
return true;
},
);
// 3. Symmetric direct JWE encryption and decryption with EncryptJWT and jwtDecrypt (A256GCM)
const secretKey = await generateSecret('A256GCM', { extractable: true });
const encryptedToken = await new EncryptJWT({ secretData: 'confidential-42' })
.setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })
.setIssuedAt()
.setIssuer('urn:example:issuer')
.setExpirationTime('1h')
.encrypt(secretKey);
const decrypted = await jwtDecrypt(encryptedToken, secretKey, {
issuer: 'urn:example:issuer',
contentEncryptionAlgorithms: ['A256GCM'],
keyManagementAlgorithms: ['dir'],
});
assert.equal(decrypted.payload.secretData, 'confidential-42');
assert.equal(decrypted.protectedHeader.alg, 'dir');
assert.equal(decrypted.protectedHeader.enc, 'A256GCM');
// 4. Wrong key decryption rejection with JWEDecryptionFailed
const wrongSecretKey = await generateSecret('A256GCM');
await assert.rejects(
() => jwtDecrypt(encryptedToken, wrongSecretKey),
(err) => {
assert.ok(err instanceof errors.JWEDecryptionFailed);
assert.equal(err.code, 'ERR_JWE_DECRYPTION_FAILED');
return true;
},
);
Seeder de origen
anónimo