Class: Stellar::SignerKey

Inherits:
Object
  • Object
show all
Defined in:
lib/stellar/signer_key.rb

Constant Summary collapse

PREIMAGE_LENGTH =
32

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ed25519(keypair) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
# 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) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
# 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) ⇒ Object



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

def self.preauthorized_transaction(tx)
  new(:signer_key_type_pre_auth_tx, tx.hash)
end

Instance Method Details

#inspectObject



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

def inspect
  # label = switch.to_s
  "#<Stellar::SignerKey #{self}>"
end

#signature_hintObject



41
42
43
44
# File 'lib/stellar/signer_key.rb', line 41

def signature_hint
  # take last 4 bytes
  value.to_xdr.slice(-4, 4)
end

#to_sObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# 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