public void Should_Join_Table_In_First_Empty_Seat() { //private key 91xCHwaMdufE8fmxachVhU12wdTjY7nGbZeGgjx4JQSuSDNizhf Guid tableId = new Guid("be7514a3-e73c-4f95-ba26-c398641eea5c"); _controller.TableRepo = new Repository.Mocks.TableRepository(); NBitcoin.BitcoinSecret secret = new NBitcoin.BitcoinSecret("91xCHwaMdufE8fmxachVhU12wdTjY7nGbZeGgjx4JQSuSDNizhf", NBitcoin.Network.TestNet); NBitcoin.BitcoinAddress address = secret.GetAddress(); Models.Messages.JoinTableRequest request = new Models.Messages.JoinTableRequest() { Id = new Guid(REQUEST_ID), BitcoinAddress = address.ToString(), TableId = tableId, TimeStamp = new DateTime(2016, 12, 12), PublicKey = secret.PubKey.ToString(), Version = 1 }; Models.Messages.JoinTableResponse response = null; // = _controller.Join(request); Assert.IsNotNull(response); Assert.AreEqual(1, response.Seat); }
public Boolean Verify(String address, String message, String signature) { NBitcoin.BitcoinAddress a = NBitcoin.BitcoinAddress.Create(address); var pubKey = new NBitcoin.BitcoinPubKeyAddress(address); bool verified = pubKey.VerifyMessage(message, signature); return(verified); }
/// <summary> /// Get deck for mock hand /// </summary> /// <param name="tableId"></param> /// <param name="handId"></param> /// <returns></returns> public BitPoker.Models.Messages.DeckResponse Get(Guid handId) { //As its heads up, create the first hand and deck BitPoker.Models.Hand hand = repo.Find(handId); //Assume alice const String alice_wif = "93Loqe8T3Qn3fCc87AiJHYHJfFFMLy6YuMpXzffyFsiodmAMCZS"; NBitcoin.BitcoinSecret alice_secret = new NBitcoin.BitcoinSecret(alice_wif, NBitcoin.Network.TestNet); NBitcoin.BitcoinAddress alice_address = alice_secret.GetAddress(); BitPoker.Models.Messages.DeckResponse response = new BitPoker.Models.Messages.DeckResponse() { HandId = handId, //BitcoinAddress = alice_address.ToString(), Deck = hand.Deck }; String message = response.ToString(); //response.Signature = alice_secret.PrivateKey.SignMessage(message); return(response); }
public BitPoker.Models.Hand Post(BitPoker.Models.Messages.DealRequest request) { var table = tableRepo.Find(request.TableId); if (table != null) { BitPoker.Models.Hand hand = new BitPoker.Models.Hand() { Deck = request.Deck }; //todo: change to position var sb = table.Peers[0]; const String alice_wif = "93Loqe8T3Qn3fCc87AiJHYHJfFFMLy6YuMpXzffyFsiodmAMCZS"; NBitcoin.BitcoinSecret alice_secret = new NBitcoin.BitcoinSecret(alice_wif, NBitcoin.Network.TestNet); NBitcoin.BitcoinAddress alice_address = alice_secret.GetAddress(); const String alice_pubkey = "041fa97efd760f26e93e91e29fddf3ddddd3f543841cf9435bdc156fb73854f4bf22557798ba535a3ee89a62238c5afc7f8bf1fa0985dc4e1a06c25209bab78bd1"; BitPoker.Models.Messages.ActionMessage smallBlind = new BitPoker.Models.Messages.ActionMessage() { //Id = new Guid("4bc7f305-aa16-450a-a3be-aad8fba7f425"), Index = 0, Action = "SMALL BLIND", Amount = table.SmallBlind, //BitcoinAddress = sb.BitcoinAddress, HandId = hand.Id, //PublicKey = alice_pubkey, TableId = request.TableId }; //smallBlind.Signature = alice_secret.PrivateKey.SignMessage(smallBlind.ToString()); //hand.AddMessage(smallBlind); //var bb = table.Players[1]; //const String bob_wif = "91yMBYURGqd38spSA1ydY6UjqWiyD1SBGJDuqPPfRWcpG53T672"; //NBitcoin.BitcoinSecret bob_secret = new NBitcoin.BitcoinSecret(bob_wif, NBitcoin.Network.TestNet); //NBitcoin.BitcoinAddress bob_address = bob_secret.GetAddress(); //const String bob_pubkey = "04f48396ac675b97eeb54e57554827cc2b937c2dae285a9198f9582b15c920d91309bc567858dc63357bcd5d24fd8c041ca55de8bae62c7315b0ba66fe5f96c20d"; ////NBitcoin.Crypto.Hashes.SHA256(NBitcoin.DataEncoders.Encoders.ASCII.(smallBlind.ToString())); //Byte[] hash = NBitcoin.Crypto.Hashes.SHA256(NBitcoin.DataEncoders.Encoders.ASCII.DecodeData(smallBlind.ToString())); //BitPoker.Models.Messages.ActionMessage bigBlind = new BitPoker.Models.Messages.ActionMessage() //{ // Id = new Guid("d10cc043-4df3-4d41-8b31-8dd573824c8b"), // Index = 1, // Action = "BIG BLIND", // Amount = table.BigBlind, // BitcoinAddress = bb.BitcoinAddress, // HandId = hand.Id, // PreviousHash = NBitcoin.DataEncoders.Encoders.ASCII.EncodeData(hash), // PublicKey = bob_pubkey, // TableId = request.TableId //}; //bigBlind.Signature = bob_secret.PrivateKey.SignMessage(bigBlind.ToString()); //hand.AddMessage(bigBlind); this.handRepo.Add(hand); return(hand); } else { throw new ArgumentException(); } }