-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use separate helper file for NoiseSecretStreams
This change should have no impact on functionality. This change creates `src/lib/noise-secret-stream-helpers.js`. It moves `openedNoiseSecretStream()` and two types in there. It also tweaks the types for `OpenedNoiseStream` and `DestroyedNoiseStream`. I think this is a useful change on its own but may also make an upcoming change easier.
- Loading branch information
Showing
8 changed files
with
49 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** @import { Duplex as NodeDuplex } from 'node:stream' */ | ||
/** @import { Duplex as StreamxDuplex } from 'streamx' */ | ||
/** @import NoiseSecretStream from '@hyperswarm/secret-stream' */ | ||
|
||
/** | ||
* @internal | ||
* @typedef {NodeDuplex | StreamxDuplex} RawStream | ||
*/ | ||
|
||
/** | ||
* @template {RawStream} [T=RawStream] | ||
* @typedef {NoiseSecretStream<T> & { destroyed: true }} DestroyedNoiseStream | ||
*/ | ||
|
||
/** | ||
* @template {RawStream} [T=RawStream] | ||
* @typedef {NoiseSecretStream<T> & { | ||
* publicKey: Buffer, | ||
* remotePublicKey: Buffer, | ||
* handshake: Buffer, | ||
* destroyed: false | ||
* }} OpenedNoiseStream | ||
*/ | ||
|
||
/** | ||
* Utility to await a NoiseSecretStream to open, that returns a stream with the | ||
* correct types for publicKey and remotePublicKey (which can be null before | ||
* stream is opened) | ||
* | ||
* @template {RawStream} T | ||
* @param {NoiseSecretStream<T>} stream | ||
* @returns {Promise<OpenedNoiseStream<T> | DestroyedNoiseStream<T>>} | ||
*/ | ||
export async function openedNoiseSecretStream(stream) { | ||
await stream.opened | ||
return /** @type {OpenedNoiseStream<T> | DestroyedNoiseStream<T>} */ (stream) | ||
} |
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
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