Skip to content

Add DID document validation module and fixtures#7

Merged
chrishooooo-netizen merged 3 commits intotrailprotocol:mainfrom
AmeyParle:feat/did-document-validation
Apr 6, 2026
Merged

Add DID document validation module and fixtures#7
chrishooooo-netizen merged 3 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.

@AmeyParle AmeyParle marked this pull request as ready for review April 5, 2026 00:00
@chrishooooo-netizen
Copy link
Copy Markdown
Contributor

@AmeyParle — Excellent work! This is a thorough and well-structured validation module. A few highlights:

What I really like:

  • Clean separation of concerns (validator, CLI, tests, fixtures)
  • Helpful, specific error messages
  • Good coverage of both JWK and multibase key formats
  • Agent-specific trail:parentOrganization validation is spot-on

Minor observations (non-blocking, potential follow-ups):

  1. The trail-hash regex enforces exactly 16 hex chars, but some spec examples use shorter hashes (e.g., e1f2a3b4 in Appendix A). We should align this — I'll create a separate issue for spec example consistency. For now, your 16-char pattern matches the canonical examples in §5.

  2. trail:trailTrustTier and trail:aiSystemType are present in the fixtures but not validated yet. These would be great follow-up additions — would you be interested in tackling them in a next PR?

  3. No @context validation yet — also a good follow-up candidate.

Approved! Merging this as-is. Thanks for the solid contribution — looking forward to more from you! 🚀

@chrishooooo-netizen chrishooooo-netizen merged commit f6a1d0d into trailprotocol:main Apr 6, 2026
3 checks passed
@AmeyParle
Copy link
Copy Markdown
Author

Thanks a lot for the detailed review and for merging this — I really appreciate the feedback.

I’m glad the structure and validation coverage looked solid. The follow-up areas you mentioned also sound interesting, especially trail:trailTrustTier, trail:aiSystemType, and @context validation.

I’d be happy to take one of those on next in a separate PR. Thanks again!

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