@@ -19,16 +19,16 @@ import {
1919import PeerId from 'peer-id'
2020
2121export class IKHandshake implements IHandshake {
22- public isInitiator : boolean ;
23- public session : NoiseSession ;
24- public remotePeer ! : PeerId ;
25- public remoteEarlyData : Buffer ;
22+ public isInitiator : boolean
23+ public session : NoiseSession
24+ public remotePeer ! : PeerId
25+ public remoteEarlyData : Buffer
2626
27- private payload : bytes ;
28- private prologue : bytes32 ;
29- private staticKeypair : KeyPair ;
30- private connection : WrappedConnection ;
31- private ik : IK ;
27+ private readonly payload : bytes
28+ private readonly prologue : bytes32
29+ private readonly staticKeypair : KeyPair
30+ private readonly connection : WrappedConnection
31+ private readonly ik : IK
3232
3333 constructor (
3434 isInitiator : boolean ,
@@ -48,7 +48,7 @@ export class IKHandshake implements IHandshake {
4848 if ( remotePeer ) {
4949 this . remotePeer = remotePeer
5050 }
51- this . ik = handshake || new IK ( )
51+ this . ik = handshake ?? new IK ( )
5252 this . session = this . ik . initSession ( this . isInitiator , this . prologue , this . staticKeypair , remoteStaticKey )
5353 this . remoteEarlyData = Buffer . alloc ( 0 )
5454 }
@@ -79,9 +79,10 @@ export class IKHandshake implements IHandshake {
7979 logger ( 'IK Stage 0 - Responder successfully verified payload!' )
8080 logRemoteEphemeralKey ( this . session . hs . re )
8181 } catch ( e ) {
82+ const err = e as Error
8283 logger ( 'Responder breaking up with IK handshake in stage 0.' )
8384
84- throw new FailedIKError ( receivedMsg , `Error occurred while verifying initiator's signed payload: ${ e . message } ` )
85+ throw new FailedIKError ( receivedMsg , `Error occurred while verifying initiator's signed payload: ${ err . message } ` )
8586 }
8687 }
8788 }
@@ -104,8 +105,9 @@ export class IKHandshake implements IHandshake {
104105 logger ( 'IK Stage 1 - Initiator successfully verified payload!' )
105106 logRemoteEphemeralKey ( this . session . hs . re )
106107 } catch ( e ) {
108+ const err = e as Error
107109 logger ( 'Initiator breaking up with IK handshake in stage 1.' )
108- throw new FailedIKError ( receivedMsg , `Error occurred while verifying responder's signed payload: ${ e . message } ` )
110+ throw new FailedIKError ( receivedMsg , `Error occurred while verifying responder's signed payload: ${ err . message } ` )
109111 }
110112 } else {
111113 logger ( 'IK Stage 1 - Responder sending message...' )
@@ -117,7 +119,7 @@ export class IKHandshake implements IHandshake {
117119 logCipherState ( this . session )
118120 }
119121
120- public decrypt ( ciphertext : bytes , session : NoiseSession ) : { plaintext : bytes ; valid : boolean } {
122+ public decrypt ( ciphertext : bytes , session : NoiseSession ) : { plaintext : bytes , valid : boolean } {
121123 const cs = this . getCS ( session , false )
122124 return this . ik . decryptWithAd ( cs , Buffer . alloc ( 0 ) , ciphertext )
123125 }
0 commit comments