private void Code11() { var scanKey = new Key(); var spendKey = new Key(); BitcoinStealthAddress stealthAddress = new BitcoinStealthAddress ( scanKey: scanKey.PubKey, pubKeys: new[] { spendKey.PubKey }, signatureCount: 1, bitfield: null, network: Network.Main); var ephem = new Key(); StealthPayment payment = stealthAddress.CreatePayment(ephem); Transaction transaction = new Transaction(); payment.AddToTransaction(transaction, Money.Coins(1.0m)); Console.WriteLine(transaction); payment = stealthAddress.GetPayments(transaction, scanKey).FirstOrDefault(); //Optional check (GetPayment already do it) BitcoinAddress expectedAddress = payment.StealthKeys[0].GetAddress(Network.Main); bool hasPayment = transaction .Outputs .Any(o => o.ScriptPubKey.GetDestinationAddress(Network.Main) == expectedAddress); Console.WriteLine(hasPayment); //// payment = stealthAddress.GetPayments(transaction, scanKey).FirstOrDefault(); Key privateKey = spendKey.Uncover(scanKey, payment.Metadata.EphemKey); expectedAddress = privateKey.PubKey.GetAddress(Network.Main); bool isRightKey = transaction .Outputs .Any(o => o.ScriptPubKey.GetDestinationAddress(Network.Main) == expectedAddress); Console.WriteLine(isRightKey); }
public void CanCreatePayment() { var tests = new[] { new CanCreatePaymentData { //sx stealth-newkey StealthAddress = "vJmtjxSDxNPXL4RNapp9ARdqKz3uJyf1EDGjr1Fgqs9c8mYsVH82h8wvnA4i5rtJ57mr3kor1EVJrd4e5upACJd588xe52yXtzumxj", ScanSecret = "3e49e7257cb31db997edb1cf8299af0f37e2663e2260e4b8033e49d39a6d02f2", ScanPubKey = "025e58a31122b38c86abc119b9379fe247410aee87a533f9c07b189aef6c3c1f52", SpendSecret = "aa3db0cfb3edc94de4d10f873f8190843f2a17484f6021a95a7742302c744748", SpendPubKey = "03616562c98e7d7b74be409a787cec3a912122f3fb331a9bee9b0b73ce7b9f50af", //sx newkey | sx wif-to-secret EphemSecret = "9e63abaf8dcd5ea3919e6de0b6c544e00bf51bf92496113a01d6e369944dc091", EphemPubKey = "03403d306ec35238384c7e340393335f9bc9bb4a2e574eb4e419452c4ea19f14b0", //sx steatlh-uncover-secret [EphemPubKey] [ScanSecret] [SpendSecret] StealthSecret = "4e422fb1e5e1db6c1f6ab32a7706d368ceb385e7fab098e633c5c5949c3b97cd", //sx stealth-initiate [EphemSecret] [ScanPubKey] [SpendPubKey] (for sender) //or //sx stealth-uncover [EphemPubKey] [ScanSecret] [SpendPubKey] (for receiver) StealthPubKey = "02726112ad39cb6bf848b1b1ef30b88e35286bf99f746c2be575f96c0e02a9357c", }, //Need padding for to find the stealth secret new CanCreatePaymentData { StealthAddress = "vJmyTEybwCKz7W8y6vP62jo7RoyfLneiANcPLBBNYwn98EXzQRStMKqKGRiZhqscuQ6WKy2J3U3zfx72V3b2J6YvxxBcxUj4XMDsw7", ScanSecret = "2f517d81cf30e47dbf4809321275bbfd92192af81a6141a17aa53e40bd28fe36", ScanPubKey = "039d91ae0eebea6dc500fb57b704abce3d3fa700cc762a52bc5dcaee27770a8402", SpendSecret = "71e33219884fc27011f8da9adcc730f0c2e940759bdb1b615764492bce04fcea", SpendPubKey = "021a3d5b40ec83fc58b5a23207eb9c99b741d8f0e9f8b80f04f49cec915b540c40", EphemSecret = "578ffe42c0fbfb324a31f41dbbcd8b1f910ce2f4d803444a83b18ae9f8ccd97e", EphemPubKey = "03c190be0a1c6e50577b3dd637b1fff9344de31c2544ff3d815535c0515711150f", StealthSecret = "006d138b4bcef0f09c8784c0cc68f2be4497a1a822d8d7b0519c5c0378b5cb45", StealthPubKey = "0223a99278a5279ea93718503a42377067e72960eb808d8bff6defdd95d4feff76" } }; foreach (CanCreatePaymentData test in tests) { Key scan = AssertKeys(test.ScanSecret, test.ScanPubKey); Key spend = AssertKeys(test.SpendSecret, test.SpendPubKey); Key ephem = AssertKeys(test.EphemSecret, test.EphemPubKey); Key stealth = AssertKeys(test.StealthSecret, test.StealthPubKey); BitcoinStealthAddress address = spend.PubKey.CreateStealthAddress(scan.PubKey, KnownNetworks.Main); Assert.Equal(test.StealthAddress, address.ToString()); //Try roundtrip address = new BitcoinStealthAddress(address.ToBytes(), KnownNetworks.Main); Assert.Equal(test.StealthAddress, address.ToString()); StealthPayment payment = address.CreatePayment(ephem); Key generatedKey = spend.Uncover(scan, payment.Metadata.EphemKey); if (stealth != null) { Assert.Equal(stealth.PubKey.Hash, payment.StealthKeys[0].ID); Assert.Equal(stealth.ToBytes(), generatedKey.ToBytes()); } PubKey uncoveredSender = spend.PubKey.UncoverSender(ephem, scan.PubKey); PubKey uncovertedReceiver = spend.PubKey.UncoverReceiver(scan, ephem.PubKey); AssertEx.CollectionEquals(uncoveredSender.ToBytes(), uncovertedReceiver.ToBytes()); AssertEx.CollectionEquals(generatedKey.PubKey.ToBytes(), uncovertedReceiver.ToBytes()); var transaction = new Transaction(); payment.AddToTransaction(transaction, 100); } }