-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`[email protected]` will remove the `localPeer` argument from the `secureInbound` and `secureOutbound` methods of the `ConnectionEncrypter` interface. Unfortunately the `js-libp2p` monorepo has a depdendency on this module so the change cannot be released until this module is compatible... with the unreleased change. This PR tests the first argument to `secureInbound` and `secureOutbound` to ensure that it is actually a `PeerId`. If not it shuffles all the arguments along by one place. This PR can be reverted and the first argument removed once `[email protected]` is released.
- Loading branch information
1 parent
0a349b6
commit fed9eec
Showing
5 changed files
with
81 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { unmarshalPrivateKey } from '@libp2p/crypto/keys' | ||
import { type MultiaddrConnection, type SecuredConnection, type PeerId, CodeError, type PrivateKey, serviceCapabilities } from '@libp2p/interface' | ||
import { type MultiaddrConnection, type SecuredConnection, type PeerId, CodeError, type PrivateKey, serviceCapabilities, isPeerId } from '@libp2p/interface' | ||
import { peerIdFromKeys } from '@libp2p/peer-id' | ||
import { decode } from 'it-length-prefixed' | ||
import { lpStream, type LengthPrefixedStream } from 'it-length-prefixed-stream' | ||
|
@@ -73,6 +73,14 @@ export class Noise implements INoiseConnection { | |
* @param remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer. | ||
*/ | ||
public async secureOutbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise<SecuredConnection<Stream, NoiseExtensions>> { | ||
// handle upcoming changes in [email protected] | ||
// @see https://github.com/libp2p/js-libp2p/pull/2304 | ||
if (!isPeerId(localPeer)) { | ||
remotePeer = connection as unknown as PeerId | ||
connection = localPeer | ||
localPeer = this.components.peerId | ||
} | ||
|
||
const wrappedConnection = lpStream( | ||
connection, | ||
{ | ||
|
@@ -114,6 +122,14 @@ export class Noise implements INoiseConnection { | |
* @param remotePeer - optional PeerId of the initiating peer, if known. This may only exist during transport upgrades. | ||
*/ | ||
public async secureInbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise<SecuredConnection<Stream, NoiseExtensions>> { | ||
// handle upcoming changes in [email protected] | ||
// @see https://github.com/libp2p/js-libp2p/pull/2304 | ||
if (!isPeerId(localPeer)) { | ||
remotePeer = connection as unknown as PeerId | ||
connection = localPeer | ||
localPeer = this.components.peerId | ||
} | ||
|
||
const wrappedConnection = lpStream( | ||
connection, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters