mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-06-25 06:41:44 +00:00
feat: add types (#74)
This commit is contained in:
15
src/crypto/errors.d.ts
vendored
15
src/crypto/errors.d.ts
vendored
@ -1,15 +0,0 @@
|
||||
export class UnexpectedPeerError extends Error {
|
||||
static get code(): string;
|
||||
constructor(message?: string);
|
||||
code: string;
|
||||
}
|
||||
export class InvalidCryptoExchangeError extends Error {
|
||||
static get code(): string;
|
||||
constructor(message?: string);
|
||||
code: string;
|
||||
}
|
||||
export class InvalidCryptoTransmissionError extends Error {
|
||||
static get code(): string;
|
||||
constructor(message?: string);
|
||||
code: string;
|
||||
}
|
@ -6,7 +6,7 @@ const expect = chai.expect
|
||||
chai.use(require('dirty-chai'))
|
||||
|
||||
const duplexPair = require('it-pair/duplex')
|
||||
const pipe = require('it-pipe')
|
||||
const { pipe } = require('it-pipe')
|
||||
const PeerId = require('peer-id')
|
||||
const { collect } = require('streaming-iterables')
|
||||
const uint8arrayFromString = require('uint8arrays/from-string')
|
||||
|
24
src/crypto/types.ts
Normal file
24
src/crypto/types.ts
Normal file
@ -0,0 +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 Crypto {
|
||||
protocol: string;
|
||||
/**
|
||||
* Encrypt outgoing data to the remote party.
|
||||
*/
|
||||
secureOutbound(localPeer: PeerId, connection: MultiaddrConnection, remotePeer: PeerId): Promise<SecureOutbound>;
|
||||
/**
|
||||
* Decrypt incoming data.
|
||||
*/
|
||||
secureInbound(localPeer: PeerId, connection: MultiaddrConnection, remotePeer?: PeerId): Promise<SecureOutbound>;
|
||||
}
|
||||
|
||||
export type SecureOutbound = {
|
||||
conn: MultiaddrConnection;
|
||||
remoteEarlyData: Buffer;
|
||||
remotePeer: PeerId;
|
||||
}
|
Reference in New Issue
Block a user