From 8134dcddc796dec19b0641b21c6a1547fb32307f Mon Sep 17 00:00:00 2001 From: itsm3abena Date: Mon, 15 Jul 2024 14:29:20 +0300 Subject: [PATCH 1/2] Update: docs current --- docs/ecc.rst | 18 --- hdwallet/ecc/__init__.py | 67 +++++++++++ hdwallet/ecc/iprivate_key.py | 4 - hdwallet/ecc/ipublic_key.py | 8 -- hdwallet/ecc/kholaw/ed25519/point.py | 5 - hdwallet/ecc/kholaw/ed25519/private_key.py | 27 +---- hdwallet/ecc/kholaw/ed25519/public_key.py | 9 -- hdwallet/ecc/slip10/ed25519/blake2b/point.py | 5 - .../ecc/slip10/ed25519/blake2b/private_key.py | 26 ----- .../ecc/slip10/ed25519/blake2b/public_key.py | 33 ------ hdwallet/ecc/slip10/ed25519/monero/point.py | 5 - .../ecc/slip10/ed25519/monero/private_key.py | 13 --- .../ecc/slip10/ed25519/monero/public_key.py | 25 ---- hdwallet/ecc/slip10/ed25519/point.py | 56 +-------- hdwallet/ecc/slip10/ed25519/private_key.py | 26 +---- hdwallet/ecc/slip10/ed25519/public_key.py | 37 ------ hdwallet/ecc/slip10/nist256p1/point.py | 53 --------- hdwallet/ecc/slip10/nist256p1/private_key.py | 25 ---- hdwallet/ecc/slip10/nist256p1/public_key.py | 37 ------ hdwallet/ecc/slip10/secp256k1/point.py | 108 +----------------- hdwallet/ecc/slip10/secp256k1/private_key.py | 49 -------- hdwallet/ecc/slip10/secp256k1/public_key.py | 75 +----------- 22 files changed, 75 insertions(+), 636 deletions(-) diff --git a/docs/ecc.rst b/docs/ecc.rst index 8caed77..f8ef64e 100644 --- a/docs/ecc.rst +++ b/docs/ecc.rst @@ -7,72 +7,54 @@ Elliptic Curve Cryptography (ECC) .. autoclass:: hdwallet.ecc.kholaw.ed25519.point.KholawEd25519Point :members: - :inherited-members: .. autoclass:: hdwallet.ecc.kholaw.ed25519.private_key.KholawEd25519PrivateKey :members: - :inherited-members: .. autoclass:: hdwallet.ecc.kholaw.ed25519.public_key.KholawEd25519PublicKey :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.ed25519.blake2b.point.SLIP10Ed25519Blake2bPoint :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.ed25519.blake2b.private_key.SLIP10Ed25519Blake2bPrivateKey :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.ed25519.blake2b.public_key.SLIP10Ed25519Blake2bPublicKey :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.ed25519.monero.point.SLIP10Ed25519MoneroPoint :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.ed25519.monero.private_key.SLIP10Ed25519MoneroPrivateKey :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.ed25519.monero.public_key.SLIP10Ed25519MoneroPublicKey :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.ed25519.point.SLIP10Ed25519Point :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.ed25519.private_key.SLIP10Ed25519PrivateKey :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.ed25519.public_key.SLIP10Ed25519PublicKey :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.nist256p1.point.SLIP10Nist256p1Point :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.nist256p1.private_key.SLIP10Nist256p1PrivateKey :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.nist256p1.public_key.SLIP10Nist256p1PublicKey :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.secp256k1.point.SLIP10Secp256k1PointCoincurve :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.secp256k1.private_key.SLIP10Secp256k1PrivateKeyCoincurve :members: - :inherited-members: .. autoclass:: hdwallet.ecc.slip10.secp256k1.public_key.SLIP10Secp256k1PublicKeyCoincurve :members: - :inherited-members: diff --git a/hdwallet/ecc/__init__.py b/hdwallet/ecc/__init__.py index a335185..360c776 100644 --- a/hdwallet/ecc/__init__.py +++ b/hdwallet/ecc/__init__.py @@ -26,6 +26,29 @@ class ECCS: + """ + A class that manages a dictionary of ecc classes. + + This class provides methods to retrieve names and classes of various entropy implementations, + as well as methods to validate and access specific ecc classes by name. + + Here are available ecc names and classes: + +--------------------------+--------------------------------------------------------------------------+ + | Name | Class | + +==========================+==========================================================================+ + | KholawEd25519ECC | | + +--------------------------+--------------------------------------------------------------------------+ + | SLIP10Ed25519ECC | | + +--------------------------+--------------------------------------------------------------------------+ + | SLIP10Ed25519Blake2bECC | | + +--------------------------+--------------------------------------------------------------------------+ + | SLIP10Ed25519MoneroECC | | + +--------------------------+--------------------------------------------------------------------------+ + | SLIP10Nist256p1ECC | | + +--------------------------+--------------------------------------------------------------------------+ + | SLIP10Secp256k1ECC | | + +--------------------------+--------------------------------------------------------------------------+ + """ dictionary: Dict[str, Type[IEllipticCurveCryptography]] = { KholawEd25519ECC.NAME: KholawEd25519ECC, @@ -38,14 +61,37 @@ class ECCS: @classmethod def names(cls) -> List[str]: + """ + Get the names from the class's dictionary. + + :return: A list of names stored as keys in the `dictionary`. + :rtype: List[str] + """ + return list(cls.dictionary.keys()) @classmethod def classes(cls) -> List[Type[IEllipticCurveCryptography]]: + """ + Get the list of elliptic curve cryptography (ECC) classes from the class's dictionary. + + :return: A list of ECC classes stored as values in the `dictionary`. + :rtype: List[Type[IEllipticCurveCryptography]] + """ + return list(cls.dictionary.values()) @classmethod def ecc(cls, name: str) -> Type[IEllipticCurveCryptography]: + """ + Retrieve an elliptic curve cryptography (ECC) class by name. + + :param name: The name of the ECC class to retrieve. + :type name: str + + :return: The ECC class corresponding to the given name. + :rtype: Type[IEllipticCurveCryptography] + """ if not cls.is_ecc(name=name): raise ECCError( @@ -56,12 +102,33 @@ def ecc(cls, name: str) -> Type[IEllipticCurveCryptography]: @classmethod def is_ecc(cls, name: str) -> bool: + """ + Check if the given name is a valid ECC class name. + + :param name: The name to check. + :type name: str + + :return: True if the name is a valid ECC class name, False otherwise. + :rtype: bool + """ + return name in cls.names() def validate_and_get_public_key( public_key: Union[bytes, str, IPublicKey], public_key_cls: Type[IPublicKey] ) -> IPublicKey: + """ + Validate and convert the input to an IPublicKey instance. + + :param public_key: The public key to validate and convert. It can be of type bytes, str, or IPublicKey. + :type public_key: Union[bytes, str, IPublicKey] + :param public_key_cls: The class to use for creating an IPublicKey instance from bytes. + :type public_key_cls: Type[IPublicKey] + + :return: A valid IPublicKey instance. + :rtype: IPublicKey + """ if isinstance(public_key, bytes): public_key: IPublicKey = public_key_cls.from_bytes(public_key) elif isinstance(public_key, str): diff --git a/hdwallet/ecc/iprivate_key.py b/hdwallet/ecc/iprivate_key.py index b7cc675..448e227 100644 --- a/hdwallet/ecc/iprivate_key.py +++ b/hdwallet/ecc/iprivate_key.py @@ -53,10 +53,6 @@ def is_valid_bytes(cls, private_key: bytes) -> bool: :return: True if the point is valid, False otherwise. :rtype: bool - - >>> from {module_path} import {class_name} - >>> {class_name}.is_valid_bytes(private_key=...) - ... """ try: diff --git a/hdwallet/ecc/ipublic_key.py b/hdwallet/ecc/ipublic_key.py index d2d6af2..58a2d69 100644 --- a/hdwallet/ecc/ipublic_key.py +++ b/hdwallet/ecc/ipublic_key.py @@ -67,10 +67,6 @@ def is_valid_bytes(cls, public_key: bytes) -> bool: :return: True if the byte array represents a valid public key, False otherwise. :rtype: bool - - >>> from {module_path} import {class_name} - >>> {class_name}.is_valid_bytes(public_key=...) - ... """ try: @@ -89,10 +85,6 @@ def is_valid_point(cls, point: IPoint) -> bool: :return: True if the point is valid, False otherwise. :rtype: bool - - >>> from {module_path} import {class_name} - >>> {class_name}.is_valid_point(point=...) - ... """ try: diff --git a/hdwallet/ecc/kholaw/ed25519/point.py b/hdwallet/ecc/kholaw/ed25519/point.py index b42d59c..2e00e34 100644 --- a/hdwallet/ecc/kholaw/ed25519/point.py +++ b/hdwallet/ecc/kholaw/ed25519/point.py @@ -16,11 +16,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.kholaw.ed25519.point import KholawEd25519Point - >>> ecc: = KholawEd25519Point(point=...) - >>> ecc.name() - "Kholaw-Ed25519" """ return "Kholaw-Ed25519" diff --git a/hdwallet/ecc/kholaw/ed25519/private_key.py b/hdwallet/ecc/kholaw/ed25519/private_key.py index 3edb707..81d8a19 100644 --- a/hdwallet/ecc/kholaw/ed25519/private_key.py +++ b/hdwallet/ecc/kholaw/ed25519/private_key.py @@ -27,7 +27,6 @@ def __init__(self, private_key: IPrivateKey, extended_key: bytes) -> None: :param private_key: The private key to be used. Must be an instance of `SLIP10Ed25519PrivateKey`. :type private_key: IPrivateKey - :param extended_key: The extended key associated with the private key. Must be of length specified by `SLIP10Ed25519PrivateKey.length()`. :type extended_key: bytes @@ -48,11 +47,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.kholaw.ed25519.private_key import KholawEd25519PrivateKey - >>> ecc: = KholawEd25519PrivateKey(private_key=...) - >>> ecc.name() - "Kholaw-Ed25519" """ return "Kholaw-Ed25519" @@ -64,12 +58,9 @@ def from_bytes(cls, private_key: bytes) -> IPrivateKey: :param private_key: The byte sequence representing the private key. :type private_key: bytes + :return: An instance of the private key. :rtype: IPrivateKey - - >>> from hdwallet.ecc.kholaw.ed25519.private_key import KholawEd25519PrivateKey - >>> KholawEd25519PrivateKey(private_key=...) - "..." """ return cls( @@ -89,10 +80,6 @@ def length() -> int: :return: The length of the private key in bytes. :rtype: int - - >>> from hdwallet.ecc.kholaw.ed25519.private_key import KholawEd25519PrivateKey - >>> KholawEd25519PrivateKey.length() - ... """ return KHOLAW_ED25519_CONST.PRIVATE_KEY_BYTE_LENGTH @@ -103,10 +90,6 @@ def underlying_object(self) -> Any: :return: The underlying object of the signing key. :rtype: Any - - >>> from hdwallet.ecc.kholaw.ed25519.private_key import KholawEd25519PrivateKey - >>> KholawEd25519PrivateKey.underlying_object() - "..." """ return self.signing_key.underlying_object() @@ -117,10 +100,6 @@ def raw(self) -> bytes: :return: The raw byte sequence of the signing key and extended key. :rtype: bytes - - >>> from hdwallet.ecc.kholaw.ed25519.private_key import KholawEd25519PrivateKey - >>> KholawEd25519PrivateKey.raw() - ... """ return self.signing_key.raw() + self.extended_key @@ -131,10 +110,6 @@ def public_key(self) -> IPublicKey: :return: The generated public key. :rtype: IPublicKey - - >>> from hdwallet.ecc.kholaw.ed25519.private_key import KholawEd25519PrivateKey - >>> KholawEd25519PrivateKey.public_key) - "..." """ return KholawEd25519PublicKey(VerifyKey( diff --git a/hdwallet/ecc/kholaw/ed25519/public_key.py b/hdwallet/ecc/kholaw/ed25519/public_key.py index db1bb91..05d5668 100644 --- a/hdwallet/ecc/kholaw/ed25519/public_key.py +++ b/hdwallet/ecc/kholaw/ed25519/public_key.py @@ -18,11 +18,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.kholaw.ed25519.public_key import KholawEd25519PublicKey - >>> ecc: = KholawEd25519PublicKey(public_key=...) - >>> ecc.name() - "Kholaw-Ed25519" """ return "Kholaw-Ed25519" @@ -33,10 +28,6 @@ def point(self) -> IPoint: :return: The point on the Ed25519 curve corresponding to the public key. :rtype: IPoint - - >>> from hdwallet.ecc.kholaw.ed25519.public_key import KholawEd25519PublicKey - >>> KholawEd25519PublicKey.point() - "..." """ return KholawEd25519Point(bytes(self.verify_key)) diff --git a/hdwallet/ecc/slip10/ed25519/blake2b/point.py b/hdwallet/ecc/slip10/ed25519/blake2b/point.py index e72fc16..10dcc1b 100644 --- a/hdwallet/ecc/slip10/ed25519/blake2b/point.py +++ b/hdwallet/ecc/slip10/ed25519/blake2b/point.py @@ -16,11 +16,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.point import SLIP10Ed25519Blake2bPoint - >>> ecc: = SLIP10Ed25519Blake2bPoint(point=...) - >>> ecc.name() - "SLIP10-Ed25519-Blake2b" """ return "SLIP10-Ed25519-Blake2b" diff --git a/hdwallet/ecc/slip10/ed25519/blake2b/private_key.py b/hdwallet/ecc/slip10/ed25519/blake2b/private_key.py index 6efddb7..f6a36d4 100644 --- a/hdwallet/ecc/slip10/ed25519/blake2b/private_key.py +++ b/hdwallet/ecc/slip10/ed25519/blake2b/private_key.py @@ -35,11 +35,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.private_key import SLIP10Ed25519Blake2bPrivateKey - >>> ecc: = SLIP10Ed25519Blake2bPrivateKey(private_key=...) - >>> ecc.name() - "SLIP10-Ed25519-Blake2b" """ return "SLIP10-Ed25519-Blake2b" @@ -54,10 +49,6 @@ def from_bytes(cls, private_key: bytes) -> IPrivateKey: :return: An instance of the private key. :rtype: IPrivateKey - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.private_key import SLIP10Ed25519Blake2bPrivateKey - >>> SLIP10Ed25519Blake2bPrivateKey.from_bytes(private_key=...) - "..." """ try: @@ -72,10 +63,6 @@ def length() -> int: :return: The length of the private key in bytes. :rtype: int - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.private_key import SLIP10Ed25519Blake2bPrivateKey - >>> SLIP10Ed25519Blake2bPrivateKey.length() - ... """ return SLIP10_ED25519_CONST.PRIVATE_KEY_BYTE_LENGTH @@ -86,10 +73,6 @@ def underlying_object(self) -> Any: :return: The underlying object of the signing key. :rtype: Any - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.private_key import SLIP10Ed25519Blake2bPrivateKey - >>> SLIP10Ed25519Blake2bPrivateKey.underlying_object() - "..." """ return self.signing_key @@ -100,11 +83,6 @@ def raw(self) -> bytes: :return: The raw bytes of the signing key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.private_key import SLIP10Ed25519Blake2bPrivateKey - >>> SLIP10Ed25519Blake2bPrivateKey.raw() - ... - """ return self.signing_key.to_bytes() @@ -115,10 +93,6 @@ def public_key(self) -> IPublicKey: :return: The public key as an instance of IPublicKey. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.private_key import SLIP10Ed25519Blake2bPrivateKey - >>> SLIP10Ed25519Blake2bPrivateKey.public_key() - "..." """ return SLIP10Ed25519Blake2bPublicKey(self.signing_key.get_verifying_key()) diff --git a/hdwallet/ecc/slip10/ed25519/blake2b/public_key.py b/hdwallet/ecc/slip10/ed25519/blake2b/public_key.py index 607c13d..ba2fe46 100644 --- a/hdwallet/ecc/slip10/ed25519/blake2b/public_key.py +++ b/hdwallet/ecc/slip10/ed25519/blake2b/public_key.py @@ -40,11 +40,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.public_key import SLIP10Ed25519Blake2bPublicKey - >>> ecc: = SLIP10Ed25519Blake2bPublicKey(public_key=...) - >>> ecc.name() - "SLIP10-Ed25519-Blake2b" """ return "SLIP10-Ed25519-Blake2b" @@ -59,10 +54,6 @@ def from_bytes(cls, public_key: bytes) -> IPublicKey: :return: An instance of IPublicKey. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.public_key import SLIP10Ed25519Blake2bPublicKey - >>> SLIP10Ed25519Blake2bPublicKey.from_bytes(public_key=...) - "..." """ if (len(public_key) == SLIP10_ED25519_CONST.PUBLIC_KEY_BYTE_LENGTH + len(SLIP10_ED25519_CONST.PUBLIC_KEY_PREFIX) @@ -86,10 +77,6 @@ def from_point(cls, point: IPoint) -> IPublicKey: :return: An instance of IPublicKey. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.public_key import SLIP10Ed25519Blake2bPublicKey - >>> SLIP10Ed25519Blake2bPublicKey.from_point(point="...") - "..." """ return cls.from_bytes(point.raw_encoded()) @@ -101,10 +88,6 @@ def compressed_length() -> int: :return: The compressed length of the public key. :rtype: int - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.public_key import SLIP10Ed25519Blake2bPublicKey - >>> SLIP10Ed25519Blake2bPublicKey.compressed_length() - ... """ return SLIP10_ED25519_CONST.PUBLIC_KEY_BYTE_LENGTH + len(SLIP10_ED25519_CONST.PUBLIC_KEY_PREFIX) @@ -126,10 +109,6 @@ def underlying_object(self) -> Any: :return: The underlying object representing the public key. :rtype: Any - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.public_key import SLIP10Ed25519Blake2bPublicKey - >>> SLIP10Ed25519Blake2bPublicKey.underlying_object() - "..." """ return self.verify_key @@ -143,10 +122,6 @@ def raw_compressed(self) -> bytes: :return: The raw compressed bytes of the public key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.public_key import SLIP10Ed25519Blake2bPublicKey - >>> SLIP10Ed25519Blake2bPublicKey.raw_compressed() - ... """ return SLIP10_ED25519_CONST.PUBLIC_KEY_PREFIX + self.verify_key.to_bytes() @@ -157,10 +132,6 @@ def raw_uncompressed(self) -> bytes: :return: The raw uncompressed bytes of the public key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.public_key import SLIP10Ed25519Blake2bPublicKey - >>> SLIP10Ed25519Blake2bPublicKey.raw_uncompressed() - ... """ return self.raw_compressed() @@ -171,10 +142,6 @@ def point(self) -> IPoint: :return: The point corresponding to the public key. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.ed25519.blake2b.public_key import SLIP10Ed25519Blake2bPublicKey - >>> SLIP10Ed25519Blake2bPublicKey.point() - "..." """ return SLIP10Ed25519Blake2bPoint(self.verify_key.to_bytes()) diff --git a/hdwallet/ecc/slip10/ed25519/monero/point.py b/hdwallet/ecc/slip10/ed25519/monero/point.py index 5dbfb21..bdca6ba 100644 --- a/hdwallet/ecc/slip10/ed25519/monero/point.py +++ b/hdwallet/ecc/slip10/ed25519/monero/point.py @@ -16,11 +16,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.ed25519.monero.point import SLIP10Ed25519MoneroPoint - >>> ecc: = SLIP10Ed25519MoneroPoint(point=...) - >>> ecc.name() - "SLIP10-Ed25519-Monero" """ return "SLIP10-Ed25519-Monero" diff --git a/hdwallet/ecc/slip10/ed25519/monero/private_key.py b/hdwallet/ecc/slip10/ed25519/monero/private_key.py index e93a231..df4d12d 100644 --- a/hdwallet/ecc/slip10/ed25519/monero/private_key.py +++ b/hdwallet/ecc/slip10/ed25519/monero/private_key.py @@ -25,11 +25,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.ed25519.monero.private_key import SLIP10Ed25519MoneroPrivateKey - >>> ecc: = SLIP10Ed25519MoneroPrivateKey(private_key=...) - >>> ecc.name() - "SLIP10-Ed25519-Monero" """ return "SLIP10-Ed25519-Monero" @@ -44,10 +39,6 @@ def from_bytes(cls, private_key: bytes) -> IPrivateKey: :return: An instance of IPrivateKey created from the provided byte sequence. :rtype: IPrivateKey - - >>> from hdwallet.ecc.slip10.ed25519.monero.private_key import SLIP10Ed25519MoneroPrivateKey - >>> SLIP10Ed25519MoneroPrivateKey.from_bytes(private_key=...) - "..." """ if not scalar_is_valid(private_key): @@ -60,10 +51,6 @@ def public_key(self) -> IPublicKey: :return: The public key derived from the private key. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.ed25519.monero.private_key import SLIP10Ed25519MoneroPrivateKey - >>> SLIP10Ed25519MoneroPrivateKey.point() - "..." """ return SLIP10Ed25519MoneroPublicKey( diff --git a/hdwallet/ecc/slip10/ed25519/monero/public_key.py b/hdwallet/ecc/slip10/ed25519/monero/public_key.py index 2dd3ada..c926907 100644 --- a/hdwallet/ecc/slip10/ed25519/monero/public_key.py +++ b/hdwallet/ecc/slip10/ed25519/monero/public_key.py @@ -19,11 +19,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.ed25519.monero.public_key import SLIP10Ed25519MoneroPublicKey - >>> ecc: = SLIP10Ed25519MoneroPublicKey(public_key=...) - >>> ecc.name() - "SLIP10-Ed25519-Monero" """ return "SLIP10-Ed25519-Monero" @@ -35,10 +30,6 @@ def compressed_length() -> int: :return: The compressed length of the Ed25519 Monero public key. :rtype: int - - >>> from hdwallet.ecc.slip10.ed25519.monero.public_key import SLIP10Ed25519MoneroPublicKey - >>> SLIP10Ed25519MoneroPublicKey.compressed_length() - ... """ return SLIP10_ED25519_CONST.PUBLIC_KEY_BYTE_LENGTH @@ -50,10 +41,6 @@ def uncompressed_length() -> int: :return: The uncompressed length of the Ed25519 Monero public key. :rtype: int - - >>> from hdwallet.ecc.slip10.ed25519.monero.public_key import SLIP10Ed25519MoneroPublicKey - >>> SLIP10Ed25519MoneroPublicKey.uncompressed_length() - ... """ return SLIP10Ed25519MoneroPublicKey.compressed_length() @@ -64,10 +51,6 @@ def raw_compressed(self) -> bytes: :return: The raw compressed public key bytes. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.monero.public_key import SLIP10Ed25519MoneroPublicKey - >>> SLIP10Ed25519MoneroPublicKey.raw_compressed() - ... """ return bytes(self.verify_key) @@ -78,10 +61,6 @@ def raw_uncompressed(self) -> bytes: :return: The raw compressed public key bytes. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.monero.public_key import SLIP10Ed25519MoneroPublicKey - >>> SLIP10Ed25519MoneroPublicKey.raw_uncompressed() - ... """ return self.raw_compressed() @@ -92,10 +71,6 @@ def point(self) -> IPoint: :return: The elliptic curve point corresponding to the public key. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.ed25519.monero.public_key import SLIP10Ed25519MoneroPublicKey - >>> SLIP10Ed25519MoneroPublicKey.point() - "..." """ return SLIP10Ed25519MoneroPoint(bytes(self.verify_key)) diff --git a/hdwallet/ecc/slip10/ed25519/point.py b/hdwallet/ecc/slip10/ed25519/point.py index 3aabf4a..aab342e 100644 --- a/hdwallet/ecc/slip10/ed25519/point.py +++ b/hdwallet/ecc/slip10/ed25519/point.py @@ -53,11 +53,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> ecc: = SLIP10Ed25519Point(point=...) - >>> ecc.name() - "SLIP10-Ed25519" """ return "SLIP10-Ed25519" @@ -69,12 +64,9 @@ def from_bytes(cls, point: bytes) -> IPoint: :param point: The byte representation of the point. :type point: bytes + :return: An instance of the Ed25519 point. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.from_bytes(point=...) - "..." """ if not point_is_on_curve(point): @@ -92,14 +84,12 @@ def from_coordinates(cls, x: int, y: int) -> IPoint: :param x: The x-coordinate of the point. :type x: int + :param y: The y-coordinate of the point. :type y: int + :return: An instance of the Ed25519 point. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.from_coordinates(x=..., y=...) - "..." """ return cls.from_bytes( @@ -112,10 +102,6 @@ def underlying_object(self) -> Any: :return: The underlying object representing the Ed25519 Monero point. :rtype: Any - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.underlying_object() - "..." """ return self.point @@ -126,10 +112,6 @@ def x(self) -> int: :return: The x-coordinate of the Ed25519 Monero public key point. :rtype: int - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.x() - ... """ if self._x is None: @@ -142,10 +124,6 @@ def y(self) -> int: :return: The y-coordinate of the Ed25519 point. :rtype: int - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.y() - ... """ if self._y is None: @@ -158,10 +136,6 @@ def raw(self) -> bytes: :return: Raw bytes of the signing key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.raw() - ... """ return self.raw_decoded() @@ -172,10 +146,6 @@ def raw_encoded(self) -> bytes: :return: The raw encoded point as bytes. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.raw_encoded() - ... """ return self.point @@ -186,10 +156,6 @@ def raw_decoded(self) -> bytes: :return: The raw decoded bytes of the point coordinates. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.raw_decoded() - ... """ return int_encode(self.x()) + int_encode(self.y()) @@ -203,10 +169,6 @@ def __add__(self, point: IPoint) -> IPoint: :return: The resulting point after addition. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.__add__(point="...") - "..." """ return self.__class__( @@ -222,10 +184,6 @@ def __radd__(self, point: IPoint) -> IPoint: :return: The resulting point after addition. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.__radd__(point="...") - "..." """ return self + point @@ -239,10 +197,6 @@ def __mul__(self, scalar: int) -> IPoint: :return: The resulting point after scalar multiplication. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.__mul__(scalar=...) - "..." """ if self.is_generator: @@ -262,10 +216,6 @@ def __rmul__(self, scalar: int) -> IPoint: :return: The resulting point after scalar multiplication. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.ed25519.point import SLIP10Ed25519Point - >>> SLIP10Ed25519Point.__rmul__(scalar=...) - "..." """ return self * scalar diff --git a/hdwallet/ecc/slip10/ed25519/private_key.py b/hdwallet/ecc/slip10/ed25519/private_key.py index 1a8afed..c46257a 100644 --- a/hdwallet/ecc/slip10/ed25519/private_key.py +++ b/hdwallet/ecc/slip10/ed25519/private_key.py @@ -36,11 +36,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.ed25519.private_key import SLIP10Ed25519PrivateKey - >>> ecc: = SLIP10Ed25519PrivateKey(private_key=...) - >>> ecc.name() - "SLIP10-Ed25519" """ return "SLIP10-Ed25519" @@ -52,12 +47,9 @@ def from_bytes(cls, private_key: bytes) -> IPrivateKey: :param private_key: The byte representation of the private key. :type private_key: bytes + :return: An instance of the class initialized with the provided private key. :rtype: IPrivateKey - - >>> from hdwallet.ecc.slip10.ed25519.private_key import SLIP10Ed25519PrivateKey - >>> SLIP10Ed25519PrivateKey.from_bytes(private_key=...) - "..." """ try: @@ -72,10 +64,6 @@ def length() -> int: :return: The length of the private key in bytes. :rtype: int - - >>> from hdwallet.ecc.slip10.ed25519.private_key import SLIP10Ed25519PrivateKey - >>> SLIP10Ed25519PrivateKey.length() - ... """ return SLIP10_ED25519_CONST.PRIVATE_KEY_BYTE_LENGTH @@ -86,10 +74,6 @@ def underlying_object(self) -> Any: :return: The underlying signing key object. :rtype: Any - - >>> from hdwallet.ecc.slip10.ed25519.private_key import SLIP10Ed25519PrivateKey - >>> SLIP10Ed25519PrivateKey.underlying_object() - "..." """ return self.signing_key @@ -100,10 +84,6 @@ def raw(self) -> bytes: :return: Raw bytes of the signing key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.private_key import SLIP10Ed25519PrivateKey - >>> SLIP10Ed25519PrivateKey.raw() - ... """ return bytes(self.signing_key) @@ -114,10 +94,6 @@ def public_key(self) -> IPublicKey: :return: The public key corresponding to the signing key. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.ed25519.private_key import SLIP10Ed25519PrivateKey - >>> SLIP10Ed25519PrivateKey.public_key() - "..." """ return SLIP10Ed25519PublicKey(self.signing_key.verify_key) diff --git a/hdwallet/ecc/slip10/ed25519/public_key.py b/hdwallet/ecc/slip10/ed25519/public_key.py index a8f8075..6029577 100644 --- a/hdwallet/ecc/slip10/ed25519/public_key.py +++ b/hdwallet/ecc/slip10/ed25519/public_key.py @@ -38,11 +38,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.ed25519.public_key import SLIP10Ed25519PublicKey - >>> ecc: = SLIP10Ed25519PublicKey(public_key=...) - >>> ecc.name() - "SLIP10-Ed25519" """ return "SLIP10-Ed25519" @@ -58,10 +53,6 @@ def from_bytes(cls, public_key: bytes) -> IPublicKey: :type public_key: bytes :return: An instance of IPublicKey. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.ed25519.public_key import SLIP10Ed25519PublicKey - >>> SLIP10Ed25519PublicKey.from_bytes(public_key=...) - "..." """ if (len(public_key) == SLIP10_ED25519_CONST.PUBLIC_KEY_BYTE_LENGTH + len(SLIP10_ED25519_CONST.PUBLIC_KEY_PREFIX) @@ -83,10 +74,6 @@ def from_point(cls, point: IPoint) -> IPublicKey: :return: The length of the compressed public key in bytes. :rtype: int - - >>> from hdwallet.ecc.slip10.ed25519.public_key import SLIP10Ed25519PublicKey - >>> SLIP10Ed25519PublicKey.from_point(point="...") - "..." """ return cls.from_bytes(point.raw_encoded()) @@ -98,10 +85,6 @@ def compressed_length() -> int: :return: The total length of the compressed public key. :rtype: int - - >>> from hdwallet.ecc.slip10.ed25519.public_key import SLIP10Ed25519PublicKey - >>> SLIP10Ed25519PublicKey.compressed_length() - ... """ return SLIP10_ED25519_CONST.PUBLIC_KEY_BYTE_LENGTH + len(SLIP10_ED25519_CONST.PUBLIC_KEY_PREFIX) @@ -113,10 +96,6 @@ def uncompressed_length() -> int: :return: The underlying object of the public key. :rtype: Any - - >>> from hdwallet.ecc.slip10.ed25519.public_key import SLIP10Ed25519PublicKey - >>> SLIP10Ed25519PublicKey.uncompressed_length() - ... """ return SLIP10Ed25519PublicKey.compressed_length() @@ -127,10 +106,6 @@ def underlying_object(self) -> Any: :return: The underlying verify key object. :rtype: Any - - >>> from hdwallet.ecc.slip10.ed25519.public_key import SLIP10Ed25519PublicKey - >>> SLIP10Ed25519PublicKey.underlying_object() - "..." """ return self.verify_key @@ -141,10 +116,6 @@ def raw_compressed(self) -> bytes: :return: Compressed raw bytes of the public key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.public_key import SLIP10Ed25519PublicKey - >>> SLIP10Ed25519PublicKey.raw_compressed() - ... """ return SLIP10_ED25519_CONST.PUBLIC_KEY_PREFIX + bytes(self.verify_key) @@ -155,10 +126,6 @@ def raw_uncompressed(self) -> bytes: :return: Uncompressed raw bytes of the public key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.ed25519.public_key import SLIP10Ed25519PublicKey - >>> SLIP10Ed25519PublicKey.raw_uncompressed() - ... """ return self.raw_compressed() @@ -169,10 +136,6 @@ def point(self) -> IPoint: :return: An instance of IPoint representing the public key point. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.ed25519.public_key import SLIP10Ed25519PublicKey - >>> SLIP10Ed25519PublicKey.point() - "..." """ return SLIP10Ed25519Point(bytes(self.verify_key)) diff --git a/hdwallet/ecc/slip10/nist256p1/point.py b/hdwallet/ecc/slip10/nist256p1/point.py index 49f0049..c54a556 100644 --- a/hdwallet/ecc/slip10/nist256p1/point.py +++ b/hdwallet/ecc/slip10/nist256p1/point.py @@ -39,11 +39,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> ecc: = SLIP10Nist256p1Point(point=...) - >>> ecc.name() - "SLIP10-Nist256p1" """ return "SLIP10-Nist256p1" @@ -58,10 +53,6 @@ def from_bytes(cls, point: bytes) -> "SLIP10Nist256p1Point": :return: An instance of SLIP10Nist256p1Point representing the decoded point. :rtype: SLIP10Nist256p1Point - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.from_bytes(point=...) - "..." """ try: @@ -91,10 +82,6 @@ def from_coordinates(cls, x: int, y: int) -> "SLIP10Nist256p1Point": :return: An instance of SLIP10Nist256p1Point representing the specified coordinates. :rtype: SLIP10Nist256p1Point - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.from_coordinates(x=..., y=...) - "..." """ return cls( @@ -112,10 +99,6 @@ def underlying_object(self) -> Any: :return: The underlying elliptic curve point object. :rtype: Any - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.underlying_object() - "..." """ return self.point @@ -126,10 +109,6 @@ def x(self) -> int: :return: The x-coordinate of the elliptic curve point. :rtype: int - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.x() - ... """ return self.point.x() @@ -140,10 +119,6 @@ def y(self) -> int: :return: The y-coordinate of the elliptic curve point. :rtype: int - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.y() - ... """ return self.point.y() @@ -154,10 +129,6 @@ def raw(self) -> bytes: :return: Raw bytes representation of the elliptic curve point. :rtype: bytes - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.raw() - ... """ return self.raw_decoded() @@ -168,10 +139,6 @@ def raw_encoded(self) -> bytes: :return: Encoded bytes representation of the elliptic curve point. :rtype: bytes - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.raw_encoded() - ... """ try: @@ -190,10 +157,6 @@ def raw_decoded(self) -> bytes: :return: Decoded bytes representation of the elliptic curve point. :rtype: bytes - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.raw_decoded() - ... """ try: @@ -214,10 +177,6 @@ def __add__(self, point: IPoint) -> IPoint: :return: A new instance of the same class representing the resulting point after addition. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.__add__(point="...") - "..." """ return self.__class__(self.point + point.underlying_object()) @@ -232,10 +191,6 @@ def __radd__(self, point: IPoint) -> IPoint: :return: A new instance of the same class representing the resulting point after addition. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.__radd__(point="...") - "..." """ return self + point @@ -250,10 +205,6 @@ def __mul__(self, scalar: int) -> IPoint: :return: A new instance of the same class representing the resulting point after scalar multiplication. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.__mul__(scalar=...) - "..." """ return self.__class__(self.point * scalar) @@ -267,10 +218,6 @@ def __rmul__(self, scalar: int) -> IPoint: :return: The resulting point after scalar multiplication. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.nist256p1.point import SLIP10Nist256p1Point - >>> SLIP10Nist256p1Point.__rmul__(scalar=...) - "..." """ return self * scalar diff --git a/hdwallet/ecc/slip10/nist256p1/private_key.py b/hdwallet/ecc/slip10/nist256p1/private_key.py index 2629048..485a647 100644 --- a/hdwallet/ecc/slip10/nist256p1/private_key.py +++ b/hdwallet/ecc/slip10/nist256p1/private_key.py @@ -38,11 +38,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.nist256p1.private_key import SLIP10Nist256p1PrivateKey - >>> ecc: = SLIP10Nist256p1PrivateKey(private_key=...) - >>> ecc.name() - "SLIP10-Nist256p1" """ return "SLIP10-Nist256p1" @@ -57,10 +52,6 @@ def from_bytes(cls, private_key: bytes) -> IPrivateKey: :return: An instance of the private key. :rtype: IPrivateKey - - >>> from hdwallet.ecc.slip10.nist256p1.private_key import SLIP10Nist256p1PrivateKey - >>> SLIP10Nist256p1PrivateKey.from_bytes(private_key=...) - "..." """ try: @@ -79,10 +70,6 @@ def length() -> int: :return: The private key length in bytes. :rtype: int - - >>> from hdwallet.ecc.slip10.nist256p1.private_key import SLIP10Nist256p1PrivateKey - >>> SLIP10Nist256p1PrivateKey.length() - ... """ return SLIP10_SECP256K1_CONST.PRIVATE_KEY_BYTE_LENGTH @@ -93,10 +80,6 @@ def underlying_object(self) -> Any: :return: The underlying signing key object. :rtype: Any - - >>> from hdwallet.ecc.slip10.nist256p1.private_key import SLIP10Nist256p1PrivateKey - >>> SLIP10Nist256p1PrivateKey.underlying_object() - "..." """ return self.signing_key @@ -107,10 +90,6 @@ def raw(self) -> bytes: :return: The raw bytes of the signing key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.nist256p1.private_key import SLIP10Nist256p1PrivateKey - >>> SLIP10Nist256p1PrivateKey.raw() - ... """ return self.signing_key.to_string() @@ -121,10 +100,6 @@ def public_key(self) -> IPublicKey: :return: The public key associated with the signing key. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.nist256p1.private_key import SLIP10Nist256p1PrivateKey - >>> SLIP10Nist256p1PrivateKey.public_key() - "..." """ return SLIP10Nist256p1PublicKey(self.signing_key.get_verifying_key()) diff --git a/hdwallet/ecc/slip10/nist256p1/public_key.py b/hdwallet/ecc/slip10/nist256p1/public_key.py index c7e23aa..fd95c61 100644 --- a/hdwallet/ecc/slip10/nist256p1/public_key.py +++ b/hdwallet/ecc/slip10/nist256p1/public_key.py @@ -39,11 +39,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.nist256p1.public_key import SLIP10Nist256p1PublicKey - >>> ecc: = SLIP10Nist256p1PublicKey(public_key=...) - >>> ecc.name() - "SLIP10-Nist256p1" """ return "SLIP10-Nist256p1" @@ -58,10 +53,6 @@ def from_bytes(cls, public_key: bytes) -> IPublicKey: :return: An instance of IPublicKey. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.nist256p1.public_key import SLIP10Nist256p1PublicKey - >>> SLIP10Nist256p1PublicKey.from_bytes(public_key=...) - "..." """ try: @@ -83,10 +74,6 @@ def from_point(cls, point: IPoint) -> IPublicKey: :return: An instance of IPublicKey. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.nist256p1.public_key import SLIP10Nist256p1PublicKey - >>> SLIP10Nist256p1PublicKey.from_point(point=...) - "..." """ try: @@ -108,10 +95,6 @@ def compressed_length() -> int: :return: The length of the compressed public key. :rtype: int - - >>> from hdwallet.ecc.slip10.nist256p1.public_key import SLIP10Nist256p1PublicKey - >>> SLIP10Nist256p1PublicKey.compressed_length() - ... """ return SLIP10_SECP256K1_CONST.PUBLIC_KEY_COMPRESSED_BYTE_LENGTH @@ -123,10 +106,6 @@ def uncompressed_length() -> int: :return: The length of the uncompressed public key. :rtype: int - - >>> from hdwallet.ecc.slip10.nist256p1.public_key import SLIP10Nist256p1PublicKey - >>> SLIP10Nist256p1PublicKey.uncompressed_length() - ... """ return SLIP10_SECP256K1_CONST.PUBLIC_KEY_UNCOMPRESSED_BYTE_LENGTH @@ -137,10 +116,6 @@ def underlying_object(self) -> Any: :return: The underlying object representing the public key. :rtype: Any - - >>> from hdwallet.ecc.slip10.nist256p1.public_key import SLIP10Nist256p1PublicKey - >>> SLIP10Nist256p1PublicKey.underlying_object() - "..." """ return self.verify_key @@ -151,10 +126,6 @@ def raw_compressed(self) -> bytes: :return: The compressed raw bytes of the public key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.nist256p1.public_key import SLIP10Nist256p1PublicKey - >>> SLIP10Nist256p1PublicKey.raw_compressed() - ... """ return self.verify_key.to_string("compressed") @@ -165,10 +136,6 @@ def raw_uncompressed(self) -> bytes: :return: The uncompressed raw bytes of the public key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.nist256p1.public_key import SLIP10Nist256p1PublicKey - >>> SLIP10Nist256p1PublicKey.raw_uncompressed() - ... """ return self.verify_key.to_string("uncompressed") @@ -179,10 +146,6 @@ def point(self) -> IPoint: :return: The elliptic curve point. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.nist256p1.public_key import SLIP10Nist256p1PublicKey - >>> SLIP10Nist256p1PublicKey.point() - "..." """ return SLIP10Nist256p1Point(self.verify_key.pubkey.point) diff --git a/hdwallet/ecc/slip10/secp256k1/point.py b/hdwallet/ecc/slip10/secp256k1/point.py index f74b4ec..b7eb450 100644 --- a/hdwallet/ecc/slip10/secp256k1/point.py +++ b/hdwallet/ecc/slip10/secp256k1/point.py @@ -43,11 +43,6 @@ def name() -> str: :return: The name of the algorithm. :rtype: str - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> ecc: = SLIP10Secp256k1PointCoincurve(point=...) - >>> ecc.name() - "SLIP10-Secp256k1" """ return "SLIP10-Secp256k1" @@ -61,12 +56,9 @@ def from_bytes(cls, point_bytes: bytes) -> IPoint: :type cls: Type :param point_bytes: The bytes representing the point. :type point_bytes: bytes + :return: A point object created from the provided bytes. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.from_bytes(point_bytes=...) - "..." """ if len(point_bytes) == SLIP10_SECP256K1_CONST.PUBLIC_KEY_UNCOMPRESSED_BYTE_LENGTH - 1: @@ -86,12 +78,9 @@ def from_coordinates(cls, x: int, y: int) -> IPoint: :type x: int :param y: The y-coordinate of the point. :type y: int + :return: A point object representing the coordinates (x, y). :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.from_coordinates(x=..., y=...) - "..." """ try: @@ -105,10 +94,6 @@ def underlying_object(self) -> Any: :return: The underlying public key object. :rtype: Any - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.underlying_object() - "..." """ return self.public_key @@ -119,10 +104,6 @@ def x(self) -> int: :return: The x of the point. :rtype: int - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.x() - ... """ return self.public_key.point()[0] @@ -133,10 +114,6 @@ def y(self) -> int: :return: The y of the point. :rtype: int - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.y() - ... """ return self.public_key.point()[1] @@ -147,10 +124,6 @@ def raw(self) -> bytes: :return: The raw bytes of the public key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.raw() - ... """ return self.raw_decoded() @@ -161,10 +134,6 @@ def raw_encoded(self) -> bytes: :return: The encoded raw bytes of the public key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.raw_encoded() - ... """ return self.public_key.format(True) @@ -175,10 +144,6 @@ def raw_decoded(self) -> bytes: :return: The decoded raw bytes of the public key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.raw_decoded() - ... """ return self.public_key.format(False)[1:] @@ -192,10 +157,6 @@ def __add__(self, point: IPoint) -> IPoint: :return: A new instance of the class with the resulting point after addition. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.__add__(point=...) - "..." """ return self.__class__(self.public_key.combine([point.underlying_object()])) @@ -210,10 +171,6 @@ def __radd__(self, point: IPoint) -> IPoint: :return: A new instance of the class with the resulting point after addition. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.__radd__(point=...) - "..." """ return self + point @@ -227,10 +184,6 @@ def __mul__(self, scalar: int) -> IPoint: :return: A new instance of the class with the resulting point after multiplication. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.__mul__(scalar=...) - "..." """ bytes_num = None or ((scalar.bit_length() if scalar > 0 else 1) + 7) // 8 @@ -246,9 +199,6 @@ def __rmul__(self, scalar: int) -> IPoint: :return: Resulting point after scalar multiplication. :rtype: IPoint - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointCoincurve - >>> SLIP10Secp256k1PointCoincurve.__rmul__(scalar=...) - "..." """ return self * scalar @@ -275,11 +225,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> ecc: = SLIP10Secp256k1PointECDSA(point=...) - >>> ecc.name() - "SLIP10-Secp256k1" """ return "SLIP10-Secp256k1" @@ -294,10 +239,6 @@ def from_bytes(cls, point_bytes: bytes) -> IPoint: :return: An instance of IPoint representing the decoded point. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.from_bytes(point_bytes=...) - "..." """ try: @@ -321,16 +262,11 @@ def from_coordinates(cls, x: int, y: int) -> IPoint: :param x: The x of the point. :type x: int - :param y: The y of the point. :type y: int :return: An instance of IPoint representing the point with the given coordinates. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.from_coordinates(x=..., y=...) - "..." """ return cls( @@ -345,10 +281,6 @@ def underlying_object(self) -> Any: :return: The underlying point object. :rtype: Any - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.underlying_object() - "..." """ return self.point @@ -359,10 +291,6 @@ def x(self) -> int: :return: The x of the point. :rtype: int - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.x() - ... """ return self.point.x() @@ -373,10 +301,6 @@ def y(self) -> int: :return: The y of the point. :rtype: int - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.y() - ... """ return self.point.y() @@ -387,10 +311,6 @@ def raw(self) -> bytes: :return: The raw bytes representation of the point. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.raw() - ... """ return self.raw_decoded() @@ -401,10 +321,6 @@ def raw_encoded(self) -> bytes: :return: The raw encoded bytes of the point. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.raw_encoded() - ... """ try: @@ -419,10 +335,6 @@ def raw_decoded(self) -> bytes: :return: The raw bytes of the point. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.raw_decoded() - ... """ try: @@ -442,10 +354,6 @@ def __add__(self, point: IPoint) -> IPoint: :return: A new instance of the class representing the result of the addition. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.__add__(point=...) - "..." """ return self.__class__(self.point + point.underlying_object()) @@ -459,10 +367,6 @@ def __radd__(self, point: IPoint) -> IPoint: :return: A new instance of the class representing the result of the addition. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.__radd__(point=...) - "..." """ return self + point @@ -476,10 +380,6 @@ def __mul__(self, scalar: int) -> IPoint: :return: A new instance of the class representing the result of scalar multiplication. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.__mul__(scalar=...) - "..." """ return self.__class__(self.point * scalar) @@ -493,10 +393,6 @@ def __rmul__(self, scalar: int) -> IPoint: :return: The result of scalar multiplication. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.point import SLIP10Secp256k1PointECDSA - >>> SLIP10Secp256k1PointECDSA.__rmul__(scalar=...) - "..." """ return self * scalar diff --git a/hdwallet/ecc/slip10/secp256k1/private_key.py b/hdwallet/ecc/slip10/secp256k1/private_key.py index 0efff19..f473bd9 100644 --- a/hdwallet/ecc/slip10/secp256k1/private_key.py +++ b/hdwallet/ecc/slip10/secp256k1/private_key.py @@ -38,11 +38,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyCoincurve - >>> ecc: = SLIP10Secp256k1PrivateKeyCoincurve(private_key=...) - >>> ecc.name() - "SLIP10-Secp256k1" """ return "SLIP10-Secp256k1" @@ -57,10 +52,6 @@ def from_bytes(cls, private_key: bytes) -> IPrivateKey: :return: An instance implementing the IPrivateKey interface. :rtype: IPrivateKey - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyCoincurve - >>> SLIP10Secp256k1PrivateKeyCoincurve.from_bytes(private_key=...) - "..." """ if len(private_key) != cls.length(): @@ -78,10 +69,6 @@ def length() -> int: :return: The length of the private key in bytes. :rtype: int - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyCoincurve - >>> SLIP10Secp256k1PrivateKeyCoincurve.length() - ... """ return SLIP10_SECP256K1_CONST.PRIVATE_KEY_BYTE_LENGTH @@ -92,10 +79,6 @@ def underlying_object(self) -> Any: :return: The underlying signing key object. :rtype: Any - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyCoincurve - >>> SLIP10Secp256k1PrivateKeyCoincurve.underlying_object() - "..." """ return self.signing_key @@ -106,10 +89,6 @@ def raw(self) -> bytes: :return: The raw secret bytes of the signing key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyCoincurve - >>> SLIP10Secp256k1PrivateKeyCoincurve.raw() - ... """ return self.signing_key.secret @@ -120,10 +99,6 @@ def public_key(self) -> IPublicKey: :return: The public key object. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyCoincurve - >>> SLIP10Secp256k1PrivateKeyCoincurve.public_key() - "..." """ return SLIP10Secp256k1PublicKeyCoincurve(self.signing_key.public_key) @@ -150,11 +125,6 @@ def name() -> str: :return: The name of the algorithm. :rtype: str - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyECDSA - >>> ecc: = SLIP10Secp256k1PrivateKeyECDSA(private_key=...) - >>> ecc.name() - "SLIP10-Secp256k1" """ return "SLIP10-Secp256k1" @@ -169,10 +139,6 @@ def from_bytes(cls, key_bytes: bytes) -> IPrivateKey: :return: An instance of IPrivateKey corresponding to the given bytes. :rtype: IPrivateKey - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyECDSA - >>> SLIP10Secp256k1PrivateKeyECDSA.from_bytes(key_bytes=...) - "..." """ try: @@ -192,9 +158,6 @@ def length() -> int: :return: Length of the private key in bytes. :rtype: int - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyECDSA - >>> SLIP10Secp256k1PrivateKeyECDSA.length() - ... """ return SLIP10_SECP256K1_CONST.PRIVATE_KEY_BYTE_LENGTH @@ -205,10 +168,6 @@ def underlying_object(self) -> Any: :return: The underlying signing key object. :rtype: Any - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyECDSA - >>> SLIP10Secp256k1PrivateKeyECDSA.underlying_object() - "..." """ return self.signing_key @@ -219,10 +178,6 @@ def raw(self) -> bytes: :return: The raw bytes of the private key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyECDSA - >>> SLIP10Secp256k1PrivateKeyECDSA.raw() - ... """ return self.signing_key.to_string() @@ -233,10 +188,6 @@ def public_key(self) -> IPublicKey: :return: The public key object. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyECDSA - >>> SLIP10Secp256k1PrivateKeyECDSA.public_key() - "..." """ return SLIP10Secp256k1PublicKeyECDSA(self.signing_key.get_verifying_key()) diff --git a/hdwallet/ecc/slip10/secp256k1/public_key.py b/hdwallet/ecc/slip10/secp256k1/public_key.py index 9e8d166..75555da 100644 --- a/hdwallet/ecc/slip10/secp256k1/public_key.py +++ b/hdwallet/ecc/slip10/secp256k1/public_key.py @@ -29,6 +29,7 @@ def __init__(self, public_key: coincurve.PublicKey) -> None: :param public_key: The coincurve PublicKey object representing the public key. :type public_key: coincurve.PublicKey """ + self.verify_key = public_key @staticmethod @@ -38,11 +39,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyCoincurve - >>> ecc: = SLIP10Secp256k1PublicKeyCoincurve(public_key=...) - >>> ecc.name() - "SLIP10-Secp256k1" """ return "SLIP10-Secp256k1" @@ -57,10 +53,6 @@ def from_bytes(cls, public_key: bytes) -> IPublicKey: :return: An instance of the public key created from the byte representation. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyCoincurve - >>> SLIP10Secp256k1PublicKeyCoincurve.from_bytes(public_key=...) - "..." """ try: @@ -78,10 +70,6 @@ def from_point(cls, point: IPoint) -> IPublicKey: :return: An instance of the public key derived from the elliptic curve point. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyCoincurve - >>> SLIP10Secp256k1PublicKeyCoincurve.from_point(point=...) - "..." """ try: @@ -100,10 +88,6 @@ def compressed_length() -> int: :return: Length of the compressed public key in bytes. :rtype: int - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyCoincurve - >>> SLIP10Secp256k1PublicKeyCoincurve.compressed_length() - ... """ return SLIP10_SECP256K1_CONST.PUBLIC_KEY_COMPRESSED_BYTE_LENGTH @@ -115,10 +99,6 @@ def uncompressed_length() -> int: :return: The length of an uncompressed public key in bytes. :rtype: int - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyCoincurve - >>> SLIP10Secp256k1PublicKeyCoincurve.uncompressed_length() - ... """ return SLIP10_SECP256K1_CONST.PUBLIC_KEY_UNCOMPRESSED_BYTE_LENGTH @@ -129,10 +109,6 @@ def underlying_object(self) -> Any: :return: The underlying verification key object. :rtype: Any - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyCoincurve - >>> SLIP10Secp256k1PublicKeyCoincurve.underlying_object() - "..." """ return self.verify_key @@ -143,10 +119,6 @@ def raw_compressed(self) -> bytes: :return: The compressed public key bytes. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyCoincurve - >>> SLIP10Secp256k1PublicKeyCoincurve.raw_uncompressed() - ... """ return self.verify_key.format(True) @@ -157,10 +129,6 @@ def raw_uncompressed(self) -> bytes: :return: Uncompressed raw bytes of the verifying key. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyCoincurve - >>> SLIP10Secp256k1PublicKeyCoincurve.raw_uncompressed() - ... """ return self.verify_key.format(False) @@ -171,10 +139,6 @@ def point(self) -> IPoint: :return: The cryptographic point. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyCoincurve - >>> SLIP10Secp256k1PublicKeyCoincurve.point() - "..." """ point = self.verify_key.point() @@ -204,11 +168,6 @@ def name() -> str: :return: The name of the ecc class. :rtype: str - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyECDSA - >>> ecc: = SLIP10Secp256k1PublicKeyECDSA(public_key=...) - >>> ecc.name() - "SLIP10-Secp256k1" """ return "SLIP10-Secp256k1" @@ -223,10 +182,6 @@ def from_bytes(cls, public_key: bytes) -> IPublicKey: :return: An instance of the public key derived from the given bytes. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyECDSA - >>> SLIP10Secp256k1PublicKeyECDSA.from_bytes(public_key=...) - "..." """ try: @@ -248,10 +203,6 @@ def from_point(cls, point: IPoint) -> IPublicKey: :return: An instance of the public key derived from the given point. :rtype: IPublicKey - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyECDSA - >>> SLIP10Secp256k1PublicKeyECDSA.from_point(point=...) - "..." """ try: @@ -273,10 +224,6 @@ def compressed_length() -> int: :return: The length of a compressed public key in bytes. :rtype: int - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyECDSA - >>> SLIP10Secp256k1PublicKeyECDSA.compressed_length() - ... """ return SLIP10_SECP256K1_CONST.PUBLIC_KEY_COMPRESSED_BYTE_LENGTH @@ -288,10 +235,6 @@ def uncompressed_length() -> int: :return: The length of an uncompressed public key in bytes. :rtype: int - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyECDSA - >>> SLIP10Secp256k1PublicKeyECDSA.uncompressed_length() - ... """ return SLIP10_SECP256K1_CONST.PUBLIC_KEY_UNCOMPRESSED_BYTE_LENGTH @@ -302,10 +245,6 @@ def underlying_object(self) -> Any: :return: The underlying verification key object. :rtype: Any - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyECDSA - >>> SLIP10Secp256k1PublicKeyECDSA.underlying_object() - "..." """ return self.verify_key @@ -316,10 +255,6 @@ def raw_compressed(self) -> bytes: :return: The compressed public key bytes. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyECDSA - >>> SLIP10Secp256k1PublicKeyECDSA.raw_compressed() - ... """ return self.verify_key.to_string("compressed") @@ -330,10 +265,6 @@ def raw_uncompressed(self) -> bytes: :return: The uncompressed public key bytes. :rtype: bytes - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyECDSA - >>> SLIP10Secp256k1PublicKeyECDSA.raw_uncompressed() - ... """ return self.verify_key.to_string("uncompressed") @@ -344,10 +275,6 @@ def point(self) -> IPoint: :return: The point object implementing the IPoint interface. :rtype: IPoint - - >>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyECDSA - >>> SLIP10Secp256k1PublicKeyECDSA.point() - "..." """ return SLIP10Secp256k1PointECDSA(self.verify_key.pubkey.point) From 94eaadb3949f529a18293285ca1252332ae4bbf8 Mon Sep 17 00:00:00 2001 From: itsm3abena Date: Mon, 15 Jul 2024 16:12:59 +0300 Subject: [PATCH 2/2] Update: ecc examples done and comments --- docs/ecc.rst | 186 +++++++++++++++++++++++++++++++++++ hdwallet/ecc/ipoint.py | 111 ++++++++++++++++++--- hdwallet/ecc/iprivate_key.py | 45 +++++++-- hdwallet/ecc/ipublic_key.py | 69 +++++++++++-- 4 files changed, 383 insertions(+), 28 deletions(-) diff --git a/docs/ecc.rst b/docs/ecc.rst index f8ef64e..14df709 100644 --- a/docs/ecc.rst +++ b/docs/ecc.rst @@ -11,50 +11,236 @@ Elliptic Curve Cryptography (ECC) .. autoclass:: hdwallet.ecc.kholaw.ed25519.private_key.KholawEd25519PrivateKey :members: +>>> from hdwallet.ecc.kholaw.ed25519.private_key import KholawEd25519PrivateKey +>>> from hdwallet.utils import get_bytes +>>> KholawEd25519PrivateKey.name() +'Kholaw-Ed25519' +>>> KholawEd25519PrivateKey.length() +64 +>>> private_key = KholawEd25519PrivateKey.from_bytes( +... get_bytes("8061879a8fc9e7c685cb89b7014c85a6c4a2a8f3b6fa4964381d0751baf8fb5ff97530b002426a6eb1308e01372905d4c19c2b52a939bccd24c99a5826b9f87c") +... ) +>>> private_key.raw().hex() +'8061879a8fc9e7c685cb89b7014c85a6c4a2a8f3b6fa4964381d0751baf8fb5ff97530b002426a6eb1308e01372905d4c19c2b52a939bccd24c99a5826b9f87c' +>>> private_key.public_key().raw_compressed().hex() +'00e55487c92c1913439f336b1b2dc316da6e88c02a157208f98781494b87f27eb8' +>>> private_key.public_key().raw_uncompressed().hex() +'00e55487c92c1913439f336b1b2dc316da6e88c02a157208f98781494b87f27eb8' + + .. autoclass:: hdwallet.ecc.kholaw.ed25519.public_key.KholawEd25519PublicKey :members: +>>> from hdwallet.ecc.kholaw.ed25519 import KholawEd25519PublicKey +>>> from hdwallet.utils import get_bytes +>>> KholawEd25519PublicKey.name() +'Kholaw-Ed25519' +>>> public_key = KholawEd25519PublicKey.from_bytes( +... get_bytes("00e55487c92c1913439f336b1b2dc316da6e88c02a157208f98781494b87f27eb8") +... ) +>>> public_key.raw_compressed().hex() +'00e55487c92c1913439f336b1b2dc316da6e88c02a157208f98781494b87f27eb8' +>>> public_key.point().raw_encoded().hex() +'e55487c92c1913439f336b1b2dc316da6e88c02a157208f98781494b87f27eb8' +>>> public_key.point().x() +18529038270296824438026848489315401829943202020841826252456650783397010322849 + + .. autoclass:: hdwallet.ecc.slip10.ed25519.blake2b.point.SLIP10Ed25519Blake2bPoint :members: .. autoclass:: hdwallet.ecc.slip10.ed25519.blake2b.private_key.SLIP10Ed25519Blake2bPrivateKey :members: +>>> from hdwallet.ecc.slip10.ed25519.blake2b import SLIP10Ed25519Blake2bPrivateKey +>>> from hdwallet.utils import get_bytes +>>> SLIP10Ed25519Blake2bPrivateKey.name() +'SLIP10-Ed25519-Blake2b' +>>> SLIP10Ed25519Blake2bPrivateKey.length() +32 +>>> private_key = SLIP10Ed25519Blake2bPrivateKey.from_bytes( +... get_bytes("bb37794073e5094ebbfcfa070e9254fe6094b56e7cccb094a2304c5eccccdc07") +... ) +>>> private_key.raw().hex() +'bb37794073e5094ebbfcfa070e9254fe6094b56e7cccb094a2304c5eccccdc07' +>>> private_key.public_key().raw_compressed().hex() +'006aea61eeed872052377ab16b0fc5d9b9f142be59ac1488e6610645dedb4da45c' +>>> private_key.public_key().raw_uncompressed().hex() +'006aea61eeed872052377ab16b0fc5d9b9f142be59ac1488e6610645dedb4da45c' + + .. autoclass:: hdwallet.ecc.slip10.ed25519.blake2b.public_key.SLIP10Ed25519Blake2bPublicKey :members: +>>> from hdwallet.ecc.slip10.ed25519.blake2b import SLIP10Ed25519Blake2bPublicKey +>>> from hdwallet.utils import get_bytes +>>> SLIP10Ed25519Blake2bPublicKey.name() +'SLIP10-Ed25519-Blake2b' +>>> public_key = SLIP10Ed25519Blake2bPublicKey.from_bytes( +... get_bytes("00d14696583ee9144878635b557d515a502b04366818dfe7765737746b4f57978d") +... ) +>>> public_key.raw_compressed().hex() +'00d14696583ee9144878635b557d515a502b04366818dfe7765737746b4f57978d' +>>> public_key.point().raw_encoded().hex() +'d14696583ee9144878635b557d515a502b04366818dfe7765737746b4f57978d' +>>> public_key.point().x() +35008547582340824597639173221735807482318787407965447203743372716499096148063 + + .. autoclass:: hdwallet.ecc.slip10.ed25519.monero.point.SLIP10Ed25519MoneroPoint :members: .. autoclass:: hdwallet.ecc.slip10.ed25519.monero.private_key.SLIP10Ed25519MoneroPrivateKey :members: +>>> from hdwallet.ecc.slip10.ed25519.monero import SLIP10Ed25519MoneroPrivateKey +>>> from hdwallet.utils import get_bytes +>>> SLIP10Ed25519MoneroPrivateKey.name() +'SLIP10-Ed25519-Monero' +>>> SLIP10Ed25519MoneroPrivateKey.length() +32 +>>> private_key = SLIP10Ed25519MoneroPrivateKey.from_bytes( +... get_bytes("bb37794073e5094ebbfcfa070e9254fe6094b56e7cccb094a2304c5eccccdc07") +... ) +>>> private_key.raw().hex() +'bb37794073e5094ebbfcfa070e9254fe6094b56e7cccb094a2304c5eccccdc07' +>>> private_key.public_key().raw_compressed().hex() +'628247d3de93857cdd360fee4aef9a67ecfebedfe8eaec9cf6be35eacc895ca7' +>>> private_key.public_key().raw_uncompressed().hex() +'628247d3de93857cdd360fee4aef9a67ecfebedfe8eaec9cf6be35eacc895ca7' + + .. autoclass:: hdwallet.ecc.slip10.ed25519.monero.public_key.SLIP10Ed25519MoneroPublicKey :members: +>>> from hdwallet.ecc.slip10.ed25519.monero import SLIP10Ed25519MoneroPublicKey +>>> from hdwallet.utils import get_bytes +>>> SLIP10Ed25519MoneroPublicKey.name() +'SLIP10-Ed25519-Monero' +>>> public_key = SLIP10Ed25519MoneroPublicKey.from_bytes( +... get_bytes("628247d3de93857cdd360fee4aef9a67ecfebedfe8eaec9cf6be35eacc895ca7") +... ) +>>> public_key.raw_compressed().hex() +'628247d3de93857cdd360fee4aef9a67ecfebedfe8eaec9cf6be35eacc895ca7' +>>> public_key.point().raw_encoded().hex() +'628247d3de93857cdd360fee4aef9a67ecfebedfe8eaec9cf6be35eacc895ca7' +>>> public_key.point().x() +29078407399097928298542937704975150613766572636435642857509307729044618011935 + + .. autoclass:: hdwallet.ecc.slip10.ed25519.point.SLIP10Ed25519Point :members: .. autoclass:: hdwallet.ecc.slip10.ed25519.private_key.SLIP10Ed25519PrivateKey :members: +>>> from hdwallet.ecc.slip10.ed25519.private_key import SLIP10Ed25519PrivateKey +>>> from hdwallet.utils import get_bytes +>>> SLIP10Ed25519PrivateKey.name() +'SLIP10-Ed25519' +>>> SLIP10Ed25519PrivateKey.length() +32 +>>> private_key = SLIP10Ed25519PrivateKey.from_bytes( +... get_bytes("bb37794073e5094ebbfcfa070e9254fe6094b56e7cccb094a2304c5eccccdc07") +... ) +>>> private_key.raw().hex() +'bb37794073e5094ebbfcfa070e9254fe6094b56e7cccb094a2304c5eccccdc07' +>>> private_key.public_key().raw_compressed().hex() +'00d14696583ee9144878635b557d515a502b04366818dfe7765737746b4f57978d' +>>> private_key.public_key().raw_uncompressed().hex() +'00d14696583ee9144878635b557d515a502b04366818dfe7765737746b4f57978d' + .. autoclass:: hdwallet.ecc.slip10.ed25519.public_key.SLIP10Ed25519PublicKey :members: +>>> from hdwallet.ecc.slip10.ed25519.public_key import SLIP10Ed25519PublicKey +>>> from hdwallet.utils import get_bytes +>>> SLIP10Ed25519PublicKey.name() +'SLIP10-Ed25519' +>>> public_key = SLIP10Ed25519PublicKey.from_bytes( +... get_bytes("00d14696583ee9144878635b557d515a502b04366818dfe7765737746b4f57978d") +... ) +>>> public_key.raw_compressed().hex() +'00d14696583ee9144878635b557d515a502b04366818dfe7765737746b4f57978d' +>>> public_key.point().raw_encoded().hex() +'d14696583ee9144878635b557d515a502b04366818dfe7765737746b4f57978d' +>>> public_key.point().x() +35008547582340824597639173221735807482318787407965447203743372716499096148063 + .. autoclass:: hdwallet.ecc.slip10.nist256p1.point.SLIP10Nist256p1Point :members: .. autoclass:: hdwallet.ecc.slip10.nist256p1.private_key.SLIP10Nist256p1PrivateKey :members: +>>> from hdwallet.ecc.slip10.nist256p1.private_key import SLIP10Nist256p1PrivateKey +>>> from hdwallet.utils import get_bytes +>>> SLIP10Nist256p1PrivateKey.name() +'SLIP10-Nist256p1' +>>> SLIP10Nist256p1PrivateKey.length() +32 +>>> private_key = SLIP10Nist256p1PrivateKey.from_bytes( +... get_bytes("f79495fda777197ce73551bcd8e162ceca19167575760d3cc2bced4bf2a213dc") +... ) +>>> private_key.raw().hex() +'f79495fda777197ce73551bcd8e162ceca19167575760d3cc2bced4bf2a213dc' +>>> private_key.public_key().raw_compressed().hex() +'02e4bd97a82a8f3e575a9a35b7cca19cd730addd499a2bd4e9a9811df8bfc35e51' +>>> private_key.public_key().raw_uncompressed().hex() +'04e4bd97a82a8f3e575a9a35b7cca19cd730addd499a2bd4e9a9811df8bfc35e51c68c3bed41d47d4d05ae880250e4432cc6480b417597f1cffc5ed7d28991d164' + .. autoclass:: hdwallet.ecc.slip10.nist256p1.public_key.SLIP10Nist256p1PublicKey :members: +>>> from hdwallet.ecc.slip10.nist256p1.public_key import SLIP10Nist256p1PublicKey +>>> from hdwallet.utils import get_bytes +>>> SLIP10Nist256p1PublicKey.name() +'SLIP10-Nist256p1' +>>> public_key = SLIP10Nist256p1PublicKey.from_bytes( +... get_bytes("02e4bd97a82a8f3e575a9a35b7cca19cd730addd499a2bd4e9a9811df8bfc35e51") +... ) +>>> public_key.raw_compressed().hex() +'02e4bd97a82a8f3e575a9a35b7cca19cd730addd499a2bd4e9a9811df8bfc35e51' +>>> public_key.point().raw_encoded().hex() +'02e4bd97a82a8f3e575a9a35b7cca19cd730addd499a2bd4e9a9811df8bfc35e51' +>>> public_key.point().x() +103462310269679299860340333843259692621316029910306332627414876684344367472209 + .. autoclass:: hdwallet.ecc.slip10.secp256k1.point.SLIP10Secp256k1PointCoincurve :members: .. autoclass:: hdwallet.ecc.slip10.secp256k1.private_key.SLIP10Secp256k1PrivateKeyCoincurve :members: +>>> from hdwallet.ecc.slip10.secp256k1.private_key import SLIP10Secp256k1PrivateKeyCoincurve +>>> from hdwallet.utils import get_bytes +>>> SLIP10Secp256k1PrivateKeyCoincurve.name() +'SLIP10-Secp256k1' +>>> SLIP10Secp256k1PrivateKeyCoincurve.length() +32 +>>> private_key = SLIP10Secp256k1PrivateKeyCoincurve.from_bytes( +... get_bytes("b66022fff8b6322f8b8fa444d6d097457b6b9e7bb05add5b75f9c827df7bd3b6") +... ) +>>> private_key.raw().hex() +'b66022fff8b6322f8b8fa444d6d097457b6b9e7bb05add5b75f9c827df7bd3b6' +>>> private_key.public_key().raw_compressed().hex() +'0374a436044b4904bbd7a074b098d65fad39fc5b66f28da8440f10dbcf86568429' +>>> private_key.public_key().raw_uncompressed().hex() +'0474a436044b4904bbd7a074b098d65fad39fc5b66f28da8440f10dbcf86568429aae5b09b4de9cee5d2f9f98044f688aa98f910134a8e87eff28ec5ba35ddf273' + .. autoclass:: hdwallet.ecc.slip10.secp256k1.public_key.SLIP10Secp256k1PublicKeyCoincurve :members: + +>>> from hdwallet.ecc.slip10.secp256k1.public_key import SLIP10Secp256k1PublicKeyCoincurve +>>> from hdwallet.utils import get_bytes +>>> SLIP10Secp256k1PublicKeyCoincurve.name() +'SLIP10-Secp256k1' +>>> public_key = SLIP10Secp256k1PublicKeyCoincurve.from_bytes( +... get_bytes("0374a436044b4904bbd7a074b098d65fad39fc5b66f28da8440f10dbcf86568429") +... ) +>>> public_key.raw_compressed().hex() +'0374a436044b4904bbd7a074b098d65fad39fc5b66f28da8440f10dbcf86568429' +>>> public_key.point().raw_encoded().hex() +'0374a436044b4904bbd7a074b098d65fad39fc5b66f28da8440f10dbcf86568429' +>>> public_key.point().x() +52758426164353529380574599868388529660378638078403259786555024244882051335209 diff --git a/hdwallet/ecc/ipoint.py b/hdwallet/ecc/ipoint.py index 4d8ee1d..e8e119e 100644 --- a/hdwallet/ecc/ipoint.py +++ b/hdwallet/ecc/ipoint.py @@ -17,54 +17,139 @@ class IPoint(ABC): @staticmethod @abstractmethod def name() -> str: - pass + """ + Get the name of the ecc class. + + :return: The name of the ecc class. + :rtype: str + """ @classmethod @abstractmethod def from_bytes(cls, point: bytes) -> "IPoint": - pass + """ + Create an IPoint instance from a byte representation. + + :param point: The byte sequence representing the point. + :type point: bytes + + :return: A new IPoint instance initialized from the byte representation. + :rtype: IPoint + """ @classmethod @abstractmethod def from_coordinates(cls, x: int, y: int) -> "IPoint": - pass + """ + Create an IPoint instance from x and y coordinates. + + :param x: The x-coordinate. + :type x: int + :param y: The y-coordinate. + :type y: int + + :return: A new IPoint instance initialized with the given coordinates. + :rtype: IPoint + """ @abstractmethod def x(self) -> int: - pass + """ + Get the x-coordinate value of the point. + + :return: The x-coordinate value. + :rtype: int + """ @abstractmethod def y(self) -> int: - pass + """ + Get the y-coordinate value of the point. + + :return: The y-coordinate value. + :rtype: int + """ @abstractmethod def raw(self) -> bytes: - pass + """ + Get the raw byte representation of the object. + + :return: The raw byte representation of the object. + :rtype: bytes + """ @abstractmethod def raw_encoded(self) -> bytes: - pass + """ + Get the encoded raw byte representation of the object. + + :return: The encoded raw byte representation of the object. + :rtype: bytes + """ @abstractmethod def raw_decoded(self) -> bytes: - pass + """ + Get the decoded raw byte representation of the object. + + :return: The decoded raw byte representation of the object. + :rtype: bytes + """ @abstractmethod def underlying_object(self) -> Any: - pass + """ + Get the underlying object represented by this instance. + + :return: The underlying object represented by this instance. + :rtype: Any + """ @abstractmethod def __add__(self, point: "IPoint") -> "IPoint": - pass + """ + Add another point to this point. + + :param point: The point to add to this point. + :type point: IPoint + + :return: A new instance of IPoint representing the sum of the points. + :rtype: IPoint + """ @abstractmethod def __radd__(self, point: "IPoint") -> "IPoint": - pass + """ + Add this point to another point on the right-hand side. + + :param point: The point to which this point is added. + :type point: IPoint + + :return: A new instance of IPoint representing the sum of the points. + :rtype: IPoint + """ @abstractmethod def __mul__(self, scalar: int) -> 'IPoint': - pass + """ + Multiply this point by a scalar. + + :param scalar: The scalar integer to multiply this point by. + :type scalar: int + + :return: A new instance of IPoint representing the result of the multiplication. + :rtype: IPoint + """ @abstractmethod def __rmul__(self, scalar: int) -> 'IPoint': - pass + """ + Multiply a scalar by this point on the right-hand side. + + :param scalar: The scalar integer to multiply by this point. + :type scalar: int + + :return: A new instance of IPoint representing the result of the multiplication. + :rtype: IPoint + """ diff --git a/hdwallet/ecc/iprivate_key.py b/hdwallet/ecc/iprivate_key.py index 448e227..01a0044 100644 --- a/hdwallet/ecc/iprivate_key.py +++ b/hdwallet/ecc/iprivate_key.py @@ -19,29 +19,62 @@ class IPrivateKey(ABC): @staticmethod @abstractmethod def name() -> str: - pass + """ + Get the name of the ecc class. + + :return: The name of the ecc class. + :rtype: str + """ @classmethod @abstractmethod def from_bytes(cls, private_key: bytes) -> "IPrivateKey": - pass + """ + Create an IPrivateKey instance from a byte representation. + + :param private_key: The byte sequence representing the private key. + :type private_key: bytes + + :return: A new IPrivateKey instance initialized from the byte representation. + :rtype: IPrivateKey + """ @abstractmethod def raw(self) -> bytes: - pass + """ + Get the raw byte representation of the object. + + :return: The raw byte representation of the object. + :rtype: bytes + """ @abstractmethod def public_key(self) -> IPublicKey: - pass + """ + Get the public key represented by this object. + + :return: The IPublicKey representation of the public key. + :rtype: IPublicKey + """ @abstractmethod def underlying_object(self) -> Any: - pass + """ + Retrieve the underlying object represented by this instance. + + :return: The underlying object represented by this instance. + :rtype: Any + """ @staticmethod @abstractmethod def length() -> int: - pass + """ + Get the length of the object. + + :return: The length of the object. + :rtype: int + """ @classmethod def is_valid_bytes(cls, private_key: bytes) -> bool: diff --git a/hdwallet/ecc/ipublic_key.py b/hdwallet/ecc/ipublic_key.py index 58a2d69..e74fcda 100644 --- a/hdwallet/ecc/ipublic_key.py +++ b/hdwallet/ecc/ipublic_key.py @@ -19,43 +19,94 @@ class IPublicKey(ABC): @staticmethod @abstractmethod def name() -> str: - pass + """ + Get the name of the ecc class. + + :return: The name of the ecc class. + :rtype: str + """ @classmethod @abstractmethod def from_bytes(cls, public_key: bytes) -> "IPublicKey": - pass + """ + Create an IPublicKey instance from a byte representation. + + :param public_key: The byte sequence representing the public key. + :type public_key: bytes + + :return: A new IPublicKey instance initialized from the byte representation. + :rtype: IPublicKey + """ @classmethod @abstractmethod def from_point(cls, point: IPoint) -> "IPublicKey": - pass + """ + Create an IPublicKey instance from an IPoint. + + :param point: The IPoint instance to create the IPublicKey from. + :type point: IPoint + + :return: An IPublicKey instance created from the given IPoint. + :rtype: IPublicKey + """ @abstractmethod def raw_compressed(self) -> bytes: - pass + """ + Get the compressed raw byte representation of the object. + + :return: The compressed raw byte representation of the object. + :rtype: bytes + """ @abstractmethod def raw_uncompressed(self) -> bytes: - pass + """ + Get the uncompressed raw byte representation of the object. + + :return: The uncompressed raw byte representation of the object. + :rtype: bytes + """ @abstractmethod def point(self) -> IPoint: - pass + """ + Get the point representation of this object. + + :return: The IPoint representation of this object. + :rtype: IPoint + """ @abstractmethod def underlying_object(self) -> Any: - pass + """ + Retrieve the underlying object represented by this instance. + + :return: The underlying object represented by this instance. + :rtype: Any + """ @staticmethod @abstractmethod def compressed_length() -> int: - pass + """ + Get the compressed length of the object's data. + + :return: The length of the compressed data representation. + :rtype: int + """ @staticmethod @abstractmethod def uncompressed_length() -> int: - pass + """ + Get the uncompressed length of the object's data. + + :return: The length of the uncompressed data representation. + :rtype: int + """ @classmethod def is_valid_bytes(cls, public_key: bytes) -> bool: