Exemple #1
0
 public async Task <CoreAccountKeyStore> StoreAccount(string name, long accountId, Key key, string password)
 {
     return(await Task.Run(async() =>
     {
         var keyStore = new CoreAccountKeyStore(name, accountId, key, password);
         await StoreAccount(keyStore);
         await keyStore.DecryptKeyAsync(password, false);
         return keyStore;
     }));
 }
        public static async Task <HeleusClientResponse> RequestRestore(long accountId, string name, string password, Key key)
        {
            HeleusClientResponse result = null;

            if (CurrentCoreAccount != null)
            {
                result = new HeleusClientResponse(HeleusClientResultTypes.CoreAccountAlreadyAvailable);
                goto end;
            }

            if (!IsValidPassword(password))
            {
                result = new HeleusClientResponse(HeleusClientResultTypes.PasswordError);
                goto end;
            }

            if (_busy)
            {
                result = new HeleusClientResponse(HeleusClientResultTypes.Busy);
                goto end;
            }
            _busy = true;

            var coreAccountDownload = await Client.DownloadCoreAccount(accountId);

            var coreAccount = coreAccountDownload.Data;

            if (name.IsNullOrWhiteSpace())
            {
                name = $"Heleus Account ({accountId})";
            }

            if (coreAccount != null)
            {
                if (key.PublicKey == coreAccount.AccountKey)
                {
                    var coreAccountStore = new CoreAccountKeyStore(name, accountId, key, password);
                    await coreAccountStore.DecryptKeyAsync(password, true);

                    await Client.StoreAccount(coreAccountStore);

                    CurrentCoreAccount = coreAccountStore;

                    result = new HeleusClientResponse(HeleusClientResultTypes.Ok);
                }
                else
                {
                    result = new HeleusClientResponse(HeleusClientResultTypes.RestoreInvalidSignatureKey);
                }
            }
            else
            {
                result = new HeleusClientResponse(HeleusClientResultTypes.RestoreCoreAccountNotFound);
            }

end:
            await UIApp.PubSub.PublishAsync(new CoreAccountRegisterEvent(result, CurrentCoreAccount));

            if (CurrentCoreAccount != null)
            {
                await UnlockCoreAccount(password);
            }

            if (result.ResultType != HeleusClientResultTypes.Busy)
            {
                _busy = false;
            }

            return(result);
        }