Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement flexibility on resolver to cycle between methods using ? to transform keys [DEV-2208] #137

Merged
merged 52 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3aa4ffa
Add handling for only did queries and small refactoring
Apr 3, 2023
0e25625
Makes linter happy
Apr 4, 2023
df549e5
Add unit tests
Apr 6, 2023
7a373ee
Add basic implementation for resource queries
Apr 9, 2023
2fe3edb
Small refactoring
Apr 9, 2023
2f91293
Add resourceVersion and handler for it
Apr 9, 2023
aaff569
Makes Linter happy
Apr 9, 2023
0a7793a
Makes linter happy
Apr 9, 2023
7d07b7f
Small refactoring
Apr 10, 2023
b40cdf7
Merge remote-tracking branch 'origin/develop' into DEV-2351
Apr 11, 2023
ce6b42c
Merge remote-tracking branch 'origin/develop' into DEV-2351
Apr 11, 2023
94385c6
Fix unit tests for queries
Apr 12, 2023
c8ba3f9
MAkes linter happy and fix integration tests
Apr 12, 2023
795fa06
Add more integration tests for queries
Apr 12, 2023
09d3d76
Fixed:
Apr 13, 2023
2fb0a75
Add common functions and constants for transforming
abdulla-ashurov Apr 14, 2023
6f1cc5c
Add implementation for supporting transformKey
abdulla-ashurov Apr 14, 2023
aea4372
Fix golangci-lint mistakes.
abdulla-ashurov Apr 14, 2023
2e6b486
Add correct commands for running unit and
abdulla-ashurov Apr 14, 2023
1c47c91
Refactor code and fix typo mistakes.
abdulla-ashurov Apr 17, 2023
7450210
Changed did doc implementation due to the latest changes in doc
Apr 17, 2023
bf52be5
Makes linter happy
Apr 17, 2023
b7509d8
Add payload files for transformKey query results.
abdulla-ashurov Apr 17, 2023
79e6526
Add positive integration tests for getting DIDDoc
abdulla-ashurov Apr 17, 2023
e6be49a
Add integration tests runner for running
abdulla-ashurov Apr 17, 2023
492237c
Merge branch 'DEV-2351' into DEV-2208-transform-key
abdulla-ashurov Apr 17, 2023
3b095b9
Update incorrect last merge.
abdulla-ashurov Apr 17, 2023
ef5cdc1
Fix problem with an incorrect concatenation logic
abdulla-ashurov Apr 18, 2023
894ab73
Small validation and refactorings
Apr 18, 2023
81d10ef
Add more positive integration tests.
abdulla-ashurov Apr 18, 2023
bac74ba
Add checksum handling and small improvements
Apr 18, 2023
bac682b
Add more static validation for transformKey query.
abdulla-ashurov Apr 19, 2023
6e1caa6
Add negative integration tests for testing
abdulla-ashurov Apr 19, 2023
4787afe
Add validation for a combination of transformKey &
abdulla-ashurov Apr 19, 2023
6ab9b24
Add unit tests for testing transformKey query.
abdulla-ashurov Apr 19, 2023
5bd1f2c
Fix RequestURI parameter displaying
Apr 19, 2023
597e594
Makes linter happy
Apr 19, 2023
a57e169
Merge branch 'DEV-2351' into DEV-2208-transform-key
abdulla-ashurov Apr 19, 2023
a88dcd1
Fix problem with go-releaser:
abdulla-ashurov Apr 19, 2023
2a24208
Refactor code and integration tests.
abdulla-ashurov Apr 19, 2023
a610dd3
Update transformKey query payloads.
abdulla-ashurov Apr 19, 2023
36e543f
Add integration tests for testing transformKey
abdulla-ashurov Apr 19, 2023
10cfabf
Rename file from "transform_key_suite_test.go" to
abdulla-ashurov Apr 19, 2023
0010cf3
Remove debug println.
abdulla-ashurov Apr 19, 2023
cb77d9f
Update did/versions integration tests payloads.
abdulla-ashurov Apr 19, 2023
87f1bb0
Fix problem with go-releaser.
abdulla-ashurov Apr 19, 2023
a580790
Refactor code and unit/integration tests.
abdulla-ashurov Apr 19, 2023
6812d7d
Set correct time format in unit/integration tests.
abdulla-ashurov Apr 19, 2023
ec2f4fa
Set correct time format in unit/integration tests.
abdulla-ashurov Apr 19, 2023
523952b
Merge branch 'develop' into DEV-2208-transform-key
abdulla-ashurov Apr 21, 2023
ef74560
Merge branch 'develop' into DEV-2208-transform-key
Apr 21, 2023
cbe1934
Fix the review comments.
abdulla-ashurov Apr 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ tidy:
###############################################################################

