Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
feat!: Add remoteExtensions to connection-encrypter (#293)
Browse files Browse the repository at this point in the history
* Add remoteExtensions to connection-encrypter

* Use unknown instead of any

* Remove remoteEarlyData

* Make remoteExtensions optional

* Lint
  • Loading branch information
MarcoPolo committed Oct 4, 2022
1 parent 4f440c6 commit 501c684
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
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

0 comments on commit 501c684

Please sign in to comment.