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
15 changes: 14 additions & 1 deletion src/lighthouseweb3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down Expand Up @@ -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

1 change: 1 addition & 0 deletions src/lighthouseweb3/functions/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

56 changes: 56 additions & 0 deletions src/lighthouseweb3/functions/podsi.py
Original file line number Diff line number Diff line change
@@ -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_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))