Class: ECC::PrivateKey

Inherits:
Object
  • Object
show all
Defined in:
lib/elliptic-lite/signature.rb

Instance Method Summary collapse

Constructor Details

#initialize(secret, group: SECP256K1) ⇒ PrivateKey

Returns a new instance of PrivateKey.



42
43
44
45
# File 'lib/elliptic-lite/signature.rb', line 42

def initialize( secret, group: SECP256K1 )
  @secret = secret
  @group  = group
end

Instance Method Details

#public_keyObject Also known as: pubkey



47
48
49
# File 'lib/elliptic-lite/signature.rb', line 47

def public_key
  @pubkey ||= PublicKey.new( @secret * @group.g, group: @group )
end

#sign(z) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/elliptic-lite/signature.rb', line 52

def sign( z )
  k = 1 + SecureRandom.random_number( @group.n - 1)
  # k = 1234567890
  r = (k*@group.g).x
  k_inv = k.pow( @group.n-2, @group.n )
  s = (z+r*@secret) * k_inv % @group.n
  s = @group.n - s   if s > @group.n/2
  Signature.new( r, s )
end