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();
        }
Пример #2
0
        public TransactionSignature Sign(Key key, Script scriptPubKey, SigHash sigHash = SigHash.All)
        {
            var hash = GetSignatureHash(scriptPubKey, sigHash);

            return(key.Sign(hash, sigHash));
        }
Пример #3
0
 public void SignAll(Key key)
 {
     for(int i = 0 ; i < Inputs.Count ; i++)
     {
         if(Inputs[i].ScriptSig == null)
             Inputs[i].ScriptSig = new PayToPubkeyHashTemplate().GenerateScriptPubKey(key.PubKey);
     }
     for(int i = 0 ; i < Inputs.Count ; i++)
     {
         var hash = Inputs[i].ScriptSig.SignatureHash(this, i, SigHash.All);
         var sig = key.Sign(hash);
         Inputs[i].ScriptSig
             = new PayToPubkeyHashTemplate().GenerateScriptSig(new TransactionSignature(sig, SigHash.All), key.PubKey);
     }
 }
Пример #4
0
        public TransactionSignature Sign(Key key, ICoin coin, SigHash sigHash)
        {
            var hash = GetSignatureHash(coin, sigHash);

            return(key.Sign(hash, sigHash));
        }