/// <summary> /// /// </summary> /// <param name="addressOrName"></param> /// <param name="password"></param> /// <returns></returns> public async Task <Profile> RequestProfile(string addressOrName, string password) { ErrorCallbackProvider.ReportInfo("Requesting user account."); KeyStoreUtils.ProfileDesc accountDesc = await KeyStoreUtils.RequestProfile(UserInputProvider, addressOrName, ProfilesDir, password); if (accountDesc != null) { return(new KeyStoreProfile(accountDesc.Name, new HoardID(accountDesc.Address), accountDesc.PrivKey)); } return(null); }
/// <summary> /// Creates new profile with given name /// </summary> /// <param name="name">name of profile </param> /// <returns>new account</returns> public async Task <Profile> CreateProfile(string name) { ErrorCallbackProvider.ReportInfo("Generating user account."); string password = await UserInputProvider.RequestInput(name, null, eUserInputType.kPassword, "new password"); Tuple <string, byte[]> accountTuple = KeyStoreUtils.CreateProfile(name, password, ProfilesDir); Profile profile = new KeyStoreProfile(name, new HoardID(accountTuple.Item1), accountTuple.Item2); accountTuple.Item2.Initialize(); return(profile); }
/// <summary> /// Enumerates existing profiles /// </summary> /// <returns>list of found profiles</returns> public async Task <KeyStoreUtils.ProfileDesc[]> EnumerateProfiles() { List <KeyStoreUtils.ProfileDesc> profiles = new List <KeyStoreUtils.ProfileDesc>(); await KeyStoreUtils.EnumerateProfiles(ProfilesDir, async (fileName) => { StreamReader jsonReader = new StreamReader(Path.Combine(ProfilesDir, fileName)); JObject jobj = JObject.Parse(await jsonReader.ReadToEndAsync()); jsonReader.Close(); if (jobj.TryGetValue("address", out JToken valueAddress) && jobj.TryGetValue("name", out JToken valueName)) { profiles.Add(new KeyStoreUtils.ProfileDesc(valueName.Value <string>(), valueAddress.Value <string>(), null)); } }); return(profiles.ToArray()); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="oldPassword"></param> /// <param name="newPassword"></param> /// <returns></returns> public Task <string> ChangePassword(HoardID id, string oldPassword, string newPassword) { return(Task.FromResult <string>(KeyStoreUtils.ChangePassword(id, oldPassword, newPassword, ProfilesDir))); }
/// <summary> /// Deletes profile /// </summary> /// <param name="id"></param> /// <param name="passwordNeeded"></param> /// <returns></returns> public async Task DeleteProfile(HoardID id, bool passwordNeeded = false) { await KeyStoreUtils.DeleteProfile(UserInputProvider, id, ProfilesDir, passwordNeeded); }