unit-tests:
go test -v ./...
cd tests/unit && ginkgo -r --tags unit --race
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved

integration-tests:
cd tests/integration/rest && ginkgo -r --tags integration --race

lint:
golangci-lint run --config .github/linters/.golangci.yaml
Expand Down
3 changes: 1 addition & 2 deletions docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/go-resty/resty/v2 v2.7.0
github.com/google/uuid v1.3.0
github.com/labstack/echo/v4 v4.10.2
github.com/lestrrat-go/jwx v1.2.25
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multibase v0.2.0
github.com/onsi/ginkgo/v2 v2.9.2
Expand All @@ -24,13 +25,15 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
github.com/cosmos/cosmos-sdk/api v0.1.0 // indirect
github.com/cosmos/gogoproto v1.4.6 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.0-20210816181553-5444fa50b93d // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand All @@ -39,6 +42,11 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.0 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/iter v1.0.1 // indirect
github.com/lestrrat-go/option v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -47,6 +55,7 @@ require (
github.com/multiformats/go-base32 v0.0.3 // indirect
github.com/multiformats/go-base36 v0.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand Down
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.0-20210816181553-5444fa50b93d h1:1iy2qD6JEhHKKhUOA9IWs7mjco7lnw2qx8FsRI2wirE=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.0-20210816181553-5444fa50b93d/go.mod h1:tmAIfUFEirG/Y8jhZ9M+h36obRZAk/1fcSpXwAVlfqE=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -92,6 +95,8 @@ github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPr
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM=
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
Expand Down Expand Up @@ -183,6 +188,18 @@ github.com/labstack/echo/v4 v4.10.2 h1:n1jAhnq/elIFTHr1EYpiYtyKgx4RW9ccVgkqByZaN
github.com/labstack/echo/v4 v4.10.2/go.mod h1:OEyqf2//K1DFdE57vw2DRgWY0M7s65IVQO2FzvI4J5k=
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/lestrrat-go/backoff/v2 v2.0.8 h1:oNb5E5isby2kiro9AgdHLv5N5tint1AnDVVf2E2un5A=
github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y=
github.com/lestrrat-go/blackmagic v1.0.0 h1:XzdxDbuQTz0RZZEmdU7cnQxUtFUzgCSPq8RCz4BxIi4=
github.com/lestrrat-go/blackmagic v1.0.0/go.mod h1:TNgH//0vYSs8VXDCfkZLgIrVTTXQELZffUV0tz3MtdQ=
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E=
github.com/lestrrat-go/iter v1.0.1 h1:q8faalr2dY6o8bV45uwrxq12bRa1ezKrB6oM9FUgN4A=
github.com/lestrrat-go/iter v1.0.1/go.mod h1:zIdgO1mRKhn8l9vrZJZz9TUMMFbQbLeTsbqPDrJ/OJc=
github.com/lestrrat-go/jwx v1.2.25 h1:tAx93jN2SdPvFn08fHNAhqFJazn5mBBOB8Zli0g0otA=
github.com/lestrrat-go/jwx v1.2.25/go.mod h1:zoNuZymNl5lgdcu6P7K6ie2QRll5HVfF4xwxBBK1NxY=
github.com/lestrrat-go/option v1.0.0 h1:WqAWL8kh8VcSoD6xjSH34/1m8yxluXQbDeKNfvFeEO4=
github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down Expand Up @@ -215,6 +232,7 @@ github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -280,6 +298,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -350,6 +369,7 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down
15 changes: 13 additions & 2 deletions services/diddoc/diddoc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ func (dd *QueryDIDDocRequestService) SpecificValidation(c services.ResolverConte

versionId := dd.GetQueryParam(types.VersionId)
versionTime := dd.GetQueryParam(types.VersionTime)
transformKey := types.TransformKeyType(dd.GetQueryParam(types.TransformKey))
service := dd.GetQueryParam(types.ServiceQ)
relativeRef := dd.GetQueryParam(types.RelativeRef)
resourceId := dd.GetQueryParam(types.ResourceId)
resourceVersionTime := dd.GetQueryParam(types.ResourceVersionTime)
metadata := dd.GetQueryParam(types.Metadata)
resourceMetadata := dd.GetQueryParam(types.ResourceMetadata)

if string(transformKey) != "" && (!transformKey.IsSupported() || !types.IsSupportedWithCombinationTransformKeyQuery(dd.Queries)) {
return types.NewRepresentationNotSupportedError(dd.Did, dd.GetContentType(), nil, dd.IsDereferencing)
}

// relativeRef should be only with service parameter also
if relativeRef != "" && service == "" {
return types.NewRepresentationNotSupportedError(dd.GetDid(), dd.GetContentType(), nil, dd.IsDereferencing)
Expand Down Expand Up @@ -165,12 +170,13 @@ func (dd *QueryDIDDocRequestService) RegisterDidDocQueryHandlers(startHandler qu
// or
// - versionIdHandler
// After that we can find for service field if it's set.
// VersionIdHandler -> VersionTimeHandler -> DidDocResolveHandler -> DidDocMetadataHandler -> ServiceHandler -> RelativeRefHandler
// VersionIdHandler -> VersionTimeHandler -> DidDocResolveHandler -> TransformKeyHandler -> DidDocMetadataHandler -> ServiceHandler -> RelativeRefHandler
relativeRefHandler := diddocQueries.RelativeRefHandler{}
serviceHandler := diddocQueries.ServiceHandler{}
versionIdHandler := diddocQueries.VersionIdHandler{}
versionTimeHandler := diddocQueries.VersionTimeHandler{}
didDocResolveHandler := diddocQueries.DidDocResolveHandler{}
transformKeyHandler := diddocQueries.TransformKeyHandler{}
didDocMetadataHandler := diddocQueries.DidDocMetadataHandler{}

err := startHandler.SetNext(c, &versionIdHandler)
Expand All @@ -188,7 +194,12 @@ func (dd *QueryDIDDocRequestService) RegisterDidDocQueryHandlers(startHandler qu
return nil, err
}

err = didDocResolveHandler.SetNext(c, &didDocMetadataHandler)
err = didDocResolveHandler.SetNext(c, &transformKeyHandler)
if err != nil {
return nil, err
}

err = transformKeyHandler.SetNext(c, &didDocMetadataHandler)
if err != nil {
return nil, err
}
Expand Down
42 changes: 42 additions & 0 deletions services/diddoc/queries/diddoc/did_query_transform_key_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package diddoc

import (
"github.com/cheqd/did-resolver/services"
"github.com/cheqd/did-resolver/services/diddoc/queries"
"github.com/cheqd/did-resolver/types"
)

type TransformKeyHandler struct {
queries.BaseQueryHandler
}

func (t *TransformKeyHandler) Handle(c services.ResolverContext, service services.RequestServiceI, response types.ResolutionResultI) (types.ResolutionResultI, error) {
// Get Params
transformKey := types.TransformKeyType(service.GetQueryParam(types.TransformKey))

// If transformKey is empty, call the next handler. We don't need to handle it here
if transformKey == "" {
return t.Continue(c, service, response)
}

if !transformKey.IsSupported() {
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
return nil, types.NewRepresentationNotSupportedError(service.GetDid(), types.DIDJSONLD, nil, t.IsDereferencing)
}

// We expect here only DidResolution
didResolution, ok := response.(*types.DidResolution)
if !ok {
return nil, types.NewInternalError(service.GetDid(), types.DIDJSONLD, nil, t.IsDereferencing)
}

for i, vMethod := range didResolution.Did.VerificationMethod {
result, err := transformVerificationMethodKey(vMethod, transformKey)
if err != nil {
return nil, err
}
didResolution.Did.VerificationMethod[i] = result
}

// Call the next handler
return t.Continue(c, service, didResolution)
}
136 changes: 136 additions & 0 deletions services/diddoc/queries/diddoc/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package diddoc

import (
"fmt"

"github.com/cheqd/did-resolver/types"
"github.com/cheqd/did-resolver/utils"
)

func transformKeyEd25519VerificationKey2018ToEd25519VerificationKey2020(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyMultibase, err := utils.Ed25519VerificationKey2018ToEd25519VerificationKey2020(verificationMethod.PublicKeyBase58)
if err != nil {
return verificationMethod, err
}

verificationMethod.PublicKeyBase58 = ""
verificationMethod.Type = string(types.Ed25519VerificationKey2020)
verificationMethod.PublicKeyMultibase = publicKeyMultibase

return verificationMethod, nil
}

func transformKeyEd25519VerificationKey2018ToJSONWebKey2020(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyJwk, err := utils.Ed25519VerificationKey2018ToJSONWebKey2020(verificationMethod.PublicKeyBase58)
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return verificationMethod, err
}

verificationMethod.PublicKeyBase58 = ""
verificationMethod.Type = string(types.JsonWebKey2020)
verificationMethod.PublicKeyJwk = publicKeyJwk

return verificationMethod, nil
}

func transformKeyEd25519VerificationKey2020ToEd25519VerificationKey2018(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyBase58, err := utils.Ed25519VerificationKey2020ToEd25519VerificationKey2018(verificationMethod.PublicKeyMultibase)
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return verificationMethod, err
}

verificationMethod.PublicKeyMultibase = ""
verificationMethod.Type = string(types.Ed25519VerificationKey2018)
verificationMethod.PublicKeyBase58 = publicKeyBase58

return verificationMethod, nil
}

func transformKeyEd25519VerificationKey2020ToJSONWebKey2020(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyJwk, err := utils.Ed25519VerificationKey2020ToJSONWebKey2020(verificationMethod.PublicKeyMultibase)
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return verificationMethod, err
}

verificationMethod.PublicKeyMultibase = ""
verificationMethod.Type = string(types.JsonWebKey2020)
verificationMethod.PublicKeyJwk = publicKeyJwk

return verificationMethod, nil
}

func transformKeyJSONWebKey2020ToEd25519VerificationKey2018(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyBase58, err := utils.JSONWebKey2020ToEd25519VerificationKey2018(verificationMethod.PublicKeyJwk)
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return verificationMethod, err
}

verificationMethod.PublicKeyJwk = nil
verificationMethod.Type = string(types.Ed25519VerificationKey2018)
verificationMethod.PublicKeyBase58 = publicKeyBase58

return verificationMethod, nil
}

