Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: align against W3C VC 2.0 test suite and complete unit tests #272

Merged
merged 108 commits into from May 3, 2024

Conversation

HJunyuan
Copy link
Member

@HJunyuan HJunyuan commented Mar 20, 2024

What does this PR do?

Schema related changes

  • Align against W3C VC 2.0 test suite
    • Utilise jsonld for expansion (i.e. ensure VC contexts are interpretable)
    • Utilise zod for data model validation
  • Avoid using sub types (e.g. renderMethodType: EMBEDDED_RENDERER) and just utilise a scoped context (e.g. type: OpenAttestationEmbeddedRenderer)
  • Make renderMethod an array and rename name to templateName
  • Update v4 test fixtures

Improvements

  • Utilise cross-fetch instead due to segmentation fault when using default nodeDocumentLoader()
  • Digest to handle falsy values correctly

Prerequisite

- upgrade @types/jsonld and ts-node
- instead of keeping a local copy, may consider to use node-cache in the future
- fix: utilise "expand" from jsonld to ensure provided @context are interpretable
- fix: improve readability and allow flexibility in oa v4 schema (wrap vs unwrapped, etc.)
@HJunyuan HJunyuan changed the title fix: align against W3C VC 2.0 test suite feat: align against W3C VC 2.0 test suite and complete unit tests Mar 20, 2024
src/4.0/wrap.ts Outdated Show resolved Hide resolved
github-actions[bot]

This comment was marked as resolved.

@phanshiyu phanshiyu marked this pull request as ready for review May 2, 2024 08:22
@phanshiyu phanshiyu merged commit 0fc7fa0 into alpha May 3, 2024
6 checks passed
@phanshiyu phanshiyu deleted the oa-v4 branch May 3, 2024 08:33
Copy link

github-actions bot commented May 3, 2024

🎉 This PR is included in version 6.8.0-alpha.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

phanshiyu added a commit that referenced this pull request May 3, 2024
* ci: prepare alpha release

* feat: oa v4 alpha

* fix: lint errors

* test: update fixtures

* chore: update id description

* test: update fixtures

* chore: improve readability

* fix: pr review suggestions

* fix: stricter checks for isStringArray

* fix: getDocumentData for v4

* chore: update getTemplateURL error message

