Skip to content

Commit

Permalink
update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed May 23, 2016
1 parent e9b107f commit 4afbedb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -46,7 +46,7 @@
"type": "git",
"url": "https://github.com/diasdavid/js-peer-id.git"
},
"dignified": {
"aegir": {
"webpack": {
"resolve": {
"alias": {
Expand Down
28 changes: 15 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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

Expand Down Expand Up @@ -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
})
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit 4afbedb

Please sign in to comment.