Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/npm_and_yarn/develop/conventio…
Browse files Browse the repository at this point in the history
…nal-changelog-conventionalcommits-6.1.0
  • Loading branch information
Andrew Nikitin authored Jun 28, 2023
2 parents 59fcfb9 + dbf3d37 commit e78544b
Show file tree
Hide file tree
Showing 25 changed files with 659 additions and 177 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ jobs:

- uses: actions/setup-go@v4
with:
go-version: 1.18
go-version-file: ./go.mod
cache: true

- name: Setup CodeQL
uses: github/codeql-action/init@v2
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ tidy:
###############################################################################

unit-tests:
cd tests/unit && ginkgo -r --tags unit --race
cd tests/unit && ginkgo -r --tags unit --race --keep-going

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

lint:
golangci-lint run --config .github/linters/.golangci.yaml
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
### STAGE 1: Build cheqd did-resolver binary pre-requisites ###
#####################################################################

FROM golang:1.18-alpine AS builder
FROM golang:1.20-alpine AS builder

# Install minimum necessary dependencies
ENV PACKAGES make git bash linux-headers findutils
Expand Down
4 changes: 2 additions & 2 deletions docs/docs.go

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

4 changes: 2 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
{
"type": "string",
"description": "Can transform Verification Method into another type",
"name": "transformKey",
"name": "transformKeys",
"in": "query"
},
{
Expand Down Expand Up @@ -138,7 +138,7 @@
],
"responses": {
"200": {
"description": "versionId, versionTime, transformKey returns Full DID Document",
"description": "versionId, versionTime, transformKeys returns Full DID Document",
"schema": {
"$ref": "#/definitions/types.DidResolution"
}
Expand Down
4 changes: 2 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ paths:
type: string
- description: Can transform Verification Method into another type
in: query
name: transformKey
name: transformKeys
type: string
- description: Redirects to Service Endpoint
in: query
Expand Down Expand Up @@ -340,7 +340,7 @@ paths:
- application/did+json
responses:
"200":
description: versionId, versionTime, transformKey returns Full DID Document
description: versionId, versionTime, transformKeys returns Full DID Document
schema:
$ref: '#/definitions/types.DidResolution'
"400":
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cheqd/did-resolver

go 1.18
go 1.20

require (
github.com/cheqd/cheqd-node/api/v2 v2.1.0
Expand Down
12 changes: 6 additions & 6 deletions services/diddoc/diddoc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ func (dd *QueryDIDDocRequestService) SpecificValidation(c services.ResolverConte

versionId := dd.GetQueryParam(types.VersionId)
versionTime := dd.GetQueryParam(types.VersionTime)
transformKey := types.TransformKeyType(dd.GetQueryParam(types.TransformKey))
transformKeys := types.TransformKeysType(dd.GetQueryParam(types.TransformKeys))
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)) {
if string(transformKeys) != "" && (!transformKeys.IsSupported() || !types.IsSupportedWithCombinationTransformKeysQuery(dd.Queries)) {
return types.NewRepresentationNotSupportedError(dd.GetDid(), dd.GetContentType(), nil, dd.IsDereferencing)
}

Expand Down Expand Up @@ -179,13 +179,13 @@ func (dd *QueryDIDDocRequestService) RegisterDidDocQueryHandlers(startHandler qu
// or
// - versionIdHandler
// After that we can find for service field if it's set.
// VersionIdHandler -> VersionTimeHandler -> DidDocResolveHandler -> TransformKeyHandler -> DidDocMetadataHandler -> ServiceHandler -> RelativeRefHandler
// VersionIdHandler -> VersionTimeHandler -> DidDocResolveHandler -> TransformKeysHandler -> DidDocMetadataHandler -> ServiceHandler -> RelativeRefHandler
relativeRefHandler := diddocQueries.RelativeRefHandler{}
serviceHandler := diddocQueries.ServiceHandler{}
versionIdHandler := diddocQueries.VersionIdHandler{}
versionTimeHandler := diddocQueries.VersionTimeHandler{}
didDocResolveHandler := diddocQueries.DidDocResolveHandler{}
transformKeyHandler := diddocQueries.TransformKeyHandler{}
transformKeysHandler := diddocQueries.TransformKeysHandler{}
didDocMetadataHandler := diddocQueries.DidDocMetadataHandler{}

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

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

err = transformKeyHandler.SetNext(c, &didDocMetadataHandler)
err = transformKeysHandler.SetNext(c, &didDocMetadataHandler)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions services/diddoc/echo_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// @Param fragmentId query string false "#Fragment"
// @Param versionId query string false "Version"
// @Param versionTime query string false "Created of Updated time of DID Document"
// @Param transformKey query string false "Can transform Verification Method into another type"
// @Param transformKeys query string false "Can transform Verification Method into another type"
// @Param service query string false "Redirects to Service Endpoint"
// @Param relativeRef query string false "Addition to Service Endpoint"
// @Param metadata query string false "Show only metadata of DID Document"
Expand All @@ -32,7 +32,7 @@ import (
// @Param resourceVersionTime query string false "Get the nearest resource by creation time"
// @Param resourceMetadata query string false "Show only metadata of resources"
// @Param checksum query string false "Sanity check that Checksum of resource is the same as expected"
// @success 200 {object} types.DidResolution "versionId, versionTime, transformKey returns Full DID Document"
// @success 200 {object} types.DidResolution "versionId, versionTime, transformKeys returns Full DID Document"
// @Failure 400 {object} types.IdentityError
// @Failure 404 {object} types.IdentityError
// @Failure 406 {object} types.IdentityError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
"github.com/cheqd/did-resolver/types"
)

type TransformKeyHandler struct {
type TransformKeysHandler struct {
queries.BaseQueryHandler
}

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

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

if !transformKey.IsSupported() {
if !transformKeys.IsSupported() {
return nil, types.NewRepresentationNotSupportedError(service.GetDid(), types.DIDJSONLD, nil, t.IsDereferencing)
}

Expand All @@ -30,7 +30,7 @@ func (t *TransformKeyHandler) Handle(c services.ResolverContext, service service
}

for i, vMethod := range didResolution.Did.VerificationMethod {
result, err := transformVerificationMethodKey(vMethod, transformKey)
result, err := transformVerificationMethodKey(vMethod, transformKeys)
if err != nil {
return nil, err
}
Expand Down
36 changes: 18 additions & 18 deletions services/diddoc/queries/diddoc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/cheqd/did-resolver/utils"
)

func transformKeyEd25519VerificationKey2018ToEd25519VerificationKey2020(
func transformKeysEd25519VerificationKey2018ToEd25519VerificationKey2020(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyMultibase, err := utils.Ed25519VerificationKey2018ToEd25519VerificationKey2020(verificationMethod.PublicKeyBase58)
Expand All @@ -22,7 +22,7 @@ func transformKeyEd25519VerificationKey2018ToEd25519VerificationKey2020(
return verificationMethod, nil
}

func transformKeyEd25519VerificationKey2018ToJSONWebKey2020(
func transformKeysEd25519VerificationKey2018ToJSONWebKey2020(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyJwk, err := utils.Ed25519VerificationKey2018ToJSONWebKey2020(verificationMethod.PublicKeyBase58)
Expand All @@ -37,7 +37,7 @@ func transformKeyEd25519VerificationKey2018ToJSONWebKey2020(
return verificationMethod, nil
}

func transformKeyEd25519VerificationKey2020ToEd25519VerificationKey2018(
func transformKeysEd25519VerificationKey2020ToEd25519VerificationKey2018(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyBase58, err := utils.Ed25519VerificationKey2020ToEd25519VerificationKey2018(verificationMethod.PublicKeyMultibase)
Expand All @@ -52,7 +52,7 @@ func transformKeyEd25519VerificationKey2020ToEd25519VerificationKey2018(
return verificationMethod, nil
}

func transformKeyEd25519VerificationKey2020ToJSONWebKey2020(
func transformKeysEd25519VerificationKey2020ToJSONWebKey2020(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyJwk, err := utils.Ed25519VerificationKey2020ToJSONWebKey2020(verificationMethod.PublicKeyMultibase)
Expand All @@ -67,7 +67,7 @@ func transformKeyEd25519VerificationKey2020ToJSONWebKey2020(
return verificationMethod, nil
}

func transformKeyJSONWebKey2020ToEd25519VerificationKey2018(
func transformKeysJSONWebKey2020ToEd25519VerificationKey2018(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyBase58, err := utils.JSONWebKey2020ToEd25519VerificationKey2018(verificationMethod.PublicKeyJwk)
Expand All @@ -82,7 +82,7 @@ func transformKeyJSONWebKey2020ToEd25519VerificationKey2018(
return verificationMethod, nil
}

func transformKeyJSONWebKey2020ToEd25519VerificationKey2020(
func transformKeysJSONWebKey2020ToEd25519VerificationKey2020(
verificationMethod types.VerificationMethod,
) (types.VerificationMethod, error) {
publicKeyMultibase, err := utils.JSONWebKey2020ToEd25519VerificationKey2020(verificationMethod.PublicKeyJwk)
Expand All @@ -98,37 +98,37 @@ func transformKeyJSONWebKey2020ToEd25519VerificationKey2020(
}

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

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

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

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

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

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/rest/diddoc/query/common_positive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ var _ = DescribeTable("Positive: request with common query parameters", func(tes
),

Entry(
"can get DIDDoc with an existent versionId and transformKey query parameters",
"can get DIDDoc with an existent versionId and transformKeys query parameters",
utils.PositiveTestCase{
DidURL: fmt.Sprintf(
"http://localhost:8080/1.0/identifiers/%s?versionId=%s&transformKey=%s",
"http://localhost:8080/1.0/identifiers/%s?versionId=%s&transformKeys=%s",
testconstants.SeveralVersionsDID,
"ce298b6f-594b-426e-b431-370d6bc5d3ad",
types.JsonWebKey2020,
Expand All @@ -64,10 +64,10 @@ var _ = DescribeTable("Positive: request with common query parameters", func(tes
),

Entry(
"can get DIDDoc with an existent versionId, versionTime, transformKey",
"can get DIDDoc with an existent versionId, versionTime, transformKeys",
utils.PositiveTestCase{
DidURL: fmt.Sprintf(
"http://localhost:8080/1.0/identifiers/%s?versionId=%s&versionTime=%s&transformKey=%s",
"http://localhost:8080/1.0/identifiers/%s?versionId=%s&versionTime=%s&transformKeys=%s",
testconstants.SeveralVersionsDID,
"ce298b6f-594b-426e-b431-370d6bc5d3ad",
"2023-03-06T09:39:49Z",
Expand Down
Loading

0 comments on commit e78544b

Please sign in to comment.