-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: minor type hint corrections for VcLdpManager #2704
Merged
swcurran
merged 3 commits into
openwallet-foundation:main
from
dbluhm:fix/vc-ldp-manager-types
Jan 16, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
"""Manager for performing Linked Data Proof signatures over JSON-LD formatted W3C VCs.""" | ||
|
||
|
||
from typing import Dict, Optional, Type | ||
from typing import Dict, List, Optional, Type, Union, cast | ||
|
||
from ...core.profile import Profile | ||
from ...wallet.base import BaseWallet | ||
|
@@ -32,31 +32,37 @@ | |
from .models.options import LDProofVCOptions | ||
from .verify import verify_credential, verify_presentation | ||
|
||
|
||
SignatureTypes = Union[ | ||
Type[Ed25519Signature2018], | ||
Type[Ed25519Signature2020], | ||
Type[BbsBlsSignature2020], | ||
] | ||
ProofTypes = Union[ | ||
Type[Ed25519Signature2018], | ||
Type[Ed25519Signature2020], | ||
Type[BbsBlsSignature2020], | ||
Type[BbsBlsSignatureProof2020], | ||
] | ||
SUPPORTED_ISSUANCE_PROOF_PURPOSES = { | ||
CredentialIssuancePurpose.term, | ||
AuthenticationProofPurpose.term, | ||
} | ||
SUPPORTED_ISSUANCE_SUITES = {Ed25519Signature2018, Ed25519Signature2020} | ||
SIGNATURE_SUITE_KEY_TYPE_MAPPING: Dict[Type[LinkedDataProof], KeyType] = { | ||
SIGNATURE_SUITE_KEY_TYPE_MAPPING: Dict[SignatureTypes, KeyType] = { | ||
Ed25519Signature2018: ED25519, | ||
Ed25519Signature2020: ED25519, | ||
} | ||
PROOF_KEY_TYPE_MAPPING = cast( | ||
Dict[ProofTypes, KeyType], SIGNATURE_SUITE_KEY_TYPE_MAPPING | ||
) | ||
|
||
|
||
# We only want to add bbs suites to supported if the module is installed | ||
if BbsBlsSignature2020.BBS_SUPPORTED: | ||
SUPPORTED_ISSUANCE_SUITES.add(BbsBlsSignature2020) | ||
SUPPORTED_ISSUANCE_SUITES.add(BbsBlsSignatureProof2020) | ||
SIGNATURE_SUITE_KEY_TYPE_MAPPING.update( | ||
{ | ||
BbsBlsSignature2020: BLS12381G2, | ||
BbsBlsSignatureProof2020: BLS12381G2, | ||
} | ||
) | ||
SIGNATURE_SUITE_KEY_TYPE_MAPPING[BbsBlsSignature2020] = BLS12381G2 | ||
PROOF_KEY_TYPE_MAPPING[BbsBlsSignatureProof2020] = BLS12381G2 | ||
|
||
|
||
PROOF_TYPE_SIGNATURE_SUITE_MAPPING = { | ||
PROOF_TYPE_SIGNATURE_SUITE_MAPPING: Dict[str, SignatureTypes] = { | ||
suite.signature_type: suite for suite in SIGNATURE_SUITE_KEY_TYPE_MAPPING | ||
} | ||
|
||
|
@@ -311,16 +317,24 @@ async def _get_suite_for_credential( | |
|
||
return suite | ||
|
||
async def _get_all_suites(self): | ||
"""Get all supported suites for verifying presentation.""" | ||
suites = [] | ||
for suite, key_type in SIGNATURE_SUITE_KEY_TYPE_MAPPING.items(): | ||
suites.append( | ||
suite( | ||
async def _get_all_proof_suites(self) -> List[LinkedDataProof]: | ||
"""Get all supported suites for verifying presentation. | ||
|
||
Returns a list of suites instantiated with a key type, derived from | ||
PROOF_KEY_TYPE_MAPPING entries. | ||
""" | ||
return [ | ||
# Satisfy type checks with a cast to LinkedDataProof | ||
cast( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section could use a short comment to understand what is happening, there's a lot going on in the return statement. I could suggest: |
||
LinkedDataProof, | ||
# Instantiate suite with a key type | ||
SuiteClass( | ||
key_pair=WalletKeyPair(profile=self.profile, key_type=key_type), | ||
) | ||
), | ||
) | ||
return suites | ||
# for each suite class -> key_type pair from PROOF_KEY_TYPE_MAPPING | ||
for SuiteClass, key_type in PROOF_KEY_TYPE_MAPPING.items() | ||
] | ||
|
||
async def issue( | ||
self, credential: VerifiableCredential, options: LDProofVCOptions | ||
|
@@ -354,7 +368,7 @@ async def verify_presentation( | |
|
||
return await verify_presentation( | ||
presentation=vp.serialize(), | ||
suites=await self._get_all_suites(), | ||
suites=await self._get_all_proof_suites(), | ||
document_loader=self.profile.inject(DocumentLoader), | ||
challenge=options.challenge, | ||
) | ||
|
@@ -365,6 +379,6 @@ async def verify_credential( | |
"""Verify a VC with a Linked Data Proof.""" | ||
return await verify_credential( | ||
credential=vc.serialize(), | ||
suites=await self._get_all_suites(), | ||
suites=await self._get_all_proof_suites(), | ||
document_loader=self.profile.inject(DocumentLoader), | ||
) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.