nuts-foundation/nuts-node

View on GitHub

Showing 141 of 166 total issues

Method validator.sync has 53 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (v *validator) sync() {
    // Use a WaitGroup to track when background goroutines are complete
    wg := &sync.WaitGroup{}

    // maximum time between updates
Severity: Minor
Found in pki/validator.go - About 1 hr to fix

    Function createCmd has 53 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func createCmd() *cobra.Command {
        // needs to be initialized for pflags, values will be overwritten with defaults from pflag
        var createRequest = api.DIDCreateRequest{
            VerificationMethodRelationship: api.VerificationMethodRelationship{
                AssertionMethod:      new(bool),
    Severity: Minor
    Found in vdr/cmd/cmd.go - About 1 hr to fix

      Method verifier.Verify has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
      Open

      func (v verifier) Verify(credentialToVerify vc.VerifiableCredential, allowUntrusted bool, checkSignature bool, validAt *time.Time) error {
          // it must have valid content
          validator := credential.FindValidator(credentialToVerify)
          if err := validator.Validate(credentialToVerify); err != nil {
              return err
      Severity: Minor
      Found in vcr/verifier/verifier.go - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function resolveCredential has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
      Open

      func resolveCredential(path []string, mapping InputDescriptorMappingObject, value interface{}) (*vc.VerifiableCredential, error) {
          fullPath := append(path, mapping.Path)
          fullPathString := strings.Join(fullPath, "/")
      
          targetValueRaw, err := jsonpath.Get(mapping.Path, value)
      Severity: Minor
      Found in vcr/pe/presentation_submission.go - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method Wrapper.CreateVP has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
      Open

      func (w *Wrapper) CreateVP(ctx context.Context, request CreateVPRequestObject) (CreateVPResponseObject, error) {
          if len(request.Body.VerifiableCredentials) == 0 {
              return nil, core.InvalidInputError("verifiableCredentials needs at least 1 item")
          }
      
      
      Severity: Minor
      Found in vcr/api/vcr/v2/api.go - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      func readDIDDocument(reader io.Reader) (*did.Document, error) {
          data, err := io.ReadAll(reader)
          if err != nil {
              return nil, fmt.Errorf("unable to read DID Document response: %w", err)
          }
      Severity: Major
      Found in vdr/api/v2/client.go and 2 other locations - About 1 hr to fix
      vdr/api/v1/client.go on lines 158..168
      vdr/api/v1/client.go on lines 194..204

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 134.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Method Wrapper.IntrospectAccessToken has 51 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (w Wrapper) IntrospectAccessToken(ctx context.Context, request IntrospectAccessTokenRequestObject) (IntrospectAccessTokenResponseObject, error) {
          token := request.Body.Token
      
          introspectionResponse := TokenIntrospectionResponse{
              Active: false,
      Severity: Minor
      Found in auth/api/auth/v1/api.go - About 1 hr to fix

        Method StatusList2021.validate has 51 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (cs *StatusList2021) validate(cred vc.VerifiableCredential) (*StatusList2021CredentialSubject, error) {
            // TODO: replace with json schema validator?
            { // Credential checks
                // context
                // all fields in the StatusList2021Credential must be defined by the contexts
        Severity: Minor
        Found in vcr/revocation/statuslist2021_verifier.go - About 1 hr to fix

          Method PresentationDefinition.matchSubmissionRequirements has 51 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (presentationDefinition PresentationDefinition) matchSubmissionRequirements(vcs []vc.VerifiableCredential) ([]InputDescriptorMappingObject, []vc.VerifiableCredential, error) {
              // first we use the constraint matching algorithm to get the matching credentials
              candidates, err := presentationDefinition.matchConstraints(vcs)
              if err != nil {
                  return nil, nil, err
          Severity: Minor
          Found in vcr/pe/presentation_definition.go - About 1 hr to fix

            Method openidHandler.HandleCredentialRequest has 51 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (i *openidHandler) HandleCredentialRequest(ctx context.Context, request openid4vci.CredentialRequest, accessToken string) (*vc.VerifiableCredential, error) {
                if request.Format != vc.JSONLDCredentialProofFormat {
                    return nil, openid4vci.Error{
                        Err:        fmt.Errorf("credential request: unsupported format '%s'", request.Format),
                        Code:       openid4vci.UnsupportedCredentialType,
            Severity: Minor
            Found in vcr/issuer/openid.go - About 1 hr to fix

              Method verifier.Verify has 51 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (v verifier) Verify(credentialToVerify vc.VerifiableCredential, allowUntrusted bool, checkSignature bool, validAt *time.Time) error {
                  // it must have valid content
                  validator := credential.FindValidator(credentialToVerify)
                  if err := validator.Validate(credentialToVerify); err != nil {
                      return err
              Severity: Minor
              Found in vcr/verifier/verifier.go - About 1 hr to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                func (d dag) getNumberOfTransactions(tx stoabs.ReadTx) uint64 {
                    value, err := tx.GetShelfReader(metadataShelf).Get(stoabs.BytesKey(numberOfTransactionsKey))
                    if errors.Is(err, stoabs.ErrKeyNotFound) {
                        return 0
                    }
                Severity: Major
                Found in network/dag/dag.go and 1 other location - About 1 hr to fix
                network/dag/dag.go on lines 285..297

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 131.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                func (d dag) getHighestClockValue(tx stoabs.ReadTx) uint32 {
                    value, err := tx.GetShelfReader(metadataShelf).Get(stoabs.BytesKey(highestClockValue))
                    if errors.Is(err, stoabs.ErrKeyNotFound) {
                        return 0
                    }
                Severity: Major
                Found in network/dag/dag.go and 1 other location - About 1 hr to fix
                network/dag/dag.go on lines 257..269

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 131.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Function NewAuthorizationServer has 8 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    didResolver resolver.DIDResolver, vcFinder vcr.Finder, vcVerifier verifier.Verifier,
                    serviceResolver didman.CompoundServiceResolver, privateKeyStore nutsCrypto.KeyStore,
                    contractNotary services.ContractNotary, jsonldManager jsonld.JSONLD, accessTokenLifeSpan time.Duration) AuthorizationServer {
                Severity: Major
                Found in auth/services/oauth/authz_server.go - About 1 hr to fix

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  func (w *Wrapper) UpdateCompoundService(ctx context.Context, request UpdateCompoundServiceRequestObject) (UpdateCompoundServiceResponseObject, error) {
                      if request.Body.Type != "" && request.Body.Type != request.Type {
                          return nil, core.InvalidInputError("updating compound service type is not supported")
                      }
                      request.Body.Type = request.Type
                  Severity: Minor
                  Found in didman/api/v1/api.go and 1 other location - About 1 hr to fix
                  didman/api/v1/api.go on lines 128..138

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 129.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  func (s redisSessionStore) Get(key string, target interface{}) error {
                      result, err := s.client.Get(context.Background(), s.toRedisKey(key)).Result()
                      if err != nil {
                          if errors.Is(redis.Nil, err) {
                              return ErrNotFound
                  Severity: Minor
                  Found in storage/session_redis.go and 1 other location - About 1 hr to fix
                  storage/session_redis.go on lines 102..112

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 129.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  func (w *Wrapper) UpdateEndpoint(ctx context.Context, request UpdateEndpointRequestObject) (UpdateEndpointResponseObject, error) {
                      if request.Body.Type != "" && request.Body.Type != request.Type {
                          return nil, core.InvalidInputError("updating endpoint type is not supported")
                      }
                      request.Body.Type = request.Type
                  Severity: Minor
                  Found in didman/api/v1/api.go and 1 other location - About 1 hr to fix
                  didman/api/v1/api.go on lines 224..234

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 129.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  func (s redisSessionStore) GetAndDelete(key string, target interface{}) error {
                      // GetDel requires redis-server version >= 6.2.0.
                      result, err := s.client.GetDel(context.Background(), s.toRedisKey(key)).Result()
                      if err != nil {
                          if errors.Is(redis.Nil, err) {
                  Severity: Minor
                  Found in storage/session_redis.go and 1 other location - About 1 hr to fix
                  storage/session_redis.go on lines 83..92

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 129.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Method Wrapper.handleAuthorizeResponseSubmission has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func (r Wrapper) handleAuthorizeResponseSubmission(ctx context.Context, request HandleAuthorizeResponseRequestObject) (HandleAuthorizeResponseResponseObject, error) {
                      verifier, err := r.toOwnedDIDForOAuth2(ctx, request.Did)
                      if err != nil {
                          return nil, oauthError(oauth.InvalidRequest, "unknown verifier id", err)
                      }
                  Severity: Minor
                  Found in auth/api/iam/openid4vp.go - About 55 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method store.Resolve has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func (tl *store) Resolve(id did.DID, resolveMetadata *resolver.ResolveMetadata) (returnDocument *did.Document, returnMetadata *resolver.DocumentMetadata, txErr error) {
                      txErr = tl.db.Read(context.Background(), func(tx stoabs.ReadTx) error {
                          latestReader := tx.GetShelfReader(latestShelf)
                          latestMetaRef, err := latestReader.Get(stoabs.BytesKey(id.String()))
                          if err != nil && !errors.Is(err, stoabs.ErrKeyNotFound) {
                  Severity: Minor
                  Found in vdr/didnuts/didstore/store.go - About 55 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Severity
                  Category
                  Status
                  Source
                  Language