Class: MixinBot::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/mixin_bot/configuration.rb

Constant Summary collapse

CONFIGURABLE_ATTRS =
%i[
  app_id
  client_secret
  session_id
  session_private_key
  server_public_key
  spend_key
  pin
  api_host
  blaze_host
  session_private_key_curve25519
  server_public_key_curve25519
  debug
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Configuration

Returns a new instance of Configuration.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mixin_bot/configuration.rb', line 21

def initialize(**kwargs)
  @app_id = kwargs[:app_id] || kwargs[:client_id]
  @client_secret = kwargs[:client_secret]
  @session_id = kwargs[:session_id]
  @api_host = kwargs[:api_host] || 'api.mixin.one'
  @blaze_host = kwargs[:blaze_host] || 'blaze.mixin.one'
  @debug = kwargs[:debug] || false

  self.session_private_key = kwargs[:session_private_key] || kwargs[:private_key]
  self.server_public_key = kwargs[:server_public_key] || kwargs[:pin_token]
  self.spend_key = kwargs[:spend_key]
  self.pin = kwargs[:pin] || spend_key
end

Instance Method Details

#pin=(key) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/mixin_bot/configuration.rb', line 80

def pin=(key)
  return if key.blank?

  _private_key = decode_key key
  @pin =
    if _private_key.size == 32
      JOSE::JWA::Ed25519.keypair(_private_key).last
    else
      _private_key
    end
end

#server_public_key=(key) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/mixin_bot/configuration.rb', line 55

def server_public_key=(key)
  return if key.blank?

  @server_public_key = decode_key key
  # HEX encoded
  @server_public_key_curve25519 =
    if key.match?(/\A[\h]{32,}\z/i)
      JOSE::JWA::Ed25519.pk_to_curve25519 @server_public_key
    else
      server_public_key
    end
end

#session_private_key=(key) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mixin_bot/configuration.rb', line 41

def session_private_key=(key)
  return if key.blank?

  _private_key = decode_key key
  @session_private_key =
    if _private_key.size == 32
      JOSE::JWA::Ed25519.keypair(_private_key).last
    else
      _private_key
    end

  @session_private_key_curve25519 = JOSE::JWA::Ed25519.sk_to_curve25519(@session_private_key) if @session_private_key.size == 64
end

#spend_key=(key) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mixin_bot/configuration.rb', line 68

def spend_key=(key)
  return if key.blank?

  _private_key = decode_key key
  @spend_key =
    if _private_key.size == 32
      JOSE::JWA::Ed25519.keypair(_private_key).last
    else
      _private_key
    end
end

#valid?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/mixin_bot/configuration.rb', line 35

def valid?
  %i[app_id session_id session_private_key server_public_key].all? do |attr|
    send(attr).present?
  end
end