Skip to content
Closed
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
14 changes: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,26 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Install clang-format
run: sudo apt-get install -y clang-format-14

- name: Check code formatting
run: |
# Use pre-installed clang-format (ubuntu-latest ships with it)
CF=$(command -v clang-format-14 || command -v clang-format || true)
if [ -z "$CF" ]; then
echo "::warning::clang-format not found, skipping lint"
exit 0
fi
echo "Using: $CF ($($CF --version | head -1))"
FAILED=0
for f in $(find include/keepkey lib/firmware lib/board lib/transport/src \
-name '*.c' -o -name '*.h' 2>/dev/null | grep -v generated | grep -v '.pb.'); do
if ! clang-format-14 --style=file --dry-run --Werror "$f" 2>/dev/null; then
if ! $CF --style=file --dry-run --Werror "$f" 2>/dev/null; then
echo "::warning file=$f::Formatting differs from .clang-format"
FAILED=1
fi
done
if [ "$FAILED" = "1" ]; then
echo ""
echo "Run: clang-format -i <file> to fix formatting"
echo "Run: $CF -i <file> to fix formatting"
echo "Note: treating as warning until codebase is reformatted"
fi
# Warn-only until existing code is reformatted
Expand Down
5 changes: 5 additions & 0 deletions include/keepkey/firmware/fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ void fsm_msgMayachainGetAddress(const MayachainGetAddress *msg);
void fsm_msgMayachainSignTx(const MayachainSignTx *msg);
void fsm_msgMayachainMsgAck(const MayachainMsgAck *msg);

void fsm_msgTronGetAddress(const TronGetAddress *msg);
void fsm_msgTronSignTx(TronSignTx *msg);
void fsm_msgTonGetAddress(const TonGetAddress *msg);
void fsm_msgTonSignTx(TonSignTx *msg);

#if DEBUG_LINK
// void fsm_msgDebugLinkDecision(DebugLinkDecision *msg);
void fsm_msgDebugLinkGetState(DebugLinkGetState *msg);
Expand Down
68 changes: 68 additions & 0 deletions include/keepkey/firmware/ton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This file is part of the KeepKey project.
*
* Copyright (C) 2024 KeepKey
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KEEPKEY_FIRMWARE_TON_H
#define KEEPKEY_FIRMWARE_TON_H

#include "trezor/crypto/bip32.h"
#include "trezor/crypto/ed25519-donna/ed25519.h"

#include "messages-ton.pb.h"

// TON address length (Base64 URL-safe encoded, typically 48 chars)
#define TON_ADDRESS_MAX_LEN 64
#define TON_RAW_ADDRESS_MAX_LEN 128

// TON decimals (1 TON = 1,000,000,000 nanoTON)
#define TON_DECIMALS 9

/**
* Generate TON address from Ed25519 public key
* @param public_key Ed25519 public key (32 bytes)
* @param bounceable Bounceable flag for address encoding
* @param testnet Testnet flag for address encoding
* @param workchain Workchain ID (-1 or 0)
* @param address Output buffer for user-friendly Base64 encoded address
* @param address_len Length of address output buffer
* @param raw_address Output buffer for raw address format (workchain:hash)
* @param raw_address_len Length of raw_address output buffer
* @return true on success, false on failure
*/
bool ton_get_address(const ed25519_public_key public_key, bool bounceable,
bool testnet, int32_t workchain, char *address,
size_t address_len, char *raw_address,
size_t raw_address_len);

/**
* Format TON amount (nanoTON) for display
* @param buf Output buffer
* @param len Length of output buffer
* @param amount Amount in nanoTON (1 TON = 1,000,000,000 nanoTON)
*/
void ton_formatAmount(char *buf, size_t len, uint64_t amount);

/**
* Sign a TON transaction
* @param node HD node containing private key
* @param msg TonSignTx request message
* @param resp TonSignedTx response message (will be filled with signature)
*/
bool ton_signTx(const HDNode *node, const TonSignTx *msg, TonSignedTx *resp);

#endif
60 changes: 60 additions & 0 deletions include/keepkey/firmware/tron.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of the KeepKey project.
*
* Copyright (C) 2024 KeepKey
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KEEPKEY_FIRMWARE_TRON_H
#define KEEPKEY_FIRMWARE_TRON_H

#include "trezor/crypto/bip32.h"

#include "messages-tron.pb.h"

// TRON address length (Base58Check, typically 34 chars starting with 'T')
#define TRON_ADDRESS_MAX_LEN 64

