Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit 70a8a98

Browse files
jacobheunDidrik Nordström
and
Didrik Nordström
authored
fix: return public key (#121)
* Populate the remote public key consistently * test: verify pubkey exists in results Co-authored-by: Didrik Nordström <[email protected]>
1 parent d2efc8c commit 70a8a98

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/handshake/crypto.js

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ exports.identify = async (state, msg) => {
6868
if (state.id.remote.toString() !== remoteId.toString()) {
6969
throw new UnexpectedPeerError('Dialed to the wrong peer: IDs do not match!')
7070
}
71+
state.id.remote.pubKey = state.key.remote
7172
} else {
7273
state.id.remote = remoteId
7374
}

test/secio.spec.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const dirtyChai = require('dirty-chai')
66
const expect = chai.expect
77
chai.use(dirtyChai)
88

9+
const PeerId = require('peer-id')
910
const duplexPair = require('it-pair/duplex')
1011
const Handshake = require('it-pb-rpc')
1112
const Secio = require('../src')
@@ -32,7 +33,7 @@ describe('secio', () => {
3233

3334
it('performs a spec compliant inbound exchange', async () => {
3435
const [inboundConnection, outboundConnection] = duplexPair()
35-
await Promise.all([
36+
const [result] = await Promise.all([
3637
Secio.secureInbound(remotePeer, inboundConnection, null),
3738
(async () => {
3839
const wrap = Handshake(outboundConnection)
@@ -102,12 +103,16 @@ describe('secio', () => {
102103
expect(ourNonce.slice()).to.eql(state.proposal.out.rand)
103104
})()
104105
])
106+
107+
expect(result.remotePeer.pubKey).to.exist()
108+
expect(result.remotePeer.pubKey.bytes).to.eql(localPeer.pubKey.bytes)
105109
})
106110

107111
it('performs a spec compliant outbound exchange', async () => {
108112
const [inboundConnection, outboundConnection] = duplexPair()
109-
await Promise.all([
110-
Secio.secureOutbound(localPeer, outboundConnection, remotePeer),
113+
const cidOnlyPeerId = PeerId.createFromCID(remotePeer.toB58String())
114+
const [result] = await Promise.all([
115+
Secio.secureOutbound(localPeer, outboundConnection, cidOnlyPeerId),
111116
(async () => {
112117
const wrap = Handshake(inboundConnection)
113118
const state = new State(remotePeer, localPeer)
@@ -176,5 +181,8 @@ describe('secio', () => {
176181
expect(ourNonce.slice()).to.eql(state.proposal.out.rand)
177182
})()
178183
])
184+
185+
expect(result.remotePeer.pubKey).to.exist()
186+
expect(result.remotePeer.pubKey.bytes).to.eql(remotePeer.pubKey.bytes)
179187
})
180188
})

0 commit comments

Comments
 (0)