Esempio n. 1
0
 public static Task <GetSubscribersResult> GetSubscribersAsync(
     string topic,
     WalletOptions options = null)
 {
     options = options ?? new WalletOptions();
     return(RpcClient.GetSubscribers(options.RpcServerAddress, topic, options.Offset, options.Limit, options.TxPool));
 }
Esempio n. 2
0
        public static Wallet Decrypt(WalletJson wallet, WalletOptions options)
        {
            options.Iv        = wallet.Iv;
            options.MasterKey = Aes.Decrypt(wallet.MasterKey, options.PasswordKey, options.Iv.FromHexString());
            options.SeedHex   = Aes.Decrypt(wallet.SeedEncrypted, options.MasterKey, options.Iv.FromHexString());
            options.PasswordKeys.Add(wallet.Version.Value, options.PasswordKey);

            switch (wallet.Version)
            {
            case 2:

                options.Scrypt = new ScryptParams
                {
                    Salt = wallet.Scrypt.Salt,
                    N    = wallet.Scrypt.N,
                    P    = wallet.Scrypt.P,
                    R    = wallet.Scrypt.R
                };

                break;

            default:
                break;
            }

            var account = new Account(options.SeedHex);

            if (account.Address != wallet.Address)
            {
                throw new WrongPasswordException();
            }

            return(new Wallet(options));
        }
Esempio n. 3
0
        private static string ComputePasswordKey(WalletOptions options)
        {
            if (options.Version == null)
            {
                throw new System.Exception();
            }

            switch (options.Version.Value)
            {
            case 1: return(Hash.DoubleSha256(options.Password));

            case 2:
                var scrypt = ScryptUtil.Scrypt(
                    options.Password,
                    options.Scrypt.Salt.FromHexString(),
                    options.Scrypt.N,
                    options.Scrypt.R,
                    options.Scrypt.P,
                    32);

                return(scrypt.ToHexString());

            default: throw new System.Exception();
            }
        }
Esempio n. 4
0
 public static GetSubscribersWithMetadataResult GetSubscribersWithMetadataAsync(
     string topic,
     WalletOptions options = null)
 {
     options = options ?? new WalletOptions();
     return(RpcClient.GetSubscribersWithMetadata(options.RpcServerAddress, topic, options.Offset, options.Limit, options.TxPool));
 }
Esempio n. 5
0
        private static async Task <string> ComputePasswordKeyAsync(WalletOptions options)
        {
            if (options.Version == null)
            {
                throw new System.Exception();
            }

            switch (options.Version.Value)
            {
            case 1: return(await Task.Run(() => Hash.DoubleSha256(options.Password)));

            case 2:

                var scrypt = await Task.Run(() =>
                {
                    return(ScryptUtil
                           .Scrypt(
                               options.Password,
                               options.Scrypt.Salt.FromHexString(),
                               options.Scrypt.N,
                               options.Scrypt.R,
                               options.Scrypt.P,
                               32)
                           .ToHexString());
                });

                return(scrypt);

            default: throw new InvalidWalletVersionException("unsupported wallet version " + options.Version);
            }
        }