// TRON decimals (1 TRX = 1,000,000 SUN)
#define TRON_DECIMALS 6

/**
* Generate TRON address from secp256k1 public key
* @param public_key secp256k1 public key (33 bytes compressed)
* @param address Output buffer for Base58Check encoded address
* @param address_len Length of output buffer
* @return true on success, false on failure
*/
bool tron_getAddress(const uint8_t public_key[33], char *address,
size_t address_len);

/**
* Format TRON amount (SUN) for display
* @param buf Output buffer
* @param len Length of output buffer
* @param amount Amount in SUN (1 TRX = 1,000,000 SUN)
*/
void tron_formatAmount(char *buf, size_t len, uint64_t amount);

/**
* Sign a TRON transaction
* @param node HD node containing private key
* @param msg TronSignTx request message
* @param resp TronSignedTx response message (will be filled with signature)
*/
bool tron_signTx(const HDNode *node, const TronSignTx *msg,
TronSignedTx *resp);

#endif
2 changes: 2 additions & 0 deletions include/keepkey/transport/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "messages-tendermint.pb.h"
#include "messages-thorchain.pb.h"
#include "messages-mayachain.pb.h"
#include "messages-tron.pb.h"
#include "messages-ton.pb.h"

#include "types.pb.h"
#include "trezor_transport.h"
Expand Down
17 changes: 17 additions & 0 deletions include/keepkey/transport/messages-solana.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SolanaGetAddress.address_n max_count:8
SolanaGetAddress.coin_name max_size:21

SolanaAddress.address max_size:64

SolanaSignTx.address_n max_count:8
SolanaSignTx.coin_name max_size:21
SolanaSignTx.raw_tx max_size:2048

SolanaSignedTx.signature max_size:64

SolanaSignMessage.address_n max_count:8
SolanaSignMessage.coin_name max_size:21
SolanaSignMessage.message max_size:1024

SolanaMessageSignature.public_key max_size:32
SolanaMessageSignature.signature max_size:64
12 changes: 12 additions & 0 deletions include/keepkey/transport/messages-ton.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TonGetAddress.address_n max_count:8
TonGetAddress.coin_name max_size:21

TonAddress.address max_size:50
TonAddress.raw_address max_size:70

TonSignTx.address_n max_count:8
TonSignTx.coin_name max_size:21
TonSignTx.raw_tx max_size:1024
TonSignTx.to_address max_size:50

TonSignedTx.signature max_size:64
14 changes: 14 additions & 0 deletions include/keepkey/transport/messages-tron.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
TronGetAddress.address_n max_count:8
TronGetAddress.coin_name max_size:21

TronAddress.address max_size:35

TronSignTx.address_n max_count:8
TronSignTx.coin_name max_size:21
TronSignTx.raw_data max_size:2048
TronSignTx.ref_block_bytes max_size:4
TronSignTx.ref_block_hash max_size:32
TronSignTx.contract_type max_size:64
TronSignTx.to_address max_size:35

TronSignedTx.signature max_size:65
2 changes: 2 additions & 0 deletions include/keepkey/transport/messages.options
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ FlashHash.challenge max_size:32
FlashWrite.data max_size:1024

FlashHashResponse.data max_size:32

Bip85Mnemonic.mnemonic max_size:241
2 changes: 2 additions & 0 deletions lib/firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ set(sources
tendermint.c
thorchain.c
tiny-json.c
tron.c
ton.c
transaction.c
txin_check.c
u2f.c)
Expand Down
6 changes: 6 additions & 0 deletions lib/firmware/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#include "keepkey/firmware/storage.h"
#include "keepkey/firmware/tendermint.h"
#include "keepkey/firmware/thorchain.h"
#include "keepkey/firmware/tron.h"
#include "keepkey/firmware/ton.h"
#include "keepkey/firmware/transaction.h"
#include "keepkey/firmware/txin_check.h"
#include "keepkey/firmware/u2f.h"
Expand All @@ -84,6 +86,8 @@
#include "messages-ripple.pb.h"
#include "messages-thorchain.pb.h"
#include "messages-mayachain.pb.h"
#include "messages-tron.pb.h"
#include "messages-ton.pb.h"

#include <stdio.h>

Expand Down Expand Up @@ -284,3 +288,5 @@ void fsm_msgClearSession(ClearSession *msg) {
#include "fsm_msg_tendermint.h"
#include "fsm_msg_thorchain.h"
#include "fsm_msg_mayachain.h"
#include "fsm_msg_tron.h"
#include "fsm_msg_ton.h"
Loading
Loading