Example #1
0
        private T sendECCRequest <T>(string endpoint, NameValueCollection options, bool newAccount = false)
        {
            var cli = new WebClient();

            if (!newAccount)
            {
                options.Add("endpoint", endpoint);
                options.Add("nonce", generateNonce());
                cli.Headers.Add("cpt-ecc-pub", CoinapultAPI.sha256(eccPubPEM));
            }
            else
            {
                cli.Headers.Add("cpt-ecc-new",
                                Convert.ToBase64String(Encoding.ASCII.GetBytes(eccPubPEM)));
            }
            options.Add("timestamp", timestampNow().ToString());

            var dictOptions = new Dictionary <string, string> ();

            foreach (string key in options.Keys)
            {
                dictOptions.Add(key, options [key]);
            }
            var data     = JsonConvert.SerializeObject(dictOptions);
            var signdata = Convert.ToBase64String(Encoding.ASCII.GetBytes(data));

            cli.Headers.Add("cpt-ecc-sign", CoinapultECC.generateSign(Encoding.ASCII.GetBytes(signdata), eccPriv));

            return(makePostRequest <T> (endpoint, cli, signdata));
        }
Example #2
0
        public CoinapultAPI(string secret)
        {
            /* Authentication method: ECC */
            authMethod = "ecc";
            AsymmetricCipherKeyPair kp = CoinapultECC.importFromPEM(secret);

            eccPub    = kp.Public;
            eccPubPEM = CoinapultECC.exportPubToPEM(eccPub).Trim();
            eccPriv   = kp.Private;

            initialize();
            COINAPULT_PUBKEY = CoinapultECC.importPublicFromPEM(CoinapultECC.COINAPULT_PUBLIC_KEY);
        }
Example #3
0
 private T receiveECC <T>(ECCJson resp)
 {
     if (resp.sign != null && resp.data != null)
     {
         if (!CoinapultECC.verifySign(resp.sign, Encoding.ASCII.GetBytes(resp.data), COINAPULT_PUBKEY))
         {
             throw new CoinapultExceptionECC("Invalid ECC signature");
         }
         var data = Encoding.ASCII.GetString(Convert.FromBase64String(resp.data));
         return(JsonConvert.DeserializeObject <T> (data));
     }
     else
     {
         Console.WriteLine(JsonConvert.SerializeObject(resp, Formatting.Indented));
         throw new CoinapultExceptionECC("Invalid ECC message");
     }
 }