File tree 2 files changed +10
-3
lines changed
2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,8 @@ def child(self, index):
158
158
"""Returns the child HDPrivateKey at a particular index.
159
159
Hardened children return for indices >= 0x8000000.
160
160
"""
161
- # if index >= 0x80000000
161
+ if index < 0 :
162
+ raise ValueError ("index should always be positive" )
162
163
if index >= 0x80000000 :
163
164
# the message data is the private key secret in 33 bytes in
164
165
# big-endian and the index in 4 bytes big-endian.
@@ -589,11 +590,13 @@ def fingerprint(self):
589
590
590
591
def child (self , index ):
591
592
"""Returns the child HDPublicKey at a particular index.
592
- Raises ValueError for indices >= 0x8000000.
593
+ Raises ValueError for indices >= 0x8000000 and indices < 0 .
593
594
"""
594
- # if index >= 0x80000000, raise a ValueError
595
595
if index >= 0x80000000 :
596
596
raise ValueError ("child number should always be less than 2^31" )
597
+ if index < 0 :
598
+ raise ValueError ("child number should always be positive" )
599
+
597
600
# data is the SEC compressed and the index in 4 bytes big-endian
598
601
data = self .point .sec () + int_to_big_endian (index , 4 )
599
602
# get hmac_sha512 with chain code, data
Original file line number Diff line number Diff line change @@ -54,8 +54,12 @@ def test_child(self):
54
54
self .assertEqual (addr , want1 )
55
55
addr = priv .child (0x80000002 ).p2wpkh_address ()
56
56
self .assertEqual (addr , want2 )
57
+ with self .assertRaises (ValueError ):
58
+ priv .child (- 1 )
57
59
with self .assertRaises (ValueError ):
58
60
pub .child (0x80000002 )
61
+ with self .assertRaises (ValueError ):
62
+ pub .child (- 1 )
59
63
60
64
def test_traverse (self ):
61
65
seed = b"[email protected] Jimmy Song"
You can’t perform that action at this time.
0 commit comments