settings: pasting private key should update pubkey #24

Merged
offbyn merged 1 commits from settings-calc-pubkey into master 2 years ago

@ -59,16 +59,16 @@
<input type="text" name="username" id="username" placeholder="username"> <input type="text" name="username" id="username" placeholder="username">
<button type="button" name="publish-username" tabindex="0">publish</button> <button type="button" name="publish-username" tabindex="0">publish</button>
</div> --> </div> -->
<form action="#" name="settings"> <form action="#" name="settings" autocomplete="new-password">
<label for="pubkey">public-key</label> <label for="pubkey">public-key</label>
<input type="text" id="pubkey"> <input type="text" id="pubkey" autocomplete="off">
<label for="privatekey"> <label for="privatekey">
private-key private-key
<button type="button" name="privatekey-toggle" class="btn-inline" > <button type="button" name="privatekey-toggle" class="btn-inline" >
<small>show</small> <small>show</small>
</button> </button>
</label> </label>
<input type="password" id="privatekey"> <input type="password" id="privatekey" autocomplete="off">
<div class="buttons"> <div class="buttons">
<small id="keystatus" class="form-status" hidden></small> <small id="keystatus" class="form-status" hidden></small>
<button type="button" name="generate" tabindex="0">new</button> <button type="button" name="generate" tabindex="0">new</button>

@ -604,6 +604,19 @@ importBtn.addEventListener('click', () => {
}); });
settingsForm.addEventListener('input', () => validKeys(privateKeyInput.value, pubKeyInput.value)); settingsForm.addEventListener('input', () => validKeys(privateKeyInput.value, pubKeyInput.value));
privateKeyInput.addEventListener('paste', (event) => {
if (pubKeyInput.value || !event.clipboardData) {
return;
}
if (privateKeyInput.value === '' || (
x1ddos commented 2 years ago
Review

maybe add a comment here, to clarify? something like:

make sure paste event overwrites the whole privateKeyInput.value.
otherwise, the computed pubkey may be computed from only a partial
privateKeyInput.value.

i was staring at this again for a minute, trying to remember why this is needed.

maybe add a comment here, to clarify? something like: > make sure paste event overwrites the whole privateKeyInput.value. > otherwise, the computed pubkey may be computed from only a partial > privateKeyInput.value. i was staring at this again for a minute, trying to remember why this is needed.
offbyn commented 2 years ago
Review

done 0047c0bdc0

done https://git.qcode.ch/nostr/nostrweb/commit/0047c0bdc0d33f8101aaf2138c7b41d655bb8343
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) { function validKeys(privatekey, pubkey) {
try { try {

Loading…
Cancel
Save