eigensdk.crypto
This module provides classes and functions for handling BLS signatures, cryptographic key management, and various utility functions for elliptic curve operations using the BLS signature scheme.
Example Usage
>>> from eigensdk.crypto.bls.attestation import new_key_pair_from_string
>>> # Generate a new key pair from a string seed
>>> key_pair = new_key_pair_from_string("a1b2c3d4")
>>> # Assume a simple message
>>> message = b"Hello, world!"
>>> # Sign the message with the private key
>>> signature = key_pair.sign_message(message)
>>> print("Signature JSON:", signature.to_json())
Signature JSON: {'X': 10529196257730034571674059145519291271312341314564905285488980484390382467013, 'Y': 18927811237058023983585857108877009845959756493464435916975837710431732965093}
>>> # Verification would typically need the public key in G2; simulate getting this
>>> pub_g2 = key_pair.get_pub_g2() # This would normally be known or retrieved independently
>>> # Verify the signature against the message and the public key
>>> is_valid = signature.verify(pub_g2, message)
>>> print("Signature valid:", is_valid)
Signature valid: True
This example demonstrates the complete lifecycle of a BLS signature within the eigensdk.crypto.bls.attestation module, from generating key pairs to signing messages and verifying those signatures. The verify method checks if the signature is valid given the original message and the signer’s public key, ensuring the integrity and authenticity of the signed data.
eigensdk.crypto.bls.attestation
- class eigensdk.crypto.bls.attestation.G1Point(x, y)
Bases:
G1
Represents a point on the G1 curve.
Provides basic arithmetic operations.
- Parameters:
x (int)
y (int)
- from_G1()
Creates a G1Point from an existing G1 object.
- Parameters:
g1 (mcl.G1)
- class eigensdk.crypto.bls.attestation.G2Point(xa, xb, ya, yb)
Bases:
G2
Represents a point on the G2 curve.
- Parameters:
xa (int)
xb (int)
ya (int)
yb (int)
- from_G2()
Creates a G2Point from an existing G2 object.
- Parameters:
g2 (mcl.G2)
- class eigensdk.crypto.bls.attestation.GTPoint(*args, **kwargs)
Bases:
GT
Represents a point on the GT curve (target group of the pairing).
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- class eigensdk.crypto.bls.attestation.KeyPair(priv_key=None)
Bases:
object
Represents a BLS key pair, including both private and public keys.
- Parameters:
priv_key (PrivateKey)
- static from_string(sk, base=16)
Constructs a KeyPair from a private key string.
- Return type:
- Parameters:
sk (str)
- static read_from_file(_path, password)
Loads a key pair from a keystore file using the given password.
- Parameters:
_path (str)
password (str)
- save_to_file(_path, password)
Saves the key pair to a keystore file encrypted with the given password.
- Parameters:
_path (str)
password (str)
- sign_hashed_to_curve_message(msg_map_point)
Signs a message that has already been hashed to the curve.
- class eigensdk.crypto.bls.attestation.PrivateKey(secret=None)
Bases:
Fr
Represents a BLS private key.
- Parameters:
secret (bytes)
- get_str()
Returns the private key as a hexadecimal string.
- Return type:
str
- class eigensdk.crypto.bls.attestation.Signature(x, y)
Bases:
G1Point
A special type of G1Point specifically used for signatures.
- Parameters:
x (int)
y (int)
- static from_g1_point(p)
Constructs a Signature from a G1Point.
- to_json()
Converts the signature to a JSON-serializable dictionary.
- Return type:
dict
- eigensdk.crypto.bls.attestation.g1_to_tupple(g1)
Converts a G1 point to a tuple of (x, y) coordinates.
- eigensdk.crypto.bls.attestation.g2_to_tupple(g2)
Converts a G2 point to a tuple of ((xa, xb), (ya, yb)) coordinates.
- eigensdk.crypto.bls.attestation.gen_random_bls_keys()
Generates a new random BLS key pair.
- Return type:
- eigensdk.crypto.bls.attestation.new_fp_element(v)
Creates a new Fp element with the given integer value.
- Return type:
Fp
- Parameters:
v (int)
- eigensdk.crypto.bls.attestation.new_g1_point(x, y)
Constructs a new G1Point.
- Return type:
- Parameters:
x (int)
y (int)
- eigensdk.crypto.bls.attestation.new_g2_point(xa, xb, ya, yb)
Constructs a new G2Point.
- Return type:
- Parameters:
xa (int)
xb (int)
ya (int)
yb (int)
- eigensdk.crypto.bls.attestation.new_key_pair(priv_key)
Creates a new key pair from the given private key.
- Return type:
- Parameters:
priv_key (PrivateKey)
- eigensdk.crypto.bls.attestation.new_key_pair_from_string(sk)
Creates a new key pair from a private key string.
- Return type:
- Parameters:
sk (str)
- eigensdk.crypto.bls.attestation.new_private_key(sk=b'')
Creates a new BLS private key from the given secret bytes.
- Return type:
- Parameters:
sk (bytes)
- eigensdk.crypto.bls.attestation.new_zero_g1_point()
Creates a new G1Point representing the zero point.
- Return type:
- eigensdk.crypto.bls.attestation.new_zero_g2_point()
Creates a new G2Point representing the zero point.
- Return type: