/// <summary>
    /// Checks if the hardware wallet is connected and invokes any required events.
    /// </summary>
    public async void PeriodicUpdate()
    {
        if (isPolling || initializing)
        {
            return;
        }

        isPolling = true;

        bool isConnected = await IsHardwareWalletConnected().ConfigureAwait(false);

        if (!isConnected)
        {
            if (wasConnected)
            {
                MainThreadExecutor.QueueAction(() => OnHardwareWalletDisconnected?.Invoke());
            }
        }
        else
        {
            if (!wasConnected)
            {
                MainThreadExecutor.QueueAction(() => OnHardwareWalletConnected?.Invoke());
            }
        }

        wasConnected = isConnected;
        isPolling    = false;
    }
Ejemplo n.º 2
0
    /// <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));
    }
Ejemplo n.º 3
0
        public static void Create(bool dontDestroy = true, bool useFixedUpdate = false)
        {
            lock (syncLock)
            {
                try
                {
                    if (executor != null)
                    {
                        return;
                    }
#if NETFX_CORE || !NET_LEGACY
                    mainThreadId = Environment.CurrentManagedThreadId;
#else
                    Thread currentThread = Thread.CurrentThread;
                    if (currentThread.ManagedThreadId > 1 || currentThread.IsThreadPoolThread)
                    {
                        throw new Exception("Initialize the class on the main thread, please!");
                    }

                    mainThread = currentThread;
#endif
                    executor = CreateMainThreadExecutor(dontDestroy, useFixedUpdate);
                }
                catch (Exception e)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat("Start Executors failure.Exception:{0}", e);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void GenerateCapture(Action <byte[]> result)
        {
            Debug.Log("GenerateCapture");

            _recorder.CurrentState = Recorder.RecordingState.OnHold;
            if (StoreWorker.Instance.StoredFrames.Count() > 0)
            {
                var generator = new GeneratorWorker(loopPlayback, playbackFrameRate, ThreadPriority.BelowNormal, StoreWorker.Instance.StoredFrames,
                                                    _resultFilePath,
                                                    () =>
                {
                    Debug.Log("Result: " + _resultFilePath);

                    MainThreadExecutor.Queue(() => {
                        result(File.ReadAllBytes(_resultFilePath));
                    });
                });
                generator.Start();
            }
            else
            {
                Debug.Log("Something went wrong, check your settings");
                result(new byte[0]);
            }
        }
Ejemplo n.º 5
0
        void onPrivateRoomMessage(AndroidJavaObject chatRoom, AndroidJavaObject messageAJO)
        {
            var privateChatRoom = new PrivateChatRoomAndroidImpl(chatRoom);
            var message         = AndroidChatUtils.ChatMessageFromJavaObject(messageAJO);

            MainThreadExecutor.Queue(() => onPrivateRoomMessageAction(privateChatRoom, message));
        }
    /// <summary>
    /// Generates a spoof key asynchronously.
    /// </summary>
    /// <returns> The task used for generating the spoof key. </returns>
    private async Task GenerateSpoofKey()
    {
        string key = await Task.Run(() => RandomString.Secure.SHA3.GetString(PASSWORD_LENGTH)).ConfigureAwait(false);

        string value = await Task.Run(() => RandomString.Secure.SHA3.GetString()).ConfigureAwait(false);

        MainThreadExecutor.QueueAction(() => SecurePlayerPrefsAsync.SetString(key, value));
    }
Ejemplo n.º 7
0
 /// <summary>
 /// Downloads a string from a url.
 /// </summary>
 /// <param name="url"> The url which contains the string data. </param>
 /// <param name="onStringReceived"> Action to call once the string has been received. </param>
 public static void DownloadString(string url, Action<string> onStringReceived)
 {
     Task.Factory.StartNew(async () =>
     {
         string downloadedString = await DownloadString(url).ConfigureAwait(false);
         MainThreadExecutor.QueueAction(() => onStringReceived?.Invoke(downloadedString));
     });
 }
 void onUnreadConversationsCountChanged(int unreadConversationsCount)
 {
     if(onUnreadConversationsCountChangeAction != null)
     {
         MainThreadExecutor.Queue(
             () => onUnreadConversationsCountChangeAction(unreadConversationsCount)
         );
     }
 }
Ejemplo n.º 9
0
        void onPrivateRoomTypingStatus(AndroidJavaObject chatRoom,
                                       AndroidJavaObject userAJO,
                                       AndroidJavaObject typingStatusAJO)
        {
            var privateChatRoom = new PrivateChatRoomAndroidImpl(chatRoom);
            var user            = AndroidUtils.UserFromJavaObj(userAJO);
            var typingStatus    = AndroidChatUtils.TypingStatusFromAJO(typingStatusAJO);

            MainThreadExecutor.Queue(() => onPrivateRoomTypingStatusAction(privateChatRoom, user, typingStatus));
        }
Ejemplo n.º 10
0
    // Start is called before the first frame update
    void Start()
    {
        MainThreadExecutor.Initialize();

        Task.Run(() => {
            MainThreadExecutor.Instance.Post(() => {
                Debug.Log("Task Completed!!!!");
            });
        });
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Called when the pin needs to be entered.
    /// Invokes the ReloadPINSection event.
    /// </summary>
    public void ReEnterPIN()
    {
        if (!checkingPin)
        {
            return;
        }

        MainThreadExecutor.QueueAction(() => ReloadPINSection?.Invoke());

        checkingPin = false;
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Decrypts the wallet given the user's password.
    /// </summary>
    /// <param name="walletInfo"> The wallet to decrypt. </param>
    /// <param name="password"> The user's password to the wallet. </param>
    /// <param name="onWalletDecrypted"> Action called once the wallet has been decrypted, passing the <see langword="byte"/>[] seed of the wallet. </param>
    public void DecryptWallet(WalletInfo walletInfo, byte[] password, Action <byte[]> onWalletDecrypted)
    {
        MainThreadExecutor.QueueAction(() =>
        {
            playerPrefPassword.PopulatePrefDictionary(walletInfo.WalletAddresses[0][0]);

            Task.Factory.StartNew(() => AsyncDecryptWallet(
                                      walletInfo.EncryptedWalletData.EncryptionHashes,
                                      walletInfo.EncryptedWalletData.EncryptedSeed,
                                      password,
                                      onWalletDecrypted));
        });
    }
Ejemplo n.º 13
0
    /// <summary>
    /// Calls events based on the current status of the pin section.
    /// </summary>
    public void UpdatePINSection()
    {
        if (!pinSectionOpen)
        {
            pinSectionOpen = true;

            MainThreadExecutor.QueueAction(() => TrezorPINSectionOpening?.Invoke());
        }
        else
        {
            MainThreadExecutor.QueueAction(() => ReloadPINSection?.Invoke());
        }
    }
Ejemplo n.º 14
0
    /// <summary>
    /// Sets a string value to the <see cref="SecurePlayerPrefs"/> asynchronously.
    /// Gets the secure key, secure entropy, and encrypted value all asynchronously.
    /// </summary>
    /// <param name="baseKeyEncrypted"> The encrypted base key to use to get the secure key of this SecurePlayerPref. </param>
    /// <param name="key"> The key to use to set the PlayerPref. </param>
    /// <param name="value"> The value to use for the PlayerPref. </param>
    /// <param name="onValueSet"> Action called once the PlayerPref has been set successfully. </param>
    /// <returns> The task for creating the hashed key/values and setting the PlayerPref. </returns>
    private static async Task InternalSetString(string baseKeyEncrypted, string key, string value, Action onValueSet)
    {
        string secureKey = await GetSecureKey(baseKeyEncrypted, key).ConfigureAwait(false);

        string secureEntropy = await Task.Run(() => GetValueHash(secureKey)).ConfigureAwait(false);

        string encryptedValue = await Task.Run(() => dataEncryptor.Encrypt(value, secureEntropy)).ConfigureAwait(false);

        MainThreadExecutor.QueueAction(() =>
        {
            PlayerPrefs.SetString(secureKey, encryptedValue);
            onValueSet?.Invoke();
        });
    }
    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);
        });
    }
