package Ġorg . dex on . wallet . keystore Ċ Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . rules . Expected Exception Ċ import Ġorg . ke thereum . bip 3 9 . dirty Phrase To Mnemonic Words Ċ import Ġorg . ke thereum . bip 3 9 . generate Mnemonic Ċ import Ġorg . ke thereum . bip 3 9 . word lists . WORD LIST _ EN GL ISH Ċ import Ġorg . ke thereum . extensions . to HexString No Prefix Ċ import Ġorg . ke thereum . model . PrivateKey Ċ import Ġorg . ke thereum . wallet . model . Cipher Exception Ċ import Ġorg . w alle th . k hex . hex To ByteArray Ċ Ċ @ Suppress (" RECE IVER _ NULL ABILITY _ MIS MATCH _ BASE D _ ON _ JAVA _ AN NOT ATIONS ") Ċ class ĠKe yst ore Key Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġexpected Exception : ĠExpected Exception Ġ= ĠExpected Exception . none () ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠTest . None :: class ) ĊĠĠĠ Ġfun Ġtest Create Wallet With Password () Ġ{ ĊĠĠĠĠĠĠĠ ĠKe yst ore Key ( password Ġ= ĠPASSWORD ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Create Wallet With PrivateKey () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexpected PrivateKey Ġ= ĠPrivate Key ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" 3 a 1 0 7 6 bf 4 5 ab 8 7 7 1 2 ad 6 4 ccb 3 b 1 0 2 1 7 7 3 7 f 7 fa ac bf 2 8 7 2 e 8 8 fdd 9 a 5 3 7 d 8 fe 2 6 6 ". hex To ByteArray () ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= ĠKe yst ore Key ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpassword Ġ= ĠPASSWORD , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġkey Ġ= Ġexpected PrivateKey , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcoin Ġ= ĠCoin Type . ET HERE UM ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual PrivateKey Ġ= ĠPrivate Key ( key . decrypt ( password Ġ= ĠPASSWORD )) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Wallet Type . PRIVATE _ KEY , Ġkey . type ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Coin Type . ET HERE UM , Ġkey . coin ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( expected PrivateKey . key , Ġactual PrivateKey . key ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Create Wallet With Mnemonic () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexpected Mnemonic Ġ= Ġdirty Phrase To Mnemonic Words ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġgenerate Mnemonic ( strength Ġ= Ġ 1 2 8 , Ġword List Ġ= ĠWORD LIST _ EN GL ISH ) ĊĠĠĠĠĠĠĠ Ġ). words . join ToString (" Ġ") ĊĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= ĠKe yst ore Key ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpassword Ġ= ĠPASSWORD , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmnemonic Ġ= Ġexpected Mnemonic , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpassphrase Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Mnemonic Ġ= Ġkey . decrypt ( password Ġ= ĠPASSWORD ). toString ( Charsets . US _ ASCII ) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Wallet Type . HD _ WAL LET , Ġkey . type ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( expected Mnemonic , Ġactual Mnemonic ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Read Wallet With Mnemonic Type () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclass Loader Ġ= Ġjava Class . class Loader . getResource (" wallet _ mn emonic . json ") ĊĠĠĠĠĠĠĠ Ġval Ġuri Ġ= Ġclass Loader . to URI () ĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= ĠKe yst ore Key ( uri ) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" e 0 fe 5 3 d 0 - 7 a 3 d - 4 f 6 5 - 8 8 b 1 - 9 bb 4 e 2 4 5 a 1 6 9 ", Ġkey . id ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 3 , Ġkey . version ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Wallet Type . HD _ WAL LET , Ġkey . type ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Coin Type . ET HERE UM , Ġkey . coin ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 0 x 3 2 dd 5 5 E 0 B CF 5 0 9 a 3 5 A 3 F 5 e Eb 8 5 9 3 fb Eb 2 4 4 7 9 6 b 1 ", Ġkey . address ?. hex ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ("", Ġkey . pass phrase ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcrypto Ġ= Ġkey . crypto ĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" aes - 1 2 8 - ctr ", Ġcrypto . cipher ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 6 4 b 5 b 4 1 6 bb 2 bef 8 8 2 eb 7 cc 6 3 ed 9 2 c 0 6 4 e 5 3 c 8 1 8 ec 4 6 3 5 1 e 0 7 ac 1 4 0 e 5 ba 8 7 1 5 9 6 f 1 5 9 5 fe 6 cad 8 3 3 3 1 4 7 fe 6 8 c 0 3 1 ba 0 0 1 b 7 9 b 6 4 dd 1 edd 5 1 3 0 4 3 1 3 4 2 1 7 b 7 ffe 1 9 0 3 ca 2 3 b 1 fbe 8 2 3 6 7 1 8 2 7 e 3 b 2 dff 6 9 bbd 4 4 8 d 9 cb 7 9 a 3 3 2 1 ec 8 8 0 1 f 2 a 9 9 5 ", Ġcrypto . cipher Text ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" sc rypt ", Ġcrypto . k df ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 0 1 8 1 6 d 0 a 5 c 3 1 cd 0 3 b 6 4 4 f 2 d 7 5 6 ac 8 1 6 7 c 2 4 9 8 8 0 8 0 4 0 cb ace 8 c 3 5 c 4 6 dcf 0 6 b 7 a 1 ", Ġcrypto . mac ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 7 aaf 7 eb 6 f 4 b 0 e 7 d 9 9 5 e 8 eac 6 7 e 4 d 5 2 eb ", Ġcrypto . cipher Params . iv ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 3 2 , Ġcrypto . k df Params . dk len ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 4 0 9 6 , Ġcrypto . k df Params . n ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 6 , Ġcrypto . k df Params . p ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 8 , Ġcrypto . k df Params . r ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 8 0 1 3 2 8 4 2 c 6 cde 8 f 9 d 0 4 5 8 2 9 3 2 ef 9 2 c 3 cad 3 ba 6 b 4 1 e 1 2 9 6 ef 6 8 1 6 9 2 3 7 2 8 8 6 db 8 6 ", Ġcrypto . k df Params . salt ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Read Wallet With PrivateKey Type () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclass Loader Ġ= Ġjava Class . class Loader . getResource (" wallet _ private _ key . json ") ĊĠĠĠĠĠĠĠ Ġval Ġuri Ġ= Ġclass Loader . to URI () ĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= ĠKe yst ore Key ( uri ) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 2 ea 9 acf 7 - 1 7 ac - 4 8 f 7 - b 2 fb - c 1 6 e 1 0 0 3 6 f 0 6 ", Ġkey . id ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 3 , Ġkey . version ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Wallet Type . PRIVATE _ KEY , Ġkey . type ) ĊĠĠĠĠĠĠĠ ĠAssert . assertNull ( key . coin ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 0 x 8 0 ef 3 7 2 3 6 4 1 8 3 2 0 c 0 f 7 a 5 5 a 8 4 cc aa 7 e 0 8 0 cdf b 1 7 ", Ġkey . address ?. hex ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ("", Ġkey . pass phrase ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcrypto Ġ= Ġkey . crypto ĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" aes - 1 2 8 - ctr ", Ġcrypto . cipher ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" d 6 a 9 dcc 3 1 2 6 4 9 a 4 c 1 7 7 cdc 4 5 8 b 5 1 d 2 4 9 d 9 0 1 df 2 4 a 0 4 2 b 3 f 8 1 8 d 2 7 4 d 1 9 c 5 7 2 2 a 8 ", Ġcrypto . cipher Text ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" sc rypt ", Ġcrypto . k df ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" bc 5 3 e 9 6 3 4 f 9 bb 1 2 9 3 7 f 9 0 1 0 3 7 2 1 5 c 1 bf 3 c 3 a 1 2 de 2 0 3 eaa 2 6 6 5 1 ffa 6 b 7 6 6 dad 0 4 ", Ġcrypto . mac ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" d 3 bc 6 0 7 4 4 0 6 5 6 2 1 cf 1 8 2 8 2 4 c 2 d 2 0 8 d 0 5 ", Ġcrypto . cipher Params . iv ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 3 2 , Ġcrypto . k df Params . dk len ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 4 0 9 6 , Ġcrypto . k df Params . n ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 6 , Ġcrypto . k df Params . p ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 8 , Ġcrypto . k df Params . r ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" cc 9 1 a 0 1 c 3 ca 9 8 3 5 1 fa 7 b 5 6 4 cc 4 4 7 7 7 c 3 f 5 0 6 9 7 1 ef 5 ea 7 0 3 0 9 7 5 a 4 c 3 6 4 9 5 8 ad cb ", Ġcrypto . k df Params . salt ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Read My Ether Wallet () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclass Loader Ġ= Ġjava Class . class Loader . getResource (" my ether wallet . uu ") ĊĠĠĠĠĠĠĠ Ġval Ġuri Ġ= Ġclass Loader . to URI () ĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= ĠKe yst ore Key ( uri ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 0 x 8 5 6 2 fcc cb ae 3 0 1 9 f 5 a 7 1 6 9 9 7 6 0 9 b 3 0 1 ac 3 1 fe 0 4 a ", Ġkey . address ?. hex ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Decrypt Invalid Password () Ġ{ ĊĠĠĠĠĠĠĠ Ġexpected Exception . expect ( Cipher Exception :: class . java ) ĊĠĠĠĠĠĠĠ Ġexpected Exception . expect Message (" Invalid Ġpassword ") ĊĊĠĠĠĠĠĠĠ Ġval Ġclass Loader Ġ= Ġjava Class . class Loader . getResource (" wallet _ private _ key . json ") ĊĠĠĠĠĠĠĠ Ġval Ġuri Ġ= Ġclass Loader . to URI () ĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= ĠKe yst ore Key ( uri ) ĊĠĠĠĠĠĠĠ Ġkey . decrypt ( password Ġ= Ġ" password 1 2 3 ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Decrypt PrivateKey () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclass Loader Ġ= Ġjava Class . class Loader . getResource (" wallet _ private _ key . json ") ĊĠĠĠĠĠĠĠ Ġval Ġuri Ġ= Ġclass Loader . to URI () ĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= ĠKe yst ore Key ( uri ) ĊĠĠĠĠĠĠĠ Ġval ĠprivateKey Ġ= ĠPrivate Key ( key . decrypt ( password Ġ= ĠPASSWORD )) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Wallet Type . PRIVATE _ KEY , Ġkey . type ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" d 6 ddd 6 0 7 fb 6 5 0 8 cb 4 8 cbb 0 4 9 2 4 9 5 be 2 4 7 a 3 4 7 6 f 4 b 1 4 0 4 7 3 e 2 3 a 8 2 9 e 7 2 2 fd 4 9 6 8 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠprivateKey . key . to HexString No Prefix () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ Ċ }