Skip to content

Commit

Permalink
refactor: renderer method context and revocation list to map the cont…
Browse files Browse the repository at this point in the history
…ext (#156)

<!--
  For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for
further details.
  
  For a timely review/response, please avoid force-pushing additional
  commits if your PR already received reviews or comments.
  
Before submitting a Pull Request, please ensure you've done the
following:
- 📖 Read the [Contributing
Guide](https://github.com/uncefact/project-vckit/blob/main/CONTRIBUTING.md).
- 📖 Read the [Code of
Conduct](https://github.com/uncefact/project-vckit/blob/main/CODE_OF_CONDUCT.md).
  - 👷‍♀️ Create small PRs. In most cases, this will be possible.
  - ✅ Provide tests for your changes.
- 📝 Use descriptive commit messages following [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0/).
- 📗 Update any related documentation and include any relevant
screenshots.
-->

## What type of PR is this? (check all applicable)

- [ ] 🍕 Feature
- [x] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 🎨 Style
- [x] 🧑‍💻 Code Refactor
- [ ] 🔥 Performance Improvements
- [ ] ✅ Test
- [ ] 🤖 Build
- [ ] 🔁 CI
- [ ] 📦 Chore (Release)
- [ ] ⏩ Revert

## Description

<!-- 
Please do not leave this blank 
This PR [adds/removes/fixes/replaces] the [feature/bug/etc]. 
-->

## Related Tickets & Documents
<!-- 
Please use this format link issue numbers: Fixes #123

https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->

## Mobile & Desktop Screenshots/Recordings

<!-- Visual changes require screenshots -->


## Added tests?

- [ ] 👍 yes
- [ ] 🙅 no, because they aren't needed
- [ ] 🙋 no, because I need help

## Added to documentation?

- [ ] 📜 README.md
- [ ] 📓 [vc-kit doc site](https://uncefact.github.io/vckit/)
- [ ] 📕 storybook
- [ ] 🙅 no documentation needed

## [optional] Are there any post-deployment tasks we need to perform?


<!-- note: PRs with deleted sections will be marked invalid -->

---------

Co-authored-by: Hoa Ngo <[email protected]>
  • Loading branch information
namhoang1604 and hoa-ngo-gs committed Oct 11, 2023
1 parent 3929e3f commit aa2da7a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/renderer/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,26 @@ export class Renderer implements IAgentPlugin {
context?: IRendererContext
): Promise<IRenderResult> {
try {
const [expandedDocument] = await expandVerifiableCredential(
args.credential
);
const renderMethods: RenderMethodPayload[] | [] =
extractRenderMethods(expandedDocument);
const renderMethods: RenderMethodPayload[] | [] = [];

// const [expandedDocument] = await expandVerifiableCredential(
// args.credential
// );
// const renderMethods: RenderMethodPayload[] | [] =
// extractRenderMethods(expandedDocument);

// TODO: There's an issue with W3 availability causing the fetching of some W3 context files to fail. Since we know the exact location of the template we can bypass the JSONLD expansion. This is a temporary workaround.

const template = args.credential.render[0]?.template;
const type = args.credential.render[0]?.['@type'];

if (template && type) {
renderMethods[0] = {
template,
'@type': type,
};
}

if (!renderMethods.length) {
throw new Error('Render method not found in the verifiable credential');
}
Expand Down
1 change: 1 addition & 0 deletions packages/revocation-list-2020/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@vckit/core-types": "workspace:^",
"@veramo/data-store": "5.2.0",
"@veramo/utils": "5.2.0",
"@veramo/credential-ld": "5.2.0",
"credential-status": "^2.0.5",
"dotenv": "^16.0.0",
"express-interceptor": "^1.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DocumentLoader } from '@transmute/vc-status-rl-2020/dist/types';
import * as didKey from '@transmute/did-key.js';
import * as didWeb from '@transmute/did-web';
import { CredentialStatus } from '@vckit/core-types';
import { LdDefaultContexts } from '@veramo/credential-ld';

const resolve = async (did: string) => {
if (did.startsWith('did:key')) {
Expand All @@ -27,6 +28,10 @@ const documentLoader: DocumentLoader = async (iri: string) => {
return { documentUrl: iri, document: contexts.get(iri) };
}

if (LdDefaultContexts.get(iri)) {
return { documentUrl: iri, document: LdDefaultContexts.get(iri) };
}

if (iri.startsWith('did:')) {
const didDocument = await resolve(iri);
return { documentUrl: iri, document: didDocument };
Expand Down

0 comments on commit aa2da7a

Please sign in to comment.