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); }
public async Task <MessageSentEvent> SendMessage(Chat chat, string text) { var index = chat.Index; var submitAccount = ServiceNode.GetSubmitAccount <MessageSubmitAccount>(chat.KeyIndex, index); if (submitAccount == null) { submitAccount = GenerateSubmitAccount(index); } await GenerateSecretExchangeKey(submitAccount, chat.FriendAccountId, chat.FriendKeyIndex); var result = await SetSubmitAccount(submitAccount, true); if (result != null) { goto end; } if (string.IsNullOrWhiteSpace(text)) { result = new HeleusClientResponse(HeleusClientResultTypes.Ok, (long)ServiceUserCodes.InvalidAttachement); goto end; } var secretKey = submitAccount.DefaultSecretKey; var record = await EncrytpedRecord <MessageRecord> .EncryptRecord(secretKey, new MessageRecord(text)); var transaction = new DataTransaction(submitAccount.AccountId, submitAccount.ChainId, MessageServiceInfo.MessageDataChainIndex); transaction.EnableFeature <PreviousAccountTransaction>(PreviousAccountTransaction.FeatureId); var sharedAccountIndex = transaction.EnableFeature <SharedAccountIndex>(SharedAccountIndex.FeatureId); sharedAccountIndex.Index = index; var data = transaction.EnableFeature <Data>(Data.FeatureId); data.AddBinary(MessageServiceInfo.MessageDataIndex, record.ToByteArray()); var receiver = transaction.EnableFeature <Receiver>(Receiver.FeatureId); receiver.AddReceiver(submitAccount.FriendAccountId); transaction.EnableFeature(EnforceReceiverFriend.FeatureId); result = await _client.SendDataTransaction(transaction, true); if (result.TransactionResult == TransactionResultTypes.Ok) { if (!_chats.ContainsKey(chat.Index)) { _chats[chat.Index] = chat; await SaveAsync(); } UIApp.Run(() => chat.DownloadMessages(false)); } end: var @event = new MessageSentEvent(text, index, this, result); await UIApp.PubSub.PublishAsync(@event); return(@event); }
public JoinChainEvent(long accountId, int chainId, HeleusClientResponse response) { AccountId = accountId; ChainId = chainId; Response = response; }
public TodoListRegistrationEvent(HeleusClientResponse result, long listId) : base(result) { ListId = listId; }
public TodoListAccountDeleteEvent(HeleusClientResponse result, long listId, long accountId) : base(result) { ListId = listId; AccountId = accountId; }
public TodoListNameChangedEvent(HeleusClientResponse result, long listId) : base(result) { ListId = listId; }
public TodoTaskStatusEvent(HeleusClientResponse result, TodoTaskStatusTypes itemStatus) : base(result) { ItemStatus = itemStatus; }
public InboxRenameEvent(string title, short keyIndex, MessageNode node, HeleusClientResponse heleusClientResponse) : base(node, heleusClientResponse) { Title = title; KeyIndex = keyIndex; }
public MessageSentEvent(HeleusClientResponse result) : base(result) { }
public NoteUploadedEvent(HeleusClientResponse response) { Response = response; }
public MessageNodeClientEvent(MessageNode node, HeleusClientResponse heleusClientResponse) : base(heleusClientResponse) { Node = node; }
public CoreAccountTransferEvent(HeleusClientResponse response) { Response = response; }
public UnfriendEvent(long accountId, MessageNode node, HeleusClientResponse heleusClientResponse) : base(node, heleusClientResponse) { AccountId = accountId; }
public VerifyUploadEvent(HeleusClientResponse response, ServiceNode serviceNode) : base(serviceNode) { Response = response; }
public static async Task UpdateChain(ChainKeyStore chainKey, string password, string chainName, string chainWebsite, WalletClient.ChainKey[] chainKeys, Uri[] endPoints, PurchaseInfo[] purchases, short[] revokedChainKeys, Uri[] revokedEndPoints, int[] revokedPurchases) { if (CurrentCoreAccount == null) { return; } HeleusClientResponse result = null; ChainInfo chainInfo = null; if (_busy) { result = new HeleusClientResponse(HeleusClientResultTypes.Busy); goto end; } _busy = true; try { await chainKey.DecryptKeyAsync(password, true); await Client.SetChainAccount(chainKey, password); } catch { result = new HeleusClientResponse(HeleusClientResultTypes.PasswordError); goto end; } try { var transaction = Client.NewChainUpdateTransaction(true); if (chainKeys != null) { foreach (var ck in chainKeys) { transaction.AddChainKey(ck.SignedPublicKey); } } if (endPoints != null) { foreach (var ep in endPoints) { transaction.AddPublicEndpoint(ep.AbsoluteUri); } } if (purchases != null) { foreach (var p in purchases) { transaction.AddPurchase(p); } } if (revokedChainKeys != null) { foreach (var key in revokedChainKeys) { transaction.RevokeChainKey(key); } } if (revokedEndPoints != null) { foreach (var ep in revokedEndPoints) { transaction.RemovePublicEndPoint(ep.AbsoluteUri); } } if (revokedPurchases != null) { foreach (var p in revokedPurchases) { transaction.RemovePurchase(p); } } transaction.UpdateChainName(chainName); transaction.UpdateChainWebsite(chainWebsite); if (!await Client.SetTargetChain(Protocol.CoreChainId)) { result = new HeleusClientResponse(HeleusClientResultTypes.EndpointConnectionError); goto end; } result = await Client.UpdateChain(transaction, chainKeys); if (result.TransactionResult == TransactionResultTypes.Ok) { chainInfo = (await Client.DownloadChainInfo((result.Transaction as ChainInfoOperation).ChainId)).Data; } } catch (Exception ex) { Log.IgnoreException(ex); } end: await UIApp.PubSub.PublishAsync(new ChainRegistrationEvent(result, chainInfo)); if (result.ResultType != HeleusClientResultTypes.Busy) { _busy = false; } }
public ProfileUploadEvent(long accountId, int chainId, HeleusClientResponse response) { AccountId = accountId; ChainId = chainId; Response = response; }
public static async Task <(HeleusClientResponse, PublicServiceAccountKey)> JoinChain(int chainId, long expires, Key accountChainKey, string accountPassword, string chainKeyName = null, string chainKeyPassword = null) { HeleusClientResponse result = null; PublicServiceAccountKey publicKey = null; if (!HasCoreAccount) { result = new HeleusClientResponse(HeleusClientResultTypes.NoCoreAccount); goto end; } if (_busy) { result = new HeleusClientResponse(HeleusClientResultTypes.Busy); goto end; } _busy = true; if (!IsCoreAccountUnlocked) { if (!await CurrentCoreAccount.DecryptKeyAsync(accountPassword, false)) { result = new HeleusClientResponse(HeleusClientResultTypes.PasswordError); goto end; } await UnlockCoreAccount(accountPassword); } if (!await Client.SetTargetChain(chainId)) { result = new HeleusClientResponse(HeleusClientResultTypes.EndpointConnectionError); goto end; } var nextKeyIndex = (await Client.DownloadNextServiceAccountKeyIndex(CurrentCoreAccount.AccountId, chainId)).Data; if (nextKeyIndex == null) { result = new HeleusClientResponse(HeleusClientResultTypes.EndpointConnectionError); goto end; } if (!nextKeyIndex.IsValid) { var err = HeleusClientResultTypes.EndpointConnectionError; if (nextKeyIndex.ResultType == ResultTypes.AccountNotFound) { err = HeleusClientResultTypes.NoCoreAccount; } result = new HeleusClientResponse(err); goto end; } publicKey = PublicServiceAccountKey.GenerateSignedPublicKey(CurrentCoreAccount.AccountId, chainId, expires, nextKeyIndex.Item, accountChainKey, CurrentCoreAccount.DecryptedKey); result = await Client.JoinChain(chainId, publicKey, accountChainKey, chainKeyName, chainKeyPassword); end: await UIApp.PubSub.PublishAsync(new JoinChainEvent(CurrentCoreAccount == null ? 0 : CurrentCoreAccount.AccountId, chainId, result)); if (result.ResultType != HeleusClientResultTypes.Busy) { _busy = false; } return(result, publicKey); }
public ChainRegistrationEvent(HeleusClientResponse response, ChainInfo chainInfo) { ChainOperation = response.Transaction as ChainInfoOperation; Response = response; ChainInfo = chainInfo; }
public NewTodoTaskEvent(HeleusClientResponse result) : base(result) { }
public SubscriptionEvent(HeleusClientResponse result, long accountId, bool subscribed) : base(result) { AccountId = accountId; Subscribed = subscribed; }
protected TodoListEvent(HeleusClientResponse result, ServiceNode serviceNode) : base(result) { ServiceNode = serviceNode; }
public PurchaseEvent(HeleusClientResponse response) { Response = response; }
public TodoListDeletetEvent(HeleusClientResponse result, long listId) : base(result) { ListId = listId; }
public RequestRevenueEvent(HeleusClientResponse response, AccountRevenueInfo revenueInfo) { Response = response; RevenueInfo = revenueInfo; }
public TodoListInvitationSentEvent(HeleusClientResponse result, long listId) : base(result) { ListId = listId; }
public static async Task <HeleusClientResponse> RegisterCoreAccount(string name, string password, Key key) { HeleusClientResponse result = null; if (CurrentCoreAccount != null) { result = new HeleusClientResponse(HeleusClientResultTypes.CoreAccountAlreadyAvailable); goto end; } if (_busy) { result = new HeleusClientResponse(HeleusClientResultTypes.Busy); goto end; } _busy = true; if (!IsValidPassword(password)) { result = new HeleusClientResponse(HeleusClientResultTypes.PasswordError); goto end; } if (name.IsNullOrWhiteSpace()) { name = $"Heleus Account"; } if (!await Client.SetTargetChain(Protocol.CoreChainId)) { result = new HeleusClientResponse(HeleusClientResultTypes.EndpointConnectionError); goto end; } try { result = await Client.RegisterAccount(name, key, password); CurrentCoreAccount = Client.GetRegisteredCoreAccount(result); } catch (Exception ex) { Log.IgnoreException(ex); } end: await UIApp.PubSub.PublishAsync(new CoreAccountRegisterEvent(result, CurrentCoreAccount)); if (CurrentCoreAccount != null) { await UnlockCoreAccount(password); } if (result.ResultType != HeleusClientResultTypes.Busy) { _busy = false; } return(result); }
public SendInvitationEvent(long accountId, MessageNode node, HeleusClientResponse heleusClientResponse) : base(node, heleusClientResponse) { AccountId = accountId; }
public MessageSentEvent(string text, Chain.Index index, MessageNode node, HeleusClientResponse heleusClientResponse) : base(node, heleusClientResponse) { Text = text; Index = index; }