-
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.
* chore: cleanup comments * fix: simplify uint16 encode/decode * fix: fix node crypto * chore: consolidate types * fix: avoid reallocations of empty key * fix: simplify XX initialization * chore: add more comments to types * fix: remove unused psk state variable * feat: refactor the codebase
- Loading branch information
1 parent
0ffa85f
commit 9ebbfc5
Showing
25 changed files
with
959 additions
and
1,279 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,17 +1,27 @@ | ||
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' | ||
import type { ICrypto, KeyPair } from './types.js' | ||
import type { Uint8ArrayList } from 'uint8arraylist' | ||
|
||
/** Underlying crypto implementation, meant to be overridable */ | ||
export interface ICryptoInterface { | ||
hashSHA256(data: Uint8Array | Uint8ArrayList): Uint8Array | ||
|
||
getHKDF(ck: bytes32, ikm: Uint8Array): Hkdf | ||
getHKDF(ck: Uint8Array, ikm: Uint8Array): [Uint8Array, Uint8Array, Uint8Array] | ||
|
||
generateX25519KeyPair(): KeyPair | ||
generateX25519KeyPairFromSeed(seed: Uint8Array): KeyPair | ||
generateX25519SharedKey(privateKey: Uint8Array | Uint8ArrayList, publicKey: Uint8Array | Uint8ArrayList): Uint8Array | ||
|
||
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 | ||
chaCha20Poly1305Encrypt(plaintext: Uint8Array | Uint8ArrayList, nonce: Uint8Array, ad: Uint8Array, k: Uint8Array): Uint8ArrayList | Uint8Array | ||
chaCha20Poly1305Decrypt(ciphertext: Uint8Array | Uint8ArrayList, nonce: Uint8Array, ad: Uint8Array, k: Uint8Array, dst?: Uint8Array): Uint8ArrayList | Uint8Array | ||
} | ||
|
||
export function wrapCrypto (crypto: ICryptoInterface): ICrypto { | ||
return { | ||
generateKeypair: crypto.generateX25519KeyPair, | ||
dh: (keypair, publicKey) => crypto.generateX25519SharedKey(keypair.privateKey, publicKey).subarray(0, 32), | ||
encrypt: crypto.chaCha20Poly1305Encrypt, | ||
decrypt: crypto.chaCha20Poly1305Decrypt, | ||
hash: crypto.hashSHA256, | ||
hkdf: crypto.getHKDF | ||
} | ||
} |
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
Oops, something went wrong.