Class: Cryptos::PrivateKey

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptos/private_key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, order = nil) ⇒ PrivateKey

Returns a new instance of PrivateKey.



15
16
17
18
# File 'lib/cryptos/private_key.rb', line 15

def initialize(value, order = nil)
  @value = value
  @order = order
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



5
6
7
# File 'lib/cryptos/private_key.rb', line 5

def order
  @order
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/cryptos/private_key.rb', line 5

def value
  @value
end

Class Method Details

.generate(group = EllipticCurve::Secp256k1) ⇒ Object

Generates new private key

Parameters:

Returns:

  • the private key



10
11
12
13
# File 'lib/cryptos/private_key.rb', line 10

def self.generate(group = EllipticCurve::Secp256k1)
  value = 1 + SecureRandom.random_number(group.order - 1)
  new value, group.order
end

Instance Method Details

#to_sObject



20
21
22
# File 'lib/cryptos/private_key.rb', line 20

def to_s
  value.to_s
end