@ -349,6 +349,55 @@ async def register(
print ( f " \n API Request Error: { str ( e ) } " )
print ( f " \n API Request Error: { str ( e ) } " )
return { " error " : f " Error submitting claim: { str ( e ) } " }
return { " error " : f " Error submitting claim: { str ( e ) } " }
async def fetch_claim (
claim_id : str ,
active_did : str ,
private_key_hex : str ,
api_server : str = API_SERVER
) - > Dict [ str , Any ] :
"""
Fetch claim details from the endorser service .
Args :
claim_id ( str ) : The ID of the claim to fetch
active_did ( str ) : The DID making the request
private_key_hex ( str ) : Private key for signing auth JWT
api_server ( str , optional ) : API endpoint . Defaults to API_SERVER .
Returns :
Dict [ str , Any ] : The claim details
Raises :
requests . RequestException : For API communication errors
"""
# Create authentication JWT
auth_payload = {
" intent " : " claim.read " ,
" claimId " : claim_id
}
# Sign with the active DID (not endorser DID)
auth_token = await create_endorser_jwt (
active_did ,
private_key_hex ,
auth_payload
)
try :
response = requests . get (
f " { api_server } /api/claim/byHandle/ { claim_id } " ,
headers = {
' Authorization ' : f ' Bearer { auth_token } ' ,
' Content-Type ' : ' application/json '
}
)
return response . json ( )
except requests . RequestException as e :
print ( " \n Error fetching claim: " )
print ( f " Error: { str ( e ) } " )
raise
# Main execution
# Main execution
async def main ( ) :
async def main ( ) :
"""
"""
@ -398,5 +447,19 @@ async def main():
result = await register ( active_did , private_key_hex )
result = await register ( active_did , private_key_hex )
print ( " Registration result: " , result )
print ( " Registration result: " , result )
# Step 3: If registration successful, fetch claim details
if result . get ( " success " ) and result . get ( " claimId " ) :
print ( " \n Fetching claim details... " )
try :
claim_details = await fetch_claim (
result [ " claimId " ] ,
active_did ,
private_key_hex
)
print ( " \n Claim Details: " )
print ( json . dumps ( claim_details , indent = 2 ) )
except Exception as e :
print ( f " Error fetching claim: { str ( e ) } " )
if __name__ == " __main__ " :
if __name__ == " __main__ " :
asyncio . run ( main ( ) )
asyncio . run ( main ( ) )