diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b3e606..9998e38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Change Log +## v0.2.6-beta - December XX, 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 + ## 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..9998e38 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,4 +1,9 @@ # Change Log +## v0.2.6-beta - December XX, 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 + ## 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/qubipy/rpc/rpc_client.py b/qubipy/rpc/rpc_client.py index 2a47d46..85eb2be 100644 --- a/qubipy/rpc/rpc_client.py +++ b/qubipy/rpc/rpc_client.py @@ -128,11 +128,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 +354,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 +507,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 +536,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 +566,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..0fa1fc7 100644 --- a/qubipy/utils.py +++ b/qubipy/utils.py @@ -57,3 +57,16 @@ def check_bytes(tx: bytes): if not isinstance(tx, (bytes, bytearray)): raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_TX_BYTES) + + +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: