Skip to content

Commit f6c1108

Browse files
Migrate to MDK (#372)
* Update dependencies * Migrate whitenoise from nostr_mls to mdk * Fix dependency and update name of doc file * Removing nostr_mls from comments, scripts
1 parent dfce7c6 commit f6c1108

File tree

30 files changed

+338
-327
lines changed

30 files changed

+338
-327
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
if: matrix.target == 'native' && matrix.os == 'ubuntu-latest'
9090
run: |
9191
mkdir -p ./dev/data/integration_test/
92-
RUST_LOG=warn,sqlx=info,refinery_core=error,keyring=info,nostr_relay_pool=error,nostr_mls_sqlite_storage=error,tungstenite=error,integration_test=debug cargo run --bin integration_test --features integration-tests -- --data-dir ./dev/data/integration_test/ --logs-dir ./dev/data/integration_test/
92+
RUST_LOG=warn,sqlx=info,refinery_core=error,keyring=info,nostr_relay_pool=error,mdk_sqlite_storage=error,tungstenite=error,integration_test=debug cargo run --bin integration_test --features integration-tests -- --data-dir ./dev/data/integration_test/ --logs-dir ./dev/data/integration_test/
9393
rm -rf ./dev/data/integration_test/
9494
9595
- name: Stop Docker Compose services

Cargo.lock

Lines changed: 62 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,24 @@ keyring = { version = "3.6", features = [
2929
] }
3030
lightning-invoice = "0.33.1"
3131

32-
nostr-mls = { version = "0.43.0", git="https://github.com/rust-nostr/nostr", rev = "fadf1a6b3d8c5457e5a66d95d6c1677b4353e653" }
33-
nostr-mls-sqlite-storage = { version = "0.43.0", git="https://github.com/rust-nostr/nostr", rev = "fadf1a6b3d8c5457e5a66d95d6c1677b4353e653" }
34-
nwc = { version = "0.43.0", git="https://github.com/rust-nostr/nostr", rev = "fadf1a6b3d8c5457e5a66d95d6c1677b4353e653" }
35-
nostr-blossom = { version = "0.43.0", git="https://github.com/rust-nostr/nostr", rev = "fadf1a6b3d8c5457e5a66d95d6c1677b4353e653" }
36-
nostr-sdk = { version = "0.43.0", git="https://github.com/rust-nostr/nostr", rev = "fadf1a6b3d8c5457e5a66d95d6c1677b4353e653", features = [
32+
mdk-core = { version = "0.5.0", git="https://github.com/parres-hq/mdk", rev = "e20d4cf34edcd8592b6218ec20086e453860bf1d" }
33+
mdk-sqlite-storage = { version = "0.5.0", git="https://github.com/parres-hq/mdk", rev = "e20d4cf34edcd8592b6218ec20086e453860bf1d" }
34+
35+
nwc = "0.43"
36+
nostr-blossom = "0.43"
37+
nostr-sdk = { version = "0.43", features = [
3738
"lmdb",
3839
"nip04",
3940
"nip44",
4041
"nip47",
4142
"nip59",
4243
] }
4344

45+
# LOCAL MDK FOR DEVELOPMENT
46+
# mdk-core = { version = "0.5.0", path="../mdk/crates/mdk-core" }
47+
# mdk-sqlite-storage = { version = "0.5.0", path="../mdk/crates/mdk-sqlite-storage" }
48+
4449
# LOCAL RUST_NOSTR FOR DEVELOPMENT
45-
# nostr-mls = { version = "0.43", path="../rust-nostr/mls/nostr-mls" }
46-
# nostr-mls-sqlite-storage = { version = "0.43", path="../rust-nostr/mls/nostr-mls-sqlite-storage" }
4750
# nwc = { version = "0.43", path="../rust-nostr/crates/nwc" }
4851
# nostr-blossom = { version = "0.43", path="../rust-nostr/rfs/nostr-blossom" }
4952
# nostr-sdk = { version = "0.43", path="../rust-nostr/crates/nostr-sdk", features = [

docs/mls/mdk-integration.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# MDK Crate Integration
2+
3+
## Overview
4+
5+
Whitenoise uses the `mdk-core` crate for MLS protocol implementation. This document details the integration patterns and usage within our project.
6+
7+
## Dependencies
8+
9+
From `Cargo.toml`:
10+
```toml
11+
mdk-core = { version = "0.5.0", git="https://github.com/parres-hq/mdk" }
12+
mdk-sqlite-storage = { version = "0.5.0", git="https://github.com/parres-hq/mdk" }
13+
```
14+
15+
## Core Integration Points
16+
17+
### MDK Initialization
18+
19+
The `mdk` instance is created per account:
20+
21+
```rust
22+
// From src/whitenoise/accounts.rs
23+
let mdk = Account::create_mdk(account.pubkey, &self.config.data_dir)?;
24+
```
25+
26+
### Message Processing
27+
28+
MLS messages are processed through the nostr-mls interface:
29+
30+
```rust
31+
// From src/whitenoise/event_processor/event_handlers/handle_mls_message.rs
32+
match mdk.process_message(&event) {
33+
Ok(result) => {
34+
// Handle successful processing
35+
}
36+
Err(e) => {
37+
// Handle MLS errors
38+
Err(WhitenoiseError::MdkCoreError(e))
39+
}
40+
}
41+
```
42+
43+
### Storage Backend
44+
45+
We use SQLite storage for MLS state persistence:
46+
- Database location: `{data_dir}/mls/`
47+
- Per-account storage isolation
48+
- Integrated with main application database
49+
50+
### Key Package Management
51+
52+
Key packages are generated and managed through the mdk interface:
53+
54+
```rust
55+
// Key package generation for group joining
56+
let key_package = mdk.generate_key_package()?;
57+
```
58+
59+
### Group Operations
60+
61+
Core group operations available:
62+
63+
1. **Create Group**: `mdk.create_group()`
64+
2. **Join Group**: `mdk.join_group(welcome_message)`
65+
3. **Add Member**: `mdk.add_member(key_package)`
66+
4. **Remove Member**: `mdk.remove_member(member_id)`
67+
5. **Send Message**: `mdk.send_message(content)`
68+
69+
### Error Handling
70+
71+
MLS errors are wrapped in our custom error type:
72+
73+
```rust
74+
#[derive(Debug, thiserror::Error)]
75+
pub enum WhitenoiseError {
76+
#[error("MDK error: {0}")]
77+
MdkCoreError(#[from] mdk_core::Error),
78+
// ... other error types
79+
}
80+
```
81+
82+
## Configuration
83+
84+
### MLS Provider Configuration
85+
86+
The mdk crate is configured with:
87+
- Crypto provider: Default MLS crypto implementation
88+
- Storage provider: SQLite backend
89+
- Transport: Nostr event system

0 commit comments

Comments
 (0)