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

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

            return(result == null ? null : result.PublicKey);
        }
Esempio n. 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);
        }
Esempio n. 4
0
        public BitcoinScriptAddress GetScriptAddress()
        {
            if (this is BitcoinScriptAddress)
            {
                return((BitcoinScriptAddress)this);
            }
            var redeem = new PayToPubkeyHashTemplate().GenerateScriptPubKey(this);

            return(new BitcoinScriptAddress(redeem.ID, Network));
        }
Esempio n. 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();
 }
Esempio n. 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();
 }
Esempio n. 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);
 }
Esempio n. 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();
            }
        }
Esempio n. 9
0
 public PubKey GetSourcePubKey()
 {
     var template = new PayToPubkeyHashTemplate();
     var result = template.ExtractScriptSigParameters(this);
     return result == null ? null : result.PublicKey;
 }
Esempio n. 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;
 }
Esempio n. 11
0
 public void SetDestination(BitcoinAddress address)
 {
     ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(address);
 }
Esempio n. 12
0
 private void SetDestination(KeyId keyId)
 {
     ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(keyId);
 }
Esempio n. 13
0
 public bool IsFrom(PubKey pubKey)
 {
     var template = new PayToPubkeyHashTemplate();
     var result = template.ExtractScriptSigParameters(ScriptSig);
     return result != null && result.PublicKey == pubKey;
 }
Esempio n. 14
0
 public void SetDestination(BitcoinAddress address)
 {
     ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(address);
 }
Esempio n. 15
0
 private void SetDestination(KeyId keyId)
 {
     ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(keyId);
 }
Esempio n. 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();
            }
        }
Esempio n. 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;
 }