Skip to content

Commit

Permalink
♲ Refactor to the latest contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
puria committed Oct 8, 2019
1 parent d0be1a5 commit 94dbf9d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 36 deletions.
4 changes: 2 additions & 2 deletions app/routers/authorizable_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def authorizable_attribute(
optional = [_.json() for _ in item.authorizable_attribute_info_optional]

keypair_contract = ZenContract(
CONTRACTS.GENERATE_KEYPAIR, {"issuer_identifier": config.get("uid")}
CONTRACTS.GENERATE_KEYPAIR, {"MadHatter": config.get("uid")}
)
keypair = keypair_contract.execute()
contract = ZenContract(
CONTRACTS.PUBLIC_VERIFY, {"issuer_identifier": config.get("uid")}
CONTRACTS.PUBLIC_VERIFY, {"MadHatter": config.get("uid")}
)
contract.keys(keypair)
verification_key = contract.execute()
Expand Down
4 changes: 2 additions & 2 deletions app/routers/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __get_aa(authorizable_attribute_id):

def __issue_credential(keypair, bsr):
contract = ZenContract(
CONTRACTS.BLIND_SIGN, {"issuer_identifier": config.get("uid")}
CONTRACTS.BLIND_SIGN, {"MadHatter": config.get("uid")}
)
contract.keys(keypair)
contract.data(bsr)
Expand Down Expand Up @@ -114,7 +114,7 @@ def credential(
__validate_reissuing(aa, received_values)
__check_mandatory_info_fields(aa, received_values)
__check_wrong_info_fields(aa, received_values)
issued_credential = __issue_credential(aa.keypair, item.blind_sign_request.json())
issued_credential = __issue_credential(aa.keypair, json.dumps(item.blind_sign_request))
vc = ValidatedCredentials(
aaid=aa.authorizable_attribute_id, value=json.dumps(received_values)
)
Expand Down
2 changes: 1 addition & 1 deletion app/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ValidateAuthorizableAttributeInfoInput(BaseModel):
authorizable_attribute_id: str
values: List[AuthorizableAttributeInfoValue]
optional_values: List[AuthorizableAttributeInfoValue]
blind_sign_request: BlindSignatureInput
blind_sign_request: Dict


class UidOutput(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion app/test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
debug = true
uid = issuer_identifier
keypair = /home/travis/build/DECODEproject/credential-issuer/tests/ci_keypair.keys
contracts_path = /home/travis/build/DECODEproject/credential-issuer/app/contracts/src
contracts_path = /home/travis/build/DECODEproject/Zenroom/test/zencode_coconut
secret = 615872afdb35a291f56166d63399d0fa1f2a37415b24206fb051dbce294afc5c

ALGORITHM = HS256
Expand Down
40 changes: 18 additions & 22 deletions app/zencontract.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from pathlib import Path

from zenroom.zenroom import zencode_exec
from zenroom.zenroom import zencode_exec, ZenroomException

from app.config.config import BaseConfig


class CONTRACTS:
GENERATE_KEYPAIR = "03-CREDENTIAL_ISSUER-keygen.zencode"
PUBLIC_VERIFY = "04-CREDENTIAL_ISSUER-publish-verifier.zencode"
BLIND_SIGN = "05-CREDENTIAL_ISSUER-credential-sign.zencode"
CITIZEN_KEYGEN = "01-CITIZEN-credential-keygen.zencode"
CITIZEN_REQ_BLIND_SIG = "02-CITIZEN-credential-request.zencode"
AGGREGATE_CREDENTIAL = "06-CITIZEN-aggregate-credential-signature.zencode"
PROVE_CREDENTIAL = "07-CITIZEN-prove-credential.zencode"
VERIFY_CREDENTIAL = "08-VERIFIER-verify-credential.zencode"
CREATE_PETITION = "09-CITIZEN-create-petition.zencode"
APPROVE_PETITION = "10-VERIFIER-approve-petition.zencode"
SIGN_PETITION = "11-CITIZEN-sign-petition.zencode"
INCREMENT_PETITION = "12-LEDGER-add-signed-petition.zencode"
TALLY_PETITION = "13-CITIZEN-tally-petition.zencode"
COUNT_PETITION = "14-CITIZEN-count-petition.zencode"
GENERATE_KEYPAIR = "issuer_keygen.zen"
PUBLIC_VERIFY = "publish_verifier.zen"
BLIND_SIGN = "issuer_sign.zen"
CITIZEN_KEYGEN = "credential_keygen.zen"
CITIZEN_REQ_BLIND_SIG = "create_request.zen"
AGGREGATE_CREDENTIAL = "aggregate_signature.zen"
PROVE_CREDENTIAL = "create_proof.zen"
VERIFY_CREDENTIAL = "verify_proof.zen"
CREATE_PETITION = "create_petition.zen"
APPROVE_PETITION = "approve_petition.zen"
SIGN_PETITION = "sign_petition.zen"
INCREMENT_PETITION = "aggregate_petition_signature.zen"
TALLY_PETITION = "tally_petition.zen"
COUNT_PETITION = "count_petition.zen"


config = BaseConfig()
Expand Down Expand Up @@ -51,13 +51,12 @@ def execute(self):
log.debug("KEYS: %s" % self._keys)
log.debug("CODE: \n%s" % self.zencode)
try:
result, errors = zencode_exec(
result = zencode_exec(
script=self.zencode, keys=self._keys, data=self._data
)
self._error = str(errors)
except Exception:
except ZenroomException:
log.exception("Zenroom contract exception", exc_info=True)
return result
return result.stdout

def keys(self, keys=None):
if keys:
Expand All @@ -68,6 +67,3 @@ def data(self, data=None):
if data:
self._data = data
return self._data

def errors(self):
return self._error
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"bunch==1.0.1",
"fastapi==0.33.0",
"pytest_runner==4.4",
"zenroom==1.0.6",
"zenroom==1.0.7rc0",
"pre-commit==1.17.0",
"python-multipart==0.0.5",
"pyjwt==1.7.1",
Expand Down
8 changes: 5 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ def test_wrong_auth(client):


def test_generate_secret_key():
key = json.loads(ZenContract(CONTRACTS.GENERATE_KEYPAIR).execute())
keys = ["encoding", "zenroom", "sign", "schema", "curve"]
contract = json.loads(ZenContract(
CONTRACTS.GENERATE_KEYPAIR, {"MadHatter": "issuer_identifier"}
).execute())
keys = ["zenroom", "issuer_identifier"]
for _ in keys:
assert key["issuer_identifier"][_]
assert contract[_]


@pytest.fixture(scope="function")
Expand Down
8 changes: 4 additions & 4 deletions tests/test_zencontract.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ def _smart_contract_check(smart_contract, expected):
print(result)
assert result, smart_contract.errors()
for _ in expected:
assert _ in result, smart_contract.errors()
assert _ in result


def test_execute():
expected = ["encoding", "x", "zenroom", "sign", "schema", "curve"]
expected = "zenroom MadHatter".split()
contract = ZenContract(CONTRACTS.GENERATE_KEYPAIR)
_smart_contract_check(contract, expected)


def test_issuer_public():
expected = "issuer_identifier verify beta alpha".split()
expected = "zenroom MadHatter".split()
contract = ZenContract(CONTRACTS.PUBLIC_VERIFY)
contract.keys(ZenContract(CONTRACTS.GENERATE_KEYPAIR).execute())
_smart_contract_check(contract, expected)


def test_keygen():
expected = "identifier public private".split()
expected = "zenroom Alice".split()
contract = ZenContract(CONTRACTS.CITIZEN_KEYGEN)
_smart_contract_check(contract, expected)

Expand Down

0 comments on commit 94dbf9d

Please sign in to comment.