Skip to content

Commit 4afbedb

Browse files
committed
update dependencies
1 parent e9b107f commit 4afbedb

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"homepage": "https://github.com/diasdavid/js-peer-id",
3333
"devDependencies": {
34-
"aegir": "^2.1.1",
34+
"aegir": "^3.0.4",
3535
"buffer-loader": "0.0.1",
3636
"chai": "^3.5.0",
3737
"pre-commit": "^1.1.2"
@@ -46,7 +46,7 @@
4646
"type": "git",
4747
"url": "https://github.com/diasdavid/js-peer-id.git"
4848
},
49-
"dignified": {
49+
"aegir": {
5050
"webpack": {
5151
"resolve": {
5252
"alias": {

src/index.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Id is an object representation of a peer Id. a peer Id is a multihash
33
*/
4+
45
'use strict'
56

67
const fs = require('fs')
@@ -10,8 +11,7 @@ const forge = require('node-forge')
1011
const protobuf = require('protocol-buffers')
1112
const path = require('path')
1213

13-
// protobuf read from file
14-
const messages = protobuf(fs.readFileSync(path.resolve(__dirname, '../protos/crypto.proto')))
14+
const pbCrypto = protobuf(fs.readFileSync(path.resolve(__dirname, '../protos/crypto.proto')))
1515

1616
exports = module.exports = Id
1717

@@ -52,23 +52,25 @@ function Id (id, privKey, pubKey) {
5252
}
5353

5454
// unwrap the private key protobuf
55-
function unmarshal (key) {
56-
return messages.PrivateKey.decode(key)
55+
function keyUnmarshal (key) {
56+
return pbCrypto.PrivateKey.decode(key)
5757
}
5858

5959
// create a public key protobuf to be base64 string stored in config
60-
function marshal (data, type) {
61-
var epb
60+
function keyMarshal (data, type) {
61+
const RSA = 0
62+
63+
let epb
6264
if (type === 'Public') {
63-
epb = messages.PublicKey.encode({
64-
Type: 0,
65+
epb = pbCrypto.PublicKey.encode({
66+
Type: RSA,
6567
Data: data
6668
})
6769
}
6870

6971
if (type === 'Private') {
70-
epb = messages.PrivateKey.encode({
71-
Type: 0,
72+
epb = pbCrypto.PrivateKey.encode({
73+
Type: RSA,
7274
Data: data
7375
})
7476
}
@@ -88,10 +90,10 @@ function formatKey (key, type) {
8890
const nDerBuf = new Buffer(fDerBuf.getBytes(), 'binary')
8991

9092
// protobuf the new DER bytes to the PublicKey Data: field
91-
const marshalKey = marshal(nDerBuf, type)
93+
const marsheledKey = keyMarshal(nDerBuf, type)
9294

9395
// encode the protobuf public key to base64 string
94-
const b64 = marshalKey.toString('base64')
96+
const b64 = marsheledKey.toString('base64')
9597
return b64
9698
}
9799

@@ -148,7 +150,7 @@ exports.createFromPrivKey = function (privKey) {
148150
const buf = new Buffer(privKey, 'base64')
149151

150152
// get the private key data from the protobuf
151-
const mpk = unmarshal(buf)
153+
const mpk = keyUnmarshal(buf)
152154

153155
// create a forge buffer
154156
const fbuf = forge.util.createBuffer(mpk.Data.toString('binary'))

0 commit comments

Comments
 (0)