Beispiel #1
0
        public bool IsFrom(PubKey pubKey)
        {
            var template = new PayToPubkeyHashTemplate();
            var result   = template.ExtractScriptSigParameters(ScriptSig);

            return(result != null && result.PublicKey == pubKey);
        }
Beispiel #2
0
        public PubKey GetSourcePubKey()
        {
            var template = new PayToPubkeyHashTemplate();
            var result   = template.ExtractScriptSigParameters(this);

            return(result == null ? null : result.PublicKey);
        }
Beispiel #3
0
        public KeyId GetDestination()
        {
            var template        = FindTemplate();
            var payToPubKeyHash = template as PayToPubkeyHashTemplate;

            if (payToPubKeyHash != null)
            {
                return(payToPubKeyHash.ExtractScriptPubKeyParameters(this));
            }
            var payToPubKey = template as PayToPubkeyTemplate;

            if (payToPubKey != null)
            {
                var result = new PayToPubkeyHashTemplate().ExtractScriptPubKeyParameters(this);
                if (result == null)
                {
                    var pub = new PayToPubkeyTemplate().ExtractScriptPubKeyParameters(this);
                    if (pub != null)
                    {
                        return(pub.ID);
                    }
                }
            }
            return(null);
        }
Beispiel #4
0
        public BitcoinScriptAddress GetScriptAddress()
        {
            if (this is BitcoinScriptAddress)
            {
                return((BitcoinScriptAddress)this);
            }
            var redeem = new PayToPubkeyHashTemplate().GenerateScriptPubKey(this);

            return(new BitcoinScriptAddress(redeem.ID, Network));
        }
Beispiel #5
0
 public StealthPayment(int sigCount, PubKey[] spendPubKeys, Key privateKey, PubKey publicKey, StealthMetadata metadata)
 {
     Metadata = metadata;
     if(sigCount == 1 && spendPubKeys.Length == 1)
     {
         var template = new PayToPubkeyHashTemplate();
         SpendableScript = template.GenerateScriptPubKey(spendPubKeys[0].Uncover(privateKey, publicKey).ID);
     }
     else
     {
         var template = new PayToMultiSigTemplate();
         SpendableScript = template.GenerateScriptPubKey(sigCount, spendPubKeys.Select(p => p.Uncover(privateKey, publicKey)).ToArray());
     }
     ParseSpendable();
 }
Beispiel #6
0
 public StealthPayment(int sigCount, PubKey[] spendPubKeys, Key privateKey, PubKey publicKey, StealthMetadata metadata)
 {
     Metadata = metadata;
     if (sigCount == 1 && spendPubKeys.Length == 1)
     {
         var template = new PayToPubkeyHashTemplate();
         SpendableScript = template.GenerateScriptPubKey(spendPubKeys[0].Uncover(privateKey, publicKey).ID);
     }
     else
     {
         var template = new PayToMultiSigTemplate();
         SpendableScript = template.GenerateScriptPubKey(sigCount, spendPubKeys.Select(p => p.Uncover(privateKey, publicKey)).ToArray());
     }
     ParseSpendable();
 }
Beispiel #7
0
 public bool SignedByMe(Transaction tx)
 {
     for (int i = 0; i < tx.Inputs.Count; i++)
     {
         var vin = tx.Inputs[i];
         var key = GetKey(vin.ScriptSig.GetSourcePubKey());
         if (key == null)
         {
             return(false);
         }
         var pubkeyScript = new PayToPubkeyHashTemplate().GenerateScriptPubKey(key.PubKey);
         var eval         = new ScriptEvaluationContext();
         eval.SigHash = SigHash.All;
         if (!eval.VerifyScript(vin.ScriptSig, pubkeyScript, tx, i))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #8
0
        private void ParseSpendable()
        {
            List <KeyId> pubkeys = new List <KeyId>();

            var payToHash = new PayToPubkeyHashTemplate();
            var keyId     = payToHash.ExtractScriptPubKeyParameters(SpendableScript);

            if (keyId != null)
            {
                StealthKeys = new StealthSpendKey[] { new StealthSpendKey(keyId, this) };
            }
            else
            {
                var payToMultiSig = new PayToMultiSigTemplate();
                var para          = payToMultiSig.ExtractScriptPubKeyParameters(SpendableScript);
                if (para == null)
                {
                    throw new ArgumentException("Invalid stealth spendable output script", "spendable");
                }
                StealthKeys = para.PubKeys.Select(k => new StealthSpendKey(k.ID, this)).ToArray();
            }
        }
Beispiel #9
0
 public PubKey GetSourcePubKey()
 {
     var template = new PayToPubkeyHashTemplate();
     var result = template.ExtractScriptSigParameters(this);
     return result == null ? null : result.PublicKey;
 }
Beispiel #10
0
 public bool SignedByMe(Transaction tx)
 {
     for(int i = 0 ; i < tx.Inputs.Count ; i++)
     {
         var vin = tx.Inputs[i];
         var key = GetKey(vin.ScriptSig.GetSourcePubKey());
         if(key == null)
             return false;
         var pubkeyScript = new PayToPubkeyHashTemplate().GenerateScriptPubKey(key.PubKey);
         var eval = new ScriptEvaluationContext();
         eval.SigHash = SigHash.All;
         if(!eval.VerifyScript(vin.ScriptSig, pubkeyScript, tx, i))
             return false;
     }
     return true;
 }
Beispiel #11
0
 public void SetDestination(BitcoinAddress address)
 {
     ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(address);
 }
Beispiel #12
0
 private void SetDestination(KeyId keyId)
 {
     ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(keyId);
 }
Beispiel #13
0
 public bool IsFrom(PubKey pubKey)
 {
     var template = new PayToPubkeyHashTemplate();
     var result = template.ExtractScriptSigParameters(ScriptSig);
     return result != null && result.PublicKey == pubKey;
 }
Beispiel #14
0
 public void SetDestination(BitcoinAddress address)
 {
     ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(address);
 }
Beispiel #15
0
 private void SetDestination(KeyId keyId)
 {
     ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(keyId);
 }
Beispiel #16
0
        private void ParseSpendable()
        {
            List<KeyId> pubkeys = new List<KeyId>();

            var payToHash = new PayToPubkeyHashTemplate();
            var keyId = payToHash.ExtractScriptPubKeyParameters(SpendableScript);
            if(keyId != null)
            {
                StealthKeys = new StealthSpendKey[] { new StealthSpendKey(keyId, this) };
            }
            else
            {
                var payToMultiSig = new PayToMultiSigTemplate();
                var para = payToMultiSig.ExtractScriptPubKeyParameters(SpendableScript);
                if(para == null)
                    throw new ArgumentException("Invalid stealth spendable output script", "spendable");
                StealthKeys = para.PubKeys.Select(k => new StealthSpendKey(k.ID, this)).ToArray();
            }
        }
Beispiel #17
0
 public KeyId GetDestination()
 {
     var template = FindTemplate();
     var payToPubKeyHash = template as PayToPubkeyHashTemplate;
     if(payToPubKeyHash != null)
     {
         return payToPubKeyHash.ExtractScriptPubKeyParameters(this);
     }
     var payToPubKey = template as PayToPubkeyTemplate;
     if(payToPubKey != null)
     {
         var result = new PayToPubkeyHashTemplate().ExtractScriptPubKeyParameters(this);
         if(result == null)
         {
             var pub = new PayToPubkeyTemplate().ExtractScriptPubKeyParameters(this);
             if(pub != null)
                 return pub.ID;
         }
     }
     return null;
 }