def signature_to_G2(signature): return _signature_to_G2(signature)
from py_ecc.bls import G2ProofOfPossession as py_ecc_bls from py_ecc.bls.g2_primatives import signature_to_G2 as _signature_to_G2 import milagro_bls_binding as milagro_bls # noqa: F401 for BLS switching option # Flag to make BLS active or not. Used for testing, do not ignore BLS in production unless you know what you are doing. bls_active = True # To change bls implementation, default to PyECC for correctness. Milagro is a good faster alternative. bls = py_ecc_bls STUB_SIGNATURE = b'\x11' * 96 STUB_PUBKEY = b'\x22' * 48 G2_POINT_AT_INFINITY = b'\xc0' + b'\x00' * 95 STUB_COORDINATES = _signature_to_G2(G2_POINT_AT_INFINITY) def use_milagro(): """ Shortcut to use Milagro as BLS library """ global bls bls = milagro_bls def use_py_ecc(): """ Shortcut to use Py-ecc as BLS library """ global bls bls = py_ecc_bls
from py_ecc.bls import G2ProofOfPossession as py_ecc_bls from py_ecc.bls.g2_primatives import signature_to_G2 as _signature_to_G2 import milagro_bls_binding as milagro_bls # noqa: F401 for BLS switching option # Flag to make BLS active or not. Used for testing, do not ignore BLS in production unless you know what you are doing. bls_active = True # To change bls implementation, default to PyECC for correctness. Milagro is a good faster alternative. bls = py_ecc_bls STUB_SIGNATURE = b'\x11' * 96 STUB_PUBKEY = b'\x22' * 48 Z2_SIGNATURE = b'\xc0' + b'\x00' * 95 STUB_COORDINATES = _signature_to_G2(Z2_SIGNATURE) def use_milagro(): """ Shortcut to use Milagro as BLS library """ global bls bls = milagro_bls def use_py_ecc(): """ Shortcut to use Py-ecc as BLS library """ global bls bls = py_ecc_bls
from py_ecc.bls import G2ProofOfPossession as bls from py_ecc.bls.g2_primatives import signature_to_G2 as _signature_to_G2 # Flag to make BLS active or not. Used for testing, do not ignore BLS in production unless you know what you are doing. bls_active = True STUB_SIGNATURE = b'\x11' * 96 STUB_PUBKEY = b'\x22' * 48 STUB_COORDINATES = _signature_to_G2(bls.Sign(0, b"")) def only_with_bls(alt_return=None): """ Decorator factory to make a function only run when BLS is active. Otherwise return the default. """ def runner(fn): def entry(*args, **kw): if bls_active: return fn(*args, **kw) else: return alt_return return entry return runner @only_with_bls(alt_return=True) def Verify(PK, message, signature): return bls.Verify(PK, message, signature) @only_with_bls(alt_return=True)