-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat/documentation] Documented openid4vp plus refactoring and some t…
…odo (#202) * feat: added policy apply on metadata * test: added intial tests for TrustEvaluationHelper * fix: fixed validation issues * feat: implemented method add_trust_attestation_metadata * test: added test for add_trust_attestation_metadata * fix: added metadata association by metadata_type field * fix: minor fix to test for add_trust_attestation_metadata's data type * chore: renamed test file * chore: Removed comment * fix: fixed x509 verification exception handling * chore: fix typo * fix: merged federation and metadata policy implementation * test: adapted tests * feat: added final_metadata property * feat: added chain discovery plus refactoring * docs: documented file class and functions * fix: fixed trust_anchor_entity_conf handling * docs: documented trust_chain_builder.py * fix: moved implementation of get_http_url in utils.py * fix: fixed response handling * docs: documented file class and function plus refactoring * docs: documented file __init__.py * docs: added docs for http_client.py * docs: documented the content of __init__.py * docs: documented contento of __init__.py * fix: method name refactoring * fix: added exception * fix: refactored method find_jwk * docs: fixed documentation * fix: refactoring * docs: documented content of utils.py * docs: documented __init__.py content * fix: Resolved todo (what if the credential is not a JWT?) * feat: implemented is_jwe_format and is_jws_format * test: amplied test * fix: refactored code * feat: resolved todo (detect if it is encrypted otherwise) * fix: code refactoring * docs: documented content of direct_post_response.py * fix: amplied error messages * feat: resolved todo (automatic detection of the credential) * docs: amplied the documentation * fix: refactored code * fix: added dependency * docs: documented content of vp_sd_jwt.py * fix: refactored code * docs: documented content of vp.py --------- Co-authored-by: Giuseppe De Marco <[email protected]>
- Loading branch information
Showing
8 changed files
with
222 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,62 @@ | ||
|
||
from pyeudiw.jwt.utils import decode_jwt_payload, decode_jwt_header | ||
from pyeudiw.openid4vp.vp_sd_jwt import VpSdJwt | ||
|
||
|
||
class Vp(VpSdJwt): | ||
"Class for SD-JWT Format" | ||
def __init__(self, jwt: str) -> None: | ||
""" | ||
Generates a VP istance. | ||
def __init__(self, jwt: str): | ||
# TODO: what if the credential is not a JWT? | ||
self.headers = decode_jwt_header(jwt) | ||
self.jwt = jwt | ||
self.payload = decode_jwt_payload(jwt) | ||
:param jwt: a string that represents the jwt. | ||
:type jwt: str | ||
self.credential_headers: dict = {} | ||
self.credential_payload: dict = {} | ||
:raises InvalidVPToken: if the jwt field's value is not a JWT. | ||
""" | ||
super().__init__(jwt) | ||
|
||
self.parse_digital_credential() | ||
self.disclosed_user_attributes: dict = {} | ||
|
||
def _detect_vp_type(self): | ||
# TODO - automatic detection of the credential | ||
return 'jwt' | ||
|
||
def get_credential_jwks(self): | ||
def _detect_vp_type(self) -> str: | ||
""" | ||
Detects and return the type of verifiable presentation. | ||
:returns: the type of VP. | ||
:rtype: str | ||
""" | ||
return self.headers["typ"].lower() | ||
|
||
def get_credential_jwks(self) -> list[dict]: | ||
""" | ||
Returns the credential JWKs. | ||
:returns: the list containing credential's JWKs. | ||
:rtype: list[dict] | ||
""" | ||
if not self.credential_jwks: | ||
return {} | ||
return self.credential_jwks | ||
|
||
@property | ||
def credential_issuer(self): | ||
if not self.credential_payload.get('iss', None): | ||
self.parse_digital_credential() | ||
return self.credential_payload.get('iss', None) | ||
|
||
def parse_digital_credential(self): | ||
def parse_digital_credential(self) -> None: | ||
""" | ||
Parse the digital credential of VP. | ||
:raises NotImplementedError: if VP Digital credentials type not implemented. | ||
""" | ||
_typ = self._detect_vp_type() | ||
if _typ == 'jwt': | ||
self.credential_headers = decode_jwt_header(self.payload['vp']) | ||
self.credential_payload = decode_jwt_payload(self.payload['vp']) | ||
else: | ||
|
||
if _typ != 'jwt': | ||
raise NotImplementedError( | ||
f"VP Digital credentials type not implemented yet: {_typ}" | ||
) | ||
|
||
self.credential_headers = decode_jwt_header(self.payload['vp']) | ||
self.credential_payload = decode_jwt_payload(self.payload['vp']) | ||
|
||
@property | ||
def credential_issuer(self) -> str: | ||
"""Returns the credential issuer""" | ||
if not self.credential_payload.get('iss', None): | ||
self.parse_digital_credential() | ||
return self.credential_payload.get('iss', None) |
Oops, something went wrong.