public void CanParseStealthAddress() { var tests = new[] { //Test vector created with sx //sx stealth-newkey -> ScanSecret,SpendSecret,StealthAddress //sx stealth-show-addr StealthAddress -> ScanPubKey,SpendPubKey,RequiredSignature... new { ScanSecret = "9ac9fdee7c2c19611bcbed8959e1c61d00cdc27cf17bb50a1f4d29db7f953632", SpendSecrets = new[] { "4e2fa767cc241c3fa4c512d572b2758a3960a06d374f2c819fe409b161d72ad4" }, StealthAddress = "vJmsmwE8cVt9ytJxBuY2jayh8RAfvpG42CyNVYpeVZAkHaiwASobUEzskpXMwbH1TZNBLoxWWYem5WuZewTL8xz3upJ75zKcdVmTfg", ScanPubKey = "021ce89be99a229d123e8bc13ffbcb66722d6200bbeb1d90ddddbf97df82ed2672", SpendPubKeys = new[] { "03c197525241d3d70bbf33bb2b54d41e6b9595a92a2c6b7bf7157727c017f0154a" }, RequiredSignature = 1, Options = 0, PrefixLength = 0, PrefixValue = "", } }; foreach (var test in tests) { var scanSecret = new Key(TestUtils.ParseHex(test.ScanSecret)); AssertEx.CollectionEquals(scanSecret.PubKey.ToBytes(), TestUtils.ParseHex(test.ScanPubKey)); var stealth = new BitcoinStealthAddress(test.StealthAddress, Network.Main); Assert.Equal(test.RequiredSignature, stealth.SignatureCount); Assert.Equal(test.PrefixLength, stealth.Prefix.BitCount); AssertEx.CollectionEquals(stealth.Prefix.GetRawForm(), TestUtils.ParseHex(test.PrefixValue)); Assert.Equal(test.Options, stealth.Options); AssertEx.CollectionEquals(stealth.ScanPubKey.ToBytes(), TestUtils.ParseHex(test.ScanPubKey)); for (int i = 0; i < test.SpendPubKeys.Length; i++) { AssertEx.CollectionEquals(stealth.SpendPubKeys[i].ToBytes(), TestUtils.ParseHex(test.SpendPubKeys[i])); var spendSecret = new Key(TestUtils.ParseHex(test.SpendSecrets[i])); AssertEx.CollectionEquals(stealth.SpendPubKeys[i].ToBytes(), TestUtils.ParseHex(test.SpendPubKeys[i])); } } }
private Key AssertKeys(string key, string pub) { if (key == null) { return(null); } Key k = new Key(TestUtils.ParseHex(key)); if (pub != null) { PubKey p = new PubKey(TestUtils.ParseHex(pub)); AssertEx.Equal(k.PubKey.ToBytes(), p.ToBytes()); } return(k); }
public void bloom_create_insert_key() { string strSecret = "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C"; BitcoinSecret vchSecret = Network.Main.CreateBitcoinSecret(strSecret); var pubkey = vchSecret.PrivateKey.PubKey; BloomFilter filter = new BloomFilter(2, 0.001, 0, BloomFlags.UPDATE_ALL); filter.Insert(pubkey.ToBytes()); filter.Insert(pubkey.Hash.ToBytes()); var ms = new MemoryStream(); BitcoinStream bitcoinStream = new BitcoinStream(ms, true); bitcoinStream.ReadWrite(filter); var expected = ParseHex("038fc16b080000000000000001"); AssertEx.CollectionEquals(expected, ms.ToArray()); }
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 (var test in tests) { var scan = AssertKeys(test.ScanSecret, test.ScanPubKey); var spend = AssertKeys(test.SpendSecret, test.SpendPubKey); var ephem = AssertKeys(test.EphemSecret, test.EphemPubKey); var stealth = AssertKeys(test.StealthSecret, test.StealthPubKey); var address = spend.PubKey.CreateStealthAddress(scan.PubKey, Network.Main); Assert.Equal(test.StealthAddress, address.ToString()); //Try roundtrip address = new BitcoinStealthAddress(address.ToBytes(), Network.Main); Assert.Equal(test.StealthAddress, address.ToString()); var payment = address.CreatePayment(ephem); var 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()); } var uncoveredSender = spend.PubKey.UncoverSender(ephem, scan.PubKey); var 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); } }