Пример #1
0
        public async Task <HeleusClientResponse> UploadVerification(SubmitAccount submitAccount, VerifyJson verifyJson)
        {
            var serviceNode = submitAccount?.ServiceNode;
            var result      = await SetSubmitAccount(submitAccount);

            if (result != null)
            {
                goto end;
            }

            var attachements = serviceNode.Client.NewAttachements(VerifyServiceInfo.ChainIndex);

            if (verifyJson != null)
            {
                var json = verifyJson.ToJson();
                attachements.AddStringAttachement(VerifyServiceInfo.JsonFileName, json);
            }

            result = await serviceNode.Client.UploadAttachements(attachements, (transaction) =>
            {
                transaction.EnableFeature <AccountIndex>(AccountIndex.FeatureId).Index = VerifyServiceInfo.VerifyIndex;

                transaction.PrivacyType = DataTransactionPrivacyType.PublicData;
            });

end:
            await UIApp.PubSub.PublishAsync(new VerifyUploadEvent(result, serviceNode));

            return(result);
        }
Пример #2
0
        protected async Task <HeleusClientResponse> SetSubmitAccount(SubmitAccount submitAccount, bool requiresSecretKey = false)
        {
            var serviceNode = submitAccount?.ServiceNode;

            if (serviceNode == null)
            {
                return(new HeleusClientResponse(HeleusClientResultTypes.ServiceNodeMissing));
            }

            var account = submitAccount.ServiceAccount;

            if (account == null)
            {
                return(new HeleusClientResponse(HeleusClientResultTypes.ServiceNodeAccountMissing));
            }

            if (requiresSecretKey)
            {
                var secretKey = submitAccount.DefaultSecretKey;
                if (secretKey == null)
                {
                    return(new HeleusClientResponse(HeleusClientResultTypes.ServiceNodeSecretKeyMissing));
                }
            }

            if (!await serviceNode.Client.SetServiceAccount(account, string.Empty, false))
            {
                return(new HeleusClientResponse(HeleusClientResultTypes.InternalError));
            }

            return(null);
        }
Пример #3
0
        public async Task <HeleusClientResponse> UploadNote(SubmitAccount submitAccount, string text)
        {
            var serviceNode = submitAccount?.ServiceNode;
            var result      = await SetSubmitAccount(submitAccount, true);

            if (result != null)
            {
                goto end;
            }

            if (string.IsNullOrWhiteSpace(text))
            {
                result = new HeleusClientResponse(HeleusClientResultTypes.Ok, (long)NoteUserCodes.InvalidAttachement);
                goto end;
            }

            var secretKey    = submitAccount.DefaultSecretKey;
            var attachements = serviceNode.Client.NewAttachements(NoteServiceInfo.ChainIndex);
            var note         = await EncrytpedRecord <NoteRecord> .EncryptRecord(secretKey, new NoteRecord(text));

            attachements.AddBinaryAttachement(NoteServiceInfo.NoteFileName, note.ToByteArray());

            result = await serviceNode.Client.UploadAttachements(attachements, (transaction) =>
            {
                transaction.PrivacyType = DataTransactionPrivacyType.PrivateData;
                transaction.EnableFeature <AccountIndex>(AccountIndex.FeatureId).Index = NoteServiceInfo.NoteIndex;
            });

end:

            await UIApp.PubSub.PublishAsync(new NoteUploadedEvent(result));

            return(result);
        }
Пример #4
0
        public async Task <HeleusClientResponse> RegisterNewList(SubmitAccount submitAccount)
        {
            var serviceNode = submitAccount?.ServiceNode;
            var groupId     = GroupAdministrationInfo.InvalidGroupId;

            var result = await SetSubmitAccount(submitAccount, false);

            if (result != null)
            {
                goto end;
            }


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

            _groupBusy = true;

            var groupReg = new FeatureRequestDataTransaction(submitAccount.AccountId, submitAccount.ChainId, TodoServiceInfo.GroupChainIndex);

            groupReg.SetFeatureRequest(new GroupRegistrationRequest(GroupFlags.AdminOnlyInvitation));

            result = await serviceNode.Client.SendDataTransaction(groupReg, true);

            if (result.TransactionResult == TransactionResultTypes.Ok)
            {
                groupId = (result.Transaction as Transaction).GetFeature <GroupAdministration>(GroupAdministration.FeatureId).NewGroupId;

                var todo     = GetTodo(serviceNode);
                var todoList = todo.AddGroupId(groupId);
                await todo.SaveAsync();

                UIApp.Run(todoList.DownloadTransactions);

                UpdateSubmitAccounts();
            }

end:

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

            await UIApp.PubSub.PublishAsync(new TodoListRegistrationEvent(result, groupId));

            return(result);
        }
Пример #5
0
        public bool IsLastUsedSecretKey(SubmitAccount submitAccount)
        {
            if (LastUsedSecretKeyInfo == null)
            {
                return(true);
            }

            var keyInfo = submitAccount?.DefaultSecretKey?.KeyInfo;

            if (keyInfo != null)
            {
                return(keyInfo.SecretId == LastUsedSecretKeyInfo.SecretId);
            }
            return(false);
        }
Пример #6
0
        public static async Task <bool> CheckSecretKey(TodoList todoList, SubmitAccount submitAccount, ExtContentPage page)
        {
            if (todoList == null)
            {
                return(false);
            }

            if (!todoList.IsLastUsedSecretKey(submitAccount))
            {
                if (!await page.ConfirmAsync("TodoPage.DifferentSecretKeyConfirm"))
                {
                    return(false);
                }
            }

            return(true);
        }