diff --git a/apps/vault/locales/i18n.json b/apps/vault/locales/i18n.json index 6f09c41cf..1f8023eef 100644 --- a/apps/vault/locales/i18n.json +++ b/apps/vault/locales/i18n.json @@ -48,6 +48,27 @@ "ja": "アンマウントするベースを選択します:", "zh": "选择要卸载的基础:" }, + "vault.bip39.input": { + "en": "Enter your BIP39 password:", + "en-tts": "Enter your BIP39 password:", + "fr": "Saisissez votre mot de passe BIP39: *MT*", + "ja": "BIP39 パスワードを入力してください:", + "zh": "输入您的 BIP39 密码:" + }, + "vault.bip39.output": { + "en": "Password as BIP39:", + "en-tts": "Password as BIP39:", + "fr": "Mot de passe en tant que BIP39: *MT*", + "ja": "BIP39としてのパスワード:", + "zh": "密码为 BIP39:" + }, + "vault.bip39.output_error": { + "en": "Password field is not encodable as BIP39.", + "en-tts": "Password field is not encodable as BIP39.", + "fr": "Le champ Mot de passe n'est pas encodable en tant que BIP39. *MT*", + "ja": "パスワードフィールドはBIP39としてエンコードできません。", + "zh": "密码字段不可编码为 BIP39。" + }, "vault.completed": { "en": "Operation completed.", "en-tts": "Operation completed.", diff --git a/apps/vault/src/actions.rs b/apps/vault/src/actions.rs index 2e20c06d5..24e8d3e39 100644 --- a/apps/vault/src/actions.rs +++ b/apps/vault/src/actions.rs @@ -774,8 +774,35 @@ impl<'a> ActionManager<'a> { pw.password = edit_data.content()[2].content.as_str().unwrap().to_string(); pw.notes = edit_data.content()[3].content.as_str().unwrap().to_string(); - // if the password is empty, prompt to generate a new password - if pw.password.len() == 0 { + // if the notes field starts with the word "bip39" (case insensitive), use BIP39 to display/edit the password field + if pw.notes.to_ascii_lowercase().starts_with("bip39") { + if pw.password.len() == 0 { + match self.modals.input_bip39(Some(t!("vault.bip39.input", xous::LANG))) { + Ok(data) => { + pw.password = hex::encode(data); + } + _ => pw.password = "".to_string(), // leave it blank if invalid or aborted + } + } else { + match hex::decode(&pw.password) { + Ok(data) => { + match self.modals.show_bip39( + Some(t!("vault.bip39.output", xous::LANG)), + &data + ) { + Ok(_) => {}, + Err(_) => { + self.modals.show_notification(t!("vault.bip39.output_error", xous::LANG), None).unwrap(); + } + } + } + Err(_) => { + self.modals.show_notification(t!("vault.bip39.output_error", xous::LANG), None).unwrap(); + } + } + } + } else if pw.password.len() == 0 && !pw.notes.to_ascii_lowercase().starts_with("bip39") { + // if the password is empty, prompt to generate a new password let pg = PasswordGenerator { length: 20, numbers: true,