From 6dc8e8288d8f9a83d9c96f9fb54c4ad2919a6da6 Mon Sep 17 00:00:00 2001 From: morrigan Date: Thu, 28 Nov 2019 17:53:27 +0100 Subject: [PATCH] Fix eslint --- src/@types/it-pb-rpc/index.d.ts | 10 +++++----- src/@types/libp2p.ts | 24 ++++++++++++------------ src/crypto.ts | 6 +++--- src/handshake.ts | 6 +++--- src/noise.ts | 6 +++--- src/utils.ts | 10 +++++----- src/xx.ts | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/@types/it-pb-rpc/index.d.ts b/src/@types/it-pb-rpc/index.d.ts index c8741f3..3424cf9 100644 --- a/src/@types/it-pb-rpc/index.d.ts +++ b/src/@types/it-pb-rpc/index.d.ts @@ -2,11 +2,11 @@ declare module "it-pb-rpc" { import { Buffer } from "buffer"; import { Duplex } from "it-pair"; type WrappedDuplex = { - read(bytes?: number): Promise, - readLP(): Promise, - write(input: Buffer): void, - writeLP(input: Buffer): void, - unwrap(): Duplex + read(bytes?: number): Promise; + readLP(): Promise; + write(input: Buffer): void; + writeLP(input: Buffer): void; + unwrap(): Duplex; } function Wrap (duplex: any): WrappedDuplex; diff --git a/src/@types/libp2p.ts b/src/@types/libp2p.ts index 2c3323f..46bf95f 100644 --- a/src/@types/libp2p.ts +++ b/src/@types/libp2p.ts @@ -2,28 +2,28 @@ import { bytes, bytes32 } from "./basic"; import { Duplex } from "it-pair"; export interface KeyPair { - publicKey: bytes32, - privateKey: bytes32, + publicKey: bytes32; + privateKey: bytes32; } export type PeerId = { - id: bytes, + id: bytes; privKey: { - marshal(): bytes, - }, + marshal(): bytes; + }; pubKey: { - marshal(): bytes, - }, + marshal(): bytes; + }; }; export interface NoiseConnection { - remoteEarlyData?(): bytes, - secureOutbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise, - secureInbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise, + remoteEarlyData?(): bytes; + secureOutbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise; + secureInbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise; } export type SecureOutbound = { - conn: Duplex, - remotePeer: PeerId, + conn: Duplex; + remotePeer: PeerId; } diff --git a/src/crypto.ts b/src/crypto.ts index d3a8a06..590ac11 100644 --- a/src/crypto.ts +++ b/src/crypto.ts @@ -2,12 +2,12 @@ import { Duplex } from "it-pair"; import { NoiseSession } from "./xx"; import { Handshake } from "./handshake"; -interface IReturnEncryptionWrapper { +interface ReturnEncryptionWrapper { (source: any): any; } // Returns generator that encrypts payload from the user -export function encryptStream(handshake: Handshake, session: NoiseSession) : IReturnEncryptionWrapper { +export function encryptStream(handshake: Handshake, session: NoiseSession): ReturnEncryptionWrapper { return async function * (source) { for await (const chunk of source) { const data = await handshake.encrypt(chunk, session); @@ -18,7 +18,7 @@ export function encryptStream(handshake: Handshake, session: NoiseSession) : IRe // Decrypt received payload to the user -export function decryptStream(handshake: Handshake, session: NoiseSession) : IReturnEncryptionWrapper { +export function decryptStream(handshake: Handshake, session: NoiseSession): ReturnEncryptionWrapper { return async function * (source) { for await (const chunk of source) { const decrypted = await handshake.decrypt(chunk, session); diff --git a/src/handshake.ts b/src/handshake.ts index 55a9e4a..ed4f594 100644 --- a/src/handshake.ts +++ b/src/handshake.ts @@ -45,7 +45,7 @@ export class Handshake { } // stage 0 - async propose(earlyData?: bytes) : Promise { + async propose(earlyData?: bytes): Promise { if (this.isInitiator) { const signedPayload = signPayload(this.libp2pPrivateKey, getHandshakePayload(this.staticKeys.publicKey)); const signedEarlyDataPayload = signEarlyDataPayload(this.libp2pPrivateKey, earlyData || Buffer.alloc(0)); @@ -68,7 +68,7 @@ export class Handshake { } // stage 1 - async exchange() : Promise { + async exchange(): Promise { if (this.isInitiator) { const receivedMessageBuffer = decodeMessageBuffer((await this.connection.readLP()).slice()); const plaintext = await this.xx.recvMessage(this.session, receivedMessageBuffer); @@ -89,7 +89,7 @@ export class Handshake { } // stage 2 - async finish() : Promise { + async finish(): Promise { if (this.isInitiator) { const messageBuffer = await this.xx.sendMessage(this.session, Buffer.alloc(0)); this.connection.writeLP(encodeMessageBuffer(messageBuffer)); diff --git a/src/noise.ts b/src/noise.ts index 4e783fc..9d09b41 100644 --- a/src/noise.ts +++ b/src/noise.ts @@ -45,7 +45,7 @@ export class Noise implements NoiseConnection { * @param {PeerId} remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer. * @returns {Promise} */ - public async secureOutbound(localPeer: PeerId, connection: any, remotePeer: PeerId) : Promise { + public async secureOutbound(localPeer: PeerId, connection: any, remotePeer: PeerId): Promise { const wrappedConnection = Wrap(connection); const libp2pPublicKey = localPeer.pubKey.marshal(); const handshake = await this.performHandshake(wrappedConnection, true, libp2pPublicKey); @@ -64,7 +64,7 @@ export class Noise implements NoiseConnection { * @param {PeerId} remotePeer - optional PeerId of the initiating peer, if known. This may only exist during transport upgrades. * @returns {Promise} */ - public async secureInbound(localPeer: PeerId, connection: any, remotePeer: PeerId) : Promise { + public async secureInbound(localPeer: PeerId, connection: any, remotePeer: PeerId): Promise { const wrappedConnection = Wrap(connection); const libp2pPublicKey = localPeer.pubKey.marshal(); const handshake = await this.performHandshake(wrappedConnection, false, libp2pPublicKey); @@ -94,7 +94,7 @@ export class Noise implements NoiseConnection { private async createSecureConnection( connection: WrappedConnection, handshake: Handshake, - ) : Promise { + ): Promise { // Create encryption box/unbox wrapper const [secure, user] = DuplexPair(); const network = connection.unwrap(); diff --git a/src/utils.ts b/src/utils.ts index 1be87f3..f65da02 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -14,7 +14,7 @@ export async function loadPayloadProto () { return payloadProtoBuf.lookupType("pb.NoiseHandshakePayload"); } -export function generateKeypair() : KeyPair { +export function generateKeypair(): KeyPair { const privateKey = x25519.privateKeyGenerate(); const publicKey = x25519.publicKeyCreate(privateKey); @@ -29,7 +29,7 @@ export async function createHandshakePayload( libp2pPrivateKey: bytes, signedPayload: bytes, signedEarlyData?: EarlyDataPayload, -) : Promise { +): Promise { const NoiseHandshakePayload = await loadPayloadProto(); const earlyDataPayload = signedEarlyData ? { @@ -56,7 +56,7 @@ type EarlyDataPayload = { libp2pDataSignature: bytes; } -export function signEarlyDataPayload(libp2pPrivateKey: bytes, earlyData: bytes) : EarlyDataPayload { +export function signEarlyDataPayload(libp2pPrivateKey: bytes, earlyData: bytes): EarlyDataPayload { const payload = getEarlyDataPayload(earlyData); const signedPayload = signPayload(libp2pPrivateKey, payload); @@ -70,11 +70,11 @@ export const getHandshakePayload = (publicKey: bytes ) => Buffer.concat([Buffer. export const getEarlyDataPayload = (earlyData: bytes) => Buffer.concat([Buffer.from("noise-libp2p-early-data:"), earlyData]); -export function encodeMessageBuffer(message: MessageBuffer) : bytes { +export function encodeMessageBuffer(message: MessageBuffer): bytes { return Buffer.concat([message.ne, message.ns, message.ciphertext]); } -export function decodeMessageBuffer(message: bytes) : MessageBuffer { +export function decodeMessageBuffer(message: bytes): MessageBuffer { return { ne: message.slice(0, 32), ns: message.slice(32, 64), diff --git a/src/xx.ts b/src/xx.ts index d453efc..95aa619 100644 --- a/src/xx.ts +++ b/src/xx.ts @@ -150,7 +150,7 @@ export class XXHandshake { const ck = h; const key = this.createEmptyKey(); - const cs:CipherState = this.initializeKey(key); + const cs: CipherState = this.initializeKey(key); return { cs, ck, h }; }