Example #1
0
        public TransactionSignature Sign(Key key, SigHash sigHash)
        {
            CheckCompatibleSigHash(sigHash);

            if (PartialSigs.ContainsKey(key.PubKey))
            {
                var signature = PartialSigs[key.PubKey];
                if (sigHash != signature.SigHash)
                {
                    throw new InvalidOperationException("A signature with a different sighash is already in the partial sigs");
                }
                return(signature);
            }
            if (!IsRelatedKey(key.PubKey))
            {
                return(null);
            }

            var coin = GetSignableCoin();

            if (coin == null)
            {
                return(null);
            }

            var hash       = Transaction.GetSignatureHash(coin, sigHash);
            var signature2 = key.Sign(hash, sigHash, Parent.Settings.UseLowR);

            this.PartialSigs.TryAdd(key.PubKey, signature2);
            return(signature2);
        }
        public static string GetHexSignedTransaction(TransactionToSign txToSign)
        {
            var walletPrivateKey = ConfigurationManager.AppSettings[METACO_ENV_WALLET_PRIVATE_KEY_HEX_NAME];

            var key = new Key(Encoders.Hex.DecodeData(walletPrivateKey));

            var scriptPubKey = PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(key.PubKey);
            var tx = new Transaction(Encoders.Hex.DecodeData(txToSign.Raw));

            foreach(var inputsToSign in txToSign.InputsToSign)
            {
                var sigHash = tx.GetSignatureHash(scriptPubKey, inputsToSign.Index);
                var sig = key.Sign(sigHash);

                var txSign = new TransactionSignature(sig, SigHash.All);
                var inputScript = PayToPubkeyHashTemplate.Instance.GenerateScriptSig(txSign, key.PubKey);

                tx.Inputs[inputsToSign.Index].ScriptSig = inputScript;
                Assert.True(Script.VerifyScript(scriptPubKey, tx, inputsToSign.Index));
            }

            return tx.ToHex();
        }
Example #3
0
 public static uint256 SignatureHash(Script scriptCode, Transaction txTo, int nIn, SigHash nHashType, Money amount, HashVersion sigversion, PrecomputedTransactionData precomputedTransactionData)
 {
     return(txTo.GetSignatureHash(scriptCode, nIn, nHashType, amount, sigversion, precomputedTransactionData));
 }
Example #4
0
 public static uint256 SignatureHash(Script scriptCode, Transaction txTo, int nIn, SigHash nHashType, Money amount = null, HashVersion sigversion = HashVersion.Original)
 {
     return(txTo.GetSignatureHash(scriptCode, nIn, nHashType, amount, sigversion, null));
 }
Example #5
0
 public static uint256 SignatureHash(ICoin coin, Transaction txTo, SigHash nHashType = SigHash.All)
 {
     return(txTo.GetSignatureHash(coin, nHashType));
 }