-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathverifier.py
117 lines (89 loc) · 3.97 KB
/
verifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from enum import Enum
from typing import Optional
from aries_cloudcontroller import DIFPresSpec, DIFProofRequest, IndyPresSpec
from aries_cloudcontroller import IndyProofRequest as AcaPyIndyProofRequest
from pydantic import BaseModel, Field, ValidationInfo, field_validator
from shared.exceptions import CloudApiValueError
from shared.models.protocol import PresentProofProtocolVersion
class ProofRequestType(str, Enum):
INDY: str = "indy"
JWT: str = "jwt"
LD_PROOF: str = "ld_proof"
class IndyProofRequest(AcaPyIndyProofRequest):
name: str = Field(default="Proof", description="Proof request name")
version: str = Field(default="1.0", description="Proof request version")
class ProofRequestBase(BaseModel):
type: ProofRequestType = ProofRequestType.INDY
indy_proof_request: Optional[IndyProofRequest] = None
dif_proof_request: Optional[DIFProofRequest] = None
@field_validator("indy_proof_request", mode="before")
@classmethod
def check_indy_proof_request(cls, value, values: ValidationInfo):
proof_type = values.data.get("type")
if proof_type == ProofRequestType.INDY and value is None:
raise CloudApiValueError(
"indy_proof_request must be populated if `indy` type is selected"
)
if (
proof_type == ProofRequestType.INDY
and values.data.get("dif_proof_request") is not None
):
raise CloudApiValueError(
"dif_proof_request must not be populated if `indy` type is selected"
)
return value
@field_validator("dif_proof_request", mode="before")
@classmethod
def check_dif_proof_request(cls, value, values: ValidationInfo):
proof_type = values.data.get("type")
if proof_type == ProofRequestType.LD_PROOF and value is None:
raise CloudApiValueError(
"dif_proof_request must be populated if `ld_proof` type is selected"
)
if (
proof_type == ProofRequestType.LD_PROOF
and values.data.get("indy_proof_request") is not None
):
raise CloudApiValueError(
"indy_proof_request must not be populated if `ld_proof` type is selected"
)
return value
class ProofRequestMetadata(BaseModel):
protocol_version: PresentProofProtocolVersion = PresentProofProtocolVersion.v2
comment: Optional[str] = None
trace: Optional[bool] = None
class CreateProofRequest(ProofRequestBase, ProofRequestMetadata):
save_exchange_record: bool = Field(
default=False,
description="Whether the presentation exchange record should be saved on completion",
)
class SendProofRequest(CreateProofRequest):
connection_id: str
class ProofId(BaseModel):
proof_id: str
class AcceptProofRequest(ProofId):
type: ProofRequestType = ProofRequestType.INDY
indy_presentation_spec: Optional[IndyPresSpec] = None
dif_presentation_spec: Optional[DIFPresSpec] = None
save_exchange_record: bool = Field(
default=False,
description="Whether the presentation exchange record should be saved on completion",
)
@field_validator("indy_presentation_spec", mode="before")
@classmethod
def check_indy_presentation_spec(cls, value, values: ValidationInfo):
if values.data.get("type") == ProofRequestType.INDY and value is None:
raise CloudApiValueError(
"indy_presentation_spec must be populated if `indy` type is selected"
)
return value
@field_validator("dif_presentation_spec", mode="before")
@classmethod
def check_dif_presentation_spec(cls, value, values: ValidationInfo):
if values.data.get("type") == ProofRequestType.LD_PROOF and value is None:
raise CloudApiValueError(
"dif_presentation_spec must be populated if `ld_proof` type is selected"
)
return value
class RejectProofRequest(ProofId):
problem_report: Optional[str] = None