MessageSubmitAccount GenerateSubmitAccount(Chain.Index index) { (var friendAccountId, var friendKeyIndex, var accountId, var keyIndex) = GetFriendAccountId(index); if (accountId != AccountId) { return(null); } var submitAccount = ServiceNode.GetSubmitAccount <MessageSubmitAccount>(keyIndex, index); if (submitAccount != null) { return(submitAccount); } foreach (var account in ServiceNode.ServiceAccounts.Values) { if (!account.IsDecrypted) { continue; } if (account.AccountId == accountId && account.KeyIndex == keyIndex) { submitAccount = new MessageSubmitAccount(account, this, friendAccountId, friendKeyIndex, keyIndex, index, true); ServiceNode.AddSubmitAccount(submitAccount); return(submitAccount); } } return(null); }
public bool GenerateSubmitAccounts(long friendAccountId, short friendKeyIndex) { foreach (var account in ServiceNode.ServiceAccounts.Values) { if (!account.IsDecrypted) { continue; } var index = MessageServiceInfo.GetConversationIndex(account.AccountId, account.KeyIndex, friendAccountId, friendKeyIndex); var submitAccount = ServiceNode.GetSubmitAccount <MessageSubmitAccount>(account.KeyIndex, index); if (submitAccount == null) { submitAccount = new MessageSubmitAccount(account, this, friendAccountId, friendKeyIndex, account.KeyIndex, index, true); ServiceNode.AddSubmitAccount(submitAccount); } } return(true); }
async Task <bool> GenerateSecretExchangeKey(MessageSubmitAccount submitAccount, long friendAccountId, short friendKeyIndex) { if (submitAccount == null) { return(false); } //await GenerateSubmitAccounts(friendAccountId, friendKeyIndex, false); var index = MessageServiceInfo.GetConversationIndex(submitAccount.AccountId, submitAccount.KeyIndex, friendAccountId, friendKeyIndex); var keyManager = submitAccount.SecretKeyManager; if (!keyManager.HasSecretKeyType(index, SecretKeyInfoTypes.KeyExchange)) { var friend = GetFriend(friendAccountId); if (friend != null) { var key = await friend.GetSignedPublicKey(friendKeyIndex); if (key != null) { var exchangeKey = Key.KeyExchange(KeyTypes.Ed25519, submitAccount.Account.DecryptedKey, key.PublicKey); var secretKey = await KeyExchageSecretKeyInfo.NewKeyExchangeSecetKey(submitAccount.AccountId, submitAccount.KeyIndex, friendAccountId, friendKeyIndex, submitAccount.ChainId, exchangeKey); keyManager.AddSecretKey(index, secretKey); return(true); } } return(false); } return(true); }