class Mobius::Client::Auth::Challenge

Generates challenge transaction on developer's side.

Constants

MAX_SEQ_NUMBER
RANDOM_LIMITS

Public Instance Methods

call() click to toggle source

@return [String] base64-encoded transaction envelope

# File lib/mobius/client/auth/challenge.rb, line 22
def call
  payment = Stellar::Transaction.payment(
    source_account: keypair,
    account: Stellar::KeyPair.random,
    destination: keypair,
    sequence: random_sequence,
    amount: micro_xlm,
    memo: memo
  )

  payment.time_bounds = build_time_bounds(expire_in)

  payment.to_envelope(keypair).to_xdr(:base64)
end

Private Instance Methods

build_time_bounds(expire_in) click to toggle source

@return [Stellar::TimeBounds] Current time..expire time

# File lib/mobius/client/auth/challenge.rb, line 50
def build_time_bounds(expire_in)
  Stellar::TimeBounds.new(
    min_time: Time.now.to_i,
    max_time: Time.now.to_i + expire_in.to_i || 0
  )
end
keypair() click to toggle source

@return [Stellar::Keypair] Stellar::Keypair object for given seed.

# File lib/mobius/client/auth/challenge.rb, line 40
def keypair
  @keypair ||= Stellar::KeyPair.from_seed(seed)
end
memo() click to toggle source

@return [Stellar::Memo] Auth transaction memo

# File lib/mobius/client/auth/challenge.rb, line 63
def memo
  Stellar::Memo.new(:memo_text, "Mobius authentication")
end
micro_xlm() click to toggle source

@return [Stellar::Amount] 1 XLM

# File lib/mobius/client/auth/challenge.rb, line 58
def micro_xlm
  Stellar::Amount.new(1).to_payment
end
random_sequence() click to toggle source

@return [Integer] Random sequence number

# File lib/mobius/client/auth/challenge.rb, line 45
def random_sequence
  MAX_SEQ_NUMBER - SecureRandom.random_number(RANDOM_LIMITS)
end