From f93d9de3f1ec0094a230a184735c3e4c4ac5230a Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 17 May 2023 03:53:55 +0800 Subject: [PATCH] add BIP-39 entry for passwords in vault If the "notes" field starts with the characters "bip39" (case insensitive), then, the password field is interpreted as a hexadecimal encoding of BIP39 entropy. To create a BIP-39 entry, leave the password field blank, and then start the Notes field with the characters 'bip39', and this will trigger a dialog box that will only allow valid bip39 entry and check the checksum etc. To view the BIP-39, after opening up the entry for "edit", close it, and it will pop up a second dialog box that interprets the hex data as BIP-39 words. You could also in theory enter the hex digits yourself into the password field, if you're masochist. --- apps/vault/locales/i18n.json | 21 +++++++++++++++++++++ apps/vault/src/actions.rs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) 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,