Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Maya (fork of thorchain) #1293

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Binary file added images/coin/coinCacao.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions rust/apps/cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,45 @@ mod tests {
}
}

#[test]
fn test_parse_tx() {
// transfer cacao
let raw_tx = "0a570a500a0e2f74797065732e4d736753656e64123e0a14d2a392d2d0e98f64dd0f9aa422da9b37b21944501214ead5b280c71c6ae156ee581cff8c9147a64cca1f1a100a0472756e65120831303030303030301203626d79125a0a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103b1f26f209231b1ee90a8c52a981038794195fd7e08c47df02ff8bb7c1ce2a43512040a020801180012061080cab5ee011a1474686f72636861696e2d6d61696e6e65742d763120bdb106";
let data_type = transaction::structs::DataType::Direct;
let parsed_tx = parse(&hex::decode(raw_tx).unwrap(), data_type).unwrap();

let overview = parsed_tx.overview;
let network = overview.common.network;
assert_eq!("MAYAChain", network.as_str(),)
}

#[test]
fn test_derive_mayachain_address_by_seed() {
let seed = [
150, 6, 60, 69, 19, 44, 132, 15, 126, 22, 101, 163, 185, 120, 20, 216, 235, 37, 134,
243, 75, 217, 69, 240, 111, 161, 91, 147, 39, 238, 190, 53, 95, 101, 78, 129, 198, 35,
58, 82, 20, 157, 122, 149, 234, 116, 134, 235, 141, 105, 145, 102, 245, 103, 126, 80,
117, 41, 72, 37, 153, 98, 76, 220,
];
let path = "M/44'/931'/0'/0/0";
let pub_key =
keystore::algorithms::secp256k1::get_public_key_by_seed(&seed, &path.to_string())
.unwrap();
let address = generate_address(pub_key, "maya").unwrap();
assert_eq!("maya14vc9484wvt66f7upncl7hq8kcvdd7qm80gnre6", address);
}

#[test]
fn test_derive_mayachain_address_by_xpub() {
{
let root_path = "44'/931'/0'";
let root_xpub = "xpub6CexGUAW8CXpTAZ19JxEGRxt2g4W7YNc3XSopBxw27jjBWDF67KShM7JqUibfQpHTsjzBdEwAw9X7QsBTVxjRpgK3bUbhS4e3y6kVhUfkek";
let hd_path = "44'/931'/0'/0/0";
let address = derive_address(hd_path, root_xpub, root_path, "maya").unwrap();
assert_eq!("maya14vc9484wvt66f7upncl7hq8kcvdd7qm80gnre6", address);
}
}