func transformKeyJSONWebKey2020ToEd25519VerificationKey2020(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyMultibase, err := utils.JSONWebKey2020ToEd25519VerificationKey2020(verificationMethod.PublicKeyJwk)
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return verificationMethod, err
}

verificationMethod.PublicKeyJwk = nil
verificationMethod.Type = string(types.Ed25519VerificationKey2020)
verificationMethod.PublicKeyMultibase = publicKeyMultibase

return verificationMethod, nil
}

func transformVerificationMethodKey(
verificationMethod types.VerificationMethod, transformKeyType types.TransformKeyType,
) (types.VerificationMethod, error) {
verificationMethodType := types.TransformKeyType(verificationMethod.Type)
if verificationMethodType == transformKeyType {
return verificationMethod, nil
}

switch verificationMethodType {
case types.Ed25519VerificationKey2018:
switch transformKeyType {
case types.Ed25519VerificationKey2020:
return transformKeyEd25519VerificationKey2018ToEd25519VerificationKey2020(verificationMethod)
case types.JsonWebKey2020:
return transformKeyEd25519VerificationKey2018ToJSONWebKey2020(verificationMethod)
}

case types.Ed25519VerificationKey2020:
switch transformKeyType {
case types.Ed25519VerificationKey2018:
return transformKeyEd25519VerificationKey2020ToEd25519VerificationKey2018(verificationMethod)
case types.JsonWebKey2020:
return transformKeyEd25519VerificationKey2020ToJSONWebKey2020(verificationMethod)
}

case types.JsonWebKey2020:
switch transformKeyType {
case types.Ed25519VerificationKey2018:
return transformKeyJSONWebKey2020ToEd25519VerificationKey2018(verificationMethod)

case types.Ed25519VerificationKey2020:
return transformKeyJSONWebKey2020ToEd25519VerificationKey2020(verificationMethod)
}
}

return verificationMethod, fmt.Errorf("not supported transform key type")
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var _ = DescribeTable("Positive: Get Service param", func(testCase utils.Positiv
client := resty.New()
client.SetRedirectPolicy(resty.NoRedirectPolicy())

fmt.Println(testCase.DidURL)
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
resp, err := client.R().
SetHeader("Accept", testCase.ResolutionType).
Get(testCase.DidURL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var _ = DescribeTable("Positive: Get resource", func(testCase utils.PositiveTest
Expect(err).To(BeNil())
Expect(testCase.ExpectedStatusCode).To(Equal(resp.StatusCode()))


expectedDidDereferencing, err = utils.GetTextResource(testCase.ExpectedJSONPath)
Expect(err).To(BeNil())
Expect(expectedDidDereferencing).To(Equal(string(resp.Body())))
Expand Down
Loading