Skip to content

Commit

Permalink
Id of credential
Browse files Browse the repository at this point in the history
Fixes #90

Signed-off-by: Mirko Mollik <mirkomollik@gmail.com>
  • Loading branch information
cre8 committed Jul 28, 2024
1 parent 99b5b19 commit 54fa829
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 35 deletions.
25 changes: 17 additions & 8 deletions apps/holder-backend/src/app/credentials/credentials.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CredentialResponse } from './dto/credential-response.dto';
import { OnEvent } from '@nestjs/event-emitter';
import { USER_DELETED_EVENT, UserDeletedEvent } from '../auth/auth.service';
import { Interval } from '@nestjs/schedule';
import { createHash } from 'crypto';

type DateKey = 'exp' | 'nbf';
@Injectable()
Expand All @@ -41,20 +42,28 @@ export class CredentialsService {
}

async create(createCredentialDto: CreateCredentialDto, user: string) {
const credential = new Credential();
credential.id = createCredentialDto.id;
credential.user = user;
credential.value = createCredentialDto.value;
credential.metaData = createCredentialDto.metaData;
credential.issuer = createCredentialDto.issuer;
credential.nbf = await this.getDate(createCredentialDto.value, 'nbf');
credential.exp = await this.getDate(createCredentialDto.value, 'exp');
const credential = this.credentialRepository.create({
...createCredentialDto,
user,
id: this.getCredentialId(createCredentialDto),
nbf: await this.getDate(createCredentialDto.value, 'nbf'),
exp: await this.getDate(createCredentialDto.value, 'exp'),
});
await this.credentialRepository.save(credential);
return {
id: credential.id,
};
}

/**
* Create the id of the credential based on the hash of the value.
* @param createCredentialDto
* @returns
*/
private getCredentialId(createCredentialDto: CreateCredentialDto): string {
return createHash('sha256').update(createCredentialDto.value).digest('hex');
}

/**
* Get the date from the credential, use key to get the correct value.
* @param credential
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
<mat-card-subtitle>{{ issuer[0].description }}</mat-card-subtitle>
</mat-card-header>
<img
*ngIf="credentials"
[src]="credentials[0].display![0].background_image?.url"
[alt]="credentials[0].display![0].background_image?.url"
*ngIf="
credentials &&
credentials[0].display &&
credentials[0].display[0].background_image
"
[src]="credentials[0].display[0].background_image.url"
[alt]="credentials[0].display[0].background_image.url"
/>
<!-- instead of just the credential name, we could present the credential with it's attributes. In this case the parse event was already executed and we need a "accept" button to persist it into the database. Because it could be that the holder is denying the credential.-->
<mat-card-content *ngIf="credentials">
<p>wants to offer you a credential.</p>
<mat-list>
<mat-list-item>
<span matListItemTitle>{{ credentials[0].display![0].name }}</span>
<span matListItemLine>{{
credentials[0].display![0].description
}}</span>
@for(credential of credentials; track credential) {
<mat-list-item *ngIf="credential.display">
<span matListItemTitle>{{ credential.display[0].name }}</span>
<span matListItemLine>{{ credential.display[0].description }}</span>
</mat-list-item>
}
</mat-list>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayoutAlign="space-between center">
Expand Down
44 changes: 25 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 54fa829

Please sign in to comment.