Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
feat: Add support for AlsoKnownAs to Orb VDR (#276)
Browse files Browse the repository at this point in the history
Add support for AlsoKnownAs to Orb VDR

Closes #274

Signed-off-by: Sandra Vrtikapa <sandra.vrtikapa@securekey.com>
  • Loading branch information
sandrask authored Jul 28, 2022
1 parent dc0c08c commit 0a8903e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
4 changes: 2 additions & 2 deletions component/vdr/orb/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ go 1.17
require (
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/hyperledger/aries-framework-go v0.1.9-0.20220725145110-78317f6d44d8
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2.0.20220728150434-dc0c08cf45dc
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220428211718-66cc046674a1
github.com/opentracing/opentracing-go v1.1.0
github.com/piprate/json-gold v0.4.1
github.com/stretchr/testify v1.7.2
github.com/trustbloc/orb v1.0.0-rc2.0.20220722161937-49dd83f0166a
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220721143952-577302c8aca8
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220727134606-0164affe3d8f
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd
)

Expand Down
9 changes: 5 additions & 4 deletions component/vdr/orb/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -783,15 +783,16 @@ github.com/hyperledger/aries-framework-go v0.1.8-0.20220322085443-50e8f9bd208b/g
github.com/hyperledger/aries-framework-go v0.1.8/go.mod h1:7ilurt17sjWruVIBxZSrwn8qUbROq8LXYYY+O7dNxIM=
github.com/hyperledger/aries-framework-go v0.1.9-0.20220526205258-18d510d84955/go.mod h1:7ilurt17sjWruVIBxZSrwn8qUbROq8LXYYY+O7dNxIM=
github.com/hyperledger/aries-framework-go v0.1.9-0.20220602200413-1135b419c644/go.mod h1:7ilurt17sjWruVIBxZSrwn8qUbROq8LXYYY+O7dNxIM=
github.com/hyperledger/aries-framework-go v0.1.9-0.20220714220520-d96b693387a7/go.mod h1:NHOXYxR3jOtO6Uf+WGRreOSrutWSzbIf6g4lmEtaQuU=
github.com/hyperledger/aries-framework-go v0.1.9-0.20220725145110-78317f6d44d8 h1:g2IIFXFfs8CxnRpiB7z73x9NX8UM+paCzLcervMjBOs=
github.com/hyperledger/aries-framework-go v0.1.9-0.20220725145110-78317f6d44d8/go.mod h1:wwKd/zpTcv2NuMSShCGka8vRgycSIO6KOkjSsyi5+Uc=
github.com/hyperledger/aries-framework-go-ext/component/storage/couchdb v0.0.0-20220428163625-96d8261511e1/go.mod h1:q8qjsQpYo7AYG0pqQg1zgEoIVc+Hrpf5S0WciiwPDQA=
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220428163625-96d8261511e1/go.mod h1:rO6A/9mCSo2pPQqMVmhgGvOkFX/7FVLgoanqazkiKSc=
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220615170242-cda5092b4faf h1:F12zbOSRsye3IWK3Zb6prgrqQQFYnz5zjGSCh9pfYzk=
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220615170242-cda5092b4faf/go.mod h1:GDANCnJONcCqBvv6QgKuk5Y2FWHyD/Hu26kyc7NTyfY=
github.com/hyperledger/aries-framework-go-ext/component/storage/postgresql v0.0.0-20220428163625-96d8261511e1/go.mod h1:35iXtsPH1PImVDq8xFHETtrcvyHhJXKcvf82YJ6/z4k=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2 h1:J/5dDlk+s6EJI5zXREnMY1w2Xg43rZNbkKP1qjvAmFA=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2/go.mod h1:e8aQHQRjTfZpB7bsEBrSKyP0LFAsgPs/AzCKe82nQyo=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2.0.20220728150434-dc0c08cf45dc h1:uAI9v49r398ILOAIKcpgftAE46PRznRI/Y+RzTqqbmY=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2.0.20220728150434-dc0c08cf45dc/go.mod h1:FtNOe/ITYs0yixH03SLOYjo6JRf7Xc3vkht0aV6vpt0=
github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20210520055214-ae429bb89bf7/go.mod h1:7D+Y5J9cIsUrMGFAsIED+3bAPNjxp6ggXo0/kT5N6BI=
github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20210820175050-dcc7a225178d/go.mod h1:i40JkMHCh9cHHxSc1SYznO3xDH6ly5CE0B3vPYZVeWI=
github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20220308060532-714cd5c18552/go.mod h1:eIac5lubCy3tw6D0sTluM5U6Bw3inBwUfjX17o2U7PE=
Expand Down Expand Up @@ -1429,9 +1430,9 @@ github.com/trustbloc/edge-core v0.1.8/go.mod h1:gfoyG/xquRXyHkww0ldM2jwOTuKKZpHY
github.com/trustbloc/kms v0.1.9-0.20220526151939-d46e46e8f7e1/go.mod h1:a6XvGLZgwVqBAt47550cQeRKm04X2Nn1M8DE0PVb0XA=
github.com/trustbloc/orb v1.0.0-rc2.0.20220722161937-49dd83f0166a h1:p0Kv8aWiaAXR1HfAQvkqAi6p0ltRQA/fd/pYdBln8D4=
github.com/trustbloc/orb v1.0.0-rc2.0.20220722161937-49dd83f0166a/go.mod h1:183OtyfZ0okmvqV5dtL5UZgFgrlpyKQoiJjKht0Pcls=
github.com/trustbloc/sidetree-core-go v1.0.0-rc2/go.mod h1:SYCYxrsviTcRoUCoM6VosXF+sqWkKpk8C1dqD0doRYQ=
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220721143952-577302c8aca8 h1:mtAVT5A3C5233Nfevgwx1q8eJQ9yQw/QOlcSx2vd6TQ=
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220721143952-577302c8aca8/go.mod h1:SYCYxrsviTcRoUCoM6VosXF+sqWkKpk8C1dqD0doRYQ=
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220727134606-0164affe3d8f h1:nY0jUz8M6uOqG38SBS1aZGyocCYHt7OxxTEqj199Z8g=
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220727134606-0164affe3d8f/go.mod h1:SYCYxrsviTcRoUCoM6VosXF+sqWkKpk8C1dqD0doRYQ=
github.com/trustbloc/vct v1.0.0-rc2 h1:iuoG3rLC3V0kuwGnBmnzVPGH6xAxWzpozgkW5T5Qlac=
github.com/trustbloc/vct v1.0.0-rc2/go.mod h1:k45HahHV0lr2h8ldzITXLjcWpTgXzRE8WL1avfC95po=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
Expand Down
48 changes: 48 additions & 0 deletions component/vdr/orb/vdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ func (v *VDR) Create(did *docdid.Doc,
}
}

// get also known as
for i := range did.AlsoKnownAs {
createOpt = append(createOpt, create.WithAlsoKnownAs(did.AlsoKnownAs[i]))
}

// get services
for i := range did.Service {
createOpt = append(createOpt, create.WithService(&did.Service[i]))
Expand Down Expand Up @@ -638,6 +643,10 @@ func (v *VDR) Update(didDoc *docdid.Doc, opts ...vdrapi.DIDMethodOption) error {

updateOpt = append(updateOpt, updatedPKKeysID...)

updatedAlsoKnownAsOpts := getUpdatedAlsoKnownAs(docResolution.DIDDocument.AlsoKnownAs, didDoc.AlsoKnownAs)

updateOpt = append(updateOpt, updatedAlsoKnownAsOpts...)

updateOpt = append(updateOpt, update.WithSidetreeEndpoint(func() ([]string, error) {
var endpoint *models.Endpoint

Expand Down Expand Up @@ -712,6 +721,11 @@ func (v *VDR) recover(didDoc *docdid.Doc, getEndpoints func() ([]string, error),
recoveryOpt = append(recoveryOpt, recovery.WithPublicKey(pks[k].publicKey))
}

// get also known as
for i := range didDoc.AlsoKnownAs {
recoveryOpt = append(recoveryOpt, recovery.WithAlsoKnownAs(didDoc.AlsoKnownAs[i]))
}

// get keys
nextUpdatePublicKey, err := v.keyRetriever.GetNextUpdatePublicKey(didDoc.ID, recoveryCommitment)
if err != nil {
Expand Down Expand Up @@ -904,6 +918,40 @@ func getRemovedSvcKeysID(currentService, updatedService []docdid.Service) []upda
return updateOpt
}

func getUpdatedAlsoKnownAs(current, updated []string) []update.Option {
var updateOpt []update.Option

currentMap := sliceToMap(current)
updatedMap := sliceToMap(updated)

for _, val := range updated {
_, ok := currentMap[val]
if !ok {
// new URI - append it to add URIs
updateOpt = append(updateOpt, update.WithAddAlsoKnownAs(val))
}
}

for _, val := range current {
_, ok := updatedMap[val]
if !ok {
// missing URI - append it to remove URIs
updateOpt = append(updateOpt, update.WithRemoveAlsoKnownAs(val))
}
}

return updateOpt
}

func sliceToMap(values []string) map[string]bool {
m := make(map[string]bool)
for _, value := range values {
m[value] = true
}

return m
}

func getUpdatedPKKeysID(currentDID, updatedDID *docdid.Doc) ([]update.Option, error) { //nolint:gocognit,gocyclo
var updateOpt []update.Option

Expand Down
4 changes: 4 additions & 0 deletions component/vdr/orb/vdr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const validDocResolutionCachedUpdate = `
const validDoc = `{
"@context": ["https://w3id.org/did/v1"],
"id": "did:example:21tDAKCERh95uGgKbJNHYp",
"alsoKnownAs": ["https://myblog.example/"],
"verificationMethod": [
{
"id": "did:example:123456789abcdefghi#keys-1",
Expand Down Expand Up @@ -180,6 +181,7 @@ func TestVDRI_Create(t *testing.T) {
Service: []did.Service{
{ID: "svc"},
},
AlsoKnownAs: []string{"https://myblog.example/"},
Authentication: []did.Verification{
*ver,
*ver2,
Expand Down Expand Up @@ -492,6 +494,7 @@ func TestVDRI_Update(t *testing.T) {
ver1 := did.NewReferencedVerification(vm1, did.Authentication)

err = v.Update(&did.Doc{
AlsoKnownAs: []string{"https://other-blog.example/"},
Service: []did.Service{
{ID: "svc"},
},
Expand Down Expand Up @@ -756,6 +759,7 @@ func TestVDRI_Recover(t *testing.T) {
ver := did.NewReferencedVerification(vm, did.Authentication)

err = v.Update(&did.Doc{
AlsoKnownAs: []string{"https://recover.example/"},
Service: []did.Service{
{ID: "svc"},
},
Expand Down
4 changes: 2 additions & 2 deletions test/bdd/vdr/orb/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ require (
github.com/fsouza/go-dockerclient v1.7.4
github.com/hyperledger/aries-framework-go v0.1.9-0.20220725145110-78317f6d44d8
github.com/hyperledger/aries-framework-go-ext/component/vdr/orb v0.0.0
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2.0.20220728150434-dc0c08cf45dc
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220428211718-66cc046674a1
github.com/hyperledger/aries-framework-go/spi v0.0.0-20220614152730-3d817acfa48b
github.com/trustbloc/edge-core v0.1.8
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220721143952-577302c8aca8
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220727134606-0164affe3d8f
)

require (
Expand Down
9 changes: 5 additions & 4 deletions test/bdd/vdr/orb/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -961,15 +961,16 @@ github.com/hyperledger/aries-framework-go v0.1.8-0.20220322085443-50e8f9bd208b/g
github.com/hyperledger/aries-framework-go v0.1.8/go.mod h1:7ilurt17sjWruVIBxZSrwn8qUbROq8LXYYY+O7dNxIM=
github.com/hyperledger/aries-framework-go v0.1.9-0.20220526205258-18d510d84955/go.mod h1:7ilurt17sjWruVIBxZSrwn8qUbROq8LXYYY+O7dNxIM=
github.com/hyperledger/aries-framework-go v0.1.9-0.20220602200413-1135b419c644/go.mod h1:7ilurt17sjWruVIBxZSrwn8qUbROq8LXYYY+O7dNxIM=
github.com/hyperledger/aries-framework-go v0.1.9-0.20220714220520-d96b693387a7/go.mod h1:NHOXYxR3jOtO6Uf+WGRreOSrutWSzbIf6g4lmEtaQuU=
github.com/hyperledger/aries-framework-go v0.1.9-0.20220725145110-78317f6d44d8 h1:g2IIFXFfs8CxnRpiB7z73x9NX8UM+paCzLcervMjBOs=
github.com/hyperledger/aries-framework-go v0.1.9-0.20220725145110-78317f6d44d8/go.mod h1:wwKd/zpTcv2NuMSShCGka8vRgycSIO6KOkjSsyi5+Uc=
github.com/hyperledger/aries-framework-go-ext/component/storage/couchdb v0.0.0-20220428163625-96d8261511e1/go.mod h1:q8qjsQpYo7AYG0pqQg1zgEoIVc+Hrpf5S0WciiwPDQA=
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220428163625-96d8261511e1/go.mod h1:rO6A/9mCSo2pPQqMVmhgGvOkFX/7FVLgoanqazkiKSc=
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220615170242-cda5092b4faf h1:F12zbOSRsye3IWK3Zb6prgrqQQFYnz5zjGSCh9pfYzk=
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220615170242-cda5092b4faf/go.mod h1:GDANCnJONcCqBvv6QgKuk5Y2FWHyD/Hu26kyc7NTyfY=
github.com/hyperledger/aries-framework-go-ext/component/storage/postgresql v0.0.0-20220428163625-96d8261511e1/go.mod h1:35iXtsPH1PImVDq8xFHETtrcvyHhJXKcvf82YJ6/z4k=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2 h1:J/5dDlk+s6EJI5zXREnMY1w2Xg43rZNbkKP1qjvAmFA=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2/go.mod h1:e8aQHQRjTfZpB7bsEBrSKyP0LFAsgPs/AzCKe82nQyo=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2.0.20220728150434-dc0c08cf45dc h1:uAI9v49r398ILOAIKcpgftAE46PRznRI/Y+RzTqqbmY=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc2.0.20220728150434-dc0c08cf45dc/go.mod h1:FtNOe/ITYs0yixH03SLOYjo6JRf7Xc3vkht0aV6vpt0=
github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20210520055214-ae429bb89bf7/go.mod h1:7D+Y5J9cIsUrMGFAsIED+3bAPNjxp6ggXo0/kT5N6BI=
github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20210820175050-dcc7a225178d/go.mod h1:i40JkMHCh9cHHxSc1SYznO3xDH6ly5CE0B3vPYZVeWI=
github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20220308060532-714cd5c18552/go.mod h1:eIac5lubCy3tw6D0sTluM5U6Bw3inBwUfjX17o2U7PE=
Expand Down Expand Up @@ -1677,9 +1678,9 @@ github.com/trustbloc/edge-core v0.1.8/go.mod h1:gfoyG/xquRXyHkww0ldM2jwOTuKKZpHY
github.com/trustbloc/kms v0.1.9-0.20220526151939-d46e46e8f7e1/go.mod h1:a6XvGLZgwVqBAt47550cQeRKm04X2Nn1M8DE0PVb0XA=
github.com/trustbloc/orb v1.0.0-rc2.0.20220722161937-49dd83f0166a h1:p0Kv8aWiaAXR1HfAQvkqAi6p0ltRQA/fd/pYdBln8D4=
github.com/trustbloc/orb v1.0.0-rc2.0.20220722161937-49dd83f0166a/go.mod h1:183OtyfZ0okmvqV5dtL5UZgFgrlpyKQoiJjKht0Pcls=
github.com/trustbloc/sidetree-core-go v1.0.0-rc2/go.mod h1:SYCYxrsviTcRoUCoM6VosXF+sqWkKpk8C1dqD0doRYQ=
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220721143952-577302c8aca8 h1:mtAVT5A3C5233Nfevgwx1q8eJQ9yQw/QOlcSx2vd6TQ=
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220721143952-577302c8aca8/go.mod h1:SYCYxrsviTcRoUCoM6VosXF+sqWkKpk8C1dqD0doRYQ=
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220727134606-0164affe3d8f h1:nY0jUz8M6uOqG38SBS1aZGyocCYHt7OxxTEqj199Z8g=
github.com/trustbloc/sidetree-core-go v1.0.0-rc2.0.20220727134606-0164affe3d8f/go.mod h1:SYCYxrsviTcRoUCoM6VosXF+sqWkKpk8C1dqD0doRYQ=
github.com/trustbloc/vct v1.0.0-rc2 h1:iuoG3rLC3V0kuwGnBmnzVPGH6xAxWzpozgkW5T5Qlac=
github.com/trustbloc/vct v1.0.0-rc2/go.mod h1:k45HahHV0lr2h8ldzITXLjcWpTgXzRE8WL1avfC95po=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
Expand Down

0 comments on commit 0a8903e

Please sign in to comment.