@@ -32,6 +32,43 @@ class web3swift_Keystores_tests: XCTestCase {
32
32
let recoveredSeed = BIP39 . mnemonicsToEntropy ( mnemonics!, language: . english)
33
33
XCTAssert ( seed == recoveredSeed)
34
34
}
35
+
36
+ // https://github.com/trezor/python-mnemonic/blob/master/vectors.json
37
+ func testBIP39MnemonicIsMultipleOfThree( ) {
38
+ // https://github.com/trezor/python-mnemonic/blob/master/vectors.json#L95
39
+ let mnemonic_12 = " scheme spot photo card baby mountain device kick cradle pact join borrow "
40
+ let entropy_12 = BIP39 . mnemonicsToEntropy ( mnemonic_12, language: . english)
41
+ XCTAssertEqual ( entropy_12!. toHexString ( ) , " c0ba5a8e914111210f2bd131f3d5e08d " )
42
+
43
+ let mnemonic_15 = " foster muscle start pluck when army tool surprise essay monitor impulse hello segment garage twenty "
44
+ let entropy_15 = BIP39 . mnemonicsToEntropy ( mnemonic_15, language: . english)
45
+ XCTAssertEqual ( entropy_15!. toHexString ( ) , " 5c123352d35fa218392ed34d31e1c8b56c32befa " )
46
+
47
+ // https://github.com/trezor/python-mnemonic/blob/master/vectors.json#L101
48
+ let mnemonic_18 = " horn tenant knee talent sponsor spell gate clip pulse soap slush warm silver nephew swap uncle crack brave "
49
+ let entropy_18 = BIP39 . mnemonicsToEntropy ( mnemonic_18, language: . english)
50
+ XCTAssertEqual ( entropy_18!. toHexString ( ) , " 6d9be1ee6ebd27a258115aad99b7317b9c8d28b6d76431c3 " )
51
+
52
+ let mnemonic_21 = " weird change toe upper damp panel unaware long noise resource grant prevent file live travel price cry danger fix manage base "
53
+ let entropy_21 = BIP39 . mnemonicsToEntropy ( mnemonic_21, language: . english)
54
+ XCTAssertEqual ( entropy_21!. toHexString ( ) , " f924c78e7783733f3b1c1e95d6f196d525630579e5533526ed604371 " )
55
+
56
+ // https://github.com/trezor/python-mnemonic/blob/master/vectors.json#L107
57
+ let mnemonic_24 = " panda eyebrow bullet gorilla call smoke muffin taste mesh discover soft ostrich alcohol speed nation flash devote level hobby quick inner drive ghost inside "
58
+ let entropy_24 = BIP39 . mnemonicsToEntropy ( mnemonic_24, language: . english)
59
+ XCTAssertEqual ( entropy_24!. toHexString ( ) , " 9f6a2878b2520799a44ef18bc7df394e7061a224d2c33cd015b157d746869863 " )
60
+
61
+ // Invalid mnemonics
62
+
63
+ let mnemonic_9 = " initial repeat scout eye october lucky rabbit enact unfair "
64
+ XCTAssertNil ( BIP39 . mnemonicsToEntropy ( mnemonic_9, language: . english) )
65
+
66
+ let mnemonic_16 = " success drip spoon lunar effort unfold clinic seminar custom protect orchard correct pledge cousin slab visa "
67
+ XCTAssertNil ( BIP39 . mnemonicsToEntropy ( mnemonic_16, language: . english) )
68
+
69
+ let mnemonic_27 = " clock venue style demise net float differ click object poet afraid october hurry organ faint inject cart trade test immense gentle speak almost rude success drip spoon "
70
+ XCTAssertNil ( BIP39 . mnemonicsToEntropy ( mnemonic_27, language: . english) )
71
+ }
35
72
36
73
func testHMAC( ) {
37
74
let seed = Data . fromHex ( " 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b " ) !
0 commit comments