class Stellar::SignerKey

Constants

PREIMAGE_LENGTH

Public Class Methods

ed25519(keypair) click to toggle source
# File lib/stellar/signer_key.rb, line 5
def self.ed25519(keypair)
  raise ArgumentError, "Bad keypair" unless keypair.is_a?(KeyPair)
  new(:signer_key_type_ed25519, keypair.raw_public_key)
end
hash_x(preimage) click to toggle source
# File lib/stellar/signer_key.rb, line 14
def self.hash_x(preimage)
  raise ArgumentError, "Must be string" unless preimage.is_a?(String)
  raise ArgumentError, "Must be 32 bytes" unless preimage.bytesize == PREIMAGE_LENGTH

  hash_x = Digest::SHA256.digest(preimage)
  new(:signer_key_type_hash_x, hash_x)
end
preauthorized_transaction(tx) click to toggle source
# File lib/stellar/signer_key.rb, line 10
def self.preauthorized_transaction(tx)
  new(:signer_key_type_pre_auth_tx, tx.hash)
end

Public Instance Methods

inspect() click to toggle source
# File lib/stellar/signer_key.rb, line 36
def inspect
  # label = switch.to_s
  "#<Stellar::SignerKey #{self}>"
end
signature_hint() click to toggle source
# File lib/stellar/signer_key.rb, line 41
def signature_hint
  # take last 4 bytes
  value.to_xdr.slice(-4, 4)
end
to_s() click to toggle source
# File lib/stellar/signer_key.rb, line 22
def to_s
  case switch
  when SignerKeyType.signer_key_type_ed25519
    address = Stellar::Convert.pk_to_address(self)
    "ed25519: #{address}"
  when SignerKeyType.signer_key_type_pre_auth_tx
    tx = Stellar::Convert.to_hex(pre_auth_tx!)
    "pre_auth_tx: #{tx}"
  when SignerKeyType.signer_key_type_hash_x
    hx = Stellar::Convert.to_hex(hash_x!)
    "hash_x: #{hx}"
  end
end