11const uuidv4 = require ( 'uuid/v4' ) ;
22const { Claim } = require ( 'claim/Claim' ) ;
3- const VC = require ( 'creds/VerifiableCredential' ) ;
43const { 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" ) ;
510
611const credentialSubject = 'did:sol:J2vss1hB3kgEfQMSSdvvjwRm3JdyFWp7S7dbX5mudS4V' ;
712
13+
14+ const cvcMerkleProof = new CvcMerkleProof ( new Ed25519SignerVerifier (
15+ solResolver ,
16+ `${ didTestUtil . DID_CONTROLLER } #default` ,
17+ didTestUtil . keyPair ( didTestUtil . DID_CONTROLLER ) ) ) ;
18+
819jest . setTimeout ( 200000 ) ;
920
1021describe ( 'Integration Tests for Verifiable Credentials' , ( ) => {
@@ -18,11 +29,21 @@ describe('Integration Tests for Verifiable Credentials', () => {
1829
1930 it ( 'should request an anchor for Credential and return an temporary attestation' , async ( done ) => {
2031 const name = await Claim . create ( 'claim-cvc:Identity.name-v1' ,
21- { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
32+ { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
2233
2334 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 ) => {
2647 expect ( updated . proof . anchor . type ) . toBe ( 'temporary' ) ;
2748 expect ( updated . proof . anchor . value ) . not . toBeDefined ( ) ;
2849 expect ( updated . proof . anchor ) . toBeDefined ( ) ;
@@ -33,13 +54,23 @@ describe('Integration Tests for Verifiable Credentials', () => {
3354
3455 it ( 'should refresh an temporary anchoring with an permanent one' , async ( done ) => {
3556 const name = await Claim . create ( 'claim-cvc:Identity.name-v1' ,
36- { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
57+ { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
3758
3859 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 ) => {
4172 expect ( updated . proof . anchor ) . toBeDefined ( ) ;
42- return updated . updateAnchor ( ) . then ( ( newUpdated ) => {
73+ return CvcMerkleProof . updateAnchor ( updated ) . then ( ( newUpdated ) => {
4374 expect ( newUpdated . proof . anchor . type ) . toBe ( 'permanent' ) ;
4475 expect ( newUpdated . proof . anchor ) . toBeDefined ( ) ;
4576 expect ( newUpdated . proof . anchor . value ) . toBeDefined ( ) ;
@@ -49,15 +80,25 @@ describe('Integration Tests for Verifiable Credentials', () => {
4980 } ) ;
5081 it ( 'should revoke the permanent anchor and succed verification' , async ( done ) => {
5182 const name = await Claim . create ( 'claim-cvc:Identity.name-v1' ,
52- { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
83+ { givenNames : 'Joao' , otherNames : 'Barbosa' , familyNames : 'Santos' } ) ;
5384
5485 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 ) ;
59100 if ( validation ) {
60- const isRevoked = await cred . revokeAttestation ( ) ;
101+ const isRevoked = await CvcMerkleProof . revokeAttestation ( cred ) ;
61102 expect ( isRevoked ) . toBeTruthy ( ) ;
62103 }
63104 done ( ) ;
0 commit comments