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

refactor: restructure consent model for updated api #85

Merged
merged 13 commits into from
Aug 20, 2021

Conversation

kleyow
Copy link
Contributor

@kleyow kleyow commented Aug 13, 2021

No description provided.

import { NotFoundError, RevokedConsentModificationError } from '../errors'
import Knex from 'knex'
import { NotFoundError } from '../errors'
import Knex from 'knex';

/*
* Interface for Consent resource type
*/
export interface Consent {
Copy link
Contributor Author

@kleyow kleyow Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the Consent model was built around the idea of asking the auth-service for a challenge, storing a partial active consent and then later it would have a credential later be verified and updated on the Consent object.

Our API has changed to where the DFSP derives the challenge, PISP user signs and then the DFSP sends the Consent creation request alongside a credential to be verified.

So my thinking is

  • that the credential* fields should no longer be nullable since they are available on creation of the Consent object
  • all credentials in Consent objects are verified since the registerConsent flow verifies before storing, bringing into question if credentialStatus is still needed
  • Consent objects never need to be updated in the traditional sense. The only "updating" that happens is the revoking of the Consent. So I've removed all update logic that fell into the old logic of "create Consent object now, verify/update credential later"

The DB schema ditates a lot and I could use a second opinion @lewisdaly , as well as on any TODO you see as well.

Other than those refactors. I've added two fields that we should need later in for assertion and removed fields that I don't think necessary anymore.

@kleyow kleyow marked this pull request as ready for review August 13, 2021 05:15
Copy link
Contributor

@lewisdaly lewisdaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just commenting on the Consent interface for now, once we are in agreement we can look more closely at the db

I'm also thinking we just scrap the old model and rewrite it... I'd rather that be much more readable than break the database for our 0 users.

credentialPayload?: string;
credentialChallenge?: string;
// NOTE: not sure what purpose credentialId serves.
credentialId: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was the keyHandleId of the credential that is used to lookup the credential on the user's device.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove it, as it would be covered in credentialPayload.id

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

credentialPayload is just the public key correct? Where is credentialPayload.id coming from?

// credential on receiving them
credentialStatus: string;
// assuming this is the public key of the pair
credentialPayload: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be type string | FIDOPublicKeyCredentialAttestation, depending on the credentialType

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consent interface is 1:1 with the db are you suggesting we store all the fields from FIDOPublicKeyCredentialAttestation?

Looking at https://www.npmjs.com/package/fido2-lib I'm just assuming we need to store the public key from await f2l.attestationResult for FIDO at least

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw some old code that pointed me to the assumption that credentialPayload is a public key. Can't find it atm...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right. The f2l.attestationResult should do the trick

src/model/consent/consent.ts Outdated Show resolved Hide resolved
src/model/consent/consent.ts Outdated Show resolved Hide resolved
src/model/consent/consent.ts Show resolved Hide resolved
participantId?: string;
// participant DFSP that requested a Consent resource be made
participantId: string;
// status of the consent
status: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be of type ConsentStatus

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm auth-service used ACTIVE/REVOKED but since we are re-doing this might as well make it the same as the api currently i.e VERIFIED/REVOKED

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please.

@kleyow
Copy link
Contributor Author

kleyow commented Aug 16, 2021

I believe you are commenting under the assumption that the Consent interface is akin to the tpAPI Consent, but it really is a representation of the db model schema and is 1:1 atm. Maybe I'm wrong.

I think I'm going to rename the interface to something else.

@kleyow
Copy link
Contributor Author

kleyow commented Aug 18, 2021

Think we might need to talk this over voice chat. @lewisdaly
For now please take another look.

@lewisdaly
Copy link
Contributor

Yeah I'm pretty lost here.

Let's talk it over tonight before we dive into the thirdparty-scheme-adapter stuff

@kleyow kleyow requested a review from lewisdaly August 20, 2021 03:34
@kleyow kleyow merged commit 7999312 into mojaloop:master Aug 20, 2021
@kleyow kleyow deleted the refactor/consent branch August 20, 2021 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants