Skip to content

Commit

Permalink
feat(legacy): add manta/lnurl support & fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lyxyx committed Jan 26, 2024
1 parent ff9efe5 commit 3ecf966
Show file tree
Hide file tree
Showing 32 changed files with 637 additions and 41 deletions.
26 changes: 26 additions & 0 deletions common/protob/messages-lnurl.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto2";
package hw.trezor.messages.lnurl;

// Sugar for easier handling in Java
option java_package = "com.satoshilabs.trezor.lib.protobuf";
option java_outer_classname = "TrezorMessageLnurl";

/**
* Request: linkingKey derivation
* @start
* @next LnurlPublicKey
*/
message LnurlAuth {
required bytes domain = 2; // domain
required bytes data = 3; // random_data
}

/**
* Response: LnurlPublicKey for the given index
* @end
*/
message LnurlAuthResp {
optional string publickey = 1;
optional string path = 2;
optional bytes signature = 3;
}
26 changes: 25 additions & 1 deletion common/protob/messages-sui.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ message SuiAddress {
/**
* Request: ask device to sign Sui transaction
* @start
* @next SuiSignedTx
* @next SuiSignedTx/SuiTxRequest
*/
message SuiSignTx {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required bytes raw_tx = 2; // serialized raw transaction
optional bytes data_initial_chunk = 3 [default='']; // The initial data chunk (<= 1024 bytes)
optional uint32 data_length = 4; // Length of transaction payload
}


/**
* Response: signature for transaction
* @end
Expand All @@ -42,6 +45,27 @@ message SuiSignedTx {
required bytes signature = 2; // the signature of the raw transaction
}

/**
* Response: Device asks for more data from transaction payload, or returns the signature.
* If data_length is set, device awaits that many more bytes of payload.
* Otherwise, the signature fields contain the computed transaction signature. All three fields will be present.
* @end
* @next SuiTxAck
*/
message SuiTxRequest {
optional uint32 data_length = 1; // Number of bytes being requested (<= 1024)
optional bytes public_key = 2; // public key for the private key used to sign tx
optional bytes signature = 3; // the signature of the raw transaction
}

/**
* Request: Transaction payload data.
* @next SuiTxRequest
*/
message SuiTxAck {
required bytes data_chunk = 1; // Bytes from transaction payload (<= 1024 bytes)
}

/**
* Request: Ask device to sign message
* @next SuiMessageSignature
Expand Down
6 changes: 6 additions & 0 deletions common/protob/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ enum MessageType {
MessageType_SuiSignedTx = 11103 [(wire_out) = true];
MessageType_SuiSignMessage = 11104 [(wire_in) = true];
MessageType_SuiMessageSignature = 11105 [(wire_out) = true];
MessageType_SuiTxRequest = 11106 [(wire_out) = true];
MessageType_SuiTxAck = 11107 [(wire_in) = true];

// Filecoin
MessageType_FilecoinGetAddress = 11200 [(wire_in) = true];
Expand Down Expand Up @@ -512,6 +514,10 @@ enum MessageType {
MessageType_NostrSignSchnorr = 11508 [(wire_in) = true];
MessageType_NostrSignedSchnorr = 11509 [(wire_out) = true];

// lnurl
MessageType_LnurlAuth = 11600 [(wire_in) = true];
MessageType_LnurlAuthResp = 11601 [(wire_out) = true];

//onekey
MessageType_DeviceInfoSettings = 10001 [(wire_in) = true];
MessageType_GetDeviceInfo = 10002 [(wire_in) = true];
Expand Down
4 changes: 4 additions & 0 deletions core/src/trezor/enums/MessageType.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@
SuiSignedTx = 11103
SuiSignMessage = 11104
SuiMessageSignature = 11105
SuiTxRequest = 11106
SuiTxAck = 11107
FilecoinGetAddress = 11200
FilecoinAddress = 11201
FilecoinSignTx = 11202
Expand All @@ -344,6 +346,8 @@
NostrDecryptedMessage = 11507
NostrSignSchnorr = 11508
NostrSignedSchnorr = 11509
LnurlAuth = 11600
LnurlAuthResp = 11601
DeviceInfoSettings = 10001
GetDeviceInfo = 10002
DeviceInfo = 10003
Expand Down
4 changes: 4 additions & 0 deletions core/src/trezor/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ class MessageType(IntEnum):
SuiSignedTx = 11103
SuiSignMessage = 11104
SuiMessageSignature = 11105
SuiTxRequest = 11106
SuiTxAck = 11107
FilecoinGetAddress = 11200
FilecoinAddress = 11201
FilecoinSignTx = 11202
Expand All @@ -367,6 +369,8 @@ class MessageType(IntEnum):
NostrDecryptedMessage = 11507
NostrSignSchnorr = 11508
NostrSignedSchnorr = 11509
LnurlAuth = 11600
LnurlAuthResp = 11601
DeviceInfoSettings = 10001
GetDeviceInfo = 10002
DeviceInfo = 10003
Expand Down
70 changes: 70 additions & 0 deletions core/src/trezor/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5235,6 +5235,40 @@ def __init__(
def is_type_of(cls, msg: Any) -> TypeGuard["KaspaSignedTx"]:
return isinstance(msg, cls)

class LnurlAuth(protobuf.MessageType):
domain: "bytes"
data: "bytes"

def __init__(
self,
*,
domain: "bytes",
data: "bytes",
) -> None:
pass

@classmethod
def is_type_of(cls, msg: Any) -> TypeGuard["LnurlAuth"]:
return isinstance(msg, cls)

class LnurlAuthResp(protobuf.MessageType):
publickey: "str | None"
path: "str | None"
signature: "bytes | None"

def __init__(
self,
*,
publickey: "str | None" = None,
path: "str | None" = None,
signature: "bytes | None" = None,
) -> None:
pass

@classmethod
def is_type_of(cls, msg: Any) -> TypeGuard["LnurlAuthResp"]:
return isinstance(msg, cls)

class MoneroTransactionSourceEntry(protobuf.MessageType):
outputs: "list[MoneroOutputEntry]"
real_output: "int | None"
Expand Down Expand Up @@ -7516,12 +7550,16 @@ def is_type_of(cls, msg: Any) -> TypeGuard["SuiAddress"]:
class SuiSignTx(protobuf.MessageType):
address_n: "list[int]"
raw_tx: "bytes"
data_initial_chunk: "bytes"
data_length: "int | None"

def __init__(
self,
*,
raw_tx: "bytes",
address_n: "list[int] | None" = None,
data_initial_chunk: "bytes | None" = None,
data_length: "int | None" = None,
) -> None:
pass

Expand All @@ -7545,6 +7583,38 @@ def __init__(
def is_type_of(cls, msg: Any) -> TypeGuard["SuiSignedTx"]:
return isinstance(msg, cls)

class SuiTxRequest(protobuf.MessageType):
data_length: "int | None"
public_key: "bytes | None"
signature: "bytes | None"

def __init__(
self,
*,
data_length: "int | None" = None,
public_key: "bytes | None" = None,
signature: "bytes | None" = None,
) -> None:
pass

@classmethod
def is_type_of(cls, msg: Any) -> TypeGuard["SuiTxRequest"]:
return isinstance(msg, cls)

class SuiTxAck(protobuf.MessageType):
data_chunk: "bytes"

def __init__(
self,
*,
data_chunk: "bytes",
) -> None:
pass

@classmethod
def is_type_of(cls, msg: Any) -> TypeGuard["SuiTxAck"]:
return isinstance(msg, cls)

class SuiSignMessage(protobuf.MessageType):
address_n: "list[int]"
message: "bytes"
Expand Down
2 changes: 2 additions & 0 deletions legacy/firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ OBJS += kaspa.o
OBJS += nexa.o
OBJS += nostr.o
OBJS += base64.o
OBJS += lnurl.o
endif

OBJS += debug.o
Expand Down Expand Up @@ -237,6 +238,7 @@ OBJS += protob/messages-cardano.pb.o
OBJS += protob/messages-kaspa.pb.o
OBJS += protob/messages-nexa.pb.o
OBJS += protob/messages-nostr.pb.o
OBJS += protob/messages-lnurl.pb.o
endif

OPTFLAGS ?= -Os
Expand Down
68 changes: 39 additions & 29 deletions legacy/firmware/cosmos_networks.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@
#include <string.h>

const CosmosNetworkType cosmos_networks[COSMOS_NETWORK_COUNT] = {
{"cosmoshub-4", "Cosmos Hub", "ATOM", "uatom", 6},
{"osmosis-1", "Osmosis", "OSMO", "uosmo", 6},
{"secret-4", "Secret Network", "SCRT", "uscrt", 6},
{"akashnet-2", "Akash", "AKT", "uakt", 6},
{"crypto-org-chain-mainnet-1", "Crypto.org", "CRO", "basecro", 8},
{"iov-mainnet-ibc", "Starname", "IOV", "uiov", 6},
{"sifchain-1", "Sifchain", "ROWAN", "rowan", 18},
{"shentu-2.2", "Shentu", "CTK", "uctk", 6},
{"irishub-1", "IRISnet", "IRIS", "uiris", 6},
{"regen-1", "Regen", "REGEN", "uregen", 6},
{"core-1", "Persistence", "XPRT", "uxprt", 6},
{"sentinelhub-2", "Sentinel", "DVPN", "udvpn", 6},
{"ixo-4", "ixo", "IXO", "uixo", 6},
{"emoney-3", "e-Money", "NGM", "ungm", 6},
{"agoric-3", "Agoric", "BLD", "ubld", 6},
{"bostrom", "Bostrom", "BOOT", "boot", 0},
{"juno-1", "Juno", "JUNO", "ujuno", 6},
{"stargaze-1", "Stargaze", "STARS", "ustars", 6},
{"axelar-dojo-1", "Axelar", "AXL", "uaxl", 6},
{"sommelier-3", "Sommelier", "SOMM", "usomm", 6},
{"umee-1", "Umee", "UMEE", "uumee", 6},
{"gravity-bridge-3", "Gravity Bridge", "GRAV", "ugraviton", 6},
{"tgrade-mainnet-1", "Tgrade", "TGD", "utgd", 6},
{"stride-1", "Stride", "STRD", "ustrd", 6},
{"evmos_9001-2", "Evmos", "EVMOS", "aevmos", 18},
{"injective-1", "Injective", "INJ", "inj", 18},
{"kava_2222-10", "Kava", "KAVA", "ukava", 6},
{"quicksilver-1", "Quicksilver", "QCK", "uqck", 6},
{"fetchhub-4", "Fetch.ai", "FET", "afet", 18},
{"cosmoshub-4", "cosmos", "Cosmos Hub", "ATOM", "uatom", 6},
{"osmosis-1", "osmo", "Osmosis", "OSMO", "uosmo", 6},
{"secret-4", "secret", "Secret Network", "SCRT", "uscrt", 6},
{"akashnet-2", "akash", "Akash", "AKT", "uakt", 6},
{"crypto-org-chain-mainnet-1", "cro", "Crypto.org", "CRO", "basecro", 8},
{"iov-mainnet-ibc", "star", "Starname", "IOV", "uiov", 6},
{"sifchain-1", "sif", "Sifchain", "ROWAN", "rowan", 18},
{"shentu-2.2", "certik", "Shentu", "CTK", "uctk", 6},
{"irishub-1", "iaa", "IRISnet", "IRIS", "uiris", 6},
{"regen-1", "regen", "Regen", "REGEN", "uregen", 6},
{"core-1", "persistence", "Persistence", "XPRT", "uxprt", 6},
{"sentinelhub-2", "sent", "Sentinel", "DVPN", "udvpn", 6},
{"ixo-4", "ixo", "ixo", "IXO", "uixo", 6},
{"emoney-3", "emoney", "e-Money", "NGM", "ungm", 6},
{"agoric-3", "agoric", "Agoric", "BLD", "ubld", 6},
{"bostrom", "bostrom", "Bostrom", "BOOT", "boot", 0},
{"juno-1", "juno", "Juno", "JUNO", "ujuno", 6},
{"stargaze-1", "stars", "Stargaze", "STARS", "ustars", 6},
{"axelar-dojo-1", "axelar", "Axelar", "AXL", "uaxl", 6},
{"sommelier-3", "somm", "Sommelier", "SOMM", "usomm", 6},
{"umee-1", "umee", "Umee", "UMEE", "uumee", 6},
{"gravity-bridge-3", "gravity", "Gravity Bridge", "GRAV", "ugraviton", 6},
{"tgrade-mainnet-1", "tgrade", "Tgrade", "TGD", "utgd", 6},
{"stride-1", "stride", "Stride", "STRD", "ustrd", 6},
{"evmos_9001-2", "evmos", "Evmos", "EVMOS", "aevmos", 18},
{"injective-1", "inj", "Injective", "INJ", "inj", 18},
{"kava_2222-10", "kava", "Kava", "KAVA", "ukava", 6},
{"quicksilver-1", "quick", "Quicksilver", "QCK", "uqck", 6},
{"fetchhub-4", "fetch", "Fetch.ai", "FET", "afet", 18},
{"celestia", "celestia", "Celestia", "TIA", "utia", 6},
};

const CosmosNetworkType *cosmosnetworkByChainId(const char *chain_id) {
Expand All @@ -41,3 +42,12 @@ const CosmosNetworkType *cosmosnetworkByChainId(const char *chain_id) {
}
return NULL;
}

const CosmosNetworkType *cosmosnetworkByHrp(const char *hrp) {
for (int i = 0; i < COSMOS_NETWORK_COUNT; i++) {
if (memcmp(hrp, cosmos_networks[i].hrp, strlen(hrp)) == 0) {
return &(cosmos_networks[i]);
}
}
return NULL;
}
4 changes: 3 additions & 1 deletion legacy/firmware/cosmos_networks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#include <stdint.h>

#define COSMOS_NETWORK_COUNT 29
#define COSMOS_NETWORK_COUNT 30

typedef struct {
const char *const chain_id;
const char *const hrp;
const char *const chain_name;
const char *const coin_denom;
const char *const coin_minimal_denom;
Expand All @@ -16,5 +17,6 @@ typedef struct {
extern const CosmosNetworkType cosmos_networks[COSMOS_NETWORK_COUNT];

const CosmosNetworkType *cosmosnetworkByChainId(const char *chain_id);
const CosmosNetworkType *cosmosnetworkByHrp(const char *hrp);

#endif
6 changes: 4 additions & 2 deletions legacy/firmware/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

#include "fsm.h"
#include <libopencm3/stm32/flash.h>

#include <stdio.h>
#include "address.h"
#include "aes/aes.h"
#include "base58.h"
Expand All @@ -34,7 +35,6 @@
#include "curves.h"
#include "debug.h"
#include "ecdsa.h"
#include "fsm.h"
#include "fw_signatures.h"
#include "gettext.h"
#include "hmac.h"
Expand Down Expand Up @@ -75,6 +75,7 @@
#include "ethereum_onekey.h"
#include "filecoin.h"
#include "kaspa.h"
#include "lnurl.h"
#include "near.h"
#include "nem.h"
#include "nem2.h"
Expand Down Expand Up @@ -579,6 +580,7 @@ bool fsm_layoutPathWarning(uint32_t address_n_count,
#include "fsm_msg_ethereum_onekey.h"
#include "fsm_msg_filecoin.h"
#include "fsm_msg_kaspa.h"
#include "fsm_msg_lnurl.h"
#include "fsm_msg_near.h"
#include "fsm_msg_nem.h"
#include "fsm_msg_nexa.h"
Expand Down
5 changes: 5 additions & 0 deletions legacy/firmware/fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "messages-ethereum.pb.h"
#include "messages-filecoin.pb.h"
#include "messages-kaspa.pb.h"
#include "messages-lnurl.pb.h"
#include "messages-management.pb.h"
#include "messages-near.pb.h"
#include "messages-nem.pb.h"
Expand Down Expand Up @@ -248,6 +249,7 @@ void fsm_msgRippleSignTx(RippleSignTx *msg);
void fsm_msgSuiGetAddress(const SuiGetAddress *msg);
void fsm_msgSuiSignTx(const SuiSignTx *msg);
void fsm_msgSuiSignMessage(SuiSignMessage *msg);
void fsm_msgSuiTxAck(SuiTxAck *msg);

// filecoin
void fsm_msgFilecoinGetAddress(const FilecoinGetAddress *msg);
Expand Down Expand Up @@ -313,4 +315,7 @@ void fsm_msgNostrEncryptMessage(NostrEncryptMessage *msg);
void fsm_msgNostrDecryptMessage(NostrDecryptMessage *msg);
void fsm_msgNostrSignSchnorr(const NostrSignSchnorr *msg);

// lnurl
void fsm_msgLnurlAuth(const LnurlAuth *msg);

#endif
Loading

0 comments on commit 3ecf966

Please sign in to comment.