-
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.
- Loading branch information
1 parent
823404c
commit 54f7e32
Showing
20 changed files
with
897 additions
and
1,201 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import { type Uint8ArrayList } from 'uint8arraylist' | ||
import type { bytes32, Hkdf, KeyPair } from './types.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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.