Exemplo n.º 1
0
        public async Task <string> GetSeedWords(string password)
        {
            var iKey = await GetIntermediateKey(password);

            var encSeedWords = await _hsm.GetAsync(EncSeedWordsLoc);

            var seedWords = AesThenHmac.Decrypt(encSeedWords, iKey);

            return(seedWords);
        }
Exemplo n.º 2
0
        public async Task <bool> HasGotSeedWords()
        {
            var seedWords = await HSM.GetAsync($"{Global.Network}-seedWords");

            if (seedWords is null)
            {
                return(false);
            }

            SeedWords = seedWords.Split(' ').ToList();
            return(true);
        }
Exemplo n.º 3
0
        public async Task InitSeedWords(string password)
        {
            string     wordString = null;
            KeyManager keyManager = null;

            try
            {
                // ensure correct pw
                PasswordHelper.Guard(password);
                string walletFilePath = Path.Combine(_walletManager.WalletDirectories.WalletsDir, $"{_config.Network}.json");
                await Task.Run(() =>
                {
                    keyManager = KeyManager.FromFile(walletFilePath);
                    keyManager.GetMasterExtKey(password ?? "");
                });

                await Task.Run(async() =>
                {
                    // this next line doesn't really run async :/
                    wordString = await _storage.GetSeedWords(password);
                    if (wordString is null)
                    {
                        throw new KeyNotFoundException();
                    }
                });
            }
            catch (SecurityException e)
            {
                // toss bad password to UI
                throw e;
            }
            // KeyNotFoundException || ArgumentException
            catch
            {
                // try migrate from the legacy system
                var seedWords = await _hsm.GetAsync(LegacyWordsLoc);

                if (string.IsNullOrEmpty(seedWords))
                {
                    // check if corrupted and show message
                    throw new InvalidOperationException("Try again if you cancelled the biometric authentication. Otherwise, there are no seed words saved. Please back up using \"Export Wallet File\"");
                }

                // check if words match the wallet file
                KeyManager legacyKM = null;
                await Task.Run(() =>
                {
                    KeyPath.TryParse(ACCOUNT_KEY_PATH, out KeyPath keyPath);

                    var mnemonic = new Mnemonic(seedWords);
                    legacyKM     = KeyManager.Recover(mnemonic, password, filePath: null, keyPath, MIN_GAP_LIMIT);
                });

                if (legacyKM.EncryptedSecret != keyManager.EncryptedSecret)
                {
                    throw new InvalidOperationException("Corrupt seed words. Please back up using \"Export Wallet File\" instead.");
                }

                await _storage.SetSeedWords(password, seedWords);

                wordString = seedWords;
            }
            finally
            {
                SeedWords = wordString?.Split(' ').ToList();
            }
        }