public static SignedTransactionBase CreateTransaction(string to, BigInteger gas, BigInteger gasPrice, BigInteger amount, string data, BigInteger nonce, string r, string s, string v)
        {
            var rBytes = r.HexToByteArray();
            var sBytes = s.HexToByteArray();
            var vBytes = v.HexToByteArray();

            var signature = EthECDSASignatureFactory.FromComponents(rBytes, sBytes, vBytes);

            if (signature.IsVSignedForChain())
            {
                var vBigInteger = vBytes.ToBigIntegerFromRLPDecoded();
                var chainId     = EthECKey.GetChainFromVChain(vBigInteger);
                return(new TransactionChainId(nonce.ToBytesForRLPEncoding(), gasPrice.ToBytesForRLPEncoding(), gas.ToBytesForRLPEncoding(),
                                              to.HexToByteArray(), amount.ToBytesForRLPEncoding(), data.HexToByteArray(), chainId.ToBytesForRLPEncoding(), rBytes, sBytes, vBytes));
            }
            else
            {
                return(new Transaction(nonce.ToBytesForRLPEncoding(), gasPrice.ToBytesForRLPEncoding(), gas.ToBytesForRLPEncoding(),
                                       to.HexToByteArray(), amount.ToBytesForRLPEncoding(), data.HexToByteArray(), rBytes, sBytes, vBytes[0]));
            }
        }
예제 #2
0
        public static SignedData DecodeSigned(byte[] rawdata, int numberOfEncodingElements)
        {
            var decodedList             = RLP.RLP.Decode(rawdata);
            var decodedData             = new List <byte[]>();
            var decodedElements         = (RLPCollection)decodedList;
            EthECDSASignature signature = null;

            for (var i = 0; i < numberOfEncodingElements; i++)
            {
                decodedData.Add(decodedElements[i].RLPData);
            }
            // only parse signature in case is signed
            if (decodedElements[numberOfEncodingElements].RLPData != null)
            {
                //Decode Signature
                var v = decodedElements[numberOfEncodingElements].RLPData;
                var r = decodedElements[numberOfEncodingElements + 1].RLPData;
                var s = decodedElements[numberOfEncodingElements + 2].RLPData;
                signature = EthECDSASignatureFactory.FromComponents(r, s, v);
            }
            return(new SignedData(decodedData.ToArray(), signature));
        }
예제 #3
0
 public static EthECDSASignature ExtractEcdsaSignature(string signature)
 {
     return(EthECDSASignatureFactory.ExtractECDSASignature(signature));
 }
예제 #4
0
 public RLPSigner(byte[][] data, byte[] r, byte[] s, byte[] v, int numberOfEncodingElements)
 {
     this.numberOfEncodingElements = numberOfEncodingElements;
     this.Data = data;
     Signature = EthECDSASignatureFactory.FromComponents(r, s, v);
 }