Remove unused

This commit is contained in:
morrigan 2019-11-29 16:23:24 +01:00
parent 6dc8e8288d
commit 6ee527e621
3 changed files with 7 additions and 9 deletions

View File

@ -1,5 +1,4 @@
import { Duplex } from "it-pair"; import { Duplex } from "it-pair";
import { NoiseSession } from "./xx";
import { Handshake } from "./handshake"; import { Handshake } from "./handshake";
interface ReturnEncryptionWrapper { interface ReturnEncryptionWrapper {
@ -7,10 +6,10 @@ interface ReturnEncryptionWrapper {
} }
// Returns generator that encrypts payload from the user // Returns generator that encrypts payload from the user
export function encryptStream(handshake: Handshake, session: NoiseSession): ReturnEncryptionWrapper { export function encryptStream(handshake: Handshake): ReturnEncryptionWrapper {
return async function * (source) { return async function * (source) {
for await (const chunk of source) { for await (const chunk of source) {
const data = await handshake.encrypt(chunk, session); const data = await handshake.encrypt(chunk, handshake.session);
yield data; yield data;
} }
} }
@ -18,10 +17,10 @@ export function encryptStream(handshake: Handshake, session: NoiseSession): Retu
// Decrypt received payload to the user // Decrypt received payload to the user
export function decryptStream(handshake: Handshake, session: NoiseSession): ReturnEncryptionWrapper { export function decryptStream(handshake: Handshake): ReturnEncryptionWrapper {
return async function * (source) { return async function * (source) {
for await (const chunk of source) { for await (const chunk of source) {
const decrypted = await handshake.decrypt(chunk, session); const decrypted = await handshake.decrypt(chunk, handshake.session);
yield decrypted yield decrypted
} }
} }

View File

@ -12,7 +12,6 @@ import { decryptStream, encryptStream } from "./crypto";
import { bytes } from "./@types/basic"; import { bytes } from "./@types/basic";
import { NoiseConnection, PeerId, KeyPair, SecureOutbound } from "./@types/libp2p"; import { NoiseConnection, PeerId, KeyPair, SecureOutbound } from "./@types/libp2p";
import { Duplex } from "./@types/it-pair"; import { Duplex } from "./@types/it-pair";
import {NoiseSession} from "./xx";
export type WrappedConnection = ReturnType<typeof Wrap>; export type WrappedConnection = ReturnType<typeof Wrap>;
@ -102,12 +101,12 @@ export class Noise implements NoiseConnection {
pipe( pipe(
secure, // write to wrapper secure, // write to wrapper
ensureBuffer, // ensure any type of data is converted to buffer ensureBuffer, // ensure any type of data is converted to buffer
encryptStream(handshake, handshake.session), // data is encrypted encryptStream(handshake), // data is encrypted
lp.encode({ lengthEncoder: int16BEEncode }), // prefix with message length lp.encode({ lengthEncoder: int16BEEncode }), // prefix with message length
network, // send to the remote peer network, // send to the remote peer
lp.decode({ lengthDecoder: int16BEDecode }), // read message length prefix lp.decode({ lengthDecoder: int16BEDecode }), // read message length prefix
ensureBuffer, // ensure any type of data is converted to buffer ensureBuffer, // ensure any type of data is converted to buffer
decryptStream(handshake, handshake.session), // decrypt the incoming data decryptStream(handshake), // decrypt the incoming data
secure // pipe to the wrapper secure // pipe to the wrapper
); );

View File

@ -5,7 +5,7 @@ import Wrap from "it-pb-rpc";
import {Handshake} from "../src/handshake"; import {Handshake} from "../src/handshake";
import {generateKeypair} from "../src/utils"; import {generateKeypair} from "../src/utils";
import {createPeerIds, createPeerIdsFromFixtures} from "./fixtures/peer"; import {createPeerIds} from "./fixtures/peer";
describe("Handshake", () => { describe("Handshake", () => {