Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/lighthouseweb3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/lighthouseweb3/functions/create_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions src/lighthouseweb3/functions/get_access_condition.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/test_get_access_condition.py
Original file line number Diff line number Diff line change
@@ -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)