WhiteflagProtocol / whiteflag-api

Reference implementation of the Whiteflag protocol in Node.js that acts as an API to connect applications with the underlying blockchains
https://api.whiteflagprotocol.org
Other
4 stars 5 forks source link

Check messages for correct subject code and object type #13

Closed ts5746 closed 4 years ago

ts5746 commented 4 years ago

Description

Check incoming and outgoing Whiteflag messages for the correct (combination of) subject code and object type i.a.w. the Whiteflag specification.

Rationale

Currently, Whiteflag messages are checked against the JSON message schema in ./lib/protocol/static/message.schema.json. However, this check does not include whether the (combination of) values used in the SubjectCode and ObjectType fields are valid in accordance with the Whiteflag specification. The JSON message schema itself already includes all valid values.

Solution

Specification

Incoming (tx) and outgoing (rx) messages should be checked for correct values just after the messages are checked against the schema of the Whiteflag specification, which does not check the (combination of) values for subject and object codes. Possibly, this check might be disabled, separately for tx and rx, in the whiteflag.toml configuration file for performance reasons.

Affected components

  1. The check most probably needs to be added as a new module to ./lib/protocol, since codec.js does the full schema check and reference.js the reference check.
  2. This new check would also require an additional step in both the tx and rx message processing chains that calls the new module.
  3. The JSON message schema might require to be updated to also included valid combinations of subjects and objects.

Alternatives

Alternatively, the check is not implemented and has to be dealt with at application level, meaning that the API does not guarantee protocol compliance on this aspect.

ts5746 commented 4 years ago

Implemented in existing module lib/protocol/codec.js without additional steps in the TX and RX processing chains. The JSON message schema has been extended to support this feature. Tested and merged into develop in a7c22f2168408941613a9f82820071aa04a34e23.