Example #1
0
		public Script GenerateScriptSig(TransactionSignature[] signatures, Script redeemScript)
		{
			List<Op> ops = new List<Op>();
			PayToMultiSigTemplate multiSigTemplate = new PayToMultiSigTemplate();
			bool multiSig = multiSigTemplate.CheckScriptPubKey(redeemScript);
			if(multiSig)
				ops.Add(OpcodeType.OP_0);
			foreach(var sig in signatures)
			{
				ops.Add(sig == null ? OpcodeType.OP_0 : Op.GetPushOp(sig.ToBytes()));
			}
			return GenerateScriptSig(ops.ToArray(), redeemScript);
		}
Example #2
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();
 }
Example #3
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();
 }
Example #4
0
        public IEnumerable <KeyId> GetDestinations()
        {
            var single = GetDestination();

            if (single != null)
            {
                yield return(single);
            }
            else
            {
                var result = new PayToMultiSigTemplate().ExtractScriptPubKeyParameters(this);
                if (result != null)
                {
                    foreach (var key in result.PubKeys)
                    {
                        yield return(key.ID);
                    }
                }
            }
        }
Example #5
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();
            }
        }
Example #6
0
        /// <summary>
        /// Extract public keys if this script is a multi sig or pay to pub key scriptPubKey
        /// </summary>
        /// <param name="network"></param>
        /// <returns></returns>
        public PubKey[] GetDestinationPublicKeys()
        {
            List <PubKey> result = new List <PubKey>();
            var           single = new PayToPubkeyTemplate().ExtractScriptPubKeyParameters(this);

            if (single != null)
            {
                result.Add(single);
            }
            else
            {
                var multiSig = new PayToMultiSigTemplate().ExtractScriptPubKeyParameters(this);
                if (multiSig != null)
                {
                    foreach (var key in multiSig.PubKeys)
                    {
                        result.Add(key);
                    }
                }
            }
            return(result.ToArray());
        }
		public Script GenerateScriptSig(TransactionSignature[] signatures, Script redeemScript)
		{
			List<Op> ops = new List<Op>();
			PayToMultiSigTemplate multiSigTemplate = new PayToMultiSigTemplate();
			bool multiSig = multiSigTemplate.CheckScriptPubKey(redeemScript);
			if(multiSig)
				ops.Add(OpcodeType.OP_0);
			foreach(var sig in signatures)
			{
				ops.Add(sig == null ? OpcodeType.OP_0 : Op.GetPushOp(sig.ToBytes()));
			}
			return GenerateScriptSig(ops.ToArray(), redeemScript);
		}
Example #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();
            }
        }
Example #9
0
 public IEnumerable<KeyId> GetDestinations()
 {
     var single = GetDestination();
     if(single != null)
     {
         yield return single;
     }
     else
     {
         var result = new PayToMultiSigTemplate().ExtractScriptPubKeyParameters(this);
         if(result != null)
         {
             foreach(var key in result.PubKeys)
             {
                 yield return key.ID;
             }
         }
     }
 }