Skip to content

Add DID document validation module and fixtures#7

Draft
AmeyParle wants to merge 2 commits intotrailprotocol:mainfrom
AmeyParle:feat/did-document-validation
Draft

Add DID document validation module and fixtures#7
AmeyParle wants to merge 2 commits intotrailprotocol:mainfrom
AmeyParle:feat/did-document-validation

Conversation

@AmeyParle
Copy link
Copy Markdown

Summary

This PR adds a validation module for checking whether did:trail DID Documents conform to the validation requirements described in Issue #6.

Changes

  • added validation/did-document-validator.js with validation for:

    • required top-level fields (id, controller, verificationMethod, authentication)
    • did:trail identifier format
    • verificationMethod entries and key material
    • authentication references
    • service entries
    • capabilityDelegation structure
    • agent-specific trail:parentOrganization
  • added validation/validate.js as a CLI runner

  • added validation/fixtures/ with one valid fixture and multiple invalid fixtures

  • added validation/README.md with usage instructions and references to the relevant spec sections

Validation

Tested the CLI against:

  • valid-did-document.json
  • invalid-missing-id.json
  • invalid-missing-controller.json
  • invalid-bad-id-format.json
  • invalid-missing-verification-method.json
  • invalid-bad-key-material.json
  • invalid-bad-service-endpoint.json
  • invalid-bad-capability-delegation.json
  • invalid-agent-missing-parent-org.json

Notes

  • This validator follows the issue requirement to treat top-level controller as required.
  • The valid fixture uses an extended agent-style DID Document so the required-field checks and agent-specific validation can be exercised together.

Refs #6

Copy link
Copy Markdown
Contributor

@chrishooooo-netizen chrishooooo-netizen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @AmeyParle — this is a solid foundation for DID Document validation. I ran all fixtures locally and they pass cleanly. A few notes:

What works well:

  • Clean separation between validation functions (composable, testable)
  • Good fixture coverage: 8 invalid cases + 1 valid, covering required fields, ID format, key material, services, capability delegation, and agent-specific rules
  • The trail:parentOrganization check for agent DIDs is a nice catch
  • CLI runner is straightforward and useful

Requested changes:

  1. Add automated tests. The validator is core infrastructure — we need a test runner (e.g. a simple Node.js script using assert, or a lightweight framework like node:test) that programmatically runs all fixtures and checks expected outcomes. Right now validation correctness depends on someone manually running each fixture and reading the output. A test.js or npm test setup that exits non-zero on failure would make this much more robust.

  2. Add trailing newlines. did-document-validator.js, README.md, and all fixture JSON files are missing a final newline. Small thing, but keeps diffs clean and follows POSIX convention.

Optional improvements (not blocking):

  • Consider a fixture for a valid did:trail:self:z... document (currently only agent is tested as valid)
  • Consider a fixture for a valid did:trail:org:... document
  • The serviceEndpoint validation could eventually support arrays and maps per DID Core, but string-only is fine for now

Contributor scope note:
We're thrilled to have community contributions in examples/, validation/, tests/, and docs/. These areas are open and we actively welcome PRs. Normative spec changes and security-critical components (trust model, capability credential schema, key management) go through maintainer review only — just so expectations are clear as the project grows.

Looking forward to the test additions — once those are in, this is ready to merge. Keep up the great work!

@AmeyParle
Copy link
Copy Markdown
Author

Thanks for the review — I’ve added an automated test runner for the fixtures and cleaned up the trailing newlines. The validator tests now pass with node --test validation/test.js.

I’ve held off on the optional extra valid fixtures for now to keep this PR focused, but I’d be happy to add them in a follow-up if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants