Example #1
0
        public bool UnlockAccount(Address address, SecureString passphrase, TimeSpan?timeSpan)
        {
            if (address is null || address == Address.Zero)
            {
                return(false);
            }

            if (!_passwords.ContainsKey(address))
            {
                if (_logger.IsError)
                {
                    _logger.Error("Account does not exist.");
                }
                return(false);
            }

            if (!CheckPassword(address, passphrase))
            {
                if (_logger.IsError)
                {
                    _logger.Error("Password is invalid.");
                }
                return(false);
            }

            AccountUnlocked?.Invoke(this, new AccountUnlockedEventArgs(address));
            _isUnlocked[address] = true;

            return(true);
        }
Example #2
0
        public bool UnlockAccount(Address address, SecureString passphrase, TimeSpan?timeSpan)
        {
            if (address == Address.Zero)
            {
                return(false);
            }
            else if (IsUnlocked(address))
            {
                return(true);
            }
            else
            {
                (PrivateKey key, Result result) = _keyStore.GetKey(address, passphrase);
                if (result.ResultType == ResultType.Success)
                {
                    if (_logger.IsInfo)
                    {
                        _logger.Info($"Unlocking account: {address}");
                    }
                    _unlockedAccounts.Add(key.Address.ToString(), _protectedPrivateKeyFactory.Create(key),
                                          new CacheItemPolicy()
                    {
                        Priority = CacheItemPriority.NotRemovable, AbsoluteExpiration = _timestamper.UtcNowOffset + (timeSpan ?? DefaultExpirationTime)
                    });
                    AccountUnlocked?.Invoke(this, new AccountUnlockedEventArgs(address));
                    return(true);
                }

                if (_logger.IsError)
                {
                    _logger.Error($"Failed to unlock the account: {address}");
                }
                return(false);
            }
        }
Example #3
0
        public bool UnlockAccount(Address address, SecureString passphrase, TimeSpan?timeSpan)
        {
            if (address == Address.Zero)
            {
                return(false);
            }

            if (_unlockedAccounts.ContainsKey(address))
            {
                return(true);
            }

            (PrivateKey key, Result result) = _keyStore.GetKey(address, passphrase);
            if (result.ResultType == ResultType.Success)
            {
                if (_logger.IsInfo)
                {
                    _logger.Info($"Unlocking account: {address}");
                }
                _unlockedAccounts.Add(key.Address, key);
                AccountUnlocked?.Invoke(this, new AccountUnlockedEventArgs(address));
                return(true);
            }

            if (_logger.IsError)
            {
                _logger.Error($"Failed to unlock the account: {address}");
            }
            return(false);
        }
Example #4
0
        public bool UnlockAccount(Address address, SecureString passphrase, TimeSpan?timeSpan)
        {
            if (address == Address.Zero)
            {
                return(false);
            }
            else if (IsUnlocked(address))
            {
                return(true);
            }
            else
            {
                (PrivateKey key, Result result) = _keyStore.GetKey(address, passphrase);
                if (result.ResultType == ResultType.Success)
                {
                    if (_logger.IsInfo)
                    {
                        _logger.Info($"Unlocking account: {address}");
                    }
                    _unlockedAccounts.Set(key.Address.ToString(), _protectedPrivateKeyFactory.Create(key));
                    AccountUnlocked?.Invoke(this, new AccountUnlockedEventArgs(address));
                    return(true);
                }

                if (_logger.IsError)
                {
                    _logger.Error($"Failed to unlock the account: {address}");
                }
                return(false);
            }
        }
Example #5
0
 public bool UnlockAccount(Address address, SecureString passphrase, TimeSpan timeSpan)
 {
     AccountUnlocked?.Invoke(this, new AccountUnlockedEventArgs(address));
     return(true);
 }
Example #6
0
 public bool UnlockAccount(Address address, SecureString passphrase, TimeSpan timeSpan)
 {
     AccountUnlocked?.Invoke(this, new AccountUnlockedEventArgs(address));
     throw new NotSupportedException();
 }
Example #7
0
 public async Task HandleAsync(AccountUnlocked @event)
 => await CompleteAsync(@event, @event.UserId);