/// <inheritdoc /> public virtual async Task <List <Credential> > ListCredentialsForProofRequestAsync(IAgentContext agentContext, ProofRequest proofRequest, string attributeReferent) { using (var search = await AnonCreds.ProverSearchCredentialsForProofRequestAsync(agentContext.Wallet, proofRequest.ToJson())) { var searchResult = await search.NextAsync(attributeReferent, 100); return(JsonConvert.DeserializeObject <List <Credential> >(searchResult)); } }
/// <inheritdoc /> public virtual async Task <List <Credential> > ListCredentialsForProofRequestAsync(IAgentContext agentContext, ProofRequest proofRequest, string attributeReferent) { using (var search = await AnonCreds.ProverSearchCredentialsForProofRequestAsync(agentContext.Wallet, proofRequest.ToJson())) { var searchResult = await search.NextAsync(attributeReferent, 100); var result = JsonConvert.DeserializeObject <List <Credential> >(searchResult); if (proofRequest.NonRevoked != null) { return(result.Where(x => x.CredentialInfo.RevocationRegistryId != null).ToList()); } return(result); } }
public async Task TestProverSearchCredentialsForProofRequestWorksForNotFound() { var proofRequest = "{" + " \"nonce\":\"123432421212\"," + " \"name\":\"proof_req_1\"," + " \"version\":\"0.1\"," + " \"requested_attributes\":{" + " \"attr1_referent\":{\"name\":\"not_found_attr\"}" + " }," + " \"requested_predicates\":{}" + " }"; var credentialsSearch = await AnonCreds.ProverSearchCredentialsForProofRequestAsync(wallet, proofRequest); var credentialsForAttribute1 = await credentialsSearch.NextAsync("attr1_referent", 100); var jsonArray = JArray.Parse(credentialsForAttribute1); Assert.AreEqual(0, jsonArray.Count); //TODO: Shouldn't there be an explicit close of the credential search here? }
public async Task testProverSearchCredentialsForProofRequestWorksForRevealedAttributeAndExtraQuery() { var proofRequest = "{" + " \"nonce\":\"123432421212\"," + " \"name\":\"proof_req_1\"," + " \"version\":\"0.1\"," + " \"requested_attributes\":{" + " \"attr1_referent\":{\"name\":\"name\"}" + " }," + " \"requested_predicates\":{}" + " }"; var extraQuery = "{\"attr1_referent\": { \"attr::name::value\": \"Alex\"}}"; var credentialsSearch = await AnonCreds.ProverSearchCredentialsForProofRequestAsync(wallet, proofRequest, extraQuery); var credentialsForAttribute1 = await credentialsSearch.NextAsync("attr1_referent", 100); var jsonArray = JArray.Parse(credentialsForAttribute1); Assert.AreEqual(1, jsonArray.Count); //TODO: Shouldn't there be an explicit close of the credential search here? }
/* * Proofs the holder of the open wallet is a doctor by using the first * credential that meets the docotr proof requirements. */ public static async Task <string> createDoctorProof( Wallet wallet, string masterKey = "doctor-certificate") { string proofReqJson = getProofRequest(); proofReqJson = proofReqJson.Replace(" ", string.Empty); proofReqJson = proofReqJson.Replace(Environment.NewLine, string.Empty); try { var credList = await AnonCreds.ProverSearchCredentialsForProofRequestAsync( wallet, proofReqJson); string attr1Cred = await getCredentialforRequest( credList, "attr1_referent"); string attr2Cred = await getCredentialforRequest( credList, "attr2_referent"); string predicate1Cred = await getCredentialforRequest( credList, "predicate1_referent"); string requestedCreds = proverDoctorRequestCreds( getReferentFromCredential(attr1Cred), getReferentFromCredential(attr2Cred), getReferentFromCredential(predicate1Cred)); EmergencyDoctorCredentialModel model = EmergencyDoctorCredentialModel.importFromJsonFile(); // IOFacilitator io = new IOFacilitator(); // DoctorCredDefInfoModel model = JsonConvert.DeserializeObject // <DoctorCredDefInfoModel>(File.ReadAllText( // io.getDoctorCredDefConfigPathAbs())); string schemas = "{"; schemas += "\"" + model.schema_id + "\":" + model.schema_json; schemas += "}"; string credDefs = "{"; credDefs += "\"" + model.cred_def_id + "\":" + model.cred_def_json; credDefs += "}"; string res = await AnonCreds.ProverCreateProofAsync( wallet, proofReqJson, requestedCreds, masterKey, schemas, credDefs, "{}" ); return(res); } catch (InvalidOperationException e) { return(e.Message); } catch (Exception e) { return($"Error: {e.Message}"); } }