Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
perf: remove jwk2privPem and jwk2pubPem (#162)
Browse files Browse the repository at this point in the history
These 2 unused functions required us to import the whole of the node-forge PKI implementation when we only use some RSA stuffs.

BREAKING CHANGE: removes unused jwk2pem methods `jwk2pubPem` and `jwk2privPem`. These methods are not being used in any js libp2p modules, so only users referencing these directly will be impacted.
  • Loading branch information
Alan Shaw authored Feb 3, 2020
1 parent ad4bf3b commit cc20949
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/keys/jwk2pem.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict'

const forge = {
util: require('node-forge/lib/util'),
pki: require('node-forge/lib/pki'),
jsbn: require('node-forge/lib/jsbn')
}
require('node-forge/lib/rsa')
require('node-forge/lib/util')
require('node-forge/lib/jsbn')
const forge = require('node-forge/lib/forge')

function base64urlToBigInteger (str) {
var bytes = forge.util.decode64(
Expand All @@ -22,21 +21,11 @@ function jwk2priv (key) {
return forge.pki.setRsaPrivateKey(...convert(key, ['n', 'e', 'd', 'p', 'q', 'dp', 'dq', 'qi']))
}

function jwk2privPem (key) {
return forge.pki.privateKeyToPem(jwk2priv(key))
}

function jwk2pub (key) {
return forge.pki.setRsaPublicKey(...convert(key, ['n', 'e']))
}

function jwk2pubPem (key) {
return forge.pki.publicKeyToPem(jwk2pub(key))
}

module.exports = {
jwk2pub,
jwk2pubPem,
jwk2priv,
jwk2privPem
jwk2priv
}

0 comments on commit cc20949

Please sign in to comment.