From 6b251c9d127a2f26ab5cc31e5422840c2ae464e7 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 6084296..2fc2159 100644 --- a/src/index.html +++ b/src/index.html @@ -59,16 +59,16 @@ --> -
+ - + - +
diff --git a/src/main.js b/src/main.js index 273f3e4..5c001da 100644 --- a/src/main.js +++ b/src/main.js @@ -579,6 +579,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 {