protected override async Task ProcessRequestAsync(HttpWebRequest request, Dictionary <string, object> payload)
        {
            // Only Private APIs are POST and need Authorization
            if (CanMakeAuthenticatedRequest(payload) && request.Method == "POST")
            {
                string requestContentBase64String = string.Empty;
                string nonce = payload["nonce"] as string;
                payload.Remove("nonce");

                string jsonContent = CryptoUtility.GetJsonForPayload(payload);
                if (!String.IsNullOrEmpty(jsonContent))
                {
                    using (MD5 md5 = MD5.Create())
                    {
                        requestContentBase64String = Convert.ToBase64String(md5.ComputeHash(Encoding.UTF8.GetBytes(jsonContent)));
                    }
                }
                else
                {
                    request.ContentLength = 0;
                }

                string baseSig   = string.Concat(PublicApiKey.ToUnsecureString(), request.Method, Uri.EscapeDataString(request.RequestUri.AbsoluteUri).ToLower(), nonce, requestContentBase64String);
                string signature = CryptoUtility.SHA256SignBase64(baseSig, Convert.FromBase64String(PrivateApiKey.ToUnsecureString()));
                request.Headers.Add(HttpRequestHeader.Authorization, string.Format("amx {0}:{1}:{2}", PublicApiKey.ToUnsecureString(), signature, nonce));

                // Cryptopia is very picky on how the payload is passed. There might be a better way to do this, but this works...
                using (Stream stream = await request.GetRequestStreamAsync())
                {
                    byte[] content = Encoding.UTF8.GetBytes(jsonContent);
                    stream.Write(content, 0, content.Length);
                }
            }
        }
Esempio n. 2
0
        protected override async Task ProcessRequestAsync(IHttpWebRequest request, Dictionary <string, object> payload)
        {
            if (CanMakeAuthenticatedRequest(payload))
            {
                request.AddHeader("KC-API-KEY", PublicApiKey.ToUnsecureString());
                request.AddHeader("KC-API-TIMESTAMP", payload["nonce"].ToStringInvariant());
                request.AddHeader("KC-API-PASSPHRASE", CryptoUtility.SHA256Sign(Passphrase.ToUnsecureString(), PrivateApiKey.ToUnsecureString(), true));
                var endpoint = request.RequestUri.PathAndQuery;
                //For Gets, Deletes, no need to add the parameters in JSON format
                var message = "";
                var sig     = "";
                if (request.Method == "GET" || request.Method == "DELETE")
                {
                    //Request will be a querystring
                    message = string.Format("{0}{1}{2}", payload["nonce"], request.Method, endpoint);
                    sig     = CryptoUtility.SHA256Sign(message, PrivateApiKey.ToUnsecureString(), true);
                }
                else if (request.Method == "POST")
                {
                    message = string.Format("{0}{1}{2}{3}", payload["nonce"], request.Method, endpoint, CryptoUtility.GetJsonForPayload(payload, true));
                    sig     = CryptoUtility.SHA256Sign(message, PrivateApiKey.ToUnsecureString(), true);
                }
                request.AddHeader("KC-API-KEY-VERSION", 2.ToStringInvariant());
                request.AddHeader("KC-API-SIGN", sig);
            }

            if (request.Method == "POST")
            {
                string msg     = CryptoUtility.GetJsonForPayload(payload, true);
                byte[] content = msg.ToBytesUTF8();
                await request.WriteAllAsync(content, 0, content.Length);
            }
        }
Esempio n. 3
0
        /// <inheritdoc />
        protected override async Task ProcessRequestAsync(IHttpWebRequest request, Dictionary <string, object> payload)
        {
            if (CanMakeAuthenticatedRequest(payload))
            {
                string timestamp = payload["nonce"].ToStringInvariant();

                payload.Remove("nonce");

                string form = CryptoUtility.GetJsonForPayload(payload);

                //Create the signature payload
                string toHash = $"{timestamp}{request.Method.ToUpperInvariant()}{request.RequestUri.PathAndQuery}";

                if (request.Method == "POST")
                {
                    toHash += form;

                    await CryptoUtility.WriteToRequestAsync(request, form);
                }

                byte[] secret = CryptoUtility.ToUnsecureBytesUTF8(PrivateApiKey);

                string signatureHexString = CryptoUtility.SHA256Sign(toHash, secret);

                request.AddHeader("FTX-KEY", PublicApiKey.ToUnsecureString());
                request.AddHeader("FTX-SIGN", signatureHexString);
                request.AddHeader("FTX-TS", timestamp);
            }
        }
Esempio n. 4
0
        protected override async Task ProcessRequestAsync(IHttpWebRequest request, Dictionary <string, object> payload)
        {
            if (CanMakeAuthenticatedRequest(payload))
            {
                // convert nonce to long, trim off milliseconds
                var nonce = payload["nonce"].ConvertInvariant <long>();
                payload.Remove("nonce");
                var stringToCommit = String.Empty;
                if (request.Method == "POST")
                {
                    var msg = CryptoUtility.GetJsonForPayload(payload);
                    stringToCommit = $"{nonce}{msg}";
                    await request.WritePayloadJsonToRequestAsync(payload);
                }
                else if (request.Method == "GET")
                {
                    stringToCommit = $"{nonce}{request.RequestUri.PathAndQuery}";
                }
                else
                {
                    throw new APIException($"BitBank does not support {request.Method} as its HTTP method!");
                }
                string signature = CryptoUtility.SHA256Sign(stringToCommit, CryptoUtility.ToUnsecureBytesUTF8(PrivateApiKey));

                request.AddHeader("ACCESS-NONCE", nonce.ToStringInvariant());
                request.AddHeader("ACCESS-KEY", PublicApiKey.ToUnsecureString());
                request.AddHeader("ACCESS-SIGNATURE", signature);
            }
            return;
        }
