Class: EthereumTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/ethereum_tree/node.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wallet_node) ⇒ Node



4
5
6
# File 'lib/ethereum_tree/node.rb', line 4

def initialize(wallet_node)
  @wallet_node = wallet_node
end

Class Method Details

.from_bip32(address) ⇒ Object



8
9
10
11
# File 'lib/ethereum_tree/node.rb', line 8

def self.from_bip32(address)
  wallet_node = MoneyTree::Master.from_bip32(address)
  Node.new(wallet_node)
end

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_keyObject



27
28
29
# File 'lib/ethereum_tree/node.rb', line 27

def private_key
  @wallet_node.private_key.key
end

#to_addressObject



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

#xprvObject



39
40
41
# File 'lib/ethereum_tree/node.rb', line 39

def xprv
  @wallet_node.to_bip32(:private)
end

#xpubObject



35
36
37
# File 'lib/ethereum_tree/node.rb', line 35

def xpub
  @wallet_node.to_bip32
end