Class: Ciri::DevP2P::RLPX::NodeID

Inherits:
Object
  • Object
show all
Defined in:
lib/ciri/devp2p/rlpx/node.rb

Overview

present node id

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_key) ⇒ NodeID


43
44
45
46
47
48
# File 'lib/ciri/devp2p/rlpx/node.rb', line 43

def initialize(public_key)
  unless public_key.is_a?(Ciri::Key)
    raise TypeError.new("expect Ciri::Key but get #{public_key.class}")
  end
  @public_key = public_key
end

Instance Attribute Details

#public_keyObject (readonly) Also known as: key

Returns the value of attribute public_key


39
40
41
# File 'lib/ciri/devp2p/rlpx/node.rb', line 39

def public_key
  @public_key
end

Class Method Details

.from_raw_id(raw_id) ⇒ Object


34
35
36
# File 'lib/ciri/devp2p/rlpx/node.rb', line 34

def from_raw_id(raw_id)
  NodeID.new(Ciri::Key.new(raw_public_key: "\x04".b + raw_id))
end

Instance Method Details

#==(other) ⇒ Object


54
55
56
# File 'lib/ciri/devp2p/rlpx/node.rb', line 54

def == (other)
  self.class == other.class && id == other.id
end

#idObject


50
51
52
# File 'lib/ciri/devp2p/rlpx/node.rb', line 50

def id
  @id ||= key.raw_public_key[1..-1]
end