Skip to content

Commit

Permalink
[SC-773] Edit github workflows.
Browse files Browse the repository at this point in the history
  • Loading branch information
hyerim-kim committed Aug 31, 2023
1 parent cdc577c commit 7e9a37c
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 187 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/linting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint

on: [pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: pip
- name: check sort imports with isort
uses: isort/isort-action@v1
with:
configuration: "--check-only --diff --verbose"
sortPaths: "./myid ./tests"

- name: check code formatting with black
uses: psf/black@stable
with:
options: "--check --verbose"
src: "./myid ./tests"
23 changes: 3 additions & 20 deletions .github/workflows/action.yml → .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
python-version: '3.11'
- name: Change private repo url
run: |
sed -i -e "s/git@/${{ secrets.ICONLOOP_PRIVATE_REPO_ACCESS_TOKEN }}@/" -e "s/git+ssh:/git+https:/" requirements.txt
sed -i -e "s/git@/${{ secrets.ICONLOOP_PRIVATE_REPO_ACCESS_TOKEN }}@/" -e "s/git+ssh:/git+https:/" pyproject.toml
- name: Install dependencies for ecdsa
run: |
sudo apt-get update
Expand All @@ -24,23 +24,6 @@ jobs:
- name: Install dependencies
run: |
python -V
pip install -e .[tests]
pip install -e .[dev]
- name: Run unit tests
run: pytest -vx
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Remove unnecessary dependencies for lint test
run: |
echo "" > requirements.txt
- name: Install dependencies
run: |
python -V
pip install -e .[lint]
- name: Lint
run: flake8
run: pytest -vx
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
# - repo: https://github.com/pycqa/isort
# rev: 5.12.0
# hooks:
# - id: isort

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.11
args: [--line-length=120]
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

2 changes: 1 addition & 1 deletion myid/base_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dataclasses
from typing import Dict, Optional, Any
from typing import Any, Dict, Optional

from didsdk.document.document import Document
from didsdk.jwe.ecdhkey import ECDHKey
Expand Down
20 changes: 10 additions & 10 deletions myid/core/api_path.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
class APIPath:
# IV WAS
# GET
R_DID = '/v1/did/'
GET_VC = '/v1/credential'
IS_VALID_VC = '/v1/credential/isValid'
R_DID = "/v1/did/"
GET_VC = "/v1/credential"
IS_VALID_VC = "/v1/credential/isValid"

# POST
C_DID = '/v1/did/create'
U_DID = '/v1/did/update'
REG_VC = '/v1/credential/register'
REV_VC = '/v1/credential/revoke'
C_DID = "/v1/did/create"
U_DID = "/v1/did/update"
REG_VC = "/v1/credential/register"
REV_VC = "/v1/credential/revoke"

ISS_VC_LOG = '/v1/log/issueCredential'
ISS_VP_LOG = '/v1/log/issuePresentation'
VRF_VP_LOG = '/v1/log/verifyPresentation'
ISS_VC_LOG = "/v1/log/issueCredential"
ISS_VP_LOG = "/v1/log/issuePresentation"
VRF_VP_LOG = "/v1/log/verifyPresentation"
89 changes: 47 additions & 42 deletions myid/credential/credential_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
class CredentialInfo:
"""Represents a credential info"""

def __init__(self, type_: str,
issuer_did: str,
signature: str,
is_revoke: bool = False,
holder_did: str = None,
issue_date: int = None,
revoke_date: int = None,
expiry_date: int = None,
creation_block: int = None,
revocation_block: int = None):
def __init__(
self,
type_: str,
issuer_did: str,
signature: str,
is_revoke: bool = False,
holder_did: str = None,
issue_date: int = None,
revoke_date: int = None,
expiry_date: int = None,
creation_block: int = None,
revocation_block: int = None,
):
"""create credential info object
:param type_: a string CredentialInfo type
:param issuer_did: a string issuer DID
Expand All @@ -28,12 +31,12 @@ def __init__(self, type_: str,
"""
if type_ == PropertyName.CREDENTIAL_INFO_TYPE_REGIST:
if not issue_date:
raise ValueError('issue_date cannot be None.')
raise ValueError("issue_date cannot be None.")
if not expiry_date:
raise ValueError('expiry_date cannot be None.')
raise ValueError("expiry_date cannot be None.")

if type_ == PropertyName.CREDENTIAL_INFO_TYPE_REVOKE and not revoke_date:
raise ValueError('revoke_date cannot be None.')
raise ValueError("revoke_date cannot be None.")

self._type: str = type_
self._issuer_did: str = issuer_did
Expand Down Expand Up @@ -87,38 +90,40 @@ def expiry_date(self) -> int:
return self._expiry_date

@staticmethod
def from_json(data: dict) -> 'CredentialInfo':
parameters = {'type_': PropertyName.CREDENTIAL_INFO_TYPE_COMMON,
'issuer_did': data['issuerDid'],
'signature': data['sig']}

if data.get('holderDid'):
parameters['holder_did'] = data['holderDid']
if data.get('issueDate'):
parameters['issue_date'] = data['issueDate']
if data.get('isRevoke'):
parameters['is_revoke'] = data['isRevoke']
if data.get('revokeDate'):
parameters['revoke_date'] = data['revokeDate']
if data.get('expiryDate'):
parameters['expiry_date'] = data['expiryDate']
if data.get('created'):
parameters['creation_block'] = data['created']
if data.get('revoked'):
parameters['revocation_block'] = data['revoked']
def from_json(data: dict) -> "CredentialInfo":
parameters = {
"type_": PropertyName.CREDENTIAL_INFO_TYPE_COMMON,
"issuer_did": data["issuerDid"],
"signature": data["sig"],
}

if data.get("holderDid"):
parameters["holder_did"] = data["holderDid"]
if data.get("issueDate"):
parameters["issue_date"] = data["issueDate"]
if data.get("isRevoke"):
parameters["is_revoke"] = data["isRevoke"]
if data.get("revokeDate"):
parameters["revoke_date"] = data["revokeDate"]
if data.get("expiryDate"):
parameters["expiry_date"] = data["expiryDate"]
if data.get("created"):
parameters["creation_block"] = data["created"]
if data.get("revoked"):
parameters["revocation_block"] = data["revoked"]

return CredentialInfo(**parameters)

def to_json(self) -> dict:
return {
'type': self._type,
'issuerDid': self._issuer_did,
'holderDid': self._holder_did,
'sig': self._signature,
'isRevoke': self._is_revoke,
'issueDate': self._issue_date,
'revokeDate': self._revoke_date,
'expiryDate': self._expiry_date,
'created': self._creation_block,
'revoked': self._revocation_block
"type": self._type,
"issuerDid": self._issuer_did,
"holderDid": self._holder_did,
"sig": self._signature,
"isRevoke": self._is_revoke,
"issueDate": self._issue_date,
"revokeDate": self._revoke_date,
"expiryDate": self._expiry_date,
"created": self._creation_block,
"revoked": self._revocation_block,
}
5 changes: 3 additions & 2 deletions myid/credential/revoke_score_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def revoke_credential_info_param(did_key_holder: DidKeyHolder, revoke_credential
contents = {
PropertyName.CREDENTIAL_INFO_ISSUER_DID: revoke_credential_info.issuer_did,
PropertyName.CREDENTIAL_INFO_SIGNATURE: revoke_credential_info.signature,
PropertyName.CREDENTIAL_INFO_REVOKE_DATE: (revoke_credential_info.revoke_date
if revoke_credential_info.revoke_date else 0)
PropertyName.CREDENTIAL_INFO_REVOKE_DATE: (
revoke_credential_info.revoke_date if revoke_credential_info.revoke_date else 0
),
}
payload: Payload = Payload(contents=contents)

Expand Down
2 changes: 1 addition & 1 deletion myid/issuer_service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dataclasses
import json
import time
from typing import Optional, List
from typing import List, Optional

from didsdk.core.did_key_holder import DidKeyHolder
from didsdk.core.property_name import PropertyName as DIDPropertyName
Expand Down
36 changes: 19 additions & 17 deletions myid/score/credential_info_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,38 @@ def __init__(self, icon_service: IconService, network_id: int, score_address: st

def _build_transaction(self, from_address: str, method: str, params: dict) -> CallTransaction:
timestamp = int(time.time() * 1_000_000)
builder = CallTransactionBuilder(nid=self._network_id,
from_=from_address,
to=self._score_address,
step_limit=5_000_000,
timestamp=timestamp,
method=method,
params=params)
builder = CallTransactionBuilder(
nid=self._network_id,
from_=from_address,
to=self._score_address,
step_limit=5_000_000,
timestamp=timestamp,
method=method,
params=params,
)
return builder.build()

def _build_call(self, method: str, params: dict = None) -> Call:
builder = CallBuilder(to=self._score_address, method=method, params=params)
return builder.build()

def get(self, signature: str) -> str:
params = {'sig': signature}
call: Call = self._build_call(method='get', params=params)
params = {"sig": signature}
call: Call = self._build_call(method="get", params=params)
return self._icon_service.call(call)

def get_reject_history(self, vc_id: str):
params = {'vcId': vc_id}
call: Call = self._build_call(method='getRejectHistory', params=params)
params = {"vcId": vc_id}
call: Call = self._build_call(method="getRejectHistory", params=params)
return self._icon_service.call(call)

def get_under_taker_list(self):
call: Call = self._build_call(method='getUndertakerList')
call: Call = self._build_call(method="getUndertakerList")
return self._icon_service.call(call)

def is_valid(self, signature: str) -> str:
params = {'sig': signature}
call: Call = self._build_call(method='isValid', params=params)
params = {"sig": signature}
call: Call = self._build_call(method="isValid", params=params)
return self._icon_service.call(call)

def jwt_method(self, from_address: str, jwt: str, method: str) -> CallTransaction:
Expand All @@ -61,7 +63,7 @@ def jwt_method(self, from_address: str, jwt: str, method: str) -> CallTransactio
:param method: score method (add, revoke, revokeDid, revokeVCAndDid)
:return: Transaction object
"""
params = {'credentialJwt': jwt}
params = {"credentialJwt": jwt}
return self._build_transaction(from_address, method=method, params=params)

def jwt_list_method(self, from_address: str, jwt_list: str, method: str) -> CallTransaction:
Expand All @@ -72,7 +74,7 @@ def jwt_list_method(self, from_address: str, jwt_list: str, method: str) -> Call
:param method: score method (add, revoke, revokeDid, revokeVCAndDid)
:return: Transaction object
"""
params = {'credentialJwtList': jwt_list}
params = {"credentialJwtList": jwt_list}
return self._build_transaction(from_address, method=method, params=params)

def reject_history_jwt_method(self, from_address: str, jwt: str, method: str) -> CallTransaction:
Expand All @@ -83,5 +85,5 @@ def reject_history_jwt_method(self, from_address: str, jwt: str, method: str) ->
:param method: score method (add, revoke, revokeDid, revokeVCAndDid)
:return: Transaction object
"""
params = {'rejectJwt': jwt}
params = {"rejectJwt": jwt}
return self._build_transaction(from_address, method=method, params=params)
10 changes: 6 additions & 4 deletions myid/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ def get(url: str) -> ResultResponse:
try:
with requests.Session() as session:
response: requests.Response = session.get(url=url)
return ResultResponse(status=(response.status_code == requests.codes.ok),
result=response.json().get('result'))
return ResultResponse(
status=(response.status_code == requests.codes.ok), result=response.json().get("result")
)
except Exception as e:
return ResultResponse(status=False, result=str(e))

Expand All @@ -19,7 +20,8 @@ def post(url: str, json: dict):
try:
with requests.Session() as session:
response: requests.Response = session.post(url=url, json=json)
return ResultResponse(status=(response.status_code == requests.codes.ok),
result=response.json().get('result'))
return ResultResponse(
status=(response.status_code == requests.codes.ok), result=response.json().get("result")
)
except Exception as e:
return ResultResponse(status=False, result=str(e))
12 changes: 7 additions & 5 deletions myid/verifier_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _decrypt(self, protocol_message: ProtocolMessage):
kid: str = protocol_message.jwe_kid
ecdh_key: ECDHKey = self._ecdh_keys.get(kid)
if not ecdh_key:
raise JweException(f'Not exist ECDHKey kid({kid})')
raise JweException(f"Not exist ECDHKey kid({kid})")

protocol_message.decrypt_jwe(ecdh_key)

Expand All @@ -51,7 +51,7 @@ def _verified_credential_result(self, credential: Credential, holder_did: str) -
return ServiceResult.from_result(result_response)

@staticmethod
def create(url: str) -> 'VerifierService':
def create(url: str) -> "VerifierService":
"""Create a `VerifierService` instance that can use methods for Verifier.
:param url: A Verifier WAS endpoint
Expand All @@ -63,12 +63,14 @@ def decrypt_presentation(self, jwe_token: str) -> Presentation:
protocol_message: ProtocolMessage = ProtocolMessage.from_(
type_=ProtocolType.RESPONSE_PROTECTED_PRESENTATION.value,
message=JWE().deserialize(jwe_token),
is_protected=True)
is_protected=True,
)
self._decrypt(protocol_message)

return protocol_message.presentation

def sign_encrypt_request_presentation(self, protocol_message: ProtocolMessage,
verifier_key_holder: DidKeyHolder) -> ServiceResult:
def sign_encrypt_request_presentation(
self, protocol_message: ProtocolMessage, verifier_key_holder: DidKeyHolder
) -> ServiceResult:
result: SignResult = protocol_message.sign_encrypt(verifier_key_holder)
return ServiceResult.from_signed_object(result)
Loading

0 comments on commit 7e9a37c

Please sign in to comment.