Safe native MoonBit bindings for Discord's official libdave C API
moon add gaato/dave@0.1.0import {
"gaato/dave",
}///|
fn make_key_package() -> Bytes raise @dave.DaveError {
let session = @dave.Session::new(
protocol_version=1,
group_id=42UL,
self_user_id=100UL,
)
session.key_package()
}let fingerprint = session.current_group_pairwise_fingerprint_blocking(
user_id=peer_user_id,
)
let display_code = @dave.pairwise_verification_code(fingerprint)env MBT_DAVE_REQUIRE_NATIVE=1 moon build --target native --release --deny-warn| Host | Architecture | CI coverage |
|---|---|---|
| Linux | x86-64 | native build and tests |
| Linux | ARM64 | native build and tests |
| macOS | ARM64 | native build and tests |
| macOS | x86-64 | asset bootstrap and digest smoke test |
| Windows | x86-64 | native build and tests |
moon fmt --check
node --test test/build.test.js
moon check --target all --deny-warn
env MBT_DAVE_REQUIRE_NATIVE=1 moon build --target native --release --deny-warn
env MBT_DAVE_REQUIRE_NATIVE=1 moon test --target native --release --deny-warn
moon test --target js --release --deny-warn
moon info --target native
moon package --list///|
fn make_key_package_for_docs() -> Bytes raise @dave.DaveError {
let session = @dave.Session::new(
protocol_version=1,
group_id=42UL,
self_user_id=100UL,
)
session.key_package()
}
///|
fn current_group_verification_code_for_docs(
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 "documented native flows typecheck" {
let _ = make_key_package_for_docs
let _ = current_group_verification_code_for_docs
}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