Class: Stellar::SignerKey
- Inherits:
-
XDR::Union
- Object
- XDR::Union
- Stellar::SignerKey
- Defined in:
- lib/stellar/signer_key.rb,
generated/stellar/signer_key.rb
Constant Summary collapse
- PREIMAGE_LENGTH =
32
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.ed25519(keypair) ⇒ Object
6 7 8 9 |
# File 'lib/stellar/signer_key.rb', line 6 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
17 18 19 20 21 22 23 |
# File 'lib/stellar/signer_key.rb', line 17 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
12 13 14 |
# File 'lib/stellar/signer_key.rb', line 12 def self.(tx) new(:signer_key_type_pre_auth_tx, tx.hash) end |
Instance Method Details
#inspect ⇒ Object
39 40 41 42 |
# File 'lib/stellar/signer_key.rb', line 39 def inspect label = switch.to_s "#<Stellar::SignerKey #{to_s}>" end |
#signature_hint ⇒ Object
44 45 46 47 |
# File 'lib/stellar/signer_key.rb', line 44 def signature_hint # take last 4 bytes value.to_xdr.slice(-4, 4) end |
#to_s ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/stellar/signer_key.rb', line 25 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 |