Skip to content

Commit

Permalink
Merge pull request #31 from dbluhm/fix/integrations
Browse files Browse the repository at this point in the history
fixes: consistency and built doc dereferencing
  • Loading branch information
dbluhm authored May 5, 2021
2 parents 26e75a3 + b7d4402 commit 6b54afa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pydid/doc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def add(

def add_didcomm(
self,
endpoint: str,
service_endpoint: str,
recipient_keys: List[VerificationMethod],
routing_keys: List[VerificationMethod] = None,
*,
Expand All @@ -150,7 +150,7 @@ def add_didcomm(
priority = priority or self._determine_next_priority()
service = DIDCommService.make(
id=self._did.ref(ident),
service_endpoint=endpoint,
service_endpoint=service_endpoint,
recipient_keys=[vmethod.id for vmethod in recipient_keys],
routing_keys=[vmethod.id for vmethod in routing_keys],
type=type_,
Expand Down Expand Up @@ -228,7 +228,7 @@ def from_doc(cls, doc: DIDDocument) -> "DIDDocumentBuilder":
def build(self) -> DIDDocument:
"""Build document."""
return DIDDocument.construct(
id=str(self.id),
id=self.id,
context=self.context,
also_known_as=self.also_known_as,
controller=self.controller,
Expand Down
7 changes: 7 additions & 0 deletions pydid/doc/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ def to_json(self):
"""Serialize DID Document to JSON."""
return self.json()

@classmethod
def construct(cls, **data):
"""Construct and index."""
doc = super(Resource, cls).construct(**data)
doc._index_resources()
return doc


PossibleMethodTypes = Union[KnownVerificationMethods, UnknownVerificationMethod]
PossibleServiceTypes = Union[DIDCommService, UnknownService]
Expand Down
15 changes: 12 additions & 3 deletions tests/doc/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ def test_programmatic_construction_didcomm():
ExampleVerificationMethod, public_key_example="abcd"
)
builder.service.add_didcomm(
endpoint="https://example.com", recipient_keys=[key], routing_keys=[route]
service_endpoint="https://example.com",
recipient_keys=[key],
routing_keys=[route],
)
print(builder.build())
print(builder.build().serialize())
assert builder.build().serialize() == {
"@context": ["https://www.w3.org/ns/did/v1"],
"id": "did:example:123",
Expand Down Expand Up @@ -598,6 +598,15 @@ def test_key_rotation_from_doc():
}


def test_build_and_dereference():
builder = DIDDocumentBuilder("did:example:123")
builder.verification_method.add(
Ed25519VerificationKey2018, public_key_base58="test", ident="1"
)
doc = builder.build()
assert doc.dereference("#1")


def test_dereference_and_membership_check():
doc_raw = {
"@context": "https://www.w3.org/ns/did/v1",
Expand Down

0 comments on commit 6b54afa

Please sign in to comment.