class Fireblocks::Token

This class will issue a new Fireblocks token

Attributes

body[RW]
uri[RW]

Public Class Methods

call(body, uri) click to toggle source
# File lib/fireblocks/api/token.rb, line 11
def call(body, uri)
  new(body, uri).call
end
new(body, uri) click to toggle source
# File lib/fireblocks/api/token.rb, line 18
def initialize(body, uri)
  @body = body
  @uri = uri
end

Public Instance Methods

body_hash() click to toggle source
# File lib/fireblocks/api/token.rb, line 35
def body_hash
  Digest::SHA256.hexdigest(body.to_json)
end
call() click to toggle source
# File lib/fireblocks/api/token.rb, line 31
def call
  JWT.encode jwt_headers, rsa_private, 'RS256', typ: 'JWT'
end
created_at() click to toggle source
# File lib/fireblocks/api/token.rb, line 23
def created_at
  Time.now.to_i
end
decode_token() click to toggle source
# File lib/fireblocks/api/token.rb, line 39
def decode_token
  JWT.decode token, rsa_private.public_key, true, algorithm: 'RS256'
end
expire_at() click to toggle source
# File lib/fireblocks/api/token.rb, line 27
def expire_at
  Time.now.to_i + 55
end
jwt_headers() click to toggle source
# 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() click to toggle source
# File lib/fireblocks/api/token.rb, line 54
def nonce
  "#{Time.now.to_i}#{Time.now.nsec}".to_i
end
rsa_private() click to toggle source
# File lib/fireblocks/api/token.rb, line 58
def rsa_private
  OpenSSL::PKey::RSA.new(Fireblocks.configuration.private_key)
end