Create skeleton

This commit is contained in:
morrigan 2019-11-08 14:03:34 +01:00
parent 90e16e2abe
commit b69769f8dd
5 changed files with 39 additions and 12 deletions

View File

@ -1,3 +0,0 @@
export function encrypt() {
return "Encrypt world";
}

View File

@ -1,8 +1,5 @@
import { encrypt } from './encrypt';
const tag = '/noise';
import { Noise } from './noise';
export {
tag,
encrypt,
Noise,
}

17
src/noise.ts Normal file
View File

@ -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) {
}
}

15
src/types/libp2p.ts Normal file
View File

@ -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,
}

View File

@ -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');
})
});