Skip to content

Commit 3542e8c

Browse files
authored
feat(core): add InvokeHostFunctionOp support for stellar (#423)
* feat(core): add InvokeHostFunctionOp support for stellar * feat(core/address_book): add view fresh incoming BTC address in address book 1. update i18n items * feat(core): add TestNet support for Cardano sign-message * fix(core): misc fix 1. fix Solana signing issue 2. optimize Ethereum sign-typed-data display 3. optimize the auto screen off logic * chore(core): bump version to 4.20.0
1 parent 5baaa25 commit 3542e8c

43 files changed

Lines changed: 897 additions & 312 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

common/protob/messages-cardano.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ message CardanoSignMessage {
536536
required CardanoDerivationType derivation_type = 3;
537537
required uint32 network_id = 4; // network id - mainnet or testnet
538538
optional CardanoAddressType address_type = 5; // one of the CardanoAddressType
539+
optional uint32 protocol_magic = 6; // network's protocol magic - needed for Byron addresses on testnets
540+
539541
}
540542

541543
/**

common/protob/messages-stellar.proto

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ message StellarSignTx {
5959
optional uint64 memo_id = 12; // 8-byte uint64
6060
optional bytes memo_hash = 13; // 32 bytes representing a hash
6161
required uint32 num_operations = 14; // number of operations in this transaction
62+
optional uint32 soroban_data_size = 60[default=0]; // soroban transaction
6263

6364
// https://github.com/stellar/stellar-core/blob/02d26858069de7c0eefe065056fb0a19bf72ea56/src/xdr/Stellar-transaction.x#L506-L513
6465
enum StellarMemoType {
@@ -85,6 +86,7 @@ message StellarSignTx {
8586
* @next StellarAccountMergeOp
8687
* @next StellarManageDataOp
8788
* @next StellarBumpSequenceOp
89+
* @next StellarInvokeHostFunctionOp
8890
*/
8991
message StellarTxOpRequest {
9092
}
@@ -268,6 +270,44 @@ message StellarBumpSequenceOp {
268270
required uint64 bump_to = 2; // new sequence number
269271
}
270272

273+
/**
274+
* Request: ask device to confirm this operation type
275+
* @next StellarSorobanDataRequest
276+
* @next StellarSignedTx
277+
*/
278+
message StellarInvokeHostFunctionOp {
279+
optional string source_account = 1; // (optional) source account address
280+
required string contract_address = 2; // contract id string
281+
required string function_name = 3; // invoked contract function name (SCSymbol, max 32 bytes)
282+
required uint32 call_args_xdr_size = 4; // the total size of call args xdr
283+
required bytes call_args_xdr_initial_chunk = 5; // invokecontract call args xdr bytes
284+
required uint32 soroban_auth_xdr_size = 6;
285+
required bytes soroban_auth_xdr_initial_chunk = 7; // soroban authorization entries xdr
286+
}
287+
288+
/**
289+
* Response: device is ready for client to send the soroban data
290+
* @next StellarSorobanDataAck
291+
*/
292+
message StellarSorobanDataRequest {
293+
required StellarRequestType type = 1;
294+
required uint32 data_length = 2; // Number of bytes being requested (<= 1024)
295+
296+
enum StellarRequestType {
297+
CALL = 0;
298+
AUTH = 1;
299+
EXT = 2;
300+
}
301+
}
302+
303+
/**
304+
* Request: ask device to confirm
305+
* @next StellarSignedTx
306+
*/
307+
message StellarSorobanDataAck {
308+
required bytes data_chunk_xdr = 1; // the soroban data in xdr format
309+
}
310+
271311
/**
272312
* Response: signature for transaction
273313
* @end

common/protob/messages.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ enum MessageType {
296296
MessageType_StellarManageBuyOfferOp = 222 [(wire_in) = true];
297297
MessageType_StellarPathPaymentStrictSendOp = 223 [(wire_in) = true];
298298
MessageType_StellarSignedTx = 230 [(wire_out) = true];
299+
MessageType_StellarInvokeHostFunctionOp = 260 [(wire_in) = true];
300+
MessageType_StellarSorobanDataRequest = 261 [(wire_out) = true];
301+
MessageType_StellarSorobanDataAck = 262 [(wire_in) = true];
299302

300303
// Cardano
301304
// dropped Sign/VerifyMessage ids 300-302

core/embed/firmware/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define FIX_VERSION_BUILD VERSION_BUILD
1010

1111
#define ONEKEY_VERSION_MAJOR 4
12-
#define ONEKEY_VERSION_MINOR 19
12+
#define ONEKEY_VERSION_MINOR 20
1313
#define ONEKEY_VERSION_PATCH 0
1414
#define ONEKEY_VERSION_BUILD 0
1515

core/src/all_modules.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,8 @@
11291129
import trezor.enums.StellarAssetType
11301130
trezor.enums.StellarMemoType
11311131
import trezor.enums.StellarMemoType
1132+
trezor.enums.StellarRequestType
1133+
import trezor.enums.StellarRequestType
11321134
trezor.enums.StellarSignerType
11331135
import trezor.enums.StellarSignerType
11341136
trezor.enums.TezosBallotType

core/src/apps/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,9 @@ def boot() -> None:
822822
)
823823
workflow_handlers.register(MessageType.UnLockDevice, handle_UnLockDevice)
824824

825-
reload_settings_from_storage()
825+
reload_settings_from_storage(
826+
timeout_ms=10 * 1000 if utils.is_rest_by_usb_lock() else None
827+
)
826828
from trezor.lvglui.scrs import fingerprints
827829

828830
if config.is_unlocked() and fingerprints.is_unlocked():

core/src/apps/cardano/sign_message.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from . import seed
1010
from .addresses import assert_params_cond
11-
from .helpers.paths import SCHEMA_STAKING_ANY_ACCOUNT
1211

1312
if TYPE_CHECKING:
1413
from trezor.wire import Context
@@ -22,7 +21,8 @@ async def sign_message(
2221
from trezor.messages import CardanoMessageSignature, CardanoAddressParametersType
2322
from trezor.enums import CardanoAddressType
2423
from apps.common import paths
25-
from .helpers.paths import SCHEMA_MINT, SCHEMA_PAYMENT
24+
from .helpers.paths import SCHEMA_PAYMENT, SCHEMA_STAKING_ANY_ACCOUNT
25+
2626
from trezor.crypto.curve import ed25519
2727
from trezor import wire
2828
from .helpers import network_ids, protocol_magics
@@ -38,10 +38,10 @@ async def sign_message(
3838
msg.address_n,
3939
True,
4040
# path must match the PUBKEY schema
41-
(SCHEMA_PAYMENT.match(msg.address_n) or SCHEMA_MINT.match(msg.address_n)),
41+
SCHEMA_PAYMENT.match(msg.address_n),
4242
)
43-
if msg.network_id != network_ids.MAINNET:
44-
raise wire.ProcessError("Invalid Networ ID")
43+
if msg.protocol_magic is None and (msg.network_id != network_ids.MAINNET):
44+
raise wire.ProcessError("Invalid Network id, need protocol magic provide")
4545

4646
address_type = msg.address_type if msg.address_type else CardanoAddressType.BASE
4747
address_n = msg.address_n
@@ -70,7 +70,7 @@ async def sign_message(
7070
script_payment_hash=None,
7171
script_staking_hash=None,
7272
),
73-
protocol_magics.MAINNET,
73+
protocol_magics.MAINNET if msg.protocol_magic is None else msg.protocol_magic,
7474
msg.network_id,
7575
)
7676
address = addresses.encode_human_readable(address_bytes)

core/src/apps/ethereum/onekey/sign_typed_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,4 +593,5 @@ async def confirm_domain(ctx: Context, typed_data_envelope: TypedDataEnvelope) -
593593
eip712_domain[member.name] = value
594594
from ..layout import confirm_domain
595595

596-
await confirm_domain(ctx, eip712_domain)
596+
if eip712_domain:
597+
await confirm_domain(ctx, eip712_domain)

core/src/apps/solana/sign_tx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ async def sign_tx(
6767
print(
6868
f"Invalid signer used: {PublicKey(fee_payer.get())} != {PublicKey(signer_pub_key_bytes)}"
6969
)
70-
raise wire.DataError("Invalid signer used")
70+
else:
71+
raise wire.DataError("Invalid signer used")
7172
else:
7273
if PublicKey(signer_pub_key_bytes) not in accounts_keys[:sigs_count]:
7374
raise wire.DataError("Invalid transaction params")

core/src/apps/solana/spl/spl_token_program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ async def parse(ctx: wire.Context, accounts: list[PublicKey], data: bytes) -> No
437437
from ..constents import SPL_TOKEN_PROGRAM_ID
438438

439439
owner_address = None
440-
if hasattr(ctx, "extra"):
440+
if ctx.extra is not None:
441441
owner_address = try_get_token_account_owner_address(
442442
params.dest.get(),
443443
SPL_TOKEN_PROGRAM_ID.get(),

0 commit comments

Comments
 (0)