Ejemplo n.º 16
0
        private static MainThreadExecutor CreateMainThreadExecutor(bool dontDestroy, bool useFixedUpdate)
        {
            GameObject         go       = new GameObject("MainThreadExecutor");
            MainThreadExecutor executor = go.AddComponent <MainThreadExecutor>();

            go.hideFlags = HideFlags.HideAndDontSave;
            if (dontDestroy)
            {
                Object.DontDestroyOnLoad(go);
            }

            executor.useFixedUpdate = useFixedUpdate;
            return(executor);
        }
Ejemplo n.º 17
0
 private void ShowChat()
 {
     MainThreadExecutor.Queue(() => {
         //todo
         // ShowMenuSection<SocialGraphSection> ();
         // _menuSections.ForEach (section => {
         //     if (section is SocialGraphSection) {
         //         ((SocialGraphSection) section).MessageFriend (_latestChatId);
         //         _latestChatId = null;
         //     }
         // });
         // if (_console.IsVisible) {
         //     _console.Toggle ();
         // }
     });
 }
Ejemplo n.º 18
0
        //[ReflectionProtect(typeof(DisposableData<string>))]
        public DisposableDataPromise <TType> CreateDisposableData()
        {
            DisposableDataPromise <TType> promise = new DisposableDataPromise <TType>();

            byte[] data = memoryEncryptor.Decrypt(protectedData);

            AsyncTaskScheduler.Schedule(() => Task.Run(() =>
            {
                SetValue((byte[])data.Clone());

                GC.Collect();

                disposableData = disposableData?.Disposed != false ? (TDisposable)Activator.CreateInstance(typeof(TDisposable), data) : disposableData;
                MainThreadExecutor.QueueAction(() => promise.Build(() => disposableData));
            }));

            return(promise);
        }
