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); }
/// <summary> /// Scan the Transaction for StealthCoin given address and scan key /// </summary> /// <param name="tx">The transaction to scan</param> /// <param name="address">The stealth address</param> /// <param name="scan">The scan private key</param> /// <returns></returns> public static StealthCoin Find(Transaction tx, BitcoinStealthAddress address, Key scan) { var payment = address.GetPayments(tx, scan).FirstOrDefault(); if (payment == null) { return(null); } var txId = tx.GetHash(); var txout = tx.Outputs.First(o => o.ScriptPubKey == payment.ScriptPubKey); return(new StealthCoin(new OutPoint(txId, tx.Outputs.IndexOf(txout)), txout, payment.Redeem, payment.Metadata, address)); }
/// <summary> /// Scan the Transaction for StealthCoin given address and scan key /// </summary> /// <param name="tx">The transaction to scan</param> /// <param name="address">The stealth address</param> /// <param name="scan">The scan private key</param> /// <returns></returns> public static StealthCoin Find(Transaction tx, BitcoinStealthAddress address, Key scan) { var payment = address.GetPayments(tx, scan).FirstOrDefault(); if(payment == null) return null; var txId = tx.GetHash(); var txout = tx.Outputs.First(o => o.ScriptPubKey == payment.ScriptPubKey); return new StealthCoin(new OutPoint(txId, tx.Outputs.IndexOf(txout)), txout, payment.Redeem, payment.Metadata, address); }