Skip to content

Commit

Permalink
Merge pull request #27 from chainxlab/axiom90/fix-hd-docs
Browse files Browse the repository at this point in the history
Fix: hd docs
  • Loading branch information
axiom90 authored Jul 15, 2024
2 parents f4366e4 + dbfe32d commit 73255be
Show file tree
Hide file tree
Showing 14 changed files with 503 additions and 693 deletions.
45 changes: 36 additions & 9 deletions docs/hds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,66 @@
HD's
====

.. autoclass:: hdwallet.hds.HDS
:members:

>>> from hdwallet.hds import HDS
>>> HDS.names()
['BIP32', 'BIP44', 'BIP49', 'BIP84', 'BIP86', 'BIP141', 'Cardano', 'Electrum-V1', 'Electrum-V2', 'Monero']
>>> HDS.classes()
[<class 'hdwallet.hds.bip32.BIP32HD'>, <class 'hdwallet.hds.bip44.BIP44HD'>, <class 'hdwallet.hds.bip49.BIP49HD'>, <class 'hdwallet.hds.bip84.BIP84HD'>, <class 'hdwallet.hds.bip86.BIP86HD'>, <class 'hdwallet.hds.bip141.BIP141HD'>, <class 'hdwallet.hds.cardano.CardanoHD'>, <class 'hdwallet.hds.electrum.v1.ElectrumV1HD'>, <class 'hdwallet.hds.electrum.v2.ElectrumV2HD'>, <class 'hdwallet.hds.monero.MoneroHD'>]
>>> from hdwallet.hds.electrum.v2 import ElectrumV2HD
>>> HDS.hd(name="BIP32")
<class 'hdwallet.hds.bip32.BIP32HD'>
>>> HDS.hd(name="Electrum-V2") == ElectrumV2HD
True
>>> HDS.is_hd(name="Electrum-V1")
True

.. autoclass:: hdwallet.hds.ihd.IHD
:members:

.. autoclass:: hdwallet.hds.bip32.BIP32HD
:members:
:inherited-members:

Example: https://github.com/chainxlab/python-hdwallet/blob/master/clients/bip32.py

.. autoclass:: hdwallet.hds.bip44.BIP44HD
:members:
:inherited-members:

Example: https://github.com/chainxlab/python-hdwallet/blob/master/clients/bip44.py

.. autoclass:: hdwallet.hds.bip49.BIP49HD
:members:
:inherited-members:

Example: https://github.com/chainxlab/python-hdwallet/blob/master/clients/bip49.py

.. autoclass:: hdwallet.hds.bip84.BIP84HD
:members:
:inherited-members:

Example: https://github.com/chainxlab/python-hdwallet/blob/master/clients/bip84.py

.. autoclass:: hdwallet.hds.bip86.BIP86HD
:members:
:inherited-members:

Example: https://github.com/chainxlab/python-hdwallet/blob/master/clients/bip86.py

.. autoclass:: hdwallet.hds.bip141.BIP141HD
:members:
:inherited-members:

Example: https://github.com/chainxlab/python-hdwallet/blob/master/clients/bip141.py

.. autoclass:: hdwallet.hds.cardano.CardanoHD
:members:
:inherited-members:

Example: https://github.com/chainxlab/python-hdwallet/tree/master/clients/cardano

.. autoclass:: hdwallet.hds.electrum.v1.ElectrumV1HD
:members:
:inherited-members:

Example: https://github.com/chainxlab/python-hdwallet/blob/master/clients/electrum/v1.py

.. autoclass:: hdwallet.hds.electrum.v2.ElectrumV2HD
:members:
:inherited-members:

Example: https://github.com/chainxlab/python-hdwallet/tree/master/clients/electrum/v2
3 changes: 3 additions & 0 deletions hdwallet/addresses/iaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@


class IAddress(ABC):
"""
Interface class for Address.
"""

@staticmethod
@abstractmethod
Expand Down
33 changes: 33 additions & 0 deletions hdwallet/hds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,39 @@


class HDS:
"""
A class that manages a dictionary of hd classes.
This class provides methods to retrieve names and classes of various hd implementations,
as well as methods to validate and access specific hd classes by name.
Here are available hd names and classes:
+--------------+--------------------------------------------------+
| Name | Class |
+==============+==================================================+
| BIP32 | <class 'hdwallet.hds.bip32.BIP32HD'> |
+--------------+--------------------------------------------------+
| BIP44 | <class 'hdwallet.hds.bip44.BIP44HD'> |
+--------------+--------------------------------------------------+
| BIP49 | <class 'hdwallet.hds.bip49.BIP49HD'> |
+--------------+--------------------------------------------------+
| BIP84 | <class 'hdwallet.hds.bip84.BIP84HD'> |
+--------------+--------------------------------------------------+
| BIP86 | <class 'hdwallet.hds.bip86.BIP86HD'> |
+--------------+--------------------------------------------------+
| BIP141 | <class 'hdwallet.hds.bip141.BIP141HD'> |
+--------------+--------------------------------------------------+
| Cardano | <class 'hdwallet.hds.cardano.CardanoHD'> |
+--------------+--------------------------------------------------+
| Electrum-V1 | <class 'hdwallet.hds.electrum.v1.ElectrumV1HD'> |
+--------------+--------------------------------------------------+
| Electrum-V2 | <class 'hdwallet.hds.electrum.v2.ElectrumV2HD'> |
+--------------+--------------------------------------------------+
| Monero | <class 'hdwallet.hds.monero.MoneroHD'> |
+--------------+--------------------------------------------------+
"""

