Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Lint

on:
push:
branches:
- "master"
- "develop"
Comment thread
alexbarnsley marked this conversation as resolved.
Resolved
- "feat/mainsail"
pull_request:
types: [ready_for_review, synchronize, opened]

jobs:
flake8:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v7
with:
submodules: true
ref: ${{ github.head_ref }}

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.13"

- name: install dependencies
run: |
python3 -m venv venv
. venv/bin/activate
pip install .[test]

- name: run flake8
run: |
. venv/bin/activate
make lint
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
3. Run the tests to confirm they all pass on your system. If they don’t, you’ll need to investigate why they fail. If you’re unable to diagnose this yourself raise it as a bug report.
4. Make your change.
5. Write tests that demonstrate your bug or feature.
6. Run the entire test suite again, confirming that all tests pass including the ones you just added.
6. Run the entire test suite again, confirming that all tests pass including the ones you just added, and run `make lint` to check for lint errors.
7. Send a GitHub Pull Request. GitHub Pull Requests are the expected method of code collaboration on this project.

If you have any questions, requests or ideas open an issue or ask us in #developers channel on the [ArkEcosystem Discord](https://discord.ark.io/).
Expand Down
1 change: 0 additions & 1 deletion crypto/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion crypto/configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

2 changes: 2 additions & 0 deletions crypto/configuration/network.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from crypto.networks.abstract_network import AbstractNetwork
from crypto.networks.testnet import Testnet


class Network:
_network: AbstractNetwork

Expand All @@ -23,4 +24,5 @@ def get_network(cls) -> AbstractNetwork:
"""
return cls._network


Network.set_network(Testnet())
1 change: 0 additions & 1 deletion crypto/enums/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 1 addition & 0 deletions crypto/enums/abi_function.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum


class AbiFunction(Enum):
VOTE = 'vote'
UNVOTE = 'unvote'
Expand Down
1 change: 1 addition & 0 deletions crypto/enums/contract_abi_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum


class ContractAbiType(Enum):
CUSTOM = 'custom'
CONSENSUS = 'consensus'
Expand Down
1 change: 1 addition & 0 deletions crypto/enums/contract_addresses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum


class ContractAddresses(Enum):
CONSENSUS = '0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1'
MULTIPAYMENT = '0x00EFd0D4639191C49908A7BddbB9A11A994A8527'
Expand Down
1 change: 0 additions & 1 deletion crypto/identity/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

10 changes: 6 additions & 4 deletions crypto/identity/address.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import hashlib
from binascii import unhexlify
import re

from crypto.identity.private_key import PrivateKey
from binascii import unhexlify

from Cryptodome.Hash import keccak

from coincurve import PublicKey

from crypto.identity.private_key import PrivateKey


class Address:
@classmethod
def from_public_key(cls, public_key: str) -> str:
Expand Down Expand Up @@ -82,7 +84,7 @@ def get_checksum_address(cls, address: str) -> str:
if (hashed[i >> 1] & 0x0F) >= 8:
chars[i + 1] = chars[i + 1].upper()

return "0x" + ''.join(chars)
return '0x' + ''.join(chars)

@classmethod
def validate(cls, address: str) -> bool:
Expand Down
3 changes: 2 additions & 1 deletion crypto/identity/bls_private_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

sys.path.append(os.path.join(dirname(dirname(__file__)), 'thirdparty/bls-signatures/python-impl'))

from schemes import BasicSchemeMPL
from schemes import BasicSchemeMPL # noqa: E402, I100, I201


class BLSPrivateKey(object):
def __init__(self, private_key: bytes):
Expand Down
7 changes: 4 additions & 3 deletions crypto/identity/bls_public_key.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import sys
import os
import sys
from os.path import dirname

from crypto.identity.bls_private_key import BLSPrivateKey

sys.path.append(os.path.join(dirname(dirname(__file__)), 'thirdparty/bls-signatures/python-impl'))

from schemes import PrivateKey
from schemes import PrivateKey # noqa: E402, I100, I201

from crypto.identity.bls_private_key import BLSPrivateKey

class BLSPublicKey:
def __init__(self, public_key: bytes):
Expand Down
4 changes: 2 additions & 2 deletions crypto/identity/legacy_address.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import hashlib

from base58 import b58decode_check, b58encode_check

from Cryptodome.Hash import RIPEMD160

from base58 import b58decode_check, b58encode_check

from crypto.identity.private_key import PrivateKey


Expand Down
8 changes: 6 additions & 2 deletions crypto/identity/private_key.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from binascii import hexlify
from hashlib import sha256
from coincurve import PrivateKey as PvtKey

from Cryptodome.Hash import keccak

from base58 import b58decode

from coincurve import PrivateKey as PvtKey

from crypto.configuration.network import Network


class PrivateKey(object):
def __init__(self, private_key: str):
self.private_key = PvtKey.from_hex(private_key)
Expand Down Expand Up @@ -92,7 +96,7 @@ def from_wif(cls, wif: str):

version = wif[0:2]
if version != Network.get_network().wif():
raise ValueError(f"Invalid network version: {version}")
raise ValueError(f'Invalid network version: {version}')

private_key = wif[2:66]

Expand Down
16 changes: 8 additions & 8 deletions crypto/identity/proof_of_possession.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import sys
import os
import sys
from os.path import dirname

sys.path.append(os.path.join(dirname(dirname(__file__)), 'thirdparty/bls-signatures/python-impl'))

from schemes import PrivateKey as BLSSchemePrivateKey, core_sign_mpl

from crypto.configuration.network import Network
from crypto.exceptions import InvalidProofOfPossessionException
from crypto.identity.address import Address
from crypto.identity.bls_private_key import BLSPrivateKey

sys.path.append(os.path.join(dirname(dirname(__file__)), 'thirdparty/bls-signatures/python-impl'))

from schemes import PrivateKey as BLSSchemePrivateKey, core_sign_mpl # noqa: E402, I100, I201

POP_DST = b'MAINSAIL_BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_'


Expand Down Expand Up @@ -69,10 +69,10 @@ def build_proof_of_possession(cls, private_key_bytes: bytes, registrant_address:

cls.validate_registrant_address(registrant_address)

sk = BLSSchemePrivateKey.from_bytes(private_key_bytes)
pk = bytes(sk.get_g1())
sk = BLSSchemePrivateKey.from_bytes(private_key_bytes)
pk = bytes(sk.get_g1())
message = cls.build_message(Network.get_network().chain_id(), registrant_address, pk)
pop = bytes(core_sign_mpl(sk, message, POP_DST))
pop = bytes(core_sign_mpl(sk, message, POP_DST))

return {'pk': pk.hex(), 'pop': pop.hex()}

Expand Down
1 change: 1 addition & 0 deletions crypto/identity/public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from crypto.identity.private_key import PrivateKey


class PublicKey(object):
public_key: str

Expand Down
1 change: 1 addition & 0 deletions crypto/identity/wif.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from crypto.configuration.network import Network


class WIF:
@staticmethod
def from_passphrase(passphrase: str, network_wif: Optional[str] = None):
Expand Down
1 change: 0 additions & 1 deletion crypto/networks/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 1 addition & 0 deletions crypto/networks/abstract_network.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import ABC, abstractmethod


class AbstractNetwork(ABC):
@abstractmethod
def chain_id(self) -> int:
Expand Down
1 change: 1 addition & 0 deletions crypto/networks/mainnet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from crypto.networks.abstract_network import AbstractNetwork


class Mainnet(AbstractNetwork):
def chain_id(self):
return 11811
Expand Down
1 change: 1 addition & 0 deletions crypto/networks/testnet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from crypto.networks.abstract_network import AbstractNetwork


class Testnet(AbstractNetwork):
def chain_id(self):
return 11812
Expand Down
1 change: 0 additions & 1 deletion crypto/transactions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion crypto/transactions/builder/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def to_json(self):
return self.transaction.to_json()

def get_transaction_instance(self, data: dict) -> AbstractTransaction:
raise NotImplementedError("Subclasses must implement get_transaction_instance()")
raise NotImplementedError('Subclasses must implement get_transaction_instance()')
1 change: 1 addition & 0 deletions crypto/transactions/builder/evm_call_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from crypto.transactions.types.evm_call import EvmCall
from crypto.utils.transaction_utils import TransactionUtils


class EvmCallBuilder(AbstractTransactionBuilder):
def payload(self, payload: str):
payload = TransactionUtils.parse_hex_from_str(payload) # Remove '0x' prefix if present
Expand Down
1 change: 1 addition & 0 deletions crypto/transactions/builder/multipayment_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from crypto.transactions.builder.abstract_transaction_builder import AbstractTransactionBuilder
from crypto.transactions.types.multipayment import Multipayment


class MultipaymentBuilder(AbstractTransactionBuilder):
def __init__(self, data: dict):
super().__init__(data)
Expand Down
1 change: 1 addition & 0 deletions crypto/transactions/builder/unvote_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from crypto.transactions.builder.abstract_transaction_builder import AbstractTransactionBuilder
from crypto.transactions.types.unvote import Unvote


class UnvoteBuilder(AbstractTransactionBuilder):
def __init__(self, data: dict):
super().__init__(data)
Expand Down
11 changes: 9 additions & 2 deletions crypto/transactions/builder/username_registration_builder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import re

from crypto.enums.contract_addresses import ContractAddresses
from crypto.exceptions import InvalidUsernameException
from crypto.transactions.builder.abstract_transaction_builder import AbstractTransactionBuilder
from crypto.transactions.types.username_registration import UsernameRegistration


class UsernameRegistrationBuilder(AbstractTransactionBuilder):
def __init__(self, data: dict):
super().__init__(data)
Expand All @@ -24,10 +26,15 @@ def get_transaction_instance(self, data: dict):
@staticmethod
def is_valid_username(username: str) -> bool:
if len(username) < 1 or len(username) > 20:
raise InvalidUsernameException(f'Username must be between 1 and 20 characters long. Got {len(username)} characters.')
raise InvalidUsernameException(
'Username must be between 1 and 20 characters long. '
f'Got {len(username)} characters.'
)

if re.search(r'[^a-z0-9_]', username):
raise InvalidUsernameException('Username can only contain lowercase letters, numbers and underscores.')
raise InvalidUsernameException(
'Username can only contain lowercase letters, numbers and underscores.'
)

if re.search(r'^_|_$', username):
raise InvalidUsernameException('Username cannot start or end with an underscore.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from crypto.transactions.builder.abstract_transaction_builder import AbstractTransactionBuilder
from crypto.transactions.types.username_resignation import UsernameResignation


class UsernameResignationBuilder(AbstractTransactionBuilder):
def __init__(self, data: dict):
super().__init__(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, data: dict):
def validator_proof(self, passphrase: str, registrant_address: str):
bls = ProofOfPossession.from_passphrase(passphrase, registrant_address)
self.transaction.data['validatorPublicKey'] = '0x' + bls['pk']
self.transaction.data['validatorProof'] = '0x' + bls['pop']
self.transaction.data['validatorProof'] = '0x' + bls['pop']
self.transaction.refresh_payload_data()
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from crypto.transactions.builder.abstract_transaction_builder import AbstractTransactionBuilder
from crypto.transactions.types.validator_resignation import ValidatorResignation


class ValidatorResignationBuilder(AbstractTransactionBuilder):
def __init__(self, data: dict):
super().__init__(data)
Expand Down
2 changes: 1 addition & 1 deletion crypto/transactions/builder/validator_update_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, data: dict):
def validator_proof(self, passphrase: str, registrant_address: str):
bls = ProofOfPossession.from_passphrase(passphrase, registrant_address)
self.transaction.data['validatorPublicKey'] = '0x' + bls['pk']
self.transaction.data['validatorProof'] = '0x' + bls['pop']
self.transaction.data['validatorProof'] = '0x' + bls['pop']
self.transaction.refresh_payload_data()
return self

Expand Down
1 change: 1 addition & 0 deletions crypto/transactions/builder/vote_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from crypto.transactions.builder.abstract_transaction_builder import AbstractTransactionBuilder
from crypto.transactions.types.vote import Vote


class VoteBuilder(AbstractTransactionBuilder):
def __init__(self, data: dict):
super().__init__(data)
Expand Down
Loading