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

Add peer did 3 convert method #62

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions peerdid/dids.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Peer DID document generation and resolution."""

import re

from hashlib import sha256
from typing import Optional, Sequence, Union

from pydid import DID, DIDDocument, DIDDocumentBuilder, DIDUrl, InvalidDIDError

from .core.peer_did_helper import (
Numalgo2Prefix,
ServiceJson,
Expand All @@ -14,7 +13,8 @@
decode_service,
)
from .errors import MalformedPeerDIDError
from .keys import KeyFormat, KeyRelationshipType, BaseKey

from .keys import KeyFormat, KeyRelationshipType, BaseKey, to_multibase, MultibaseFormat

PEER_DID_PATTERN = re.compile(
r"^did:peer:(([0](z)([1-9a-km-zA-HJ-NP-Z]+))|(2((\.[AEVID](z)([1-9a-km-zA-HJ-NP-Z]+))+"
Expand Down Expand Up @@ -187,3 +187,12 @@ def _build_did_doc_numalgo_2(
raise MalformedPeerDIDError("Unknown prefix: {}.".format(prefix))

return builder.build()



def gen_did_peer_3(peer_did_2 : Union[str,DID]) -> DID:
if not peer_did_2.startswith("did:peer:2"):
raise MalformedPeerDIDError("did:peer:2 expected")

content = to_multibase(sha256(peer_did_2.lstrip("did:peer:2")),MultibaseFormat.BASE58)
return "did:peer:3"+content
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

# TODO move remaining things
setup(
install_requires=["base58~=2.1.0", "pydid~=0.3.5", "varint~=1.0.2"],
install_requires=["base58~=2.1.0", "pydid~=0.3.9a0", "varint~=1.0.2"],
extras_require={"tests": ["pytest==6.2.5", "pytest-xdist==2.3.0"]},
)