@@ -316,7 +316,7 @@ public static void DeleteLocalAccount()
316
316
File . Delete ( GetAccountPath ( ) ) ;
317
317
}
318
318
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 )
320
320
{
321
321
password = string . IsNullOrEmpty ( password ) ? GetDeviceIdentifier ( ) : password ;
322
322
@@ -334,7 +334,7 @@ public static Account UnlockOrGenerateLocalAccount(BigInteger chainId, string pa
334
334
try
335
335
{
336
336
var encryptedJson = File . ReadAllText ( path ) ;
337
- var key = keyStoreService . DecryptKeyStoreFromJson ( password , encryptedJson ) ;
337
+ var key = await Task . Run ( ( ) => keyStoreService . DecryptKeyStoreFromJson ( password , encryptedJson ) ) ;
338
338
return new Account ( key , chainId ) ;
339
339
}
340
340
catch ( System . Exception )
@@ -350,13 +350,13 @@ public static Account UnlockOrGenerateLocalAccount(BigInteger chainId, string pa
350
350
rng . GetBytes ( seed ) ;
351
351
}
352
352
var ecKey = Nethereum . Signer . EthECKey . GenerateKey ( seed ) ;
353
- File . WriteAllText ( path , EncryptAndGenerateKeyStore ( ecKey , password ) ) ;
353
+ File . WriteAllText ( path , await EncryptAndGenerateKeyStore ( ecKey , password ) ) ;
354
354
return new Account ( ecKey , chainId ) ;
355
355
}
356
356
}
357
357
}
358
358
359
- public static string EncryptAndGenerateKeyStore ( EthECKey ecKey , string password )
359
+ public static async Task < string > EncryptAndGenerateKeyStore ( EthECKey ecKey , string password )
360
360
{
361
361
var keyStoreService = new Nethereum . KeyStore . KeyStoreScryptService ( ) ;
362
362
var scryptParams = new Nethereum . KeyStore . Model . ScryptParams
@@ -366,7 +366,7 @@ public static string EncryptAndGenerateKeyStore(EthECKey ecKey, string password)
366
366
R = 1 ,
367
367
P = 8
368
368
} ;
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 ) ) ;
370
370
return keyStoreService . SerializeKeyStoreToJson ( keyStore ) ;
371
371
}
372
372
0 commit comments