-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,62 @@ | ||
// TODO: create types for these modules | ||
declare module 'hyperswarm' | ||
declare module '@hyperswarm/secret-stream' | ||
declare module '@hyperswarm/secret-stream' { | ||
import { Duplex as NodeDuplex } from 'stream' | ||
import { Duplex, DuplexEvents } from 'streamx' | ||
|
||
interface Opts { | ||
autostart?: boolean | ||
// TODO: Use https://github.com/chm-diederichs/noise-handshake/blob/main/noise.js for specific patterns | ||
pattern?: string | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
remotePublicKey?: Buffer | ||
keyPair?: { publicKey: Buffer; secretKey: Buffer } | ||
handshake?: { | ||
tx: Buffer | ||
rx: Buffer | ||
hash: Buffer | ||
publicKey: Buffer | ||
remotePublicKey: Buffer | ||
} | ||
} | ||
|
||
type NoiseStreamEvents = { | ||
connect: () => void | ||
} | ||
|
||
class NoiseSecretStream< | ||
RawStream extends NodeDuplex | Duplex = Duplex | ||
> extends Duplex< | ||
any, | ||
any, | ||
any, | ||
any, | ||
true, | ||
true, | ||
DuplexEvents<any, any> & NoiseStreamEvents | ||
> { | ||
Comment on lines
+28
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a more concise way to write this?? |
||
readonly publicKey: Buffer | ||
readonly remotePublicKey: Buffer | ||
readonly handshakeHash: Buffer | ||
readonly rawStream: RawStream | ||
readonly isInitiator: boolean | ||
readonly noiseStream: this | ||
readonly opened: Promise<boolean> | ||
readonly userData: any | ||
|
||
constructor(isInitiator: boolean, rawStream?: RawStream, opts?: Opts) | ||
|
||
static keyPair(seed?: Buffer): { | ||
publicKey: Buffer | ||
secretKey: Buffer | ||
} | ||
|
||
start(rawStream?: NodeDuplex, opts?: Opts): void | ||
setTimeout(ms?: number): void | ||
setKeepAlive(ms?: number): void | ||
} | ||
|
||
export = NoiseSecretStream | ||
} | ||
declare module '@hyperswarm/testnet' | ||
declare module 'base32.js' | ||
declare module '@mapeo/crypto' | ||
|
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.