Skip to content

Instantly share code, notes, and snippets.

@qlrd

qlrd/Makefile Secret

Last active July 22, 2022 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qlrd/95d2a6431b2fd854c1d658395c763966 to your computer and use it in GitHub Desktop.
Save qlrd/95d2a6431b2fd854c1d658395c763966 to your computer and use it in GitHub Desktop.
Possible change proposals for repetitive tasks of krux development.
help:
@echo "================"
@echo " ██"
@echo " ██"
@echo " ██"
@echo " ██████"
@echo " ██"
@echo " ██ ██"
@echo " ██ ██"
@echo " ████"
@echo " ██ ██"
@echo " ██ ██"
@echo " ██ ██"
@echo ""
@echo "KRUX MAKE TASKS "
@echo "================"
@echo ""
@echo "build/maixpy_m5stickv: build a firmware for m5stickv"
@echo "build/maixpy_amigo_ips: build a firmware for amigo"
@echo "build/sign: create new signature hash on src/krux/metadata.py"
@echo "clean/dependencies: clean dependencies files installed by poetry"
@echo "clean/simulator: clean generated simulator assets"
@echo "clean: execute clean/dependencies and clean/simulator"
@echo "debug/<tty>/<baudrate>: live debug on specific tty with specific baudrate, generally, 115200"
@echo "format: run poetry/black code formating"
@echo "help: show this message"
@echo "install: install main python dependencies"
@echo "install/docs: install python dependencies for documentation"
@echo "install/simulator: install python dependencies for simulator"
@echo "install/update: update python dependencies"
@echo "lint/src: lint src folder"
@echo "lint/tests: lint tests folder"
@echo "repl: run python repl with dependencies"
@echo "simulator: run simulator"
@echo "test: run tests"
@echo "test/verbose: run tests in verbose mode"
@echo "update: update current branch (and its submodules) with the origin (selfcustody) remote"
build/%:
@vagrant ssh -c 'cd vagrant && ./krux build $(echo $@ | cut -d/ -f2)'
build/flash:
@vagrant ssh -c 'cd /vagrant; ./krux flash'
build/sign:
@echo "==> Creating src/krux/metadata.py.backup"
@cp src/krux/metadata.py src/krux/metadata.py.backup
@vagrant up
@vagrant ssh -c 'cd /vagrant && ./krux generate-keypair'
@echo "$$(vagrant ssh -c "cd /vagrant && ./krux pem-to-pubkey pubkey.pem" | grep -E '[a-z0-9]{66}')" > .newhash
@vagrant halt
@sed -i -E 's/\r//' .newhash
@echo $$(awk '/SIGNER_PUBKEY/{print $$3}' src/krux/metadata.py) > .oldhash
@echo "==> Substituting $$(cat .oldhash) to \"$$(cat .newhash)\""
@sed -i -E 's/'$$(cat .oldhash)'/"'$$(cat .newhash)'"/g' src/krux/metadata.py
@rm .oldhash
@rm .newhash
@echo "==> WARN: Check if its ok."
@cat src/krux/metadata.py
@echo "==> WARN: If not execute `mv src/krux/metadata.py.backup src/krux/metadata.py`"
@echo "==> DONE"
clean/dependencies:
@echo "==> cleaning poetry dependencies"
@echo $$(poetry env list --full-path) | xargs rm -rf
@echo "==> removing poetry.lock"
@rm ./poetry.lock
clean/simulator:
@echo "==> cleaning simulator/screenshots folder"
@rm -rf simulator/screenshots
@echo "==> cleaning simulator/sd folder"
@rm -rf simulator/sd
@echo "==> cleaning simulator/logs folder"
@rm -rf simulator/logs
clean: clean/dependencies clean/simulator
debug/%/%:
@vagrant halt
@screen /dev/$(cut -d/ -f2) $(cut -d/ -f3)
format:
@poetry run black ./src && poetry run black ./tests
install:
@poetry install -v
install/docs:
@poetry install -v --extras docs
install/simulator:
@poetry install -v --extras simulator
install/update:
@poetry update -v
lint/%:
@poetry run pylint ./$(cut -d/ -f2)
update:
@git pull origin $(git branch --show-current) && git submodule update --init --recursive
repl:
@poetry run python
test:
@poetry run pytest --cache-clear --cov src/krux --cov-report html ./tests
test/verbose:
@poetry run pytest --cache-clear --cov src/krux --cov-report html --show-capture all --capture tee-sys -r A ./tests
.PHONY: simulator
simulator:
@cd simulator && ./run-all-sequences.sh
# The MIT License (MIT)
# Copyright (c) 2021 Tom J. Sun
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
[tool.poetry]
name = "krux"
version = "22.03.0"
description = "Open-source, airgapped bitcoin hardware signer for the M5StickV"
authors = ["Jeff S <jeffreesun@protonmail.com>"]
# The optional dependencies moved to here due to,
# according the link below, optional dependencies cannot be in dev section.
# https://stackoverflow.com/questions/60971502/python-poetry-how-to-install-optional-dependencies#answer-66030875
[tool.poetry.dependencies]
python = "^3.9.1"
embit = { path = "./vendor/embit/", develop = true }
ur = { path = "./vendor/foundation-ur-py/", develop = true }
urtypes = { path = "./vendor/urtypes/", develop = true }
PyQRCode = {version = "^1.2.1", optional = true}
pygame = {version = "^2.1.2", optional = true}
opencv-python = {version = "^4.5.5", optional = true}
numpy = {version = "^1.22.3", optional = true}
Pillow = {version = "^9.0.1", optional = true}
pyzbar = {version = "^0.1.9", optional = true}
mkdocs-static-i18n = {version = "^0.46", optional = true}
[tool.poetry.dev-dependencies]
black = "^22.1.0"
mkdocs = "^1.2.3"
pylint = "^2.12.2"
pytest = "^6.2.5"
pytest-cov = "^3.0.0"
pytest-mock = "^3.6.1"
[tool.poetry.extras]
docs = ["mkdocs-static-i18n"]
simulator = ["PyQRCode", "pygame", "opencv-python", "numpy", "Pillow", "pyzbar"]
#!/bin/sh
mkdir -p screenshots
mkdir -p sd
mkdir -p logs
cp -rf ../i18n/translations sd/translations
rm -f sd/settings.json
declare -a SEQUENCES_1=(
about
debug-options
extended-public-key-wpkh
extended-public-key-wsh
home-options
load-mnemonic-options
load-mnemonic-via-bits
load-mnemonic-via-numbers
load-mnemonic-via-qr
load-mnemonic-via-text
)
declare -a SEQUENCES_WITH_SD=(locale-option login-locale-de-de)
declare -a SEQUENCES_2=(
login-options
logo
mnemonic-12-word
mnemonic-24-word
network-options
new-mnemonic-options
new-mnemonic-via-d6
new-mnemonic-via-d20
)
declare -a SEQUENCES_WITH_PRINTER=(
print-qr
)
declare -a SEQUENCES_3=(
printer-options
scan-address
settings-options
shutdown
sign-message
sign-options
sign-psbt
wallet-type-options
wallet-wpkh
wallet-wsh
)
for sequence in "${SEQUENCES_1[@]}"
do
echo "[ INFO ] $(date --iso-8601=seconds) | Simulating $sequence"
poetry run python simulator.py --sequence sequences/$sequence.txt > logs/$sequence.log 2>&1
done
for sequence in "${SEQUENCES_WITH_SD[@]}"
do
echo "[ INFO ] $(date --iso-8601=seconds) | Simulating $sequence"
poetry run python simulator.py --sequence sequences/$sequence.txt --with-sd True > logs/$sequence.log 2>&1
echo "[ WARN ] $(date --iso-8601=seconds) | removing sd/settings.json"
rm -f sd/settings.json
done
for sequence in "${SEQUENCES_2[@]}"
do
echo "[ INFO ] $(date --iso-8601=seconds) | Simulating $sequence"
poetry run python simulator.py --sequence sequences/$sequence.txt > logs/$sequence.log 2>&1
done
for sequence in "${SEQUENCES_WITH_PRINTER[@]}"
do
echo "[ INFO ] $(date --iso-8601=seconds) | Simulating $sequence"
poetry run python simulator.py --sequence sequences/$sequence.txt --with-printer True > logs/$sequence.log 2>&1
done
for sequence in "${SEQUENCES_3[@]}"
do
echo "[ INFO ] $(date --iso-8601=seconds) | Simulating $sequence"
poetry run python simulator.py --sequence sequences/$sequence.txt > logs/$sequence.log 2>&1
done
#poetry run python simulator.py --sequence sequences/about.txt
#poetry run python simulator.py --sequence sequences/debug-options.txt
#poetry run python simulator.py --sequence sequences/extended-public-key-wpkh.txt
#poetry run python simulator.py --sequence sequences/extended-public-key-wsh.txt
#poetry run python simulator.py --sequence sequences/home-options.txt
#poetry run python simulator.py --sequence sequences/load-mnemonic-options.txt
#poetry run python simulator.py --sequence sequences/load-mnemonic-via-bits.txt
#poetry run python simulator.py --sequence sequences/load-mnemonic-via-numbers.txt
#poetry run python simulator.py --sequence sequences/load-mnemonic-via-qr.txt
#poetry run python simulator.py --sequence sequences/load-mnemonic-via-text.txt
#poetry run python simulator.py --sequence sequences/locale-options.txt --with-sd True
#rm -f sd/settings.json
#poetry run python simulator.py --sequence sequences/login-locale-de-de.txt --with-sd True
#rm -f sd/settings.json
#poetry run python simulator.py --sequence sequences/login-options.txt
#poetry run python simulator.py --sequence sequences/logo.txt
#poetry run python simulator.py --sequence sequences/mnemonic-12-word.txt
#poetry run python simulator.py --sequence sequences/mnemonic-24-word.txt
#poetry run python simulator.py --sequence sequences/network-options.txt
#poetry run python simulator.py --sequence sequences/new-mnemonic-options.txt
#poetry run python simulator.py --sequence sequences/new-mnemonic-via-d6.txt
#poetry run python simulator.py --sequence sequences/new-mnemonic-via-d20.txt
#poetry run python simulator.py --sequence sequences/print-qr.txt --with-printer True
#poetry run python simulator.py --sequence sequences/printer-options.txt
#poetry run python simulator.py --sequence sequences/scan-address.txt
#poetry run python simulator.py --sequence sequences/settings-options.txt
#poetry run python simulator.py --sequence sequences/shutdown.txt
#poetry run python simulator.py --sequence sequences/sign-message.txt
#poetry run python simulator.py --sequence sequences/sign-options.txt
#poetry run python simulator.py --sequence sequences/sign-psbt.txt
#poetry run python simulator.py --sequence sequences/wallet-type-options.txt
#poetry run python simulator.py --sequence sequences/wallet-wpkh.txt
#poetry run python simulator.py --sequence sequences/wallet-wsh.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment