Sha256: 51323bea3e140a8dbfe734ff4618d206754663d8f33731e69725047e4896d973

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module EthereumTree
  class Node

    def initialize(wallet_node)
      @wallet_node = wallet_node
    end

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

    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

    def private_key
      @wallet_node.private_key.key
    end

    def node_for_path(path)
      Node.new(@wallet_node.node_for_path(path))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ethereum_tree-0.1.2 lib/ethereum_tree/node.rb
ethereum_tree-0.1.1 lib/ethereum_tree/node.rb
ethereum_tree-0.1.0 lib/ethereum_tree/node.rb