-
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.
Merge branch 'dev' into elliptic-curve-support
- Loading branch information
Showing
8 changed files
with
222 additions
and
61 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.