Ejemplo n.º 19
0
 public static void Create(bool dontDestroy = true, bool useFixedUpdate = true)
 {
     lock (syncLock)
     {
         try
         {
             if (executor != null)
             {
                 return;
             }
             mainThreadId = Environment.CurrentManagedThreadId;
             executor     = CreateMainThreadExecutor(dontDestroy, useFixedUpdate);
         }
         catch (Exception e)
         {
             Log.Error($"Start Executors failure.Exception:{e}");
         }
     }
 }
Ejemplo n.º 20
0
    /// <summary>
    /// Queries the transaction data for a TradableAsset.
    /// </summary>
    /// <param name="query1"> The first query for the TradableAsset's transaction data. </param>
    /// <param name="query2"> The second query for the TradableAsset's transaction data. </param>
    private void QueryTransactionData(AssetTransactionQuery query1, AssetTransactionQuery query2)
    {
        query1.Query?.Invoke().OnSuccess(txData1 =>
        {
            query2.Query?.Invoke().OnSuccess(txData2 =>
            {
                Observable.Start(() =>
                {
                    query1.ProcessTransactionList(txData1, query1.AssetAddress, query1.IgnoreReceipt);
                    query2.ProcessTransactionList(txData2, query2.AssetAddress, query2.IgnoreReceipt);
                }).SubscribeOnMainThread().Subscribe(_ =>
                {
                    addressLastUpdatedTimes.AddOrReplace(query1.AssetAddress, DateTimeUtils.GetCurrentUnixTime());

                    MainThreadExecutor.QueueAction(() => OnTransactionsAdded?.Invoke());
                    isScraping = false;
                });
            });
        });
    }
        private void OnNewWalletEncrypted(string[] hashes, string passwordHash, string encryptedSeed)
        {
            hopeWalletInfoManager.UpdateWalletInfo(
                walletInfo.WalletNum,
                new WalletInfo(
                    new WalletInfo.EncryptedDataContainer(hashes, encryptedSeed, passwordHash),
                    walletInfo.WalletName,
                    walletInfo.WalletAddresses,
                    walletInfo.WalletNum));

            playerPrefPasswordDerivation.SetupPlayerPrefs(walletInfo.WalletAddresses[0][0], () =>
            {
                MainThreadExecutor.QueueAction(() =>
                {
                    newPasswordField.Text     = string.Empty;
                    confirmPasswordField.Text = string.Empty;
                    settingsPopupAnimator.ShowLoadingIcon(saveButton.gameObject, loadingIcon, false);
                    settingsPopupAnimator.AnimateIcon(saveButton.transform.GetChild(0).gameObject);
                });
            }, false);
        }
