fix: cannot import ncryptsec
This commit is contained in:
@@ -80,38 +80,40 @@ pub async fn create_account(
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
pub async fn import_account(
|
pub async fn import_account(key: String, password: String) -> Result<String, String> {
|
||||||
key: String,
|
let (npub, enc_bech32) = match key.starts_with("ncryptsec") {
|
||||||
password: Option<String>,
|
true => {
|
||||||
state: State<'_, Nostr>,
|
let enc = EncryptedSecretKey::from_bech32(key).map_err(|err| err.to_string())?;
|
||||||
) -> Result<String, String> {
|
let enc_bech32 = enc.to_bech32().map_err(|err| err.to_string())?;
|
||||||
let client = &state.client;
|
let secret_key = enc.to_secret_key(password).map_err(|err| err.to_string())?;
|
||||||
let secret_key = SecretKey::from_bech32(key).map_err(|err| err.to_string())?;
|
let keys = Keys::new(secret_key);
|
||||||
let keys = Keys::new(secret_key.clone());
|
let npub = keys.public_key().to_bech32().unwrap();
|
||||||
let npub = keys.public_key().to_bech32().unwrap();
|
|
||||||
|
|
||||||
let enc_bech32 = match password {
|
(npub, enc_bech32)
|
||||||
Some(pw) => {
|
}
|
||||||
let enc = EncryptedSecretKey::new(&secret_key, pw, 16, KeySecurity::Medium)
|
false => {
|
||||||
|
let secret_key = SecretKey::from_bech32(key).map_err(|err| err.to_string())?;
|
||||||
|
let keys = Keys::new(secret_key.clone());
|
||||||
|
let npub = keys.public_key().to_bech32().unwrap();
|
||||||
|
|
||||||
|
let enc = EncryptedSecretKey::new(&secret_key, password, 16, KeySecurity::Medium)
|
||||||
.map_err(|err| err.to_string())?;
|
.map_err(|err| err.to_string())?;
|
||||||
|
|
||||||
enc.to_bech32().map_err(|err| err.to_string())?
|
let enc_bech32 = enc.to_bech32().map_err(|err| err.to_string())?;
|
||||||
|
|
||||||
|
(npub, enc_bech32)
|
||||||
}
|
}
|
||||||
None => secret_key.to_bech32().map_err(|err| err.to_string())?,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let keyring = Entry::new("Lume Secret Storage", &npub).map_err(|e| e.to_string())?;
|
let keyring = Entry::new("Lume Secret Storage", &npub).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
let account = Account {
|
let account = Account {
|
||||||
password: enc_bech32,
|
password: enc_bech32,
|
||||||
nostr_connect: None,
|
nostr_connect: None,
|
||||||
};
|
};
|
||||||
let j = serde_json::to_string(&account).map_err(|e| e.to_string())?;
|
|
||||||
let _ = keyring.set_password(&j);
|
|
||||||
|
|
||||||
let signer = NostrSigner::Keys(keys);
|
let pwd = serde_json::to_string(&account).map_err(|e| e.to_string())?;
|
||||||
|
keyring.set_password(&pwd).map_err(|e| e.to_string())?;
|
||||||
// Update client's signer
|
|
||||||
client.set_signer(Some(signer)).await;
|
|
||||||
|
|
||||||
Ok(npub)
|
Ok(npub)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ async createAccount(name: string, about: string, picture: string, password: stri
|
|||||||
else return { status: "error", error: e as any };
|
else return { status: "error", error: e as any };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async importAccount(key: string, password: string | null) : Promise<Result<string, string>> {
|
async importAccount(key: string, password: string) : Promise<Result<string, string>> {
|
||||||
try {
|
try {
|
||||||
return { status: "ok", data: await TAURI_INVOKE("import_account", { key, password }) };
|
return { status: "ok", data: await TAURI_INVOKE("import_account", { key, password }) };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -95,13 +95,15 @@ function Screen() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{key.length && !key.startsWith("ncryptsec") ? (
|
{key.length ? (
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<label
|
<label
|
||||||
htmlFor="password"
|
htmlFor="password"
|
||||||
className="text-sm font-medium text-neutral-800 dark:text-neutral-200"
|
className="text-sm font-medium text-neutral-800 dark:text-neutral-200"
|
||||||
>
|
>
|
||||||
Set password to secure your key
|
{!key.startsWith("ncryptsec")
|
||||||
|
? "Set password to secure your key"
|
||||||
|
: "Enter password to decrypt your key"}
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
name="password"
|
name="password"
|
||||||
|
|||||||
Reference in New Issue
Block a user