diff --git a/credential/builder.go b/credential/builder.go index d3a338f5..5e7202b2 100644 --- a/credential/builder.go +++ b/credential/builder.go @@ -22,7 +22,7 @@ const ( // VerifiableCredentialBuilder uses the builder pattern to construct a verifiable credential type VerifiableCredentialBuilder struct { - // contexts and types are kept to avoid having cast to/from interface{} values + // contexts and types are kept to avoid having cast to/from any values contexts []string types []string *VerifiableCredential @@ -65,7 +65,7 @@ func (vcb *VerifiableCredentialBuilder) IsEmpty() bool { return reflect.DeepEqual(vcb, &VerifiableCredentialBuilder{}) } -func (vcb *VerifiableCredentialBuilder) AddContext(context interface{}) error { +func (vcb *VerifiableCredentialBuilder) AddContext(context any) error { if vcb.IsEmpty() { return errors.New(BuilderEmptyError) } @@ -88,7 +88,7 @@ func (vcb *VerifiableCredentialBuilder) SetID(id string) error { return nil } -func (vcb *VerifiableCredentialBuilder) AddType(t interface{}) error { +func (vcb *VerifiableCredentialBuilder) AddType(t any) error { if vcb.IsEmpty() { return errors.New(BuilderEmptyError) } @@ -102,7 +102,7 @@ func (vcb *VerifiableCredentialBuilder) AddType(t interface{}) error { return nil } -func (vcb *VerifiableCredentialBuilder) SetIssuer(issuer interface{}) error { +func (vcb *VerifiableCredentialBuilder) SetIssuer(issuer any) error { if vcb.IsEmpty() { return errors.New(BuilderEmptyError) } @@ -160,14 +160,14 @@ func (vcb *VerifiableCredentialBuilder) SetExpirationDate(dateTime string) error return nil } -func (vcb *VerifiableCredentialBuilder) SetCredentialStatus(status interface{}) error { +func (vcb *VerifiableCredentialBuilder) SetCredentialStatus(status any) error { if vcb.IsEmpty() { return errors.New(BuilderEmptyError) } statusMap, err := util.ToJSONMap(status) if err != nil { - return errors.Wrap(err, "status value not of required type map[string]interface{}") + return errors.Wrap(err, "status value not of required type map[string]any") } // check required properties @@ -233,7 +233,7 @@ func (vcb *VerifiableCredentialBuilder) SetTermsOfUse(terms []TermsOfUse) error return nil } -func (vcb *VerifiableCredentialBuilder) SetEvidence(evidence []interface{}) error { +func (vcb *VerifiableCredentialBuilder) SetEvidence(evidence []any) error { if vcb.IsEmpty() { return errors.New(BuilderEmptyError) } @@ -247,7 +247,7 @@ func (vcb *VerifiableCredentialBuilder) SetEvidence(evidence []interface{}) erro // VerifiablePresentationBuilder uses the builder pattern to construct a verifiable presentation type VerifiablePresentationBuilder struct { - // contexts and types are kept to avoid having cast to/from interface{} values + // contexts and types are kept to avoid having cast to/from any values contexts []string types []string *VerifiablePresentation @@ -289,7 +289,7 @@ func (vpb *VerifiablePresentationBuilder) IsEmpty() bool { return reflect.DeepEqual(vpb, &VerifiablePresentationBuilder{}) } -func (vpb *VerifiablePresentationBuilder) AddContext(context interface{}) error { +func (vpb *VerifiablePresentationBuilder) AddContext(context any) error { if vpb.IsEmpty() { return errors.New(BuilderEmptyError) } @@ -321,7 +321,7 @@ func (vpb *VerifiablePresentationBuilder) SetHolder(holder string) error { return nil } -func (vpb *VerifiablePresentationBuilder) AddType(t interface{}) error { +func (vpb *VerifiablePresentationBuilder) AddType(t any) error { if vpb.IsEmpty() { return errors.New(BuilderEmptyError) } @@ -335,7 +335,7 @@ func (vpb *VerifiablePresentationBuilder) AddType(t interface{}) error { return nil } -func (vpb *VerifiablePresentationBuilder) SetPresentationSubmission(ps interface{}) error { +func (vpb *VerifiablePresentationBuilder) SetPresentationSubmission(ps any) error { if vpb.IsEmpty() { return errors.New(BuilderEmptyError) } @@ -346,7 +346,7 @@ func (vpb *VerifiablePresentationBuilder) SetPresentationSubmission(ps interface // AddVerifiableCredentials appends the given credentials to the verifiable presentation. // It does not check for duplicates. -func (vpb *VerifiablePresentationBuilder) AddVerifiableCredentials(creds ...interface{}) error { +func (vpb *VerifiablePresentationBuilder) AddVerifiableCredentials(creds ...any) error { if vpb.IsEmpty() { return errors.New(BuilderEmptyError) } diff --git a/credential/builder_test.go b/credential/builder_test.go index 5e67be5f..2f0830eb 100644 --- a/credential/builder_test.go +++ b/credential/builder_test.go @@ -16,14 +16,14 @@ func TestCredential(t *testing.T) { knownType := []string{"VerifiableCredential", "AlumniCredential"} knownIssuer := "https://example.edu/issuers/565049" knownIssuanceDate := "2010-01-01T19:23:24Z" - knownSubject := map[string]interface{}{ + knownSubject := map[string]any{ "id": "did:example:ebfeb1f712ebc6f1c276e12ec21", - "alumniOf": map[string]interface{}{ + "alumniOf": map[string]any{ "id": "did:example:c276e12ec21ebfeb1f712ebc6f1", - "name": []interface{}{ - map[string]interface{}{"value": "Example University", + "name": []any{ + map[string]any{"value": "Example University", "lang": "en", - }, map[string]interface{}{ + }, map[string]any{ "value": "Exemple d'Université", "lang": "fr", }, @@ -119,7 +119,7 @@ func TestCredentialBuilder(t *testing.T) { assert.NoError(t, err) // reset issuer as an object without an id property - badIssuerObject := map[string]interface{}{ + badIssuerObject := map[string]any{ "issuer": "abcd", "bad": "efghi", } @@ -128,7 +128,7 @@ func TestCredentialBuilder(t *testing.T) { assert.Contains(t, err.Error(), "issuer object did not contain `id` property") // issuer object with an id property - goodIssuerObject := map[string]interface{}{ + goodIssuerObject := map[string]any{ "id": "issuer", } err = builder.SetIssuer(goodIssuerObject) @@ -227,12 +227,12 @@ func TestCredentialBuilder(t *testing.T) { assert.NoError(t, err) // empty evidence - err = builder.SetEvidence([]interface{}{}) + err = builder.SetEvidence([]any{}) assert.Error(t, err) assert.Contains(t, err.Error(), "evidence cannot be empty") // valid evidence - evidence := []interface{}{"evidence"} + evidence := []any{"evidence"} err = builder.SetEvidence(evidence) assert.NoError(t, err) @@ -303,7 +303,7 @@ func TestVerifiablePresentationBuilder(t *testing.T) { assert.NoError(t, err) // add two credentials - creds := []interface{}{ + creds := []any{ VerifiableCredential{ ID: "cred-1", Type: "type", diff --git a/credential/exchange/builder.go b/credential/exchange/builder.go index c4fd7a37..8b7e8cc5 100644 --- a/credential/exchange/builder.go +++ b/credential/exchange/builder.go @@ -134,7 +134,7 @@ func (pdb *PresentationDefinitionBuilder) SetSubmissionRequirements(requirements return nil } -func (pdb *PresentationDefinitionBuilder) SetFrame(frame interface{}) error { +func (pdb *PresentationDefinitionBuilder) SetFrame(frame any) error { if pdb.IsEmpty() { return errors.New(BuilderEmptyError) } diff --git a/credential/exchange/builder_test.go b/credential/exchange/builder_test.go index 5420eb15..1fb8e14f 100644 --- a/credential/exchange/builder_test.go +++ b/credential/exchange/builder_test.go @@ -117,7 +117,7 @@ func TestInputDescriptorBuilderProperties(t *testing.T) { } }`) - var props interface{} + var props any err := json.Unmarshal(b, &props) assert.NoError(t, err) @@ -169,7 +169,7 @@ func TestInputDescriptorBuilderRequired(t *testing.T) { } }`) - var props interface{} + var props any err := json.Unmarshal(b, &props) assert.NoError(t, err) diff --git a/credential/exchange/model.go b/credential/exchange/model.go index 414adbd0..f3eaebe7 100644 --- a/credential/exchange/model.go +++ b/credential/exchange/model.go @@ -76,7 +76,7 @@ type PresentationDefinition struct { SubmissionRequirements []SubmissionRequirement `json:"submission_requirements,omitempty" validate:"omitempty,dive"` // https://identity.foundation/presentation-exchange/#json-ld-framing-feature - Frame interface{} `json:"frame,omitempty"` + Frame any `json:"frame,omitempty"` } func (pd *PresentationDefinition) IsEmpty() bool { @@ -287,23 +287,23 @@ type RelationalConstraint struct { } type Filter struct { - Type string `json:"type,omitempty"` - Format string `json:"format,omitempty"` - Properties interface{} `json:"properties,omitempty"` - Required []string `json:"required,omitempty"` - AdditionalProperties bool `json:"additionalProperties,omitempty"` - Pattern string `json:"pattern,omitempty"` - Minimum interface{} `json:"minimum,omitempty"` - Maximum interface{} `json:"maximum,omitempty"` - MinLength int `json:"minLength,omitempty"` - MaxLength int `json:"maxLength,omitempty"` - ExclusiveMinimum interface{} `json:"exclusiveMinimum,omitempty"` - ExclusiveMaximum interface{} `json:"exclusiveMaximum,omitempty"` - Const interface{} `json:"const,omitempty"` - Enum []interface{} `json:"enum,omitempty"` - Not interface{} `json:"not,omitempty"` - AllOf interface{} `json:"allOf,omitempty"` - OneOf interface{} `json:"oneOf,omitempty"` + Type string `json:"type,omitempty"` + Format string `json:"format,omitempty"` + Properties any `json:"properties,omitempty"` + Required []string `json:"required,omitempty"` + AdditionalProperties bool `json:"additionalProperties,omitempty"` + Pattern string `json:"pattern,omitempty"` + Minimum any `json:"minimum,omitempty"` + Maximum any `json:"maximum,omitempty"` + MinLength int `json:"minLength,omitempty"` + MaxLength int `json:"maxLength,omitempty"` + ExclusiveMinimum any `json:"exclusiveMinimum,omitempty"` + ExclusiveMaximum any `json:"exclusiveMaximum,omitempty"` + Const any `json:"const,omitempty"` + Enum []any `json:"enum,omitempty"` + Not any `json:"not,omitempty"` + AllOf any `json:"allOf,omitempty"` + OneOf any `json:"oneOf,omitempty"` } // CredentialStatus https://identity.foundation/presentation-exchange/#credential-status-constraint-feature diff --git a/credential/exchange/request.go b/credential/exchange/request.go index 28167326..aebbe0e0 100644 --- a/credential/exchange/request.go +++ b/credential/exchange/request.go @@ -40,7 +40,7 @@ func BuildPresentationRequest(signer crypto.JWTSigner, pt PresentationRequestTyp // BuildJWTPresentationRequest builds a JWT representation of a presentation request func BuildJWTPresentationRequest(signer crypto.JWTSigner, def PresentationDefinition, target string) ([]byte, error) { - jwtValues := map[string]interface{}{ + jwtValues := map[string]any{ jwt.JwtIDKey: uuid.NewString(), jwt.IssuerKey: signer.KeyID(), jwt.AudienceKey: target, diff --git a/credential/exchange/request_test.go b/credential/exchange/request_test.go index 9b5589e1..73d5c24f 100644 --- a/credential/exchange/request_test.go +++ b/credential/exchange/request_test.go @@ -87,7 +87,7 @@ func getDummyPresentationDefinition() PresentationDefinition { } // turn two objects into json and compare value equality -func jsonEq(t *testing.T, a interface{}, b interface{}) { +func jsonEq(t *testing.T, a any, b any) { aBytes, err := json.Marshal(a) assert.NoError(t, err) bBytes, err := json.Marshal(b) diff --git a/credential/exchange/submission.go b/credential/exchange/submission.go index 0d6290a5..1c2cb920 100644 --- a/credential/exchange/submission.go +++ b/credential/exchange/submission.go @@ -57,7 +57,7 @@ func (pc *PresentationClaim) IsEmpty() bool { // GetClaimValue returns the value of the claim, since PresentationClaim is a union type. An error is returned if // no value is present in any of the possible embedded types. -func (pc *PresentationClaim) GetClaimValue() (interface{}, error) { +func (pc *PresentationClaim) GetClaimValue() (any, error) { if pc.Credential != nil { return *pc.Credential, nil } @@ -95,13 +95,13 @@ func (pc *PresentationClaim) GetClaimFormat() (string, error) { return "", errors.New("claim is empty") } -// GetClaimJSON gets the claim value and attempts to turn it into a generic go-JSON object represented by an interface{} -func (pc *PresentationClaim) GetClaimJSON() (map[string]interface{}, error) { +// GetClaimJSON gets the claim value and attempts to turn it into a generic go-JSON object represented by an any +func (pc *PresentationClaim) GetClaimJSON() (map[string]any, error) { claimValue, err := pc.GetClaimValue() if err != nil { return nil, err } - jsonClaim := make(map[string]interface{}) + jsonClaim := make(map[string]any) // need to handle the case where we already have a string, since we won't need to marshal it var claimBytes []byte @@ -151,7 +151,7 @@ type NormalizedClaim struct { // id for the claim ID string // go-json representation of the claim - Data map[string]interface{} + Data map[string]any // JWT_VC, JWT_VP, LDP_VC, LDP_VP, etc. Format string // Signing algorithm used for the claim (e.g. EdDSA, ES256, PS256, etc.). @@ -159,7 +159,7 @@ type NormalizedClaim struct { AlgOrProofType string } -// normalizePresentationClaims takes a set of Presentation Claims and turns them into map[string]interface{} as +// normalizePresentationClaims takes a set of Presentation Claims and turns them into map[string]any as // go-JSON representations. The claim format and signature algorithm type are noted as well. // This method is greedy, meaning it returns the set of claims it was able to normalize. func normalizePresentationClaims(claims []PresentationClaim) ([]NormalizedClaim, error) { @@ -196,7 +196,7 @@ func normalizePresentationClaims(claims []PresentationClaim) ([]NormalizedClaim, // processedClaim represents a claim that has been processed for an input descriptor along with relevant // information for building a valid descriptor_map in the resulting presentation submission type processedClaim struct { - claim map[string]interface{} + claim map[string]any SubmissionDescriptor } @@ -236,7 +236,7 @@ func BuildPresentationSubmissionVP(def PresentationDefinition, claims []Normaliz // check if claim already exists. if it has, we won't duplicate the claim var currIndex int - var claim map[string]interface{} + var claim map[string]any claimID := processedID.ClaimID if seen, ok := seenClaims[claimID]; ok { currIndex = seen @@ -285,7 +285,7 @@ type processedInputDescriptor struct { // ID of the claim ClaimID string // generic claim - Claim map[string]interface{} + Claim map[string]any // claim format Format string } @@ -293,7 +293,7 @@ type processedInputDescriptor struct { // limitedInputDescriptor is the claim data after being filtered/limited via JSON path type limitedInputDescriptor struct { Path string - Data interface{} + Data any } // processInputDescriptor runs the input evaluation algorithm described in the spec for a specific input descriptor @@ -387,8 +387,8 @@ func filterClaimsByFormat(claims []NormalizedClaim, format *ClaimFormat) []Norma } // constructLimitedClaim builds a limited disclosure/filtered claim from a set of filtered input descriptors -func constructLimitedClaim(limitedDescriptors []limitedInputDescriptor) map[string]interface{} { - result := make(map[string]interface{}) +func constructLimitedClaim(limitedDescriptors []limitedInputDescriptor) map[string]any { + result := make(map[string]any) for _, ld := range limitedDescriptors { curr := result @@ -407,12 +407,12 @@ func constructLimitedClaim(limitedDescriptors []limitedInputDescriptor) map[stri // if the path is not contained in the resulting JSON, create it if _, ok := curr[normalizedPart]; !ok { - curr[normalizedPart] = make(map[string]interface{}) + curr[normalizedPart] = make(map[string]any) } // make sure the value is represented in curr currVal, _ := curr[normalizedPart] - curr = currVal.(map[string]interface{}) + curr = currVal.(map[string]any) } // since we've gone to one short of the end, we need to repeat the process for the last element in the path @@ -437,7 +437,7 @@ func normalizeJSONPath(path string) string { // processInputDescriptorField applies all possible path values to a claim, and checks to see if any match. // if a path matches fulfilled will be set to true and no processed value will be returned. if limitDisclosure is // set to true, the processed value will be returned as well. -func processInputDescriptorField(field Field, claimData map[string]interface{}) (*limitedInputDescriptor, bool) { +func processInputDescriptorField(field Field, claimData map[string]any) (*limitedInputDescriptor, bool) { for _, path := range field.Path { pathedData, err := jsonpath.JsonPathLookup(claimData, path) if err == nil { diff --git a/credential/exchange/submission_test.go b/credential/exchange/submission_test.go index 64b3c218..f9d5bb21 100644 --- a/credential/exchange/submission_test.go +++ b/credential/exchange/submission_test.go @@ -287,13 +287,13 @@ func TestBuildPresentationSubmissionVP(t *testing.T) { vcBytesJWT, err := json.Marshal(vp.VerifiableCredential[1]) assert.NoError(tt, err) - var asVCJWT map[string]interface{} + var asVCJWT map[string]any err = json.Unmarshal(vcBytesJWT, &asVCJWT) assert.NoError(tt, err) assert.NotEmpty(tt, asVCJWT) assert.Equal(tt, "did:example:456", asVCJWT["sub"]) - assert.Equal(tt, "yellow", asVCJWT["vc"].(map[string]interface{})["credentialSubject"].(map[string]interface{})["color"]) + assert.Equal(tt, "yellow", asVCJWT["vc"].(map[string]any)["credentialSubject"].(map[string]any)["color"]) }) } @@ -599,19 +599,19 @@ func TestConstructLimitedClaim(t *testing.T) { credSubjRes, ok := result["credentialSubject"] assert.True(tt, ok) - id, ok := credSubjRes.(map[string]interface{})["id"] + id, ok := credSubjRes.(map[string]any)["id"] assert.True(tt, ok) assert.Contains(tt, id, "test-id") - favoritesRes, ok := credSubjRes.(map[string]interface{})["favorites"] + favoritesRes, ok := credSubjRes.(map[string]any)["favorites"] assert.True(tt, ok) assert.NotEmpty(tt, favoritesRes) - statesRes, ok := favoritesRes.(map[string]interface{})["citiesByState"] + statesRes, ok := favoritesRes.(map[string]any)["citiesByState"] assert.True(tt, ok) assert.Contains(tt, statesRes, "CA") - citiesRes, ok := statesRes.(map[string]interface{})["CA"] + citiesRes, ok := statesRes.(map[string]any)["CA"] assert.True(tt, ok) assert.Contains(tt, citiesRes, "Oakland") }) @@ -636,7 +636,7 @@ func TestConstructLimitedClaim(t *testing.T) { assert.True(tt, ok) assert.NotEmpty(tt, csValue) - addressValue, ok := csValue.(map[string]interface{})["address"] + addressValue, ok := csValue.(map[string]any)["address"] assert.True(tt, ok) assert.Contains(tt, addressValue, "road street") assert.Contains(tt, addressValue, "USA") @@ -645,13 +645,13 @@ func TestConstructLimitedClaim(t *testing.T) { func getTestVerifiableCredential() credential.VerifiableCredential { return credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential", Type: []string{"VerifiableCredential"}, Issuer: "test-issuer", IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id", "company": "Block", "website": "https://block.xyz", @@ -664,15 +664,15 @@ func getTestVerifiablePresentation() credential.VerifiablePresentation { Context: []string{"https://www.w3.org/2018/credentials/v1"}, ID: "test-verifiable-presentation", Type: []string{"VerifiablePresentation"}, - VerifiableCredential: []interface{}{ + VerifiableCredential: []any{ credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-vp-verifiable-credential", Type: []string{"VerifiableCredential"}, Issuer: "test-issuer", IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vp-vc-id", "company": "TBD", "github": "https://github.com/TBD54566975", @@ -767,25 +767,25 @@ func getTestJWTVerifiableCredential() string { return strings.ReplaceAll(noTabs, " ", "") } -func getGenericTestClaim() map[string]interface{} { - return map[string]interface{}{ - "@context": []interface{}{"https://www.w3.org/2018/credentials/v1", +func getGenericTestClaim() map[string]any { + return map[string]any{ + "@context": []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, "type": []string{"VerifiableCredential"}, "issuer": "did:example:123", "issuanceDate": "2021-01-01T19:23:24Z", - "credentialSubject": map[string]interface{}{ + "credentialSubject": map[string]any{ "id": "test-id", "firstName": "Satoshi", "lastName": "Nakamoto", - "address": map[string]interface{}{ + "address": map[string]any{ "number": 1, "street": "road street", "country": "USA", }, - "favorites": map[string]interface{}{ + "favorites": map[string]any{ "color": "blue", - "citiesByState": map[string]interface{}{ + "citiesByState": map[string]any{ "NY": []string{"NY"}, "CA": []string{"Oakland", "San Francisco"}, }, diff --git a/credential/exchange/verification.go b/credential/exchange/verification.go index 7c4aeca1..53da73a9 100644 --- a/credential/exchange/verification.go +++ b/credential/exchange/verification.go @@ -121,7 +121,7 @@ func VerifyPresentationSubmissionVP(def PresentationDefinition, vp credential.Ve return nil } -func toPresentationSubmission(maybePresentationSubmission interface{}) (*PresentationSubmission, error) { +func toPresentationSubmission(maybePresentationSubmission any) (*PresentationSubmission, error) { bytes, err := json.Marshal(maybePresentationSubmission) if err != nil { return nil, err @@ -133,7 +133,7 @@ func toPresentationSubmission(maybePresentationSubmission interface{}) (*Present return &submission, nil } -func findMatchingPath(claim interface{}, paths []string) error { +func findMatchingPath(claim any, paths []string) error { for _, path := range paths { if _, err := jsonpath.JsonPathLookup(claim, path); err == nil { return nil diff --git a/credential/exchange/verification_test.go b/credential/exchange/verification_test.go index 03b63283..5c3dfbf9 100644 --- a/credential/exchange/verification_test.go +++ b/credential/exchange/verification_test.go @@ -240,7 +240,7 @@ func TestVerifyPresentationSubmissionVP(t *testing.T) { }, }, }, - VerifiableCredential: []interface{}{ + VerifiableCredential: []any{ getTestVerifiableCredential(), }, } @@ -286,7 +286,7 @@ func TestVerifyPresentationSubmissionVP(t *testing.T) { vpBuilder := credential.NewVerifiablePresentationBuilder() assert.NoError(t, vpBuilder.SetPresentationSubmission(ps)) - assert.NoError(t, vpBuilder.AddVerifiableCredentials([]interface{}{string(vcData)}...)) + assert.NoError(t, vpBuilder.AddVerifiableCredentials([]any{string(vcData)}...)) vp2, err := vpBuilder.Build() assert.NoError(t, err) vp := *vp2 diff --git a/credential/manifest/model.go b/credential/manifest/model.go index 65999a4f..fb77812d 100644 --- a/credential/manifest/model.go +++ b/credential/manifest/model.go @@ -86,7 +86,7 @@ func (od *OutputDescriptor) IsValid() error { type CredentialApplicationWrapper struct { CredentialApplication CredentialApplication `json:"credential_application"` - Credentials []interface{} `json:"verifiableCredentials,omitempty"` + Credentials []any `json:"verifiableCredentials,omitempty"` } // CredentialApplication https://identity.foundation/credential-manifest/#credential-application @@ -123,7 +123,7 @@ func (ca *CredentialApplication) IsValid() error { type CredentialResponseWrapper struct { CredentialResponse CredentialResponse `json:"credential_response"` - Credentials []interface{} `json:"verifiableCredentials,omitempty"` + Credentials []any `json:"verifiableCredentials,omitempty"` } // CredentialResponse https://identity.foundation/credential-manifest/#credential-response diff --git a/credential/manifest/validation.go b/credential/manifest/validation.go index da319cb7..00bceaf0 100644 --- a/credential/manifest/validation.go +++ b/credential/manifest/validation.go @@ -16,7 +16,7 @@ import ( // IsValidCredentialApplicationForManifest validates the rules on how a credential manifest [cm] and credential // application [ca] relate to each other https://identity.foundation/credential-manifest/#credential-application // applicationAndCredsJSON is the credential application and credentials as a JSON object -func IsValidCredentialApplicationForManifest(cm CredentialManifest, applicationAndCredsJSON map[string]interface{}) (map[string]string, error) { +func IsValidCredentialApplicationForManifest(cm CredentialManifest, applicationAndCredsJSON map[string]any) (map[string]string, error) { var err error // parse out the application to its known object model @@ -176,7 +176,7 @@ func IsValidCredentialApplicationForManifest(cm CredentialManifest, applicationA continue } - // convert submitted claim vc to map[string]interface{} + // convert submitted claim vc to map[string]any cred, credErr := credutil.CredentialsFromInterface(submittedClaim) if credErr != nil { unfulfilledInputDescriptors[inputDescriptor.ID] = "failed to extract credential from json" @@ -196,7 +196,7 @@ func IsValidCredentialApplicationForManifest(cm CredentialManifest, applicationA // TODO(gabe) consider enforcing limited disclosure if present // for each field we need to verify at least one path matches - credMap := make(map[string]interface{}) + credMap := make(map[string]any) claimBytes, jsonErr := json.Marshal(cred) if jsonErr != nil { err = errresp.NewErrorResponseWithErrorAndMsg(errresp.CriticalError, err, "failed to marshal vc") @@ -224,7 +224,7 @@ func IsValidCredentialApplicationForManifest(cm CredentialManifest, applicationA return unfulfilledInputDescriptors, err } -func findMatchingPath(claim interface{}, paths []string) error { +func findMatchingPath(claim any, paths []string) error { for _, path := range paths { if _, err := jsonpath.JsonPathLookup(claim, path); err == nil { return nil diff --git a/credential/manifest/validation_test.go b/credential/manifest/validation_test.go index d2476521..19733697 100644 --- a/credential/manifest/validation_test.go +++ b/credential/manifest/validation_test.go @@ -20,7 +20,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -35,7 +35,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -52,7 +52,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -184,7 +184,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -201,7 +201,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -220,7 +220,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -236,7 +236,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -255,7 +255,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -278,7 +278,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -298,7 +298,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -312,7 +312,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { cm, ca := getValidTestCredManifestCredApplication(tt) credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -328,7 +328,7 @@ func TestIsValidCredentialApplicationForManifest(t *testing.T) { ca.CredentialApplication.PresentationSubmission = nil credAppRequestBytes, err := json.Marshal(ca) assert.NoError(tt, err) - request := make(map[string]interface{}) + request := make(map[string]any) err = json.Unmarshal(credAppRequestBytes, &request) assert.NoError(tt, err) @@ -372,7 +372,7 @@ func getValidTestCredManifestCredApplication(t *testing.T) (CredentialManifest, require.NotEmpty(t, vc) require.NoError(t, vc.IsValid()) - return cm, CredentialApplicationWrapper{CredentialApplication: ca, Credentials: []interface{}{vc}} + return cm, CredentialApplicationWrapper{CredentialApplication: ca, Credentials: []any{vc}} } func getValidTestCredManifestCredApplicationJWTCred(t *testing.T) (CredentialManifest, CredentialApplicationWrapper) { @@ -416,5 +416,5 @@ func getValidTestCredManifestCredApplicationJWTCred(t *testing.T) (CredentialMan require.NoError(t, err) require.NotEmpty(t, jwt) - return cm, CredentialApplicationWrapper{CredentialApplication: ca, Credentials: []interface{}{string(jwt)}} + return cm, CredentialApplicationWrapper{CredentialApplication: ca, Credentials: []any{string(jwt)}} } diff --git a/credential/model.go b/credential/model.go index ae5df39f..d93521d7 100644 --- a/credential/model.go +++ b/credential/model.go @@ -11,22 +11,22 @@ import ( // vc-data-model spec https://www.w3.org/TR/2021/REC-vc-data-model-20211109/#basic-concepts type VerifiableCredential struct { // Either a string or set of strings - Context interface{} `json:"@context" validate:"required"` - ID string `json:"id,omitempty"` + Context any `json:"@context" validate:"required"` + ID string `json:"id,omitempty"` // Either a string or a set of strings https://www.w3.org/TR/2021/REC-vc-data-model-20211109/#types - Type interface{} `json:"type" validate:"required"` + Type any `json:"type" validate:"required"` // either a URI or an object containing an `id` property. - Issuer interface{} `json:"issuer" validate:"required"` + Issuer any `json:"issuer" validate:"required"` // https://www.w3.org/TR/xmlschema11-2/#dateTimes - IssuanceDate string `json:"issuanceDate" validate:"required"` - ExpirationDate string `json:"expirationDate,omitempty"` - CredentialStatus interface{} `json:"credentialStatus,omitempty" validate:"omitempty,dive"` + IssuanceDate string `json:"issuanceDate" validate:"required"` + ExpirationDate string `json:"expirationDate,omitempty"` + CredentialStatus any `json:"credentialStatus,omitempty" validate:"omitempty,dive"` // This is where the subject's ID *may* be present CredentialSubject CredentialSubject `json:"credentialSubject" validate:"required"` CredentialSchema *CredentialSchema `json:"credentialSchema,omitempty" validate:"omitempty,dive"` RefreshService *RefreshService `json:"refreshService,omitempty" validate:"omitempty,dive"` TermsOfUse []TermsOfUse `json:"termsOfUse,omitempty" validate:"omitempty,dive"` - Evidence []interface{} `json:"evidence,omitempty" validate:"omitempty,dive"` + Evidence []any `json:"evidence,omitempty" validate:"omitempty,dive"` // For embedded proof support // Proof is a digital signature over a credential https://www.w3.org/TR/2021/REC-vc-data-model-20211109/#proofs-signatures Proof *crypto.Proof `json:"proof,omitempty"` @@ -46,7 +46,7 @@ type DefaultCredentialStatus struct { Type string `json:"type" validate:"required"` } -type CredentialSubject map[string]interface{} +type CredentialSubject map[string]any func (cs CredentialSubject) GetID() string { id := "" @@ -96,14 +96,14 @@ func (v *VerifiableCredential) IsValid() error { // VerifiablePresentation https://www.w3.org/TR/2021/REC-vc-data-model-20211109/#presentations-0 type VerifiablePresentation struct { // Either a string or set of strings - Context interface{} `json:"@context,omitempty"` - ID string `json:"id,omitempty"` - Holder string `json:"holder,omitempty"` - Type interface{} `json:"type" validate:"required"` + Context any `json:"@context,omitempty"` + ID string `json:"id,omitempty"` + Holder string `json:"holder,omitempty"` + Type any `json:"type" validate:"required"` // an optional field as a part of https://identity.foundation/presentation-exchange/#embed-targets - PresentationSubmission interface{} `json:"presentation_submission,omitempty"` + PresentationSubmission any `json:"presentation_submission,omitempty"` // Verifiable credential could be our object model, a JWT, or any other valid credential representation - VerifiableCredential []interface{} `json:"verifiableCredential,omitempty"` + VerifiableCredential []any `json:"verifiableCredential,omitempty"` Proof *crypto.Proof `json:"proof,omitempty"` } diff --git a/credential/schema/model.go b/credential/schema/model.go index 565ebca1..bb2e5f8c 100644 --- a/credential/schema/model.go +++ b/credential/schema/model.go @@ -7,7 +7,7 @@ const ( VCJSONSchemaType string = "https://w3c-ccg.github.io/vc-json-schemas/schema/2.0/schema.json" ) -type JSONSchema map[string]interface{} +type JSONSchema map[string]any // VCJSONSchema is the model representing the // credential json schema specification https://w3c-ccg.github.io/vc-json-schemas/v2/index.html#credential_schema_definition @@ -21,7 +21,7 @@ type VCJSONSchema struct { Schema JSONSchema `json:"schema"` } -func (vcs VCJSONSchema) GetProperty(propertyName string) (interface{}, error) { +func (vcs VCJSONSchema) GetProperty(propertyName string) (any, error) { got, ok := vcs.Schema[propertyName] if !ok { return "", fmt.Errorf("property<%s> not found in schema<%s>", propertyName, vcs.ID) diff --git a/credential/signing/jws_test.go b/credential/signing/jws_test.go index 8b4c5035..4d5366f4 100644 --- a/credential/signing/jws_test.go +++ b/credential/signing/jws_test.go @@ -10,11 +10,11 @@ import ( func TestVerifiableCredentialJWS(t *testing.T) { testCredential := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, - Type: []interface{}{"VerifiableCredential"}, + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, + Type: []any{"VerifiableCredential"}, Issuer: "did:example:123", IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{}, + CredentialSubject: map[string]any{}, } signer := getTestVectorKey0Signer(t) diff --git a/credential/signing/jwt.go b/credential/signing/jwt.go index 89198edc..8cc1e175 100644 --- a/credential/signing/jwt.go +++ b/credential/signing/jwt.go @@ -138,7 +138,7 @@ func ParseVerifiableCredentialFromJWT(token string) (*credential.VerifiableCrede subStr, ok := sub.(string) if hasSub && ok && subStr != "" { if cred.CredentialSubject == nil { - cred.CredentialSubject = make(map[string]interface{}) + cred.CredentialSubject = make(map[string]any) } cred.CredentialSubject[credential.VerifiableCredentialIDProperty] = subStr } diff --git a/credential/signing/jwt_test.go b/credential/signing/jwt_test.go index 3d34ceb7..e0910eae 100644 --- a/credential/signing/jwt_test.go +++ b/credential/signing/jwt_test.go @@ -13,11 +13,11 @@ import ( func TestVerifiableCredentialJWT(t *testing.T) { testCredential := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, Type: []string{"VerifiableCredential"}, Issuer: "did:example:123", IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{}, + CredentialSubject: map[string]any{}, } signer := getTestVectorKey0Signer(t) signed, err := SignVerifiableCredentialJWT(signer, testCredential) diff --git a/credential/status/statuslist2021.go b/credential/status/statuslist2021.go index e05613f3..e2639196 100644 --- a/credential/status/statuslist2021.go +++ b/credential/status/statuslist2021.go @@ -147,7 +147,7 @@ func prepareCredentialsForStatusList(purpose StatusPurpose, credentials []creden // determine whether the credential status property is of the expected format // additionally makes sure the status list has all required properties -func getStatusEntry(maybeCredentialStatus interface{}) (*StatusList2021Entry, error) { +func getStatusEntry(maybeCredentialStatus any) (*StatusList2021Entry, error) { statusBytes, err := json.Marshal(maybeCredentialStatus) if err != nil { return nil, errors.Wrap(err, "could not marshal credential status property") @@ -304,13 +304,13 @@ func ValidateCredentialInStatusList(credentialToValidate credential.VerifiableCr return false, nil } -func toStatusList2021Entry(credStatus interface{}) (*StatusList2021Entry, bool) { +func toStatusList2021Entry(credStatus any) (*StatusList2021Entry, bool) { statusListEntryValue, ok := credStatus.(StatusList2021Entry) if ok { return &statusListEntryValue, true } - credStatusMap, ok := credStatus.(map[string]interface{}) + credStatusMap, ok := credStatus.(map[string]any) if !ok { return nil, false } diff --git a/credential/status/statuslist2021_test.go b/credential/status/statuslist2021_test.go index 3e689b8c..26d4d0c5 100644 --- a/credential/status/statuslist2021_test.go +++ b/credential/status/statuslist2021_test.go @@ -15,13 +15,13 @@ func TestGenerateStatusList2021Credential(t *testing.T) { revocationID := "revocation-id" testIssuer := "test-issuer" testCred1 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-1", "company": "Block", "website": "https://block.xyz", @@ -35,13 +35,13 @@ func TestGenerateStatusList2021Credential(t *testing.T) { }, } testCred2 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-2", "company": "Block", "website": "https://block.xyz", @@ -77,13 +77,13 @@ func TestGenerateStatusList2021Credential(t *testing.T) { revocationID := "revocation-id" testIssuer := "test-issuer" testCred1 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-1", "company": "Block", "website": "https://block.xyz", @@ -97,13 +97,13 @@ func TestGenerateStatusList2021Credential(t *testing.T) { }, } testCred2 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-2", "company": "Block", "website": "https://block.xyz", @@ -127,13 +127,13 @@ func TestGenerateStatusList2021Credential(t *testing.T) { revocationID := "revocation-id" testIssuer := "test-issuer" testCred1 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-1", "company": "Block", "website": "https://block.xyz", @@ -147,13 +147,13 @@ func TestGenerateStatusList2021Credential(t *testing.T) { }, } testCred2 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-2", "company": "Block", "website": "https://block.xyz", @@ -185,13 +185,13 @@ func TestGenerateStatusList2021Credential(t *testing.T) { revocationID := "revocation-id" testIssuer := "test-issuer" testCred1 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-1", "company": "Block", "website": "https://block.xyz", @@ -214,13 +214,13 @@ func TestGenerateStatusList2021Credential(t *testing.T) { revocationID := "revocation-id" testIssuer := "test-issuer" testCred1 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-1", "company": "Block", "website": "https://block.xyz", @@ -245,13 +245,13 @@ func TestValidateCredentialInStatusList(t *testing.T) { revocationID := "revocation-id" testIssuer := "test-issuer" testCred1 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-1", "company": "Block", "website": "https://block.xyz", @@ -279,18 +279,18 @@ func TestValidateCredentialInStatusList(t *testing.T) { revocationID := "revocation-id" testIssuer := "test-issuer" testCred1 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-1", "company": "Block", "website": "https://block.xyz", }, - CredentialStatus: map[string]interface{}{ + CredentialStatus: map[string]any{ "id": revocationID, "type": "Block", "statusPurpose": "revocation", @@ -313,13 +313,13 @@ func TestValidateCredentialInStatusList(t *testing.T) { revocationID := "revocation-id" testIssuer := "test-issuer" testCred1 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-1", "company": "Block", "website": "https://block.xyz", @@ -333,13 +333,13 @@ func TestValidateCredentialInStatusList(t *testing.T) { }, } testCred2 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-2", "company": "Block", "website": "https://block.xyz", @@ -367,13 +367,13 @@ func TestValidateCredentialInStatusList(t *testing.T) { revocationID := "revocation-id" testIssuer := "test-issuer" testCred1 := credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential-2", Type: []string{"VerifiableCredential"}, Issuer: testIssuer, IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id-1", "company": "Block", "website": "https://block.xyz", diff --git a/credential/util/util.go b/credential/util/util.go index 89a79186..94f2731f 100644 --- a/credential/util/util.go +++ b/credential/util/util.go @@ -11,7 +11,7 @@ import ( ) // CredentialsFromInterface turn a generic cred into a known shape without maintaining the proof/signature wrapper -func CredentialsFromInterface(genericCred interface{}) (*credential.VerifiableCredential, error) { +func CredentialsFromInterface(genericCred any) (*credential.VerifiableCredential, error) { switch genericCred.(type) { case string: // JWT @@ -20,10 +20,10 @@ func CredentialsFromInterface(genericCred interface{}) (*credential.VerifiableCr return nil, errors.Wrap(err, "could not parse credential from JWT") } return cred, nil - case map[string]interface{}: + case map[string]any: // JSON var cred credential.VerifiableCredential - credMapBytes, err := json.Marshal(genericCred.(map[string]interface{})) + credMapBytes, err := json.Marshal(genericCred.(map[string]any)) if err != nil { return nil, errors.Wrap(err, "could not marshal credential map") } @@ -40,11 +40,11 @@ func CredentialsFromInterface(genericCred interface{}) (*credential.VerifiableCr } } -// ClaimAsJSON converts a claim with an unknown interface{} into the go-json representation of that credential. +// ClaimAsJSON converts a claim with an unknown any into the go-json representation of that credential. // claim can only be of type {string, map[string]interface, VerifiableCredential}. -func ClaimAsJSON(claim interface{}) (map[string]interface{}, error) { +func ClaimAsJSON(claim any) (map[string]any, error) { switch c := claim.(type) { - case map[string]interface{}: + case map[string]any: return c, nil default: } @@ -57,7 +57,7 @@ func ClaimAsJSON(claim interface{}) (map[string]interface{}, error) { if err != nil { return nil, errors.Wrap(err, "marshalling credential") } - var submittedClaim map[string]interface{} + var submittedClaim map[string]any if err := json.Unmarshal(vcData, &submittedClaim); err != nil { return nil, errors.Wrap(err, "unmarshalling credential") } diff --git a/credential/util/util_test.go b/credential/util/util_test.go index 23dd53d3..d439f3ab 100644 --- a/credential/util/util_test.go +++ b/credential/util/util_test.go @@ -82,10 +82,10 @@ func TestCredentialsFromInterface(t *testing.T) { func getTestCredential() credential.VerifiableCredential { return credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, Type: []string{"VerifiableCredential"}, Issuer: "did:example:123", IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{}, + CredentialSubject: map[string]any{}, } } diff --git a/credential/verification/verification.go b/credential/verification/verification.go index 00bc5201..6130771f 100644 --- a/credential/verification/verification.go +++ b/credential/verification/verification.go @@ -25,11 +25,11 @@ type ( // VerificationOption represents a single option that may be required for a verifier type VerificationOption struct { ID OptionKey - Option interface{} + Option any } // GetVerificationOption returns a verification option given an ID -func GetVerificationOption(opts []VerificationOption, id OptionKey) (interface{}, error) { +func GetVerificationOption(opts []VerificationOption, id OptionKey) (any, error) { for _, opt := range opts { if opt.ID == id { return opt.Option, nil diff --git a/credential/verification/verification_test.go b/credential/verification/verification_test.go index 4f914fa0..df9c9978 100644 --- a/credential/verification/verification_test.go +++ b/credential/verification/verification_test.go @@ -89,7 +89,7 @@ func TestVerifier(t *testing.T) { assert.Contains(tt, err.Error(), "missing properties: 'emailAddress'") // verify cred with schema, schema passed in, cred with good data - sampleCredential.CredentialSubject = map[string]interface{}{ + sampleCredential.CredentialSubject = map[string]any{ "id": "test-vc-id", "emailAddress": "grandma@aol.com", } @@ -104,14 +104,14 @@ func NoOpVerifier(_ credential.VerifiableCredential, _ ...VerificationOption) er func getSampleCredential() credential.VerifiableCredential { return credential.VerifiableCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, ID: "test-verifiable-credential", Type: []string{"VerifiableCredential"}, Issuer: "test-issuer", ExpirationDate: "2021-01-01T00:00:00Z", IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "test-vc-id", "company": "Block", "website": "https://block.xyz", diff --git a/credential/verification/verifiers.go b/credential/verification/verifiers.go index 178af339..868b6120 100644 --- a/credential/verification/verifiers.go +++ b/credential/verification/verifiers.go @@ -82,7 +82,7 @@ func VerifyJSONSchema(cred credential.VerifiableCredential, opts ...Verification return credschema.IsCredentialValidForVCJSONSchema(cred, *credSchema) } -func optionToCredentialSchema(maybeSchema interface{}) (*credschema.VCJSONSchema, error) { +func optionToCredentialSchema(maybeSchema any) (*credschema.VCJSONSchema, error) { schema, ok := maybeSchema.(string) if !ok { return nil, errors.New("the option provided must be a string value representing a Verifiable Credential JSON Schema") diff --git a/crypto/jwt.go b/crypto/jwt.go index 3e57ac2c..0db10b79 100644 --- a/crypto/jwt.go +++ b/crypto/jwt.go @@ -111,7 +111,7 @@ func jwkVerifierFromKey(kid string, key jwk.Key) (jwk.Key, *jwa.SignatureAlgorit return jwtSignerVerifier(kid, key) } -func jwtSignerVerifier(kid string, key interface{}) (jwk.Key, *jwa.SignatureAlgorithm, error) { +func jwtSignerVerifier(kid string, key any) (jwk.Key, *jwa.SignatureAlgorithm, error) { jwkBytes, err := json.Marshal(key) if err != nil { return nil, nil, err @@ -147,7 +147,7 @@ func (s *JWTSigner) GetSigningAlgorithm() string { } // SignJWT takes a set of JWT keys and values to add to a JWT before singing them with the key defined in the signer -func (s *JWTSigner) SignJWT(kvs map[string]interface{}) ([]byte, error) { +func (s *JWTSigner) SignJWT(kvs map[string]any) ([]byte, error) { t := jwt.New() // set known default values, which can be overridden by the kvs diff --git a/crypto/jwt_test.go b/crypto/jwt_test.go index d0c9eb5f..8b259a3f 100644 --- a/crypto/jwt_test.go +++ b/crypto/jwt_test.go @@ -46,7 +46,7 @@ func TestJsonWebSignature2020TestVectorJWT(t *testing.T) { func TestSignVerifyJWTForEachSupportedKeyType(t *testing.T) { testKID := "test-kid" - testData := map[string]interface{}{ + testData := map[string]any{ "test": "data", } @@ -109,10 +109,10 @@ func TestSignVerifyGenericJWT(t *testing.T) { verifier, err := signer.ToVerifier() assert.NoError(t, err) - jwtData := map[string]interface{}{ + jwtData := map[string]any{ "id": "abcd", "jti": "1234", - "data": []interface{}{"one", "two", "three"}, + "data": []any{"one", "two", "three"}, "more_data": map[string]int{ "a": 1, "b": 2, @@ -146,7 +146,7 @@ func TestSignVerifyGenericJWT(t *testing.T) { gotData, ok := parsed.Get("data") assert.True(t, ok) - assert.EqualValues(t, []interface{}{"one", "two", "three"}, gotData) + assert.EqualValues(t, []any{"one", "two", "three"}, gotData) _, err = verifier.VerifyAndParseJWT(string(token)) assert.NoError(t, err) diff --git a/crypto/models.go b/crypto/models.go index 6ab5f926..73f11284 100644 --- a/crypto/models.go +++ b/crypto/models.go @@ -1,7 +1,7 @@ package crypto type ( - Proof interface{} + Proof any KeyType string HashType string SignatureAlgorithm string diff --git a/cryptosuite/cryptosuite.go b/cryptosuite/cryptosuite.go index f40c7e2c..c7695d1d 100644 --- a/cryptosuite/cryptosuite.go +++ b/cryptosuite/cryptosuite.go @@ -40,7 +40,7 @@ type CryptoSuiteInfo interface { // It encapsulates the functionality defined by the data integrity proof type specification // https://w3c-ccg.github.io/data-integrity-spec/#creating-new-proof-types type CryptoSuiteProofType interface { - Marshal(data interface{}) ([]byte, error) + Marshal(data any) ([]byte, error) Canonicalize(marshaled []byte) (*string, error) // CreateVerifyHash https://w3c-ccg.github.io/data-integrity-spec/#create-verify-hash-algorithm CreateVerifyHash(provable Provable, proof crypto.Proof, proofOptions *ProofOptions) ([]byte, error) @@ -76,17 +76,17 @@ type Verifier interface { type ProofOptions struct { // JSON-LD contexts to add to the proof - Contexts []interface{} + Contexts []any } // GetContextsFromProvable searches from a Linked Data `@context` property in the document and returns the value // associated with the context, if it exists. -func GetContextsFromProvable(p Provable) ([]interface{}, error) { +func GetContextsFromProvable(p Provable) ([]any, error) { provableBytes, err := json.Marshal(p) if err != nil { return nil, err } - var genericProvable map[string]interface{} + var genericProvable map[string]any if err := json.Unmarshal(provableBytes, &genericProvable); err != nil { return nil, err } @@ -102,7 +102,7 @@ func GetContextsFromProvable(p Provable) ([]interface{}, error) { } // attempt to verify that string context(s) exist in the context interface -func ensureRequiredContexts(context []interface{}, requiredContexts []string) []interface{} { +func ensureRequiredContexts(context []any, requiredContexts []string) []any { required := make(map[string]bool) for _, v := range requiredContexts { required[v] = true diff --git a/cryptosuite/jwssignaturesuite.go b/cryptosuite/jwssignaturesuite.go index afc42f98..b982027f 100644 --- a/cryptosuite/jwssignaturesuite.go +++ b/cryptosuite/jwssignaturesuite.go @@ -136,7 +136,7 @@ func (j JWSSignatureSuite) Verify(v Verifier, p Provable) error { // CryptoSuiteProofType interface -func (JWSSignatureSuite) Marshal(data interface{}) ([]byte, error) { +func (JWSSignatureSuite) Marshal(data any) ([]byte, error) { // JSONify the provable object jsonBytes, err := json.Marshal(data) if err != nil { @@ -147,7 +147,7 @@ func (JWSSignatureSuite) Marshal(data interface{}) ([]byte, error) { func (JWSSignatureSuite) Canonicalize(marshaled []byte) (*string, error) { // the LD library anticipates a generic golang json object to normalize - var generic map[string]interface{} + var generic map[string]any if err := json.Unmarshal(marshaled, &generic); err != nil { return nil, err } @@ -223,7 +223,7 @@ func (j JWSSignatureSuite) prepareProof(proof crypto.Proof, opts *ProofOptions) return nil, err } - var genericProof map[string]interface{} + var genericProof map[string]any if err = json.Unmarshal(proofBytes, &genericProof); err != nil { return nil, err } @@ -237,7 +237,7 @@ func (j JWSSignatureSuite) prepareProof(proof crypto.Proof, opts *ProofOptions) genericProof["created"] = GetRFC3339Timestamp() } - var contexts []interface{} + var contexts []any if opts != nil { contexts = opts.Contexts } else { @@ -263,7 +263,7 @@ func FromGenericProof(p crypto.Proof) (*JSONWebSignature2020Proof, error) { if err != nil { return nil, err } - var generic map[string]interface{} + var generic map[string]any if err = json.Unmarshal(proofBytes, &generic); err != nil { return nil, err } diff --git a/cryptosuite/jwssignaturesuite_test.go b/cryptosuite/jwssignaturesuite_test.go index 83a311c7..2f72e168 100644 --- a/cryptosuite/jwssignaturesuite_test.go +++ b/cryptosuite/jwssignaturesuite_test.go @@ -10,18 +10,18 @@ import ( ) type TestCredential struct { - Context interface{} `json:"@context" validate:"required"` + Context any `json:"@context" validate:"required"` ID string `json:"id,omitempty"` - Type interface{} `json:"type" validate:"required"` - Issuer interface{} `json:"issuer" validate:"required"` + Type any `json:"type" validate:"required"` + Issuer any `json:"issuer" validate:"required"` IssuanceDate string `json:"issuanceDate" validate:"required"` ExpirationDate string `json:"expirationDate,omitempty"` - CredentialStatus interface{} `json:"credentialStatus,omitempty" validate:"omitempty,dive"` - CredentialSubject interface{} `json:"credentialSubject" validate:"required"` - CredentialSchema interface{} `json:"credentialSchema,omitempty" validate:"omitempty,dive"` - RefreshService interface{} `json:"refreshService,omitempty" validate:"omitempty,dive"` - TermsOfUse []interface{} `json:"termsOfUse,omitempty" validate:"omitempty,dive"` - Evidence []interface{} `json:"evidence,omitempty" validate:"omitempty,dive"` + CredentialStatus any `json:"credentialStatus,omitempty" validate:"omitempty,dive"` + CredentialSubject any `json:"credentialSubject" validate:"required"` + CredentialSchema any `json:"credentialSchema,omitempty" validate:"omitempty,dive"` + RefreshService any `json:"refreshService,omitempty" validate:"omitempty,dive"` + TermsOfUse []any `json:"termsOfUse,omitempty" validate:"omitempty,dive"` + Evidence []any `json:"evidence,omitempty" validate:"omitempty,dive"` Proof *crypto.Proof `json:"proof,omitempty"` } @@ -111,12 +111,12 @@ func TestJsonWebSignature2020AllKeyTypes(t *testing.T) { suite := GetJSONWebSignature2020Suite() testCred := TestCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, Type: []string{"VerifiableCredential"}, Issuer: "did:example:123", IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "did:example:abcd", "firstName": "Satoshi", "lastName": "Nakamoto", @@ -153,19 +153,19 @@ func TestJsonWebSignature2020AllKeyTypes(t *testing.T) { func TestCredentialLDProof(t *testing.T) { issuer := "https://example.edu/issuers/565049" knownCred := TestCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", "https://www.w3.org/2018/credentials/examples/v1"}, + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://www.w3.org/2018/credentials/examples/v1"}, ID: "http://example.edu/credentials/1872", - Type: []interface{}{"VerifiableCredential", "AlumniCredential"}, + Type: []any{"VerifiableCredential", "AlumniCredential"}, Issuer: issuer, IssuanceDate: "2010-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "did:example:ebfeb1f712ebc6f1c276e12ec21", - "alumniOf": map[string]interface{}{ + "alumniOf": map[string]any{ "id": "did:example:c276e12ec21ebfeb1f712ebc6f1", - "name": []interface{}{ - map[string]interface{}{"value": "Example University", + "name": []any{ + map[string]any{"value": "Example University", "lang": "en", - }, map[string]interface{}{ + }, map[string]any{ "value": "Exemple d'Université", "lang": "fr", }, @@ -226,11 +226,11 @@ func TestJsonWebSignature2020TestVectorCredential0(t *testing.T) { // https://github.com/decentralized-identity/JWS-Test-Suite/blob/main/data/credentials/credential-0.json knownCred := TestCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, Type: []string{"VerifiableCredential"}, Issuer: "did:example:123", IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{}, + CredentialSubject: map[string]any{}, } suite := GetJSONWebSignature2020Suite() @@ -267,12 +267,12 @@ func TestJsonWebSignature2020TestVectorsCredential1(t *testing.T) { // https://github.com/decentralized-identity/JWS-Test-Suite/blob/main/data/credentials/credential-1.json knownCred := TestCredential{ - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1", map[string]string{"@vocab": "https://example.com/#"}}, + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1", map[string]string{"@vocab": "https://example.com/#"}}, Type: []string{"VerifiableCredential"}, Issuer: "did:example:123", IssuanceDate: "2021-01-01T19:23:24Z", ExpirationDate: "2031-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "did:example:456", "type": "Person", }, @@ -291,11 +291,11 @@ func TestJsonWebSignature2020TestVectorsCredential1(t *testing.T) { } type TestVerifiablePresentation struct { - Context interface{} `json:"@context,omitempty"` + Context any `json:"@context,omitempty"` ID string `json:"id,omitempty"` Holder string `json:"holder,omitempty"` - Type interface{} `json:"type" validate:"required"` - PresentationSubmission interface{} `json:"presentation_submission,omitempty"` + Type any `json:"type" validate:"required"` + PresentationSubmission any `json:"presentation_submission,omitempty"` VerifiableCredential []TestCredential `json:"verifiableCredential,omitempty" validate:"omitempty,dive"` Proof *crypto.Proof `json:"proof,omitempty"` } @@ -334,7 +334,7 @@ func TestJsonWebSignature2020TestVectorPresentation0(t *testing.T) { // verify against known working impl // https://identity.foundation/JWS-Test-Suite/implementations/transmute/presentation-0--key-0-ed25519.vp.json - var knownProof crypto.Proof = map[string]interface{}{ + var knownProof crypto.Proof = map[string]any{ "type": "JsonWebSignature2020", "proofPurpose": "authentication", "challenge": "123", @@ -355,7 +355,7 @@ func TestJsonWebSignature2020TestVectorPresentation1(t *testing.T) { signer, jwk := getTestVectorKey0Signer(t, Authentication) // https://github.com/decentralized-identity/JWS-Test-Suite/blob/main/data/presentations/presentation-1.json - var credProof crypto.Proof = map[string]interface{}{ + var credProof crypto.Proof = map[string]any{ "type": "JsonWebSignature2020", "created": "2021-10-02T17:58:00Z", "proofPurpose": "assertionMethod", @@ -370,19 +370,19 @@ func TestJsonWebSignature2020TestVectorPresentation1(t *testing.T) { Type: []string{"VerifiablePresentation"}, VerifiableCredential: []TestCredential{ { - Context: []interface{}{"https://www.w3.org/2018/credentials/v1", + Context: []any{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1", - map[string]interface{}{ + map[string]any{ "@vocab": "https://example.com/#", }}, Type: []string{"VerifiableCredential"}, Issuer: "did:example:123", IssuanceDate: "2021-01-01T19:23:24Z", - CredentialSubject: map[string]interface{}{ + CredentialSubject: map[string]any{ "id": "did:example:456", }, - Evidence: []interface{}{ - map[string]interface{}{ + Evidence: []any{ + map[string]any{ "id": "https://example.edu/evidence/f2aeec97-fc0d-42bf-8ca7-0548192d4231", "type": []string{"DocumentVerification"}, "verifier": "https://example.edu/issuers/14", @@ -390,7 +390,7 @@ func TestJsonWebSignature2020TestVectorPresentation1(t *testing.T) { "subjectPresence": "Physical", "documentPresence": "Physical", }, - map[string]interface{}{ + map[string]any{ "id": "https://example.edu/evidence/f2aeec97-fc0d-42bf-8ca7-0548192dxyzab", "type": []string{"SupportingActivity"}, "verifier": "https://example.edu/issuers/14", @@ -418,7 +418,7 @@ func TestJsonWebSignature2020TestVectorPresentation1(t *testing.T) { // verify against known working impl // https://identity.foundation/JWS-Test-Suite/implementations/transmute/presentation-1--key-0-ed25519.vp.json - var knownProof crypto.Proof = map[string]interface{}{ + var knownProof crypto.Proof = map[string]any{ "type": "JsonWebSignature2020", "created": "2022-03-08T23:38:19Z", "verificationMethod": "did:example:123#key-0", diff --git a/did/builder.go b/did/builder.go index 56030c94..d6230eb0 100644 --- a/did/builder.go +++ b/did/builder.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" ) -// contexts and types are kept to avoid having cast to/from interface{} values +// contexts and types are kept to avoid having cast to/from any values type DIDDocumentBuilder struct { contexts []string types []string @@ -55,7 +55,7 @@ func (builder *DIDDocumentBuilder) IsEmpty() bool { return reflect.DeepEqual(builder, &DIDDocumentBuilder{}) } -func (builder *DIDDocumentBuilder) AddContext(context interface{}) error { +func (builder *DIDDocumentBuilder) AddContext(context any) error { if builder.IsEmpty() { return errors.New(BuilderEmptyError) } diff --git a/did/model.go b/did/model.go index b15a0f6d..b75fd45f 100644 --- a/did/model.go +++ b/did/model.go @@ -71,7 +71,7 @@ type DIDResolutionMetadata struct { // DIDDocument is a representation of the did core specification https://www.w3.org/TR/did-core // TODO(gabe) enforce validation of DID syntax https://www.w3.org/TR/did-core/#did-syntax type DIDDocument struct { - Context interface{} `json:"@context,omitempty"` + Context any `json:"@context,omitempty"` // As per https://www.w3.org/TR/did-core/#did-subject intermediate representations of DID Documents do not // require an ID property. The provided test vectors demonstrate IRs. As such, the property is optional. ID string `json:"id,omitempty"` @@ -103,7 +103,7 @@ type VerificationMethod struct { // `capabilityInvocation`, and `capabilityDelegation` types. // A set of one or more verification methods. Each verification method MAY be embedded or referenced. // TODO(gabe) consider changing this to a custom unmarshaler https://stackoverflow.com/a/28016508 -type VerificationMethodSet interface{} +type VerificationMethodSet any // Service is a property compliant with the did-core spec https://www.w3.org/TR/did-core/#services type Service struct { @@ -111,9 +111,9 @@ type Service struct { Type string `json:"type" validate:"required"` // A string, map, or set composed of one or more strings and/or maps // All string values must be valid URIs - ServiceEndpoint interface{} `json:"serviceEndpoint" validate:"required"` - RoutingKeys []string `json:"routingKeys,omitempty"` - Accept []string `json:"accept,omitempty"` + ServiceEndpoint any `json:"serviceEndpoint" validate:"required"` + RoutingKeys []string `json:"routingKeys,omitempty"` + Accept []string `json:"accept,omitempty"` } func (s *Service) IsValid() bool { diff --git a/did/peer.go b/did/peer.go index 4548a73b..f2fcc40d 100644 --- a/did/peer.go +++ b/did/peer.go @@ -153,7 +153,7 @@ func (PeerMethod1) Method() Method { // PeerMethod2 Method 2: multiple inception key without doc type PeerMethod2 struct { KT crypto.KeyType - Values []interface{} + Values []any } func (PeerMethod2) Method() Method { diff --git a/did/peer_test.go b/did/peer_test.go index a95bcc07..1ad81f95 100644 --- a/did/peer_test.go +++ b/did/peer_test.go @@ -209,7 +209,7 @@ func TestPeerMethod2(t *testing.T) { Accept: []string{"didcomm/v2"}, } - m2 := PeerMethod2{KT: kt, Values: []interface{}{pubKey, service}} + m2 := PeerMethod2{KT: kt, Values: []any{pubKey, service}} did, err := m2.Generate() assert.NoError(t, err) diff --git a/did/resolver.go b/did/resolver.go index 8b9dcb6c..ef185c5d 100644 --- a/did/resolver.go +++ b/did/resolver.go @@ -8,7 +8,7 @@ import ( ) // ResolutionOptions https://www.w3.org/TR/did-spec-registries/#did-resolution-options -type ResolutionOptions interface{} +type ResolutionOptions any // Resolution provides an interface for resolving DIDs as per the spec https://www.w3.org/TR/did-core/#did-resolution type Resolution interface { diff --git a/error/response.go b/error/response.go index 0e3017f7..954333d6 100644 --- a/error/response.go +++ b/error/response.go @@ -38,7 +38,7 @@ func NewErrorResponse(errorType Type, errorMessage string) *Response { } } -func NewErrorResponsef(errorType Type, msg string, a ...interface{}) *Response { +func NewErrorResponsef(errorType Type, msg string, a ...any) *Response { return &Response{ Valid: isApplicationErr(errorType), ErrorType: errorType, @@ -62,7 +62,7 @@ func NewErrorResponseWithErrorAndMsg(errorType Type, err error, msg string) *Res } } -func NewErrorResponseWithErrorAndMsgf(errorType Type, err error, msg string, a ...interface{}) *Response { +func NewErrorResponseWithErrorAndMsgf(errorType Type, err error, msg string, a ...any) *Response { return &Response{ Valid: isApplicationErr(errorType), ErrorType: errorType, diff --git a/example/manifest/manifest.go b/example/manifest/manifest.go index f2aef277..1c74a085 100644 --- a/example/manifest/manifest.go +++ b/example/manifest/manifest.go @@ -38,25 +38,25 @@ func prepareResultingCredentialSchema(issuerDID string) schema.VCJSONSchema { Name: "Drivers License Schema", Author: issuerDID, Authored: time.Now().Format(time.RFC3339), - Schema: map[string]interface{}{ + Schema: map[string]any{ "id": "ca-dmv-drivers-license-schema-1.0", "$schema": "https://json-schema.org/draft/2019-09/schema", "description": "CA DMV Drivers License Schema", "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", }, - "dateOfBirth": map[string]interface{}{ + "dateOfBirth": map[string]any{ "type": "string", }, - "licenseNumber": map[string]interface{}{ + "licenseNumber": map[string]any{ "type": "string", }, - "licenseClass": map[string]interface{}{ + "licenseClass": map[string]any{ "type": "string", }, }, @@ -205,7 +205,7 @@ func issueApplicationCredential(id did.DIDKey, s schema.VCJSONSchema) (*credenti return nil, err } - if err := builder.SetCredentialSubject(map[string]interface{}{ + if err := builder.SetCredentialSubject(map[string]any{ "id": id.String(), "firstName": "Satoshi", "lastName": "Nakamoto", @@ -292,7 +292,7 @@ func issueDriversLicenseCredential(issuerDID did.DIDKey, subjectDID string, s sc return nil, err } - if err := builder.SetCredentialSubject(map[string]interface{}{ + if err := builder.SetCredentialSubject(map[string]any{ "id": subjectDID, "firstName": data.FirstName, "lastName": data.LastName, diff --git a/example/usecase/apartment_application/apartment_application.go b/example/usecase/apartment_application/apartment_application.go index 799b0132..63145db3 100644 --- a/example/usecase/apartment_application/apartment_application.go +++ b/example/usecase/apartment_application/apartment_application.go @@ -62,7 +62,7 @@ func main() { knownIssuer := govtDIDKey knownIssuanceDate := "2020-01-01T19:23:24Z" - knownSubject := map[string]interface{}{ + knownSubject := map[string]any{ "id": string(*holderDIDKey), "birthdate": "1975-01-01", } diff --git a/example/usecase/employer_university_flow/pkg/issuer.go b/example/usecase/employer_university_flow/pkg/issuer.go index 9e10d9d5..32e6fe76 100644 --- a/example/usecase/employer_university_flow/pkg/issuer.go +++ b/example/usecase/employer_university_flow/pkg/issuer.go @@ -22,14 +22,14 @@ func BuildExampleUniversityVC(universityID, recipient string) (*credential.Verif knownType := []string{"VerifiableCredential", "AlumniCredential"} knownIssuer := "https://example.edu/issuers/565049" knownIssuanceDate := time.Now().Format(time.RFC3339) - knownSubject := map[string]interface{}{ + knownSubject := map[string]any{ "id": universityID, // did:: - "alumniOf": map[string]interface{}{ // claims are here + "alumniOf": map[string]any{ // claims are here "id": recipient, - "name": []interface{}{ - map[string]interface{}{"value": "Example University", + "name": []any{ + map[string]any{"value": "Example University", "lang": "en", - }, map[string]interface{}{ + }, map[string]any{ "value": "Exemple d'Université", "lang": "fr", }, diff --git a/example/usecase/employer_university_flow/pkg/util.go b/example/usecase/employer_university_flow/pkg/util.go index 9ac47ad7..1960e5ce 100644 --- a/example/usecase/employer_university_flow/pkg/util.go +++ b/example/usecase/employer_university_flow/pkg/util.go @@ -104,7 +104,7 @@ func MakePresentationRequest(jwk cryptosuite.JSONWebKey2020, presentationData ex return requestJWTBytes, signer, err } -// normalizePresentationClaims takes a set of Presentation Claims and turns them into map[string]interface{} as +// normalizePresentationClaims takes a set of Presentation Claims and turns them into map[string]any as // go-JSON representations. The claim format and signature algorithm type are noted as well. // This method is greedy, meaning it returns the set of claims it was able to normalize. func normalizePresentationClaims(claims []exchange.PresentationClaim) []exchange.NormalizedClaim { diff --git a/example/vc/vc.go b/example/vc/vc.go index 974f9fa9..86df86bf 100644 --- a/example/vc/vc.go +++ b/example/vc/vc.go @@ -22,14 +22,14 @@ func main() { knownType := []string{"VerifiableCredential", "AlumniCredential"} knownIssuer := "https://example.edu/issuers/565049" knownIssuanceDate := "2010-01-01T19:23:24Z" - knownSubject := map[string]interface{}{ + knownSubject := map[string]any{ "id": "did:example:ebfeb1f712ebc6f1c276e12ec21", // did:: - "alumniOf": map[string]interface{}{ // claims are here + "alumniOf": map[string]any{ // claims are here "id": "did:example:c276e12ec21ebfeb1f712ebc6f1", - "name": []interface{}{ - map[string]interface{}{"value": "Example University", + "name": []any{ + map[string]any{"value": "Example University", "lang": "en", - }, map[string]interface{}{ + }, map[string]any{ "value": "Exemple d'Université", "lang": "fr", }, diff --git a/schema/jsonschema.go b/schema/jsonschema.go index b51b0576..2680a9af 100644 --- a/schema/jsonschema.go +++ b/schema/jsonschema.go @@ -67,9 +67,9 @@ func IsJSONValidAgainstSchema(json, schema string) error { return jsonSchema.Validate(jsonInterface) } -// IsJSONValidAgainstSchemaGeneric validates a piece of JSON as an interface{} against a schema, +// IsJSONValidAgainstSchemaGeneric validates a piece of JSON as an any against a schema, // returning an error if it is not valid -func IsJSONValidAgainstSchemaGeneric(json interface{}, schema string) error { +func IsJSONValidAgainstSchemaGeneric(json any, schema string) error { if !IsValidJSON(schema) { return errors.New("schema input is not valid json") } diff --git a/schema/jsonschema_test.go b/schema/jsonschema_test.go index 596de300..e92ae92a 100644 --- a/schema/jsonschema_test.go +++ b/schema/jsonschema_test.go @@ -75,7 +75,7 @@ func TestJSONSchemaValidation(t *testing.T) { }) t.Run("Test Invalid JSON Schema", func(tt *testing.T) { - addressData := map[string]interface{}{ + addressData := map[string]any{ "street-address": "1455 Market St.", "city": "San Francisco", "state": "California", @@ -93,7 +93,7 @@ func TestJSONSchemaValidation(t *testing.T) { addressJSONSchema, err := getTestVector(JSONSchemaTestVector1) assert.NoError(tt, err) - addressData := map[string]interface{}{ + addressData := map[string]any{ "street-address": "1455 Market St.", "city": "San Francisco", "state": "California", @@ -114,7 +114,7 @@ func TestJSONSchemaValidation(t *testing.T) { assert.NoError(tt, err) // Missing required field - addressData := map[string]interface{}{ + addressData := map[string]any{ "street-address": "1455 Market St.", "city": "San Francisco", "state": "California", @@ -136,7 +136,7 @@ func TestJSONSchemaValidation(t *testing.T) { assert.NoError(tt, err) // Additional field - personData := map[string]interface{}{ + personData := map[string]any{ "firstName": "Satoshi", "lastName": "Nakamoto", } @@ -155,7 +155,7 @@ func TestJSONSchemaValidation(t *testing.T) { assert.NoError(tt, err) // Additional field - personData := map[string]interface{}{ + personData := map[string]any{ "firstName": "Satoshi", "middleName": "Coin", "lastName": "Nakamoto", @@ -198,7 +198,7 @@ func TestLoadJSONSchema(t *testing.T) { assert.NoError(t, IsValidJSONSchema(schemaString)) - latLong := map[string]interface{}{ + latLong := map[string]any{ "latitude": 1, "longitude": 1, } diff --git a/schema/loader.go b/schema/loader.go index 1db59173..cd745e65 100644 --- a/schema/loader.go +++ b/schema/loader.go @@ -112,7 +112,7 @@ func (cl *CachingLoader) cachingLoaderForProtocol(protocol string) func(url stri // GetCachedSchemas returns an array of cached schema URIs func (cl *CachingLoader) GetCachedSchemas() ([]string, error) { var schemas []string - cl.schemas.Range(func(_, value interface{}) bool { + cl.schemas.Range(func(_, value any) bool { schemas = append(schemas, value.(string)) return true }) diff --git a/util/errors.go b/util/errors.go index a5f93fd2..8ef0ae3a 100644 --- a/util/errors.go +++ b/util/errors.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/util/helpers.go b/util/helpers.go index 1a617597..9982b32b 100644 --- a/util/helpers.go +++ b/util/helpers.go @@ -23,7 +23,7 @@ func NewValidator() *validator.Validate { return validator.New() } -func IsValidStruct(data interface{}) error { +func IsValidStruct(data any) error { if t := reflect.TypeOf(data).Kind(); t != reflect.Struct { return fmt.Errorf("provided data is not of Kind struct: %+v", data) } @@ -52,11 +52,11 @@ func (l LDProcessor) GetOptions() *ld.JsonLdOptions { return l.JsonLdOptions } -func (l LDProcessor) GetContextFromMap(dataMap map[string]interface{}) (*ld.Context, error) { +func (l LDProcessor) GetContextFromMap(dataMap map[string]any) (*ld.Context, error) { var activeCtx *ld.Context var err error ldCtx := ld.NewContext(nil, l.JsonLdOptions) - contextMap, ok := dataMap["@context"].(map[string]interface{}) + contextMap, ok := dataMap["@context"].(map[string]any) if !ok { activeCtx, err = ldCtx.Parse(dataMap) } else { @@ -68,7 +68,7 @@ func (l LDProcessor) GetContextFromMap(dataMap map[string]interface{}) (*ld.Cont return activeCtx, nil } -func LDNormalize(document interface{}) (interface{}, error) { +func LDNormalize(document any) (any, error) { processor := NewLDProcessor() return processor.Normalize(document, processor.GetOptions()) } @@ -89,7 +89,7 @@ func IsRFC3339Timestamp(t string) bool { } // Copy makes a 1:1 copy of src into dst. -func Copy(src interface{}, dst interface{}) error { +func Copy(src any, dst any) error { if err := validateCopy(src, dst); err != nil { return err } @@ -100,18 +100,18 @@ func Copy(src interface{}, dst interface{}) error { return json.Unmarshal(bytes, dst) } -func ToJSON(i interface{}) (string, error) { +func ToJSON(i any) (string, error) { b, err := json.Marshal(i) return string(b), err } -func ToJSONInterface(data string) (interface{}, error) { - var result interface{} +func ToJSONInterface(data string) (any, error) { + var result any err := json.Unmarshal([]byte(data), &result) return result, err } -func validateCopy(src interface{}, dst interface{}) error { +func validateCopy(src any, dst any) error { if src == nil { return errors.New("src is nil") } @@ -189,7 +189,7 @@ func Contains(needle string, haystack []string) bool { return false } -func ArrayInterfaceToStr(have []interface{}) ([]string, error) { +func ArrayInterfaceToStr(have []any) ([]string, error) { var want []string for _, item := range have { strItem, ok := item.(string) @@ -201,8 +201,8 @@ func ArrayInterfaceToStr(have []interface{}) ([]string, error) { return want, nil } -func ArrayStrToInterface(have []string) []interface{} { - var want []interface{} +func ArrayStrToInterface(have []string) []any { + var want []any for _, v := range have { want = append(want, v) } @@ -210,17 +210,17 @@ func ArrayStrToInterface(have []string) []interface{} { } // InterfaceToInterfaceArray attempts to array-ify an interface type -func InterfaceToInterfaceArray(have interface{}) ([]interface{}, error) { +func InterfaceToInterfaceArray(have any) ([]any, error) { // case 1: it's a string strVal, ok := have.(string) if ok { - return []interface{}{strVal}, nil + return []any{strVal}, nil } // case 2: it's an array of string types strVals, ok := have.([]string) if ok { - var want []interface{} + var want []any for _, s := range strVals { want = append(want, s) } @@ -228,18 +228,18 @@ func InterfaceToInterfaceArray(have interface{}) ([]interface{}, error) { } // case 3: it's an array of interface types - interVals, ok := have.([]interface{}) + interVals, ok := have.([]any) if ok { return interVals, nil } // case 4: it's another interface type - return []interface{}{have}, nil + return []any{have}, nil } -// InterfaceToStrings assumes we are given an interface of either `string`, `[]string` or `[]interface{}` types +// InterfaceToStrings assumes we are given an interface of either `string`, `[]string` or `[]any` types // and attempts to flatten into an array of strings -func InterfaceToStrings(have interface{}) ([]string, error) { +func InterfaceToStrings(have any) ([]string, error) { // case 1: it's a string strVal, ok := have.(string) if ok { @@ -257,7 +257,7 @@ func InterfaceToStrings(have interface{}) ([]string, error) { } // case 3: it's an array of interface types - interVals, ok := have.([]interface{}) + interVals, ok := have.([]any) if ok { return ArrayInterfaceToStr(interVals) } @@ -265,12 +265,12 @@ func InterfaceToStrings(have interface{}) ([]string, error) { return nil, errors.New("could not turn interface into strings") } -func ToJSONMap(data interface{}) (map[string]interface{}, error) { +func ToJSONMap(data any) (map[string]any, error) { dataBytes, err := json.Marshal(data) if err != nil { return nil, err } - var jsonMap map[string]interface{} + var jsonMap map[string]any if err := json.Unmarshal(dataBytes, &jsonMap); err != nil { return nil, err } @@ -298,6 +298,6 @@ func MergeUniqueValues(a, b []string) []string { } // PrettyJSON JSON-ifies data in a 'pretty-print' fashion -func PrettyJSON(data interface{}) ([]byte, error) { +func PrettyJSON(data any) ([]byte, error) { return json.MarshalIndent(data, "", " ") } diff --git a/util/helpers_test.go b/util/helpers_test.go index a532d4f4..2869da60 100644 --- a/util/helpers_test.go +++ b/util/helpers_test.go @@ -48,7 +48,7 @@ func TestInterfaceToStrings(t *testing.T) { func TestArrayInterfaceToStr(t *testing.T) { t.Run("simple string array", func(tt *testing.T) { - data := []interface{}{"hello"} + data := []any{"hello"} res, err := ArrayInterfaceToStr(data) assert.NoError(tt, err) assert.True(tt, len(res) == 1) @@ -56,14 +56,14 @@ func TestArrayInterfaceToStr(t *testing.T) { }) t.Run("multi value string array", func(tt *testing.T) { - data := []interface{}{"hello", "goodbye"} + data := []any{"hello", "goodbye"} res, err := ArrayInterfaceToStr(data) assert.NoError(tt, err) assert.True(tt, len(res) == 2) }) t.Run("non string array", func(tt *testing.T) { - bad := []interface{}{2} + bad := []any{2} _, err := ArrayInterfaceToStr(bad) assert.Error(tt, err) }) @@ -123,10 +123,10 @@ func TestLDProcessor(t *testing.T) { }) t.Run("get context from map", func(tt *testing.T) { - contextMap := map[string]interface{}{ + contextMap := map[string]any{ "dc": "http://purl.org/dc/elements/1.1/", "ex": "http://example.org/vocab#", - "ex:contains": map[string]interface{}{ + "ex:contains": map[string]any{ "@type": "@id", }, } diff --git a/wasm/main.go b/wasm/main.go index 35c96885..bfc0943c 100644 --- a/wasm/main.go +++ b/wasm/main.go @@ -42,13 +42,13 @@ func main() { } // 1. Simplest function - note we wrap things with js.ValueOf (if a primitive you don't technically need to) -func sayHello(_ js.Value, args []js.Value) interface{} { +func sayHello(_ js.Value, args []js.Value) any { return js.ValueOf("Hello from golang via wasm!") } // 2. Calling a ssi-sdk function directly - but returning a plain old string // TODO: check arg lentgh and return an error if not correct -func generateKey(_ js.Value, args []js.Value) interface{} { +func generateKey(_ js.Value, args []js.Value) any { keyType := args[0].String() kt := crypto.KeyType(keyType) @@ -61,7 +61,7 @@ func generateKey(_ js.Value, args []js.Value) interface{} { } // 3. Returning a richer object, converting to json and then unmarshalling to make it a js object -func makeDid(_ js.Value, args []js.Value) interface{} { +func makeDid(_ js.Value, args []js.Value) any { pubKey, _, _ := crypto.GenerateKeyByKeyType(crypto.Ed25519) didKey, _ := did.CreateDIDKey(crypto.Ed25519, pubKey.(ed25519.PublicKey)) @@ -69,13 +69,13 @@ func makeDid(_ js.Value, args []js.Value) interface{} { // unmarshall into json bytes, then back into a simple struct for converting to js resultBytes, _ := json.Marshal(result) - var resultObj map[string]interface{} + var resultObj map[string]any json.Unmarshal(resultBytes, &resultObj) return js.ValueOf(resultObj) } -func resolveDid(_ js.Value, args []js.Value) interface{} { +func resolveDid(_ js.Value, args []js.Value) any { didString := args[0].String() resolvers := []did.Resolution{did.KeyResolver{}, did.WebResolver{}, did.PKHResolver{}, did.PeerResolver{}} @@ -93,7 +93,7 @@ func resolveDid(_ js.Value, args []js.Value) interface{} { if err != nil { return err } - var resultObj map[string]interface{} + var resultObj map[string]any err = json.Unmarshal(resultBytes, &resultObj) if err != nil { return err diff --git a/wasm/static/main.wasm b/wasm/static/main.wasm index 6a1caf6a..cd382ab1 100755 Binary files a/wasm/static/main.wasm and b/wasm/static/main.wasm differ