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 static async Task <(bool, string)> GetCode(string txid, NBitcoin.BitcoinSecret key) { var msg = CreateMessage(txid); var signed = await ECDSAProvider.SignMessage(msg, key); return(signed); }
public BitPayClient(GlobalSettings globalSettings) { var btcSecret = new NBitcoin.BitcoinSecret(globalSettings.BitPay.Base58Secret, globalSettings.BitPay.Production ? null : NBitcoin.Network.TestNet); _bpClient = new NBitpayClient.Bitpay(btcSecret.PrivateKey, new Uri(globalSettings.BitPay.Production ? "https://bitpay.com/" : "https://test.bitpay.com/")); }
/// <summary> /// this function will decrypt the NFT if it is possile /// It needs the owner Private Key to create shared password which the combination of the sender public key. /// </summary> /// <param name="secret">Owner Private Key</param> /// <param name="decryptEvenOnSameAddress">Set true when you have preset the partner address manually - for example encryption on same address. </param> /// <returns>true if success</returns> public async Task <bool> Decrypt(NBitcoin.BitcoinSecret secret, bool decryptEvenOnSameAddress = false) { if (runningDecryption) { return(false); } if (Decrypted) { return(false); } if (string.IsNullOrEmpty(Partner)) { return(false);//throw new Exception("Cannot decrypt without loaded Partner address."); } var add = secret.PubKey.GetAddress(NBitcoin.ScriptPubKeyType.Legacy, NeblioTransactionHelpers.Network); if (Partner == add.ToString() && !decryptEvenOnSameAddress) { IsReceivedMessage = false; Partner = await NeblioTransactionHelpers.GetTransactionReceiver(Utxo); if (string.IsNullOrEmpty(Partner)) { return(false);//throw new Exception("Cannot decrypt without loaded Partner address."); } } else { IsReceivedMessage = true; } runningDecryption = true; if (await LoadSharedKeyForEncrypt(secret)) { Description = await DecryptProperty(Description, secret, "", Partner, sharedkey : SharedKey); Name = await DecryptProperty(Name, secret, "", Partner, sharedkey : SharedKey); Text = await DecryptProperty(Text, secret, "", Partner, sharedkey : SharedKey); ImageLink = await DecryptProperty(ImageLink, secret, "", Partner, sharedkey : SharedKey); Link = await DecryptProperty(Link, secret, "", Partner, sharedkey : SharedKey); } else { Console.WriteLine("Cannot decrypt NFT. Shared key not found."); } Decrypted = true; runningDecryption = false; return(true); }
public void OnGenerateKeyTappedAsync() { const String carol_wif = "91rahqyxZb6R1MMq2rdYomfB8GWsLVqkBMHrUnaepxks73KgfaQ"; NBitcoin.BitcoinSecret carol_secret = new NBitcoin.BitcoinSecret(carol_wif, NBitcoin.Network.TestNet); this.BitcoinAddress = carol_secret.GetAddress().ToString(); MessagingCenter.Send <HomeViewModel>(this, "Hi"); //MessagingCenter.Send<HomeViewModel>(this, "Hi", this.BitcoinAddress); }
public void Should_Sign_Action_Message() { String messageToSign = "{\"TableId\":\"bf368921-346a-42d8-9cb8-621f9cad5e16\",\"HandId\":\"398b5fe2-da27-4772-81ce-37fa615719b5\",\"Index\":2,\"Action\":\"CALL\",\"Amount\":5000000,\"Tx\":null,\"PreviousHash\":\"8ab9f91c002d8ccdbd8a49f7e028d27ca6ef01cf1fdaa4eca637868d8e4adf31\",\"HashAlgorithm\":\"SHA256\",\"Version\":1.0,\"BitcoinAddress\":\"msPJhg9GPzMN6twknwmSQvrUKZbZnk51Tv\",\"TimeStamp\":\"2016-08-17T00:00:00\"}"; String alice_wif = "93Loqe8T3Qn3fCc87AiJHYHJfFFMLy6YuMpXzffyFsiodmAMCZS"; NBitcoin.BitcoinSecret secret = new NBitcoin.BitcoinSecret(alice_wif, NBitcoin.Network.TestNet); String actual = secret.PrivateKey.SignMessage(messageToSign); Assert.IsNotNull(actual); Assert.AreEqual("HGlWJ1/MDp9JWiJWtMo5z8Se6JJtyuNZLhK6c3dJEYbRPrZrgPEr9j51R7Jsqu5HlkzOb073oRu+mT+/hBuyTP0=", actual); }
private async Task <bool> LoadSharedKeyForEncrypt(NBitcoin.BitcoinSecret secret) { if (string.IsNullOrEmpty(SharedKey)) { var sharedkey = await ECDSAProvider.GetSharedSecret(Partner, secret); if (sharedkey.Item1) { SharedKey = sharedkey.Item2; return(true); } else { return(false); } } else { return(true); } }
public void Should_Join_Table_In_Seat_2() { Guid tableId = new Guid(TABLE_ID); _controller.TableRepo = new Repository.Mocks.TableRepository(); Models.Messages.JoinTableRequest request = new Models.Messages.JoinTableRequest() { Id = new Guid(REQUEST_ID), BitcoinAddress = BITCOIN_ADDRESS_1, TableId = tableId, TimeStamp = new DateTime(2016, 12, 12), Seat = 2, Version = 1 }; NBitcoin.BitcoinSecret secret = new NBitcoin.BitcoinSecret(PRIVATE_KEY, NBitcoin.Network.TestNet); request.Signature = secret.PrivateKey.SignMessage(request.ToString()); Models.Messages.JoinTableResponse response = null; //_controller.Post(request); Assert.IsNotNull(response); Assert.AreEqual(2, response.Seat); }
/// <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 static async Task <(bool, (OwnershipVerificationCodeDto, byte[]))> GetQRCode(string txid, NBitcoin.BitcoinSecret key) { var signature = await GetCode(txid, key); if (signature.Item1) { var dto = new OwnershipVerificationCodeDto(); dto.TxId = txid; dto.Signature = signature.Item2; var dtos = JsonConvert.SerializeObject(dto); if (dtos != null) { //QRCodeData qrCodeData = qrGenerator.CreateQrCode(dtos, QRCodeGenerator.ECCLevel.Q); //var qrCode = new BitmapByteQRCode(qrCodeData); //var g = qrCode.GetGraphic(20); return(true, (dto, new byte[0])); } } return(false, (null, null)); }
public static async Task <OwnershipVerificationCodeDto> GetCodeInDto(string txid, NBitcoin.BitcoinSecret key) { var dto = new OwnershipVerificationCodeDto(); dto.TxId = txid; dto.Signature = (await GetCode(txid, key)).Item2; return(dto); }
/// <summary> /// This function will change Coruzant Post NFT /// You can use this function for sending the NFT when you will fill receiver parameter /// </summary> /// <param name="address">sender address</param> /// <param name="ekey">Encryption Key object of the address</param> /// <param name="NFT">Input NFT object with data to save to metadata. Must contain Utxo hash</param> /// <param name="nutxos">List of spendable neblio utxos if you have it loaded.</param> /// <param name="receiver">Fill when you want to send NFT to another address</param> /// <returns>New Tx Id Hash</returns> public static async Task <string> ChangeCoruzantPostNFT(string address, EncryptionKey ekey, INFT NFT, ICollection <Utxos> nutxos, NBitcoin.BitcoinSecret secret, string receiver = "") { var cnft = NFT as CoruzantArticleNFT; // create token metadata var metadata = new Dictionary <string, string>(); metadata.Add("NFT", "true"); metadata.Add("Type", "NFT CoruzantPost"); metadata.Add("Name", NFT.Name); metadata.Add("Author", NFT.Author); metadata.Add("AuthorProfileUtxo", cnft.AuthorProfileUtxo); metadata.Add("Description", NFT.Description); metadata.Add("Image", NFT.ImageLink); metadata.Add("Link", NFT.Link); metadata.Add("Tags", NFT.Tags); metadata.Add("FullPostLink", cnft.FullPostLink); metadata.Add("LastComment", cnft.LastComment); metadata.Add("LastCommentBy", cnft.LastCommentBy); if (NFT.Price > 0) { metadata.Add("Price", NFT.Price.ToString(CultureInfo.InvariantCulture)); } var rec = address; if (!string.IsNullOrEmpty(receiver)) { rec = receiver; } // fill input data for sending tx var dto = new SendTokenTxData() // please check SendTokenTxData for another properties such as specify source UTXOs { Id = CoruzantTokenId, // id of token Metadata = metadata, Amount = 1, sendUtxo = new List <string>() { NFT.Utxo }, SenderAddress = address, ReceiverAddress = rec }; try { // send tx var transaction = await NeblioTransactionHelpers.SendNFTTokenAsync(dto, nutxos); var rtxid = await NeblioTransactionHelpers.SignAndBroadcastTransaction(transaction, secret); if (rtxid != null) { return(rtxid); } else { return(string.Empty); } } catch (Exception ex) { throw ex; } }
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(); } }