diff --git a/src/index.js b/src/index.js index 82e1063..b855374 100644 --- a/src/index.js +++ b/src/index.js @@ -109,9 +109,13 @@ exports.create = function () { const protoPublic64 = formatKey(asnPub, 'Public') const protoPrivate64 = formatKey(asnPriv, 'Private') + // store the keys as a buffer + const bufProtoPub64 = new Buffer(protoPublic64, 'base64') + const bufProtoPriv64 = new Buffer(protoPrivate64, 'base64') + const mhId = multihashing(new Buffer(protoPublic64, 'base64'), 'sha2-256') - return new Id(mhId, protoPrivate64, protoPublic64) + return new Id(mhId, bufProtoPriv64, bufProtoPub64) } exports.createFromHexString = function (str) { diff --git a/tests/test.js b/tests/test.js index 72922b7..73f4147 100644 --- a/tests/test.js +++ b/tests/test.js @@ -55,5 +55,12 @@ describe('id', function (done) { expect(testIdB58String).to.equal(id.toB58String()) done() }) + + it('Compare generated ID with one created from PubKey', (done) => { + const id1 = PeerId.create() + const id2 = PeerId.createFromPubKey(id1.pubKey) + expect(id2.id).to.deep.equal(id1.id) + done() + }) })