/// <summary>
 /// Loops through the saved wallets and checks if a wallet is already saved under the given name.
 /// </summary>
 /// <param name="text"> The current text in the input field </param>
 /// <returns> Whether the given walletName has been used before </returns>
 private bool WalletNameExists(string text)
 {
     for (int i = 1; ; i++)
     {
         if (hopeWalletInfoManager.GetWalletInfo(i).WalletName.EqualsIgnoreCase(text))
         {
             return(true);
         }
         else if (string.IsNullOrEmpty(hopeWalletInfoManager.GetWalletInfo(i).WalletName))
         {
             return(false);
         }
     }
 }
Example #2
0
    public void Construct(
        PlayerPrefPasswordDerivation playerPrefPasswordDerivation,
        UserWalletManager userWalletManager,
        HopeWalletInfoManager hopeWalletInfoManager,
        WalletPasswordVerification walletPasswordVerification,
        ContactsManager contactsManager,
        DynamicDataCache dynamicDataCache,
        ButtonClickObserver buttonClickObserver,
        CurrencyManager currencyManager,
        LogoutHandler logoutHandler)
    {
        this.playerPrefPasswordDerivation = playerPrefPasswordDerivation;
        this.userWalletManager            = userWalletManager;
        this.hopeWalletInfoManager        = hopeWalletInfoManager;
        this.walletPasswordVerification   = walletPasswordVerification;
        this.contactsManager     = contactsManager;
        this.dynamicDataCache    = dynamicDataCache;
        this.buttonClickObserver = buttonClickObserver;
        this.currencyManager     = currencyManager;
        this.logoutHandler       = logoutHandler;

        buttonClickObserver.SubscribeObservable(this);
        defaultCurrencyOptions.ButtonClicked((int)currencyManager.ActiveCurrency);

        walletName = hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress()).WalletName;

        deleteWalletButton.onClick.AddListener(() => popupManager.GetPopup <GeneralOkCancelPopup>(true)
                                               .SetSubText($"Are you sure you want to delete wallet '{walletName}'?\nThis cannot be undone!")
                                               .OnOkClicked(() => DeleteWallet(userWalletManager, hopeWalletInfoManager, logoutHandler))
                                               .DisableEnterButton());
    }
        public WalletNameSection(
            HopeWalletInfoManager hopeWalletInfoManager,
            WalletPasswordVerification walletPasswordVerification,
            ContactsManager contactsManager,
            DynamicDataCache dynamicDataCache,
            UserWalletManager userWalletManager,
            SettingsPopupAnimator settingsPopupAnimator,
            GameObject currentPasswordSection,
            GameObject walletNameSection,
            GameObject loadingIcon,
            HopeInputField currentPasswordField,
            HopeInputField currentWalletNameField,
            HopeInputField newWalletNameField,
            Button nextButton,
            Button saveButton,
            GameObject[] hopeOnlyCategoryButtons)
        {
            this.hopeWalletInfoManager      = hopeWalletInfoManager;
            this.walletPasswordVerification = walletPasswordVerification;
            this.contactsManager            = contactsManager;
            this.dynamicDataCache           = dynamicDataCache;
            this.settingsPopupAnimator      = settingsPopupAnimator;
            this.currentPasswordSection     = currentPasswordSection;
            this.walletNameSection          = walletNameSection;
            this.loadingIcon             = loadingIcon;
            this.currentPasswordField    = currentPasswordField;
            this.currentWalletNameField  = currentWalletNameField;
            this.newWalletNameField      = newWalletNameField;
            this.nextButton              = nextButton;
            this.saveButton              = saveButton;
            this.hopeOnlyCategoryButtons = hopeOnlyCategoryButtons;

            walletInfo = hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress());
            SetListeners();
        }
    /// <summary>
    /// Verifies a password.
    /// </summary>
    /// <param name="password"> The password to verify. </param>
    /// <returns> The current instance of WalletPasswordVerification. </returns>
    public WalletPasswordVerification VerifyPassword(byte[] password)
    {
        var saltedHash = hopeWalletInfoManager.GetWalletInfo((int)dynamicDataCache.GetData("walletnum")).EncryptedWalletData.PasswordHash;
        var pbkdf2     = new PBKDF2PasswordHashing(new Blake2b_512_Engine());

        VerifyingPassword = true;

        onPasswordCorrect   = null;
        onPasswordIncorrect = null;

        Observable.WhenAll(Observable.Start(() => password == null || password.Length == 0 ? false : pbkdf2.VerifyPassword(password, saltedHash)))
        .ObserveOnMainThread()
        .Subscribe(correctPass =>
        {
            VerifyingPassword = false;
            if (!correctPass[0])
            {
                PasswordIncorrect();
            }
            else
            {
                PasswordCorrect(password);
            }
        });

        return(this);
    }
        public PasswordSection(
            PlayerPrefPasswordDerivation playerPrefPasswordDerivation,
            UserWalletManager userWalletManager,
            HopeWalletInfoManager hopeWalletInfoManager,
            DynamicDataCache dynamicDataCache,
            SettingsPopupAnimator settingsPopupAnimator,
            HopeInputField newPasswordField,
            HopeInputField confirmPasswordField,
            Button saveButton,
            GameObject loadingIcon)
        {
            this.playerPrefPasswordDerivation = playerPrefPasswordDerivation;
            this.hopeWalletInfoManager        = hopeWalletInfoManager;
            this.dynamicDataCache             = dynamicDataCache;
            this.settingsPopupAnimator        = settingsPopupAnimator;
            this.newPasswordField             = newPasswordField;
            this.confirmPasswordField         = confirmPasswordField;
            this.saveButton  = saveButton;
            this.loadingIcon = loadingIcon;

            walletEncryptor = new WalletEncryptor(playerPrefPasswordDerivation, dynamicDataCache);
            walletDecryptor = new WalletDecryptor(playerPrefPasswordDerivation, dynamicDataCache);
            walletInfo      = hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress());

            newPasswordField.OnInputUpdated     += _ => PasswordsUpdated();
            confirmPasswordField.OnInputUpdated += _ => PasswordsUpdated();
            saveButton.onClick.AddListener(SavePasswordButtonClicked);
        }
