feat: disable login with nostr-connect
This commit is contained in:
@@ -212,45 +212,24 @@ pub async fn set_inbox(relays: Vec<String>, state: State<'_, Nostr>) -> Result<(
|
|||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
pub async fn login(
|
pub async fn login(
|
||||||
id: String,
|
id: String,
|
||||||
bunker: Option<String>,
|
|
||||||
state: State<'_, Nostr>,
|
state: State<'_, Nostr>,
|
||||||
handle: tauri::AppHandle,
|
handle: tauri::AppHandle,
|
||||||
) -> Result<String, String> {
|
) -> Result<String, String> {
|
||||||
let client = &state.client;
|
let client = &state.client;
|
||||||
let public_key = PublicKey::parse(&id).map_err(|e| e.to_string())?;
|
let public_key = PublicKey::parse(&id).map_err(|e| e.to_string())?;
|
||||||
let hex = public_key.to_hex();
|
let hex = public_key.to_hex();
|
||||||
let keyring = Entry::new("coop", &id).expect("Unexpected.");
|
let keyring = Entry::new("coop", &id).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
let password = match keyring.get_password() {
|
let password = match keyring.get_password() {
|
||||||
Ok(pw) => pw,
|
Ok(pw) => pw,
|
||||||
Err(_) => return Err("Cancelled".into()),
|
Err(_) => return Err("Cancelled".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
match bunker {
|
let keys = Keys::parse(password).map_err(|e| e.to_string())?;
|
||||||
Some(uri) => {
|
let signer = NostrSigner::Keys(keys);
|
||||||
let app_keys =
|
|
||||||
Keys::parse(password).expect("Secret Key is modified, please check again.");
|
|
||||||
|
|
||||||
match NostrConnectURI::parse(uri) {
|
// Update signer
|
||||||
Ok(bunker_uri) => {
|
client.set_signer(Some(signer)).await;
|
||||||
match Nip46Signer::new(bunker_uri, app_keys, Duration::from_secs(30), None)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(signer) => client.set_signer(Some(signer.into())).await,
|
|
||||||
Err(err) => return Err(err.to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => return Err(err.to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
let keys = Keys::parse(password).expect("Secret Key is modified, please check again.");
|
|
||||||
let signer = NostrSigner::Keys(keys);
|
|
||||||
|
|
||||||
// Update signer
|
|
||||||
client.set_signer(Some(signer)).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let inbox = Filter::new().kind(Kind::Custom(10050)).author(public_key).limit(1);
|
let inbox = Filter::new().kind(Kind::Custom(10050)).author(public_key).limit(1);
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ function Screen() {
|
|||||||
{isPending ? <Spinner /> : "Continue"}
|
{isPending ? <Spinner /> : "Continue"}
|
||||||
</button>
|
</button>
|
||||||
<GoBack className="mt-2 w-full text-sm text-neutral-600 dark:text-neutral-400 inline-flex items-center justify-center">
|
<GoBack className="mt-2 w-full text-sm text-neutral-600 dark:text-neutral-400 inline-flex items-center justify-center">
|
||||||
Back
|
Go back to previous screen
|
||||||
</GoBack>
|
</GoBack>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ function Screen() {
|
|||||||
{isPending ? <Spinner /> : "Continue"}
|
{isPending ? <Spinner /> : "Continue"}
|
||||||
</button>
|
</button>
|
||||||
<GoBack className="mt-2 w-full text-sm text-neutral-600 dark:text-neutral-400 inline-flex items-center justify-center">
|
<GoBack className="mt-2 w-full text-sm text-neutral-600 dark:text-neutral-400 inline-flex items-center justify-center">
|
||||||
Back
|
Go back to previous screen
|
||||||
</GoBack>
|
</GoBack>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ function Screen() {
|
|||||||
const loginWith = async (npub: string) => {
|
const loginWith = async (npub: string) => {
|
||||||
setValue(npub);
|
setValue(npub);
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
const bunker: string = localStorage.getItem(`${npub}_bunker`);
|
const res = await commands.login(npub);
|
||||||
const verifyBunker = bunker?.length && bunker?.startsWith("bunker://");
|
|
||||||
const res = await commands.login(npub, verifyBunker ? bunker : null);
|
|
||||||
|
|
||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
navigate({
|
navigate({
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ function Screen() {
|
|||||||
<div className="w-[320px] flex flex-col gap-8">
|
<div className="w-[320px] flex flex-col gap-8">
|
||||||
<div className="flex flex-col gap-1 text-center">
|
<div className="flex flex-col gap-1 text-center">
|
||||||
<h1 className="leading-tight text-xl font-semibold">
|
<h1 className="leading-tight text-xl font-semibold">
|
||||||
Direct Message client for Nostr.
|
Direct Message on Nostr.
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
@@ -24,17 +24,19 @@ function Screen() {
|
|||||||
Create a new identity
|
Create a new identity
|
||||||
</Link>
|
</Link>
|
||||||
<Link
|
<Link
|
||||||
to="/nostr-connect"
|
to="/import-key"
|
||||||
className="w-full h-10 bg-white hover:bg-neutral-100 dark:hover:bg-neutral-100 dark:bg-white dark:text-black rounded-lg inline-flex items-center justify-center"
|
className="w-full h-10 bg-white hover:bg-neutral-100 dark:hover:bg-neutral-100 dark:bg-white dark:text-black rounded-lg inline-flex items-center justify-center"
|
||||||
>
|
>
|
||||||
Login with Nostr Connect
|
Login with Private Key
|
||||||
</Link>
|
</Link>
|
||||||
|
{/*
|
||||||
<Link
|
<Link
|
||||||
to="/import-key"
|
to="/import-key"
|
||||||
className="w-full text-sm text-neutral-600 dark:text-neutral-400 inline-flex items-center justify-center"
|
className="w-full text-sm text-neutral-600 dark:text-neutral-400 inline-flex items-center justify-center"
|
||||||
>
|
>
|
||||||
Login with Private Key (not recommended)
|
Login with Private Key (not recommended)
|
||||||
</Link>
|
</Link>
|
||||||
|
*/}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -35,13 +35,6 @@ function Screen() {
|
|||||||
const res = await commands.connectAccount(uri);
|
const res = await commands.connectAccount(uri);
|
||||||
|
|
||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
const npub = res.data;
|
|
||||||
const parsed = new URL(uri);
|
|
||||||
parsed.searchParams.delete("secret");
|
|
||||||
|
|
||||||
// save connection string
|
|
||||||
localStorage.setItem(`${npub}_bunker`, parsed.toString());
|
|
||||||
|
|
||||||
navigate({ to: "/", replace: true });
|
navigate({ to: "/", replace: true });
|
||||||
} else {
|
} else {
|
||||||
await message(res.error, { title: "Nostr Connect", kind: "error" });
|
await message(res.error, { title: "Nostr Connect", kind: "error" });
|
||||||
@@ -103,7 +96,7 @@ function Screen() {
|
|||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<GoBack className="mt-2 w-full text-sm text-neutral-600 dark:text-neutral-400 inline-flex items-center justify-center">
|
<GoBack className="mt-2 w-full text-sm text-neutral-600 dark:text-neutral-400 inline-flex items-center justify-center">
|
||||||
Back
|
Go back to previous screen
|
||||||
</GoBack>
|
</GoBack>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user