Skip to content

Commit 6b54afa

Browse files
authored
Merge pull request #31 from dbluhm/fix/integrations
fixes: consistency and built doc dereferencing
2 parents 26e75a3 + b7d4402 commit 6b54afa

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

pydid/doc/builder.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def add(
136136

137137
def add_didcomm(
138138
self,
139-
endpoint: str,
139+
service_endpoint: str,
140140
recipient_keys: List[VerificationMethod],
141141
routing_keys: List[VerificationMethod] = None,
142142
*,
@@ -150,7 +150,7 @@ def add_didcomm(
150150
priority = priority or self._determine_next_priority()
151151
service = DIDCommService.make(
152152
id=self._did.ref(ident),
153-
service_endpoint=endpoint,
153+
service_endpoint=service_endpoint,
154154
recipient_keys=[vmethod.id for vmethod in recipient_keys],
155155
routing_keys=[vmethod.id for vmethod in routing_keys],
156156
type=type_,
@@ -228,7 +228,7 @@ def from_doc(cls, doc: DIDDocument) -> "DIDDocumentBuilder":
228228
def build(self) -> DIDDocument:
229229
"""Build document."""
230230
return DIDDocument.construct(
231-
id=str(self.id),
231+
id=self.id,
232232
context=self.context,
233233
also_known_as=self.also_known_as,
234234
controller=self.controller,

pydid/doc/doc.py

+7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ def to_json(self):
148148
"""Serialize DID Document to JSON."""
149149
return self.json()
150150

151+
@classmethod
152+
def construct(cls, **data):
153+
"""Construct and index."""
154+
doc = super(Resource, cls).construct(**data)
155+
doc._index_resources()
156+
return doc
157+
151158

152159
PossibleMethodTypes = Union[KnownVerificationMethods, UnknownVerificationMethod]
153160
PossibleServiceTypes = Union[DIDCommService, UnknownService]

tests/doc/test_doc.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@ def test_programmatic_construction_didcomm():
415415
ExampleVerificationMethod, public_key_example="abcd"
416416
)
417417
builder.service.add_didcomm(
418-
endpoint="https://example.com", recipient_keys=[key], routing_keys=[route]
418+
service_endpoint="https://example.com",
419+
recipient_keys=[key],
420+
routing_keys=[route],
419421
)
420-
print(builder.build())
421-
print(builder.build().serialize())
422422
assert builder.build().serialize() == {
423423
"@context": ["https://www.w3.org/ns/did/v1"],
424424
"id": "did:example:123",
@@ -598,6 +598,15 @@ def test_key_rotation_from_doc():
598598
}
599599

600600

601+
def test_build_and_dereference():
602+
builder = DIDDocumentBuilder("did:example:123")
603+
builder.verification_method.add(
604+
Ed25519VerificationKey2018, public_key_base58="test", ident="1"
605+
)
606+
doc = builder.build()
607+
assert doc.dereference("#1")
608+
609+
601610
def test_dereference_and_membership_check():
602611
doc_raw = {
603612
"@context": "https://www.w3.org/ns/did/v1",

0 commit comments

Comments
 (0)