Skip to content

Instantly share code, notes, and snippets.

@zetxx
Last active June 22, 2022 08:32
Show Gist options
  • Save zetxx/f009eb33101f7ebf3131b387427468a0 to your computer and use it in GitHub Desktop.
Save zetxx/f009eb33101f7ebf3131b387427468a0 to your computer and use it in GitHub Desktop.
// jose version v2.x
const jose = require('jose');
const simpleJWKgen = async({
kty = 'OKP',
crvOrSize = 'Ed25519',
options: {
alg = 'EdDSA',
kid,
key_ops,
use = 'sig'
} = {}
} = {}) => {
const data = await jose.JWK.generate(kty, crvOrSize, {
alg,
kid,
key_ops,
use
});
return ['kty', 'd', 'use', 'crv', 'kid', 'x', 'alg']
.reduce((rdy, prop) => (
(data[prop] && {...rdy, [prop]: data[prop]}) || rdy
), {});
};
(async() => console.log(await simpleJWKgen()))();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment