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)); }
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)); }
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(); } }
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)); }
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); } }
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)); }
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(); }
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; }
public TestPage(WalletOptions walletOptions) : base(walletOptions) { components.Add(new TextBlockComponent { PositionX = 5, PositionY = 5, Text = "test" }); }
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(); }
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; }
/// <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; }
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; }
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)); }
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; }
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))); }
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; }
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)); }
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)); }
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))); }
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))); }
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))); }
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)); }
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)); }
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; }