-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat!: refactor codebase #407
Conversation
|
||
constructor (crypto: ICrypto, k: Uint8Array | undefined = undefined, n = 0) { | ||
this.crypto = crypto | ||
this.k = k |
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.
Single letter variable names should at least have comments for clarity
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.
If you use an IDE, all protocol-related types have comments.
@@ -181,8 +185,7 @@ export const defaultCrypto: ICryptoInterface = { | |||
publicKey | |||
], X25519_PREFIX.byteLength + publicKey.byteLength) | |||
} else { | |||
publicKey.prepend(X25519_PREFIX) | |||
publicKey = publicKey.subarray() | |||
publicKey = new Uint8ArrayList(X25519_PREFIX, publicKey).subarray() |
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.
you should write a test to ensure that this state is consistent
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.
a regression test?
This fixes a bug where the input Uint8ArrayList was mutated. When that input Uint8ArrayList is part of the noise state, then that mutation breaks things.
argh release-please never picked this up! @mpetrunic do you have any ideas? |
nevermind, it just appeared! |
Souch impatience and doubt in release-please 😋 |
Motivation:
Review notes:
src/protocol.ts
which contains the core noise protocol (agnostic to libp2p's usage)src/performHandshake.ts
which uses the noise protocol according to the libp2p spec. The initiator and responder flows are broken into separate functions.Description
src/handshakes
withsrc/protocol.ts
, this is noise protocol code, following the spec verbatim, agnostic to libp2p usagesrc/xx-handshake.ts with
src/performHandshake.ts` which performs a noise handshake, libp2p-style. This adds logging, reading/writing to a connection, and sending/receiving/verifying a libp2p noise payload.BREAKING CHANGE:
The return type of
ICryptoInterface#chaCha20Poly1305Decrypt
has changed, now no longer returnsnull
but rather throws on invalid decryption.