Skip to content

Commit

Permalink
Merge pull request #7 from decentralized-identity/feature/input-doc-g…
Browse files Browse the repository at this point in the history
…en-extra-params

feat: add extra params to key spec
  • Loading branch information
dbluhm authored Nov 14, 2023
2 parents 2e46dce + 3171489 commit e347840
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 4 deletions.
10 changes: 6 additions & 4 deletions did_peer_4/input_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class KeySpec:
"""Key specification."""

multikey: str
relationships: Sequence[Relationship]
relationships: Optional[Sequence[Relationship]] = None
ident: Optional[str] = None
type: Optional[str] = None


def input_doc_from_keys_and_services(
Expand All @@ -41,12 +43,12 @@ def input_doc_from_keys_and_services(
ident = f"#key-{index}"
input_doc.setdefault("verificationMethod", []).append(
{
"id": ident,
"type": "Multikey",
"id": key.ident or ident,
"type": key.type or "Multikey",
"publicKeyMultibase": key.multikey,
}
)
for relationship in key.relationships:
for relationship in key.relationships or []:
if relationship not in RELATIONSHIPS:
raise ValueError(f"Invalid relationship: {relationship}")

Expand Down
69 changes: 69 additions & 0 deletions tests/test_input_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

ED25519_MULTIKEY = "z6MkrCD1csqtgdj8sjrsu8jxcbeyP6m7LiK87NzhfWqio5yr"
X25519_MULTIKEY = "z6LSqPZfn9krvgXma2icTMKf2uVcYhKXsudCmPoUzqGYW24U"
ANOTHER_ED25519_MULTIKEY = "z6Mkq4o8kZj1nK5z5Y8K8gY7aV9j8jg6YJzqZ6Dj9j7eY4d2"


def test_input_doc_generation():
Expand Down Expand Up @@ -62,3 +63,71 @@ def test_input_doc_generation():
}
assert validate_input_document(input_doc)
assert encode(input_doc)


def test_input_doc_generation_extra_params():
input_doc = input_doc_from_keys_and_services(
[
KeySpec(
ident="#auth-0",
multikey=ED25519_MULTIKEY,
relationships=["authentication"],
),
KeySpec(
ident="#agree-0",
multikey=X25519_MULTIKEY,
relationships=["keyAgreement"],
),
KeySpec(
multikey=ANOTHER_ED25519_MULTIKEY,
),
],
[
{
"id": "#didcommmessaging-0",
"type": "DIDCommMessaging",
"serviceEndpoint": {
"uri": "didcomm:transport/queue",
"accept": ["didcomm/v2"],
},
}
],
)

assert input_doc == {
"@context": [
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/multikey/v1",
],
"verificationMethod": [
{
"id": "#auth-0",
"type": "Multikey",
"publicKeyMultibase": ED25519_MULTIKEY,
},
{
"id": "#agree-0",
"type": "Multikey",
"publicKeyMultibase": X25519_MULTIKEY,
},
{
"id": "#key-2",
"type": "Multikey",
"publicKeyMultibase": ANOTHER_ED25519_MULTIKEY,
},
],
"authentication": ["#key-0"],
"keyAgreement": ["#key-1"],
"service": [
{
"id": "#didcommmessaging-0",
"type": "DIDCommMessaging",
"serviceEndpoint": {
"uri": "didcomm:transport/queue",
"accept": ["didcomm/v2"],
},
}
],
}
assert validate_input_document(input_doc)
assert encode(input_doc)

0 comments on commit e347840

Please sign in to comment.