@@ -90,8 +90,6 @@ public void testAnoncredsDemo() throws Exception {
9090 String credDefId = createCredDefResult .getCredDefId ();
9191 String credDef = createCredDefResult .getCredDefJson ();
9292
93- System .out .println (credDef );
94-
9593 // Prover create Master Secret
9694 Anoncreds .proverCreateMasterSecret (proverWallet , masterSecretId ).get ();
9795
@@ -117,41 +115,49 @@ public void testAnoncredsDemo() throws Exception {
117115 " \" name\" :\" proof_req_1\" ,\n " +
118116 " \" version\" :\" 0.1\" , " +
119117 " \" requested_attributes\" : {" +
120- " \" attr1_referent\" :{\" name\" :\" name\" }" +
118+ " \" attr1_referent\" :{\" name\" :\" name\" }," +
119+ " \" attr2_referent\" :{\" name\" :\" sex\" }," +
120+ " \" attr3_referent\" :{\" name\" :\" phone\" }" +
121121 " }," +
122122 " \" requested_predicates\" :{" +
123+ " \" predicate1_referent\" :{\" name\" :\" age\" ,\" p_type\" :\" >=\" ,\" p_value\" :18}" +
123124 " }" +
124125 " }" ).toString ();
125126
126127 String credentialsForProofJson = Anoncreds .proverGetCredentialsForProofReq (proverWallet , proofRequestJson ).get ();
127128
128129 JSONObject credentialsForProof = new JSONObject (credentialsForProofJson );
129130 JSONArray credentialsForAttribute1 = credentialsForProof .getJSONObject ("attrs" ).getJSONArray ("attr1_referent" );
131+ JSONArray credentialsForAttribute2 = credentialsForProof .getJSONObject ("attrs" ).getJSONArray ("attr2_referent" );
132+ JSONArray credentialsForAttribute3 = credentialsForProof .getJSONObject ("attrs" ).getJSONArray ("attr3_referent" );
133+ JSONArray credentialsForPredicate = credentialsForProof .getJSONObject ("predicates" ).getJSONArray ("predicate1_referent" );
130134
131135 assertEquals (credentialsForAttribute1 .length (), 1 );
136+ assertEquals (credentialsForAttribute2 .length (), 1 );
137+ assertEquals (credentialsForAttribute3 .length (), 0 );
138+ assertEquals (credentialsForPredicate .length (), 1 );
132139
133140 String credentialUuid = credentialsForAttribute1 .getJSONObject (0 ).getJSONObject ("cred_info" ).getString ("referent" );
134141
135142 // Prover create Proof
136143 String selfAttestedValue = "8-800-300" ;
137144 String requestedCredentialsJson = new JSONObject (String .format ("{\n " +
138- " \" self_attested_attributes\" :{},\n " +
139- " \" requested_attributes\" :{\" attr1_referent\" :{\" cred_id\" :\" %s\" , \" revealed\" :true}},\n " +
140- " \" requested_predicates\" :{}\n " +
141- " }" , credentialUuid )).toString ();
145+ " \" self_attested_attributes\" :{\" attr3_referent\" :\" %s\" },\n " +
146+ " \" requested_attributes\" :{\" attr1_referent\" :{\" cred_id\" :\" %s\" , \" revealed\" :true},\n " +
147+ " \" attr2_referent\" :{\" cred_id\" :\" %s\" , \" revealed\" :false}},\n " +
148+ " \" requested_predicates\" :{\" predicate1_referent\" :{\" cred_id\" :\" %s\" }}\n " +
149+ " }" , selfAttestedValue , credentialUuid , credentialUuid , credentialUuid )).toString ();
142150
143151 String schemas = new JSONObject (String .format ("{\" %s\" :%s}" , gvtSchemaId , gvtSchema )).toString ();
144152 String credentialDefs = new JSONObject (String .format ("{\" %s\" :%s}" , credDefId , credDef )).toString ();
145153 String revocStates = new JSONObject ("{}" ).toString ();
146154
147155 String proofJson = Anoncreds .proverCreateProof (proverWallet , proofRequestJson , requestedCredentialsJson ,
148156 masterSecretId , schemas , credentialDefs , revocStates ).get ();
149-
150- System .out .println (proofJson );
151157 JSONObject proof = new JSONObject (proofJson );
152158
153159 // Verifier verify Proof
154- /* JSONObject revealedAttr1 = proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONObject("attr1_referent");
160+ JSONObject revealedAttr1 = proof .getJSONObject ("requested_proof" ).getJSONObject ("revealed_attrs" ).getJSONObject ("attr1_referent" );
155161 assertEquals ("Alex" , revealedAttr1 .getString ("raw" ));
156162
157163 assertNotNull (proof .getJSONObject ("requested_proof" ).getJSONObject ("unrevealed_attrs" ).getJSONObject ("attr2_referent" ).getInt ("sub_proof_index" ));
@@ -162,7 +168,7 @@ public void testAnoncredsDemo() throws Exception {
162168 String revocRegs = new JSONObject ("{}" ).toString ();
163169
164170 Boolean valid = Anoncreds .verifierVerifyProof (proofRequestJson , proofJson , schemas , credentialDefs , revocRegDefs , revocRegs ).get ();
165- assertTrue(valid);*/
171+ assertTrue (valid );
166172 }
167173
168174 @ Test
@@ -620,4 +626,4 @@ public void testVerifyProofWorksForProofDoesNotCorrespondToProofRequest() throws
620626
621627 Anoncreds .verifierVerifyProof (proofRequestJson , proofJson , schemas , credentialDefs , revocRegDefs , revocRegs ).get ();
622628 }
623- }
629+ }
0 commit comments