diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b3e606..393fa33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ # Change Log +## v0.2.6-beta - December 26, 2024 +* Added a check function to verify and validate the wallet ID before making a call to the Qubic network +* Optimized network calls by preventing invalid requests +* Added input validation to enhance security and reliability +* Refactored transaction bytes validation for better data integrity +* Added empty bytes check for transaction data validation + ## v0.2.5-beta - December 22, 2024 * Added new advanced code examples * Reorganized documentation structure diff --git a/README.md b/README.md index b625f37..7bfdc86 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Currently, QubiPy is in a very early development phase, so please take this into Please visit the [Change log](https://github.com/QubiPy-Labs/QubiPy/blob/main/docs/changelog.md) to see all changes. -![release](https://img.shields.io/badge/release-v0.2.5--beta-blue) +![release](https://img.shields.io/badge/release-v0.2.6--beta-blue) ![python](https://img.shields.io/badge/python-3.10_%7C_3.11_%7C_3.12-blue) ![Python Package](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/python-package.yml/badge.svg) ![Code Quality](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/pylint.yml/badge.svg) diff --git a/docs/changelog.md b/docs/changelog.md index 2b3e606..393fa33 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,4 +1,11 @@ # Change Log +## v0.2.6-beta - December 26, 2024 +* Added a check function to verify and validate the wallet ID before making a call to the Qubic network +* Optimized network calls by preventing invalid requests +* Added input validation to enhance security and reliability +* Refactored transaction bytes validation for better data integrity +* Added empty bytes check for transaction data validation + ## v0.2.5-beta - December 22, 2024 * Added new advanced code examples * Reorganized documentation structure diff --git a/docs/index.md b/docs/index.md index 2883863..caa6de0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,11 +1,11 @@ # Welcome to the **QubiPy** official documentation, a Python Library for the QUBIC RPC API -!!! note "Beta Version: 0.2.5" +!!! note "Beta Version: 0.2.6" QubiPy is currently in beta. While functional, some features might change before the stable release. **QubiPy** is a Python library that provides RPC and Core client functionality. You can interact quickly and easily with the Qubic RPC API using the different methods offered by this library. -![release](https://img.shields.io/badge/release-v0.2.5--beta-blue) +![release](https://img.shields.io/badge/release-v0.2.6--beta-blue) ![python](https://img.shields.io/badge/python-3.10_%7C_3.11_%7C_3.12-blue) ![Python Package](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/python-package.yml/badge.svg) ![Code Quality](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/pylint.yml/badge.svg) diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css index 6feda53..1bcb5d1 100644 --- a/docs/stylesheets/extra.css +++ b/docs/stylesheets/extra.css @@ -21,4 +21,9 @@ .md-nav__link:hover { color: #B0F9FE !important; text-shadow: 0 0 10px rgba(176, 249, 254, 0.5); - } \ No newline at end of file + } + + .md-header__button.md-logo img { + width: 40px; + height: auto; +} \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 98b5fc4..fc1e584 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -3,6 +3,8 @@ repo_url: https://github.com/QubiPy-Labs/QubiPy repo_name: QubiPy theme: name: material + logo: assets/images/logo.png + favicon: assets/images/favicon.ico palette: scheme: slate primary: custom diff --git a/qubipy/rpc/rpc_client.py b/qubipy/rpc/rpc_client.py index 2a47d46..d61233b 100644 --- a/qubipy/rpc/rpc_client.py +++ b/qubipy/rpc/rpc_client.py @@ -54,7 +54,8 @@ def broadcast_transaction(self, tx: bytes) -> Dict[str, Any]: QubiPy_Exceptions: If there is an issue broadcasting the transaction. """ - check_bytes(tx) + if is_tx_bytes_invalid(tx): + raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_TX_BYTES) tx_encoded = base64.b64encode(tx).decode('utf-8') payload = json.dumps({ @@ -128,11 +129,10 @@ def get_balance(self, wallet_id: str | None = None) -> Dict[str, Any]: QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout). """ - if not wallet_id: + if not wallet_id or is_wallet_id_invalid(wallet_id): raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID) - - endpoint = WALLET_BALANCE.format(id = wallet_id) + endpoint = WALLET_BALANCE.format(id = wallet_id.upper()) try: response = requests.get(f'{self.rpc_url}{endpoint}', headers=HEADERS, timeout=self.timeout) @@ -355,7 +355,7 @@ def get_transfer_transactions_per_tick(self, identity: str | None = None, start_ QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout). """ - if not identity: + if not identity or is_wallet_id_invalid(identity): raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID) @@ -508,7 +508,7 @@ def get_issued_assets(self, identity: str | None = None) -> Dict[str, Any]: QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout). """ - if not identity: + if not identity or is_wallet_id_invalid(identity): raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID) endpoint = ISSUED_ASSETS.format(identity = identity) @@ -537,9 +537,10 @@ def get_owned_assets(self, identity: str | None = None) -> Dict[str, Any]: QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout). """ - if not identity: + if not identity or is_wallet_id_invalid(identity): raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID) + endpoint = OWNED_ASSETS.format(identity = identity) try: @@ -566,9 +567,10 @@ def get_possessed_assets(self, identity: str | None = None) -> Dict[str, Any]: QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout). """ - if not identity: + if not identity or is_wallet_id_invalid(identity): raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID) + endpoint = POSSESSED_ASSETS.format(identity = identity) try: diff --git a/qubipy/utils.py b/qubipy/utils.py index 1242854..6a6036a 100644 --- a/qubipy/utils.py +++ b/qubipy/utils.py @@ -42,18 +42,30 @@ def check_ticks_format(start_tick: int, end_tick: int): if start_tick <= 0 or end_tick <= 0: raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_START_TICK_AND_END_TICK) - -def check_bytes(tx: bytes): + +def is_tx_bytes_invalid(tx: bytes) -> bool: """ Validates that the input transaction data is in bytes format. Args: - tx (bytes): The transaction data to validate. Must be of type bytes or bytearray. + tx (bytes): The transaction data to validate. Must be of type bytes or bytearray + and not empty. - Raises: - QubiPy_Exceptions: If the transaction data is not in bytes or bytearray format. + Returns: + bool: True if the transaction data is invalid, False if valid """ - - if not isinstance(tx, (bytes, bytearray)): - raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_TX_BYTES) + return not isinstance(tx, (bytes, bytearray)) or len(tx) == 0 + + +def is_wallet_id_invalid(wallet_id: str) -> bool: + """ + Checks if the provided wallet ID is invalid. + + Args: + wallet_id (str): The wallet ID to validate. Must be exactly 60 characters long. + + Returns: + bool: True if the wallet ID is invalid, False if valid + """ + return not isinstance(wallet_id, str) or len(wallet_id) != 60 or not wallet_id.isalpha() \ No newline at end of file diff --git a/setup.py b/setup.py index dcbf6ff..ceef3ad 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -__version__ = '0.2.5' +__version__ = '0.2.6' with open("README.md", "r", encoding="utf-8") as fh: