@@ -316,7 +316,7 @@ public static void DeleteLocalAccount()
316316 File . Delete ( GetAccountPath ( ) ) ;
317317 }
318318
319- public static Account UnlockOrGenerateLocalAccount ( BigInteger chainId , string password = null , string privateKey = null )
319+ public static async Task < Account > UnlockOrGenerateLocalAccount ( BigInteger chainId , string password = null , string privateKey = null )
320320 {
321321 password = string . IsNullOrEmpty ( password ) ? GetDeviceIdentifier ( ) : password ;
322322
@@ -334,7 +334,7 @@ public static Account UnlockOrGenerateLocalAccount(BigInteger chainId, string pa
334334 try
335335 {
336336 var encryptedJson = File . ReadAllText ( path ) ;
337- var key = keyStoreService . DecryptKeyStoreFromJson ( password , encryptedJson ) ;
337+ var key = await Task . Run ( ( ) => keyStoreService . DecryptKeyStoreFromJson ( password , encryptedJson ) ) ;
338338 return new Account ( key , chainId ) ;
339339 }
340340 catch ( System . Exception )
@@ -350,13 +350,13 @@ public static Account UnlockOrGenerateLocalAccount(BigInteger chainId, string pa
350350 rng . GetBytes ( seed ) ;
351351 }
352352 var ecKey = Nethereum . Signer . EthECKey . GenerateKey ( seed ) ;
353- File . WriteAllText ( path , EncryptAndGenerateKeyStore ( ecKey , password ) ) ;
353+ File . WriteAllText ( path , await EncryptAndGenerateKeyStore ( ecKey , password ) ) ;
354354 return new Account ( ecKey , chainId ) ;
355355 }
356356 }
357357 }
358358
359- public static string EncryptAndGenerateKeyStore ( EthECKey ecKey , string password )
359+ public static async Task < string > EncryptAndGenerateKeyStore ( EthECKey ecKey , string password )
360360 {
361361 var keyStoreService = new Nethereum . KeyStore . KeyStoreScryptService ( ) ;
362362 var scryptParams = new Nethereum . KeyStore . Model . ScryptParams
@@ -366,7 +366,7 @@ public static string EncryptAndGenerateKeyStore(EthECKey ecKey, string password)
366366 R = 1 ,
367367 P = 8
368368 } ;
369- var keyStore = keyStoreService . EncryptAndGenerateKeyStore ( password , ecKey . GetPrivateKeyAsBytes ( ) , ecKey . GetPublicAddress ( ) , scryptParams ) ;
369+ var keyStore = await Task . Run ( ( ) => keyStoreService . EncryptAndGenerateKeyStore ( password , ecKey . GetPrivateKeyAsBytes ( ) , ecKey . GetPublicAddress ( ) , scryptParams ) ) ;
370370 return keyStoreService . SerializeKeyStoreToJson ( keyStore ) ;
371371 }
372372
0 commit comments