Skip to content

Commit

Permalink
fix: check and convert keypair to buffer (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
aulneau authored Jun 27, 2020
1 parent 24e4598 commit af29fb5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const noisePeer = require('noise-peer')
const EventEmitter = require('events')
const pump = require('pump')
const getStream = require('get-stream')
const isBuffer = require('is-buffer')

const METADATA_NAME = 'p2plex-topics'

Expand All @@ -17,12 +18,23 @@ class P2Plex extends EventEmitter {
} = {}) {
super()
this.opts = opts
this.keyPair = keyPair || noisePeer.keygen()
this.swarm = hyperswarm({
multiplex: true,
...opts
})

let { publicKey, secretKey } = opts.keyPair || noisePeer.keygen()
if (!isBuffer(publicKey)) {
publicKey = Buffer.from(publicKey)
}
if (!isBuffer(secretKey)) {
secretKey = Buffer.from(secretKey)
}
this.keyPair = {
publicKey,
secretKey,
}

this.peers = new Set()

this.swarm.on('connection', (socket, info) => this._handleConnection(socket, info))
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
"dependencies": {
"get-stream": "^5.1.0",
"hyperswarm": "^2.11.2",
"is-buffer": "^2.0.4",
"multiplex": "^6.7.0",
"noise-peer": "^1.1.0",
"noise-peer": "^2.1.0",
"pump": "^3.0.0"
},
"devDependencies": {
"supertape": "^1.2.4"
"supertape": "^2.0.1"
}
}

0 comments on commit af29fb5

Please sign in to comment.