wip
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m20s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m39s
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m20s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m39s
This commit is contained in:
@@ -9,11 +9,13 @@ common = { path = "../common" }
|
||||
|
||||
nostr-sdk.workspace = true
|
||||
nostr-lmdb.workspace = true
|
||||
nostr-connect.workspace = true
|
||||
|
||||
gpui.workspace = true
|
||||
smol.workspace = true
|
||||
flume.workspace = true
|
||||
log.workspace = true
|
||||
anyhow.workspace = true
|
||||
webbrowser.workspace = true
|
||||
|
||||
rustls = "0.23"
|
||||
|
||||
@@ -2,8 +2,9 @@ use std::collections::HashSet;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Error;
|
||||
use common::{config_dir, BOOTSTRAP_RELAYS, SEARCH_RELAYS};
|
||||
use common::{config_dir, BOOTSTRAP_RELAYS, CLIENT_NAME, SEARCH_RELAYS};
|
||||
use gpui::{App, AppContext, Context, Entity, Global, Subscription, Task};
|
||||
use nostr_connect::prelude::*;
|
||||
use nostr_lmdb::NostrLmdb;
|
||||
use nostr_sdk::prelude::*;
|
||||
|
||||
@@ -25,6 +26,10 @@ pub fn init(cx: &mut App) {
|
||||
|
||||
/// Default timeout for subscription
|
||||
pub const TIMEOUT: u64 = 3;
|
||||
/// Default timeout for Nostr Connect
|
||||
pub const NOSTR_CONNECT_TIMEOUT: u64 = 200;
|
||||
/// Default Nostr Connect relay
|
||||
pub const NOSTR_CONNECT_RELAY: &str = "wss://relay.nsec.app";
|
||||
|
||||
/// Default subscription id for gift wrap events
|
||||
pub const GIFTWRAP_SUBSCRIPTION: &str = "giftwrap-events";
|
||||
@@ -592,4 +597,56 @@ impl NostrRegistry {
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
|
||||
/// Store a connection for future uses
|
||||
pub fn persit_connection(&mut self, uri: NostrConnectUri, cx: &mut App) {
|
||||
let client = self.client();
|
||||
let rng_keys = Keys::generate();
|
||||
|
||||
self.tasks.push(cx.background_spawn(async move {
|
||||
// Construct the event for application-specific data
|
||||
let event = EventBuilder::new(Kind::ApplicationSpecificData, uri.to_string())
|
||||
.tag(Tag::identifier("coop:account"))
|
||||
.sign(&rng_keys)
|
||||
.await?;
|
||||
|
||||
// Store the event in the database
|
||||
client.database().save_event(&event).await?;
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
|
||||
/// Generate a direct nostr connection initiated by the client
|
||||
pub fn client_connect(&self, relay: Option<RelayUrl>) -> (NostrConnect, NostrConnectUri) {
|
||||
let app_keys = self.app_keys();
|
||||
let timeout = Duration::from_secs(NOSTR_CONNECT_TIMEOUT);
|
||||
|
||||
// Determine the relay will be used for Nostr Connect
|
||||
let relay = match relay {
|
||||
Some(relay) => relay,
|
||||
None => RelayUrl::parse(NOSTR_CONNECT_RELAY).unwrap(),
|
||||
};
|
||||
|
||||
// Generate the nostr connect uri
|
||||
let uri = NostrConnectUri::client(app_keys.public_key(), vec![relay], CLIENT_NAME);
|
||||
|
||||
// Generate the nostr connect
|
||||
let signer = NostrConnect::new(uri.clone(), app_keys.clone(), timeout, None).unwrap();
|
||||
|
||||
(signer, uri)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CoopAuthUrlHandler;
|
||||
|
||||
impl AuthUrlHandler for CoopAuthUrlHandler {
|
||||
#[allow(mismatched_lifetime_syntaxes)]
|
||||
fn on_auth_url(&self, auth_url: Url) -> BoxedFuture<Result<()>> {
|
||||
Box::pin(async move {
|
||||
webbrowser::open(auth_url.as_str())?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user