Module: Schnorr::Util

Included in:
Schnorr, MuSig2, MuSig2::KeyAggContext, MuSig2::SessionContext
Defined in:
lib/schnorr/util.rb

Instance Method Summary collapse

Instance Method Details

#hex2bin(str) ⇒ String

If str is a hex value, it is converted to binary. Otherwise, it is returned as is.

Parameters:

Returns:



17
18
19
# File 'lib/schnorr/util.rb', line 17

def hex2bin(str)
  hex_string?(str) ? [str].pack('H*') : str
end

#hex_string?(str) ⇒ Boolean

Check whether str is hex string or not.

Parameters:

Returns:

  • (Boolean)


7
8
9
10
11
12
# File 'lib/schnorr/util.rb', line 7

def hex_string?(str)
  return false if str.bytes.any? { |b| b > 127 }
  return false if str.length % 2 != 0
  hex_chars = str.chars.to_a
  hex_chars.all? { |c| c =~ /[0-9a-fA-F]/ }
end

#string2point(str) ⇒ ECDSA::Point

Convert str to the point of elliptic curve.

Parameters:

  • str (String)

    A byte string for point.

Returns:



24
25
26
# File 'lib/schnorr/util.rb', line 24

def string2point(str)
  ECDSA::Format::PointOctetString.decode(str, GROUP)
end