mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-25 08:22:35 +00:00
Update noise interface
This commit is contained in:
parent
2bb63e3e91
commit
ac12fbf987
26
src/noise.ts
26
src/noise.ts
@ -48,7 +48,7 @@ export class Noise implements NoiseConnection {
|
||||
public async secureOutbound(localPeer: PeerId, connection: any, remotePeer: PeerId): Promise<SecureOutbound> {
|
||||
const wrappedConnection = Wrap(connection);
|
||||
const libp2pPublicKey = localPeer.marshalPubKey();
|
||||
const handshake = await this.performXXHandshake(wrappedConnection, true, libp2pPublicKey, remotePeer);
|
||||
const handshake = await this.performHandshake(wrappedConnection, true, libp2pPublicKey, remotePeer);
|
||||
const conn = await this.createSecureConnection(wrappedConnection, handshake);
|
||||
|
||||
return {
|
||||
@ -67,7 +67,7 @@ export class Noise implements NoiseConnection {
|
||||
public async secureInbound(localPeer: PeerId, connection: any, remotePeer: PeerId): Promise<SecureOutbound> {
|
||||
const wrappedConnection = Wrap(connection);
|
||||
const libp2pPublicKey = localPeer.marshalPubKey();
|
||||
const handshake = await this.performXXHandshake(wrappedConnection, false, libp2pPublicKey, remotePeer);
|
||||
const handshake = await this.performHandshake(wrappedConnection, false, libp2pPublicKey, remotePeer);
|
||||
const conn = await this.createSecureConnection(wrappedConnection, handshake);
|
||||
|
||||
return {
|
||||
@ -76,6 +76,28 @@ export class Noise implements NoiseConnection {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* If Noise pipes supported, tries IK handshake first with XX as fallback if it fails.
|
||||
* If remote peer static key is unknown, use XX.
|
||||
* @param connection
|
||||
* @param isInitiator
|
||||
* @param libp2pPublicKey
|
||||
* @param remotePeer
|
||||
*/
|
||||
private async performHandshake(
|
||||
connection: WrappedConnection,
|
||||
isInitiator: boolean,
|
||||
libp2pPublicKey: bytes,
|
||||
remotePeer: PeerId,
|
||||
): Promise<Handshake> {
|
||||
if (false) {
|
||||
// TODO: Implement noise pipes
|
||||
|
||||
} else {
|
||||
return await this.performXXHandshake(connection, isInitiator, libp2pPublicKey, remotePeer)
|
||||
}
|
||||
}
|
||||
|
||||
private async performXXHandshake(
|
||||
connection: WrappedConnection,
|
||||
isInitiator: boolean,
|
||||
|
Loading…
x
Reference in New Issue
Block a user