Skip to content

Commit 6c1851a

Browse files
authored
Nostr contact resolver (#509)
* Nostr contact helper functions * Revert default config * Nostr contact store * Use Nostr contacts, fix all tests * Use Nostr contacts * Resolve contacts on bill event * Global trusted contact config flag * Review fixes * Review fixes
1 parent 699bac2 commit 6c1851a

File tree

29 files changed

+1427
-202
lines changed

29 files changed

+1427
-202
lines changed

.cargo/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[env]
2+
# our dev nostr relay
3+
NOSTR_RELAY = "ws://bitcr-cloud-run-05-550030097098.europe-west1.run.app"
4+
5+
# more detailed logs
6+
RUST_LOG = "info"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/target
22
/contacts/*
33
/esplora/.docker_data/
4-
./data/
4+
/data
55
/frontend_build/*
66
/identity/*
77
/bills/*

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ members = [
99
]
1010

1111
[profile.release]
12-
opt-level = "s" # Optimize for size ("z" can be used for even more aggressive size reduction)
13-
lto = true # Enable Link-Time Optimization
14-
codegen-units = 1 # Reduces binary size at the cost of compile time
12+
opt-level = "s" # Optimize for size ("z" can be used for even more aggressive size reduction)
13+
lto = true # Enable Link-Time Optimization
14+
codegen-units = 1 # Reduces binary size at the cost of compile time
1515

1616
[workspace.dependencies]
1717
sha2 = { version = "0.10", default-features = false }
@@ -36,8 +36,8 @@ uuid = { version = "1", default-features = false, features = ["v4", "js"] }
3636
bitcoin = { version = "0.32", default-features = false }
3737
bip39 = { version = "2.1", features = ["rand"] }
3838
ecies = { version = "0.2", default-features = false, features = ["pure"] }
39-
nostr = { version = "0.40"}
40-
nostr-sdk = { version = "0.40", features = ["nip04", "nip59"] }
39+
nostr = { version = "0.41" }
40+
nostr-sdk = { version = "0.41", features = ["nip04", "nip59"] }
4141
getrandom = { version = "0.3.1", features = ["wasm_js"] }
4242
async-broadcast = "0.7.2"
4343
rstest = "0.25.0"

crates/bcr-ebill-api/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ thiserror.workspace = true
2121
uuid.workspace = true
2222
bitcoin.workspace = true
2323
nostr-sdk.workspace = true
24+
nostr.workspace = true
2425
futures.workspace = true
2526
infer = { version = "0.19.0", default-features = false }
2627
bcr-ebill-core = { path = "../bcr-ebill-core" }
@@ -37,7 +38,7 @@ reqwest = { workspace = true, features = ["default", "json"] }
3738

3839
[dev-dependencies]
3940
mockall = "0.13.1"
40-
nostr-relay-builder = "0.40"
41+
nostr-relay-builder = "0.41"
4142
tokio.workspace = true
4243
async-broadcast.workspace = true
4344

crates/bcr-ebill-api/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ pub use persistence::notification::NotificationFilter;
2424
pub struct Config {
2525
pub bitcoin_network: String,
2626
pub esplora_base_url: String,
27-
pub nostr_relays: Vec<String>,
2827
pub db_config: SurrealDbConfig,
2928
pub data_dir: String,
29+
pub nostr_config: NostrConfig,
3030
}
3131

3232
static CONFIG: OnceLock<Config> = OnceLock::new();
@@ -43,6 +43,15 @@ impl Config {
4343
}
4444
}
4545

46+
/// Nostr specific configuration
47+
#[derive(Debug, Clone, Default)]
48+
pub struct NostrConfig {
49+
/// Only known contacts can message us via DM.
50+
pub only_known_contacts: bool,
51+
/// All relays we want to publish our messages to and receive messages from.
52+
pub relays: Vec<String>,
53+
}
54+
4655
pub fn init(conf: Config) -> Result<()> {
4756
CONFIG
4857
.set(conf)

crates/bcr-ebill-api/src/persistence/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ use bcr_ebill_persistence::{
66
SurrealNostrEventOffsetStore, SurrealNotificationStore,
77
bill::{BillChainStoreApi, BillStoreApi},
88
company::{CompanyChainStoreApi, CompanyStoreApi},
9-
db::nostr_send_queue::SurrealNostrEventQueueStore,
9+
db::{
10+
nostr_contact_store::SurrealNostrContactStore,
11+
nostr_send_queue::SurrealNostrEventQueueStore,
12+
},
1013
file_upload::FileUploadStoreApi,
1114
get_surreal_db,
1215
identity::{IdentityChainStoreApi, IdentityStoreApi},
13-
nostr::NostrQueuedMessageStoreApi,
16+
nostr::{NostrContactStoreApi, NostrQueuedMessageStoreApi},
1417
};
1518
use log::error;
1619
use std::sync::Arc;
@@ -42,6 +45,7 @@ pub struct DbContext {
4245
pub notification_store: Arc<dyn NotificationStoreApi>,
4346
pub backup_store: Arc<dyn BackupStoreApi>,
4447
pub queued_message_store: Arc<dyn NostrQueuedMessageStoreApi>,
48+
pub nostr_contact_store: Arc<dyn NostrContactStoreApi>,
4549
}
4650

4751
/// Creates a new instance of the DbContext with the given SurrealDB configuration.
@@ -80,6 +84,7 @@ pub async fn get_db_context(conf: &Config) -> bcr_ebill_persistence::Result<DbCo
8084
let notification_store = Arc::new(SurrealNotificationStore::new(db.clone()));
8185
let backup_store = Arc::new(SurrealBackupStore::new(db.clone()));
8286
let queued_message_store = Arc::new(SurrealNostrEventQueueStore::new(db.clone()));
87+
let nostr_contact_store = Arc::new(SurrealNostrContactStore::new(db.clone()));
8388

8489
Ok(DbContext {
8590
contact_store,
@@ -94,5 +99,6 @@ pub async fn get_db_context(conf: &Config) -> bcr_ebill_persistence::Result<DbCo
9499
notification_store,
95100
backup_store,
96101
queued_message_store,
102+
nostr_contact_store,
97103
})
98104
}

0 commit comments

Comments
 (0)