Add DID document validation module and fixtures#7
Add DID document validation module and fixtures#7AmeyParle wants to merge 2 commits intotrailprotocol:mainfrom
Conversation
chrishooooo-netizen
left a comment
There was a problem hiding this comment.
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:parentOrganizationcheck for agent DIDs is a nice catch - CLI runner is straightforward and useful
Requested changes:
-
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 likenode: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. Atest.jsornpm testsetup that exits non-zero on failure would make this much more robust. -
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
serviceEndpointvalidation 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!
|
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 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. |
Summary
This PR adds a validation module for checking whether
did:trailDID Documents conform to the validation requirements described in Issue #6.Changes
added
validation/did-document-validator.jswith validation for:id,controller,verificationMethod,authentication)did:trailidentifier formatverificationMethodentries and key materialauthenticationreferencesserviceentriescapabilityDelegationstructuretrail:parentOrganizationadded
validation/validate.jsas a CLI runneradded
validation/fixtures/with one valid fixture and multiple invalid fixturesadded
validation/README.mdwith usage instructions and references to the relevant spec sectionsValidation
Tested the CLI against:
valid-did-document.jsoninvalid-missing-id.jsoninvalid-missing-controller.jsoninvalid-bad-id-format.jsoninvalid-missing-verification-method.jsoninvalid-bad-key-material.jsoninvalid-bad-service-endpoint.jsoninvalid-bad-capability-delegation.jsoninvalid-agent-missing-parent-org.jsonNotes
controlleras required.Refs #6