1
1
const uuidv4 = require ( 'uuid/v4' ) ;
2
2
const { Claim } = require ( 'claim/Claim' ) ;
3
- const VC = require ( 'creds/VerifiableCredential' ) ;
4
3
const { schemaLoader, CVCSchemaLoader } = require ( 'index' ) ;
4
+ const didTestUtil = require ( "../../__test__/lib/util/did" ) ;
5
+
6
+ const solResolver = require ( 'lib/did' ) ;
7
+ const { VerifiableCredential} = require ( 'vc/VerifiableCredential' )
8
+ const CvcMerkleProof = require ( 'proof/CvcMerkleProof' ) . default ;
9
+ const { Ed25519SignerVerifier} = require ( "proof/CvcMerkleProof/Ed25519SignerVerifier" ) ;
5
10
6
11
const credentialSubject = 'did:sol:J2vss1hB3kgEfQMSSdvvjwRm3JdyFWp7S7dbX5mudS4V' ;
7
12
13
+
14
+ const cvcMerkleProof = new CvcMerkleProof ( new Ed25519SignerVerifier (
15
+ solResolver ,
16
+ `${ didTestUtil . DID_CONTROLLER } #default` ,
17
+ didTestUtil . keyPair ( didTestUtil . DID_CONTROLLER ) ) ) ;
18
+
8
19
jest . setTimeout ( 200000 ) ;
9
20
10
21
describe ( 'Integration Tests for Verifiable Credentials' , ( ) => {
@@ -18,11 +29,21 @@ describe('Integration Tests for Verifiable Credentials', () => {
18
29
19
30
it ( 'should request an anchor for Credential and return an temporary attestation' , async ( done ) => {
20
31
const name = await Claim . create ( 'claim-cvc:Identity.name-v1' ,
21
- { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
32
+ { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
22
33
23
34
const dob = await Claim . create ( 'claim-cvc:Identity.dateOfBirth-v1' , { day : 20 , month : 3 , year : 1978 } ) ;
24
- const cred = await VC . create ( 'credential-cvc:Identity-v3' , uuidv4 ( ) , null , credentialSubject , [ name , dob ] ) ;
25
- return cred . requestAnchor ( ) . then ( ( updated ) => {
35
+
36
+ const unsignedCred = await VerifiableCredential . create ( {
37
+ issuer : didTestUtil . DID_CONTROLLER ,
38
+ identifier : 'credential-cvc:Identity-v3' ,
39
+ subject : credentialSubject ,
40
+ claims : [ name , dob ] ,
41
+ expiry : null ,
42
+ } ) ;
43
+
44
+ const cred = await cvcMerkleProof . sign ( unsignedCred ) ;
45
+
46
+ return CvcMerkleProof . requestAnchor ( cred ) . then ( ( updated ) => {
26
47
expect ( updated . proof . anchor . type ) . toBe ( 'temporary' ) ;
27
48
expect ( updated . proof . anchor . value ) . not . toBeDefined ( ) ;
28
49
expect ( updated . proof . anchor ) . toBeDefined ( ) ;
@@ -33,13 +54,23 @@ describe('Integration Tests for Verifiable Credentials', () => {
33
54
34
55
it ( 'should refresh an temporary anchoring with an permanent one' , async ( done ) => {
35
56
const name = await Claim . create ( 'claim-cvc:Identity.name-v1' ,
36
- { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
57
+ { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
37
58
38
59
const dob = await Claim . create ( 'claim-cvc:Identity.dateOfBirth-v1' , { day : 20 , month : 3 , year : 1978 } ) ;
39
- const cred = await VC . create ( 'credential-cvc:Identity-v3' , uuidv4 ( ) , null , credentialSubject , [ name , dob ] ) ;
40
- return cred . requestAnchor ( ) . then ( ( updated ) => {
60
+
61
+ const unsignedCred = await VerifiableCredential . create ( {
62
+ issuer : didTestUtil . DID_CONTROLLER ,
63
+ identifier : 'credential-cvc:Identity-v3' ,
64
+ subject : credentialSubject ,
65
+ claims : [ name , dob ] ,
66
+ expiry : null ,
67
+ } ) ;
68
+
69
+ const cred = await cvcMerkleProof . sign ( unsignedCred ) ;
70
+
71
+ return CvcMerkleProof . requestAnchor ( cred ) . then ( ( updated ) => {
41
72
expect ( updated . proof . anchor ) . toBeDefined ( ) ;
42
- return updated . updateAnchor ( ) . then ( ( newUpdated ) => {
73
+ return CvcMerkleProof . updateAnchor ( updated ) . then ( ( newUpdated ) => {
43
74
expect ( newUpdated . proof . anchor . type ) . toBe ( 'permanent' ) ;
44
75
expect ( newUpdated . proof . anchor ) . toBeDefined ( ) ;
45
76
expect ( newUpdated . proof . anchor . value ) . toBeDefined ( ) ;
@@ -49,15 +80,25 @@ describe('Integration Tests for Verifiable Credentials', () => {
49
80
} ) ;
50
81
it ( 'should revoke the permanent anchor and succed verification' , async ( done ) => {
51
82
const name = await Claim . create ( 'claim-cvc:Identity.name-v1' ,
52
- { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
83
+ { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
53
84
54
85
const dob = await Claim . create ( 'claim-cvc:Identity.dateOfBirth-v1' , { day : 20 , month : 3 , year : 1978 } ) ;
55
- const cred = await VC . create ( 'credential-cvc:Identity-v3' , uuidv4 ( ) , null , credentialSubject , [ name , dob ] ) ;
56
- await cred . requestAnchor ( ) ;
57
- await cred . updateAnchor ( ) ;
58
- const validation = await cred . verifyAttestation ( ) ;
86
+
87
+ const unsignedCred = await VerifiableCredential . create ( {
88
+ issuer : didTestUtil . DID_CONTROLLER ,
89
+ identifier : 'credential-cvc:Identity-v3' ,
90
+ subject : credentialSubject ,
91
+ claims : [ name , dob ] ,
92
+ expiry : null ,
93
+ } ) ;
94
+
95
+ const cred = await cvcMerkleProof . sign ( unsignedCred ) ;
96
+
97
+ await CvcMerkleProof . requestAnchor ( cred ) ;
98
+ await CvcMerkleProof . updateAnchor ( cred ) ;
99
+ const validation = await CvcMerkleProof . verifyAttestation ( cred ) ;
59
100
if ( validation ) {
60
- const isRevoked = await cred . revokeAttestation ( ) ;
101
+ const isRevoked = await CvcMerkleProof . revokeAttestation ( cred ) ;
61
102
expect ( isRevoked ) . toBeTruthy ( ) ;
62
103
}
63
104
done ( ) ;
0 commit comments