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

fix: return public key #121

Merged
merged 2 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/handshake/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ exports.identify = async (state, msg) => {
if (state.id.remote.toString() !== remoteId.toString()) {
throw new UnexpectedPeerError('Dialed to the wrong peer: IDs do not match!')
}
state.id.remote.pubKey = state.key.remote
} else {
state.id.remote = remoteId
}
Expand Down
14 changes: 11 additions & 3 deletions test/secio.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

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

it('performs a spec compliant inbound exchange', async () => {
const [inboundConnection, outboundConnection] = duplexPair()
await Promise.all([
const [result] = await Promise.all([
Secio.secureInbound(remotePeer, inboundConnection, null),
(async () => {
const wrap = Handshake(outboundConnection)
Expand Down Expand Up @@ -102,12 +103,16 @@ describe('secio', () => {
expect(ourNonce.slice()).to.eql(state.proposal.out.rand)
})()
])

expect(result.remotePeer.pubKey).to.exist()
expect(result.remotePeer.pubKey.bytes).to.eql(localPeer.pubKey.bytes)
})

it('performs a spec compliant outbound exchange', async () => {
const [inboundConnection, outboundConnection] = duplexPair()
await Promise.all([
Secio.secureOutbound(localPeer, outboundConnection, remotePeer),
const cidOnlyPeerId = PeerId.createFromCID(remotePeer.toB58String())
const [result] = await Promise.all([
Secio.secureOutbound(localPeer, outboundConnection, cidOnlyPeerId),
(async () => {
const wrap = Handshake(inboundConnection)
const state = new State(remotePeer, localPeer)
Expand Down Expand Up @@ -176,5 +181,8 @@ describe('secio', () => {
expect(ourNonce.slice()).to.eql(state.proposal.out.rand)
})()
])

expect(result.remotePeer.pubKey).to.exist()
expect(result.remotePeer.pubKey.bytes).to.eql(remotePeer.pubKey.bytes)
})
})