16
16
# under the License.
17
17
18
18
import functools
19
- import typing
20
19
from base64 import urlsafe_b64decode
21
20
from base64 import urlsafe_b64encode
22
21
from enum import Enum
22
+ from typing import Any
23
+ from typing import Dict
24
+ from typing import Optional
25
+ from typing import Union
23
26
24
27
25
28
class Protocol (str , Enum ):
@@ -65,7 +68,7 @@ def __init__(
65
68
self .is_user_consenting : bool = is_user_consenting
66
69
self .is_user_verified : bool = is_user_verified
67
70
68
- def to_dict (self ) -> typing . Dict [str , typing . Union [str , bool ]]:
71
+ def to_dict (self ) -> Dict [str , Union [str , bool ]]:
69
72
return {
70
73
"protocol" : self .protocol ,
71
74
"transport" : self .transport ,
@@ -82,7 +85,7 @@ def __init__(
82
85
credential_id : bytes ,
83
86
is_resident_credential : bool ,
84
87
rp_id : str ,
85
- user_handle : typing . Optional [bytes ],
88
+ user_handle : Optional [bytes ],
86
89
private_key : bytes ,
87
90
sign_count : int ,
88
91
):
@@ -117,7 +120,7 @@ def rp_id(self) -> str:
117
120
return self ._rp_id
118
121
119
122
@property
120
- def user_handle (self ) -> typing . Optional [str ]:
123
+ def user_handle (self ) -> Optional [str ]:
121
124
if self ._user_handle :
122
125
return urlsafe_b64encode (self ._user_handle ).decode ()
123
126
return None
@@ -147,7 +150,7 @@ def create_non_resident_credential(cls, id: bytes, rp_id: str, private_key: byte
147
150
148
151
@classmethod
149
152
def create_resident_credential (
150
- cls , id : bytes , rp_id : str , user_handle : typing . Optional [bytes ], private_key : bytes , sign_count : int
153
+ cls , id : bytes , rp_id : str , user_handle : Optional [bytes ], private_key : bytes , sign_count : int
151
154
) -> "Credential" :
152
155
"""Creates a resident (i.e. stateful) credential.
153
156
@@ -163,7 +166,7 @@ def create_resident_credential(
163
166
"""
164
167
return cls (id , True , rp_id , user_handle , private_key , sign_count )
165
168
166
- def to_dict (self ) -> typing . Dict [str , typing . Any ]:
169
+ def to_dict (self ) -> Dict [str , Any ]:
167
170
credential_data = {
168
171
"credentialId" : self .id ,
169
172
"isResidentCredential" : self ._is_resident_credential ,
@@ -178,7 +181,7 @@ def to_dict(self) -> typing.Dict[str, typing.Any]:
178
181
return credential_data
179
182
180
183
@classmethod
181
- def from_dict (cls , data : typing . Dict [str , typing . Any ]) -> "Credential" :
184
+ def from_dict (cls , data : Dict [str , Any ]) -> "Credential" :
182
185
_id = urlsafe_b64decode (f"{ data ['credentialId' ]} ==" )
183
186
is_resident_credential = bool (data ["isResidentCredential" ])
184
187
rp_id = data .get ("rpId" , None )
0 commit comments