From 71945b105f1c6baa1b2e941c7be160a2b5f91801 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Thu, 8 Dec 2022 23:12:50 +0100 Subject: [PATCH] settings: pasting private key should update pubkey If the user pastes a private-key and the pubkey field is empty, it should be ok to generate and autofill the pubkey without confusing the user. There might be circumstances where it is preferred to see an error if the pubkey does not correspond with the private key. Added an on paste event listener that tries to generate and auto- fill the pubkey (if empty). Also disabled autocomplete on the settings form to indicate to not save the key in password manager. --- src/index.html | 6 +++--- src/main.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/index.html b/src/index.html index 16c8913..1706437 100644 --- a/src/index.html +++ b/src/index.html @@ -59,16 +59,16 @@ --> -
+ - + - +
diff --git a/src/main.js b/src/main.js index 7a98a60..fac23a7 100644 --- a/src/main.js +++ b/src/main.js @@ -604,6 +604,19 @@ importBtn.addEventListener('click', () => { }); settingsForm.addEventListener('input', () => validKeys(privateKeyInput.value, pubKeyInput.value)); +privateKeyInput.addEventListener('paste', (event) => { + if (pubKeyInput.value || !event.clipboardData) { + return; + } + if (privateKeyInput.value === '' || ( + privateKeyInput.selectionStart === 0 + && privateKeyInput.selectionEnd === privateKeyInput.value.length + )) { + try { + pubKeyInput.value = getPublicKey(event.clipboardData.getData('text')); + } catch(err) {} // settings form will call validKeys on input and display the error + } +}); function validKeys(privatekey, pubkey) { try { -- 2.46.2