class Stellar::KeyPair
Public Class Methods
from_address(address)
click to toggle source
# File lib/stellar/key_pair.rb, line 19 def self.from_address(address) pk_bytes = Util::StrKey.check_decode(:account_id, address) from_public_key(pk_bytes) end
from_network_passphrase(passphrase)
click to toggle source
# File lib/stellar/key_pair.rb, line 30 def self.from_network_passphrase(passphrase) network_id = Digest::SHA256.digest(passphrase) from_raw_seed network_id end
from_public_key(pk_bytes)
click to toggle source
# File lib/stellar/key_pair.rb, line 14 def self.from_public_key(pk_bytes) public_key = RbNaCl::VerifyKey.new(pk_bytes) new(public_key) end
from_raw_seed(seed_bytes)
click to toggle source
# File lib/stellar/key_pair.rb, line 8 def self.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)
click to toggle source
# File lib/stellar/key_pair.rb, line 3 def self.from_seed(seed) seed_bytes = Util::StrKey.check_decode(:seed, seed) from_raw_seed seed_bytes end
master()
click to toggle source
# File lib/stellar/key_pair.rb, line 35 def self.master from_raw_seed(Stellar.current_network_id) end
new(public_key, secret_key=nil)
click to toggle source
# File lib/stellar/key_pair.rb, line 39 def initialize(public_key, secret_key=nil) @public_key = public_key @secret_key = secret_key end
random()
click to toggle source
# File lib/stellar/key_pair.rb, line 24 def self.random secret_key = RbNaCl::SigningKey.generate public_key = secret_key.verify_key new(public_key, secret_key) end
Public Instance Methods
account_id()
click to toggle source
# File lib/stellar/key_pair.rb, line 44 def account_id Stellar::AccountID.new :key_type_ed25519, raw_public_key end
address()
click to toggle source
# File lib/stellar/key_pair.rb, line 73 def address pk_bytes = raw_public_key Util::StrKey.check_encode(:account_id, pk_bytes) end
public_key()
click to toggle source
# File lib/stellar/key_pair.rb, line 48 def public_key Stellar::PublicKey.new :key_type_ed25519, raw_public_key end
raw_public_key()
click to toggle source
# File lib/stellar/key_pair.rb, line 52 def raw_public_key @public_key.to_bytes end
raw_seed()
click to toggle source
# File lib/stellar/key_pair.rb, line 61 def raw_seed @secret_key.to_bytes end
rbnacl_signing_key()
click to toggle source
# File lib/stellar/key_pair.rb, line 65 def rbnacl_signing_key @secret_key end
rbnacl_verify_key()
click to toggle source
# File lib/stellar/key_pair.rb, line 69 def rbnacl_verify_key @public_key end
seed()
click to toggle source
# File lib/stellar/key_pair.rb, line 78 def seed raise "no private key" if @secret_key.nil? #TODO: improve the error class above seed_bytes = raw_seed encoder = Util::StrKey.check_encode(:seed, seed_bytes) end
sign(message)
click to toggle source
# File lib/stellar/key_pair.rb, line 89 def sign(message) raise "no private key" if @secret_key.nil? #TODO: improve the error class above @secret_key.sign(message) end
sign?()
click to toggle source
# File lib/stellar/key_pair.rb, line 85 def sign? !@secret_key.nil? end
sign_decorated(message)
click to toggle source
# File lib/stellar/key_pair.rb, line 95 def sign_decorated(message) raw_signature = sign(message) Stellar::DecoratedSignature.new({ hint: signature_hint, signature: raw_signature }) end
signature_hint()
click to toggle source
# File lib/stellar/key_pair.rb, line 56 def signature_hint # take last 4 bytes account_id.to_xdr.slice(-4, 4) end
verify(signature, message)
click to toggle source
# File lib/stellar/key_pair.rb, line 103 def verify(signature, message) @public_key.verify(signature, message) rescue RbNaCl::LengthError false rescue RbNaCl::BadSignatureError false end