diff --git a/package.json b/package.json index 772690e..a93cc1d 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ }, "homepage": "https://github.com/diasdavid/js-peer-id", "devDependencies": { - "aegir": "^2.1.1", + "aegir": "^3.0.4", "buffer-loader": "0.0.1", "chai": "^3.5.0", "pre-commit": "^1.1.2" @@ -46,7 +46,7 @@ "type": "git", "url": "https://github.com/diasdavid/js-peer-id.git" }, - "dignified": { + "aegir": { "webpack": { "resolve": { "alias": { diff --git a/src/index.js b/src/index.js index d8df1a2..5805f7a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ /* * Id is an object representation of a peer Id. a peer Id is a multihash */ + 'use strict' const fs = require('fs') @@ -10,8 +11,7 @@ const forge = require('node-forge') const protobuf = require('protocol-buffers') const path = require('path') -// protobuf read from file -const messages = protobuf(fs.readFileSync(path.resolve(__dirname, '../protos/crypto.proto'))) +const pbCrypto = protobuf(fs.readFileSync(path.resolve(__dirname, '../protos/crypto.proto'))) exports = module.exports = Id @@ -52,23 +52,25 @@ function Id (id, privKey, pubKey) { } // unwrap the private key protobuf -function unmarshal (key) { - return messages.PrivateKey.decode(key) +function keyUnmarshal (key) { + return pbCrypto.PrivateKey.decode(key) } // create a public key protobuf to be base64 string stored in config -function marshal (data, type) { - var epb +function keyMarshal (data, type) { + const RSA = 0 + + let epb if (type === 'Public') { - epb = messages.PublicKey.encode({ - Type: 0, + epb = pbCrypto.PublicKey.encode({ + Type: RSA, Data: data }) } if (type === 'Private') { - epb = messages.PrivateKey.encode({ - Type: 0, + epb = pbCrypto.PrivateKey.encode({ + Type: RSA, Data: data }) } @@ -88,10 +90,10 @@ function formatKey (key, type) { const nDerBuf = new Buffer(fDerBuf.getBytes(), 'binary') // protobuf the new DER bytes to the PublicKey Data: field - const marshalKey = marshal(nDerBuf, type) + const marsheledKey = keyMarshal(nDerBuf, type) // encode the protobuf public key to base64 string - const b64 = marshalKey.toString('base64') + const b64 = marsheledKey.toString('base64') return b64 } @@ -148,7 +150,7 @@ exports.createFromPrivKey = function (privKey) { const buf = new Buffer(privKey, 'base64') // get the private key data from the protobuf - const mpk = unmarshal(buf) + const mpk = keyUnmarshal(buf) // create a forge buffer const fbuf = forge.util.createBuffer(mpk.Data.toString('binary'))