-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: yield uint8arraylists instead of concatenating buffers (#391)
* fix: yield uint8arraylists instead of concatenating buffers In order to avoid unnecessary buffer copies, update to the new libp2p connection encrypter API that lets connection encrypters consume/yield lists of buffers instead of requiring them to be concatenated before/after encryption/decryption. * chore: fix tcp version * feat: use libp2p component logger Refactors code to use the component logger from libp2p to allow more flexible logging patterns. Nb. adds a `NoiseComponents` interface separate from `NoiseInit` that contains the `Metrics` instance - this is consistent with every other libp2p module. Refs: https://github.com/libp2p/js-libp2p/issue/2105 Refs: libp2p/js-libp2p#2198 Refs: https://github.com/libp2p/js-libp2p/issue/378 * chore: fix linter errors --------- Co-authored-by: Cayman <caymannava@gmail.com>
- Loading branch information
1 parent
ea9f556
commit ad25a5e
Showing
25 changed files
with
353 additions
and
217 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
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import type { bytes } from './basic.js' | ||
import type { NoiseSession } from './handshake.js' | ||
import type { NoiseExtensions } from '../proto/payload.js' | ||
import type { PeerId } from '@libp2p/interface/peer-id' | ||
import type { PeerId } from '@libp2p/interface' | ||
import type { Uint8ArrayList } from 'uint8arraylist' | ||
|
||
export interface IHandshake { | ||
session: NoiseSession | ||
remotePeer: PeerId | ||
remoteExtensions: NoiseExtensions | ||
encrypt(plaintext: bytes, session: NoiseSession): bytes | ||
decrypt(ciphertext: bytes, session: NoiseSession, dst?: Uint8Array): { plaintext: bytes, valid: boolean } | ||
encrypt(plaintext: Uint8Array | Uint8ArrayList, session: NoiseSession): Uint8Array | Uint8ArrayList | ||
decrypt(ciphertext: Uint8Array | Uint8ArrayList, session: NoiseSession, dst?: Uint8Array): { plaintext: Uint8Array | Uint8ArrayList, valid: boolean } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import type { bytes32, bytes } from './@types/basic.js' | ||
import { type Uint8ArrayList } from 'uint8arraylist' | ||
import type { bytes32 } from './@types/basic.js' | ||
import type { Hkdf } from './@types/handshake.js' | ||
import type { KeyPair } from './@types/libp2p.js' | ||
|
||
export interface ICryptoInterface { | ||
hashSHA256(data: Uint8Array): Uint8Array | ||
hashSHA256(data: Uint8Array | Uint8ArrayList): Uint8Array | ||
|
||
getHKDF(ck: bytes32, ikm: Uint8Array): Hkdf | ||
|
||
generateX25519KeyPair(): KeyPair | ||
generateX25519KeyPairFromSeed(seed: Uint8Array): KeyPair | ||
generateX25519SharedKey(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array | ||
generateX25519SharedKey(privateKey: Uint8Array | Uint8ArrayList, publicKey: Uint8Array | Uint8ArrayList): Uint8Array | ||
|
||
chaCha20Poly1305Encrypt(plaintext: Uint8Array, nonce: Uint8Array, ad: Uint8Array, k: bytes32): bytes | ||
chaCha20Poly1305Decrypt(ciphertext: Uint8Array, nonce: Uint8Array, ad: Uint8Array, k: bytes32, dst?: Uint8Array): bytes | null | ||
chaCha20Poly1305Encrypt(plaintext: Uint8Array | Uint8ArrayList, nonce: Uint8Array, ad: Uint8Array, k: bytes32): Uint8ArrayList | Uint8Array | ||
chaCha20Poly1305Decrypt(ciphertext: Uint8Array | Uint8ArrayList, nonce: Uint8Array, ad: Uint8Array, k: bytes32, dst?: Uint8Array): Uint8ArrayList | Uint8Array | null | ||
} |
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
Oops, something went wrong.