-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
// 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
// TODO: Use https://github.com/chm-diederichs/noise-handshake/blob/main/noise.js for specific patterns | ||
pattern?: string |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
> extends Duplex< | ||
any, | ||
any, | ||
any, | ||
any, | ||
true, | ||
true, | ||
DuplexEvents<any, any> & NoiseStreamEvents | ||
> { |
There was a problem hiding this comment.
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??
33caf88
to
37b4c9d
Compare
lib/discovery/index.js
Outdated
@@ -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] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
lib/discovery/index.js
Outdated
@@ -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 |
There was a problem hiding this comment.
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
68d56e8
to
37b4c9d
Compare
37b4c9d
to
f70d211
Compare
There was a problem hiding this 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
Towards #14
wow i thought this would be easier...
Notes: