Class: DbchainClient::PublicKey
- Inherits:
-
Object
- Object
- DbchainClient::PublicKey
- Defined in:
- lib/dbchain_client/key.rb
Instance Method Summary collapse
- #address ⇒ Object
-
#initialize(pub_key) ⇒ PublicKey
constructor
hex or raw public key.
- #public_key_hex ⇒ Object
- #to_raw ⇒ Object
- #to_s ⇒ Object
- #verify(message, signature) ⇒ Object
Constructor Details
#initialize(pub_key) ⇒ PublicKey
hex or raw public key
6 7 8 9 10 11 12 13 |
# File 'lib/dbchain_client/key.rb', line 6 def initialize(pub_key) # hex or raw public key if pub_key.instance_of?(Secp256k1::PublicKey) @public_key = pub_key else raw_pub_key = Secp256k1::Utils.decode_hex(pub_key) @public_key = Secp256k1::PublicKey.new(pubkey: raw_pub_key, raw: true) end end |
Instance Method Details
#address ⇒ Object
27 28 29 |
# File 'lib/dbchain_client/key.rb', line 27 def address @address ||= Mnemonics.public_key_to_address(public_key_hex) end |
#public_key_hex ⇒ Object
15 16 17 |
# File 'lib/dbchain_client/key.rb', line 15 def public_key_hex @public_key.serialize.unpack('H*')[0] end |
#to_raw ⇒ Object
19 20 21 |
# File 'lib/dbchain_client/key.rb', line 19 def to_raw @public_key.serialize end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/dbchain_client/key.rb', line 23 def to_s public_key_hex end |
#verify(message, signature) ⇒ Object
31 32 33 34 |
# File 'lib/dbchain_client/key.rb', line 31 def verify(, signature) raw_sig = signature.raw @public_key.ecdsa_verify(, raw_sig) end |