simple-hypercore-protocol
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -16,2 +16,3 @@ const Handshake = require('./lib/handshake') | ||
this.publicKey = null | ||
this.handshakeHash = null | ||
this.destroyed = false | ||
@@ -140,3 +141,3 @@ | ||
_onhandshake (err, remotePayload, split, overflow, remotePublicKey) { | ||
_onhandshake (err, remotePayload, split, overflow, remotePublicKey, handshakeHash) { | ||
if (err) return this.destroy(new Error('Noise handshake error')) // workaround for https://github.com/emilbayes/noise-protocol/issues/5 | ||
@@ -146,2 +147,3 @@ if (!remotePayload) return this.destroy(new Error('Remote did not include a handshake payload')) | ||
this.remotePublicKey = remotePublicKey | ||
this.handshakeHash = handshakeHash | ||
@@ -148,0 +150,0 @@ try { |
@@ -86,3 +86,3 @@ const SH = require('simple-handshake') | ||
crypto.free(self.noise.split.tx) | ||
self.ondone(null, self.remotePayload, split, self.buffer, self.remotePublicKey) | ||
self.ondone(null, self.remotePayload, split, self.buffer, self.remotePublicKey, self.noise.handshakeHash) | ||
} | ||
@@ -89,0 +89,0 @@ |
{ | ||
"name": "simple-hypercore-protocol", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Hypercore protocol state machine", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -86,2 +86,8 @@ # simple-hypercore-protocol | ||
#### `p.handshakeHash` | ||
The noise handshake hash which uniquely identifies the noise session. | ||
http://noiseprotocol.org/noise.html#channel-binding | ||
#### `handlers.onauthenticate(remotePublicKey, done)` | ||
@@ -88,0 +94,0 @@ |
30
test.js
@@ -256,1 +256,31 @@ const tape = require('tape') | ||
}) | ||
tape('handshakeHash', function (t) { | ||
t.plan(3) | ||
var pending = 3 | ||
const a = new SHP(true, { | ||
onhandshake () { | ||
if (--pending === 0) process.nextTick(check) | ||
}, | ||
send (data) { | ||
process.nextTick(() => b.recv(data)) | ||
} | ||
}) | ||
const b = new SHP(false, { | ||
onhandshake () { | ||
if (--pending === 0) process.nextTick(check) | ||
}, | ||
send (data) { | ||
process.nextTick(() => a.recv(data)) | ||
} | ||
}) | ||
if (--pending === 0) check() | ||
function check () { | ||
t.ok(a.handshakeHash) | ||
t.ok(b.handshakeHash) | ||
t.deepEqual(a.handshakeHash, b.handshakeHash) | ||
} | ||
}) |
56541
1714
169