mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
Add support for Stellar
This commit is contained in:
parent
2c56c4de1b
commit
8e8749dc68
@ -28,6 +28,7 @@ OBJS += ethereum.o
|
||||
OBJS += ethereum_tokens.o
|
||||
OBJS += nem2.o
|
||||
OBJS += nem_mosaics.o
|
||||
OBJS += stellar.o
|
||||
|
||||
OBJS += debug.o
|
||||
|
||||
|
275
firmware/fsm.c
275
firmware/fsm.c
@ -56,6 +56,7 @@
|
||||
#include "rfc6979.h"
|
||||
#include "gettext.h"
|
||||
#include "supervise.h"
|
||||
#include "stellar.h"
|
||||
|
||||
// message methods
|
||||
|
||||
@ -1637,6 +1638,280 @@ void fsm_msgCosiSign(CosiSign *msg)
|
||||
layoutHome();
|
||||
}
|
||||
|
||||
void fsm_msgStellarGetPublicKey(StellarGetPublicKey *msg)
|
||||
{
|
||||
RESP_INIT(StellarPublicKey);
|
||||
|
||||
CHECK_INITIALIZED
|
||||
|
||||
CHECK_PIN
|
||||
|
||||
// Will exit if the user does not confirm
|
||||
stellar_layoutGetPublicKey(msg->address_n, msg->address_n_count);
|
||||
|
||||
// Read public key and write it to the response
|
||||
resp->has_public_key = true;
|
||||
resp->public_key.size = 32;
|
||||
stellar_getPubkeyAtAddress(msg->address_n, msg->address_n_count, resp->public_key.bytes, sizeof(resp->public_key.bytes));
|
||||
|
||||
msg_write(MessageType_MessageType_StellarPublicKey, resp);
|
||||
|
||||
layoutHome();
|
||||
}
|
||||
|
||||
void fsm_msgStellarSignMessage(StellarSignMessage *msg)
|
||||
{
|
||||
CHECK_INITIALIZED
|
||||
CHECK_PIN
|
||||
|
||||
RESP_INIT(StellarMessageSignature);
|
||||
|
||||
// Will exit if the user does not confirm
|
||||
stellar_confirmSignString(msg, resp);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarMessageSignature, resp);
|
||||
|
||||
layoutHome();
|
||||
}
|
||||
|
||||
void fsm_msgStellarVerifyMessage(StellarVerifyMessage *msg)
|
||||
{
|
||||
if (!stellar_verifySignature(msg)) {
|
||||
fsm_sendFailure(FailureType_Failure_DataError, _("Invalid signature"));
|
||||
return;
|
||||
}
|
||||
|
||||
fsm_sendSuccess(_("Message verified"));
|
||||
layoutHome();
|
||||
}
|
||||
|
||||
void fsm_msgStellarSignTx(StellarSignTx *msg)
|
||||
{
|
||||
CHECK_INITIALIZED
|
||||
CHECK_PIN
|
||||
|
||||
stellar_signingInit(msg);
|
||||
|
||||
// Confirm transaction basics
|
||||
stellar_layoutTransactionSummary(msg);
|
||||
|
||||
// Respond with a request for the first operation
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
|
||||
void fsm_msgStellarCreateAccountOp(StellarCreateAccountOp *msg)
|
||||
{
|
||||
stellar_confirmCreateAccountOp(msg);
|
||||
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
void fsm_msgStellarPaymentOp(StellarPaymentOp *msg)
|
||||
{
|
||||
// This will display additional dialogs to the user
|
||||
stellar_confirmPaymentOp(msg);
|
||||
|
||||
// Last operation was confirmed, send a StellarSignedTx
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
void fsm_msgStellarPathPaymentOp(StellarPathPaymentOp *msg)
|
||||
{
|
||||
stellar_confirmPathPaymentOp(msg);
|
||||
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
void fsm_msgStellarManageOfferOp(StellarManageOfferOp *msg)
|
||||
{
|
||||
stellar_confirmManageOfferOp(msg);
|
||||
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
void fsm_msgStellarCreatePassiveOfferOp(StellarCreatePassiveOfferOp *msg)
|
||||
{
|
||||
stellar_confirmCreatePassiveOfferOp(msg);
|
||||
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
void fsm_msgStellarSetOptionsOp(StellarSetOptionsOp *msg)
|
||||
{
|
||||
stellar_confirmSetOptionsOp(msg);
|
||||
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
void fsm_msgStellarChangeTrustOp(StellarChangeTrustOp *msg)
|
||||
{
|
||||
stellar_confirmChangeTrustOp(msg);
|
||||
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
void fsm_msgStellarAllowTrustOp(StellarAllowTrustOp *msg)
|
||||
{
|
||||
stellar_confirmAllowTrustOp(msg);
|
||||
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
void fsm_msgStellarAccountMergeOp(StellarAccountMergeOp *msg)
|
||||
{
|
||||
stellar_confirmAccountMergeOp(msg);
|
||||
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
void fsm_msgStellarManageDataOp(StellarManageDataOp *msg)
|
||||
{
|
||||
stellar_confirmManageDataOp(msg);
|
||||
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
void fsm_msgStellarBumpSequenceOp(StellarBumpSequenceOp *msg)
|
||||
{
|
||||
stellar_confirmBumpSequenceOp(msg);
|
||||
|
||||
if (stellar_allOperationsConfirmed()) {
|
||||
RESP_INIT(StellarSignedTx);
|
||||
|
||||
stellar_fillSignedTx(resp);
|
||||
msg_write(MessageType_MessageType_StellarSignedTx, resp);
|
||||
layoutHome();
|
||||
}
|
||||
// Request the next operation to sign
|
||||
else {
|
||||
RESP_INIT(StellarTxOpRequest);
|
||||
|
||||
msg_write(MessageType_MessageType_StellarTxOpRequest, resp);
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG_LINK
|
||||
|
||||
void fsm_msgDebugLinkGetState(DebugLinkGetState *msg)
|
||||
|
@ -80,6 +80,23 @@ void fsm_msgNEMDecryptMessage(NEMDecryptMessage *msg);
|
||||
void fsm_msgCosiCommit(CosiCommit *msg);
|
||||
void fsm_msgCosiSign(CosiSign *msg);
|
||||
|
||||
// Stellar
|
||||
void fsm_msgStellarGetPublicKey(StellarGetPublicKey *msg);
|
||||
void fsm_msgStellarSignTx(StellarSignTx *msg);
|
||||
void fsm_msgStellarPaymentOp(StellarPaymentOp *msg);
|
||||
void fsm_msgStellarCreateAccountOp(StellarCreateAccountOp *msg);
|
||||
void fsm_msgStellarPathPaymentOp(StellarPathPaymentOp *msg);
|
||||
void fsm_msgStellarManageOfferOp(StellarManageOfferOp *msg);
|
||||
void fsm_msgStellarCreatePassiveOfferOp(StellarCreatePassiveOfferOp *msg);
|
||||
void fsm_msgStellarSetOptionsOp(StellarSetOptionsOp *msg);
|
||||
void fsm_msgStellarChangeTrustOp(StellarChangeTrustOp *msg);
|
||||
void fsm_msgStellarAllowTrustOp(StellarAllowTrustOp *msg);
|
||||
void fsm_msgStellarAccountMergeOp(StellarAccountMergeOp *msg);
|
||||
void fsm_msgStellarManageDataOp(StellarManageDataOp *msg);
|
||||
void fsm_msgStellarSignMessage(StellarSignMessage *msg);
|
||||
void fsm_msgStellarVerifyMessage(StellarVerifyMessage *msg);
|
||||
void fsm_msgStellarBumpSequenceOp(StellarBumpSequenceOp *msg);
|
||||
|
||||
// debug message functions
|
||||
#if DEBUG_LINK
|
||||
//void fsm_msgDebugLinkDecision(DebugLinkDecision *msg);
|
||||
|
@ -176,6 +176,68 @@ CosiSign.global_pubkey max_size:32
|
||||
|
||||
CosiSignature.signature max_size:32
|
||||
|
||||
|
||||
# Stellar
|
||||
StellarGetPublicKey.address_n max_count:10
|
||||
|
||||
StellarPublicKey.public_key max_size:32
|
||||
|
||||
StellarSignMessage.address_n max_count:10
|
||||
StellarSignMessage.message max_size:1024
|
||||
|
||||
StellarMessageSignature.public_key max_size:32
|
||||
StellarMessageSignature.signature max_size:64
|
||||
|
||||
StellarVerifyMessage.public_key max_size:32
|
||||
StellarVerifyMessage.message max_size:1024
|
||||
StellarVerifyMessage.signature max_size:64
|
||||
|
||||
StellarMessageVerification.public_key max_size: 32
|
||||
|
||||
StellarSignTx.address_n max_count:10
|
||||
StellarSignTx.network_passphrase max_size:1024
|
||||
StellarSignTx.source_account max_size:32
|
||||
StellarSignTx.memo_text max_size:29
|
||||
StellarSignTx.memo_hash max_size:32
|
||||
|
||||
StellarPaymentOp.source_account max_size:32
|
||||
StellarPaymentOp.destination_account max_size:32
|
||||
|
||||
StellarCreateAccountOp.source_account max_size:32
|
||||
StellarCreateAccountOp.new_account max_size:32
|
||||
|
||||
StellarPathPaymentOp.source_account max_size:32
|
||||
StellarPathPaymentOp.destination_account max_size:32
|
||||
StellarPathPaymentOp.paths max_count:5
|
||||
|
||||
StellarManageOfferOp.source_account max_size:32
|
||||
|
||||
StellarCreatePassiveOfferOp.source_account max_size:32
|
||||
|
||||
StellarSetOptionsOp.source_account max_size:32
|
||||
StellarSetOptionsOp.inflation_destination_account max_size:32
|
||||
StellarSetOptionsOp.home_domain max_size:33
|
||||
StellarSetOptionsOp.signer_key max_size:32
|
||||
|
||||
StellarChangeTrustOp.source_account max_size:32
|
||||
|
||||
StellarAllowTrustOp.source_account max_size:32
|
||||
StellarAllowTrustOp.trusted_account max_size:32
|
||||
StellarAllowTrustOp.asset_code max_size:13
|
||||
|
||||
StellarAccountMergeOp.source_account max_size:32
|
||||
StellarAccountMergeOp.destination_account max_size:32
|
||||
|
||||
StellarManageDataOp.source_account max_size:32
|
||||
StellarManageDataOp.key max_size:65
|
||||
StellarManageDataOp.value max_size:65
|
||||
|
||||
StellarBumpSequenceOp.source_account max_size:32
|
||||
|
||||
StellarSignedTx.public_key max_size:32
|
||||
StellarSignedTx.signature max_size:64 # ed25519 signatures are 64 bytes, this does not include the hint
|
||||
|
||||
|
||||
# deprecated
|
||||
SimpleSignTx skip_message:true
|
||||
|
||||
|
@ -72,3 +72,6 @@ NEMAggregateModification.modifications max_count:16
|
||||
NEMCosignatoryModification.public_key max_size:32
|
||||
|
||||
NEMImportanceTransfer.public_key max_size:32
|
||||
|
||||
StellarAssetType.code max_size:13
|
||||
StellarAssetType.issuer max_size:32
|
1850
firmware/stellar.c
Normal file
1850
firmware/stellar.c
Normal file
File diff suppressed because it is too large
Load Diff
99
firmware/stellar.h
Normal file
99
firmware/stellar.h
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* This file is part of the TREZOR project.
|
||||
*
|
||||
* 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 __STELLAR_H__
|
||||
#define __STELLAR_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "bip32.h"
|
||||
#include "crypto.h"
|
||||
#include "messages.pb.h"
|
||||
#include "fsm.h"
|
||||
|
||||
typedef struct {
|
||||
// BIP32 path to the address being used for signing
|
||||
uint32_t address_n[10];
|
||||
size_t address_n_count;
|
||||
uint8_t signing_pubkey[32];
|
||||
|
||||
// 1 - public network, 2 - official testnet, 3 - other private network
|
||||
uint8_t network_type;
|
||||
|
||||
// Total number of operations expected
|
||||
uint8_t num_operations;
|
||||
// Number that have been confirmed by the user
|
||||
uint8_t confirmed_operations;
|
||||
|
||||
// sha256 context that will eventually be signed
|
||||
SHA256_CTX sha256_ctx;
|
||||
} StellarTransaction;
|
||||
|
||||
// Signing process
|
||||
void stellar_signingInit(StellarSignTx *tx);
|
||||
void stellar_signingAbort(void);
|
||||
void stellar_confirmCreateAccountOp(StellarCreateAccountOp *msg);
|
||||
void stellar_confirmPaymentOp(StellarPaymentOp *msg);
|
||||
void stellar_confirmPathPaymentOp(StellarPathPaymentOp *msg);
|
||||
void stellar_confirmManageOfferOp(StellarManageOfferOp *msg);
|
||||
void stellar_confirmCreatePassiveOfferOp(StellarCreatePassiveOfferOp *msg);
|
||||
void stellar_confirmSetOptionsOp(StellarSetOptionsOp *msg);
|
||||
void stellar_confirmChangeTrustOp(StellarChangeTrustOp *msg);
|
||||
void stellar_confirmAllowTrustOp(StellarAllowTrustOp *msg);
|
||||
void stellar_confirmAccountMergeOp(StellarAccountMergeOp *msg);
|
||||
void stellar_confirmManageDataOp(StellarManageDataOp *msg);
|
||||
void stellar_confirmBumpSequenceOp(StellarBumpSequenceOp *msg);
|
||||
|
||||
void stellar_confirmSignString(StellarSignMessage *msg, StellarMessageSignature *resp);
|
||||
|
||||
void stellar_signString(const uint8_t *str_to_sign, uint32_t *address_n, size_t address_n_count, uint8_t *out_signature);
|
||||
bool stellar_verifySignature(StellarVerifyMessage *msg);
|
||||
|
||||
// Layout
|
||||
void stellar_layoutGetPublicKey(uint32_t *address_n, size_t address_n_count);
|
||||
void stellar_layoutTransactionDialog(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5);
|
||||
void stellar_layoutTransactionSummary(StellarSignTx *msg);
|
||||
void stellar_layoutSigningDialog(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, uint32_t *address_n, size_t address_n_count, const char *warning, bool is_final_step);
|
||||
|
||||
// Helpers
|
||||
HDNode *stellar_deriveNode(uint32_t *address_n, size_t address_n_count);
|
||||
|
||||
size_t stellar_publicAddressAsStr(uint8_t *bytes, char *out, size_t outlen);
|
||||
const char **stellar_lineBreakAddress(uint8_t *addrbytes);
|
||||
void stellar_getPubkeyAtAddress(uint32_t *address_n, size_t address_n_count, uint8_t *out, size_t outlen);
|
||||
|
||||
void stellar_hashupdate_uint32(uint32_t value);
|
||||
void stellar_hashupdate_uint64(uint64_t value);
|
||||
void stellar_hashupdate_bool(bool value);
|
||||
void stellar_hashupdate_string(uint8_t *data, size_t len);
|
||||
void stellar_hashupdate_address(uint8_t *address_bytes);
|
||||
void stellar_hashupdate_asset(StellarAssetType *asset);
|
||||
void stellar_hashupdate_bytes(uint8_t *data, size_t len);
|
||||
|
||||
StellarTransaction *stellar_getActiveTx(void);
|
||||
void stellar_fillSignedTx(StellarSignedTx *resp);
|
||||
uint8_t stellar_allOperationsConfirmed(void);
|
||||
void stellar_getSignatureForActiveTx(uint8_t *out_signature);
|
||||
|
||||
void stellar_format_uint32(uint32_t number, char *out, size_t outlen);
|
||||
void stellar_format_uint64(uint64_t number, char *out, size_t outlen);
|
||||
void stellar_format_stroops(uint64_t number, char *out, size_t outlen);
|
||||
void stellar_format_asset(StellarAssetType *asset, char *str_formatted, size_t len);
|
||||
void stellar_format_price(uint32_t numerator, uint32_t denominator, char *out, size_t outlen);
|
||||
|
||||
uint16_t stellar_crc16(uint8_t *bytes, uint32_t length);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user