diff --git a/src/handshake.ts b/src/handshake.ts index 567f734..dc4d3ab 100644 --- a/src/handshake.ts +++ b/src/handshake.ts @@ -1,5 +1,6 @@ -import {bytes, bytes32} from "./types/basic"; -import {KeyPair, NoiseSession, XXHandshake} from "./xx"; +import { bytes, bytes32 } from "./types/basic"; +import { NoiseSession, XXHandshake } from "./xx"; +import { KeyPair } from "./types/libp2p"; export class Handshake { static async runXX( diff --git a/src/noise.ts b/src/noise.ts index 085e5f6..1caf533 100644 --- a/src/noise.ts +++ b/src/noise.ts @@ -6,7 +6,7 @@ import { InsecureConnection, NoiseConnection, PeerId, SecureConnection, KeyPair import { Handshake } from "./handshake"; import { generateKeypair, signPayload } from "./utils"; -import {encryptStream} from "./crypto"; +import { encryptStreams } from "./crypto"; export class Noise implements NoiseConnection { private readonly privateKey: bytes; @@ -64,17 +64,13 @@ export class Noise implements NoiseConnection { const prologue = Buffer.from(this.protocol()); const session = await Handshake.runXX(isInitiator, remotePublicKey, prologue, signedPayload, this.staticKeys); - await encryptStream(connection.streams, session); + await encryptStreams(connection.streams(), session); return { ...connection, initiator: isInitiator, prologue, - // localKey: get public key, - local: { - noiseKey: this.staticKeys.publicKey, - // libp2pKey: - }, + localKey: Buffer.alloc(0), // get libp2p public key, xxNoiseSession: session, xxComplete: true, noiseKeypair: this.staticKeys, diff --git a/src/types/libp2p.ts b/src/types/libp2p.ts index e2a5a8a..3ecb276 100644 --- a/src/types/libp2p.ts +++ b/src/types/libp2p.ts @@ -57,5 +57,4 @@ export interface SecureConnection { xxComplete: boolean, noiseKeypair: KeyPair, - msgBuffer: bytes, } diff --git a/src/utils.ts b/src/utils.ts index 9b3f4e3..c01adb4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import { x25519 } from 'bcrypto'; import * as crypto from 'libp2p-crypto'; -import { KeyPair } from "./xx"; +import { KeyPair } from "./types/libp2p"; import { bytes } from "./types/basic"; export async function generateKeypair() : Promise { diff --git a/test/noise.test.ts b/test/noise.test.ts index 516298e..08cd2c3 100644 --- a/test/noise.test.ts +++ b/test/noise.test.ts @@ -1,4 +1,6 @@ import { expect } from "chai"; +import DuplexPair from 'it-pair/duplex'; + import { Noise } from "../src"; import {generateEd25519Keys} from "./utils";