mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-07-31 06:32:00 +00:00
10
src/index.js
10
src/index.js
@@ -97,9 +97,15 @@ function formatKey (key, type) {
|
||||
}
|
||||
|
||||
// generation
|
||||
exports.create = function () {
|
||||
exports.create = function (opts) {
|
||||
opts = opts || {}
|
||||
opts.bits = opts.bits || 2048
|
||||
|
||||
// generate keys
|
||||
const pair = forge.rsa.generateKeyPair({ bits: 2048, e: 0x10001 })
|
||||
const pair = forge.rsa.generateKeyPair({
|
||||
bits: opts.bits,
|
||||
e: 0x10001
|
||||
})
|
||||
|
||||
// return the RSA public/private key to asn1 object
|
||||
const asnPub = forge.pki.publicKeyToAsn1(pair.publicKey)
|
||||
|
@@ -62,5 +62,12 @@ describe('id', function (done) {
|
||||
expect(id2.id).to.deep.equal(id1.id)
|
||||
done()
|
||||
})
|
||||
|
||||
it('Non-default # of bits', (done) => {
|
||||
const shortId = PeerId.create({ bits: 128 })
|
||||
const longId = PeerId.create({ bits: 256 })
|
||||
expect(shortId.privKey.length).is.below(longId.privKey.length)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user