From 53c7f94979e739e4584550b27d7161637328d3c5 Mon Sep 17 00:00:00 2001 From: morrigan Date: Mon, 25 Nov 2019 14:03:23 +0100 Subject: [PATCH] Fix reading peer id --- src/@types/libp2p.ts | 10 +++++++--- src/noise.ts | 17 ++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/@types/libp2p.ts b/src/@types/libp2p.ts index edf4dbc..1698dfe 100644 --- a/src/@types/libp2p.ts +++ b/src/@types/libp2p.ts @@ -7,9 +7,13 @@ export interface KeyPair { } export type PeerId = { - id: string, - privKey: string, - pubKey: string, + id: bytes, + privKey: { + bytes: bytes, + }, + pubKey: { + bytes: bytes, + }, }; export interface NoiseConnection { diff --git a/src/noise.ts b/src/noise.ts index 9fbb7d9..b3be2df 100644 --- a/src/noise.ts +++ b/src/noise.ts @@ -47,11 +47,11 @@ export class Noise implements NoiseConnection { */ public async secureOutbound(localPeer: PeerId, connection: any, remotePeer: PeerId) : Promise { const wrappedConnection = Wrap(connection); - const remotePublicKey = Buffer.from(remotePeer.pubKey); - const session = await this.createSecureConnection(wrappedConnection, remotePublicKey, true); + const remotePublicKey = remotePeer.pubKey.bytes; + const conn = await this.createSecureConnection(wrappedConnection, remotePublicKey, true); return { - conn: session, + conn, remotePeer, } } @@ -63,12 +63,15 @@ export class Noise implements NoiseConnection { * @param {PeerId} remotePeer - optional PeerId of the initiating peer, if known. This may only exist during transport upgrades. * @returns {Promise} */ - // tslint:disable-next-line public async secureInbound(localPeer: PeerId, connection: any, remotePeer: PeerId) : Promise { + const wrappedConnection = Wrap(connection); + const remotePublicKey = remotePeer.pubKey.bytes; + const conn = await this.createSecureConnection(wrappedConnection, remotePublicKey, false); + return { - conn: undefined, - remotePeer - } + conn, + remotePeer, + }; } private async createSecureConnection(