Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add types for @hyperswarm/secret-stream #34

Merged
merged 2 commits into from
Oct 6, 2022

Conversation

achou11
Copy link
Member

@achou11 achou11 commented Oct 4, 2022

Towards #14

wow i thought this would be easier...

Notes:

  • A few todo comments but will point them out and see if they're blocking (most aren't)

@achou11 achou11 requested a review from sethvincent October 4, 2022 21:16
Comment on lines +55 to +57
// TODO: Figure out where those extra fields come from and find more elegant way to represent this
/**
* @typedef {Object} NoiseSecretStream
* @property {Buffer} remotePublicKey
* @property {number} remotePort
* @property {string} remoteHost
* @property {import('net').Socket} rawStream
* @property {function} end
* @typedef {import('streamx').Duplex & {remoteAddress: string, remotePort:number}} RawDHTConnectionStream
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seth may have an idea of where these come from, but my guess is that it would require even more work to get the proper typings for that to update this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the approach used here makes sense.

Comment on lines +9 to +10
// TODO: Use https://github.com/chm-diederichs/noise-handshake/blob/main/noise.js for specific patterns
pattern?: string
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh i had no idea how to read those pattern variables in the link provided, so went with string for now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i think we're unlikely to set the pattern option too, so seems lower priority.

Comment on lines +28 to +36
> extends Duplex<
any,
any,
any,
any,
true,
true,
DuplexEvents<any, any> & NoiseStreamEvents
> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a more concise way to write this??

@achou11 achou11 force-pushed the ac/secret-stream-types branch 2 times, most recently from 33caf88 to 37b4c9d Compare October 4, 2022 21:21
@@ -889,7 +888,7 @@ export class PeerInfo extends TypedEmitter {
* @param {Object} options
* @param {IdentityPublicKeyString} [options.identityPublicKey]
* @param {('dht'|'mdns')} [options.discoveryType]
* @param {ConnectionStream} [options.connection]
* @param {SecretStream<RawConnectionStream>} [options.connection]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally would do some conditional typing to narrow down the RawConnectionStream type based on the discoveryType. not sure how to go about that in TS + JSDoc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yeah that would be nice. i think we're good for now with SecretStream<RawConnectionStream> in part because ideally at this stage the streams from the two discovery types should be pretty much equivalent.

@@ -832,7 +831,7 @@ export class PeerInfo extends TypedEmitter {
* @typedef {Object} PeerInfoOptions
* @property {IdentityPublicKeyString} identityPublicKey
* @property {('dht'|'mdns')} discoveryType
* @property {ConnectionStream} connection
* @property {SecretStream<RawConnectionStream>} connection
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally would do some conditional typing to narrow down the RawConnectionStream type based on the discoveryType. not sure how to go about that in TS + JSDoc

@achou11 achou11 force-pushed the ac/secret-stream-types branch from 68d56e8 to 37b4c9d Compare October 5, 2022 18:59
@achou11 achou11 force-pushed the ac/secret-stream-types branch from 37b4c9d to f70d211 Compare October 5, 2022 19:09
Copy link
Contributor

@sethvincent sethvincent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me! i think for any remaining todos here we could make some low-priority issues for improvements

@achou11 achou11 merged commit 95e6718 into main Oct 6, 2022
@achou11 achou11 deleted the ac/secret-stream-types branch October 6, 2022 15:23
@achou11 achou11 mentioned this pull request Oct 17, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants