Skip to content

Commit

Permalink
fix xbr mnemonic helper (#1437)
Browse files Browse the repository at this point in the history
* fix xbr mnemonic helper

* more unit test coverage

* update changelog; bump version

* update and adjust docker files to upstream changes
  • Loading branch information
oberstet committed Dec 14, 2020
1 parent e1cc990 commit cd3c4d8
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 54 deletions.
2 changes: 1 addition & 1 deletion autobahn/_version.py
Expand Up @@ -24,4 +24,4 @@
#
###############################################################################

__version__ = '20.12.1'
__version__ = '20.12.2'
10 changes: 5 additions & 5 deletions autobahn/xbr/_mnemonic.py
Expand Up @@ -63,9 +63,9 @@ def derive_public_key(private_key):
Logic adapted from https://github.com/satoshilabs/slips/blob/master/slip-0010/testvectors.py. """

Q = int.from_bytes(private_key, byteorder='big') * BIP32_CURVE.generator
xstr = Q.x().to_bytes(32, byteorder='big')
xstr = int(Q.x()).to_bytes(32, byteorder='big')
parity = Q.y() & 1
return (2 + parity).to_bytes(1, byteorder='big') + xstr
return int(2 + parity).to_bytes(1, byteorder='big') + xstr


def derive_bip32childkey(parent_key, parent_chain_code, i):
Expand All @@ -87,7 +87,7 @@ def derive_bip32childkey(parent_key, parent_chain_code, i):
b = int.from_bytes(parent_key, byteorder='big')
key = (a + b) % BIP32_CURVE.order
if a < BIP32_CURVE.order and key != 0:
key = key.to_bytes(32, byteorder='big')
key = int(key).to_bytes(32, byteorder='big')
break
d = b'\x01' + h[32:] + struct.pack('>L', i)

Expand All @@ -103,7 +103,7 @@ def fingerprint(public_key):
def b58xprv(parent_fingerprint, private_key, chain, depth, childnr):
""" Private key b58 serialization format. """

raw = (b'\x04\x88\xad\xe4' + bytes(chr(depth), 'utf-8') + parent_fingerprint + childnr.to_bytes(
raw = (b'\x04\x88\xad\xe4' + bytes(chr(depth), 'utf-8') + parent_fingerprint + int(childnr).to_bytes(
4, byteorder='big') + chain + b'\x00' + private_key)

return b58encode_check(raw)
Expand All @@ -112,7 +112,7 @@ def b58xprv(parent_fingerprint, private_key, chain, depth, childnr):
def b58xpub(parent_fingerprint, public_key, chain, depth, childnr):
""" Public key b58 serialization format. """

raw = (b'\x04\x88\xb2\x1e' + bytes(chr(depth), 'utf-8') + parent_fingerprint + childnr.to_bytes(
raw = (b'\x04\x88\xb2\x1e' + bytes(chr(depth), 'utf-8') + parent_fingerprint + int(childnr).to_bytes(
4, byteorder='big') + chain + public_key)

return b58encode_check(raw)
Expand Down
9 changes: 7 additions & 2 deletions autobahn/xbr/test/test_mnemonic.py
Expand Up @@ -32,6 +32,7 @@
from autobahn.xbr import generate_seedphrase, check_seedphrase, account_from_seedphrase

_SEEDPHRASE = "myth like bonus scare over problem client lizard pioneer submit female collect"
_INVALID_SEEDPHRASE = "9 nn \0 kk$"

_EXPECTED = [
('0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1', '0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d'),
Expand All @@ -58,15 +59,19 @@

class TestEthereumMnemonic(unittest.TestCase):

def test_check_seedphrase(self):
def test_check_valid_seedphrase(self):
self.assertTrue(check_seedphrase(_SEEDPHRASE))

def test_check_invalid_seedphrase(self):
self.assertFalse(check_seedphrase(_INVALID_SEEDPHRASE))

def test_generate_seedphrase(self):
for strength in [128, 160, 192, 224, 256]:
seedphrase = generate_seedphrase(strength)

self.assertEqual(type(seedphrase), str)
self.assertTrue(type(word) == bool for word in seedphrase.split())
for word in seedphrase.split():
self.assertTrue(type(word) == str)
self.assertTrue(check_seedphrase(seedphrase))

def test_derive_wallet(self):
Expand Down
2 changes: 1 addition & 1 deletion docker/aarch64/Dockerfile.cpy3
@@ -1,4 +1,4 @@
FROM arm64v8/python:3.7-slim-stretch
FROM arm64v8/python:3.9-slim

COPY .qemu/qemu-aarch64-static /usr/bin/qemu-aarch64-static

Expand Down
2 changes: 1 addition & 1 deletion docker/aarch64/Dockerfile.pypy3
@@ -1,4 +1,4 @@
FROM arm64v8/pypy:3.6-slim-stretch
FROM arm64v8/pypy:3.7-slim

COPY .qemu/qemu-aarch64-static /usr/bin/qemu-aarch64-static

Expand Down
2 changes: 1 addition & 1 deletion docker/armhf/Dockerfile.cpy3
@@ -1,4 +1,4 @@
FROM arm32v7/python:3.7-slim-stretch
FROM arm32v7/python:3.9-slim

COPY .qemu/qemu-arm-static /usr/bin/qemu-arm-static

Expand Down
4 changes: 3 additions & 1 deletion docker/armhf/Dockerfile.pypy3
@@ -1,4 +1,6 @@
FROM arm32v7/pypy:3.6-slim-stretch
FROM arm32v7/pypy:3.6-slim
# FROM arm32v7/pypy:3.7-7.3.3-slim
# arm32v7/pypy:3.7-slim

COPY .qemu/qemu-arm-static /usr/bin/qemu-arm-static

Expand Down
2 changes: 1 addition & 1 deletion docker/x86_64/Dockerfile.cpy3
@@ -1,4 +1,4 @@
FROM amd64/python:3.7-slim-stretch
FROM amd64/python:3.9-slim

MAINTAINER The Crossbar.io Project <support@crossbario.com>

Expand Down
2 changes: 1 addition & 1 deletion docker/x86_64/Dockerfile.cpy3-alpine
@@ -1,4 +1,4 @@
FROM python:3.7-alpine
FROM python:3.9-alpine

MAINTAINER The Crossbar.io Project <support@crossbario.com>

Expand Down
2 changes: 1 addition & 1 deletion docker/x86_64/Dockerfile.cpy3-minimal-aio
@@ -1,4 +1,4 @@
FROM python:3.7-alpine
FROM python:3.9-alpine

MAINTAINER The Crossbar.io Project <support@crossbario.com>

Expand Down
2 changes: 1 addition & 1 deletion docker/x86_64/Dockerfile.cpy3-minimal-tx
@@ -1,4 +1,4 @@
FROM python:3.7-alpine
FROM python:3.9-alpine

MAINTAINER The Crossbar.io Project <support@crossbario.com>

Expand Down
3 changes: 2 additions & 1 deletion docker/x86_64/Dockerfile.pypy3
@@ -1,4 +1,5 @@
FROM amd64/pypy:3.6-slim-stretch
FROM amd64/pypy:3.7-7.3.3-slim-buster
# FROM amd64/pypy:3.6-slim-stretch

MAINTAINER The Crossbar.io Project <support@crossbario.com>

Expand Down
74 changes: 37 additions & 37 deletions docker/x86_64/Makefile
Expand Up @@ -17,51 +17,51 @@ build:
-t crossbario/autobahn-python:pypy3-${AUTOBAHN_PYTHON_VERSION} \
-f Dockerfile.pypy3 .

time docker build \
--build-arg BUILD_DATE=${BUILD_DATE} \
--build-arg AUTOBAHN_PYTHON_VCS_REF=${AUTOBAHN_PYTHON_VCS_REF} \
--build-arg AUTOBAHN_PYTHON_VERSION=${AUTOBAHN_PYTHON_VERSION} \
-t crossbario/autobahn-python:latest \
-t crossbario/autobahn-python:cpy3-alpine \
-t crossbario/autobahn-python:cpy3-alpine-${AUTOBAHN_PYTHON_VERSION} \
-f Dockerfile.cpy3-alpine .

time docker build \
--build-arg BUILD_DATE=${BUILD_DATE} \
--build-arg AUTOBAHN_PYTHON_VCS_REF=${AUTOBAHN_PYTHON_VCS_REF} \
--build-arg AUTOBAHN_PYTHON_VERSION=${AUTOBAHN_PYTHON_VERSION} \
-t crossbario/autobahn-python:cpy3-minimal-aio \
-t crossbario/autobahn-python:cpy3-minimal-aio-${AUTOBAHN_PYTHON_VERSION} \
-f Dockerfile.cpy3-minimal-aio .

time docker build \
--build-arg BUILD_DATE=${BUILD_DATE} \
--build-arg AUTOBAHN_PYTHON_VCS_REF=${AUTOBAHN_PYTHON_VCS_REF} \
--build-arg AUTOBAHN_PYTHON_VERSION=${AUTOBAHN_PYTHON_VERSION} \
-t crossbario/autobahn-python:cpy3-minimal-tx \
-t crossbario/autobahn-python:cpy3-minimal-tx-${AUTOBAHN_PYTHON_VERSION} \
-f Dockerfile.cpy3-minimal-tx .
# time docker build \
# --build-arg BUILD_DATE=${BUILD_DATE} \
# --build-arg AUTOBAHN_PYTHON_VCS_REF=${AUTOBAHN_PYTHON_VCS_REF} \
# --build-arg AUTOBAHN_PYTHON_VERSION=${AUTOBAHN_PYTHON_VERSION} \
# -t crossbario/autobahn-python:latest \
# -t crossbario/autobahn-python:cpy3-alpine \
# -t crossbario/autobahn-python:cpy3-alpine-${AUTOBAHN_PYTHON_VERSION} \
# -f Dockerfile.cpy3-alpine .

# time docker build \
# --build-arg BUILD_DATE=${BUILD_DATE} \
# --build-arg AUTOBAHN_PYTHON_VCS_REF=${AUTOBAHN_PYTHON_VCS_REF} \
# --build-arg AUTOBAHN_PYTHON_VERSION=${AUTOBAHN_PYTHON_VERSION} \
# -t crossbario/autobahn-python:cpy3-minimal-aio \
# -t crossbario/autobahn-python:cpy3-minimal-aio-${AUTOBAHN_PYTHON_VERSION} \
# -f Dockerfile.cpy3-minimal-aio .

# time docker build \
# --build-arg BUILD_DATE=${BUILD_DATE} \
# --build-arg AUTOBAHN_PYTHON_VCS_REF=${AUTOBAHN_PYTHON_VCS_REF} \
# --build-arg AUTOBAHN_PYTHON_VERSION=${AUTOBAHN_PYTHON_VERSION} \
# -t crossbario/autobahn-python:cpy3-minimal-tx \
# -t crossbario/autobahn-python:cpy3-minimal-tx-${AUTOBAHN_PYTHON_VERSION} \
# -f Dockerfile.cpy3-minimal-tx .

version: python_version autobahn_version xbr_version

python_version:
docker run -it --rm crossbario/autobahn-python:cpy3 python -V
docker run -it --rm crossbario/autobahn-python:pypy3 python -V
docker run -it --rm crossbario/autobahn-python:cpy3-alpine python -V
docker run -it --rm crossbario/autobahn-python:cpy3-minimal-aio python -V
docker run -it --rm crossbario/autobahn-python:cpy3-minimal-tx python -V
# docker run -it --rm crossbario/autobahn-python:cpy3-alpine python -V
# docker run -it --rm crossbario/autobahn-python:cpy3-minimal-aio python -V
# docker run -it --rm crossbario/autobahn-python:cpy3-minimal-tx python -V

autobahn_version:
docker run -it --rm crossbario/autobahn-python:cpy3 python -c "import autobahn; print('running autobahn-{}'.format(autobahn.__version__))"
docker run -it --rm crossbario/autobahn-python:pypy3 python -c "import autobahn; print('running autobahn-{}'.format(autobahn.__version__))"
docker run -it --rm crossbario/autobahn-python:cpy3-alpine python -c "import autobahn; print('running autobahn-{}'.format(autobahn.__version__))"
docker run -it --rm crossbario/autobahn-python:cpy3-minimal-aio python -c "import autobahn; print('running autobahn-{}'.format(autobahn.__version__))"
docker run -it --rm crossbario/autobahn-python:cpy3-minimal-tx python -c "import autobahn; print('running autobahn-{}'.format(autobahn.__version__))"
# docker run -it --rm crossbario/autobahn-python:cpy3-alpine python -c "import autobahn; print('running autobahn-{}'.format(autobahn.__version__))"
# docker run -it --rm crossbario/autobahn-python:cpy3-minimal-aio python -c "import autobahn; print('running autobahn-{}'.format(autobahn.__version__))"
# docker run -it --rm crossbario/autobahn-python:cpy3-minimal-tx python -c "import autobahn; print('running autobahn-{}'.format(autobahn.__version__))"

xbr_version:
docker run -it --rm crossbario/autobahn-python:cpy3 python -c "from autobahn import xbr; print(xbr.network.address)"
docker run -it --rm crossbario/autobahn-python:pypy3 python -c "from autobahn import xbr; print(xbr.network.address)"
docker run -it --rm crossbario/autobahn-python:cpy3-alpine python -c "from autobahn import xbr; print(xbr.network.address)"
# docker run -it --rm crossbario/autobahn-python:cpy3-alpine python -c "from autobahn import xbr; print(xbr.network.address)"


test: test_cpy3 test_pypy3 test_cpy3_alpine test_cpy3_minimal_aio test_cpy3_minimal_tx
Expand All @@ -88,12 +88,12 @@ publish:
docker push crossbario/autobahn-python:cpy3-${AUTOBAHN_PYTHON_VERSION}
docker push crossbario/autobahn-python:pypy3
docker push crossbario/autobahn-python:pypy3-${AUTOBAHN_PYTHON_VERSION}
docker push crossbario/autobahn-python:cpy3-alpine
docker push crossbario/autobahn-python:cpy3-alpine-${AUTOBAHN_PYTHON_VERSION}
docker push crossbario/autobahn-python:cpy3-minimal-aio
docker push crossbario/autobahn-python:cpy3-minimal-aio-${AUTOBAHN_PYTHON_VERSION}
docker push crossbario/autobahn-python:cpy3-minimal-tx
docker push crossbario/autobahn-python:cpy3-minimal-tx-${AUTOBAHN_PYTHON_VERSION}
# docker push crossbario/autobahn-python:cpy3-alpine
# docker push crossbario/autobahn-python:cpy3-alpine-${AUTOBAHN_PYTHON_VERSION}
# docker push crossbario/autobahn-python:cpy3-minimal-aio
# docker push crossbario/autobahn-python:cpy3-minimal-aio-${AUTOBAHN_PYTHON_VERSION}
# docker push crossbario/autobahn-python:cpy3-minimal-tx
# docker push crossbario/autobahn-python:cpy3-minimal-tx-${AUTOBAHN_PYTHON_VERSION}

list:
-docker images crossbario/autobahn-python:*
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.rst
Expand Up @@ -5,6 +5,12 @@
Changelog
=========

20.12.2
-------

* fix: derive_bip32childkey traceback (#1436)
* fix: update and adjust docker files to upstream changes

20.12.1
-------

Expand Down

0 comments on commit cd3c4d8

Please sign in to comment.