Class: Eth::Key
- Inherits:
-
Object
- Object
- Eth::Key
- Defined in:
- lib/eth/key.rb
Instance Attribute Summary collapse
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
Instance Method Summary collapse
- #address ⇒ Object (also: #to_address)
-
#initialize(priv: nil) ⇒ Key
constructor
A new instance of Key.
- #private_hex ⇒ Object
- #public_bytes ⇒ Object
- #public_hex ⇒ Object
- #sign(message) ⇒ Object
- #sign_hash(hash) ⇒ Object
- #verify_signature(message, signature) ⇒ Object
Constructor Details
#initialize(priv: nil) ⇒ Key
Returns a new instance of Key.
6 7 8 9 |
# File 'lib/eth/key.rb', line 6 def initialize(priv: nil) @private_key = MoneyTree::PrivateKey.new key: priv @public_key = MoneyTree::PublicKey.new private_key, compressed: false end |
Instance Attribute Details
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
4 5 6 |
# File 'lib/eth/key.rb', line 4 def private_key @private_key end |
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
4 5 6 |
# File 'lib/eth/key.rb', line 4 def public_key @public_key end |
Instance Method Details
#address ⇒ Object Also known as: to_address
23 24 25 |
# File 'lib/eth/key.rb', line 23 def address Utils.public_key_to_address public_hex end |
#private_hex ⇒ Object
11 12 13 |
# File 'lib/eth/key.rb', line 11 def private_hex private_key.to_hex end |
#public_bytes ⇒ Object
15 16 17 |
# File 'lib/eth/key.rb', line 15 def public_bytes public_key.to_bytes end |
#public_hex ⇒ Object
19 20 21 |
# File 'lib/eth/key.rb', line 19 def public_hex public_key.to_hex end |
#sign(message) ⇒ Object
28 29 30 |
# File 'lib/eth/key.rb', line 28 def sign() sign_hash () end |
#sign_hash(hash) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/eth/key.rb', line 32 def sign_hash(hash) loop do signature = OpenSsl.sign_compact hash, private_hex, public_hex return signature if valid_s? signature end end |
#verify_signature(message, signature) ⇒ Object
39 40 41 42 |
# File 'lib/eth/key.rb', line 39 def verify_signature(, signature) hash = () public_hex == OpenSsl.recover_compact(hash, signature) end |