Setup Jose JWK key outside of routes
Unanswered
blahaj.bitch posted this in #help-forum
I want to setup Jose keys outside of routes for APIs, how can I do this while still leaving the private and public key able to be used by all scripts since it seems to slow down everything when it generates the keys?
I heard about instrumentation, but I'm unsure of how I'd get it to work in there.
Here's my current implementation:
I heard about instrumentation, but I'm unsure of how I'd get it to work in there.
Here's my current implementation:
function setupjose() {
const key = crypto.generateKeyPairSync('rsa', { modulusLength: 8192 });
const privkey = key.privateKey.export({ format: 'jwk' })
const pubkey = key.publicKey.export({ format: 'jwk' })
const privateJWK = privkey as unknown as jose.JWK;
const publicJWK = pubkey as unknown as jose.JWK;
return { privkey: privateJWK, pubkey: publicJWK };
}
const { privkey, pubkey } = setupjose();
jose.importJWK(privkey).catch(err => console.error(err));
jose.importJWK(pubkey).catch(err => console.error(err));