Class: ECC::PublicKey

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, group: SECP256K1) ⇒ PublicKey

Returns a new instance of PublicKey.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/elliptic-lite/signature.rb', line 18

def initialize( *args, group: SECP256K1 )
  @group = group

  if args.size == 1     ## assume it's a point already -- todo/fix: check class via group - why? why not?
    @point = args[0]
  elsif args.size == 2  ## assume it's an x/y coord pair -- todo/fix: check must be Integer class/type - why? why not?
    @point = @group.point( *args )
  else
    raise ArgumentError, "expected point or x/y coords for point; got: #{args.inspect}"
  end
end

Instance Attribute Details

#pointObject (readonly)

Returns the value of attribute point.



16
17
18
# File 'lib/elliptic-lite/signature.rb', line 16

def point
  @point
end

Instance Method Details

#verify?(z, sig) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
# File 'lib/elliptic-lite/signature.rb', line 30

def verify?( z, sig )
  s_inv = sig.s.pow( @group.n-2, @group.n )
  u = z * s_inv % @group.n
  v = sig.r * s_inv % @group.n

  total = u*@group.g + v*@point
  total.x == sig.r
end