Exemplo n.º 1
0
        public async Task SetSeedWords(string password, string seedWords)
        {
            var iKey = await GetOrGenerateIntermediateKey(password);

            var encSeedWords = AesThenHmac.Encrypt(seedWords, iKey);
            await _hsm.SetAsync(EncSeedWordsLoc, encSeedWords);
        }
        public bool LoadWallet()
        {
            SeedWords = Guard.Correct(SeedWords);
            Password  = Guard.Correct(Password);            // Do not let whitespaces to the beginning and to the end.

            string walletFilePath = Path.Combine(Global.WalletManager.WalletDirectories.WalletsDir, $"{Global.Network}.json");
            bool   isLoadSuccessful;

            try
            {
                KeyPath.TryParse(ACCOUNT_KEY_PATH, out KeyPath keyPath);

                var mnemonic = new Mnemonic(SeedWords);
                var km       = KeyManager.Recover(mnemonic, Password, filePath: null, keyPath, MIN_GAP_LIMIT);
                km.SetNetwork(Global.Network);
                km.SetFilePath(walletFilePath);
                Global.WalletManager.AddWallet(km);
                Hsm.SetAsync($"{Global.Network}-seedWords", SeedWords.ToString());                 // PROMPT
                Global.UiConfig.HasSeed = true;
                Global.UiConfig.ToFile();
                isLoadSuccessful = true;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                isLoadSuccessful = false;
            }
            return(isLoadSuccessful);
        }
        public NewPasswordViewModel()
            : base(Locator.Current.GetService <IViewStackService>())
        {
            Global = Locator.Current.GetService <Global>();
            Hsm    = Locator.Current.GetService <IHsmStorage>();

            SubmitCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                PasswordHelper.Guard(Password);                 // Here we are not letting anything that will be autocorrected later. We need to generate the wallet exactly with the entered password bacause of compatibility.

                string walletFilePath = Path.Combine(Global.WalletManager.WalletDirectories.WalletsDir, $"{Global.Network}.json");
                KeyManager.CreateNew(out Mnemonic seedWords, Password, walletFilePath);

                Hsm.SetAsync($"{Global.Network}-seedWords", seedWords.ToString());                 // PROMPT
                Global.UiConfig.HasSeed = true;
                Global.UiConfig.ToFile();
                ViewStackService.PushPage(new MainViewModel()).Subscribe();
                return(Observable.Return(Unit.Default));
            });
        }