Esempio n. 6
0
        public async Task <GetNonceByAddrResult> GetNonceAsync(string address = null, bool txPool = false)
        {
            var addr = string.IsNullOrEmpty(address) ? this.DefaultClient.Wallet.Address : address;

            foreach (var clientId in this.Clients.Keys)
            {
                if (string.IsNullOrEmpty(this.Clients[clientId].Wallet.Options.RpcServerAddress) == false)
                {
                    try
                    {
                        var options = this.Clients[clientId].Wallet.Options.Clone();
                        options.TxPool = txPool;

                        var getNonceResult = await Wallet.Wallet.GetNonceAsync(addr, options);

                        return(getNonceResult);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            var walletOptions = WalletOptions.NewFrom(this.options);

            walletOptions.TxPool = txPool;

            return(await Wallet.Wallet.GetNonceAsync(addr, walletOptions));
        }
Esempio n. 7
0
        public Client(ClientOptions options)
        {
            this.reconnectInterval = options.ReconnectIntervalMin ?? 0;
            this.options           = options;

            var key = string.IsNullOrWhiteSpace(options.SeedHex)
                                ? new CryptoKey()
                                : new CryptoKey(options.SeedHex);

            var identifier = options.Identifier ?? "";
            var address    = string.IsNullOrWhiteSpace(identifier)
                                ? key.PublicKey
                                : identifier + "." + key.PublicKey;

            this.key        = key;
            this.identifier = identifier;
            this.Address    = address;

            var walletOptions = new WalletOptions {
                Version = 1, SeedHex = key.SeedHex
            };

            this.Wallet = new Wallet.Wallet(walletOptions);

            this.options.SeedHex = null;

            this.messageHandlers       = new List <Func <MessageHandlerRequest, Task <object> > >();
            this.textResponseManager   = new ResponseManager <string>();
            this.binaryResponseManager = new ResponseManager <byte[]>();

            this.ConnectAsync();
        }
Esempio n. 8
0
 public static Task <GetSubscriptionResult> GetSubscriptionAsync(
     string topic,
     string subscriber,
     WalletOptions options = null)
 {
     options = options ?? new WalletOptions();
     return(RpcClient.GetSubscription(options.RpcServerAddress, topic, subscriber));
 }
 public HomeController(
     IWalletService walletService,
     IProvisioningService provisioningService,
     IOptions <WalletOptions> walletOptions)
 {
     _walletService       = walletService;
     _provisioningService = provisioningService;
     _walletOptions       = walletOptions.Value;
 }
Esempio n. 10
0
 public TestPage(WalletOptions walletOptions) : base(walletOptions)
 {
     components.Add(new TextBlockComponent
     {
         PositionX = 5,
         PositionY = 5,
         Text      = "test"
     });
 }
Esempio n. 11
0
        public Wallet(WalletOptions options = null)
        {
            options = options ?? new WalletOptions();

            this.version = options.Version ?? Wallet.DefaultVersion;

            switch (this.version)
            {
            case 2:
                this.scryptParams      = new ScryptParams();
                this.scryptParams.Salt = this.scryptParams.Salt ?? PseudoRandom.RandomBytesAsHexString(this.scryptParams.SaltLength);
                break;

            default:
                break;
            }

            string passwordKey = default;

            if (options.PasswordKeys != null && options.PasswordKeys.ContainsKey(this.version))
            {
                passwordKey = options.PasswordKeys[this.version];
            }
            else
            {
                passwordKey = Wallet.ComputePasswordKey(new WalletOptions
                {
                    Version  = this.version,
                    Password = options.Password,
                    Scrypt   = this.scryptParams
                });
            }

            var account = new Account(options.SeedHex);

            var ivHex        = options.Iv ?? PseudoRandom.RandomBytesAsHexString(16);
            var masterKeyHex = string.IsNullOrWhiteSpace(options.MasterKey)
                ? PseudoRandom.RandomBytesAsHexString(16)
                : options.MasterKey;

            this.Options     = options;
            this.account     = account;
            this.ivHex       = ivHex;
            this.Address     = this.account.Address;
            this.programHash = this.account.ProgramHash;

            this.masterKey     = Aes.Encrypt(masterKeyHex, passwordKey, ivHex.FromHexString());
            this.seedEncrypted = Aes.Encrypt(options.SeedHex, masterKeyHex, ivHex.FromHexString());

            this.Options.Iv          = null;
            this.Options.SeedHex     = null;
            this.Options.Password    = null;
            this.Options.MasterKey   = null;
            this.Options.PasswordKey = null;
            this.Options.PasswordKeys.Clear();
        }
Esempio n. 12
0
 public ConnectionsController(
     IConnectionService connectionService,
     IWalletService walletService,
     IProvisioningService provisioningService,
     IOptions <WalletOptions> walletOptions)
 {
     _connectionService   = connectionService;
     _walletService       = walletService;
     _provisioningService = provisioningService;
     _walletOptions       = walletOptions.Value;
 }
 /// <summary>Initializes a new instance of the <see cref="AgentMiddleware"/> class.</summary>
 /// <param name="next">The next.</param>
 /// <param name="walletService">The wallet service.</param>
 /// <param name="serviceProvider">The service provider.</param>
 /// <param name="walletOptions">The wallet options.</param>
 public AgentMiddleware(
     RequestDelegate next,
     IWalletService walletService,
     IServiceProvider serviceProvider,
     IOptions <WalletOptions> walletOptions)
     : base(serviceProvider)
 {
     _next          = next;
     _walletService = walletService;
     _walletOptions = walletOptions.Value;
 }
 public AgentBuilder(
     IPoolService poolService,
     IProvisioningService provisioningService,
     IOptions <WalletOptions> walletOptions,
     IOptions <PoolOptions> poolOptions)
 {
     _poolService         = poolService;
     _provisioningService = provisioningService;
     _walletOptions       = walletOptions.Value;
     _poolOptions         = poolOptions.Value;
 }
Esempio n. 15
0
        /// <summary>
        /// Default Agent Context Provider.
        /// </summary>
        /// <param name="walletOptions">The wallet options provider.</param>
        /// <param name="poolOptions">The pool options provider/</param>
        /// <param name="walletService">The wallet service.</param>
        /// <param name="poolService">The pool service.</param>
        public DefaultAgentContextProvider(IOptions <WalletOptions> walletOptions,
                                           IOptions <PoolOptions> poolOptions,
                                           IWalletService walletService,
                                           IPoolService poolService)
        {
            _walletOptions = walletOptions.Value;
            _poolOptions   = poolOptions.Value;

            _walletService = walletService;
            _poolService   = poolService;
        }
Esempio n. 16
0
        public bool VerifyPassword(string password)
        {
            var options = new WalletOptions
            {
                Version  = this.version,
                Password = password,
                Scrypt   = this.scryptParams
            };

            var passwordKey = Wallet.ComputePasswordKey(options);

            return(this.VerifyPasswordKey(passwordKey));
        }
 /// <inheritdoc />
 public DefaultProvisioningHostedService(
     IProvisioningService provisioningService,
     IWalletService walletService,
     IWalletRecordService recordService,
     IOptions <AgentOptions> agentOptions,
     IOptions <WalletOptions> walletOptions)
 {
     _provisioningService = provisioningService;
     _walletService       = walletService;
     _recordService       = recordService;
     _walletOptions       = walletOptions.Value;
     _agentOptions        = agentOptions.Value;
 }
Esempio n. 18
0
        public async Task <bool> VerifyPasswordAsync(string password)
        {
            var options = new WalletOptions
            {
                Version  = this.version,
                Password = password,
                Scrypt   = this.scryptParams
            };

            var passwordKey = await Wallet.ComputePasswordKeyAsync(options);

            return(this.VerifyPasswordKey(passwordKey));
        }
Esempio n. 19
0
        public GetSubscriptionResult GetSubscriptionAsync(string topic, string subscriber)
        {
            if (string.IsNullOrWhiteSpace(this.Wallet.Options.RpcServerAddress) == false)
            {
                try
                {
                    return(NknSdk.Wallet.Wallet.GetSubscriptionAsync(topic, subscriber, this.Wallet.Options));
                }
                catch (Exception)
                {
                }
            }

            return(NknSdk.Wallet.Wallet.GetSubscriptionAsync(topic, subscriber, WalletOptions.NewFrom(this.options)));
        }
 public ConnectionsController(
     IConnectionService connectionService,
     IWalletService walletService,
     IWalletRecordService recordService,
     IProvisioningService provisioningService,
     IMessageService routerService,
     IOptions <WalletOptions> walletOptions)
 {
     _connectionService   = connectionService;
     _walletService       = walletService;
     _recordService       = recordService;
     _provisioningService = provisioningService;
     _routerService       = routerService;
     _walletOptions       = walletOptions.Value;
 }
Esempio n. 21
0
        public long GetSubscrinersCountAsync(string topic)
        {
            if (string.IsNullOrWhiteSpace(this.Wallet.Options.RpcServerAddress) == false)
            {
                try
                {
                    return(NknSdk.Wallet.Wallet.GetSubscribersCountAsync(topic, this.Wallet.Options));
                }
                catch (Exception)
                {
                }
            }

            return(NknSdk.Wallet.Wallet.GetSubscribersCountAsync(topic, WalletOptions.NewFrom(this.options)));
        }
Esempio n. 22
0
 public ConnectionsController(
     IEventAggregator eventAggregator,
     IConnectionService connectionService,
     IWalletService walletService,
     IWalletRecordService recordService,
     IProvisioningService provisioningService,
     IMessageService messageService,
     IOptions <WalletOptions> walletOptions)
 {
     _eventAggregator     = eventAggregator;
     _connectionService   = connectionService;
     _walletService       = walletService;
     _recordService       = recordService;
     _provisioningService = provisioningService;
     _messageService      = messageService;
     _walletOptions       = walletOptions.Value;
 }
Esempio n. 23
0
        public GetRegistrantResult GetRegistrantAsync(string name)
        {
            if (string.IsNullOrWhiteSpace(this.Wallet.Options.RpcServerAddress))
            {
                try
                {
                    return(NknSdk.Wallet.Wallet.GetRegistrantAsync(name, this.Wallet.Options));
                }
                catch (Exception)
                {
                }
            }

            var walletOptions = WalletOptions.NewFrom(this.options);

            return(NknSdk.Wallet.Wallet.GetRegistrantAsync(name, walletOptions));
        }
Esempio n. 24
0
        public GetLatestBlockHashResult GetLatestBlockAsync()
        {
            if (string.IsNullOrWhiteSpace(this.Wallet.Options.RpcServerAddress))
            {
                try
                {
                    return(NknSdk.Wallet.Wallet.GetLatestBlockAsync(this.Wallet.Options));
                }
                catch (Exception)
                {
                }
            }

            var walletOptions = WalletOptions.NewFrom(this.options);

            return(NknSdk.Wallet.Wallet.GetLatestBlockAsync(walletOptions));
        }
Esempio n. 25
0
        public async Task <GetLatestBlockHashResult> GetLatestBlockAsync()
        {
            foreach (var clientId in this.Clients.Keys)
            {
                if (string.IsNullOrEmpty(this.Clients[clientId].Wallet.Options.RpcServerAddress) == false)
                {
                    try
                    {
                        return(await Wallet.Wallet.GetLatestBlockAsync(this.Clients[clientId].Wallet.Options));
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(await Wallet.Wallet.GetLatestBlockAsync(WalletOptions.NewFrom(this.options)));
        }
Esempio n. 26
0
        public async Task <GetRegistrantResult> GetRegistrantAsync(string name)
        {
            foreach (var clientId in this.Clients.Keys)
            {
                if (string.IsNullOrEmpty(this.Clients[clientId].Wallet.Options.RpcServerAddress) == false)
                {
                    try
                    {
                        return(await Wallet.Wallet.GetRegistrantAsync(name, this.Clients[clientId].Wallet.Options));
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(await Wallet.Wallet.GetRegistrantAsync(name, WalletOptions.NewFrom(this.options)));
        }
Esempio n. 27
0
        public async Task <int> GetSubscribersCountAsync(string topic)
        {
            foreach (var clientId in this.Clients.Keys)
            {
                if (string.IsNullOrEmpty(this.Clients[clientId].Wallet.Options.RpcServerAddress) == false)
                {
                    try
                    {
                        return(await Wallet.Wallet.GetSubscribersCountAsync(topic, this.Clients[clientId].Wallet.Options));
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(await Wallet.Wallet.GetSubscribersCountAsync(topic, WalletOptions.NewFrom(this.options)));
        }
Esempio n. 28
0
        public static Wallet FromJson(string json, WalletOptions options = null)
        {
            options = options ?? new WalletOptions();

            var wallet = WalletJson.FromJson(json);

            options.AssignFrom(wallet);

            var computeOptions = WalletOptions.FromWalletJson(wallet);

            computeOptions.Password = options.Password;

            var passwordKey = Wallet.ComputePasswordKey(computeOptions);

            options.PasswordKey = passwordKey;

            return(Wallet.Decrypt(wallet, options));
        }
Esempio n. 29
0
        public GetSubscribersResult GetSubscribersAsync(string topic, PublishOptions options = null)
        {
            options = options ?? new PublishOptions();

            if (string.IsNullOrWhiteSpace(this.Wallet.Options.RpcServerAddress))
            {
                try
                {
                    var mergedOptions = this.Wallet.Options.MergeWith(options);
                    return(NknSdk.Wallet.Wallet.GetSubscribersAsync(topic, mergedOptions));
                }
                catch (Exception)
                {
                }
            }

            var walletOptions = WalletOptions.NewFrom(this.options).AssignFrom(options);

            return(NknSdk.Wallet.Wallet.GetSubscribersAsync(topic, walletOptions));
        }
Esempio n. 30
0
 public AgentMiddleware(RequestDelegate next,
                        IWalletService walletService,
                        IPoolService poolService,
                        IMessageSerializer messageSerializer,
                        IConnectionService connectionService,
                        ICredentialService credentialService,
                        IProvisioningService provisioningService,
                        IOptions <WalletOptions> walletOptions,
                        IOptions <PoolOptions> poolOptions)
 {
     _next                = next;
     _walletService       = walletService;
     _poolService         = poolService;
     _messageSerializer   = messageSerializer;
     _connectionService   = connectionService;
     _credentialService   = credentialService;
     _provisioningService = provisioningService;
     _poolOptions         = poolOptions.Value;
     _walletOptions       = walletOptions.Value;
 }