tr-jwk
v1.0.0
Published
JWK key generation library (HMAC, EC, RSA, ML-DSA, AES)
Readme
tr-jwk
JWK key generation library for Node.js. Produces JSON Web Keys ready to use with JWT signers, JWE encryptors, ECDH-ES key agreement, and AES content-encryption / key-wrap operations.
The package exposes three utilities:
macKeyGen(alg)for HMAC, ECDSA, RSA, and ML-DSA signing keyscipherKeyGen(alg)for AES content-encryption and AES-GCM key-wrap keysecKeyGen(curve)for EC key pairs used with ECDH-ES
Reference
Installation
npm install tr-jwkNode.js >=24.0.0 is required.
macKeyGen(alg)
Generates a private JWK suitable for JWT signing.
Supported alg values:
HS256,HS384,HS512ES256,ES384,ES512RS256,RS384,RS512ML-DSA-44,ML-DSA-65,ML-DSA-87
Example:
const { macKeyGen } = require('tr-jwk');
const key = macKeyGen('ES256');
console.log(key);Notes:
- HMAC keys are returned as
octJWKs with randomkmaterial. - EC, RSA, and ML-DSA keys are returned as private JWKs.
- A random
kidis always added.
cipherKeyGen(alg)
Generates a symmetric JWK for encryption or key wrapping.
Supported alg values:
A128GCM,A192GCM,A256GCMA128GCMKW,A192GCMKW,A256GCMKW
Example:
const { cipherKeyGen } = require('tr-jwk');
const key = cipherKeyGen('A256GCM');
console.log(key);Returned keys include:
kty: "oct"algkey_opsuse: "enc"- random
kid
ecKeyGen(curve)
Generates an EC key pair and returns both the private and public JWK.
Supported curve values:
P-256P-384P-521
Example:
const { ecKeyGen } = require('tr-jwk');
const { secretKey, publicKey } = ecKeyGen('P-256');Both returned JWKs share the same kid.
Exports
const { macKeyGen, cipherKeyGen, ecKeyGen } = require('tr-jwk');Author
Timo J. Rinne [email protected] — https://github.com/rinne/
Copyright
Copyright © 2023–2026 Timo J. Rinne [email protected].
See COPYING for the full MIT license text.
License
MIT License
