diff --git a/src/handshake-xx-fallback.ts b/src/handshake-xx-fallback.ts index 900705e..a7c0788 100644 --- a/src/handshake-xx-fallback.ts +++ b/src/handshake-xx-fallback.ts @@ -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; } diff --git a/src/noise.ts b/src/noise.ts index 81656cf..249e76d 100644 --- a/src/noise.ts +++ b/src/noise.ts @@ -130,7 +130,7 @@ export class Noise implements NoiseConnection { ): Promise { 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(); diff --git a/test/xx-fallback-handshake.test.ts b/test/xx-fallback-handshake.test.ts index 130a8ff..7eb7e28 100644 --- a/test/xx-fallback-handshake.test.ts +++ b/test/xx-fallback-handshake.test.ts @@ -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();