forked from Snazzah/davey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdavey.pyi
More file actions
347 lines (297 loc) · 10.8 KB
/
davey.pyi
File metadata and controls
347 lines (297 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
"""
Davey
A Discord Audio & Video End-to-End Encryption (DAVE) Protocol implementation in Python.
:copyright: (c) 2025-present Snazzah
:license: MIT
"""
from typing import Final, List, Optional
from enum import Enum
__version__: str = ...
__author__: Final = "Snazzah"
__copyright__: Final = "Copyright 2025-present Snazzah"
__license__: Final = "MIT"
DEBUG_BUILD: bool = ...
""" Whether davey is using a debug build."""
DAVE_PROTOCOL_VERSION: int = ...
"""The maximum supported version of the DAVE protocol."""
class SigningKeyPair:
"""
A signing key pair. This is needed if you want to pass your own key pair or store the key pair for later.
:param private: The private key.
:param public: The public key.
"""
def __init__(self, private: bytes, public: bytes) -> None: ...
private: bytes
"""The private key of this key pair."""
public: bytes
"""The public key of this key pair."""
def __repr__(self) -> str: ...
def generate_p256_keypair() -> SigningKeyPair:
"""Create a P256 signing key pair."""
...
def generate_displayable_code(data: bytes, desired_length: int, group_size: int) -> str:
"""
Generate a displayable code.
See: https://daveprotocol.com/#displayable-codes
:param data: The data to generate a code with.
:param desired_length: The desired length of the code.
:param group_size: The group size of the code.
"""
...
def generate_key_fingerprint(version: int, key: bytes, user_id: int) -> bytes:
"""
Generate a key fingerprint.
See: https://daveprotocol.com/#verification-fingerprint
:param version: The version of the fingerprint.
:param key: The key to fingerprint.
:param user_id: The user ID of this fingerprint.
"""
...
def generate_pairwise_fingerprint(
version: int,
local_key: bytes,
local_user_id: int,
remote_key: bytes,
remote_user_id: int,
) -> bytes:
"""
Generate a pairwise fingerprint.
See: https://daveprotocol.com/#verification-fingerprint
:param version: The version of the fingerprint.
:param local_key: The local user's key.
:param local_user_id: The local user's ID.
:param remote_key: The remote user's key.
:param remote_user_id: The remote user's ID.
"""
...
class Codec(Enum):
"""The type of codec being used."""
unknown = 0
opus = 1
vp8 = 2
vp9 = 3
h264 = 4
h265 = 5
av1 = 6
class MediaType(Enum):
"""The type of media being referenced."""
audio = 0
video = 1
class ProposalsOperationType(Enum):
"""
The operation type of the proposals payload.
See the [DAVE Protocol Whitepaper on opcode 27](https://daveprotocol.com/#dave_mls_proposals-27) for technical details.
"""
append = 0
revoke = 1
class SessionStatus(Enum):
"""The status of the DAVE session."""
inactive = 0
pending = 1
awaiting_response = 2
active = 3
class EncryptionStats:
successes: int
"""Number of encryption successes"""
failures: int
"""Number of encryption failures"""
duration: int
"""Total encryption duration in microseconds"""
attempts: int
"""Total amounts of encryption attempts"""
max_attempts: int
"""Maximum attempts reached at encryption"""
class DecryptionStats:
successes: int
"""Number of decryption successes"""
failures: int
"""Number of decryption failures"""
duration: int
"""Total decryption duration in microseconds"""
attempts: int
"""Total amounts of decryption attempts"""
passthroughs: int
"""Total amounts of packets that passed through"""
class CommitWelcome:
"""
Contains the commit and optional welcome for
[dave_mls_commit_welcome (28)](https://daveprotocol.com/#dave_mls_commit_welcome-28).
"""
commit: bytes
welcome: Optional[bytes]
class DaveSession:
"""
A DAVE session.
:param protocol_version: The protocol version to use.
:param user_id: The user ID of the session.
:param channel_id: The channel ID of the session.
:param key_pair: The key pair to use for this session. Will generate a new one if not specified.
"""
def __init__(
self,
protocol_version: int,
user_id: int,
channel_id: int,
key_pair: Optional[SigningKeyPair] = None,
) -> None: ...
protocol_version: int
"""he DAVE protocol version used for this session."""
user_id: int
"""The user ID for this session."""
channel_id: int
"""The channel ID (group ID in MLS standards) for this session."""
epoch: Optional[int]
"""The epoch for this session, `undefined` if there is no group yet."""
own_leaf_index: Optional[int]
"""Your own leaf index for this session, `undefined` if there is no group yet."""
ciphersuite: int
"""The ciphersuite being used in this session."""
status: SessionStatus
"""The current status of the session."""
ready: bool
"""Whether the session is ready to encrypt/decrypt."""
voice_privacy_code: Optional[str]
"""
Get the voice privacy code of this session's group.
The result of this is created and cached each time a new transition is executed.
See: https://daveprotocol.com/#displayable-codes
"""
def reset(self) -> None:
"""
Resets the session by deleting the group and clearing the storage.
"""
...
def reinit(
self,
protocol_version: int,
user_id: int,
channel_id: int,
key_pair: Optional[SigningKeyPair] = None,
) -> None:
"""
Resets and re-initializes the session.
:param protocol_version: The protocol version to use.
:param user_id: The user ID of the session.
:param channel_id: The channel ID of the session.
:param key_pair: The key pair to use for this session. Will generate a new one if not specified.
"""
...
def get_epoch_authenticator(self) -> Optional[bytes]:
"""Get the epoch authenticator of this session's group."""
...
def set_external_sender(self, external_sender_data: bytes) -> None:
"""
Set the external sender this session will recieve from.
See the [DAVE Protocol Whitepaper on opcode 25](https://daveprotocol.com/#dave_mls_external_sender_package-25) for technical details.
:param external_sender_data: The serialized external sender data.
"""
...
def get_serialized_key_package(self) -> bytes:
"""
Create, store, and return the serialized key package buffer.
Key packages are not meant to be reused, and will be recreated on each call of this function.
"""
...
def process_proposals(
self,
operation_type: ProposalsOperationType,
proposals: bytes,
expected_user_ids: Optional[List[int]] = None,
) -> Optional[CommitWelcome]:
"""
Process proposals from the voice server.
See the [DAVE Protocol Whitepaper on opcode 27](https://daveprotocol.com/#dave_mls_proposals-27) for technical details.
:param operation_type: The operation type of the proposals.
:param proposals: The operation type of the proposals.
:param expected_user_ids: The expected user IDs to come from the proposals.
If provided, this will reject unexpected user IDs.
"""
...
def process_welcome(self, welcome: bytes) -> None:
"""
Process a welcome message.
See the [DAVE Protocol Whitepaper on opcode 30](https://daveprotocol.com/#dave_mls_welcome-30) for technical details.
:param welcome: The welcome message to process.
"""
...
def process_commit(self, commit: bytes) -> None:
"""
Process a commit.
See the [DAVE Protocol Whitepaper on opcode 29](https://daveprotocol.com/#dave_mls_announce_commit_transition-29) for technical details.
:param commit: The commit to process.
"""
...
def get_verification_code(self, user_id: int) -> str:
"""
Get the verification code of another member of the group.
See: https://daveprotocol.com/#displayable-codes
:param user_id: The ID of the user to get the verification code of.
"""
...
def get_pairwise_fingerprint(self, version: int, user_id: int) -> bytes:
"""
Create a pairwise fingerprint of you and another member.
See: https://daveprotocol.com/#verification-fingerprint
:param version: The version of the fingerprint.
:param user_id: The ID of the user to get the pairwise fingerprint of.
"""
...
def encrypt(self, media_type: MediaType, codec: Codec, packet: bytes) -> bytes:
"""
End-to-end encrypt a packet.
:param media_type: The type of media to encrypt.
:param codec: The codec of the packet.
:param packet: The packet to encrypt.
"""
...
def encrypt_opus(self, packet: bytes) -> bytes:
"""
End-to-end encrypt an opus packet.
:param packet: The packet to encrypt.
"""
...
def get_encryption_stats(
self, media_type: Optional[MediaType] = None
) -> EncryptionStats:
"""
Get encryption stats.
:param media_type: The media type to get stats for. Defaults to audio.
"""
...
def decrypt(self, user_id: int, media_type: MediaType, packet: bytes) -> bytes:
"""
Decrypt an end-to-end encrypted packet.
:param user_id: The ID of the user to decrypt the packet for.
:param media_type: The type of media to decrypt.
:param packet: The packet to decrypt.
"""
...
def get_decryption_stats(
self, user_id: int, media_type: Optional[MediaType] = None
) -> Optional[DecryptionStats]:
"""
Get decryption stats.
:param user_id: The ID of the user to get stats for.
:param media_type: The media type to get stats for. Defaults to audio.
"""
...
def get_user_ids(self) -> List[str]:
"""Get the IDs of the users in the current group."""
...
def can_passthrough(self, user_id: int) -> bool:
"""
Check whether this user's decryptor is in passthrough mode.
If passthrough mode is enabled, then unencrypted packets are allowed to be passed through the decryptor.
:param user_id: The ID of the user to check their decryptoe's passthrough mode.
"""
...
def set_passthrough_mode(
self, passthrough_mode: bool, transition_expiry: Optional[int] = None
) -> None:
"""
Set whether passthrough mode is enabled on all decryptors.
:param passthrough_mode: Whether to enable passthrough mode.
:param transition_expiry: The transition expiry (in seconds) to use when disabling passthrough mode, defaults to 10 seconds.
"""
...
def __repr__(self) -> str: ...