/// <summary>
    /// Generates the mnemonic phrase.
    /// </summary>
    private void GenerateMnemonic()
    {
        Wallet wallet = new Wallet(Wordlist.English, WordCount.Twelve);

        dynamicDataCache.SetData("seed", wallet.Seed);
        dynamicDataCache.SetData("mnemonic", wallet.Phrase);
    }
    /// <summary>
    /// Sets up the wallet name and password and opens the next menu.
    /// </summary>
    private void CreateWalletNameAndPass()
    {
        dynamicDataCache.SetData("pass", new ProtectedString(password1Field.InputFieldBytes));
        dynamicDataCache.SetData("name", walletNameField.Text);

        uiManager.OpenMenu <ImportOrCreateMnemonicMenu>();
    }
    /// <summary>
    /// Encrypts the wallet data asynchronously.
    /// </summary>
    /// <param name="seed"> The <see langword="byte"/>[] seed to encrypt. </param>
    /// <param name="password"> The base password to use for encryption, retrieved from the user input. </param>
    /// <param name="onWalletEncrypted"> Action called once the wallet has been encrypted. </param>
    private void AsyncEncryptWallet(
        byte[] seed,
        byte[] password,
        Action <string[], string, string> onWalletEncrypted)
    {
        string[] encryptedHashes    = null;
        string   saltedPasswordHash = null;
        string   encryptedSeed      = null;

        byte[] derivedPassword = playerPrefPassword.Derive(password);

        using (var dataEncryptor = new DataEncryptor(new AdvancedSecureRandom(new Blake2bDigest(512), derivedPassword)))
        {
            byte[] hash1 = RandomBytes.Secure.Blake2.GetBytes(512);
            byte[] hash2 = RandomBytes.Secure.Blake2.GetBytes(1024);

            saltedPasswordHash = new PBKDF2PasswordHashing(new Blake2b_512_Engine()).GetSaltedPasswordHash(password).GetBase64String();
            encryptedSeed      = dataEncryptor.Encrypt(dataEncryptor.Encrypt(seed.GetHexString(), hash1), hash2);

            encryptedHashes = new string[]
            {
                dataEncryptor.Encrypt(hash1).GetBase64String(),
                dataEncryptor.Encrypt(hash2).GetBase64String()
            };

            hash1.ClearBytes();
            hash2.ClearBytes();
        }

        dynamicDataCache.SetData("pass", new ProtectedString(password, this));
        dynamicDataCache.SetData("mnemonic", null);

        MainThreadExecutor.QueueAction(() => onWalletEncrypted?.Invoke(encryptedHashes, saltedPasswordHash, encryptedSeed));
    }
    /// <summary>
    /// Gets the numbers of the words that need to be confirmed.
    /// </summary>
    private void GetConfirmationNumbers()
    {
        int[] numbers;

        do
        {
            numbers = new int[4] {
                Random.Range(1, 13), Random.Range(1, 13), Random.Range(1, 13), Random.Range(1, 13)
            };
        } while (numbers.Distinct().Count() < 4);

        dynamicDataCache.SetData("confirmation numbers", numbers);
    }
    /// <summary>
    /// Starts the asset transfer.
    /// </summary>
    public override void OkButton()
    {
        dynamicDataCache.SetData("txfee", Gas.TransactionFee.ToString());

        Asset.ActiveAsset.Transfer(
            userWalletManager,
            new HexBigInteger(Gas.TransactionGasLimit),
            Gas.TransactionGasPrice.FunctionalGasPrice,
            Address.SendAddress,
            Amount.SendableAmount);
    }
Example #6
0
    /// <summary>
    /// Called when the correct password is entered.
    /// </summary>
    /// <param name="password"> The correct password. </param>
    private void CorrectPassword(byte[] password)
    {
        if (dynamicDataCache.GetData("pass") != null && dynamicDataCache.GetData("pass") is ProtectedString)
        {
            ((ProtectedString)dynamicDataCache.GetData("pass")).SetValue(password);
        }
        else
        {
            dynamicDataCache.SetData("pass", new ProtectedString(password));
        }

        SecurePlayerPrefs.SetInt(WalletName + PlayerPrefConstants.SETTING_CURRENT_LOGIN_ATTEMPT, 1);

        userWalletManager.UnlockWallet();
    }
Example #7
0
    /// <summary>
    /// Sets the wallet num in the data cache and opens the <see cref="UnlockWalletPopup"/>.
    /// </summary>
    private void WalletButtonClicked()
    {
        Button.interactable = false;
        walletNameText.gameObject.AnimateColor(PURE_WHITE, 0.15f);

        dynamicDataCache.SetData("walletnum", ButtonInfo.WalletNum);

        var popup = popupManager.GetPopup <UnlockWalletPopup>();

        popup.SetWalletInfo(fullWalletName);
        popup.OnPopupClose(() =>
        {
            Button.interactable = true;
            walletNameText.gameObject.AnimateColor(UIColors.White, 0.15f);
        });
    }
Example #8
0
 /// <summary>
 /// Sets the wallet info to the dynamic data cache.
 /// </summary>
 /// <param name="wallet"> The wallet we are importing. </param>
 private void SetWalletInfo(Wallet wallet)
 {
     dynamicDataCache.SetData("seed", wallet.Seed);
     dynamicDataCache.SetData("mnemonic", null);
 }