simple-hypercore-protocol
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -5,3 +5,2 @@ const Handshake = require('./lib/handshake') | ||
const SMC = require('simple-message-channels') | ||
const SH = require('simple-handshake') | ||
const crypto = require('hypercore-crypto') | ||
@@ -228,2 +227,3 @@ const varint = require('varint') | ||
this.destroyed = true | ||
if (this._handshake) this._handshake.destroy() | ||
if (this._encryption) this._encryption.destroy() | ||
@@ -234,4 +234,3 @@ if (this.handlers.destroy) this.handlers.destroy(err) | ||
static keyPair (seed) { | ||
if (seed && Buffer.isBuffer(seed)) return SH.seedKeygen(seed) | ||
return SH.keygen() | ||
return Handshake.keyPair(seed) | ||
} | ||
@@ -238,0 +237,0 @@ } |
const SH = require('simple-handshake') | ||
const DH = require('noise-protocol/dh') | ||
const crypto = require('hypercore-crypto') | ||
const varint = require('varint') | ||
@@ -12,3 +14,3 @@ | ||
this.payload = payload | ||
this.keyPair = opts.keyPair || SH.keygen() | ||
this.keyPair = opts.keyPair || ProtocolHandshake.keyPair() | ||
this.remotePublicKey = null | ||
@@ -58,4 +60,19 @@ this.onrecv = onrecv.bind(this) | ||
this.destroyed = true | ||
if (!this.noise.finished) this.noise.destroy() | ||
this.ondone(err) | ||
} | ||
static keyPair (seed) { | ||
const obj = { | ||
// suboptimal but to reduce secure memory overhead on linux with default settings | ||
// better fix is to batch mallocs in noise-protocol | ||
publicKey: Buffer.alloc(DH.PKLEN), | ||
secretKey: Buffer.alloc(DH.SKLEN) | ||
} | ||
if (seed) DH.generateSeedKeypair(obj.publicKey, obj.secretKey, seed) | ||
else DH.generateKeypair(obj.publicKey, obj.secretKey) | ||
return obj | ||
} | ||
} | ||
@@ -66,3 +83,8 @@ | ||
self.destroyed = true | ||
self.ondone(null, self.remotePayload, self.noise.split, self.buffer, self.remotePublicKey) | ||
// suboptimal but to reduce secure memory overhead on linux with default settings | ||
// better fix is to batch mallocs in noise-protocol | ||
const split = { rx: Buffer.from(self.noise.split.rx), tx: Buffer.from(self.noise.split.tx) } | ||
crypto.free(self.noise.split.rx) | ||
crypto.free(self.noise.split.tx) | ||
self.ondone(null, self.remotePayload, split, self.buffer, self.remotePublicKey) | ||
} | ||
@@ -69,0 +91,0 @@ |
{ | ||
"name": "simple-hypercore-protocol", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Hypercore protocol state machine", | ||
"main": "index.js", | ||
"dependencies": { | ||
"hypercore-crypto": "^2.0.0", | ||
"hypercore-crypto": "^2.1.0", | ||
"noise-protocol": "^2.0.0", | ||
"protocol-buffers-encodings": "^1.1.0", | ||
@@ -9,0 +10,0 @@ "simple-handshake": "^2.0.0", |
55691
1686
7
+ Addednoise-protocol@^2.0.0
Updatedhypercore-crypto@^2.1.0