Example #1
0
    def test_request(self):
        with coconut_contract.test_service():
            ## create transactions
            # init
            init_transaction = coconut_chainspace.init()
            token = init_transaction['transaction']['outputs'][0]
            # create instance
            create_transaction = coconut_chainspace.create(
                (token, ),
                None,
                None,
                q,
                t,
                n,
                callback,
                aggr_vk,
            )
            instance = create_transaction['transaction']['outputs'][1]
            # request
            transaction = coconut_chainspace.request(
                (instance, ), None, None, public_m, private_m, gamma)

            ## submit transaction
            response = requests.post('http://127.0.0.1:5000/' +
                                     coconut_contract.contract_name +
                                     '/request',
                                     json=transaction_to_solution(transaction))
            self.assertTrue(response.json()['success'])
Example #2
0
    def test_init(self):
        with coconut_contract.test_service():
            ## create transaction
            transaction = coconut_chainspace.init()

            ## submit transaction
            response = requests.post('http://127.0.0.1:5000/' +
                                     coconut_contract.contract_name + '/init',
                                     json=transaction_to_solution(transaction))
            self.assertTrue(response.json()['success'])
Example #3
0
    def test_issue(self):
        with coconut_contract.test_service():
            ## create transactions
            # init
            init_transaction = coconut_chainspace.init()
            token = init_transaction['transaction']['outputs'][0]
            # create instance
            create_transaction = coconut_chainspace.create(
                (token, ),
                None,
                None,
                q,
                t,
                n,
                callback,
                aggr_vk,
            )
            instance = create_transaction['transaction']['outputs'][1]
            # request
            request_transaction = coconut_chainspace.request(
                (instance, ), None, None, public_m, private_m, gamma)
            old_request = request_transaction['transaction']['outputs'][1]

            # issue a credential
            transaction = coconut_chainspace.issue((old_request, ), None,
                                                   (0, ), sk[0])
            old_request = transaction['transaction']['outputs'][0]

            ## submit transaction
            response = requests.post('http://127.0.0.1:5000/' +
                                     coconut_contract.contract_name + '/issue',
                                     json=transaction_to_solution(transaction))
            self.assertTrue(response.json()['success'])

            # issue the other credential
            for i in range(1, n):
                transaction = coconut_chainspace.issue((old_request, ), None,
                                                       (i, ), sk[i])
                old_request = transaction['transaction']['outputs'][0]

            # some crypto - to show that this actually works
            # ------------------------------------
            packed_sigs_tilde = loads(old_request)['sigs']
            sigs_tilde = [unpack(x) for x in packed_sigs_tilde]
            sigs = [
                unblind(params, sigma_tilde, d) for sigma_tilde in sigs_tilde
            ]
            aggr_sigma = agg_cred(params, sigs)
            Theta = prove_cred(params, aggr_vk, aggr_sigma, private_m)
            print("\n\n=================== VERIFICATION ===================\n")
            print(verify_cred(params, aggr_vk, Theta, public_m=public_m))
            print("\n====================================================\n\n")