2019-09-12 13:42:04 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-05-16 11:28:20 +00:00
|
|
|
cd $(dirname $0)/..
|
|
|
|
|
|
|
|
PROTOB=common/protob
|
|
|
|
|
|
|
|
CORE_PROTOBUF_SOURCES="\
|
|
|
|
$PROTOB/messages.proto \
|
2019-07-31 15:02:41 +00:00
|
|
|
$PROTOB/messages-binance.proto \
|
2019-05-16 11:28:20 +00:00
|
|
|
$PROTOB/messages-bitcoin.proto \
|
|
|
|
$PROTOB/messages-cardano.proto \
|
|
|
|
$PROTOB/messages-common.proto \
|
|
|
|
$PROTOB/messages-crypto.proto \
|
|
|
|
$PROTOB/messages-debug.proto \
|
|
|
|
$PROTOB/messages-eos.proto \
|
|
|
|
$PROTOB/messages-ethereum.proto \
|
|
|
|
$PROTOB/messages-lisk.proto \
|
|
|
|
$PROTOB/messages-management.proto \
|
|
|
|
$PROTOB/messages-monero.proto \
|
|
|
|
$PROTOB/messages-nem.proto \
|
|
|
|
$PROTOB/messages-ripple.proto \
|
|
|
|
$PROTOB/messages-stellar.proto \
|
|
|
|
$PROTOB/messages-tezos.proto \
|
2019-09-01 20:54:34 +00:00
|
|
|
$PROTOB/messages-webauthn.proto \
|
2019-05-16 11:28:20 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
PYTHON_PROTOBUF_SOURCES=$PROTOB/*.proto
|
|
|
|
|
2019-07-01 13:52:36 +00:00
|
|
|
CORE_MESSAGES_IGNORE="\
|
|
|
|
CosiCommit \
|
|
|
|
CosiCommitment \
|
|
|
|
CosiSign \
|
|
|
|
CosiSignature \
|
|
|
|
DebugLinkFlashErase \
|
|
|
|
DebugLinkLog \
|
|
|
|
DebugLinkMemory \
|
|
|
|
DebugLinkMemoryRead \
|
|
|
|
DebugLinkMemoryWrite \
|
|
|
|
DebugLinkStop \
|
|
|
|
NEMDecryptMessage \
|
|
|
|
NEMDecryptedMessage \
|
|
|
|
PinMatrixAck \
|
|
|
|
PinMatrixRequest \
|
|
|
|
PinMatrixRequestType \
|
|
|
|
WordAck \
|
|
|
|
WordRequest \
|
|
|
|
WordRequestType \
|
|
|
|
"
|
|
|
|
|
|
|
|
PYTHON_MESSAGES_IGNORE=""
|
|
|
|
|
2019-05-16 11:28:20 +00:00
|
|
|
RETURN=0
|
|
|
|
|
|
|
|
do_rebuild() {
|
|
|
|
# rebuild protobuf in specified directory
|
|
|
|
local DESTDIR="$1"
|
|
|
|
shift
|
|
|
|
local SOURCES="$1"
|
|
|
|
shift
|
2019-07-01 13:52:36 +00:00
|
|
|
local IGNORE="$1"
|
|
|
|
shift
|
2019-08-26 12:50:11 +00:00
|
|
|
local APPLY_BITCOIN_ONLY="$1"
|
|
|
|
shift
|
2019-05-16 11:28:20 +00:00
|
|
|
|
|
|
|
mkdir -p "$DESTDIR"
|
|
|
|
rm -f "$DESTDIR"/[A-Z]*.py
|
|
|
|
|
|
|
|
# note $SOURCES is unquoted - we want wildcard expansion and multiple args
|
|
|
|
$PROTOB/pb2py "$@" -o "$DESTDIR" $SOURCES
|
2019-07-01 13:52:36 +00:00
|
|
|
|
2019-08-26 12:50:11 +00:00
|
|
|
# TODO: make this less hackish
|
|
|
|
# maybe introduce attribute "altcoin" in protobuf?
|
|
|
|
if [ "$APPLY_BITCOIN_ONLY" == "TRUE" ]; then
|
2019-08-28 10:42:33 +00:00
|
|
|
sed -i "3ifrom trezor import utils\n" "$DESTDIR"/Capability.py
|
2019-08-26 12:50:11 +00:00
|
|
|
sed -i "3ifrom trezor import utils\n" "$DESTDIR"/MessageType.py
|
|
|
|
sed -i "/^EthereumGetPublicKey/iif not utils.BITCOIN_ONLY:" "$DESTDIR"/MessageType.py
|
2019-09-01 20:54:34 +00:00
|
|
|
for altcoin in Ethereum NEM Lisk Tezos Stellar Cardano Ripple Monero DebugMonero Eos Binance WebAuthn; do
|
2019-08-28 10:42:33 +00:00
|
|
|
sed -i "s:^$altcoin: $altcoin:" "$DESTDIR"/Capability.py
|
2019-08-26 12:50:11 +00:00
|
|
|
sed -i "s:^$altcoin: $altcoin:" "$DESTDIR"/MessageType.py
|
|
|
|
done
|
2019-08-28 10:42:33 +00:00
|
|
|
sed -i "/^Bitcoin_like/iif not utils.BITCOIN_ONLY:" "$DESTDIR"/Capability.py
|
|
|
|
sed -i "/^EOS/iif not utils.BITCOIN_ONLY:" "$DESTDIR"/Capability.py
|
2019-08-26 12:50:11 +00:00
|
|
|
for feature in Bitcoin_like EOS U2F; do
|
2019-08-28 10:42:33 +00:00
|
|
|
sed -i "s:^$feature: $feature:" "$DESTDIR"/Capability.py
|
2019-08-26 12:50:11 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
# ENDTODO
|
|
|
|
|
2019-07-01 13:52:36 +00:00
|
|
|
# delete unused messages
|
|
|
|
for F in $IGNORE; do
|
|
|
|
rm -f "$DESTDIR"/"$F".py
|
|
|
|
done
|
2019-05-16 11:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do_check() {
|
|
|
|
# rebuild protobuf in tmpdir and check result against specified directory
|
|
|
|
local TMPDIR=$(mktemp -d proto-check.XXXXXX)
|
|
|
|
local DESTDIR="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
cp -rT "$DESTDIR" "$TMPDIR"
|
|
|
|
do_rebuild "$TMPDIR" "$@"
|
|
|
|
DIFF=$(diff -ur "$DESTDIR" "$TMPDIR")
|
|
|
|
rm -r "$TMPDIR"
|
|
|
|
if [ -n "$DIFF" ]; then
|
|
|
|
echo "$DIFF"
|
|
|
|
RETURN=1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$1" == "--check" ]; then
|
|
|
|
func=do_check
|
|
|
|
else
|
|
|
|
func=do_rebuild
|
|
|
|
fi
|
|
|
|
|
2019-08-26 12:50:11 +00:00
|
|
|
$func core/src/trezor/messages "$CORE_PROTOBUF_SOURCES" "$CORE_MESSAGES_IGNORE" TRUE --no-init-py
|
|
|
|
$func python/src/trezorlib/messages "$PYTHON_PROTOBUF_SOURCES" "$PYTHON_MESSAGES_IGNORE" FALSE -P ..protobuf
|
2019-05-16 11:28:20 +00:00
|
|
|
|
|
|
|
exit $RETURN
|