Exemplo n.º 1
0
def test_uniresolver_docs(caplog, doc):
    caplog.set_level(logging.INFO)
    LOGGER.info("Doc\n%s", json.dumps(doc, indent=2))
    DIDDocument.deserialize(
        doc,
        options={
            doc_allow_public_key,
            doc_insert_missing_ids,
            vm_allow_controller_list,
            vm_allow_missing_controller,
            vm_allow_type_list,
        },
    )
Exemplo n.º 2
0
    async def _resolve(self, profile: Profile, did: str) -> dict:
        """Resolve did:web DIDs."""

        url = self.__transform_to_url(did)
        async with aiohttp.ClientSession() as session:
            async with session.get(url) as response:
                if response.status == 200:
                    try:
                        # Validate DIDDoc with pyDID
                        did_doc = DIDDocument.from_json(await response.text())
                        return did_doc.serialize()
                    except Exception as err:
                        raise ResolverError(
                            "Response was incorrectly formatted") from err
                if response.status == 404:
                    raise DIDNotFound(f"No document found for {did}")
                raise ResolverError("Could not find doc for {}: {}".format(
                    did, await response.text()))
Exemplo n.º 3
0
    async def resolve(self, profile: Profile, did: Union[str,
                                                         DID]) -> DIDDocument:
        """Resolve a DID using this resolver."""
        py_did = DID(did) if isinstance(did, str) else did

        if not self.supports(py_did.method):
            raise DIDMethodNotSupported(
                f"{self.__class__.__name__} does not support DID method {py_did.method}"
            )

        did_document = await self._resolve(profile, str(py_did))
        result = DIDDocument.deserialize(
            did_document,
            options={
                doc_insert_missing_ids,
                doc_allow_public_key,
                vm_allow_controller_list,
                vm_allow_missing_controller,
                vm_allow_type_list,
            },
        )
        return result
Exemplo n.º 4
0
    async def resolve(self, profile: Profile, did: Union[str,
                                                         DID]) -> DIDDocument:
        """Resolve a DID using this resolver."""
        if isinstance(did, DID):
            did = str(did)
        else:
            DID.validate(did)
        if not await self.supports(profile, did):
            raise DIDMethodNotSupported(
                f"{self.__class__.__name__} does not support DID method for: {did}"
            )

        doc_dict = await self._resolve(profile, did)
        return DIDDocument.deserialize(
            doc_dict,
            options={
                doc_insert_missing_ids,
                doc_allow_public_key,
                vm_allow_controller_list,
                vm_allow_missing_controller,
                vm_allow_type_list,
            },
        )
Exemplo n.º 5
0
def resolver():
    did_resolver_registry = DIDResolverRegistry()
    for method in TEST_DID_METHODS:
        resolver = MockResolver([method], DIDDocument.deserialize(DOC))
        did_resolver_registry.register(resolver)
    return DIDResolver(did_resolver_registry)
Exemplo n.º 6
0
 async def _resolve(self, profile, did) -> DIDDocument:
     return DIDDocument("did:example:123")
def did_doc():
    yield DIDDocument.deserialize(DOC)
Exemplo n.º 8
0
from ....resolver.base import DIDMethodNotSupported, DIDNotFound, ResolverError
from ....resolver.did_resolver import DIDResolver
from ....resolver.tests import DOC
from ....wallet.base import BaseWallet
from ....wallet.error import WalletError
from ....vc.ld_proofs.document_loader import DocumentLoader
from .document_loader import custom_document_loader

from .. import routes as test_module
from ..error import (
    BadJWSHeaderError,
    DroppedAttributeError,
    MissingVerificationMethodError,
)

did_doc = DIDDocument.deserialize(DOC)


@pytest.fixture
def mock_resolver():
    did_resolver = async_mock.MagicMock()
    did_resolver.resolve = async_mock.CoroutineMock(return_value=did_doc)
    url = "did:example:1234abcd#4"
    did_resolver.dereference = async_mock.CoroutineMock(
        return_value=did_doc.dereference(url)
    )
    yield did_resolver


@pytest.fixture
def mock_sign_credential():
Exemplo n.º 9
0
def test_uniresolver_docs_strict(caplog, doc):
    caplog.set_level(logging.INFO)
    LOGGER.info("Doc\n%s", json.dumps(doc, indent=2))
    DIDDocument.deserialize(doc)