예제 #1
0
        public EthECDSASignature Sign(string contract, string makerAddress, string makerToken,
                                      string takerToken, string makerAmount, string takerAmount, string expires, string nonce)
        {
            var plainData = new Object[]
            {
                contract,
                takerToken,
                BigInteger.Parse(takerAmount),
                makerToken,
                BigInteger.Parse(makerAmount),
                BigInteger.Parse(expires),
                BigInteger.Parse(nonce)
            };

            var prms = new[] {
                new Parameter("address", 1),
                new Parameter("address", 1),
                new Parameter("uint256", 1),
                new Parameter("address", 1),
                new Parameter("uint256", 1),
                new Parameter("uint256", 1),
                new Parameter("uint256", 1)
            };


            var data = SolidityPack(plainData, prms);



            var keystoreCrypto = new KeyStoreCrypto();
            //for etherDelta its SHA256, for IDEX just change with SHA3
            var hashed = keystoreCrypto.CalculateSha256Hash(data);


            var signer  = new EthereumMessageSigner();
            var newHash = signer.HashPrefixedMessage(hashed);


            var signatureRaw = signer.SignAndCalculateV(newHash, _userDataProvider.PrivateKey);
            var signature    = EthECDSASignature.CreateStringSignature(signatureRaw);
            var probe        = signer.EcRecover(hashed, signature);


            var ethEcdsa = MessageSigner.ExtractEcdsaSignature(signature);

            if (probe == makerAddress)
            {
                return(ethEcdsa);
            }
            //depending on usage, but it would be better to throw exc here if fails
            return(null);

            //throw new Exception("Signing failed");
        }