Skip to content

Instantly share code, notes, and snippets.

@jorilallo
Created January 29, 2015 21:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorilallo/c72e2211b7b8d3770bc3 to your computer and use it in GitHub Desktop.
Save jorilallo/c72e2211b7b8d3770bc3 to your computer and use it in GitHub Desktop.
Coinbase Exchange signing with Ruby
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