Skip to content

Commit

Permalink
fix: check instance types of record properties (#163)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra authored Jan 14, 2021
1 parent 026beb9 commit cc61c80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/lib/modules/CredentialsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ export class CredentialsModule {
public async acceptCredential(credential: CredentialRecord) {
logger.log('acceptCredential credential', credential);

// FIXME: credential.offer is already CredentialOfferMessage type
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const offer = JsonTransformer.fromJSON(credential.offer, CredentialOfferMessage);
// FIXME: transformation should be handled by credential record
const offer =
credential.offer instanceof CredentialOfferMessage
? credential.offer
: JsonTransformer.fromJSON(credential.offer, CredentialOfferMessage);

const [offerAttachment] = offer.attachments;

if (!offerAttachment.data.base64) {
Expand Down
18 changes: 10 additions & 8 deletions src/lib/protocols/credentials/CredentialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ export class CredentialService extends EventEmitter {

const proverDid = connection.did;

// FIXME: TypeScript thinks the type of credential.offer is already CredentialOfferMessage, but it still needs to be transformed
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const offer = JsonTransformer.fromJSON(credential.offer, CredentialOfferMessage);
// FIXME: transformation should be handled by credential record
const offer =
credential.offer instanceof CredentialOfferMessage
? credential.offer
: JsonTransformer.fromJSON(credential.offer, CredentialOfferMessage);
const [offerAttachment] = offer.attachments;

if (!offerAttachment.data.base64) {
Expand Down Expand Up @@ -190,10 +191,11 @@ export class CredentialService extends EventEmitter {

this.assertState(credential.state, CredentialState.RequestReceived);

// FIXME: credential.offer is already CredentialOfferMessage type
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const offer = JsonTransformer.fromJSON(credential.offer, CredentialOfferMessage);
// FIXME: transformation should be handled by credential record
const offer =
credential.offer instanceof CredentialOfferMessage
? credential.offer
: JsonTransformer.fromJSON(credential.offer, CredentialOfferMessage);
const [offerAttachment] = offer.attachments;

if (!offerAttachment.data.base64) {
Expand Down

0 comments on commit cc61c80

Please sign in to comment.