Class: Schnorr::MuSig2::KeyAggContext
- Inherits:
-
Object
- Object
- Schnorr::MuSig2::KeyAggContext
- Includes:
- Util
- Defined in:
- lib/schnorr/musig2/context/key_agg.rb
Instance Attribute Summary collapse
-
#gacc ⇒ Object
readonly
Returns the value of attribute gacc.
-
#q ⇒ Object
readonly
Returns the value of attribute q.
-
#tacc ⇒ Object
readonly
Returns the value of attribute tacc.
Instance Method Summary collapse
-
#apply_tweak(tweak, is_xonly_t) ⇒ Schnorr::MuSig2::KeyAggContext
Tweaking the aggregate public key.
-
#initialize(q, gacc, tacc) ⇒ KeyAggContext
constructor
A new instance of KeyAggContext.
-
#x_only_pubkey ⇒ String
Get x-only public key.
Methods included from Util
#hex2bin, #hex_string?, #string2point
Constructor Details
#initialize(q, gacc, tacc) ⇒ KeyAggContext
Returns a new instance of KeyAggContext.
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
#gacc ⇒ Object (readonly)
Returns the value of attribute gacc.
6 7 8 |
# File 'lib/schnorr/musig2/context/key_agg.rb', line 6 def gacc @gacc end |
#q ⇒ Object (readonly)
Returns the value of attribute q.
6 7 8 |
# File 'lib/schnorr/musig2/context/key_agg.rb', line 6 def q @q end |
#tacc ⇒ Object (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
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_pubkey ⇒ String
Get x-only public key.
22 23 24 |
# File 'lib/schnorr/musig2/context/key_agg.rb', line 22 def x_only_pubkey q.encode(true).unpack1('H*') end |