Class: Schnorr::MuSig2::KeyAggContext

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/schnorr/musig2/context/key_agg.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#hex2bin, #hex_string?, #string2point

Constructor Details

#initialize(q, gacc, tacc) ⇒ KeyAggContext

Returns a new instance of KeyAggContext.

Parameters:

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
# File 'lib/schnorr/musig2/context/key_agg.rb', line 11

def initialize(q, gacc, tacc)
  raise ArgumentError, 'The gacc must be Integer.' unless gacc.is_a?(Integer)
  raise ArgumentError, 'The tacc must be Integer.' unless tacc.is_a?(Integer)
  raise ArgumentError, 'The q must be ECDSA::Point.' unless q.is_a?(ECDSA::Point)
  @q = q
  @gacc = gacc
  @tacc = tacc
end

Instance Attribute Details

#gaccObject (readonly)

Returns the value of attribute gacc.



6
7
8
# File 'lib/schnorr/musig2/context/key_agg.rb', line 6

def gacc
  @gacc
end

#qObject (readonly)

Returns the value of attribute q.



6
7
8
# File 'lib/schnorr/musig2/context/key_agg.rb', line 6

def q
  @q
end

#taccObject (readonly)

Returns the value of attribute tacc.



6
7
8
# File 'lib/schnorr/musig2/context/key_agg.rb', line 6

def tacc
  @tacc
end

Instance Method Details

#apply_tweak(tweak, is_xonly_t) ⇒ Schnorr::MuSig2::KeyAggContext

Tweaking the aggregate public key

Parameters:

  • tweak (String)

    32 bytes tweak value.

  • is_xonly_t (Boolean)

    Tweak mode.

Returns:

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/schnorr/musig2/context/key_agg.rb', line 30

def apply_tweak(tweak, is_xonly_t)
  tweak = hex2bin(tweak)
  raise ArgumentError, 'The tweak must be a 32-bytes.' unless tweak.bytesize == 32

  g = is_xonly_t && !q.has_even_y? ? q.group.order - 1 : 1
  t = tweak.bti

  raise ArgumentError, 'The tweak must be less than curve order.' if t >= q.group.order
  new_q = (q.to_jacobian * g + q.group.generator.to_jacobian * t).to_affine
  raise ArgumentError, 'The result of tweaking cannot be infinity.' if new_q.infinity?
  new_gacc = (g * gacc) % q.group.order
  new_tacc = (t + g * tacc) % q.group.order
  KeyAggContext.new(new_q, new_gacc, new_tacc)
end

#x_only_pubkeyString

Get x-only public key.

Returns:

  • (String)

    x-only public key(hex format).



22
23
24
# File 'lib/schnorr/musig2/context/key_agg.rb', line 22

def x_only_pubkey
  q.encode(true).unpack1('H*')
end