@@ -108,7 +108,9 @@ pub fn bip85_ln(index: u32) -> Result<zeroize::Zeroizing<Vec<u8>>, ()> {
108
108
mod tests {
109
109
use super :: * ;
110
110
111
- use bitbox02:: testing:: { mock_unlocked, mock_unlocked_using_mnemonic, TEST_MNEMONIC } ;
111
+ use bitbox02:: testing:: {
112
+ mock_memory, mock_unlocked, mock_unlocked_using_mnemonic, TEST_MNEMONIC ,
113
+ } ;
112
114
113
115
#[ test]
114
116
fn test_get_bip39_mnemonic ( ) {
@@ -252,4 +254,76 @@ mod tests {
252
254
// Index too high.
253
255
assert ! ( bip85_ln( HARDENED ) . is_err( ) ) ;
254
256
}
257
+
258
+ #[ test]
259
+ fn test_fixtures ( ) {
260
+ struct Test {
261
+ seed_len : usize ,
262
+ mnemonic_passphrase : & ' static str ,
263
+ expected_mnemonic : & ' static str ,
264
+ expected_xpub : & ' static str ,
265
+ expected_u2f_seed_hex : & ' static str ,
266
+ }
267
+ let seed = hex:: decode ( "cb33c20cea62a5c277527e2002da82e6e2b37450a755143a540a54cea8da9044" )
268
+ . unwrap ( ) ;
269
+
270
+ let tests = [
271
+ Test {
272
+ seed_len : 32 ,
273
+ mnemonic_passphrase : "" ,
274
+ expected_mnemonic : "sleep own lobster state clean thrive tail exist cactus bitter pass soccer clinic riot dream turkey before sport action praise tunnel hood donate man" ,
275
+ expected_xpub : "xpub6Cj6NNCGj2CRPHvkuEG1rbW3nrNCAnLjaoTg1P67FCGoahSsbg9WQ7YaMEEP83QDxt2kZ3hTPAPpGdyEZcfAC1C75HfR66UbjpAb39f4PnG" ,
276
+ expected_u2f_seed_hex : "4f464a6667ad88eebcd0f02982761e474ee0dd16253160320f49d1d6681745e9" ,
277
+ } ,
278
+ Test {
279
+ seed_len : 32 ,
280
+ mnemonic_passphrase : "abc" ,
281
+ expected_mnemonic : "sleep own lobster state clean thrive tail exist cactus bitter pass soccer clinic riot dream turkey before sport action praise tunnel hood donate man" ,
282
+ expected_xpub : "xpub6DXBP3HhFdhUTafatEULxfTXUUxDVuCxfa9RAiBU5r6aRgKiABbeBDyqwWWjmKPP1BZvpvVNMbVR5LeHzhQphtLcPZ8jk3MdLBgc2sACJwR" ,
283
+ expected_u2f_seed_hex : "d599da991ad83baaf449c789e2dff1539dd66983b47a1dec1c00ff3f352cccbc" ,
284
+ } ,
285
+ Test {
286
+ seed_len : 24 ,
287
+ mnemonic_passphrase : "" ,
288
+ expected_mnemonic : "sleep own lobster state clean thrive tail exist cactus bitter pass soccer clinic riot dream turkey before subject" ,
289
+ expected_xpub : "xpub6C7fKxGtTzEVxCC22U2VHx4GpaVy77DzU6KdZ1CLuHgoUGviBMWDc62uoQVxqcRa5RQbMPnffjpwxve18BG81VJhJDXnSpRe5NGKwVpXiAb" ,
290
+ expected_u2f_seed_hex : "fb9dc3fb0a17390776df5c3d8f9261bc5fd5df9f00414cee1393e37e0efda7ef" ,
291
+ } ,
292
+ Test {
293
+ seed_len : 16 ,
294
+ mnemonic_passphrase : "" ,
295
+ expected_mnemonic : "sleep own lobster state clean thrive tail exist cactus bitter pass sniff" ,
296
+ expected_xpub : "xpub6DLvpzjKpJ8k4xYrWYPmZQkUe9dkG1eRig2v6Jz4iYgo8hcpHWx87gGoCGDaB2cHFZ3ExUfe1jDiMu7Ch6gA4ULCBhvwZj29mHCPYSux3YV" ,
297
+ expected_u2f_seed_hex : "20d68b206aff9667b623a460ce61fc94762de67561d6855ca9a6df7b409b2a54" ,
298
+ } ,
299
+ ] ;
300
+
301
+ for test in tests {
302
+ mock_memory ( ) ;
303
+ keystore:: lock ( ) ;
304
+ let seed = & seed[ ..test. seed_len ] ;
305
+ assert ! ( keystore:: unlock_bip39( test. mnemonic_passphrase) . is_err( ) ) ;
306
+ assert ! ( keystore:: encrypt_and_store_seed( seed, "foo" ) . is_ok( ) ) ;
307
+ assert ! ( keystore:: unlock_bip39( test. mnemonic_passphrase) . is_err( ) ) ;
308
+ assert ! ( keystore:: is_locked( ) ) ;
309
+ assert ! ( keystore:: unlock( "foo" ) . is_ok( ) ) ;
310
+ assert ! ( keystore:: is_locked( ) ) ;
311
+ assert ! ( keystore:: unlock_bip39( test. mnemonic_passphrase) . is_ok( ) ) ;
312
+ assert ! ( !keystore:: is_locked( ) ) ;
313
+ assert_eq ! (
314
+ get_bip39_mnemonic( ) . unwrap( ) . as_str( ) ,
315
+ test. expected_mnemonic,
316
+ ) ;
317
+ let keypath = & [ 44 + HARDENED , 0 + HARDENED , 0 + HARDENED ] ;
318
+ let xpub = get_xpub ( keypath) . unwrap ( ) ;
319
+ assert_eq ! (
320
+ xpub. serialize_str( crate :: bip32:: XPubType :: Xpub ) . unwrap( ) ,
321
+ test. expected_xpub,
322
+ ) ;
323
+ assert_eq ! (
324
+ hex:: encode( keystore:: get_u2f_seed( ) . unwrap( ) ) ,
325
+ test. expected_u2f_seed_hex,
326
+ ) ;
327
+ }
328
+ }
255
329
}
0 commit comments