From dd94793e23ee32a3c4b611a084c202eb02f516ed Mon Sep 17 00:00:00 2001 From: Belma Gutlic Date: Sat, 11 Jan 2020 20:27:26 +0100 Subject: [PATCH] Fix eslint --- src/@types/handshake.ts | 2 +- src/@types/libp2p.ts | 4 ++-- src/crypto.ts | 6 +++--- src/handshake-xx-fallback.ts | 4 ---- src/noise.ts | 6 +++--- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/@types/handshake.ts b/src/@types/handshake.ts index 265f769..cb67eeb 100644 --- a/src/@types/handshake.ts +++ b/src/@types/handshake.ts @@ -3,7 +3,7 @@ import {KeyPair} from "./libp2p"; export type Hkdf = [bytes, bytes, bytes]; -export interface MessageBuffer { +export type MessageBuffer = { ne: bytes32; ns: bytes; ciphertext: bytes; diff --git a/src/@types/libp2p.ts b/src/@types/libp2p.ts index 58ecd87..8f0ac27 100644 --- a/src/@types/libp2p.ts +++ b/src/@types/libp2p.ts @@ -1,7 +1,7 @@ import { bytes, bytes32 } from "./basic"; import { Duplex } from "it-pair"; -export interface KeyPair { +export type KeyPair = { publicKey: bytes32; privateKey: bytes32; } @@ -18,7 +18,7 @@ export type PeerId = { marshalPrivKey(): bytes; }; -export interface NoiseConnection { +export interface INoiseConnection { remoteEarlyData?(): bytes; secureOutbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise; secureInbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise; diff --git a/src/crypto.ts b/src/crypto.ts index 1c63b6d..83508ec 100644 --- a/src/crypto.ts +++ b/src/crypto.ts @@ -1,14 +1,14 @@ import { Buffer } from "buffer"; import {IHandshake} from "./@types/handshake-interface"; -interface ReturnEncryptionWrapper { +interface IReturnEncryptionWrapper { (source: Iterable): AsyncIterableIterator; } const maxPlaintextLength = 65519; // Returns generator that encrypts payload from the user -export function encryptStream(handshake: IHandshake): ReturnEncryptionWrapper { +export function encryptStream(handshake: IHandshake): IReturnEncryptionWrapper { return async function * (source) { for await (const chunk of source) { const chunkBuffer = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.length); @@ -28,7 +28,7 @@ export function encryptStream(handshake: IHandshake): ReturnEncryptionWrapper { // Decrypt received payload to the user -export function decryptStream(handshake: IHandshake): ReturnEncryptionWrapper { +export function decryptStream(handshake: IHandshake): IReturnEncryptionWrapper { return async function * (source) { for await (const chunk of source) { const chunkBuffer = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.length); diff --git a/src/handshake-xx-fallback.ts b/src/handshake-xx-fallback.ts index 223ee2b..c01539b 100644 --- a/src/handshake-xx-fallback.ts +++ b/src/handshake-xx-fallback.ts @@ -5,10 +5,6 @@ import { XX } from "./handshakes/xx"; import { KeyPair, PeerId } from "./@types/libp2p"; import { bytes, bytes32 } from "./@types/basic"; import { - createHandshakePayload, - getHandshakePayload, - signEarlyDataPayload, - signPayload, verifySignedPayload, } from "./utils"; import { logger } from "./logger"; diff --git a/src/noise.ts b/src/noise.ts index 6f99fab..676beb3 100644 --- a/src/noise.ts +++ b/src/noise.ts @@ -13,7 +13,7 @@ import { generateKeypair, getPayload } from "./utils"; import { uint16BEDecode, uint16BEEncode } from "./encoder"; import { decryptStream, encryptStream } from "./crypto"; import { bytes } from "./@types/basic"; -import { NoiseConnection, PeerId, KeyPair, SecureOutbound } from "./@types/libp2p"; +import { INoiseConnection, PeerId, KeyPair, SecureOutbound } from "./@types/libp2p"; import { Duplex } from "./@types/it-pair"; import {IHandshake} from "./@types/handshake-interface"; @@ -26,7 +26,7 @@ type HandshakeParams = { remotePeer: PeerId; }; -export class Noise implements NoiseConnection { +export class Noise implements INoiseConnection { public protocol = "/noise"; private readonly prologue = Buffer.from(this.protocol); @@ -163,7 +163,7 @@ export class Noise implements NoiseConnection { params: HandshakeParams, payload: bytes, ): Promise { - const { isInitiator, localPeer, remotePeer, connection } = params; + const { isInitiator, remotePeer, connection } = params; const handshake = new IKHandshake(isInitiator, payload, this.prologue, this.staticKeys, connection, remotePeer); // TODO