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

Commit

Permalink
feat: use ursa-optional for lightning fast key generation
Browse files Browse the repository at this point in the history
The difference between ursa and ursa-optional is that ursa-optional does not cause any problems if it fails to compile
  • Loading branch information
mkg20001 authored and daviddias committed Sep 17, 2018
1 parent ad47845 commit b05e77f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"protons": "^1.0.1",
"rsa-pem-to-jwk": "^1.1.3",
"tweetnacl": "^1.0.0",
"ursa-optional": "^0.9.6",
"webcrypto-shim": "github:dignifiedquire/webcrypto-shim#master"
},
"devDependencies": {
Expand Down
14 changes: 13 additions & 1 deletion src/keys/rsa.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
'use strict'

const crypto = require('crypto')
const keypair = require('keypair')
let keypair
try {
const ursa = require('ursa-optional') // throws if not compiled
keypair = ({bits}) => {
const key = ursa.generatePrivateKey(bits)
return {
private: key.toPrivatePem(),
public: key.toPublicPem()
}
}
} catch (e) {
keypair = require('keypair')
}
const setImmediate = require('async/setImmediate')
const pemToJwk = require('pem-jwk').pem2jwk
const jwkToPem = require('pem-jwk').jwk2pem
Expand Down

0 comments on commit b05e77f

Please sign in to comment.