def handle_credentials(self, state, message):
        global admin_url
        credential_exchange_id = message["credential_exchange_id"]
        s_print(
            "Credential: state=",
            state,
            ", credential_exchange_id=",
            credential_exchange_id,
        )

        if state == "request_received":
            print("#17 Issue credential to X")
            cred_attrs = {
                "name": "Alice Smith",
                "date": "2018-05-28",
                "degree": "Maths",
                "age": "24",
            }
            resp = requests.post(
                admin_url + "/credential_exchange/" + credential_exchange_id +
                "/issue",
                json={"credential_values": cred_attrs},
            )
            assert resp.status_code == 200

            return ""

        return ""
    def handle_presentations(self, state, message):
        global admin_url
        presentation_exchange_id = message["presentation_exchange_id"]
        s_print(
            "Presentation: state=",
            state,
            ", presentation_exchange_id=",
            presentation_exchange_id,
        )

        if state == "presentation_received":
            print("#27 Process the proof provided by X")
            print("#28 Check if proof is valid")
            resp = requests.post(admin_url + "/presentation_exchange/" +
                                 presentation_exchange_id +
                                 "/verify_presentation")
            assert resp.status_code == 200
            proof = json.loads(resp.text)

            s_print("Proof =", proof["verified"])

            return ""

        return ""
示例#3
0
    def handle_credentials(self, state, message):
        global admin_url
        credential_exchange_id = message["credential_exchange_id"]
        s_print(
            "Credential: state=",
            state,
            ", credential_exchange_id=",
            credential_exchange_id,
        )

        if state == "offer_received":
            print(
                "#15 After receiving credential offer, send credential request"
            )
            resp = requests.post(admin_url + "/credential_exchange/" +
                                 credential_exchange_id + "/send-request")
            assert resp.status_code == 200
            return ""

        elif state == "stored":
            print("Stored credential in wallet")
            resp = requests.get(admin_url + "/credential/" +
                                message["credential_id"])
            assert resp.status_code == 200
            print("Stored credential:")
            print(resp.text)
            print("credential_id", message["credential_id"])
            print("credential_definition_id",
                  message["credential_definition_id"])
            print("schema_id", message["schema_id"])
            print("credential_request_metadata",
                  message["credential_request_metadata"])

            return ""

        return ""
示例#4
0
    def handle_presentations(self, state, message):
        global admin_url
        presentation_exchange_id = message["presentation_exchange_id"]
        presentation_request = message["presentation_request"]

        s_print(
            "Presentation: state=",
            state,
            ", presentation_exchange_id=",
            presentation_exchange_id,
        )

        if state == "request_received":
            print(
                "#24 Query for credentials in the wallet that satisfy the proof request"
            )

            # include self-attested attributes (not included in credentials)
            revealed = {}
            self_attested = {}
            predicates = {}

            for referent in presentation_request["requested_attributes"]:

                # select credentials to provide for the proof
                creds = requests.get(admin_url + "/presentation_exchange/" +
                                     presentation_exchange_id +
                                     "/credentials/" + referent)
                assert creds.status_code == 200
                credentials = json.loads(creds.text)

                if credentials:
                    revealed[referent] = {
                        "cred_id": credentials[0]["cred_info"]["referent"],
                        "revealed": True,
                    }
                else:
                    self_attested[referent] = "my self-attested value"

            for referent in presentation_request["requested_predicates"]:

                # select credentials to provide for the proof
                creds = requests.get(admin_url + "/presentation_exchange/" +
                                     presentation_exchange_id +
                                     "/credentials/" + referent)
                assert creds.status_code == 200
                credentials = json.loads(creds.text)

                if credentials:
                    predicates[referent] = {
                        "cred_id": credentials[0]["cred_info"]["referent"],
                        "revealed": True,
                    }

            print("#25 Generate the proof")
            proof = {
                "name": presentation_request["name"],
                "version": presentation_request["version"],
                "requested_predicates": predicates,
                "requested_attributes": revealed,
                "self_attested_attributes": self_attested,
            }
            print("#26 Send the proof to X")
            resp = requests.post(
                admin_url + "/presentation_exchange/" +
                presentation_exchange_id + "/send_presentation",
                json=proof,
            )
            assert resp.status_code == 200

            return ""

        return ""