Overview of @discordapp/libdave
mainThe @discordapp/libdave package is a JavaScript implementation of the DAVE protocol. It is used by Discord clients to perform out-of-band verifications of:
- DAVE protocol call members
- MLS epoch authenticators
repository·main·Indexed 43 days ago
https://github.com/discord/libdaveJS and C++ implementations of Discord's DAVE protocol used to secure media streams in native clients. Includes the @discordapp/libdave package for out-of-band verification of call members and MLS epoch authenticators, as well as C++ libraries for encrypting and decrypting audio and video frames using key ratcheting and MLS (Messaging Layer Security) sessions.
The @discordapp/libdave package is a JavaScript implementation of the DAVE protocol. It is used by Discord clients to perform out-of-band verifications of:
The libdave repository provides the JS and C++ implementations of Discord's Audio & Video End-to-End Encryption (DAVE) protocol. These libraries are used by Discord's native clients to enable secure audio and video communication.
For a detailed technical specification of the protocol itself, refer to the DAVE protocol whitepaper.
Before building, ensure the vcpkg submodule is up to date and initialized by running the submodule update and the bootstrap script.
git submodule update --recursive
./vcpkg/bootstrap-vcpkg.shThe DaveSessionManager class is designed to handle Voice Gateway events related to DAVE (Discord Audio Video Encryption). It manages the lifecycle of DAVE sessions, including event handling and the generation of key ratchets.
To use it, follow these steps:
DaveSessionManager object for every unique combination of selfUserId and groupId.DaveSessionManager instance to process the event.Note: This sample is an implementation guide. You will need to provide the actual networking and media processing logic where indicated by TODO comments in the source code.
Use make to compile the library. It is recommended to run make cclean before starting a new build to ensure a clean state.
# For a static library
make cclean
make
# For a shared library
make cclean
make sharedpnpm jest.pnpm jestVCPKG_MANIFEST_DIR variable within the Makefile.The @discordapp/libdave package relies on the following dependencies:
@noble/hashesbase64-jsThe following dependencies and tools are used by libdave:
Core Dependencies
mlspp: Must be configured with -DMLS_CXX_NAMESPACE="mlspp" and -DDISABLE_GREASE=ON.Testing Frameworks
googletestAFLplusplusThe Encryptor allows controlling the security state and encryption bypass:
SetKeyRatchet(std::unique_ptr<IKeyRatchet> keyRatchet) to provide a mechanism for rotating encryption keys. Use HasKeyRatchet() to check if a ratchet is currently active.SetPassthroughMode(bool passthroughMode) to enable or disable encryption entirely. When enabled, data is passed through without encryption. Use IsPassthroughMode() to check the current state.// Enable key ratcheting
encryptor.SetKeyRatchet(std::move(my_ratchet_ptr));
// Enable passthrough (no encryption)
encryptor.SetPassthroughMode(true);The Encryptor can notify you when the underlying protocol version changes. Use SetProtocolVersionChangedCallback to register a std::function<void()> that will be triggered upon a version change. You can query the current version at any time using GetProtocolVersion().
encryptor.SetProtocolVersionChangedCallback([]() {
// Handle protocol version change
});
ProtocolVersion current = encryptor.GetProtocolVersion();To perform pairwise operations or manage keys for a specific member of the group, use GetKeyRatchet(userId). This returns a std::unique_ptr<IKeyRatchet> which manages the key evolution for that specific user identity.
std::unique_ptr<IKeyRatchet> ratchet = session->GetKeyRatchet("target_user_id");
if (ratchet) {
// Use the ratchet for pairwise encryption/decryption
}