Davey Protocol Implementation
Davey is a Python library that provides an implementation of the Discord Audio & Video End-to-End Encryption (DAVE) Protocol. It acts as a Python binding to a Rust-based implementation that leverages OpenMLS. The library is currently in beta (0.1.5) but actively maintained, with recent updates focusing on security fixes related to its internal OpenMLS dependency.
Common errors
-
ModuleNotFoundError: No module named 'davey'
cause The `davey` package is not installed in the current Python environment or the environment is not activated.fixEnsure the library is installed with `pip install davey` and that your Python interpreter is running in the correct environment. -
AttributeError: 'DaveySession' object has no attribute 'encrypt_audio'
cause Attempting to call a method or access an attribute that does not exist on the object, often due to an outdated understanding of the API or an assumption about its functionality without consulting the typings. The DAVE implementation is low-level and might require specific protocol message handling.fixReview the `davey.pyi` typing file in the installed package for available methods and attributes. The library provides protocol primitives rather than a high-level Discord bot integration layer. -
TypeError: argument 'private_key' must be bytes, not str
cause Passing arguments of incorrect types, such as a string when a bytes-like object is expected, particularly for cryptographic keys or data payloads.fixEnsure all cryptographic material and protocol data (e.g., keys, nonces, payloads) are provided as `bytes` objects. Convert strings using `.encode('utf-8')` if necessary, or use byte literals (e.g., `b'mydata'`).
Warnings
- breaking Version 0.1.4 and later fixed a high-severity vulnerability in the internal OpenMLS dependency. Users on older versions (0.1.3 and below) are strongly advised to update immediately to mitigate potential security risks.
- gotcha The library is in 'Beta' (Development Status 4) as per PyPI. This indicates that the API might still undergo non-backward-compatible changes, and it may not yet be considered stable for production environments without careful testing.
- gotcha Official, comprehensive usage documentation for the Python `davey` library is currently limited. The GitHub README suggests checking the Python typings (`davey.pyi`) for usage examples and available functions. Deeper understanding requires referring to the DAVE Protocol Whitepaper.
Install
-
pip install davey
Imports
- SigningKeyPair
from davey import SigningKeyPair
- generate_p256_keypair
from davey import generate_p256_keypair
- generate_displayable_code
from davey import generate_displayable_code
- SessionStatus
from davey import SessionStatus
Quickstart
from davey import SigningKeyPair, generate_p256_keypair, generate_displayable_code
import os
# Note: In a real application, keys and session data should be securely managed
# and integrated with Discord's voice gateway interactions. This is a minimal example.
# 1. Generate a P256 signing key pair
# This key pair is fundamental for establishing trust in DAVE sessions.
key_pair = generate_p256_keypair()
print(f"Generated Private Key (truncated): {key_pair.private.hex()[:10]}...")
print(f"Generated Public Key (truncated): {key_pair.public.hex()[:10]}...")
# 2. Generate a displayable code for user verification
# The 'data' parameter would typically be a unique session identifier or
# derived from shared secrets in a real DAVE handshake.
example_data_for_code = os.urandom(32) # Using random bytes for demonstration
display_code = generate_displayable_code(
data=example_data_for_code,
desired_length=12, # Total length of the code string
group_size=4 # How many characters per group (e.g., AAAA-BBBB-CCCC)
)
print(f"Generated Displayable Code: {display_code}")
# Further steps would involve Discord API interaction to manage DAVE sessions,
# process proposals, and handle media encryption/decryption, which is highly
# application-specific and not directly covered by simple library calls here.
# Refer to the DAVE Protocol whitepaper and library's typings for advanced usage.