Skip to content

Commit

Permalink
fix: rendering issue (#148)
Browse files Browse the repository at this point in the history
<!--
  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
- [ ] 🧑‍💻 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]. 
-->
- Fix missing the additional fields from schema when issue the vc
- Fix storing the encrypted data when issue
- Fix retrieving the proofFormat when issue

## 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 -->

Signed-off-by: Nam Hoang <[email protected]>
  • Loading branch information
namhoang1604 authored Aug 17, 2023
1 parent 5d1ed2e commit c8bb087
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 44 deletions.
2 changes: 1 addition & 1 deletion packages/cli/default/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ dbConnectionEncrypted:
- type: sqlite
database:
$ref: /constants/databaseFile
synchronize: true
synchronize: false
migrationsRun: true
migrations:
$require: '@vckit/encrypted-storage?t=object#migrations'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ const IssueCredentialFromSchema: React.FC<IssueCredentialFromSchemaProps> = ({
name: schema.issuer.name,
type: schema.issuer.type,
},
additionalFieldsFromSchema: {
...dropFields(schema, [
'@context',
'type',
'credentialSubject',
'id',
'issuer',
'issuanceDate',
'openAttestationMetadata',
]),
},
})
setFormData({})
} catch (err) {
Expand Down
5 changes: 4 additions & 1 deletion packages/demo-explorer/src/utils/signing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ function buildCredential(
issuerDid: string,
additionalProperties: { [key: string]: any },
): any {
const _credential = { ...credential }
const _credential = {
...credential,
...additionalProperties.additionalFieldsFromSchema,
}

let issuer = { id: issuerDid }

Expand Down
46 changes: 18 additions & 28 deletions packages/encrypted-storage/src/encrypted-store-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,25 @@ export function encryptedStoreMiddleware(args: {
return true;
},
intercept: async function (body: string, send: (body: string) => void) {
if (!req.agent) throw Error('Agent not available');
let updatedBody: string = body;

if (
res.statusCode === 200 &&
body &&
args.apiRoutes.includes(req.path)
) {
try {
switch (req.path) {
case '/createVerifiableCredential':
updatedBody = await processCreateVerifiableCredentialRequest(
req.agent,
JSON.parse(body)
);

break;
default:
break;
}
} catch (e: any) {
throw Error(e.message);
try {
if (!req.agent) throw Error('Agent not available');
let updatedBody: string = body;

if (
res.statusCode === 200 &&
body &&
args.apiRoutes.includes(req.path)
) {
updatedBody = await encryptAndStoreData(
req.agent,
JSON.parse(body)
);
}
}

send(updatedBody);
send(updatedBody);
} catch (e: any) {
throw Error(e.message);
}
},
};
});
Expand All @@ -56,10 +49,7 @@ export function encryptedStoreMiddleware(args: {
return router;
}

async function processCreateVerifiableCredentialRequest(
agent: IAgent,
payload: object
) {
async function encryptAndStoreData(agent: IAgent, payload: object) {
const { id, key }: IEncrypteAndStoreDataResult = await agent.execute(
'encryptAndStoreData',
{
Expand Down
4 changes: 2 additions & 2 deletions packages/encrypted-storage/src/migrations/1.createDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { migrationGetTableName } from './migration-functions.js';
*
* @public
*/
export class CreateDatabase1688974564000 implements MigrationInterface {
name = 'CreateDatabase1688974564000'; // Used in case this class gets minified, which would change the classname
export class CreateDatabase1688974564002 implements MigrationInterface {
name = 'CreateDatabase1688974564002'; // Used in case this class gets minified, which would change the classname

async up(queryRunner: QueryRunner): Promise<void> {
const dateTimeType: string = queryRunner.connection.driver.mappedDataTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ export function revocationList2020Middleware(args: {

router.use(
async (req: RequestWithAgent, res: Response, next: NextFunction) => {
if (!req.agent) {
throw Error('Agent not available');
}
try {
if (!req.agent) {
throw Error('Agent not available');
}

if (
!req.body ||
!args.apiRoutes.includes(req.path) ||
!args.supportedProofFormats.includes(req.body.proof.format)
) {
next();
return;
}
if (
!req.body ||
!args.apiRoutes.includes(req.path) ||
!args.supportedProofFormats.includes(req.body.proofFormat)
) {
next();
return;
}

try {
const revocationVCIssuer = extractIssuer(req.body.credential);

const revocationData = await req.agent.execute('getRevocationData', {
Expand Down

0 comments on commit c8bb087

Please sign in to comment.