Class: Mobius::Client::Auth::Token

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/mobius/client/auth/token.rb

Overview

Checks challenge transaction signed by user on developer’s side.

Instance Method Summary collapse

Constructor Details

#initialize(seed, xdr, address) ⇒ Object

Parameters:

  • seed (String)

    Developers private key.

  • xdr (String)

    Auth transaction XDR.

  • address (String)

    User public key.



10
# File 'lib/mobius/client/auth/token.rb', line 10

param :seed

Instance Method Details

#hash(format = :binary) ⇒ String

Returns transaction hash.

Returns:

  • (String)

    transaction hash



43
44
45
46
47
48
# File 'lib/mobius/client/auth/token.rb', line 43

def hash(format = :binary)
  validate! # Guard!
  h = envelope.tx.hash
  return h if format == :binary
  h.unpack("H*").first
end

#time_boundsStellar::TimeBounds

Returns time bounds for given transaction.

Returns:

  • (Stellar::TimeBounds)

    Time bounds for given transaction (‘.min_time` and `.max_time`).

Raises:

  • (Unauthorized)

    if one of the signatures is invalid.

  • (Invalid)

    if transaction is malformed or time bounds are missing.



19
20
21
22
23
24
25
26
# File 'lib/mobius/client/auth/token.rb', line 19

def time_bounds
  bounds = envelope.tx.time_bounds

  raise Mobius::Client::Error::Unauthorized unless signed_correctly?
  raise Mobius::Client::Error::MalformedTransaction if bounds.nil?

  bounds
end

#validate!(strict = true) ⇒ Boolean

Validates transaction signed by developer and user.

Parameters:

  • strict (Bool) (defaults to: true)

    if true, checks that lower time limit is within Mobius::Client.strict_interval seconds from now

Returns:

  • (Boolean)

    true if transaction is valid, raises exception otherwise

Raises:

  • (Unauthorized)

    if one of the signatures is invalid

  • (Invalid)

    if transaction is malformed or time bounds are missing

  • (Expired)

    if transaction is expired (current time outside it’s time bounds)



35
36
37
38
39
40
# File 'lib/mobius/client/auth/token.rb', line 35

def validate!(strict = true)
  bounds = time_bounds
  raise Mobius::Client::Error::TokenExpired unless time_now_covers?(bounds)
  raise Mobius::Client::Error::TokenTooOld if strict && too_old?(bounds)
  true
end