44from data .bip93_vectors import VECTOR_1 , VECTOR_2 , VECTOR_3 , VECTOR_4 , VECTOR_5
55from data .sharing_vectors import SHARING_VECTORS
66
7- from codex32 import (
8- MasterSeed ,
9- core_descriptors ,
10- master_xprv ,
11- parse_codex32 ,
12- )
13- from codex32 .wallet import _with_checksum
14-
15- _MAIN_DESCRIPTORS = (
16- (
17- "pkh([3f3521a6/44h/0h/0h]"
18- "xpub6CeZ5XxHp6rXSwi2GCi7UT25rswWQtoPvj36MbzRBr3QEoEmBFNGgnMy329ZMk"
19- "fjRKBZHtKKpYfpkrPWohTjHZZn7y1NR9EHnojaGLKdMAR/<0;1>/*)#smv8ra2a"
20- ),
21- (
22- "sh(wpkh([3f3521a6/49h/0h/0h]"
23- "xpub6D9YUddFXuNKQvNrT9RQh8ueiTvHwF3RzdgU6uTEri73WTnBpKaDCGhTUiPBTy"
24- "VJxtR5u2atDmCHE7tw369ahXddCNqJBxFpseud3j7pjX8/<0;1>/*))#gylcnnd3"
25- ),
26- (
27- "wpkh([3f3521a6/84h/0h/0h]"
28- "xpub6CNhWVRpA49Bz3LSaBibGqfBV4qa5NH1CStbQfsxWKScwrws5jioMunWKj2uM2"
29- "rrfdJSroNuJBNDUmmdYXQw5LwVro39pH5nqEgAqrzTPyc/<0;1>/*)#zy06y40v"
30- ),
31- (
32- "tr([3f3521a6/86h/0h/0h]"
33- "xpub6C5pT77VWNhWvrB3TqSEbpm7NCpMYEzbJreYbB68RCUoAMkT7rdhafinmdKL4M5"
34- "275TyDqNAWCnssYnDNaPoXMiAg3sWvCgAiYqY8dHk1k4/<0;1>/*)#r8r04qrm"
35- ),
36- )
37-
38-
39- class _FakePublicDeriver :
40- def fingerprint (self , secret : MasterSeed ) -> bytes :
41- del secret
42- return bytes .fromhex ("3f3521a6" )
43-
44- def public_descriptors (
45- self ,
46- secret : MasterSeed ,
47- * ,
48- wallet : str ,
49- account : int = 0 ,
50- timestamp : int | str = 0 ,
51- ) -> tuple [dict [str , object ], ...]:
52- del secret
53- if wallet != "signer" :
54- raise AssertionError ("unexpected wallet" )
55- if account != 0 :
56- raise AssertionError ("unexpected frozen descriptor request" )
57- return tuple ({"desc" : desc , "active" : True , "timestamp" : timestamp } for desc in _MAIN_DESCRIPTORS )
7+ from codex32 import MasterSeed , master_xprv , parse_codex32
8+ from codex32 .wallet import _core_descriptors , _with_checksum
589
5910
6011def _master () -> MasterSeed :
@@ -71,29 +22,8 @@ def test_master_xprv_matches_bip93_vectors(vector: dict[str, str]) -> None:
7122 assert master_xprv (secret ) == vector ["xprv" ]
7223
7324
74- def test_public_core_descriptors_are_fixed_and_private_free () -> None :
75- records = core_descriptors (_master (), integration = _FakePublicDeriver (), wallet = "signer" )
76-
77- assert len (records ) == 4
78- assert [record ["desc" ].split ("(" , 1 )[0 ] for record in records ] == [
79- "pkh" ,
80- "sh" ,
81- "wpkh" ,
82- "tr" ,
83- ]
84- assert all (record ["active" ] is True for record in records )
85- assert all (record ["timestamp" ] == 0 for record in records )
86- assert all ("xpub" in str (record ["desc" ]) for record in records )
87- assert all ("xprv" not in str (record ["desc" ]) for record in records )
88- assert records [0 ]["desc" ] == (
89- "pkh([3f3521a6/44h/0h/0h]"
90- "xpub6CeZ5XxHp6rXSwi2GCi7UT25rswWQtoPvj36MbzRBr3QEoEmBFNGgnMy329ZMk"
91- "fjRKBZHtKKpYfpkrPWohTjHZZn7y1NR9EHnojaGLKdMAR/<0;1>/*)#smv8ra2a"
92- )
93-
94-
9525def test_private_core_descriptors_use_root_xprv_and_explicit_inputs () -> None :
96- records = core_descriptors (_master (), account = 3 , testnet = True , private = True , timestamp = 123 )
26+ records = _core_descriptors (_master (), account = 3 , testnet = True , timestamp = 123 )
9727
9828 assert all (record ["timestamp" ] == 123 for record in records )
9929 for purpose , record in zip ((44 , 49 , 84 , 86 ), records , strict = True ):
@@ -103,12 +33,7 @@ def test_private_core_descriptors_use_root_xprv_and_explicit_inputs() -> None:
10333
10434
10535def test_core_descriptors_accept_bitcoin_core_now_timestamp () -> None :
106- assert all (
107- record ["timestamp" ] == "now"
108- for record in core_descriptors (
109- _master (), timestamp = "now" , integration = _FakePublicDeriver (), wallet = "signer"
110- )
111- )
36+ assert all (record ["timestamp" ] == "now" for record in _core_descriptors (_master (), timestamp = "now" ))
11237
11338
11439def test_descriptor_checksum_matches_published_example () -> None :
@@ -125,18 +50,18 @@ def test_descriptor_checksum_matches_published_example() -> None:
12550 ),
12651)
12752def test_wallet_boundary_rejects_every_non_master_seed (invalid : object ) -> None :
128- for function in (master_xprv , core_descriptors ):
53+ for function in (master_xprv , _core_descriptors ):
12954 with pytest .raises (TypeError , match = "only MasterSeed" ):
13055 function (invalid ) # type: ignore[arg-type]
13156
13257
13358@pytest .mark .parametrize ("account" , (- 1 , 2 ** 31 , True , "0" ))
13459def test_account_is_explicitly_bounded (account : object ) -> None :
13560 with pytest .raises ((TypeError , ValueError )):
136- core_descriptors (_master (), account = account , integration = _FakePublicDeriver (), wallet = "signer" ) # type: ignore[arg-type]
61+ _core_descriptors (_master (), account = account ) # type: ignore[arg-type]
13762
13863
13964@pytest .mark .parametrize ("timestamp" , (- 1 , True , "yesterday" ))
14065def test_timestamp_is_a_supported_core_value (timestamp : object ) -> None :
14166 with pytest .raises ((TypeError , ValueError )):
142- core_descriptors (_master (), timestamp = timestamp ) # type: ignore[arg-type]
67+ _core_descriptors (_master (), timestamp = timestamp ) # type: ignore[arg-type]
0 commit comments