Method: Stellar::DSL.KeyPair

Defined in:
lib/stellar/dsl.rb

.KeyPair(subject = nil) ⇒ Stellar::Keypair

Generates Stellar::Keypair from subject, use Stellar::Client.to_keypair as shortcut.

Parameters:

Returns:

  • (Stellar::Keypair)

    Stellar::Keypair instance.

Raises:

  • (TypeError)

    if subject cannot be converted to Stellar::KeyPair



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/stellar/dsl.rb', line 74

def KeyPair(subject = nil)
  case subject
  when ->(subj) { subj.respond_to?(:to_keypair) }
    subject.to_keypair
  when PublicKey
    KeyPair.from_public_key(subject.value)
  when SignerKey
    KeyPair.from_raw_seed(subject.value)
  when /^G[A-Z0-9]{55}$/
    KeyPair.from_address(subject.to_str)
  when /^S[A-Z0-9]{55}$/
    KeyPair.from_seed(subject.to_str)
  when /^.{32}$/
    KeyPair.from_raw_seed(subject.to_str)
  when nil
    KeyPair.random
  else
    raise TypeError, "cannot convert #{subject.inspect} to Stellar::KeyPair"
  end
end