diff --git a/index.js b/index.js index 80801b1..d512368 100644 --- a/index.js +++ b/index.js @@ -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' @@ -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)) diff --git a/package.json b/package.json index 478a0fe..682ca75 100644 --- a/package.json +++ b/package.json @@ -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" } }