chore: remove required fields (#271)

feat: align against W3C VC 2.0 test suite and complete unit tests (#272)

* chore: npm install jsonld & joi

- upgrade @types/jsonld and ts-node

* chore: add vc 2.0 context url and store as cache

- instead of keeping a local copy, may consider to use node-cache in the future

* fix: align validation with vc 2.0 test suite

- fix: utilise "expand" from jsonld to ensure provided @context are interpretable
- fix: improve readability and allow flexibility in oa v4 schema (wrap vs unwrapped, etc.)

* fix: set additionalProperties to false due to AJV false positive

* fix: allow additional properties in credentialStatus

* fix: include error details instead of console log

* test: update v4 alpha test fixtures

* lint: ignore unused argument options

* chore: upgrade jest and ts-jest

* fix: segmentation fault when using default nodeDocumentLoader()

* fix: use scoped context types

avoid using sub types (e.g. renderMethodType = EMBEDDED_RENDERER) and just utilise a scoped context (e.g. type = OpenAttestationEmbeddedRenderer)

* test: no more auto-correct for @context based on vc 2.0 test suite

expected behaviour is to throw error

* fix: digest should handle falsy values correctly

* fix: rename to renderMethod.templateName

* fix: make renderMethod an array

* fix: remove json schema validation in v4.0 wrap

* test: update v4.0 fixtures

* fix: digest test

* fix: make renderMethod.templateName required in v4.0 json schema

* fix: migrate to zod for input vc data model validation

* wip: oa v4 types

* refactor: prefer string union

* refactor: reference constant tuple instead

* refactor: finalTypes follows pattern of finalContexts

* refactor: document -> raw document for clarity

* fix: rawDocument should not be used directly for digest and salting

* fix: remove asserting to string to let the literal infer properly

* fix: typings

* refactor: move assertion earlier

* refactor: assert oa vc than try vc

* fix: refer to new oa vc type in digest and verify

* fix: refer to new oa vc typings

* fix: refer to new oa vc typings

* fix: refer to new oa vc typings

* refactor: improve naming consistency

* fix: typing, should be looser

* fix: a union b does not override a props with b props

* fix: added assertion type to prevent accident extension to base type

* refactor: wording

* refactor: better readability for wrapped types

* refactor: move things within file and some renaming

* refactor: improve naming of variables

* fix: use new typings

* fix: passthroughs needed to allow extension, added name and render method so they dont get stripped

* test: added a guard test which is currently failing

* refactor: merged data model with types and renamed VC type

* refactor: improve helper fn naming

* fix: use extend instead of and since it results in dup errors, remove hex validation since these props are generated by us, allow passthrough for wrap proof so that a signed wrap can pass a wrap only validation test

* test: update snapshot

* fix: was using the wrong document for the check

* test: added tests for wrapped only document

* fix: diagnose to use new guards

* fix: path

* chore: remove vscode

* chore: ignore vscode settings

* chore: remove experimental version guard

* fix: add back the missing wrapDocuments that was accidentally removed

* fix: replace back original implementation of getMerkleRoot

* fix: make our own real types stricter

* fix: diagnose did not handle raw v4

* refactor: remove useless renaming

* fix: object object in test case

* refactor: improve type safety of wrap document v4

* chore: remove to make way for auto generated fixtures

* chore: auto generate v4 fixtures

* fix: could not generated nested dir

* test: add wrap unit tests

* test: extra assertion for proof

* fix: salt test

* fix: allow resigning and validate proof before using

* fix: v4 sign tests

* chore: add batch wrapped document fixture. freeze all documents before exporting

* fix: obfuscate typing was loses the initial input typing

* fix: should not allow obfuscate to produce non compliant v4 wrapped document

* fix: partially fix obfuscate test

* fix: it is more accurate that credentials subject after obfuscastion shd be deeply partial

* fix: clean up digest test

* feat: support attachments

* fix: digestMultibase shd be optional, added descriptions to fields

* refactor: remove renderMethod from w3c model and force it to be exported in passthrough mode

* chore: improve guard test to use direct output of our fns as test case

* fix: allow attachment item to be empty so that obfuscation of a single attachment item is possible

* refactor: improve typing

* fix: partial fix of obfuscate test

* wip: draft of changes to address issues raised

* fix: wrongly returned object for boolean

* fix: shd not allow new empty objects after obfuscation or removing array items

* chore: update fixtures

* fix: digest should not include proof

* fix: skip finding leaf nodes to hash if document without proof is empty

* refactor: improve naming

* fix: broken tests

* fix: revert target bump

* fix: all obfuscate tests

* fix: verify should treat salt not found error as invalid

* fix: partial fix of verify tests, added bunch of todos

* chore: add batched signed documents

* fix: complete verify tests

* refactor: typo remove redundant top describe

* fix: fixtures and test it will break on update

* refactor: improve error message to provide more guidance

* fix: array items cannot be undefined

* chore: commit generated fixtures and allow ci tests to catch any drifts

* chore: added remedy action if fixture test fails

* chore: remove lint for all generated files

* fix: v4 e2e

* refactor: improve error types and exporting

---------

Co-authored-by: Phan Shi Yu <phan_shi_yu@tech.gov.sg>
Co-authored-by: Phan Shi Yu <phan_shi_yu@hive.gov.sg>
HJunyuan added a commit that referenced this pull request May 15, 2024
* feat: oa v4 (alpha) (#254)

* ci: prepare alpha release

* feat: oa v4 alpha

* fix: lint errors

* test: update fixtures

* chore: update id description

* test: update fixtures

* chore: improve readability

* fix: pr review suggestions

* fix: stricter checks for isStringArray

* fix: getDocumentData for v4

* chore: update getTemplateURL error message

chore: remove required fields (#271)

feat: align against W3C VC 2.0 test suite and complete unit tests (#272)

* chore: npm install jsonld & joi

- upgrade @types/jsonld and ts-node

* chore: add vc 2.0 context url and store as cache

- instead of keeping a local copy, may consider to use node-cache in the future

* fix: align validation with vc 2.0 test suite

- fix: utilise "expand" from jsonld to ensure provided @context are interpretable
- fix: improve readability and allow flexibility in oa v4 schema (wrap vs unwrapped, etc.)

* fix: set additionalProperties to false due to AJV false positive

* fix: allow additional properties in credentialStatus

* fix: include error details instead of console log

* test: update v4 alpha test fixtures

* lint: ignore unused argument options

* chore: upgrade jest and ts-jest

* fix: segmentation fault when using default nodeDocumentLoader()

* fix: use scoped context types

avoid using sub types (e.g. renderMethodType = EMBEDDED_RENDERER) and just utilise a scoped context (e.g. type = OpenAttestationEmbeddedRenderer)

* test: no more auto-correct for @context based on vc 2.0 test suite

expected behaviour is to throw error

* fix: digest should handle falsy values correctly

* fix: rename to renderMethod.templateName

* fix: make renderMethod an array

* fix: remove json schema validation in v4.0 wrap

* test: update v4.0 fixtures

* fix: digest test

* fix: make renderMethod.templateName required in v4.0 json schema

* fix: migrate to zod for input vc data model validation

* wip: oa v4 types

* refactor: prefer string union

* refactor: reference constant tuple instead

* refactor: finalTypes follows pattern of finalContexts

* refactor: document -> raw document for clarity

* fix: rawDocument should not be used directly for digest and salting

* fix: remove asserting to string to let the literal infer properly

* fix: typings

* refactor: move assertion earlier

* refactor: assert oa vc than try vc

* fix: refer to new oa vc type in digest and verify

* fix: refer to new oa vc typings

* fix: refer to new oa vc typings

* fix: refer to new oa vc typings

* refactor: improve naming consistency

* fix: typing, should be looser

* fix: a union b does not override a props with b props

* fix: added assertion type to prevent accident extension to base type

* refactor: wording

* refactor: better readability for wrapped types

* refactor: move things within file and some renaming

* refactor: improve naming of variables

* fix: use new typings

* fix: passthroughs needed to allow extension, added name and render method so they dont get stripped

* test: added a guard test which is currently failing

* refactor: merged data model with types and renamed VC type

* refactor: improve helper fn naming

* fix: use extend instead of and since it results in dup errors, remove hex validation since these props are generated by us, allow passthrough for wrap proof so that a signed wrap can pass a wrap only validation test

* test: update snapshot

* fix: was using the wrong document for the check

* test: added tests for wrapped only document

* fix: diagnose to use new guards

* fix: path

* chore: remove vscode

* chore: ignore vscode settings

* chore: remove experimental version guard

* fix: add back the missing wrapDocuments that was accidentally removed

* fix: replace back original implementation of getMerkleRoot

* fix: make our own real types stricter

* fix: diagnose did not handle raw v4

* refactor: remove useless renaming

* fix: object object in test case

* refactor: improve type safety of wrap document v4

* chore: remove to make way for auto generated fixtures

* chore: auto generate v4 fixtures

* fix: could not generated nested dir

* test: add wrap unit tests

* test: extra assertion for proof

* fix: salt test

* fix: allow resigning and validate proof before using

* fix: v4 sign tests

* chore: add batch wrapped document fixture. freeze all documents before exporting

* fix: obfuscate typing was loses the initial input typing

* fix: should not allow obfuscate to produce non compliant v4 wrapped document

* fix: partially fix obfuscate test

* fix: it is more accurate that credentials subject after obfuscastion shd be deeply partial

* fix: clean up digest test

* feat: support attachments

* fix: digestMultibase shd be optional, added descriptions to fields

* refactor: remove renderMethod from w3c model and force it to be exported in passthrough mode

* chore: improve guard test to use direct output of our fns as test case

* fix: allow attachment item to be empty so that obfuscation of a single attachment item is possible

* refactor: improve typing

* fix: partial fix of obfuscate test

* wip: draft of changes to address issues raised

* fix: wrongly returned object for boolean

* fix: shd not allow new empty objects after obfuscation or removing array items

* chore: update fixtures

* fix: digest should not include proof

* fix: skip finding leaf nodes to hash if document without proof is empty

* refactor: improve naming

* fix: broken tests

* fix: revert target bump

* fix: all obfuscate tests

* fix: verify should treat salt not found error as invalid

* fix: partial fix of verify tests, added bunch of todos

* chore: add batched signed documents

* fix: complete verify tests

* refactor: typo remove redundant top describe

* fix: fixtures and test it will break on update

* refactor: improve error message to provide more guidance

* fix: array items cannot be undefined

* chore: commit generated fixtures and allow ci tests to catch any drifts

* chore: added remedy action if fixture test fails

* chore: remove lint for all generated files

* fix: v4 e2e

* refactor: improve error types and exporting

---------

Co-authored-by: Phan Shi Yu <phan_shi_yu@tech.gov.sg>
Co-authored-by: Phan Shi Yu <phan_shi_yu@hive.gov.sg>

* Chore: tidy v4 exports (#278)

* refactor: shift context constants into 4.0

* refactor: bring context down to root of 4.0

* refactor: add custom error class, change algorithm to non enum

* refactor: only leave the bare essentials of v4 in root index, fix tests

* refactor: free up 4.0 from the mess of dependencies caused by importing of utils

* fix: circular dependency caused by getData

* feat: v4 utility guards

* feat: export v4

* chore: generate v4 json schemas based with zod (#279)

* chore: generate v4 json schemas based with zod

* fix: small typo

* chore: sign document should be clear on what errors it could throw, export of v4 verify shd be more explicit (#280)

* chore: sign document should be clear on what errors it could throw

* fix: verify export naming shd be more explicit

* fix: bump target platform, and remove baseUrl as it is not supported (#282)

* fix: bump target platform, and remove baseUrl as it is not supported

* refactor: lint

* Feat:document builder (#283)

* feat: document builder poc

* test: happy flow tests

* refactor: improve comments

* chore: export builder

* test: more tests

* fix: added logic to prevent re-setting of values

* fix: guard constructor and added more test cases to test guards

* fix: revocation support (#285)

* fix: added revocation methods, refactor: revamp state management in instance

* fix: tests

* feat: added revocation store revocation method

* feat: implemented revocation store revocation builder method

* test: update to check credentialStatus

* fix: improve ethereum address validation

* tests: added tests for revocation store revocation method

* chore: update json schemas

* chore: update descriptions

* chore: setup husky and lintstaged

* fix: clean up hashing utils from utils and fix brokenreferences

* feat: remove the need to polyfill manually in browser envs

* fix: test

* fix: remove use of crypto completely

* fix: import buffer based on docs

* fix: rendering methods (#287)

* fix: missing svg renderer props and no renderer method

* fix: only add render method if its defined

* chore: improve handle bar template description

* fix: improved descriptions on documentLoader's interface

* fix: improving naming and description

* feat: computeDigestMultibase (#288)

* fix: only generate json fixtures when fixtures.ts changes (#289)

* fix: move attachments into credentialSubject (#290)

* fix: renamed document (#291)

* fix: obfuscate typing and guard exports (#292)

* fix: obfuscate typing refused to accept document that could be multiple version

* fix: improve consistency of utils guard

* fix: simplify obfuscateVerifiableCredential typing

* fix: obfuscation return type should still have a compliant attachment… (#293)

* fix: obfuscation return type should still have a compliant attachment array

* fix: improve typing more

* fix: mark v3 functions as deprecated (#298)

---------

Co-authored-by: Phan Shi Yu <phan_shi_yu@tech.gov.sg>
Co-authored-by: Phan Shi Yu <phan_shi_yu@hive.gov.sg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants