2018-04-06 21:45:32 +00:00
|
|
|
/*
|
2019-06-17 18:27:55 +00:00
|
|
|
* This file is part of the Trezor project, https://trezor.io/
|
2018-09-06 16:28:56 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2018 ZuluCrypto <zulucrypto@protonmail.com>
|
2018-04-06 21:45:32 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2019-03-29 16:10:31 +00:00
|
|
|
#include "base32.h"
|
2018-04-06 21:45:32 +00:00
|
|
|
#include "bip32.h"
|
|
|
|
#include "crypto.h"
|
|
|
|
#include "fsm.h"
|
2019-03-29 16:10:31 +00:00
|
|
|
#include "messages.pb.h"
|
2018-06-27 15:36:51 +00:00
|
|
|
|
|
|
|
// 56 character base-32 encoded string
|
|
|
|
#define STELLAR_ADDRESS_SIZE 56
|
|
|
|
// Decodes to 35 bytes
|
|
|
|
#define STELLAR_ADDRESS_SIZE_RAW 35
|
|
|
|
// Raw key size is 32 bytes
|
|
|
|
#define STELLAR_KEY_SIZE 32
|
2018-04-06 21:45:32 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2019-03-29 16:10:31 +00:00
|
|
|
// BIP32 path to the address being used for signing
|
|
|
|
uint32_t address_n[10];
|
|
|
|
size_t address_n_count;
|
|
|
|
uint8_t signing_pubkey[32];
|
2018-04-06 21:45:32 +00:00
|
|
|
|
2019-03-29 16:10:31 +00:00
|
|
|
// 1 - public network, 2 - official testnet, 3 - other private network
|
|
|
|
uint8_t network_type;
|
2018-04-06 21:45:32 +00:00
|
|
|
|
2019-03-29 16:10:31 +00:00
|
|
|
// Total number of operations expected
|
|
|
|
uint32_t num_operations;
|
|
|
|
// Number that have been confirmed by the user
|
|
|
|
uint32_t confirmed_operations;
|
2018-04-06 21:45:32 +00:00
|
|
|
|
2019-03-29 16:10:31 +00:00
|
|
|
// sha256 context that will eventually be signed
|
|
|
|
SHA256_CTX sha256_ctx;
|
2018-04-06 21:45:32 +00:00
|
|
|
} StellarTransaction;
|
|
|
|
|
|
|
|
// Signing process
|
2018-10-23 12:15:26 +00:00
|
|
|
bool stellar_signingInit(const StellarSignTx *tx);
|
2018-06-27 15:36:51 +00:00
|
|
|
void stellar_signingAbort(const char *reason);
|
2019-03-29 16:10:31 +00:00
|
|
|
bool stellar_confirmSourceAccount(bool has_source_account,
|
|
|
|
const char *str_account);
|
2018-09-14 12:40:29 +00:00
|
|
|
bool stellar_confirmCreateAccountOp(const StellarCreateAccountOp *msg);
|
|
|
|
bool stellar_confirmPaymentOp(const StellarPaymentOp *msg);
|
2021-10-07 01:58:52 +00:00
|
|
|
bool stellar_confirmPathPaymentStrictReceiveOp(
|
|
|
|
const StellarPathPaymentStrictReceiveOp *msg);
|
2021-10-07 14:06:08 +00:00
|
|
|
bool stellar_confirmPathPaymentStrictSendOp(
|
|
|
|
const StellarPathPaymentStrictSendOp *msg);
|
2021-10-07 03:48:45 +00:00
|
|
|
bool stellar_confirmManageBuyOfferOp(const StellarManageBuyOfferOp *msg);
|
2021-10-07 01:58:52 +00:00
|
|
|
bool stellar_confirmManageSellOfferOp(const StellarManageSellOfferOp *msg);
|
2021-10-07 23:33:09 +00:00
|
|
|
bool stellar_confirmCreatePassiveSellOfferOp(
|
|
|
|
const StellarCreatePassiveSellOfferOp *msg);
|
2018-09-14 12:40:29 +00:00
|
|
|
bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg);
|
|
|
|
bool stellar_confirmChangeTrustOp(const StellarChangeTrustOp *msg);
|
|
|
|
bool stellar_confirmAllowTrustOp(const StellarAllowTrustOp *msg);
|
|
|
|
bool stellar_confirmAccountMergeOp(const StellarAccountMergeOp *msg);
|
|
|
|
bool stellar_confirmManageDataOp(const StellarManageDataOp *msg);
|
|
|
|
bool stellar_confirmBumpSequenceOp(const StellarBumpSequenceOp *msg);
|
2018-04-06 21:45:32 +00:00
|
|
|
|
|
|
|
// Layout
|
2019-03-29 16:10:31 +00:00
|
|
|
void stellar_layoutTransactionDialog(const char *line1, const char *line2,
|
|
|
|
const char *line3, const char *line4,
|
|
|
|
const char *line5);
|
2018-09-14 12:40:29 +00:00
|
|
|
void stellar_layoutTransactionSummary(const StellarSignTx *msg);
|
2019-03-29 16:10:31 +00:00
|
|
|
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);
|
2018-04-06 21:45:32 +00:00
|
|
|
|
|
|
|
// Helpers
|
2019-03-29 16:10:31 +00:00
|
|
|
const HDNode *stellar_deriveNode(const uint32_t *address_n,
|
|
|
|
size_t address_n_count);
|
2018-04-06 21:45:32 +00:00
|
|
|
|
2019-03-29 16:10:31 +00:00
|
|
|
size_t stellar_publicAddressAsStr(const uint8_t *bytes, char *out,
|
|
|
|
size_t outlen);
|
2018-09-14 12:40:29 +00:00
|
|
|
const char **stellar_lineBreakAddress(const uint8_t *addrbytes);
|
2018-04-06 21:45:32 +00:00
|
|
|
|
|
|
|
void stellar_hashupdate_uint32(uint32_t value);
|
|
|
|
void stellar_hashupdate_uint64(uint64_t value);
|
|
|
|
void stellar_hashupdate_bool(bool value);
|
2018-10-23 12:15:26 +00:00
|
|
|
void stellar_hashupdate_string(const uint8_t *data, size_t len);
|
|
|
|
void stellar_hashupdate_address(const uint8_t *address_bytes);
|
2021-07-26 09:16:43 +00:00
|
|
|
void stellar_hashupdate_asset(const StellarAsset *asset);
|
2018-09-14 12:40:29 +00:00
|
|
|
void stellar_hashupdate_bytes(const uint8_t *data, size_t len);
|
2018-04-06 21:45:32 +00:00
|
|
|
|
|
|
|
void stellar_fillSignedTx(StellarSignedTx *resp);
|
2018-07-10 18:44:30 +00:00
|
|
|
bool stellar_allOperationsConfirmed(void);
|
2018-07-10 18:28:07 +00:00
|
|
|
void stellar_getSignatureForActiveTx(uint8_t *out_signature);
|
2018-04-06 21:45:32 +00:00
|
|
|
|
|
|
|
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);
|
2021-07-26 09:16:43 +00:00
|
|
|
void stellar_format_asset(const StellarAsset *asset, char *str_formatted,
|
2019-03-29 16:10:31 +00:00
|
|
|
size_t len);
|
|
|
|
void stellar_format_price(uint32_t numerator, uint32_t denominator, char *out,
|
|
|
|
size_t outlen);
|
2018-04-06 21:45:32 +00:00
|
|
|
|
2018-06-27 15:36:51 +00:00
|
|
|
bool stellar_validateAddress(const char *str_address);
|
2019-03-29 16:10:31 +00:00
|
|
|
bool stellar_getAddressBytes(const char *str_address, uint8_t *out_bytes);
|
2018-04-06 21:45:32 +00:00
|
|
|
uint16_t stellar_crc16(uint8_t *bytes, uint32_t length);
|
|
|
|
|
2018-09-06 16:28:56 +00:00
|
|
|
#endif
|