From b69769f8dd815d689e740fb24a13381e75f0e270 Mon Sep 17 00:00:00 2001 From: morrigan Date: Fri, 8 Nov 2019 14:03:34 +0100 Subject: [PATCH] Create skeleton --- src/encrypt.ts | 3 --- src/index.ts | 7 ++----- src/noise.ts | 17 +++++++++++++++++ src/types/libp2p.ts | 15 +++++++++++++++ test/index.test.ts | 9 +++++---- 5 files changed, 39 insertions(+), 12 deletions(-) delete mode 100644 src/encrypt.ts create mode 100644 src/noise.ts create mode 100644 src/types/libp2p.ts diff --git a/src/encrypt.ts b/src/encrypt.ts deleted file mode 100644 index fbcbfeb..0000000 --- a/src/encrypt.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function encrypt() { - return "Encrypt world"; -} diff --git a/src/index.ts b/src/index.ts index 9c1cda0..3cf64c4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,5 @@ -import { encrypt } from './encrypt'; - -const tag = '/noise'; +import { Noise } from './noise'; export { - tag, - encrypt, + Noise, } diff --git a/src/noise.ts b/src/noise.ts new file mode 100644 index 0000000..24887a3 --- /dev/null +++ b/src/noise.ts @@ -0,0 +1,17 @@ +import { bytes } from "./types/basic"; +import { Connection } from "./types/libp2p"; + +export class Noise { + constructor(privateKey: bytes, staticNoiseKey?: bytes, earlyData?: bytes) { + + } + + public tag() { + return '/noise'; + } + + public encrypt(InsecureConnection: Connection, remotePublicKey: bytes) { + + } + +} diff --git a/src/types/libp2p.ts b/src/types/libp2p.ts new file mode 100644 index 0000000..62303fa --- /dev/null +++ b/src/types/libp2p.ts @@ -0,0 +1,15 @@ +type PeerId = { + id: string, + privKey: string, + pubKey: string, +}; + +type ConnectionStat = { + direction: "inbound" | "outbound", +} + +export interface Connection { + localPeer: PeerId, + remotePeer: PeerId, + stat: ConnectionStat, +} diff --git a/test/index.test.ts b/test/index.test.ts index d13bbbe..6f1fc72 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1,9 +1,10 @@ import { expect } from "chai"; -import { tag, encrypt} from "../src"; +import { Noise } from "../src"; describe("Index", () => { - it("should expose right tag and encrypt function", () => { - expect(tag).to.equal('/noise'); - expect(typeof(encrypt)).to.equal('function'); + it("should expose class with tag and encrypt functions", () => { + const noise = new Noise(Buffer.from("privatekey")); + expect(noise.tag()).to.equal('/noise'); + expect(typeof(noise.encrypt)).to.equal('function'); }) });