settings: pasting private key should update pubkey
#24
Merged
offbyn
merged 1 commits from settings-calc-pubkey
into master
2 years ago
Loading…
Reference in New Issue
There is no content yet.
Delete Branch 'settings-calc-pubkey'
Deleting a branch is permanent. It CANNOT be undone. Continue?
If the user pastes a private-key and the pubkey input is empty,
it should be ok to generate and autofill the pubkey field 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.
part of #14
lgtm
@ -607,1 +607,4 @@
privateKeyInput.addEventListener('paste', (event) => {
if (!pubKeyInput.value && event.clipboardData) {
pubKeyInput.value = getPublicKey(event.clipboardData.getData('text'));
this throws an error "Expected 32 bytes of private key" in js console if i paste something other than 32 hex-encoded string. maybe wrap it in try/catch?
Good catch, wrapped into
try {} catch(err) {}
and ignore the error, as on input it triggers a validation and shows a proper error already.Also moved the function next to the on input event listener.
There was another issue when pasting a private key.
Added another check that the clipboard data should only be taken if the private key field is either empty or the whole field is selected and overwritten by the pasted data.
123b3655e2
to8ab09fda40
2 years ago8ab09fda40
to6b251c9d12
2 years ago@ -582,0 +585,4 @@
}
if (privateKeyInput.value === '' || (
privateKeyInput.selectionStart === 0
&& privateKeyInput.selectionEnd === privateKeyInput.value.length
but does it really matter here? if there's a paste event and it's somewhere in the middle, so the resulting input.value is invalid, more than 32 hex, you'll catch it in try/catch anyway.
what i mean is:
will not assign to
pubKeyInput.value
anyway - it'll go into thecatch
branch due togetPublicKey
throwing an error.so, the complicated
if
with selection start/end seems superfluous.the issue is on paste event fires before the privateKeyInput field is updated.
if it checks that either privateKeyInput.value is empty or the whole private key is selected then we can assume that only the clipboard content is relevant and set the pubkey.
6b251c9d12
to71945b105f
2 years agorebased
71945b105f
into master 2 years ago@ -607,0 +608,4 @@
if (pubKeyInput.value || !event.clipboardData) {
return;
}
if (privateKeyInput.value === '' || (
maybe add a comment here, to clarify? something like:
i was staring at this again for a minute, trying to remember why this is needed.
done
0047c0bdc0
Reviewers
71945b105f
.Step 1:
From your project repository, check out a new branch and test the changes.Step 2:
Merge the changes and update on Gitea.