Class: RippleToken::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/ripple_token/token.rb

Instance Method Summary collapse

Constructor Details

#initialize(public_key) ⇒ Token

Returns a new instance of Token.



5
6
7
# File 'lib/ripple_token/token.rb', line 5

def initialize(public_key)
  @public_key = public_key
end

Instance Method Details

#decode(token) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/ripple_token/token.rb', line 9

def decode(token)
  decoded_token = JWT.decode(token, public_key, true, { algorithm: 'RS256' })[0]
  raise ExpiredTokenError if expired? decoded_token

  decoded_token
rescue JWT::DecodeError => e
  raise TokenDecodeError, e.message
rescue JWT::ExpiredSignature => e
  raise ExpiredTokenError, e.message
end

#public_path?(method, path) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/ripple_token/token.rb', line 20

def public_path?(method, path)
  return false if Client.public_paths.nil? || Client.public_paths.empty?

  return true if Client.public_paths[method]&.select { |p| path[p] }&.any?

  false
end