Bitcoin Forum
February 07, 2025, 03:16:16 PM *
News: Community Awards voting is open
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Bitcoin Technical Support / [C#] Could use some help with authenticated requests with MtGox API v2 on: May 14, 2013, 03:54:15 AM
For fun (and to teach myself some C#) I've been integrating someone's C# socket.io class with MtGox's API.  I can currently recieve and parse all the public information (trades, depth, ticker, lag).  That's all peachy.  My issue is with authenticated requests.  I've been trying to follow along and convert the code example listed at  https://en.bitcoin.it/wiki/MtGox/API/Streaming.  Here's the part I'm interested in replicating:

Code:
$nonce = explode(' ', microtime(false));
$nonce = $nonce[1].substr($nonce[0], 2, 6);
$id = md5($nonce); // id can be anything to recognize this call
$query = array('call' => $call, 'params' => $params, 'item' => $item, 'currency' => $currency, 'id' => $id, 'nonce' => $nonce);
$query = json_encode($query);
// generate signature
$sign = hash_hmac('sha512', $query, base64_decode($apiSecret), true);
// prefix signature to query
$query = pack('H*', str_replace('-','',$apiKey)).$sign.$query;
// send query
$call = array('op' => 'call', 'call' => base64_encode($query), 'id' => $id, 'context' => 'mtgox.com');
// $call can now be pushed out to the websocket

Essentially what happens is once I try to make the authenticated call, my socket immediately drops connection.  I do have try/catch all over the place (including some added to the socket.io and websocket classes I aquired) but it doesn't seem to be causing any errors, and no op:remark comes back from the server. It just dies. Poof. gonzo. Dead as a doornail.

So now in order to try and reclaim what little sanity I may have left, I'm asking for some advice.  Yes, I do realize I could just flip to another language and all is good, but I'm trying to pick up C# for my day-job.

I believe that my JSON is well-formed, but I think my issue with the code lies within the encoding/hashing algorithms. 

The call I'm specifically trying to make is to "private/info".  Here is what I have for each encoded/decoded/hashed value:

$ID:
Code:
string nonce = DateTime.Now.Ticks.ToString();
string id = Encoding.UTF8.GetString(md5Hash.ComputeHash(Encoding.UTF8.GetBytes(nonce)))

$SIGN:
Code:
protected string EncodeSign(string query)
{
   var hmacsha512 = new HMACSHA512(Convert.FromBase64String(this.apiSecret));
   var byteArray = hmacsha512.ComputeHash( Encoding.UTF8.GetBytes(query));
   return Encoding.UTF8.GetString(byteArray);
}

$KEY:
Code:
string key = HexToString(apiKey.Replace("-", ""));

protected string HexToString(string hex)
{
   var buffer = new byte[hex.Length / 2];
   for (int i = 0; i < hex.Length; i += 2)
   {
       string hexdec = hex.Substring(i, 2);
       buffer[i / 2] = byte.Parse(hexdec, NumberStyles.HexNumber);
   }
   return Encoding.UTF8.GetString(buffer);
}


$QUERY (the pack() line, not the json_encode line)
Code:
encQuery = key + encQuery + sb.ToString();     //sb is a StringBuilder object containing the inner query (equivalent of the $query = json_encode($query); line in the PHP example)
System.Convert.ToBase64String(Encoding.UTF8.GetBytes(encQuery)) //This is used in the same way as "base64_encode($query)" in the last line of the PHP example).

Does anyone see an issue with my encoding off the top of their head?  Any help is appreciated.
2  Bitcoin / Bitcoin Discussion / Mentioned this on another forum, but what about this for bitcoin... on: November 04, 2011, 11:03:57 PM
I read a thread in here that reminded me of something I mentioned on reddit a little while back:

If porn helped VHS win over Beta thanks to being cheap and plentiful, why can't porn help bitcoin in the same way?

Shy people making sex-toy purchases online, people signing up to swinger sites, or cheating spouces signing up to Ashleymadison.com etc... I'm sure many of these people would prefer that a payment NOT show up on their credit card statements (even if the transaction shows up under a generic name).  If these sites accepted bitcoin, they may do some extra business.

It's just a thought. With Silk Road doing the business it does, I'm surprised that adult-themed sites haven't started inquiring about this kind of thing.

3  Other / Beginners & Help / Xenland - Readme Please on: October 23, 2011, 05:07:41 AM
Ok so i just signed up so I could offer some advice, unfortuately the post is located in the main Discussion area, to which i don't yet have access...  That said, if anyone with access could just type a nice post in that thread pointing to this this one for him to see, that would be great, thanks. Smiley

Original Thread here:  https://bitcointalk.org/index.php?topic=49457.0

Xenland, to determine in which method you should display pagination, you really do need to determine what kind of data you're displaying.  In your case you gave an example of it being an alphabetical order.  In this case, instead of asking the user to guess a page number that corresponds to the letter, it may benefot you to split the pagination in latter increments, and pages within those letters.

A-E F-K L-S T-Z 0-9 for instance.  Within each of those divisions would be standard numeric pages.  Even better if you provide an overarching search function that will allow people to seek out a title directly without having to remember what page it was on.

Sorry, App developer by trade, *and* I've had quite a few beer, so when I read the post I just felt the need to add my $0.02. Wink

- Effayy
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!