mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-27 12:02:25 +00:00
Fix eslint
This commit is contained in:
parent
1b89efd288
commit
dd94793e23
@ -3,7 +3,7 @@ import {KeyPair} from "./libp2p";
|
|||||||
|
|
||||||
export type Hkdf = [bytes, bytes, bytes];
|
export type Hkdf = [bytes, bytes, bytes];
|
||||||
|
|
||||||
export interface MessageBuffer {
|
export type MessageBuffer = {
|
||||||
ne: bytes32;
|
ne: bytes32;
|
||||||
ns: bytes;
|
ns: bytes;
|
||||||
ciphertext: bytes;
|
ciphertext: bytes;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { bytes, bytes32 } from "./basic";
|
import { bytes, bytes32 } from "./basic";
|
||||||
import { Duplex } from "it-pair";
|
import { Duplex } from "it-pair";
|
||||||
|
|
||||||
export interface KeyPair {
|
export type KeyPair = {
|
||||||
publicKey: bytes32;
|
publicKey: bytes32;
|
||||||
privateKey: bytes32;
|
privateKey: bytes32;
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ export type PeerId = {
|
|||||||
marshalPrivKey(): bytes;
|
marshalPrivKey(): bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface NoiseConnection {
|
export interface INoiseConnection {
|
||||||
remoteEarlyData?(): bytes;
|
remoteEarlyData?(): bytes;
|
||||||
secureOutbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise<SecureOutbound>;
|
secureOutbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise<SecureOutbound>;
|
||||||
secureInbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise<SecureOutbound>;
|
secureInbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise<SecureOutbound>;
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { Buffer } from "buffer";
|
import { Buffer } from "buffer";
|
||||||
import {IHandshake} from "./@types/handshake-interface";
|
import {IHandshake} from "./@types/handshake-interface";
|
||||||
|
|
||||||
interface ReturnEncryptionWrapper {
|
interface IReturnEncryptionWrapper {
|
||||||
(source: Iterable<Uint8Array>): AsyncIterableIterator<Uint8Array>;
|
(source: Iterable<Uint8Array>): AsyncIterableIterator<Uint8Array>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxPlaintextLength = 65519;
|
const maxPlaintextLength = 65519;
|
||||||
|
|
||||||
// Returns generator that encrypts payload from the user
|
// Returns generator that encrypts payload from the user
|
||||||
export function encryptStream(handshake: IHandshake): ReturnEncryptionWrapper {
|
export function encryptStream(handshake: IHandshake): IReturnEncryptionWrapper {
|
||||||
return async function * (source) {
|
return async function * (source) {
|
||||||
for await (const chunk of source) {
|
for await (const chunk of source) {
|
||||||
const chunkBuffer = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.length);
|
const chunkBuffer = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.length);
|
||||||
@ -28,7 +28,7 @@ export function encryptStream(handshake: IHandshake): ReturnEncryptionWrapper {
|
|||||||
|
|
||||||
|
|
||||||
// Decrypt received payload to the user
|
// Decrypt received payload to the user
|
||||||
export function decryptStream(handshake: IHandshake): ReturnEncryptionWrapper {
|
export function decryptStream(handshake: IHandshake): IReturnEncryptionWrapper {
|
||||||
return async function * (source) {
|
return async function * (source) {
|
||||||
for await (const chunk of source) {
|
for await (const chunk of source) {
|
||||||
const chunkBuffer = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.length);
|
const chunkBuffer = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.length);
|
||||||
|
@ -5,10 +5,6 @@ import { XX } from "./handshakes/xx";
|
|||||||
import { KeyPair, PeerId } from "./@types/libp2p";
|
import { KeyPair, PeerId } from "./@types/libp2p";
|
||||||
import { bytes, bytes32 } from "./@types/basic";
|
import { bytes, bytes32 } from "./@types/basic";
|
||||||
import {
|
import {
|
||||||
createHandshakePayload,
|
|
||||||
getHandshakePayload,
|
|
||||||
signEarlyDataPayload,
|
|
||||||
signPayload,
|
|
||||||
verifySignedPayload,
|
verifySignedPayload,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
import { logger } from "./logger";
|
import { logger } from "./logger";
|
||||||
|
@ -13,7 +13,7 @@ import { generateKeypair, getPayload } from "./utils";
|
|||||||
import { uint16BEDecode, uint16BEEncode } from "./encoder";
|
import { uint16BEDecode, uint16BEEncode } from "./encoder";
|
||||||
import { decryptStream, encryptStream } from "./crypto";
|
import { decryptStream, encryptStream } from "./crypto";
|
||||||
import { bytes } from "./@types/basic";
|
import { bytes } from "./@types/basic";
|
||||||
import { NoiseConnection, PeerId, KeyPair, SecureOutbound } from "./@types/libp2p";
|
import { INoiseConnection, PeerId, KeyPair, SecureOutbound } from "./@types/libp2p";
|
||||||
import { Duplex } from "./@types/it-pair";
|
import { Duplex } from "./@types/it-pair";
|
||||||
import {IHandshake} from "./@types/handshake-interface";
|
import {IHandshake} from "./@types/handshake-interface";
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ type HandshakeParams = {
|
|||||||
remotePeer: PeerId;
|
remotePeer: PeerId;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Noise implements NoiseConnection {
|
export class Noise implements INoiseConnection {
|
||||||
public protocol = "/noise";
|
public protocol = "/noise";
|
||||||
|
|
||||||
private readonly prologue = Buffer.from(this.protocol);
|
private readonly prologue = Buffer.from(this.protocol);
|
||||||
@ -163,7 +163,7 @@ export class Noise implements NoiseConnection {
|
|||||||
params: HandshakeParams,
|
params: HandshakeParams,
|
||||||
payload: bytes,
|
payload: bytes,
|
||||||
): Promise<IKHandshake> {
|
): Promise<IKHandshake> {
|
||||||
const { isInitiator, localPeer, remotePeer, connection } = params;
|
const { isInitiator, remotePeer, connection } = params;
|
||||||
const handshake = new IKHandshake(isInitiator, payload, this.prologue, this.staticKeys, connection, remotePeer);
|
const handshake = new IKHandshake(isInitiator, payload, this.prologue, this.staticKeys, connection, remotePeer);
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
Loading…
x
Reference in New Issue
Block a user