chore: always call get_public_key on nip46 (#171)
* get public key on login * .
This commit is contained in:
44
Cargo.lock
generated
44
Cargo.lock
generated
@@ -1129,7 +1129,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "collections"
|
name = "collections"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"rustc-hash 2.1.1",
|
"rustc-hash 2.1.1",
|
||||||
@@ -1570,7 +1570,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "derive_refineable"
|
name = "derive_refineable"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -2506,7 +2506,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "gpui"
|
name = "gpui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"as-raw-xcb-connection",
|
"as-raw-xcb-connection",
|
||||||
@@ -2600,7 +2600,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "gpui_macros"
|
name = "gpui_macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.5.0",
|
"heck 0.5.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -2612,7 +2612,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "gpui_tokio"
|
name = "gpui_tokio"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"gpui",
|
"gpui",
|
||||||
@@ -2832,7 +2832,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "http_client"
|
name = "http_client"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -2852,7 +2852,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "http_client_tls"
|
name = "http_client_tls"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rustls",
|
"rustls",
|
||||||
"rustls-platform-verifier",
|
"rustls-platform-verifier",
|
||||||
@@ -3657,7 +3657,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "media"
|
name = "media"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bindgen 0.71.1",
|
"bindgen 0.71.1",
|
||||||
@@ -4500,7 +4500,7 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "perf"
|
name = "perf"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"collections",
|
"collections",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -5108,7 +5108,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "refineable"
|
name = "refineable"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derive_refineable",
|
"derive_refineable",
|
||||||
"workspace-hack",
|
"workspace-hack",
|
||||||
@@ -5262,7 +5262,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest_client"
|
name = "reqwest_client"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -5317,7 +5317,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rope"
|
name = "rope"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"log",
|
"log",
|
||||||
@@ -5812,7 +5812,7 @@ checksum = "0f7d95a54511e0c7be3f51e8867aa8cf35148d7b9445d44de2f943e2b206e749"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "semantic_version"
|
name = "semantic_version"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -5827,9 +5827,9 @@ checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.227"
|
version = "1.0.228"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "80ece43fc6fbed4eb5392ab50c07334d3e577cbf40997ee896fe7af40bba4245"
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_core",
|
"serde_core",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
@@ -5837,18 +5837,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_core"
|
name = "serde_core"
|
||||||
version = "1.0.227"
|
version = "1.0.228"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7a576275b607a2c86ea29e410193df32bc680303c82f31e275bbfcafe8b33be5"
|
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.227"
|
version = "1.0.228"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "51e694923b8824cf0e9b382adf0f60d4e05f348f357b38833a3fa5ed7c2ede04"
|
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -6264,7 +6264,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "sum_tree"
|
name = "sum_tree"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"log",
|
"log",
|
||||||
@@ -7310,7 +7310,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "util"
|
name = "util"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-fs",
|
"async-fs",
|
||||||
@@ -7345,7 +7345,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "util_macros"
|
name = "util_macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed#ead38fd1bec5aa5db2ed8462cb804fe525963bca"
|
source = "git+https://github.com/zed-industries/zed#78098f6809346ba8b45db7ffa768fba75578a263"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"perf",
|
"perf",
|
||||||
"quote",
|
"quote",
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ use global::nostr_client;
|
|||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, relative, AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle,
|
div, relative, AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle,
|
||||||
Focusable, IntoElement, ParentElement, Render, SharedString, Styled, Subscription, Window,
|
Focusable, IntoElement, ParentElement, Render, SharedString, Styled, Subscription, Task,
|
||||||
|
Window,
|
||||||
};
|
};
|
||||||
use i18n::{shared_t, t};
|
use i18n::{shared_t, t};
|
||||||
use nostr_connect::prelude::*;
|
use nostr_connect::prelude::*;
|
||||||
@@ -292,30 +293,22 @@ impl Login {
|
|||||||
|
|
||||||
// Handle connection
|
// Handle connection
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
let client = nostr_client();
|
|
||||||
|
|
||||||
match signer.bunker_uri().await {
|
match signer.bunker_uri().await {
|
||||||
Ok(uri) => {
|
Ok(uri) => {
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.write_uri_to_disk(&uri, cx);
|
this.write_uri_to_disk(signer, uri, cx);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
// Set the client's signer with the current nostr connect instance
|
|
||||||
client.set_signer(signer).await;
|
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
this.update(cx, |this, cx| {
|
this.set_error(error.to_string(), window, cx);
|
||||||
this.set_error(error.to_string(), window, cx);
|
// Force reset the client keys
|
||||||
// Force reset the client keys
|
//
|
||||||
//
|
// This step is necessary to ensure that user can retry the connection
|
||||||
// This step is necessary to ensure that user can retry the connection
|
client_keys.update(cx, |this, cx| {
|
||||||
client_keys.update(cx, |this, cx| {
|
this.force_new_keys(cx);
|
||||||
this.force_new_keys(cx);
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
@@ -324,38 +317,41 @@ impl Login {
|
|||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_uri_to_disk(&mut self, uri: &NostrConnectURI, cx: &mut Context<Self>) {
|
fn write_uri_to_disk(
|
||||||
let Some(public_key) = uri.remote_signer_public_key().cloned() else {
|
&mut self,
|
||||||
log::error!("Remote Signer's public key not found");
|
signer: NostrConnect,
|
||||||
return;
|
uri: NostrConnectURI,
|
||||||
};
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
let mut uri_without_secret = uri.to_string();
|
||||||
|
|
||||||
let mut value = uri.to_string();
|
// Clear the secret parameter in the URI if it exists
|
||||||
|
|
||||||
// Clear the secret param if it exists
|
|
||||||
if let Some(secret) = uri.secret() {
|
if let Some(secret) = uri.secret() {
|
||||||
value = value.replace(secret, "");
|
uri_without_secret = uri_without_secret.replace(secret, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.background_spawn(async move {
|
let task: Task<Result<(), anyhow::Error>> = cx.background_spawn(async move {
|
||||||
let client = nostr_client();
|
let client = nostr_client();
|
||||||
let keys = Keys::generate();
|
|
||||||
let tags = vec![Tag::identifier(ACCOUNT_IDENTIFIER)];
|
|
||||||
let kind = Kind::ApplicationSpecificData;
|
|
||||||
|
|
||||||
let builder = EventBuilder::new(kind, value)
|
// Update the client's signer
|
||||||
.tags(tags)
|
client.set_signer(signer).await;
|
||||||
|
|
||||||
|
let signer = client.signer().await?;
|
||||||
|
let public_key = signer.get_public_key().await?;
|
||||||
|
|
||||||
|
let event = EventBuilder::new(Kind::ApplicationSpecificData, uri_without_secret)
|
||||||
|
.tags(vec![Tag::identifier(ACCOUNT_IDENTIFIER)])
|
||||||
.build(public_key)
|
.build(public_key)
|
||||||
.sign(&keys)
|
.sign(&Keys::generate())
|
||||||
.await;
|
.await?;
|
||||||
|
|
||||||
if let Ok(event) = builder {
|
// Save the event to the database
|
||||||
if let Err(e) = client.database().save_event(&event).await {
|
client.database().save_event(&event).await?;
|
||||||
log::error!("Failed to save event: {e}");
|
|
||||||
};
|
Ok(())
|
||||||
}
|
});
|
||||||
})
|
|
||||||
.detach();
|
task.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_keys_to_disk(&self, keys: &Keys, password: String, cx: &mut Context<Self>) {
|
pub fn write_keys_to_disk(&self, keys: &Keys, password: String, cx: &mut Context<Self>) {
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ impl Onboarding {
|
|||||||
self._tasks.push(
|
self._tasks.push(
|
||||||
// Wait for Nostr Connect approval
|
// Wait for Nostr Connect approval
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
let client = nostr_client();
|
|
||||||
let connect = this.read_with(cx, |this, cx| this.nostr_connect.read(cx).clone());
|
let connect = this.read_with(cx, |this, cx| this.nostr_connect.read(cx).clone());
|
||||||
|
|
||||||
if let Ok(Some(signer)) = connect {
|
if let Ok(Some(signer)) = connect {
|
||||||
@@ -143,12 +142,9 @@ impl Onboarding {
|
|||||||
Ok(uri) => {
|
Ok(uri) => {
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.set_connecting(cx);
|
this.set_connecting(cx);
|
||||||
this.write_uri_to_disk(&uri, cx);
|
this.write_uri_to_disk(signer, uri, cx);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
// Set the client's signer with the current nostr connect instance
|
|
||||||
client.set_signer(signer).await;
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
this.update_in(cx, |_, window, cx| {
|
this.update_in(cx, |_, window, cx| {
|
||||||
@@ -169,38 +165,41 @@ impl Onboarding {
|
|||||||
ChatSpace::proxy_signer(window, cx);
|
ChatSpace::proxy_signer(window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_uri_to_disk(&mut self, uri: &NostrConnectURI, cx: &mut Context<Self>) {
|
fn write_uri_to_disk(
|
||||||
let Some(public_key) = uri.remote_signer_public_key().cloned() else {
|
&mut self,
|
||||||
log::error!("Remote Signer's public key not found");
|
signer: NostrConnect,
|
||||||
return;
|
uri: NostrConnectURI,
|
||||||
};
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
let mut uri_without_secret = uri.to_string();
|
||||||
|
|
||||||
let mut value = uri.to_string();
|
// Clear the secret parameter in the URI if it exists
|
||||||
|
|
||||||
// Clear the secret param if it exists
|
|
||||||
if let Some(secret) = uri.secret() {
|
if let Some(secret) = uri.secret() {
|
||||||
value = value.replace(secret, "");
|
uri_without_secret = uri_without_secret.replace(secret, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.background_spawn(async move {
|
let task: Task<Result<(), anyhow::Error>> = cx.background_spawn(async move {
|
||||||
let client = nostr_client();
|
let client = nostr_client();
|
||||||
let keys = Keys::generate();
|
|
||||||
let tags = vec![Tag::identifier(ACCOUNT_IDENTIFIER)];
|
|
||||||
let kind = Kind::ApplicationSpecificData;
|
|
||||||
|
|
||||||
let builder = EventBuilder::new(kind, value)
|
// Update the client's signer
|
||||||
.tags(tags)
|
client.set_signer(signer).await;
|
||||||
|
|
||||||
|
let signer = client.signer().await?;
|
||||||
|
let public_key = signer.get_public_key().await?;
|
||||||
|
|
||||||
|
let event = EventBuilder::new(Kind::ApplicationSpecificData, uri_without_secret)
|
||||||
|
.tags(vec![Tag::identifier(ACCOUNT_IDENTIFIER)])
|
||||||
.build(public_key)
|
.build(public_key)
|
||||||
.sign(&keys)
|
.sign(&Keys::generate())
|
||||||
.await;
|
.await?;
|
||||||
|
|
||||||
if let Ok(event) = builder {
|
// Save the event to the database
|
||||||
if let Err(e) = client.database().save_event(&event).await {
|
client.database().save_event(&event).await?;
|
||||||
log::error!("Failed to save event: {e}");
|
|
||||||
};
|
Ok(())
|
||||||
}
|
});
|
||||||
})
|
|
||||||
.detach();
|
task.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_uri(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn copy_uri(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user