Skip to content

Commit

Permalink
Merge pull request #84 from xeroc/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
xeroc authored Mar 8, 2019
2 parents e0dc590 + d984255 commit ba2e6b8
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 101 deletions.
11 changes: 11 additions & 0 deletions .pyup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# autogenerated pyup.io config file
# see https://pyup.io/docs/configuration/ for all available options

update: all

# update schedule
# default: empty
# allowed: "every day", "every week", ..
schedule: "every week"

pin: False
27 changes: 14 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
dist: trusty
language: python
sudo: false
python:
- 3.5
python: 3.5
env:
global:
- CC_TEST_REPORTER_ID=cd0802782ea41e43bb232d303415f475ee6f5087c0d3e4252e3ac4b56509d13d
matrix:
include:
- env: TOXENV=py35
python: 3.5
- env: TOXENV=py36
python: 3.6
#- env: TOXENV=py37
# python: 3.7
# - env: TOXENV=py37
# python: 3.7
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
install:
- pip install tox-travis codecov
- pip install tox-travis codecov coveralls
script:
- tox
- sed -i 's/filename="/filename=".\//g' coverage.xml
- ( which sonar-scanner && sonar-scanner || true )
after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT --prefix $(readlink -f .)
after_success:
- codecov

addons:
sonarcloud:
organization: graphene
token:
secure: "KcIUKNAnkaA50M52pfiUhJYT3F4VtXQSlmdedcUO0xVxig6Z5watdDEKSbqmD7jDCX+aZizCx2gPHrm+hPdXPKz4B9/U4MtxOyn35bJ7i58mWRvKicBf8PaPmQSYTWW8iJIuJ1GNv9Ymxq45IbkgjL/A7XQEGXiKmpbgLKe0ADMohG63UufarltGuQr0fXKAXaVCb9mJNBICXHLSY2VeNYqyLtS/gEbOoVpTh7yKgrUT7u3j3Yn+oC+1+1KzRNzZ9/iY5AqWSkpUV20Rt41njBCEulNR2t8b0Ykd127pOy9qxddqoBbJ0Dav5a+gXRwNt4h8t0iioHFnBaE4Nhtdvps0pFHHzON8UDEiAtcTTtttrayqNZZ/g3TRrZsujavE9PxINXEClc0AaX4bJOEhmimcnvzQfaSj5xuGvT7Ci2sA/UXw9dSGthJIpqeMdmGKrc/0CrP29Azoa6D9G+q4ZE6pEF1jmkaaER8AA+EqRZTQBuqlSeDyTH+ro1SMDqvV7X5rTro4eMpCTSCvVsr3/02XNyPQ0FplQ7QafZi2kMjP8h7y45EdQKr8Rq6INk08J2ae6UwcS8yH7EQw3WhHx3sSuuZZSFJ5uiTb5+a10MFqw8ng/seXW9HglcR/rskml3kZToECEk4EWfbLmMCFDWJlYv8LIbUQwOIsxgHX3tw="
- coveralls
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
![](https://img.shields.io/github/downloads/xeroc/python-graphenelib/total.svg?style=for-the-badge)
![](https://img.shields.io/pypi/pyversions/graphenelib.svg?style=for-the-badge)
![](https://img.shields.io/pypi/l/graphenelib.svg?style=for-the-badge)
![](https://cla-assistant.io/readme/badge/xeroc/python-graphenelib)

**Stable**
### Current build status

[![Travis master](https://travis-ci.org/xeroc/python-graphenelib.png?branch=master)](https://travis-ci.org/xeroc/python-graphenelib)
[![docs master](https://readthedocs.org/projects/python-graphenelib/badge/?version=latest)](http://python-graphenelib.readthedocs.io/en/latest/)
[![codecov](https://codecov.io/gh/xeroc/python-graphenelib/branch/master/graph/badge.svg)](https://codecov.io/gh/xeroc/python-graphenelib)


**Develop**

[![Travis develop](https://travis-ci.org/xeroc/python-graphenelib.png?branch=develop)](https://travis-ci.org/xeroc/python-graphenelib)
[![docs develop](https://readthedocs.org/projects/python-graphenelib/badge/?version=develop)](http://python-graphenelib.readthedocs.io/en/develop/)
[![codecov develop](https://codecov.io/gh/xeroc/python-graphenelib/branch/develop/graph/badge.svg)](https://codecov.io/gh/xeroc/python-graphenelib)
[![Maintainability](https://api.codeclimate.com/v1/badges/8dd7a9b3f06a1ef9188a/maintainability)](https://codeclimate.com/github/xeroc/python-graphenelib/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/8dd7a9b3f06a1ef9188a/test_coverage)](https://codeclimate.com/github/xeroc/python-graphenelib/test_coverage)
![](https://pyup.io/repos/github/xeroc/python-graphenelib/shield.svg)
![](https://cla-assistant.io/readme/badge/xeroc/python-graphenelib)

---
## Documentation
Expand Down
30 changes: 30 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "{branch}.{build}"

environment:
matrix:
- TOXENV: py35
PYTHON: "C:\\Python35-x64"
PYTHON_VERSION: "3.5.x"
PYTHON_ARCH: "64"

- TOXENV: py36
PYTHON: "C:\\Python36-x64"
PYTHON_VERSION: "3.6.x"
PYTHON_ARCH: "64"

- TOXENV: py37
PYTHON: "C:\\Python37-x64"
PYTHON_VERSION: "3.7.x"
PYTHON_ARCH: "64"

install:
- pip install tox

build: off

test_script: tox

notifications:
- provider: Email
on_build_success: false
on_build_status_changed: false
4 changes: 2 additions & 2 deletions graphenebase/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ def __init__(self, a):
super().__init__(a)


class Sha1(Bytes):
class Sha1(Hash):
def __init__(self, a):
assert len(a) == 40, "Require 40 char long hex"
super().__init__(a)


class Sha256(Bytes):
class Sha256(Hash):
def __init__(self, a):
assert len(a) == 64, "Require 64 char long hex"
super().__init__(a)
Expand Down
42 changes: 25 additions & 17 deletions graphenestorage/masterpassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import hashlib
import logging
import warnings

from binascii import hexlify

Expand Down Expand Up @@ -87,32 +88,32 @@ def unlock(self, password):
"""
self.password = password
if self.config_key in self.config and self.config[self.config_key]:
self.decryptEncryptedMaster()
self._decrypt_masterpassword()
else:
self.newMaster(password)
self.saveEncrytpedMaster()
self._new_masterpassword(password)
self._save_encrypted_masterpassword()

def decryptEncryptedMaster(self):
def _decrypt_masterpassword(self):
""" Decrypt the encrypted masterkey
"""
aes = AESCipher(self.password)
checksum, encrypted_master = self.config[self.config_key].split("$")
try:
decrypted_master = aes.decrypt(encrypted_master)
except Exception:
self.raiseWrongMasterPasswordException()
if checksum != self.deriveChecksum(decrypted_master):
self.raiseWrongMasterPasswordException()
self._raise_wrongmasterpassexception()
if checksum != self._derive_checksum(decrypted_master):
self._raise_wrongmasterpassexception()
self.decrypted_master = decrypted_master

def raiseWrongMasterPasswordException(self):
def _raise_wrongmasterpassexception(self):
self.password = None
raise WrongMasterPasswordException

def saveEncrytpedMaster(self):
self.config[self.config_key] = self.getEncryptedMaster()
def _save_encrypted_masterpassword(self):
self.config[self.config_key] = self._get_encrypted_masterpassword()

def newMaster(self, password):
def _new_masterpassword(self, password):
""" Generate a new random masterkey, encrypt it with the password and
store it in the store.
Expand All @@ -126,18 +127,18 @@ def newMaster(self, password):

# Encrypt and save master
self.password = password
self.saveEncrytpedMaster()
self._save_encrypted_masterpassword()
return self.masterkey

def deriveChecksum(self, s):
def _derive_checksum(self, s):
""" Derive the checksum
:param str s: Random string for which to derive the checksum
"""
checksum = hashlib.sha256(bytes(s, "ascii")).hexdigest()
return checksum[:4]

def getEncryptedMaster(self):
def _get_encrypted_masterpassword(self):
""" Obtain the encrypted masterkey
.. note:: The encrypted masterkey is checksummed, so that we can
Expand All @@ -148,16 +149,16 @@ def getEncryptedMaster(self):
raise WalletLocked
aes = AESCipher(self.password)
return "{}${}".format(
self.deriveChecksum(self.masterkey), aes.encrypt(self.masterkey)
self._derive_checksum(self.masterkey), aes.encrypt(self.masterkey)
)

def changePassword(self, newpassword):
def change_password(self, newpassword):
""" Change the password that allows to decrypt the master key
"""
if not self.unlocked():
raise WalletLocked
self.password = newpassword
self.saveEncrytpedMaster()
self._save_encrypted_masterpassword()

def decrypt(self, wif):
""" Decrypt the content according to BIP38
Expand All @@ -176,3 +177,10 @@ def encrypt(self, wif):
if not self.unlocked():
raise WalletLocked
return format(bip38.encrypt(str(wif), self.masterkey), "encwif")

def changePassword(self, newpassword):
warnings.warn(
"changePassword will be replaced by change_password in the future",
PendingDeprecationWarning,
)
return self.change_password(newpassword)
22 changes: 11 additions & 11 deletions graphenestorage/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, *args, **kwargs):
else:
self.storageDatabase = "{}.sqlite".format(appname)

self.sqlDataBaseFile = os.path.join(data_dir, self.storageDatabase)
self.sqlite_file = os.path.join(data_dir, self.storageDatabase)

""" Ensure that the directory in which the data is stored
exists
Expand Down Expand Up @@ -97,7 +97,7 @@ def _haveKey(self, key):
),
(key,),
)
connection = sqlite3.connect(self.sqlDataBaseFile)
connection = sqlite3.connect(self.sqlite_file)
cursor = connection.cursor()
cursor.execute(*query)
return True if cursor.fetchone() else False
Expand All @@ -122,7 +122,7 @@ def __setitem__(self, key, value):
),
(key, value),
)
connection = sqlite3.connect(self.sqlDataBaseFile)
connection = sqlite3.connect(self.sqlite_file)
cursor = connection.cursor()
cursor.execute(*query)
connection.commit()
Expand All @@ -138,7 +138,7 @@ def __getitem__(self, key):
),
(key,),
)
connection = sqlite3.connect(self.sqlDataBaseFile)
connection = sqlite3.connect(self.sqlite_file)
cursor = connection.cursor()
cursor.execute(*query)
result = cursor.fetchone()
Expand All @@ -157,7 +157,7 @@ def __iter__(self):

def keys(self):
query = "SELECT {} from {}".format(self.__key__, self.__tablename__)
connection = sqlite3.connect(self.sqlDataBaseFile)
connection = sqlite3.connect(self.sqlite_file)
cursor = connection.cursor()
cursor.execute(query)
return [x[0] for x in cursor.fetchall()]
Expand All @@ -166,7 +166,7 @@ def __len__(self):
""" return lenght of store
"""
query = "SELECT id from {}".format(self.__tablename__)
connection = sqlite3.connect(self.sqlDataBaseFile)
connection = sqlite3.connect(self.sqlite_file)
cursor = connection.cursor()
cursor.execute(query)
return len(cursor.fetchall())
Expand All @@ -189,7 +189,7 @@ def items(self):
query = "SELECT {}, {} from {}".format(
self.__key__, self.__value__, self.__tablename__
)
connection = sqlite3.connect(self.sqlDataBaseFile)
connection = sqlite3.connect(self.sqlite_file)
cursor = connection.cursor()
cursor.execute(query)
r = []
Expand Down Expand Up @@ -218,7 +218,7 @@ def delete(self, key):
"DELETE FROM {} WHERE {}=?".format(self.__tablename__, self.__key__),
(key,),
)
connection = sqlite3.connect(self.sqlDataBaseFile)
connection = sqlite3.connect(self.sqlite_file)
cursor = connection.cursor()
cursor.execute(*query)
connection.commit()
Expand All @@ -227,7 +227,7 @@ def wipe(self):
""" Wipe the store
"""
query = "DELETE FROM {}".format(self.__tablename__)
connection = sqlite3.connect(self.sqlDataBaseFile)
connection = sqlite3.connect(self.sqlite_file)
cursor = connection.cursor()
cursor.execute(query)
connection.commit()
Expand All @@ -239,7 +239,7 @@ def exists(self):
"SELECT name FROM sqlite_master " + "WHERE type='table' AND name=?",
(self.__tablename__,),
)
connection = sqlite3.connect(self.sqlDataBaseFile)
connection = sqlite3.connect(self.sqlite_file)
cursor = connection.cursor()
cursor.execute(*query)
return True if cursor.fetchone() else False
Expand All @@ -255,7 +255,7 @@ def create(self): # pragma: no cover
{} STRING(256)
)"""
).format(self.__tablename__, self.__key__, self.__value__)
connection = sqlite3.connect(self.sqlDataBaseFile)
connection = sqlite3.connect(self.sqlite_file)
cursor = connection.cursor()
cursor.execute(query)
connection.commit()
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ secp256k1==0.13.2
pytest==4.3.0
coverage==4.5.2
mock==2.0.0
nose

# Code style

Expand Down
11 changes: 9 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ omit=
[coverage:report]
ignore_errors=True
show_missing=True

include=graphene*
omit =
# This file is proven and won't be touch
Expand All @@ -31,7 +30,7 @@ exclude_lines =
except ImportError:
if 0:
if __name__ == .__main__.:
if sys.version > '3':
if sys.version > '3':
SECP256K1_MODULE

[flake8]
Expand All @@ -55,3 +54,11 @@ multi_line_output = 3
line_length = 88
known_third_party =
include_trailing_comma = true

[nosetests]
verbosity=3
nocapture=1
nologcapture=1
cover-xml=1
with-coverage=1
with-xunit=1
Loading

0 comments on commit ba2e6b8

Please sign in to comment.