libp2p.crypto package
Subpackages
Submodules
libp2p.crypto.authenticated_encryption module
- class libp2p.crypto.authenticated_encryption.EncryptionParameters(cipher_type: str, hash_type: str, iv: bytes, mac_key: bytes, cipher_key: bytes)
Bases:
object
- class libp2p.crypto.authenticated_encryption.MacAndCipher(parameters: EncryptionParameters)
Bases:
object
- libp2p.crypto.authenticated_encryption.initialize_pair(cipher_type: str, hash_type: str, secret: bytes) tuple[EncryptionParameters, EncryptionParameters]
Return a pair of
Keysfor use in securing a communications channel with authenticated encryption derived from thesecretand using the requestedcipher_typeandhash_type.
libp2p.crypto.ecc module
- class libp2p.crypto.ecc.ECCPrivateKey(impl: int, curve: <MagicMock name='mock.curve.Curve' id='132160889003488'>)
Bases:
PrivateKey- classmethod new(curve: str) ECCPrivateKey
- class libp2p.crypto.ecc.ECCPublicKey(impl: <MagicMock name='mock.point.Point' id='132160889008096'>, curve: <MagicMock name='mock.curve.Curve' id='132160889003488'>)
Bases:
PublicKey- classmethod from_bytes(data: bytes, curve: str) ECCPublicKey
libp2p.crypto.ed25519 module
Ed25519 cryptographic key implementation.
This module provides Ed25519 public and private key implementations using the PyNaCl library. Ed25519 is used for libp2p peer identity signatures.
- class libp2p.crypto.ed25519.Ed25519PrivateKey(impl: SigningKey)
Bases:
PrivateKeyEd25519 private key implementation.
Provides cryptographic operations for Ed25519 private keys including signature generation and public key derivation. Used for libp2p peer identity signing.
- classmethod from_bytes(data: bytes) Ed25519PrivateKey
- classmethod new(seed: bytes | None = None) Ed25519PrivateKey
- class libp2p.crypto.ed25519.Ed25519PublicKey(impl: VerifyKey)
Bases:
PublicKeyEd25519 public key implementation.
Provides cryptographic operations for Ed25519 public keys including signature verification. Used for libp2p peer identity verification.
- classmethod from_bytes(key_bytes: bytes) Ed25519PublicKey
libp2p.crypto.exceptions module
- exception libp2p.crypto.exceptions.CryptographyError
Bases:
BaseLibp2pError
- exception libp2p.crypto.exceptions.MissingDeserializerError
Bases:
CryptographyErrorRaise if the requested deserialization routine is missing for some type of cryptographic key.
libp2p.crypto.key_exchange module
libp2p.crypto.keys module
Key types and interfaces.
- class libp2p.crypto.keys.KeyPair(private_key: libp2p.crypto.keys.PrivateKey, public_key: libp2p.crypto.keys.PublicKey)
Bases:
object- private_key: PrivateKey
- class libp2p.crypto.keys.KeyType(value)
Bases:
EnumAn enumeration.
- ECC_P256 = 4
- ECDSA = 3
- Ed25519 = 1
- RSA = 0
- Secp256k1 = 2
- X25519 = 5
- class libp2p.crypto.keys.PrivateKey
Bases:
KeyA
PrivateKeyrepresents a cryptographic private key.
libp2p.crypto.rsa module
- class libp2p.crypto.rsa.RSAPrivateKey(impl: RsaKey)
Bases:
PrivateKey- classmethod new(bits: int = 2048, e: int = 65537) RSAPrivateKey
- class libp2p.crypto.rsa.RSAPublicKey(impl: RsaKey)
Bases:
PublicKey- classmethod from_bytes(key_bytes: bytes) RSAPublicKey
- libp2p.crypto.rsa.create_new_key_pair(bits: int = 2048, e: int = 65537) KeyPair
Returns a new RSA keypair with the requested key size (
bits) and the given public exponente.Sane defaults are provided for both values.
- libp2p.crypto.rsa.validate_rsa_key_length(key_length: int) None
Validate that the RSA key length is positive and within the allowed maximum.
- Parameters:
key_length – RSA key size in bits.
- Raises:
CryptographyError – If the key size is not positive or exceeds MAX_RSA_KEY_SIZE.
- libp2p.crypto.rsa.validate_rsa_key_size(key: RsaKey) None
Validate that an RSA key’s size is within acceptable bounds.
- Parameters:
key – The RSA key to validate.
- Raises:
CryptographyError – If the key size is invalid.
libp2p.crypto.secp256k1 module
- class libp2p.crypto.secp256k1.Secp256k1PrivateKey(impl: PrivateKey)
Bases:
PrivateKey- classmethod deserialize(data: bytes) Secp256k1PrivateKey
- classmethod from_bytes(data: bytes) Secp256k1PrivateKey
- classmethod new(secret: bytes | None = None) Secp256k1PrivateKey
- class libp2p.crypto.secp256k1.Secp256k1PublicKey(impl: PublicKey)
Bases:
PublicKey- classmethod deserialize(data: bytes) Secp256k1PublicKey
- classmethod from_bytes(data: bytes) Secp256k1PublicKey
libp2p.crypto.serialization module
- libp2p.crypto.serialization.deserialize_private_key(data: bytes) PrivateKey