Class: Wazirx::Client::REST::SignRequestMiddleware
- Inherits:
-
Struct
- Object
- Struct
- Wazirx::Client::REST::SignRequestMiddleware
- Defined in:
- lib/wazirx/client/rest/sign_request_middleware.rb
Overview
Sign the query string using HMAC(sha-256) and appends to query string
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app
5 6 7 |
# File 'lib/wazirx/client/rest/sign_request_middleware.rb', line 5 def app @app end |
#secret_key ⇒ Object
Returns the value of attribute secret_key
5 6 7 |
# File 'lib/wazirx/client/rest/sign_request_middleware.rb', line 5 def secret_key @secret_key end |
Instance Method Details
#call(env) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/wazirx/client/rest/sign_request_middleware.rb', line 6 def call(env) key = 'signature' hash = OpenSSL::HMAC.hexdigest( OpenSSL::Digest.new('sha256'), secret_key, env.method == :get ? env.url.query : URI.encode_www_form(JSON.parse(env.body)) ) if env.method == :get env.url.query = REST.add_query_param(env.url.query, 'signature', hash) else body = REST.sort_body env.body, key, hash env.body = URI.encode_www_form(body) end app.call env end |