mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-15 03:41:31 +00:00
Fix reading peer id
This commit is contained in:
@ -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 {
|
||||||
|
17
src/noise.ts
17
src/noise.ts
@ -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(
|
||||||
|
Reference in New Issue
Block a user