Class: FROST::SigningKey

Inherits:
Object
  • Object
show all
Defined in:
lib/frost/signing_key.rb

Overview

A signing key for a Schnorr signature on a FROST.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, scalar) ⇒ SigningKey

Constructor

Parameters:

  • context (FROST::Context)

    Frost context.

  • scalar (Integer)

    secret key value.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
# File 'lib/frost/signing_key.rb', line 10

def initialize(context, scalar)
  raise ArgumentError "context must be FROST::Context." unless context.is_a?(FROST::Context)
  raise ArgumentError, "scalar must be integer." unless scalar.is_a?(Integer)
  raise ArgumentError, "Invalid scalar range." if scalar < 1 || context.group.order - 1 < scalar

  @scalar = scalar
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/frost/signing_key.rb', line 5

def context
  @context
end

#scalarObject (readonly)

Returns the value of attribute scalar.



4
5
6
# File 'lib/frost/signing_key.rb', line 4

def scalar
  @scalar
end

Class Method Details

.generate(context) ⇒ Object

Generate signing key.

Parameters:



27
28
29
30
31
32
33
34
35
36
# File 'lib/frost/signing_key.rb', line 27

def self.generate(context)
  raise ArgumentError "context must be FROST::Context." unless context.is_a?(FROST::Context)
  scalar = 1 + SecureRandom.random_number(context.group.order - 1)
  key = SigningKey.new(context, scalar)
  if context.taproot? && !key.to_point.y.even?
    self.generate(context)
  else
    key
  end
end

Instance Method Details

#gen_poly(degree) ⇒ FROST::Polynomial

Generate random polynomial using this secret.

Parameters:

  • degree (Integer)

    Degree of polynomial.

Returns:



41
42
43
# File 'lib/frost/signing_key.rb', line 41

def gen_poly(degree)
  Polynomial.from_secret(context, scalar, degree)
end

#groupECDSA::Group

Get group

Returns:

  • (ECDSA::Group)


21
22
23
# File 'lib/frost/signing_key.rb', line 21

def group
  context.group
end

#to_pointECDSA::Point

Compute public key.

Returns:

  • (ECDSA::Point)


47
48
49
# File 'lib/frost/signing_key.rb', line 47

def to_point
  group.generator * scalar
end