mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-08-01 02:11:59 +00:00
10
src/index.js
10
src/index.js
@@ -97,9 +97,15 @@ function formatKey (key, type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generation
|
// generation
|
||||||
exports.create = function () {
|
exports.create = function (opts) {
|
||||||
|
opts = opts || {}
|
||||||
|
opts.bits = opts.bits || 2048
|
||||||
|
|
||||||
// generate keys
|
// 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
|
// return the RSA public/private key to asn1 object
|
||||||
const asnPub = forge.pki.publicKeyToAsn1(pair.publicKey)
|
const asnPub = forge.pki.publicKeyToAsn1(pair.publicKey)
|
||||||
|
@@ -62,5 +62,12 @@ describe('id', function (done) {
|
|||||||
expect(id2.id).to.deep.equal(id1.id)
|
expect(id2.id).to.deep.equal(id1.id)
|
||||||
done()
|
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