Class: Binance::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/binance/authentication.rb

Overview

Authentication response to API key and signature

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, private_key = nil, private_key_pass_phrase = nil) ⇒ Authentication

Returns a new instance of Authentication.



11
12
13
14
15
16
# File 'lib/binance/authentication.rb', line 11

def initialize(key, secret, private_key = nil, private_key_pass_phrase = nil)
  @key = key
  @secret = secret
  @private_key = private_key
  @private_key_pass_phrase = private_key_pass_phrase
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



9
10
11
# File 'lib/binance/authentication.rb', line 9

def key
  @key
end

#private_keyObject

Returns the value of attribute private_key.



9
10
11
# File 'lib/binance/authentication.rb', line 9

def private_key
  @private_key
end

#private_key_pass_phraseObject

Returns the value of attribute private_key_pass_phrase.



9
10
11
# File 'lib/binance/authentication.rb', line 9

def private_key_pass_phrase
  @private_key_pass_phrase
end

#secretObject

Returns the value of attribute secret.



9
10
11
# File 'lib/binance/authentication.rb', line 9

def secret
  @secret
end

Instance Method Details

#hmac_sign(data) ⇒ Object



22
23
24
25
26
# File 'lib/binance/authentication.rb', line 22

def hmac_sign(data)
  OpenSSL::HMAC.hexdigest(
    OpenSSL::Digest.new('sha256'), secret, data
  )
end

#provide_private_key?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/binance/authentication.rb', line 18

def provide_private_key?
  private_key
end

#rsa_sign(data) ⇒ Object



28
29
30
31
# File 'lib/binance/authentication.rb', line 28

def rsa_sign(data)
  pkey = OpenSSL::PKey::RSA.new(private_key, private_key_pass_phrase)
  Base64.encode64(pkey.sign('SHA256', data))
end