コード例 #1
0
        public static async Task <bool> verifyDoctorProof(string proofJson)
        {
            string proofReqJson = getProofRequest();

            proofReqJson = proofReqJson.Replace(" ", string.Empty);
            proofReqJson = proofReqJson.Replace(Environment.NewLine, string.Empty);
            try
            {
                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 += "}";

                bool result = await AnonCreds.VerifierVerifyProofAsync(proofReqJson, proofJson,
                                                                       schemas, credDefs, "{}", "{}");

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
                return(false);
            }
        }
コード例 #2
0
        static public EmergencyDoctorCredentialModel importFromJsonFile()
        {
            string importJson = IOFacilitator.readFile(
                EmergencyDoctorCredentialModel.filePath());

            return(JsonConvert.DeserializeObject
                   <EmergencyDoctorCredentialModel>(importJson));
        }
コード例 #3
0
        public async Task createERCredentials(string issuer, string issuerDid,
                                              string schemaJson)
        {
            await initialize(issuer, issuerDid);



            Console.WriteLine("creating CredDef for schema Doctor-Certificate");
            string credDefDefinition = await d_ledger.createCredDef(
                schemaJson, "TAG1");

            JObject o         = JObject.Parse(credDefDefinition);
            string  credDefId = o["id"].ToString();

            string credOffer = await d_wallet.createCredentialOffer(credDefId);

            Console.WriteLine("Creating Docotor-Certificate Credentials for: ");
            string[] doctors = { "Doctor1", "Doctor2", "Doctor3" };

            o = JObject.Parse(schemaJson);
            string schemaId = o["id"].ToString();

            EmergencyDoctorCredentialModel model = new EmergencyDoctorCredentialModel(
                issuerDid,
                schemaId,
                schemaJson,
                credDefId,
                credDefDefinition);

            model.exportToJsonFile();

            foreach (string doctor in doctors)
            {
                Console.WriteLine(doctor);
                await initialize(doctor);

                string linkSecret =
                    await d_wallet.createMasterSecret("doctor-certificate");

                string credReq = await d_wallet.createCredentialRequest(
                    credOffer, credDefDefinition, linkSecret);

                o = JObject.Parse(credReq);
                string credReqJson     = o["CredentialRequestJson"].ToString();
                string credReqMetaJson =
                    o["CredentialRequestMetadataJson"].ToString();

                string schemaAttributes =
                    "[\"is_emergency_doctor\", \"name\", \"school\"]";
                string schemaValues = "[1, \"" + doctor + "\", \"RUG\"]";
                string credValue    = CredentialFacilitator.generateCredValueJson(
                    schemaAttributes, schemaValues);
                await d_wallet.open(issuer);

                string cred = await d_wallet.createCredential(credOffer,
                                                              credReqJson, credValue);

                await d_wallet.open(doctor);

                await d_wallet.storeCredential(credReqMetaJson,
                                               cred, credDefDefinition);
            }
        }
コード例 #4
0
        /*
         * 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}");
            }
        }