Example #6
0
    private void DeleteWallet(UserWalletManager userWalletManager, HopeWalletInfoManager hopeWalletInfoManager, LogoutHandler logoutHandler)
    {
        var wallets        = hopeWalletInfoManager.Wallets;
        var walletToDelete = hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress());

        for (int i = wallets.IndexOf(walletToDelete) + 1; i < wallets.Count; i++)
        {
            hopeWalletInfoManager.UpdateWalletInfo(wallets[i].WalletNum, new WalletInfo(wallets[i].EncryptedWalletData, wallets[i].WalletName, wallets[i].WalletAddresses, wallets[i].WalletNum - 1));
        }

        hopeWalletInfoManager.DeleteWalletInfo(walletToDelete);
        logoutHandler.Logout();
    }
    public void SignTransaction(string walletAddress, string path, byte[] encryptedPasswordBytes, Action <TransactionSignedUnityRequest> onRequestReceived)
    {
        var plainTextBytes = passwordEncryptor.Decrypt(encryptedPasswordBytes);

        walletDecryptor.DecryptWallet(hopeWalletInfoManager.GetWalletInfo(walletAddress), plainTextBytes, seed =>
        {
            TransactionSignedUnityRequest request = new TransactionSignedUnityRequest(
                new Wallet(seed, path).GetAccount(walletAddress),
                ethereumNetworkManager.CurrentNetwork.NetworkUrl);

            MainThreadExecutor.QueueAction(() => onRequestReceived?.Invoke(request));
            ClearData(seed, plainTextBytes);
        });
    }
Example #8
0
    public void Construct(
        HopeWalletInfoManager hopeWalletInfoManager,
        UserWalletManager userWalletManager,
        WalletPasswordVerification walletPasswordVerification,
        LogoutHandler logoutHandler,
        DynamicDataCache dynamicDataCache,
        ButtonClickObserver buttonClickObserver)
    {
        this.walletPasswordVerification = walletPasswordVerification;
        this.logoutHandler       = logoutHandler;
        this.dynamicDataCache    = dynamicDataCache;
        this.buttonClickObserver = buttonClickObserver;

        walletName     = hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress()).WalletName;
        formTitle.text = walletName;

        SetMessageText();

        (dynamicDataCache.GetData("pass") as ProtectedString)?.SetValue(RandomBytes.Secure.SHA3.GetBytes(16));
    }
    /// <summary>
    /// Adds contact under the newly created wallet name and address
    /// </summary>
    /// <param name="userWalletManager"> The active UserWalletManager </param>
    /// <param name="userWalletInfoManager"> The active UserWalletInfoManager </param>
    /// <param name="settings"> The settings for the ContactsManager. </param>
    /// <param name="networkSettings"> The settings for the EthereumNetworkManager. </param>
    public ContactsManager(
        UserWalletManager userWalletManager,
        HopeWalletInfoManager userWalletInfoManager,
        EthereumNetworkManager.Settings networkSettings)
    {
        UserWalletManager.OnWalletLoadSuccessful += () =>
        {
            ContactList = new SecurePlayerPrefList <ContactInfo>(PlayerPrefConstants.CONTACT_LIST, (int)networkSettings.networkType);

            var walletAddress = userWalletManager.GetWalletAddress();

            if (!ContactList.Contains(walletAddress.ToLower()))
            {
                var info = userWalletInfoManager.GetWalletInfo(walletAddress);

                if (!string.IsNullOrEmpty(info?.WalletName))
                {
                    AddContact(walletAddress.ToLower(), info.WalletName);
                }
            }
        };
    }
    public void Construct(
        TradableAssetManager tradableAssetManager,
        TradableAssetImageManager tradableAssetImageManager,
        ContactsManager contactsManager,
        UserWalletManager userWalletManager,
        HopeWalletInfoManager userWalletInfoManager,
        Hodler hodler)
    {
        this.tradableAssetManager      = tradableAssetManager;
        this.tradableAssetImageManager = tradableAssetImageManager;
        this.contactsManager           = contactsManager;
        this.hodler = hodler;

        walletAddress = userWalletManager.GetWalletAddress();
        walletName    = userWalletManager.ActiveWalletType == UserWalletManager.WalletType.Hope ? userWalletInfoManager.GetWalletInfo(walletAddress).WalletName : userWalletManager.ActiveWalletType.ToString();
    }
Example #11
0
 /// <summary>
 /// Updates the wallet name text.
 /// </summary>
 private void UpdateWalletName()
 {
     walletNameText.text = userWalletManager.ActiveWalletType == UserWalletManager.WalletType.Hope
         ? hopeWalletInfoManager.GetWalletInfo(userWalletManager.GetWalletAddress()).WalletName
         : userWalletManager.ActiveWalletType.ToString();
 }