Ejemplo n.º 22
0
    /// <summary>
    /// Gets the public key data from the Trezor wallet.
    /// </summary>
    /// <returns> Task returning the ExtendedPublicKeyDataHolder instance. </returns>
    protected override async Task <ExtendedPublicKeyDataHolder> GetExtendedPublicKeyData()
    {
        var trezorManager = TrezorConnector.GetWindowsConnectedTrezor(GetExtendedPublicKeyDataEnterPin);

        if (trezorManager == null)
        {
            return(null);
        }

        var publicKeyRequest = new GetPublicKey {
            AddressNs = KeyPath.Parse(EXTENDED_PUBLIC_KEY_PATH).Indexes, ShowDisplay = false
        };
        var publicKeyResponse = (PublicKey)null;

        while (publicKeyResponse == null)
        {
            try
            {
                publicKeyResponse = await trezorManager.SendMessageAsync <PublicKey, GetPublicKey>(publicKeyRequest).ConfigureAwait(false);
            }
            catch (FailureException <Failure> )
            {
                MainThreadExecutor.QueueAction(() => PINIncorrect?.Invoke());

                publicKeyResponse = null;
                advance           = false;
            }
        }

        if (publicKeyResponse == null)
        {
            return(null);
        }

        return(new ExtendedPublicKeyDataHolder {
            publicKeyData = publicKeyResponse.Node.PublicKey, chainCodeData = publicKeyResponse.Node.ChainCode
        });
    }
    private void OnUiAction(UiAction action, Action pendingAction)
    {
        var forbiddenForAnonymous = new List <UiAction>()
        {
            UiAction.LikeActivity, UiAction.LikeComment, UiAction.PostActivity, UiAction.PostComment
        };

        if (forbiddenForAnonymous.Contains(action) && GetSocial.User.IsAnonymous)
        {
            var message = "Action " + action + " is not allowed for anonymous.";
#if UNITY_ANDROID
            MainThreadExecutor.Queue(() => {
                DemoUtils.ShowPopup("Info", message);
            });
#else
            DemoUtils.ShowPopup("Info", message);
#endif
            _console.LogD(message);
        }
        else
        {
            pendingAction();
        }
    }
Ejemplo n.º 24
0
    /// <summary>
    /// Enter pin callback for when the Trezor is requested a transaction signature.
    /// </summary>
    /// <returns> Task returning the pin string. </returns>
    private async Task <string> GetSignedTransactionDataEnterPin()
    {
        var popup = (EnterTrezorPINPopup)null;

        MainThreadExecutor.QueueAction(() => popup = popupManager.GetPopup <EnterTrezorPINPopup>(true));

        while (popup == null)
        {
            await Task.Delay(100);
        }

        var advanceAction = new UnityAction(() => advance = true);

        popup.ReEnterPIN();
        popup.TrezorPINSection.NextButton.onClick.AddListener(advanceAction);

        while (!advance)
        {
            if (popupManager.ActivePopupType != typeof(EnterTrezorPINPopup))
            {
                forceCancel = true;
                advance     = false;

                return(string.Empty);
            }

            await Task.Delay(100);
        }

        advance = false;

        popup.CheckPIN();
        popup.TrezorPINSection.NextButton.onClick.RemoveListener(advanceAction);

        return(popup.TrezorPINSection.PinText);
    }