dictionary: Dict[str, Type[IHD]] = {
BIP32HD.name(): BIP32HD,
Expand Down
42 changes: 0 additions & 42 deletions hdwallet/hds/bip141.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ def __init__(
:param ecc: Elliptic curve cryptography class or type.
:type ecc: Type[IEllipticCurveCryptography]
:param semantic: Semantic information to initialize from.
:type semantic: str
:param public_key_type: Type of public key (default is PUBLIC_KEY_TYPES.COMPRESSED).
:type public_key_type: str
Expand All @@ -61,11 +59,6 @@ def name(cls) -> str:
:return: The name of the bip class.
:rtype: str
>>> from hdwallet.hds.bip141 import BIP141HD
>>> bip141: BIP141HD = BIP141HD(bip="...")
>>> bip141.name()
"BIP141"
"""
return "BIP141"

Expand All @@ -75,15 +68,10 @@ def from_semantic(self, semantic: str, **kwargs) -> "BIP141HD":
:param semantic: Semantic type for address generation.
:type semantic: str
:param kwargs: Additional keyword arguments for specific semantic types.
:return: Self-reference for method chaining.
:rtype: BIP141HD
>>> from hdwallet.hds.bip141 import BIP141HD
>>> BIP141HD.from_semantic(semantic="...")
"..."
"""

if semantic not in [
Expand Down Expand Up @@ -134,10 +122,6 @@ def semantic(self) -> str:
:return: Semantic type.
:rtype: str
>>> from hdwallet.hds.bip141 import BIP141HD
>>> BIP141HD.semantic()
"..."
"""
return self._semantic

Expand All @@ -150,16 +134,11 @@ def root_xprivate_key(
:param version: Optional version bytes or integer for the extended private key.
If None, uses the instance's `_xprivate_key_version`.
:type version: Union[bytes, int], optional
:param encoded: Flag indicating whether the key should be encoded (default is True).
:type encoded: bool
:return: Root extended private key as a string, or None if not available.
:rtype: Optional[str]
>>> from hdwallet.hds.bip141 import BIP141HD
>>> BIP141HD.root_xprivate_key(version=..., encoded=...)
"..."
"""

return super(BIP141HD, self).root_xprivate_key(
Expand All @@ -175,16 +154,11 @@ def root_xpublic_key(
:param version: Optional version bytes or integer for the extended public key.
If None, uses the instance's `_xpublic_key_version`.
:type version: Union[bytes, int], optional
:param encoded: Flag indicating whether the key should be encoded (default is True).
:type encoded: bool
:return: Root extended public key as a string, or None if not available.
:rtype: Optional[str]
>>> from hdwallet.hds.bip141 import BIP141HD
>>> BIP141HD.root_xpublic_key(version=..., encoded=...)
"..."
"""

return super(BIP141HD, self).root_xpublic_key(
Expand All @@ -200,16 +174,11 @@ def xprivate_key(
:param version: Optional version bytes or integer for the extended private key.
If None, uses the instance's `_xprivate_key_version`.
:type version: Union[bytes, int], optional
:param encoded: Flag indicating whether the key should be encoded (default is True).
:type encoded: bool
:return: Extended private key as a string, or None if not available.
:rtype: Optional[str]
>>> from hdwallet.hds.bip141 import BIP141HD
>>> BIP141HD.xprivate_key(version=..., encoded=...)
"..."
"""

return super(BIP141HD, self).xprivate_key(
Expand All @@ -225,16 +194,11 @@ def xpublic_key(
:param version: Optional version bytes or integer for the extended public key.
If None, uses the instance's `_xpublic_key_version`.
:type version: Union[bytes, int], optional
:param encoded: Flag indicating whether the key should be encoded (default is True).
:type encoded: bool
:return: Extended public key as a string, or None if not available.
:rtype: Optional[str]
>>> from hdwallet.hds.bip141 import BIP141HD
>>> BIP141HD.xpublic_key(version=..., encoded=...)
"..."
"""

return super(BIP141HD, self).xpublic_key(
Expand All @@ -258,19 +222,13 @@ def address(
:param script_address_prefix: Script address prefix for P2WPKH-in-P2SH and P2WSH-in-P2SH addresses.
Default is Bitcoin mainnet script address prefix.
:type script_address_prefix: int
:param hrp: Human-readable part for P2WPKH and P2WSH addresses. Default is Bitcoin mainnet HRP.
:type hrp: str
:param witness_version: Witness version for P2WPKH and P2WSH addresses. Default is Bitcoin mainnet witness version.
:type witness_version: int
:return: Encoded address string.
:rtype: str
>>> from hdwallet.hds.bip141 import BIP141HD
>>> BIP141HD.address(address="...", script_address_prefix=..., hrp="...", witness_version=...)
"..."
"""

if address is None:
Expand Down
Loading

0 comments on commit 73255be

Please sign in to comment.