Esempio n. 5
0
 protected override async Task ProcessRequestAsync(IHttpWebRequest request, Dictionary <string, object> payload)
 {
     if (CanMakeAuthenticatedRequest(payload))
     {
         if (request.Method == "POST")
         {
             request.AddHeader("content-type", "application/json");
             payload.Remove("nonce");
             var msg = CryptoUtility.GetJsonForPayload(payload);
             await CryptoUtility.WriteToRequestAsync(request, msg);
         }
     }
 }
        protected override async Task ProcessRequestAsync(HttpWebRequest request, Dictionary <string, object> payload)
        {
            if (CanMakeAuthenticatedRequest(payload))
            {
                var nonce = payload["nonce"].ConvertInvariant <long>();
                payload.Remove("nonce");
                var    msg       = CryptoUtility.GetJsonForPayload(payload);
                var    sign      = $"{request.Method}{request.RequestUri.AbsolutePath}{request.RequestUri.Query}{nonce}{msg}";
                string signature = CryptoUtility.SHA256Sign(sign, CryptoUtility.ToBytes(PrivateApiKey));

                request.Headers["api-nonce"]     = nonce.ToStringInvariant();
                request.Headers["api-key"]       = PublicApiKey.ToUnsecureString();
                request.Headers["api-signature"] = signature;

                await CryptoUtility.WritePayloadJsonToRequestAsync(request, payload);
            }
        }
Esempio n. 7
0
        protected override async Task ProcessRequestAsync(IHttpWebRequest request, Dictionary <string, object> payload)
        {
            if (CanMakeAuthenticatedRequest(payload))
            {
                // convert nonce to long, trim off milliseconds
                var nonce = payload["nonce"].ConvertInvariant <long>();
                payload.Remove("nonce");
                var    msg       = CryptoUtility.GetJsonForPayload(payload);
                var    sign      = $"{request.Method}{request.RequestUri.AbsolutePath}{request.RequestUri.Query}{nonce}{msg}";
                string signature = CryptoUtility.SHA256Sign(sign, CryptoUtility.ToUnsecureBytesUTF8(PrivateApiKey));

                request.AddHeader("api-expires", nonce.ToStringInvariant());
                request.AddHeader("api-key", PublicApiKey.ToUnsecureString());
                request.AddHeader("api-signature", signature);

                await CryptoUtility.WritePayloadJsonToRequestAsync(request, payload);
            }
        }
Esempio n. 8
0
 protected override async Task ProcessRequestAsync(HttpWebRequest request, Dictionary <string, object> payload)
 {
     if (CanMakeAuthenticatedRequest(payload))
     {
         // gdax is funny and wants a seconds double for the nonce, weird... we convert it to double and back to string invariantly to ensure decimal dot is used and not comma
         string timestamp = payload["nonce"].ToStringInvariant();
         payload.Remove("nonce");
         string form   = CryptoUtility.GetJsonForPayload(payload);
         byte[] secret = CryptoUtility.ToBytesBase64Decode(PrivateApiKey);
         string toHash = timestamp + request.Method.ToUpper() + request.RequestUri.PathAndQuery + form;
         string signatureBase64String = CryptoUtility.SHA256SignBase64(toHash, secret);
         secret = null;
         toHash = null;
         request.Headers["CB-ACCESS-KEY"]        = PublicApiKey.ToUnsecureString();
         request.Headers["CB-ACCESS-SIGN"]       = signatureBase64String;
         request.Headers["CB-ACCESS-TIMESTAMP"]  = timestamp;
         request.Headers["CB-ACCESS-PASSPHRASE"] = CryptoUtility.ToUnsecureString(Passphrase);
         await CryptoUtility.WriteToRequestAsync(request, form);
     }
 }
Esempio n. 9
0
        protected override async Task ProcessRequestAsync(IHttpWebRequest request, Dictionary <string, object> payload)
        {
            if (CanMakeAuthenticatedRequest(payload))
            {
                payload.Remove("nonce");
                string body      = CryptoUtility.GetJsonForPayload(payload);
                string timestamp = ((int)CryptoUtility.UtcNow.UnixTimestampFromDateTimeSeconds()).ToStringInvariant();
                string msg       = timestamp + request.Method + request.RequestUri.PathAndQuery + (request.Method.Equals("POST") ? body : string.Empty);
                string sign      = CryptoUtility.SHA256SignBase64(msg, CryptoUtility.ToBytesBase64Decode(PrivateApiKey));

                request.AddHeader("AC-ACCESS-KEY", CryptoUtility.ToUnsecureString(PublicApiKey));
                request.AddHeader("AC-ACCESS-SIGN", sign);
                request.AddHeader("AC-ACCESS-TIMESTAMP", timestamp);
                request.AddHeader("AC-ACCESS-PASSPHRASE", CryptoUtility.ToUnsecureString(Passphrase));

                if (request.Method == "POST")
                {
                    await CryptoUtility.WriteToRequestAsync(request, body);
                }
            }
        }