diff --git a/src/lighthouseweb3/__init__.py b/src/lighthouseweb3/__init__.py index b1d8d7c..166827f 100644 --- a/src/lighthouseweb3/__init__.py +++ b/src/lighthouseweb3/__init__.py @@ -14,10 +14,12 @@ ipns_publish_record as ipnsPublishRecord, get_ipns_record as getIpnsRecord, remove_ipns_record as removeIpnsRecord, - create_wallet as createWallet + create_wallet as createWallet, + get_access_condition as getAccessCondition ) + class Lighthouse: def __init__(self, token: str = ""): self.token = token or os.environ.get("LIGHTHOUSE_TOKEN", "") @@ -224,3 +226,15 @@ def getTagged(self, tag: str): except Exception as e: raise e + @staticmethod + def getAccessCondition(cid: str): + """ + Retrieves the access condition for a given content identifier (CID). + + :param cid: str, Content Identifier for the data to be retrieved + :return: dict, A dictionary containing the access condition + """ + try: + return getAccessCondition.get_access_condition(cid) + except Exception as e: + raise e diff --git a/src/lighthouseweb3/functions/create_wallet.py b/src/lighthouseweb3/functions/create_wallet.py index a8d2335..455162d 100644 --- a/src/lighthouseweb3/functions/create_wallet.py +++ b/src/lighthouseweb3/functions/create_wallet.py @@ -6,7 +6,7 @@ def create_wallet(password: str): wallet = Account.create() - url = f"{Config.lighthouse_api}/api/auth/get_auth_message?publicKey={wallet.address}" + url = f"{Config.lighthouse_bls_node}/api/auth/get_auth_message?publicKey={wallet.address}" try: response = req.get(url) diff --git a/src/lighthouseweb3/functions/get_access_condition.py b/src/lighthouseweb3/functions/get_access_condition.py new file mode 100644 index 0000000..599d912 --- /dev/null +++ b/src/lighthouseweb3/functions/get_access_condition.py @@ -0,0 +1,15 @@ +import httpx +from typing import Any, Dict +from .config import Config + +async def get_access_condition(cid: str) -> Dict[str, Any]: + url = f"{Config.lighthouse_api}/api/fileAccessConditions/get/{cid}" + + try: + async with httpx.AsyncClient() as client: + response = await client.get(url) + response.raise_for_status() + conditions = response.json() + return {"data": conditions} + except httpx.HTTPError as exc: + raise Exception(f"HTTP error occurred: {exc}") from exc diff --git a/tests/test_get_access_condition.py b/tests/test_get_access_condition.py new file mode 100644 index 0000000..13e99dc --- /dev/null +++ b/tests/test_get_access_condition.py @@ -0,0 +1,12 @@ +import unittest +from src.lighthouseweb3 import Lighthouse + + +class TestCreateWallet(unittest.TestCase): + + async def test_get_access_condition(self): + """test static create wallet function""" + cid = 'QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH' + res = await Lighthouse.getAccessCondition(cid=cid) + self.assertIsInstance(res, dict) + self.assertEqual(res.get("data").get("cid"), cid)