Skip to content

Commit ead1514

Browse files
committed
fix: ts and lint errors
1 parent 2df5f95 commit ead1514

22 files changed

+168
-161
lines changed

src/@types/basic.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {Buffer} from 'buffer';
1+
import { Buffer } from 'buffer'
22

3-
export type bytes = Buffer;
4-
export type bytes32 = Buffer;
5-
export type bytes16 = Buffer;
3+
export type bytes = Buffer
4+
export type bytes32 = Buffer
5+
export type bytes16 = Buffer
66

7-
export type uint32 = number;
8-
export type uint64 = number;
7+
export type uint32 = number
8+
export type uint64 = number
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {bytes} from "./basic";
2-
import {NoiseSession} from "./handshake";
3-
import PeerId from "peer-id";
1+
import { bytes } from './basic'
2+
import { NoiseSession } from './handshake'
3+
import PeerId from 'peer-id'
44

55
export interface IHandshake {
6-
session: NoiseSession;
7-
remotePeer: PeerId;
8-
remoteEarlyData: Buffer;
9-
encrypt(plaintext: bytes, session: NoiseSession): bytes;
10-
decrypt(ciphertext: bytes, session: NoiseSession): {plaintext: bytes; valid: boolean};
6+
session: NoiseSession
7+
remotePeer: PeerId
8+
remoteEarlyData: Buffer
9+
encrypt: (plaintext: bytes, session: NoiseSession) => bytes
10+
decrypt: (ciphertext: bytes, session: NoiseSession) => {plaintext: bytes, valid: boolean}
1111
}

src/@types/handshake.d.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
import {bytes, bytes32, uint32, uint64} from "./basic";
2-
import {KeyPair} from "./libp2p";
1+
import { bytes, bytes32, uint32, uint64 } from './basic'
2+
import { KeyPair } from './libp2p'
33

4-
export type Hkdf = [bytes, bytes, bytes];
4+
export type Hkdf = [bytes, bytes, bytes]
55

6-
export type MessageBuffer = {
7-
ne: bytes32;
8-
ns: bytes;
9-
ciphertext: bytes;
6+
export interface MessageBuffer {
7+
ne: bytes32
8+
ns: bytes
9+
ciphertext: bytes
1010
}
1111

12-
export type CipherState = {
13-
k: bytes32;
14-
n: uint32;
12+
export interface CipherState {
13+
k: bytes32
14+
n: uint32
1515
}
1616

17-
export type SymmetricState = {
18-
cs: CipherState;
19-
ck: bytes32; // chaining key
20-
h: bytes32; // handshake hash
17+
export interface SymmetricState {
18+
cs: CipherState
19+
ck: bytes32 // chaining key
20+
h: bytes32 // handshake hash
2121
}
2222

23-
export type HandshakeState = {
24-
ss: SymmetricState;
25-
s: KeyPair;
26-
e?: KeyPair;
27-
rs: bytes32;
28-
re: bytes32;
29-
psk: bytes32;
23+
export interface HandshakeState {
24+
ss: SymmetricState
25+
s: KeyPair
26+
e?: KeyPair
27+
rs: bytes32
28+
re: bytes32
29+
psk: bytes32
3030
}
3131

32-
export type NoiseSession = {
33-
hs: HandshakeState;
34-
h?: bytes32;
35-
cs1?: CipherState;
36-
cs2?: CipherState;
37-
mc: uint64;
38-
i: boolean;
32+
export interface NoiseSession {
33+
hs: HandshakeState
34+
h?: bytes32
35+
cs1?: CipherState
36+
cs2?: CipherState
37+
mc: uint64
38+
i: boolean
3939
}
4040

4141
export interface INoisePayload {
42-
identityKey: bytes;
43-
identitySig: bytes;
44-
data: bytes;
42+
identityKey: bytes
43+
identitySig: bytes
44+
data: bytes
4545
}

src/@types/it-length-prefixed/index.d.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ declare module 'it-length-prefixed' {
33
import { Buffer } from 'buffer'
44

55
interface LengthDecoderFunction {
6-
(data: Buffer | BufferList): number;
7-
bytes: number;
6+
(data: Buffer | BufferList): number
7+
bytes: number
88
}
99

1010
interface LengthEncoderFunction {
11-
(value: number, target: Buffer, offset: number): number|Buffer;
12-
bytes: number;
11+
(value: number, target: Buffer, offset: number): number|Buffer
12+
bytes: number
1313
}
1414

1515
interface Encoder {
16-
(options?: Partial<{lengthEncoder: LengthEncoderFunction}>): AsyncGenerator<BufferList, Buffer>;
17-
single: (chunk: Buffer, options?: Partial<{lengthEncoder: LengthEncoderFunction}>) => BufferList;
18-
MIN_POOL_SIZE: number;
19-
DEFAULT_POOL_SIZE: number;
16+
(options?: Partial<{lengthEncoder: LengthEncoderFunction}>): AsyncGenerator<BufferList, Buffer>
17+
single: (chunk: Buffer, options?: Partial<{lengthEncoder: LengthEncoderFunction}>) => BufferList
18+
MIN_POOL_SIZE: number
19+
DEFAULT_POOL_SIZE: number
2020
}
2121

2222
interface DecoderOptions {
23-
lengthDecoder: LengthDecoderFunction;
24-
maxLengthLength: number;
25-
maxDataLength: number;
23+
lengthDecoder: LengthDecoderFunction
24+
maxLengthLength: number
25+
maxDataLength: number
2626
}
2727

2828
interface Decoder {
29-
(options?: Partial<DecoderOptions>): AsyncGenerator<BufferList, BufferList>;
30-
fromReader: (reader: any, options?: Partial<DecoderOptions>) => BufferList;
31-
MAX_LENGTH_LENGTH: number;
32-
MAX_DATA_LENGTH: number;
29+
(options?: Partial<DecoderOptions>): AsyncGenerator<BufferList, BufferList>
30+
fromReader: (reader: any, options?: Partial<DecoderOptions>) => BufferList
31+
MAX_LENGTH_LENGTH: number
32+
MAX_DATA_LENGTH: number
3333
}
3434

3535
export const encode: Encoder

src/@types/it-pair/index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
declare module 'it-pair' {
2-
export type Duplex = [Stream, Stream];
2+
export type Duplex = [Stream, Stream]
33

4-
type Stream = {
5-
sink(source: Iterable<any>): void;
6-
source: Record<string, any>;
4+
interface Stream {
5+
sink: (source: Iterable<any>) => void
6+
source: Record<string, any>
77
}
88
}

src/@types/libp2p.d.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import { bytes, bytes32 } from "./basic";
2-
import PeerId from "peer-id";
1+
import { bytes, bytes32 } from './basic'
2+
import PeerId from 'peer-id'
33

4-
export type KeyPair = {
5-
publicKey: bytes32;
6-
privateKey: bytes32;
4+
export interface KeyPair {
5+
publicKey: bytes32
6+
privateKey: bytes32
77
}
88

99
export interface INoiseConnection {
10-
remoteEarlyData?(): bytes;
11-
secureOutbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise<SecureOutbound>;
12-
secureInbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise<SecureOutbound>;
10+
remoteEarlyData?: () => bytes
11+
secureOutbound: (localPeer: PeerId, insecure: any, remotePeer: PeerId) => Promise<SecureOutbound>
12+
secureInbound: (localPeer: PeerId, insecure: any, remotePeer: PeerId) => Promise<SecureOutbound>
1313
}
1414

15-
export type SecureOutbound = {
16-
conn: any;
17-
remoteEarlyData: Buffer;
18-
remotePeer: PeerId;
15+
export interface SecureOutbound {
16+
conn: any
17+
remoteEarlyData: Buffer
18+
remotePeer: PeerId
1919
}
20-

src/crypto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IHandshake } from './@types/handshake-interface'
33
import { NOISE_MSG_MAX_LENGTH_BYTES, NOISE_MSG_MAX_LENGTH_BYTES_WITHOUT_TAG } from './constants'
44

55
interface IReturnEncryptionWrapper {
6-
(source: Iterable<Uint8Array>): AsyncIterableIterator<Uint8Array>;
6+
(source: Iterable<Uint8Array>): AsyncIterableIterator<Uint8Array>
77
}
88

99
// Returns generator that encrypts payload from the user

src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import BufferList from 'bl'
22

33
export class FailedIKError extends Error {
4-
public initialMsg: string|BufferList|Buffer;
4+
public initialMsg: string|BufferList|Buffer
55

66
constructor (initialMsg: string|BufferList|Buffer, message?: string) {
77
super(message)

src/handshake-ik.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ import {
1919
import PeerId from 'peer-id'
2020

2121
export 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
}

src/handshake-xx-fallback.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { decode0, decode1 } from './encoder'
1010
import PeerId from 'peer-id'
1111

1212
export class XXFallbackHandshake extends XXHandshake {
13-
private ephemeralKeys?: KeyPair;
14-
private initialMsg: bytes;
13+
private readonly ephemeralKeys?: KeyPair
14+
private readonly initialMsg: bytes
1515

1616
constructor (
1717
isInitiator: boolean,
@@ -73,7 +73,8 @@ export class XXFallbackHandshake extends XXHandshake {
7373
await verifySignedPayload(this.session.hs.rs, decodedPayload, this.remotePeer)
7474
this.setRemoteEarlyData(decodedPayload.data)
7575
} catch (e) {
76-
throw new Error(`Error occurred while verifying signed payload from responder: ${e.message}`)
76+
const err = e as Error
77+
throw new Error(`Error occurred while verifying signed payload from responder: ${err.message}`)
7778
}
7879
logger('All good with the signature!')
7980
} else {

0 commit comments

Comments
 (0)