Make ephemeral keypair optional

This commit is contained in:
Belma Gutlic 2020-01-07 13:20:42 +01:00
parent 73c336088e
commit 28bf51c492
3 changed files with 8 additions and 6 deletions

View File

@ -16,7 +16,7 @@ import { WrappedConnection } from "./noise";
import {decode0, decode1, encode1} from "./encoder";
export class Handshake extends XXHandshake {
private ephemeralKeys: KeyPair;
private ephemeralKeys?: KeyPair;
private initialMsg: bytes;
constructor(
@ -27,12 +27,14 @@ export class Handshake extends XXHandshake {
staticKeys: KeyPair,
connection: WrappedConnection,
remotePeer: PeerId,
ephemeralKeys: KeyPair,
initialMsg: bytes,
ephemeralKeys?: KeyPair,
handshake?: XX,
) {
super(isInitiator, libp2pPrivateKey, libp2pPublicKey, prologue, staticKeys, connection, remotePeer, handshake);
this.ephemeralKeys = ephemeralKeys;
if (ephemeralKeys) {
this.ephemeralKeys = ephemeralKeys;
}
this.initialMsg = initialMsg;
}

View File

@ -130,7 +130,7 @@ export class Noise implements NoiseConnection {
): Promise<XXFallback> {
const { isInitiator, libp2pPublicKey, remotePeer, connection } = params;
const handshake =
new XXFallback(isInitiator, this.privateKey, libp2pPublicKey, this.prologue, this.staticKeys, connection, remotePeer, ephemeralKeys, initialMsg);
new XXFallback(isInitiator, this.privateKey, libp2pPublicKey, this.prologue, this.staticKeys, connection, remotePeer, initialMsg, ephemeralKeys);
try {
await handshake.propose();

View File

@ -48,10 +48,10 @@ describe("XX Fallback Handshake", () => {
});
const handshakeInit =
new Handshake(true, initiatorPrivKey, initiatorPubKey, prologue, staticKeysInitiator, connectionFrom, peerB, ephemeralKeys, initialMsg);
new Handshake(true, initiatorPrivKey, initiatorPubKey, prologue, staticKeysInitiator, connectionFrom, peerB, initialMsg, ephemeralKeys);
const handshakeResp =
new Handshake(false, responderPrivKey, responderPubKey, prologue, staticKeysResponder, connectionTo, peerA, ephemeralKeys, initialMsg);
new Handshake(false, responderPrivKey, responderPubKey, prologue, staticKeysResponder, connectionTo, peerA, initialMsg);
await handshakeInit.propose();