Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
bachelor 2022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mikkel Aas
bachelor 2022
Commits
05b9b7b2
Commit
05b9b7b2
authored
May 11, 2022
by
Mikkel Aas
Browse files
Options
Downloads
Patches
Plain Diff
added a function that verifies the data within a termination vc
parent
93584b5b
Branches
Branches containing commit
No related tags found
1 merge request
!88
Nav verifier extended
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/controllers/NAVAgentController.ts
+32
-6
32 additions, 6 deletions
src/controllers/NAVAgentController.ts
with
32 additions
and
6 deletions
src/controllers/NAVAgentController.ts
+
32
−
6
View file @
05b9b7b2
import
{
TYPE_EMPLOYMENT_CREDENTIAL
,
TYPE_PERSON_CREDENTIAL
,
TYPE_TERMINATION_CREDENTIAL
}
from
'
../constants/verifiableCredentialConstants
'
;
import
{
agentNAV
}
from
'
../veramo/veramo.setup
'
;
import
{
AgentController
}
from
'
./AgentController
'
;
import
{
computeYearsBetweenDates
}
from
'
../utils/dateUtils
'
;
import
{
IVCMessageDataPerson
}
from
'
../interfaces/message.interface
'
;
import
{
computeMonthsBetweenDates
,
computeYearsBetweenDates
}
from
'
../utils/dateUtils
'
;
import
{
IVCMessageDataPerson
,
IVCMessageDataTermination
}
from
'
../interfaces/message.interface
'
;
import
{
issuers
,
verifyIssuer
,
verifySchema
}
from
'
../utils/verifyPresentation
'
;
import
{
INAVAgentController
}
from
'
../interfaces/navAgentController.interface
'
;
...
...
@@ -49,7 +49,7 @@ export class NAVAgentController extends AgentController implements INAVAgentCont
});
// get credential message data
const
credentialMessageData
:
IVCMessageDataPerson
=
credentialMessage
.
data
;
const
credentialMessageData
:
any
=
credentialMessage
.
data
;
switch
(
credentialMessageData
.
vc
.
type
.
at
(
1
))
{
case
TYPE_EMPLOYMENT_CREDENTIAL
:
...
...
@@ -65,7 +65,8 @@ export class NAVAgentController extends AgentController implements INAVAgentCont
case
TYPE_TERMINATION_CREDENTIAL
:
if
(
!
await
verifySchema
(
credentialMessageData
)
||
!
await
verifyIssuer
(
credentialMessageData
,
issuers
.
symfoni
)
!
await
verifyIssuer
(
credentialMessageData
,
issuers
.
symfoni
)
||
!
this
.
verifyTerminationVCData
(
credentialMessageData
)
)
{
return
false
;
}
...
...
@@ -115,8 +116,33 @@ export class NAVAgentController extends AgentController implements INAVAgentCont
}
return
true
;
}
catch
(
error
)
{
console
.
error
(
error
);
return
new
Error
(
'
unable to verify person data
'
);
}
}
/**
* verifyTerminationVCData verifies the data within the termination contract credential.
* @param credentialMessageData the credential message.
* @returns true if all requirements are met.
*/
private
verifyTerminationVCData
(
credentialMessageData
:
IVCMessageDataTermination
):
boolean
|
Error
{
try
{
const
todaysDate
=
new
Date
().
toISOString
();
const
lastPayDay
=
credentialMessageData
.
vc
.
credentialSubject
.
termination
.
employee
.
lastPayday
;
const
years
=
computeYearsBetweenDates
(
lastPayDay
,
todaysDate
);
const
months
=
computeMonthsBetweenDates
(
lastPayDay
,
todaysDate
);
// if years is more than one, or months is less than three, return false
if
(
years
>
1
||
months
<
3
)
{
return
false
;
}
return
true
;
}
catch
(
error
)
{
return
new
Error
(
'
unable to verify the termination contract data
'
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment