diff --git a/.golangci.yaml b/.golangci.yaml index cca74d08d..f5c0f4d4c 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -15,6 +15,7 @@ linters: - errcheck - errorlint - gocritic + - goimports - gosec - govet - ineffassign diff --git a/config/config_test.go b/config/config_test.go index a829f67a4..42d19835d 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1,8 +1,9 @@ package config import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestConfig(t *testing.T) { diff --git a/integration/common.go b/integration/common.go index f05aa7817..66854ae8b 100644 --- a/integration/common.go +++ b/integration/common.go @@ -3,20 +3,20 @@ package integration import ( "bytes" "embed" - cmpact "github.com/goccy/go-json" - "github.com/goccy/go-json" "fmt" + "io" + "net/http" + "strings" + manifestsdk "github.com/TBD54566975/ssi-sdk/credential/manifest" "github.com/TBD54566975/ssi-sdk/crypto" + "github.com/goccy/go-json" "github.com/mr-tron/base58" "github.com/oliveagle/jsonpath" "github.com/pkg/errors" "github.com/sirupsen/logrus" credmodel "github.com/tbd54566975/ssi-service/internal/credential" "github.com/tbd54566975/ssi-service/internal/keyaccess" - "io" - "net/http" - "strings" ) const ( @@ -139,10 +139,10 @@ func SubmitApplication(credAppJWT string) (string, error) { return output, nil } -func compactJSONOutput(json string) string { - jsonBytes := []byte(json) +func compactJSONOutput(jsonString string) string { + jsonBytes := []byte(jsonString) buffer := new(bytes.Buffer) - if err := cmpact.Compact(buffer, jsonBytes); err != nil { + if err := json.Compact(buffer, jsonBytes); err != nil { logrus.Println(err) panic(err) } @@ -151,7 +151,7 @@ func compactJSONOutput(json string) string { } func getJSONElement(jsonString string, jsonPath string) (string, error) { - jsonMap := make(map[string]interface{}) + jsonMap := make(map[string]any) if err := json.Unmarshal([]byte(jsonString), &jsonMap); err != nil { return "", errors.Wrap(err, "unmarshalling json string") } diff --git a/integration/credential_revocation_integration_test.go b/integration/credential_revocation_integration_test.go index 740fc2610..8e5380e7e 100644 --- a/integration/credential_revocation_integration_test.go +++ b/integration/credential_revocation_integration_test.go @@ -1,8 +1,9 @@ package integration import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) var credentialRevocationContext = NewTestContext("CredentialRevocation") diff --git a/integration/didweb_integration_test.go b/integration/didweb_integration_test.go index 8ec927821..1750e2ea9 100644 --- a/integration/didweb_integration_test.go +++ b/integration/didweb_integration_test.go @@ -1,8 +1,9 @@ package integration import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) var didWebContext = NewTestContext("DIDWeb") diff --git a/integration/steelthread_integration_test.go b/integration/steelthread_integration_test.go index 8160aa157..08f5dcc45 100644 --- a/integration/steelthread_integration_test.go +++ b/integration/steelthread_integration_test.go @@ -1,8 +1,9 @@ package integration import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) var steelThreadContext = NewTestContext("SteelThread") diff --git a/integration/testutil.go b/integration/testutil.go index 4bb32195a..36e6b1f60 100644 --- a/integration/testutil.go +++ b/integration/testutil.go @@ -1,13 +1,14 @@ package integration import ( - "github.com/pkg/errors" "sync" + + "github.com/pkg/errors" ) type TestContext struct { testName string - values map[string]interface{} + values map[string]any } var globalMutex sync.RWMutex @@ -15,19 +16,19 @@ var globalMutex sync.RWMutex func NewTestContext(testName string) *TestContext { return &TestContext{ testName: testName, - values: make(map[string]interface{}), + values: make(map[string]any), } } // SetValue sets a value in the test context. -func SetValue(ctx *TestContext, key string, value interface{}) { +func SetValue(ctx *TestContext, key string, value any) { globalMutex.RLock() defer globalMutex.RUnlock() ctx.values[key] = value } // GetValue retrieves a value from the test context. -func GetValue(ctx *TestContext, key string) (interface{}, error) { +func GetValue(ctx *TestContext, key string) (any, error) { globalMutex.RLock() defer globalMutex.RUnlock() value, ok := ctx.values[key] diff --git a/internal/credential/model.go b/internal/credential/model.go index a215885c3..67da30376 100644 --- a/internal/credential/model.go +++ b/internal/credential/model.go @@ -57,7 +57,7 @@ func NewCredentialContainerFromJWT(credentialJWT string) (*Container, error) { // NewCredentialContainerFromMap attempts to parse a data integrity credential from a piece of JSON, // which is represented as a map in go, into a Container -func NewCredentialContainerFromMap(credMap map[string]interface{}) (*Container, error) { +func NewCredentialContainerFromMap(credMap map[string]any) (*Container, error) { var cred credential.VerifiableCredential credMapBytes, err := json.Marshal(credMap) if err != nil { @@ -76,8 +76,8 @@ func NewCredentialContainerFromMap(credMap map[string]interface{}) (*Container, return nil, errors.New("credential does not have a data integrity proof") } -func ContainersToInterface(cs []Container) []interface{} { - var credentials []interface{} +func ContainersToInterface(cs []Container) []any { + var credentials []any for _, container := range cs { if container.HasDataIntegrityCredential() { credentials = append(credentials, *container.Credential) @@ -90,7 +90,7 @@ func ContainersToInterface(cs []Container) []interface{} { // NewCredentialContainerFromArray attempts to parse arrays of credentials of any type (either data integrity or JWT) // into an array of CredentialContainers. The method will return an error if any of the credentials are invalid. -func NewCredentialContainerFromArray(creds []interface{}) ([]Container, error) { +func NewCredentialContainerFromArray(creds []any) ([]Container, error) { var containers []Container for _, c := range creds { switch v := c.(type) { @@ -101,7 +101,7 @@ func NewCredentialContainerFromArray(creds []interface{}) ([]Container, error) { return nil, errors.Wrap(err, "could not parse credential from JWT") } containers = append(containers, *container) - case map[string]interface{}: + case map[string]any: // JSON container, err := NewCredentialContainerFromMap(v) if err != nil { diff --git a/internal/did/access.go b/internal/did/access.go index 5e7d055d8..cfb54f5d8 100644 --- a/internal/did/access.go +++ b/internal/did/access.go @@ -3,6 +3,7 @@ package did import ( "crypto" "fmt" + "github.com/TBD54566975/ssi-sdk/cryptosuite" didsdk "github.com/TBD54566975/ssi-sdk/did" "github.com/goccy/go-json" diff --git a/internal/did/access_test.go b/internal/did/access_test.go index 7aac60639..64d0537df 100644 --- a/internal/did/access_test.go +++ b/internal/did/access_test.go @@ -4,9 +4,10 @@ import ( "crypto" "crypto/ed25519" "fmt" + "testing" + "github.com/TBD54566975/ssi-sdk/did" "github.com/stretchr/testify/assert" - "testing" ) func TestGetVerificationInformation(t *testing.T) { diff --git a/internal/keyaccess/jwt.go b/internal/keyaccess/jwt.go index 7994060c1..832b3e3bf 100644 --- a/internal/keyaccess/jwt.go +++ b/internal/keyaccess/jwt.go @@ -71,7 +71,7 @@ func JWTPtr(j string) *JWT { } // SignJSON takes an object that is either itself json or json-serializable and signs it. -func (ka JWKKeyAccess) SignJSON(data interface{}) (*JWT, error) { +func (ka JWKKeyAccess) SignJSON(data any) (*JWT, error) { if ka.JWTSigner == nil { return nil, errors.New("cannot sign with nil signer") } @@ -79,14 +79,14 @@ func (ka JWKKeyAccess) SignJSON(data interface{}) (*JWT, error) { if err != nil { return nil, err } - payload := make(map[string]interface{}) + payload := make(map[string]any) if err = json.Unmarshal(jsonBytes, &payload); err != nil { return nil, err } return ka.Sign(payload) } -func (ka JWKKeyAccess) Sign(payload map[string]interface{}) (*JWT, error) { +func (ka JWKKeyAccess) Sign(payload map[string]any) (*JWT, error) { if ka.JWTSigner == nil { return nil, errors.New("cannot sign with nil signer") } diff --git a/internal/keyaccess/jwt_test.go b/internal/keyaccess/jwt_test.go index fbc0ae14a..e09cab944 100644 --- a/internal/keyaccess/jwt_test.go +++ b/internal/keyaccess/jwt_test.go @@ -12,7 +12,7 @@ import ( func TestJWKKeyAccessForEachKeyType(t *testing.T) { testKID := "test-kid" - testData := map[string]interface{}{ + testData := map[string]any{ "test": "data", } @@ -99,7 +99,7 @@ func TestJWKKeyAccessSignVerify(t *testing.T) { assert.NoError(tt, err) assert.NotEmpty(tt, ka) - data := map[string]interface{}{ + data := map[string]any{ "test": "test", } token, err := ka.Sign(data) @@ -270,9 +270,9 @@ func getTestCredential() credential.VerifiableCredential { knownType := []string{"VerifiableCredential", "HappyCredential"} knownIssuer := "https://example.com/issuers/565049" knownIssuanceDate := "2010-01-01T19:23:24Z" - knownSubject := map[string]interface{}{ + knownSubject := map[string]any{ "id": "did:example:ebfeb1f712ebc6f1c276e12ec21", - "happiness": map[string]interface{}{ + "happiness": map[string]any{ "howHappy": "really happy", }, } @@ -296,6 +296,6 @@ func getTestPresentation() credential.VerifiablePresentation { ID: knownID, Type: knownType, Holder: knownHolder, - VerifiableCredential: []interface{}{getTestCredential()}, + VerifiableCredential: []any{getTestCredential()}, } } diff --git a/internal/util/util.go b/internal/util/util.go index cb7f7d663..69a0c2c59 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -31,7 +31,7 @@ func LoggingNewError(msg string) error { } // LoggingNewErrorf is a utility to create an error from a formatted message, log it, and return it as an error -func LoggingNewErrorf(msg string, args ...interface{}) error { +func LoggingNewErrorf(msg string, args ...any) error { return LoggingNewError(fmt.Sprintf(msg, args...)) } @@ -42,7 +42,7 @@ func LoggingErrorMsg(err error, msg string) error { } // LoggingErrorMsgf is a utility to combine logging an error, and returning and error with a formatted message -func LoggingErrorMsgf(err error, msg string, args ...interface{}) error { +func LoggingErrorMsgf(err error, msg string, args ...any) error { return LoggingErrorMsg(err, fmt.Sprintf(msg, args...)) } diff --git a/pkg/server/framework/request.go b/pkg/server/framework/request.go index eff86a596..5edd17bbd 100644 --- a/pkg/server/framework/request.go +++ b/pkg/server/framework/request.go @@ -59,7 +59,7 @@ func RouteParams(r *http.Request) map[string]string { // The body is decoded into the value provided. // // The provided value is checked for validation tags if it's a struct. -func Decode(r *http.Request, val interface{}) error { +func Decode(r *http.Request, val any) error { decoder := json.NewDecoder(r.Body) decoder.DisallowUnknownFields() @@ -97,6 +97,6 @@ func Decode(r *http.Request, val interface{}) error { return nil } -func ValidateRequest(request interface{}) error { +func ValidateRequest(request any) error { return util.IsValidStruct(request) } diff --git a/pkg/server/framework/response.go b/pkg/server/framework/response.go index 554872de4..0363235a5 100644 --- a/pkg/server/framework/response.go +++ b/pkg/server/framework/response.go @@ -2,14 +2,14 @@ package framework import ( "context" - "github.com/goccy/go-json" "net/http" + "github.com/goccy/go-json" "github.com/pkg/errors" ) // Respond convert a Go value to JSON and sends it to the client. -func Respond(ctx context.Context, w http.ResponseWriter, data interface{}, statusCode int) error { +func Respond(ctx context.Context, w http.ResponseWriter, data any, statusCode int) error { // set the status code within the context's request state. Gracefully shutdown if // the request state doesn't exist in the context v, ok := ctx.Value(KeyRequestState).(*RequestState) diff --git a/pkg/server/middleware/logger.go b/pkg/server/middleware/logger.go index ffcb99d7c..d601826d2 100644 --- a/pkg/server/middleware/logger.go +++ b/pkg/server/middleware/logger.go @@ -2,20 +2,25 @@ package middleware import ( "context" - "github.com/sirupsen/logrus" - "github.com/tbd54566975/ssi-service/pkg/server/framework" "net/http" "time" + + "github.com/sirupsen/logrus" + "github.com/tbd54566975/ssi-service/pkg/server/framework" ) // Logger logs request info before and after a handler runs. // logs to to stdout in the following format: // Before: -// TraceID : (StatusCode) HTTPMethod Path -> IPAddr (latency) -// e.g. 12345 : (200) GET /users/1 -> 192.168.1.0 (4ms) +// +// TraceID : (StatusCode) HTTPMethod Path -> IPAddr (latency) +// e.g. 12345 : (200) GET /users/1 -> 192.168.1.0 (4ms) +// // After: -// TODO: add after format -// TODO: add after example +// +// TODO: add after format +// TODO: add after example +// // TODO: make logging output configurable func Logger() framework.Middleware { mw := func(handler framework.Handler) framework.Handler { diff --git a/pkg/server/middleware/panics.go b/pkg/server/middleware/panics.go index 6b5923ffe..ad625e016 100644 --- a/pkg/server/middleware/panics.go +++ b/pkg/server/middleware/panics.go @@ -2,12 +2,12 @@ package middleware import ( "context" - "github.com/sirupsen/logrus" - "github.com/tbd54566975/ssi-service/pkg/server/framework" "net/http" "runtime/debug" "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "github.com/tbd54566975/ssi-service/pkg/server/framework" ) // Panics recovers from panics and converts the panic into an error diff --git a/pkg/server/router/credential.go b/pkg/server/router/credential.go index 4225fb07a..db5e4a394 100644 --- a/pkg/server/router/credential.go +++ b/pkg/server/router/credential.go @@ -46,10 +46,10 @@ type CreateCredentialRequest struct { // A context is optional. If not present, we'll apply default, required context values. Context string `json:"@context"` // A schema is optional. If present, we'll attempt to look it up and validate the data against it. - Schema string `json:"schema"` - Data map[string]interface{} `json:"data" validate:"required"` - Expiry string `json:"expiry"` - Revocable bool `json:"revocable"` + Schema string `json:"schema"` + Data map[string]any `json:"data" validate:"required"` + Expiry string `json:"expiry"` + Revocable bool `json:"revocable"` // TODO(gabe) support more capabilities like signature type, format, status, and more. } diff --git a/pkg/server/router/credential_test.go b/pkg/server/router/credential_test.go index f7b1474bf..637bbd417 100644 --- a/pkg/server/router/credential_test.go +++ b/pkg/server/router/credential_test.go @@ -74,7 +74,7 @@ func TestCredentialRouter(t *testing.T) { createdCred, err := credService.CreateCredential(credential.CreateCredentialRequest{ Issuer: issuer, Subject: subject, - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Satoshi", "lastName": "Nakamoto", }, @@ -132,7 +132,7 @@ func TestCredentialRouter(t *testing.T) { Issuer: issuer, Subject: "did:abcd:efghi", JSONSchema: "https://test-schema.com", - Data: map[string]interface{}{ + Data: map[string]any{ "email": "satoshi@nakamoto.com", }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), @@ -141,14 +141,14 @@ func TestCredentialRouter(t *testing.T) { assert.Contains(tt, err.Error(), "schema not found with id: https://test-schema.com") // create schema - emailSchema := map[string]interface{}{ + emailSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "email": map[string]interface{}{ + "properties": map[string]any{ + "email": map[string]any{ "type": "string", }, }, - "required": []interface{}{"email"}, + "required": []any{"email"}, "additionalProperties": false, } createdSchema, err := schemaService.CreateSchema(schema.CreateSchemaRequest{Author: "me", Name: "simple schema", Schema: emailSchema}) @@ -160,7 +160,7 @@ func TestCredentialRouter(t *testing.T) { Issuer: issuer, Subject: "did:abcd:efghi", JSONSchema: createdSchema.ID, - Data: map[string]interface{}{ + Data: map[string]any{ "email": "satoshi@nakamoto.com", }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), @@ -231,14 +231,14 @@ func TestCredentialRouter(t *testing.T) { assert.NotEmpty(tt, issuerDID) // create a schema - emailSchema := map[string]interface{}{ + emailSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "email": map[string]interface{}{ + "properties": map[string]any{ + "email": map[string]any{ "type": "string", }, }, - "required": []interface{}{"email"}, + "required": []any{"email"}, "additionalProperties": false, } @@ -253,7 +253,7 @@ func TestCredentialRouter(t *testing.T) { Issuer: issuer, Subject: subject, JSONSchema: createdSchema.ID, - Data: map[string]interface{}{ + Data: map[string]any{ "email": "Satoshi@Nakamoto.btc", }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), @@ -264,7 +264,7 @@ func TestCredentialRouter(t *testing.T) { assert.NotEmpty(tt, createdCred) assert.NotEmpty(tt, createdCred.CredentialJWT) - credStatusMap, ok := createdCred.Credential.CredentialStatus.(map[string]interface{}) + credStatusMap, ok := createdCred.Credential.CredentialStatus.(map[string]any) assert.True(tt, ok) assert.Contains(tt, credStatusMap["id"], fmt.Sprintf("v1/credentials/%s/status", createdCred.ID)) @@ -275,7 +275,7 @@ func TestCredentialRouter(t *testing.T) { Issuer: issuer, Subject: subject, JSONSchema: createdSchema.ID, - Data: map[string]interface{}{ + Data: map[string]any{ "email": "Satoshi2@Nakamoto2.btc", }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), @@ -286,7 +286,7 @@ func TestCredentialRouter(t *testing.T) { assert.NotEmpty(tt, createdCredTwo) assert.NotEmpty(tt, createdCredTwo.CredentialJWT) - credStatusMapTwo, ok := createdCredTwo.Credential.CredentialStatus.(map[string]interface{}) + credStatusMapTwo, ok := createdCredTwo.Credential.CredentialStatus.(map[string]any) assert.True(tt, ok) assert.Contains(tt, credStatusMapTwo["id"], fmt.Sprintf("v1/credentials/%s/status", createdCredTwo.ID)) diff --git a/pkg/server/router/manifest.go b/pkg/server/router/manifest.go index 0f00e789e..ad7fa546d 100644 --- a/pkg/server/router/manifest.go +++ b/pkg/server/router/manifest.go @@ -41,8 +41,8 @@ func NewManifestRouter(s svcframework.Service) (*ManifestRouter, error) { // CreateManifestRequest is the request body for creating a manifest, which populates all remaining fields // and builds a well-formed manifest object. type CreateManifestRequest struct { - Name *string `json:"name,omitempty"` - Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` IssuerDID string `json:"issuerDid" validate:"required"` IssuerName *string `json:"issuerName,omitempty"` ClaimFormat *exchange.ClaimFormat `json:"format" validate:"required,dive"` @@ -52,8 +52,8 @@ type CreateManifestRequest struct { func (c CreateManifestRequest) ToServiceRequest() manifest.CreateManifestRequest { return manifest.CreateManifestRequest{ - Name: c.Name, - Description: c.Description, + Name: c.Name, + Description: c.Description, IssuerDID: c.IssuerDID, IssuerName: c.IssuerName, OutputDescriptors: c.OutputDescriptors, @@ -235,7 +235,7 @@ func (sar SubmitApplicationRequest) ToServiceRequest() (*manifest.SubmitApplicat // make sure the known properties are present (Application and Credentials) - var creds []interface{} + var creds []any credentials, ok := token.Get(vcsJSONProperty) if !ok { logrus.Warn("could not find vc in Credential Application token, looking for `verifiableCredentials`") @@ -243,7 +243,7 @@ func (sar SubmitApplicationRequest) ToServiceRequest() (*manifest.SubmitApplicat return nil, errors.New("could not find vc or verifiableCredentials in Credential Application token") } } - creds, ok = credentials.([]interface{}) + creds, ok = credentials.([]any) if !ok { errMsg := fmt.Sprintf("could not parse Credential Application token, %s is not an array", vcsJSONProperty) logrus.Errorf("%s: %s", errMsg, credentials) @@ -282,7 +282,7 @@ func (sar SubmitApplicationRequest) ToServiceRequest() (*manifest.SubmitApplicat type SubmitApplicationResponse struct { Response manifestsdk.CredentialResponse `json:"credential_response"` // this is an interface type to union Data Integrity and JWT style VCs - Credentials []interface{} `json:"verifiableCredentials,omitempty"` + Credentials []any `json:"verifiableCredentials,omitempty"` ResponseJWT keyaccess.JWT `json:"responseJwt,omitempty"` } diff --git a/pkg/server/router/manifest_test.go b/pkg/server/router/manifest_test.go index b3cb5eb3b..ba860e8c5 100644 --- a/pkg/server/router/manifest_test.go +++ b/pkg/server/router/manifest_test.go @@ -73,10 +73,10 @@ func TestManifestRouter(t *testing.T) { assert.NotEmpty(tt, applicantDID) // create a schema for the creds to be issued against - licenseSchema := map[string]interface{}{ + licenseSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "licenseType": map[string]interface{}{ + "properties": map[string]any{ + "licenseType": map[string]any{ "type": "string", }, }, @@ -91,7 +91,7 @@ func TestManifestRouter(t *testing.T) { Issuer: issuerDID.DID.ID, Subject: applicantDID.DID.ID, JSONSchema: createdSchema.ID, - Data: map[string]interface{}{"licenseType": "WA-DL-CLASS-A"}, + Data: map[string]any{"licenseType": "WA-DL-CLASS-A"}, }) assert.NoError(tt, err) assert.NotEmpty(tt, createdCred) diff --git a/pkg/server/router/operation.go b/pkg/server/router/operation.go index f4d841051..f0e1e645e 100644 --- a/pkg/server/router/operation.go +++ b/pkg/server/router/operation.go @@ -3,6 +3,8 @@ package router import ( "context" "fmt" + "net/http" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/tbd54566975/ssi-service/internal/util" @@ -10,7 +12,6 @@ import ( svcframework "github.com/tbd54566975/ssi-service/pkg/service/framework" "github.com/tbd54566975/ssi-service/pkg/service/operation" "go.einride.tech/aip/filtering" - "net/http" ) type OperationRouter struct { diff --git a/pkg/server/router/presentation.go b/pkg/server/router/presentation.go index bc1d2e705..f67ec7956 100644 --- a/pkg/server/router/presentation.go +++ b/pkg/server/router/presentation.go @@ -3,6 +3,8 @@ package router import ( "context" "fmt" + "net/http" + "github.com/TBD54566975/ssi-sdk/credential/exchange" "github.com/TBD54566975/ssi-sdk/credential/signing" "github.com/goccy/go-json" @@ -16,7 +18,6 @@ import ( "github.com/tbd54566975/ssi-service/pkg/service/presentation" "github.com/tbd54566975/ssi-service/pkg/service/presentation/model" "go.einride.tech/aip/filtering" - "net/http" ) type PresentationRouter struct { diff --git a/pkg/server/router/presentation_test.go b/pkg/server/router/presentation_test.go index 2a705225d..d77db5bd6 100644 --- a/pkg/server/router/presentation_test.go +++ b/pkg/server/router/presentation_test.go @@ -1,6 +1,9 @@ package router import ( + "os" + "testing" + "github.com/TBD54566975/ssi-sdk/credential/exchange" "github.com/TBD54566975/ssi-sdk/crypto" "github.com/stretchr/testify/assert" @@ -8,8 +11,6 @@ import ( "github.com/tbd54566975/ssi-service/pkg/service/presentation" "github.com/tbd54566975/ssi-service/pkg/service/presentation/model" "github.com/tbd54566975/ssi-service/pkg/storage" - "os" - "testing" ) func TestPresentationDefinitionRouter(t *testing.T) { diff --git a/pkg/server/router/schema_test.go b/pkg/server/router/schema_test.go index 25857a8ee..9e06b571d 100644 --- a/pkg/server/router/schema_test.go +++ b/pkg/server/router/schema_test.go @@ -64,14 +64,14 @@ func TestSchemaRouter(t *testing.T) { assert.Contains(tt, err.Error(), "error getting schema") // create a schema - simpleSchema := map[string]interface{}{ + simpleSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "foo": map[string]interface{}{ + "properties": map[string]any{ + "foo": map[string]any{ "type": "string", }, }, - "required": []interface{}{"foo"}, + "required": []any{"foo"}, "additionalProperties": false, } createdSchema, err := schemaService.CreateSchema(schema.CreateSchemaRequest{Author: "me", Name: "simple schema", Schema: simpleSchema}) @@ -145,14 +145,14 @@ func TestSchemaSigning(t *testing.T) { assert.Equal(tt, framework.StatusReady, schemaService.Status().Status) // create a schema and don't sign it - simpleSchema := map[string]interface{}{ + simpleSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "foo": map[string]interface{}{ + "properties": map[string]any{ + "foo": map[string]any{ "type": "string", }, }, - "required": []interface{}{"foo"}, + "required": []any{"foo"}, "additionalProperties": false, } createdSchema, err := schemaService.CreateSchema(schema.CreateSchemaRequest{Author: "me", Name: "simple schema", Schema: simpleSchema}) diff --git a/pkg/server/server_credential_test.go b/pkg/server/server_credential_test.go index 7b070a48d..74872bcc3 100644 --- a/pkg/server/server_credential_test.go +++ b/pkg/server/server_credential_test.go @@ -1,7 +1,6 @@ package server import ( - "github.com/goccy/go-json" "fmt" "net/http" "net/http/httptest" @@ -10,6 +9,8 @@ import ( "testing" "time" + "github.com/goccy/go-json" + credsdk "github.com/TBD54566975/ssi-sdk/credential" "github.com/TBD54566975/ssi-sdk/crypto" didsdk "github.com/TBD54566975/ssi-sdk/did" @@ -67,7 +68,7 @@ func TestCredentialAPI(t *testing.T) { missingIssuerRequest := router.CreateCredentialRequest{ Issuer: "did:abc:123", Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -86,7 +87,7 @@ func TestCredentialAPI(t *testing.T) { createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -131,17 +132,17 @@ func TestCredentialAPI(t *testing.T) { assert.NotEmpty(tt, issuerDID) // create a schema - simpleSchema := map[string]interface{}{ + simpleSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "firstName": map[string]interface{}{ + "properties": map[string]any{ + "firstName": map[string]any{ "type": "string", }, - "lastName": map[string]interface{}{ + "lastName": map[string]any{ "type": "string", }, }, - "required": []interface{}{"firstName", "lastName"}, + "required": []any{"firstName", "lastName"}, "additionalProperties": false, } createdSchema, err := schemaService.CreateSchema(schema.CreateSchemaRequest{Author: "me", Name: "simple schema", Schema: simpleSchema}) @@ -152,7 +153,7 @@ func TestCredentialAPI(t *testing.T) { Issuer: issuerDID.DID.ID, Subject: "did:abc:456", Schema: createdSchema.ID, - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -191,7 +192,7 @@ func TestCredentialAPI(t *testing.T) { Issuer: issuerDID.DID.ID, Subject: "did:abc:456", Schema: "bad", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -249,7 +250,7 @@ func TestCredentialAPI(t *testing.T) { createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -305,17 +306,17 @@ func TestCredentialAPI(t *testing.T) { assert.NotEmpty(tt, issuerDID) // create a schema - simpleSchema := map[string]interface{}{ + simpleSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "firstName": map[string]interface{}{ + "properties": map[string]any{ + "firstName": map[string]any{ "type": "string", }, - "lastName": map[string]interface{}{ + "lastName": map[string]any{ "type": "string", }, }, - "required": []interface{}{"firstName", "lastName"}, + "required": []any{"firstName", "lastName"}, "additionalProperties": false, } createdSchema, err := schemaService.CreateSchema(schema.CreateSchemaRequest{Author: "me", Name: "simple schema", Schema: simpleSchema}) @@ -326,7 +327,7 @@ func TestCredentialAPI(t *testing.T) { Issuer: issuerDID.DID.ID, Subject: "did:abc:456", Schema: createdSchema.ID, - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -386,7 +387,7 @@ func TestCredentialAPI(t *testing.T) { createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -446,7 +447,7 @@ func TestCredentialAPI(t *testing.T) { createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: subjectID, - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -504,7 +505,7 @@ func TestCredentialAPI(t *testing.T) { createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -576,7 +577,7 @@ func TestCredentialAPI(t *testing.T) { createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -658,7 +659,7 @@ func TestCredentialAPI(t *testing.T) { createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -682,7 +683,7 @@ func TestCredentialAPI(t *testing.T) { createRevocableCredRequestOne := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -703,7 +704,7 @@ func TestCredentialAPI(t *testing.T) { assert.NotEmpty(tt, revocableRespOne.Credential.CredentialStatus) assert.Equal(tt, revocableRespOne.Credential.Issuer, issuerDID.DID.ID) - credStatusMap, ok := revocableRespOne.Credential.CredentialStatus.(map[string]interface{}) + credStatusMap, ok := revocableRespOne.Credential.CredentialStatus.(map[string]any) assert.True(tt, ok) assert.NotEmpty(tt, credStatusMap["statusListIndex"]) @@ -712,7 +713,7 @@ func TestCredentialAPI(t *testing.T) { createRevocableCredRequestTwo := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -733,7 +734,7 @@ func TestCredentialAPI(t *testing.T) { assert.NotEmpty(tt, revocableRespTwo.Credential.CredentialStatus) assert.Equal(tt, revocableRespTwo.Credential.Issuer, issuerDID.DID.ID) - credStatusMap, ok = revocableRespTwo.Credential.CredentialStatus.(map[string]interface{}) + credStatusMap, ok = revocableRespTwo.Credential.CredentialStatus.(map[string]any) assert.True(tt, ok) assert.NotEmpty(tt, credStatusMap["statusListIndex"]) @@ -742,7 +743,7 @@ func TestCredentialAPI(t *testing.T) { createRevocableCredRequestThree := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -763,7 +764,7 @@ func TestCredentialAPI(t *testing.T) { assert.NotEmpty(tt, revocableRespThree.Credential.CredentialStatus) assert.Equal(tt, revocableRespThree.Credential.Issuer, issuerDID.DID.ID) - credStatusMap, ok = revocableRespThree.Credential.CredentialStatus.(map[string]interface{}) + credStatusMap, ok = revocableRespThree.Credential.CredentialStatus.(map[string]any) assert.True(tt, ok) assert.NotEmpty(tt, credStatusMap["statusListIndex"]) @@ -772,7 +773,7 @@ func TestCredentialAPI(t *testing.T) { createRevocableCredRequestFour := router.CreateCredentialRequest{ Issuer: issuerDIDTwo.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -793,7 +794,7 @@ func TestCredentialAPI(t *testing.T) { assert.NotEmpty(tt, revocableRespFour.Credential.CredentialStatus) assert.Equal(tt, revocableRespFour.Credential.Issuer, issuerDIDTwo.DID.ID) - credStatusMap, ok = revocableRespFour.Credential.CredentialStatus.(map[string]interface{}) + credStatusMap, ok = revocableRespFour.Credential.CredentialStatus.(map[string]any) assert.True(tt, ok) assert.NotEmpty(tt, credStatusMap["statusListIndex"]) @@ -827,7 +828,7 @@ func TestCredentialAPI(t *testing.T) { createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -848,7 +849,7 @@ func TestCredentialAPI(t *testing.T) { assert.NotEmpty(tt, resp.Credential.CredentialStatus) assert.Equal(tt, resp.Credential.Issuer, issuerDID.DID.ID) - credStatusMap, ok := resp.Credential.CredentialStatus.(map[string]interface{}) + credStatusMap, ok := resp.Credential.CredentialStatus.(map[string]any) assert.True(tt, ok) assert.NotEmpty(tt, credStatusMap["statusListIndex"]) @@ -905,7 +906,7 @@ func TestCredentialAPI(t *testing.T) { createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, Subject: "did:abc:456", - Data: map[string]interface{}{ + Data: map[string]any{ "firstName": "Jack", "lastName": "Dorsey", }, @@ -926,7 +927,7 @@ func TestCredentialAPI(t *testing.T) { assert.NotEmpty(tt, resp.Credential.CredentialStatus) assert.Equal(tt, resp.Credential.Issuer, issuerDID.DID.ID) - credStatusMap, ok := resp.Credential.CredentialStatus.(map[string]interface{}) + credStatusMap, ok := resp.Credential.CredentialStatus.(map[string]any) assert.True(tt, ok) assert.NotEmpty(tt, credStatusMap["statusListIndex"]) diff --git a/pkg/server/server_manifest_test.go b/pkg/server/server_manifest_test.go index 19cf867f7..8f1fa3e14 100644 --- a/pkg/server/server_manifest_test.go +++ b/pkg/server/server_manifest_test.go @@ -63,10 +63,10 @@ func TestManifestAPI(t *testing.T) { assert.NotEmpty(tt, issuerDID) // create a schema for the creds to be issued against - licenseSchema := map[string]interface{}{ + licenseSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "licenseType": map[string]interface{}{ + "properties": map[string]any{ + "licenseType": map[string]any{ "type": "string", }, }, @@ -143,10 +143,10 @@ func TestManifestAPI(t *testing.T) { assert.NotEmpty(tt, issuerDID) // create a schema for the creds to be issued against - licenseSchema := map[string]interface{}{ + licenseSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "licenseType": map[string]interface{}{ + "properties": map[string]any{ + "licenseType": map[string]any{ "type": "string", }, }, @@ -207,10 +207,10 @@ func TestManifestAPI(t *testing.T) { assert.NotEmpty(tt, issuerDID) // create a schema for the creds to be issued against - licenseSchema := map[string]interface{}{ + licenseSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "licenseType": map[string]interface{}{ + "properties": map[string]any{ + "licenseType": map[string]any{ "type": "string", }, }, @@ -278,10 +278,10 @@ func TestManifestAPI(t *testing.T) { assert.NotEmpty(tt, issuerDID) // create a schema for the creds to be issued against - licenseSchema := map[string]interface{}{ + licenseSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "licenseType": map[string]interface{}{ + "properties": map[string]any{ + "licenseType": map[string]any{ "type": "string", }, }, @@ -382,10 +382,10 @@ func TestManifestAPI(t *testing.T) { assert.NotEmpty(tt, issuerDID) // create a schema for the creds to be issued against - licenseSchema := map[string]interface{}{ + licenseSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "licenseType": map[string]interface{}{ + "properties": map[string]any{ + "licenseType": map[string]any{ "type": "string", }, }, @@ -400,7 +400,7 @@ func TestManifestAPI(t *testing.T) { Issuer: issuerDID.DID.ID, Subject: applicantDID.DID.ID, JSONSchema: createdSchema.ID, - Data: map[string]interface{}{"licenseType": "WA-DL-CLASS-A"}, + Data: map[string]any{"licenseType": "WA-DL-CLASS-A"}, }) assert.NoError(tt, err) assert.NotEmpty(tt, createdCred) @@ -505,10 +505,10 @@ func TestManifestAPI(t *testing.T) { assert.NotEmpty(tt, issuerDID) // create a schema for the creds to be issued against - licenseSchema := map[string]interface{}{ + licenseSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "licenseType": map[string]interface{}{ + "properties": map[string]any{ + "licenseType": map[string]any{ "type": "string", }, }, @@ -523,7 +523,7 @@ func TestManifestAPI(t *testing.T) { Issuer: issuerDID.DID.ID, Subject: applicantDID.DID.ID, JSONSchema: createdSchema.ID, - Data: map[string]interface{}{"licenseType": "WA-DL-CLASS-A"}, + Data: map[string]any{"licenseType": "WA-DL-CLASS-A"}, }) assert.NoError(tt, err) assert.NotEmpty(tt, createdCred) @@ -650,10 +650,10 @@ func TestManifestAPI(t *testing.T) { assert.NotEmpty(tt, applicantDID) // create a schema for the creds to be issued against - licenseSchema := map[string]interface{}{ + licenseSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "licenseType": map[string]interface{}{ + "properties": map[string]any{ + "licenseType": map[string]any{ "type": "string", }, }, @@ -668,7 +668,7 @@ func TestManifestAPI(t *testing.T) { Issuer: issuerDID.DID.ID, Subject: applicantDID.DID.ID, JSONSchema: createdSchema.ID, - Data: map[string]interface{}{"licenseType": "WA-DL-CLASS-A"}, + Data: map[string]any{"licenseType": "WA-DL-CLASS-A"}, }) assert.NoError(tt, err) assert.NotEmpty(tt, createdCred) @@ -797,10 +797,10 @@ func TestManifestAPI(t *testing.T) { assert.NotEmpty(tt, issuerDID) // create a schema for the creds to be issued against - licenseSchema := map[string]interface{}{ + licenseSchema := map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "licenseType": map[string]interface{}{ + "properties": map[string]any{ + "licenseType": map[string]any{ "type": "string", }, }, @@ -815,7 +815,7 @@ func TestManifestAPI(t *testing.T) { Issuer: issuerDID.DID.ID, Subject: applicantDID.DID.ID, JSONSchema: createdSchema.ID, - Data: map[string]interface{}{"licenseType": "WA-DL-CLASS-A"}, + Data: map[string]any{"licenseType": "WA-DL-CLASS-A"}, }) assert.NoError(tt, err) assert.NotEmpty(tt, createdCred) diff --git a/pkg/server/server_operation_test.go b/pkg/server/server_operation_test.go index aca2abcc5..01c9272a2 100644 --- a/pkg/server/server_operation_test.go +++ b/pkg/server/server_operation_test.go @@ -2,6 +2,11 @@ package server import ( "fmt" + "net/http" + "net/http/httptest" + "os" + "testing" + "github.com/TBD54566975/ssi-sdk/credential/exchange" "github.com/goccy/go-json" "github.com/google/go-cmp/cmp" @@ -11,10 +16,6 @@ import ( "github.com/tbd54566975/ssi-service/pkg/server/router" "github.com/tbd54566975/ssi-service/pkg/service/operation" "github.com/tbd54566975/ssi-service/pkg/storage" - "net/http" - "net/http/httptest" - "os" - "testing" ) func TestOperationsAPI(t *testing.T) { diff --git a/pkg/server/server_presentation_test.go b/pkg/server/server_presentation_test.go index b754b2181..ebbde08b0 100644 --- a/pkg/server/server_presentation_test.go +++ b/pkg/server/server_presentation_test.go @@ -2,6 +2,10 @@ package server import ( "fmt" + "net/http" + "net/http/httptest" + "testing" + "github.com/TBD54566975/ssi-sdk/credential" "github.com/TBD54566975/ssi-sdk/credential/exchange" "github.com/TBD54566975/ssi-sdk/credential/signing" @@ -20,9 +24,6 @@ import ( "github.com/tbd54566975/ssi-service/pkg/service/presentation" "github.com/tbd54566975/ssi-service/pkg/service/presentation/model" "github.com/tbd54566975/ssi-service/pkg/storage" - "net/http" - "net/http/httptest" - "testing" ) func TestPresentationAPI(t *testing.T) { @@ -497,7 +498,7 @@ func createSubmissionRequest(t *testing.T, definitionID string, vc credential.Ve Holder: holderDID.String(), Type: []string{credential.VerifiablePresentationType}, PresentationSubmission: ps, - VerifiableCredential: []interface{}{keyaccess.JWT(vcData)}, + VerifiableCredential: []any{keyaccess.JWT(vcData)}, Proof: nil, } diff --git a/pkg/server/server_schema_test.go b/pkg/server/server_schema_test.go index c0ca2b101..633322af2 100644 --- a/pkg/server/server_schema_test.go +++ b/pkg/server/server_schema_test.go @@ -288,17 +288,17 @@ func TestSchemaAPI(t *testing.T) { } func getTestSchema() schema.JSONSchema { - return map[string]interface{}{ + return map[string]any{ "$id": "https://example.com/foo.schema.json", "$schema": "http://json-schema.org/draft-07/schema#", "description": "foo schema", "type": "object", - "properties": map[string]interface{}{ - "foo": map[string]interface{}{ + "properties": map[string]any{ + "foo": map[string]any{ "type": "string", }, }, - "required": []interface{}{"foo"}, + "required": []any{"foo"}, "additionalProperties": false, } } diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index ed449ee3f..2fcc7a243 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -90,7 +90,7 @@ func TestReadinessAPI(t *testing.T) { assert.Len(t, resp.ServiceStatuses, 0) } -func newRequestValue(t *testing.T, data interface{}) io.Reader { +func newRequestValue(t *testing.T, data any) io.Reader { dataBytes, err := json.Marshal(data) require.NoError(t, err) require.NotEmpty(t, dataBytes) diff --git a/pkg/service/credential/model.go b/pkg/service/credential/model.go index b3a02084b..41c2d32f3 100644 --- a/pkg/service/credential/model.go +++ b/pkg/service/credential/model.go @@ -14,10 +14,10 @@ type CreateCredentialRequest struct { // A context is optional. If not present, we'll apply default, required context values. Context string `json:"context,omitempty"` // A schema is optional. If present, we'll attempt to look it up and validate the data against it. - JSONSchema string `json:"jsonSchema,omitempty"` - Data map[string]interface{} `json:"data,omitempty"` - Expiry string `json:"expiry,omitempty"` - Revocable bool `json:"revocable,omitempty"` + JSONSchema string `json:"jsonSchema,omitempty"` + Data map[string]any `json:"data,omitempty"` + Expiry string `json:"expiry,omitempty"` + Revocable bool `json:"revocable,omitempty"` // TODO(gabe) support more capabilities like signature type, format, status, and more. } diff --git a/pkg/service/credential/service.go b/pkg/service/credential/service.go index 810336a36..09b5235da 100644 --- a/pkg/service/credential/service.go +++ b/pkg/service/credential/service.go @@ -2,11 +2,12 @@ package credential import ( "fmt" - statussdk "github.com/TBD54566975/ssi-sdk/credential/status" - "github.com/google/uuid" "strconv" "time" + statussdk "github.com/TBD54566975/ssi-sdk/credential/status" + "github.com/google/uuid" + "github.com/TBD54566975/ssi-sdk/credential" schemalib "github.com/TBD54566975/ssi-sdk/credential/schema" didsdk "github.com/TBD54566975/ssi-sdk/did" @@ -502,7 +503,7 @@ func updateCredentialStatus(s Service, gotCred *credstorage.StoredCredential, re return nil, util.LoggingErrorMsg(err, "could not store credential") } - statusListCredentialID := gotCred.Credential.CredentialStatus.(map[string]interface{})["statusListCredential"].(string) + statusListCredentialID := gotCred.Credential.CredentialStatus.(map[string]any)["statusListCredential"].(string) if len(statusListCredentialID) == 0 { return nil, util.LoggingNewErrorf("problem with getting status list credential id") diff --git a/pkg/service/credential/storage/bolt.go b/pkg/service/credential/storage/bolt.go index 6b0ef9f9c..2ec4d8e25 100644 --- a/pkg/service/credential/storage/bolt.go +++ b/pkg/service/credential/storage/bolt.go @@ -2,12 +2,13 @@ package storage import ( "fmt" + "math/rand" + "strings" + "github.com/TBD54566975/ssi-sdk/credential/signing" "github.com/goccy/go-json" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "math/rand" - "strings" "github.com/tbd54566975/ssi-service/internal/util" "github.com/tbd54566975/ssi-service/pkg/storage" diff --git a/pkg/service/manifest/application.go b/pkg/service/manifest/application.go index 04b6cf9c7..16683a254 100644 --- a/pkg/service/manifest/application.go +++ b/pkg/service/manifest/application.go @@ -2,9 +2,10 @@ package manifest import ( "fmt" - "github.com/tbd54566975/ssi-service/pkg/jwt" "strings" + "github.com/tbd54566975/ssi-service/pkg/jwt" + "github.com/TBD54566975/ssi-sdk/credential/manifest" errresp "github.com/TBD54566975/ssi-sdk/error" "github.com/tbd54566975/ssi-service/internal/keyaccess" diff --git a/pkg/service/manifest/model.go b/pkg/service/manifest/model.go index f6d14a9b5..d955ff291 100644 --- a/pkg/service/manifest/model.go +++ b/pkg/service/manifest/model.go @@ -11,8 +11,8 @@ import ( // Manifest type CreateManifestRequest struct { - Name *string `json:"name,omitempty"` - Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` IssuerDID string `json:"issuerDid" validate:"required"` IssuerName *string `json:"issuerName,omitempty"` OutputDescriptors []manifestsdk.OutputDescriptor `json:"outputDescriptors" validate:"required,dive"` @@ -59,12 +59,12 @@ type SubmitApplicationRequest struct { Application manifestsdk.CredentialApplication `json:"application" validate:"required"` Credentials []cred.Container `json:"credentials,omitempty"` ApplicationJWT keyaccess.JWT `json:"applicationJwt,omitempty" validate:"required"` - ApplicationJSON map[string]interface{} `json:"applicationJson,omitempty"` + ApplicationJSON map[string]any `json:"applicationJson,omitempty"` } type SubmitApplicationResponse struct { Response manifestsdk.CredentialResponse `json:"response" validate:"required"` - Credentials []interface{} `json:"credentials,omitempty"` + Credentials []any `json:"credentials,omitempty"` ResponseJWT keyaccess.JWT `json:"responseJwt,omitempty" validate:"required"` } diff --git a/pkg/service/manifest/response.go b/pkg/service/manifest/response.go index 131be24ef..c3b8b0b4a 100644 --- a/pkg/service/manifest/response.go +++ b/pkg/service/manifest/response.go @@ -51,7 +51,7 @@ func (s Service) buildCredentialResponse(applicantDID, manifestID, applicationID Subject: applicantDID, JSONSchema: od.Schema, // TODO(gabe) need to add in data here to match the request + schema - Data: make(map[string]interface{}), + Data: make(map[string]any), } credentialResponse, err := s.credential.CreateCredential(credentialRequest) diff --git a/pkg/service/manifest/service.go b/pkg/service/manifest/service.go index c8df7b2f1..1f6e622e6 100644 --- a/pkg/service/manifest/service.go +++ b/pkg/service/manifest/service.go @@ -212,7 +212,7 @@ func (s Service) DeleteManifest(request DeleteManifestRequest) error { // CredentialResponseContainer represents what is signed over and return for a credential response type CredentialResponseContainer struct { Response manifest.CredentialResponse `json:"credential_response"` - Credentials []interface{} `json:"verifiableCredentials,omitempty"` + Credentials []any `json:"verifiableCredentials,omitempty"` } func (s Service) ProcessApplicationSubmission(request SubmitApplicationRequest) (*SubmitApplicationResponse, error) { diff --git a/pkg/service/operation/model.go b/pkg/service/operation/model.go index 71310845c..fef7c622d 100644 --- a/pkg/service/operation/model.go +++ b/pkg/service/operation/model.go @@ -2,10 +2,11 @@ package operation import ( "fmt" + "strings" + "github.com/TBD54566975/ssi-sdk/util" "github.com/tbd54566975/ssi-service/pkg/service/operation/storage" "go.einride.tech/aip/filtering" - "strings" ) type Result struct { diff --git a/pkg/service/operation/model_test.go b/pkg/service/operation/model_test.go index 8903db270..db8084cd9 100644 --- a/pkg/service/operation/model_test.go +++ b/pkg/service/operation/model_test.go @@ -1,8 +1,9 @@ package operation import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestSubmissionID(t *testing.T) { diff --git a/pkg/service/operation/service.go b/pkg/service/operation/service.go index 7ca01c970..71ab2439c 100644 --- a/pkg/service/operation/service.go +++ b/pkg/service/operation/service.go @@ -2,6 +2,8 @@ package operation import ( "fmt" + "strings" + sdkutil "github.com/TBD54566975/ssi-sdk/util" "github.com/goccy/go-json" "github.com/pkg/errors" @@ -12,7 +14,6 @@ import ( "github.com/tbd54566975/ssi-service/pkg/service/presentation/model" prestorage "github.com/tbd54566975/ssi-service/pkg/service/presentation/storage" "github.com/tbd54566975/ssi-service/pkg/storage" - "strings" ) type Service struct { diff --git a/pkg/service/operation/storage/bolt.go b/pkg/service/operation/storage/bolt.go index e52cb1440..4952bbe66 100644 --- a/pkg/service/operation/storage/bolt.go +++ b/pkg/service/operation/storage/bolt.go @@ -1,13 +1,14 @@ package storage import ( + "strings" + "github.com/goccy/go-json" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/tbd54566975/ssi-service/internal/util" "github.com/tbd54566975/ssi-service/pkg/storage" "go.einride.tech/aip/filtering" - "strings" ) const ( diff --git a/pkg/service/operation/storage/storage.go b/pkg/service/operation/storage/storage.go index 1ac3b4c20..e4e9b3c41 100644 --- a/pkg/service/operation/storage/storage.go +++ b/pkg/service/operation/storage/storage.go @@ -19,8 +19,8 @@ type StoredOperation struct { Response []byte `json:"response,omitempty"` } -func (s StoredOperation) FilterVariablesMap() map[string]interface{} { - return map[string]interface{}{ +func (s StoredOperation) FilterVariablesMap() map[string]any { + return map[string]any{ "done": s.Done, // "true" and "false" are currently being parsed as identifiers, so we need to pass in the values that they // evaluate to. Ideally, we should change them to be parsed as constants. That requires an upstream change in diff --git a/pkg/service/presentation/service.go b/pkg/service/presentation/service.go index 1061d8b0d..53605fc29 100644 --- a/pkg/service/presentation/service.go +++ b/pkg/service/presentation/service.go @@ -2,6 +2,7 @@ package presentation import ( "fmt" + "github.com/TBD54566975/ssi-sdk/credential/exchange" "github.com/TBD54566975/ssi-sdk/credential/signing" didsdk "github.com/TBD54566975/ssi-sdk/did" diff --git a/pkg/service/presentation/storage/bolt.go b/pkg/service/presentation/storage/bolt.go index 6f092cb11..7556aacfb 100644 --- a/pkg/service/presentation/storage/bolt.go +++ b/pkg/service/presentation/storage/bolt.go @@ -2,6 +2,7 @@ package storage import ( "fmt" + "github.com/goccy/go-json" "github.com/pkg/errors" "github.com/sirupsen/logrus" diff --git a/pkg/service/presentation/storage/storage.go b/pkg/service/presentation/storage/storage.go index 41b248878..97f4dc173 100644 --- a/pkg/service/presentation/storage/storage.go +++ b/pkg/service/presentation/storage/storage.go @@ -72,8 +72,8 @@ type StoredSubmission struct { Reason string `json:"reason"` } -func (s StoredSubmission) FilterVariablesMap() map[string]interface{} { - return map[string]interface{}{ +func (s StoredSubmission) FilterVariablesMap() map[string]any { + return map[string]any{ "status": s.Status.String(), } } diff --git a/pkg/storage/bolt.go b/pkg/storage/bolt.go index 827b8faa3..d2df74bd5 100644 --- a/pkg/storage/bolt.go +++ b/pkg/storage/bolt.go @@ -3,15 +3,14 @@ package storage import ( "bytes" "fmt" - "github.com/goccy/go-json" "strings" "time" + "github.com/goccy/go-json" "github.com/pkg/errors" "github.com/sirupsen/logrus" - bolt "go.etcd.io/bbolt" - "github.com/tbd54566975/ssi-service/internal/util" + bolt "go.etcd.io/bbolt" ) const ( @@ -162,7 +161,7 @@ func NewUpdater(values map[string]any) UpdaterWithMap { } func (u UpdaterWithMap) Update(v []byte) ([]byte, error) { - var model map[string]interface{} + var model map[string]any if err := json.Unmarshal(v, &model); err != nil { return nil, errors.Wrap(err, "unmarshalling json") } diff --git a/pkg/storage/bolt_test.go b/pkg/storage/bolt_test.go index c816eaa0a..55af21d0e 100644 --- a/pkg/storage/bolt_test.go +++ b/pkg/storage/bolt_test.go @@ -2,11 +2,12 @@ package storage import ( "fmt" + "os" + "testing" + "github.com/goccy/go-json" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "os" - "testing" ) func TestBoltDB(t *testing.T) { @@ -136,7 +137,7 @@ func setupBoltDB(t *testing.T) *BoltDB { t.Cleanup(func() { _ = db.Close() - os.Remove("test.db") + _ = os.Remove("test.db") }) return db } diff --git a/pkg/storage/filter.go b/pkg/storage/filter.go index 0469025d3..945e22f99 100644 --- a/pkg/storage/filter.go +++ b/pkg/storage/filter.go @@ -11,7 +11,7 @@ import ( // FilterVarsMapper is an interface that encapsulates the FilterVariablesMap method. This interface is meant to be // implemented by any object that wants to include support for filtering. type FilterVarsMapper interface { - FilterVariablesMap() map[string]interface{} + FilterVariablesMap() map[string]any } // IncludeFunc is a function that given a mapper object, decides whether the object should be included in the result.