/// <summary>
        /// Sign the transaction by RLP encoding it and calculating the signature of the resulting byte[].
        /// </summary>
        /// <param name="transaction">The transaction that will be signed.</param>
        /// <param name="key">The key with which the transaction will be signed.</param>
        /// <returns>The signed transaction</returns>
        public static RawTransaction Sign(this RawTransaction transaction, ECKeyPair key)
        {
            var rlp = RlpEncoder.Encode(new RlpTransaction(transaction).AsRlpValues());

            SignatureData signatureData = ECDSASign.SignMessage(rlp, key, true);

            transaction.signature = signatureData.ToByteArray();

            return(transaction);
        }
Exemple #2
0
        /// <summary>
        /// Sign the raw transaction.
        /// </summary>
        /// <param name="rawTransaction">
        ///            <seealso cref="RawTransaction"/> </param>
        /// <returns> <seealso cref="RawTransaction"/> with signature. </returns>
        public static RawTransaction Sign(RawTransaction rawTransaction, ECKeyPair keyPair)
        {
            if (rawTransaction == null)
            {
                throw ClientArgumentException.Exception("raw transaction object is invalid");
            }
            var signature = ECDSASign.SignMessage(rawTransaction.Encode(), keyPair, true);
            var signBytes = signature.ToByteArray();

            rawTransaction.Signature = signBytes;
            return(rawTransaction);
        }
Exemple #3
0
        public Transaction Sign(ECKeyPair key)
        {
            var hash = Hash.Blake2B(RlpDataForSignature);

            var sig = ECDSASign.SignMessage(hash, key, false);

            var sigBytes = sig.ToByteArray();

            signature = sigBytes.ToHex(true);

            var signer = key.GetRawAddress();

            byte[] concatenatedBytes = new byte[52];
            Unsafe.CopyBlock(ref concatenatedBytes[0], ref hash[0], (uint)hash.Length);
            Unsafe.CopyBlock(ref concatenatedBytes[hash.Length], ref signer[0], (uint)signer.Length);

            byte[] txIdBytes = Hash.Blake2B(concatenatedBytes);
            id = txIdBytes.ToHex(true);

            return(this);
        }
Exemple #4
0
        public static string BuildSignature(byte[] cert, byte[] txRawHash, string privateKey)
        {
            var txRawBytes  = CryptoUtils.Blake2b(txRawHash);
            var cerHexBytes = CryptoUtils.Sha256(cert);

            var message = new byte[txRawBytes.Length + cerHexBytes.Length];

            Array.Copy(cerHexBytes, 0, message, 0, cerHexBytes.Length);
            Array.Copy(txRawBytes, 0, message, cerHexBytes.Length, txRawBytes.Length);

            var key       = ECKeyPair.Create(ByteUtils.ToByteArray(privateKey));
            var signature = ECDSASign.SignMessage(CryptoUtils.Sha256(message), key, false);

            var signBytes = signature.ToByteArray();

            _logger.Info("signature: {} {}", ByteUtils.ToHexString(signBytes, null),
                         ByteUtils.CleanHexPrefix(ByteUtils.ToHexString(signature.R, Prefix.ZeroLowerX))
                         + ByteUtils.CleanHexPrefix(ByteUtils.ToHexString(signature.S, Prefix.ZeroLowerX)) + "0"
                         + signature.V);
            return(ByteUtils.ToHexString(signBytes, null));
        }