Пример #1
0
        public static async Task <bool> ValidateAccount(KeyStore account, string password)
        {
            try
            {
                await account.DecryptKeyAsync(password, true);

                if (account.KeyStoreType == KeyStoreTypes.CoreAccount)
                {
                    var coreAccount = (await Client.DownloadCoreAccount(account.AccountId)).Data;
                    if (coreAccount != null)
                    {
                        return(coreAccount.AccountKey == account.DecryptedKey.PublicKey);
                    }
                }
                else if (account.KeyStoreType == KeyStoreTypes.Chain)
                {
                    var chainData = (await Client.DownloadChainInfo(account.ChainId)).Data;
                    if (chainData != null)
                    {
                        var key = chainData.GetChainKey(account.KeyIndex);
                        return(key != null && key.PublicKey == account.DecryptedKey.PublicKey);
                    }
                }
            }
            catch
            {
            }

            return(false);
        }
Пример #2
0
        public static async Task <ImportAccountResult> ImportAccount(KeyStore account, string password)
        {
            try
            {
                await account.DecryptKeyAsync(password, true);

                if (CurrentCoreAccount != null && account.KeyStoreType == KeyStoreTypes.CoreAccount)
                {
                    return(ImportAccountResult.CoreAccountAlreadyPresent);
                }

                if (!await ValidateAccount(account, password))
                {
                    return(ImportAccountResult.ValidationFailed);
                }

                await Client.StoreAccount(account);

                if (account.KeyStoreType == KeyStoreTypes.CoreAccount)
                {
                    CurrentCoreAccount = (CoreAccountKeyStore)account;
                    await UnlockCoreAccount(password);
                }

                await UIApp.PubSub.PublishAsync(new AccountImportEvent(account));

                return(ImportAccountResult.Ok);
            }
            catch (Exception ex)
            {
                global::Heleus.Base.Log.IgnoreException(ex);
            }

            return(ImportAccountResult.PasswordInvalid);
        }
Пример #3
0
        protected async Task <bool> UnlockAccount(KeyStore account, string password, KeyStoreTypes keyStoreType)
        {
            if (account == null)
            {
                return(false);
            }

            if (account.KeyStoreType != keyStoreType)
            {
                return(false);
            }

            try
            {
                if (await account.DecryptKeyAsync(password, false))
                {
                    Log.Trace($"Account unlocked: {account.Name}, id {account.AccountId}, chainid {account.ChainId}, keyindex {account.KeyIndex}.", this);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.IgnoreException(ex, this);
            }
            return(false);
        }