Skip to content

Instantly share code, notes, and snippets.

@MaxMoskalenko
Created August 15, 2022 18:10
Show Gist options
  • Save MaxMoskalenko/0d50313c5bc0d23961c2253dd4d86cc2 to your computer and use it in GitHub Desktop.
Save MaxMoskalenko/0d50313c5bc0d23961c2253dd4d86cc2 to your computer and use it in GitHub Desktop.
const crypto = require('crypto');
const { SignJWT } = require('jose');
async function generateKeys() {
const { privateKey } = crypto.generateKeyPairSync('ec', {
namedCurve: 'secp256k1',
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
},
});
const privateKeyObject = crypto.createPrivateKey(privateKey)
const jwtToken = await new SignJWT({data: 'hello'})
.setProtectedHeader({ alg: 'ES256' })
.sign(privateKeyObject);
}
generateKeys();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment