import time
from importlib.metadata import version
from typing import Optional
from ._dcap_qvl import (
PyQuoteCollateralV3 as QuoteCollateralV3,
PyVerifiedReport as VerifiedReport,
PyQuote as Quote,
py_verify as verify,
py_verify_with_root_ca as verify_with_root_ca,
parse_quote,
get_collateral_for_fmspc,
)
PHALA_PCCS_URL = "https://pccs.phala.network"
INTEL_PCS_URL = "https://api.trustedservices.intel.com"
PCS_URL = INTEL_PCS_URL
async def get_collateral(pccs_url: str, raw_quote: bytes) -> QuoteCollateralV3:
if not isinstance(raw_quote, (bytes, bytearray)):
raise TypeError("raw_quote must be bytes")
quote = Quote.parse(raw_quote)
fmspc = quote.fmspc()
is_sgx = quote.is_sgx()
ca = quote.ca()
return await get_collateral_for_fmspc(pccs_url, fmspc, ca, is_sgx)
async def get_collateral_from_pcs(raw_quote: bytes) -> QuoteCollateralV3:
return await get_collateral(INTEL_PCS_URL, raw_quote)
async def get_collateral_and_verify(
raw_quote: bytes, pccs_url: Optional[str] = None
) -> VerifiedReport:
url = (pccs_url or "").strip() or PHALA_PCCS_URL
collateral = await get_collateral(url, raw_quote)
now_secs = int(time.time())
return verify(raw_quote, collateral, now_secs)
__all__ = [
"QuoteCollateralV3",
"VerifiedReport",
"Quote",
"verify",
"verify_with_root_ca",
"get_collateral",
"get_collateral_from_pcs",
"get_collateral_and_verify",
"get_collateral_for_fmspc",
"parse_quote",
"PHALA_PCCS_URL",
"INTEL_PCS_URL",
"PCS_URL",
]
__version__ = version("dcap-qvl")