Open-Attestation / open-attestation

Meta framework for providing digital provenance and integrity to documents.
https://openattestation.com
Apache License 2.0
54 stars 18 forks source link

feat: added w3c context checker in wrap #101

Closed gjj closed 4 years ago

gjj commented 4 years ago

wrap.ts

Since our wrapper adds OA-specific properties, I feel that we should check if the OA v3 context is missing or not. In the original unwrapped document, the user can:

(This is also to ensure we can pass the W3C test inputs since the original inputs does not come with OA v3's context)

This is the logic:

If @context doesn't exist (i.e. undefined):

  • wrap will create the @context array with https://www.w3.org/2018/credentials/v1 as the first item

(Now this would mean that some @context validations check in validateW3C may be unreachable)

Next, if @context exists and is an array, and if OA v3 contexts is not in the original @context:

  • then we add it in for them

But I believe this is something to be discussed.

Also added a new testcase to improve test coverage in case @context is a string.

Nebulis commented 4 years ago

I agree on this, just have a look on w3c test suite and make sure there is no test that this code would fail. IIRC it should be ok (there is one test that expect a failure f the context is in second position)