Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

feat: add validation #4

Merged
merged 37 commits into from
Apr 1, 2024
Merged

feat: add validation #4

merged 37 commits into from
Apr 1, 2024

Conversation

ethanwlee
Copy link
Contributor

@ethanwlee ethanwlee commented Mar 29, 2024

Summary

closes #2

  • validating messages/resources
    • introduces a validator using json_schema to validate the message/resources and the message/resource kinds in parse()
    • validator pulls in schemas from the tbdex submodule (inspired by tbdex-js)
  • verifying rfq offering requirements
    • completes verifyOfferingRequirements() in rfq.dart (except verifying the claims)

also adds ci

Comment on lines 81 to 82
// TODO: how to initialize properly?
await Validator.initialize();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

would like a better solution for initializing Validator... any ideas?

Choose a reason for hiding this comment

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

You beat me to it, I was just about to suggest possibly using a singleton with a static constructor. Nice work!

Copy link
Member

@wesbillman wesbillman left a comment

Choose a reason for hiding this comment

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

Awesome!

Comment on lines +18 to +30
- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: true

- name: Install Dependencies
run: just get

- name: Run Static Analysis
run: just analyze

- name: Run Tests
run: just test
Copy link
Member

Choose a reason for hiding this comment

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

Nice!!

lib/src/protocol/models/message_data.dart Outdated Show resolved Hide resolved
Comment on lines 67 to 79
final jsonResource = jsonDecode(payload) as Map<String, dynamic>?;
if (jsonResource == null) {
throw Exception('payload is not a valid JSON object');
}
Validator.validate(jsonResource, 'resource');

final jsonResourceData = jsonResource['data'];
final resourceMetadata = jsonResource['metadata'] as ResourceMetadata?;
if (resourceMetadata == null) {
throw Exception('metadata property is required');
}
final resourceKind = resourceMetadata.kind.name;
Validator.validate(jsonResourceData, resourceKind);
Copy link
Member

Choose a reason for hiding this comment

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

This logic seems duplicated, would it be better to put it in a class that can be parsed with data and metadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will make sure to cover this in #6!

lib/src/protocol/validator.dart Outdated Show resolved Hide resolved
@ethanwlee ethanwlee merged commit 3130a86 into main Apr 1, 2024
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add message/resource validation
3 participants