py_ecc
Warning
This library contains some experimental code and has not been audited.
BLS Signatures
py_ecc implements the IETF BLS draft standard v4 as per the inter-blockchain standardization agreement. The BLS standards specify different ciphersuites which each have different functionality to accommodate various use cases. The following ciphersuites are available from this library:
G2Basicalso known asBLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_G2MessageAugmentationalso known asBLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_AUG_G2ProofOfPossessionalso known asBLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_
Basic Usage
from py_ecc.bls import G2ProofOfPossession as bls_pop
private_key = 5566
public_key = bls_pop.SkToPk(private_key)
message = b'\xab' * 32 # The message to be signed
# Signing
signature = bls_pop.Sign(private_key, message)
# Verifying
assert bls_pop.Verify(public_key, message, signature)
Aggregating Signatures
private_keys = [3, 14, 159]
public_keys = [bls_pop.SkToPk(key) for key in private_keys]
signatures = [bls_pop.Sign(key, message) for key in private_keys]
# Aggregating
agg_sig = bls_pop.Aggregate(signatures)
# Verifying signatures over the same message.
# Note this is only safe if Proofs of Possession have been verified for each of the public keys beforehand.
# See the BLS standards for why this is the case.
assert bls_pop.FastAggregateVerify(public_keys, message, agg_sig)
Multiple Aggregation
messages = [b'\xaa' * 42, b'\xbb' * 32, b'\xcc' * 64]
signatures = [bls_pop.Sign(key, message) for key, message in zip(private_keys, messages)]
agg_sig = bls_pop.Aggregate(signatures)
# Verify aggregate signature with different messages
assert bls_pop.AggregateVerify(public_keys, messages, agg_sig)
py_ecc package
- py_ecc.bls package
- Submodules
- py_ecc.bls.ciphersuites module
- py_ecc.bls.constants module
- py_ecc.bls.g2_primitives module
- py_ecc.bls.hash module
- py_ecc.bls.hash_to_curve module
- py_ecc.bls.point_compression module
- py_ecc.bls.typing module
- Module contents
- py_ecc.bls12_381 package
- py_ecc.bn128 package
- py_ecc.optimized_bn128 package
- py_ecc.secp256k1 package
- py_ecc.fields package
- Submodules
- py_ecc.fields.field_elements module
- py_ecc.fields.field_properties module
- py_ecc.fields.optimized_field_elements module
- Module contents
- py_ecc.optimized_bls12_381 package