module Mobius::Client::Blockchain::KeyPairFactory
Transforms given value into Stellar::Keypair object.
Public Class Methods
produce(subject)
click to toggle source
rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity Generates Stellar::Keypair from subject, use Stellar::Client.to_keypair as shortcut. @param subject [String||Stellar::Account||Stellar::PublicKey||Stellar::SignerKey||Stellar::Keypair] subject. @return [Stellar::Keypair] Stellar::Keypair instance.
# File lib/mobius/client/blockchain/key_pair_factory.rb, line 8 def produce(subject) case subject when String from_string(subject) when Stellar::Account subject.keypair when Stellar::PublicKey from_public_key(subject) when Stellar::SignerKey from_secret_key(subject) when Stellar::KeyPair subject else raise Mobius::Client::Error::UnknownKeyPairType, "Unknown KeyPair type: #{subject.class.name}" end rescue ArgumentError => e raise Mobius::Client::Error::UnknownKeyPairType, "Unknown KeyPair type: #{e.message}" end
Private Class Methods
from_public_key(subject)
click to toggle source
# File lib/mobius/client/blockchain/key_pair_factory.rb, line 34 def from_public_key(subject) Stellar::KeyPair.from_public_key(subject.value) end
from_secret_key(subject)
click to toggle source
# File lib/mobius/client/blockchain/key_pair_factory.rb, line 38 def from_secret_key(subject) Stellar::KeyPair.from_raw_seed(subject.value) end
from_string(subject)
click to toggle source
rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
# File lib/mobius/client/blockchain/key_pair_factory.rb, line 30 def from_string(subject) subject[0] == "S" ? Stellar::KeyPair.from_seed(subject) : Stellar::KeyPair.from_address(subject) end