55
66from .generate_test import substitute , nonrandom_bytes
77from .generate import account , create
8- from .recovery import recover
8+ from .recovery import recover , recover_bip39
99
1010SEED_XMAS_HEX = b"dd0e2f02b1f6c92a1a265561bc164135"
1111SEED_XMAS = codecs .decode ( SEED_XMAS_HEX , 'hex_codec' )
@@ -79,14 +79,14 @@ def test_recover():
7979 ]
8080 )
8181 }
82- recover ( details .groups ['one' ][1 ] + details .groups ['fren' ][1 ][:3 ] ) == SEED_XMAS
82+ assert recover ( details .groups ['one' ][1 ] + details .groups ['fren' ][1 ][:3 ] ) == SEED_XMAS
8383
8484 # Enough correct number of mnemonics must be provided (extras ignored)
8585 with pytest .raises (shamir_mnemonic .MnemonicError ) as excinfo :
8686 recover ( details .groups ['one' ][1 ] + details .groups ['fren' ][1 ][:2 ] )
8787 assert "Wrong number of mnemonics" in str (excinfo .value )
8888
89- recover ( details .groups ['one' ][1 ] + details .groups ['fren' ][1 ][:4 ] ) == SEED_XMAS
89+ assert recover ( details .groups ['one' ][1 ] + details .groups ['fren' ][1 ][:4 ] ) == SEED_XMAS
9090
9191 # Invalid mnemonic phrases are rejected (one word changed)
9292 with pytest .raises (shamir_mnemonic .MnemonicError ) as excinfo :
@@ -106,3 +106,71 @@ def test_recover():
106106 "academic acid academic axle crush swing purple violence teacher curly total equation clock mailman display husband tendency smug laundry disaster"
107107 ])
108108 assert "Invalid set of mnemonics" in str (excinfo .value )
109+
110+
111+ @substitute ( shamir_mnemonic .shamir , 'RANDOM_BYTES' , nonrandom_bytes )
112+ def test_bip39 ():
113+ bip39seed = recover_bip39 ( 'zoo ' * 11 + 'wrong' )
114+ details = create (
115+ "bip39 recovery test" , 2 , dict ( one = (1 ,1 ), two = (1 ,1 ), fam = (2 ,4 ), fren = (3 ,5 ) ),
116+ master_secret = bip39seed ,
117+ )
118+ #import json
119+ #print( json.dumps( details.groups, indent=4 ))
120+ assert details .groups == {
121+ "one" : (
122+ 1 ,
123+ [
124+ "academic acid acrobat romp academic angel email prospect endorse strategy debris award strike frost actress facility legend safari pistol"
125+ " mouse hospital identify unwrap talent entrance trust cause ranked should impulse avoid fangs various radar dilemma indicate says rich work"
126+ " presence jerky glance hesitate huge depend tension loan tolerate news agree geology phrase random simple finger alarm depart inherit grin"
127+ ]
128+ ),
129+ "two" : (
130+ 1 ,
131+ [
132+ "academic acid beard romp acne floral cricket answer debris making decorate square withdraw empty decorate object artwork tracks rocky tolerate"
133+ " syndrome decorate predator sweater ordinary pecan plastic spew facility predator miracle change solution item lizard testify coal excuse lecture"
134+ " exercise hamster hand crystal rainbow indicate phantom require satisfy flame acrobat detect closet patent therapy overall muscle spill adjust unhappy"
135+ ]
136+ ),
137+ "fam" : (
138+ 2 ,
139+ [
140+ "academic acid ceramic roster acquire again tension ugly edge profile custody geology listen hazard smug branch adequate fishing simple adapt fancy"
141+ " hour method emperor tactics float quiet location satoshi guilt fantasy royal machine dictate squeeze devote oven eclipse writing level sheriff"
142+ " teacher purchase building veteran spirit woman realize width vanish scholar jewelry desktop stilt random rhyme debut premium theater" ,
143+ "academic acid ceramic scared acid space fantasy breathe true recover privacy tactics boring harvest punish swimming leader talent exchange diet"
144+ " enforce vanish volume organize coastal emperor change intend club scene intimate upgrade dragon burning lily huge market calcium forecast holiday"
145+ " merit method type ruler equip retailer pancake paces thorn worthy always story promise clock staff floral smart iris repair" ,
146+ "academic acid ceramic shadow acne rumor decent elder aspect lizard obesity friendly regular aircraft beyond military campus employer seafood cover"
147+ " ivory dough galaxy victim diminish average music cause behavior declare brave toxic visual academic include lilac repair morning rapids building"
148+ " kernel herald careful helpful move hawk flash glimpse seafood listen writing rocky browser change hybrid diet organize system wrote" ,
149+ "academic acid ceramic sister academic both legend raspy pecan mixed broken tenant critical again imply finance pacific single echo capital hesitate"
150+ " piece disease crush slush belong airline smug voice organize dryer standard emission curious charity swing pitch senior behavior vintage chemical"
151+ " cage editor rebuild costume adult ancestor erode steady makeup depart carpet level sympathy being soldier glimpse airport picture"
152+ ]
153+ ),
154+ "fren" : (
155+ 3 ,
156+ [
157+ "academic acid decision round academic academic academic academic academic academic academic academic academic academic academic academic academic"
158+ " academic academic academic academic academic academic academic academic academic academic academic academic academic academic academic academic"
159+ " academic academic academic academic academic academic academic academic academic academic academic academic academic academic academic academic"
160+ " academic academic academic academic academic academic academic aviation endless plastic" ,
161+ "academic acid decision scatter acid ugly raspy famous swimming else length gray raspy brother fake aunt auction premium military emphasis perfect"
162+ " surprise class suitable crunch famous burden military laundry inmate regret elder mixture tenant taught smirk voter process steady artist equip"
163+ " jury carve acrobat western cylinder gasoline artwork snapshot ancestor object cinema market species platform iris dragon dive medal" ,
164+ "academic acid decision shaft acid carbon credit cards rich living humidity peasant source triumph magazine ladle ruin ocean aspect curious round"
165+ " main evoke deny stadium zero discuss union strike pencil golden silent geology display wrap peanut listen aide learn juice decision plot bike example"
166+ " obesity ancient square pistol twice sister hour amuse human hobo hospital escape expect wildlife luck" ,
167+ "academic acid decision skin academic vanish olympic evoke gesture rumor unfair scroll grasp very steady include smell diploma package guest greatest"
168+ " firm humidity trial width priest class large photo sniff survive machine usher stick capacity heat improve predator float iris jacket soldier apart"
169+ " excuse garden cleanup realize permit dough script veteran crazy theater rival secret drink kernel lips pants" ,
170+ "academic acid decision snake acid vegan darkness bucket benefit therapy valuable impulse canyon swing distance vampire round losing twin medal treat"
171+ " amount fiction hush remind faint distance custody device believe campus guest preach mule exhaust regular short phrase column rescue steady float"
172+ " mixture testify taught fiction usher snake museum detailed agree intend inherit likely typical blimp symbolic prayer course"
173+ ]
174+ )
175+ }
176+ assert recover ( details .groups ['one' ][1 ][:] + details .groups ['fren' ][1 ][:3 ] ) == bip39seed
0 commit comments