forked from nostr/nostrweb
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.
parent
8ec9420be8
commit
71945b105f
|
@ -59,16 +59,16 @@
|
|||
<input type="text" name="username" id="username" placeholder="username">
|
||||
<button type="button" name="publish-username" tabindex="0">publish</button>
|
||||
</div> -->
|
||||
<form action="#" name="settings">
|
||||
<form action="#" name="settings" autocomplete="new-password">
|
||||
<label for="pubkey">public-key</label>
|
||||
<input type="text" id="pubkey">
|
||||
<input type="text" id="pubkey" autocomplete="off">
|
||||
<label for="privatekey">
|
||||
private-key
|
||||
<button type="button" name="privatekey-toggle" class="btn-inline" >
|
||||
<small>show</small>
|
||||
</button>
|
||||
</label>
|
||||
<input type="password" id="privatekey">
|
||||
<input type="password" id="privatekey" autocomplete="off">
|
||||
<div class="buttons">
|
||||
<small id="keystatus" class="form-status" hidden></small>
|
||||
<button type="button" name="generate" tabindex="0">new</button>
|
||||
|
|
13
src/main.js
13
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 {
|
||||
|
|
Loading…
Reference in New Issue