Ejemplo n.º 25
0
    /// <summary>
    /// Method used for initializing all the addresses for this hardware wallet.
    /// </summary>
    public async void InitializeAddresses()
    {
        addresses[0] = new string[50];
        addresses[1] = new string[50];

        var data = await GetExtendedPublicKeyData().ConfigureAwait(false);

        if (data == null || data.chainCodeData.Length != 32)
        {
            MainThreadExecutor.QueueAction(WalletLoadUnsuccessful);
            return;
        }

        var electrumLedgerXPub = new ExtPubKey(new PubKey(data.publicKeyData).Compress(), data.chainCodeData);
        var defaultXPub        = electrumLedgerXPub.Derive(0);

        for (uint i = 0; i < addresses[0].Length; i++)
        {
            addresses[0][i] = new EthECKey(defaultXPub.Derive(i).PubKey.ToBytes(), false).GetPublicAddress().ConvertToEthereumChecksumAddress();
            addresses[1][i] = new EthECKey(electrumLedgerXPub.Derive(i).PubKey.ToBytes(), false).GetPublicAddress().ConvertToEthereumChecksumAddress();
        }

        MainThreadExecutor.QueueAction(WalletLoadSuccessful);
    }
Ejemplo n.º 26
0
 /// <summary>
 /// Calls the CheckingPIN event.
 /// </summary>
 public void CheckPIN()
 {
     MainThreadExecutor.QueueAction(() => CheckingPIN?.Invoke());
 }
 public WebBrowserContext(IStreamerBase streamer, MainThreadExecutor mainThreadExecutor)
 {
     _streamer = streamer;
 }
Ejemplo n.º 28
0
 void RestartGame()
 {
     webSocket.Close();
     MainThreadExecutor.Clear();
     SceneManager.LoadScene(SceneManager.GetActiveScene().name);
 }
Ejemplo n.º 29
0
    void Start()
    {
        webSocket = new WebSocket(connectAddress);

        // コネクションを確立したときのハンドラ
        webSocket.OnOpen += (sender, eventArgs) =>
        {
            Debug.Log("WebSocket Opened");
        };

        // エラーが発生したときのハンドラ
        webSocket.OnError += (sender, eventArgs) =>
        {
            Debug.Log("WebSocket Error Message: " + eventArgs.Message);
        };

        // コネクションを閉じたときのハンドラ
        webSocket.OnClose += (sender, eventArgs) =>
        {
            Debug.Log("WebSocket Closed");
        };

        // メッセージを受信したときのハンドラ
        webSocket.OnMessage += (sender, eventArgs) =>
        {
            Debug.Log("WebSocket Message: " + eventArgs.Data);

            var header = JsonUtility.FromJson <RPC.Header>(eventArgs.Data);
            switch (header.Method)
            {
            case "ping":
            {
                var pong = JsonUtility.FromJson <RPC.Ping>(eventArgs.Data);
                Debug.Log(pong.Payload.Message);
                break;
            }

            case "login_response":
            {
                var loginResponse = JsonUtility.FromJson <RPC.LoginResponse>(eventArgs.Data);
                MainThreadExecutor.Enqueue(() => OnLoginResponse(loginResponse.Payload));
                break;
            }

            case "sync":
            {
                var syncMessage = JsonUtility.FromJson <RPC.Sync>(eventArgs.Data);
                MainThreadExecutor.Enqueue(() => OnSync(syncMessage.Payload));
                break;
            }

            case "spawn":
            {
                var spawnResponse = JsonUtility.FromJson <RPC.Spawn>(eventArgs.Data);
                MainThreadExecutor.Enqueue(() => OnSpawn(spawnResponse.Payload));
                break;
            }

            case "delete_item":
            {
                var deleteMessage = JsonUtility.FromJson <RPC.DeleteItem>(eventArgs.Data);
                MainThreadExecutor.Enqueue(() => OnDeleteItem(deleteMessage.Payload));
                break;
            }

            case "environment":
            {
                var environmentMessage = JsonUtility.FromJson <RPC.Environment>(eventArgs.Data);
                MainThreadExecutor.Enqueue(() => OnEnvironment(environmentMessage.Payload));
                break;
            }

            case "delete_player":
            {
                var deletePlayerMessage = JsonUtility.FromJson <RPC.DeletePlayer>(eventArgs.Data);
                MainThreadExecutor.Enqueue(() => OnDeletePlayer(deletePlayerMessage.Payload));
                break;
            }
            }
        };

        webSocket.Connect();

        Login();
    }
Ejemplo n.º 30
0
 public PluginContext(IStreamerBase streamer, MainThreadExecutor mainThreadExecutor) : base(streamer, mainThreadExecutor)
 {
 }