diff --git a/.golangci.yaml b/.golangci.yaml index c875fde..747215c 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,11 +1,6 @@ run: tests: true timeout: 5m - skip-dirs: - - resources - - old - skip-files: - - cmd/protopkg/main.go output: print-issued-lines: false @@ -73,12 +68,11 @@ linters: - nolintlint - wrapcheck # We might want to re-enable this if we manually wrap all the existing errors with fmt.Errorf - testableexamples + linters-settings: exhaustive: default-signifies-exhaustive: true - govet: - check-shadowing: true dupl: threshold: 100 goconst: @@ -101,9 +95,9 @@ linters-settings: desc: "use fmt.Errorf or errors.New" - pkg: braces.dev/errtrace desc: "use fmt.Errorf or errors.New" - # wrapcheck: - # ignorePackageGlobs: - # - github.com/TBD54566975/ftl/* + gosec: + excludes: + - G601 issues: max-same-issues: 0 diff --git a/dids/didcore/document.go b/dids/didcore/document.go index 5915de1..d32a142 100644 --- a/dids/didcore/document.go +++ b/dids/didcore/document.go @@ -48,7 +48,7 @@ type Document struct { // Service expresses ways of communicating with the DID subject or associated entities. // A service can be any type of service the DID subject wants to advertise. // spec reference: https://www.w3.org/TR/did-core/#verification-methods - Service []*Service `json:"service,omitempty"` + Service []Service `json:"service,omitempty"` // AssertionMethod is used to specify how the DID subject is expected to express claims, // such as for the purposes of issuing a Verifiable Credential. @@ -193,7 +193,7 @@ func (d *Document) SelectVerificationMethod(selector VMSelector) (VerificationMe } // AddService will append the given Service to the Document.Services array -func (d *Document) AddService(service *Service) { +func (d *Document) AddService(service Service) { d.Service = append(d.Service, service) } diff --git a/dids/diddht/diddht.go b/dids/diddht/diddht.go index de1bcc0..fd62505 100644 --- a/dids/diddht/diddht.go +++ b/dids/diddht/diddht.go @@ -191,7 +191,7 @@ func CreateWithContext(ctx context.Context, opts ...CreateOption) (did.BearerDID document := didcore.Document{ Context: []string{"https://www.w3.org/ns/did/v1"}, ID: bdid.URI, - Service: []*didcore.Service{}, + Service: []didcore.Service{}, VerificationMethod: []didcore.VerificationMethod{}, } @@ -248,8 +248,7 @@ func CreateWithContext(ctx context.Context, opts ...CreateOption) (did.BearerDID } for _, service := range o.services { - s := service - document.AddService(&s) + document.AddService(service) } // 5. Map the output DID Document to a DNS packet diff --git a/dids/diddht/internal/dns/did.go b/dids/diddht/internal/dns/did.go index 441aaa1..731d3f4 100644 --- a/dids/diddht/internal/dns/did.go +++ b/dids/diddht/internal/dns/did.go @@ -68,10 +68,9 @@ func MarshalDIDDocument(d *didcore.Document) ([]byte, error) { msg.Answers = append(msg.Answers, resource) // add verification methods to dns message - for _, v := range d.VerificationMethod { - vm := v + for _, vm := range d.VerificationMethod { // look for the key after the # in the verification method ID - key, ok := vmIDToK[v.ID] + key, ok := vmIDToK[vm.ID] if !ok { // TODO handle error continue @@ -166,7 +165,7 @@ func MarshalVerificationMethod(vm *didcore.VerificationMethod) (string, error) { } // MarshalService packs a service into a TXT DNS resource record and adds to the DNS message Answers -func MarshalService(dhtDNSkey string, s *didcore.Service, msg *dnsmessage.Message) error { +func MarshalService(dhtDNSkey string, s didcore.Service, msg *dnsmessage.Message) error { rawData := fmt.Sprintf("id=%s;t=%s;se=%s", s.ID, s.Type, strings.Join(s.ServiceEndpoint, ",")) resource, err := newResource(fmt.Sprintf("_%s._did.", dhtDNSkey), rawData) diff --git a/dids/diddht/internal/dns/dns.go b/dids/diddht/internal/dns/dns.go index 9802544..7dd2d19 100644 --- a/dids/diddht/internal/dns/dns.go +++ b/dids/diddht/internal/dns/dns.go @@ -66,12 +66,12 @@ func (rec *decoder) DIDDocument() (*didcore.Document, error) { didcore.Purposes(opts...), ) case strings.HasPrefix(name, "_s"): - var s didcore.Service - if err := UnmarshalService(data, &s); err != nil { + var service didcore.Service + if err := UnmarshalService(data, &service); err != nil { // TODO handle error continue } - document.AddService(&s) + document.AddService(service) case strings.HasPrefix(name, "_cnt"): // TODO add controller https://did-dht.com/#controller // optional field diff --git a/dids/diddht/resolver_test.go b/dids/diddht/resolver_test.go index ea7bf36..ffd78d3 100644 --- a/dids/diddht/resolver_test.go +++ b/dids/diddht/resolver_test.go @@ -60,8 +60,7 @@ func Test_VectorsResolve(t *testing.T) { r := NewResolver(ts.URL, http.DefaultClient) - for _, v := range vectors { - vector := v + for _, vector := range vectors { t.Run(vector.Description, func(t *testing.T) { res, err := r.Resolve(vector.Input.DIDUri) if vector.Errors { @@ -107,8 +106,7 @@ func Test_resolve(t *testing.T) { r := NewResolver(ts.URL, http.DefaultClient) - for k := range vectors { - did := k + for did := range vectors { t.Run(did, func(t *testing.T) { res, err := r.Resolve(did) assert.NoError(t, err) diff --git a/dids/didweb/didweb.go b/dids/didweb/didweb.go index 52e4307..0759377 100644 --- a/dids/didweb/didweb.go +++ b/dids/didweb/didweb.go @@ -177,7 +177,7 @@ func Create(domain string, opts ...CreateOption) (_did.BearerDID, error) { } for _, svc := range options.services { - document.AddService(&svc) //nolint:gosec + document.AddService(svc) } return _did.BearerDID{ diff --git a/dids/didweb/didweb_test.go b/dids/didweb/didweb_test.go index aef1734..c0f6f06 100644 --- a/dids/didweb/didweb_test.go +++ b/dids/didweb/didweb_test.go @@ -36,13 +36,13 @@ func TestCreate_WithOptions(t *testing.T) { assert.Equal(t, 2, len(document.Service)) pfisvc := document.Service[0] - assert.NotEqual(t, didcore.Service{}, *pfisvc) + assert.NotEqual(t, didcore.Service{}, pfisvc) assert.Equal(t, "#pfi", pfisvc.ID) assert.Equal(t, "PFI", pfisvc.Type) assert.Equal(t, "http://localhost:8080/tbdex", pfisvc.ServiceEndpoint[0]) idvsvc := document.Service[1] - assert.NotEqual(t, didcore.Service{}, *idvsvc) + assert.NotEqual(t, didcore.Service{}, idvsvc) assert.Equal(t, "#idv", idvsvc.ID) assert.Equal(t, "IDV", idvsvc.Type) assert.Equal(t, "http://localhost:8080/idv", idvsvc.ServiceEndpoint[0]) diff --git a/jws/jws.go b/jws/jws.go index 6ca518b..1a16ff5 100644 --- a/jws/jws.go +++ b/jws/jws.go @@ -54,7 +54,7 @@ func Decode(jws string, opts ...DecodeOption) (Decoded, error) { } if header.KID == "" { - return Decoded{}, errors.New("malformed JWS. Expected header to contain kid.") + return Decoded{}, errors.New("malformed JWS. Expected header to contain kid") } signerDID, err := _did.Parse(header.KID) diff --git a/jws/jws_test.go b/jws/jws_test.go index 5c85fd3..9d51e58 100644 --- a/jws/jws_test.go +++ b/jws/jws_test.go @@ -53,7 +53,9 @@ func TestDecode_SuccessWithTestJwtWithPayload(t *testing.T) { "Z29acnY5czlnUkpOZkhPeTkyNmhkWk50U1lYZ2hhYl9RRmhFNTM3Yk0ifQ", decoded.SignerDID.URI) var payloadMap map[string]interface{} - json.Unmarshal(decoded.Payload, &payloadMap) + err = json.Unmarshal(decoded.Payload, &payloadMap) + assert.NoError(t, err) + if iss, ok := payloadMap["iss"].(string); ok { assert.Equal(t, "did:jwk:eyJrdHkiOiJPS1AiLCJjcnYiOiJFZDI1NTE5IiwieCI6Imdl"+ "Z29acnY5czlnUkpOZkhPeTkyNmhkWk50U1lYZ2hhYl9RRmhFNTM3Yk0ifQ", iss) @@ -105,7 +107,9 @@ func TestDecode_SuccessWithTestJwtWithDetachedPayload(t *testing.T) { "Z29acnY5czlnUkpOZkhPeTkyNmhkWk50U1lYZ2hhYl9RRmhFNTM3Yk0ifQ", decoded.SignerDID.URI) var payloadMap map[string]interface{} - json.Unmarshal(decoded.Payload, &payloadMap) + err = json.Unmarshal(decoded.Payload, &payloadMap) + assert.NoError(t, err) + if iss, ok := payloadMap["iss"].(string); ok { assert.Equal(t, "did:jwk:eyJrdHkiOiJPS1AiLCJjcnYiOiJFZDI1NTE5IiwieCI6Imdl"+ "Z29acnY5czlnUkpOZkhPeTkyNmhkWk50U1lYZ2hhYl9RRmhFNTM3Yk0ifQ", iss)