Skip to content

Commit 417b178

Browse files
committed
Warn user if imported key has derivation path different from xpub's depth
1 parent a42cb46 commit 417b178

File tree

1 file changed

+10
-1
lines changed
  • src/cryptoadvance/specter

1 file changed

+10
-1
lines changed

src/cryptoadvance/specter/key.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import logging
12
from collections import OrderedDict
23
from binascii import hexlify
34
from embit import base58
45
from .util.xpub import get_xpub_fingerprint
56

7+
logger = logging.getLogger(__name__)
68

79
purposes = OrderedDict(
810
{
@@ -135,9 +137,16 @@ def parse_xpub(cls, xpub, purpose=""):
135137
elif derivation_path[4] == "2h":
136138
key_type = "wsh"
137139

140+
# warn user if imported key has derivation path different from xpub's depth
141+
depth = xpub_bytes[4]
142+
if derivation != "" and depth != len(derivation_path):
143+
logger.warning(
144+
f"xpup has a depth of {depth} while derivation path "
145+
f"indicates the key is {len(derivation_path)} levels deep"
146+
)
147+
138148
# infer fingerprint and derivation if depth == 0 or depth == 1
139149
xpub_bytes = base58.decode_check(xpub)
140-
depth = xpub_bytes[4]
141150
if depth == 0:
142151
fingerprint = hexlify(get_xpub_fingerprint(xpub)).decode()
143152
derivation = "m"

0 commit comments

Comments
 (0)