#[test]
fn test_derive_address() {
{
Expand Down
2 changes: 2 additions & 0 deletions rust/apps/cosmos/src/transaction/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub fn get_network_by_chain_id(chain_id: &str) -> Result<String> {
map.insert("phoenix", "Terra");
map.insert("columbus", "Terra Classic");
map.insert("thorchain-mainnet", "THORChain");
map.insert("mayachain-mainnet", "MAYAChain");
let chain_id_parts: Vec<&str> = chain_id.split("-").collect();
let chain_id_prefix = if chain_id_parts.len() > 1 {
chain_id_parts[..chain_id_parts.len() - 1].join("-")
Expand Down Expand Up @@ -96,6 +97,7 @@ pub fn get_chain_id_by_address(address: &str) -> String {
map.insert("quick", "quicksilver-1");
map.insert("terra", "phoenix-1");
map.insert("thor", "thorchain-mainnet");
map.insert("maya", "mayachain-mainnet");
for (k, v) in map {
if address.starts_with(k) {
return v.to_string();
Expand Down
2 changes: 2 additions & 0 deletions rust/apps/wallets/src/thor_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const BTC_SEGWIT_PREFIX: &str = "m/49'/0'/0'";
const BTC_NATIVE_SEGWIT_PREFIX: &str = "m/84'/0'/0'";
const ETH_STANDARD_PREFIX: &str = "m/44'/60'/0'";
const ETH_LEDGER_LIVE_PREFIX: &str = "m/44'/60'"; //overlap with ETH_STANDARD at 0
const MAYACHAIN_PREFIX: &str = "m/44'/931'/0'";
const THORCHAIN_PREFIX: &str = "m/44'/931'/0'";

pub fn generate_crypto_multi_accounts(
Expand All @@ -42,6 +43,7 @@ pub fn generate_crypto_multi_accounts(
BTC_LEGACY_PREFIX.to_string(),
BTC_SEGWIT_PREFIX.to_string(),
BTC_NATIVE_SEGWIT_PREFIX.to_string(),
MAYACHAIN_PREFIX.to_string(),
THORCHAIN_PREFIX.to_string(),
];
for ele in extended_public_keys {
Expand Down
1 change: 1 addition & 0 deletions src/crypto/account_public_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static const ChainItem_t g_chainTable[] = {
{XPUB_TYPE_TERRA, SECP256K1, "terra", "M/44'/330'/0'" },
{XPUB_TYPE_XRP, SECP256K1, "xrp", "M/44'/144'/0'" },
{XPUB_TYPE_THOR, SECP256K1, "thor", "M/44'/931'/0'" },
{XPUB_TYPE_MAYA, SECP256K1, "maya", "M/44'/931'/0'" },
{XPUB_TYPE_SOL_BIP44_0, ED25519, "sol_bip44_0", "M/44'/501'/0'" },
{XPUB_TYPE_SOL_BIP44_1, ED25519, "sol_bip44_1", "M/44'/501'/1'" },
{XPUB_TYPE_SOL_BIP44_2, ED25519, "sol_bip44_2", "M/44'/501'/2'" },
Expand Down
1 change: 1 addition & 0 deletions src/crypto/account_public_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef enum {
XPUB_TYPE_TERRA,
XPUB_TYPE_XRP,
XPUB_TYPE_THOR,
XPUB_TYPE_MAYA,
XPUB_TYPE_SOL_BIP44_0,
XPUB_TYPE_SOL_BIP44_1,
XPUB_TYPE_SOL_BIP44_2,
Expand Down
1 change: 1 addition & 0 deletions src/ui/gui_chain/gui_chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ typedef enum {
CHAIN_ATOM,
CHAIN_CRO,
CHAIN_RUNE,
CHAIN_CACAO,
CHAIN_KAVA,
CHAIN_LUNC,
CHAIN_AXL,
Expand Down
3 changes: 2 additions & 1 deletion src/ui/gui_chain/others/gui_cosmos.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "user_memory.h"
#include "account_manager.h"
#include "gui_chain.h"
#define MAX_COSMOS_ADDR_LEN 61
#define MAX_COSMOS_ADDR_LEN 62

static bool g_isMulti = false;
static URParseResult *g_urResult = NULL;
Expand All @@ -27,6 +27,7 @@ static const CosmosChain_t g_cosmosChains[COSMOS_CHAINS_LEN] = {
{CHAIN_AKT, "akash", 118, XPUB_TYPE_COSMOS, "akashnet-2"},
{CHAIN_CRO, "cro", 394, XPUB_TYPE_CRO, "crypto-org-chain-mainnet-1"},
{CHAIN_RUNE, "thor", 931, XPUB_TYPE_THOR, "thorchain-mainnet-v1"},
{CHAIN_CACAO, "maya", 931, XPUB_TYPE_MAYA, "mayachain-mainnet-v1"},
{CHAIN_IOV, "star", 234, XPUB_TYPE_IOV, "iov-mainnet-ibc"},
{CHAIN_ROWAN, "sif", 118, XPUB_TYPE_COSMOS, "sifchain-1"},
{CHAIN_CTK, "shentu", 118, XPUB_TYPE_COSMOS, "shentu-2.2"},
Expand Down
4 changes: 2 additions & 2 deletions src/ui/gui_chain/others/gui_cosmos.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "rust.h"
#include "account_public_info.h"
#define COSMOS_CHAINS_LEN 33
#define COSMOS_CHAINS_LEN 34

typedef struct {
uint8_t index;
Expand Down Expand Up @@ -71,4 +71,4 @@ void GetCosmosTextOfKind(void *indata, void *param, uint32_t maxLen);
void GetCosmosDetailItemValue(void *indata, void *param, uint32_t maxLen);
bool IsCosmosMsg(ViewType viewType);
char *GetKeplrConnectionDisplayAddressByIndex(uint32_t index);
char *GetCosmosChainAddressByCoinTypeAndIndex(uint8_t chainType, uint32_t address_index);
char *GetCosmosChainAddressByCoinTypeAndIndex(uint8_t chainType, uint32_t address_index);
2 changes: 1 addition & 1 deletion src/ui/gui_components/gui_status_bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const static CoinWalletInfo_t g_coinWalletBtn[] = {
{HOME_WALLET_CARD_COSMOS, "", &coinCosmos}, {HOME_WALLET_CARD_TIA, "", &coinTia},
{HOME_WALLET_CARD_DYM, "", &coinDym}, {HOME_WALLET_CARD_OSMO, "", &coinOsmo},
{HOME_WALLET_CARD_INJ, "", &coinInj}, {HOME_WALLET_CARD_ATOM, "", &coinAtom},
{HOME_WALLET_CARD_CRO, "", &coinCro}, {HOME_WALLET_CARD_RUNE, "", &coinRune},
{HOME_WALLET_CARD_CRO, "", &coinCro}, {HOME_WALLET_CARD_RUNE, "", &coinRune}, {HOME_WALLET_CARD_CACAO, "", &coinCacao},
{HOME_WALLET_CARD_KAVA, "", &coinKava}, {HOME_WALLET_CARD_LUNC, "", &coinLunc}, {HOME_WALLET_CARD_AXL, "", &coinAxl},
{HOME_WALLET_CARD_LUNA, "", &coinLuna}, {HOME_WALLET_CARD_AKT, "", &coinAkt},
{HOME_WALLET_CARD_STRD, "", &coinStrd}, {HOME_WALLET_CARD_SCRT, "", &coinScrt},
Expand Down
1 change: 1 addition & 0 deletions src/ui/gui_frame/gui_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ LV_IMG_DECLARE(coinTrac);
LV_IMG_DECLARE(coinSats);
LV_IMG_DECLARE(coinXlm);
LV_IMG_DECLARE(coinRune);
LV_IMG_DECLARE(coinCacao);

// wallet
LV_IMG_DECLARE(walletKeystone);
Expand Down
7 changes: 7 additions & 0 deletions src/ui/gui_widgets/general/gui_home_widgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static WalletState_t g_walletState[HOME_WALLET_CARD_BUTT] = {
{HOME_WALLET_CARD_ATOM, false, "ATOM", true},
{HOME_WALLET_CARD_CRO, false, "CRO", true},
{HOME_WALLET_CARD_RUNE, false, "RUNE", true},
{HOME_WALLET_CARD_CACAO, false, "CACAO", true},
{HOME_WALLET_CARD_KAVA, false, "KAVA", true},
{HOME_WALLET_CARD_LUNC, false, "LUNC", true},
{HOME_WALLET_CARD_AXL, false, "AXL", true},
Expand Down Expand Up @@ -272,6 +273,12 @@ static const ChainCoinCard_t g_coinCardArray[HOME_WALLET_CARD_BUTT] = {
.chain = "THORChain",
.icon = &coinRune,
},
{
.index = HOME_WALLET_CARD_CACAO,
.coin = "CACAO",
.chain = "MAYAChain",
.icon = &coinCacao,
},
{
.index = HOME_WALLET_CARD_KAVA,
.coin = "KAVA",
Expand Down
1 change: 1 addition & 0 deletions src/ui/gui_widgets/general/gui_home_widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef enum {
HOME_WALLET_CARD_ATOM,
HOME_WALLET_CARD_CRO,
HOME_WALLET_CARD_RUNE,
HOME_WALLET_CARD_CACAO,
HOME_WALLET_CARD_KAVA,
HOME_WALLET_CARD_LUNC,
HOME_WALLET_CARD_AXL,
Expand Down
6 changes: 6 additions & 0 deletions src/ui/gui_widgets/general/gui_standard_receive_widgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ static uint32_t g_umeeChainSelectIndex[3] = {0};
static uint32_t g_qckChainSelectIndex[3] = {0};
static uint32_t g_tgdChainSelectIndex[3] = {0};
static uint32_t g_thorChainSelectIndex[3] = {0};
static uint32_t g_mayaChainSelectIndex[3] = {0};

static PageWidget_t *g_pageWidget;
static uint32_t g_selectedIndex[3] = {0};
Expand Down Expand Up @@ -988,6 +989,7 @@ void GuiResetCurrentStandardAddressIndex(uint8_t index)
g_qckChainSelectIndex[index] = 0;
g_tgdChainSelectIndex[index] = 0;
g_thorChainSelectIndex[index] = 0;
g_mayaChainSelectIndex[index] = 0;
}

void GuiResetAllStandardAddressIndex(void)
Expand Down Expand Up @@ -1030,6 +1032,7 @@ void GuiResetAllStandardAddressIndex(void)
memset_s(g_qckChainSelectIndex, sizeof(g_qckChainSelectIndex), 0, sizeof(g_qckChainSelectIndex));
memset_s(g_tgdChainSelectIndex, sizeof(g_tgdChainSelectIndex), 0, sizeof(g_tgdChainSelectIndex));
memset_s(g_thorChainSelectIndex, sizeof(g_thorChainSelectIndex), 0, sizeof(g_thorChainSelectIndex));
memset_s(g_mayaChainSelectIndex, sizeof(g_mayaChainSelectIndex), 0, sizeof(g_mayaChainSelectIndex));
}

static uint32_t* GetCosmosChainCurrentSelectIndex()
Expand Down Expand Up @@ -1134,6 +1137,9 @@ static uint32_t* GetCosmosChainCurrentSelectIndex()
case HOME_WALLET_CARD_RUNE:
return &g_thorChainSelectIndex[GetCurrentAccountIndex()];
break;
case HOME_WALLET_CARD_CACAO:
return &g_mayaChainSelectIndex[GetCurrentAccountIndex()];
break;

default:
return NULL;
Expand Down
5 changes: 3 additions & 2 deletions src/ui/gui_widgets/gui_connect_wallet_widgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ static const lv_img_dsc_t *g_tonKeeperCoinArray[1] = {
&coinTon,
};

static const lv_img_dsc_t *g_ThorWalletCoinArray[3] = {
static const lv_img_dsc_t *g_ThorWalletCoinArray[4] = {
// todo thorchain will support bitcoin later
// &coinBtc,
&coinEth,
&coinRune,
&coinCacao,
};

static CoinState_t g_defaultFewchaState[FEWCHA_COINS_BUTT] = {
Expand Down Expand Up @@ -1881,4 +1882,4 @@ void GuiConnectWalletDeInit(void)
uint8_t GuiConnectWalletGetWalletIndex(void)
{
return g_connectWalletTileView.walletIndex;
}
}
6 changes: 4 additions & 2 deletions src/ui/wallet/gui_wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,12 @@ UREncodeResult *GuiGetBackpackData(void)
UREncodeResult *GuiGetThorWalletBtcData(void)
{

uint8_t mfp[4] = {0};
uint8_t mfp[5] = {0};
GetMasterFingerPrint(mfp);

PtrT_CSliceFFI_ExtendedPublicKey public_keys =
SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey));
ExtendedPublicKey keys[5];
ExtendedPublicKey keys[6];
public_keys->data = keys;
public_keys->size = 5;
keys[0].path = "m/84'/0'/0'";
Expand All @@ -633,6 +633,8 @@ UREncodeResult *GuiGetThorWalletBtcData(void)
keys[3].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_THOR);
keys[4].path = "m/44'/60'/0'";
keys[4].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_ETH_BIP44_STANDARD);
keys[5].path = "m/44'/931'/0'";
keys[5].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_MAYA);

char serialNumber[256];
GetSerialNumber(serialNumber);
Expand Down