Fix reading peer id

This commit is contained in:
morrigan
2019-11-25 14:03:23 +01:00
parent 579bb0a491
commit 53c7f94979
2 changed files with 17 additions and 10 deletions

View File

@ -7,9 +7,13 @@ export interface KeyPair {
} }
export type PeerId = { export type PeerId = {
id: string, id: bytes,
privKey: string, privKey: {
pubKey: string, bytes: bytes,
},
pubKey: {
bytes: bytes,
},
}; };
export interface NoiseConnection { export interface NoiseConnection {

View File

@ -47,11 +47,11 @@ export class Noise implements NoiseConnection {
*/ */
public async secureOutbound(localPeer: PeerId, connection: any, remotePeer: PeerId) : Promise<SecureOutbound> { public async secureOutbound(localPeer: PeerId, connection: any, remotePeer: PeerId) : Promise<SecureOutbound> {
const wrappedConnection = Wrap(connection); const wrappedConnection = Wrap(connection);
const remotePublicKey = Buffer.from(remotePeer.pubKey); const remotePublicKey = remotePeer.pubKey.bytes;
const session = await this.createSecureConnection(wrappedConnection, remotePublicKey, true); const conn = await this.createSecureConnection(wrappedConnection, remotePublicKey, true);
return { return {
conn: session, conn,
remotePeer, 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. * @param {PeerId} remotePeer - optional PeerId of the initiating peer, if known. This may only exist during transport upgrades.
* @returns {Promise<SecureOutbound>} * @returns {Promise<SecureOutbound>}
*/ */
// tslint:disable-next-line
public async secureInbound(localPeer: PeerId, connection: any, remotePeer: PeerId) : Promise<SecureOutbound> { public async secureInbound(localPeer: PeerId, connection: any, remotePeer: PeerId) : Promise<SecureOutbound> {
const wrappedConnection = Wrap(connection);
const remotePublicKey = remotePeer.pubKey.bytes;
const conn = await this.createSecureConnection(wrappedConnection, remotePublicKey, false);
return { return {
conn: undefined, conn,
remotePeer remotePeer,
} };
} }
private async createSecureConnection( private async createSecureConnection(