This repository was archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdid.py
More file actions
87 lines (60 loc) · 2.37 KB
/
did.py
File metadata and controls
87 lines (60 loc) · 2.37 KB
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
import json
from typing import Any, Dict, Union
from indy import did
from .error import IndyErrorHandler, WalletItemNotFound
@IndyErrorHandler()
async def create_and_store_my_did(
wallet_handle: int, did_dict: Dict[str, Any] = {}
) -> (str, str):
return await did.create_and_store_my_did(wallet_handle, json.dumps(did_dict))
@IndyErrorHandler()
async def create_key(wallet_handle: int, key_dict: Dict[str, Any]) -> str:
return await did.create_key(wallet_handle, json.dumps(key_dict))
@IndyErrorHandler()
async def store_their_did(wallet_handle: int, identity_dict: Dict[str, Any]) -> None:
await did.store_their_did(wallet_handle, json.dumps(identity_dict))
@IndyErrorHandler()
async def set_key_metadata(
wallet_handle: int, verkey: str, metadata: Union[Dict, str]
) -> None:
if isinstance(metadata, dict):
metadata = json.dumps(metadata)
await did.set_key_metadata(wallet_handle, verkey, metadata)
@IndyErrorHandler()
async def get_key_metadata(wallet_handle: int, verkey: str) -> str:
metadata = await did.get_key_metadata(wallet_handle, verkey)
try:
metadata = json.loads(metadata)
except json.decoder.JSONDecodeError:
pass
return metadata
@IndyErrorHandler()
async def get_did_metadata(wallet_handle: int, did_subject: str) -> str:
metadata = await did.get_did_metadata(wallet_handle, did_subject)
try:
metadata = json.loads(metadata)
except json.decoder.JSONDecodeError:
pass
return metadata
@IndyErrorHandler()
async def set_did_metadata(
wallet_handle: int, did_subject: str, metadata: Union[Dict, str]
) -> None:
if isinstance(metadata, dict):
metadata = json.dumps(metadata)
return await did.set_did_metadata(wallet_handle, did_subject, metadata)
@IndyErrorHandler()
async def key_for_local_did(wallet_handle: int, did: str) -> str:
return await did.key_for_local_did(wallet_handle, did)
async def did_for_key(wallet_handle: int, verkey: str) -> str:
try:
with IndyErrorHandler():
key_meta = await get_key_metadata(wallet_handle, verkey)
if "did" not in key_meta:
return None
return key_meta["did"]
except WalletItemNotFound:
return None
@IndyErrorHandler()
async def map_key_to_did(wallet_handle: int, verkey: str, did: str):
await set_key_metadata(wallet_handle, verkey, {"did": did})