Skip to content

Commit

Permalink
Warn user if imported key has derivation path different from xpub's d…
Browse files Browse the repository at this point in the history
…epth
  • Loading branch information
roshii committed Jun 2, 2024
1 parent a42cb46 commit 417b178
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cryptoadvance/specter/key.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import logging
from collections import OrderedDict
from binascii import hexlify
from embit import base58
from .util.xpub import get_xpub_fingerprint

logger = logging.getLogger(__name__)

purposes = OrderedDict(
{
Expand Down Expand Up @@ -135,9 +137,16 @@ def parse_xpub(cls, xpub, purpose=""):
elif derivation_path[4] == "2h":
key_type = "wsh"

# warn user if imported key has derivation path different from xpub's depth
depth = xpub_bytes[4]
if derivation != "" and depth != len(derivation_path):
logger.warning(
f"xpup has a depth of {depth} while derivation path "
f"indicates the key is {len(derivation_path)} levels deep"
)

# infer fingerprint and derivation if depth == 0 or depth == 1
xpub_bytes = base58.decode_check(xpub)
depth = xpub_bytes[4]
if depth == 0:
fingerprint = hexlify(get_xpub_fingerprint(xpub)).decode()
derivation = "m"
Expand Down

0 comments on commit 417b178

Please sign in to comment.