public static LedgerAnchorWorker CreateLedgerAnchorWorker(IServiceProvider serviceProvider) { IConfiguration configuration = serviceProvider.GetService <IConfiguration>(); IConfiguration anchoring = configuration.GetSection("anchoring"); ILogger logger = serviceProvider.GetService <ILogger>(); IAnchorRecorder recorder = null; switch (anchoring["type"]) { case "blockchain": string anchorKey = anchoring["key"]; if (!string.IsNullOrEmpty(anchorKey)) { NBitcoin.Key key = NBitcoin.Key.Parse(anchorKey); NBitcoin.Network network = NBitcoin.Network.GetNetworks() .First(item => item.GetVersionBytes(NBitcoin.Base58Type.PUBKEY_ADDRESS)[0] == byte.Parse(anchoring["network_byte"])); logger.LogInformation($"Starting Blockchain anchor (address: {key.PubKey.GetAddress(network).ToString()})"); recorder = new BlockchainAnchorRecorder(new Uri(anchoring["bitcoin_api_url"]), key, network, long.Parse(anchoring["fees"])); } break; } if (recorder != null) { return(new LedgerAnchorWorker(serviceProvider.GetRequiredService <IAnchorBuilder>(), recorder, serviceProvider.GetRequiredService <ILogger>())); } else { return(null); } }
public static string SendTransaction( NBitcoinSV.IBitcoinSVApi bsvApi, BitIndex.Client.IBitIndexApi bitIndexApi, NBitcoin.Key user_key, string target_address, decimal margin_sum, string message, string message_name) { var tr = bsvApi.PrepareTransaction(user_key, target_address, margin_sum).Result; tr.Send( (new API.FileInfo { body = System.Text.Encoding.UTF8.GetBytes(message), type = "text", name = message_name }).GetScript(), NBitcoin.Money.Zero); var trx = tr.BuildTransaction(true); var trx_id = trx.GetHash().ToString(); bitIndexApi.Broadcast(trx.ToHex()).Wait(); return(trx_id); }
public async Task <NBitcoin.TransactionBuilder> PrepareTransaction(NBitcoin.Key from, string to, decimal amount) { var fromAddress = from.PubKey.GetAddress(NBitcoin.ScriptPubKeyType.Legacy, this.bitIndexApi_.Network).ToString(); var balance = await this.bitIndexApi_.GetBalance(fromAddress); var unspentCoins = new List <NBitcoin.Coin>(); decimal current_balance = 0M; if (balance.Length > 0) { foreach (var coin in balance.OrderBy(x => x.Amount)) { if (0 < coin.Amount) { unspentCoins.Add(new NBitcoin.Coin( NBitcoin.uint256.Parse(coin.TxId), coin.OutIndex, NBitcoin.Money.Coins(coin.Amount), from.ScriptPubKey)); current_balance += coin.Amount; if (current_balance >= amount) { break; } } } } if (current_balance < amount) { throw new Exception("Not enough money"); } var builder = BSVConsensusFactory.Instance.CreateTransactionBuilder(); builder.AddKeys(from); builder.AddCoins(unspentCoins); builder.Send(NBitcoin.BitcoinAddress.Create(to, this.bitIndexApi_.Network), NBitcoin.Money.Coins(amount)); builder.SetChange(from.ScriptPubKey); return(builder); }
private static void CreateWallet() { var Key1 = new NBitcoin.Key(); var bitcoinPrivateKey = Key1.GetWif(NBitcoin.Network.TestNet); NBitcoin.BitcoinEncryptedSecret encryptedBitcoinPrivateKey = bitcoinPrivateKey.Encrypt("your_pass_word"); Console.WriteLine("Your Address : " + bitcoinPrivateKey.GetAddress()); Console.WriteLine("Encrypted PrivateKey : " + bitcoinPrivateKey.ScriptPubKey.ToString()); //Result : //Wallet A //Your Address : mvJh993ZpnVFgX4Bs9jacjFLsKPhXj3nkj //Encrypted PrivateKey: 6PYQBZhumqnrhETBXNvqW61XHpwYVefbTmZtM2BZcekPjunUbPgUPGe8H2 //Wallet B //Your Address : mshr22VWpq7XTTA3EhAoqoizPuqRAvZfvi //Encrypted PrivateKey: 6PYTsdNrmWyNTBJVMd7LqXnAM7ApFkTtG1GMA5RdqczYW8kuAaTwbvJENw }
void Auth() { inauth = true; try { apiclient.Close(); } catch { } try { apiclient = new TcpClient(); apiclient.Connect("api.yolodice.com", 4444); if (apiclient.Connected) { sslStream = new SslStream(apiclient.GetStream()); sslStream.AuthenticateAsClient("https://api.yolodice.com"); string frstchallenge = string.Format(basestring, id++, "generate_auth_challenge", ""); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); int bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLChallenge tmp = null; try { tmp = json.JsonDeserialize <YLChallenge>(challenge); } catch (Exception e) { Parent.updateStatus("error: " + challenge); /*finishedlogin(false); * return;*/ } NBitcoin.Key tmpkey = NBitcoin.Key.Parse(privkey); string address = tmpkey.ScriptPubKey.GetDestinationAddress(NBitcoin.Network.GetNetwork("Main")).ToString(); string message = tmpkey.SignMessage(tmp.result); frstchallenge = string.Format(basestring, id++, "auth_by_address", ",\"params\":" + json.JsonSerializer <YLAuthSend>(new YLAuthSend { address = address, signature = message })); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLOgin tmologin = null; try { tmologin = json.JsonDeserialize <YLOgin>(challenge); } catch (Exception e) { Parent.updateStatus("error: " + challenge); /*finishedlogin(false); * return;*/ } uid = tmologin.result.id; this.username = tmologin.result.name; frstchallenge = string.Format(basestring, id++, "read_user_coin_data", ",\"params\":{\"selector\":{\"id\":\"" + uid + "_" + Currency.ToLower() + "\"}}"); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLUserStats tmpstats = null; try { tmpstats = json.JsonDeserialize <YLUserStats>(challenge).result; } catch (Exception e) { Parent.updateStatus("error: " + challenge); /*finishedlogin(false); * return;*/ } if (tmpstats != null) { balance = (decimal)tmpstats.balance / 100000000m; bets = (int)tmpstats.bets; wins = (int)tmpstats.wins; losses = (int)tmpstats.losses; profit = (decimal)tmpstats.profit / 100000000m; wagered = (decimal)tmpstats.wagered / 100000000m; Parent.updateBalance(balance); Parent.updateBets(bets); Parent.updateWins(wins); Parent.updateLosses(losses); Parent.updateProfit(profit); Parent.updateWagered(wagered); ispd = true; lastupdate = DateTime.Now; new Thread(new ThreadStart(BalanceThread)).Start(); new Thread(new ThreadStart(Beginreadthread)).Start(); //sslStream.BeginRead(ReadBuffer, 0, 512, ReadTCP, sslStream); //Write("read_current_seed", "{\"selector\":{\"user_id\":" + uid + "}}"); //privkey = Password; //Thread.Sleep(50); //finishedlogin(true); inauth = false; return; } //tmp2.ImportPrivKey(Password, "", false); //string message = tmp2.SignMessage(username, tmp.result); //string message = //FullSignatureTest(tmp.result, new AsymmetricCipherKeyPair("", "")); /*ispd = true; * new Thread(new ThreadStart(BalanceThread)).Start();*/ } } catch (Exception e) { } //finishedlogin(false); inauth = false; }
//long uid = 0; public override void Login(string Username, string Password, string twofa) { try { apiclient = new TcpClient(); apiclient.Connect("api.yolodice.com", 4444); if (apiclient.Connected) { sslStream = new SslStream(apiclient.GetStream()); sslStream.AuthenticateAsClient("api.yolodice.com");//, null, System.Security.Authentication.SslProtocols.Ssl2| System.Security.Authentication.SslProtocols.Ssl3| System.Security.Authentication.SslProtocols.Tls11|System.Security.Authentication.SslProtocols.Tls12, false); string frstchallenge = string.Format(basestring, id++, "generate_auth_challenge", ""); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); int bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLChallenge tmp = null; try { tmp = json.JsonDeserialize <YLChallenge>(challenge); } catch (Exception e) { Parent.updateStatus("error: " + challenge); finishedlogin(false); return; } string address = ""; string message = ""; try { NBitcoin.Key tmpkey = NBitcoin.Key.Parse(Password); address = tmpkey.ScriptPubKey.GetDestinationAddress(NBitcoin.Network.GetNetwork("Main")).ToString(); message = tmpkey.SignMessage(tmp.result); } catch (Exception e) { Parent.updateStatus("API key format error. Are you using your Private key?"); finishedlogin(false); return; } frstchallenge = string.Format(basestring, id++, "auth_by_address", ",\"params\":" + json.JsonSerializer <YLAuthSend>(new YLAuthSend { address = address, signature = message })); //{"id":1,"method":"auth_by_address","params":{"address":"n3kmufwdR3Zzgk3k6NYeeLBxB9SpHKe5Tc","signature":"H4W6yMaVK6EzrTw/9jqmLh1lvoyFnxCFqRon2g25lJ7FTCAUHGJWWF3UJD5wCzCVafdjIfCmIYH2KyHboodjjcU="}} //{"id":1,"method":"auth_by_address","params":{"address":"1PUgaiHavJrpi7r7JhkhwWj7Kf9Ls68Z6w","signature":"Hz0oh29Nho+bVz7zggS1dqx\/N7VAyD6jsk8k98qW84ild7D71Q9rUbmEE4GIj0a5eKPcK1EjvSEwwa74jBJRyY8="}} sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLOgin tmologin = null; try { tmologin = json.JsonDeserialize <YLOgin>(challenge); } catch (Exception e) { Parent.updateStatus("error: " + challenge); finishedlogin(false); return; } uid = tmologin.result.id; this.username = tmologin.result.name; frstchallenge = string.Format(basestring, id++, "read_user_coin_data", ",\"params\":{\"selector\":{\"id\":\"" + uid + "_" + Currency.ToLower() + "\"}}"); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLUserStats tmpstats = null; try { tmpstats = json.JsonDeserialize <YLUserStats>(challenge).result; } catch (Exception e) { Parent.updateStatus("error: " + challenge); finishedlogin(false); return; } if (tmpstats != null) { balance = (decimal)tmpstats.balance / 100000000m; bets = (int)tmpstats.bets; wins = (int)tmpstats.wins; losses = (int)tmpstats.losses; profit = (decimal)tmpstats.profit / 100000000m; wagered = (decimal)tmpstats.wagered / 100000000m; Parent.updateBalance(balance); Parent.updateBets(bets); Parent.updateWins(wins); Parent.updateLosses(losses); Parent.updateProfit(profit); Parent.updateWagered(wagered); ispd = true; lastupdate = DateTime.Now; new Thread(new ThreadStart(BalanceThread)).Start(); privkey = Password; new Thread(new ThreadStart(Beginreadthread)).Start(); Thread.Sleep(50); finishedlogin(true); return; } //tmp2.ImportPrivKey(Password, "", false); //string message = tmp2.SignMessage(username, tmp.result); //string message = //FullSignatureTest(tmp.result, new AsymmetricCipherKeyPair("", "")); /*ispd = true; * new Thread(new ThreadStart(BalanceThread)).Start();*/ } } catch (Exception e) { Parent.DumpLog(e.ToString(), 0); } finishedlogin(false); }
protected override void _Login(LoginParamValue[] LoginParams) { try { privkey = LoginParams[0].Value; apiclient = new TcpClient(); apiclient.Connect("api.yolodice.com", 4444); if (apiclient.Connected) { sslStream = new SslStream(apiclient.GetStream()); sslStream.AuthenticateAsClient("api.yolodice.com");//, null, System.Security.Authentication.SslProtocols.Ssl2| System.Security.Authentication.SslProtocols.Ssl3| System.Security.Authentication.SslProtocols.Tls11|System.Security.Authentication.SslProtocols.Tls12, false); string frstchallenge = string.Format(basestring, id++, "generate_auth_challenge", ""); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); int bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLChallenge tmp = null; try { tmp = json.JsonDeserialize <YLChallenge>(challenge); } catch (Exception e) { callError("error: ", true, ErrorType.Other); callLoginFinished(false); return; } string address = ""; string message = ""; try { NBitcoin.Key tmpkey = NBitcoin.Key.Parse(privkey, NBitcoin.Network.Main); address = tmpkey.ScriptPubKey.GetDestinationAddress(NBitcoin.Network.GetNetwork("Main")).ToString(); message = tmpkey.SignMessage(tmp.result); } catch (Exception e) { callError("API key format error. Are you using your Private key?", true, ErrorType.Other); callLoginFinished(false); return; } frstchallenge = string.Format(basestring, id++, "auth_by_address", ",\"params\":" + json.JsonSerializer <YLAuthSend>(new YLAuthSend { address = address, signature = message })); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLOgin tmologin = null; try { tmologin = json.JsonDeserialize <YLOgin>(challenge); } catch (Exception e) { callError("error: " + challenge, true, ErrorType.Other); callLoginFinished(false); return; } uid = tmologin.result.id; this.username = tmologin.result.name; frstchallenge = string.Format(basestring, id++, "read_user_coin_data", ",\"params\":{\"selector\":{\"id\":\"" + uid + "_" + CurrentCurrency.ToLower() + "\"}}"); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLUserStats tmpstats = null; try { tmpstats = json.JsonDeserialize <YLUserStats>(challenge).result; } catch (Exception e) { callError("error: " + challenge, true, ErrorType.Other); callLoginFinished(false); return; } if (tmpstats != null) { Stats.Balance = (decimal)tmpstats.balance / 100000000m; Stats.Bets = (int)tmpstats.bets; Stats.Wins = (int)tmpstats.wins; Stats.Losses = (int)tmpstats.losses; Stats.Profit = (decimal)tmpstats.profit / 100000000m; Stats.Wagered = (decimal)tmpstats.wagered / 100000000m; ispd = true; lastupdate = DateTime.Now; new Thread(new ThreadStart(BalanceThread)).Start(); new Thread(new ThreadStart(Beginreadthread)).Start(); Thread.Sleep(50); callLoginFinished(true); return; } //tmp2.ImportPrivKey(Password, "", false); //string message = tmp2.SignMessage(username, tmp.result); //string message = //FullSignatureTest(tmp.result, new AsymmetricCipherKeyPair("", "")); /*ispd = true; * new Thread(new ThreadStart(BalanceThread)).Start();*/ } } catch (Exception e) { Logger.DumpLog(e); } callLoginFinished(false); }
void Auth() { inauth = true; try { apiclient.Close(); } catch { } try { apiclient = new TcpClient(); apiclient.Connect("api.yolodice.com", 4444); if (apiclient.Connected) { sslStream = new SslStream(apiclient.GetStream()); sslStream.AuthenticateAsClient("https://api.yolodice.com"); string frstchallenge = string.Format(basestring, id++, "generate_auth_challenge", ""); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); int bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLChallenge tmp = null; try { tmp = json.JsonDeserialize <YLChallenge>(challenge); } catch (Exception e) { Logger.DumpLog(e); callError("error: " + challenge, true, ErrorType.Unknown); /*finishedlogin(false); * return;*/ } NBitcoin.Key tmpkey = NBitcoin.Key.Parse(privkey, NBitcoin.Network.Main); string address = tmpkey.ScriptPubKey.GetDestinationAddress(NBitcoin.Network.GetNetwork("Main")).ToString(); string message = tmpkey.SignMessage(tmp.result); frstchallenge = string.Format(basestring, id++, "auth_by_address", ",\"params\":" + json.JsonSerializer <YLAuthSend>(new YLAuthSend { address = address, signature = message })); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLOgin tmologin = null; try { tmologin = json.JsonDeserialize <YLOgin>(challenge); } catch (Exception e) { Logger.DumpLog(e); callError("error: " + challenge, true, ErrorType.Unknown); /*finishedlogin(false); * return;*/ } uid = tmologin.result.id; this.username = tmologin.result.name; frstchallenge = string.Format(basestring, id++, "read_user_coin_data", ",\"params\":{\"selector\":{\"id\":\"" + uid + "_" + CurrentCurrency.ToLower() + "\"}}"); sslStream.Write(Encoding.ASCII.GetBytes(frstchallenge)); bytes = sslStream.Read(ReadBuffer, 0, 512); challenge = Encoding.ASCII.GetString(ReadBuffer, 0, bytes); YLUserStats tmpstats = null; try { tmpstats = json.JsonDeserialize <YLUserStats>(challenge).result; } catch (Exception e) { callError("error: " + challenge, true, ErrorType.Unknown); /*finishedlogin(false); * return;*/ } if (tmpstats != null) { Stats.Balance = (decimal)tmpstats.balance / 100000000m; Stats.Bets = (int)tmpstats.bets; Stats.Wins = (int)tmpstats.wins; Stats.Losses = (int)tmpstats.losses; Stats.Profit = (decimal)tmpstats.profit / 100000000m; Stats.Wagered = (decimal)tmpstats.wagered / 100000000m; ispd = true; lastupdate = DateTime.Now; new Thread(new ThreadStart(BalanceThread)).Start(); new Thread(new ThreadStart(Beginreadthread)).Start(); inauth = false; return; } } } catch (Exception e) { } //finishedlogin(false); inauth = false; }
// [Category("BlockchainIntegration")] public void ProhibotCashOutsToHWTest() { string phonePrefix = null; string phoneNumber = TestData.GenerateNumbers(9); var currentAssetId = lykkePrivateApi.Assets.GetAssets().GetResponseObject().FirstOrDefault(a => { if (a.BlockchainIntegrationLayerId != null) { return(a.BlockchainIntegrationLayerId.ToString().ToLower() == BlockChainName.ToLower()); } return(false); })?.Id; var blockchainSettings = cfg["BlockchainsIntegration"]; var currentBlockchainSettings = JsonConvert.DeserializeObject <BlockchainSettings[]>(cfg["BlockchainsIntegration"]["Blockchains"].ToString()).FirstOrDefault(b => b.Type.ToLower().Contains(BlockChainName.ToLower())); if (currentBlockchainSettings == null) { Assert.Ignore($"Blockchain {BlockChainName} does not present in blockchain settings {blockchainSettings}"); } #region register client var bitcoinPrivateKey = new NBitcoin.Key().GetWif(NBitcoin.Network.TestNet); //STEP 0 var getApplicationInfo = walletApi.ApplicationInfo .GetApplicationInfo() .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); //STEP 2 var postEmailVerification = walletApi.EmailVerification .PostEmailVerification(new PostEmailModel() { Email = email }) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.That(postEmailVerification.GetResponseObject().Error, Is.Null); //STEP 3 var getEmailVerification = walletApi.EmailVerification .GetEmailVerification(email, code, null) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.That(getEmailVerification.GetResponseObject().Result.Passed, Is.True); //STEP 4 var postRegistration = walletApi.Registration.PostRegistrationResponse(new AccountRegistrationModel() { ClientInfo = clientInfo, Email = email, Hint = hint, Password = Sha256.GenerateHash(password) }) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.Multiple(() => { var postRegistrationData = postRegistration.GetResponseObject(); Assert.That(postRegistrationData.Result.PersonalData?.Email, Is.EqualTo(email)); Assert.That(postRegistrationData.Result.Token, Is.Not.Null.And.Not.Empty); }); token = postRegistration.GetResponseObject().Result.Token; //STEP 6 var getPersonalData = walletApi.PersonalData .GetPersonalDataResponse(token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.That(getPersonalData.GetResponseObject().Result .Email, Is.EqualTo(email)); //STEP 7 var postClientFullName = walletApi.ClientFullName .PostClientFullName(new PostClientFullNameModel() { FullName = $"{firstName} {lastName}" }, token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); //STEP 8 getPersonalData = walletApi.PersonalData .GetPersonalDataResponse(token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); var getPersonalDataResult = getPersonalData.GetResponseObject().Result; Assert.That(getPersonalDataResult.FullName, Is.EqualTo($"{firstName} {lastName}")); Assert.That(getPersonalDataResult.FirstName, Is.EqualTo(firstName)); Assert.That(getPersonalDataResult.LastName, Is.EqualTo(lastName)); Assert.That(getPersonalDataResult.Country, Is.Not.Null.And.Not.Empty); country = getPersonalData.GetResponseObject().Result.Country; //STEP 9 var getCountryPhoneCodes = walletApi.CountryPhoneCodes .GetCountryPhoneCodes(token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); var getCountryPhoneCodesResult = getCountryPhoneCodes.GetResponseObject().Result; Assert.That(getCountryPhoneCodesResult.Current, Is.EqualTo(country)); phonePrefix = getCountryPhoneCodesResult.CountriesList .FirstOrDefault(c => c.Id == country)?.Prefix; Assert.That(phonePrefix, Is.Not.Null); //STEP 10 var postCheckMobilePhone = walletApi.CheckMobilePhone .PostCheckMobilePhone(new PostClientPhoneModel() { PhoneNumber = phonePrefix + phoneNumber }, token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); //STEP 11 var getCheckMobilePhone = walletApi.CheckMobilePhone .GetCheckMobilePhone(phonePrefix + phoneNumber, code, token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.That(getCheckMobilePhone.GetResponseObject().Result .Passed, Is.True); //STEP 12 var getCheckDocumentsToUpload = walletApi.CheckDocumentsToUpload .GetCheckDocumentsToUpload(token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); var getCheckDocumentsToUploadResult = getCheckDocumentsToUpload.GetResponseObject().Result; Assert.That(getCheckDocumentsToUploadResult.IdCard, Is.True); Assert.That(getCheckDocumentsToUploadResult.ProofOfAddress, Is.True); Assert.That(getCheckDocumentsToUploadResult.Selfie, Is.True); //STEP 13 var postPinSecurity = walletApi.PinSecurity .PostPinSecurity(new PinSecurityChangeModel() { Pin = pin }, token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); //STEP 14 var getMyLykkeSettings = walletApi.MyLykkeSettings .GetMyLykkeSettings(token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.That(getMyLykkeSettings.GetResponseObject().Result.MyLykkeEnabled, Is.True); //STEP 15 var postClientKeys = walletApi.ClientKeys .PostClientKeys(new ClientKeysModel() { PubKey = bitcoinPrivateKey.PubKey.ToString(), EncodedPrivateKey = AesUtils.Encrypt(bitcoinPrivateKey.ToString(), password) }, token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); #endregion var clientId = lykkePrivateApi.ClientAccount.ClientAccountInformation. GetClientsByEmail(email).GetResponseObject().FirstOrDefault()?.Id; Assert.That(clientId, Is.Not.Null, "UnExpected ClientId is null."); var walletId = lykkePrivateApi.ClientAccount.Wallets.GetWalletsForClientById(clientId). GetResponseObject().FirstOrDefault()?.Id; Assert.That(walletId, Is.Not.Null, $"Dont have any wallets for client {clientId}"); // fill wallet with manual CashIn var manualCashIn = new ManualCashInRequestModel { Amount = 10, AssetId = currentAssetId, ClientId = clientId, Comment = "AutotestFund", UserId = "Autotest user" }; var cryptoToWalletResponse = lykkePrivateApi.ExchangeOperation.PostManualCashIn(manualCashIn); // we have crypto. Go to make CashOut var mobileSteps = new MobileSteps(walletApi); var keys = mobileSteps.Login(email, password, pin); var SignatureVerificationToken = mobileSteps.GetAccessToken(email, keys.token, keys.privateKey); //complete backup var backUp = walletApi.BackupCompleted.PostBackupCompleted(token); var cashOut = new HotWalletCashoutOperation { AssetId = currentAssetId, DestinationAddress = currentBlockchainSettings.HotWalletAddress, Volume = 5 }; var cashOutRequest = walletApi.HotWallet.PostCashOut(cashOut, SignatureVerificationToken, token); if (cashOutRequest.GetResponseObject().Error.Message.ToLower().Contains("address is invalid")) { Assert.Pass("Error message contain 'address is invalid'"); } else { var getDiscl = walletApi.AssetDisclaimers.Get(token); var postDiscl = walletApi.AssetDisclaimers.PostApproveById(getDiscl.GetResponseObject().Result.Disclaimers[0].Id, token); //make cashout again SignatureVerificationToken = mobileSteps.GetAccessToken(email, keys.token, keys.privateKey); cashOutRequest = walletApi.HotWallet.PostCashOut(cashOut, SignatureVerificationToken, token); Assert.That(cashOutRequest.GetResponseObject().Error.Message.ToLower(), Does.Contain("address is invalid"), "Unexpected error message"); } }
public static int Main(string[] args) { Arguments arguments = null; try { arguments = ParseArguments(args); } catch (ArgumentException aex) { Console.WriteLine("Error: " + aex.Message); Console.WriteLine("Usage: Lykke.Ico.KeyGenerator -n <Number of key pairs to generate> [-p <Path to public keys file>] [-s <Path to secret keys file>] [-net <Name of BTC net>] [-a] [-h] [-e <Entropy>]"); return(1); } var publicKeysPath = arguments.PublicKeysPath ?? defaultPublicKeysPath; var secretKeysPath = arguments.SecretKeysPath ?? defaultSecretKeysPath; var startedAt = DateTime.Now; if (File.Exists(publicKeysPath)) { File.Delete(publicKeysPath); } if (File.Exists(secretKeysPath)) { File.Delete(secretKeysPath); } if (!string.IsNullOrWhiteSpace(arguments.Entropy)) { NBitcoin.RandomUtils.AddEntropy(arguments.Entropy); } using (var publicWriter = new StreamWriter(File.OpenWrite(publicKeysPath))) using (var secretWriter = new StreamWriter(File.OpenWrite(secretKeysPath))) { if (arguments.WriteHeaders) { if (arguments.WriteAddress) { publicWriter.WriteLine("btcAddress;btcPublic;ethAddress;ethPublic"); secretWriter.WriteLine("btcAddress;btcPublic;btcPrivate;ethAddress;ethPublic;ethPrivate"); } else { publicWriter.WriteLine("btcPublic;ethPublic"); secretWriter.WriteLine("btcPublic;btcPrivate;ethPublic;ethPrivate"); } } for (int i = 0; i < arguments.Count; i++) { // report out the progress if (i % 1000 == 0) { Console.Write("\r{0} of {1}", i, arguments.Count); } // generate keys var btcKey = new NBitcoin.Key(); var btcPvt = btcKey.GetBitcoinSecret(arguments.BitcoinNetwork).ToWif(); var btcPub = btcKey.PubKey.ToHex(); var ethKey = Nethereum.Signer.EthECKey.GenerateKey(); var ethPvt = ethKey.GetPrivateKey(); var ethPub = ethKey.GetPubKey().ToHex(true); if (arguments.WriteAddress) { var btcAddress = btcKey.PubKey.GetAddress(arguments.BitcoinNetwork).ToString(); var ethAddress = ethKey.GetPublicAddress(); publicWriter.WriteLine("{0};{1};{2};{3}", btcAddress, btcPub, ethAddress, ethPub); secretWriter.WriteLine("{0};{1};{2};{3};{4};{5}", btcAddress, btcPub, btcPvt, ethAddress, ethPub, ethPvt); } else { publicWriter.WriteLine("{0};{1}", btcPub, ethPub); secretWriter.WriteLine("{0};{1};{2};{3}", btcPub, btcPvt, ethPub, ethPvt); } } } // report final state Console.WriteLine("\r{0} of {1}", arguments.Count, arguments.Count); Console.WriteLine("Completed in {0}", DateTime.Now - startedAt); // return success code return(0); }
public void RegisterTest() { string firstName = "Autotest"; string lastName = "User"; string clientInfo = "iPhone; Model:6 Plus; Os:9.3.5; Screen:414x736"; string hint = "qwe"; string phonePrefix = null; string phoneNumber = TestData.GenerateNumbers(9); string token = null; string country = null; var bitcoinPrivateKey = new NBitcoin.Key().GetWif(NBitcoin.Network.TestNet); //STEP 0 var getApplicationInfo = walletApi.ApplicationInfo .GetApplicationInfo() .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); //STEP 1 ////var getClientState = walletApi.ClientState //// .GetClientState(email, null) //// .Validate.StatusCode(HttpStatusCode.OK) //// .Validate.NoApiError(); ////Assert.That(getClientState.GetResponseObject().Result //// .IsRegistered, Is.False); //STEP 2 var postEmailVerification = walletApi.EmailVerification .PostEmailVerification(new PostEmailModel() { Email = email }) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.That(postEmailVerification.GetResponseObject().Error, Is.Null); //STEP 3 var getEmailVerification = walletApi.EmailVerification .GetEmailVerification(email, code, null) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.That(getEmailVerification.GetResponseObject().Result.Passed, Is.True); //STEP 4 var postRegistration = walletApi.Registration.PostRegistrationResponse(new AccountRegistrationModel() { ClientInfo = clientInfo, Email = email, Hint = hint, Password = Sha256.GenerateHash(password) }) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.Multiple(() => { var postRegistrationData = postRegistration.GetResponseObject(); Assert.That(postRegistrationData.Result.PersonalData?.Email, Is.EqualTo(email)); Assert.That(postRegistrationData.Result.Token, Is.Not.Null.And.Not.Empty); }); token = postRegistration.GetResponseObject().Result.Token; ////STEP 5 //getClientState = walletApi.ClientState // .GetClientState(email, null) // .Validate.StatusCode(HttpStatusCode.OK) // .Validate.NoApiError(); //Assert.Multiple(() => //{ // var getClientStateData = getClientState.GetResponseObject(); // Assert.That(getClientStateData.Result.IsRegistered, Is.True); // Assert.That(getClientStateData.Result.IsPwdHashed, Is.True); //}); //STEP 6 var getPersonalData = walletApi.PersonalData .GetPersonalDataResponse(token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.That(getPersonalData.GetResponseObject().Result .Email, Is.EqualTo(email)); //STEP 7 var postClientFullName = walletApi.ClientFullName .PostClientFullName(new PostClientFullNameModel() { FullName = $"{firstName} {lastName}" }, token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); //STEP 8 getPersonalData = walletApi.PersonalData .GetPersonalDataResponse(token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); var getPersonalDataResult = getPersonalData.GetResponseObject().Result; Assert.That(getPersonalDataResult.FullName, Is.EqualTo($"{firstName} {lastName}")); Assert.That(getPersonalDataResult.FirstName, Is.EqualTo(firstName)); Assert.That(getPersonalDataResult.LastName, Is.EqualTo(lastName)); Assert.That(getPersonalDataResult.Country, Is.Not.Null.And.Not.Empty); country = getPersonalData.GetResponseObject().Result.Country; //STEP 9 var getCountryPhoneCodes = walletApi.CountryPhoneCodes .GetCountryPhoneCodes(token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); var getCountryPhoneCodesResult = getCountryPhoneCodes.GetResponseObject().Result; Assert.That(getCountryPhoneCodesResult.Current, Is.EqualTo(country)); phonePrefix = getCountryPhoneCodesResult.CountriesList .FirstOrDefault(c => c.Id == country)?.Prefix; Assert.That(phonePrefix, Is.Not.Null); //STEP 10 var postCheckMobilePhone = walletApi.CheckMobilePhone .PostCheckMobilePhone(new PostClientPhoneModel() { PhoneNumber = phonePrefix + phoneNumber }, token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); //STEP 11 var getCheckMobilePhone = walletApi.CheckMobilePhone .GetCheckMobilePhone(phonePrefix + phoneNumber, code, token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.That(getCheckMobilePhone.GetResponseObject().Result .Passed, Is.True); //STEP 12 var getCheckDocumentsToUpload = walletApi.CheckDocumentsToUpload .GetCheckDocumentsToUpload(token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); var getCheckDocumentsToUploadResult = getCheckDocumentsToUpload.GetResponseObject().Result; Assert.That(getCheckDocumentsToUploadResult.IdCard, Is.True); Assert.That(getCheckDocumentsToUploadResult.ProofOfAddress, Is.True); Assert.That(getCheckDocumentsToUploadResult.Selfie, Is.True); //STEP 13 var postPinSecurity = walletApi.PinSecurity .PostPinSecurity(new PinSecurityChangeModel() { Pin = pin }, token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); //STEP 14 var getMyLykkeSettings = walletApi.MyLykkeSettings .GetMyLykkeSettings(token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); Assert.That(getMyLykkeSettings.GetResponseObject().Result.MyLykkeEnabled, Is.True); //STEP 15 var postClientKeys = walletApi.ClientKeys .PostClientKeys(new ClientKeysModel() { PubKey = bitcoinPrivateKey.PubKey.ToString(), EncodedPrivateKey = AesUtils.Encrypt(bitcoinPrivateKey.ToString(), password) }, token) .Validate.StatusCode(HttpStatusCode.OK) .Validate.NoApiError(); }