From fdfadfa794604512846aed2d3b2d21345a7afdf1 Mon Sep 17 00:00:00 2001 From: morrigan Date: Mon, 4 Nov 2019 22:09:42 +0100 Subject: [PATCH] Address PR comments --- package.json | 2 +- src/xx.ts | 36 +++++++++++++++--------------------- tsconfig.json | 6 +++--- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index a65556d..8775f27 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "js-libp2p-noise", "version": "1.0.0", - "main": "index", + "main": "dist/index.js", "repository": "git@github.com:NodeFactoryIo/js-libp2p-noise.git", "author": "NodeFactory ", "license": "MIT", diff --git a/src/xx.ts b/src/xx.ts index b80601e..e59f4bd 100644 --- a/src/xx.ts +++ b/src/xx.ts @@ -28,17 +28,17 @@ type SymmetricState = { type HandshakeState = { ss: SymmetricState, s: KeyPair, - e: KeyPair, + e?: KeyPair, rs: bytes32, - re: bytes32, + re?: bytes32, psk: bytes32, } type NoiseSession = { hs: HandshakeState, - h: bytes32, - cs1: CipherState, - cs2: CipherState, + h?: bytes32, + cs1?: CipherState, + cs2?: CipherState, mc: uint64, i: boolean, } @@ -51,25 +51,19 @@ export class XXHandshake { } private async initializeInitiator(prologue: bytes32, s: KeyPair, rs: bytes32, psk: bytes32) : Promise { - let e: KeyPair; - let re: bytes32; const name = "Noise_XX_25519_ChaChaPoly_SHA256"; const ss = await this.initializeSymmetric(name); await this.mixHash(ss, prologue); - // @ts-ignore-next-line - return {ss, s, e, rs, re, psk}; + return { ss, s, rs, psk }; } private async initializeResponder(prologue: bytes32, s: KeyPair, rs: bytes32, psk: bytes32) : Promise { - let e: KeyPair; - let re: bytes32; const name = "Noise_XX_25519_ChaChaPoly_SHA256"; const ss = await this.initializeSymmetric(name); await this.mixHash(ss, prologue); - // @ts-ignore-next-line - return {ss, s, e, rs, re, psk}; + return { ss, s, rs, psk }; } private incrementNonce(n: uint32) : uint32 { @@ -257,20 +251,20 @@ export class XXHandshake { } public async initSession(initiator: boolean, prologue: bytes32, s: KeyPair, rs: bytes32) : Promise { - // TODO: Create noisesession object/class - // @ts-ignore-next-line - let session: NoiseSession = {}; const psk = this.createEmptyKey(); + let hs; if (initiator) { - session.hs = await this.initializeInitiator(prologue, s, rs, psk); + hs = await this.initializeInitiator(prologue, s, rs, psk); } else { - session.hs = await this.initializeResponder(prologue, s, rs, psk); + hs = await this.initializeResponder(prologue, s, rs, psk); } - session.i = initiator; - session.mc = 0; - return session; + return { + hs, + i: initiator, + mc: 0 + }; } public async sendMessage(session: NoiseSession, message: bytes) : Promise { diff --git a/tsconfig.json b/tsconfig.json index f2a3ef9..fccc322 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,12 +6,12 @@ "esModuleInterop": true, "noImplicitAny": false, "typeRoots": [ - "./node_modules/@types" + "./node_modules/@types", + "./node_modules/bn.js-typings/index.d.ts" ] }, "include": [ - "**/src/**/*.ts", - "./node_modules/bn.js-typings/index.d.ts" + "**/src/**/*.ts" ], "exclude": [ "node_modules"