Created
January 29, 2015 21:17
-
-
Save jorilallo/c72e2211b7b8d3770bc3 to your computer and use it in GitHub Desktop.
Coinbase Exchange signing with Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "base64" | |
require 'openssl' | |
require 'json' | |
class CoinbaseExchange | |
def initialize(key, secret, passphrase) | |
@key = key | |
@secret = secret | |
@passphrase = passphrase | |
end | |
def signature(request_url='', body='', timestamp=nil, method='GET') | |
body = body.to_json if body.is_a?(Hash) | |
timestamp = Time.now.to_i if !timestamp | |
what = "#{timestamp}#{method}#{request_url}#{body}"; | |
# create a sha256 hmac with the secret | |
secret = Base64.decode64(@secret) | |
hash = OpenSSL::HMAC.digest('sha256', secret, what) | |
Base64.encode64(hash) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment