thomas-encryptation
v1.0.0
Published
Core criptográfico isomórfico para el protocolo thomas/encrypted (RSA-OAEP + AES-256-GCM)
Maintainers
Readme
thomas-encryptation
Core criptográfico del protocolo thomas/encrypted (RSA-OAEP + AES-256-GCM).
Librería zero-deps, isomórfica (browser + Node.js ≥ 18 + Edge runtimes).
Base de thomas-fetch y thomas-middleware.
Instalación (local)
# En el paquete consumidor
"thomas-encryptation": "file:../thomas-encryptation"API
Constantes
import { THOMAS_CONTENT_TYPE, THOMAS_RESPONSE_KEY_HEADER } from 'thomas-encryptation';
// 'thomas/encrypted'
// 'x-thomas-response-key'Lado cliente (Web Crypto API — isomórfico)
import {
encryptPayload,
decryptServerResponse,
generateStandaloneResponseKey,
} from 'thomas-encryptation';
// Cifrar body para POST/PUT/PATCH
const { wirePayload, responseKeyRaw } = await encryptPayload(data, publicKeyPem);
// Descifrar respuesta del servidor
const result = await decryptServerResponse(responseText, responseKeyRaw, contentType);
// Para peticiones GET (sin body)
const { rawKey, encryptedKey } = await generateStandaloneResponseKey(publicKeyPem);Lado servidor (Node.js — node:crypto)
import {
decryptBody,
decryptAesKey,
encryptResponseSync,
isEncryptedPayload,
} from 'thomas-encryptation';
// Descifrar body de la petición
const body = decryptBody(payload, privateKeyPem);
// Cifrar respuesta con K_resp
const envelope = encryptResponseSync(responseData, aesKey);
// Descifrar solo la clave AES (ek o rk)
const aesKeyBuffer = decryptAesKey(encryptedKeyBase64, privateKeyPem);Configuración (sin process.env)
Toda la configuración se pasa explícitamente como parámetros. Ninguna función lee process.env.
Build
npm run build # Compila CJS + ESM + types
npm run typecheck # Solo verificación de tipos