Class: EthereumTree::Node
- Inherits:
-
Object
- Object
- EthereumTree::Node
- Defined in:
- lib/ethereum_tree/node.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(wallet_node) ⇒ Node
constructor
A new instance of Node.
- #node_for_path(path) ⇒ Object
- #private_key ⇒ Object
- #to_address ⇒ Object
Constructor Details
#initialize(wallet_node) ⇒ Node
Returns a new instance of Node.
4 5 6 |
# File 'lib/ethereum_tree/node.rb', line 4 def initialize(wallet_node) @wallet_node = wallet_node end |
Class Method Details
Instance Method Details
#node_for_path(path) ⇒ Object
31 32 33 |
# File 'lib/ethereum_tree/node.rb', line 31 def node_for_path(path) Node.new(@wallet_node.node_for_path(path)) end |
#private_key ⇒ Object
27 28 29 |
# File 'lib/ethereum_tree/node.rb', line 27 def private_key @wallet_node.private_key.key end |
#to_address ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ethereum_tree/node.rb', line 13 def to_address # From bitcoin public key to ethereum public key group = ECDSA::Group::Secp256k1 public_key = ECDSA::Format::PointOctetString.decode(@wallet_node.public_key.to_bytes, group) ethereum_public = EthereumTree::Utils.padding64(public_key.x.to_s(16)) + EthereumTree::Utils.padding64(public_key.y.to_s(16)) # From ethereum public key to ethereum address bytes = RLP::Utils.decode_hex(ethereum_public) address_bytes = Digest::SHA3.new(256).digest(bytes)[-20..-1] address = RLP::Utils.encode_hex(address_bytes) EthereumTree::Utils.prefix_hex(address) end |