chore: address review

This commit is contained in:
Vasco Santos
2020-12-02 16:04:16 +01:00
parent 67a5f51805
commit 6f090617aa
9 changed files with 53 additions and 150 deletions

View File

@ -1,40 +1,24 @@
import PeerId from 'peer-id'
import { MultiaddrConnection } from '../transport/types'
/**
* A libp2p crypto module must be compliant to this interface
* to ensure all exchanged data between two peers is encrypted.
*/
export interface CryptoInterface {
export interface Crypto {
protocol: string;
/**
* Encrypt outgoing data to the remote party.
*
* @param {PeerId} localPeer - PeerId of the receiving peer
* @param {MultiaddrConnection} connection - streaming iterable duplex that will be encrypted
* @param {PeerId} remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer.
* @returns {Promise<SecureOutbound>}
*/
secureOutbound(localPeer: PeerId, connection: MultiaddrConnection, remotePeer: PeerId): Promise<SecureOutbound>;
/**
* Decrypt incoming data.
*
* @param {PeerId} localPeer - PeerId of the receiving peer.
* @param {MultiaddrConnection} connection - streaming iterable duplex that will be encryption.
* @param {PeerId} remotePeer - optional PeerId of the initiating peer, if known. This may only exist during transport upgrades.
* @returns {Promise<SecureOutbound>}
*/
secureInbound(localPeer: PeerId, connection: MultiaddrConnection, remotePeer?: PeerId): Promise<SecureOutbound>;
}
export declare class Crypto implements CryptoInterface {
protocol: string;
secureOutbound(localPeer: PeerId, connection: MultiaddrConnection, remotePeer: PeerId): Promise<SecureOutbound>;
secureInbound(localPeer: PeerId, connection: MultiaddrConnection, remotePeer?: PeerId): Promise<SecureOutbound>;
}
export type SecureOutbound = {
conn: MultiaddrConnection;
remoteEarlyData: Buffer;
remotePeer: PeerId;
}
type PeerId = import('peer-id');
type MultiaddrConnection = import('../transport/types').MultiaddrConnection