-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
103 lines (103 loc) · 3.79 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { DidIonMethod } from '@web5/dids';
import { vcGovern } from './vc-govern.js';
// __FOR_TESTING_ONLY__
const issuerPortableDID = await DidIonMethod.create();
const subjectPortableDID = await DidIonMethod.create();
const payload = {
issuer: issuerPortableDID,
subject: subjectPortableDID,
type: 'SiloVerificationCredential',
data: {
siloNum: 'silo0_UR001',
fullName: 'Tobiloba Ajibade',
city: 'Ibadan',
state: 'Oyo',
country: 'Nigeria',
joinedAt: new Date().toISOString(),
},
};
const PD = {
id: 'siloPD001',
name: 'Credential verification for silo estate residents',
purpose: 'To identity legitness of silo estate resident',
input_descriptors: [
{
id: 'siloResidenceVerification',
name: 'Silo Residence Verification',
purpose: 'Verify user residence permission',
constraints: {
fields: [
{
id: 'siloVerificationType',
purpose: "Select only VC(s) with type 'siloVerification'",
path: ['$.type[*]'],
filter: {
type: 'string',
pattern: 'SiloVerification',
},
},
{
id: 'siloNum',
purpose: 'Confirm silo resident number',
path: ['$.credentialSubject.siloNum'],
filter: {
type: 'string',
pattern: 'silo0_UR',
},
},
{
id: 'fullName',
purpose: 'Confirm silo resident full name',
path: ['$.credentialSubject.fullName'],
filter: {
type: 'string',
},
},
{
id: 'state',
purpose: 'Confirm silo resident state',
path: ['$.credentialSubject.state'],
filter: {
type: 'string',
},
},
{
id: 'city',
purpose: 'Confirm silo resident city',
path: ['$.credentialSubject.city'],
filter: {
type: 'string',
},
},
{
id: 'country',
purpose: 'Confirm silo resident country',
path: ['$.credentialSubject.country'],
filter: {
type: 'string',
},
},
{
id: 'joinedAt',
purpose: 'Confirm date and time resident joined silo estate',
path: ['$.credentialSubject.joinedAt'],
filter: {
type: 'string',
},
},
],
},
},
],
};
// Issue VC
const vcJwt = await vcGovern.issueVerifiableCredential(payload);
if (vcJwt) {
// Generate a presentation
const presentation = vcGovern.generatePresentation(PD, [vcJwt]);
// Verify single credential and return data content
const verify = await vcGovern.verifyCredential(vcJwt, true);
// Verify credential using the generated presentation instead
const verifyFromPresentation = await vcGovern.verifyCredentialFromPresentation(presentation, true);
console.log(verifyFromPresentation);
}