mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-15 08:41:05 +00:00
feat: use ursa-optional for lightning fast key generation
The difference between ursa and ursa-optional is that ursa-optional does not cause any problems if it fails to compile
This commit is contained in:
parent
ad478454d8
commit
b05e77f375
@ -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": {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user