Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/interface-connection-encrypter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ import type { Duplex } from 'it-stream-types'
* A libp2p connection encrypter module must be compliant to this interface
* to ensure all exchanged data between two peers is encrypted.
*/
export interface ConnectionEncrypter {
export interface ConnectionEncrypter<Extension = unknown> {
protocol: string

/**
* Encrypt outgoing data to the remote party. If the remote PeerId is known,
* pass it for extra verification, otherwise it will be determined during
* the handshake.
*/
secureOutbound: (localPeer: PeerId, connection: Duplex<Uint8Array>, remotePeer?: PeerId) => Promise<SecuredConnection>
secureOutbound: (localPeer: PeerId, connection: Duplex<Uint8Array>, remotePeer?: PeerId) => Promise<SecuredConnection<Extension>>

/**
* Decrypt incoming data. If the remote PeerId is known,
* pass it for extra verification, otherwise it will be determined during
* the handshake
*/
secureInbound: (localPeer: PeerId, connection: Duplex<Uint8Array>, remotePeer?: PeerId) => Promise<SecuredConnection>
secureInbound: (localPeer: PeerId, connection: Duplex<Uint8Array>, remotePeer?: PeerId) => Promise<SecuredConnection<Extension>>
}

export interface SecuredConnection {
export interface SecuredConnection<E> {
conn: Duplex<Uint8Array>
remoteEarlyData: Uint8Array
remoteExtensions?: E
remotePeer: PeerId
}
8 changes: 4 additions & 4 deletions packages/interface-mocks/src/connection-encrypter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function mockConnectionEncrypter () {
return {
conn: {
...wrapper[1],
close: async () => {},
close: async () => { },
localAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4002'),
timeline: {
Expand All @@ -63,7 +63,7 @@ export function mockConnectionEncrypter () {
conn: true
},
remotePeer,
remoteEarlyData: new Uint8Array(0)
remoteExtensions: {}
}
},
secureOutbound: async (localPeer, duplex, remotePeer) => {
Expand Down Expand Up @@ -95,7 +95,7 @@ export function mockConnectionEncrypter () {
return {
conn: {
...wrapper[1],
close: async () => {},
close: async () => { },
localAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4002'),
timeline: {
Expand All @@ -104,7 +104,7 @@ export function mockConnectionEncrypter () {
conn: true
},
remotePeer: peerIdFromBytes(remoteId.slice()),
remoteEarlyData: new Uint8Array(0)
remoteExtensions: {}
}
}
}
Expand Down