def make_did_doc(self):
     doc = DIDDoc(did=self.test_did)
     controller = self.test_did
     ident = "1"
     pk_value = self.test_verkey
     pk = PublicKey(
         self.test_did,
         ident,
         pk_value,
         PublicKeyType.ED25519_SIG_2018,
         controller,
         False,
     )
     doc.set(pk)
     recip_keys = [pk]
     router_keys = []
     service = Service(
         self.test_did,
         "indy",
         "IndyAgent",
         recip_keys,
         router_keys,
         self.test_endpoint,
     )
     doc.set(service)
     return doc
Example #2
0
    async def create_did_document(self,
                                  my_info: DIDInfo,
                                  inbound_connection_id: str = None,
                                  my_endpoint: str = None) -> DIDDoc:
        """Create our DID document for a given DID.

        Args:
            my_info: The DID I am using in this connection
            inbound_connection_id: The DID of the inbound routing connection to use
            my_endpoint: A custom endpoint for the DID Document

        Returns:
            The prepared `DIDDoc` instance

        """

        did_doc = DIDDoc(did=my_info.did)
        did_controller = my_info.did
        did_key = my_info.verkey
        pk = PublicKey(
            my_info.did,
            "1",
            did_key,
            PublicKeyType.ED25519_SIG_2018,
            did_controller,
            True,
        )
        did_doc.set(pk)

        router_id = inbound_connection_id
        routing_keys = []
        router_idx = 1
        while router_id:
            # look up routing connection information
            router = await ConnectionRecord.retrieve_by_id(
                self.context, router_id)
            if router.state != ConnectionRecord.STATE_ACTIVE:
                raise ConnectionManagerError(
                    f"Router connection not active: {router_id}")
            routing_doc = await self.fetch_did_document(router.their_did)
            if not routing_doc.service:
                raise ConnectionManagerError(
                    f"No services defined by routing DIDDoc: {router_id}")
            for service in routing_doc.service.values():
                if not service.endpoint:
                    raise ConnectionManagerError(
                        "Routing DIDDoc service has no service endpoint")
                if not service.recip_keys:
                    raise ConnectionManagerError(
                        "Routing DIDDoc service has no recipient key(s)")
                rk = PublicKey(
                    my_info.did,
                    f"routing-{router_idx}",
                    service.recip_keys[0].value,
                    PublicKeyType.ED25519_SIG_2018,
                    did_controller,
                    True,
                )
                routing_keys.append(rk)
                my_endpoint = service.endpoint
                break
            router_id = router.inbound_connection_id

        if not my_endpoint:
            my_endpoint = self.context.settings.get("default_endpoint")
        service = Service(my_info.did, "indy", "IndyAgent", [pk], routing_keys,
                          my_endpoint)
        did_doc.set(service)

        return did_doc