From 727355c4f528a67470bf516145f61c47f200ac5f Mon Sep 17 00:00:00 2001 From: Stephen Whitmore Date: Mon, 14 Mar 2016 17:10:02 -0700 Subject: [PATCH 1/2] exposes opts + bits --- src/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 6695bc6..d9267b0 100644 --- a/src/index.js +++ b/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) From 352a6cfa171d16d17d679c910864ff286ffbf329 Mon Sep 17 00:00:00 2001 From: Stephen Whitmore Date: Tue, 15 Mar 2016 12:15:44 -0700 Subject: [PATCH 2/2] tests # of bits --- tests/test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test.js b/tests/test.js index 73f4147..0e46a42 100644 --- a/tests/test.js +++ b/tests/test.js @@ -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() + }) })