-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn user if imported key has derivation path different from xpub's depth #2454
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for specter-desktop-docs canceled.
|
@stepansnigirev maybe you can have a look whether that PR goes in the right direction. |
for the record: I marked it as draft since I want to ensure users are properly notified - so far it is only printing a line to the logs |
Makes sense. We should notify about these inconsistencies at least in the logs. Warnings in the UI would be even better. |
I did try to have this notification sent top UI but my frontend knowledge is pretty limited. Since I will not have enough time to investigate UI modification, I will leave it as is, with a simple warning in the logs. |
417b178
to
9a0933f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like there is off-by-one error, testing with this:
[8c24a510/84h/1h/0h]vpub5Y24kG7ZrCFRkRnHia2sdnt5N7MmsrNry1jMrP8XptMEcZZqkjQA6bc1f52RGiEoJmdy1Vk9Qck9tAL1ohKvuq3oFXe3ADVse6UiTHzuyKx
I've logged derivation_path
out:
['m', '84h', '1h', '0h']
So this is where the mismatch comes from, it is counting the root whereas the depth of the xpub is counting from the root. @roshii wanna fix it?
Propagating the error to the UI is simple, just raise an Exception instead of the log statement (or in addition):
raise Exception(
f"xpup has a depth of {depth} while derivation path "
f"indicates the key is {len(derivation_path)} levels deep"
)
This code is taking the exceptions and their strings and propagates them to src/cryptoadvance/specter/server_endpoints/devices.py
:
@classmethod
def parse_xpubs(cls, xpubs):
xpubs = xpubs
lines = [l.strip() for l in xpubs.split("\n") if len(l) > 0]
failed = []
keys = []
for line in lines:
try:
keys.append(Key.parse_xpub(line))
except Exception as e:
failed.append(line + "\n" + str(e))
return keys, failed
Fixes #397