Skip to content
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

shorten python case names, handle if payload has an 'id' field. #51

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions peerdid/core/peer_did_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from ..errors import MalformedPeerDIDError
from ..keys import KeyFormat, BaseKey

SERVICE_ID = "id"
SERVICE_TYPE = "type"
SERVICE_ENDPOINT = "serviceEndpoint"
SERVICE_DIDCOMM_MESSAGING = "DIDCommMessaging"
SERVICE_ROUTING_KEYS = "routingKeys"
SERVICE_ACCEPT = "accept"
SERVICE_ID = ["id"] #id field not in spec
SERVICE_TYPE = ["type"]
SERVICE_ENDPOINT = ["serviceEndpoint","service_endpoint"]
SERVICE_DIDCOMM_MESSAGING = ["DIDCommMessaging"]
SERVICE_ROUTING_KEYS = ["routingKeys","routing_keys"]
SERVICE_ACCEPT = ["accept"]

ServiceJson = Union[str, dict, list]

Expand Down Expand Up @@ -75,16 +75,16 @@ def encode_service(service: ServiceJson) -> str:
def _encode_service_entry(service: dict) -> dict:
result = {}
for k, v in service.items():
if k == SERVICE_TYPE:
if k in SERVICE_TYPE:
k = ServicePrefix.SERVICE_TYPE.value
elif k == SERVICE_ENDPOINT:
elif k in SERVICE_ENDPOINT:
k = ServicePrefix.SERVICE_ENDPOINT.value
elif k == SERVICE_ROUTING_KEYS:
elif k in SERVICE_ROUTING_KEYS:
k = ServicePrefix.SERVICE_ROUTING_KEYS.value
elif k == SERVICE_ACCEPT:
elif k in SERVICE_ACCEPT:
k = ServicePrefix.SERVICE_ACCEPT.value

if v == SERVICE_DIDCOMM_MESSAGING:
if v in SERVICE_DIDCOMM_MESSAGING:
v = ServicePrefix.SERVICE_DIDCOMM_MESSAGING.value

result[k] = v
Expand Down Expand Up @@ -122,7 +122,7 @@ def decode_service(service: str) -> Optional[List[Service]]:
)
if not service_type:
raise MalformedPeerDIDError("Service doesn't contain a type")
ident = "#" + service_type.lower() + "-" + str(i)
ident = svc_def.pop("id") if "id" in svc_def else "#" + service_type.lower() + "-" + str(i)
endpoint = svc_def.pop(ServicePrefix.SERVICE_ENDPOINT.value, None)
extra = {}
for k, v in svc_def.items():
Expand Down