Safe native MoonBit bindings for Discord's official libdave C API
moon add gaato/dave///|
import {
"gaato/dave",
}///|
test "create a session and its key package" {
guard @dave.available() else { return }
let session = @dave.Session::new(
protocol_version=1,
group_id=42UL,
self_user_id=100UL,
)
let key_package = session.key_package()
assert_true(key_package.length() > 0)
}///|
fn current_group_verification_code(
session : @dave.Session,
peer_user_id : UInt64,
) -> String raise @dave.DaveError {
let fingerprint = session.current_group_pairwise_fingerprint_blocking(
user_id=peer_user_id,
)
@dave.pairwise_verification_code(fingerprint)
}
///|
test "the verification example compiles" {
ignore(current_group_verification_code)
}env MBT_DAVE_REQUIRE_NATIVE=1 moon build --target native --release| Host | Architecture | Support |
|---|---|---|
| Linux | x86-64, ARM64 | Supported |
| macOS | ARM64 | Supported |
| Windows | x86-64 | Supported |
| macOS | x86-64 | Upstream asset only; MoonBit has no Darwin x86-64 toolchain |
pub(all) suberror DaveError {
LibraryUnavailable(reason~ : String)
InvalidArgument(operation~ : String, reason~ : String)
InvalidState(operation~ : String, reason~ : String)
MlsOperationFailed(operation~ : String, failure~ : MlsFailure)
FingerprintFailed(user_id~ : UInt64, reason~ : String)
EncryptFailed(reason~ : EncryptFailure)
DecryptFailed(reason~ : DecryptFailure)
NativeFailure(operation~ : String, reason~ : String)
} derive(Eq, Debug)pub(all) enum CommitResult {
Applied(changes~ : Array[RosterChange])
Ignored
Failed(failure~ : MlsFailure)
} derive(Eq, Debug)pub struct Decryptor {
// private fields
}fn Decryptor::transition_to_key_ratchet(self : Decryptor, key_ratchet : KeyRatchet) -> Unit raise DaveErrorpub struct Encryptor {
// private fields
}pub struct KeyRatchet {
// private fields
}pub struct Session {
// private fields
}fn Session::process_welcome(self : Session, welcome : Bytes, recognized_user_ids~ : ArrayView[UInt64]) -> WelcomeResult raise DaveErrorpub(all) enum WelcomeResult {
Applied(changes~ : Array[RosterChange])
Failed(failure~ : MlsFailure)
} derive(Eq, Debug)fn available() -> Boolfn max_supported_protocol_version() -> UInt16fn unavailable_reason() -> String?Install
Download zipSafe native MoonBit bindings for Discord's official libdave C API