Module: Stellar::KeyPair::FactoryMethods

Included in:
Stellar::KeyPair
Defined in:
lib/stellar/key_pair.rb

Instance Method Summary collapse

Instance Method Details

#from_address(address) ⇒ Object


9
10
11
12
# File 'lib/stellar/key_pair.rb', line 9

def from_address(address)
  pk_bytes = Util::StrKey.check_decode(:account_id, address)
  from_public_key(pk_bytes)
end

#from_network_passphrase(passphrase) ⇒ Object


31
32
33
34
# File 'lib/stellar/key_pair.rb', line 31

def from_network_passphrase(passphrase)
  network_id = Digest::SHA256.digest(passphrase)
  from_raw_seed network_id
end

#from_public_key(pk_bytes) ⇒ Object


20
21
22
23
# File 'lib/stellar/key_pair.rb', line 20

def from_public_key(pk_bytes)
  public_key = RbNaCl::VerifyKey.new(pk_bytes)
  new(public_key)
end

#from_raw_seed(seed_bytes) ⇒ Object


14
15
16
17
18
# File 'lib/stellar/key_pair.rb', line 14

def from_raw_seed(seed_bytes)
  secret_key = RbNaCl::SigningKey.new(seed_bytes)
  public_key = secret_key.verify_key
  new(public_key, secret_key)
end

#from_seed(seed) ⇒ Object


4
5
6
7
# File 'lib/stellar/key_pair.rb', line 4

def from_seed(seed)
  seed_bytes = Util::StrKey.check_decode(:seed, seed)
  from_raw_seed seed_bytes
end

#masterObject


36
37
38
# File 'lib/stellar/key_pair.rb', line 36

def master
  from_raw_seed(Stellar.current_network_id)
end

#randomObject


25
26
27
28
29
# File 'lib/stellar/key_pair.rb', line 25

def random
  secret_key = RbNaCl::SigningKey.generate
  public_key = secret_key.verify_key
  new(public_key, secret_key)
end