Class: Fireblocks::Token
- Inherits:
-
Object
- Object
- Fireblocks::Token
- Defined in:
- lib/fireblocks/api/token.rb
Overview
This class will issue a new Fireblocks token
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #body_hash ⇒ Object
- #call ⇒ Object
- #created_at ⇒ Object
- #decode_token ⇒ Object
- #expire_at ⇒ Object
-
#initialize(body, uri) ⇒ Token
constructor
A new instance of Token.
- #jwt_headers ⇒ Object
- #nonce ⇒ Object
- #rsa_private ⇒ Object
Constructor Details
#initialize(body, uri) ⇒ Token
Returns a new instance of Token.
18 19 20 21 |
# File 'lib/fireblocks/api/token.rb', line 18 def initialize(body, uri) @body = body @uri = uri end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
16 17 18 |
# File 'lib/fireblocks/api/token.rb', line 16 def body @body end |
#uri ⇒ Object
Returns the value of attribute uri.
16 17 18 |
# File 'lib/fireblocks/api/token.rb', line 16 def uri @uri end |
Class Method Details
.call(body, uri) ⇒ Object
11 12 13 |
# File 'lib/fireblocks/api/token.rb', line 11 def call(body, uri) new(body, uri).call end |
Instance Method Details
#body_hash ⇒ Object
35 36 37 |
# File 'lib/fireblocks/api/token.rb', line 35 def body_hash Digest::SHA256.hexdigest(body.to_json) end |
#call ⇒ Object
31 32 33 |
# File 'lib/fireblocks/api/token.rb', line 31 def call JWT.encode jwt_headers, rsa_private, 'RS256', typ: 'JWT' end |
#created_at ⇒ Object
23 24 25 |
# File 'lib/fireblocks/api/token.rb', line 23 def created_at Time.now.to_i end |
#decode_token ⇒ Object
39 40 41 |
# File 'lib/fireblocks/api/token.rb', line 39 def decode_token JWT.decode token, rsa_private.public_key, true, algorithm: 'RS256' end |
#expire_at ⇒ Object
27 28 29 |
# File 'lib/fireblocks/api/token.rb', line 27 def expire_at Time.now.to_i + 55 end |
#jwt_headers ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fireblocks/api/token.rb', line 43 def jwt_headers { uri: uri.request_uri, nonce: nonce, iat: created_at, exp: expire_at, sub: Fireblocks.configuration.api_key, bodyHash: body_hash } end |
#nonce ⇒ Object
54 55 56 |
# File 'lib/fireblocks/api/token.rb', line 54 def nonce "#{Time.now.to_i}#{Time.now.nsec}".to_i end |
#rsa_private ⇒ Object
58 59 60 |
# File 'lib/fireblocks/api/token.rb', line 58 def rsa_private OpenSSL::PKey::RSA.new(Fireblocks.configuration.private_key) end |