Skip to content

Commit

Permalink
Merge pull request openwallet-foundation#36 from baegjae/feature/didd…
Browse files Browse the repository at this point in the history
…oc-move-ssw

Move did:sov to did:ssw in diddoc
  • Loading branch information
baegjae authored Feb 24, 2021
2 parents ad41cd1 + d61aa3e commit c9a362c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 48 deletions.
81 changes: 41 additions & 40 deletions aries_cloudagent/connections/models/diddoc/tests/test_diddoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from asynctest import TestCase as AsyncTestCase, mock as async_mock

from aries_cloudagent.messaging.valid import DID_PREFIX
from .. import DIDDoc, PublicKey, PublicKeyType, Service
from ..util import canon_did, canon_ref

Expand All @@ -30,38 +31,38 @@ async def test_basic(self):
# One authn key by reference
dd_in = {
"@context": "https://w3id.org/did/v1",
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKey": [
{
"id": "3",
"type": "RsaVerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyPem": "-----BEGIN PUBLIC X...",
},
{
"id": "4",
"type": "RsaVerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyPem": "-----BEGIN PUBLIC 9...",
},
{
"id": "6",
"type": "RsaVerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyPem": "-----BEGIN PUBLIC A...",
},
],
"authentication": [
{
"type": "RsaSignatureAuthentication2018",
"publicKey": "did:sov:LjgpST2rjsoxYegQDRm7EL#4",
"publicKey": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#4",
}
],
"service": [
{
"id": "0",
"type": "Agency",
"serviceEndpoint": "did:sov:Q4zqM7aXqm7gDQkUVLng9h",
"serviceEndpoint": f"{DID_PREFIX}:Q4zqM7aXqm7gDQkUVLng9h",
}
],
}
Expand Down Expand Up @@ -107,36 +108,36 @@ def test_embedded_authkey(self):
# One authn key embedded, all possible refs canonical
dd_in = {
"@context": "https://w3id.org/did/v1",
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKey": [
{
"id": "3",
"type": "RsaVerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyPem": "-----BEGIN PUBLIC X...",
},
{
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL#4",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#4",
"type": "RsaVerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyPem": "-----BEGIN PUBLIC 9...",
},
],
"authentication": [
{
"type": "RsaSignatureAuthentication2018",
"publicKey": "did:sov:LjgpST2rjsoxYegQDRm7EL#4",
"publicKey": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#4",
},
{
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL#6",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#6",
"type": "RsaVerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyPem": "-----BEGIN PUBLIC A...",
},
],
"service": [
{
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL;0",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL;0",
"type": "Agency",
"serviceEndpoint": "https://www.von.ca",
}
Expand All @@ -154,36 +155,36 @@ def test_reference_authkey(self):
# All references canonical where possible; one authn key embedded and one by reference
dd_in = {
"@context": "https://w3id.org/did/v1",
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKey": [
{
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL#3",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#3",
"type": "RsaVerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyPem": "-----BEGIN PUBLIC X...",
},
{
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL#4",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#4",
"type": "RsaVerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyPem": "-----BEGIN PUBLIC 9...",
},
],
"authentication": [
{
"type": "RsaSignatureAuthentication2018",
"publicKey": "did:sov:LjgpST2rjsoxYegQDRm7EL#4",
"publicKey": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#4",
},
{
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL#6",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#6",
"type": "RsaVerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyPem": "-----BEGIN PUBLIC A...",
},
],
"service": [
{
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL;0",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL;0",
"type": "DidMessaging",
"serviceEndpoint": "https://www.von.ca",
}
Expand Down Expand Up @@ -283,9 +284,9 @@ def test_minimal_explicit(self):
"publicKeyHex": "02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71",
},
{
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL#keys-4",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#keys-4",
"type": "RsaVerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyPem": "-----BEGIN PUBLIC A...",
},
],
Expand All @@ -295,17 +296,17 @@ def test_minimal_explicit(self):
"type": "DidMessaging",
"priority": 0,
"recipientKeys": ["~ZZZZZZZZZZZZZZZZ"],
"serviceEndpoint": "did:sov:LjgpST2rjsoxYegQDRm7EL;1",
"serviceEndpoint": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL;1",
},
{
"id": "1",
"type": "one",
"priority": 1,
"recipientKeys": [
"~XXXXXXXXXXXXXXXX",
"did:sov:LjgpST2rjsoxYegQDRm7EL#keys-1",
f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#keys-1",
],
"routingKeys": ["did:sov:LjgpST2rjsoxYegQDRm7EL#keys-4"],
"routingKeys": [f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#keys-4"],
"serviceEndpoint": "LjgpST2rjsoxYegQDRm7EL;2",
},
{
Expand All @@ -314,9 +315,9 @@ def test_minimal_explicit(self):
"priority": 2,
"recipientKeys": [
"~XXXXXXXXXXXXXXXX",
"did:sov:LjgpST2rjsoxYegQDRm7EL#keys-1",
f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#keys-1",
],
"routingKeys": ["did:sov:LjgpST2rjsoxYegQDRm7EL#keys-4"],
"routingKeys": [f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#keys-4"],
"serviceEndpoint": "https://www.two.ca/two",
},
],
Expand All @@ -332,13 +333,13 @@ def test_minimal_explicit(self):
)
assert (
"routingKeys"
not in dd.service["did:sov:LjgpST2rjsoxYegQDRm7EL;indy"].to_dict()
not in dd.service[f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL;indy"].to_dict()
)
assert all(
len(dd.service[k].to_dict()["routingKeys"]) == 1
for k in (
"did:sov:LjgpST2rjsoxYegQDRm7EL;1",
"did:sov:LjgpST2rjsoxYegQDRm7EL;2",
f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL;1",
f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL;2",
)
)

Expand Down Expand Up @@ -385,7 +386,7 @@ def test_missing_recipkey(self):
"id": "LjgpST2rjsoxYegQDRm7EL;indy",
"type": "DidMessaging",
"priority": 1,
"recipientKeys": ["did:sov:LjgpST2rjsoxYegQDRm7EL#keys-3"],
"recipientKeys": [f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL#keys-3"],
"serviceEndpoint": "https://www.von.ca",
}
],
Expand All @@ -399,12 +400,12 @@ def test_w3c_minimal(self):
# Minimal as per W3C Example 2, draft 0.12
dd_in = {
"@context": "https://w3id.org/did/v1",
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"authentication": [
{
"id": "LjgpST2rjsoxYegQDRm7EL#keys-1",
"type": "Ed25519VerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyBase58": "~XXXXXXXXXXXXXXXX",
}
],
Expand Down Expand Up @@ -432,7 +433,7 @@ def test_no_ident(self):
"authentication": [
{
"type": "Ed25519VerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyBase58": "~XXXXXXXXXXXXXXXX",
}
],
Expand All @@ -456,7 +457,7 @@ def test_canon_did(self):
canon_ref("not-a-DID", ref=valid_did, delimiter="#")

with self.assertRaises(ValueError):
canon_ref(valid_did, ref="did:sov:not-a-DID", delimiter="#")
canon_ref(valid_did, ref=f"{DID_PREFIX}:not-a-DID", delimiter="#")

urlref = (
"https://www.clafouti-quasar.ca:8443/supply-management/fruit/index.html"
Expand All @@ -467,12 +468,12 @@ def test_canon_did(self):
def test_pubkey_type(self):
dd_in = {
"@context": "https://w3id.org/did/v1",
"id": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"id": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"authentication": [
{
"id": "LjgpST2rjsoxYegQDRm7EL#keys-1",
"type": "Ed25519VerificationKey2018",
"controller": "did:sov:LjgpST2rjsoxYegQDRm7EL",
"controller": f"{DID_PREFIX}:LjgpST2rjsoxYegQDRm7EL",
"publicKeyBase58": "~XXXXXXXXXXXXXXXX",
}
],
Expand Down
16 changes: 9 additions & 7 deletions aries_cloudagent/connections/models/diddoc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from base58 import b58decode
from urllib.parse import urlparse

from aries_cloudagent.messaging.valid import DID_PREFIX


def resource(ref: str, delimiter: str = None) -> str:
"""
Expand All @@ -40,7 +42,7 @@ def resource(ref: str, delimiter: str = None) -> str:

def canon_did(uri: str) -> str:
"""
Convert a URI into a DID if need be, left-stripping 'did:sov:' if present.
Convert a URI into a DID if need be, left-stripping 'did:ssw:' if present.
Args:
uri: input URI or DID
Expand All @@ -53,7 +55,7 @@ def canon_did(uri: str) -> str:
if ok_did(uri):
return uri

if uri.startswith("did:sov:"):
if uri.startswith(f"{DID_PREFIX}:"):
rv = uri[8:]
if ok_did(rv):
return rv
Expand All @@ -78,14 +80,14 @@ def canon_ref(did: str, ref: str, delimiter: str = None):
raise ValueError("Bad DID {} cannot act as DID document identifier".format(did))

if ok_did(ref): # e.g., LjgpST2rjsoxYegQDRm7EL
return "did:sov:{}".format(did)
return "{}:{}".format(DID_PREFIX, did)

if ok_did(resource(ref, delimiter)): # e.g., LjgpST2rjsoxYegQDRm7EL#keys-1
return "did:sov:{}".format(ref)
return "{}:{}".format(DID_PREFIX, ref)

if ref.startswith(
"did:sov:"
): # e.g., did:sov:LjgpST2rjsoxYegQDRm7EL, did:sov:LjgpST2rjsoxYegQDRm7EL#3
f"{DID_PREFIX}:"
): # e.g., did:ssw:LjgpST2rjsoxYegQDRm7EL, did:ssw:LjgpST2rjsoxYegQDRm7EL#3
rv = ref[8:]
if ok_did(resource(rv, delimiter)):
return ref
Expand All @@ -94,7 +96,7 @@ def canon_ref(did: str, ref: str, delimiter: str = None):
if urlparse(ref).scheme: # e.g., https://example.com/messages/8377464
return ref

return "did:sov:{}{}{}".format(did, delimiter if delimiter else "#", ref) # e.g., 3
return "{}:{}{}{}".format(DID_PREFIX, did, delimiter if delimiter else "#", ref) # e.g., 3


def ok_did(token: str) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/protocols/connections/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def create_invitation(
{
"@type": "https://didcomm.org/connections/1.0/invitation",
"label": "Alice",
"did": "did:sov:QmWbsNYhMrjHiqZDTUTEJs"
"did": "did:ssw:QmWbsNYhMrjHiqZDTUTEJs"
}
Or, in the case of a peer DID:
Expand Down

0 comments on commit c9a362c

Please sign in to comment.