Created
August 15, 2022 18:10
-
-
Save MaxMoskalenko/0d50313c5bc0d23961c2253dd4d86cc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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