Skip to content

Commit 8178eb2

Browse files
committed
fix: on sign vp, use auth proof purpose
Signed-off-by: Daniel Bluhm <[email protected]>
1 parent e9beda3 commit 8178eb2

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

acapy_agent/protocols/present_proof/dif/pres_exch_handler.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@
4040
from ....vc.vc_di.prove import create_signed_anoncreds_presentation
4141
from ....vc.vc_ld.prove import create_presentation, derive_credential, sign_presentation
4242
from ....wallet.base import BaseWallet, DIDInfo
43-
from ....wallet.default_verification_key_strategy import BaseVerificationKeyStrategy
43+
from ....wallet.default_verification_key_strategy import (
44+
BaseVerificationKeyStrategy,
45+
ProofPurposeStr,
46+
)
4447
from ....wallet.error import WalletError, WalletNotFoundError
4548
from ....wallet.key_type import BLS12381G2, ED25519
4649
from .pres_exch import (
@@ -115,15 +118,17 @@ async def _get_issue_suite(
115118
self,
116119
*,
117120
issuer_id: str,
121+
proof_purpose: Optional[ProofPurposeStr] = None,
118122
):
119123
"""Get signature suite for signing presentation."""
124+
proof_purpose = proof_purpose or "assertionMethod"
120125
did_info = await self._did_info_for_did(issuer_id)
121126
vm_id_strategy = self.profile.context.inject(BaseVerificationKeyStrategy)
122127
verification_method = await vm_id_strategy.get_verification_method_id_for_did(
123128
issuer_id,
124129
self.profile,
125130
proof_type=self.proof_type,
126-
proof_purpose="assertionMethod",
131+
proof_purpose=proof_purpose,
127132
)
128133

129134
# Get signature class based on proof type
@@ -1300,8 +1305,9 @@ async def create_vp(
13001305
)
13011306
else:
13021307
vp = self.__add_dif_fields_to_vp(vp, submission_property)
1308+
assert issuer_id
13031309
issue_suite = await self._get_issue_suite(
1304-
issuer_id=issuer_id,
1310+
issuer_id=issuer_id, proof_purpose="authentication"
13051311
)
13061312
signed_vp = await sign_presentation(
13071313
presentation=vp,

acapy_agent/wallet/default_verification_key_strategy.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from abc import ABC, abstractmethod
44
import logging
5-
from typing import Optional
5+
from typing import Literal, Optional
66

77
from pydid import DIDDocument
88

@@ -14,6 +14,20 @@
1414
LOGGER = logging.getLogger(__name__)
1515

1616

17+
ProofPurposeStr = Literal[
18+
"assertionMethod",
19+
"authentication",
20+
"capabilityDelegation",
21+
"capabilityInvocation",
22+
]
23+
PROOF_PURPOSES = (
24+
"authentication",
25+
"assertionMethod",
26+
"capabilityInvocation",
27+
"capabilityDelegation",
28+
)
29+
30+
1731
class VerificationKeyStrategyError(BaseError):
1832
"""Raised on issues with verfication method derivation."""
1933

@@ -28,7 +42,7 @@ async def get_verification_method_id_for_did(
2842
profile: Profile,
2943
*,
3044
proof_type: Optional[str] = None,
31-
proof_purpose: Optional[str] = None,
45+
proof_purpose: Optional[ProofPurposeStr] = None,
3246
) -> Optional[str]:
3347
"""Given a DID, returns the verification key ID in use.
3448
@@ -62,7 +76,7 @@ async def get_verification_method_id_for_did(
6276
profile: Profile,
6377
*,
6478
proof_type: Optional[str] = None,
65-
proof_purpose: Optional[str] = None,
79+
proof_purpose: Optional[ProofPurposeStr] = None,
6680
) -> Optional[str]:
6781
"""Given a did:key or did:sov, returns the verification key ID in use.
6882
@@ -77,12 +91,7 @@ async def get_verification_method_id_for_did(
7791
proof_type = proof_type or "Ed25519Signature2018"
7892
proof_purpose = proof_purpose or "assertionMethod"
7993

80-
if proof_purpose not in (
81-
"authentication",
82-
"assertionMethod",
83-
"capabilityInvocation",
84-
"capabilityDelegation",
85-
):
94+
if proof_purpose not in PROOF_PURPOSES:
8695
raise ValueError("Invalid proof purpose")
8796

8897
if did.startswith("did:key:"):

0 commit comments

Comments
 (0)