From 691d061d3a3638342249c909a616960a9c8daa1c Mon Sep 17 00:00:00 2001 From: AnonO6 <21ucs043@gmail.com> Date: Sat, 26 Jul 2025 18:02:48 +0000 Subject: [PATCH 1/2] feat:added podsi method --- src/lighthouseweb3/functions/config.py | 1 + src/lighthouseweb3/functions/podsi.py | 56 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/lighthouseweb3/functions/podsi.py diff --git a/src/lighthouseweb3/functions/config.py b/src/lighthouseweb3/functions/config.py index 000c5ef..3104a7a 100644 --- a/src/lighthouseweb3/functions/config.py +++ b/src/lighthouseweb3/functions/config.py @@ -9,3 +9,4 @@ class Config: lighthouse_node = "https://node.lighthouse.storage" lighthouse_bls_node = "https://encryption.lighthouse.storage" lighthouse_gateway = "https://gateway.lighthouse.storage/ipfs" + \ No newline at end of file diff --git a/src/lighthouseweb3/functions/podsi.py b/src/lighthouseweb3/functions/podsi.py new file mode 100644 index 0000000..5431c7f --- /dev/null +++ b/src/lighthouseweb3/functions/podsi.py @@ -0,0 +1,56 @@ +import requests +from typing import TypedDict, List +from .config import Config + +class VerifierData(TypedDict): + commPc: str + sizePc: str + +class ProofIndex(TypedDict): + index: str + path: List[str] + +class ProofSubtree(TypedDict): + index: str + path: List[str] + +class IndexRecord(TypedDict): + checksum: str + proofIndex: str + proofSubtree: int + size: int + +class InclusionProof(TypedDict): + proofIndex: ProofIndex + proofSubtree: ProofSubtree + indexRecord: IndexRecord + +class Proof(TypedDict): + verifierData: VerifierData + inclusionProof: InclusionProof + +class DealInfo(TypedDict): + dealId: int + storageProvider: str + proof: Proof + +class PODSIData(TypedDict): + pieceCID: str + dealInfo: List[DealInfo] + +def get_lighthouse_proof(cid: str) -> PODSIData: + try: + response = requests.get(f"{Config.lighthouse_api}/api/lighthouse/get_proof?cid={cid}") + + if not response.ok: + if response.status_code == 400: + raise Exception("Proof Doesn't exist yet") + raise Exception(f"Request failed with status code {response.status_code}") + + data = response.json() + return data + + except requests.RequestException as error: + if hasattr(error, 'response') and error.response and error.response.status_code == 400: + raise Exception("Proof Doesn't exist yet") + raise Exception(str(error)) \ No newline at end of file From 2a6e60ab66123805f85f8b9d2e591d1aef89d8e4 Mon Sep 17 00:00:00 2001 From: AnonO6 <21ucs043@gmail.com> Date: Sun, 27 Jul 2025 07:46:15 +0000 Subject: [PATCH 2/2] fix: added podsi lighthouse client --- src/lighthouseweb3/__init__.py | 15 ++++++++++++++- src/lighthouseweb3/functions/podsi.py | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lighthouseweb3/__init__.py b/src/lighthouseweb3/__init__.py index b1d8d7c..a13f762 100644 --- a/src/lighthouseweb3/__init__.py +++ b/src/lighthouseweb3/__init__.py @@ -14,7 +14,8 @@ ipns_publish_record as ipnsPublishRecord, get_ipns_record as getIpnsRecord, remove_ipns_record as removeIpnsRecord, - create_wallet as createWallet + create_wallet as createWallet, + podsi as podsi ) @@ -224,3 +225,15 @@ def getTagged(self, tag: str): except Exception as e: raise e + def getProof(self, cid: str): + """ + Get proof from the Lighthouse. + + :param cid: str, content identifier + :return: List[t.DealData], list of deal data + """ + try: + return podsi.get_proof(cid) + except Exception as e: + raise e + diff --git a/src/lighthouseweb3/functions/podsi.py b/src/lighthouseweb3/functions/podsi.py index 5431c7f..65edf44 100644 --- a/src/lighthouseweb3/functions/podsi.py +++ b/src/lighthouseweb3/functions/podsi.py @@ -38,7 +38,7 @@ class PODSIData(TypedDict): pieceCID: str dealInfo: List[DealInfo] -def get_lighthouse_proof(cid: str) -> PODSIData: +def get_proof(cid: str) -> PODSIData: try: response = requests.get(f"{Config.lighthouse_api}/api/lighthouse/get_proof?cid={cid}")