From d4452ee09eed3a687f753661ce1954fd832c4e09 Mon Sep 17 00:00:00 2001 From: soralit Date: Tue, 24 Dec 2024 16:22:38 +0800 Subject: [PATCH 01/31] chore: organize rust_c features --- rust/CMakeLists.txt | 101 ++++++++++-------- rust/rust_c.cmake | 38 ------- rust/rust_c/Cargo.toml | 76 ++++++++----- .../{release => firmware}/btc_only.toml | 0 .../{release => firmware}/multi_coin.toml | 0 rust/rust_c/src/lib.rs | 40 +++---- 6 files changed, 132 insertions(+), 123 deletions(-) delete mode 100644 rust/rust_c.cmake rename rust/rust_c/cbindgens/{release => firmware}/btc_only.toml (100%) rename rust/rust_c/cbindgens/{release => firmware}/multi_coin.toml (100%) diff --git a/rust/CMakeLists.txt b/rust/CMakeLists.txt index ccc78dbb2..c49171367 100644 --- a/rust/CMakeLists.txt +++ b/rust/CMakeLists.txt @@ -1,51 +1,68 @@ message(STATUS "compile rust") +set(LIB_NAME librust_c.a) -include(rust_c.cmake) +# set variables +find_program(RUST_CARGO_EXECUTABLE cargo) +find_program(BINDGEN_EXE bindgen) +find_program(CBINDGEN_EXE cbindgen) -if(NOT BUILD_TYPE STREQUAL "Simulator") - if(BTC_ONLY) - set(CARGO_FLAG --release --target ${CARGO_ARM_TARGET} -p rust_c --no-default-features --features firmware-btc-only) - else() - set(CARGO_FLAG --release --target ${CARGO_ARM_TARGET} -p rust_c --no-default-features --features firmware) - endif() +# BUILD_ENVIRONMENT: PRODUCTION, DEBUG, SIMULATOR +# BUILD_VARIANT: BTC_ONLY, MULTI_COINS +set(RUST_DIR ${CMAKE_SOURCE_DIR}/rust) +set(RUST_C_DIR ${RUST_DIR}/rust_c) - if(DEFINED DEBUG_MEMORY) - message(STATUS "build with DEBUG_MEMORY") - set(CARGO_FLAG ${CARGO_FLAG} --features debug-memory) - endif() +if(BUILD_ENVIRONMENT STREQUAL "SIMULATOR") + set(FEATURE_ENVIRONMENT "simulator") + set(CBIDGEN_FOLDER "simulator") + set(TARGET_PATH ${CMAKE_SOURCE_DIR}/ui_simulator/lib/rust-builds) +elseif(BUILD_ENVIRONMENT STREQUAL "PRODUCTION") + set(FEATURE_ENVIRONMENT "production") + set(CBIDGEN_FOLDER "firmware") + set(TARGET_PATH ${CMAKE_BINARY_DIR}/rust-builds) + set(CARGO_ARM_TARGET thumbv7em-none-eabihf) +else() + set(FEATURE_ENVIRONMENT "debug") + set(CBIDGEN_FOLDER "firmware") + set(TARGET_PATH ${CMAKE_BINARY_DIR}/rust-builds) + set(CARGO_ARM_TARGET thumbv7em-none-eabihf) +endif() - message(STATUS "cargo build command: " ${CARGO_FLAG}) - message(STATUS ${TARGET_PATH}) +message(STATUS "build target path: " ${TARGET_PATH}) +if(NOT EXISTS ${TARGET_PATH}) + file(MAKE_DIRECTORY ${TARGET_PATH}) +endif() - set(COPY_COMMAND cp ${RUST_DIR}/target/${CARGO_ARM_TARGET}/release/${LIB_NAME} ${TARGET_PATH}) +if(BUILD_VARIANT STREQUAL "BTC_ONLY") + set(FEATURE_VARIANT "btc-only") + set(CBIDGEN_CONFIG_FILE "btc_only.toml") +else() + set(FEATURE_VARIANT "multi-coins") + set(CBIDGEN_CONFIG_FILE "multi_coin.toml") +endif() + +set(FEATURE ${FEATURE_ENVIRONMENT}-${FEATURE_VARIANT}) - add_custom_target(rust_c ALL - COMMAND ${CBINDGEN_EXE} ${CBINDGEN_FLAG} - COMMAND rustup run nightly-2024-01-31 ${RUST_CARGO_EXECUTABLE} build ${CARGO_FLAG} - COMMAND ${COPY_COMMAND} - WORKING_DIRECTORY ${RUST_DIR} - ) +set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/${CBIDGEN_FOLDER}/${CBIDGEN_CONFIG_FILE}) +set(CBINDGEN_FLAG ${RUST_C_DIR} --config ${CBINDGEN_CONFIG_PATH} --output ${TARGET_PATH}/librust_c.h --lang c) + +# compile rust lib +set(CARGO_FLAG --release -p rust_c --no-default-features) +set(CARGO_FLAG ${CARGO_FLAG} --features ${FEATURE}) +if(CARGO_ARM_TARGET) + set(CARGO_FLAG ${CARGO_FLAG} --target ${CARGO_ARM_TARGET}) + set(COPY_COMMAND cp ${RUST_DIR}/target/${CARGO_ARM_TARGET}/release/${LIB_NAME} ${TARGET_PATH}) else() - if(BTC_ONLY) - set(CARGO_FLAG --release -p rust_c --no-default-features --features simulator_btc_only) - else() - set(CARGO_FLAG --release -p rust_c --no-default-features --features simulator) - endif() - - if(DEFINED DEBUG_MEMORY) - message(STATUS "build with DEBUG_MEMORY") - set(CARGO_FLAG ${CARGO_FLAG} --features debug-memory) - endif() - - message(STATUS "Cargo Flags: ${CARGO_FLAG}") - - set(COPY_COMMAND cp ${RUST_DIR}/target/release/${LIB_NAME} ${TARGET_PATH}) - - add_custom_target(rust_c ALL - COMMAND ${CBINDGEN_EXE} ${CBINDGEN_FLAG} - COMMAND rustup run nightly-2024-01-31 ${RUST_CARGO_EXECUTABLE} build ${CARGO_FLAG} - COMMAND ${COPY_COMMAND} - WORKING_DIRECTORY ${RUST_DIR} - ) -endif() \ No newline at end of file + set(COPY_COMMAND cp ${RUST_DIR}/target/release/${LIB_NAME} ${TARGET_PATH}) +endif() + +message(STATUS "cargo build command: " ${CARGO_FLAG}) +#TODO: add debug-momery if need + +#run build +add_custom_target(rust_c ALL + COMMAND ${CBINDGEN_EXE} ${CBINDGEN_FLAG} + COMMAND rustup run nightly-2024-01-31 ${RUST_CARGO_EXECUTABLE} build ${CARGO_FLAG} + COMMAND ${COPY_COMMAND} + WORKING_DIRECTORY ${RUST_DIR} +) diff --git a/rust/rust_c.cmake b/rust/rust_c.cmake deleted file mode 100644 index 0252dd4f5..000000000 --- a/rust/rust_c.cmake +++ /dev/null @@ -1,38 +0,0 @@ -set(LIB_NAME librust_c.a) - -find_program(RUST_CARGO_EXECUTABLE cargo) -find_program(BINDGEN_EXE bindgen) -find_program(CBINDGEN_EXE cbindgen) - -if(NOT BUILD_TYPE STREQUAL "Simulator") - set(TARGET_PATH ${CMAKE_BINARY_DIR}/rust-builds) -else() - set(TARGET_PATH ${CMAKE_SOURCE_DIR}/ui_simulator/lib/rust-builds) -endif() - -message(STATUS "build target path: " ${TARGET_PATH}) - -option(LIB_RUST_C "Set to switch to Compile the RUST_C library" OFF) - -if(NOT EXISTS ${TARGET_PATH}) - file(MAKE_DIRECTORY ${TARGET_PATH}) -endif() - -set(RUST_DIR ${CMAKE_SOURCE_DIR}/rust) -set(RUST_C_DIR ${RUST_DIR}/rust_c) -set(CARGO_ARM_TARGET thumbv7em-none-eabihf) - -if(COMPILE_SIMULATOR) - if(BTC_ONLY) - set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/simulator/btc_only.toml) - else() - set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/simulator/multi_coin.toml) - endif() -else() - if(BTC_ONLY) - set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/release/btc_only.toml) - else() - set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/release/multi_coin.toml) - endif() -endif() -set(CBINDGEN_FLAG ${RUST_C_DIR} --config ${CBINDGEN_CONFIG_PATH} --output ${TARGET_PATH}/librust_c.h --lang c) \ No newline at end of file diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index a33a310d8..9995cf9ca 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -34,16 +34,24 @@ getrandom = { workspace = true, features = ["custom"] } crate-type = ["staticlib"] [features] +# feature toggles use-allocator = [] -firmware = ["use-allocator", "multi-coins"] -firmware-btc-only = ["use-allocator", "btc-only"] -simulator = [ - "multi-coins", - "sui_rust_c/simulator", - "simulator_rust_c/multi-coins", -] -simulator_btc_only = ["btc-only", "simulator_rust_c/btc-only"] -default = ["simulator"] +simulator = [] +aptos = ["dep:aptos_rust_c"] +arweave = ["dep:arweave_rust_c"] +bitcoin = ["dep:bitcoin_rust_c"] +cardano = ["dep:cardano_rust_c"] +cosmos = ["dep:cosmos_rust_c"] +ethereum = ["dep:ethereum_rust_c"] +near = ["dep:near_rust_c"] +solana = ["dep:solana_rust_c"] +stellar = ["dep:stellar_rust_c"] +sui = ["dep:sui_rust_c"] +ton = ["dep:ton_rust_c"] +tron = ["dep:tron_rust_c"] +xrp = ["dep:xrp_rust_c"] +zcash = ["dep:zcash_rust_c"] +test_cmd = ["dep:test_cmd"] debug-memory = [ "multi-coins", @@ -66,29 +74,47 @@ debug-memory = [ multi-coins = [ "common_rust_c/multi-coins", + "bitcoin", "bitcoin_rust_c/multi-coins", "wallet_rust_c/multi-coins", - "test_cmd/multi-coins", - "ethereum_rust_c", - "solana_rust_c", - "aptos_rust_c", - "near_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "ton_rust_c", - "zcash_rust_c" + "ethereum", + "solana", + "aptos", + "near", + "cosmos", + "cardano", + "sui", + "tron", + "xrp", + "arweave", + "stellar", + "ton", + "zcash", ] + btc-only = [ "common_rust_c/btc-only", + "bitcoin", "bitcoin_rust_c/btc-only", "wallet_rust_c/btc-only", - "test_cmd/btc-only", ] -test_feature = [] + +# build variants +# production +production-multi-coins = ["use-allocator", "multi-coins"] +production-btc-only = ["use-allocator", "btc-only"] +# debug +debug-multi-coins = ["test_cmd", "test_cmd/multi-coins", "production-multi-coins"] +debug-btc-only = ["test_cmd", "test_cmd/btc-only", "production-btc-only"] +# simulator +simulator-multi-coins = [ + "simulator", + "multi-coins", + "sui_rust_c/simulator", + "simulator_rust_c/multi-coins", +] +simulator-btc-only = ["simulator", "btc-only", "simulator_rust_c/btc-only"] +default = ["debug-multi-coins"] + [dev-dependencies] keystore = { path = "../keystore" } diff --git a/rust/rust_c/cbindgens/release/btc_only.toml b/rust/rust_c/cbindgens/firmware/btc_only.toml similarity index 100% rename from rust/rust_c/cbindgens/release/btc_only.toml rename to rust/rust_c/cbindgens/firmware/btc_only.toml diff --git a/rust/rust_c/cbindgens/release/multi_coin.toml b/rust/rust_c/cbindgens/firmware/multi_coin.toml similarity index 100% rename from rust/rust_c/cbindgens/release/multi_coin.toml rename to rust/rust_c/cbindgens/firmware/multi_coin.toml diff --git a/rust/rust_c/src/lib.rs b/rust/rust_c/src/lib.rs index f0cd428df..21b9c1d5a 100644 --- a/rust/rust_c/src/lib.rs +++ b/rust/rust_c/src/lib.rs @@ -11,55 +11,59 @@ mod allocator; #[cfg(feature = "use-allocator")] mod my_alloc; -#[allow(unused)] -use bitcoin_rust_c; #[allow(unused)] use common_rust_c; #[allow(unused)] -use test_cmd; -#[allow(unused)] use wallet_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "test_cmd")] +#[allow(unused)] +use test_cmd; + +//chains +#[cfg(feature = "aptos")] #[allow(unused)] use aptos_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "arweave")] #[allow(unused)] use arweave_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "bitcoin")] +#[allow(unused)] +use bitcoin_rust_c; +#[cfg(feature = "cardano")] #[allow(unused)] use cardano_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] #[allow(unused)] use cosmos_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] #[allow(unused)] use ethereum_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "near")] #[allow(unused)] use near_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] #[allow(unused)] use solana_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] #[allow(unused)] use stellar_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] #[allow(unused)] use sui_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ton")] #[allow(unused)] use ton_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "tron")] #[allow(unused)] use tron_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "xrp")] #[allow(unused)] use xrp_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "zcash")] #[allow(unused)] use zcash_rust_c; -#[cfg(any(feature = "simulator", feature = "simulator_btc_only"))] +#[cfg(feature = "simulator")] #[allow(unused)] use simulator_rust_c; From f80cae492e59b5af02cb89521521278324d3df96 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 14:06:52 +0800 Subject: [PATCH 02/31] chore: refactor cbindgen --- rust/rust_c/build.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 rust/rust_c/build.rs diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs new file mode 100644 index 000000000..a5ea27917 --- /dev/null +++ b/rust/rust_c/build.rs @@ -0,0 +1,72 @@ +fn main() { + let mut config = cbindgen::Config::default(); + config.language = cbindgen::Language::C; + let includes = vec![ + "common_rust_c", + "wallet_rust_c", + "btc_only_wallet_rust_c", + "multi_coins_wallet_rust_c", + #[cfg(feature = "aptos")] + "aptos_rust_c", + #[cfg(feature = "simulator")] + "simulator_rust_c", + #[cfg(feature = "arweave")] + "arweave_rust_c", + #[cfg(feature = "bitcoin")] + "bitcoin_rust_c", + #[cfg(feature = "cardano")] + "cardano_rust_c", + #[cfg(feature = "cosmos")] + "cosmos_rust_c", + #[cfg(feature = "ethereum")] + "ethereum_rust_c", + #[cfg(feature = "near")] + "near_rust_c", + #[cfg(feature = "solana")] + "solana_rust_c", + #[cfg(feature = "stellar")] + "stellar_rust_c", + #[cfg(feature = "sui")] + "sui_rust_c", + #[cfg(feature = "ton")] + "ton_rust_c", + #[cfg(feature = "tron")] + "tron_rust_c", + #[cfg(feature = "xrp")] + "xrp_rust_c", + #[cfg(feature = "zcash")] + "zcash_rust_c", + #[cfg(feature = "test_cmd")] + "test_cmd_rust_c", + #[cfg(feature = "test_cmd")] + "btc_test_cmd_rust_c", + #[cfg(feature = "test_cmd")] + "general_test_cmd_rust_c", + ]; + + let crates = includes + .into_iter() + .map(|s| s.to_string()) + .collect::>(); + + config.parse.include = Some(crates.clone()); + config.parse.parse_deps = true; + config.parse.expand.crates = crates; + let features = vec![ + #[cfg(feature = "btc-only")] + "btc_only", + #[cfg(feature = "multi-coins")] + "multi_coins", + ]; + + config.parse.expand.features = Some(features.into_iter().map(|s| s.to_string()).collect()); + + let builder = cbindgen::Builder::new(); + + builder + .with_crate(".") + .with_config(config) + .generate() + .expect("Failed to generate bindings") + .write_to_file("librust_c.h"); +} From 36e6930c23fc2f8f6e576807668034fd01637ab7 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 16:29:29 +0800 Subject: [PATCH 03/31] chore: refactor chain interfaces --- rust/Cargo.lock | 507 ++++++------------ rust/Cargo.toml | 21 - rust/rust_c/Cargo.toml | 140 ++--- rust/rust_c/build.rs | 1 + rust/rust_c/src/aptos/Cargo.toml | 22 - rust/rust_c/src/aptos/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/aptos/{src => }/structs.rs | 0 rust/rust_c/src/arweave/Cargo.toml | 20 - .../rust_c/src/arweave/{src => }/data_item.rs | 2 +- .../rust_c/src/arweave/{src/lib.rs => mod.rs} | 9 +- rust/rust_c/src/arweave/{src => }/structs.rs | 1 - rust/rust_c/src/bitcoin/Cargo.toml | 27 - rust/rust_c/src/bitcoin/{src => }/address.rs | 0 rust/rust_c/src/bitcoin/{src => }/legacy.rs | 2 +- .../rust_c/src/bitcoin/{src/lib.rs => mod.rs} | 5 - rust/rust_c/src/bitcoin/{src => }/msg.rs | 3 +- .../src/bitcoin/{src => }/multi_sig/mod.rs | 2 +- .../bitcoin/{src => }/multi_sig/structs.rs | 0 rust/rust_c/src/bitcoin/{src => }/psbt.rs | 4 +- rust/rust_c/src/bitcoin/{src => }/structs.rs | 0 rust/rust_c/src/cardano/Cargo.toml | 24 - rust/rust_c/src/cardano/{src => }/address.rs | 0 .../rust_c/src/cardano/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/cardano/{src => }/structs.rs | 0 rust/rust_c/src/cosmos/Cargo.toml | 22 - rust/rust_c/src/cosmos/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/cosmos/{src => }/structs.rs | 0 rust/rust_c/src/ethereum/Cargo.toml | 25 - rust/rust_c/src/ethereum/{src => }/abi.rs | 2 +- rust/rust_c/src/ethereum/{src => }/address.rs | 0 .../src/ethereum/{src/lib.rs => mod.rs} | 7 +- rust/rust_c/src/ethereum/{src => }/structs.rs | 2 +- rust/rust_c/src/ethereum/{src => }/util.rs | 0 rust/rust_c/src/lib.rs | 37 +- rust/rust_c/src/near/Cargo.toml | 21 - rust/rust_c/src/near/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/near/{src => }/structs.rs | 0 rust/rust_c/src/simulator/Cargo.toml | 17 - .../src/simulator/{src/lib.rs => mod.rs} | 0 rust/rust_c/src/solana/Cargo.toml | 20 - rust/rust_c/src/solana/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/solana/{src => }/structs.rs | 0 rust/rust_c/src/stellar/Cargo.toml | 16 - .../rust_c/src/stellar/{src/lib.rs => mod.rs} | 5 +- rust/rust_c/src/stellar/{src => }/structs.rs | 0 rust/rust_c/src/sui/Cargo.toml | 21 - rust/rust_c/src/sui/{src/lib.rs => mod.rs} | 7 +- rust/rust_c/src/sui/{src => }/structs.rs | 0 rust/rust_c/src/test_cmd/Cargo.toml | 17 - .../src/lib.rs => btc_test_cmd.rs} | 3 - .../src/lib.rs => general_test_cmd.rs} | 0 rust/rust_c/src/test_cmd/mod.rs | 6 + .../src/test_cmd/src/btc_test_cmd/Cargo.toml | 24 - .../test_cmd/src/general_test_cmd/Cargo.toml | 28 - rust/rust_c/src/test_cmd/src/lib.rs | 12 - rust/rust_c/src/ton/Cargo.toml | 20 - rust/rust_c/src/ton/{src/lib.rs => mod.rs} | 3 - rust/rust_c/src/ton/{src => }/structs.rs | 0 rust/rust_c/src/tron/Cargo.toml | 19 - rust/rust_c/src/tron/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/tron/{src => }/structs.rs | 0 rust/rust_c/src/wallet/Cargo.toml | 16 - .../src/lib.rs => btc_only_wallet.rs} | 4 - rust/rust_c/src/wallet/mod.rs | 4 + .../src => multi_coins_wallet}/aptos.rs | 0 .../src => multi_coins_wallet}/arconnect.rs | 0 .../src => multi_coins_wallet}/backpack.rs | 0 .../src => multi_coins_wallet}/bitget.rs | 0 .../src => multi_coins_wallet}/imtoken.rs | 0 .../src => multi_coins_wallet}/keplr.rs | 2 +- .../src => multi_coins_wallet}/keystone.rs | 0 .../src/lib.rs => multi_coins_wallet/mod.rs} | 5 +- .../src => multi_coins_wallet}/okx.rs | 0 .../src => multi_coins_wallet}/solana.rs | 0 .../src => multi_coins_wallet}/structs.rs | 0 .../src => multi_coins_wallet}/sui.rs | 0 .../src => multi_coins_wallet}/thor_wallet.rs | 4 +- .../src => multi_coins_wallet}/tonkeeper.rs | 0 .../src => multi_coins_wallet}/utils.rs | 0 .../src => multi_coins_wallet}/xbull.rs | 0 .../src => multi_coins_wallet}/xrp_toolkit.rs | 0 .../src => multi_coins_wallet}/zcash.rs | 0 .../src/wallet/src/btc_only_wallet/Cargo.toml | 23 - rust/rust_c/src/wallet/src/lib.rs | 8 - .../wallet/src/multi_coins_wallet/Cargo.toml | 25 - rust/rust_c/src/xrp/Cargo.toml | 22 - rust/rust_c/src/xrp/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/xrp/{src => }/structs.rs | 0 rust/rust_c/src/zcash/Cargo.toml | 20 - rust/rust_c/src/zcash/{src/lib.rs => mod.rs} | 9 +- rust/rust_c/src/zcash/{src => }/structs.rs | 0 91 files changed, 301 insertions(+), 1007 deletions(-) delete mode 100644 rust/rust_c/src/aptos/Cargo.toml rename rust/rust_c/src/aptos/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/aptos/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/arweave/Cargo.toml rename rust/rust_c/src/arweave/{src => }/data_item.rs (96%) rename rust/rust_c/src/arweave/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/arweave/{src => }/structs.rs (99%) delete mode 100644 rust/rust_c/src/bitcoin/Cargo.toml rename rust/rust_c/src/bitcoin/{src => }/address.rs (100%) rename rust/rust_c/src/bitcoin/{src => }/legacy.rs (98%) rename rust/rust_c/src/bitcoin/{src/lib.rs => mod.rs} (59%) rename rust/rust_c/src/bitcoin/{src => }/msg.rs (99%) rename rust/rust_c/src/bitcoin/{src => }/multi_sig/mod.rs (99%) rename rust/rust_c/src/bitcoin/{src => }/multi_sig/structs.rs (100%) rename rust/rust_c/src/bitcoin/{src => }/psbt.rs (99%) rename rust/rust_c/src/bitcoin/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/cardano/Cargo.toml rename rust/rust_c/src/cardano/{src => }/address.rs (100%) rename rust/rust_c/src/cardano/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/cardano/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/cosmos/Cargo.toml rename rust/rust_c/src/cosmos/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/cosmos/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/ethereum/Cargo.toml rename rust/rust_c/src/ethereum/{src => }/abi.rs (97%) rename rust/rust_c/src/ethereum/{src => }/address.rs (100%) rename rust/rust_c/src/ethereum/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/ethereum/{src => }/structs.rs (99%) rename rust/rust_c/src/ethereum/{src => }/util.rs (100%) delete mode 100644 rust/rust_c/src/near/Cargo.toml rename rust/rust_c/src/near/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/near/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/simulator/Cargo.toml rename rust/rust_c/src/simulator/{src/lib.rs => mod.rs} (100%) delete mode 100644 rust/rust_c/src/solana/Cargo.toml rename rust/rust_c/src/solana/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/solana/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/stellar/Cargo.toml rename rust/rust_c/src/stellar/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/stellar/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/sui/Cargo.toml rename rust/rust_c/src/sui/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/sui/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/test_cmd/Cargo.toml rename rust/rust_c/src/test_cmd/{src/btc_test_cmd/src/lib.rs => btc_test_cmd.rs} (99%) rename rust/rust_c/src/test_cmd/{src/general_test_cmd/src/lib.rs => general_test_cmd.rs} (100%) create mode 100644 rust/rust_c/src/test_cmd/mod.rs delete mode 100644 rust/rust_c/src/test_cmd/src/btc_test_cmd/Cargo.toml delete mode 100644 rust/rust_c/src/test_cmd/src/general_test_cmd/Cargo.toml delete mode 100644 rust/rust_c/src/test_cmd/src/lib.rs delete mode 100644 rust/rust_c/src/ton/Cargo.toml rename rust/rust_c/src/ton/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/ton/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/tron/Cargo.toml rename rust/rust_c/src/tron/{src/lib.rs => mod.rs} (97%) rename rust/rust_c/src/tron/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/wallet/Cargo.toml rename rust/rust_c/src/wallet/{src/btc_only_wallet/src/lib.rs => btc_only_wallet.rs} (99%) create mode 100644 rust/rust_c/src/wallet/mod.rs rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/aptos.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/arconnect.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/backpack.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/bitget.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/imtoken.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/keplr.rs (98%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/keystone.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src/lib.rs => multi_coins_wallet/mod.rs} (99%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/okx.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/solana.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/structs.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/sui.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/thor_wallet.rs (97%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/tonkeeper.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/utils.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/xbull.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/xrp_toolkit.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/zcash.rs (100%) delete mode 100644 rust/rust_c/src/wallet/src/btc_only_wallet/Cargo.toml delete mode 100644 rust/rust_c/src/wallet/src/lib.rs delete mode 100644 rust/rust_c/src/wallet/src/multi_coins_wallet/Cargo.toml delete mode 100644 rust/rust_c/src/xrp/Cargo.toml rename rust/rust_c/src/xrp/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/xrp/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/zcash/Cargo.toml rename rust/rust_c/src/zcash/{src/lib.rs => mod.rs} (96%) rename rust/rust_c/src/zcash/{src => }/structs.rs (100%) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 02e8d7a4c..d112b6a8f 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -79,6 +79,55 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +dependencies = [ + "anstyle", + "windows-sys 0.59.0", +] + [[package]] name = "anyhow" version = "1.0.91" @@ -378,23 +427,6 @@ dependencies = [ "zcash_vendor", ] -[[package]] -name = "aptos_rust_c" -version = "0.1.0" -dependencies = [ - "app_aptos", - "app_utils", - "bitcoin", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "arrayref" version = "0.3.9" @@ -407,24 +439,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" -[[package]] -name = "arweave_rust_c" -version = "0.1.0" -dependencies = [ - "app_arweave", - "app_utils", - "bitcoin", - "common_rust_c", - "cryptoxide", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "ascii" version = "1.1.0" @@ -601,24 +615,6 @@ dependencies = [ "hex-conservative", ] -[[package]] -name = "bitcoin_rust_c" -version = "0.1.0" -dependencies = [ - "app_bitcoin", - "app_utils", - "base64 0.11.0", - "bitcoin", - "common_rust_c", - "cryptoxide", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -809,38 +805,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "btc_only_wallet_rust_c" -version = "0.1.0" -dependencies = [ - "app_utils", - "app_wallets", - "bitcoin", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "ur-registry", -] - -[[package]] -name = "btc_test_cmd" -version = "0.1.0" -dependencies = [ - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "ur-parse-lib", - "ur-registry", - "wallet_rust_c", -] - [[package]] name = "bumpalo" version = "3.16.0" @@ -906,24 +870,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "cardano_rust_c" -version = "0.1.0" -dependencies = [ - "app_cardano", - "app_utils", - "bitcoin", - "common_rust_c", - "cstr_core", - "cty", - "ed25519-bip32-core", - "hex", - "itertools 0.13.0", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "cbc" version = "0.1.2" @@ -933,6 +879,25 @@ dependencies = [ "cipher", ] +[[package]] +name = "cbindgen" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fce8dd7fcfcbf3a0a87d8f515194b49d6135acab73e18bd380d1d93bb1a15eb" +dependencies = [ + "clap", + "heck", + "indexmap 2.6.0", + "log", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.85", + "tempfile", + "toml 0.8.19", +] + [[package]] name = "cbor_event" version = "2.4.0" @@ -1007,6 +972,33 @@ dependencies = [ "zeroize", ] +[[package]] +name = "clap" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim 0.11.1", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + [[package]] name = "clear_on_drop" version = "0.2.5" @@ -1067,6 +1059,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "common_rust_c" version = "0.1.0" @@ -1180,22 +1178,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "cosmos_rust_c" -version = "0.1.0" -dependencies = [ - "app_cosmos", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "either", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "cpufeatures" version = "0.2.14" @@ -1596,26 +1578,6 @@ dependencies = [ "uint", ] -[[package]] -name = "ethereum_rust_c" -version = "0.1.0" -dependencies = [ - "app_ethereum", - "app_utils", - "bitcoin", - "common_rust_c", - "core2", - "cryptoxide", - "cstr_core", - "cty", - "hex", - "itertools 0.13.0", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "ethnum" version = "1.5.0" @@ -1872,21 +1834,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "general_test_cmd" -version = "0.1.0" -dependencies = [ - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "ur-registry", - "wallet_rust_c", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -2201,6 +2148,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.10.5" @@ -2501,45 +2454,12 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "multi_coins_wallet_rust_c" -version = "0.1.0" -dependencies = [ - "app_arweave", - "app_utils", - "app_wallets", - "bitcoin", - "common_rust_c", - "cstr_core", - "cty", - "ed25519-bip32-core", - "hex", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "multimap" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "near_rust_c" -version = "0.1.0" -dependencies = [ - "app_near", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "itertools 0.13.0", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "nix" version = "0.26.4" @@ -3017,7 +2937,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ - "toml", + "toml 0.5.11", ] [[package]] @@ -3450,28 +3370,42 @@ dependencies = [ name = "rust_c" version = "0.1.0" dependencies = [ - "aptos_rust_c", - "arweave_rust_c", - "bitcoin_rust_c", - "cardano_rust_c", + "app_aptos", + "app_arweave", + "app_bitcoin", + "app_cardano", + "app_cosmos", + "app_ethereum", + "app_near", + "app_solana", + "app_stellar", + "app_sui", + "app_ton", + "app_tron", + "app_utils", + "app_wallets", + "app_xrp", + "app_zcash", + "base64 0.11.0", + "bitcoin", + "cbindgen", "common_rust_c", - "cosmos_rust_c", + "core2", + "cryptoxide", "cstr_core", "cty", - "ethereum_rust_c", + "ed25519-bip32-core", + "either", "getrandom", + "hex", + "itertools 0.13.0", "keystore", - "near_rust_c", - "simulator_rust_c", - "solana_rust_c", - "stellar_rust_c", - "sui_rust_c", - "test_cmd", - "ton_rust_c", - "tron_rust_c", - "wallet_rust_c", - "xrp_rust_c", - "zcash_rust_c", + "rust_tools", + "serde_json", + "sim_qr_reader", + "ur-parse-lib", + "ur-registry", + "zcash_vendor", ] [[package]] @@ -3727,6 +3661,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + [[package]] name = "serde_with" version = "2.3.3" @@ -3873,16 +3816,6 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" -[[package]] -name = "simulator_rust_c" -version = "0.1.0" -dependencies = [ - "common_rust_c", - "cstr_core", - "cty", - "sim_qr_reader", -] - [[package]] name = "sinsemilla" version = "0.1.0" @@ -3906,21 +3839,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "solana_rust_c" -version = "0.1.0" -dependencies = [ - "app_solana", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "itertools 0.13.0", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "spin" version = "0.9.8" @@ -3952,20 +3870,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stellar_rust_c" -version = "0.1.0" -dependencies = [ - "app_stellar", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "ur-registry", -] - [[package]] name = "strsim" version = "0.10.0" @@ -4057,22 +3961,6 @@ dependencies = [ "thiserror-core", ] -[[package]] -name = "sui_rust_c" -version = "0.1.0" -dependencies = [ - "app_sui", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "syn" version = "1.0.109" @@ -4144,14 +4032,6 @@ dependencies = [ "time", ] -[[package]] -name = "test_cmd" -version = "0.1.0" -dependencies = [ - "btc_test_cmd", - "general_test_cmd", -] - [[package]] name = "thiserror" version = "1.0.65" @@ -4266,11 +4146,26 @@ dependencies = [ "serde", ] +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -4279,25 +4174,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap 2.6.0", + "serde", + "serde_spanned", "toml_datetime", "winnow", ] -[[package]] -name = "ton_rust_c" -version = "0.1.0" -dependencies = [ - "app_ton", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "tracing" version = "0.1.40" @@ -4314,19 +4196,6 @@ version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -[[package]] -name = "tron_rust_c" -version = "0.1.0" -dependencies = [ - "app_tron", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "keystore", - "rust_tools", -] - [[package]] name = "typenum" version = "1.17.0" @@ -4420,6 +4289,12 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "version_check" version = "0.9.5" @@ -4437,14 +4312,6 @@ dependencies = [ "syn 2.0.85", ] -[[package]] -name = "wallet_rust_c" -version = "0.1.0" -dependencies = [ - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -4904,23 +4771,6 @@ dependencies = [ "quick-xml 0.30.0", ] -[[package]] -name = "xrp_rust_c" -version = "0.1.0" -dependencies = [ - "app_utils", - "app_xrp", - "bitcoin", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "zcash_address" version = "0.6.2" @@ -4990,21 +4840,6 @@ dependencies = [ "hex", ] -[[package]] -name = "zcash_rust_c" -version = "0.1.0" -dependencies = [ - "app_utils", - "app_zcash", - "common_rust_c", - "cstr_core", - "cty", - "keystore", - "rust_tools", - "ur-registry", - "zcash_vendor", -] - [[package]] name = "zcash_spec" version = "0.1.2" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 2db60a2e5..a44dca30d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -22,28 +22,7 @@ members = [ # C interface entry "rust_c", # rust_c libs - "rust_c/src/aptos", - "rust_c/src/arweave", - "rust_c/src/bitcoin", - "rust_c/src/cardano", "rust_c/src/common", - "rust_c/src/cosmos", - "rust_c/src/ethereum", - # "rust_c/src/kt_allocator", - "rust_c/src/near", - "rust_c/src/simulator", - "rust_c/src/solana", - "rust_c/src/stellar", - "rust_c/src/sui", - "rust_c/src/ton", - "rust_c/src/tron", - "rust_c/src/wallet", - "rust_c/src/xrp", - "rust_c/src/zcash", - - "rust_c/src/test_cmd", - "rust_c/src/test_cmd/src/btc_test_cmd", - "rust_c/src/test_cmd/src/general_test_cmd", # other "keystore", diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index 9995cf9ca..9eb10c19f 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -7,28 +7,54 @@ edition = "2021" [dependencies] common_rust_c = { path = "./src/common", optional = true, default-features = false } -bitcoin_rust_c = { path = "./src/bitcoin", default-features = false, optional = true } -wallet_rust_c = { path = "./src/wallet", default-features = false, optional = true } -test_cmd = { path = "./src/test_cmd", default-features = false, optional = true } -simulator_rust_c = { path = "./src/simulator", optional = true, default-features = false } - -ethereum_rust_c = { path = "./src/ethereum", optional = true } -solana_rust_c = { path = "./src/solana", optional = true } -aptos_rust_c = { path = "./src/aptos", optional = true } -near_rust_c = { path = "./src/near", optional = true } -cosmos_rust_c = { path = "./src/cosmos", optional = true } -cardano_rust_c = { path = "./src/cardano", optional = true } -sui_rust_c = { path = "./src/sui", optional = true } -tron_rust_c = { path = "./src/tron", optional = true } -xrp_rust_c = { path = "./src/xrp", optional = true } -arweave_rust_c = { path = "./src/arweave", optional = true } -stellar_rust_c = { path = "./src/stellar", optional = true } -ton_rust_c = { path = "./src/ton", optional = true } -zcash_rust_c = { path = "./src/zcash", optional = true } + cty = { workspace = true } cstr_core = { workspace = true } getrandom = { workspace = true, features = ["custom"] } +keystore = { workspace = true } +app_aptos = { workspace = true } +app_utils = { workspace = true } +rust_tools = { workspace = true } +serde_json = { workspace = true } +hex = { workspace = true } +bitcoin = { workspace = true } +ur-registry = { workspace = true } +app_arweave = { workspace = true } +cryptoxide = { workspace = true } +app_bitcoin = { workspace = true } +base64 = { workspace = true } +app_cardano = { workspace = true } +itertools = { workspace = true } +ed25519-bip32-core = { workspace = true } + +app_cosmos = { workspace = true, default-features = false } +either = { workspace = true } + +app_ethereum = { workspace = true } +core2 = { workspace = true } + +app_solana = { workspace = true } + +app_near = { workspace = true } + +app_sui = { workspace = true } + +app_stellar = { workspace = true } + +app_ton = { workspace = true } + +app_tron = { workspace = true } + +app_wallets = { workspace = true } + +ur-parse-lib = { workspace = true } + +app_xrp = { workspace = true } + +app_zcash = { workspace = true } +zcash_vendor = { workspace = true } +sim_qr_reader = { workspace = true } [lib] crate-type = ["staticlib"] @@ -37,46 +63,27 @@ crate-type = ["staticlib"] # feature toggles use-allocator = [] simulator = [] -aptos = ["dep:aptos_rust_c"] -arweave = ["dep:arweave_rust_c"] -bitcoin = ["dep:bitcoin_rust_c"] -cardano = ["dep:cardano_rust_c"] -cosmos = ["dep:cosmos_rust_c"] -ethereum = ["dep:ethereum_rust_c"] -near = ["dep:near_rust_c"] -solana = ["dep:solana_rust_c"] -stellar = ["dep:stellar_rust_c"] -sui = ["dep:sui_rust_c"] -ton = ["dep:ton_rust_c"] -tron = ["dep:tron_rust_c"] -xrp = ["dep:xrp_rust_c"] -zcash = ["dep:zcash_rust_c"] -test_cmd = ["dep:test_cmd"] - -debug-memory = [ - "multi-coins", - "common_rust_c/debug-memory", - "ethereum_rust_c/debug-memory", - "bitcoin_rust_c/debug-memory", - "wallet_rust_c/debug-memory", - "test_cmd/debug-memory", - "solana_rust_c/debug-memory", - "aptos_rust_c/debug-memory", - "near_rust_c/debug-memory", - "cosmos_rust_c/debug-memory", - "cardano_rust_c/debug-memory", - "sui_rust_c/debug-memory", - "tron_rust_c/debug-memory", - "xrp_rust_c/debug-memory", - "ton_rust_c/debug-memory", - "zcash_rust_c/debug-memory", -] +aptos = [] +arweave = [] +bitcoin = [] +cardano = [] +cosmos = [] +ethereum = [] +near = [] +solana = [] +stellar = [] +sui = [] +ton = [] +tron = [] +xrp = [] +zcash = [] +test_cmd = [] + +debug-memory = ["multi-coins", "common_rust_c/debug-memory"] multi-coins = [ "common_rust_c/multi-coins", "bitcoin", - "bitcoin_rust_c/multi-coins", - "wallet_rust_c/multi-coins", "ethereum", "solana", "aptos", @@ -92,29 +99,22 @@ multi-coins = [ "zcash", ] -btc-only = [ - "common_rust_c/btc-only", - "bitcoin", - "bitcoin_rust_c/btc-only", - "wallet_rust_c/btc-only", -] +btc-only = ["common_rust_c/btc-only", "bitcoin"] # build variants # production production-multi-coins = ["use-allocator", "multi-coins"] production-btc-only = ["use-allocator", "btc-only"] # debug -debug-multi-coins = ["test_cmd", "test_cmd/multi-coins", "production-multi-coins"] -debug-btc-only = ["test_cmd", "test_cmd/btc-only", "production-btc-only"] +debug-multi-coins = ["test_cmd", "production-multi-coins"] +debug-btc-only = ["test_cmd", "production-btc-only"] # simulator -simulator-multi-coins = [ - "simulator", - "multi-coins", - "sui_rust_c/simulator", - "simulator_rust_c/multi-coins", -] -simulator-btc-only = ["simulator", "btc-only", "simulator_rust_c/btc-only"] -default = ["debug-multi-coins"] +simulator-multi-coins = ["simulator", "multi-coins"] +simulator-btc-only = ["simulator", "btc-only"] +default = ["simulator-multi-coins"] [dev-dependencies] keystore = { path = "../keystore" } + +[build-dependencies] +cbindgen = "0.27.0" diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index a5ea27917..3f3060fae 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -1,4 +1,5 @@ fn main() { + return; let mut config = cbindgen::Config::default(); config.language = cbindgen::Language::C; let includes = vec![ diff --git a/rust/rust_c/src/aptos/Cargo.toml b/rust/rust_c/src/aptos/Cargo.toml deleted file mode 100644 index f0322cc47..000000000 --- a/rust/rust_c/src/aptos/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "aptos_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_aptos = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -common_rust_c = { path = "../common" } -serde_json = { workspace = true } -hex = { workspace = true } -bitcoin = { workspace = true } -ur-registry = { workspace = true } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/aptos/src/lib.rs b/rust/rust_c/src/aptos/mod.rs similarity index 98% rename from rust/rust_c/src/aptos/src/lib.rs rename to rust/rust_c/src/aptos/mod.rs index 217b74570..2f53993a4 100644 --- a/rust/rust_c/src/aptos/src/lib.rs +++ b/rust/rust_c/src/aptos/mod.rs @@ -1,8 +1,4 @@ -#![no_std] - -extern crate alloc; - -use crate::structs::DisplayAptosTx; +use structs::DisplayAptosTx; use alloc::format; use alloc::slice; use alloc::string::ToString; diff --git a/rust/rust_c/src/aptos/src/structs.rs b/rust/rust_c/src/aptos/structs.rs similarity index 100% rename from rust/rust_c/src/aptos/src/structs.rs rename to rust/rust_c/src/aptos/structs.rs diff --git a/rust/rust_c/src/arweave/Cargo.toml b/rust/rust_c/src/arweave/Cargo.toml deleted file mode 100644 index 8face4943..000000000 --- a/rust/rust_c/src/arweave/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "arweave_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_utils = { workspace = true } -app_arweave = { workspace = true } -rust_tools = { workspace = true } -common_rust_c = { path = "../common" } -cty = { workspace = true } -cstr_core = { workspace = true } -serde_json = { workspace = true } -hex = { workspace = true } -bitcoin = { workspace = true } -ur-registry = { workspace = true } -cryptoxide = { workspace = true } diff --git a/rust/rust_c/src/arweave/src/data_item.rs b/rust/rust_c/src/arweave/data_item.rs similarity index 96% rename from rust/rust_c/src/arweave/src/data_item.rs rename to rust/rust_c/src/arweave/data_item.rs index 25a3cc4d6..80ebe5a8b 100644 --- a/rust/rust_c/src/arweave/src/data_item.rs +++ b/rust/rust_c/src/arweave/data_item.rs @@ -6,7 +6,7 @@ use common_rust_c::{ }; use ur_registry::arweave::arweave_sign_request::ArweaveSignRequest; -use crate::structs::{DisplayArweaveAOTransfer, DisplayArweaveDataItem}; +use super::structs::{DisplayArweaveAOTransfer, DisplayArweaveDataItem}; #[no_mangle] pub extern "C" fn ar_is_ao_transfer(ptr: PtrUR) -> bool { diff --git a/rust/rust_c/src/arweave/src/lib.rs b/rust/rust_c/src/arweave/mod.rs similarity index 99% rename from rust/rust_c/src/arweave/src/lib.rs rename to rust/rust_c/src/arweave/mod.rs index b04a30c32..74903381f 100644 --- a/rust/rust_c/src/arweave/src/lib.rs +++ b/rust/rust_c/src/arweave/mod.rs @@ -1,8 +1,7 @@ -#![no_std] - -extern crate alloc; +pub mod structs; +pub mod data_item; -use crate::structs::{ArweaveRequestType, DisplayArweaveMessage, DisplayArweaveTx}; +use structs::{ArweaveRequestType, DisplayArweaveMessage, DisplayArweaveTx}; use alloc::boxed::Box; use alloc::slice; @@ -29,8 +28,6 @@ use ur_registry::arweave::arweave_sign_request::{ArweaveSignRequest, SaltLen, Si use ur_registry::arweave::arweave_signature::ArweaveSignature; use ur_registry::traits::RegistryItem; -pub mod data_item; -pub mod structs; fn generate_aes_key_iv(seed: &[u8]) -> ([u8; 32], [u8; 16]) { // The number 1557192335 is derived from the ASCII representation of "keystone" hashed with SHA-256, taking the first 32 bits with the highest bit set to 0. diff --git a/rust/rust_c/src/arweave/src/structs.rs b/rust/rust_c/src/arweave/structs.rs similarity index 99% rename from rust/rust_c/src/arweave/src/structs.rs rename to rust/rust_c/src/arweave/structs.rs index 963b515bd..1fc2be1d6 100644 --- a/rust/rust_c/src/arweave/src/structs.rs +++ b/rust/rust_c/src/arweave/structs.rs @@ -1,5 +1,4 @@ use core::ptr::null_mut; - use alloc::vec::Vec; use app_arweave::{ ao_transaction::AOTransferTransaction, diff --git a/rust/rust_c/src/bitcoin/Cargo.toml b/rust/rust_c/src/bitcoin/Cargo.toml deleted file mode 100644 index 902c85444..000000000 --- a/rust/rust_c/src/bitcoin/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "bitcoin_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_bitcoin = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -base64 = { workspace = true } -ur-registry = { workspace = true } -bitcoin = { workspace = true } -cryptoxide = { workspace = true } -hex = { workspace = true } - -common_rust_c = { path = "../common" } - -[features] -debug-memory = ["default"] -default = ["multi-coins"] -multi-coins = ["common_rust_c/multi-coins"] -btc-only = ["common_rust_c/btc-only"] diff --git a/rust/rust_c/src/bitcoin/src/address.rs b/rust/rust_c/src/bitcoin/address.rs similarity index 100% rename from rust/rust_c/src/bitcoin/src/address.rs rename to rust/rust_c/src/bitcoin/address.rs diff --git a/rust/rust_c/src/bitcoin/src/legacy.rs b/rust/rust_c/src/bitcoin/legacy.rs similarity index 98% rename from rust/rust_c/src/bitcoin/src/legacy.rs rename to rust/rust_c/src/bitcoin/legacy.rs index dcf0a0e6b..1979b16c7 100644 --- a/rust/rust_c/src/bitcoin/src/legacy.rs +++ b/rust/rust_c/src/bitcoin/legacy.rs @@ -1,4 +1,4 @@ -use crate::structs::DisplayTx; +use super::structs::DisplayTx; use alloc::boxed::Box; use alloc::slice; use common_rust_c::errors::RustCError; diff --git a/rust/rust_c/src/bitcoin/src/lib.rs b/rust/rust_c/src/bitcoin/mod.rs similarity index 59% rename from rust/rust_c/src/bitcoin/src/lib.rs rename to rust/rust_c/src/bitcoin/mod.rs index 102dfdb3b..1221afdff 100644 --- a/rust/rust_c/src/bitcoin/src/lib.rs +++ b/rust/rust_c/src/bitcoin/mod.rs @@ -1,8 +1,3 @@ -#![no_std] -#![feature(vec_into_raw_parts)] - -extern crate alloc; - pub mod address; pub mod legacy; pub mod msg; diff --git a/rust/rust_c/src/bitcoin/src/msg.rs b/rust/rust_c/src/bitcoin/msg.rs similarity index 99% rename from rust/rust_c/src/bitcoin/src/msg.rs rename to rust/rust_c/src/bitcoin/msg.rs index 53934386c..0a1e62fbf 100644 --- a/rust/rust_c/src/bitcoin/src/msg.rs +++ b/rust/rust_c/src/bitcoin/msg.rs @@ -1,6 +1,5 @@ use core::ptr::null_mut; - -use crate::structs::DisplayBtcMsg; +use super::structs::DisplayBtcMsg; use alloc::{ slice, string::{String, ToString}, diff --git a/rust/rust_c/src/bitcoin/src/multi_sig/mod.rs b/rust/rust_c/src/bitcoin/multi_sig/mod.rs similarity index 99% rename from rust/rust_c/src/bitcoin/src/multi_sig/mod.rs rename to rust/rust_c/src/bitcoin/multi_sig/mod.rs index 3f1d7aae7..e5ecf3be0 100644 --- a/rust/rust_c/src/bitcoin/src/multi_sig/mod.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/mod.rs @@ -29,7 +29,7 @@ use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; use common_rust_c::ur::{UREncodeResult, ViewType, FRAGMENT_MAX_LENGTH_DEFAULT}; use common_rust_c::utils::{convert_c_char, recover_c_array, recover_c_char}; -use crate::multi_sig::structs::{MultiSigWallet, NetworkType}; +use structs::{MultiSigWallet, NetworkType}; use common_rust_c::extract_ptr_with_type; use ur_registry::crypto_account::CryptoAccount; diff --git a/rust/rust_c/src/bitcoin/src/multi_sig/structs.rs b/rust/rust_c/src/bitcoin/multi_sig/structs.rs similarity index 100% rename from rust/rust_c/src/bitcoin/src/multi_sig/structs.rs rename to rust/rust_c/src/bitcoin/multi_sig/structs.rs diff --git a/rust/rust_c/src/bitcoin/src/psbt.rs b/rust/rust_c/src/bitcoin/psbt.rs similarity index 99% rename from rust/rust_c/src/bitcoin/src/psbt.rs rename to rust/rust_c/src/bitcoin/psbt.rs index 1e3f0faa6..1a8410495 100644 --- a/rust/rust_c/src/bitcoin/src/psbt.rs +++ b/rust/rust_c/src/bitcoin/psbt.rs @@ -23,8 +23,8 @@ use hex; use ur_registry::crypto_psbt::CryptoPSBT; use ur_registry::traits::RegistryItem; -use crate::multi_sig::structs::MultisigSignResult; -use crate::structs::DisplayTx; +use super::multi_sig::structs::MultisigSignResult; +use super::structs::DisplayTx; #[no_mangle] pub extern "C" fn btc_parse_psbt( diff --git a/rust/rust_c/src/bitcoin/src/structs.rs b/rust/rust_c/src/bitcoin/structs.rs similarity index 100% rename from rust/rust_c/src/bitcoin/src/structs.rs rename to rust/rust_c/src/bitcoin/structs.rs diff --git a/rust/rust_c/src/cardano/Cargo.toml b/rust/rust_c/src/cardano/Cargo.toml deleted file mode 100644 index 95fe47c17..000000000 --- a/rust/rust_c/src/cardano/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "cardano_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true} -app_cardano = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -itertools = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } -bitcoin = { workspace = true } -ed25519-bip32-core = { workspace = true } - -common_rust_c = { path = "../common" } - -[features] -debug-memory = [] \ No newline at end of file diff --git a/rust/rust_c/src/cardano/src/address.rs b/rust/rust_c/src/cardano/address.rs similarity index 100% rename from rust/rust_c/src/cardano/src/address.rs rename to rust/rust_c/src/cardano/address.rs diff --git a/rust/rust_c/src/cardano/src/lib.rs b/rust/rust_c/src/cardano/mod.rs similarity index 99% rename from rust/rust_c/src/cardano/src/lib.rs rename to rust/rust_c/src/cardano/mod.rs index 85f15025a..7e7a38f37 100644 --- a/rust/rust_c/src/cardano/src/lib.rs +++ b/rust/rust_c/src/cardano/mod.rs @@ -1,7 +1,3 @@ -#![no_std] - -extern crate alloc; - use alloc::{format, slice}; use alloc::{ string::{String, ToString}, @@ -30,7 +26,7 @@ use ur_registry::cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest use ur_registry::cardano::cardano_signature::CardanoSignature; use ur_registry::crypto_key_path::CryptoKeyPath; -use crate::structs::{DisplayCardanoCatalyst, DisplayCardanoSignData, DisplayCardanoTx}; +use structs::{DisplayCardanoCatalyst, DisplayCardanoSignData, DisplayCardanoTx}; use common_rust_c::errors::{RustCError, R}; use common_rust_c::extract_ptr_with_type; use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; diff --git a/rust/rust_c/src/cardano/src/structs.rs b/rust/rust_c/src/cardano/structs.rs similarity index 100% rename from rust/rust_c/src/cardano/src/structs.rs rename to rust/rust_c/src/cardano/structs.rs diff --git a/rust/rust_c/src/cosmos/Cargo.toml b/rust/rust_c/src/cosmos/Cargo.toml deleted file mode 100644 index b67ab6549..000000000 --- a/rust/rust_c/src/cosmos/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "cosmos_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_cosmos = { workspace = true, default-features = false } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -either = { workspace = true } -serde_json = { workspace = true } -ur-registry = { workspace = true } - -common_rust_c = { path = "../common" } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/cosmos/src/lib.rs b/rust/rust_c/src/cosmos/mod.rs similarity index 99% rename from rust/rust_c/src/cosmos/src/lib.rs rename to rust/rust_c/src/cosmos/mod.rs index 0686fc684..9306d783f 100644 --- a/rust/rust_c/src/cosmos/src/lib.rs +++ b/rust/rust_c/src/cosmos/mod.rs @@ -1,10 +1,6 @@ -#![no_std] - -extern crate alloc; - pub mod structs; -use crate::structs::DisplayCosmosTx; +use structs::DisplayCosmosTx; use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; diff --git a/rust/rust_c/src/cosmos/src/structs.rs b/rust/rust_c/src/cosmos/structs.rs similarity index 100% rename from rust/rust_c/src/cosmos/src/structs.rs rename to rust/rust_c/src/cosmos/structs.rs diff --git a/rust/rust_c/src/ethereum/Cargo.toml b/rust/rust_c/src/ethereum/Cargo.toml deleted file mode 100644 index e803d2db3..000000000 --- a/rust/rust_c/src/ethereum/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "ethereum_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true, default-features = false } -app_ethereum = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -itertools = { workspace = true } -hex = { workspace = true } -serde_json = { workspace = true } -ur-registry = { workspace = true } -core2 = { workspace = true } -cryptoxide = { workspace = true } -bitcoin = { workspace = true } -common_rust_c = { path = "../common" } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/ethereum/src/abi.rs b/rust/rust_c/src/ethereum/abi.rs similarity index 97% rename from rust/rust_c/src/ethereum/src/abi.rs rename to rust/rust_c/src/ethereum/abi.rs index 2311ad2d1..223ff412b 100644 --- a/rust/rust_c/src/ethereum/src/abi.rs +++ b/rust/rust_c/src/ethereum/abi.rs @@ -1,4 +1,4 @@ -use crate::structs::DisplayContractData; +use super::structs::DisplayContractData; use common_rust_c::errors::RustCError; use common_rust_c::structs::Response; use common_rust_c::types::{Ptr, PtrString}; diff --git a/rust/rust_c/src/ethereum/src/address.rs b/rust/rust_c/src/ethereum/address.rs similarity index 100% rename from rust/rust_c/src/ethereum/src/address.rs rename to rust/rust_c/src/ethereum/address.rs diff --git a/rust/rust_c/src/ethereum/src/lib.rs b/rust/rust_c/src/ethereum/mod.rs similarity index 99% rename from rust/rust_c/src/ethereum/src/lib.rs rename to rust/rust_c/src/ethereum/mod.rs index 66fa99f6f..99aa9d2f0 100644 --- a/rust/rust_c/src/ethereum/src/lib.rs +++ b/rust/rust_c/src/ethereum/mod.rs @@ -1,6 +1,3 @@ -#![no_std] -extern crate alloc; - use alloc::string::{String, ToString}; use alloc::vec::Vec; use alloc::{format, slice}; @@ -33,7 +30,7 @@ use common_rust_c::ur::{ use common_rust_c::utils::{convert_c_char, recover_c_char}; use common_rust_c::{extract_ptr_with_type, KEYSTONE}; -use crate::structs::{ +use structs::{ DisplayETH, DisplayETHPersonalMessage, DisplayETHTypedData, EthParsedErc20Transaction, TransactionType, }; @@ -41,7 +38,7 @@ use crate::structs::{ mod abi; pub mod address; pub mod structs; -mod util; +pub(crate) mod util; #[no_mangle] pub extern "C" fn eth_check_ur_bytes( diff --git a/rust/rust_c/src/ethereum/src/structs.rs b/rust/rust_c/src/ethereum/structs.rs similarity index 99% rename from rust/rust_c/src/ethereum/src/structs.rs rename to rust/rust_c/src/ethereum/structs.rs index 9cd768a30..c2d7f7667 100644 --- a/rust/rust_c/src/ethereum/src/structs.rs +++ b/rust/rust_c/src/ethereum/structs.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] use alloc::boxed::Box; -use crate::util::{calculate_max_txn_fee, convert_wei_to_eth}; +use super::util::{calculate_max_txn_fee, convert_wei_to_eth}; use alloc::string::{String, ToString}; use alloc::vec::Vec; use app_ethereum::abi::{ContractData, ContractMethodParam}; diff --git a/rust/rust_c/src/ethereum/src/util.rs b/rust/rust_c/src/ethereum/util.rs similarity index 100% rename from rust/rust_c/src/ethereum/src/util.rs rename to rust/rust_c/src/ethereum/util.rs diff --git a/rust/rust_c/src/lib.rs b/rust/rust_c/src/lib.rs index 21b9c1d5a..b066d5ecb 100644 --- a/rust/rust_c/src/lib.rs +++ b/rust/rust_c/src/lib.rs @@ -1,6 +1,7 @@ +#![feature(vec_into_raw_parts)] #![cfg_attr(feature = "use-allocator", no_std)] #![cfg_attr(feature = "use-allocator", feature(alloc_error_handler))] -#[cfg(feature = "use-allocator")] + extern crate alloc; mod bindings; @@ -14,56 +15,56 @@ mod my_alloc; #[allow(unused)] use common_rust_c; #[allow(unused)] -use wallet_rust_c; +mod wallet; #[cfg(feature = "test_cmd")] #[allow(unused)] -use test_cmd; +mod test_cmd; //chains #[cfg(feature = "aptos")] #[allow(unused)] -use aptos_rust_c; +mod aptos; #[cfg(feature = "arweave")] #[allow(unused)] -use arweave_rust_c; +mod arweave; #[cfg(feature = "bitcoin")] #[allow(unused)] -use bitcoin_rust_c; +mod bitcoin; #[cfg(feature = "cardano")] #[allow(unused)] -use cardano_rust_c; +mod cardano; #[cfg(feature = "cosmos")] #[allow(unused)] -use cosmos_rust_c; +mod cosmos; #[cfg(feature = "ethereum")] #[allow(unused)] -use ethereum_rust_c; +mod ethereum; #[cfg(feature = "near")] #[allow(unused)] -use near_rust_c; +mod near; #[cfg(feature = "solana")] #[allow(unused)] -use solana_rust_c; +mod solana; #[cfg(feature = "stellar")] #[allow(unused)] -use stellar_rust_c; +mod stellar; #[cfg(feature = "sui")] #[allow(unused)] -use sui_rust_c; +mod sui; #[cfg(feature = "ton")] #[allow(unused)] -use ton_rust_c; +mod ton; #[cfg(feature = "tron")] #[allow(unused)] -use tron_rust_c; +mod tron; #[cfg(feature = "xrp")] #[allow(unused)] -use xrp_rust_c; +mod xrp; #[cfg(feature = "zcash")] #[allow(unused)] -use zcash_rust_c; +mod zcash; #[cfg(feature = "simulator")] #[allow(unused)] -use simulator_rust_c; +mod simulator; diff --git a/rust/rust_c/src/near/Cargo.toml b/rust/rust_c/src/near/Cargo.toml deleted file mode 100644 index 116eef054..000000000 --- a/rust/rust_c/src/near/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "near_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true, default-features = false } -app_near = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -itertools = { workspace = true } -ur-registry = { workspace = true } - -common_rust_c = { path = "../common" } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/near/src/lib.rs b/rust/rust_c/src/near/mod.rs similarity index 98% rename from rust/rust_c/src/near/src/lib.rs rename to rust/rust_c/src/near/mod.rs index c1a63651f..6c63b7f65 100644 --- a/rust/rust_c/src/near/src/lib.rs +++ b/rust/rust_c/src/near/mod.rs @@ -1,8 +1,4 @@ -#![no_std] - -extern crate alloc; - -use crate::structs::DisplayNearTx; +use structs::DisplayNearTx; use alloc::string::ToString; use alloc::{format, vec}; use app_near::errors::NearError; diff --git a/rust/rust_c/src/near/src/structs.rs b/rust/rust_c/src/near/structs.rs similarity index 100% rename from rust/rust_c/src/near/src/structs.rs rename to rust/rust_c/src/near/structs.rs diff --git a/rust/rust_c/src/simulator/Cargo.toml b/rust/rust_c/src/simulator/Cargo.toml deleted file mode 100644 index 82d17e1ac..000000000 --- a/rust/rust_c/src/simulator/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "simulator_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -sim_qr_reader = { workspace = true } -cty = "0.2.2" -cstr_core = "0.2.6" -common_rust_c = { path = "../common", default-features = false } - -[features] -multi-coins = ["common_rust_c/multi-coins"] -btc-only = ["common_rust_c/btc-only"] -default = ["multi-coins"] \ No newline at end of file diff --git a/rust/rust_c/src/simulator/src/lib.rs b/rust/rust_c/src/simulator/mod.rs similarity index 100% rename from rust/rust_c/src/simulator/src/lib.rs rename to rust/rust_c/src/simulator/mod.rs diff --git a/rust/rust_c/src/solana/Cargo.toml b/rust/rust_c/src/solana/Cargo.toml deleted file mode 100644 index b32f5d2a7..000000000 --- a/rust/rust_c/src/solana/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "solana_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true, default-features = false } -app_solana = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -itertools = { workspace = true } -common_rust_c = { path = "../common" } -ur-registry = { workspace = true } -app_utils = { workspace = true } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/solana/src/lib.rs b/rust/rust_c/src/solana/mod.rs similarity index 98% rename from rust/rust_c/src/solana/src/lib.rs rename to rust/rust_c/src/solana/mod.rs index d18f61d15..7ea96109c 100644 --- a/rust/rust_c/src/solana/src/lib.rs +++ b/rust/rust_c/src/solana/mod.rs @@ -1,8 +1,4 @@ -#![no_std] - -extern crate alloc; - -use crate::structs::{DisplaySolanaMessage, DisplaySolanaTx}; +use structs::{DisplaySolanaMessage, DisplaySolanaTx}; use alloc::format; use alloc::string::ToString; use app_solana::errors::SolanaError; diff --git a/rust/rust_c/src/solana/src/structs.rs b/rust/rust_c/src/solana/structs.rs similarity index 100% rename from rust/rust_c/src/solana/src/structs.rs rename to rust/rust_c/src/solana/structs.rs diff --git a/rust/rust_c/src/stellar/Cargo.toml b/rust/rust_c/src/stellar/Cargo.toml deleted file mode 100644 index 40272beba..000000000 --- a/rust/rust_c/src/stellar/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "stellar_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_utils = { workspace = true } -app_stellar = { workspace = true } -common_rust_c = { path = "../common" } -cty = { workspace = true } -cstr_core = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } diff --git a/rust/rust_c/src/stellar/src/lib.rs b/rust/rust_c/src/stellar/mod.rs similarity index 98% rename from rust/rust_c/src/stellar/src/lib.rs rename to rust/rust_c/src/stellar/mod.rs index d2910a0f4..f8688edfd 100644 --- a/rust/rust_c/src/stellar/src/lib.rs +++ b/rust/rust_c/src/stellar/mod.rs @@ -1,13 +1,10 @@ -#![no_std] - -extern crate alloc; use alloc::borrow::ToOwned; use alloc::boxed::Box; use alloc::slice; use alloc::string::ToString; use cty::c_char; -use crate::structs::DisplayStellarTx; +use structs::DisplayStellarTx; use app_stellar::strkeys::{sign_hash, sign_signature_base}; use app_stellar::{address::get_address, base_to_xdr}; use common_rust_c::errors::RustCError; diff --git a/rust/rust_c/src/stellar/src/structs.rs b/rust/rust_c/src/stellar/structs.rs similarity index 100% rename from rust/rust_c/src/stellar/src/structs.rs rename to rust/rust_c/src/stellar/structs.rs diff --git a/rust/rust_c/src/sui/Cargo.toml b/rust/rust_c/src/sui/Cargo.toml deleted file mode 100644 index 3723fbc50..000000000 --- a/rust/rust_c/src/sui/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "sui_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_sui = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -serde_json = { workspace = true } -ur-registry = { workspace = true } -common_rust_c = { path = "../common" } -hex = { workspace = true } -[features] -debug-memory = [] -simulator = ["app_sui/simulator"] diff --git a/rust/rust_c/src/sui/src/lib.rs b/rust/rust_c/src/sui/mod.rs similarity index 98% rename from rust/rust_c/src/sui/src/lib.rs rename to rust/rust_c/src/sui/mod.rs index 5d33ce61c..cec7ad788 100644 --- a/rust/rust_c/src/sui/src/lib.rs +++ b/rust/rust_c/src/sui/mod.rs @@ -1,7 +1,3 @@ -#![no_std] - -extern crate alloc; - use alloc::string::{String, ToString}; use alloc::vec::Vec; use alloc::{format, vec}; @@ -22,8 +18,7 @@ use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use common_rust_c::utils::{convert_c_char, recover_c_char}; use structs::DisplaySuiSignMessageHash; - -use crate::structs::DisplaySuiIntentMessage; +use structs::DisplaySuiIntentMessage; pub mod structs; diff --git a/rust/rust_c/src/sui/src/structs.rs b/rust/rust_c/src/sui/structs.rs similarity index 100% rename from rust/rust_c/src/sui/src/structs.rs rename to rust/rust_c/src/sui/structs.rs diff --git a/rust/rust_c/src/test_cmd/Cargo.toml b/rust/rust_c/src/test_cmd/Cargo.toml deleted file mode 100644 index a42e0eaa9..000000000 --- a/rust/rust_c/src/test_cmd/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "test_cmd" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - - -[dependencies] -btc_test_cmd = {path = "./src/btc_test_cmd", default-features = false, optional = true} -general_test_cmd = {path = "./src/general_test_cmd", optional = true} - -[features] -debug-memory = ["default"] -default = ["multi-coins"] -multi-coins = ["btc_test_cmd/multi-coins","general_test_cmd/multi-coins"] -btc-only = ["btc_test_cmd/btc-only"] \ No newline at end of file diff --git a/rust/rust_c/src/test_cmd/src/btc_test_cmd/src/lib.rs b/rust/rust_c/src/test_cmd/btc_test_cmd.rs similarity index 99% rename from rust/rust_c/src/test_cmd/src/btc_test_cmd/src/lib.rs rename to rust/rust_c/src/test_cmd/btc_test_cmd.rs index 97091d21f..b0922b690 100644 --- a/rust/rust_c/src/test_cmd/src/btc_test_cmd/src/lib.rs +++ b/rust/rust_c/src/test_cmd/btc_test_cmd.rs @@ -1,6 +1,3 @@ -#![no_std] - -extern crate alloc; use alloc::boxed::Box; use alloc::string::{String, ToString}; diff --git a/rust/rust_c/src/test_cmd/src/general_test_cmd/src/lib.rs b/rust/rust_c/src/test_cmd/general_test_cmd.rs similarity index 100% rename from rust/rust_c/src/test_cmd/src/general_test_cmd/src/lib.rs rename to rust/rust_c/src/test_cmd/general_test_cmd.rs diff --git a/rust/rust_c/src/test_cmd/mod.rs b/rust/rust_c/src/test_cmd/mod.rs new file mode 100644 index 000000000..f428cdb9e --- /dev/null +++ b/rust/rust_c/src/test_cmd/mod.rs @@ -0,0 +1,6 @@ +#[allow(unused)] +pub mod btc_test_cmd; + +#[cfg(feature = "multi-coins")] +#[allow(unused)] +pub mod general_test_cmd; diff --git a/rust/rust_c/src/test_cmd/src/btc_test_cmd/Cargo.toml b/rust/rust_c/src/test_cmd/src/btc_test_cmd/Cargo.toml deleted file mode 100644 index 70f6da073..000000000 --- a/rust/rust_c/src/test_cmd/src/btc_test_cmd/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "btc_test_cmd" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } -ur-parse-lib = { workspace = true } - -common_rust_c = { path = "../../../common", default-features = false, optional = true } -wallet_rust_c = { path = "../../../wallet", default-features = false, optional = true } - -[features] -default = ["multi-coins"] -multi-coins = ["common_rust_c/multi-coins", "wallet_rust_c/multi-coins"] -btc-only = ["common_rust_c/btc-only", "wallet_rust_c/btc-only"] diff --git a/rust/rust_c/src/test_cmd/src/general_test_cmd/Cargo.toml b/rust/rust_c/src/test_cmd/src/general_test_cmd/Cargo.toml deleted file mode 100644 index 212872a13..000000000 --- a/rust/rust_c/src/test_cmd/src/general_test_cmd/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "general_test_cmd" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } -common_rust_c = { path = "../../../common" } -wallet_rust_c = { path = "../../../wallet" } - -[features] -default = ["multi-coins"] -multi-coins = [ - "common_rust_c/multi-coins", - "wallet_rust_c/multi-coins" -] -btc-only = [ - "common_rust_c/btc-only", - "wallet_rust_c/btc-only" -] \ No newline at end of file diff --git a/rust/rust_c/src/test_cmd/src/lib.rs b/rust/rust_c/src/test_cmd/src/lib.rs deleted file mode 100644 index 27eff21e0..000000000 --- a/rust/rust_c/src/test_cmd/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![no_std] -#![feature(vec_into_raw_parts)] -#![feature(error_in_core)] -#![allow(unused_unsafe)] -extern crate alloc; - -#[allow(unused)] -use btc_test_cmd; - -#[cfg(feature = "multi-coins")] -#[allow(unused)] -use general_test_cmd; diff --git a/rust/rust_c/src/ton/Cargo.toml b/rust/rust_c/src/ton/Cargo.toml deleted file mode 100644 index 0d475c163..000000000 --- a/rust/rust_c/src/ton/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "ton_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_ton = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -common_rust_c = { path = "../common" } -hex = { workspace = true } -ur-registry = { workspace = true } - -[features] -debug-memory = [] \ No newline at end of file diff --git a/rust/rust_c/src/ton/src/lib.rs b/rust/rust_c/src/ton/mod.rs similarity index 99% rename from rust/rust_c/src/ton/src/lib.rs rename to rust/rust_c/src/ton/mod.rs index bbc890145..6ad0a5ddf 100644 --- a/rust/rust_c/src/ton/src/lib.rs +++ b/rust/rust_c/src/ton/mod.rs @@ -1,6 +1,3 @@ -#![no_std] -extern crate alloc; - pub mod structs; use alloc::{ boxed::Box, diff --git a/rust/rust_c/src/ton/src/structs.rs b/rust/rust_c/src/ton/structs.rs similarity index 100% rename from rust/rust_c/src/ton/src/structs.rs rename to rust/rust_c/src/ton/structs.rs diff --git a/rust/rust_c/src/tron/Cargo.toml b/rust/rust_c/src/tron/Cargo.toml deleted file mode 100644 index a5d2b439b..000000000 --- a/rust/rust_c/src/tron/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "tron_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { path = "../../../keystore", default-features = false } -app_tron = { path = "../../../apps/tron" } -app_utils = { path = "../../../apps/utils" } -rust_tools = {path="../../../tools"} -cty = "0.2.2" -cstr_core = "0.2.6" - -common_rust_c = {path = "../common"} - -[features] -debug-memory = [] \ No newline at end of file diff --git a/rust/rust_c/src/tron/src/lib.rs b/rust/rust_c/src/tron/mod.rs similarity index 97% rename from rust/rust_c/src/tron/src/lib.rs rename to rust/rust_c/src/tron/mod.rs index 3029fac63..9882c819d 100644 --- a/rust/rust_c/src/tron/src/lib.rs +++ b/rust/rust_c/src/tron/mod.rs @@ -1,10 +1,6 @@ -#![no_std] - -extern crate alloc; - pub mod structs; -use crate::structs::DisplayTron; +use structs::DisplayTron; use alloc::boxed::Box; use alloc::slice; use common_rust_c::errors::RustCError; diff --git a/rust/rust_c/src/tron/src/structs.rs b/rust/rust_c/src/tron/structs.rs similarity index 100% rename from rust/rust_c/src/tron/src/structs.rs rename to rust/rust_c/src/tron/structs.rs diff --git a/rust/rust_c/src/wallet/Cargo.toml b/rust/rust_c/src/wallet/Cargo.toml deleted file mode 100644 index f9f54357b..000000000 --- a/rust/rust_c/src/wallet/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "wallet_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -btc_only_wallet_rust_c = {path = "src/btc_only_wallet", default-features = false, optional = true} -multi_coins_wallet_rust_c = {path = "./src/multi_coins_wallet", optional = true} - -[features] -debug-memory = ["default"] -default = ["multi-coins"] -multi-coins = ["btc_only_wallet_rust_c/multi-coins","multi_coins_wallet_rust_c"] -btc-only = ["btc_only_wallet_rust_c/btc-only"] \ No newline at end of file diff --git a/rust/rust_c/src/wallet/src/btc_only_wallet/src/lib.rs b/rust/rust_c/src/wallet/btc_only_wallet.rs similarity index 99% rename from rust/rust_c/src/wallet/src/btc_only_wallet/src/lib.rs rename to rust/rust_c/src/wallet/btc_only_wallet.rs index 4d80bf99e..f44fd9290 100644 --- a/rust/rust_c/src/wallet/src/btc_only_wallet/src/lib.rs +++ b/rust/rust_c/src/wallet/btc_only_wallet.rs @@ -1,7 +1,3 @@ -#![no_std] - -extern crate alloc; - use alloc::string::ToString; use alloc::vec::Vec; use alloc::{format, vec}; diff --git a/rust/rust_c/src/wallet/mod.rs b/rust/rust_c/src/wallet/mod.rs new file mode 100644 index 000000000..3d89d7745 --- /dev/null +++ b/rust/rust_c/src/wallet/mod.rs @@ -0,0 +1,4 @@ +pub mod btc_only_wallet; +pub use btc_only_wallet::*; +#[cfg(feature = "multi-coins")] +pub mod multi_coins_wallet; \ No newline at end of file diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/aptos.rs b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/aptos.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/arconnect.rs b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/arconnect.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/backpack.rs b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/backpack.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/bitget.rs b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/bitget.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/imtoken.rs b/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/imtoken.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/keplr.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs similarity index 98% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/keplr.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs index b50cbcd5e..665371b18 100644 --- a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/keplr.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs @@ -1,4 +1,4 @@ -use crate::structs::KeplrAccount; +use super::structs::KeplrAccount; use alloc::format; use alloc::string::ToString; use alloc::vec::Vec; diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/keystone.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/keystone.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/lib.rs b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs similarity index 99% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/lib.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/mod.rs index e895fe304..78082b49d 100644 --- a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/lib.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs @@ -1,6 +1,3 @@ -#![no_std] - -extern crate alloc; pub mod aptos; pub mod arconnect; pub mod backpack; @@ -49,7 +46,7 @@ use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UN use common_rust_c::utils::{recover_c_array, recover_c_char}; use common_rust_c::{extract_array, extract_ptr_with_type}; -use crate::structs::QRHardwareCallData; +use structs::QRHardwareCallData; #[repr(C)] pub enum ETHAccountType { diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/okx.rs b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/okx.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/okx.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/solana.rs b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/solana.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/solana.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/structs.rs b/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/structs.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/structs.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/sui.rs b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/sui.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/sui.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/thor_wallet.rs b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs similarity index 97% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/thor_wallet.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs index e854ee6c3..20053bd15 100644 --- a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/thor_wallet.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs @@ -1,5 +1,3 @@ -#![no_std] -extern crate alloc; use alloc::format; use alloc::string::ToString; use core::slice; @@ -15,7 +13,7 @@ use common_rust_c::types::{PtrString, PtrT}; use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use common_rust_c::utils::{recover_c_array, recover_c_char}; -use crate::utils::normalize_xpub; +use super::utils::normalize_xpub; #[no_mangle] pub extern "C" fn get_connect_thor_wallet_ur( diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/tonkeeper.rs b/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/tonkeeper.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/utils.rs b/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/utils.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/utils.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/xbull.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/xbull.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/xrp_toolkit.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/xrp_toolkit.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/zcash.rs b/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/zcash.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs diff --git a/rust/rust_c/src/wallet/src/btc_only_wallet/Cargo.toml b/rust/rust_c/src/wallet/src/btc_only_wallet/Cargo.toml deleted file mode 100644 index 12438747c..000000000 --- a/rust/rust_c/src/wallet/src/btc_only_wallet/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "btc_only_wallet_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_wallets = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -bitcoin = { workspace = true } -ur-registry = { workspace = true } -hex = { workspace = true } -common_rust_c = { path = "../../../common" } -app_utils = { workspace = true } - -[features] -default = ["multi-coins"] -multi-coins = ["common_rust_c/multi-coins"] -btc-only = ["common_rust_c/btc-only"] diff --git a/rust/rust_c/src/wallet/src/lib.rs b/rust/rust_c/src/wallet/src/lib.rs deleted file mode 100644 index 4b5b7a1d2..000000000 --- a/rust/rust_c/src/wallet/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![no_std] - -extern crate alloc; - -pub use btc_only_wallet_rust_c; -pub use btc_only_wallet_rust_c::*; -#[cfg(feature = "multi-coins")] -pub use multi_coins_wallet_rust_c; diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/Cargo.toml b/rust/rust_c/src/wallet/src/multi_coins_wallet/Cargo.toml deleted file mode 100644 index 621fe61e8..000000000 --- a/rust/rust_c/src/wallet/src/multi_coins_wallet/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "multi_coins_wallet_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_wallets = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -app_arweave = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -ur-registry = { workspace = true } -hex = { workspace = true } -bitcoin = { workspace = true } -common_rust_c = { path = "../../../common" } -ed25519-bip32-core = { workspace = true } - -[features] -default = ["multi-coins"] -multi-coins = [] -btc-only = [] \ No newline at end of file diff --git a/rust/rust_c/src/xrp/Cargo.toml b/rust/rust_c/src/xrp/Cargo.toml deleted file mode 100644 index a6889bec4..000000000 --- a/rust/rust_c/src/xrp/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "xrp_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_xrp = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -bitcoin = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } -serde_json = { workspace = true } -common_rust_c = { path = "../common" } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/xrp/src/lib.rs b/rust/rust_c/src/xrp/mod.rs similarity index 99% rename from rust/rust_c/src/xrp/src/lib.rs rename to rust/rust_c/src/xrp/mod.rs index 97f6b8f8c..ff99ef680 100644 --- a/rust/rust_c/src/xrp/src/lib.rs +++ b/rust/rust_c/src/xrp/mod.rs @@ -1,7 +1,3 @@ -#![no_std] - -extern crate alloc; - use alloc::format; use alloc::string::ToString; use alloc::vec::Vec; @@ -29,7 +25,7 @@ use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; use common_rust_c::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use common_rust_c::utils::{convert_c_char, recover_c_char}; -use crate::structs::DisplayXrpTx; +use structs::DisplayXrpTx; pub mod structs; diff --git a/rust/rust_c/src/xrp/src/structs.rs b/rust/rust_c/src/xrp/structs.rs similarity index 100% rename from rust/rust_c/src/xrp/src/structs.rs rename to rust/rust_c/src/xrp/structs.rs diff --git a/rust/rust_c/src/zcash/Cargo.toml b/rust/rust_c/src/zcash/Cargo.toml deleted file mode 100644 index f9d01f851..000000000 --- a/rust/rust_c/src/zcash/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "zcash_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_zcash = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -common_rust_c = { path = "../common" } -cty = { workspace = true } -ur-registry = { workspace = true } -cstr_core = { workspace = true } -zcash_vendor = { workspace = true } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/zcash/src/lib.rs b/rust/rust_c/src/zcash/mod.rs similarity index 96% rename from rust/rust_c/src/zcash/src/lib.rs rename to rust/rust_c/src/zcash/mod.rs index 3a4dc54e0..f66a89c08 100644 --- a/rust/rust_c/src/zcash/src/lib.rs +++ b/rust/rust_c/src/zcash/mod.rs @@ -1,6 +1,3 @@ -#![no_std] -extern crate alloc; - pub mod structs; use alloc::{boxed::Box, format}; @@ -24,7 +21,11 @@ use ur_registry::{traits::RegistryItem, zcash::zcash_pczt::ZcashPczt}; use zcash_vendor::zcash_protocol::consensus::MainNetwork; #[no_mangle] -pub extern "C" fn derive_zcash_ufvk(seed: PtrBytes, seed_len: u32, account_path: PtrString) -> *mut SimpleResponse { +pub extern "C" fn derive_zcash_ufvk( + seed: PtrBytes, + seed_len: u32, + account_path: PtrString, +) -> *mut SimpleResponse { let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; let account_path = recover_c_char(account_path); let ufvk_text = derive_ufvk(&MainNetwork, seed, &account_path); diff --git a/rust/rust_c/src/zcash/src/structs.rs b/rust/rust_c/src/zcash/structs.rs similarity index 100% rename from rust/rust_c/src/zcash/src/structs.rs rename to rust/rust_c/src/zcash/structs.rs From 22a3436f72e097c9bb986c88196d51a70e632111 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 16:55:48 +0800 Subject: [PATCH 04/31] chore: refactor common interfaces --- rust/Cargo.lock | 46 ++------ rust/Cargo.toml | 2 - rust/rust_c/Cargo.toml | 101 +++++++++--------- rust/rust_c/src/aptos/mod.rs | 12 +-- rust/rust_c/src/aptos/structs.rs | 10 +- rust/rust_c/src/arweave/data_item.rs | 6 +- rust/rust_c/src/arweave/mod.rs | 17 ++- rust/rust_c/src/arweave/structs.rs | 12 +-- rust/rust_c/src/bitcoin/address.rs | 6 +- rust/rust_c/src/bitcoin/legacy.rs | 12 +-- rust/rust_c/src/bitcoin/msg.rs | 4 +- rust/rust_c/src/bitcoin/multi_sig/mod.rs | 15 ++- rust/rust_c/src/bitcoin/multi_sig/structs.rs | 12 +-- rust/rust_c/src/bitcoin/psbt.rs | 14 +-- rust/rust_c/src/bitcoin/structs.rs | 16 +-- rust/rust_c/src/cardano/address.rs | 6 +- rust/rust_c/src/cardano/mod.rs | 12 +-- rust/rust_c/src/cardano/structs.rs | 12 +-- rust/rust_c/src/common/Cargo.toml | 50 --------- rust/rust_c/src/common/{src => }/errors.rs | 0 rust/rust_c/src/common/{src => }/ffi.rs | 4 +- rust/rust_c/src/common/{src => }/free.rs | 10 +- rust/rust_c/src/common/{src => }/keystone.rs | 10 +- rust/rust_c/src/common/{src => }/macros.rs | 12 +-- rust/rust_c/src/common/{src/lib.rs => mod.rs} | 14 +-- .../rust_c/src/common/{src => }/qrcode/mod.rs | 6 +- .../{src => }/qrcode/seed_signer_message.rs | 0 rust/rust_c/src/common/{src => }/structs.rs | 8 +- rust/rust_c/src/common/{src => }/types.rs | 2 +- rust/rust_c/src/common/{src => }/ur.rs | 10 +- rust/rust_c/src/common/{src => }/ur_ext.rs | 6 +- rust/rust_c/src/common/{src => }/utils.rs | 6 +- rust/rust_c/src/common/{src => }/web_auth.rs | 0 rust/rust_c/src/cosmos/mod.rs | 12 +-- rust/rust_c/src/cosmos/structs.rs | 10 +- rust/rust_c/src/ethereum/abi.rs | 8 +- rust/rust_c/src/ethereum/address.rs | 6 +- rust/rust_c/src/ethereum/mod.rs | 15 +-- rust/rust_c/src/ethereum/structs.rs | 12 +-- rust/rust_c/src/lib.rs | 2 +- rust/rust_c/src/near/mod.rs | 10 +- rust/rust_c/src/near/structs.rs | 12 +-- rust/rust_c/src/simulator/mod.rs | 2 +- rust/rust_c/src/solana/mod.rs | 12 +-- rust/rust_c/src/solana/structs.rs | 12 +-- rust/rust_c/src/stellar/mod.rs | 12 +-- rust/rust_c/src/stellar/structs.rs | 8 +- rust/rust_c/src/sui/mod.rs | 12 +-- rust/rust_c/src/sui/structs.rs | 10 +- rust/rust_c/src/test_cmd/btc_test_cmd.rs | 12 +-- rust/rust_c/src/test_cmd/general_test_cmd.rs | 12 +-- rust/rust_c/src/ton/mod.rs | 24 ++--- rust/rust_c/src/ton/structs.rs | 7 +- rust/rust_c/src/tron/mod.rs | 12 +-- rust/rust_c/src/tron/structs.rs | 10 +- rust/rust_c/src/wallet/btc_only_wallet.rs | 14 +-- .../src/wallet/multi_coins_wallet/aptos.rs | 12 +-- .../wallet/multi_coins_wallet/arconnect.rs | 6 +- .../src/wallet/multi_coins_wallet/backpack.rs | 12 +-- .../src/wallet/multi_coins_wallet/bitget.rs | 12 +-- .../src/wallet/multi_coins_wallet/imtoken.rs | 8 +- .../src/wallet/multi_coins_wallet/keplr.rs | 10 +- .../src/wallet/multi_coins_wallet/keystone.rs | 12 +-- .../src/wallet/multi_coins_wallet/mod.rs | 14 +-- .../src/wallet/multi_coins_wallet/okx.rs | 12 +-- .../src/wallet/multi_coins_wallet/solana.rs | 12 +-- .../src/wallet/multi_coins_wallet/structs.rs | 14 +-- .../src/wallet/multi_coins_wallet/sui.rs | 12 +-- .../wallet/multi_coins_wallet/thor_wallet.rs | 10 +- .../wallet/multi_coins_wallet/tonkeeper.rs | 8 +- .../src/wallet/multi_coins_wallet/utils.rs | 6 +- .../src/wallet/multi_coins_wallet/xbull.rs | 12 +-- .../wallet/multi_coins_wallet/xrp_toolkit.rs | 6 +- .../src/wallet/multi_coins_wallet/zcash.rs | 12 +-- rust/rust_c/src/xrp/mod.rs | 14 +-- rust/rust_c/src/xrp/structs.rs | 10 +- rust/rust_c/src/zcash/mod.rs | 6 +- rust/rust_c/src/zcash/structs.rs | 14 ++- 78 files changed, 415 insertions(+), 518 deletions(-) delete mode 100644 rust/rust_c/src/common/Cargo.toml rename rust/rust_c/src/common/{src => }/errors.rs (100%) rename rust/rust_c/src/common/{src => }/ffi.rs (94%) rename rust/rust_c/src/common/{src => }/free.rs (94%) rename rust/rust_c/src/common/{src => }/keystone.rs (97%) rename rust/rust_c/src/common/{src => }/macros.rs (98%) rename rust/rust_c/src/common/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/common/{src => }/qrcode/mod.rs (94%) rename rust/rust_c/src/common/{src => }/qrcode/seed_signer_message.rs (100%) rename rust/rust_c/src/common/{src => }/structs.rs (97%) rename rust/rust_c/src/common/{src => }/types.rs (95%) rename rust/rust_c/src/common/{src => }/ur.rs (99%) rename rust/rust_c/src/common/{src => }/ur_ext.rs (99%) rename rust/rust_c/src/common/{src => }/utils.rs (85%) rename rust/rust_c/src/common/{src => }/web_auth.rs (100%) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index d112b6a8f..0b908bb18 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1065,45 +1065,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" -[[package]] -name = "common_rust_c" -version = "0.1.0" -dependencies = [ - "aes", - "app_aptos", - "app_arweave", - "app_bitcoin", - "app_cardano", - "app_cosmos", - "app_ethereum", - "app_near", - "app_solana", - "app_stellar", - "app_sui", - "app_ton", - "app_tron", - "app_utils", - "app_wallets", - "app_xrp", - "app_zcash", - "base64 0.11.0", - "bitcoin", - "bitcoin_hashes 0.14.0", - "cbc", - "cryptoxide", - "cstr_core", - "cty", - "hex", - "keystore", - "rsa", - "rust_tools", - "serde_json", - "sha1", - "thiserror-core", - "ur-parse-lib", - "ur-registry", -] - [[package]] name = "const-oid" version = "0.9.6" @@ -3370,6 +3331,7 @@ dependencies = [ name = "rust_c" version = "0.1.0" dependencies = [ + "aes", "app_aptos", "app_arweave", "app_bitcoin", @@ -3388,8 +3350,9 @@ dependencies = [ "app_zcash", "base64 0.11.0", "bitcoin", + "bitcoin_hashes 0.14.0", + "cbc", "cbindgen", - "common_rust_c", "core2", "cryptoxide", "cstr_core", @@ -3400,9 +3363,12 @@ dependencies = [ "hex", "itertools 0.13.0", "keystore", + "rsa", "rust_tools", "serde_json", + "sha1", "sim_qr_reader", + "thiserror-core", "ur-parse-lib", "ur-registry", "zcash_vendor", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index a44dca30d..231047af4 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -21,8 +21,6 @@ members = [ # C interface entry "rust_c", - # rust_c libs - "rust_c/src/common", # other "keystore", diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index 9eb10c19f..f1c38a8c4 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -6,55 +6,51 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -common_rust_c = { path = "./src/common", optional = true, default-features = false } - - +#external cty = { workspace = true } cstr_core = { workspace = true } getrandom = { workspace = true, features = ["custom"] } -keystore = { workspace = true } -app_aptos = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } serde_json = { workspace = true } hex = { workspace = true } bitcoin = { workspace = true } -ur-registry = { workspace = true } -app_arweave = { workspace = true } cryptoxide = { workspace = true } -app_bitcoin = { workspace = true } base64 = { workspace = true } -app_cardano = { workspace = true } itertools = { workspace = true } -ed25519-bip32-core = { workspace = true } - -app_cosmos = { workspace = true, default-features = false } either = { workspace = true } - -app_ethereum = { workspace = true } core2 = { workspace = true } - -app_solana = { workspace = true } - -app_near = { workspace = true } - -app_sui = { workspace = true } - -app_stellar = { workspace = true } - -app_ton = { workspace = true } - -app_tron = { workspace = true } - -app_wallets = { workspace = true } - +thiserror = { workspace = true } +bitcoin_hashes = { workspace = true } +rsa = { workspace = true } +sha1 = { workspace = true } +aes = { workspace = true } +cbc = { workspace = true } + +#keystone owned +keystore = { workspace = true } +sim_qr_reader = { workspace = true } +ur-registry = { workspace = true } ur-parse-lib = { workspace = true } - -app_xrp = { workspace = true } - -app_zcash = { workspace = true } zcash_vendor = { workspace = true } -sim_qr_reader = { workspace = true } +ed25519-bip32-core = { workspace = true } +app_utils = { workspace = true } +rust_tools = { workspace = true } + +#apps +app_bitcoin = { workspace = true, optional = true } +app_wallets = { workspace = true } +app_ethereum = { workspace = true, optional = true } +app_cardano = { workspace = true, optional = true } +app_tron = { workspace = true, optional = true } +app_solana = { workspace = true, optional = true } +app_near = { workspace = true, optional = true } +app_xrp = { workspace = true, optional = true } +app_cosmos = { workspace = true, optional = true } +app_aptos = { workspace = true, optional = true } +app_sui = { workspace = true, optional = true } +app_arweave = { workspace = true, optional = true } +app_stellar = { workspace = true, optional = true } +app_ton = { workspace = true, optional = true } +app_zcash = { workspace = true, optional = true } [lib] crate-type = ["staticlib"] @@ -63,26 +59,25 @@ crate-type = ["staticlib"] # feature toggles use-allocator = [] simulator = [] -aptos = [] -arweave = [] -bitcoin = [] -cardano = [] -cosmos = [] -ethereum = [] -near = [] -solana = [] -stellar = [] -sui = [] -ton = [] -tron = [] -xrp = [] -zcash = [] +aptos = ["dep:app_aptos"] +arweave = ["dep:app_arweave"] +bitcoin = ["dep:app_bitcoin"] +cardano = ["dep:app_cardano"] +cosmos = ["dep:app_cosmos"] +ethereum = ["dep:app_ethereum"] +near = ["dep:app_near"] +solana = ["dep:app_solana"] +stellar = ["dep:app_stellar"] +sui = ["dep:app_sui"] +ton = ["dep:app_ton"] +tron = ["dep:app_tron"] +xrp = ["dep:app_xrp"] +zcash = ["dep:app_zcash"] test_cmd = [] -debug-memory = ["multi-coins", "common_rust_c/debug-memory"] +debug-memory = ["multi-coins"] multi-coins = [ - "common_rust_c/multi-coins", "bitcoin", "ethereum", "solana", @@ -99,7 +94,7 @@ multi-coins = [ "zcash", ] -btc-only = ["common_rust_c/btc-only", "bitcoin"] +btc-only = ["bitcoin"] # build variants # production diff --git a/rust/rust_c/src/aptos/mod.rs b/rust/rust_c/src/aptos/mod.rs index 2f53993a4..7029ed6b9 100644 --- a/rust/rust_c/src/aptos/mod.rs +++ b/rust/rust_c/src/aptos/mod.rs @@ -6,12 +6,12 @@ use alloc::vec::Vec; use app_aptos; use app_aptos::errors::AptosError; use app_aptos::parser::is_tx; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use cty::c_char; use hex; use hex::FromHex; diff --git a/rust/rust_c/src/aptos/structs.rs b/rust/rust_c/src/aptos/structs.rs index 8101587ca..f23d20dba 100644 --- a/rust/rust_c/src/aptos/structs.rs +++ b/rust/rust_c/src/aptos/structs.rs @@ -1,10 +1,10 @@ use alloc::string::{String, ToString}; use app_aptos::parser::AptosTx; -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; use serde_json::Value; #[repr(C)] diff --git a/rust/rust_c/src/arweave/data_item.rs b/rust/rust_c/src/arweave/data_item.rs index 80ebe5a8b..1a11291bc 100644 --- a/rust/rust_c/src/arweave/data_item.rs +++ b/rust/rust_c/src/arweave/data_item.rs @@ -1,9 +1,9 @@ -use app_arweave::{ao_transaction::AOTransferTransaction, parse_data_item}; -use common_rust_c::{ - extract_ptr_with_type, +use crate::common::{ structs::TransactionParseResult, types::{PtrT, PtrUR}, }; +use crate::extract_ptr_with_type; +use app_arweave::{ao_transaction::AOTransferTransaction, parse_data_item}; use ur_registry::arweave::arweave_sign_request::ArweaveSignRequest; use super::structs::{DisplayArweaveAOTransfer, DisplayArweaveDataItem}; diff --git a/rust/rust_c/src/arweave/mod.rs b/rust/rust_c/src/arweave/mod.rs index 74903381f..906ae6aea 100644 --- a/rust/rust_c/src/arweave/mod.rs +++ b/rust/rust_c/src/arweave/mod.rs @@ -1,9 +1,15 @@ -pub mod structs; pub mod data_item; +pub mod structs; -use structs::{ArweaveRequestType, DisplayArweaveMessage, DisplayArweaveTx}; use alloc::boxed::Box; +use structs::{ArweaveRequestType, DisplayArweaveMessage, DisplayArweaveTx}; +use crate::common::errors::RustCError; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; use alloc::slice; use alloc::string::{String, ToString}; use alloc::vec::Vec; @@ -12,12 +18,6 @@ use app_arweave::{ aes256_decrypt, aes256_encrypt, errors::ArweaveError, fix_address, generate_public_key_from_primes, generate_secret, parse, }; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; use cty::c_char; use hex; use keystore::algorithms::ed25519::slip10_ed25519::get_private_key_by_seed; @@ -28,7 +28,6 @@ use ur_registry::arweave::arweave_sign_request::{ArweaveSignRequest, SaltLen, Si use ur_registry::arweave::arweave_signature::ArweaveSignature; use ur_registry::traits::RegistryItem; - fn generate_aes_key_iv(seed: &[u8]) -> ([u8; 32], [u8; 16]) { // The number 1557192335 is derived from the ASCII representation of "keystone" hashed with SHA-256, taking the first 32 bits with the highest bit set to 0. let key_path = "m/44'/1557192335'/0'/0'/0'".to_string(); diff --git a/rust/rust_c/src/arweave/structs.rs b/rust/rust_c/src/arweave/structs.rs index 1fc2be1d6..bec53ee75 100644 --- a/rust/rust_c/src/arweave/structs.rs +++ b/rust/rust_c/src/arweave/structs.rs @@ -4,12 +4,12 @@ use app_arweave::{ ao_transaction::AOTransferTransaction, data_item::{DataItem, Tag}, }; -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{Ptr, PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; -use common_rust_c::{ffi::VecFFI, free_vec}; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{Ptr, PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method, free_vec}; +use crate::common::ffi::VecFFI; #[repr(C)] pub enum ArweaveRequestType { diff --git a/rust/rust_c/src/bitcoin/address.rs b/rust/rust_c/src/bitcoin/address.rs index 336bfd941..655fea642 100644 --- a/rust/rust_c/src/bitcoin/address.rs +++ b/rust/rust_c/src/bitcoin/address.rs @@ -1,9 +1,9 @@ use app_bitcoin; use app_bitcoin::addresses::xyzpub; use bitcoin::secp256k1::ffi::types::c_char; -use common_rust_c::structs::SimpleResponse; -use common_rust_c::types::PtrString; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::structs::SimpleResponse; +use crate::common::types::PtrString; +use crate::common::utils::{convert_c_char, recover_c_char}; use core::str::FromStr; #[no_mangle] diff --git a/rust/rust_c/src/bitcoin/legacy.rs b/rust/rust_c/src/bitcoin/legacy.rs index 1979b16c7..f0eae8f28 100644 --- a/rust/rust_c/src/bitcoin/legacy.rs +++ b/rust/rust_c/src/bitcoin/legacy.rs @@ -1,12 +1,12 @@ use super::structs::DisplayTx; use alloc::boxed::Box; use alloc::slice; -use common_rust_c::errors::RustCError; -use common_rust_c::keystone; -use common_rust_c::keystone::{build_parse_context, build_payload}; -use common_rust_c::structs::{TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{QRCodeType, UREncodeResult}; +use crate::common::errors::RustCError; +use crate::common::keystone; +use crate::common::keystone::{build_parse_context, build_payload}; +use crate::common::structs::{TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{QRCodeType, UREncodeResult}; #[no_mangle] pub extern "C" fn utxo_parse_keystone( diff --git a/rust/rust_c/src/bitcoin/msg.rs b/rust/rust_c/src/bitcoin/msg.rs index 0a1e62fbf..da66b535d 100644 --- a/rust/rust_c/src/bitcoin/msg.rs +++ b/rust/rust_c/src/bitcoin/msg.rs @@ -6,9 +6,8 @@ use alloc::{ vec::Vec, }; use base64; -use common_rust_c::{ +use crate::common::{ errors::RustCError, - extract_ptr_with_type, ffi::CSliceFFI, qrcode::seed_signer_message::SeedSignerMessage, structs::{ExtendedPublicKey, TransactionCheckResult, TransactionParseResult}, @@ -16,6 +15,7 @@ use common_rust_c::{ ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}, utils::{convert_c_char, recover_c_array, recover_c_char}, }; +use crate::extract_ptr_with_type; use keystore::algorithms::secp256k1; use ur_registry::bitcoin::btc_sign_request::{BtcSignRequest, DataType}; use ur_registry::bitcoin::btc_signature::BtcSignature; diff --git a/rust/rust_c/src/bitcoin/multi_sig/mod.rs b/rust/rust_c/src/bitcoin/multi_sig/mod.rs index e5ecf3be0..e29a6de58 100644 --- a/rust/rust_c/src/bitcoin/multi_sig/mod.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/mod.rs @@ -18,20 +18,19 @@ use structs::{MultiSigFormatType, MultiSigXPubInfoItem}; use cryptoxide::hashing::sha256; use hex; - use ur_registry::bytes::Bytes; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; -use common_rust_c::structs::{ExtendedPublicKey, Response, SimpleResponse}; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, ViewType, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_array, recover_c_char}; +use crate::common::structs::{ExtendedPublicKey, Response, SimpleResponse}; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, ViewType, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_array, recover_c_char}; use structs::{MultiSigWallet, NetworkType}; -use common_rust_c::extract_ptr_with_type; +use crate::extract_ptr_with_type; use ur_registry::crypto_account::CryptoAccount; use ur_registry::error::URError; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/bitcoin/multi_sig/structs.rs b/rust/rust_c/src/bitcoin/multi_sig/structs.rs index dfe6a6ba1..83b69a2b1 100644 --- a/rust/rust_c/src/bitcoin/multi_sig/structs.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/structs.rs @@ -5,12 +5,12 @@ use alloc::string::ToString; use alloc::vec::Vec; use app_bitcoin::multi_sig::wallet::{BsmsWallet, MultiSigWalletConfig}; use app_bitcoin::multi_sig::{MultiSigFormat, MultiSigType, MultiSigXPubInfo, Network}; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::Free; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT}; -use common_rust_c::ur::UREncodeResult; -use common_rust_c::utils::{convert_c_char, recover_c_char}; -use common_rust_c::{check_and_free_ptr, free_str_ptr, free_vec, impl_c_ptr, make_free_method}; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT}; +use crate::common::ur::UREncodeResult; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::{check_and_free_ptr, free_str_ptr, free_vec, impl_c_ptr, make_free_method}; #[repr(C)] pub enum NetworkType { diff --git a/rust/rust_c/src/bitcoin/psbt.rs b/rust/rust_c/src/bitcoin/psbt.rs index 1a8410495..c96c9901d 100644 --- a/rust/rust_c/src/bitcoin/psbt.rs +++ b/rust/rust_c/src/bitcoin/psbt.rs @@ -10,15 +10,15 @@ use core::str::FromStr; use app_bitcoin::parsed_tx::ParseContext; use app_bitcoin::{self, parse_psbt_hex_sign_status, parse_psbt_sign_status}; use bitcoin::bip32::{DerivationPath, Xpub}; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::ffi::{CSliceFFI, VecFFI}; -use common_rust_c::structs::{ +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::ffi::{CSliceFFI, VecFFI}; +use crate::common::structs::{ ExtendedPublicKey, Response, TransactionCheckResult, TransactionParseResult, }; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH}; -use common_rust_c::utils::{convert_c_char, recover_c_array, recover_c_char}; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH}; +use crate::common::utils::{convert_c_char, recover_c_array, recover_c_char}; use hex; use ur_registry::crypto_psbt::CryptoPSBT; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/bitcoin/structs.rs b/rust/rust_c/src/bitcoin/structs.rs index fdf91375a..323d9c6ba 100644 --- a/rust/rust_c/src/bitcoin/structs.rs +++ b/rust/rust_c/src/bitcoin/structs.rs @@ -4,14 +4,14 @@ use core::ptr::null_mut; use app_bitcoin; use app_bitcoin::parsed_tx::{DetailTx, OverviewTx, ParsedInput, ParsedOutput, ParsedTx}; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::Free; -use common_rust_c::structs::Response; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::ur::UREncodeResult; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::structs::Response; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::ur::UREncodeResult; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct PsbtSignResult { diff --git a/rust/rust_c/src/cardano/address.rs b/rust/rust_c/src/cardano/address.rs index 1b58321a2..bde4fa0a1 100644 --- a/rust/rust_c/src/cardano/address.rs +++ b/rust/rust_c/src/cardano/address.rs @@ -1,8 +1,8 @@ use app_cardano; use app_cardano::address::AddressType; -use common_rust_c::structs::SimpleResponse; -use common_rust_c::types::PtrString; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::structs::SimpleResponse; +use crate::common::types::PtrString; +use crate::common::utils::{convert_c_char, recover_c_char}; use cty::c_char; #[no_mangle] diff --git a/rust/rust_c/src/cardano/mod.rs b/rust/rust_c/src/cardano/mod.rs index 7e7a38f37..9f34865ea 100644 --- a/rust/rust_c/src/cardano/mod.rs +++ b/rust/rust_c/src/cardano/mod.rs @@ -27,12 +27,12 @@ use ur_registry::cardano::cardano_signature::CardanoSignature; use ur_registry::crypto_key_path::CryptoKeyPath; use structs::{DisplayCardanoCatalyst, DisplayCardanoSignData, DisplayCardanoTx}; -use common_rust_c::errors::{RustCError, R}; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::{RustCError, R}; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use ur_registry::registry_types::{ CARDANO_CATALYST_VOTING_REGISTRATION_SIGNATURE, CARDANO_SIGNATURE, CARDANO_SIGN_DATA_SIGNATURE, }; diff --git a/rust/rust_c/src/cardano/structs.rs b/rust/rust_c/src/cardano/structs.rs index 70538b53b..35b7f85c2 100644 --- a/rust/rust_c/src/cardano/structs.rs +++ b/rust/rust_c/src/cardano/structs.rs @@ -10,12 +10,12 @@ use hex; use itertools::Itertools; use ur_registry::cardano::cardano_catalyst_voting_registration::CardanoCatalystVotingRegistrationRequest; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::{free_ptr_string, Free}; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{Ptr, PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{ +use crate::common::ffi::VecFFI; +use crate::common::free::{free_ptr_string, Free}; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{Ptr, PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{ check_and_free_ptr, free_str_ptr, free_vec, impl_c_ptr, impl_c_ptrs, make_free_method, }; diff --git a/rust/rust_c/src/common/Cargo.toml b/rust/rust_c/src/common/Cargo.toml deleted file mode 100644 index afd8edb06..000000000 --- a/rust/rust_c/src/common/Cargo.toml +++ /dev/null @@ -1,50 +0,0 @@ -[package] -name = "common_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -base64 = { workspace = true } -thiserror = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } -serde_json = { workspace = true } -bitcoin = { workspace = true } -bitcoin_hashes = { workspace = true } -rsa = { workspace = true } -cryptoxide = { workspace = true } -ur-parse-lib = { workspace = true } -sha1 = { workspace = true } -aes = { workspace = true } -cbc = { workspace = true } - -app_bitcoin = { workspace = true } -app_wallets = { workspace = true } - -app_ethereum = { workspace = true, optional = true } -app_cardano = { workspace = true, optional = true } -app_tron = { workspace = true, optional = true } -app_solana = { workspace = true, optional = true } -app_near = { workspace = true, optional = true } -app_xrp = { workspace = true, optional = true } -app_cosmos = { workspace = true, optional = true } -app_aptos = { workspace = true, optional = true } -app_sui = { workspace = true, optional = true } -app_arweave = { workspace = true, optional = true } -app_stellar = { workspace = true, optional = true } -app_ton = { workspace = true, optional = true } -app_zcash = { workspace = true, optional = true } - -[features] -debug-memory = ["default"] -default = ["multi-coins"] -multi-coins = ["app_ethereum", "app_cardano", "app_tron", "app_solana", "app_near", "app_xrp", "app_cosmos", "app_aptos", "app_sui", "app_arweave", "app_ton", "app_stellar", "app_zcash"] -# -btc-only = [] \ No newline at end of file diff --git a/rust/rust_c/src/common/src/errors.rs b/rust/rust_c/src/common/errors.rs similarity index 100% rename from rust/rust_c/src/common/src/errors.rs rename to rust/rust_c/src/common/errors.rs diff --git a/rust/rust_c/src/common/src/ffi.rs b/rust/rust_c/src/common/ffi.rs similarity index 94% rename from rust/rust_c/src/common/src/ffi.rs rename to rust/rust_c/src/common/ffi.rs index 6c96f095d..cc992dc84 100644 --- a/rust/rust_c/src/common/src/ffi.rs +++ b/rust/rust_c/src/common/ffi.rs @@ -1,8 +1,8 @@ -use crate::free::{Free, SimpleFree}; +use super::free::{Free, SimpleFree}; use alloc::vec::Vec; use cty::size_t; -use crate::types::PtrT; +use super::types::PtrT; use crate::{impl_c_ptr, impl_simple_free}; #[repr(C)] diff --git a/rust/rust_c/src/common/src/free.rs b/rust/rust_c/src/common/free.rs similarity index 94% rename from rust/rust_c/src/common/src/free.rs rename to rust/rust_c/src/common/free.rs index d287c2b99..eeaa625ec 100644 --- a/rust/rust_c/src/common/src/free.rs +++ b/rust/rust_c/src/common/free.rs @@ -1,8 +1,8 @@ -use crate::ffi::VecFFI; +use super::ffi::VecFFI; use crate::make_free_method; -use crate::structs::SimpleResponse; -use crate::types::{PtrString, PtrT}; -use crate::ur::{UREncodeMultiResult, UREncodeResult, URParseMultiResult, URParseResult}; +use super::structs::SimpleResponse; +use super::types::{PtrString, PtrT}; +use super::ur::{UREncodeMultiResult, UREncodeResult, URParseMultiResult, URParseResult}; use alloc::boxed::Box; use cty::{c_char, c_void}; @@ -57,7 +57,7 @@ macro_rules! free_ptr_with_type { ($x: expr, $name: ident) => { if (!$x.is_null()) { unsafe { - let x = extract_ptr_with_type!($x, $name); + let x = crate::extract_ptr_with_type!($x, $name); let _b = alloc::boxed::Box::from_raw(x); // drop(b); } diff --git a/rust/rust_c/src/common/src/keystone.rs b/rust/rust_c/src/common/keystone.rs similarity index 97% rename from rust/rust_c/src/common/src/keystone.rs rename to rust/rust_c/src/common/keystone.rs index cfa49fb25..beba14975 100644 --- a/rust/rust_c/src/common/src/keystone.rs +++ b/rust/rust_c/src/common/keystone.rs @@ -1,9 +1,9 @@ -use crate::errors::{KeystoneError, RustCError}; +use super::errors::{KeystoneError, RustCError}; +use super::structs::TransactionCheckResult; +use super::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use super::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use super::utils::recover_c_char; use crate::extract_ptr_with_type; -use crate::structs::TransactionCheckResult; -use crate::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use crate::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use crate::utils::recover_c_char; use alloc::borrow::ToOwned; use alloc::format; use alloc::string::{String, ToString}; diff --git a/rust/rust_c/src/common/src/macros.rs b/rust/rust_c/src/common/macros.rs similarity index 98% rename from rust/rust_c/src/common/src/macros.rs rename to rust/rust_c/src/common/macros.rs index c9a2eed9c..50338ed0c 100644 --- a/rust/rust_c/src/common/src/macros.rs +++ b/rust/rust_c/src/common/macros.rs @@ -134,8 +134,8 @@ macro_rules! impl_new_error { } } - impl From for $name { - fn from(value: crate::errors::KeystoneError) -> Self { + impl From for $name { + fn from(value: super::errors::KeystoneError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } @@ -267,8 +267,8 @@ macro_rules! impl_new_error { } } - impl<$t: Free> From for $name<$t> { - fn from(value: crate::errors::KeystoneError) -> Self { + impl<$t: Free> From for $name<$t> { + fn from(value: super::errors::KeystoneError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } @@ -488,7 +488,7 @@ macro_rules! make_free_method { app_utils::paste::item! { #[no_mangle] pub extern "C" fn [](ptr: PtrT<$t>) { - check_and_free_ptr!(ptr) + crate::check_and_free_ptr!(ptr) } } }; @@ -496,7 +496,7 @@ macro_rules! make_free_method { app_utils::paste::item! { #[no_mangle] pub extern "C" fn [](ptr: PtrT<$t1<$t2>>) { - check_and_free_ptr!(ptr) + crate::check_and_free_ptr!(ptr) } } }; diff --git a/rust/rust_c/src/common/src/lib.rs b/rust/rust_c/src/common/mod.rs similarity index 98% rename from rust/rust_c/src/common/src/lib.rs rename to rust/rust_c/src/common/mod.rs index f1f972409..840f8894f 100644 --- a/rust/rust_c/src/common/src/lib.rs +++ b/rust/rust_c/src/common/mod.rs @@ -1,9 +1,3 @@ -#![no_std] -#![feature(vec_into_raw_parts)] -#![feature(error_in_core)] -#![allow(unused_unsafe)] -extern crate alloc; - use aes::cipher::block_padding::Pkcs7; use aes::cipher::generic_array::GenericArray; use aes::cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit}; @@ -25,10 +19,10 @@ use errors::ErrorCodes; use structs::{Response, TransactionCheckResult}; use types::Ptr; -use crate::errors::RustCError; -use crate::structs::SimpleResponse; -use crate::types::{PtrBytes, PtrString}; -use crate::utils::{convert_c_char, recover_c_char}; +use errors::RustCError; +use structs::SimpleResponse; +use types::{PtrBytes, PtrString}; +use utils::{convert_c_char, recover_c_char}; pub mod errors; pub mod ffi; diff --git a/rust/rust_c/src/common/src/qrcode/mod.rs b/rust/rust_c/src/common/qrcode/mod.rs similarity index 94% rename from rust/rust_c/src/common/src/qrcode/mod.rs rename to rust/rust_c/src/common/qrcode/mod.rs index faf4353e0..4a132c8ca 100644 --- a/rust/rust_c/src/common/src/qrcode/mod.rs +++ b/rust/rust_c/src/common/qrcode/mod.rs @@ -3,7 +3,7 @@ use seed_signer_message::{MessageEncoding, SeedSignerMessage}; pub mod seed_signer_message; -use crate::{ +use super::{ errors::RustCError, types::{Ptr, PtrString}, ur::URParseResult, @@ -47,8 +47,8 @@ pub extern "C" fn parse_qrcode_text(qr: PtrString) -> Ptr { MessageEncoding::ASCII, ); return URParseResult::single( - crate::ur::ViewType::BtcMsg, - crate::ur::QRCodeType::SeedSignerMessage, + super::ur::ViewType::BtcMsg, + super::ur::QRCodeType::SeedSignerMessage, data, ) .c_ptr(); diff --git a/rust/rust_c/src/common/src/qrcode/seed_signer_message.rs b/rust/rust_c/src/common/qrcode/seed_signer_message.rs similarity index 100% rename from rust/rust_c/src/common/src/qrcode/seed_signer_message.rs rename to rust/rust_c/src/common/qrcode/seed_signer_message.rs diff --git a/rust/rust_c/src/common/src/structs.rs b/rust/rust_c/src/common/structs.rs similarity index 97% rename from rust/rust_c/src/common/src/structs.rs rename to rust/rust_c/src/common/structs.rs index fc081fd76..144b3f333 100644 --- a/rust/rust_c/src/common/src/structs.rs +++ b/rust/rust_c/src/common/structs.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] -use crate::errors::ErrorCodes; -use crate::errors::RustCError; +use super::errors::ErrorCodes; +use super::errors::RustCError; use alloc::boxed::Box; use alloc::string::{String, ToString}; use app_bitcoin::errors::BitcoinError; @@ -12,8 +12,8 @@ use cstr_core::CString; use keystore::errors::KeystoreError; use ur_registry::error::URError; -use crate::free::Free; -use crate::types::{PtrString, PtrT}; +use super::free::Free; +use super::types::{PtrString, PtrT}; use crate::{ check_and_free_ptr, free_str_ptr, impl_c_ptr, impl_new_error, impl_response, impl_simple_c_ptr, impl_simple_new_error, make_free_method, diff --git a/rust/rust_c/src/common/src/types.rs b/rust/rust_c/src/common/types.rs similarity index 95% rename from rust/rust_c/src/common/src/types.rs rename to rust/rust_c/src/common/types.rs index 77ecec753..3c5c0b355 100644 --- a/rust/rust_c/src/common/src/types.rs +++ b/rust/rust_c/src/common/types.rs @@ -1,7 +1,7 @@ use alloc::boxed::Box; use core::ffi::c_void; -use crate::free::Free; +use super::free::Free; use cty::c_char; pub type PtrString = *mut c_char; diff --git a/rust/rust_c/src/common/src/ur.rs b/rust/rust_c/src/common/ur.rs similarity index 99% rename from rust/rust_c/src/common/src/ur.rs rename to rust/rust_c/src/common/ur.rs index 5abc99ddb..3ee8a875e 100644 --- a/rust/rust_c/src/common/src/ur.rs +++ b/rust/rust_c/src/common/ur.rs @@ -59,11 +59,11 @@ use ur_registry::{ cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest, }; -use crate::errors::{ErrorCodes, RustCError}; -use crate::free::Free; -use crate::types::{PtrDecoder, PtrEncoder, PtrString, PtrUR}; -use crate::ur_ext::InferViewType; -use crate::utils::{convert_c_char, recover_c_char}; +use super::errors::{ErrorCodes, RustCError}; +use super::free::Free; +use super::types::{PtrDecoder, PtrEncoder, PtrString, PtrUR}; +use super::ur_ext::InferViewType; +use super::utils::{convert_c_char, recover_c_char}; use crate::{ extract_ptr_with_type, free_ptr_with_type, free_str_ptr, impl_c_ptr, impl_new_error, impl_response, diff --git a/rust/rust_c/src/common/src/ur_ext.rs b/rust/rust_c/src/common/ur_ext.rs similarity index 99% rename from rust/rust_c/src/common/src/ur_ext.rs rename to rust/rust_c/src/common/ur_ext.rs index 07ae1a018..c7c21d95a 100644 --- a/rust/rust_c/src/common/src/ur_ext.rs +++ b/rust/rust_c/src/common/ur_ext.rs @@ -49,7 +49,7 @@ use ur_registry::{ bitcoin::btc_sign_request::BtcSignRequest, sui::sui_sign_hash_request::SuiSignHashRequest, }; -use crate::ur::ViewType; +use super::ur::ViewType; pub trait InferViewType { fn infer(&self) -> Result { @@ -323,8 +323,8 @@ mod tests { use hex::FromHex; use ur_registry::bytes::Bytes; - use crate::ur::ViewType; - use crate::ur_ext::InferViewType; + use super::InferViewType; + use crate::common::ur::ViewType; #[test] fn test_parse_ur_type() { diff --git a/rust/rust_c/src/common/src/utils.rs b/rust/rust_c/src/common/utils.rs similarity index 85% rename from rust/rust_c/src/common/src/utils.rs rename to rust/rust_c/src/common/utils.rs index 643255473..2759b7df1 100644 --- a/rust/rust_c/src/common/src/utils.rs +++ b/rust/rust_c/src/common/utils.rs @@ -2,12 +2,12 @@ use alloc::string::{String, ToString}; use core::slice; use crate::extract_ptr_with_type; -use crate::ffi::CSliceFFI; -use crate::free::Free; +use super::ffi::CSliceFFI; +use super::free::Free; use cstr_core::{CStr, CString}; use cty::c_char; -use crate::types::{PtrString, PtrT}; +use crate::common::types::{PtrString, PtrT}; pub fn convert_c_char(s: String) -> PtrString { CString::new(s.clone()).unwrap().into_raw() diff --git a/rust/rust_c/src/common/src/web_auth.rs b/rust/rust_c/src/common/web_auth.rs similarity index 100% rename from rust/rust_c/src/common/src/web_auth.rs rename to rust/rust_c/src/common/web_auth.rs diff --git a/rust/rust_c/src/cosmos/mod.rs b/rust/rust_c/src/cosmos/mod.rs index 9306d783f..b412e80b8 100644 --- a/rust/rust_c/src/cosmos/mod.rs +++ b/rust/rust_c/src/cosmos/mod.rs @@ -7,12 +7,12 @@ use alloc::vec::Vec; use app_cosmos::errors::CosmosError; use app_cosmos::transaction::structs::SignMode; use app_utils::normalize_path; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use core::slice; use cty::c_char; use either::Either; diff --git a/rust/rust_c/src/cosmos/structs.rs b/rust/rust_c/src/cosmos/structs.rs index 3dff8e20e..d2d2fb495 100644 --- a/rust/rust_c/src/cosmos/structs.rs +++ b/rust/rust_c/src/cosmos/structs.rs @@ -4,11 +4,11 @@ use app_cosmos::transaction::structs::{CosmosTxDisplayType, ParsedCosmosTx}; use core::ptr::null_mut; use serde_json; -use common_rust_c::free::{free_ptr_string, Free}; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, impl_c_ptr, make_free_method}; +use crate::common::free::{free_ptr_string, Free}; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct DisplayCosmosTx { diff --git a/rust/rust_c/src/ethereum/abi.rs b/rust/rust_c/src/ethereum/abi.rs index 223ff412b..677eb0824 100644 --- a/rust/rust_c/src/ethereum/abi.rs +++ b/rust/rust_c/src/ethereum/abi.rs @@ -1,8 +1,8 @@ use super::structs::DisplayContractData; -use common_rust_c::errors::RustCError; -use common_rust_c::structs::Response; -use common_rust_c::types::{Ptr, PtrString}; -use common_rust_c::utils::recover_c_char; +use crate::common::errors::RustCError; +use crate::common::structs::Response; +use crate::common::types::{Ptr, PtrString}; +use crate::common::utils::recover_c_char; use hex; #[no_mangle] diff --git a/rust/rust_c/src/ethereum/address.rs b/rust/rust_c/src/ethereum/address.rs index a5c168ab4..f8d91961e 100644 --- a/rust/rust_c/src/ethereum/address.rs +++ b/rust/rust_c/src/ethereum/address.rs @@ -3,9 +3,9 @@ use app_ethereum; use cty::c_char; use app_ethereum::errors::EthereumError; -use common_rust_c::structs::SimpleResponse; -use common_rust_c::types::PtrString; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::structs::SimpleResponse; +use crate::common::types::PtrString; +use crate::common::utils::{convert_c_char, recover_c_char}; #[no_mangle] pub extern "C" fn eth_get_address( diff --git a/rust/rust_c/src/ethereum/mod.rs b/rust/rust_c/src/ethereum/mod.rs index 99aa9d2f0..a09687721 100644 --- a/rust/rust_c/src/ethereum/mod.rs +++ b/rust/rust_c/src/ethereum/mod.rs @@ -20,15 +20,16 @@ use ur_registry::pb::protoc::payload::Content; use ur_registry::pb::protoc::sign_transaction::Transaction::EthTx; use ur_registry::traits::RegistryItem; -use common_rust_c::errors::{KeystoneError, RustCError}; -use common_rust_c::keystone::build_payload; -use common_rust_c::structs::{TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{ +use crate::common::errors::{KeystoneError, RustCError}; +use crate::common::keystone::build_payload; +use crate::common::structs::{TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{ QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH, }; -use common_rust_c::utils::{convert_c_char, recover_c_char}; -use common_rust_c::{extract_ptr_with_type, KEYSTONE}; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::common::KEYSTONE; +use crate::extract_ptr_with_type; use structs::{ DisplayETH, DisplayETHPersonalMessage, DisplayETHTypedData, EthParsedErc20Transaction, diff --git a/rust/rust_c/src/ethereum/structs.rs b/rust/rust_c/src/ethereum/structs.rs index c2d7f7667..f595fdc87 100644 --- a/rust/rust_c/src/ethereum/structs.rs +++ b/rust/rust_c/src/ethereum/structs.rs @@ -2,17 +2,17 @@ use alloc::boxed::Box; use super::util::{calculate_max_txn_fee, convert_wei_to_eth}; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::structs::{Response, TransactionParseResult}; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; use alloc::string::{String, ToString}; use alloc::vec::Vec; use app_ethereum::abi::{ContractData, ContractMethodParam}; use app_ethereum::erc20::encode_erc20_transfer_calldata; use app_ethereum::structs::{ParsedEthereumTransaction, PersonalMessage, TypedData}; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::Free; -use common_rust_c::structs::{Response, TransactionParseResult}; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; use core::ptr::null_mut; use core::str::FromStr; use itertools::Itertools; diff --git a/rust/rust_c/src/lib.rs b/rust/rust_c/src/lib.rs index b066d5ecb..4abc9335d 100644 --- a/rust/rust_c/src/lib.rs +++ b/rust/rust_c/src/lib.rs @@ -13,7 +13,7 @@ mod allocator; mod my_alloc; #[allow(unused)] -use common_rust_c; +mod common; #[allow(unused)] mod wallet; diff --git a/rust/rust_c/src/near/mod.rs b/rust/rust_c/src/near/mod.rs index 6c63b7f65..5839deafd 100644 --- a/rust/rust_c/src/near/mod.rs +++ b/rust/rust_c/src/near/mod.rs @@ -2,11 +2,11 @@ use structs::DisplayNearTx; use alloc::string::ToString; use alloc::{format, vec}; use app_near::errors::NearError; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use ur_registry::near::near_sign_request::NearSignRequest; use ur_registry::near::near_signature::NearSignature; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/near/structs.rs b/rust/rust_c/src/near/structs.rs index fe2ea7acf..0f8d4afa0 100644 --- a/rust/rust_c/src/near/structs.rs +++ b/rust/rust_c/src/near/structs.rs @@ -1,14 +1,14 @@ +use crate::common::ffi::VecFFI; +use crate::common::free::{free_ptr_string, Free}; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, impl_c_ptrs, make_free_method}; use alloc::boxed::Box; use alloc::string::ToString; use alloc::vec::Vec; use app_near::parser::overview::NearTxOverview; use app_near::parser::structs::{NearTxDisplayType, ParsedNearTx}; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::{free_ptr_string, Free}; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, impl_c_ptrs, make_free_method}; use core::ptr::null_mut; use itertools::Itertools; diff --git a/rust/rust_c/src/simulator/mod.rs b/rust/rust_c/src/simulator/mod.rs index 027a6f8e4..44e6c7b36 100644 --- a/rust/rust_c/src/simulator/mod.rs +++ b/rust/rust_c/src/simulator/mod.rs @@ -1,4 +1,4 @@ -use common_rust_c::utils::convert_c_char; +use crate::common::utils::convert_c_char; use cty::c_char; use sim_qr_reader::*; diff --git a/rust/rust_c/src/solana/mod.rs b/rust/rust_c/src/solana/mod.rs index 7ea96109c..ee30c3940 100644 --- a/rust/rust_c/src/solana/mod.rs +++ b/rust/rust_c/src/solana/mod.rs @@ -3,12 +3,12 @@ use alloc::format; use alloc::string::ToString; use app_solana::errors::SolanaError; use app_solana::parse_message; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use cty::c_char; use ur_registry::solana::sol_sign_request::SolSignRequest; use ur_registry::solana::sol_signature::SolSignature; diff --git a/rust/rust_c/src/solana/structs.rs b/rust/rust_c/src/solana/structs.rs index 7fd34e70d..6e520db7a 100644 --- a/rust/rust_c/src/solana/structs.rs +++ b/rust/rust_c/src/solana/structs.rs @@ -8,12 +8,12 @@ use app_solana::parser::structs::{ParsedSolanaTx, SolanaTxDisplayType}; use app_solana::structs::SolanaMessage; use itertools::Itertools; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, impl_c_ptrs, make_free_method}; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, impl_c_ptrs, make_free_method}; #[repr(C)] pub struct DisplaySolanaTx { diff --git a/rust/rust_c/src/stellar/mod.rs b/rust/rust_c/src/stellar/mod.rs index f8688edfd..8a234eb63 100644 --- a/rust/rust_c/src/stellar/mod.rs +++ b/rust/rust_c/src/stellar/mod.rs @@ -7,12 +7,12 @@ use cty::c_char; use structs::DisplayStellarTx; use app_stellar::strkeys::{sign_hash, sign_signature_base}; use app_stellar::{address::get_address, base_to_xdr}; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use hex; use ur_registry::stellar::stellar_sign_request::{SignType, StellarSignRequest}; use ur_registry::stellar::stellar_signature::StellarSignature; diff --git a/rust/rust_c/src/stellar/structs.rs b/rust/rust_c/src/stellar/structs.rs index 614a6fc57..70426ef50 100644 --- a/rust/rust_c/src/stellar/structs.rs +++ b/rust/rust_c/src/stellar/structs.rs @@ -1,8 +1,8 @@ -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct DisplayStellarTx { diff --git a/rust/rust_c/src/sui/mod.rs b/rust/rust_c/src/sui/mod.rs index cec7ad788..c7b36c5fb 100644 --- a/rust/rust_c/src/sui/mod.rs +++ b/rust/rust_c/src/sui/mod.rs @@ -11,12 +11,12 @@ use ur_registry::traits::RegistryItem; use app_sui::errors::SuiError; use app_utils::normalize_path; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use structs::DisplaySuiSignMessageHash; use structs::DisplaySuiIntentMessage; diff --git a/rust/rust_c/src/sui/structs.rs b/rust/rust_c/src/sui/structs.rs index dc4a8095c..9271c36f5 100644 --- a/rust/rust_c/src/sui/structs.rs +++ b/rust/rust_c/src/sui/structs.rs @@ -2,11 +2,11 @@ use alloc::string::String; use app_sui::Intent; use serde_json; -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct DisplaySuiIntentMessage { diff --git a/rust/rust_c/src/test_cmd/btc_test_cmd.rs b/rust/rust_c/src/test_cmd/btc_test_cmd.rs index b0922b690..b87971c13 100644 --- a/rust/rust_c/src/test_cmd/btc_test_cmd.rs +++ b/rust/rust_c/src/test_cmd/btc_test_cmd.rs @@ -8,15 +8,15 @@ use ur_registry::bytes::Bytes; use ur_registry::crypto_psbt::CryptoPSBT; use ur_registry::traits::RegistryItem; -use common_rust_c::errors::ErrorCodes; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::PtrDecoder; -use common_rust_c::ur::{ +use crate::common::errors::ErrorCodes; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::PtrDecoder; +use crate::common::ur::{ decode_ur, receive, QRCodeType, UREncodeResult, URParseMultiResult, URParseResult, ViewType, FRAGMENT_MAX_LENGTH_DEFAULT, }; -use common_rust_c::utils::convert_c_char; +use crate::common::utils::convert_c_char; use wallet_rust_c::get_connect_blue_wallet_ur; diff --git a/rust/rust_c/src/test_cmd/general_test_cmd.rs b/rust/rust_c/src/test_cmd/general_test_cmd.rs index c1f0db23d..1b0d7add9 100644 --- a/rust/rust_c/src/test_cmd/general_test_cmd.rs +++ b/rust/rust_c/src/test_cmd/general_test_cmd.rs @@ -22,15 +22,15 @@ use ur_registry::near::near_sign_request::NearSignRequest; use ur_registry::solana::sol_sign_request::SolSignRequest; use ur_registry::sui::sui_sign_request::SuiSignRequest; -use common_rust_c::errors::ErrorCodes; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{PtrBytes, PtrDecoder, PtrString}; -use common_rust_c::ur::{ +use crate::common::errors::ErrorCodes; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{PtrBytes, PtrDecoder, PtrString}; +use crate::common::ur::{ decode_ur, receive, QRCodeType, UREncodeResult, URParseMultiResult, URParseResult, ViewType, FRAGMENT_MAX_LENGTH_DEFAULT, }; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::utils::{convert_c_char, recover_c_char}; #[no_mangle] pub extern "C" fn test_get_bch_keystone_succeed_bytes() -> *mut URParseResult { diff --git a/rust/rust_c/src/ton/mod.rs b/rust/rust_c/src/ton/mod.rs index 6ad0a5ddf..b1e21c599 100644 --- a/rust/rust_c/src/ton/mod.rs +++ b/rust/rust_c/src/ton/mod.rs @@ -1,21 +1,21 @@ pub mod structs; -use alloc::{ - boxed::Box, - format, slice, - string::{String, ToString}, - vec::Vec, -}; -use app_ton::{mnemonic::ton_mnemonic_validate, ton_compare_address_and_public_key}; -use common_rust_c::{ +use crate::common::{ errors::RustCError, - extract_ptr_with_type, ffi::VecFFI, - impl_c_ptr, structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}, types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}, ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}, utils::recover_c_char, }; +use alloc::{ + boxed::Box, + format, slice, + string::{String, ToString}, + vec::Vec, +}; +use app_ton::{mnemonic::ton_mnemonic_validate, ton_compare_address_and_public_key}; + +use crate::{extract_ptr_with_type, impl_c_ptr}; use cty::c_char; use keystore::algorithms::ed25519; use rust_tools::convert_c_char; @@ -239,7 +239,7 @@ pub extern "C" fn ton_seed_to_publickey( let public_key = app_ton::mnemonic::ton_master_seed_to_public_key(_seed); SimpleResponse::success(convert_c_char(hex::encode(public_key))).simple_c_ptr() } - Err(_e) => SimpleResponse::from(common_rust_c::errors::RustCError::InvalidData(format!( + Err(_e) => SimpleResponse::from(crate::common::errors::RustCError::InvalidData(format!( "seed length should be 64" ))) .simple_c_ptr(), @@ -255,7 +255,7 @@ pub extern "C" fn ton_get_address(public_key: PtrString) -> *mut SimpleResponse< Err(e) => SimpleResponse::from(e).simple_c_ptr(), }, Err(e) => { - SimpleResponse::from(common_rust_c::errors::RustCError::InvalidHex(e.to_string())) + SimpleResponse::from(crate::common::errors::RustCError::InvalidHex(e.to_string())) .simple_c_ptr() } } diff --git a/rust/rust_c/src/ton/structs.rs b/rust/rust_c/src/ton/structs.rs index e580cd917..f3eb88584 100644 --- a/rust/rust_c/src/ton/structs.rs +++ b/rust/rust_c/src/ton/structs.rs @@ -1,14 +1,13 @@ use core::ptr::null_mut; -use app_ton::structs::{TonProof, TonTransaction}; -use common_rust_c::{ - check_and_free_ptr, +use crate::common::{ free::Free, - free_str_ptr, impl_c_ptr, make_free_method, structs::TransactionParseResult, types::{PtrString, PtrT}, utils::convert_c_char, }; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use app_ton::structs::{TonProof, TonTransaction}; #[repr(C)] pub struct DisplayTonTransaction { diff --git a/rust/rust_c/src/tron/mod.rs b/rust/rust_c/src/tron/mod.rs index 9882c819d..6fc23da01 100644 --- a/rust/rust_c/src/tron/mod.rs +++ b/rust/rust_c/src/tron/mod.rs @@ -3,12 +3,12 @@ pub mod structs; use structs::DisplayTron; use alloc::boxed::Box; use alloc::slice; -use common_rust_c::errors::RustCError; -use common_rust_c::keystone; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{QRCodeType, UREncodeResult}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::common::keystone; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{QRCodeType, UREncodeResult}; +use crate::common::utils::{convert_c_char, recover_c_char}; use cty::c_char; #[no_mangle] diff --git a/rust/rust_c/src/tron/structs.rs b/rust/rust_c/src/tron/structs.rs index ae26ceadd..9a2332ae7 100644 --- a/rust/rust_c/src/tron/structs.rs +++ b/rust/rust_c/src/tron/structs.rs @@ -1,11 +1,11 @@ use alloc::boxed::Box; use app_tron::{DetailTx, OverviewTx, ParsedTx}; -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct DisplayTron { diff --git a/rust/rust_c/src/wallet/btc_only_wallet.rs b/rust/rust_c/src/wallet/btc_only_wallet.rs index f44fd9290..0d09372ac 100644 --- a/rust/rust_c/src/wallet/btc_only_wallet.rs +++ b/rust/rust_c/src/wallet/btc_only_wallet.rs @@ -4,13 +4,13 @@ use alloc::{format, vec}; use app_utils::normalize_path; use bitcoin::bip32::{DerivationPath, Xpub}; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use core::slice; use core::str::FromStr; use cty::{int32_t, uint32_t}; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs index 81677c220..d51cecd5d 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs @@ -9,12 +9,12 @@ use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; use ur_registry::traits::RegistryItem; use app_wallets::aptos::generate_sync_ur; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::PtrT; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::PtrT; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; #[no_mangle] pub extern "C" fn get_connect_aptos_wallet_ur( diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs index ab9d6f600..bba618c1d 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs @@ -1,9 +1,9 @@ use alloc::slice; use alloc::vec::Vec; use app_arweave::generate_public_key_from_primes; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::recover_c_char; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::recover_c_char; use cty::uint32_t; use hex; use ur_registry::arweave::arweave_crypto_account::ArweaveCryptoAccount; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs index fd2664a72..484d6a4ac 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs @@ -1,10 +1,10 @@ use alloc::{format, string::ToString}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{Ptr, PtrBytes}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::recover_c_array; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{Ptr, PtrBytes}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::recover_c_array; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs index ad258565d..99986f7f0 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs @@ -1,10 +1,10 @@ use alloc::{format, string::ToString}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs b/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs index 41cb4ba67..abeb7c4e9 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs @@ -1,10 +1,10 @@ use alloc::format; use alloc::string::ToString; use app_wallets::metamask::ETHAccountTypeApp::Bip44Standard; -use common_rust_c::extract_array; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::UREncodeResult; -use common_rust_c::utils::recover_c_char; +use crate::extract_array; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::UREncodeResult; +use crate::common::utils::recover_c_char; use cty::uint32_t; use ur_registry::crypto_hd_key::CryptoHDKey; use ur_registry::error::URError; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs index 665371b18..6e556da1d 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs @@ -3,11 +3,11 @@ use alloc::format; use alloc::string::ToString; use alloc::vec::Vec; use app_wallets::keplr::{generate_sync_ur, sync_info::SyncInfo}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::types::{PtrBytes, PtrT}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::types::{PtrBytes, PtrT}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use cty::uint32_t; use keystore::algorithms::secp256k1::derive_extend_public_key; use ur_registry::error::URError; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs index 82017e7a3..c00b99756 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs @@ -1,10 +1,10 @@ use alloc::{format, string::ToString}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::error::URError; use super::utils::normalize_xpub; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs index 78082b49d..cadf86106 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs @@ -38,13 +38,13 @@ use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; use ur_registry::extend::qr_hardware_call::QRHardwareCall; use ur_registry::traits::RegistryItem; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::{ExtendedPublicKey, Response}; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; -use common_rust_c::{extract_array, extract_ptr_with_type}; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::{ExtendedPublicKey, Response}; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH}; +use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::{extract_array, extract_ptr_with_type}; use structs::QRHardwareCallData; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs index b41c05d44..79c5e28db 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs @@ -1,10 +1,10 @@ use alloc::{format, string::ToString}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs index 1c364c4a5..7c1bdf0db 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs @@ -8,12 +8,12 @@ use ur_registry::error::URError; use ur_registry::traits::RegistryItem; use app_wallets::solana::generate_sync_ur; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::PtrT; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::PtrT; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; #[no_mangle] diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs b/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs index dc3fa2679..98b1b0fe2 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs @@ -6,13 +6,13 @@ use app_wallets::keplr::sync_info::SyncInfo; use ur_registry::extend::key_derivation_schema::{Curve, DerivationAlgo}; use ur_registry::extend::qr_hardware_call::{CallParams, CallType, QRHardwareCall}; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::Free; -use common_rust_c::structs::Response; -use common_rust_c::types::{Ptr, PtrString, PtrT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::errors::RustCError; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::structs::Response; +use crate::common::types::{Ptr, PtrString, PtrT}; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct KeplrAccount { diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs index 1c09a0122..7a8181135 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs @@ -2,12 +2,12 @@ use alloc::collections::BTreeMap; use alloc::format; use app_wallets::sui::generate_sync_ur; use bitcoin::bip32::DerivationPath; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::PtrT; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::PtrT; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use core::slice; use core::str::FromStr; use hex; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs index 20053bd15..06b844d77 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs @@ -7,11 +7,11 @@ use ur_registry::error::URError; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; use ur_registry::traits::RegistryItem; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{PtrString, PtrT}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use super::utils::normalize_xpub; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs b/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs index 32cff2018..48d7dff8d 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs @@ -1,11 +1,11 @@ -use alloc::string::ToString; -use app_wallets::tonkeeper::{generate_sync_ur, PathInfo}; -use common_rust_c::{ - extract_array, +use crate::common::{ types::{Ptr, PtrBytes, PtrString}, ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}, utils::recover_c_char, }; +use crate::extract_array; +use alloc::string::ToString; +use app_wallets::tonkeeper::{generate_sync_ur, PathInfo}; use { hex, ur_registry::{crypto_hd_key::CryptoHDKey, error::URError, traits::RegistryItem}, diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs b/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs index c7dae7b4d..3eb423dda 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs @@ -3,9 +3,9 @@ use core::str::FromStr; use alloc::vec; use alloc::vec::Vec; use app_utils::normalize_path; -use common_rust_c::errors::RustCError; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::utils::recover_c_char; +use crate::common::errors::RustCError; +use crate::common::structs::ExtendedPublicKey; +use crate::common::utils::recover_c_char; use { bitcoin::bip32::{DerivationPath, Xpub}, hex, diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs index 5ad9dda4c..d7ee10f35 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs @@ -8,12 +8,12 @@ use ur_registry::error::URError; use ur_registry::traits::RegistryItem; use app_wallets::xbull::generate_sync_ur; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::PtrT; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::PtrT; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; #[no_mangle] diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs index 7678da767..d1dc8bd1c 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs @@ -1,7 +1,7 @@ use app_wallets::xrp_toolkit::generate_sync_ur; -use common_rust_c::types::PtrString; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::recover_c_char; +use crate::common::types::PtrString; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::recover_c_char; use ur_registry::bytes::Bytes; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs b/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs index 1b0e71116..85f5a0a12 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs @@ -2,12 +2,12 @@ use alloc::string::ToString; use alloc::vec::Vec; use alloc::{format, slice}; use app_wallets::zcash::{generate_sync_ur, UFVKInfo}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ZcashKey; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ZcashKey; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::bytes::Bytes; use ur_registry::error::URError; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/xrp/mod.rs b/rust/rust_c/src/xrp/mod.rs index ff99ef680..274b6dcf3 100644 --- a/rust/rust_c/src/xrp/mod.rs +++ b/rust/rust_c/src/xrp/mod.rs @@ -17,13 +17,13 @@ use ur_registry::pb::protoc::payload::Content; use ur_registry::pb::protoc::sign_transaction::Transaction::XrpTx; use ur_registry::traits::RegistryItem; -use common_rust_c::errors::{ErrorCodes, KeystoneError, RustCError}; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::keystone::build_payload; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::{ErrorCodes, KeystoneError, RustCError}; +use crate::extract_ptr_with_type; +use crate::common::keystone::build_payload; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use structs::DisplayXrpTx; diff --git a/rust/rust_c/src/xrp/structs.rs b/rust/rust_c/src/xrp/structs.rs index dd68224ca..6535cbd7b 100644 --- a/rust/rust_c/src/xrp/structs.rs +++ b/rust/rust_c/src/xrp/structs.rs @@ -6,11 +6,11 @@ use app_xrp::parser::structs::{ParsedXrpTx, XrpTxDisplayType}; use serde_json; use ur_registry::pb::protoc::XrpTx; -use common_rust_c::free::{free_ptr_string, Free}; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::free::{free_ptr_string, Free}; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct XRPHDPath { diff --git a/rust/rust_c/src/zcash/mod.rs b/rust/rust_c/src/zcash/mod.rs index f66a89c08..95f1b28b6 100644 --- a/rust/rust_c/src/zcash/mod.rs +++ b/rust/rust_c/src/zcash/mod.rs @@ -2,17 +2,15 @@ pub mod structs; use alloc::{boxed::Box, format}; use app_zcash::get_address; -use common_rust_c::{ - check_and_free_ptr, +use crate::common::{ errors::RustCError, - extract_ptr_with_type, free::Free, - make_free_method, structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}, types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}, ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}, utils::{convert_c_char, recover_c_char}, }; +use crate::{extract_ptr_with_type, make_free_method, }; use core::slice; use cty::c_char; use keystore::algorithms::zcash::{calculate_seed_fingerprint, derive_ufvk}; diff --git a/rust/rust_c/src/zcash/structs.rs b/rust/rust_c/src/zcash/structs.rs index 35aadcad7..266d24076 100644 --- a/rust/rust_c/src/zcash/structs.rs +++ b/rust/rust_c/src/zcash/structs.rs @@ -1,18 +1,16 @@ use core::ptr::null_mut; -use alloc::vec::Vec; -use app_zcash::pczt::structs::{ - ParsedFrom, ParsedOrchard, ParsedPczt, ParsedTo, ParsedTransparent, -}; -use common_rust_c::{ - extract_ptr_with_type, +use crate::common::{ ffi::VecFFI, free::Free, - free_ptr_with_type, free_str_ptr, free_vec, impl_c_ptr, impl_c_ptrs, types::{Ptr, PtrString}, utils::convert_c_char, }; - +use crate::{free_ptr_with_type, free_str_ptr, free_vec, impl_c_ptr, impl_c_ptrs}; +use alloc::vec::Vec; +use app_zcash::pczt::structs::{ + ParsedFrom, ParsedOrchard, ParsedPczt, ParsedTo, ParsedTransparent, +}; use cstr_core; #[repr(C)] From 869eb85548b1c4057ec0658604165eb5095517e4 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 17:26:36 +0800 Subject: [PATCH 05/31] chore: refactor cbindgen --- rust/Cargo.lock | 1 - rust/rust_c/Cargo.toml | 6 +- rust/rust_c/build.rs | 74 +- rust/rust_c/cbindgen.toml | 15 + rust/rust_c/librust_c.h | 2433 ++++++++++++++++++++++ rust/rust_c/src/test_cmd/btc_test_cmd.rs | 2 +- rust/zcash_vendor/Cargo.toml | 1 - 7 files changed, 2467 insertions(+), 65 deletions(-) create mode 100644 rust/rust_c/cbindgen.toml create mode 100644 rust/rust_c/librust_c.h diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 0b908bb18..bbb743ccc 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -4841,7 +4841,6 @@ dependencies = [ name = "zcash_vendor" version = "0.1.0" dependencies = [ - "aes", "bech32 0.11.0", "bip32", "bitvec", diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index f1c38a8c4..51aed7047 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -26,8 +26,8 @@ aes = { workspace = true } cbc = { workspace = true } #keystone owned +sim_qr_reader = { workspace = true, optional = true } keystore = { workspace = true } -sim_qr_reader = { workspace = true } ur-registry = { workspace = true } ur-parse-lib = { workspace = true } zcash_vendor = { workspace = true } @@ -36,8 +36,8 @@ app_utils = { workspace = true } rust_tools = { workspace = true } #apps -app_bitcoin = { workspace = true, optional = true } app_wallets = { workspace = true } +app_bitcoin = { workspace = true, optional = true } app_ethereum = { workspace = true, optional = true } app_cardano = { workspace = true, optional = true } app_tron = { workspace = true, optional = true } @@ -58,7 +58,7 @@ crate-type = ["staticlib"] [features] # feature toggles use-allocator = [] -simulator = [] +simulator = ["dep:sim_qr_reader"] aptos = ["dep:app_aptos"] arweave = ["dep:app_arweave"] bitcoin = ["dep:app_bitcoin"] diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index 3f3060fae..18b73f5df 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -1,65 +1,21 @@ fn main() { - return; - let mut config = cbindgen::Config::default(); - config.language = cbindgen::Language::C; - let includes = vec![ - "common_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", - #[cfg(feature = "aptos")] - "aptos_rust_c", - #[cfg(feature = "simulator")] - "simulator_rust_c", - #[cfg(feature = "arweave")] - "arweave_rust_c", - #[cfg(feature = "bitcoin")] - "bitcoin_rust_c", - #[cfg(feature = "cardano")] - "cardano_rust_c", - #[cfg(feature = "cosmos")] - "cosmos_rust_c", - #[cfg(feature = "ethereum")] - "ethereum_rust_c", - #[cfg(feature = "near")] - "near_rust_c", - #[cfg(feature = "solana")] - "solana_rust_c", - #[cfg(feature = "stellar")] - "stellar_rust_c", - #[cfg(feature = "sui")] - "sui_rust_c", - #[cfg(feature = "ton")] - "ton_rust_c", - #[cfg(feature = "tron")] - "tron_rust_c", - #[cfg(feature = "xrp")] - "xrp_rust_c", - #[cfg(feature = "zcash")] - "zcash_rust_c", - #[cfg(feature = "test_cmd")] - "test_cmd_rust_c", - #[cfg(feature = "test_cmd")] - "btc_test_cmd_rust_c", - #[cfg(feature = "test_cmd")] - "general_test_cmd_rust_c", - ]; - - let crates = includes - .into_iter() - .map(|s| s.to_string()) - .collect::>(); - - config.parse.include = Some(crates.clone()); - config.parse.parse_deps = true; - config.parse.expand.crates = crates; + let mut config = + cbindgen::Config::from_file("cbindgen.toml").expect("Failed to read cbindgen.toml"); let features = vec![ - #[cfg(feature = "btc-only")] - "btc_only", - #[cfg(feature = "multi-coins")] - "multi_coins", + #[cfg(feature = "production-multi-coins")] + "production-multi-coins", + #[cfg(feature = "production-btc-only")] + "production-btc-only", + #[cfg(feature = "simulator-multi-coins")] + "simulator-multi-coins", + #[cfg(feature = "simulator-btc-only")] + "simulator-btc-only", + #[cfg(feature = "debug-multi-coins")] + "debug-multi-coins", + #[cfg(feature = "debug-btc-only")] + "debug-btc-only", ]; - + println!("cargo:warning={}", format!("features: {:?}", features)); config.parse.expand.features = Some(features.into_iter().map(|s| s.to_string()).collect()); let builder = cbindgen::Builder::new(); diff --git a/rust/rust_c/cbindgen.toml b/rust/rust_c/cbindgen.toml new file mode 100644 index 000000000..75a59cfd1 --- /dev/null +++ b/rust/rust_c/cbindgen.toml @@ -0,0 +1,15 @@ +include_guard = "_LIBRUST_C_H" + +after_includes = "#define BUILD_MULTI_COINS\n#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" + +language = "C" + +[defines] +"feature = multi-coins" = "BUILD_MULTI_COINS" + +[parse] +extra_bindings = ["rust_c"] + +[parse.expand] +crates = ["rust_c"] +default_features = false \ No newline at end of file diff --git a/rust/rust_c/librust_c.h b/rust/rust_c/librust_c.h new file mode 100644 index 000000000..ef0e43e32 --- /dev/null +++ b/rust/rust_c/librust_c.h @@ -0,0 +1,2433 @@ +#ifndef _LIBRUST_C_H +#define _LIBRUST_C_H + +#include +#include +#include +#include +#define BUILD_MULTI_COINS +#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048 +#define ADDRESS_MAX_LEN 256 +#define PATH_ITEM_MAX_LEN 32 + +typedef enum ArweaveRequestType { + ArweaveRequestTypeTransaction = 1, + ArweaveRequestTypeDataItem, + ArweaveRequestTypeMessage, + ArweaveRequestTypeUnknown, +} ArweaveRequestType; + +#if defined(BUILD_MULTI_COINS) +typedef enum ETHAccountType { +#if defined(BUILD_MULTI_COINS) + Bip44Standard, +#endif +#if defined(BUILD_MULTI_COINS) + LedgerLive, +#endif +#if defined(BUILD_MULTI_COINS) + LedgerLegacy, +#endif +} ETHAccountType; +#endif + +typedef enum ErrorCodes { + Success = 0, + InvalidMasterFingerprint, + MasterFingerprintMismatch, + InvalidHDPath, + UnsupportedTransaction, + InvalidXPub, + SignFailure, + UnexpectedError, + InvalidHex, + WebAuthFailed, + InvalidData, + CborDecodeError = 20, + CborEncodeError, + URDecodeError, + UREncodeError, + NotSupportURTypeError, + NotAnUr, + URTypeUnspecified, + URProtobufDecodeError, + URProtobufEncodeError, + URGzipDecodeError, + URGzipEnCodeError, + KeystoreSeedError = 40, + KeystoreDerivationError, + KeystoreXPubError, + KeystoreInvalidDerivationPath, + KeystoreDeivePubkey, + KeystoreGenerateSigningKeyError, + KeystoreRSASignError, + KeystoreRSAVerifyError, + KeystoreInvalidDataError, + KeystoreZcashOrchardSignError, + BitcoinInvalidInput = 100, + BitcoinInvalidOutput, + BitcoinInvalidPsbt, + BitcoinInvalidTransaction, + BitcoinNoInputs, + BitcoinNoOutputs, + BitcoinNoMyInputs, + BitcoinInputValueTampered, + BitcoinSignFailure, + BitcoinAddressError, + BitcoinGetKeyError, + BitcoinSignLegacyTxError, + BitcoinUnsupportedTransaction, + BitcoinUnsupportedNetwork, + BitcoinTransactionConsensusEncodeError, + BitcoinPushBytesFailed, + BitcoinInvalidHex, + BitcoinBase58Error, + BitcoinKeystoreError, + BitcoinInvalidParseContext, + BitcoinInvalidRawTxCryptoBytes, + BitcoinInvalidTxData, + BitcoinUnsupportedScriptType, + BitcoinBech32DecodeError, + BitcoinWitnessProgramError, + BitcoinMultiSigWalletParseError, + BitcoinMultiSigWalletNotMyWallet, + BitcoinMultiSigWalletAddressCalError, + BitcoinMultiSigWalletImportXpubError, + BitcoinMultiSigWalletCrateError, + BitcoinMultiSigWalletFormatError, + BitcoinMultiSigNetworkError, + BitcoinMultiSigInputError, + BitcoinDerivePublicKeyError, + BitcoinWalletTypeError, + EthereumRlpDecodingError = 200, + EthereumInvalidTransaction, + EthereumSignFailure, + EthereumInvalidHDPath, + EthereumKeystoreError, + EthereumInvalidAddressError, + EthereumInvalidUtf8Error, + EthereumInvalidContractABI, + EthereumDecodeContractDataError, + EthereumInvalidTypedData, + EthereumHashTypedDataError, + TronInvalidRawTxCryptoBytes = 300, + TronInvalidParseContext, + TronBase58Error, + TronSignFailure, + TronProtobufError, + TronParseNumberError, + TronNoMyInputs, + CompanionAppProtobufError = 400, + CompanionAppInvalidParseContext, + CompanionAppSignTxFailed, + CompanionAppCheckTxFailed, + CardanoInvalidTransaction = 500, + CardanoAddressEncodingError, + SolanaAddressEncodingError = 600, + SolanaKeystoreError, + SolanaUnsupportedProgram, + SolanaInvalidData, + SolanaAccountNotFound, + SolanaProgramError, + SolanaParseTxError, + NearKeystoreError = 700, + NearSignFailure, + NearParseTxError, + XRPSignFailure = 800, + XRPInvalidData, + XRPParseTxError, + CosmosSignFailure = 900, + CosmosKeystoreError, + CosmosInvalidData, + CosmosParseTxError, + AptosSignFailure = 1000, + AptosKeystoreError, + AptosInvalidData, + AptosParseTxError, + SuiSignFailure = 1100, + SuiInvalidData, + SuiParseTxError, + ArweaveSignFailure = 1200, + ArweaveKeystoreError, + ArweaveInvalidData, + ArweaveParseTxError, + ArweaveParseAOTxError, + TonUnknownError = 1300, + TonMnemonicError, + TonTransactionError, + InvalidProof, + TonTransactionJsonError, + AddressError, + StellarAddressError = 1400, + StellarInvalidData, + StellarParseTxError, + StellarKeystoreError, + ZcashGenerateAddressError = 1500, + ZcashSigningError, + ZcashInvalidPczt, +} ErrorCodes; + +typedef enum NetworkType { + MainNet, + TestNet, +} NetworkType; + +typedef enum QRCodeType { + CryptoPSBT, + CryptoMultiAccounts, + CryptoAccount, + Bytes, + BtcSignRequest, + SeedSignerMessage, +#if defined(BUILD_MULTI_COINS) + KeystoneSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + EthSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + SolSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + NearSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoSignTxHashRequest, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoSignDataRequest, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoCatalystVotingRegistrationRequest, +#endif +#if defined(BUILD_MULTI_COINS) + CosmosSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + EvmSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + SuiSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + SuiSignHashRequest, +#endif +#if defined(BUILD_MULTI_COINS) + AptosSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + QRHardwareCall, +#endif +#if defined(BUILD_MULTI_COINS) + ArweaveSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + StellarSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + TonSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + ZcashPczt, +#endif + URTypeUnKnown, +} QRCodeType; + +typedef enum QRProtocol { + QRCodeTypeText, + QRCodeTypeUR, +} QRProtocol; + +typedef enum ViewType { + BtcNativeSegwitTx, + BtcSegwitTx, + BtcLegacyTx, + BtcTx, + BtcMsg, +#if defined(BUILD_MULTI_COINS) + LtcTx, +#endif +#if defined(BUILD_MULTI_COINS) + DashTx, +#endif +#if defined(BUILD_MULTI_COINS) + BchTx, +#endif +#if defined(BUILD_MULTI_COINS) + EthTx, +#endif +#if defined(BUILD_MULTI_COINS) + EthPersonalMessage, +#endif +#if defined(BUILD_MULTI_COINS) + EthTypedData, +#endif +#if defined(BUILD_MULTI_COINS) + TronTx, +#endif +#if defined(BUILD_MULTI_COINS) + SolanaTx, +#endif +#if defined(BUILD_MULTI_COINS) + SolanaMessage, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoTx, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoSignData, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoCatalystVotingRegistration, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoSignTxHash, +#endif +#if defined(BUILD_MULTI_COINS) + NearTx, +#endif +#if defined(BUILD_MULTI_COINS) + XRPTx, +#endif +#if defined(BUILD_MULTI_COINS) + CosmosTx, +#endif +#if defined(BUILD_MULTI_COINS) + CosmosEvmTx, +#endif +#if defined(BUILD_MULTI_COINS) + SuiTx, +#endif +#if defined(BUILD_MULTI_COINS) + SuiSignMessageHash, +#endif +#if defined(BUILD_MULTI_COINS) + ArweaveTx, +#endif +#if defined(BUILD_MULTI_COINS) + ArweaveMessage, +#endif +#if defined(BUILD_MULTI_COINS) + ArweaveDataItem, +#endif +#if defined(BUILD_MULTI_COINS) + StellarTx, +#endif +#if defined(BUILD_MULTI_COINS) + StellarHash, +#endif +#if defined(BUILD_MULTI_COINS) + TonTx, +#endif +#if defined(BUILD_MULTI_COINS) + TonSignProof, +#endif +#if defined(BUILD_MULTI_COINS) + ZcashTx, +#endif +#if defined(BUILD_MULTI_COINS) + AptosTx, +#endif + WebAuthResult, +#if defined(BUILD_MULTI_COINS) + KeyDerivationRequest, +#endif + ViewTypeUnKnown, +} ViewType; + +typedef char *PtrString; + +typedef struct SimpleResponse_u8 { + uint8_t *data; + uint32_t error_code; + PtrString error_message; +} SimpleResponse_u8; + +typedef uint8_t *PtrBytes; + +typedef struct SimpleResponse_c_char { + char *data; + uint32_t error_code; + PtrString error_message; +} SimpleResponse_c_char; + +typedef struct TransactionCheckResult { + uint32_t error_code; + PtrString error_message; +} TransactionCheckResult; + +typedef struct TransactionCheckResult *Ptr_TransactionCheckResult; + +typedef void *PtrVoid; + +typedef PtrVoid PtrUR; + +typedef PtrVoid PtrDecoder; + +typedef struct URParseResult { + bool is_multi_part; + uint32_t progress; + enum ViewType t; + enum QRCodeType ur_type; + PtrUR data; + PtrDecoder decoder; + uint32_t error_code; + PtrString error_message; +} URParseResult; + +typedef struct URParseResult *PtrT_URParseResult; + +typedef struct URParseMultiResult { + bool is_complete; + enum ViewType t; + enum QRCodeType ur_type; + uint32_t progress; + PtrUR data; + uint32_t error_code; + PtrString error_message; +} URParseMultiResult; + +typedef struct URParseMultiResult *PtrT_URParseMultiResult; + +typedef PtrVoid PtrEncoder; + +typedef struct UREncodeResult { + bool is_multi_part; + char *data; + PtrEncoder encoder; + uint32_t error_code; + char *error_message; +} UREncodeResult; + +typedef struct UREncodeResult *PtrT_UREncodeResult; + +typedef struct UREncodeMultiResult { + char *data; + uint32_t error_code; + char *error_message; +} UREncodeMultiResult; + +typedef struct UREncodeMultiResult *PtrT_UREncodeMultiResult; + +typedef struct SimpleResponse_u8 *PtrT_SimpleResponse_u8; + +typedef struct SimpleResponse_c_char *PtrT_SimpleResponse_c_char; + +typedef uint8_t *PtrT_u8; + +typedef struct VecFFI_u8 { + PtrT_u8 data; + size_t size; + size_t cap; +} VecFFI_u8; + +typedef struct VecFFI_u8 *PtrT_VecFFI_u8; + +typedef struct URParseResult *Ptr_URParseResult; + +typedef struct TransactionCheckResult *PtrT_TransactionCheckResult; + +typedef const void *ConstPtrVoid; + +typedef ConstPtrVoid ConstPtrUR; + +typedef struct ExtendedPublicKey { + PtrString path; + PtrString xpub; +} ExtendedPublicKey; + +typedef struct ExtendedPublicKey *PtrT_ExtendedPublicKey; + +typedef struct CSliceFFI_ExtendedPublicKey { + PtrT_ExtendedPublicKey data; + size_t size; +} CSliceFFI_ExtendedPublicKey; + +typedef struct CSliceFFI_ExtendedPublicKey *PtrT_CSliceFFI_ExtendedPublicKey; + +typedef struct AccountConfig { + PtrString hd_path; + PtrString x_pub; + int32_t address_length; + bool is_multi_sign; +} AccountConfig; + +typedef struct CoinConfig { + bool is_active; + PtrString coin_code; + struct AccountConfig *accounts; + uint32_t accounts_length; +} CoinConfig; + +typedef struct CoinConfig *PtrT_CoinConfig; + +typedef struct UREncodeResult *Ptr_UREncodeResult; + +typedef struct CSliceFFI_ExtendedPublicKey *Ptr_CSliceFFI_ExtendedPublicKey; + +#if defined(BUILD_MULTI_COINS) +typedef struct KeyDerivationSchema { + PtrString key_path; + PtrString curve; + PtrString algo; + PtrString chain_type; + bool is_ada; +} KeyDerivationSchema; +#endif + +typedef struct KeyDerivationSchema *PtrT_KeyDerivationSchema; + +typedef struct VecFFI_KeyDerivationSchema { + PtrT_KeyDerivationSchema data; + size_t size; + size_t cap; +} VecFFI_KeyDerivationSchema; + +typedef struct VecFFI_KeyDerivationSchema *Ptr_VecFFI_KeyDerivationSchema; + +#if defined(BUILD_MULTI_COINS) +typedef struct KeyDerivationRequestData { + Ptr_VecFFI_KeyDerivationSchema schemas; +} KeyDerivationRequestData; +#endif + +typedef struct KeyDerivationRequestData *Ptr_KeyDerivationRequestData; + +#if defined(BUILD_MULTI_COINS) +typedef struct QRHardwareCallData { + PtrString call_type; + PtrString origin; + Ptr_KeyDerivationRequestData key_derivation; + PtrString version; +} QRHardwareCallData; +#endif + +typedef struct Response_QRHardwareCallData { + struct QRHardwareCallData *data; + uint32_t error_code; + PtrString error_message; +} Response_QRHardwareCallData; + +typedef struct Response_QRHardwareCallData *Ptr_Response_QRHardwareCallData; + +typedef struct Response_bool { + bool *data; + uint32_t error_code; + PtrString error_message; +} Response_bool; + +#if defined(BUILD_MULTI_COINS) +typedef struct KeplrAccount { + PtrString name; + PtrString path; + PtrString xpub; +} KeplrAccount; +#endif + +typedef struct KeplrAccount *PtrT_KeplrAccount; + +typedef struct CSliceFFI_KeplrAccount { + PtrT_KeplrAccount data; + size_t size; +} CSliceFFI_KeplrAccount; + +typedef struct CSliceFFI_KeplrAccount *PtrT_CSliceFFI_KeplrAccount; + +typedef struct Response_QRHardwareCallData *PtrT_Response_QRHardwareCallData; + +typedef struct ZcashKey { + PtrString key_text; + PtrString key_name; + uint32_t index; +} ZcashKey; + +typedef struct ZcashKey *PtrT_ZcashKey; + +typedef struct CSliceFFI_ZcashKey { + PtrT_ZcashKey data; + size_t size; +} CSliceFFI_ZcashKey; + +typedef struct CSliceFFI_ZcashKey *Ptr_CSliceFFI_ZcashKey; + +typedef struct DisplayAptosTx { + PtrString detail; + bool is_msg; +} DisplayAptosTx; + +typedef struct TransactionParseResult_DisplayAptosTx { + struct DisplayAptosTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayAptosTx; + +typedef struct TransactionParseResult_DisplayAptosTx *PtrT_TransactionParseResult_DisplayAptosTx; + +typedef struct SimpleResponse_ArweaveRequestType { + enum ArweaveRequestType *data; + uint32_t error_code; + PtrString error_message; +} SimpleResponse_ArweaveRequestType; + +typedef struct DisplayArweaveMessage { + PtrString message; + PtrString raw_message; +} DisplayArweaveMessage; + +typedef struct TransactionParseResult_DisplayArweaveMessage { + struct DisplayArweaveMessage *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayArweaveMessage; + +typedef struct TransactionParseResult_DisplayArweaveMessage *PtrT_TransactionParseResult_DisplayArweaveMessage; + +typedef struct DisplayArweaveTx { + PtrString value; + PtrString fee; + PtrString from; + PtrString to; + PtrString detail; +} DisplayArweaveTx; + +typedef struct TransactionParseResult_DisplayArweaveTx { + struct DisplayArweaveTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayArweaveTx; + +typedef struct TransactionParseResult_DisplayArweaveTx *PtrT_TransactionParseResult_DisplayArweaveTx; + +typedef struct DisplayTag { + PtrString name; + PtrString value; +} DisplayTag; + +typedef struct DisplayTag *PtrT_DisplayTag; + +typedef struct VecFFI_DisplayTag { + PtrT_DisplayTag data; + size_t size; + size_t cap; +} VecFFI_DisplayTag; + +typedef struct VecFFI_DisplayTag *Ptr_VecFFI_DisplayTag; + +typedef struct DisplayArweaveDataItem { + PtrString owner; + PtrString target; + PtrString anchor; + Ptr_VecFFI_DisplayTag tags; + PtrString data; +} DisplayArweaveDataItem; + +typedef struct TransactionParseResult_DisplayArweaveDataItem { + struct DisplayArweaveDataItem *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayArweaveDataItem; + +typedef struct TransactionParseResult_DisplayArweaveDataItem *PtrT_TransactionParseResult_DisplayArweaveDataItem; + +typedef struct DisplayArweaveAOTransfer { + PtrString from; + PtrString to; + PtrString quantity; + PtrString token_id; + Ptr_VecFFI_DisplayTag other_info; +} DisplayArweaveAOTransfer; + +typedef struct TransactionParseResult_DisplayArweaveAOTransfer { + struct DisplayArweaveAOTransfer *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayArweaveAOTransfer; + +typedef struct TransactionParseResult_DisplayArweaveAOTransfer *PtrT_TransactionParseResult_DisplayArweaveAOTransfer; + +typedef struct DisplayTxOverviewInput { + PtrString address; +} DisplayTxOverviewInput; + +typedef struct DisplayTxOverviewInput *PtrT_DisplayTxOverviewInput; + +typedef struct VecFFI_DisplayTxOverviewInput { + PtrT_DisplayTxOverviewInput data; + size_t size; + size_t cap; +} VecFFI_DisplayTxOverviewInput; + +typedef struct VecFFI_DisplayTxOverviewInput *PtrT_VecFFI_DisplayTxOverviewInput; + +typedef struct DisplayTxOverviewOutput { + PtrString address; +} DisplayTxOverviewOutput; + +typedef struct DisplayTxOverviewOutput *PtrT_DisplayTxOverviewOutput; + +typedef struct VecFFI_DisplayTxOverviewOutput { + PtrT_DisplayTxOverviewOutput data; + size_t size; + size_t cap; +} VecFFI_DisplayTxOverviewOutput; + +typedef struct VecFFI_DisplayTxOverviewOutput *PtrT_VecFFI_DisplayTxOverviewOutput; + +typedef struct DisplayTxOverview { + PtrString total_output_amount; + PtrString fee_amount; + PtrString total_output_sat; + PtrString fee_sat; + PtrT_VecFFI_DisplayTxOverviewInput from; + PtrT_VecFFI_DisplayTxOverviewOutput to; + PtrString network; + bool is_multisig; + bool fee_larger_than_amount; + PtrString sign_status; + bool need_sign; +} DisplayTxOverview; + +typedef struct DisplayTxDetailInput { + bool has_address; + PtrString address; + PtrString amount; + bool is_mine; + PtrString path; + bool is_external; +} DisplayTxDetailInput; + +typedef struct DisplayTxDetailInput *PtrT_DisplayTxDetailInput; + +typedef struct VecFFI_DisplayTxDetailInput { + PtrT_DisplayTxDetailInput data; + size_t size; + size_t cap; +} VecFFI_DisplayTxDetailInput; + +typedef struct VecFFI_DisplayTxDetailInput *PtrT_VecFFI_DisplayTxDetailInput; + +typedef struct DisplayTxDetailOutput { + PtrString address; + PtrString amount; + bool is_mine; + PtrString path; + bool is_external; +} DisplayTxDetailOutput; + +typedef struct DisplayTxDetailOutput *PtrT_DisplayTxDetailOutput; + +typedef struct VecFFI_DisplayTxDetailOutput { + PtrT_DisplayTxDetailOutput data; + size_t size; + size_t cap; +} VecFFI_DisplayTxDetailOutput; + +typedef struct VecFFI_DisplayTxDetailOutput *PtrT_VecFFI_DisplayTxDetailOutput; + +typedef struct DisplayTxDetail { + PtrString total_input_amount; + PtrString total_output_amount; + PtrString fee_amount; + PtrT_VecFFI_DisplayTxDetailInput from; + PtrT_VecFFI_DisplayTxDetailOutput to; + PtrString network; + PtrString total_input_sat; + PtrString total_output_sat; + PtrString fee_sat; + PtrString sign_status; +} DisplayTxDetail; + +typedef struct DisplayTx { + struct DisplayTxOverview *overview; + struct DisplayTxDetail *detail; +} DisplayTx; + +typedef struct TransactionParseResult_DisplayTx { + struct DisplayTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayTx; + +typedef struct DisplayBtcMsg { + PtrString detail; + PtrString address; +} DisplayBtcMsg; + +typedef struct TransactionParseResult_DisplayBtcMsg { + struct DisplayBtcMsg *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayBtcMsg; + +typedef struct TransactionParseResult_DisplayBtcMsg *Ptr_TransactionParseResult_DisplayBtcMsg; + +typedef PtrString *PtrT_PtrString; + +typedef struct VecFFI_PtrString { + PtrT_PtrString data; + size_t size; + size_t cap; +} VecFFI_PtrString; + +typedef struct VecFFI_PtrString *PtrT_VecFFI_PtrString; + +typedef struct MultiSigXPubItem { + PtrString xfp; + PtrString xpub; +} MultiSigXPubItem; + +typedef struct MultiSigXPubItem *PtrT_MultiSigXPubItem; + +typedef struct VecFFI_MultiSigXPubItem { + PtrT_MultiSigXPubItem data; + size_t size; + size_t cap; +} VecFFI_MultiSigXPubItem; + +typedef struct VecFFI_MultiSigXPubItem *PtrT_VecFFI_MultiSigXPubItem; + +typedef struct MultiSigWallet { + PtrString creator; + PtrString name; + PtrString policy; + uint32_t threshold; + uint32_t total; + PtrT_VecFFI_PtrString derivations; + PtrString format; + PtrT_VecFFI_MultiSigXPubItem xpub_items; + PtrString verify_code; + PtrString config_text; + uint32_t network; +} MultiSigWallet; + +typedef struct MultiSigWallet *PtrT_MultiSigWallet; + +typedef struct Response_MultiSigWallet { + struct MultiSigWallet *data; + uint32_t error_code; + PtrString error_message; +} Response_MultiSigWallet; + +typedef struct Response_MultiSigWallet *Ptr_Response_MultiSigWallet; + +typedef struct SimpleResponse_c_char *Ptr_SimpleResponse_c_char; + +typedef struct MultiSigXPubInfoItem { + PtrString path; + PtrString xfp; + PtrString xpub; +} MultiSigXPubInfoItem; + +typedef struct MultiSigXPubInfoItem *PtrT_MultiSigXPubInfoItem; + +typedef struct MultisigSignResult { + Ptr_UREncodeResult ur_result; + PtrString sign_status; + bool is_completed; + PtrBytes psbt_hex; + uint32_t psbt_len; +} MultisigSignResult; + +typedef struct MultisigSignResult *PtrT_MultisigSignResult; + +typedef struct PsbtSignResult { + PtrString base_str; + PtrString hex_str; + PtrT_UREncodeResult ur_result; +} PsbtSignResult; + +typedef struct Response_PsbtSignResult { + struct PsbtSignResult *data; + uint32_t error_code; + PtrString error_message; +} Response_PsbtSignResult; + +typedef struct Response_PsbtSignResult *PtrT_Response_PsbtSignResult; + +typedef struct TransactionParseResult_DisplayTx *PtrT_TransactionParseResult_DisplayTx; + +typedef struct TransactionParseResult_DisplayBtcMsg *PtrT_TransactionParseResult_DisplayBtcMsg; + +typedef struct VecFFI_PtrString *Ptr_VecFFI_PtrString; + +typedef struct DisplayCardanoSignTxHash { + PtrString network; + Ptr_VecFFI_PtrString path; + PtrString tx_hash; + Ptr_VecFFI_PtrString address_list; +} DisplayCardanoSignTxHash; + +typedef struct TransactionParseResult_DisplayCardanoSignTxHash { + struct DisplayCardanoSignTxHash *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayCardanoSignTxHash; + +typedef struct TransactionParseResult_DisplayCardanoSignTxHash *PtrT_TransactionParseResult_DisplayCardanoSignTxHash; + +typedef struct DisplayCardanoSignData { + PtrString payload; + PtrString derivation_path; + PtrString message_hash; + PtrString xpub; +} DisplayCardanoSignData; + +typedef struct TransactionParseResult_DisplayCardanoSignData { + struct DisplayCardanoSignData *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayCardanoSignData; + +typedef struct TransactionParseResult_DisplayCardanoSignData *PtrT_TransactionParseResult_DisplayCardanoSignData; + +typedef struct DisplayCardanoCatalyst { + PtrString nonce; + PtrString stake_key; + PtrString rewards; + Ptr_VecFFI_PtrString vote_keys; +} DisplayCardanoCatalyst; + +typedef struct TransactionParseResult_DisplayCardanoCatalyst { + struct DisplayCardanoCatalyst *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayCardanoCatalyst; + +typedef struct TransactionParseResult_DisplayCardanoCatalyst *PtrT_TransactionParseResult_DisplayCardanoCatalyst; + +typedef struct DisplayCardanoFrom { + PtrString address; + PtrString amount; + bool has_path; + PtrString path; +} DisplayCardanoFrom; + +typedef struct DisplayCardanoFrom *PtrT_DisplayCardanoFrom; + +typedef struct VecFFI_DisplayCardanoFrom { + PtrT_DisplayCardanoFrom data; + size_t size; + size_t cap; +} VecFFI_DisplayCardanoFrom; + +typedef struct VecFFI_DisplayCardanoFrom *PtrT_VecFFI_DisplayCardanoFrom; + +typedef struct DisplayCardanoTo { + PtrString address; + PtrString amount; + bool has_assets; + PtrString assets_text; +} DisplayCardanoTo; + +typedef struct DisplayCardanoTo *PtrT_DisplayCardanoTo; + +typedef struct VecFFI_DisplayCardanoTo { + PtrT_DisplayCardanoTo data; + size_t size; + size_t cap; +} VecFFI_DisplayCardanoTo; + +typedef struct VecFFI_DisplayCardanoTo *PtrT_VecFFI_DisplayCardanoTo; + +typedef struct DisplayCertField { + PtrString label; + PtrString value; +} DisplayCertField; + +typedef struct DisplayCertField *PtrT_DisplayCertField; + +typedef struct VecFFI_DisplayCertField { + PtrT_DisplayCertField data; + size_t size; + size_t cap; +} VecFFI_DisplayCertField; + +typedef struct VecFFI_DisplayCertField *Ptr_VecFFI_DisplayCertField; + +typedef struct DisplayCardanoCertificate { + PtrString cert_type; + Ptr_VecFFI_DisplayCertField fields; +} DisplayCardanoCertificate; + +typedef struct DisplayCardanoCertificate *PtrT_DisplayCardanoCertificate; + +typedef struct VecFFI_DisplayCardanoCertificate { + PtrT_DisplayCardanoCertificate data; + size_t size; + size_t cap; +} VecFFI_DisplayCardanoCertificate; + +typedef struct VecFFI_DisplayCardanoCertificate *Ptr_VecFFI_DisplayCardanoCertificate; + +typedef struct DisplayCardanoWithdrawal { + PtrString address; + PtrString amount; +} DisplayCardanoWithdrawal; + +typedef struct DisplayCardanoWithdrawal *PtrT_DisplayCardanoWithdrawal; + +typedef struct VecFFI_DisplayCardanoWithdrawal { + PtrT_DisplayCardanoWithdrawal data; + size_t size; + size_t cap; +} VecFFI_DisplayCardanoWithdrawal; + +typedef struct VecFFI_DisplayCardanoWithdrawal *Ptr_VecFFI_DisplayCardanoWithdrawal; + +typedef struct DisplayVotingProcedure { + PtrString voter; + PtrString transaction_id; + PtrString index; + PtrString vote; +} DisplayVotingProcedure; + +typedef struct DisplayVotingProcedure *PtrT_DisplayVotingProcedure; + +typedef struct VecFFI_DisplayVotingProcedure { + PtrT_DisplayVotingProcedure data; + size_t size; + size_t cap; +} VecFFI_DisplayVotingProcedure; + +typedef struct VecFFI_DisplayVotingProcedure *Ptr_VecFFI_DisplayVotingProcedure; + +typedef struct DisplayVotingProposal { + PtrString anchor; +} DisplayVotingProposal; + +typedef struct DisplayVotingProposal *PtrT_DisplayVotingProposal; + +typedef struct VecFFI_DisplayVotingProposal { + PtrT_DisplayVotingProposal data; + size_t size; + size_t cap; +} VecFFI_DisplayVotingProposal; + +typedef struct VecFFI_DisplayVotingProposal *Ptr_VecFFI_DisplayVotingProposal; + +typedef struct DisplayCardanoTx { + PtrT_VecFFI_DisplayCardanoFrom from; + PtrT_VecFFI_DisplayCardanoTo to; + PtrString fee; + PtrString network; + PtrString total_input; + PtrString total_output; + Ptr_VecFFI_DisplayCardanoCertificate certificates; + Ptr_VecFFI_DisplayCardanoWithdrawal withdrawals; + PtrString auxiliary_data; + Ptr_VecFFI_DisplayVotingProcedure voting_procedures; + Ptr_VecFFI_DisplayVotingProposal voting_proposals; +} DisplayCardanoTx; + +typedef struct TransactionParseResult_DisplayCardanoTx { + struct DisplayCardanoTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayCardanoTx; + +typedef struct TransactionParseResult_DisplayCardanoTx *PtrT_TransactionParseResult_DisplayCardanoTx; + +typedef struct DisplayCosmosTxOverview { + PtrString display_type; + PtrString method; + PtrString network; + PtrString send_value; + PtrString send_from; + PtrString send_to; + PtrString delegate_value; + PtrString delegate_from; + PtrString delegate_to; + PtrString undelegate_value; + PtrString undelegate_to; + PtrString undelegate_validator; + PtrString redelegate_value; + PtrString redelegate_to; + PtrString redelegate_new_validator; + PtrString withdraw_reward_to; + PtrString withdraw_reward_validator; + PtrString transfer_from; + PtrString transfer_to; + PtrString transfer_value; + PtrString vote_voted; + PtrString vote_proposal; + PtrString vote_voter; + PtrString overview_list; +} DisplayCosmosTxOverview; + +typedef struct DisplayCosmosTxOverview *PtrT_DisplayCosmosTxOverview; + +typedef struct DisplayCosmosTx { + PtrT_DisplayCosmosTxOverview overview; + PtrString detail; +} DisplayCosmosTx; + +typedef struct TransactionParseResult_DisplayCosmosTx { + struct DisplayCosmosTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayCosmosTx; + +typedef struct TransactionParseResult_DisplayCosmosTx *PtrT_TransactionParseResult_DisplayCosmosTx; + +typedef struct DisplayETHOverview { + PtrString value; + PtrString max_txn_fee; + PtrString gas_price; + PtrString gas_limit; + PtrString from; + PtrString to; +} DisplayETHOverview; + +typedef struct DisplayETHOverview *PtrT_DisplayETHOverview; + +typedef struct DisplayETHDetail { + PtrString value; + PtrString max_txn_fee; + PtrString max_fee; + PtrString max_priority; + PtrString max_fee_price; + PtrString max_priority_price; + PtrString gas_price; + PtrString gas_limit; + PtrString from; + PtrString to; + PtrString input; +} DisplayETHDetail; + +typedef struct DisplayETHDetail *PtrT_DisplayETHDetail; + +typedef struct DisplayETH { + PtrString tx_type; + uint64_t chain_id; + PtrT_DisplayETHOverview overview; + PtrT_DisplayETHDetail detail; +} DisplayETH; + +typedef struct TransactionParseResult_DisplayETH { + struct DisplayETH *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayETH; + +typedef struct TransactionParseResult_DisplayETH *PtrT_TransactionParseResult_DisplayETH; + +typedef struct DisplayETHPersonalMessage { + PtrString raw_message; + PtrString utf8_message; + PtrString from; +} DisplayETHPersonalMessage; + +typedef struct TransactionParseResult_DisplayETHPersonalMessage { + struct DisplayETHPersonalMessage *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayETHPersonalMessage; + +typedef struct TransactionParseResult_DisplayETHPersonalMessage *PtrT_TransactionParseResult_DisplayETHPersonalMessage; + +typedef struct DisplayETHTypedData { + PtrString name; + PtrString version; + PtrString chain_id; + PtrString verifying_contract; + PtrString salt; + PtrString primary_type; + PtrString message; + PtrString from; +} DisplayETHTypedData; + +typedef struct TransactionParseResult_DisplayETHTypedData { + struct DisplayETHTypedData *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayETHTypedData; + +typedef struct TransactionParseResult_DisplayETHTypedData *PtrT_TransactionParseResult_DisplayETHTypedData; + +typedef struct EthParsedErc20Transaction { + PtrString to; + PtrString value; +} EthParsedErc20Transaction; + +typedef struct TransactionParseResult_EthParsedErc20Transaction { + struct EthParsedErc20Transaction *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_EthParsedErc20Transaction; + +typedef struct TransactionParseResult_EthParsedErc20Transaction *PtrT_TransactionParseResult_EthParsedErc20Transaction; + +typedef struct DisplayContractParam { + PtrString name; + PtrString value; +} DisplayContractParam; + +typedef struct DisplayContractParam *PtrT_DisplayContractParam; + +typedef struct VecFFI_DisplayContractParam { + PtrT_DisplayContractParam data; + size_t size; + size_t cap; +} VecFFI_DisplayContractParam; + +typedef struct VecFFI_DisplayContractParam *PtrT_VecFFI_DisplayContractParam; + +typedef struct DisplayContractData { + PtrString contract_name; + PtrString method_name; + PtrT_VecFFI_DisplayContractParam params; +} DisplayContractData; + +typedef struct Response_DisplayContractData { + struct DisplayContractData *data; + uint32_t error_code; + PtrString error_message; +} Response_DisplayContractData; + +typedef struct Response_DisplayContractData *Ptr_Response_DisplayContractData; + +typedef struct Response_DisplayContractData *PtrT_Response_DisplayContractData; + +typedef struct DisplayNearTxOverviewGeneralAction { + PtrString action; +} DisplayNearTxOverviewGeneralAction; + +typedef struct DisplayNearTxOverviewGeneralAction *PtrT_DisplayNearTxOverviewGeneralAction; + +typedef struct VecFFI_DisplayNearTxOverviewGeneralAction { + PtrT_DisplayNearTxOverviewGeneralAction data; + size_t size; + size_t cap; +} VecFFI_DisplayNearTxOverviewGeneralAction; + +typedef struct VecFFI_DisplayNearTxOverviewGeneralAction *PtrT_VecFFI_DisplayNearTxOverviewGeneralAction; + +typedef struct DisplayNearTxOverview { + PtrString display_type; + PtrString main_action; + PtrString transfer_value; + PtrString transfer_from; + PtrString transfer_to; + PtrT_VecFFI_DisplayNearTxOverviewGeneralAction action_list; +} DisplayNearTxOverview; + +typedef struct DisplayNearTxOverview *PtrT_DisplayNearTxOverview; + +typedef struct DisplayNearTx { + PtrString network; + PtrT_DisplayNearTxOverview overview; + PtrString detail; +} DisplayNearTx; + +typedef struct TransactionParseResult_DisplayNearTx { + struct DisplayNearTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayNearTx; + +typedef struct TransactionParseResult_DisplayNearTx *PtrT_TransactionParseResult_DisplayNearTx; + +typedef struct DisplaySolanaTxOverviewVotesOn { + PtrString slot; +} DisplaySolanaTxOverviewVotesOn; + +typedef struct DisplaySolanaTxOverviewVotesOn *PtrT_DisplaySolanaTxOverviewVotesOn; + +typedef struct VecFFI_DisplaySolanaTxOverviewVotesOn { + PtrT_DisplaySolanaTxOverviewVotesOn data; + size_t size; + size_t cap; +} VecFFI_DisplaySolanaTxOverviewVotesOn; + +typedef struct VecFFI_DisplaySolanaTxOverviewVotesOn *PtrT_VecFFI_DisplaySolanaTxOverviewVotesOn; + +typedef struct DisplaySolanaTxOverviewGeneral { + PtrString program; + PtrString method; +} DisplaySolanaTxOverviewGeneral; + +typedef struct DisplaySolanaTxOverviewGeneral *PtrT_DisplaySolanaTxOverviewGeneral; + +typedef struct VecFFI_DisplaySolanaTxOverviewGeneral { + PtrT_DisplaySolanaTxOverviewGeneral data; + size_t size; + size_t cap; +} VecFFI_DisplaySolanaTxOverviewGeneral; + +typedef struct VecFFI_DisplaySolanaTxOverviewGeneral *PtrT_VecFFI_DisplaySolanaTxOverviewGeneral; + +typedef struct Instruction { + PtrT_VecFFI_PtrString accounts; + PtrString data; + PtrString program_address; +} Instruction; + +typedef struct Instruction *PtrT_Instruction; + +typedef struct VecFFI_Instruction { + PtrT_Instruction data; + size_t size; + size_t cap; +} VecFFI_Instruction; + +typedef struct VecFFI_Instruction *PtrT_VecFFI_Instruction; + +typedef struct DisplaySolanaTxOverviewUnknownInstructions { + PtrT_VecFFI_PtrString overview_accounts; + PtrT_VecFFI_Instruction overview_instructions; +} DisplaySolanaTxOverviewUnknownInstructions; + +typedef struct DisplaySolanaTxOverviewUnknownInstructions *PtrT_DisplaySolanaTxOverviewUnknownInstructions; + +typedef struct ProgramOverviewTransfer { + PtrString value; + PtrString main_action; + PtrString from; + PtrString to; +} ProgramOverviewTransfer; + +typedef struct ProgramOverviewTransfer *PtrT_ProgramOverviewTransfer; + +typedef struct VecFFI_ProgramOverviewTransfer { + PtrT_ProgramOverviewTransfer data; + size_t size; + size_t cap; +} VecFFI_ProgramOverviewTransfer; + +typedef struct VecFFI_ProgramOverviewTransfer *PtrT_VecFFI_ProgramOverviewTransfer; + +typedef struct DisplaySolanaTxOverviewSquadsV4MultisigCreate { + PtrString wallet_name; + PtrString wallet_desc; + uint16_t threshold; + uintptr_t member_count; + PtrT_VecFFI_PtrString members; + PtrString total_value; + PtrT_VecFFI_ProgramOverviewTransfer transfers; +} DisplaySolanaTxOverviewSquadsV4MultisigCreate; + +typedef struct DisplaySolanaTxOverviewSquadsV4MultisigCreate *PtrT_DisplaySolanaTxOverviewSquadsV4MultisigCreate; + +typedef struct DisplaySolanaTxProposalOverview { + PtrString program; + PtrString method; + PtrString memo; + PtrString data; +} DisplaySolanaTxProposalOverview; + +typedef struct DisplaySolanaTxProposalOverview *PtrT_DisplaySolanaTxProposalOverview; + +typedef struct VecFFI_DisplaySolanaTxProposalOverview { + PtrT_DisplaySolanaTxProposalOverview data; + size_t size; + size_t cap; +} VecFFI_DisplaySolanaTxProposalOverview; + +typedef struct VecFFI_DisplaySolanaTxProposalOverview *PtrT_VecFFI_DisplaySolanaTxProposalOverview; + +typedef struct DisplaySolanaTxSplTokenTransferOverview { + PtrString source; + PtrString destination; + PtrString authority; + uint8_t decimals; + PtrString amount; + PtrString token_mint_account; + PtrString token_symbol; + PtrString token_name; +} DisplaySolanaTxSplTokenTransferOverview; + +typedef struct DisplaySolanaTxSplTokenTransferOverview *PtrT_DisplaySolanaTxSplTokenTransferOverview; + +typedef struct JupiterV6SwapTokenInfoOverview { + PtrString token_name; + PtrString token_symbol; + PtrString token_address; + PtrString token_amount; + bool exist_in_address_lookup_table; +} JupiterV6SwapTokenInfoOverview; + +typedef struct JupiterV6SwapTokenInfoOverview *PtrT_JupiterV6SwapTokenInfoOverview; + +typedef struct DisplaySolanaTxOverviewJupiterV6Swap { + PtrString program_name; + PtrString program_address; + PtrString instruction_name; + PtrT_JupiterV6SwapTokenInfoOverview token_a_overview; + PtrT_JupiterV6SwapTokenInfoOverview token_b_overview; + PtrString slippage_bps; + PtrString platform_fee_bps; +} DisplaySolanaTxOverviewJupiterV6Swap; + +typedef struct DisplaySolanaTxOverviewJupiterV6Swap *PtrT_DisplaySolanaTxOverviewJupiterV6Swap; + +typedef struct DisplaySolanaTxOverview { + PtrString display_type; + PtrString main_action; + PtrString transfer_value; + PtrString transfer_from; + PtrString transfer_to; + PtrT_VecFFI_DisplaySolanaTxOverviewVotesOn votes_on; + PtrString vote_account; + PtrT_VecFFI_DisplaySolanaTxOverviewGeneral general; + PtrT_DisplaySolanaTxOverviewUnknownInstructions unknown_instructions; + PtrT_DisplaySolanaTxOverviewSquadsV4MultisigCreate squads_multisig_create; + PtrT_VecFFI_DisplaySolanaTxProposalOverview squads_proposal; + PtrT_DisplaySolanaTxSplTokenTransferOverview spl_token_transfer; + PtrT_DisplaySolanaTxOverviewJupiterV6Swap jupiter_v6_swap; +} DisplaySolanaTxOverview; + +typedef struct DisplaySolanaTxOverview *PtrT_DisplaySolanaTxOverview; + +typedef struct DisplaySolanaTx { + PtrString network; + PtrT_DisplaySolanaTxOverview overview; + PtrString detail; +} DisplaySolanaTx; + +typedef struct TransactionParseResult_DisplaySolanaTx { + struct DisplaySolanaTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplaySolanaTx; + +typedef struct TransactionParseResult_DisplaySolanaTx *PtrT_TransactionParseResult_DisplaySolanaTx; + +typedef struct DisplaySolanaMessage { + PtrString raw_message; + PtrString utf8_message; + PtrString from; +} DisplaySolanaMessage; + +typedef struct TransactionParseResult_DisplaySolanaMessage { + struct DisplaySolanaMessage *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplaySolanaMessage; + +typedef struct TransactionParseResult_DisplaySolanaMessage *PtrT_TransactionParseResult_DisplaySolanaMessage; + +typedef struct DisplayStellarTx { + PtrString raw_message; +} DisplayStellarTx; + +typedef struct TransactionParseResult_DisplayStellarTx { + struct DisplayStellarTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayStellarTx; + +typedef struct TransactionParseResult_DisplayStellarTx *PtrT_TransactionParseResult_DisplayStellarTx; + +typedef struct DisplaySuiIntentMessage { + PtrString detail; +} DisplaySuiIntentMessage; + +typedef struct TransactionParseResult_DisplaySuiIntentMessage { + struct DisplaySuiIntentMessage *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplaySuiIntentMessage; + +typedef struct TransactionParseResult_DisplaySuiIntentMessage *PtrT_TransactionParseResult_DisplaySuiIntentMessage; + +typedef struct DisplaySuiSignMessageHash { + PtrString network; + PtrString path; + PtrString from_address; + PtrString message; +} DisplaySuiSignMessageHash; + +typedef struct TransactionParseResult_DisplaySuiSignMessageHash { + struct DisplaySuiSignMessageHash *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplaySuiSignMessageHash; + +typedef struct TransactionParseResult_DisplaySuiSignMessageHash *PtrT_TransactionParseResult_DisplaySuiSignMessageHash; + +typedef struct DisplayTonTransaction { + PtrString amount; + PtrString action; + PtrString to; + PtrString comment; + PtrString data_view; + PtrString raw_data; + PtrString contract_data; +} DisplayTonTransaction; + +typedef struct TransactionParseResult_DisplayTonTransaction { + struct DisplayTonTransaction *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayTonTransaction; + +typedef struct TransactionParseResult_DisplayTonTransaction *PtrT_TransactionParseResult_DisplayTonTransaction; + +typedef struct DisplayTonProof { + PtrString domain; + PtrString payload; + PtrString address; + PtrString raw_message; +} DisplayTonProof; + +typedef struct TransactionParseResult_DisplayTonProof { + struct DisplayTonProof *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayTonProof; + +typedef struct TransactionParseResult_DisplayTonProof *PtrT_TransactionParseResult_DisplayTonProof; + +typedef struct VecFFI_u8 *Ptr_VecFFI_u8; + +typedef struct DisplayTronOverview { + PtrString value; + PtrString method; + PtrString from; + PtrString to; + PtrString network; +} DisplayTronOverview; + +typedef struct DisplayTronDetail { + PtrString value; + PtrString method; + PtrString from; + PtrString to; + PtrString network; + PtrString token; + PtrString contract_address; +} DisplayTronDetail; + +typedef struct DisplayTron { + struct DisplayTronOverview *overview; + struct DisplayTronDetail *detail; +} DisplayTron; + +typedef struct TransactionParseResult_DisplayTron { + struct DisplayTron *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayTron; + +typedef struct TransactionParseResult_DisplayTron *PtrT_TransactionParseResult_DisplayTron; + +typedef struct DisplayXrpTxOverview { + PtrString display_type; + PtrString transaction_type; + PtrString from; + PtrString fee; + PtrString sequence; + PtrString value; + PtrString to; +} DisplayXrpTxOverview; + +typedef struct DisplayXrpTxOverview *PtrT_DisplayXrpTxOverview; + +typedef struct DisplayXrpTx { + PtrString network; + PtrT_DisplayXrpTxOverview overview; + PtrString detail; + PtrString signing_pubkey; +} DisplayXrpTx; + +typedef struct TransactionParseResult_DisplayXrpTx { + struct DisplayXrpTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayXrpTx; + +typedef struct TransactionParseResult_DisplayXrpTx *PtrT_TransactionParseResult_DisplayXrpTx; + +typedef struct DisplayFrom { + PtrString address; + PtrString value; + bool is_mine; +} DisplayFrom; + +typedef struct DisplayFrom *PtrT_DisplayFrom; + +typedef struct VecFFI_DisplayFrom { + PtrT_DisplayFrom data; + size_t size; + size_t cap; +} VecFFI_DisplayFrom; + +typedef struct VecFFI_DisplayFrom *Ptr_VecFFI_DisplayFrom; + +typedef struct DisplayTo { + PtrString address; + PtrString value; + bool is_change; + PtrString memo; +} DisplayTo; + +typedef struct DisplayTo *PtrT_DisplayTo; + +typedef struct VecFFI_DisplayTo { + PtrT_DisplayTo data; + size_t size; + size_t cap; +} VecFFI_DisplayTo; + +typedef struct VecFFI_DisplayTo *Ptr_VecFFI_DisplayTo; + +typedef struct DisplayTransparent { + Ptr_VecFFI_DisplayFrom from; + Ptr_VecFFI_DisplayTo to; +} DisplayTransparent; + +typedef struct DisplayTransparent *Ptr_DisplayTransparent; + +typedef struct DisplayOrchard { + Ptr_VecFFI_DisplayFrom from; + Ptr_VecFFI_DisplayTo to; +} DisplayOrchard; + +typedef struct DisplayOrchard *Ptr_DisplayOrchard; + +typedef struct DisplayPczt { + Ptr_DisplayTransparent transparent; + Ptr_DisplayOrchard orchard; + PtrString total_transfer_value; + PtrString fee_value; + bool has_sapling; +} DisplayPczt; + +typedef struct TransactionParseResult_DisplayPczt { + struct DisplayPczt *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayPczt; + +typedef struct TransactionParseResult_DisplayPczt *Ptr_TransactionParseResult_DisplayPczt; + +typedef struct TransactionParseResult_DisplayPczt *PtrT_TransactionParseResult_DisplayPczt; + +extern const uintptr_t FRAGMENT_MAX_LENGTH_DEFAULT; + +extern void LogRustMalloc(void *p, uint32_t size); + +extern void LogRustFree(void *p); + +extern void LogRustPanic(char *p); + +extern int32_t GenerateTRNGRandomness(uint8_t *randomness, uint8_t len); + +extern void *RustMalloc(int32_t size); + +extern void RustFree(void *p); + +struct SimpleResponse_u8 *get_master_fingerprint(PtrBytes seed, uint32_t seed_len); + +enum ErrorCodes dummy_function_to_export_error_codes(void); + +struct SimpleResponse_c_char *get_extended_pubkey_by_seed(PtrBytes seed, + uint32_t seed_len, + PtrString path); + +struct SimpleResponse_c_char *get_extended_pubkey_bytes_by_seed(PtrBytes seed, + uint32_t seed_len, + PtrString path); + +struct SimpleResponse_c_char *get_ed25519_pubkey_by_seed(PtrBytes seed, + uint32_t seed_len, + PtrString path); + +struct SimpleResponse_u8 *get_rsa_pubkey_by_seed(PtrBytes seed, uint32_t seed_len); + +struct SimpleResponse_c_char *get_bip32_ed25519_extended_pubkey(PtrBytes entropy, + uint32_t entropy_len, + PtrString passphrase, + PtrString path); + +struct SimpleResponse_c_char *get_ledger_bitbox02_master_key(PtrString mnemonic, + PtrString passphrase); + +struct SimpleResponse_c_char *get_icarus_master_key(PtrBytes entropy, + uint32_t entropy_len, + PtrString passphrase); + +struct SimpleResponse_c_char *derive_bip32_ed25519_extended_pubkey(PtrString master_key, + PtrString path); + +struct SimpleResponse_c_char *k1_sign_message_hash_by_private_key(PtrBytes private_key, + PtrBytes message_hash); + +bool k1_verify_signature(PtrBytes signature, PtrBytes message_hash, PtrBytes public_key); + +struct SimpleResponse_u8 *k1_generate_ecdh_sharekey(PtrBytes privkey, + uint32_t privkey_len, + PtrBytes pubkey, + uint32_t pubkey_len); + +struct SimpleResponse_u8 *k1_generate_pubkey_by_privkey(PtrBytes privkey, uint32_t privkey_len); + +struct SimpleResponse_u8 *pbkdf2_rust(PtrBytes password, PtrBytes salt, uint32_t iterations); + +struct SimpleResponse_u8 *pbkdf2_rust_64(PtrBytes password, PtrBytes salt, uint32_t iterations); + +Ptr_TransactionCheckResult tx_check_pass(void); + +struct SimpleResponse_c_char *rust_aes256_cbc_encrypt(PtrString data, + PtrString password, + PtrBytes iv, + uint32_t iv_len); + +struct SimpleResponse_c_char *rust_aes256_cbc_decrypt(PtrString hex_data, + PtrString password, + PtrBytes iv, + uint32_t iv_len); + +struct SimpleResponse_u8 *rust_derive_iv_from_seed(PtrBytes seed, uint32_t seed_len); + +void free_ur_parse_result(PtrT_URParseResult ur_parse_result); + +void free_ur_parse_multi_result(PtrT_URParseMultiResult ptr); + +void free_ur_encode_result(PtrT_UREncodeResult ptr); + +void free_ur_encode_muilt_result(PtrT_UREncodeMultiResult ptr); + +void free_simple_response_u8(PtrT_SimpleResponse_u8 ptr); + +void free_simple_response_c_char(PtrT_SimpleResponse_c_char ptr); + +void free_ptr_string(PtrString ptr); + +void free_rust_value(void *any_ptr); + +void free_VecFFI_u8(PtrT_VecFFI_u8 ptr); + +enum QRProtocol infer_qrcode_type(PtrString qrcode); + +Ptr_URParseResult parse_qrcode_text(PtrString qr); + +void free_TransactionCheckResult(PtrT_TransactionCheckResult ptr); + +struct UREncodeMultiResult *get_next_part(PtrEncoder ptr); + +struct URParseResult *parse_ur(PtrString ur); + +struct URParseMultiResult *receive(PtrString ur, PtrDecoder decoder); + +PtrString calculate_auth_code(ConstPtrUR web_auth_data, + PtrBytes rsa_key_n, + uint32_t rsa_key_n_len, + PtrBytes rsa_key_d, + uint32_t rsa_key_d_len); + +struct UREncodeResult *get_connect_blue_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); + +struct UREncodeResult *get_connect_sparrow_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); + +struct UREncodeResult *get_connect_specter_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); + +PtrT_UREncodeResult get_connect_companion_app_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + int32_t cold_version, + PtrT_CoinConfig coin_config, + uint32_t coin_config_length); + +Ptr_UREncodeResult get_okx_wallet_ur_btc_only(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString serial_number, + Ptr_CSliceFFI_ExtendedPublicKey public_keys, + PtrString device_type, + PtrString device_version); + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_metamask_ur_dynamic(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + enum ETHAccountType account_type, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + uintptr_t fragment_max_length_default, + uintptr_t fragment_max_length_other); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_metamask_ur_unlimited(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + enum ETHAccountType account_type, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_metamask_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + enum ETHAccountType account_type, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_Response_QRHardwareCallData parse_qr_hardware_call(PtrUR ur); +#endif + +#if defined(BUILD_MULTI_COINS) +struct Response_bool *check_hardware_call_path(PtrString path, PtrString chain_type); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult generate_key_derivation_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + Ptr_CSliceFFI_ExtendedPublicKey xpubs, + PtrString device_version); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_aptos_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_connect_arconnect_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrBytes p, + uint32_t p_len, + PtrBytes q, + uint32_t q_len); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_connect_arconnect_wallet_ur_from_xpub(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString xpub); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_backpack_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + Ptr_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_bitget_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString serial_number, + Ptr_CSliceFFI_ExtendedPublicKey public_keys, + PtrString device_type, + PtrString device_version); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_connect_imtoken_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString xpub, + PtrString wallet_name); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_keplr_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrT_CSliceFFI_KeplrAccount keplr_accounts); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_keystone_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString serial_number, + Ptr_CSliceFFI_ExtendedPublicKey public_keys, + PtrString device_type, + PtrString device_version); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_okx_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString serial_number, + Ptr_CSliceFFI_ExtendedPublicKey public_keys, + PtrString device_type, + PtrString device_version); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_solana_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +void free_Response_QRHardwareCallData(PtrT_Response_QRHardwareCallData ptr); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_sui_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_tonkeeper_wallet_ur(PtrString public_key, + PtrString wallet_name, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString path); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_xbull_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_xrp_toolkit_ur(PtrString hd_path, + PtrString root_x_pub, + PtrString root_path); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_zcash_wallet_ur(PtrBytes seed_fingerprint, + uint32_t seed_fingerprint_len, + Ptr_CSliceFFI_ZcashKey zcash_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_thor_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrString serial_number, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + PtrString device_type, + PtrString device_version); +#endif + +struct SimpleResponse_c_char *aptos_generate_address(PtrString pub_key); + +PtrT_TransactionCheckResult aptos_check_request(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length); + +PtrT_TransactionParseResult_DisplayAptosTx aptos_parse(PtrUR ptr); + +PtrT_UREncodeResult aptos_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len, PtrString pub_key); + +PtrString aptos_get_path(PtrUR ptr); + +struct SimpleResponse_c_char *test_aptos_parse(void); + +void free_TransactionParseResult_DisplayAptosTx(PtrT_TransactionParseResult_DisplayAptosTx ptr); + +struct SimpleResponse_u8 *generate_arweave_secret(PtrBytes seed, uint32_t seed_len); + +struct SimpleResponse_u8 *generate_arweave_public_key_from_primes(PtrBytes p, + uint32_t p_len, + PtrBytes q, + uint32_t q_len); + +struct SimpleResponse_c_char *generate_rsa_public_key(PtrBytes p, + uint32_t p_len, + PtrBytes q, + uint32_t q_len); + +struct SimpleResponse_u8 *aes256_encrypt_primes(PtrBytes seed, uint32_t seed_len, PtrBytes data); + +struct SimpleResponse_u8 *aes256_decrypt_primes(PtrBytes seed, uint32_t seed_len, PtrBytes data); + +struct SimpleResponse_c_char *arweave_get_address(PtrString xpub); + +struct SimpleResponse_c_char *fix_arweave_address(PtrString address); + +PtrT_TransactionCheckResult ar_check_tx(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); + +struct SimpleResponse_ArweaveRequestType *ar_request_type(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayArweaveMessage ar_message_parse(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayArweaveTx ar_parse(PtrUR ptr); + +PtrT_UREncodeResult ar_sign_tx(PtrUR ptr, PtrBytes p, uint32_t p_len, PtrBytes q, uint32_t q_len); + +bool ar_is_ao_transfer(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayArweaveDataItem ar_parse_data_item(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayArweaveAOTransfer ar_parse_ao_transfer(PtrUR ptr); + +void free_TransactionParseResult_DisplayArweaveTx(PtrT_TransactionParseResult_DisplayArweaveTx ptr); + +void free_TransactionParseResult_DisplayArweaveMessage(PtrT_TransactionParseResult_DisplayArweaveMessage ptr); + +struct SimpleResponse_c_char *utxo_get_address(PtrString hd_path, PtrString x_pub); + +struct SimpleResponse_c_char *xpub_convert_version(PtrString x_pub, PtrString target); + +struct TransactionParseResult_DisplayTx *utxo_parse_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub); + +struct UREncodeResult *utxo_sign_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub, + int32_t cold_version, + PtrBytes seed, + uint32_t seed_len); + +PtrT_TransactionCheckResult utxo_check_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub); + +PtrT_TransactionCheckResult btc_check_msg(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); + +struct TransactionParseResult_DisplayBtcMsg *btc_parse_msg(PtrUR ptr, + Ptr_CSliceFFI_ExtendedPublicKey xpubs, + PtrBytes master_fingerprint, + uint32_t length); + +struct UREncodeResult *btc_sign_msg(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +Ptr_TransactionParseResult_DisplayBtcMsg parse_seed_signer_message(PtrUR ptr, + Ptr_CSliceFFI_ExtendedPublicKey xpubs); + +struct UREncodeResult *sign_seed_signer_message(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +struct UREncodeResult *export_multi_sig_xpub_by_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + enum NetworkType network); + +struct UREncodeResult *export_multi_sig_wallet_by_ur_test(uint8_t *master_fingerprint, + uint32_t length, + PtrT_MultiSigWallet multi_sig_wallet); + +struct UREncodeResult *export_multi_sig_wallet_by_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrString config); + +Ptr_Response_MultiSigWallet import_multi_sig_wallet_by_ur(PtrUR ur, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +Ptr_Response_MultiSigWallet import_multi_sig_wallet_by_file(PtrString content, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +Ptr_SimpleResponse_c_char generate_address_for_multisig_wallet_config(PtrString wallet_config, + uint32_t account, + uint32_t index, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +Ptr_SimpleResponse_c_char generate_psbt_file_name(PtrBytes psbt_hex, + uint32_t psbt_len, + uint32_t time_stamp); + +Ptr_Response_MultiSigWallet parse_and_verify_multisig_config(PtrBytes seed, + uint32_t seed_len, + PtrString wallet_config, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +void free_MultiSigXPubInfoItem(PtrT_MultiSigXPubInfoItem ptr); + +void free_MultiSigWallet(PtrT_MultiSigWallet ptr); + +void free_MultisigSignResult(PtrT_MultisigSignResult ptr); + +struct TransactionParseResult_DisplayTx *btc_parse_psbt(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + PtrString multisig_wallet_config); + +struct UREncodeResult *btc_sign_psbt(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +struct UREncodeResult *btc_sign_psbt_unlimited(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +struct MultisigSignResult *btc_sign_multisig_psbt(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +struct MultisigSignResult *btc_export_multisig_psbt(PtrUR ptr); + +struct MultisigSignResult *btc_export_multisig_psbt_bytes(PtrBytes psbt_bytes, + uint32_t psbt_bytes_length); + +PtrT_TransactionCheckResult btc_check_psbt(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + PtrString verify_code, + PtrString multisig_wallet_config); + +PtrT_TransactionCheckResult btc_check_psbt_bytes(PtrBytes psbt_bytes, + uint32_t psbt_bytes_length, + PtrBytes master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + PtrString verify_code, + PtrString multisig_wallet_config); + +struct TransactionParseResult_DisplayTx *btc_parse_psbt_bytes(PtrBytes psbt_bytes, + uint32_t psbt_bytes_length, + PtrBytes master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + PtrString multisig_wallet_config); + +struct MultisigSignResult *btc_sign_multisig_psbt_bytes(PtrBytes psbt_bytes, + uint32_t psbt_bytes_length, + PtrBytes seed, + uint32_t seed_len, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +void free_Response_PsbtSignResult(PtrT_Response_PsbtSignResult ptr); + +void free_TransactionParseResult_DisplayTx(PtrT_TransactionParseResult_DisplayTx ptr); + +void free_TransactionParseResult_DisplayBtcMsg(PtrT_TransactionParseResult_DisplayBtcMsg ptr); + +Ptr_SimpleResponse_c_char cardano_catalyst_xpub(PtrUR ptr); + +PtrT_TransactionCheckResult cardano_check_catalyst(PtrUR ptr, PtrBytes master_fingerprint); + +PtrT_TransactionCheckResult cardano_check_catalyst_path_type(PtrUR ptr, PtrString cardano_xpub); + +Ptr_SimpleResponse_c_char cardano_get_catalyst_root_index(PtrUR ptr); + +Ptr_SimpleResponse_c_char cardano_get_sign_data_root_index(PtrUR ptr); + +PtrT_TransactionCheckResult cardano_check_sign_data_path_type(PtrUR ptr, PtrString cardano_xpub); + +PtrT_TransactionCheckResult cardano_check_sign_data(PtrUR ptr, PtrBytes master_fingerprint); + +PtrT_TransactionCheckResult cardano_check_tx(PtrUR ptr, + PtrBytes master_fingerprint, + PtrString cardano_xpub); + +PtrT_TransactionCheckResult cardano_check_tx_hash(PtrUR ptr, PtrBytes master_fingerprint); + +PtrT_TransactionParseResult_DisplayCardanoSignTxHash cardano_parse_sign_tx_hash(PtrUR ptr); + +Ptr_SimpleResponse_c_char cardano_get_path(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayCardanoSignData cardano_parse_sign_data(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayCardanoCatalyst cardano_parse_catalyst(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayCardanoTx cardano_parse_tx(PtrUR ptr, + PtrBytes master_fingerprint, + PtrString cardano_xpub); + +PtrT_UREncodeResult cardano_sign_catalyst_with_ledger_bitbox02(PtrUR ptr, + PtrString mnemonic, + PtrString passphrase); + +PtrT_UREncodeResult cardano_sign_catalyst(PtrUR ptr, + PtrBytes entropy, + uint32_t entropy_len, + PtrString passphrase); + +PtrT_UREncodeResult cardano_sign_sign_data_with_ledger_bitbox02(PtrUR ptr, + PtrString mnemonic, + PtrString passphrase); + +PtrT_UREncodeResult cardano_sign_sign_data(PtrUR ptr, + PtrBytes entropy, + uint32_t entropy_len, + PtrString passphrase); + +PtrT_UREncodeResult cardano_sign_tx_with_ledger_bitbox02(PtrUR ptr, + PtrBytes master_fingerprint, + PtrString cardano_xpub, + PtrString mnemonic, + PtrString passphrase, + bool enable_blind_sign); + +PtrT_UREncodeResult cardano_sign_tx(PtrUR ptr, + PtrBytes master_fingerprint, + PtrString cardano_xpub, + PtrBytes entropy, + uint32_t entropy_len, + PtrString passphrase, + bool enable_blind_sign); + +struct SimpleResponse_c_char *cardano_get_base_address(PtrString xpub, + uint32_t index, + uint8_t network_id); + +struct SimpleResponse_c_char *cardano_get_enterprise_address(PtrString xpub, + uint32_t index, + uint8_t network_id); + +struct SimpleResponse_c_char *cardano_get_stake_address(PtrString xpub, + uint32_t index, + uint8_t network_id); + +void free_TransactionParseResult_DisplayCardanoTx(PtrT_TransactionParseResult_DisplayCardanoTx ptr); + +void free_TransactionParseResult_DisplayCardanoCatalyst(PtrT_TransactionParseResult_DisplayCardanoCatalyst ptr); + +void free_TransactionParseResult_DisplayCardanoSignData(PtrT_TransactionParseResult_DisplayCardanoSignData ptr); + +void free_TransactionParseResult_DisplayCardanoSignTxHash(PtrT_TransactionParseResult_DisplayCardanoSignTxHash ptr); + +PtrT_TransactionCheckResult cosmos_check_tx(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length); + +struct SimpleResponse_c_char *cosmos_get_address(PtrString hd_path, + PtrString root_x_pub, + PtrString root_path, + PtrString prefix); + +PtrT_UREncodeResult cosmos_sign_tx(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes seed, + uint32_t seed_len); + +PtrT_TransactionParseResult_DisplayCosmosTx cosmos_parse_tx(PtrUR ptr, enum QRCodeType ur_type); + +void free_TransactionParseResult_DisplayCosmosTx(PtrT_TransactionParseResult_DisplayCosmosTx ptr); + +PtrT_TransactionCheckResult eth_check_ur_bytes(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length, + enum QRCodeType ur_type); + +PtrT_TransactionCheckResult eth_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); + +PtrString eth_get_root_path_bytes(PtrUR ptr); + +PtrString eth_get_root_path(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayETH eth_parse_bytes_data(PtrUR ptr, PtrString xpub); + +PtrT_TransactionParseResult_DisplayETH eth_parse(PtrUR ptr, PtrString xpub); + +PtrT_TransactionParseResult_DisplayETHPersonalMessage eth_parse_personal_message(PtrUR ptr, + PtrString xpub); + +PtrT_TransactionParseResult_DisplayETHTypedData eth_parse_typed_data(PtrUR ptr, PtrString xpub); + +PtrT_UREncodeResult eth_sign_tx_dynamic(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + uintptr_t fragment_length); + +PtrT_UREncodeResult eth_sign_tx_bytes(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes mfp, + uint32_t mfp_len); + +PtrT_UREncodeResult eth_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +PtrT_UREncodeResult eth_sign_tx_unlimited(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +PtrT_TransactionParseResult_EthParsedErc20Transaction eth_parse_erc20(PtrString input, + uint32_t decimal); + +Ptr_Response_DisplayContractData eth_parse_contract_data(PtrString input_data, + PtrString contract_json); + +Ptr_Response_DisplayContractData eth_parse_contract_data_by_method(PtrString input_data, + PtrString contract_name, + PtrString contract_method_json); + +struct SimpleResponse_c_char *eth_get_address(PtrString hd_path, + PtrString root_x_pub, + PtrString root_path); + +void free_TransactionParseResult_DisplayETH(PtrT_TransactionParseResult_DisplayETH ptr); + +void free_TransactionParseResult_DisplayETHPersonalMessage(PtrT_TransactionParseResult_DisplayETHPersonalMessage ptr); + +void free_TransactionParseResult_DisplayETHTypedData(PtrT_TransactionParseResult_DisplayETHTypedData ptr); + +void free_Response_DisplayContractData(PtrT_Response_DisplayContractData ptr); + +void free_TransactionParseResult_EthParsedErc20Transaction(PtrT_TransactionParseResult_EthParsedErc20Transaction ptr); + +PtrT_TransactionCheckResult near_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); + +PtrT_TransactionParseResult_DisplayNearTx near_parse_tx(PtrUR ptr); + +PtrT_UREncodeResult near_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +void free_TransactionParseResult_DisplayNearTx(PtrT_TransactionParseResult_DisplayNearTx ptr); + +struct SimpleResponse_c_char *solana_get_address(PtrString pubkey); + +PtrT_TransactionCheckResult solana_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); + +PtrT_TransactionParseResult_DisplaySolanaTx solana_parse_tx(PtrUR ptr); + +PtrT_UREncodeResult solana_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +PtrT_TransactionParseResult_DisplaySolanaMessage solana_parse_message(PtrUR ptr, PtrString pubkey); + +PtrString sol_get_path(PtrUR ptr); + +void free_TransactionParseResult_DisplaySolanaTx(PtrT_TransactionParseResult_DisplaySolanaTx ptr); + +void free_TransactionParseResult_DisplaySolanaMessage(PtrT_TransactionParseResult_DisplaySolanaMessage ptr); + +struct SimpleResponse_c_char *stellar_get_address(PtrString pubkey); + +PtrT_TransactionParseResult_DisplayStellarTx stellar_parse(PtrUR ptr); + +PtrT_TransactionCheckResult stellar_check_tx(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length); + +PtrT_UREncodeResult stellar_sign(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +void free_TransactionParseResult_DisplayStellarTx(PtrT_TransactionParseResult_DisplayStellarTx ptr); + +PtrT_TransactionCheckResult sui_check_request(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length); + +PtrT_TransactionCheckResult sui_check_sign_hash_request(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length); + +struct SimpleResponse_c_char *sui_generate_address(PtrString pub_key); + +PtrT_TransactionParseResult_DisplaySuiIntentMessage sui_parse_intent(PtrUR ptr); + +PtrT_TransactionParseResult_DisplaySuiSignMessageHash sui_parse_sign_message_hash(PtrUR ptr); + +PtrT_UREncodeResult sui_sign_hash(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +PtrT_UREncodeResult sui_sign_intent(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +void free_TransactionParseResult_DisplaySuiIntentMessage(PtrT_TransactionParseResult_DisplaySuiIntentMessage ptr); + +void free_TransactionParseResult_DisplaySuiSignMessageHash(PtrT_TransactionParseResult_DisplaySuiSignMessageHash ptr); + +PtrT_TransactionParseResult_DisplayTonTransaction ton_parse_transaction(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayTonProof ton_parse_proof(PtrUR ptr); + +PtrT_TransactionCheckResult ton_check_transaction(PtrUR ptr, PtrString public_key); + +PtrT_TransactionCheckResult ton_not_supported_error(void); + +PtrT_UREncodeResult ton_sign_transaction(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +PtrT_UREncodeResult ton_sign_proof(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +bool ton_verify_mnemonic(PtrString mnemonic); + +Ptr_VecFFI_u8 ton_mnemonic_to_entropy(PtrString mnemonic); + +struct SimpleResponse_u8 *ton_entropy_to_seed(PtrBytes entropy, uint32_t entropy_len); + +struct SimpleResponse_u8 *ton_mnemonic_to_seed(PtrString mnemonic); + +struct SimpleResponse_c_char *ton_seed_to_publickey(PtrBytes seed, uint32_t seed_len); + +struct SimpleResponse_c_char *ton_get_address(PtrString public_key); + +void free_TransactionParseResult_DisplayTonTransaction(PtrT_TransactionParseResult_DisplayTonTransaction ptr); + +void free_TransactionParseResult_DisplayTonProof(PtrT_TransactionParseResult_DisplayTonProof ptr); + +PtrT_TransactionCheckResult tron_check_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub); + +struct TransactionParseResult_DisplayTron *tron_parse_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub); + +struct UREncodeResult *tron_sign_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub, + int32_t cold_version, + PtrBytes seed, + uint32_t seed_len); + +struct SimpleResponse_c_char *tron_get_address(PtrString hd_path, PtrString x_pub); + +void free_TransactionParseResult_DisplayTron(PtrT_TransactionParseResult_DisplayTron ptr); + +struct SimpleResponse_c_char *xrp_get_address(PtrString hd_path, + PtrString root_x_pub, + PtrString root_path); + +PtrT_TransactionParseResult_DisplayXrpTx xrp_parse_tx(PtrUR ptr); + +PtrT_UREncodeResult xrp_sign_tx_bytes(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes mfp, + uint32_t mfp_len, + PtrString root_xpub); + +PtrT_UREncodeResult xrp_sign_tx(PtrUR ptr, PtrString hd_path, PtrBytes seed, uint32_t seed_len); + +PtrT_TransactionCheckResult xrp_check_tx(PtrUR ptr, PtrString root_xpub, PtrString cached_pubkey); + +bool is_keystone_xrp_tx(PtrUR ur_data_ptr); + +PtrT_TransactionCheckResult xrp_check_tx_bytes(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length, + enum QRCodeType ur_type); + +PtrT_TransactionParseResult_DisplayXrpTx xrp_parse_bytes_tx(PtrUR ptr); + +void free_TransactionParseResult_DisplayXrpTx(PtrT_TransactionParseResult_DisplayXrpTx ptr); + +struct SimpleResponse_c_char *derive_zcash_ufvk(PtrBytes seed, + uint32_t seed_len, + PtrString account_path); + +struct SimpleResponse_u8 *calculate_zcash_seed_fingerprint(PtrBytes seed, uint32_t seed_len); + +struct SimpleResponse_c_char *generate_zcash_default_address(PtrString ufvk_text); + +struct TransactionCheckResult *check_zcash_tx(PtrUR tx, + PtrString ufvk, + PtrBytes seed_fingerprint, + uint32_t account_index, + bool disabled); + +Ptr_TransactionParseResult_DisplayPczt parse_zcash_tx(PtrUR tx, + PtrString ufvk, + PtrBytes seed_fingerprint); + +struct UREncodeResult *sign_zcash_tx(PtrUR tx, PtrBytes seed, uint32_t seed_len); + +void free_TransactionParseResult_DisplayPczt(PtrT_TransactionParseResult_DisplayPczt ptr); + +#endif /* _LIBRUST_C_H */ diff --git a/rust/rust_c/src/test_cmd/btc_test_cmd.rs b/rust/rust_c/src/test_cmd/btc_test_cmd.rs index b87971c13..bd57e545d 100644 --- a/rust/rust_c/src/test_cmd/btc_test_cmd.rs +++ b/rust/rust_c/src/test_cmd/btc_test_cmd.rs @@ -18,7 +18,7 @@ use crate::common::ur::{ }; use crate::common::utils::convert_c_char; -use wallet_rust_c::get_connect_blue_wallet_ur; +use crate::wallet::get_connect_blue_wallet_ur; #[no_mangle] pub extern "C" fn test_get_crypto_psbt() -> *mut URParseResult { diff --git a/rust/zcash_vendor/Cargo.toml b/rust/zcash_vendor/Cargo.toml index b97af0b82..c3d66cdaa 100644 --- a/rust/zcash_vendor/Cargo.toml +++ b/rust/zcash_vendor/Cargo.toml @@ -23,7 +23,6 @@ pasta_curves = { version = "0.5.1", default-features = false, features = [ sinsemilla = "0.1" subtle = { version = "2.6", default-features = false } group = { version = "0.13.0" } -aes = { workspace = true } fpe = { version = "0.6", default-features = false, features = ["alloc"] } f4jumble = { version = "0.1.1", default-features = false, features = ["alloc"] } byteorder = { version = "1", default-features = false } From d0dfcfc349866d2b83c75dc75c9f654ca0a54b62 Mon Sep 17 00:00:00 2001 From: ww3512687 <15809188520@163.com> Date: Wed, 25 Dec 2024 17:44:33 +0800 Subject: [PATCH 06/31] split chain --- CMakeLists.txt | 90 +- build.sh | 132 +++ et | 539 ++++++++++ firmware.cmake | 8 +- src/crypto/account_public_info.c | 11 +- src/crypto/rsa.c | 2 +- src/managers/account_manager.c | 21 +- .../btc_only/multi_sig_wallet_manager.c | 2 +- src/managers/keystore.c | 3 +- src/tasks/data_parser_task.c | 8 - src/tasks/qrdecode_task.c | 2 +- src/ui/gui_analyze/gui_analyze.c | 999 +----------------- src/ui/gui_analyze/gui_resolve_ur.c | 27 +- .../multi/cyberpunk/gui_cyberpunk_analyze.c | 12 + .../multi/cyberpunk/gui_cyberpunk_analyze.h | 16 + .../multi/general/gui_general_analyze.c | 684 ++++++++++++ .../multi/general/gui_general_analyze.h | 163 +++ src/ui/gui_chain/{btc => }/gui_btc.c | 12 +- src/ui/gui_chain/{btc => }/gui_btc.h | 0 src/ui/gui_chain/gui_chain.c | 291 ++--- src/ui/gui_chain/gui_chain.h | 3 + .../{others => multi/cyberpunk}/gui_zcash.c | 38 +- .../{others => multi/cyberpunk}/gui_zcash.h | 0 src/ui/gui_chain/{others => multi}/gui_ada.c | 12 +- src/ui/gui_chain/{others => multi}/gui_ada.h | 3 +- .../gui_chain/{others => multi}/gui_aptos.c | 2 - .../gui_chain/{others => multi}/gui_aptos.h | 0 src/ui/gui_chain/{others => multi}/gui_ar.c | 5 +- src/ui/gui_chain/{others => multi}/gui_ar.h | 0 .../gui_chain/{others => multi}/gui_cosmos.c | 2 - .../gui_chain/{others => multi}/gui_cosmos.h | 0 src/ui/gui_chain/{others => multi}/gui_eth.c | 4 +- src/ui/gui_chain/{others => multi}/gui_eth.h | 0 src/ui/gui_chain/{others => multi}/gui_sol.c | 2 - src/ui/gui_chain/{others => multi}/gui_sol.h | 0 .../gui_chain/{others => multi}/gui_stellar.c | 4 - .../gui_chain/{others => multi}/gui_stellar.h | 0 src/ui/gui_chain/{others => multi}/gui_sui.c | 4 +- src/ui/gui_chain/{others => multi}/gui_sui.h | 0 src/ui/gui_chain/{others => multi}/gui_ton.c | 4 +- src/ui/gui_chain/{others => multi}/gui_ton.h | 0 src/ui/gui_chain/{others => multi}/gui_trx.c | 4 +- src/ui/gui_chain/{others => multi}/gui_trx.h | 0 src/ui/gui_chain/{others => multi}/gui_xrp.c | 5 +- src/ui/gui_chain/{others => multi}/gui_xrp.h | 0 src/ui/gui_components/gui_status_bar.c | 6 +- src/ui/gui_frame/gui_framework.c | 85 -- src/ui/gui_frame/gui_framework.h | 1 - src/ui/gui_model/gui_model.h | 1 + src/ui/gui_views/gui_home_view.c | 6 +- .../gui_views/gui_transaction_detail_view.c | 3 +- .../general/gui_key_derivation_request_view.c | 0 .../general/gui_multi_account_receive_view.c | 0 .../gui_multi_path_coin_receive_view.c | 0 .../general/gui_standard_receive_view.c | 0 .../general}/gui_ton_mnemonic_hint_view.c | 0 .../general/gui_usb_transport_view.c | 0 .../btc_only}/gui_wallet.c | 4 +- .../btc_only}/gui_wallet.h | 0 src/ui/{wallet => gui_wallet}/gui_qr_code.c | 0 src/ui/{wallet => gui_wallet}/gui_qr_code.h | 0 src/ui/gui_wallet/multi/gui_wallet.c | 708 +++++++++++++ src/ui/gui_wallet/multi/gui_wallet.h | 33 + .../btc_only/gui_btc_wallet_profile_widgets.c | 2 +- ..._btc_home_widgets.c => gui_home_widgets.c} | 2 +- ..._btc_home_widgets.h => gui_home_widgets.h} | 8 +- .../gui_manage_multisig_wallet_widgets.c | 2 +- .../gui_manage_multisig_wallet_widgets.h | 2 +- src/ui/gui_widgets/general/gui_home_widgets.h | 104 -- .../gui_widgets/gui_connect_wallet_widgets.h | 1 - .../gui_widgets/gui_export_pubkey_widgets.c | 3 +- src/ui/gui_widgets/gui_utxo_receive_widgets.c | 2 +- .../gui_widgets/gui_wallet_tutorial_widgets.c | 4 +- .../cyberpunk/gui_cyberpunk_home_widgets.h | 17 + .../general/gui_connect_ada_widgets.c | 0 .../general/gui_connect_ada_widgets.h | 0 .../multi/general/gui_general_home_widgets.h | 420 ++++++++ .../general/gui_ton_mnemonic_hint_widgets.c | 0 .../general/gui_ton_mnemonic_hint_widgets.h | 0 .../{general => multi}/gui_home_widgets.c | 370 +------ src/ui/gui_widgets/multi/gui_home_widgets.h | 51 + .../gui_key_derivation_request_widgets.c | 2 - .../gui_key_derivation_request_widgets.h | 0 .../gui_multi_accounts_receive_widgets.c | 0 .../gui_multi_accounts_receive_widgets.h | 0 .../gui_multi_path_coin_receive_widgets.c | 0 .../gui_multi_path_coin_receive_widgets.h | 0 .../gui_standard_receive_widgets.c | 3 +- .../gui_standard_receive_widgets.h | 0 .../gui_usb_transport_widgets.c | 0 .../gui_usb_transport_widgets.h | 0 .../setting/gui_wallet_setting_widgets.c | 2 +- src/ui/lv_i18n/lv_i18n.c | 102 +- test/test_cmd.c | 8 +- ui_simulator/simulator_model.h | 170 ++- 95 files changed, 3322 insertions(+), 1914 deletions(-) create mode 100644 build.sh create mode 100644 et create mode 100644 src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c create mode 100644 src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.h create mode 100644 src/ui/gui_analyze/multi/general/gui_general_analyze.c create mode 100644 src/ui/gui_analyze/multi/general/gui_general_analyze.h rename src/ui/gui_chain/{btc => }/gui_btc.c (99%) rename src/ui/gui_chain/{btc => }/gui_btc.h (100%) rename src/ui/gui_chain/{others => multi/cyberpunk}/gui_zcash.c (95%) rename src/ui/gui_chain/{others => multi/cyberpunk}/gui_zcash.h (100%) rename src/ui/gui_chain/{others => multi}/gui_ada.c (99%) rename src/ui/gui_chain/{others => multi}/gui_ada.h (99%) rename src/ui/gui_chain/{others => multi}/gui_aptos.c (99%) rename src/ui/gui_chain/{others => multi}/gui_aptos.h (100%) rename src/ui/gui_chain/{others => multi}/gui_ar.c (99%) rename src/ui/gui_chain/{others => multi}/gui_ar.h (100%) rename src/ui/gui_chain/{others => multi}/gui_cosmos.c (99%) rename src/ui/gui_chain/{others => multi}/gui_cosmos.h (100%) rename src/ui/gui_chain/{others => multi}/gui_eth.c (99%) rename src/ui/gui_chain/{others => multi}/gui_eth.h (100%) rename src/ui/gui_chain/{others => multi}/gui_sol.c (99%) rename src/ui/gui_chain/{others => multi}/gui_sol.h (100%) rename src/ui/gui_chain/{others => multi}/gui_stellar.c (99%) rename src/ui/gui_chain/{others => multi}/gui_stellar.h (100%) rename src/ui/gui_chain/{others => multi}/gui_sui.c (99%) rename src/ui/gui_chain/{others => multi}/gui_sui.h (100%) rename src/ui/gui_chain/{others => multi}/gui_ton.c (99%) rename src/ui/gui_chain/{others => multi}/gui_ton.h (100%) rename src/ui/gui_chain/{others => multi}/gui_trx.c (99%) rename src/ui/gui_chain/{others => multi}/gui_trx.h (100%) rename src/ui/gui_chain/{others => multi}/gui_xrp.c (99%) rename src/ui/gui_chain/{others => multi}/gui_xrp.h (100%) rename src/ui/gui_views/{ => multi}/general/gui_key_derivation_request_view.c (100%) rename src/ui/gui_views/{ => multi}/general/gui_multi_account_receive_view.c (100%) rename src/ui/gui_views/{ => multi}/general/gui_multi_path_coin_receive_view.c (100%) rename src/ui/gui_views/{ => multi}/general/gui_standard_receive_view.c (100%) rename src/ui/gui_views/{ => multi/general}/gui_ton_mnemonic_hint_view.c (100%) rename src/ui/gui_views/{ => multi}/general/gui_usb_transport_view.c (100%) rename src/ui/{wallet => gui_wallet/btc_only}/gui_wallet.c (99%) rename src/ui/{wallet => gui_wallet/btc_only}/gui_wallet.h (100%) rename src/ui/{wallet => gui_wallet}/gui_qr_code.c (100%) rename src/ui/{wallet => gui_wallet}/gui_qr_code.h (100%) create mode 100644 src/ui/gui_wallet/multi/gui_wallet.c create mode 100644 src/ui/gui_wallet/multi/gui_wallet.h rename src/ui/gui_widgets/btc_only/{gui_btc_home_widgets.c => gui_home_widgets.c} (99%) rename src/ui/gui_widgets/btc_only/{gui_btc_home_widgets.h => gui_home_widgets.h} (91%) delete mode 100644 src/ui/gui_widgets/general/gui_home_widgets.h create mode 100644 src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.h rename src/ui/gui_widgets/{ => multi}/general/gui_connect_ada_widgets.c (100%) rename src/ui/gui_widgets/{ => multi}/general/gui_connect_ada_widgets.h (100%) create mode 100644 src/ui/gui_widgets/multi/general/gui_general_home_widgets.h rename src/ui/gui_widgets/{ => multi}/general/gui_ton_mnemonic_hint_widgets.c (100%) rename src/ui/gui_widgets/{ => multi}/general/gui_ton_mnemonic_hint_widgets.h (100%) rename src/ui/gui_widgets/{general => multi}/gui_home_widgets.c (72%) create mode 100644 src/ui/gui_widgets/multi/gui_home_widgets.h rename src/ui/gui_widgets/{general => multi}/gui_key_derivation_request_widgets.c (99%) rename src/ui/gui_widgets/{general => multi}/gui_key_derivation_request_widgets.h (100%) rename src/ui/gui_widgets/{general => multi}/gui_multi_accounts_receive_widgets.c (100%) rename src/ui/gui_widgets/{general => multi}/gui_multi_accounts_receive_widgets.h (100%) rename src/ui/gui_widgets/{general => multi}/gui_multi_path_coin_receive_widgets.c (100%) rename src/ui/gui_widgets/{general => multi}/gui_multi_path_coin_receive_widgets.h (100%) rename src/ui/gui_widgets/{general => multi}/gui_standard_receive_widgets.c (99%) rename src/ui/gui_widgets/{general => multi}/gui_standard_receive_widgets.h (100%) rename src/ui/gui_widgets/{general => multi}/gui_usb_transport_widgets.c (100%) rename src/ui/gui_widgets/{general => multi}/gui_usb_transport_widgets.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a52582b6e..1d3866123 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,10 +36,6 @@ foreach(_variableName ${_variableNames}) endif() endforeach() -if(BTC_ONLY) - add_compile_definitions(BTC_ONLY) - add_compile_definitions(EXCLUDE_RUSTC) -endif() set(COMMON_DEFINITIONS USE_STDPERIPH_DRIVER @@ -61,29 +57,49 @@ set(CRYPTO_INCLUDE_PATH src/crypto/slip39/trezor-crypto ) +set(WIDGET_PATH "multi") +# if(CYBERPUNK) +# set(WIDGET_SUBPATH "multi/cyberpunk") +# add_compile_definitions(CYBERPUNK_VERSION) +# message(STATUS "Enabled option: CYBERPUNK_VERSION..............................") +# elseif(BTC_ONLY) +# set(WIDGET_SUBPATH "btc_only/multi_sig") +# set(WIDGET_PATH "btc_only") +# add_compile_definitions(BTC_ONLY) +# add_compile_definitions(EXCLUDE_RUSTC) +# else() +# add_compile_definitions(GENERAL_VERSION) +# set(WIDGET_SUBPATH "multi/general") +# endif() +add_compile_definitions(GENERAL_VERSION) +set(WIDGET_SUBPATH "multi/general") + +set(GUI_CUSTOM_INCLUDE_PATH + src/ui/gui_widgets/${WIDGET_SUBPATH} + src/ui/gui_widgets/${WIDGET_PATH} + src/ui/gui_chain/${WIDGET_SUBPATH} + src/ui/gui_chain/${WIDGET_PATH} + src/ui/gui_wallet/${WIDGET_SUBPATH} + src/ui/gui_wallet/${WIDGET_PATH} +) + set(GUI_INCLUDE_PATH src/ui src/ui/gui_views src/ui/gui_assets src/ui/gui_assets/abi src/ui/gui_frame + ${GUI_CUSTOM_INCLUDE_PATH} src/ui/gui_widgets src/ui/gui_widgets/setting src/ui/lv_i18n src/ui/gui_model src/ui/gui_analyze src/ui/gui_chain - src/ui/gui_chain/btc src/ui/gui_components - src/ui/wallet + src/ui/gui_wallet ) -if(BTC_ONLY) - list(APPEND GUI_INCLUDE_PATH src/ui/gui_widgets/btc_only src/ui/gui_widgets/btc_only/multi_sig src/ui/gui_widgets/general) -else() - list(APPEND GUI_INCLUDE_PATH src/ui/gui_chain/others src/ui/gui_widgets/general) -endif() - set(EXTERNAL_INCLUDE_PATH external external/ctaes @@ -159,21 +175,37 @@ if(NOT BUILD_PRODUCTION) list(APPEND INCLUDE_DIR test) set(TEST_CMD test) endif() + +file(GLOB GUI_CUSTOM_VIEW_WIDGETS + src/ui/gui_views/*.c + src/ui/gui_views/general/*.c + src/ui/gui_widgets/*.c + src/ui/gui_widgets/general/*.c + src/ui/gui_wallet/*.c + src/ui/gui_chain/*.c + src/ui/gui_analyze/*.c + src/ui/gui_widgets/${WIDGET_SUBPATH}/*.c + src/ui/gui_widgets/${WIDGET_PATH}/*.c + src/ui/gui_views/${WIDGET_SUBPATH}/*.c + src/ui/gui_views/${WIDGET_PATH}/*.c + src/ui/gui_chain/${WIDGET_SUBPATH}/*.c + src/ui/gui_chain/${WIDGET_PATH}/*.c + src/ui/gui_wallet/${WIDGET_SUBPATH}/*.c + src/ui/gui_wallet/${WIDGET_PATH}/*.c + src/ui/gui_analyze/${WIDGET_SUBPATH}/*.c + src/ui/gui_analyze/${WIDGET_PATH}/*.c +) file(GLOB_RECURSE GUI + ${GUI_CUSTOM_VIEW_WIDGETS} "src/ui/gui_assets/*.c" "src/ui/gui_assets/font/*.c" "src/ui/gui_assets/abi/*.c" "src/ui/gui_frame/*.c" - "src/ui/gui_views/*.c" - "src/ui/gui_widgets/*.c" "src/ui/gui_widgets/setting/*.c" "src/ui/lv_i18n/*.c" "src/ui/gui_model/*.c" - "src/ui/gui_analyze/*.c" - "src/ui/gui_chain/*.c" "src/ui/gui_components/*.c" - "src/ui/wallet/*.c" ) file(GLOB_RECURSE LVGL @@ -267,17 +299,19 @@ if(COMPILE_KEYSTONE) src/cm_backtrace/fault_handler/gcc/cmb_fault.s ) - if(BTC_ONLY) - set(excluded_directories - src/ui/gui_chain/others - src/ui/gui_widgets/general - src/ui/gui_views/general - src/webusb_protocol/general) - else() - set(excluded_directories - src/ui/gui_views/btc_only - src/ui/gui_widgets/btc_only) - endif() + message(STATUS "WEBUSB_PROTOCOL: ${WEBUSB_PROTOCOL}") + + # if(BTC_ONLY) + # set(excluded_directories + # src/ui/gui_chain/others + # src/ui/gui_widgets/general + # src/ui/gui_views/general + # src/webusb_protocol/general) + # else() + # set(excluded_directories + # src/ui/gui_views/btc_only + # src/ui/gui_widgets/btc_only) + # endif() foreach(directory ${excluded_directories}) file(GLOB_RECURSE excluded_files "${directory}/*") diff --git a/build.sh b/build.sh new file mode 100644 index 000000000..c90e57eca --- /dev/null +++ b/build.sh @@ -0,0 +1,132 @@ +#!/bin/bash + +set -e +set -o pipefail + +BUILD_FOLDER="$(pwd)/build" +BUILD_SIMULATOR_FOLDER="$(pwd)/build_simulator" +TOOLS_FOLDER="$(pwd)/tools" +MAKE_OAT_FILE_PATH="${TOOLS_FOLDER}/ota_file_maker" +MAKE_PADDING_FILE_PATH="${TOOLS_FOLDER}/padding_bin_file" +ASTYLE_PATH="${TOOLS_FOLDER}/AStyle.sh" +PACK_PATH="$(pwd)/pack.sh" +LANGUAGE_PATH="$(pwd)/src/ui/lv_i18n" +LANGUAGE_SCRIPT="python3 data_loader.py" +RUST_C_PATH="$(pwd)/rust/rust_c" + +declare -A build_options=( + ["log"]=false + ["copy"]=false + ["production"]=false + ["screen"]=false + ["debug"]=false + ["format"]=false + ["release"]=false + ["rebuild"]=false + ["btc_only"]=false + ["cyberpunk"]=false + ["simulator"]=false + ["language"]=false + ["clean"]=false +) + +for arg in "$@"; do + if [[ "$arg" == "format" ]]; then + pushd "$TOOLS_FOLDER" + echo "Formatting files..." + bash "$ASTYLE_PATH" + popd + else + echo "Building with option: $arg" + build_options["$arg"]=true + fi +done + +echo "Building with options: ${build_options[@]}" + +if [[ "${build_options[rebuild]}" == true ]]; then + if [[ -d "$BUILD_FOLDER" ]]; then + rm -rf "$BUILD_FOLDER" + fi + pushd "$RUST_C_PATH" + cargo clean + popd +fi + +mkdir -p "$BUILD_FOLDER" + +if [[ ! -f "$BUILD_FOLDER/padding_bin_file.py" ]]; then + cp "$MAKE_PADDING_FILE_PATH/padding_bin_file.py" "$BUILD_FOLDER/padding_bin_file.py" +fi + +execute_build() { + if [[ "${build_options[language]}" == true ]]; then + pushd "$LANGUAGE_PATH" + $LANGUAGE_SCRIPT + popd + fi + + cmake_parm="" + if [[ "${build_options[production]}" == true ]]; then + cmake_parm="${cmake_parm} -DBUILD_PRODUCTION=true" + fi + if [[ "${build_options[btc_only]}" == true ]]; then + cmake_parm="${cmake_parm} -DBTC_ONLY=true" + fi + if [[ "${build_options[cyberpunk]}" == true ]]; then + cmake_parm="${cmake_parm} -DCYBERPUNK=true" + fi + if [[ "${build_options[screen]}" == true ]]; then + cmake_parm="${cmake_parm} -DENABLE_SCREEN_SHOT=true" + fi + if [[ "${build_options[debug]}" == true ]]; then + cmake_parm="${cmake_parm} -DDEBUG_MEMORY=true" + fi + + echo "Building project.............." + echo "cmake_parm: $cmake_parm" + if [[ "${build_options[simulator]}" == true ]]; then + echo "Building project---------------" + mkdir -p "$BUILD_SIMULATOR_FOLDER" + pushd "$BUILD_SIMULATOR_FOLDER" + cmake -G "Unix Makefiles" -DBUILD_TYPE=Simulator $cmake_parm .. + make -j16 + popd + else + echo "Building project.............." + mkdir -p "$BUILD_SIMULATOR_FOLDER" + pushd "$BUILD_SIMULATOR_FOLDER" + cmake -G "Unix Makefiles" -DBUILD_TYPE=Simulator $cmake_parm .. + make -j16 + popd + # pushd "$BUILD_FOLDER" + # cmake -G "Unix Makefiles" $cmake_parm .. + # if [[ "${build_options[log]}" == true ]]; then + # make -j16 > makefile.log 2>&1 + # else + # make -j16 + # fi + # python3 padding_bin_file.py mh1903.bin + # popd + fi + + if [[ "${build_options[copy]}" == true ]]; then + echo "Generating pillar.bin file..." + pushd "$MAKE_OAT_FILE_PATH" + echo "Generating OTA files..." + bash make_ota_file.sh "$(pwd)/build/pillar.bin" + bash make_ota_file.sh "$(pwd)/build/keystone3.bin" + bash make_ota_file.sh "F:/pillar.bin" + popd + elif [[ "${build_options[release]}" == true ]]; then + pushd "$MAKE_OAT_FILE_PATH" + echo "Generating release files..." + bash make_ota_file.sh "$(pwd)/build/pillar.bin" + bash make_ota_file.sh "$(pwd)/build/keystone3.bin" + popd + elif [[ "${build_options[simulator]}" == true ]]; then + ./build/simulator.exe + fi +} + +execute_build diff --git a/et b/et new file mode 100644 index 000000000..b3a740f50 --- /dev/null +++ b/et @@ -0,0 +1,539 @@ +commit 1aae5288ee58bb0113ec56a59dd93be8f5a6de78 (HEAD -> refactor/c_split_chain) +Author: 0xApprentice <126858986+0xApprentice@users.noreply.github.com> +Date: Wed Dec 25 17:36:33 2024 +0800 + + split chain + +commit 3be05c54330da47bdfbb3f371b08baba6162ed11 (upstream/master, origin/master, master) +Merge: 7c449f3b bda731ce +Author: stone wang <35837388+ww3512687@users.noreply.github.com> +Date: Fri Dec 20 10:25:33 2024 +0800 + + Merge pull request #1512 from KeystoneHQ/feat/zcash + + refactor: optimize zcash + +commit bda731ce973ea577cf782de9ba10d891fd26ffb6 +Author: soralit +Date: Thu Dec 19 17:59:24 2024 +0800 + + refactor: optimize zcash + +commit 7c449f3b66fff28d06d2a603b76e6453a7a99a2b +Merge: 08a44673 cb186363 +Author: Soralit +Date: Fri Dec 20 09:29:26 2024 +0800 + + Merge pull request #1511 from KeystoneHQ/merge/v1.8.0 + + Merge/v1.8.0 + +commit cb1863637db4b288522978cda5f0e837955b1791 +Author: soralit +Date: Fri Dec 20 09:13:20 2024 +0800 + + chore: update ci config to match current project state + +commit 7a3efe9ad1464b5eb1f896edd0960f99bb8a0756 +Author: soralit +Date: Thu Dec 19 19:22:12 2024 +0800 + + style: run fmt + +commit f82da698ce1e7026b3d896ae32c1970eab453f47 (tag: 1.8.0, upstream/release/v1.8.0, origin/release/v1.8.0) +Merge: 14d54b14 03c6e99d +Author: Soralit +Date: Thu Dec 19 18:24:05 2024 +0800 + + Merge pull request #1509 from KeystoneHQ/bump-version + + chore: bump version + +commit 03c6e99d11c9a34562197c1a127871be16fe3089 +Author: soralit +Date: Thu Dec 19 18:23:33 2024 +0800 + + chore: bump version + +commit 14d54b1412061a9de77fefff5ad6ec670e0b278a +Merge: 82a380c4 431156e7 +Author: Soralit +Date: Thu Dec 19 18:01:58 2024 +0800 + + Merge pull request #1508 from KeystoneHQ/add-changelog + + docs: add v1.8.0 changelog + +commit 431156e76983133a7a8ca037e2ce9a3bcbf1d1c1 +Author: soralit +Date: Thu Dec 19 18:01:23 2024 +0800 + + docs: add v1.8.0 changelog + +commit 82a380c44a740dd58be30b435719b180a607623f (upstream/release/v1.7.18, origin/release/v1.7.18) +Author: soralit +Date: Thu Dec 19 16:25:15 2024 +0800 + + fix: ui issues + +commit 79cc49349450fd8ed76b78302c48526b1d55b3d3 +Author: soralit +Date: Thu Dec 19 15:57:33 2024 +0800 + + fix: connect wallet issue + +commit 71bdfb8e95f8e4332ea8c64f0fee109d02655440 +Author: soralit +Date: Thu Dec 19 15:53:29 2024 +0800 + + fix: app crash + +commit 05b1372c75d3505667e68d31ad49c1feeb8deb3b +Author: soralit +Date: Thu Dec 19 14:36:46 2024 +0800 + + fix: amount calculation + +commit 9a81ada3a4a4a3a3ca2c617be90ca5f37268f433 +Author: soralit +Date: Thu Dec 19 13:39:01 2024 +0800 + + feat: allow p2sh transparent output and input. refactor ut + +commit 337981f72789a396643376e9586128e5e96cdf7e +Author: soralit +Date: Thu Dec 19 10:14:07 2024 +0800 + + fix: issues + +commit d41a8f232bdbe6008f3676ffb4bf5749cf9e0235 +Author: soralit +Date: Wed Dec 18 18:46:08 2024 +0800 + + fix: passphrase judge error + +commit 6cc43e1f96dfa2b600687d3769122f5004620376 +Author: soralit +Date: Wed Dec 18 18:31:03 2024 +0800 + + fix: build + +commit 2a7c87182419fa4ae801ad1888bb3e8aca188eb3 +Author: soralit +Date: Wed Dec 18 18:28:07 2024 +0800 + + chore: bump beta version + +commit 3882c14b4c2f825a1b2a95366fe6a88b0165b23c +Author: soralit +Date: Wed Dec 18 18:26:50 2024 +0800 + + fix: disable zcash for passphrase and slip39 wallet for now + +commit 6a04d6961f03fc8f8ee852d468403158624925a6 +Author: soralit +Date: Wed Dec 18 17:57:28 2024 +0800 + + fix: open checking logic + +commit fa3f10c56d47d7d148dd33032482845c392111dd +Author: soralit +Date: Wed Dec 18 16:58:01 2024 +0800 + + fix: ui issue + +commit bed660d783658a9e5ff6d711ecd4e80be93a2ced +Author: soralit +Date: Wed Dec 18 16:31:50 2024 +0800 + + feat: support passphrase and slip39 to zcash + +commit 1a8bc53879a3627de23335cff478bac4712ae61f +Author: soralit +Date: Wed Dec 18 16:20:18 2024 +0800 + + feat: upgrade zcash dep + +commit 4641f77e93cfcbaff669af8467fff32e9de8bb07 +Author: soralit +Date: Wed Dec 18 16:17:32 2024 +0800 + + fix: unit test + +commit 0b79d5c870c69f7c203ac94db5d7f9fcb5622e26 +Author: soralit +Date: Wed Dec 18 15:43:48 2024 +0800 + + fix: zcash receive page issue + +commit b0b01da23fa86e016147935fd3c2c0e306c276f7 +Author: soralit +Date: Tue Dec 17 20:59:24 2024 +0800 + + feat: ui refinement for sapling part + +commit 2e2e5b98825fe328937e1e93ba1ef3d84a05f532 +Author: soralit +Date: Tue Dec 17 20:59:24 2024 +0800 + + feat: ui refinement for sapling part + +commit aa0220aada2a988d4309dc6ecc457dba096b21bf +Author: soralit +Date: Tue Dec 17 20:50:08 2024 +0800 + + fix: transaction signing failed issue + +commit f2fb1c34b712d9a2daa6084f88c4599a97d87bea +Author: soralit +Date: Tue Dec 17 19:00:37 2024 +0800 + + fix: disable checking ATM + +commit dd637e486fd6ec9c99dd70c8cfdbe8beb85eec3b +Author: soralit +Date: Tue Dec 17 18:59:15 2024 +0800 + + fix(bitcoin): issues happened after upgrade bitcoin + +commit b379e529d4887d16842731b59bf19d8fdc5ff5f7 +Author: soralit +Date: Tue Dec 17 18:22:54 2024 +0800 + + style(zcash): run cargo fix + +commit 7a179c9f0cf2e9877b7570ec59551eefe98c09c6 +Author: soralit +Date: Tue Dec 17 18:21:48 2024 +0800 + + style(zcash): optimize import + +commit 90b26f58e8d80fcedb9275cae6b91c0e5d7cf365 +Author: soralit +Date: Tue Dec 17 18:20:26 2024 +0800 + + style: run fmt + +commit 55390265461b79c3f45dc01bea10274a041a4b46 +Author: soralit +Date: Tue Dec 17 18:20:11 2024 +0800 + + refactor(zcash): no hardcoded network + +commit 76d6a9db7f91d996370ca3a61b6f96c2cbb1cb0f +Author: soralit +Date: Tue Dec 17 18:06:44 2024 +0800 + + fix(zcash): home page zec issue + +commit 3034a283dafcd40641f4d49ffa9f7a2230c99087 +Author: soralit +Date: Tue Dec 17 18:01:40 2024 +0800 + + chore: refine checking logic + +commit 373df133e44d266075ffd34d9b39dfb570dd726e +Author: soralit +Date: Tue Dec 17 16:33:01 2024 +0800 + + feat: add fee value display + +commit 5934b1e44025c11c8d15efd025af6a6ffbed6d3f +Author: soralit +Date: Tue Dec 17 16:06:34 2024 +0800 + + fix: change output is marked as invalid + +commit eaf9f3036e09e804933c828211d245064a235717 +Author: Jack Grigg +Date: Tue Dec 17 03:18:24 2024 +0000 + + zcash: Display user-facing addresses for outputs + +commit ac1c0ec7871f45cfa2d99175c92be9448c70e853 +Author: Jack Grigg +Date: Tue Dec 17 02:41:31 2024 +0000 + + zcash: Replace vendored `pczt` with upstream branch + + Co-authored-by: Kris Nuttycombe + +commit ddd20bac81b7291673d52d96da4d29cd98d3d43b +Author: Jack Grigg +Date: Mon Dec 16 22:41:18 2024 +0000 + + zcash: Replace vendored `zcash_keys` with upstream branch + + Co-authored-by: Kris Nuttycombe + +commit 50109c9b7af917aff4891d0431e9882c8f35dc7c +Author: Jack Grigg +Date: Mon Dec 16 13:40:22 2024 +0000 + + zcash: Replace vendored `orchard` with upstream branch + + Co-authored-by: Kris Nuttycombe + +commit df5de09458c2b32bc0df817a51044f462c3296a6 +Author: Jack Grigg +Date: Mon Dec 16 10:05:17 2024 +0000 + + zcash: Replace vendored `zcash_primitives` with `zcash_transparent` + +commit a9075ea9bd4be4744f103956f99c6dfa3aa935f0 +Author: Jack Grigg +Date: Mon Dec 16 09:15:29 2024 +0000 + + zcash: Remove vendored `zcash_encoding` files + + I forgot to do this in 7771402e4ccbe69507636f277378632f519544a1. + +commit 43ee41b18c1e5964f9f320d627ec31f20f4e676d +Author: soralit +Date: Mon Dec 16 20:34:38 2024 +0800 + + fix: unshielding transaction signing + +commit ca92e5e426018f07dd5d598e7c20597948333418 +Author: soralit +Date: Mon Dec 16 20:17:50 2024 +0800 + + chore: upgrade toolchain for CI + +commit 3c3cc5ea06fbdad6f486684eae51f11e5815bc48 +Author: soralit +Date: Mon Dec 16 20:14:08 2024 +0800 + + fix: judge dummy output + +commit 99379eb0272a8f7c384574324c8bc480783a0218 +Author: soralit +Date: Mon Dec 16 17:18:34 2024 +0800 + + chore: update toolchain + +commit 1ef44806726a6e7ca7c6a008371e45573112f2d7 +Author: soralit +Date: Mon Dec 16 16:21:28 2024 +0800 + + chore: update rust-toolchain + +commit 6dfe512a4ae13b775ae6aa81733b1d13749a7fd5 +Author: soralit +Date: Mon Dec 16 16:10:12 2024 +0800 + + fix: unshielding transaction failed because of the hash calculation + +commit d3c483b7f46bd2fde712db77efeff1e3e81e8d19 +Author: soralit +Date: Mon Dec 16 13:30:49 2024 +0800 + + fix(zcash): shielding transaction display issue and modify tx_modifiable flags after signing + +commit b0ab795991dbe1f2b8fad14761fe00166266f24c +Author: soralit +Date: Sat Dec 14 21:19:17 2024 +0800 + + fix: sign transparent input should return der signature with sighash type + +commit d5923d34917776af1fee409c5ad69b9dd2f9fd1a +Author: soralit +Date: Fri Dec 13 18:27:30 2024 +0800 + + fix: zcash memory leak + +commit a29783eb539e8313909ed6500d294f07fc8c781c +Author: Jack Grigg +Date: Fri Dec 13 13:47:33 2024 +0000 + + zcash: Replace vendored Sinsemilla with `sinsemilla` crate + +commit 9d7d6ea723811ae2c40e9a9b35e617b03f273f2a +Author: Jack Grigg +Date: Fri Dec 13 23:05:34 2024 +0000 + + zcash: Replace vendored `zip32` with published crate + +commit 0b4e182d4d884a2e64ed536016f59ba1c247b44d +Author: Jack Grigg +Date: Fri Dec 13 20:37:48 2024 +0000 + + zcash: Replace vendored `zcash_address` with published crate + +commit 27170290d06328cf2f0f250d92d1dece6f67a671 +Author: Jack Grigg +Date: Fri Dec 13 17:04:26 2024 +0000 + + zcash: Replace vendored `zcash_encoding` with published crate + +commit e6d109eb834f91d32f0097ac492a23d68924a23c +Author: Jack Grigg +Date: Fri Dec 13 15:01:17 2024 +0000 + + zcash: Replace vendored `zcash_protocol` with published crate + +commit 286f73b5d9d8c40229051f447aeac431509c7e7d +Author: Jack Grigg +Date: Fri Dec 13 09:54:08 2024 +0000 + + zcash: Switch to obtaining randomness through `rand_core::OsRng` + +commit 7b76767ce3857cf54e319487c7ecc3d1a683b7fa +Author: Jack Grigg +Date: Fri Dec 13 09:41:30 2024 +0000 + + feat: Use TRNG as a custom `getrandom` backend + + This enables Rust crates that depend on the `getrandom` crate (either + directly or via `rand::rngs::OsRng`) to get secure randomness directly + instead of needing it to be passed through a per-callsite C FFI. + +commit 049014ae4aa3dd8aa911749913a96fb5ecc0ae7a +Author: soralit +Date: Fri Dec 13 15:21:24 2024 +0800 + + fix: memo decode / an edge case of crash / use TRGN randomness when signing / ui refinement + +commit b8979c11e1afada8560c92dcd8308aaf692feb89 +Author: soralit +Date: Thu Dec 12 17:39:19 2024 +0800 + + fix: pczt transaction signing and display issues + +commit 6b0db3939585be961bd0e953d34d1520e19cda1f +Author: soralit +Date: Thu Dec 12 14:09:50 2024 +0800 + + fix: wrong total transfer value + +commit 33dfe7ac2322682f320bd4d6932c53db6a7c2268 +Author: soralit +Date: Wed Dec 11 19:59:04 2024 +0800 + + fix: omit pczt checking ATM + +commit 5ac5d2cc49773911c2bcf4fead269dff227d5232 +Author: soralit +Date: Wed Dec 11 16:01:51 2024 +0800 + + fix: should not render transparent part when it is None + +commit 3b98da78146bbbf6c0e5c44d8ec303441696a4d0 +Author: soralit +Date: Tue Dec 10 17:49:49 2024 +0800 + + chore: bump version + +commit c68244ae4f6665f115a74f3c9febfcecd1613cfe +Author: soralit +Date: Mon Dec 9 19:08:54 2024 +0800 + + fix: correct sign hash and check + +commit 783845dddf7b95ae9ec97c547bce6f6d7803b8ac +Author: soralit +Date: Fri Dec 6 17:42:41 2024 +0800 + + feat: pull pczt latest changes + +commit 2d58467ac79c828e15014d03f71d491ea7b7ddd9 +Author: soralit +Date: Tue Nov 26 14:28:25 2024 +0800 + + feat: zcash basic transaction view + +commit 8a7e196292f50f0e1f1c73dde572d61e84b7e365 +Author: soralit +Date: Fri Nov 22 15:15:13 2024 +0800 + + chore: update dep + +commit ff0037230f9cf54d75aff4f40cb381932997d4fe +Author: soralit +Date: Thu Nov 21 16:44:11 2024 +0800 + + chore: reduce firmware size + +commit ee311c6c7df3805fb611f37b1f16101fbc3023b4 +Author: soralit +Date: Thu Nov 21 14:59:40 2024 +0800 + + feat: add rust structs + +commit f25494f536714bed1800185ca11e107ce3156cc9 +Author: soralit +Date: Tue Nov 19 09:40:30 2024 +0800 + + feat: zcash ui + +commit df4dbcf2638a0a9c4b52cce089478ed085726a3c +Author: soralit +Date: Mon Nov 18 17:23:23 2024 +0800 + + feat: add zcash interfaces + +commit 40b156d1c9f5f98c2008b17a2f7564625c56a509 +Author: soralit +Date: Mon Nov 18 14:59:24 2024 +0800 + + feat: parst pczt transparent and orchard + +commit ec805589b26e121a5b155888a0f85e477f95aaaf +Author: soralit +Date: Thu Nov 14 17:43:35 2024 +0800 + + feat: support pczt check and parse output ciphertext + +commit b3e1b9aa3d4b7d430f52363f6590ff965b1780c1 +Author: soralit +Date: Wed Nov 13 15:08:55 2024 +0800 + + feat: adopt pczt latest changes + +commit 7fdb07d393328eb3ac4191ced4ed7c9e12c0503d +Author: soralit +Date: Tue Nov 5 18:12:52 2024 +0800 + + fix: adjust transaction signing code + +commit 905f9f797dd4c364d7ff4e62baa08f0f8e5e674a +Author: soralit +Date: Tue Nov 5 14:32:09 2024 +0800 + + fix: pczt hash + +commit a612b3495358a9ed53f37e0e6537a07e113c9592 +Author: soralit +Date: Thu Oct 31 17:37:44 2024 +0800 + + feat: impl signer for pczt + +commit ac2ece945977de209e034c80a191ed38b4dedb5c +Author: soralit +Date: Thu Oct 31 14:41:35 2024 +0800 + + feat: extend pczt functionality + +commit 9a180351bb2065c0715cf3fb8ad65f572438d8ac +Author: soralit +Date: Thu Oct 31 13:48:07 2024 +0800 + + feat: update pczt data hash + +commit 7b2bfc8cf6dfabc346f77085d9648c2e3695252c +Author: soralit +Date: Wed Oct 30 17:21:59 2024 +0800 + + fix: build + +commit 938ba47011e967a2f4a2ab4d2964283bcbd41b92 +Author: soralit +Date: Tue Oct 29 13:48:18 2024 +0800 + + refactor: zcash crates + +commit 45a5272ca2c8c1015ed19b2330e27f54ca7d894e +Author: soralit +Date: Tue Oct 29 11:49:27 2024 +0800 + + feat: introduce pczt vendor crate diff --git a/firmware.cmake b/firmware.cmake index 0092f06ed..62142d2a6 100644 --- a/firmware.cmake +++ b/firmware.cmake @@ -27,7 +27,7 @@ aux_source_directory(src/crypto CRYPTO) aux_source_directory(src/crypto/bips BIPS) aux_source_directory(src/crypto/checksum CHECKSUM) aux_source_directory(src/crypto/utils CRYPTO_UTILS) -file(GLOB_RECURSE WEBUSB_PROTOCOL WEBUSB_PROTOCOL/*.c) +file(GLOB_RECURSE WEBUSB_PROTOCOL src/WEBUSB_PROTOCOL/*.c) list(FILTER all_files EXCLUDE REGEX "some_directory/general/.*") file(GLOB_RECURSE USB_DRIVER @@ -57,7 +57,11 @@ if(NOT BUILD_PRODUCTION) endif() file(GLOB_RECURSE SRC - "src/*.c" + "src/device_settings.c" + "src/main.c" + "src/presetting.c" + "src/user_fatfs.c" + "src/user_sqlite3.c" "src/utils/*.c" "src/utils/log/*.c" "src/managers/*.c" diff --git a/src/crypto/account_public_info.c b/src/crypto/account_public_info.c index 9f7eb4b14..cb7231a83 100644 --- a/src/crypto/account_public_info.c +++ b/src/crypto/account_public_info.c @@ -21,15 +21,9 @@ #include "multi_sig_wallet_manager.h" #include "log_print.h" #include "rsa.h" - -#ifdef COMPILE_SIMULATOR -#include "simulator_model.h" -#else -#include "drv_mpu.h" -#endif +#include "gui_model.h" #ifdef BTC_ONLY -#include "gui_btc_home_widgets.h" static void LoadCurrentAccountMultiReceiveIndex(void); #endif @@ -643,8 +637,7 @@ int32_t AccountPublicSavePublicInfo(uint8_t accountIndex, const char *password, memcpy_s(iv_bytes, 16, iv_response->data, 16); free_simple_response_u8(iv_response); xPubResult = rust_aes256_cbc_encrypt(zcashUfvk, password, iv_bytes, 16); - } - else { + } else { xPubResult = ProcessKeyType(seed, len, g_chainTable[i].cryptoKey, g_chainTable[i].path, icarusMasterKey, ledgerBitbox02Key); } if (g_chainTable[i].cryptoKey == RSA_KEY && xPubResult == NULL) { diff --git a/src/crypto/rsa.c b/src/crypto/rsa.c index a5254b484..eac1c5ee1 100644 --- a/src/crypto/rsa.c +++ b/src/crypto/rsa.c @@ -114,7 +114,7 @@ int FlashWriteRsaPrimes(const uint8_t *data) int len = GetMnemonicType() == MNEMONIC_TYPE_BIP39 ? sizeof(seed) : GetCurrentAccountEntropyLen(); int32_t seed_ret = GetAccountSeed(GetCurrentAccountIndex(), seed, GetPassword()); ASSERT(seed_ret == 0); - SimpleResponse_u8 *cryptData = aes256_encrypt_primes(seed, len, data); + SimpleResponse_u8 *cryptData = aes256_encrypt_primes(seed, len, (PtrBytes)data); memcpy_s(fullData, SPI_FLASH_RSA_DATA_SIZE, cryptData->data, SPI_FLASH_RSA_DATA_SIZE); uint8_t *hash = SRAM_MALLOC(SPI_FLASH_RSA_HASH_SIZE); diff --git a/src/managers/account_manager.c b/src/managers/account_manager.c index c754e8933..96110ce4b 100644 --- a/src/managers/account_manager.c +++ b/src/managers/account_manager.c @@ -562,7 +562,8 @@ int32_t CreateNewTonAccount(uint8_t accountIndex, const char *mnemonic, const ch return ret; } -static void SetZcashUFVK(uint8_t accountIndex, const char* ufvk, const uint8_t* seedFingerprint) { +static void SetZcashUFVK(uint8_t accountIndex, const char* ufvk, const uint8_t* seedFingerprint) +{ ASSERT(accountIndex <= 2); g_zcashUFVKcache.accountIndex = accountIndex; ClearZcashUFVK(); @@ -572,15 +573,16 @@ static void SetZcashUFVK(uint8_t accountIndex, const char* ufvk, const uint8_t* printf("SetZcashUFVK, %s\r\n", g_zcashUFVKcache.ufvkCache); } -static void ClearZcashUFVK() { +static void ClearZcashUFVK() +{ memset_s(g_zcashUFVKcache.ufvkCache, ZCASH_UFVK_MAX_LEN, '\0', ZCASH_UFVK_MAX_LEN); memset_s(g_zcashUFVKcache.seedFingerprint, 32, 0, 32); } -int32_t GetZcashUFVK(uint8_t accountIndex, char* outUFVK, uint8_t* outSFP) { +int32_t GetZcashUFVK(uint8_t accountIndex, char* outUFVK, uint8_t* outSFP) +{ ASSERT(accountIndex <= 2); - if (g_zcashUFVKcache.accountIndex == accountIndex) - { + if (g_zcashUFVKcache.accountIndex == accountIndex) { strcpy_s(outUFVK, ZCASH_UFVK_MAX_LEN, g_zcashUFVKcache.ufvkCache); memcpy_s(outSFP, 32, g_zcashUFVKcache.seedFingerprint, 32); return SUCCESS_CODE; @@ -588,11 +590,11 @@ int32_t GetZcashUFVK(uint8_t accountIndex, char* outUFVK, uint8_t* outSFP) { return ERR_ZCASH_INVALID_ACCOUNT_INDEX; } -int32_t CalculateZcashUFVK(uint8_t accountIndex, const char* password) { +int32_t CalculateZcashUFVK(uint8_t accountIndex, const char* password) +{ ASSERT(accountIndex <= 2); - if (GetMnemonicType() == MNEMONIC_TYPE_SLIP39 || GetMnemonicType() == MNEMONIC_TYPE_TON) - { + if (GetMnemonicType() == MNEMONIC_TYPE_SLIP39 || GetMnemonicType() == MNEMONIC_TYPE_TON) { return SUCCESS_CODE; } @@ -613,8 +615,7 @@ int32_t CalculateZcashUFVK(uint8_t accountIndex, const char* password) { strcpy_s(ufvk, ZCASH_UFVK_MAX_LEN, response->data); free_simple_response_c_char(response); SimpleResponse_u8 *responseSFP = calculate_zcash_seed_fingerprint(seed, len); - if (responseSFP->error_code != 0) - { + if (responseSFP->error_code != 0) { ret = response->error_code; printf("error: %s\r\n", response->error_message); return ret; diff --git a/src/managers/btc_only/multi_sig_wallet_manager.c b/src/managers/btc_only/multi_sig_wallet_manager.c index 4e03ab99c..0d57ac797 100644 --- a/src/managers/btc_only/multi_sig_wallet_manager.c +++ b/src/managers/btc_only/multi_sig_wallet_manager.c @@ -6,7 +6,7 @@ #include "user_memory.h" #include "account_manager.h" #include "assert.h" -#include "gui_btc_home_widgets.h" +#include "gui_home_widgets.h" #include "multi_sig_wallet_manager.h" #define MAX_NAME_LENGTH 64 diff --git a/src/managers/keystore.c b/src/managers/keystore.c index 9eccf1349..38d7a4c8b 100644 --- a/src/managers/keystore.c +++ b/src/managers/keystore.c @@ -798,7 +798,8 @@ int32_t GenerateTonMnemonic(char *mnemonic, const char *password) } #endif -int32_t GenerateTRNGRandomness(uint8_t *randomness, uint8_t len) { +int32_t GenerateTRNGRandomness(uint8_t *randomness, uint8_t len) +{ return GenerateEntropy(randomness, len, "generate trng randomness"); } diff --git a/src/tasks/data_parser_task.c b/src/tasks/data_parser_task.c index 105e96cae..65c8a7e04 100644 --- a/src/tasks/data_parser_task.c +++ b/src/tasks/data_parser_task.c @@ -105,14 +105,6 @@ void PushDataToField(uint8_t *data, uint16_t len) } } -static uint8_t IsPrivileged(void) -{ - uint32_t control = 0; - __asm volatile("MRS %0, control" : "=r"(control) : : "memory"); - printf("control = %d\n", control); - return (control & 1) == 0; -} - static void DataParserCacheMpuInit(void) { uint32_t region_size = (uint32_t)&__data_parser_end - (uint32_t)&__data_parser_start; diff --git a/src/tasks/qrdecode_task.c b/src/tasks/qrdecode_task.c index 9da7eb89b..e899d635d 100644 --- a/src/tasks/qrdecode_task.c +++ b/src/tasks/qrdecode_task.c @@ -125,7 +125,7 @@ static void QrDecodeTask(void *argument) void ProcessQr(uint32_t count) { - char *qrString = GetDataParserCache(); + uint8_t *qrString = GetDataParserCache(); static uint8_t testProgress = 0; static bool firstQrFlag = true; static PtrDecoder decoder = NULL; diff --git a/src/ui/gui_analyze/gui_analyze.c b/src/ui/gui_analyze/gui_analyze.c index 44840e2a3..4995a35a2 100644 --- a/src/ui/gui_analyze/gui_analyze.c +++ b/src/ui/gui_analyze/gui_analyze.c @@ -5,6 +5,8 @@ #include "gui_analyze.h" #include "gui_chain.h" #include "gui_model.h" +#include "multi/general/gui_general_analyze.h" +#include "multi/cyberpunk/gui_cyberpunk_analyze.h" #ifndef COMPILE_SIMULATOR #include "safe_mem_lib.h" @@ -64,263 +66,7 @@ const static GuiAnalyze_t g_analyzeArray[] = { NULL, FreeBtcMsgMemory, }, -#ifndef BTC_ONLY - // temper test the ethereum page view not for production usage - { - REMAPVIEW_ETH, -#ifndef COMPILE_SIMULATOR - // ethJson, - "{\"name\":\"eth_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,144],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text\":\"Max Txn Fee\",\"pos\":[24,98],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthValue\",\"pos\":[24,50],\"text_color\":16090890,\"font\":\"openSansEnLittleTitle\"},{\"type\":\"label\",\"text_func\":\"GetEthTxFee\",\"pos\":[156,98],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthNetWork\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetEthToFromSize\",\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthGetFromAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"img\",\"pos\":[24,129],\"exist_func\":\"GetEthEnsExist\",\"img_src\":\"imgEns\"},{\"type\":\"label\",\"text_func\":\"GetEthEnsName\",\"exist_func\":\"GetEthEnsExist\",\"pos\":[56,126],\"font\":\"openSansEnIllustrate\",\"text_color\":1827014},{\"type\":\"label\",\"text\":\"To\",\"pos_func\":\"GetEthToLabelPos\",\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetEthGetToAddress\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\"},{\"type\":\"img\",\"pos\":[0,11],\"align_to\":-2,\"align\":13,\"exist_func\":\"GetToEthEnsExist\",\"img_src\":\"imgEns\"},{\"type\":\"label\",\"text_func\":\"GetToEthEnsName\",\"exist_func\":\"GetToEthEnsExist\",\"pos\":[8,0],\"align_to\":-2,\"align\":20,\"font\":\"openSansEnIllustrate\",\"text_color\":1827014},{\"type\":\"img\",\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"exist_func\":\"GetEthContractDataExist\",\"img_src\":\"imgContract\"},{\"type\":\"label\",\"text_func\":\"GetEthContractName\",\"exist_func\":\"GetEthContractDataExist\",\"pos\":[38,8],\"align_to\":-3,\"align\":13,\"font\":\"openSansEnIllustrate\",\"text_color\":10782207}]}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"table\":{\"FeeMarket\":{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,316],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthValue\",\"pos\":[92,16],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Max Fee\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthMaxFee\",\"pos\":[118,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"· Max Fee Price * Gas Limit\",\"pos\":[24,92],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Max Priority\",\"pos\":[24,124],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthMaxPriority\",\"pos\":[153,124],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"· Max Priority Fee Price * Gas Limit\",\"pos\":[24,162],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Max Fee Price\",\"pos\":[24,194],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthMaxFeePrice\",\"pos\":[169,194],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Max Priority Fee Price\",\"pos\":[24,232],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthMaxPriorityFeePrice\",\"pos\":[242,232],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Gas Limit\",\"pos\":[24,270],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthGasLimit\",\"pos\":[127,270],\"font\":\"openSansEnIllustrate\"}]},\"legacy\":{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,208],\"align\":2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthValue\",\"pos\":[92,16],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Max Txn Fee\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthTxFee\",\"pos\":[156,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetTxnFeeDesc\",\"pos\":[24,92],\"text_opa\":144,\"font\":\"openSansDesc\"},{\"type\":\"label\",\"text\":\"Gas Price\",\"pos\":[24,124],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthGasPrice\",\"pos\":[127,124],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Gas Limit\",\"pos\":[24,162],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthGasLimit\",\"pos\":[127,162],\"font\":\"openSansEnIllustrate\"}]}}},{\"type\":\"container\",\"pos\":[16,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthNetWork\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"exist_func\":\"GetEthContractDataExist\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthMethodName\",\"pos\":[113,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetEthToFromSize\",\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthGetFromAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"img\",\"pos\":[24,129],\"exist_func\":\"GetEthEnsExist\",\"img_src\":\"imgEns\"},{\"type\":\"label\",\"text_func\":\"GetEthEnsName\",\"exist_func\":\"GetEthEnsExist\",\"pos\":[56,126],\"font\":\"openSansEnIllustrate\",\"text_color\":1827014},{\"type\":\"label\",\"text\":\"To\",\"pos_func\":\"GetEthToLabelPos\",\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetEthGetToAddress\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\"},{\"type\":\"img\",\"pos\":[0,11],\"align_to\":-2,\"align\":13,\"exist_func\":\"GetToEthEnsExist\",\"img_src\":\"imgEns\"},{\"type\":\"label\",\"text_func\":\"GetToEthEnsName\",\"exist_func\":\"GetToEthEnsExist\",\"pos\":[8,0],\"align_to\":-2,\"align\":20,\"font\":\"openSansEnIllustrate\",\"text_color\":1827014},{\"type\":\"img\",\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"exist_func\":\"GetEthContractDataExist\",\"img_src\":\"imgContract\"},{\"type\":\"label\",\"text_func\":\"GetEthContractName\",\"exist_func\":\"GetEthContractDataExist\",\"pos\":[38,8],\"align_to\":-3,\"align\":13,\"font\":\"openSansEnIllustrate\",\"text_color\":10782207}]},{\"type\":\"label\",\"text\":\"Input Data\",\"align_to\":-2,\"align\":13,\"exist_func\":\"GetEthInputDataExist\",\"pos\":[0,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetEthContractDataSize\",\"exist_func\":\"GetEthInputDataExist\",\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"exist_func\":\"GetEthContractDataNotExist\",\"text_func\":\"GetEthTransactionData\",\"text_width\":360,\"pos\":[24,16],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"exist_func\":\"GetEthContractDataNotExist\",\"text\":\"Unknown Contract\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"text_color\":16105777,\"font\":\"openSansEnIllustrate\"},{\"type\":\"container\",\"exist_func\":\"GetEthContractDataNotExist\",\"aflag\":2,\"cb\":\"EthContractLearnMore\",\"pos\":[0,8],\"size\":[144,30],\"align_to\":-2,\"align\":13,\"bg_color\":1907997,\"children\":[{\"type\":\"label\",\"text\":\"Learn More\",\"text_width\":360,\"pos\":[0,0],\"text_color\":1827014,\"font\":\"openSansEnIllustrate\"},{\"type\":\"img\",\"img_src\":\"imgQrcodeTurquoise\",\"pos\":[120,3],\"text_color\":3056500,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"exist_func\":\"GetEthContractDataExist\",\"text\":\"Method\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"exist_func\":\"GetEthContractDataExist\",\"text_func\":\"GetEthMethodName\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"name\":\"contract_data\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,100],\"bg_color\":1907997,\"key_width\":30,\"table_func\":\"GetEthContractData\",\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetEthContractDataExist\"}]}]}]}", -#else - PC_SIMULATOR_PATH "/page_eth.json", -#endif - GuiGetEthData, - GetEthTransType, - FreeEthMemory, - }, - { - REMAPVIEW_ETH_PERSONAL_MESSAGE, -#ifndef COMPILE_SIMULATOR - "{\"table\":{\"utf8_message\":{\"type\":\"container\",\"pos\":[0,39],\"size\":[408,500],\"align\":2,\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetMessageFrom\",\"pos\":[24,54],\"text_width\":360,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Message\",\"pos\":[24,130],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[24,168],\"size\":[360,332],\"align\":1,\"aflag\":16,\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text_func\":\"GetMessageUtf8\",\"pos\":[0,0],\"text_width\":360,\"font\":\"openSansEnIllustrate\",\"text_color\":16777215}]}]},\"raw_message\":{\"type\":\"container\",\"pos\":[0,39],\"size\":[408,500],\"align\":2,\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Raw Message\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[24,54],\"size\":[360,450],\"align\":1,\"aflag\":16,\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text_func\":\"GetMessageRaw\",\"pos\":[0,0],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]}]}}}", -#else - PC_SIMULATOR_PATH "/page_eth_person.json", -#endif - GuiGetEthPersonalMessage, - GetEthPersonalMessageType, - FreeEthMemory, - }, - { - REMAPVIEW_ETH_TYPEDDATA, -#ifndef COMPILE_SIMULATOR - "{\"type\":\"container\",\"pos\":[0,0],\"size\":[480,542],\"align\":0,\"bg_opa\":0,\"aflag\":16,\"children\":[{\"exist_func\":\"GetEthPermitWarningExist\",\"type\":\"container\",\"pos\":[36,24],\"size\":[408,152],\"align\":0,\"bg_color\":16078897,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"img\",\"pos\":[24,24],\"img_src\":\"imgWarningRed\"},{\"type\":\"label\",\"text\":\"WARNING\",\"pos\":[68,24],\"font\":\"openSansEnText\",\"text_color\":16078897},{\"type\":\"label\",\"text\":\"sign_eth_permit_warn\",\"pos\":[24,68],\"text_color\":16777215,\"font\":\"illustrate\",\"text_width\":360}]},{\"type\":\"container\",\"size\":[408,298],\"pos_func\":\"GetEthTypeDomainPos\",\"align\":0,\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Domain Name\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthTypedDataDomianName\",\"pos\":[24,54],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Verifying Contract\",\"pos\":[24,100],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthTypedDataDomianVerifyContract\",\"pos\":[24,138],\"text_color\":16777215,\"text_width\":360,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Primary Type\",\"pos\":[24,214],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthTypedDataPrimayType\",\"pos\":[24,252],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"text\":\"Message\",\"pos\":[0,16],\"align_to\":-2,\"align\":13,\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthTypedDataMessage\",\"text_len_func\":\"GetEthTypedDataMessageLen\",\"pos\":[0,16],\"align_to\":-2,\"align\":13,\"width\":408,\"bg_color\":16777215,\"bg_opa\":31,\"pad_vertical\":16,\"pad_horizontal\":24,\"radius\":24,\"text_color\":16777215,\"font\":\"openSansEnIllustrate\"},{\"exist_func\":\"GetEthPermitCantSign\",\"type\":\"container\",\"pos\":[0,16],\"align_to\":-2,\"align\":13,\"size\":[408,182],\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"img\",\"pos\":[24,24],\"img_src\":\"imgWarningRed\"},{\"type\":\"label\",\"text\":\"Cant't Sign it Now\",\"pos\":[68,24],\"font\":\"openSansEnText\",\"text_color\":16078897},{\"type\":\"label\",\"text\":\"sign_eth_permit_deny_sing\",\"pos\":[24,68],\"text_color\":16777215,\"font\":\"illustrate\",\"text_width\":360}]}]}", -#else - PC_SIMULATOR_PATH "/page_eth_type.json", -#endif - GuiGetEthTypeData, - NULL, - FreeEthMemory, - }, - { - REMAPVIEW_TRX, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"trx_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,106],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxValue\",\"pos\":[24,50],\"text_color\":16090890,\"font\":\"openSansEnLittleTitle\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxMethod\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,244],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxFromAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,130],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetTrxToAddress\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\"}]}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxValue\",\"pos\":[92,16],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxMethod\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,244],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxFromAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,130],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetTrxToAddress\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,130],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetTrxContractExist\",\"children\":[{\"type\":\"label\",\"text\":\"Contract Address\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxContract\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\",\"text_width\":360}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetTrxTokenExist\",\"children\":[{\"type\":\"label\",\"text\":\"Token ID\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxToken\",\"pos\":[123,16],\"font\":\"openSansEnIllustrate\"}]}]}]}", -#else - PC_SIMULATOR_PATH "/page_eth.json", -#endif - GuiGetTrxData, - NULL, - FreeTrxMemory, - }, - { - REMAPVIEW_COSMOS, -#ifndef COMPILE_SIMULATOR - "{\"table\":{\"tx\":{\"name\":\"cosmos_tx_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"list\",\"exist_func\":\"GetCosmosMsgListExist\",\"len_func\":\"GetCosmosMsgLen\",\"item_key_func\":\"GetCosmosMsgKey\",\"item_map\":{\"default\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,402],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[24,96],\"text_color\":16090890,\"text_width\":2000,\"font\":\"openSansEnLittleTitle\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,144],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,144],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,182],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"From\",\"text_width\":360,\"pos\":[24,220],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,288],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,326],\"font\":\"openSansEnIllustrate\"}]},\"Undelegate\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,402],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[24,96],\"text_color\":16090890,\"font\":\"openSansEnLittleTitle\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,144],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,144],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Validator\",\"pos\":[24,182],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Validator\",\"text_width\":360,\"pos\":[24,220],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,288],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,326],\"font\":\"openSansEnIllustrate\"}]},\"Re-delegate\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,402],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[24,96],\"text_color\":16090890,\"font\":\"openSansEnLittleTitle\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,144],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,144],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,182],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,220],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"New Validator\",\"pos\":[24,288],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"New Validator\",\"text_width\":360,\"pos\":[24,326],\"font\":\"openSansEnIllustrate\"}]},\"Withdraw Reward\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,320],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,62],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,138],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Validator\",\"pos\":[24,206],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Validator\",\"text_width\":360,\"pos\":[24,244],\"font\":\"openSansEnIllustrate\"}]},\"Vote\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,290],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Proposal\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Proposal\",\"pos\":[123,62],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Voted\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Voted\",\"pos\":[95,100],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,138],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Voter\",\"pos\":[24,176],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Voter\",\"pos\":[24,214],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]}}},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,106],\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetCosmosValueExist\",\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosValue\",\"pos\":[24,50],\"text_color\":16090890,\"text_width\":2000,\"font\":\"openSansEnLittleTitle\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,106],\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetCosmosVoteExist\",\"children\":[{\"type\":\"label\",\"text\":\"Proposal\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosProposal\",\"pos\":[123,16],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Voted\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosVoted\",\"pos\":[95,54],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosNetwork\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetCosmosMethodExist\",\"children\":[{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosMethod\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetCosmosOverviewAddrSize\",\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetCosmosAddrExist\",\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosAddress1Label\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress1Value\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress2Label\",\"pos\":[24,130],\"text_opa\":144,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosAddress2Exist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress2Value\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosAddress2Exist\"}]}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"list\",\"exist_func\":\"GetCosmosMsgListExist\",\"len_func\":\"GetCosmosMsgLen\",\"item_key_func\":\"GetCosmosMsgKey\",\"item_map\":{\"default\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,358],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[92,62],\"text_color\":16090890,\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"From\",\"text_width\":360,\"pos\":[24,176],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,244],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,282],\"font\":\"openSansEnIllustrate\"}]},\"IBC Transfer\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,396],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[92,62],\"text_color\":16090890,\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"From\",\"text_width\":360,\"pos\":[24,176],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,244],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,282],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Source Channel\",\"pos\":[24,350],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Source Channel\",\"text_width\":360,\"pos\":[187,350],\"font\":\"openSansEnIllustrate\"}]},\"Undelegate\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,358],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[92,62],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Validator\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Validator\",\"text_width\":360,\"pos\":[24,176],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,244],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,282],\"font\":\"openSansEnIllustrate\"}]},\"Re-delegate\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,464],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[92,62],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,176],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Old Validator\",\"pos\":[24,244],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Old Validator\",\"text_width\":360,\"pos\":[24,282],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"New Validator\",\"pos\":[24,350],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"New Validator\",\"text_width\":360,\"pos\":[24,388],\"font\":\"openSansEnIllustrate\"}]},\"Withdraw Reward\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,322],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,62],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,138],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Validator\",\"pos\":[24,206],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Validator\",\"text_width\":360,\"pos\":[24,244],\"font\":\"openSansEnIllustrate\"}]},\"Vote\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,290],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Proposal\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Proposal\",\"pos\":[123,62],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Voted\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Voted\",\"pos\":[95,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,138],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Voter\",\"pos\":[24,176],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Voter\",\"pos\":[24,214],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]}}},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetCosmosDetailMsgSize\",\"exist_func\":\"GetCosmosMethodExist\",\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"exist_func\":\"GetCosmosValueExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosValue\",\"pos\":[92,16],\"text_color\":16090890,\"text_width\":2000,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosValueExist\"},{\"type\":\"label\",\"text\":\"Proposal\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"exist_func\":\"GetCosmosVoteExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosProposal\",\"pos\":[123,16],\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosVoteExist\"},{\"type\":\"label\",\"text\":\"Voted\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"exist_func\":\"GetCosmosVoteExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosVoted\",\"pos\":[95,62],\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosVoteExist\"},{\"type\":\"label\",\"text\":\"Method\",\"pos_func\":\"GetCosmosDetailMethodLabelPos\",\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosMethod\",\"pos_func\":\"GetCosmosDetailMethodValuePos\",\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress1Label\",\"pos_func\":\"GetCosmosDetailAddress1LabelPos\",\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress1Value\",\"text_width\":360,\"pos_func\":\"GetCosmosDetailAddress1ValuePos\",\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Old Validator\",\"pos\":[24,222],\"text_opa\":144,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosOldValidatorExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosOldValidator\",\"text_width\":360,\"pos\":[24,260],\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosOldValidatorExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress2Label\",\"pos_func\":\"GetCosmosDetailAddress2LabelPos\",\"text_opa\":144,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosAddress2Exist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress2Value\",\"text_width\":360,\"pos_func\":\"GetCosmosDetailAddress2ValuePos\",\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosAddress2Exist\"},{\"type\":\"label\",\"text\":\"Source Channel\",\"pos\":[24,336],\"text_opa\":144,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosChannelExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosChannel\",\"pos\":[187,336],\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosChannelExist\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,170],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Max Fee\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosMaxFee\",\"pos\":[118,16],\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\" · Max Fee Price * Gas Limit\",\"pos\":[24,54],\"font\":\"openSansDesc\",\"text_opa\":144},{\"type\":\"label\",\"text\":\"Fee\",\"pos\":[24,86],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosFee\",\"pos\":[73,86],\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Gas Limit\",\"pos\":[24,124],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosGasLimit\",\"pos\":[127,124],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,100],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosNetwork\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Chain ID\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosChainId\",\"pos\":[120,54],\"font\":\"openSansEnIllustrate\"}]}]}]},\"unknown\":{\"name\":\"cosmos_unknown_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,600],\"bg_color\":0,\"children\":[{\"type\":\"container\",\"pos\":[0,80],\"size\":[408,170],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Max Fee\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Max Fee\",\"pos\":[118,16],\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\" · Max Fee Price * Gas Limit\",\"pos\":[24,54],\"font\":\"openSansDesc\",\"text_opa\":144},{\"type\":\"label\",\"text\":\"Fee\",\"pos\":[24,86],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Fee\",\"pos\":[73,86],\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Gas Limit\",\"pos\":[24,124],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Gas Limit\",\"pos\":[127,124],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Network\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Message\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Message\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16105777}]}]},\"msg\":{\"name\":\"cosmos_msg_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,600],\"bg_color\":0,\"children\":[{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Network\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,130],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Signer\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Signer\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,250],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Message\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Message\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]}]}}}", -#else - PC_SIMULATOR_PATH "/page_cosmos.json", -#endif - GuiGetCosmosData, - GuiGetCosmosTmpType, - FreeCosmosMemory, - }, - { - REMAPVIEW_SUI, -#ifndef COMPILE_SIMULATOR - "{\"type\":\"container\",\"pos\":[36,0],\"size\":[408,526],\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text\":\"Transaction Raw Data\",\"text_width\":360,\"text_opa\":144,\"pos\":[0,0],\"font\":\"openSansEnIllustrate\"},{\"type\":\"container\",\"pos\":[0,38],\"size\":[408,488],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetSuiDetail\",\"text_len_func\":\"GetSuiDetailLen\",\"text_width\":360,\"pos\":[24,24],\"font\":\"openSansEnIllustrate\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_sui.json", -#endif - GuiGetSuiData, - NULL, - FreeSuiMemory, - }, - { - REMAPVIEW_SUI_SIGN_MESSAGE_HASH, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"sui_sign_hash_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,774],\"bg_color\":0,\"border_width\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowSuiSignMessageHashOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowSuiSignMessageHashDetails\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_sign_hash.json", -#endif - GuiGetSuiSignMessageHashData, - NULL, - FreeSuiMemory - }, - { - REMAPVIEW_SOL, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"sol_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,774],\"bg_color\":0,\"border_width\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowSolTxOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowSolTxDetail\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_sol.json", -#endif - GuiGetSolData, - NULL, - FreeSolMemory, - }, - { - REMAPVIEW_SOL_MESSAGE, -#ifndef COMPILE_SIMULATOR - "{\"table\":{\"utf8_message\":{\"type\":\"container\",\"pos\":[0,39],\"size\":[408,500],\"align\":2,\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetSolMessageFrom\",\"pos\":[24,54],\"text_width\":360,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Message\",\"pos\":[24,130],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[24,168],\"size\":[360,332],\"align\":1,\"aflag\":16,\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text_func\":\"GetSolMessageUtf8\",\"pos\":[0,0],\"text_width\":360,\"font\":\"openSansEnIllustrate\",\"text_color\":16777215}]}]},\"raw_message\":{\"type\":\"container\",\"pos\":[0,39],\"size\":[408,500],\"align\":2,\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Raw Message\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[24,54],\"size\":[360,450],\"align\":1,\"aflag\":16,\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text_func\":\"GetSolMessageRaw\",\"pos\":[0,0],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]}]}}}", -#else - PC_SIMULATOR_PATH "/page_sol_message.json", -#endif - GuiGetSolMessageData, - GetSolMessageType, - FreeSolMemory, - }, - { - REMAPVIEW_APT, -#ifndef COMPILE_SIMULATOR - "{\"type\":\"container\",\"pos\":[36,0],\"size\":[408,526],\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text\":\"Transaction Raw Data\",\"text_width\":360,\"text_opa\":144,\"pos\":[0,0],\"font\":\"openSansEnIllustrate\"},{\"type\":\"container\",\"pos\":[0,38],\"size\":[408,488],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetAptosDetail\",\"text_len_func\":\"GetAptosDetailLen\",\"text_width\":360,\"pos\":[24,24],\"font\":\"openSansEnIllustrate\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_eth.json", -#endif - GuiGetAptosData, - NULL, - FreeAptosMemory, - }, - { - REMAPVIEW_ADA, -#ifndef COMPILE_SIMULATOR - "{\"type\":\"container\",\"pos\":[36,0],\"size\":[408,500],\"bg_color\":0,\"border_width\":0,\"children\":[{\"type\":\"container\",\"bg_opa\":31,\"radius\":24,\"size\":[408,62],\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetAdaNetwork\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"pos\":[0,16],\"size\":[408,138],\"children\":[{\"type\":\"label\",\"text\":\"InputValue\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetAdaTotalInput\",\"pos\":[147,16],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"OutputValue\",\"pos\":[24,54],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetAdaTotalOutput\",\"pos\":[164,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Fee\",\"pos\":[24,92],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetAdaFee\",\"pos\":[73,92],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetAdaInputDetailSize\",\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"name\":\"input\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,54],\"bg_color\":2105376,\"key_width\":30,\"table_func\":\"GetAdaInputDetail\",\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetAdaOutputDetailSize\",\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"name\":\"input\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,54],\"bg_color\":2105376,\"key_width\":30,\"table_func\":\"GetAdaOutputDetail\",\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"exist_func\":\"GetAdaVotingProceduresExist\",\"text_func\":\"GetAdaVotingProceduresLabel\",\"pos\":[0,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"align\":13,\"align_to\":-2},{\"name\":\"VotingProcedures\",\"type\":\"container\",\"pos\":[0,16],\"exist_func\":\"GetAdaVotingProceduresExist\",\"size_func\":\"GetAdaVotingProceduresSize\",\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"name\":\"input\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,24],\"bg_color\":2105376,\"key_width\":30,\"table_func\":\"GetAdaVotingProceduresData\",\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"exist_func\":\"GetAdaCertificatesExist\",\"text_func\":\"GetAdaCertificatesLabel\",\"pos\":[0,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"align\":13,\"align_to\":-2},{\"name\":\"certificates\",\"type\":\"container\",\"pos\":[0,16],\"exist_func\":\"GetAdaCertificatesExist\",\"size_func\":\"GetAdaCertificatesSize\",\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"name\":\"input\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,24],\"bg_color\":2105376,\"key_width\":30,\"table_func\":\"GetAdaCertificatesData\",\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"text_func\":\"GetAdaWithdrawalsLabel\",\"exist_func\":\"GetAdaWithdrawalsExist\",\"pos\":[0,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"align\":13,\"align_to\":-2},{\"name\":\"withdrawal\",\"type\":\"container\",\"pos\":[0,16],\"exist_func\":\"GetAdaWithdrawalsExist\",\"size_func\":\"GetAdaWithdrawalsSize\",\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"name\":\"input\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,24],\"bg_color\":2105376,\"key_width\":30,\"table_func\":\"GetAdaWithdrawalsData\",\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"pos\":[0,16],\"exist_func\":\"GetAdaExtraDataExist\",\"text\":\"ExtraData\",\"align\":13,\"align_to\":-2,\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,500],\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetAdaExtraDataExist\",\"children\":[{\"type\":\"label\",\"text_func\":\"GetAdaExtraData\",\"text_len_func\":\"GetAdaExtraDataLen\",\"text_width\":360,\"pos\":[24,24],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"exist_func\":\"GetAdaVotingProposalsExist\",\"pos\":[0,16],\"size\":[408,138],\"bg_opa\":31,\"radius\":24,\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text_func\":\"GetAdaVotingProposalsLabel\",\"exist_func\":\"GetAdaVotingProposalsExist\",\"pos\":[16,16],\"text_color\":16090890,\"font\":\"illustrate\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_ada.json", -#endif - GuiGetAdaData, - NULL, - FreeAdaMemory, - }, - { - REMAPVIEW_ADA_SIGN_TX_HASH, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"ada_sign_tx_hash_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,774],\"bg_color\":0,\"border_width\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowAdaSignTxHashOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowAdaSignTxHashDetails\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_sign_ada_tx_hash.json", -#endif - GuiGetAdaSignTxHashData, - NULL, - FreeAdaMemory - }, - { - REMAPVIEW_ADA_SIGN_DATA, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"ada_sign_data_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,542],\"bg_color\":0,\"children\":[{\"type\":\"container\",\"size\":[408,100],\"pos\":[0,0],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Path \",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetAdaSignDataDerviationPathText\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"size\":[408,138],\"pos\":[0,124],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Public Key\",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetAdaSignDataXPubText\",\"text_len_func\":\"GetAdaSignDataXPubLength\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"size\":[408,138],\"pos\":[0,278],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Message Hash\",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetAdaSignDataMessageHashText\",\"text_len_func\":\"GetAdaSignDataMessageHashLength\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"size\":[408,228],\"pos\":[0,432],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Payload\",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetAdaSignDataPayloadText\",\"text_len_func\":\"GetAdaSignDataPayloadLength\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_ada_sign_data.json", -#endif - GuiGetAdaSignDataData, - NULL, - FreeAdaSignDataMemory, - }, - { - REMAPVIEW_ADA_CATALYST, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"ada_catalyst_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,542],\"bg_color\":0,\"children\":[{\"type\":\"container\",\"pos\":[0,0],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text\":\"Catalyst Key Registration\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,78],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Nonce\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCatalystNonce\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,156],\"size\":[408,160],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"StakeKey\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCatalystVotePublicKey\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,332],\"size\":[408,258],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"RewardsGoTo\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCatalystRewards\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"custom_container\",\"pos\":[24,182],\"custom_show_func\":\"GetCatalystRewardsNotice\"}]},{\"type\":\"container\",\"pos\":[0,606],\"size_func\":\"GetCatalystVoteKeysSize\",\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"VoteKey\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCatalystVoteKeys\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_ada_catalyst.json", -#endif - GuiGetAdaCatalyst, - NULL, - FreeAdaCatalystMemory, - }, - { - REMAPVIEW_XRP, -#ifndef COMPILE_SIMULATOR - "{\"type\":\"container\",\"pos\":[36,0],\"size\":[408,526],\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text\":\"Transaction Raw Data\",\"text_width\":360,\"text_opa\":144,\"pos\":[0,0],\"font\":\"openSansEnIllustrate\"},{\"type\":\"container\",\"pos\":[0,38],\"size\":[408,488],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetXrpDetail\",\"text_len_func\":\"GetXrpDetailLen\",\"text_width\":360,\"pos\":[24,24],\"font\":\"openSansEnIllustrate\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_xrp.json", -#endif - GuiGetXrpData, - NULL, - FreeXrpMemory, - }, - { - REMAPVIEW_AR, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"ar_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,144],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetArweaveValue\",\"pos\":[24,50],\"text_color\":16090890,\"font\":\"openSansEnLittleTitle\"},{\"type\":\"label\",\"text\":\"Fee\",\"pos\":[24,98],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetArweaveFee\",\"pos\":[73,98],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,244],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetArweaveFromAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,130],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetArweaveToAddress\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\"}]}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,358],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"##1\",\"font\":\"openSansEnIllustrate\",\"text_color\":16090890,\"pos\":[24,16]},{\"type\":\"label\",\"text\":\"Value\",\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"pos\":[24,62]},{\"type\":\"label\",\"text_func\":\"GetArweaveValue\",\"pos\":[92,62],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Fee\",\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"pos\":[24,100]},{\"type\":\"label\",\"text_func\":\"GetArweaveFee\",\"pos\":[73,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"From\",\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"pos\":[24,138]},{\"type\":\"label\",\"text_func\":\"GetArweaveFromAddress\",\"pos\":[24,176],\"text_width\":360,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,244],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetArweaveToAddress\",\"pos\":[24,282],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"custom_container\",\"pos\":[0,16],\"radius\":24,\"custom_show_func\":\"GuiShowArweaveTxDetail\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_ar.json", -#endif - GuiGetArData, - NULL, - FreeArMemory, - }, - { - REMAPVIEW_AR_MESSAGE, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"ar_message_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,542],\"bg_color\":0,\"children\":[{\"type\":\"container\",\"size\":[408,130],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Address \",\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetArweaveMessageAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,146],\"size\":[408,766],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Message(UTF-8)\",\"font\":\"openSansEnIllustrate\",\"text_color\":16090890,\"pos\":[24,16]},{\"type\":\"label\",\"text_func\":\"GetArweaveMessageText\",\"text_len_func\":\"GetArweaveMessageLength\",\"pos\":[24,62],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,928],\"size\":[408,900],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Message\",\"font\":\"openSansEnIllustrate\",\"text_color\":16090890,\"pos\":[24,16]},{\"type\":\"label\",\"text_func\":\"GetArweaveRawMessage\",\"text_len_func\":\"GetArweaveRawMessageLength\",\"pos\":[24,62],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_ar_message.json", -#endif - GuiGetArData, - NULL, - FreeArMemory, - }, - { - REMAPVIEW_STELLAR, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"ar_message_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,542],\"bg_color\":0,\"children\":[{\"type\":\"custom_container\",\"size\":[408,212],\"pos\":[0,0],\"radius\":24,\"custom_show_func\":\"GuiStellarTxNotice\"},{\"type\":\"container\",\"size\":[408,310],\"pos\":[0,236],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"XDR\",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetStellarRawMessage\",\"text_len_func\":\"GetStellarRawMessageLength\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_stellar.json", -#endif - GuiGetStellarData, - NULL, - FreeStellarMemory, - }, - { - REMAPVIEW_STELLAR_HASH, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"ar_message_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,542],\"bg_color\":0,\"children\":[{\"type\":\"custom_container\",\"size\":[408,260],\"pos\":[0,0],\"radius\":24,\"custom_show_func\":\"GuiStellarHashNotice\"},{\"type\":\"container\",\"size\":[408,130],\"pos\":[0,284],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Hash\",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetStellarRawMessage\",\"text_len_func\":\"GetStellarRawMessageLength\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_stellar_hash.json", -#endif - GuiGetStellarData, - NULL, - FreeStellarMemory, - }, - { - REMAPVIEW_AR_DATAITEM, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"ar_data_item_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiArDataItemOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Additions\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiArDataItemDetail\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_ar_data_item.json", -#endif - GuiGetArData, - NULL, - FreeArMemory, - }, - { - REMAPVIEW_TON, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"ton_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiTonTxOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Raw Data\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiTonTxRawData\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_ton.json", -#endif - GuiGetTonGUIData, - NULL, - FreeArMemory, - }, - { - REMAPVIEW_TON_SIGNPROOF, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"btc_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,774],\"bg_color\":0,\"border_width\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiTonProofOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Raw Data\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiTonProofRawData\"}]}]}", -#else - PC_SIMULATOR_PATH "/page_ton_proof.json", -#endif - GuiGetTonProofGUIData, - NULL, - FreeArMemory, - }, - { - REMAPVIEW_ZCASH, -#ifndef COMPILE_SIMULATOR - "{\"name\":\"zcash_page\",\"type\":\"custom_container\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"custom_show_func\":\"GuiZcashOverview\"}", -#else - PC_SIMULATOR_PATH "/page_zcash.json", -#endif - GuiGetZcashGUIData, - NULL, - FreeZcashMemory, - } -#endif + GUI_ANALYZE_OBJ_SURPLUS }; void *GuiTemplateReload(lv_obj_t *parent, uint8_t index); @@ -382,162 +128,48 @@ GetContSizeFunc GetPsbtContainerSize(char *type) return NULL; } -#ifndef BTC_ONLY -GetContSizeFunc GetEthContainerSize(char *type) -{ - if (!strcmp(type, "GetEthToFromSize")) { - return GetEthToFromSize; - } else if (!strcmp(type, "GetEthContractDataSize")) { - return GetEthContractDataSize; - } - return NULL; -} - -GetContSizeFunc GetCosmosContainerSize(char *type) -{ - if (!strcmp(type, "GetCosmosDetailMsgSize")) { - return GetCosmosDetailMsgSize; - } else if (!strcmp(type, "GetCosmosOverviewAddrSize")) { - return GetCosmosOverviewAddrSize; - } - return NULL; -} - -GetContSizeFunc GetAdaContainerSize(char *type) +__attribute__((weak)) GetContSizeFunc GetOtherChainContainerSize(char *type, GuiRemapViewType remapIndex) { - if (!strcmp(type, "GetAdaInputDetailSize")) { - return GetAdaInputDetailSize; - } - if (!strcmp(type, "GetAdaOutputDetailSize")) { - return GetAdaOutputDetailSize; - } - if (!strcmp(type, "GetAdaCertificatesSize")) { - return GetAdaCertificatesSize; - } - if (!strcmp(type, "GetAdaVotingProceduresSize")) { - return GetAdaVotingProceduresSize; - } - if (!strcmp(type, "GetAdaWithdrawalsSize")) { - return GetAdaWithdrawalsSize; - } - if (!strcmp(type, "GetCatalystVoteKeysSize")) { - return GetCatalystVoteKeysSize; - } return NULL; } -#endif GetContSizeFunc GuiTemplateSizeFuncGet(char *type) { - switch (g_reMapIndex) { - case REMAPVIEW_BTC: + if (g_reMapIndex == REMAPVIEW_BTC) { return GetPsbtContainerSize(type); -#ifndef BTC_ONLY - case REMAPVIEW_ETH: - return GetEthContainerSize(type); - case REMAPVIEW_COSMOS: - return GetCosmosContainerSize(type); - case REMAPVIEW_ADA: - case REMAPVIEW_ADA_SIGN_DATA: - case REMAPVIEW_ADA_CATALYST: - return GetAdaContainerSize(type); -#endif - default: - return NULL; + } else { + GetOtherChainContainerSize(type, g_reMapIndex); } - - return NULL; } -#ifndef BTC_ONLY -GetListLenFunc GetCosmosListLen(char *type) +__attribute__((weak)) GetListLenFunc GetOtherChainListLenFuncGet(char *type, GuiRemapViewType remapIndex) { - if (!strcmp(type, "GetCosmosMsgLen")) { - return GetCosmosMsgLen; - } return NULL; } -#endif GetListLenFunc GuiTemplateListLenFuncGet(char *type) { - switch (g_reMapIndex) { -#ifndef BTC_ONLY - case REMAPVIEW_COSMOS: - return GetCosmosListLen(type); -#endif - default: - return NULL; - } + return GetOtherChainListLenFuncGet(type, g_reMapIndex); } -#ifndef BTC_ONLY -GetListItemKeyFunc GetCosmosListItemKey(char *type) +__attribute__((weak)) GetListItemKeyFunc GetOtherChainListItemKeyFuncGet(char *type, GuiRemapViewType remapIndex) { - if (!strcmp(type, "GetCosmosMsgKey")) { - return GetCosmosMsgKey; - } return NULL; } -#endif GetListItemKeyFunc GuiTemplateListItemKeyFuncGet(char *type) { - switch (g_reMapIndex) { -#ifndef BTC_ONLY - case REMAPVIEW_COSMOS: - return GetCosmosListItemKey(type); -#endif - default: - return NULL; - } + return GetOtherChainListItemKeyFuncGet(type, g_reMapIndex); } -#ifndef BTC_ONLY -GetContSizeFunc GetEthObjPos(char *type) +__attribute__((weak)) GetContSizeFunc GetOtherChainPos(char *type, GuiRemapViewType remapIndex) { - if (!strcmp(type, "GetEthToLabelPos")) { - return GetEthToLabelPos; - } else if (!strcmp(type, "GetEthTypeDomainPos")) { - return GetEthTypeDomainPos; - } return NULL; } -GetContSizeFunc GetCosmosObjPos(char *type) -{ - if (!strcmp(type, "GetCosmosDetailMethodLabelPos")) { - return GetCosmosDetailMethodLabelPos; - } else if (!strcmp(type, "GetCosmosDetailMethodValuePos")) { - return GetCosmosDetailMethodValuePos; - } else if (!strcmp(type, "GetCosmosDetailAddress1LabelPos")) { - return GetCosmosDetailAddress1LabelPos; - } else if (!strcmp(type, "GetCosmosDetailAddress1ValuePos")) { - return GetCosmosDetailAddress1ValuePos; - } else if (!strcmp(type, "GetCosmosDetailAddress2LabelPos")) { - return GetCosmosDetailAddress2LabelPos; - } else if (!strcmp(type, "GetCosmosDetailAddress2ValuePos")) { - return GetCosmosDetailAddress2ValuePos; - } - return NULL; -} -#endif - GetContSizeFunc GuiTemplatePosFuncGet(char *type) { - switch (g_reMapIndex) { -#ifndef BTC_ONLY - case REMAPVIEW_ETH: - case REMAPVIEW_ETH_TYPEDDATA: - return GetEthObjPos(type); - case REMAPVIEW_COSMOS: - return GetCosmosObjPos(type); -#endif - default: - return NULL; - } - - return NULL; + return GetOtherChainPos(type, g_reMapIndex); } GetLabelDataFunc GuiBtcTextFuncGet(char *type) @@ -562,96 +194,6 @@ GetLabelDataFunc GuiBtcTextFuncGet(char *type) return NULL; } -#ifndef BTC_ONLY -GetLabelDataFunc GuiEthTextFuncGet(char *type) -{ - if (!strcmp(type, "GetEthValue")) { - return GetEthValue; - } else if (!strcmp(type, "GetEthTxFee")) { - return GetEthTxFee; - } else if (!strcmp(type, "GetEthGasPrice")) { - return GetEthGasPrice; - } else if (!strcmp(type, "GetEthGasLimit")) { - return GetEthGasLimit; - } else if (!strcmp(type, "GetEthNetWork")) { - return GetEthNetWork; - } else if (!strcmp(type, "GetEthMaxFee")) { - return GetEthMaxFee; - } else if (!strcmp(type, "GetEthMaxPriority")) { - return GetEthMaxPriority; - } else if (!strcmp(type, "GetEthMaxFeePrice")) { - return GetEthMaxFeePrice; - } else if (!strcmp(type, "GetEthMaxPriorityFeePrice")) { - return GetEthMaxPriorityFeePrice; - } else if (!strcmp(type, "GetEthGetFromAddress")) { - return GetEthGetFromAddress; - } else if (!strcmp(type, "GetEthGetToAddress")) { - return GetEthGetToAddress; - } else if (!strcmp(type, "GetTxnFeeDesc")) { - return GetTxnFeeDesc; - } else if (!strcmp(type, "GetEthEnsName")) { - return GetEthEnsName; - } else if (!strcmp(type, "GetToEthEnsName")) { - return GetToEthEnsName; - } else if (!strcmp(type, "GetEthMethodName")) { - return GetEthMethodName; - } else if (!strcmp(type, "GetEthTransactionData")) { - return GetEthTransactionData; - } else if (!strcmp(type, "GetEthContractName")) { - return GetEthContractName; - } - - return NULL; -} - -GetLabelDataFunc GuiEthPersonalMessageTextFuncGet(char *type) -{ - if (!strcmp(type, "GetMessageFrom")) { - return GetMessageFrom; - } else if (!strcmp(type, "GetMessageUtf8")) { - return GetMessageUtf8; - } else if (!strcmp(type, "GetMessageRaw")) { - return GetMessageRaw; - } - return NULL; -} - -GetLabelDataFunc GuiSolMessageTextFuncGet(char *type) -{ - if (!strcmp(type, "GetSolMessageFrom")) { - return GetSolMessageFrom; - } else if (!strcmp(type, "GetSolMessageUtf8")) { - return GetSolMessageUtf8; - } else if (!strcmp(type, "GetSolMessageRaw")) { - return GetSolMessageRaw; - } - return NULL; -} - -GetLabelDataFunc GuiEthTypedDataTextFuncGet(char *type) -{ - if (!strcmp(type, "GetEthTypedDataDomianName")) { - return GetEthTypedDataDomianName; - } else if (!strcmp(type, "GetEthTypedDataDomianVersion")) { - return GetEthTypedDataDomianVersion; - } else if (!strcmp(type, "GetEthTypedDataDomianChainId")) { - return GetEthTypedDataDomianChainId; - } else if (!strcmp(type, "GetEthTypedDataDomianVerifyContract")) { - return GetEthTypedDataDomianVerifyContract; - } else if (!strcmp(type, "GetEthTypedDataDomianSalt")) { - return GetEthTypedDataDomianSalt; - } else if (!strcmp(type, "GetEthTypedDataMessage")) { - return GetEthTypedDataMessage; - } else if (!strcmp(type, "GetEthTypedDataFrom")) { - return GetEthTypedDataFrom; - } else if (!strcmp(type, "GetEthTypedDataPrimayType")) { - return GetEthTypedDataPrimayType; - } - return NULL; -} - -#endif - GetTableDataFunc GuiBtcTableFuncGet(char *type) { if (!strcmp(type, "GetPsbtInputData")) { @@ -666,346 +208,42 @@ GetTableDataFunc GuiBtcTableFuncGet(char *type) return NULL; } -#ifndef BTC_ONLY -GetLabelDataLenFunc GuiStellarTextLenFuncGet(char *type) -{ - if (!strcmp(type, "GetStellarRawMessageLength")) { - return GetStellarRawMessageLength; - } - return NULL; -} - -GetLabelDataLenFunc GuiArTextLenFuncGet(char *type) +__attribute__((weak)) GetLabelDataLenFunc GuiOtherChainTextLenFuncGet(char *type, GuiRemapViewType remapIndex) { - if (!strcmp(type, "GetArweaveRawMessageLength")) { - return GetArweaveRawMessageLength; - } else if (!strcmp(type, "GetArweaveMessageLength")) { - return GetArweaveMessageLength; - } return NULL; } -GetTableDataFunc GuiEthTableFuncGet(char *type) -{ - if (!strcmp(type, "GetEthContractData")) { - return GetEthContractData; - } - return NULL; -} - -GetTableDataFunc GuiAdaTabelFuncGet(char *type) -{ - if (!strcmp(type, "GetAdaInputDetail")) { - return GetAdaInputDetail; - } - if (!strcmp(type, "GetAdaOutputDetail")) { - return GetAdaOutputDetail; - } - if (!strcmp(type, "GetAdaWithdrawalsData")) { - return GetAdaWithdrawalsData; - } - if (!strcmp(type, "GetAdaCertificatesData")) { - return GetAdaCertificatesData; - } - if (!strcmp(type, "GetAdaVotingProceduresData")) { - return GetAdaVotingProceduresData; - } - return NULL; -} - -GetLabelDataFunc GuiTrxTextFuncGet(char *type) -{ - if (!strcmp(type, "GetTrxValue")) { - return GetTrxValue; - } else if (!strcmp(type, "GetTrxMethod")) { - return GetTrxMethod; - } else if (!strcmp(type, "GetTrxFromAddress")) { - return GetTrxFromAddress; - } else if (!strcmp(type, "GetTrxToAddress")) { - return GetTrxToAddress; - } else if (!strcmp(type, "GetTrxContract")) { - return GetTrxContract; - } else if (!strcmp(type, "GetTrxToken")) { - return GetTrxToken; - } - return NULL; -} - -GetLabelDataFunc GuiCosmosTextFuncGet(char *type) -{ - if (!strcmp(type, "GetCosmosValue")) { - return GetCosmosValue; - } else if (!strcmp(type, "GetCosmosNetwork")) { - return GetCosmosNetwork; - } else if (!strcmp(type, "GetCosmosMethod")) { - return GetCosmosMethod; - } else if (!strcmp(type, "GetCosmosAddress1Label")) { - return GetCosmosAddress1Label; - } else if (!strcmp(type, "GetCosmosAddress1Value")) { - return GetCosmosAddress1Value; - } else if (!strcmp(type, "GetCosmosAddress2Label")) { - return GetCosmosAddress2Label; - } else if (!strcmp(type, "GetCosmosAddress2Value")) { - return GetCosmosAddress2Value; - } else if (!strcmp(type, "GetCosmosMaxFee")) { - return GetCosmosMaxFee; - } else if (!strcmp(type, "GetCosmosFee")) { - return GetCosmosFee; - } else if (!strcmp(type, "GetCosmosGasLimit")) { - return GetCosmosGasLimit; - } else if (!strcmp(type, "GetCosmosChainId")) { - return GetCosmosChainId; - } else if (!strcmp(type, "GetCosmosChannel")) { - return GetCosmosChannel; - } else if (!strcmp(type, "GetCosmosOldValidator")) { - return GetCosmosOldValidator; - } else if (!strcmp(type, "GetCosmosProposal")) { - return GetCosmosProposal; - } else if (!strcmp(type, "GetCosmosVoted")) { - return GetCosmosVoted; - } else if (!strcmp(type, "GetCosmosIndex")) { - return GetCosmosIndex; - } else if (!strcmp(type, "GetCosmosTextOfKind")) { - return GetCosmosTextOfKind; - } else if (!strcmp(type, "GetCosmosDetailItemValue")) { - return GetCosmosDetailItemValue; - } - return NULL; -} - -GetLabelDataFunc GuiSuiTextFuncGet(char *type) -{ - if (!strcmp(type, "GetSuiDetail")) { - return GetSuiDetail; - } - return NULL; -} - -GetLabelDataLenFunc GuiSuiTextLenFuncGet(char *type) -{ - if (!strcmp(type, "GetSuiDetailLen")) { - return GetSuiDetailLen; - } - return NULL; -} - -GetLabelDataFunc GuiAptosTextFuncGet(char *type) -{ - if (!strcmp(type, "GetAptosDetail")) { - return GetAptosDetail; - } - return NULL; -} - -GetLabelDataLenFunc GuiAptosTextLenFuncGet(char *type) -{ - if (!strcmp(type, "GetAptosDetailLen")) { - return GetAptosDetailLen; - } - return NULL; -} - -GetLabelDataFunc GuiXrpTextFuncGet(char *type) -{ - if (!strcmp(type, "GetXrpDetail")) { - return GetXrpDetail; - } - return NULL; -} - -GetLabelDataFunc GuiArTextFuncGet(char *type) -{ - if (!strcmp(type, "GetArweaveValue")) { - return GetArweaveValue; - } else if (!strcmp(type, "GetArweaveFee")) { - return GetArweaveFee; - } else if (!strcmp(type, "GetArweaveFromAddress")) { - return GetArweaveFromAddress; - } else if (!strcmp(type, "GetArweaveToAddress")) { - return GetArweaveToAddress; - } else if (!strcmp(type, "GetArweaveValue")) { - return GetArweaveValue; - } else if (!strcmp(type, "GetArweaveMessageText")) { - return GetArweaveMessageText; - } else if (!strcmp(type, "GetArweaveRawMessage")) { - return GetArweaveRawMessage; - } else if (!strcmp(type, "GetArweaveMessageAddress")) { - return GetArweaveMessageAddress; - } - return NULL; -} - -GetLabelDataFunc GuiStellarTextFuncGet(char *type) +GetLabelDataLenFunc GuiTemplateTextLenFuncGet(char *type) { - if (!strcmp(type, "GetStellarRawMessage")) { - return GetStellarRawMessage; - } - return NULL; + return GuiOtherChainTextLenFuncGet(type, g_reMapIndex); } -GetLabelDataLenFunc GuiXrpTextLenFuncGet(char *type) +__attribute__((weak)) GetLabelDataFunc GuiOtherChainTextFuncGet(char *type, GuiRemapViewType remapIndex) { - if (!strcmp(type, "GetXrpDetailLen")) { - return GetXrpDetailLen; - } return NULL; } -GetLabelDataLenFunc GuiEthTextLenFuncGet(char *type) +GetLabelDataFunc GuiTemplateTextFuncGet(char *type) { - if (!strcmp(type, "GetEthTypedDataMessageLen")) { - return GetEthTypedDataMessageLen; + if (g_reMapIndex == REMAPVIEW_BTC || g_reMapIndex == REMAPVIEW_BTC_MESSAGE) { + return GuiBtcTextFuncGet(type); } - return NULL; -} -GetLabelDataFunc GuiAdaTextFuncGet(char *type) -{ - if (!strcmp(type, "GetAdaExtraData")) { - return GetAdaExtraData; - } - if (!strcmp(type, "GetAdaNetwork")) { - return GetAdaNetwork; - } - if (!strcmp(type, "GetAdaTotalInput")) { - return GetAdaTotalInput; - } - if (!strcmp(type, "GetAdaTotalOutput")) { - return GetAdaTotalOutput; - } - if (!strcmp(type, "GetAdaFee")) { - return GetAdaFee; - } else if (!strcmp(type, "GetAdaWithdrawalsLabel")) { - return GetAdaWithdrawalsLabel; - } else if (!strcmp(type, "GetAdaCertificatesLabel")) { - return GetAdaCertificatesLabel; - } else if (!strcmp(type, "GetAdaSignDataPayloadText")) { - return GetAdaSignDataPayloadText; - } else if (!strcmp(type, "GetAdaSignDataDerviationPathText")) { - return GetAdaSignDataDerviationPathText; - } else if (!strcmp(type, "GetCatalystNonce")) { - return GetCatalystNonce; - } else if (!strcmp(type, "GetCatalystVotePublicKey")) { - return GetCatalystVotePublicKey; - } else if (!strcmp(type, "GetCatalystRewards")) { - return GetCatalystRewards; - } else if (!strcmp(type, "GetCatalystVoteKeys")) { - return GetCatalystVoteKeys; - } else if (!strcmp(type, "GetAdaSignDataMessageHashText")) { - return GetAdaSignDataMessageHashText; - } else if (!strcmp(type, "GetAdaSignDataXPubText")) { - return GetAdaSignDataXPubText; - } else if (!strcmp(type, "GetAdaVotingProceduresLabel")) { - return GetAdaVotingProceduresLabel; - } else if (!strcmp(type, "GetAdaVotingProposalsLabel")) { - return GetAdaVotingProposalsLabel; - } - return NULL; + return GuiOtherChainTextFuncGet(type, g_reMapIndex); } -GetLabelDataLenFunc GuiAdaTextLenFuncGet(char *type) +__attribute__((weak)) GetTableDataFunc GuiOtherChainTableFuncGet(char *type, GuiRemapViewType remapIndex) { - if (!strcmp(type, "GetAdaExtraDataLen")) { - return GetAdaExtraDataLen; - } else if (!strcmp(type, "GetAdaSignDataPayloadLength")) { - return GetAdaSignDataPayloadLength; - } else if (!strcmp(type, "GetAdaSignDataMessageHashLength")) { - return GetAdaSignDataMessageHashLength; - } else if (!strcmp(type, "GetAdaSignDataXPubLength")) { - return GetAdaSignDataXPubLength; - } - return NULL; -} -#endif - -GetLabelDataLenFunc GuiTemplateTextLenFuncGet(char *type) -{ - switch (g_reMapIndex) { -#ifndef BTC_ONLY - case REMAPVIEW_SUI: - return GuiSuiTextLenFuncGet(type); - case REMAPVIEW_APT: - return GuiAptosTextLenFuncGet(type); - case REMAPVIEW_ADA: - case REMAPVIEW_ADA_SIGN_DATA: - case REMAPVIEW_ADA_CATALYST: - return GuiAdaTextLenFuncGet(type); - case REMAPVIEW_XRP: - return GuiXrpTextLenFuncGet(type); - case REMAPVIEW_ETH_TYPEDDATA: - return GuiEthTextLenFuncGet(type); - case REMAPVIEW_AR: - case REMAPVIEW_AR_MESSAGE: - return GuiArTextLenFuncGet(type); - case REMAPVIEW_STELLAR: - return GuiStellarTextLenFuncGet(type); -#endif - default: - return NULL; - } -} - -GetLabelDataFunc GuiTemplateTextFuncGet(char *type) -{ - switch (g_reMapIndex) { - case REMAPVIEW_BTC: - case REMAPVIEW_BTC_MESSAGE: - return GuiBtcTextFuncGet(type); -#ifndef BTC_ONLY - case REMAPVIEW_ETH: - return GuiEthTextFuncGet(type); - case REMAPVIEW_ETH_PERSONAL_MESSAGE: - return GuiEthPersonalMessageTextFuncGet(type); - case REMAPVIEW_ETH_TYPEDDATA: - return GuiEthTypedDataTextFuncGet(type); - case REMAPVIEW_TRX: - return GuiTrxTextFuncGet(type); - case REMAPVIEW_COSMOS: - return GuiCosmosTextFuncGet(type); - case REMAPVIEW_SUI: - return GuiSuiTextFuncGet(type); - case REMAPVIEW_SOL_MESSAGE: - return GuiSolMessageTextFuncGet(type); - case REMAPVIEW_APT: - return GuiAptosTextFuncGet(type); - case REMAPVIEW_ADA: - case REMAPVIEW_ADA_SIGN_DATA: - case REMAPVIEW_ADA_CATALYST: - return GuiAdaTextFuncGet(type); - case REMAPVIEW_XRP: - return GuiXrpTextFuncGet(type); - case REMAPVIEW_AR: - case REMAPVIEW_AR_MESSAGE: - return GuiArTextFuncGet(type); - case REMAPVIEW_STELLAR: - case REMAPVIEW_STELLAR_HASH: - return GuiStellarTextFuncGet(type); -#endif - default: - return NULL; - } - return NULL; } GetTableDataFunc GuiTemplateTableFuncGet(char *type) { - switch (g_reMapIndex) { - case REMAPVIEW_BTC: + if (g_reMapIndex == REMAPVIEW_BTC) { return GuiBtcTableFuncGet(type); -#ifndef BTC_ONLY - case REMAPVIEW_ETH: - return GuiEthTableFuncGet(type); - case REMAPVIEW_ADA: - case REMAPVIEW_ADA_SIGN_DATA: - case REMAPVIEW_ADA_CATALYST: - return GuiAdaTabelFuncGet(type); -#endif - default: - return NULL; } - return NULL; + return GuiOtherChainTableFuncGet(type, g_reMapIndex); } const void *GetImgSrc(char *type) @@ -1028,58 +266,16 @@ const void *GetImgSrc(char *type) return &imgSwitch; } -GetObjStateFunc GuiTemplateStateFuncGet(char *type) +__attribute__((weak)) GetObjStateFunc GuiOtherChainStateFuncGet(char *type) { -#ifndef BTC_ONLY - if (!strcmp(type, "GetEthEnsExist")) { - return GetEthEnsExist; - } else if (!strcmp(type, "GetToEthEnsExist")) { - return GetToEthEnsExist; - } else if (!strcmp(type, "GetEthContractDataExist")) { - return GetEthContractDataExist; - } else if (!strcmp(type, "GetEthContractDataNotExist")) { - return GetEthContractDataNotExist; - } else if (!strcmp(type, "GetEthInputDataExist")) { - return GetEthInputDataExist; - } else if (!strcmp(type, "GetTrxContractExist")) { - return GetTrxContractExist; - } else if (!strcmp(type, "GetTrxTokenExist")) { - return GetTrxTokenExist; - } else if (!strcmp(type, "GetCosmosChannelExist")) { - return GetCosmosChannelExist; - } else if (!strcmp(type, "GetCosmosOldValidatorExist")) { - return GetCosmosOldValidatorExist; - } else if (!strcmp(type, "GetCosmosValueExist")) { - return GetCosmosValueExist; - } else if (!strcmp(type, "GetCosmosVoteExist")) { - return GetCosmosVoteExist; - } else if (!strcmp(type, "GetCosmosAddress2Exist")) { - return GetCosmosAddress2Exist; - } else if (!strcmp(type, "GetCosmosMsgListExist")) { - return GetCosmosMsgListExist; - } else if (!strcmp(type, "GetCosmosMethodExist")) { - return GetCosmosMethodExist; - } else if (!strcmp(type, "GetCosmosAddrExist")) { - return GetCosmosAddrExist; - } else if (!strcmp(type, "GetAdaWithdrawalsExist")) { - return GetAdaWithdrawalsExist; - } else if (!strcmp(type, "GetAdaCertificatesExist")) { - return GetAdaCertificatesExist; - } else if (!strcmp(type, "GetAdaExtraDataExist")) { - return GetAdaExtraDataExist; - } else if (!strcmp(type, "GetAdaVotingProceduresExist")) { - return GetAdaVotingProceduresExist; - } else if (!strcmp(type, "GetAdaVotingProposalsExist")) { - return GetAdaVotingProposalsExist; - } else if (!strcmp(type, "GetEthPermitWarningExist")) { - return GetEthPermitWarningExist; - } else if (!strcmp(type, "GetEthPermitCantSign")) { - return GetEthPermitCantSign; - } -#endif return NULL; } +GetObjStateFunc GuiTemplateStateFuncGet(char *type) +{ + return GuiOtherChainStateFuncGet(type); +} + static void SwitchHidden(lv_event_t *e) { SetLvglFlagFunc clearHidden = lv_obj_add_flag; @@ -1101,17 +297,18 @@ static void SwitchHidden(lv_event_t *e) } } +__attribute__((weak)) lv_event_cb_t GuiOtherChainEventCbGet(char *funcName) +{ + return NULL; +} + lv_event_cb_t GuiTemplateEventCbGet(char *type) { if (!strcmp(type, "SwitchHidden")) { return SwitchHidden; } -#ifndef BTC_ONLY - if (!strcmp(type, "EthContractLearnMore")) { - return EthContractLearnMore; - } -#endif - return NULL; + + return GuiOtherChainEventCbGet(type); } void GuiWidgetBaseInit(lv_obj_t *obj, cJSON *json) @@ -1326,6 +523,11 @@ void *GuiWidgetContainer(lv_obj_t *parent, cJSON *json) return obj; } +__attribute__((weak)) GetCustomContainerFunc GetOtherChainCustomFunc(char *funcName) +{ + return NULL; +} + GetCustomContainerFunc GuiTemplateCustomFunc(char *funcName) { if (!strcmp(funcName, "GuiBtcTxOverview")) { @@ -1335,44 +537,8 @@ GetCustomContainerFunc GuiTemplateCustomFunc(char *funcName) } else if (!strcmp(funcName, "GuiBtcMsg")) { return GuiBtcMsg; } -#ifndef BTC_ONLY - if (!strcmp(funcName, "GuiShowSolTxOverview")) { - return GuiShowSolTxOverview; - } else if (!strcmp(funcName, "GuiShowSolTxDetail")) { - return GuiShowSolTxDetail; - } else if (!strcmp(funcName, "GuiShowArweaveTxDetail")) { - return GuiShowArweaveTxDetail; - } else if (!strcmp(funcName, "GetCatalystRewardsNotice")) { - return GetCatalystRewardsNotice; - } else if (!strcmp(funcName, "GuiStellarTxNotice")) { - return GuiStellarTxNotice; - } else if (!strcmp(funcName, "GuiStellarHashNotice")) { - return GuiStellarHashNotice; - } else if (!strcmp(funcName, "GuiTonTxOverview")) { - return GuiTonTxOverview; - } else if (!strcmp(funcName, "GuiZcashOverview")) { - return GuiZcashOverview; - } else if (!strcmp(funcName, "GuiTonTxRawData")) { - return GuiTonTxRawData; - } else if (!strcmp(funcName, "GuiTonProofOverview")) { - return GuiTonProofOverview; - } else if (!strcmp(funcName, "GuiTonProofRawData")) { - return GuiTonProofRawData; - } else if (!strcmp(funcName, "GuiArDataItemOverview")) { - return GuiArDataItemOverview; - } else if (!strcmp(funcName, "GuiArDataItemDetail")) { - return GuiArDataItemDetail; - } else if (!strcmp(funcName, "GuiShowSuiSignMessageHashOverview")) { - return GuiShowSuiSignMessageHashOverview; - } else if (!strcmp(funcName, "GuiShowSuiSignMessageHashDetails")) { - return GuiShowSuiSignMessageHashDetails; - } else if (!strcmp(funcName, "GuiShowAdaSignTxHashOverview")) { - return GuiShowAdaSignTxHashOverview; - } else if (!strcmp(funcName, "GuiShowAdaSignTxHashDetails")) { - return GuiShowAdaSignTxHashDetails; - } -#endif - return NULL; + + return GetOtherChainCustomFunc(funcName); } void *GuiWidgetCustomContainer(lv_obj_t *parent, cJSON *json) @@ -1598,9 +764,6 @@ void *GuiWidgetTabViewChild(lv_obj_t *parent, cJSON *json) return obj; } - - - static void *GuiWidgetFactoryCreate(lv_obj_t *parent, cJSON *json) { lv_obj_t *obj = NULL; @@ -1609,9 +772,9 @@ static void *GuiWidgetFactoryCreate(lv_obj_t *parent, cJSON *json) item = cJSON_GetObjectItem(json, "table"); if (item != NULL) { char typeBuf[16]; - // find the ui type + // find the ui type for (int i = 0; i < NUMBER_OF_ARRAYS(g_analyzeArray); i++) { - if(g_analyzeArray[i].index == g_reMapIndex) { + if (g_analyzeArray[i].index == g_reMapIndex) { g_analyzeArray[i].typeFunc(typeBuf, g_totalData, sizeof(typeBuf)); break; } @@ -1727,76 +890,6 @@ void ParseTransaction(uint8_t index) } } -GuiRemapViewType ViewTypeReMap(uint8_t viewType) -{ - switch (viewType) { - case BtcNativeSegwitTx: - case BtcSegwitTx: - case BtcLegacyTx: - case BtcTx: -#ifndef BTC_ONLY - case LtcTx: - case DashTx: - case BchTx: -#endif - return REMAPVIEW_BTC; - case BtcMsg: - return REMAPVIEW_BTC_MESSAGE; -#ifndef BTC_ONLY - case EthTx: - return REMAPVIEW_ETH; - case EthPersonalMessage: - return REMAPVIEW_ETH_PERSONAL_MESSAGE; - case EthTypedData: - return REMAPVIEW_ETH_TYPEDDATA; - case TronTx: - return REMAPVIEW_TRX; - case CosmosTx: - case CosmosEvmTx: - return REMAPVIEW_COSMOS; - case SuiTx: - return REMAPVIEW_SUI; - case SuiSignMessageHash: - return REMAPVIEW_SUI_SIGN_MESSAGE_HASH; - case SolanaTx: - return REMAPVIEW_SOL; - case SolanaMessage: - return REMAPVIEW_SOL_MESSAGE; - case AptosTx: - return REMAPVIEW_APT; - case CardanoSignTxHash: - return REMAPVIEW_ADA_SIGN_TX_HASH; - case CardanoTx: - return REMAPVIEW_ADA; - case CardanoSignData: - return REMAPVIEW_ADA_SIGN_DATA; - case CardanoCatalystVotingRegistration: - return REMAPVIEW_ADA_CATALYST; - case XRPTx: - return REMAPVIEW_XRP; - case ArweaveTx: - return REMAPVIEW_AR; - case ArweaveMessage: - return REMAPVIEW_AR_MESSAGE; - case StellarTx: - return REMAPVIEW_STELLAR; - case StellarHash: - return REMAPVIEW_STELLAR_HASH; - case ArweaveDataItem: - return REMAPVIEW_AR_DATAITEM; - case TonTx: - return REMAPVIEW_TON; - case TonSignProof: - return REMAPVIEW_TON_SIGNPROOF; - case ZcashTx: - return REMAPVIEW_ZCASH; -#endif - default: - return REMAPVIEW_BUTT; - } - return REMAPVIEW_BUTT; -} - static lv_obj_t *g_imgCont = NULL; void GuiAnalyzeViewInit(lv_obj_t *parent) { diff --git a/src/ui/gui_analyze/gui_resolve_ur.c b/src/ui/gui_analyze/gui_resolve_ur.c index e2f1d8ed4..9202d36f0 100644 --- a/src/ui/gui_analyze/gui_resolve_ur.c +++ b/src/ui/gui_analyze/gui_resolve_ur.c @@ -7,6 +7,7 @@ #include "gui_resolve_ur.h" #include "user_delay.h" #include "gui_api.h" +#include "gui_views.h" #ifndef BTC_ONLY #include "gui_key_derivation_request_widgets.h" @@ -14,13 +15,15 @@ #include "gui_import_multisig_wallet_info_widgets.h" #include "gui_create_multisig_wallet_widgets.h" #endif -#include // The order of the enumeration must be guaranteed static SetChainData_t g_chainViewArray[] = { {REMAPVIEW_BTC, (SetChainDataFunc)GuiSetPsbtUrData}, {REMAPVIEW_BTC_MESSAGE, (SetChainDataFunc)GuiSetPsbtUrData}, #ifndef BTC_ONLY +#ifdef CYBERPUNK + {REMAPVIEW_ZCASH, (SetChainDataFunc)GuiSetZcashUrData}, +#else {REMAPVIEW_ETH, (SetChainDataFunc)GuiSetEthUrData}, {REMAPVIEW_ETH_PERSONAL_MESSAGE, (SetChainDataFunc)GuiSetEthUrData}, {REMAPVIEW_ETH_TYPEDDATA, (SetChainDataFunc)GuiSetEthUrData}, @@ -43,7 +46,7 @@ static SetChainData_t g_chainViewArray[] = { {REMAPVIEW_STELLAR_HASH, (SetChainDataFunc)GuiSetStellarUrData}, {REMAPVIEW_TON, (SetChainDataFunc)GuiSetTonUrData}, {REMAPVIEW_TON_SIGNPROOF, (SetChainDataFunc)GuiSetTonUrData}, - {REMAPVIEW_ZCASH, (SetChainDataFunc)GuiSetZcashUrData}, +#endif #endif }; @@ -67,13 +70,13 @@ void handleURResult(URParseResult *urResult, URParseMultiResult *urMultiResult, GuiSetKeyDerivationRequestData(urResult, urMultiResult, is_multi); break; #else - case MultisigWalletImport: - GuiSetMultisigImportWalletDataByQRCode(urResult, urMultiResult, is_multi); - break; - case MultisigCryptoImportXpub: - case MultisigBytesImportXpub: - GuiSetMultisigImportXpubByQRCode(urResult); - break; + // case MultisigWalletImport: + // GuiSetMultisigImportWalletDataByQRCode(urResult, urMultiResult, is_multi); + // break; + // case MultisigCryptoImportXpub: + // case MultisigBytesImportXpub: + // GuiSetMultisigImportXpubByQRCode(urResult); + // break; #endif default: HandleDefaultViewType(urResult, urMultiResult, urViewType, is_multi); @@ -84,9 +87,9 @@ void handleURResult(URParseResult *urResult, URParseMultiResult *urMultiResult, #ifndef BTC_ONLY || urViewType.viewType == KeyDerivationRequest #else - || urViewType.viewType == MultisigWalletImport - || urViewType.viewType == MultisigBytesImportXpub - || urViewType.viewType == MultisigCryptoImportXpub + // || urViewType.viewType == MultisigWalletImport + // || urViewType.viewType == MultisigBytesImportXpub + // || urViewType.viewType == MultisigCryptoImportXpub #endif || viewType != REMAPVIEW_BUTT) { #ifndef COMPILE_SIMULATOR diff --git a/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c b/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c new file mode 100644 index 000000000..7a6500e42 --- /dev/null +++ b/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c @@ -0,0 +1,12 @@ +#include "gui_chain.h" +#include "gui_analyze.h" + +// GetCustomContainerFunc GetOtherChainCustomFunc(char *funcName) +// { +// if (!strcmp(funcName, "GuiZcashOverview")) { +// // return GuiZcashOverview; +// return NULL; +// } + +// return NULL; +// } diff --git a/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.h b/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.h new file mode 100644 index 000000000..6feb89a2e --- /dev/null +++ b/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.h @@ -0,0 +1,16 @@ +#ifdef CYBERPUNK_VERSION +#ifndef _GUI_CYBERPUNK_ANALYZE_WIDGETS_H +#define _GUI_CYBERPUNK_ANALYZE_WIDGETS_H + +// temper test the ethereum page view not for production usage +#define GUI_ANALYZE_OBJ_SURPLUS \ + { \ + REMAPVIEW_ZCASH, \ + "{\"name\":\"zcash_page\",\"type\":\"custom_container\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"custom_show_func\":\"GuiZcashOverview\"}", \ + GuiGetZcashGUIData, \ + NULL, \ + FreeZcashMemory, \ + } + +#endif +#endif \ No newline at end of file diff --git a/src/ui/gui_analyze/multi/general/gui_general_analyze.c b/src/ui/gui_analyze/multi/general/gui_general_analyze.c new file mode 100644 index 000000000..553edb587 --- /dev/null +++ b/src/ui/gui_analyze/multi/general/gui_general_analyze.c @@ -0,0 +1,684 @@ +#include "gui_chain.h" +#include "gui_analyze.h" + +static GetLabelDataFunc GuiAdaTextFuncGet(char *type); +static GetLabelDataLenFunc GuiAdaTextLenFuncGet(char *type); +static GetLabelDataLenFunc GuiEthTextLenFuncGet(char *type); +static GetLabelDataLenFunc GuiXrpTextLenFuncGet(char *type); +static GetLabelDataLenFunc GuiStellarTextLenFuncGet(char *type); +static GetLabelDataLenFunc GuiArTextLenFuncGet(char *type); +static GetTableDataFunc GuiEthTableFuncGet(char *type); +static GetTableDataFunc GuiAdaTabelFuncGet(char *type); +static GetLabelDataFunc GuiTrxTextFuncGet(char *type); +static GetLabelDataFunc GuiCosmosTextFuncGet(char *type); +static GetLabelDataFunc GuiSuiTextFuncGet(char *type); +static GetLabelDataLenFunc GuiSuiTextLenFuncGet(char *type); +static GetLabelDataFunc GuiAptosTextFuncGet(char *type); +static GetLabelDataLenFunc GuiAptosTextLenFuncGet(char *type); +static GetLabelDataFunc GuiXrpTextFuncGet(char *type); +static GetLabelDataFunc GuiArTextFuncGet(char *type); +static GetLabelDataFunc GuiStellarTextFuncGet(char *type); +static GetLabelDataFunc GuiSolMessageTextFuncGet(char *type); +static GetLabelDataFunc GuiEthTypedDataTextFuncGet(char *type); +static GetLabelDataFunc GuiEthPersonalMessageTextFuncGet(char *type); +static GetLabelDataFunc GuiEthTextFuncGet(char *type); +static GetContSizeFunc GetEthObjPos(char *type); +static GetContSizeFunc GetCosmosObjPos(char *type); +static GetListItemKeyFunc GetCosmosListItemKey(char *type); +static GetListLenFunc GetCosmosListLen(char *type); +static GetContSizeFunc GetAdaContainerSize(char *type); +static GetContSizeFunc GetCosmosContainerSize(char *type); +static GetContSizeFunc GetEthContainerSize(char *type); + + +GetContSizeFunc GetOtherChainContainerSize(char *type, GuiRemapViewType remapIndex) +{ + switch (remapIndex) { + case REMAPVIEW_ETH: + return GetEthContainerSize(type); + case REMAPVIEW_COSMOS: + return GetCosmosContainerSize(type); + case REMAPVIEW_ADA: + case REMAPVIEW_ADA_SIGN_DATA: + case REMAPVIEW_ADA_CATALYST: + return GetAdaContainerSize(type); + default: + break; + } + return NULL; +} + +GetContSizeFunc GetOtherChainPos(char *type, GuiRemapViewType remapIndex) +{ + switch (remapIndex) { + case REMAPVIEW_ETH: + case REMAPVIEW_ETH_TYPEDDATA: + return GetEthObjPos(type); + case REMAPVIEW_COSMOS: + return GetCosmosObjPos(type); + default: + break; + } + return NULL; +} + +GetCustomContainerFunc GetOtherChainCustomFunc(char *funcName) +{ + if (!strcmp(funcName, "GuiShowSolTxOverview")) { + return GuiShowSolTxOverview; + } else if (!strcmp(funcName, "GuiShowSolTxDetail")) { + return GuiShowSolTxDetail; + } else if (!strcmp(funcName, "GuiShowArweaveTxDetail")) { + return GuiShowArweaveTxDetail; + } else if (!strcmp(funcName, "GetCatalystRewardsNotice")) { + return GetCatalystRewardsNotice; + } else if (!strcmp(funcName, "GuiStellarTxNotice")) { + return GuiStellarTxNotice; + } else if (!strcmp(funcName, "GuiStellarHashNotice")) { + return GuiStellarHashNotice; + } else if (!strcmp(funcName, "GuiTonTxOverview")) { + return GuiTonTxOverview; + } else if (!strcmp(funcName, "GuiTonTxRawData")) { + return GuiTonTxRawData; + } else if (!strcmp(funcName, "GuiTonProofOverview")) { + return GuiTonProofOverview; + } else if (!strcmp(funcName, "GuiTonProofRawData")) { + return GuiTonProofRawData; + } else if (!strcmp(funcName, "GuiArDataItemOverview")) { + return GuiArDataItemOverview; + } else if (!strcmp(funcName, "GuiArDataItemDetail")) { + return GuiArDataItemDetail; + } else if (!strcmp(funcName, "GuiShowSuiSignMessageHashOverview")) { + return GuiShowSuiSignMessageHashOverview; + } else if (!strcmp(funcName, "GuiShowSuiSignMessageHashDetails")) { + return GuiShowSuiSignMessageHashDetails; + } else if (!strcmp(funcName, "GuiShowAdaSignTxHashOverview")) { + return GuiShowAdaSignTxHashOverview; + } else if (!strcmp(funcName, "GuiShowAdaSignTxHashDetails")) { + return GuiShowAdaSignTxHashDetails; + } + + return NULL; +} + +lv_event_cb_t GuiOtherChainEventCbGet(char *type) +{ + if (!strcmp(type, "EthContractLearnMore")) { + return EthContractLearnMore; + } + + return NULL; +} + +GetObjStateFunc GuiOtherChainStateFuncGet(char *type) +{ + if (!strcmp(type, "GetEthEnsExist")) { + return GetEthEnsExist; + } else if (!strcmp(type, "GetToEthEnsExist")) { + return GetToEthEnsExist; + } else if (!strcmp(type, "GetEthContractDataExist")) { + return GetEthContractDataExist; + } else if (!strcmp(type, "GetEthContractDataNotExist")) { + return GetEthContractDataNotExist; + } else if (!strcmp(type, "GetEthInputDataExist")) { + return GetEthInputDataExist; + } else if (!strcmp(type, "GetTrxContractExist")) { + return GetTrxContractExist; + } else if (!strcmp(type, "GetTrxTokenExist")) { + return GetTrxTokenExist; + } else if (!strcmp(type, "GetCosmosChannelExist")) { + return GetCosmosChannelExist; + } else if (!strcmp(type, "GetCosmosOldValidatorExist")) { + return GetCosmosOldValidatorExist; + } else if (!strcmp(type, "GetCosmosValueExist")) { + return GetCosmosValueExist; + } else if (!strcmp(type, "GetCosmosVoteExist")) { + return GetCosmosVoteExist; + } else if (!strcmp(type, "GetCosmosAddress2Exist")) { + return GetCosmosAddress2Exist; + } else if (!strcmp(type, "GetCosmosMsgListExist")) { + return GetCosmosMsgListExist; + } else if (!strcmp(type, "GetCosmosMethodExist")) { + return GetCosmosMethodExist; + } else if (!strcmp(type, "GetCosmosAddrExist")) { + return GetCosmosAddrExist; + } else if (!strcmp(type, "GetAdaWithdrawalsExist")) { + return GetAdaWithdrawalsExist; + } else if (!strcmp(type, "GetAdaCertificatesExist")) { + return GetAdaCertificatesExist; + } else if (!strcmp(type, "GetAdaExtraDataExist")) { + return GetAdaExtraDataExist; + } else if (!strcmp(type, "GetAdaVotingProceduresExist")) { + return GetAdaVotingProceduresExist; + } else if (!strcmp(type, "GetAdaVotingProposalsExist")) { + return GetAdaVotingProposalsExist; + } else if (!strcmp(type, "GetEthPermitWarningExist")) { + return GetEthPermitWarningExist; + } else if (!strcmp(type, "GetEthPermitCantSign")) { + return GetEthPermitCantSign; + } + return NULL; +} + +GetTableDataFunc GuiOtherChainTableFuncGet(char *type, GuiRemapViewType remapIndex) +{ + switch (remapIndex) { + case REMAPVIEW_ETH: + return GuiEthTableFuncGet(type); + case REMAPVIEW_ADA: + case REMAPVIEW_ADA_SIGN_DATA: + case REMAPVIEW_ADA_CATALYST: + return GuiAdaTabelFuncGet(type); + default: + return NULL; + } +} + +GetLabelDataFunc GuiOtherChainTextFuncGet(char *type, GuiRemapViewType remapIndex) +{ + switch (remapIndex) { + case REMAPVIEW_ETH: + return GuiEthTextFuncGet(type); + case REMAPVIEW_ETH_PERSONAL_MESSAGE: + return GuiEthPersonalMessageTextFuncGet(type); + case REMAPVIEW_ETH_TYPEDDATA: + return GuiEthTypedDataTextFuncGet(type); + case REMAPVIEW_TRX: + return GuiTrxTextFuncGet(type); + case REMAPVIEW_COSMOS: + return GuiCosmosTextFuncGet(type); + case REMAPVIEW_SUI: + return GuiSuiTextFuncGet(type); + case REMAPVIEW_SOL_MESSAGE: + return GuiSolMessageTextFuncGet(type); + case REMAPVIEW_APT: + return GuiAptosTextFuncGet(type); + case REMAPVIEW_ADA: + case REMAPVIEW_ADA_SIGN_DATA: + case REMAPVIEW_ADA_CATALYST: + return GuiAdaTextFuncGet(type); + case REMAPVIEW_XRP: + return GuiXrpTextFuncGet(type); + case REMAPVIEW_AR: + case REMAPVIEW_AR_MESSAGE: + return GuiArTextFuncGet(type); + case REMAPVIEW_STELLAR: + case REMAPVIEW_STELLAR_HASH: + return GuiStellarTextFuncGet(type); + default: + return NULL; + } + + return NULL; +} + +GetLabelDataLenFunc GuiOtherChainTextLenFuncGet(char *type, GuiRemapViewType remapIndex) +{ + switch (remapIndex) { + case REMAPVIEW_SUI: + return GuiSuiTextLenFuncGet(type); + case REMAPVIEW_APT: + return GuiAptosTextLenFuncGet(type); + case REMAPVIEW_ADA: + case REMAPVIEW_ADA_SIGN_DATA: + case REMAPVIEW_ADA_CATALYST: + return GuiAdaTextLenFuncGet(type); + case REMAPVIEW_XRP: + return GuiXrpTextLenFuncGet(type); + case REMAPVIEW_ETH_TYPEDDATA: + return GuiEthTextLenFuncGet(type); + case REMAPVIEW_AR: + case REMAPVIEW_AR_MESSAGE: + return GuiArTextLenFuncGet(type); + case REMAPVIEW_STELLAR: + return GuiStellarTextLenFuncGet(type); + default: + return NULL; + } +} + + +GetListItemKeyFunc GetOtherChainListItemKeyFuncGet(char *type, GuiRemapViewType remapIndex) +{ + switch (remapIndex) { + case REMAPVIEW_COSMOS: + return GetCosmosListItemKey; + default: + return NULL; + } +} + +GetListLenFunc GetOtherChainListLenFuncGet(char *type, GuiRemapViewType remapIndex) +{ + switch (remapIndex) { + case REMAPVIEW_COSMOS: + return GetCosmosListLen; + default: + return NULL; + } +} + +static GetLabelDataFunc GuiAdaTextFuncGet(char *type) +{ + if (!strcmp(type, "GetAdaExtraData")) { + return GetAdaExtraData; + } + if (!strcmp(type, "GetAdaNetwork")) { + return GetAdaNetwork; + } + if (!strcmp(type, "GetAdaTotalInput")) { + return GetAdaTotalInput; + } + if (!strcmp(type, "GetAdaTotalOutput")) { + return GetAdaTotalOutput; + } + if (!strcmp(type, "GetAdaFee")) { + return GetAdaFee; + } else if (!strcmp(type, "GetAdaWithdrawalsLabel")) { + return GetAdaWithdrawalsLabel; + } else if (!strcmp(type, "GetAdaCertificatesLabel")) { + return GetAdaCertificatesLabel; + } else if (!strcmp(type, "GetAdaSignDataPayloadText")) { + return GetAdaSignDataPayloadText; + } else if (!strcmp(type, "GetAdaSignDataDerviationPathText")) { + return GetAdaSignDataDerviationPathText; + } else if (!strcmp(type, "GetCatalystNonce")) { + return GetCatalystNonce; + } else if (!strcmp(type, "GetCatalystVotePublicKey")) { + return GetCatalystVotePublicKey; + } else if (!strcmp(type, "GetCatalystRewards")) { + return GetCatalystRewards; + } else if (!strcmp(type, "GetCatalystVoteKeys")) { + return GetCatalystVoteKeys; + } else if (!strcmp(type, "GetAdaSignDataMessageHashText")) { + return GetAdaSignDataMessageHashText; + } else if (!strcmp(type, "GetAdaSignDataXPubText")) { + return GetAdaSignDataXPubText; + } else if (!strcmp(type, "GetAdaVotingProceduresLabel")) { + return GetAdaVotingProceduresLabel; + } else if (!strcmp(type, "GetAdaVotingProposalsLabel")) { + return GetAdaVotingProposalsLabel; + } + return NULL; +} + +static GetLabelDataLenFunc GuiAdaTextLenFuncGet(char *type) +{ + if (!strcmp(type, "GetAdaExtraDataLen")) { + return GetAdaExtraDataLen; + } else if (!strcmp(type, "GetAdaSignDataPayloadLength")) { + return GetAdaSignDataPayloadLength; + } else if (!strcmp(type, "GetAdaSignDataMessageHashLength")) { + return GetAdaSignDataMessageHashLength; + } else if (!strcmp(type, "GetAdaSignDataXPubLength")) { + return GetAdaSignDataXPubLength; + } + return NULL; +} + +static GetLabelDataLenFunc GuiEthTextLenFuncGet(char *type) +{ + if (!strcmp(type, "GetEthTypedDataMessageLen")) { + return GetEthTypedDataMessageLen; + } + return NULL; +} + +static GetLabelDataLenFunc GuiXrpTextLenFuncGet(char *type) +{ + if (!strcmp(type, "GetXrpDetailLen")) { + return GetXrpDetailLen; + } + return NULL; +} + +static GetLabelDataLenFunc GuiStellarTextLenFuncGet(char *type) +{ + if (!strcmp(type, "GetStellarRawMessageLength")) { + return GetStellarRawMessageLength; + } + return NULL; +} + +static GetLabelDataLenFunc GuiArTextLenFuncGet(char *type) +{ + if (!strcmp(type, "GetArweaveRawMessageLength")) { + return GetArweaveRawMessageLength; + } else if (!strcmp(type, "GetArweaveMessageLength")) { + return GetArweaveMessageLength; + } + return NULL; +} + +static GetTableDataFunc GuiEthTableFuncGet(char *type) +{ + if (!strcmp(type, "GetEthContractData")) { + return GetEthContractData; + } + return NULL; +} + +static GetTableDataFunc GuiAdaTabelFuncGet(char *type) +{ + if (!strcmp(type, "GetAdaInputDetail")) { + return GetAdaInputDetail; + } + if (!strcmp(type, "GetAdaOutputDetail")) { + return GetAdaOutputDetail; + } + if (!strcmp(type, "GetAdaWithdrawalsData")) { + return GetAdaWithdrawalsData; + } + if (!strcmp(type, "GetAdaCertificatesData")) { + return GetAdaCertificatesData; + } + if (!strcmp(type, "GetAdaVotingProceduresData")) { + return GetAdaVotingProceduresData; + } + return NULL; +} + +static GetLabelDataFunc GuiTrxTextFuncGet(char *type) +{ + if (!strcmp(type, "GetTrxValue")) { + return GetTrxValue; + } else if (!strcmp(type, "GetTrxMethod")) { + return GetTrxMethod; + } else if (!strcmp(type, "GetTrxFromAddress")) { + return GetTrxFromAddress; + } else if (!strcmp(type, "GetTrxToAddress")) { + return GetTrxToAddress; + } else if (!strcmp(type, "GetTrxContract")) { + return GetTrxContract; + } else if (!strcmp(type, "GetTrxToken")) { + return GetTrxToken; + } + return NULL; +} + +static GetLabelDataFunc GuiCosmosTextFuncGet(char *type) +{ + if (!strcmp(type, "GetCosmosValue")) { + return GetCosmosValue; + } else if (!strcmp(type, "GetCosmosNetwork")) { + return GetCosmosNetwork; + } else if (!strcmp(type, "GetCosmosMethod")) { + return GetCosmosMethod; + } else if (!strcmp(type, "GetCosmosAddress1Label")) { + return GetCosmosAddress1Label; + } else if (!strcmp(type, "GetCosmosAddress1Value")) { + return GetCosmosAddress1Value; + } else if (!strcmp(type, "GetCosmosAddress2Label")) { + return GetCosmosAddress2Label; + } else if (!strcmp(type, "GetCosmosAddress2Value")) { + return GetCosmosAddress2Value; + } else if (!strcmp(type, "GetCosmosMaxFee")) { + return GetCosmosMaxFee; + } else if (!strcmp(type, "GetCosmosFee")) { + return GetCosmosFee; + } else if (!strcmp(type, "GetCosmosGasLimit")) { + return GetCosmosGasLimit; + } else if (!strcmp(type, "GetCosmosChainId")) { + return GetCosmosChainId; + } else if (!strcmp(type, "GetCosmosChannel")) { + return GetCosmosChannel; + } else if (!strcmp(type, "GetCosmosOldValidator")) { + return GetCosmosOldValidator; + } else if (!strcmp(type, "GetCosmosProposal")) { + return GetCosmosProposal; + } else if (!strcmp(type, "GetCosmosVoted")) { + return GetCosmosVoted; + } else if (!strcmp(type, "GetCosmosIndex")) { + return GetCosmosIndex; + } else if (!strcmp(type, "GetCosmosTextOfKind")) { + return GetCosmosTextOfKind; + } else if (!strcmp(type, "GetCosmosDetailItemValue")) { + return GetCosmosDetailItemValue; + } + return NULL; +} + +static GetLabelDataFunc GuiSuiTextFuncGet(char *type) +{ + if (!strcmp(type, "GetSuiDetail")) { + return GetSuiDetail; + } + return NULL; +} + +static GetLabelDataLenFunc GuiSuiTextLenFuncGet(char *type) +{ + if (!strcmp(type, "GetSuiDetailLen")) { + return GetSuiDetailLen; + } + return NULL; +} + +static GetLabelDataFunc GuiAptosTextFuncGet(char *type) +{ + if (!strcmp(type, "GetAptosDetail")) { + return GetAptosDetail; + } + return NULL; +} + +static GetLabelDataLenFunc GuiAptosTextLenFuncGet(char *type) +{ + if (!strcmp(type, "GetAptosDetailLen")) { + return GetAptosDetailLen; + } + return NULL; +} + +static GetLabelDataFunc GuiXrpTextFuncGet(char *type) +{ + if (!strcmp(type, "GetXrpDetail")) { + return GetXrpDetail; + } + return NULL; +} + +static GetLabelDataFunc GuiArTextFuncGet(char *type) +{ + if (!strcmp(type, "GetArweaveValue")) { + return GetArweaveValue; + } else if (!strcmp(type, "GetArweaveFee")) { + return GetArweaveFee; + } else if (!strcmp(type, "GetArweaveFromAddress")) { + return GetArweaveFromAddress; + } else if (!strcmp(type, "GetArweaveToAddress")) { + return GetArweaveToAddress; + } else if (!strcmp(type, "GetArweaveValue")) { + return GetArweaveValue; + } else if (!strcmp(type, "GetArweaveMessageText")) { + return GetArweaveMessageText; + } else if (!strcmp(type, "GetArweaveRawMessage")) { + return GetArweaveRawMessage; + } else if (!strcmp(type, "GetArweaveMessageAddress")) { + return GetArweaveMessageAddress; + } + return NULL; +} + +static GetLabelDataFunc GuiStellarTextFuncGet(char *type) +{ + if (!strcmp(type, "GetStellarRawMessage")) { + return GetStellarRawMessage; + } + return NULL; +} + +static GetLabelDataFunc GuiSolMessageTextFuncGet(char *type) +{ + if (!strcmp(type, "GetSolMessageFrom")) { + return GetSolMessageFrom; + } else if (!strcmp(type, "GetSolMessageUtf8")) { + return GetSolMessageUtf8; + } else if (!strcmp(type, "GetSolMessageRaw")) { + return GetSolMessageRaw; + } + return NULL; +} + +static GetLabelDataFunc GuiEthPersonalMessageTextFuncGet(char *type) +{ + if (!strcmp(type, "GetMessageFrom")) { + return GetMessageFrom; + } else if (!strcmp(type, "GetMessageUtf8")) { + return GetMessageUtf8; + } else if (!strcmp(type, "GetMessageRaw")) { + return GetMessageRaw; + } + return NULL; +} + + +static GetLabelDataFunc GuiEthTypedDataTextFuncGet(char *type) +{ + if (!strcmp(type, "GetEthTypedDataDomianName")) { + return GetEthTypedDataDomianName; + } else if (!strcmp(type, "GetEthTypedDataDomianVersion")) { + return GetEthTypedDataDomianVersion; + } else if (!strcmp(type, "GetEthTypedDataDomianChainId")) { + return GetEthTypedDataDomianChainId; + } else if (!strcmp(type, "GetEthTypedDataDomianVerifyContract")) { + return GetEthTypedDataDomianVerifyContract; + } else if (!strcmp(type, "GetEthTypedDataDomianSalt")) { + return GetEthTypedDataDomianSalt; + } else if (!strcmp(type, "GetEthTypedDataMessage")) { + return GetEthTypedDataMessage; + } else if (!strcmp(type, "GetEthTypedDataFrom")) { + return GetEthTypedDataFrom; + } else if (!strcmp(type, "GetEthTypedDataPrimayType")) { + return GetEthTypedDataPrimayType; + } + return NULL; +} + +static GetLabelDataFunc GuiEthTextFuncGet(char *type) +{ + if (!strcmp(type, "GetEthValue")) { + return GetEthValue; + } else if (!strcmp(type, "GetEthTxFee")) { + return GetEthTxFee; + } else if (!strcmp(type, "GetEthGasPrice")) { + return GetEthGasPrice; + } else if (!strcmp(type, "GetEthGasLimit")) { + return GetEthGasLimit; + } else if (!strcmp(type, "GetEthNetWork")) { + return GetEthNetWork; + } else if (!strcmp(type, "GetEthMaxFee")) { + return GetEthMaxFee; + } else if (!strcmp(type, "GetEthMaxPriority")) { + return GetEthMaxPriority; + } else if (!strcmp(type, "GetEthMaxFeePrice")) { + return GetEthMaxFeePrice; + } else if (!strcmp(type, "GetEthMaxPriorityFeePrice")) { + return GetEthMaxPriorityFeePrice; + } else if (!strcmp(type, "GetEthGetFromAddress")) { + return GetEthGetFromAddress; + } else if (!strcmp(type, "GetEthGetToAddress")) { + return GetEthGetToAddress; + } else if (!strcmp(type, "GetTxnFeeDesc")) { + return GetTxnFeeDesc; + } else if (!strcmp(type, "GetEthEnsName")) { + return GetEthEnsName; + } else if (!strcmp(type, "GetToEthEnsName")) { + return GetToEthEnsName; + } else if (!strcmp(type, "GetEthMethodName")) { + return GetEthMethodName; + } else if (!strcmp(type, "GetEthTransactionData")) { + return GetEthTransactionData; + } else if (!strcmp(type, "GetEthContractName")) { + return GetEthContractName; + } + + return NULL; +} + +static GetContSizeFunc GetEthObjPos(char *type) +{ + if (!strcmp(type, "GetEthToLabelPos")) { + return GetEthToLabelPos; + } else if (!strcmp(type, "GetEthTypeDomainPos")) { + return GetEthTypeDomainPos; + } + return NULL; +} + +static GetContSizeFunc GetCosmosObjPos(char *type) +{ + if (!strcmp(type, "GetCosmosDetailMethodLabelPos")) { + return GetCosmosDetailMethodLabelPos; + } else if (!strcmp(type, "GetCosmosDetailMethodValuePos")) { + return GetCosmosDetailMethodValuePos; + } else if (!strcmp(type, "GetCosmosDetailAddress1LabelPos")) { + return GetCosmosDetailAddress1LabelPos; + } else if (!strcmp(type, "GetCosmosDetailAddress1ValuePos")) { + return GetCosmosDetailAddress1ValuePos; + } else if (!strcmp(type, "GetCosmosDetailAddress2LabelPos")) { + return GetCosmosDetailAddress2LabelPos; + } else if (!strcmp(type, "GetCosmosDetailAddress2ValuePos")) { + return GetCosmosDetailAddress2ValuePos; + } + return NULL; +} + +static GetListItemKeyFunc GetCosmosListItemKey(char *type) +{ + if (!strcmp(type, "GetCosmosMsgKey")) { + return GetCosmosMsgKey; + } + return NULL; +} + +static GetListLenFunc GetCosmosListLen(char *type) +{ + if (!strcmp(type, "GetCosmosMsgLen")) { + return GetCosmosMsgLen; + } + return NULL; +} + +static GetContSizeFunc GetEthContainerSize(char *type) +{ + if (!strcmp(type, "GetEthToFromSize")) { + return GetEthToFromSize; + } else if (!strcmp(type, "GetEthContractDataSize")) { + return GetEthContractDataSize; + } + return NULL; +} + +static GetContSizeFunc GetCosmosContainerSize(char *type) +{ + if (!strcmp(type, "GetCosmosDetailMsgSize")) { + return GetCosmosDetailMsgSize; + } else if (!strcmp(type, "GetCosmosOverviewAddrSize")) { + return GetCosmosOverviewAddrSize; + } + return NULL; +} + +static GetContSizeFunc GetAdaContainerSize(char *type) +{ + if (!strcmp(type, "GetAdaInputDetailSize")) { + return GetAdaInputDetailSize; + } + if (!strcmp(type, "GetAdaOutputDetailSize")) { + return GetAdaOutputDetailSize; + } + if (!strcmp(type, "GetAdaCertificatesSize")) { + return GetAdaCertificatesSize; + } + if (!strcmp(type, "GetAdaVotingProceduresSize")) { + return GetAdaVotingProceduresSize; + } + if (!strcmp(type, "GetAdaWithdrawalsSize")) { + return GetAdaWithdrawalsSize; + } + if (!strcmp(type, "GetCatalystVoteKeysSize")) { + return GetCatalystVoteKeysSize; + } + return NULL; +} \ No newline at end of file diff --git a/src/ui/gui_analyze/multi/general/gui_general_analyze.h b/src/ui/gui_analyze/multi/general/gui_general_analyze.h new file mode 100644 index 000000000..19ed81eaa --- /dev/null +++ b/src/ui/gui_analyze/multi/general/gui_general_analyze.h @@ -0,0 +1,163 @@ +#ifdef GENERAL_VERSION +#ifndef _GUI_GENERAL_ANALYZE_WIDGETS_H +#define _GUI_GENERAL_ANALYZE_WIDGETS_H + +// temper test the ethereum page view not for production usage +#define GUI_ANALYZE_OBJ_SURPLUS \ + { \ + REMAPVIEW_ETH, \ + "{\"name\":\"eth_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,144],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text\":\"Max Txn Fee\",\"pos\":[24,98],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthValue\",\"pos\":[24,50],\"text_color\":16090890,\"font\":\"openSansEnLittleTitle\"},{\"type\":\"label\",\"text_func\":\"GetEthTxFee\",\"pos\":[156,98],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthNetWork\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetEthToFromSize\",\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthGetFromAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"img\",\"pos\":[24,129],\"exist_func\":\"GetEthEnsExist\",\"img_src\":\"imgEns\"},{\"type\":\"label\",\"text_func\":\"GetEthEnsName\",\"exist_func\":\"GetEthEnsExist\",\"pos\":[56,126],\"font\":\"openSansEnIllustrate\",\"text_color\":1827014},{\"type\":\"label\",\"text\":\"To\",\"pos_func\":\"GetEthToLabelPos\",\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetEthGetToAddress\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\"},{\"type\":\"img\",\"pos\":[0,11],\"align_to\":-2,\"align\":13,\"exist_func\":\"GetToEthEnsExist\",\"img_src\":\"imgEns\"},{\"type\":\"label\",\"text_func\":\"GetToEthEnsName\",\"exist_func\":\"GetToEthEnsExist\",\"pos\":[8,0],\"align_to\":-2,\"align\":20,\"font\":\"openSansEnIllustrate\",\"text_color\":1827014},{\"type\":\"img\",\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"exist_func\":\"GetEthContractDataExist\",\"img_src\":\"imgContract\"},{\"type\":\"label\",\"text_func\":\"GetEthContractName\",\"exist_func\":\"GetEthContractDataExist\",\"pos\":[38,8],\"align_to\":-3,\"align\":13,\"font\":\"openSansEnIllustrate\",\"text_color\":10782207}]}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"table\":{\"FeeMarket\":{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,316],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthValue\",\"pos\":[92,16],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Max Fee\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthMaxFee\",\"pos\":[118,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"· Max Fee Price * Gas Limit\",\"pos\":[24,92],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Max Priority\",\"pos\":[24,124],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthMaxPriority\",\"pos\":[153,124],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"· Max Priority Fee Price * Gas Limit\",\"pos\":[24,162],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Max Fee Price\",\"pos\":[24,194],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthMaxFeePrice\",\"pos\":[169,194],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Max Priority Fee Price\",\"pos\":[24,232],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthMaxPriorityFeePrice\",\"pos\":[242,232],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Gas Limit\",\"pos\":[24,270],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthGasLimit\",\"pos\":[127,270],\"font\":\"openSansEnIllustrate\"}]},\"legacy\":{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,208],\"align\":2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthValue\",\"pos\":[92,16],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Max Txn Fee\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthTxFee\",\"pos\":[156,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetTxnFeeDesc\",\"pos\":[24,92],\"text_opa\":144,\"font\":\"openSansDesc\"},{\"type\":\"label\",\"text\":\"Gas Price\",\"pos\":[24,124],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthGasPrice\",\"pos\":[127,124],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Gas Limit\",\"pos\":[24,162],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthGasLimit\",\"pos\":[127,162],\"font\":\"openSansEnIllustrate\"}]}}},{\"type\":\"container\",\"pos\":[16,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthNetWork\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"exist_func\":\"GetEthContractDataExist\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthMethodName\",\"pos\":[113,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetEthToFromSize\",\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthGetFromAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"img\",\"pos\":[24,129],\"exist_func\":\"GetEthEnsExist\",\"img_src\":\"imgEns\"},{\"type\":\"label\",\"text_func\":\"GetEthEnsName\",\"exist_func\":\"GetEthEnsExist\",\"pos\":[56,126],\"font\":\"openSansEnIllustrate\",\"text_color\":1827014},{\"type\":\"label\",\"text\":\"To\",\"pos_func\":\"GetEthToLabelPos\",\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetEthGetToAddress\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\"},{\"type\":\"img\",\"pos\":[0,11],\"align_to\":-2,\"align\":13,\"exist_func\":\"GetToEthEnsExist\",\"img_src\":\"imgEns\"},{\"type\":\"label\",\"text_func\":\"GetToEthEnsName\",\"exist_func\":\"GetToEthEnsExist\",\"pos\":[8,0],\"align_to\":-2,\"align\":20,\"font\":\"openSansEnIllustrate\",\"text_color\":1827014},{\"type\":\"img\",\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"exist_func\":\"GetEthContractDataExist\",\"img_src\":\"imgContract\"},{\"type\":\"label\",\"text_func\":\"GetEthContractName\",\"exist_func\":\"GetEthContractDataExist\",\"pos\":[38,8],\"align_to\":-3,\"align\":13,\"font\":\"openSansEnIllustrate\",\"text_color\":10782207}]},{\"type\":\"label\",\"text\":\"Input Data\",\"align_to\":-2,\"align\":13,\"exist_func\":\"GetEthInputDataExist\",\"pos\":[0,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetEthContractDataSize\",\"exist_func\":\"GetEthInputDataExist\",\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"exist_func\":\"GetEthContractDataNotExist\",\"text_func\":\"GetEthTransactionData\",\"text_width\":360,\"pos\":[24,16],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"exist_func\":\"GetEthContractDataNotExist\",\"text\":\"Unknown Contract\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"text_color\":16105777,\"font\":\"openSansEnIllustrate\"},{\"type\":\"container\",\"exist_func\":\"GetEthContractDataNotExist\",\"aflag\":2,\"cb\":\"EthContractLearnMore\",\"pos\":[0,8],\"size\":[144,30],\"align_to\":-2,\"align\":13,\"bg_color\":1907997,\"children\":[{\"type\":\"label\",\"text\":\"Learn More\",\"text_width\":360,\"pos\":[0,0],\"text_color\":1827014,\"font\":\"openSansEnIllustrate\"},{\"type\":\"img\",\"img_src\":\"imgQrcodeTurquoise\",\"pos\":[120,3],\"text_color\":3056500,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"exist_func\":\"GetEthContractDataExist\",\"text\":\"Method\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"exist_func\":\"GetEthContractDataExist\",\"text_func\":\"GetEthMethodName\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"name\":\"contract_data\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,100],\"bg_color\":1907997,\"key_width\":30,\"table_func\":\"GetEthContractData\",\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetEthContractDataExist\"}]}]}]}", \ + GuiGetEthData, \ + GetEthTransType, \ + FreeEthMemory, \ + }, \ + { \ + REMAPVIEW_ETH_PERSONAL_MESSAGE, \ + "{\"table\":{\"utf8_message\":{\"type\":\"container\",\"pos\":[0,39],\"size\":[408,500],\"align\":2,\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetMessageFrom\",\"pos\":[24,54],\"text_width\":360,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Message\",\"pos\":[24,130],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[24,168],\"size\":[360,332],\"align\":1,\"aflag\":16,\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text_func\":\"GetMessageUtf8\",\"pos\":[0,0],\"text_width\":360,\"font\":\"openSansEnIllustrate\",\"text_color\":16777215}]}]},\"raw_message\":{\"type\":\"container\",\"pos\":[0,39],\"size\":[408,500],\"align\":2,\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Raw Message\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[24,54],\"size\":[360,450],\"align\":1,\"aflag\":16,\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text_func\":\"GetMessageRaw\",\"pos\":[0,0],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]}]}}}", \ + GuiGetEthPersonalMessage, \ + GetEthPersonalMessageType, \ + FreeEthMemory, \ + }, \ + { \ + REMAPVIEW_ETH_TYPEDDATA, \ + "{\"type\":\"container\",\"pos\":[0,0],\"size\":[480,542],\"align\":0,\"bg_opa\":0,\"aflag\":16,\"children\":[{\"exist_func\":\"GetEthPermitWarningExist\",\"type\":\"container\",\"pos\":[36,24],\"size\":[408,152],\"align\":0,\"bg_color\":16078897,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"img\",\"pos\":[24,24],\"img_src\":\"imgWarningRed\"},{\"type\":\"label\",\"text\":\"WARNING\",\"pos\":[68,24],\"font\":\"openSansEnText\",\"text_color\":16078897},{\"type\":\"label\",\"text\":\"sign_eth_permit_warn\",\"pos\":[24,68],\"text_color\":16777215,\"font\":\"illustrate\",\"text_width\":360}]},{\"type\":\"container\",\"size\":[408,298],\"pos_func\":\"GetEthTypeDomainPos\",\"align\":0,\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Domain Name\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthTypedDataDomianName\",\"pos\":[24,54],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Verifying Contract\",\"pos\":[24,100],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthTypedDataDomianVerifyContract\",\"pos\":[24,138],\"text_color\":16777215,\"text_width\":360,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Primary Type\",\"pos\":[24,214],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthTypedDataPrimayType\",\"pos\":[24,252],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"text\":\"Message\",\"pos\":[0,16],\"align_to\":-2,\"align\":13,\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetEthTypedDataMessage\",\"text_len_func\":\"GetEthTypedDataMessageLen\",\"pos\":[0,16],\"align_to\":-2,\"align\":13,\"width\":408,\"bg_color\":16777215,\"bg_opa\":31,\"pad_vertical\":16,\"pad_horizontal\":24,\"radius\":24,\"text_color\":16777215,\"font\":\"openSansEnIllustrate\"},{\"exist_func\":\"GetEthPermitCantSign\",\"type\":\"container\",\"pos\":[0,16],\"align_to\":-2,\"align\":13,\"size\":[408,182],\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"img\",\"pos\":[24,24],\"img_src\":\"imgWarningRed\"},{\"type\":\"label\",\"text\":\"Cant't Sign it Now\",\"pos\":[68,24],\"font\":\"openSansEnText\",\"text_color\":16078897},{\"type\":\"label\",\"text\":\"sign_eth_permit_deny_sing\",\"pos\":[24,68],\"text_color\":16777215,\"font\":\"illustrate\",\"text_width\":360}]}]}", \ + GuiGetEthTypeData, \ + NULL, \ + FreeEthMemory, \ + }, \ + { \ + REMAPVIEW_TRX, \ + "{\"name\":\"trx_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,106],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxValue\",\"pos\":[24,50],\"text_color\":16090890,\"font\":\"openSansEnLittleTitle\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxMethod\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,244],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxFromAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,130],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetTrxToAddress\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\"}]}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxValue\",\"pos\":[92,16],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxMethod\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,244],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxFromAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,130],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetTrxToAddress\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,130],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetTrxContractExist\",\"children\":[{\"type\":\"label\",\"text\":\"Contract Address\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxContract\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\",\"text_width\":360}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetTrxTokenExist\",\"children\":[{\"type\":\"label\",\"text\":\"Token ID\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetTrxToken\",\"pos\":[123,16],\"font\":\"openSansEnIllustrate\"}]}]}]}", \ + GuiGetTrxData, \ + NULL, \ + FreeTrxMemory, \ + }, \ + { \ + REMAPVIEW_COSMOS, \ + "{\"table\":{\"tx\":{\"name\":\"cosmos_tx_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"list\",\"exist_func\":\"GetCosmosMsgListExist\",\"len_func\":\"GetCosmosMsgLen\",\"item_key_func\":\"GetCosmosMsgKey\",\"item_map\":{\"default\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,402],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[24,96],\"text_color\":16090890,\"text_width\":2000,\"font\":\"openSansEnLittleTitle\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,144],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,144],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,182],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"From\",\"text_width\":360,\"pos\":[24,220],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,288],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,326],\"font\":\"openSansEnIllustrate\"}]},\"Undelegate\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,402],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[24,96],\"text_color\":16090890,\"font\":\"openSansEnLittleTitle\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,144],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,144],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Validator\",\"pos\":[24,182],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Validator\",\"text_width\":360,\"pos\":[24,220],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,288],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,326],\"font\":\"openSansEnIllustrate\"}]},\"Re-delegate\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,402],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[24,96],\"text_color\":16090890,\"font\":\"openSansEnLittleTitle\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,144],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,144],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,182],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,220],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"New Validator\",\"pos\":[24,288],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"New Validator\",\"text_width\":360,\"pos\":[24,326],\"font\":\"openSansEnIllustrate\"}]},\"Withdraw Reward\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,320],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,62],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,138],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Validator\",\"pos\":[24,206],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Validator\",\"text_width\":360,\"pos\":[24,244],\"font\":\"openSansEnIllustrate\"}]},\"Vote\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,290],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Proposal\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Proposal\",\"pos\":[123,62],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Voted\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Voted\",\"pos\":[95,100],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,138],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Voter\",\"pos\":[24,176],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Voter\",\"pos\":[24,214],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]}}},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,106],\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetCosmosValueExist\",\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosValue\",\"pos\":[24,50],\"text_color\":16090890,\"text_width\":2000,\"font\":\"openSansEnLittleTitle\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,106],\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetCosmosVoteExist\",\"children\":[{\"type\":\"label\",\"text\":\"Proposal\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosProposal\",\"pos\":[123,16],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Voted\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosVoted\",\"pos\":[95,54],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosNetwork\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetCosmosMethodExist\",\"children\":[{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosMethod\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetCosmosOverviewAddrSize\",\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetCosmosAddrExist\",\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosAddress1Label\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress1Value\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress2Label\",\"pos\":[24,130],\"text_opa\":144,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosAddress2Exist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress2Value\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosAddress2Exist\"}]}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"list\",\"exist_func\":\"GetCosmosMsgListExist\",\"len_func\":\"GetCosmosMsgLen\",\"item_key_func\":\"GetCosmosMsgKey\",\"item_map\":{\"default\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,358],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[92,62],\"text_color\":16090890,\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"From\",\"text_width\":360,\"pos\":[24,176],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,244],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,282],\"font\":\"openSansEnIllustrate\"}]},\"IBC Transfer\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,396],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[92,62],\"text_color\":16090890,\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"From\",\"text_width\":360,\"pos\":[24,176],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,244],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,282],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Source Channel\",\"pos\":[24,350],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Source Channel\",\"text_width\":360,\"pos\":[187,350],\"font\":\"openSansEnIllustrate\"}]},\"Undelegate\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,358],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[92,62],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Validator\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Validator\",\"text_width\":360,\"pos\":[24,176],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,244],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,282],\"font\":\"openSansEnIllustrate\"}]},\"Re-delegate\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,464],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Value\",\"pos\":[92,62],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,176],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Old Validator\",\"pos\":[24,244],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Old Validator\",\"text_width\":360,\"pos\":[24,282],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"New Validator\",\"pos\":[24,350],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"New Validator\",\"text_width\":360,\"pos\":[24,388],\"font\":\"openSansEnIllustrate\"}]},\"Withdraw Reward\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,322],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,62],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"To\",\"text_width\":360,\"pos\":[24,138],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Validator\",\"pos\":[24,206],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Validator\",\"text_width\":360,\"pos\":[24,244],\"font\":\"openSansEnIllustrate\"}]},\"Vote\":{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,290],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetCosmosIndex\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16090890},{\"type\":\"label\",\"text\":\"Proposal\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Proposal\",\"pos\":[123,62],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Voted\",\"pos\":[24,100],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Voted\",\"pos\":[95,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,138],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Method\",\"pos\":[113,138],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Voter\",\"pos\":[24,176],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosTextOfKind\",\"text_key\":\"Voter\",\"pos\":[24,214],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]}}},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetCosmosDetailMsgSize\",\"exist_func\":\"GetCosmosMethodExist\",\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"exist_func\":\"GetCosmosValueExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosValue\",\"pos\":[92,16],\"text_color\":16090890,\"text_width\":2000,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosValueExist\"},{\"type\":\"label\",\"text\":\"Proposal\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"exist_func\":\"GetCosmosVoteExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosProposal\",\"pos\":[123,16],\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosVoteExist\"},{\"type\":\"label\",\"text\":\"Voted\",\"pos\":[24,62],\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"exist_func\":\"GetCosmosVoteExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosVoted\",\"pos\":[95,62],\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosVoteExist\"},{\"type\":\"label\",\"text\":\"Method\",\"pos_func\":\"GetCosmosDetailMethodLabelPos\",\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosMethod\",\"pos_func\":\"GetCosmosDetailMethodValuePos\",\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress1Label\",\"pos_func\":\"GetCosmosDetailAddress1LabelPos\",\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress1Value\",\"text_width\":360,\"pos_func\":\"GetCosmosDetailAddress1ValuePos\",\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Old Validator\",\"pos\":[24,222],\"text_opa\":144,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosOldValidatorExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosOldValidator\",\"text_width\":360,\"pos\":[24,260],\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosOldValidatorExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress2Label\",\"pos_func\":\"GetCosmosDetailAddress2LabelPos\",\"text_opa\":144,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosAddress2Exist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosAddress2Value\",\"text_width\":360,\"pos_func\":\"GetCosmosDetailAddress2ValuePos\",\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosAddress2Exist\"},{\"type\":\"label\",\"text\":\"Source Channel\",\"pos\":[24,336],\"text_opa\":144,\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosChannelExist\"},{\"type\":\"label\",\"text_func\":\"GetCosmosChannel\",\"pos\":[187,336],\"font\":\"openSansEnIllustrate\",\"exist_func\":\"GetCosmosChannelExist\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,170],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Max Fee\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosMaxFee\",\"pos\":[118,16],\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\" · Max Fee Price * Gas Limit\",\"pos\":[24,54],\"font\":\"openSansDesc\",\"text_opa\":144},{\"type\":\"label\",\"text\":\"Fee\",\"pos\":[24,86],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosFee\",\"pos\":[73,86],\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Gas Limit\",\"pos\":[24,124],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosGasLimit\",\"pos\":[127,124],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,100],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosNetwork\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Chain ID\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosChainId\",\"pos\":[120,54],\"font\":\"openSansEnIllustrate\"}]}]}]},\"unknown\":{\"name\":\"cosmos_unknown_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,600],\"bg_color\":0,\"children\":[{\"type\":\"container\",\"pos\":[0,80],\"size\":[408,170],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Max Fee\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Max Fee\",\"pos\":[118,16],\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\" · Max Fee Price * Gas Limit\",\"pos\":[24,54],\"font\":\"openSansDesc\",\"text_opa\":144},{\"type\":\"label\",\"text\":\"Fee\",\"pos\":[24,86],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Fee\",\"pos\":[73,86],\"text_width\":2000,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Gas Limit\",\"pos\":[24,124],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Gas Limit\",\"pos\":[127,124],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Network\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Message\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Message\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\",\"text_color\":16105777}]}]},\"msg\":{\"name\":\"cosmos_msg_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,600],\"bg_color\":0,\"children\":[{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Network\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,130],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Signer\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Signer\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,250],\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text\":\"Message\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCosmosDetailItemValue\",\"text_key\":\"Message\",\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]}]}}}", \ + GuiGetCosmosData, \ + GuiGetCosmosTmpType, \ + FreeCosmosMemory, \ + }, \ + { \ + REMAPVIEW_SUI, \ + "{\"type\":\"container\",\"pos\":[36,0],\"size\":[408,526],\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text\":\"Transaction Raw Data\",\"text_width\":360,\"text_opa\":144,\"pos\":[0,0],\"font\":\"openSansEnIllustrate\"},{\"type\":\"container\",\"pos\":[0,38],\"size\":[408,488],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetSuiDetail\",\"text_len_func\":\"GetSuiDetailLen\",\"text_width\":360,\"pos\":[24,24],\"font\":\"openSansEnIllustrate\"}]}]}", \ + GuiGetSuiData, \ + NULL, \ + FreeSuiMemory, \ + }, \ + { \ + REMAPVIEW_SUI_SIGN_MESSAGE_HASH, \ + "{\"name\":\"sui_sign_hash_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,774],\"bg_color\":0,\"border_width\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowSuiSignMessageHashOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowSuiSignMessageHashDetails\"}]}]}", \ + GuiGetSuiSignMessageHashData, \ + NULL, \ + FreeSuiMemory \ + }, \ + { \ + REMAPVIEW_SOL, \ + "{\"name\":\"sol_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,774],\"bg_color\":0,\"border_width\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowSolTxOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowSolTxDetail\"}]}]}", \ + GuiGetSolData, \ + NULL, \ + FreeSolMemory, \ + }, \ + { \ + REMAPVIEW_SOL_MESSAGE, \ + "{\"table\":{\"utf8_message\":{\"type\":\"container\",\"pos\":[0,39],\"size\":[408,500],\"align\":2,\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetSolMessageFrom\",\"pos\":[24,54],\"text_width\":360,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Message\",\"pos\":[24,130],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[24,168],\"size\":[360,332],\"align\":1,\"aflag\":16,\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text_func\":\"GetSolMessageUtf8\",\"pos\":[0,0],\"text_width\":360,\"font\":\"openSansEnIllustrate\",\"text_color\":16777215}]}]},\"raw_message\":{\"type\":\"container\",\"pos\":[0,39],\"size\":[408,500],\"align\":2,\"bg_color\":16777215,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Raw Message\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[24,54],\"size\":[360,450],\"align\":1,\"aflag\":16,\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text_func\":\"GetSolMessageRaw\",\"pos\":[0,0],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]}]}}}", \ + GuiGetSolMessageData, \ + GetSolMessageType, \ + FreeSolMemory, \ + }, \ + { \ + REMAPVIEW_APT, \ + "{\"type\":\"container\",\"pos\":[36,0],\"size\":[408,526],\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text\":\"Transaction Raw Data\",\"text_width\":360,\"text_opa\":144,\"pos\":[0,0],\"font\":\"openSansEnIllustrate\"},{\"type\":\"container\",\"pos\":[0,38],\"size\":[408,488],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetAptosDetail\",\"text_len_func\":\"GetAptosDetailLen\",\"text_width\":360,\"pos\":[24,24],\"font\":\"openSansEnIllustrate\"}]}]}", \ + GuiGetAptosData, \ + NULL, \ + FreeAptosMemory, \ + }, \ + { \ + REMAPVIEW_ADA, \ + "{\"type\":\"container\",\"pos\":[36,0],\"size\":[408,500],\"bg_color\":0,\"border_width\":0,\"children\":[{\"type\":\"container\",\"bg_opa\":31,\"radius\":24,\"size\":[408,62],\"children\":[{\"type\":\"label\",\"text\":\"Network\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetAdaNetwork\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"bg_opa\":31,\"radius\":24,\"align\":13,\"align_to\":-2,\"pos\":[0,16],\"size\":[408,138],\"children\":[{\"type\":\"label\",\"text\":\"InputValue\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetAdaTotalInput\",\"pos\":[147,16],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"OutputValue\",\"pos\":[24,54],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetAdaTotalOutput\",\"pos\":[164,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Fee\",\"pos\":[24,92],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetAdaFee\",\"pos\":[73,92],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetAdaInputDetailSize\",\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"name\":\"input\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,54],\"bg_color\":2105376,\"key_width\":30,\"table_func\":\"GetAdaInputDetail\",\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size_func\":\"GetAdaOutputDetailSize\",\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"name\":\"input\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,54],\"bg_color\":2105376,\"key_width\":30,\"table_func\":\"GetAdaOutputDetail\",\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"exist_func\":\"GetAdaVotingProceduresExist\",\"text_func\":\"GetAdaVotingProceduresLabel\",\"pos\":[0,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"align\":13,\"align_to\":-2},{\"name\":\"VotingProcedures\",\"type\":\"container\",\"pos\":[0,16],\"exist_func\":\"GetAdaVotingProceduresExist\",\"size_func\":\"GetAdaVotingProceduresSize\",\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"name\":\"input\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,24],\"bg_color\":2105376,\"key_width\":30,\"table_func\":\"GetAdaVotingProceduresData\",\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"exist_func\":\"GetAdaCertificatesExist\",\"text_func\":\"GetAdaCertificatesLabel\",\"pos\":[0,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"align\":13,\"align_to\":-2},{\"name\":\"certificates\",\"type\":\"container\",\"pos\":[0,16],\"exist_func\":\"GetAdaCertificatesExist\",\"size_func\":\"GetAdaCertificatesSize\",\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"name\":\"input\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,24],\"bg_color\":2105376,\"key_width\":30,\"table_func\":\"GetAdaCertificatesData\",\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"text_func\":\"GetAdaWithdrawalsLabel\",\"exist_func\":\"GetAdaWithdrawalsExist\",\"pos\":[0,16],\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"align\":13,\"align_to\":-2},{\"name\":\"withdrawal\",\"type\":\"container\",\"pos\":[0,16],\"exist_func\":\"GetAdaWithdrawalsExist\",\"size_func\":\"GetAdaWithdrawalsSize\",\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"children\":[{\"name\":\"input\",\"type\":\"table\",\"width\":360,\"align\":2,\"pos\":[0,24],\"bg_color\":2105376,\"key_width\":30,\"table_func\":\"GetAdaWithdrawalsData\",\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"label\",\"pos\":[0,16],\"exist_func\":\"GetAdaExtraDataExist\",\"text\":\"ExtraData\",\"align\":13,\"align_to\":-2,\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,500],\"align\":13,\"align_to\":-2,\"bg_opa\":31,\"radius\":24,\"exist_func\":\"GetAdaExtraDataExist\",\"children\":[{\"type\":\"label\",\"text_func\":\"GetAdaExtraData\",\"text_len_func\":\"GetAdaExtraDataLen\",\"text_width\":360,\"pos\":[24,24],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"exist_func\":\"GetAdaVotingProposalsExist\",\"pos\":[0,16],\"size\":[408,138],\"bg_opa\":31,\"radius\":24,\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"align\":13,\"align_to\":-2,\"children\":[{\"type\":\"label\",\"text_func\":\"GetAdaVotingProposalsLabel\",\"exist_func\":\"GetAdaVotingProposalsExist\",\"pos\":[16,16],\"text_color\":16090890,\"font\":\"illustrate\"}]}]}", \ + GuiGetAdaData, \ + NULL, \ + FreeAdaMemory, \ + }, \ + { \ + REMAPVIEW_ADA_SIGN_TX_HASH, \ + "{\"name\":\"ada_sign_tx_hash_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,774],\"bg_color\":0,\"border_width\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowAdaSignTxHashOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiShowAdaSignTxHashDetails\"}]}]}", \ + GuiGetAdaSignTxHashData, \ + NULL, \ + FreeAdaMemory \ + }, \ + { \ + REMAPVIEW_ADA_SIGN_DATA, \ + "{\"name\":\"ada_sign_data_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,542],\"bg_color\":0,\"children\":[{\"type\":\"container\",\"size\":[408,100],\"pos\":[0,0],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Path \",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetAdaSignDataDerviationPathText\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"size\":[408,138],\"pos\":[0,124],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Public Key\",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetAdaSignDataXPubText\",\"text_len_func\":\"GetAdaSignDataXPubLength\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"size\":[408,138],\"pos\":[0,278],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Message Hash\",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetAdaSignDataMessageHashText\",\"text_len_func\":\"GetAdaSignDataMessageHashLength\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"size\":[408,228],\"pos\":[0,432],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Payload\",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetAdaSignDataPayloadText\",\"text_len_func\":\"GetAdaSignDataPayloadLength\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]}]}", \ + GuiGetAdaSignDataData, \ + NULL, \ + FreeAdaSignDataMemory, \ + }, \ + { \ + REMAPVIEW_ADA_CATALYST, \ + "{\"name\":\"ada_catalyst_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,542],\"bg_color\":0,\"children\":[{\"type\":\"container\",\"pos\":[0,0],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Method\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text\":\"Catalyst Key Registration\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,78],\"size\":[408,62],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Nonce\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCatalystNonce\",\"pos\":[120,16],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,156],\"size\":[408,160],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"StakeKey\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCatalystVotePublicKey\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,332],\"size\":[408,258],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"RewardsGoTo\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCatalystRewards\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"custom_container\",\"pos\":[24,182],\"custom_show_func\":\"GetCatalystRewardsNotice\"}]},{\"type\":\"container\",\"pos\":[0,606],\"size_func\":\"GetCatalystVoteKeysSize\",\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"VoteKey\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetCatalystVoteKeys\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]}]}", \ + GuiGetAdaCatalyst, \ + NULL, \ + FreeAdaCatalystMemory, \ + }, \ + { \ + REMAPVIEW_XRP, \ + "{\"type\":\"container\",\"pos\":[36,0],\"size\":[408,526],\"bg_opa\":0,\"children\":[{\"type\":\"label\",\"text\":\"Transaction Raw Data\",\"text_width\":360,\"text_opa\":144,\"pos\":[0,0],\"font\":\"openSansEnIllustrate\"},{\"type\":\"container\",\"pos\":[0,38],\"size\":[408,488],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text_func\":\"GetXrpDetail\",\"text_len_func\":\"GetXrpDetailLen\",\"text_width\":360,\"pos\":[24,24],\"font\":\"openSansEnIllustrate\"}]}]}", \ + GuiGetXrpData, \ + NULL, \ + FreeXrpMemory, \ + }, \ + { \ + REMAPVIEW_AR, \ + "{\"name\":\"ar_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,144],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Value\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetArweaveValue\",\"pos\":[24,50],\"text_color\":16090890,\"font\":\"openSansEnLittleTitle\"},{\"type\":\"label\",\"text\":\"Fee\",\"pos\":[24,98],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetArweaveFee\",\"pos\":[73,98],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,16],\"size\":[408,244],\"align_to\":-2,\"align\":13,\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"From\",\"pos\":[24,16],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetArweaveFromAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,130],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetArweaveToAddress\",\"text_width\":360,\"pos\":[0,8],\"align_to\":-2,\"align\":13,\"font\":\"openSansEnIllustrate\"}]}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Details\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"container\",\"pos\":[0,12],\"size\":[408,358],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"##1\",\"font\":\"openSansEnIllustrate\",\"text_color\":16090890,\"pos\":[24,16]},{\"type\":\"label\",\"text\":\"Value\",\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"pos\":[24,62]},{\"type\":\"label\",\"text_func\":\"GetArweaveValue\",\"pos\":[92,62],\"text_color\":16090890,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"Fee\",\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"pos\":[24,100]},{\"type\":\"label\",\"text_func\":\"GetArweaveFee\",\"pos\":[73,100],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"From\",\"font\":\"openSansEnIllustrate\",\"text_opa\":144,\"pos\":[24,138]},{\"type\":\"label\",\"text_func\":\"GetArweaveFromAddress\",\"pos\":[24,176],\"text_width\":360,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text\":\"To\",\"pos\":[24,244],\"text_opa\":144,\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetArweaveToAddress\",\"pos\":[24,282],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"custom_container\",\"pos\":[0,16],\"radius\":24,\"custom_show_func\":\"GuiShowArweaveTxDetail\"}]}]}", \ + GuiGetArData, \ + NULL, \ + FreeArMemory, \ + }, \ + { \ + REMAPVIEW_AR_MESSAGE, \ + "{\"name\":\"ar_message_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,542],\"bg_color\":0,\"children\":[{\"type\":\"container\",\"size\":[408,130],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Address \",\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\",\"text_opa\":144},{\"type\":\"label\",\"text_func\":\"GetArweaveMessageAddress\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,146],\"size\":[408,766],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Message(UTF-8)\",\"font\":\"openSansEnIllustrate\",\"text_color\":16090890,\"pos\":[24,16]},{\"type\":\"label\",\"text_func\":\"GetArweaveMessageText\",\"text_len_func\":\"GetArweaveMessageLength\",\"pos\":[24,62],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]},{\"type\":\"container\",\"pos\":[0,928],\"size\":[408,900],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Message\",\"font\":\"openSansEnIllustrate\",\"text_color\":16090890,\"pos\":[24,16]},{\"type\":\"label\",\"text_func\":\"GetArweaveRawMessage\",\"text_len_func\":\"GetArweaveRawMessageLength\",\"pos\":[24,62],\"text_width\":360,\"font\":\"openSansEnIllustrate\"}]}]}", \ + GuiGetArData, \ + NULL, \ + FreeArMemory, \ + }, \ + { \ + REMAPVIEW_STELLAR, \ + "{\"name\":\"ar_message_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,542],\"bg_color\":0,\"children\":[{\"type\":\"custom_container\",\"size\":[408,212],\"pos\":[0,0],\"radius\":24,\"custom_show_func\":\"GuiStellarTxNotice\"},{\"type\":\"container\",\"size\":[408,310],\"pos\":[0,236],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"XDR\",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetStellarRawMessage\",\"text_len_func\":\"GetStellarRawMessageLength\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]}]}", \ + GuiGetStellarData, \ + NULL, \ + FreeStellarMemory, \ + }, \ + { \ + REMAPVIEW_STELLAR_HASH, \ + "{\"name\":\"ar_message_page\",\"type\":\"container\",\"pos\":[36,0],\"size\":[408,542],\"bg_color\":0,\"children\":[{\"type\":\"custom_container\",\"size\":[408,260],\"pos\":[0,0],\"radius\":24,\"custom_show_func\":\"GuiStellarHashNotice\"},{\"type\":\"container\",\"size\":[408,130],\"pos\":[0,284],\"bg_opa\":31,\"radius\":24,\"children\":[{\"type\":\"label\",\"text\":\"Hash\",\"text_color\":16090890,\"pos\":[24,16],\"size\":[408,130],\"font\":\"openSansEnIllustrate\"},{\"type\":\"label\",\"text_func\":\"GetStellarRawMessage\",\"text_len_func\":\"GetStellarRawMessageLength\",\"text_width\":360,\"pos\":[24,54],\"font\":\"openSansEnIllustrate\"}]}]}", \ + GuiGetStellarData, \ + NULL, \ + FreeStellarMemory, \ + }, \ + { \ + REMAPVIEW_AR_DATAITEM, \ + "{\"name\":\"ar_data_item_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiArDataItemOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Additions\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiArDataItemDetail\"}]}]}", \ + GuiGetArData, \ + NULL, \ + FreeArMemory, \ + }, \ + { \ + REMAPVIEW_TON, \ + "{\"name\":\"ton_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiTonTxOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Raw Data\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiTonTxRawData\"}]}]}", \ + GuiGetTonGUIData, \ + NULL, \ + FreeArMemory, \ + }, \ + { \ + REMAPVIEW_TON_SIGNPROOF, \ + "{\"name\":\"btc_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,774],\"bg_color\":0,\"border_width\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiTonProofOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Raw Data\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiTonProofRawData\"}]}]}", \ + GuiGetTonProofGUIData, \ + NULL, \ + FreeArMemory, \ + } + +#endif +#endif \ No newline at end of file diff --git a/src/ui/gui_chain/btc/gui_btc.c b/src/ui/gui_chain/gui_btc.c similarity index 99% rename from src/ui/gui_chain/btc/gui_btc.c rename to src/ui/gui_chain/gui_btc.c index 8aadb5508..b4c95550b 100644 --- a/src/ui/gui_chain/btc/gui_btc.c +++ b/src/ui/gui_chain/gui_btc.c @@ -12,7 +12,7 @@ #include "gui_transaction_detail_widgets.h" #ifdef BTC_ONLY #include "gui_multisig_transaction_signature_widgets.h" -#include "gui_btc_home_widgets.h" +#include "gui_home_widgets.h" #endif #include "gui_chain_components.h" @@ -33,6 +33,7 @@ #define MAX_WALLET_CONFIG_LEN 3000 #define MAX_VERIFY_CODE_LEN 12 + #ifndef BTC_ONLY typedef struct UtxoViewToChain { ViewType viewType; @@ -48,10 +49,8 @@ static UtxoViewToChain_t g_UtxoViewToChainMap[] = { {DashTx, XPUB_TYPE_DASH, "m/44'/5'/0'"}, {BchTx, XPUB_TYPE_BCH, "m/44'/145'/0'"}, }; -#define CHECK_UR_TYPE() (urType != Bytes && urType != KeystoneSignRequest) -#else -#define CHECK_UR_TYPE() (urType != Bytes) #endif + static bool g_isMulti = false; static URParseResult *g_urResult = NULL; static URParseMultiResult *g_urMultiResult = NULL; @@ -1086,6 +1085,7 @@ static lv_obj_t *CreateDetailAmountView(lv_obj_t *parent, DisplayTxDetail *detai static lv_obj_t *CreateDetailFromView(lv_obj_t *parent, DisplayTxDetail *detailData, lv_obj_t *lastView) { + bool showChange = true; #ifndef BTC_ONLY enum QRCodeType urType = URTypeUnKnown; if (g_isMulti) { @@ -1094,9 +1094,7 @@ static lv_obj_t *CreateDetailFromView(lv_obj_t *parent, DisplayTxDetail *detailD urType = g_urResult->ur_type; } - bool showChange = (urType != Bytes && urType != KeystoneSignRequest); -#else - bool showChange = true; + showChange = (urType != Bytes && urType != KeystoneSignRequest); #endif lv_obj_t *formContainer = GuiCreateContainerWithParent(parent, 408, 0); diff --git a/src/ui/gui_chain/btc/gui_btc.h b/src/ui/gui_chain/gui_btc.h similarity index 100% rename from src/ui/gui_chain/btc/gui_btc.h rename to src/ui/gui_chain/gui_btc.h diff --git a/src/ui/gui_chain/gui_chain.c b/src/ui/gui_chain/gui_chain.c index 419b29d95..e4d9cdb02 100644 --- a/src/ui/gui_chain/gui_chain.c +++ b/src/ui/gui_chain/gui_chain.c @@ -1,5 +1,16 @@ #include "gui_chain.h" +typedef TransactionCheckResult *(*CheckUrResultHandler)(void); + +typedef struct { + ViewType type; + GenerateUR handler; + GenerateUR unlimitHandler; + CheckUrResultHandler checkHandler; + GuiChainCoinType coinType; + GuiRemapViewType remapType; +} ViewHandlerEntry; + #ifndef BTC_ONLY bool CheckViewTypeIsAllow(uint8_t viewType) { @@ -21,216 +32,118 @@ bool CheckViewTypeIsAllow(uint8_t viewType) } #endif +static const ViewHandlerEntry g_viewHandlerMap[] = { + {BtcNativeSegwitTx, GuiGetBtcSignQrCodeData, GuiGetBtcSignUrDataUnlimited, GuiGetPsbtCheckResult, CHAIN_BTC, REMAPVIEW_BTC}, + {BtcSegwitTx, GuiGetBtcSignQrCodeData, GuiGetBtcSignUrDataUnlimited, GuiGetPsbtCheckResult, CHAIN_BTC, REMAPVIEW_BTC}, + {BtcLegacyTx, GuiGetBtcSignQrCodeData, GuiGetBtcSignUrDataUnlimited, GuiGetPsbtCheckResult, CHAIN_BTC, REMAPVIEW_BTC}, + {BtcTx, GuiGetBtcSignQrCodeData, GuiGetBtcSignUrDataUnlimited, GuiGetPsbtCheckResult, CHAIN_BTC, REMAPVIEW_BTC}, + {BtcMsg, GuiGetBtcSignQrCodeData, GuiGetBtcSignUrDataUnlimited, GuiGetPsbtCheckResult, CHAIN_BTC, REMAPVIEW_BTC_MESSAGE}, + +#ifdef BTC_ONLY + {LtcTx, GuiGetBtcSignQrCodeData, GuiGetBtcSignUrDataUnlimited, GuiGetPsbtCheckResult, CHAIN_LTC, REMAPVIEW_BTC}, + {DashTx, GuiGetBtcSignQrCodeData, GuiGetBtcSignUrDataUnlimited, GuiGetPsbtCheckResult, CHAIN_DASH, REMAPVIEW_BTC}, + {BchTx, GuiGetBtcSignQrCodeData, GuiGetBtcSignUrDataUnlimited, GuiGetPsbtCheckResult, CHAIN_BCH, REMAPVIEW_BTC}, +#endif + +#ifdef GENERAL_VERSION + {EthTx, GuiGetEthSignQrCodeData, GuiGetEthSignUrDataUnlimited, GuiGetEthCheckResult, CHAIN_ETH, REMAPVIEW_ETH}, + {EthPersonalMessage, GuiGetEthSignQrCodeData, GuiGetEthSignUrDataUnlimited, GuiGetEthCheckResult, CHAIN_ETH, REMAPVIEW_ETH_PERSONAL_MESSAGE}, + {EthTypedData, GuiGetEthSignQrCodeData, GuiGetEthSignUrDataUnlimited, GuiGetEthCheckResult, CHAIN_ETH, REMAPVIEW_ETH_TYPEDDATA}, + + {TronTx, GuiGetTrxSignQrCodeData, NULL, GuiGetTrxCheckResult, CHAIN_TRX, CHAIN_TRX, REMAPVIEW_TRX}, + + // must get from GuiGetCosmosTxChain + {CosmosTx, GuiGetCosmosSignQrCodeData, NULL, GuiGetCosmosCheckResult, CHAIN_ATOM, REMAPVIEW_COSMOS}, + {CosmosEvmTx, GuiGetCosmosSignQrCodeData, NULL, GuiGetCosmosCheckResult, CHAIN_ATOM, REMAPVIEW_COSMOS}, + + {SuiTx, GuiGetSuiSignQrCodeData, NULL, GuiGetSuiCheckResult, CHAIN_SUI, REMAPVIEW_SUI}, + {SuiSignMessageHash, GuiGetSuiSignHashQrCodeData, NULL, GuiGetSuiSignHashCheckResult, CHAIN_SUI, REMAPVIEW_SUI_SIGN_MESSAGE_HASH}, + + {SolanaTx, GuiGetSolSignQrCodeData, NULL, GuiGetSolCheckResult, CHAIN_SOL, REMAPVIEW_SOL}, + {SolanaMessage, GuiGetSolSignQrCodeData, NULL, GuiGetSolCheckResult, CHAIN_SOL, REMAPVIEW_SOL_MESSAGE}, + + {AptosTx, GuiGetAptosSignQrCodeData, NULL, GuiGetAptosCheckResult, CHAIN_APT, REMAPVIEW_APT}, + + {CardanoSignTxHash, GuiGetAdaSignTxHashQrCodeData, NULL, GuiGetAdaSignTxHashCheckResult, CHAIN_ADA, REMAPVIEW_ADA_SIGN_TX_HASH}, + {CardanoSignData, GuiGetAdaSignSignDataQrCodeData, NULL, GuiGetAdaSignDataCheckResult, CHAIN_ADA, REMAPVIEW_ADA_SIGN_DATA}, + {CardanoCatalystVotingRegistration, GuiGetAdaSignCatalystVotingRegistrationQrCodeData, NULL, GuiGetAdaCatalystCheckResult, CHAIN_ADA, REMAPVIEW_ADA_CATALYST}, + {CardanoTx, GuiGetAdaSignQrCodeData, NULL, GuiGetAdaCheckResult, CHAIN_ADA, REMAPVIEW_ADA}, + + {XRPTx, GuiGetXrpSignQrCodeData, NULL, GuiGetXrpCheckResult, CHAIN_XRP, REMAPVIEW_XRP}, + + {ArweaveTx, GuiGetArweaveSignQrCodeData, NULL, GuiGetArCheckResult, CHAIN_ARWEAVE, REMAPVIEW_AR}, + {ArweaveMessage, GuiGetArweaveSignQrCodeData, NULL, GuiGetArCheckResult, CHAIN_ARWEAVE, REMAPVIEW_AR_MESSAGE}, + {ArweaveDataItem, GuiGetArweaveSignQrCodeData, NULL, GuiGetArCheckResult, CHAIN_ARWEAVE, REMAPVIEW_AR_DATAITEM}, + + {StellarTx, GuiGetStellarSignQrCodeData, NULL, GuiGetStellarCheckResult, CHAIN_STELLAR, REMAPVIEW_STELLAR}, + {StellarHash, GuiGetStellarSignQrCodeData, NULL, GuiGetStellarCheckResult, CHAIN_STELLAR, REMAPVIEW_STELLAR_HASH}, + + {TonTx, GuiGetTonSignQrCodeData, NULL, GuiGetTonCheckResult, CHAIN_TON, REMAPVIEW_TON}, + {TonSignProof, GuiGetTonProofSignQrCodeData, NULL, GuiGetTonCheckResult, CHAIN_TON, REMAPVIEW_TON_SIGNPROOF}, +#endif + +#ifdef CYBERPUNK_VERSION + {ZcashTx, GuiGetZcashSignQrCodeData, NULL, GuiGetZcashCheckResult, CHAIN_ZCASH, REMAPVIEW_ZCASH}, +#endif +}; + +static const ViewHandlerEntry *GetViewHandlerEntry(ViewType viewType); + PtrT_TransactionCheckResult CheckUrResult(uint8_t viewType) { - switch (ViewTypeReMap(viewType)) { - case REMAPVIEW_BTC: - case REMAPVIEW_BTC_MESSAGE: - return GuiGetPsbtCheckResult(); -#ifndef BTC_ONLY - case REMAPVIEW_ETH: - case REMAPVIEW_ETH_PERSONAL_MESSAGE: - case REMAPVIEW_ETH_TYPEDDATA: - return GuiGetEthCheckResult(); - case REMAPVIEW_TRX: - return GuiGetTrxCheckResult(); - case REMAPVIEW_COSMOS: - return GuiGetCosmosCheckResult(); - case REMAPVIEW_SUI: - return GuiGetSuiCheckResult(); - case REMAPVIEW_SUI_SIGN_MESSAGE_HASH: - return GuiGetSuiSignHashCheckResult(); - case REMAPVIEW_SOL: - case REMAPVIEW_SOL_MESSAGE: - return GuiGetSolCheckResult(); - case REMAPVIEW_APT: - return GuiGetAptosCheckResult(); - case REMAPVIEW_ADA_SIGN_TX_HASH: - return GuiGetAdaSignTxHashCheckResult(); - case REMAPVIEW_ADA: - return GuiGetAdaCheckResult(); - case REMAPVIEW_ADA_SIGN_DATA: - return GuiGetAdaSignDataCheckResult(); - case REMAPVIEW_ADA_CATALYST: - return GuiGetAdaCatalystCheckResult(); - case REMAPVIEW_XRP: - return GuiGetXrpCheckResult(); - case REMAPVIEW_AR: - case REMAPVIEW_AR_MESSAGE: - case REMAPVIEW_AR_DATAITEM: - return GuiGetArCheckResult(); - case REMAPVIEW_STELLAR: - case REMAPVIEW_STELLAR_HASH: - return GuiGetStellarCheckResult(); - case REMAPVIEW_TON: - case REMAPVIEW_TON_SIGNPROOF: - return GuiGetTonCheckResult(); - case REMAPVIEW_ZCASH: - return GuiGetZcashCheckResult(); -#endif - default: - return NULL; + const ViewHandlerEntry *entry = GetViewHandlerEntry(viewType); + if (entry != NULL) { + return entry->checkHandler(); } + return NULL; } -GuiChainCoinType ViewTypeToChainTypeSwitch(uint8_t ViewType) +GuiChainCoinType ViewTypeToChainTypeSwitch(uint8_t viewType) { - switch (ViewType) { - case BtcNativeSegwitTx: - case BtcSegwitTx: - case BtcLegacyTx: - case BtcTx: - case BtcMsg: - return CHAIN_BTC; -#ifndef BTC_ONLY - case LtcTx: - return CHAIN_LTC; - case DashTx: - return CHAIN_DASH; - case BchTx: - return CHAIN_BCH; - case EthPersonalMessage: - case EthTx: - case EthTypedData: - return CHAIN_ETH; - case TronTx: - return CHAIN_TRX; - case CosmosTx: - case CosmosEvmTx: + if (viewType == CosmosTx || viewType == CosmosEvmTx) { return GuiGetCosmosTxChain(); - case SuiTx: - return CHAIN_SUI; - case SuiSignMessageHash: - return CHAIN_SUI; - case SolanaTx: - case SolanaMessage: - return CHAIN_SOL; - case AptosTx: - return CHAIN_APT; - case CardanoSignTxHash: - return CHAIN_ADA; - case CardanoTx: - case CardanoSignData: - case CardanoCatalystVotingRegistration: - return CHAIN_ADA; - case XRPTx: - return CHAIN_XRP; - case ArweaveTx: - case ArweaveMessage: - case ArweaveDataItem: - return CHAIN_ARWEAVE; - case StellarTx: - case StellarHash: - return CHAIN_STELLAR; - case TonTx: - case TonSignProof: - return CHAIN_TON; - case ZcashTx: - return CHAIN_ZCASH; -#endif - default: - return CHAIN_BUTT; + } + + const ViewHandlerEntry *entry = GetViewHandlerEntry(viewType); + if (entry != NULL) { + return entry->coinType; } return CHAIN_BUTT; } -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION bool IsMessageType(uint8_t type) { return type == EthPersonalMessage || type == EthTypedData || IsCosmosMsg(type) || type == SolanaMessage || IsAptosMsg(type) || type == BtcMsg || type == ArweaveMessage || type == CardanoSignData; } +bool isCatalystVotingRegistration(uint8_t type) +{ + return type == CardanoCatalystVotingRegistration; +} +#endif + bool isTonSignProof(uint8_t type) { return type == TonSignProof; } -bool isCatalystVotingRegistration(uint8_t type) +static GenerateUR UrGenerator(ViewType viewType, bool isMulti) { - return type == CardanoCatalystVotingRegistration; + const ViewHandlerEntry *entry = GetViewHandlerEntry(viewType); + if (entry != NULL) { + return isMulti ? entry->handler : entry->unlimitHandler; + } + return NULL; } -#endif -static GenerateUR UrGenerator(ViewType viewType, bool isMulti) +GuiRemapViewType ViewTypeReMap(uint8_t viewType) { - GenerateUR func = NULL; - switch (viewType) { - case BtcNativeSegwitTx: - case BtcSegwitTx: - case BtcLegacyTx: - case BtcTx: - case BtcMsg: -#ifndef BTC_ONLY - case LtcTx: - case DashTx: - case BchTx: -#endif - func = isMulti ? GuiGetBtcSignQrCodeData : GuiGetBtcSignUrDataUnlimited; - break; -#ifndef BTC_ONLY - case EthTx: - case EthPersonalMessage: - case EthTypedData: - func = isMulti ? GuiGetEthSignQrCodeData : GuiGetEthSignUrDataUnlimited; - break; - case TronTx: - func = GuiGetTrxSignQrCodeData; - break; - case CosmosTx: - case CosmosEvmTx: - func = GuiGetCosmosSignQrCodeData; - break; - case SuiTx: - func = GuiGetSuiSignQrCodeData; - break; - case SuiSignMessageHash: - func = GuiGetSuiSignHashQrCodeData; - break; - case SolanaTx: - case SolanaMessage: - func = GuiGetSolSignQrCodeData; - break; - case AptosTx: - func = GuiGetAptosSignQrCodeData; - break; - case CardanoSignTxHash: - func = GuiGetAdaSignTxHashQrCodeData; - break; - case CardanoSignData: - func = GuiGetAdaSignSignDataQrCodeData; - break; - case CardanoCatalystVotingRegistration: - func = GuiGetAdaSignCatalystVotingRegistrationQrCodeData; - break; - case CardanoTx: - func = GuiGetAdaSignQrCodeData; - break; - case XRPTx: - func = GuiGetXrpSignQrCodeData; - break; - case ArweaveTx: - case ArweaveMessage: - case ArweaveDataItem: - func = GuiGetArweaveSignQrCodeData; - break; - case StellarTx: - case StellarHash: - func = GuiGetStellarSignQrCodeData; - break; - case TonTx: - func = GuiGetTonSignQrCodeData; - break; - case TonSignProof: - func = GuiGetTonProofSignQrCodeData; - break; - case ZcashTx: - func = GuiGetZcashSignQrCodeData; - break; -#endif - default: - break; + const ViewHandlerEntry *entry = GetViewHandlerEntry(viewType); + if (entry != NULL) { + return entry->remapType; } - return func; + return REMAPVIEW_BUTT; } GenerateUR GetUrGenerator(ViewType viewType) @@ -241,4 +154,14 @@ GenerateUR GetUrGenerator(ViewType viewType) GenerateUR GetSingleUrGenerator(ViewType viewType) { return UrGenerator(viewType, false); +} + +static const ViewHandlerEntry *GetViewHandlerEntry(ViewType viewType) +{ + for (size_t i = 0; i < NUMBER_OF_ARRAYS(g_viewHandlerMap); i++) { + if (g_viewHandlerMap[i].type == viewType) { + return &g_viewHandlerMap[i]; + } + } + return NULL; } \ No newline at end of file diff --git a/src/ui/gui_chain/gui_chain.h b/src/ui/gui_chain/gui_chain.h index a680ea785..87c2b5368 100644 --- a/src/ui/gui_chain/gui_chain.h +++ b/src/ui/gui_chain/gui_chain.h @@ -4,6 +4,7 @@ #include "gui_animating_qrcode.h" #include "gui_btc.h" #ifndef BTC_ONLY +#ifdef GENERAL_VERSION #include "gui_eth.h" #include "gui_trx.h" #include "gui_cosmos.h" @@ -15,8 +16,10 @@ #include "gui_ar.h" #include "gui_stellar.h" #include "gui_ton.h" +#else #include "gui_zcash.h" #endif +#endif typedef void (*SetChainDataFunc)(void *resultData, void *multiResultData, bool multi); diff --git a/src/ui/gui_chain/others/gui_zcash.c b/src/ui/gui_chain/multi/cyberpunk/gui_zcash.c similarity index 95% rename from src/ui/gui_chain/others/gui_zcash.c rename to src/ui/gui_chain/multi/cyberpunk/gui_zcash.c index a32044136..b45d24908 100644 --- a/src/ui/gui_chain/others/gui_zcash.c +++ b/src/ui/gui_chain/multi/cyberpunk/gui_zcash.c @@ -27,7 +27,8 @@ void GuiSetZcashUrData(URParseResult *urResult, URParseMultiResult *urMultiResul g_isMulti = multi; } -void *GuiGetZcashGUIData(void) { +void *GuiGetZcashGUIData(void) +{ CHECK_FREE_PARSE_RESULT(g_parseResult); void *data = g_isMulti ? g_urMultiResult->data : g_urResult->data; char ufvk[ZCASH_UFVK_MAX_LEN] = {'\0'}; @@ -50,7 +51,8 @@ static lv_obj_t* GuiZcashOverviewOrchard(lv_obj_t *parent, lv_obj_t *last_view); static lv_obj_t* GuiZcashOverviewFrom(lv_obj_t *parent, VecFFI_DisplayFrom *from, lv_obj_t *last_view); static lv_obj_t* GuiZcashOverviewTo(lv_obj_t *parent, VecFFI_DisplayTo *to, lv_obj_t *last_view); -void GuiZcashOverview(lv_obj_t *parent, void *totalData) { +void GuiZcashOverview(lv_obj_t *parent, void *totalData) +{ lv_obj_set_size(parent, 408, 480); lv_obj_add_flag(parent, LV_OBJ_FLAG_SCROLLABLE); lv_obj_add_flag(parent, LV_OBJ_FLAG_CLICKABLE); @@ -61,23 +63,24 @@ void GuiZcashOverview(lv_obj_t *parent, void *totalData) { lv_obj_t* last_view = NULL; - if(g_zcashData->has_sapling) { + if (g_zcashData->has_sapling) { last_view = CreateTransactionItemView(container, _("Warning"), _("This transaction contains Sapling spends or outputs. Keystone does not support Sapling spend signing and output checking. Please take care of the potential risks."), last_view); } last_view = CreateTransactionItemView(container, _("Amount"), g_zcashData->total_transfer_value, last_view); last_view = CreateTransactionItemView(container, _("Fee"), g_zcashData->fee_value, last_view); - if(g_zcashData->transparent != NULL) { + if (g_zcashData->transparent != NULL) { last_view = GuiZcashOverviewTransparent(container, last_view); } - if(g_zcashData->orchard != NULL) { + if (g_zcashData->orchard != NULL) { last_view = GuiZcashOverviewOrchard(container, last_view); } } -static lv_obj_t* GuiZcashOverviewTransparent(lv_obj_t *parent, lv_obj_t *last_view) { +static lv_obj_t* GuiZcashOverviewTransparent(lv_obj_t *parent, lv_obj_t *last_view) +{ lv_obj_t* inner_last_view; lv_obj_t* label = GuiCreateIllustrateLabel(parent, _("Transparent")); lv_obj_align_to(label, last_view, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 24); @@ -97,7 +100,8 @@ static lv_obj_t* GuiZcashOverviewTransparent(lv_obj_t *parent, lv_obj_t *last_vi return inner_last_view; } -static lv_obj_t* GuiZcashOverviewOrchard(lv_obj_t* parent, lv_obj_t *last_view) { +static lv_obj_t* GuiZcashOverviewOrchard(lv_obj_t* parent, lv_obj_t *last_view) +{ lv_obj_t* inner_last_view; lv_obj_t* label = GuiCreateIllustrateLabel(parent, _("Orchard")); lv_obj_align_to(label, last_view, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 24); @@ -117,7 +121,8 @@ static lv_obj_t* GuiZcashOverviewOrchard(lv_obj_t* parent, lv_obj_t *last_view) return inner_last_view; } -static lv_obj_t* GuiZcashOverviewFrom(lv_obj_t *parent, VecFFI_DisplayFrom *from, lv_obj_t *last_view) { +static lv_obj_t* GuiZcashOverviewFrom(lv_obj_t *parent, VecFFI_DisplayFrom *from, lv_obj_t *last_view) +{ lv_obj_t* label, *container; uint16_t height = 0; @@ -136,11 +141,10 @@ static lv_obj_t* GuiZcashOverviewFrom(lv_obj_t *parent, VecFFI_DisplayFrom *from lv_obj_t *innerContainer; - for (size_t i = 0; i < from->size; i++) - { + for (size_t i = 0; i < from->size; i++) { lv_obj_t *valueLabel, *indexLabel, *addressLabel; uint16_t innerHeight = 0; - if(i > 0) { + if (i > 0) { //add margin innerHeight += 16; } @@ -157,7 +161,7 @@ static lv_obj_t* GuiZcashOverviewFrom(lv_obj_t *parent, VecFFI_DisplayFrom *from lv_obj_set_style_text_color(valueLabel, ORANGE_COLOR, LV_PART_MAIN); lv_obj_align_to(valueLabel, indexLabel, LV_ALIGN_OUT_RIGHT_MID, 16, 0); - if(from->data[i].is_mine) { + if (from->data[i].is_mine) { lv_obj_t *tagContainer = GuiCreateContainerWithParent(innerContainer, 87, 30); lv_obj_set_style_radius(tagContainer, 16, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_color(tagContainer, WHITE_COLOR, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -197,7 +201,8 @@ static lv_obj_t* GuiZcashOverviewFrom(lv_obj_t *parent, VecFFI_DisplayFrom *from return container; } -static lv_obj_t* GuiZcashOverviewTo(lv_obj_t *parent, VecFFI_DisplayTo *to, lv_obj_t *last_view) { +static lv_obj_t* GuiZcashOverviewTo(lv_obj_t *parent, VecFFI_DisplayTo *to, lv_obj_t *last_view) +{ lv_obj_t* label, *container; uint16_t height = 0; @@ -218,11 +223,10 @@ static lv_obj_t* GuiZcashOverviewTo(lv_obj_t *parent, VecFFI_DisplayTo *to, lv_o lv_obj_t *innerContainer; - for (size_t i = 0; i < to->size; i++) - { + for (size_t i = 0; i < to->size; i++) { lv_obj_t *valueLabel, *indexLabel, *addressLabel; uint16_t innerHeight = 0; - if(i > 0) { + if (i > 0) { //add margin innerHeight += 16; } @@ -263,7 +267,7 @@ static lv_obj_t* GuiZcashOverviewTo(lv_obj_t *parent, VecFFI_DisplayTo *to, lv_o innerHeight += lv_obj_get_height(addressLabel); - if(to->data[i].memo != NULL && strnlen(to->data[i].memo, MAX_MEMO_LENGTH) > 0) { + if (to->data[i].memo != NULL && strnlen(to->data[i].memo, MAX_MEMO_LENGTH) > 0) { char *memo = (char *)malloc(MAX_MEMO_LENGTH); snprintf_s(memo, MAX_MEMO_LENGTH, "Memo: %s", to->data[i].memo); lv_obj_t *memoLabel = GuiCreateIllustrateLabel(innerContainer, memo); diff --git a/src/ui/gui_chain/others/gui_zcash.h b/src/ui/gui_chain/multi/cyberpunk/gui_zcash.h similarity index 100% rename from src/ui/gui_chain/others/gui_zcash.h rename to src/ui/gui_chain/multi/cyberpunk/gui_zcash.h diff --git a/src/ui/gui_chain/others/gui_ada.c b/src/ui/gui_chain/multi/gui_ada.c similarity index 99% rename from src/ui/gui_chain/others/gui_ada.c rename to src/ui/gui_chain/multi/gui_ada.c index b2f5f1c11..b13e1df36 100644 --- a/src/ui/gui_chain/others/gui_ada.c +++ b/src/ui/gui_chain/multi/gui_ada.c @@ -688,9 +688,9 @@ UREncodeResult *GuiGetAdaSignQrCodeData(void) if (GetAdaXPubType() == LEDGER_ADA) { char *mnemonic = NULL; bip39_mnemonic_from_bytes(NULL, entropy, len, &mnemonic); - encodeResult = cardano_sign_tx_with_ledger_bitbox02(data, mfp, xpub, mnemonic, GetPassphrase(GetCurrentAccountIndex()),false); + encodeResult = cardano_sign_tx_with_ledger_bitbox02(data, mfp, xpub, mnemonic, GetPassphrase(GetCurrentAccountIndex()), false); } else { - encodeResult = cardano_sign_tx(data, mfp, xpub, entropy, len, GetPassphrase(GetCurrentAccountIndex()),false); + encodeResult = cardano_sign_tx(data, mfp, xpub, entropy, len, GetPassphrase(GetCurrentAccountIndex()), false); } ClearSecretCache(); CHECK_CHAIN_BREAK(encodeResult); @@ -721,9 +721,9 @@ UREncodeResult *GuiGetAdaSignTxHashQrCodeData(void) if (GetAdaXPubType() == LEDGER_ADA) { char *mnemonic = NULL; bip39_mnemonic_from_bytes(NULL, entropy, len, &mnemonic); - encodeResult = cardano_sign_tx_with_ledger_bitbox02(data, mfp, xpub, mnemonic, GetPassphrase(GetCurrentAccountIndex()),true); + encodeResult = cardano_sign_tx_with_ledger_bitbox02(data, mfp, xpub, mnemonic, GetPassphrase(GetCurrentAccountIndex()), true); } else { - encodeResult = cardano_sign_tx(data, mfp, xpub, entropy, len, GetPassphrase(GetCurrentAccountIndex()),true); + encodeResult = cardano_sign_tx(data, mfp, xpub, entropy, len, GetPassphrase(GetCurrentAccountIndex()), true); } ClearSecretCache(); CHECK_CHAIN_BREAK(encodeResult); @@ -839,14 +839,14 @@ void GuiShowAdaSignTxHashDetails(lv_obj_t *parent, void *totalData) lv_obj_align(network_card, LV_ALIGN_DEFAULT, 0, 0); lv_obj_update_layout(network_card); int containerYOffset = lv_obj_get_height(network_card) + 16; - // From Conatiner + // From Conatiner lv_obj_t *from_container = GuiCreateContainerWithParent(parent, 408, LV_SIZE_CONTENT); lv_obj_align(from_container, LV_ALIGN_DEFAULT, 0, containerYOffset); SetFlexContainerStyle(from_container, LV_FLEX_FLOW_COLUMN, 16); lv_obj_t *from_label = GuiCreateTextLabel(from_container, "From"); lv_obj_set_style_text_opa(from_label, 144, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_align_to(from_label, from_container, LV_ALIGN_OUT_BOTTOM_LEFT, 24, 16); - // address + path card + // address + path card Ptr_VecFFI_PtrString addressList = hashData->address_list; Ptr_VecFFI_PtrString pathList = hashData->path; for (int i = 0; i < addressList->size; i++) { diff --git a/src/ui/gui_chain/others/gui_ada.h b/src/ui/gui_chain/multi/gui_ada.h similarity index 99% rename from src/ui/gui_chain/others/gui_ada.h rename to src/ui/gui_chain/multi/gui_ada.h index 17b9a0912..a2154766b 100644 --- a/src/ui/gui_chain/others/gui_ada.h +++ b/src/ui/gui_chain/multi/gui_ada.h @@ -6,8 +6,7 @@ #include "librust_c.h" #include "account_public_info.h" -typedef enum -{ +typedef enum { STANDARD_ADA = 0, LEDGER_ADA, } AdaXPubType; diff --git a/src/ui/gui_chain/others/gui_aptos.c b/src/ui/gui_chain/multi/gui_aptos.c similarity index 99% rename from src/ui/gui_chain/others/gui_aptos.c rename to src/ui/gui_chain/multi/gui_aptos.c index c5b8f50d7..a9d73cb13 100644 --- a/src/ui/gui_chain/others/gui_aptos.c +++ b/src/ui/gui_chain/multi/gui_aptos.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "define.h" #include "rust.h" #include "keystore.h" @@ -139,4 +138,3 @@ static uint8_t GetAptosPublickeyIndex(char* rootPath) ASSERT(0); return -1; } -#endif diff --git a/src/ui/gui_chain/others/gui_aptos.h b/src/ui/gui_chain/multi/gui_aptos.h similarity index 100% rename from src/ui/gui_chain/others/gui_aptos.h rename to src/ui/gui_chain/multi/gui_aptos.h diff --git a/src/ui/gui_chain/others/gui_ar.c b/src/ui/gui_chain/multi/gui_ar.c similarity index 99% rename from src/ui/gui_chain/others/gui_ar.c rename to src/ui/gui_chain/multi/gui_ar.c index e534f632d..f43da5134 100644 --- a/src/ui/gui_chain/others/gui_ar.c +++ b/src/ui/gui_chain/multi/gui_ar.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui_ar.h" #include "gui_chain_components.h" @@ -361,6 +360,4 @@ static void GuiArRenderDataItemDetail(lv_obj_t *parent, DisplayArweaveDataItem * for (size_t i = 0; i < txData->tags->size; i++) { lastView = CreateTransactionItemView(parent, txData->tags->data[i].name, txData->tags->data[i].value, lastView); } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ui/gui_chain/others/gui_ar.h b/src/ui/gui_chain/multi/gui_ar.h similarity index 100% rename from src/ui/gui_chain/others/gui_ar.h rename to src/ui/gui_chain/multi/gui_ar.h diff --git a/src/ui/gui_chain/others/gui_cosmos.c b/src/ui/gui_chain/multi/gui_cosmos.c similarity index 99% rename from src/ui/gui_chain/others/gui_cosmos.c rename to src/ui/gui_chain/multi/gui_cosmos.c index fbd4b4813..8cb77d1d3 100644 --- a/src/ui/gui_chain/others/gui_cosmos.c +++ b/src/ui/gui_chain/multi/gui_cosmos.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui_analyze.h" #include "rust.h" #include "keystore.h" @@ -607,4 +606,3 @@ UREncodeResult *GuiGetCosmosSignQrCodeData(void) SetLockScreen(enable); return encodeResult; } -#endif diff --git a/src/ui/gui_chain/others/gui_cosmos.h b/src/ui/gui_chain/multi/gui_cosmos.h similarity index 100% rename from src/ui/gui_chain/others/gui_cosmos.h rename to src/ui/gui_chain/multi/gui_cosmos.h diff --git a/src/ui/gui_chain/others/gui_eth.c b/src/ui/gui_chain/multi/gui_eth.c similarity index 99% rename from src/ui/gui_chain/others/gui_eth.c rename to src/ui/gui_chain/multi/gui_eth.c index 8d31baea0..269df0b8a 100644 --- a/src/ui/gui_chain/others/gui_eth.c +++ b/src/ui/gui_chain/multi/gui_eth.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui_analyze.h" #include "user_memory.h" #include "secret_cache.h" @@ -1391,5 +1390,4 @@ void FreeEthMemory(void) CHECK_FREE_UR_RESULT(g_urMultiResult, true); CHECK_FREE_PARSE_RESULT(g_parseResult); FreeContractData(); -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ui/gui_chain/others/gui_eth.h b/src/ui/gui_chain/multi/gui_eth.h similarity index 100% rename from src/ui/gui_chain/others/gui_eth.h rename to src/ui/gui_chain/multi/gui_eth.h diff --git a/src/ui/gui_chain/others/gui_sol.c b/src/ui/gui_chain/multi/gui_sol.c similarity index 99% rename from src/ui/gui_chain/others/gui_sol.c rename to src/ui/gui_chain/multi/gui_sol.c index e84d8055c..518372d67 100644 --- a/src/ui/gui_chain/others/gui_sol.c +++ b/src/ui/gui_chain/multi/gui_sol.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui_analyze.h" #include "rust.h" #include "account_public_info.h" @@ -1497,4 +1496,3 @@ void GuiShowSolTxDetail(lv_obj_t *parent, void *totalData) SetTitleLabelStyle(label); lv_obj_align(label, LV_ALIGN_TOP_LEFT, 0, 0); } -#endif diff --git a/src/ui/gui_chain/others/gui_sol.h b/src/ui/gui_chain/multi/gui_sol.h similarity index 100% rename from src/ui/gui_chain/others/gui_sol.h rename to src/ui/gui_chain/multi/gui_sol.h diff --git a/src/ui/gui_chain/others/gui_stellar.c b/src/ui/gui_chain/multi/gui_stellar.c similarity index 99% rename from src/ui/gui_chain/others/gui_stellar.c rename to src/ui/gui_chain/multi/gui_stellar.c index b32376e3d..198bc0c82 100644 --- a/src/ui/gui_chain/others/gui_stellar.c +++ b/src/ui/gui_chain/multi/gui_stellar.c @@ -1,5 +1,3 @@ -#ifndef BTC_ONLY - #include "gui_stellar.h" static bool g_isMulti = false; @@ -134,5 +132,3 @@ void GuiStellarHashNotice(lv_obj_t *parent, void *totalData) 180 ); } - -#endif diff --git a/src/ui/gui_chain/others/gui_stellar.h b/src/ui/gui_chain/multi/gui_stellar.h similarity index 100% rename from src/ui/gui_chain/others/gui_stellar.h rename to src/ui/gui_chain/multi/gui_stellar.h diff --git a/src/ui/gui_chain/others/gui_sui.c b/src/ui/gui_chain/multi/gui_sui.c similarity index 99% rename from src/ui/gui_chain/others/gui_sui.c rename to src/ui/gui_chain/multi/gui_sui.c index 9e12bab14..6389f55de 100644 --- a/src/ui/gui_chain/others/gui_sui.c +++ b/src/ui/gui_chain/multi/gui_sui.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "define.h" #include "rust.h" #include "keystore.h" @@ -297,5 +296,4 @@ UREncodeResult *GuiGetSuiSignHashQrCodeData(void) } while (0); SetLockScreen(enable); return encodeResult; -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ui/gui_chain/others/gui_sui.h b/src/ui/gui_chain/multi/gui_sui.h similarity index 100% rename from src/ui/gui_chain/others/gui_sui.h rename to src/ui/gui_chain/multi/gui_sui.h diff --git a/src/ui/gui_chain/others/gui_ton.c b/src/ui/gui_chain/multi/gui_ton.c similarity index 99% rename from src/ui/gui_chain/others/gui_ton.c rename to src/ui/gui_chain/multi/gui_ton.c index 2ecc665e0..8862634bc 100644 --- a/src/ui/gui_chain/others/gui_ton.c +++ b/src/ui/gui_chain/multi/gui_ton.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui_ton.h" #include "rust.h" #include "account_manager.h" @@ -433,5 +432,4 @@ void GuiTonProofRawData(lv_obj_t *parent, void *totalData) lv_obj_align(label, LV_ALIGN_TOP_LEFT, 24, 62); lv_obj_set_width(label, 360); lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ui/gui_chain/others/gui_ton.h b/src/ui/gui_chain/multi/gui_ton.h similarity index 100% rename from src/ui/gui_chain/others/gui_ton.h rename to src/ui/gui_chain/multi/gui_ton.h diff --git a/src/ui/gui_chain/others/gui_trx.c b/src/ui/gui_chain/multi/gui_trx.c similarity index 99% rename from src/ui/gui_chain/others/gui_trx.c rename to src/ui/gui_chain/multi/gui_trx.c index 7fdadb8f2..b8f252489 100644 --- a/src/ui/gui_chain/others/gui_trx.c +++ b/src/ui/gui_chain/multi/gui_trx.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui_analyze.h" #include "rust.h" #include "account_public_info.h" @@ -150,5 +149,4 @@ UREncodeResult *GuiGetTrxSignQrCodeData(void) encodeResult->error_message = NULL; return encodeResult; #endif -} -#endif +} \ No newline at end of file diff --git a/src/ui/gui_chain/others/gui_trx.h b/src/ui/gui_chain/multi/gui_trx.h similarity index 100% rename from src/ui/gui_chain/others/gui_trx.h rename to src/ui/gui_chain/multi/gui_trx.h diff --git a/src/ui/gui_chain/others/gui_xrp.c b/src/ui/gui_chain/multi/gui_xrp.c similarity index 99% rename from src/ui/gui_chain/others/gui_xrp.c rename to src/ui/gui_chain/multi/gui_xrp.c index 8f4c1026a..4d11a41af 100644 --- a/src/ui/gui_chain/others/gui_xrp.c +++ b/src/ui/gui_chain/multi/gui_xrp.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "define.h" #include "gui_xrp.h" #include "gui_chain.h" @@ -180,6 +179,4 @@ UREncodeResult *GuiGetXrpSignQrCodeData(void) } while (0); SetLockScreen(enable); return encodeResult; -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ui/gui_chain/others/gui_xrp.h b/src/ui/gui_chain/multi/gui_xrp.h similarity index 100% rename from src/ui/gui_chain/others/gui_xrp.h rename to src/ui/gui_chain/multi/gui_xrp.h diff --git a/src/ui/gui_components/gui_status_bar.c b/src/ui/gui_components/gui_status_bar.c index 58acaa3ed..5cb165bc6 100644 --- a/src/ui/gui_components/gui_status_bar.c +++ b/src/ui/gui_components/gui_status_bar.c @@ -74,10 +74,11 @@ const static CoinWalletInfo_t g_coinWalletBtn[] = { {HOME_WALLET_CARD_SUI, "", &coinSui}, {HOME_WALLET_CARD_DASH, "", &coinDash}, {HOME_WALLET_CARD_ARWEAVE, "", &coinAr}, {HOME_WALLET_CARD_XLM, "", &coinXlm}, {HOME_WALLET_CARD_COSMOS, "", &coinCosmos}, {HOME_WALLET_CARD_TIA, "", &coinTia}, - {HOME_WALLET_CARD_NTRN, "", &coinNtrn}, {HOME_WALLET_CARD_DYM, "", &coinDym}, {HOME_WALLET_CARD_OSMO, "", &coinOsmo}, + {HOME_WALLET_CARD_NTRN, "", &coinNtrn}, {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_KAVA, "", &coinKava}, {HOME_WALLET_CARD_LUNC, "", &coinLunc}, + {HOME_WALLET_CARD_KAVA, "", &coinKava}, {HOME_WALLET_CARD_LUNC, "", &coinLunc}, {HOME_WALLET_CARD_AXL, "", &coinAxl}, {HOME_WALLET_CARD_ZEC, "", &coinZec}, {HOME_WALLET_CARD_LUNA, "", &coinLuna}, {HOME_WALLET_CARD_AKT, "", &coinAkt}, {HOME_WALLET_CARD_STRD, "", &coinStrd}, {HOME_WALLET_CARD_SCRT, "", &coinScrt}, @@ -91,7 +92,6 @@ const static CoinWalletInfo_t g_coinWalletBtn[] = { {HOME_WALLET_CARD_NGM, "", &coinNgm}, {HOME_WALLET_CARD_IOV, "", &coinIov}, {HOME_WALLET_CARD_UMEE, "", &coinUmee}, {HOME_WALLET_CARD_QCK, "", &coinQck}, {HOME_WALLET_CARD_TGD, "", &coinTgd}, {HOME_WALLET_CARD_DOT, "", &coinDot}, - #endif }; diff --git a/src/ui/gui_frame/gui_framework.c b/src/ui/gui_frame/gui_framework.c index b293c6952..588ab8407 100644 --- a/src/ui/gui_frame/gui_framework.c +++ b/src/ui/gui_frame/gui_framework.c @@ -25,64 +25,6 @@ static const char *GuiFrameIdToName(SCREEN_ID_ENUM ID); static GUI_VIEW *g_workingView = NULL; static uint32_t g_viewCnt = 0; // Record how many views are opened -static GUI_VIEW *g_viewsTable[] = { - &g_initView, - &g_lockView, - &g_homeView, - &g_setupView, - &g_createWalletView, - &g_singlePhraseView, - &g_importPhraseView, - &g_createShareView, - &g_importShareView, - &g_settingView, - &g_connectWalletView, -#ifndef BTC_ONLY - &g_USBTransportView, -#endif - &g_passphraseView, - &g_utxoReceiveView, -#ifndef BTC_ONLY - &g_multiPathCoinReceiveView, - &g_standardReceiveView, -#endif - &g_forgetPassView, - &g_lockDeviceView, - &g_firmwareUpdateView, - &g_webAuthView, - &g_webAuthResultView, - &g_systemSettingView, - &g_purposeView, - &g_aboutView, - &g_aboutKeystoneView, - &g_aboutInfoView, - &g_aboutTermsView, - &g_wipeDeviceView, - &g_walletTutorialView, - &g_selfDestructView, - &g_inactiveView, - &g_displayView, - &g_tutorialView, - &g_connectionView, - &g_DevicePublicKeyView, -#ifndef BTC_ONLY - &g_multiAccountsReceiveView, - &g_keyDerivationRequestView, -#endif - &g_scanView, - &g_transactionDetailView, - &g_transactionSignatureView, - &g_diceRollsView, -#ifdef BTC_ONLY - &g_importMultisigWalletInfoView, - &g_multisigSelectImportMethodView, - &g_multisigWalletExportView, - &g_multisigReadSdcardView, - &g_createMultisigWalletView, - &g_manageMultisigWalletView, -#endif -}; - bool GuiViewHandleEvent(GUI_VIEW *view, uint16_t usEvent, void *param, uint16_t usLen) { int32_t ret; @@ -297,31 +239,4 @@ static const char *GuiFrameIdToName(SCREEN_ID_ENUM ID) printf("id = %d name = %s\n", ID, str); const char *name = str; return name; -} - -void GuiViewsTest(int argc, char *argv[]) -{ - VALUE_CHECK(argc, 2); - int viewId = atoi(argv[1]); - GUI_VIEW *view = NULL; - for (int i = 0; i < NUMBER_OF_ARRAYS(g_viewsTable); i++) { - if (viewId == g_viewsTable[i]->id) { - view = g_viewsTable[i]; - break; - } - } - if (view == NULL) { - return; - } -#ifndef COMPILE_SIMULATOR - if (strcmp(argv[0], "open") == 0) { - printf("open view %s\n", GuiFrameIdToName(view->id)); - PubValueMsg(UI_MSG_OPEN_VIEW, (uint32_t)view); - } else if (strcmp(argv[0], "close") == 0) { - printf("close view %s\n", GuiFrameIdToName(view->id)); - PubValueMsg(UI_MSG_CLOSE_VIEW, (uint32_t)view); - } else if (strcmp(argv[0], "debug") == 0) { - GuiFrameDebugging(); - } -#endif } \ No newline at end of file diff --git a/src/ui/gui_frame/gui_framework.h b/src/ui/gui_frame/gui_framework.h index ebb4c3d13..198963d79 100644 --- a/src/ui/gui_frame/gui_framework.h +++ b/src/ui/gui_frame/gui_framework.h @@ -14,7 +14,6 @@ int32_t GuiFrameWorkViewHandleMsg(void *data, uint16_t len); void GuiFrameDebugging(void); int32_t GuiCloseToTargetView(GUI_VIEW *view); bool GuiCheckIfTopView(GUI_VIEW *view); -void GuiViewsTest(int argc, char *argv[]); #define GUI_FRAME_TIMER_EVENT_PERIOD 1000 diff --git a/src/ui/gui_model/gui_model.h b/src/ui/gui_model/gui_model.h index 9ecf50fd2..fffda79f6 100644 --- a/src/ui/gui_model/gui_model.h +++ b/src/ui/gui_model/gui_model.h @@ -8,6 +8,7 @@ #include "anti_tamper.h" #include "presetting.h" #include "drv_sdcard.h" +#include "drv_mpu.h" #include "log.h" #include "presetting.h" #include "anti_tamper.h" diff --git a/src/ui/gui_views/gui_home_view.c b/src/ui/gui_views/gui_home_view.c index bc8b55904..3c151dff8 100644 --- a/src/ui/gui_views/gui_home_view.c +++ b/src/ui/gui_views/gui_home_view.c @@ -85,6 +85,9 @@ int32_t GuiHomeViewEventProcess(void *self, uint16_t usEvent, void *param, uint1 case SIG_SETUP_RSA_PRIVATE_KEY_WITH_PASSWORD_PASS: GuiShowRsaInitializatioCompleteHintbox(); break; + case SIG_CLEAR_HOME_PAGE_INDEX: + ClearHomePageCurrentIndex(); + break; #endif case SIG_QRCODE_VIEW_SCAN_FAIL: GuiScanResult(false, param); @@ -92,9 +95,6 @@ int32_t GuiHomeViewEventProcess(void *self, uint16_t usEvent, void *param, uint1 case SIG_QRCODE_VIEW_SCAN_PASS: GuiScanResult(true, param); break; - case SIG_CLEAR_HOME_PAGE_INDEX: - ClearHomePageCurrentIndex(); - break; default: return ERR_GUI_UNHANDLED; } diff --git a/src/ui/gui_views/gui_transaction_detail_view.c b/src/ui/gui_views/gui_transaction_detail_view.c index 0d5188c18..bb5e42262 100644 --- a/src/ui/gui_views/gui_transaction_detail_view.c +++ b/src/ui/gui_views/gui_transaction_detail_view.c @@ -8,7 +8,8 @@ #include "gui_attention_hintbox.h" #include "device_setting.h" -bool supportBlindSigning(uint8_t viewType) { +bool supportBlindSigning(uint8_t viewType) +{ // now we only support blind signing for Sui and Cardano return viewType == SuiSignMessageHash || viewType == CardanoSignTxHash; } diff --git a/src/ui/gui_views/general/gui_key_derivation_request_view.c b/src/ui/gui_views/multi/general/gui_key_derivation_request_view.c similarity index 100% rename from src/ui/gui_views/general/gui_key_derivation_request_view.c rename to src/ui/gui_views/multi/general/gui_key_derivation_request_view.c diff --git a/src/ui/gui_views/general/gui_multi_account_receive_view.c b/src/ui/gui_views/multi/general/gui_multi_account_receive_view.c similarity index 100% rename from src/ui/gui_views/general/gui_multi_account_receive_view.c rename to src/ui/gui_views/multi/general/gui_multi_account_receive_view.c diff --git a/src/ui/gui_views/general/gui_multi_path_coin_receive_view.c b/src/ui/gui_views/multi/general/gui_multi_path_coin_receive_view.c similarity index 100% rename from src/ui/gui_views/general/gui_multi_path_coin_receive_view.c rename to src/ui/gui_views/multi/general/gui_multi_path_coin_receive_view.c diff --git a/src/ui/gui_views/general/gui_standard_receive_view.c b/src/ui/gui_views/multi/general/gui_standard_receive_view.c similarity index 100% rename from src/ui/gui_views/general/gui_standard_receive_view.c rename to src/ui/gui_views/multi/general/gui_standard_receive_view.c diff --git a/src/ui/gui_views/gui_ton_mnemonic_hint_view.c b/src/ui/gui_views/multi/general/gui_ton_mnemonic_hint_view.c similarity index 100% rename from src/ui/gui_views/gui_ton_mnemonic_hint_view.c rename to src/ui/gui_views/multi/general/gui_ton_mnemonic_hint_view.c diff --git a/src/ui/gui_views/general/gui_usb_transport_view.c b/src/ui/gui_views/multi/general/gui_usb_transport_view.c similarity index 100% rename from src/ui/gui_views/general/gui_usb_transport_view.c rename to src/ui/gui_views/multi/general/gui_usb_transport_view.c diff --git a/src/ui/wallet/gui_wallet.c b/src/ui/gui_wallet/btc_only/gui_wallet.c similarity index 99% rename from src/ui/wallet/gui_wallet.c rename to src/ui/gui_wallet/btc_only/gui_wallet.c index b0e638766..413801660 100644 --- a/src/ui/wallet/gui_wallet.c +++ b/src/ui/gui_wallet/btc_only/gui_wallet.c @@ -10,7 +10,7 @@ #include "version.h" static UREncodeResult *g_urEncode = NULL; - +1 UREncodeResult *GuiGetBlueWalletBtcData(void) { uint8_t mfp[4] = {0}; @@ -397,7 +397,7 @@ UREncodeResult *GuiGetKeplrDataByIndex(uint32_t index) UREncodeResult *GuiGetLeapData() { - #define CHAIN_AMOUNT 4 +#define CHAIN_AMOUNT 4 uint8_t mfp[4] = {0}; GetMasterFingerPrint(mfp); PtrT_CSliceFFI_KeplrAccount publicKeys = SRAM_MALLOC(sizeof(CSliceFFI_KeplrAccount)); diff --git a/src/ui/wallet/gui_wallet.h b/src/ui/gui_wallet/btc_only/gui_wallet.h similarity index 100% rename from src/ui/wallet/gui_wallet.h rename to src/ui/gui_wallet/btc_only/gui_wallet.h diff --git a/src/ui/wallet/gui_qr_code.c b/src/ui/gui_wallet/gui_qr_code.c similarity index 100% rename from src/ui/wallet/gui_qr_code.c rename to src/ui/gui_wallet/gui_qr_code.c diff --git a/src/ui/wallet/gui_qr_code.h b/src/ui/gui_wallet/gui_qr_code.h similarity index 100% rename from src/ui/wallet/gui_qr_code.h rename to src/ui/gui_wallet/gui_qr_code.h diff --git a/src/ui/gui_wallet/multi/gui_wallet.c b/src/ui/gui_wallet/multi/gui_wallet.c new file mode 100644 index 000000000..b0a684f2d --- /dev/null +++ b/src/ui/gui_wallet/multi/gui_wallet.c @@ -0,0 +1,708 @@ +#include "stdio.h" +#include "gui_wallet.h" +#include "keystore.h" +#include "account_public_info.h" +#include "gui_connect_wallet_widgets.h" +#include "version.h" +#include "user_memory.h" +#include "gui_chain.h" +#include "presetting.h" +#include "version.h" + +static UREncodeResult *g_urEncode = NULL; + +UREncodeResult *GuiGetBlueWalletBtcData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[3]; + public_keys->data = keys; + public_keys->size = 3; + keys[0].path = "m/84'/0'/0'"; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_NATIVE_SEGWIT); + keys[1].path = "m/49'/0'/0'"; + keys[1].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC); + keys[2].path = "m/44'/0'/0'"; + keys[2].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_LEGACY); + UREncodeResult *urencode = get_connect_blue_wallet_ur(mfp, sizeof(mfp), public_keys); + CHECK_CHAIN_PRINT(urencode); + return urencode; +} + +UREncodeResult *GuiGetSparrowWalletBtcData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[4]; + public_keys->data = keys; + public_keys->size = 4; + keys[0].path = "m/84'/0'/0'"; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_NATIVE_SEGWIT); + keys[1].path = "m/49'/0'/0'"; + keys[1].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC); + keys[2].path = "m/44'/0'/0'"; + keys[2].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_LEGACY); + keys[3].path = "m/86'/0'/0'"; + keys[3].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_TAPROOT); + UREncodeResult *urencode = get_connect_sparrow_wallet_ur(mfp, sizeof(mfp), public_keys); + CHECK_CHAIN_PRINT(urencode); + return urencode; +} + +UREncodeResult *GuiGetSpecterWalletBtcData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[2]; + public_keys->data = keys; + public_keys->size = 2; + keys[0].path = "m/84'/0'/0'"; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_NATIVE_SEGWIT); + keys[1].path = "m/49'/0'/0'"; + keys[1].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC); + UREncodeResult *urencode = get_connect_specter_wallet_ur(mfp, sizeof(mfp), public_keys); + CHECK_CHAIN_PRINT(urencode); + return urencode; +} + +typedef UREncodeResult *MetamaskUrGetter(PtrBytes master_fingerprint, uint32_t master_fingerprint_length, enum ETHAccountType account_type, PtrT_CSliceFFI_ExtendedPublicKey public_keys); + +static UREncodeResult *get_unlimited_connect_metamask_ur(PtrBytes master_fingerprint, uint32_t master_fingerprint_length, enum ETHAccountType account_type, PtrT_CSliceFFI_ExtendedPublicKey public_keys) +{ + return get_connect_metamask_ur_unlimited(master_fingerprint, master_fingerprint_length, account_type, public_keys); +} + +static UREncodeResult *BasicGetMetamaskDataForAccountType(ETHAccountType accountType, MetamaskUrGetter func) +{ + if (func == NULL) { + return NULL; + } + + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + if (public_keys == NULL) { + return NULL; + } + + ExtendedPublicKey keys[10] = {0}; + public_keys->data = keys; + + switch (accountType) { + case Bip44Standard: + public_keys->size = 1; + keys[0].path = ""; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_ETH_BIP44_STANDARD); + break; + case LedgerLive: + public_keys->size = 10; + for (int i = XPUB_TYPE_ETH_LEDGER_LIVE_0; i <= XPUB_TYPE_ETH_LEDGER_LIVE_9; i++) { + keys[i - XPUB_TYPE_ETH_LEDGER_LIVE_0].path = ""; + keys[i - XPUB_TYPE_ETH_LEDGER_LIVE_0].xpub = GetCurrentAccountPublicKey(i); + } + break; + case LedgerLegacy: + public_keys->size = 1; + keys[0].path = ""; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_ETH_LEDGER_LEGACY); + break; + default: + SRAM_FREE(public_keys); + return NULL; + } + + g_urEncode = func(mfp, sizeof(mfp), accountType, public_keys); + if (g_urEncode == NULL) { + SRAM_FREE(public_keys); + return NULL; + } + + SRAM_FREE(public_keys); + return g_urEncode; +} +// copy from gui_btc, need to use real data +UREncodeResult *GetMetamaskDataForAccountType(ETHAccountType accountType) +{ + return BasicGetMetamaskDataForAccountType(accountType, get_connect_metamask_ur); +} + +UREncodeResult *GetUnlimitedMetamaskDataForAccountType(ETHAccountType accountType) +{ + return BasicGetMetamaskDataForAccountType(accountType, get_unlimited_connect_metamask_ur); +} + +UREncodeResult *GuiGetMetamaskData(void) +{ + ETHAccountType accountType = GetMetamaskAccountType(); + return GetMetamaskDataForAccountType(accountType); +} + +UREncodeResult *GuiGetImTokenData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + g_urEncode = get_connect_imtoken_ur(mfp, sizeof(mfp), GetCurrentAccountPublicKey(XPUB_TYPE_ETH_BIP44_STANDARD), GetWalletName()); + CHECK_CHAIN_PRINT(g_urEncode); + return g_urEncode; +} + +UREncodeResult *GuiGetArConnectData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + char *arXpub = GetCurrentAccountPublicKey(XPUB_TYPE_ARWEAVE); + if (arXpub == NULL || strlen(arXpub) != 1024) { + GuiSetupArConnectWallet(); + arXpub = GetCurrentAccountPublicKey(XPUB_TYPE_ARWEAVE); + ClearSecretCache(); + } + ASSERT(arXpub != NULL); + g_urEncode = get_connect_arconnect_wallet_ur_from_xpub(mfp, sizeof(mfp), arXpub); + printf("\ng_urEncode: %s\n", g_urEncode->data); + CHECK_CHAIN_PRINT(g_urEncode); + return g_urEncode; +} + +UREncodeResult *GuiGetNightlyDataByCoin(GuiChainCoinType coin) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey publicKeys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[10]; + publicKeys->data = keys; + publicKeys->size = 10; + int16_t coinType = 0; + int16_t xpubBaseIndex = 0; + switch (coin) { + case CHAIN_SUI: + coinType = 784; + xpubBaseIndex = XPUB_TYPE_SUI_0; + break; + default: + printf("invalid coin type\r\n"); + return NULL; + } + for (uint8_t i = 0; i < 10; i++) { + keys[i].path = SRAM_MALLOC(BUFFER_SIZE_32); + snprintf_s(keys[i].path, BUFFER_SIZE_32, "m/44'/%u'/%u'/0'/0'", coinType, i); + keys[i].xpub = GetCurrentAccountPublicKey(xpubBaseIndex + i); + } + g_urEncode = get_connect_sui_wallet_ur(mfp, sizeof(mfp), publicKeys); + CHECK_CHAIN_PRINT(g_urEncode); + for (uint8_t i = 0; i < 10; i++) { + SRAM_FREE(keys[i].path); + } + SRAM_FREE(publicKeys); + return g_urEncode; +} + +UREncodeResult *GuiGetFewchaDataByCoin(GuiChainCoinType coin) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey publicKeys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[10]; + publicKeys->data = keys; + publicKeys->size = 10; + int16_t coinType = 0; + int16_t xpubBaseIndex = 0; + switch (coin) { + case CHAIN_SUI: + coinType = 784; + xpubBaseIndex = XPUB_TYPE_SUI_0; + break; + case CHAIN_APT: + coinType = 637; + xpubBaseIndex = XPUB_TYPE_APT_0; + break; + default: + printf("invalid coin type\r\n"); + return NULL; + } + for (uint8_t i = 0; i < 10; i++) { + keys[i].path = SRAM_MALLOC(BUFFER_SIZE_32); + snprintf_s(keys[i].path, BUFFER_SIZE_32, "m/44'/%u'/%u'/0'/0'", coinType, i); + keys[i].xpub = GetCurrentAccountPublicKey(xpubBaseIndex + i); + } + if (coin == CHAIN_SUI) { + g_urEncode = get_connect_sui_wallet_ur(mfp, sizeof(mfp), publicKeys); + } else { + g_urEncode = get_connect_aptos_wallet_ur(mfp, sizeof(mfp), publicKeys); + } + CHECK_CHAIN_PRINT(g_urEncode); + for (uint8_t i = 0; i < 10; i++) { + SRAM_FREE(keys[i].path); + } + SRAM_FREE(publicKeys); + return g_urEncode; +} + +UREncodeResult *GuiGetPetraData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey publicKeys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[10]; + publicKeys->data = keys; + publicKeys->size = 10; + for (uint8_t i = 0; i < 10; i++) { + keys[i].path = SRAM_MALLOC(BUFFER_SIZE_32); + snprintf_s(keys[i].path, BUFFER_SIZE_32, "m/44'/637'/%u'/0'/0'", i); + keys[i].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_APT_0 + i); + } + g_urEncode = get_connect_aptos_wallet_ur(mfp, sizeof(mfp), publicKeys); + CHECK_CHAIN_PRINT(g_urEncode); + for (uint8_t i = 0; i < 10; i++) { + SRAM_FREE(keys[i].path); + } + SRAM_FREE(publicKeys); + return g_urEncode; +} + +UREncodeResult *GuiGetADADataByIndex(char *walletName) +{ + uint32_t index = GetConnectWalletAccountIndex(walletName); + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + char* xpub = GetCurrentAccountPublicKey(GetAdaXPubTypeByIndexAndDerivationType( + GetConnectWalletPathIndex(walletName), + index)); + char path[BUFFER_SIZE_32] = {0}; + sprintf(path, "1852'/1815'/%u'", index); + ExtendedPublicKey xpubs[1]; + xpubs[0].path = path; + xpubs[0].xpub = xpub; + CSliceFFI_ExtendedPublicKey keys; + keys.data = xpubs; + keys.size = 1; + char firmwareVersion[12]; + GetSoftWareVersionNumber(firmwareVersion); + return generate_key_derivation_ur(mfp, 4, &keys, firmwareVersion); +} +UREncodeResult *GuiGetKeplrDataByIndex(uint32_t index) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_KeplrAccount publicKeys = SRAM_MALLOC(sizeof(CSliceFFI_KeplrAccount)); + GuiChainCoinType chains[8] = { + CHAIN_ATOM, + CHAIN_SCRT, + CHAIN_CRO, + CHAIN_IOV, + CHAIN_BLD, + CHAIN_KAVA, + CHAIN_EVMOS, + CHAIN_LUNA, + }; + KeplrAccount keys[8]; + publicKeys->data = keys; + publicKeys->size = 8; + + for (uint8_t i = 0; i < 8; i++) { + const CosmosChain_t *chain = GuiGetCosmosChain(chains[i]); + keys[i].xpub = GetCurrentAccountPublicKey(chain->xpubType); + keys[i].name = "Account-1"; + keys[i].path = SRAM_MALLOC(BUFFER_SIZE_32); + snprintf_s(keys[i].path, BUFFER_SIZE_32, "M/44'/%u'/0'/0/%u", chain->coinType, index); + } + + g_urEncode = get_connect_keplr_wallet_ur(mfp, sizeof(mfp), publicKeys); + CHECK_CHAIN_PRINT(g_urEncode); + for (uint8_t i = 0; i < 8; i++) { + SRAM_FREE(keys[i].path); + } + SRAM_FREE(publicKeys); + return g_urEncode; +} + +UREncodeResult *GuiGetLeapData() +{ +#define CHAIN_AMOUNT 4 + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_KeplrAccount publicKeys = SRAM_MALLOC(sizeof(CSliceFFI_KeplrAccount)); + GuiChainCoinType chains[CHAIN_AMOUNT] = { + CHAIN_ATOM, + CHAIN_EVMOS, + CHAIN_RUNE, + CHAIN_SCRT + }; + KeplrAccount keys[CHAIN_AMOUNT]; + publicKeys->data = keys; + publicKeys->size = CHAIN_AMOUNT; + + for (uint8_t i = 0; i < CHAIN_AMOUNT; i++) { + const CosmosChain_t *chain = GuiGetCosmosChain(chains[i]); + keys[i].xpub = GetCurrentAccountPublicKey(chain->xpubType); + keys[i].name = "Account-1"; + keys[i].path = SRAM_MALLOC(BUFFER_SIZE_32); + snprintf_s(keys[i].path, BUFFER_SIZE_32, "M/44'/%u'/0'/0/0", chain->coinType); + } + + g_urEncode = get_connect_keplr_wallet_ur(mfp, sizeof(mfp), publicKeys); + CHECK_CHAIN_PRINT(g_urEncode); + for (uint8_t i = 0; i < CHAIN_AMOUNT; i++) { + SRAM_FREE(keys[i].path); + } + SRAM_FREE(publicKeys); + return g_urEncode; +} + +UREncodeResult *GuiGetXrpToolkitDataByIndex(uint16_t index) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + char *xpub = GetCurrentAccountPublicKey(XPUB_TYPE_XRP); + char *rootPath = "m/44'/144'/0'"; + char hdPath[BUFFER_SIZE_32] = {0}; + snprintf_s(hdPath, BUFFER_SIZE_32, "%s/0/%u", rootPath, index); + g_urEncode = get_connect_xrp_toolkit_ur(hdPath, xpub, rootPath); + CHECK_CHAIN_PRINT(g_urEncode); + return g_urEncode; +} + +UREncodeResult *GuiGetKeystoneWalletData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + // btc 3 + // + eth 1 + // + bch 1 + // + dash 1 + // + dot 1 + // + ltc 1 + // + trx 1 + // + xrp 1 + + // total xpub = 9 + uint8_t XPUB_AMMOUNT = 9; + ExtendedPublicKey keys[XPUB_AMMOUNT]; + public_keys->data = keys; + public_keys->size = XPUB_AMMOUNT; + + keys[0].path = "m/44'/0'/0'"; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_LEGACY); + + keys[1].path = "m/49'/0'/0'"; + keys[1].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC); + + keys[2].path = "m/84'/0'/0'"; + keys[2].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_NATIVE_SEGWIT); + + keys[3].path = GetXPubPath(XPUB_TYPE_BCH); + keys[3].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BCH); + + keys[4].path = GetXPubPath(XPUB_TYPE_DASH); + keys[4].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_DASH); + + keys[5].path = GetXPubPath(XPUB_TYPE_LTC); + keys[5].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_LTC); + + keys[6].path = GetXPubPath(XPUB_TYPE_TRX); + keys[6].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_TRX); + + keys[7].path = GetXPubPath(XPUB_TYPE_XRP); + keys[7].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_XRP); + + keys[8].path = GetXPubPath(XPUB_TYPE_ETH_BIP44_STANDARD); + keys[8].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_ETH_BIP44_STANDARD); + + char serialNumber[256]; + GetSerialNumber(serialNumber); + char firmwareVersion[12]; + GetSoftWareVersionNumber(firmwareVersion); + g_urEncode = get_keystone_wallet_ur(mfp, sizeof(mfp), serialNumber, public_keys, "Keystone 3 Pro", firmwareVersion); + + CHECK_CHAIN_PRINT(g_urEncode); + SRAM_FREE(public_keys); + return g_urEncode; +} + +UREncodeResult *GuiGetBitgetWalletData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + // btc 4 + // + eth 10 + ExtendedPublicKey keys[15]; + public_keys->data = keys; + public_keys->size = 15; + for (int i = XPUB_TYPE_ETH_LEDGER_LIVE_0; i <= XPUB_TYPE_ETH_LEDGER_LIVE_9; i++) { + keys[i - XPUB_TYPE_ETH_LEDGER_LIVE_0].path = SRAM_MALLOC(BUFFER_SIZE_64); + snprintf_s(keys[i - XPUB_TYPE_ETH_LEDGER_LIVE_0].path, BUFFER_SIZE_64, "m/44'/60'/%d'", i - XPUB_TYPE_ETH_LEDGER_LIVE_0); + keys[i - XPUB_TYPE_ETH_LEDGER_LIVE_0].xpub = GetCurrentAccountPublicKey(i); + } + + keys[10].path = "m/44'/0'/0'"; + keys[10].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_LEGACY); + + keys[11].path = "m/49'/0'/0'"; + keys[11].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC); + + keys[12].path = "m/84'/0'/0'"; + keys[12].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_NATIVE_SEGWIT); + + keys[13].path = "m/86'/0'/0'"; + keys[13].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_TAPROOT); + + keys[14].path = GetXPubPath(XPUB_TYPE_TON_BIP39); + keys[14].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_TON_BIP39); + + char serialNumber[256]; + GetSerialNumber(serialNumber); + char firmwareVersion[12]; + GetSoftWareVersionNumber(firmwareVersion); + g_urEncode = get_bitget_wallet_ur(mfp, sizeof(mfp), serialNumber, public_keys, "Keystone 3 Pro", firmwareVersion); + CHECK_CHAIN_PRINT(g_urEncode); + SRAM_FREE(public_keys); + return g_urEncode; +} + +UREncodeResult *GuiGetOkxWalletData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + // btc 4 + // + eth 10 + // + trx 1 + // + ltc 1 + // + dash 1 + // + bch 1 + ExtendedPublicKey keys[18]; + public_keys->data = keys; + public_keys->size = 18; + for (int i = XPUB_TYPE_ETH_LEDGER_LIVE_0; i <= XPUB_TYPE_ETH_LEDGER_LIVE_9; i++) { + keys[i - XPUB_TYPE_ETH_LEDGER_LIVE_0].path = SRAM_MALLOC(BUFFER_SIZE_64); + snprintf_s(keys[i - XPUB_TYPE_ETH_LEDGER_LIVE_0].path, BUFFER_SIZE_64, "m/44'/60'/%d'", i - XPUB_TYPE_ETH_LEDGER_LIVE_0); + keys[i - XPUB_TYPE_ETH_LEDGER_LIVE_0].xpub = GetCurrentAccountPublicKey(i); + } + + keys[10].path = "m/44'/0'/0'"; + keys[10].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_LEGACY); + + keys[11].path = "m/49'/0'/0'"; + keys[11].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC); + + keys[12].path = "m/84'/0'/0'"; + keys[12].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_NATIVE_SEGWIT); + + keys[13].path = GetXPubPath(XPUB_TYPE_TRX); + keys[13].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_TRX); + + keys[14].path = GetXPubPath(XPUB_TYPE_LTC); + keys[14].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_LTC); + + keys[15].path = GetXPubPath(XPUB_TYPE_DASH); + keys[15].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_DASH); + + keys[16].path = GetXPubPath(XPUB_TYPE_BCH); + keys[16].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BCH); + + keys[17].path = "m/86'/0'/0'"; + keys[17].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_TAPROOT); + + char serialNumber[256]; + GetSerialNumber(serialNumber); + char firmwareVersion[12]; + GetSoftWareVersionNumber(firmwareVersion); + g_urEncode = get_okx_wallet_ur(mfp, sizeof(mfp), serialNumber, public_keys, "Keystone 3 Pro", firmwareVersion); + CHECK_CHAIN_PRINT(g_urEncode); + SRAM_FREE(public_keys); + return g_urEncode; +} + +UREncodeResult *GuiGetSolflareData(void) +{ + SOLAccountType accountType = GetSolflareAccountType(); + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[10]; + public_keys->data = keys; + + if (accountType == SOLBip44) { + public_keys->size = 10; + for (int i = XPUB_TYPE_SOL_BIP44_0; i <= XPUB_TYPE_SOL_BIP44_9; i++) { + char *path = SRAM_MALLOC(BUFFER_SIZE_32); + snprintf_s(path, BUFFER_SIZE_32, "m/44'/501'/%d'", i - XPUB_TYPE_SOL_BIP44_0); + keys[i - XPUB_TYPE_SOL_BIP44_0].path = path; + keys[i - XPUB_TYPE_SOL_BIP44_0].xpub = GetCurrentAccountPublicKey(i); + } + } else if (accountType == SOLBip44ROOT) { + public_keys->size = 1; + char *path = SRAM_MALLOC(sizeof(char) * 32); + snprintf_s(path, BUFFER_SIZE_32, "m/44'/501'"); + keys[0].path = path; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_SOL_BIP44_ROOT); + } else if (accountType == SOLBip44Change) { + public_keys->size = 10; + for (int i = XPUB_TYPE_SOL_BIP44_CHANGE_0; i <= XPUB_TYPE_SOL_BIP44_CHANGE_9; i++) { + char *path = SRAM_MALLOC(sizeof(char) * 32); + snprintf_s(path, BUFFER_SIZE_32, "m/44'/501'/%d'/0'", i - XPUB_TYPE_SOL_BIP44_CHANGE_0); + keys[i - XPUB_TYPE_SOL_BIP44_CHANGE_0].path = path; + keys[i - XPUB_TYPE_SOL_BIP44_CHANGE_0].xpub = GetCurrentAccountPublicKey(i); + } + } + g_urEncode = get_connect_solana_wallet_ur(mfp, sizeof(mfp), public_keys); + CHECK_CHAIN_PRINT(g_urEncode); + for (int i = 0; i < public_keys->size; i++) { + SRAM_FREE(public_keys->data[i].path); + } + SRAM_FREE(public_keys); + return g_urEncode; +} + +UREncodeResult *GuiGetHeliumData(void) +{ + SOLAccountType accountType = GetHeliumAccountType(); + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[10]; + public_keys->data = keys; + + if (accountType == SOLBip44) { + public_keys->size = 10; + for (int i = XPUB_TYPE_SOL_BIP44_0; i <= XPUB_TYPE_SOL_BIP44_9; i++) { + char *path = SRAM_MALLOC(BUFFER_SIZE_32); + snprintf_s(path, BUFFER_SIZE_32, "m/44'/501'/%d'", i - XPUB_TYPE_SOL_BIP44_0); + keys[i - XPUB_TYPE_SOL_BIP44_0].path = path; + keys[i - XPUB_TYPE_SOL_BIP44_0].xpub = GetCurrentAccountPublicKey(i); + } + } else if (accountType == SOLBip44ROOT) { + public_keys->size = 1; + char *path = SRAM_MALLOC(sizeof(char) * 32); + snprintf_s(path, BUFFER_SIZE_32, "m/44'/501'"); + keys[0].path = path; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_SOL_BIP44_ROOT); + } else if (accountType == SOLBip44Change) { + public_keys->size = 10; + for (int i = XPUB_TYPE_SOL_BIP44_CHANGE_0; i <= XPUB_TYPE_SOL_BIP44_CHANGE_9; i++) { + char *path = SRAM_MALLOC(sizeof(char) * 32); + snprintf_s(path, BUFFER_SIZE_32, "m/44'/501'/%d'/0'", i - XPUB_TYPE_SOL_BIP44_CHANGE_0); + keys[i - XPUB_TYPE_SOL_BIP44_CHANGE_0].path = path; + keys[i - XPUB_TYPE_SOL_BIP44_CHANGE_0].xpub = GetCurrentAccountPublicKey(i); + } + } + g_urEncode = get_connect_solana_wallet_ur(mfp, sizeof(mfp), public_keys); + CHECK_CHAIN_PRINT(g_urEncode); + for (int i = 0; i < public_keys->size; i++) { + SRAM_FREE(public_keys->data[i].path); + } + SRAM_FREE(public_keys); + return g_urEncode; +} + +UREncodeResult *GuiGetXBullData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[5]; + public_keys->data = keys; + public_keys->size = 5; + for (int i = XPUB_TYPE_STELLAR_0; i <= XPUB_TYPE_STELLAR_4; i++) { + char *path = SRAM_MALLOC(BUFFER_SIZE_32); + snprintf_s(path, BUFFER_SIZE_32, "m/44'/148'/%d'", i - XPUB_TYPE_STELLAR_0); + keys[i - XPUB_TYPE_STELLAR_0].path = path; + keys[i - XPUB_TYPE_STELLAR_0].xpub = GetCurrentAccountPublicKey(i); + } + g_urEncode = get_connect_xbull_wallet_ur(mfp, sizeof(mfp), public_keys); + CHECK_CHAIN_PRINT(g_urEncode); + for (int i = 0; i < public_keys->size; i++) { + SRAM_FREE(public_keys->data[i].path); + } + SRAM_FREE(public_keys); + return g_urEncode; +} + +UREncodeResult *GuiGetBackpackData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[31]; + public_keys->data = keys; + public_keys->size = 31; + + uint8_t count = 0; + // SOLBip44ROOT + char *solPath = SRAM_MALLOC(sizeof(char) * 32); + snprintf_s(solPath, BUFFER_SIZE_32, "m/44'/501'"); + keys[count].path = solPath; + keys[count].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_SOL_BIP44_ROOT); + count++; + + // SOLBip44 + for (uint8_t i = XPUB_TYPE_SOL_BIP44_0; i <= XPUB_TYPE_SOL_BIP44_9; i++, count++) { + char *path = SRAM_MALLOC(BUFFER_SIZE_32); + snprintf_s(path, BUFFER_SIZE_32, "m/44'/501'/%d'", i - XPUB_TYPE_SOL_BIP44_0); + keys[count].path = path; + keys[count].xpub = GetCurrentAccountPublicKey(i); + } + + // SOLBip44Change + for (uint8_t i = XPUB_TYPE_SOL_BIP44_CHANGE_0; i <= XPUB_TYPE_SOL_BIP44_CHANGE_9; i++, count++) { + char *path = SRAM_MALLOC(sizeof(char) * 32); + snprintf_s(path, BUFFER_SIZE_32, "m/44'/501'/%d'/0'", i - XPUB_TYPE_SOL_BIP44_CHANGE_0); + keys[count].path = path; + keys[count].xpub = GetCurrentAccountPublicKey(i); + } + + // ETH - Bip44Standard + LedgerLive + for (uint8_t i = XPUB_TYPE_ETH_LEDGER_LIVE_0; i <= XPUB_TYPE_ETH_LEDGER_LIVE_9; i++, count++) { + char *path = SRAM_MALLOC(sizeof(char) * 32); + snprintf_s(path, BUFFER_SIZE_32, "m/44'/60'/%d'", i - XPUB_TYPE_ETH_LEDGER_LIVE_0); + keys[count].path = path; + keys[count].xpub = GetCurrentAccountPublicKey(i); + } + + g_urEncode = get_backpack_wallet_ur(mfp, sizeof(mfp), public_keys); + + CHECK_CHAIN_PRINT(g_urEncode); + for (int i = 0; i < public_keys->size; i++) { + SRAM_FREE(public_keys->data[i].path); + } + SRAM_FREE(public_keys); + return g_urEncode; +} + +UREncodeResult *GuiGetThorWalletBtcData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + + PtrT_CSliceFFI_ExtendedPublicKey public_keys = + SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[5]; + public_keys->data = keys; + public_keys->size = 5; + keys[0].path = "m/84'/0'/0'"; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_NATIVE_SEGWIT); + keys[1].path = "m/49'/0'/0'"; + keys[1].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC); + keys[2].path = "m/44'/0'/0'"; + keys[2].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_LEGACY); + keys[3].path = "m/44'/931'/0'"; + keys[3].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_THOR); + keys[4].path = "m/44'/60'/0'"; + keys[4].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_ETH_BIP44_STANDARD); + + char serialNumber[256]; + GetSerialNumber(serialNumber); + char firmwareVersion[12]; + GetSoftWareVersionNumber(firmwareVersion); + UREncodeResult *urencode = + get_connect_thor_wallet_ur(mfp, sizeof(mfp), serialNumber, public_keys, + "Keystone 3 Pro", firmwareVersion); + CHECK_CHAIN_PRINT(urencode); + return urencode; +} \ No newline at end of file diff --git a/src/ui/gui_wallet/multi/gui_wallet.h b/src/ui/gui_wallet/multi/gui_wallet.h new file mode 100644 index 000000000..61dbe9c06 --- /dev/null +++ b/src/ui/gui_wallet/multi/gui_wallet.h @@ -0,0 +1,33 @@ +#ifndef GUI_WALLET_H +#define GUI_WALLET_H + +#include "rust.h" +#include "gui_chain.h" +#include "rsa.h" +#include "gui_attention_hintbox.h" + +UREncodeResult *GuiGetBlueWalletBtcData(void); +UREncodeResult *GuiGetSparrowWalletBtcData(void); +UREncodeResult *GuiGetSpecterWalletBtcData(void); +UREncodeResult *GuiGetKeplrDataByIndex(uint32_t index); +UREncodeResult *GuiGetLeapData(); +UREncodeResult *GuiGetArConnectData(void); +UREncodeResult *GuiGetCompanionAppData(void); +UREncodeResult *GuiGetOkxWalletData(void); +UREncodeResult *GuiGetBitgetWalletData(void); +UREncodeResult *GetMetamaskDataForAccountType(ETHAccountType accountType); +UREncodeResult *GetUnlimitedMetamaskDataForAccountType(ETHAccountType accountType); +UREncodeResult *GuiGetMetamaskData(void); +UREncodeResult *GuiGetFewchaDataByCoin(GuiChainCoinType coin); +UREncodeResult *GuiGetNightlyDataByCoin(GuiChainCoinType coin); +UREncodeResult *GuiGetPetraData(void); +UREncodeResult *GuiGetSolflareData(void); +UREncodeResult *GuiGetHeliumData(void); +UREncodeResult *GuiGetXBullData(void); +UREncodeResult *GuiGetBackpackData(void); +UREncodeResult *GuiGetXrpToolkitDataByIndex(uint16_t index); +UREncodeResult *GuiGetADADataByIndex(char *walletName); +UREncodeResult *GuiGetImTokenData(void); +UREncodeResult *GuiGetKeystoneWalletData(void); +UREncodeResult *GuiGetThorWalletBtcData(void); +#endif diff --git a/src/ui/gui_widgets/btc_only/gui_btc_wallet_profile_widgets.c b/src/ui/gui_widgets/btc_only/gui_btc_wallet_profile_widgets.c index 002247a21..54a672295 100644 --- a/src/ui/gui_widgets/btc_only/gui_btc_wallet_profile_widgets.c +++ b/src/ui/gui_widgets/btc_only/gui_btc_wallet_profile_widgets.c @@ -6,7 +6,7 @@ #include "gui_status_bar.h" #include "gui_page.h" #include "gui_button.h" -#include "gui_btc_home_widgets.h" +#include "gui_home_widgets.h" #include "gui_hintbox.h" #include "gui_api.h" #include "multi_sig_wallet_manager.h" diff --git a/src/ui/gui_widgets/btc_only/gui_btc_home_widgets.c b/src/ui/gui_widgets/btc_only/gui_home_widgets.c similarity index 99% rename from src/ui/gui_widgets/btc_only/gui_btc_home_widgets.c rename to src/ui/gui_widgets/btc_only/gui_home_widgets.c index fe8828504..3fbafbdfc 100644 --- a/src/ui/gui_widgets/btc_only/gui_btc_home_widgets.c +++ b/src/ui/gui_widgets/btc_only/gui_home_widgets.c @@ -19,7 +19,7 @@ #include "gui_page.h" #include "account_manager.h" #include "log_print.h" -#include "gui_btc_home_widgets.h" +#include "gui_home_widgets.h" #include "gui_multisig_read_sdcard_widgets.h" static lv_obj_t *g_manageWalletLabel = NULL; diff --git a/src/ui/gui_widgets/btc_only/gui_btc_home_widgets.h b/src/ui/gui_widgets/btc_only/gui_home_widgets.h similarity index 91% rename from src/ui/gui_widgets/btc_only/gui_btc_home_widgets.h rename to src/ui/gui_widgets/btc_only/gui_home_widgets.h index 952ea5d4f..756f145b0 100644 --- a/src/ui/gui_widgets/btc_only/gui_btc_home_widgets.h +++ b/src/ui/gui_widgets/btc_only/gui_home_widgets.h @@ -1,6 +1,5 @@ -#ifdef BTC_ONLY -#ifndef _GUI_BTC_HOME_WIDGETS_H -#define _GUI_BTC_HOME_WIDGETS_H +#ifndef _GUI_HOME_WIDGETS_H +#define _GUI_HOME_WIDGETS_H #include "gui_model.h" #include "lvgl.h" @@ -51,5 +50,4 @@ void SetCurrentWalletIndex(CURRENT_WALLET_INDEX_ENUM walletIndex); CURRENT_WALLET_INDEX_ENUM GetCurrentWalletIndex(void); const ChainCoinCard_t* GetCoinCardByIndex(HOME_WALLET_CARD_ENUM index); void GuiHomeDeInit(void); -#endif /* _GUI_BTC_HOME_WIDGETS_H */ -#endif \ No newline at end of file +#endif /* _GUI_HOME_WIDGETS_H */ \ No newline at end of file diff --git a/src/ui/gui_widgets/btc_only/multi_sig/gui_manage_multisig_wallet_widgets.c b/src/ui/gui_widgets/btc_only/multi_sig/gui_manage_multisig_wallet_widgets.c index 2245bb464..d998dd206 100644 --- a/src/ui/gui_widgets/btc_only/multi_sig/gui_manage_multisig_wallet_widgets.c +++ b/src/ui/gui_widgets/btc_only/multi_sig/gui_manage_multisig_wallet_widgets.c @@ -18,7 +18,7 @@ #include "multi_sig_wallet_manager.h" #include "account_public_info.h" #include "gui_export_pubkey_widgets.h" -#include "gui_btc_home_widgets.h" +#include "gui_home_widgets.h" #include "gui_manage_multisig_wallet_widgets.h" #include "gui_import_multisig_wallet_info_widgets.h" #include "gui_multisig_wallet_export_widgets.h" diff --git a/src/ui/gui_widgets/btc_only/multi_sig/gui_manage_multisig_wallet_widgets.h b/src/ui/gui_widgets/btc_only/multi_sig/gui_manage_multisig_wallet_widgets.h index d7eab2c5e..5463bc2fb 100644 --- a/src/ui/gui_widgets/btc_only/multi_sig/gui_manage_multisig_wallet_widgets.h +++ b/src/ui/gui_widgets/btc_only/multi_sig/gui_manage_multisig_wallet_widgets.h @@ -1,7 +1,7 @@ #ifndef _GUI_MANAGE_MULTI_SIG_WIDGETS_H #define _GUI_MANAGE_MULTI_SIG_WIDGETS_H -#include "gui_btc_home_widgets.h" +#include "gui_home_widgets.h" void GuiManageMultisigWalletInit(CURRENT_WALLET_INDEX_ENUM index); void GuiManageMultisigWalletDeInit(void); diff --git a/src/ui/gui_widgets/general/gui_home_widgets.h b/src/ui/gui_widgets/general/gui_home_widgets.h deleted file mode 100644 index 91d0ad7e5..000000000 --- a/src/ui/gui_widgets/general/gui_home_widgets.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef BTC_ONLY -#ifndef _GUI_HOME_WIDGETS_H -#define _GUI_HOME_WIDGETS_H - -#include "gui_model.h" -#include "lvgl.h" -#include "gui_keyboard_hintbox.h" -#include "gui_attention_hintbox.h" -#ifdef COMPILE_SIMULATOR -#include "gui_pending_hintbox.h" -#endif - -typedef enum { - HOME_WALLET_CARD_BTC, - HOME_WALLET_CARD_ETH, - HOME_WALLET_CARD_ZEC, - HOME_WALLET_CARD_SOL, - HOME_WALLET_CARD_BNB, - HOME_WALLET_CARD_HNT, - HOME_WALLET_CARD_XRP, - HOME_WALLET_CARD_ADA, - HOME_WALLET_CARD_TON, - HOME_WALLET_CARD_DOT, - HOME_WALLET_CARD_TRX, - HOME_WALLET_CARD_LTC, - HOME_WALLET_CARD_BCH, - HOME_WALLET_CARD_APT, - HOME_WALLET_CARD_SUI, - HOME_WALLET_CARD_DASH, - HOME_WALLET_CARD_ARWEAVE, - HOME_WALLET_CARD_XLM, - HOME_WALLET_CARD_COSMOS, - HOME_WALLET_CARD_TIA, - HOME_WALLET_CARD_NTRN, - HOME_WALLET_CARD_DYM, - HOME_WALLET_CARD_OSMO, - HOME_WALLET_CARD_INJ, - HOME_WALLET_CARD_ATOM, - HOME_WALLET_CARD_CRO, - HOME_WALLET_CARD_RUNE, - HOME_WALLET_CARD_KAVA, - HOME_WALLET_CARD_LUNC, - HOME_WALLET_CARD_AXL, - HOME_WALLET_CARD_LUNA, - HOME_WALLET_CARD_AKT, - HOME_WALLET_CARD_STRD, - HOME_WALLET_CARD_SCRT, - HOME_WALLET_CARD_BLD, - HOME_WALLET_CARD_CTK, - HOME_WALLET_CARD_EVMOS, - HOME_WALLET_CARD_STARS, - HOME_WALLET_CARD_XPRT, - HOME_WALLET_CARD_SOMM, - HOME_WALLET_CARD_JUNO, - HOME_WALLET_CARD_IRIS, - HOME_WALLET_CARD_DVPN, - HOME_WALLET_CARD_ROWAN, - HOME_WALLET_CARD_REGEN, - HOME_WALLET_CARD_BOOT, - HOME_WALLET_CARD_GRAV, - HOME_WALLET_CARD_IXO, - HOME_WALLET_CARD_NGM, - HOME_WALLET_CARD_IOV, - HOME_WALLET_CARD_UMEE, - HOME_WALLET_CARD_QCK, - HOME_WALLET_CARD_TGD, - HOME_WALLET_CARD_BUTT, // This represents the end of the array (the number of arrays) and needs to be placed at the end. -} HOME_WALLET_CARD_ENUM; - -typedef struct { - HOME_WALLET_CARD_ENUM index; - bool state; - const char *name; - bool enable; - lv_obj_t *checkBox; -} WalletState_t; - -typedef struct { - HOME_WALLET_CARD_ENUM index; - const char *coin; - const char *chain; - const lv_img_dsc_t *icon; -} ChainCoinCard_t; - -void GuiHomeRefresh(void); -void GuiHomeAreaInit(void); -void GuiHomeDisActive(void); -void GuiHomeSetWalletDesc(WalletDesc_t *wallet); -void GuiHomeRestart(void); -bool GuiHomePageIsTop(void); -void GuiHomePasswordErrorCount(void *param); -void GuiRemoveKeyboardWidget(void); -void RecalculateManageWalletState(void); -const ChainCoinCard_t* GetCoinCardByIndex(HOME_WALLET_CARD_ENUM index); -void GuiHomeDeInit(void); -void GuiShowRsaSetupasswordHintbox(void); -void GuiShowRsaInitializatioCompleteHintbox(void); -void ClearHomePageCurrentIndex(void); - -#endif /* _GUI_HOME_WIDGETS_H */ -#else -#include "gui_btc_home_widgets.h" -#endif - diff --git a/src/ui/gui_widgets/gui_connect_wallet_widgets.h b/src/ui/gui_widgets/gui_connect_wallet_widgets.h index 0b9675756..df60d6404 100644 --- a/src/ui/gui_widgets/gui_connect_wallet_widgets.h +++ b/src/ui/gui_widgets/gui_connect_wallet_widgets.h @@ -53,7 +53,6 @@ typedef enum { WALLET_LIST_SPARROW, WALLET_LIST_NUNCHUK, WALLET_LIST_UNISAT, - #endif WALLET_LIST_BUTT, } WALLET_LIST_INDEX_ENUM; diff --git a/src/ui/gui_widgets/gui_export_pubkey_widgets.c b/src/ui/gui_widgets/gui_export_pubkey_widgets.c index a14f1764f..e4d7308b3 100644 --- a/src/ui/gui_widgets/gui_export_pubkey_widgets.c +++ b/src/ui/gui_widgets/gui_export_pubkey_widgets.c @@ -7,13 +7,12 @@ #include "account_public_info.h" #include "assert.h" #include "gui_hintbox.h" -#include "btc_only/gui_btc_home_widgets.h" #include "sdcard_manager.h" #ifdef BTC_ONLY #include "gui_animating_qrcode.h" #include "keystore.h" -#include "gui_btc_home_widgets.h" +#include "gui_home_widgets.h" static lv_obj_t *g_noticeWindow = NULL; static char *g_xpubConfigName = NULL; #endif diff --git a/src/ui/gui_widgets/gui_utxo_receive_widgets.c b/src/ui/gui_widgets/gui_utxo_receive_widgets.c index 2402377da..959691b58 100644 --- a/src/ui/gui_widgets/gui_utxo_receive_widgets.c +++ b/src/ui/gui_widgets/gui_utxo_receive_widgets.c @@ -22,7 +22,7 @@ #include "user_memory.h" #ifdef BTC_ONLY -#include "gui_btc_home_widgets.h" +#include "gui_home_widgets.h" #include "multi_sig_wallet_manager.h" #include "gui_multisig_wallet_export_widgets.h" static MultiSigWallet *g_multiSigWallet = NULL; diff --git a/src/ui/gui_widgets/gui_wallet_tutorial_widgets.c b/src/ui/gui_widgets/gui_wallet_tutorial_widgets.c index 5394f4329..41c845dc3 100644 --- a/src/ui/gui_widgets/gui_wallet_tutorial_widgets.c +++ b/src/ui/gui_widgets/gui_wallet_tutorial_widgets.c @@ -9,7 +9,7 @@ #include "gui_qr_hintbox.h" #include "gui_page.h" #if BTC_ONLY -#include "gui_btc_home_widgets.h" +#include "gui_home_widgets.h" #endif typedef struct WalletTutorialItem { @@ -353,7 +353,7 @@ static void WalletTutorialsInit() g_tutorials[WALLET_LIST_ZASHI].items[0].qrTitle = _("connect_zashi_title"); g_tutorials[WALLET_LIST_ZASHI].items[0].qrUrl = _("connect_zashi_link"); - + #else g_tutorials[WALLET_LIST_BLUE].len = 1; diff --git a/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.h b/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.h new file mode 100644 index 000000000..5305ca8c3 --- /dev/null +++ b/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.h @@ -0,0 +1,17 @@ +#ifdef CYBERPUNK_VERSION +#ifndef _GUI_CYBERPUNK_HOME_WIDGETS_H +#define _GUI_CYBERPUNK_HOME_WIDGETS_H + +#define HOME_WIDGETS_SURPLUS_CARD_ENUM HOME_WALLET_CARD_ZEC + +#define HOME_WALLET_STATE_SURPLUS {HOME_WALLET_CARD_ZEC, false, "ZEC", true} + +#define HOME_WALLET_CARD_SURPLUS { \ + .index = HOME_WALLET_CARD_ZEC, \ + .coin = "ZEC", \ + .chain = "Zcash", \ + .icon = &coinZec, \ + } + +#endif /* _GUI_CYBERPUNK_HOME_WIDGETS_H */ +#endif \ No newline at end of file diff --git a/src/ui/gui_widgets/general/gui_connect_ada_widgets.c b/src/ui/gui_widgets/multi/general/gui_connect_ada_widgets.c similarity index 100% rename from src/ui/gui_widgets/general/gui_connect_ada_widgets.c rename to src/ui/gui_widgets/multi/general/gui_connect_ada_widgets.c diff --git a/src/ui/gui_widgets/general/gui_connect_ada_widgets.h b/src/ui/gui_widgets/multi/general/gui_connect_ada_widgets.h similarity index 100% rename from src/ui/gui_widgets/general/gui_connect_ada_widgets.h rename to src/ui/gui_widgets/multi/general/gui_connect_ada_widgets.h diff --git a/src/ui/gui_widgets/multi/general/gui_general_home_widgets.h b/src/ui/gui_widgets/multi/general/gui_general_home_widgets.h new file mode 100644 index 000000000..982a5914a --- /dev/null +++ b/src/ui/gui_widgets/multi/general/gui_general_home_widgets.h @@ -0,0 +1,420 @@ + #ifdef GENERAL_VERSION +#ifndef _GUI_GENERAL_HOME_WIDGETS_H +#define _GUI_GENERAL_HOME_WIDGETS_H + +#define HOME_WIDGETS_SURPLUS_CARD_ENUM HOME_WALLET_CARD_ETH, \ + HOME_WALLET_CARD_ZEC, \ + HOME_WALLET_CARD_SOL, \ + HOME_WALLET_CARD_BNB, \ + HOME_WALLET_CARD_HNT, \ + HOME_WALLET_CARD_XRP, \ + HOME_WALLET_CARD_ADA, \ + HOME_WALLET_CARD_TON, \ + HOME_WALLET_CARD_DOT, \ + HOME_WALLET_CARD_TRX, \ + HOME_WALLET_CARD_LTC, \ + HOME_WALLET_CARD_BCH, \ + HOME_WALLET_CARD_APT, \ + HOME_WALLET_CARD_SUI, \ + HOME_WALLET_CARD_DASH, \ + HOME_WALLET_CARD_ARWEAVE, \ + HOME_WALLET_CARD_XLM, \ + HOME_WALLET_CARD_COSMOS, \ + HOME_WALLET_CARD_TIA, \ + HOME_WALLET_CARD_NTRN, \ + HOME_WALLET_CARD_DYM, \ + HOME_WALLET_CARD_OSMO, \ + HOME_WALLET_CARD_INJ, \ + HOME_WALLET_CARD_ATOM, \ + HOME_WALLET_CARD_CRO, \ + HOME_WALLET_CARD_RUNE, \ + HOME_WALLET_CARD_KAVA, \ + HOME_WALLET_CARD_LUNC, \ + HOME_WALLET_CARD_AXL, \ + HOME_WALLET_CARD_LUNA, \ + HOME_WALLET_CARD_AKT, \ + HOME_WALLET_CARD_STRD, \ + HOME_WALLET_CARD_SCRT, \ + HOME_WALLET_CARD_BLD, \ + HOME_WALLET_CARD_CTK, \ + HOME_WALLET_CARD_EVMOS, \ + HOME_WALLET_CARD_STARS, \ + HOME_WALLET_CARD_XPRT, \ + HOME_WALLET_CARD_SOMM, \ + HOME_WALLET_CARD_JUNO, \ + HOME_WALLET_CARD_IRIS, \ + HOME_WALLET_CARD_DVPN, \ + HOME_WALLET_CARD_ROWAN, \ + HOME_WALLET_CARD_REGEN, \ + HOME_WALLET_CARD_BOOT, \ + HOME_WALLET_CARD_GRAV, \ + HOME_WALLET_CARD_IXO, \ + HOME_WALLET_CARD_NGM, \ + HOME_WALLET_CARD_IOV, \ + HOME_WALLET_CARD_UMEE, \ + HOME_WALLET_CARD_QCK, \ + HOME_WALLET_CARD_TGD + // last one cant not with comma + +#define HOME_WALLET_STATE_SURPLUS {HOME_WALLET_CARD_ETH, false, "ETH", true}, \ + {HOME_WALLET_CARD_SOL, false, "SOL", true}, \ + {HOME_WALLET_CARD_BNB, false, "BNB", false}, \ + {HOME_WALLET_CARD_HNT, false, "HNT", true}, \ + {HOME_WALLET_CARD_XRP, false, "XRP", true}, \ + {HOME_WALLET_CARD_ADA, false, "ADA", true}, \ + {HOME_WALLET_CARD_TON, false, "TON", false}, \ + {HOME_WALLET_CARD_DOT, false, "DOT", false}, \ + {HOME_WALLET_CARD_TRX, false, "TRX", true}, \ + {HOME_WALLET_CARD_LTC, false, "LTC", true}, \ + {HOME_WALLET_CARD_BCH, false, "BCH", true}, \ + {HOME_WALLET_CARD_APT, false, "APT", true}, \ + {HOME_WALLET_CARD_SUI, false, "SUI", true}, \ + {HOME_WALLET_CARD_DASH, false, "DASH", true}, \ + {HOME_WALLET_CARD_ARWEAVE, false, "AR", true}, \ + {HOME_WALLET_CARD_XLM, false, "XLM", true}, \ + {HOME_WALLET_CARD_COSMOS, false, "Cosmos Eco", true}, \ + {HOME_WALLET_CARD_TIA, false, "TIA", true}, \ + {HOME_WALLET_CARD_NTRN, false, "NTRN", true}, \ + {HOME_WALLET_CARD_DYM, false, "DYM", true}, \ + {HOME_WALLET_CARD_OSMO, false, "OSMO", true}, \ + {HOME_WALLET_CARD_INJ, false, "INJ", true}, \ + {HOME_WALLET_CARD_ATOM, false, "ATOM", true}, \ + {HOME_WALLET_CARD_CRO, false, "CRO", true}, \ + {HOME_WALLET_CARD_RUNE, false, "RUNE", true}, \ + {HOME_WALLET_CARD_KAVA, false, "KAVA", true}, \ + {HOME_WALLET_CARD_LUNC, false, "LUNC", true}, \ + {HOME_WALLET_CARD_AXL, false, "AXL", true}, \ + {HOME_WALLET_CARD_LUNA, false, "LUNA", true}, \ + {HOME_WALLET_CARD_AKT, false, "AKT", true}, \ + {HOME_WALLET_CARD_STRD, false, "STRD", true}, \ + {HOME_WALLET_CARD_SCRT, false, "SCRT", true}, \ + {HOME_WALLET_CARD_BLD, false, "BLD", true}, \ + {HOME_WALLET_CARD_CTK, false, "CTK", true}, \ + {HOME_WALLET_CARD_EVMOS, false, "EVMOS", true}, \ + {HOME_WALLET_CARD_STARS, false, "STARS", true}, \ + {HOME_WALLET_CARD_XPRT, false, "XPRT", true}, \ + {HOME_WALLET_CARD_SOMM, false, "SOMM", true}, \ + {HOME_WALLET_CARD_JUNO, false, "JUNO", true}, \ + {HOME_WALLET_CARD_IRIS, false, "IRIS", true}, \ + {HOME_WALLET_CARD_DVPN, false, "DVPN", true}, \ + {HOME_WALLET_CARD_ROWAN, false, "ROWAN", true}, \ + {HOME_WALLET_CARD_REGEN, false, "REGEN", true}, \ + {HOME_WALLET_CARD_BOOT, false, "BOOT", true}, \ + {HOME_WALLET_CARD_GRAV, false, "GRAV", true}, \ + {HOME_WALLET_CARD_IXO, false, "IXO", true}, \ + {HOME_WALLET_CARD_NGM, false, "NGM", true}, \ + {HOME_WALLET_CARD_IOV, false, "IOV", true}, \ + {HOME_WALLET_CARD_UMEE, false, "UMEE", true}, \ + {HOME_WALLET_CARD_QCK, false, "QCK", true}, \ + {HOME_WALLET_CARD_TGD, false, "TGD", true} + // last one cant not with comma + +#define HOME_WALLET_CARD_SURPLUS { \ + .index = HOME_WALLET_CARD_ETH, \ + .coin = "ETH", \ + .chain = "Ethereum", \ + .icon = &coinEth, \ + }, \ + { \ + .index = HOME_WALLET_CARD_SOL, \ + .coin = "SOL", \ + .chain = "Solana", \ + .icon = &coinSol, \ + }, \ + { \ + .index = HOME_WALLET_CARD_BNB, \ + .coin = "BNB", \ + .chain = "Binance", \ + .icon = &coinBnb, \ + }, \ + { \ + .index = HOME_WALLET_CARD_HNT, \ + .coin = "HNT", \ + .chain = "Helium", \ + .icon = &coinHelium, \ + }, \ + { \ + .index = HOME_WALLET_CARD_XRP, \ + .coin = "XRP", \ + .chain = "Ripple", \ + .icon = &coinXrp, \ + }, \ + { \ + .index = HOME_WALLET_CARD_ADA, \ + .coin = "ADA", \ + .chain = "Cardano", \ + .icon = &coinAda, \ + }, \ + { \ + .index = HOME_WALLET_CARD_TON, \ + .coin = "TON", \ + .chain = "The Open Network", \ + .icon = &coinTon, \ + }, \ + { \ + .index = HOME_WALLET_CARD_DOT, \ + .coin = "DOT", \ + .chain = "Polkadot", \ + .icon = &coinDot, \ + }, \ + { \ + .index = HOME_WALLET_CARD_TRX, \ + .coin = "TRX", \ + .chain = "TRON", \ + .icon = &coinTrx, \ + }, \ + { \ + .index = HOME_WALLET_CARD_LTC, \ + .coin = "LTC", \ + .chain = "Litecoin", \ + .icon = &coinLtc, \ + }, \ + { \ + .index = HOME_WALLET_CARD_BCH, \ + .coin = "BCH", \ + .chain = "Bitcoin Cash", \ + .icon = &coinBch, \ + }, \ + { \ + .index = HOME_WALLET_CARD_APT, \ + .coin = "APT", \ + .chain = "Aptos", \ + .icon = &coinApt, \ + }, \ + { \ + .index = HOME_WALLET_CARD_SUI, \ + .coin = "SUI", \ + .chain = "Sui", \ + .icon = &coinSui, \ + }, \ + { \ + .index = HOME_WALLET_CARD_DASH, \ + .coin = "DASH", \ + .chain = "Dash", \ + .icon = &coinDash, \ + }, \ + { \ + .index = HOME_WALLET_CARD_ARWEAVE, \ + .coin = "AR", \ + .chain = "Arweave", \ + .icon = &coinAr, \ + }, \ + { \ + .index = HOME_WALLET_CARD_XLM, \ + .coin = "XLM", \ + .chain = "Stellar", \ + .icon = &coinXlm, \ + }, \ + { \ + .index = HOME_WALLET_CARD_COSMOS, \ + .coin = "Cosmos Eco", \ + .chain = "", \ + .icon = &coinCosmos, \ + }, \ + { \ + .index = HOME_WALLET_CARD_TIA, \ + .coin = "TIA", \ + .chain = "Celestia", \ + .icon = &coinTia, \ + }, \ + { \ + .index = HOME_WALLET_CARD_NTRN, \ + .coin = "NTRN", \ + .chain = "Neutron", \ + .icon = &coinNtrn, \ + }, \ + { \ + .index = HOME_WALLET_CARD_DYM, \ + .coin = "DYM", \ + .chain = "Dymension", \ + .icon = &coinDym, \ + }, \ + { \ + .index = HOME_WALLET_CARD_OSMO, \ + .coin = "OSMO", \ + .chain = "Osmosis", \ + .icon = &coinOsmo, \ + }, \ + { \ + .index = HOME_WALLET_CARD_INJ, \ + .coin = "INJ", \ + .chain = "Injective", \ + .icon = &coinInj, \ + }, \ + { \ + .index = HOME_WALLET_CARD_ATOM, \ + .coin = "ATOM", \ + .chain = "Cosmos Hub", \ + .icon = &coinAtom, \ + }, \ + { \ + .index = HOME_WALLET_CARD_CRO, \ + .coin = "CRO", \ + .chain = "Cronos POS chain", \ + .icon = &coinCro, \ + }, \ + { \ + .index = HOME_WALLET_CARD_RUNE, \ + .coin = "RUNE", \ + .chain = "THORChain", \ + .icon = &coinRune, \ + }, \ + { \ + .index = HOME_WALLET_CARD_KAVA, \ + .coin = "KAVA", \ + .chain = "Kava", \ + .icon = &coinKava, \ + }, \ + { \ + .index = HOME_WALLET_CARD_LUNC, \ + .coin = "LUNC", \ + .chain = "Terra Classic", \ + .icon = &coinLunc, \ + }, \ + { \ + .index = HOME_WALLET_CARD_AXL, \ + .coin = "AXL", \ + .chain = "Axelar", \ + .icon = &coinAxl, \ + }, \ + { \ + .index = HOME_WALLET_CARD_LUNA, \ + .coin = "LUNA", \ + .chain = "Terra", \ + .icon = &coinLuna, \ + }, \ + { \ + .index = HOME_WALLET_CARD_AKT, \ + .coin = "AKT", \ + .chain = "Akash", \ + .icon = &coinAkt, \ + }, \ + { \ + .index = HOME_WALLET_CARD_STRD, \ + .coin = "STRD", \ + .chain = "Stride", \ + .icon = &coinStrd, \ + }, \ + { \ + .index = HOME_WALLET_CARD_SCRT, \ + .coin = "SCRT", \ + .chain = "Secret Network", \ + .icon = &coinScrt, \ + }, \ + { \ + .index = HOME_WALLET_CARD_BLD, \ + .coin = "BLD", \ + .chain = "Agoric", \ + .icon = &coinBld, \ + }, \ + { \ + .index = HOME_WALLET_CARD_CTK, \ + .coin = "CTK", \ + .chain = "Shentu", \ + .icon = &coinCtk, \ + }, \ + { \ + .index = HOME_WALLET_CARD_EVMOS, \ + .coin = "EVMOS", \ + .chain = "Evmos", \ + .icon = &coinEvmos, \ + }, \ + { \ + .index = HOME_WALLET_CARD_STARS, \ + .coin = "STARS", \ + .chain = "Stargaze", \ + .icon = &coinStars, \ + }, \ + { \ + .index = HOME_WALLET_CARD_XPRT, \ + .coin = "XPRT", \ + .chain = "Persistence", \ + .icon = &coinXprt, \ + }, \ + { \ + .index = HOME_WALLET_CARD_SOMM, \ + .coin = "SOMM", \ + .chain = "Sommelier", \ + .icon = &coinSomm, \ + }, \ + { \ + .index = HOME_WALLET_CARD_JUNO, \ + .coin = "JUNO", \ + .chain = "Juno", \ + .icon = &coinJuno, \ + }, \ + { \ + .index = HOME_WALLET_CARD_IRIS, \ + .coin = "IRIS", \ + .chain = "IRISnet", \ + .icon = &coinIris, \ + }, \ + { \ + .index = HOME_WALLET_CARD_DVPN, \ + .coin = "DVPN", \ + .chain = "Sentinel", \ + .icon = &coinDvpn, \ + }, \ + { \ + .index = HOME_WALLET_CARD_ROWAN, \ + .coin = "ROWAN", \ + .chain = "Sifchain", \ + .icon = &coinRowan, \ + }, \ + { \ + .index = HOME_WALLET_CARD_REGEN, \ + .coin = "REGEN", \ + .chain = "Regen", \ + .icon = &coinRegen, \ + }, \ + { \ + .index = HOME_WALLET_CARD_BOOT, \ + .coin = "BOOT", \ + .chain = "Bostrom", \ + .icon = &coinBoot, \ + }, \ + { \ + .index = HOME_WALLET_CARD_GRAV, \ + .coin = "GRAV", \ + .chain = "Gravity Bridge", \ + .icon = &coinGrav, \ + }, \ + { \ + .index = HOME_WALLET_CARD_IXO, \ + .coin = "IXO", \ + .chain = "ixo", \ + .icon = &coinIxo, \ + }, \ + { \ + .index = HOME_WALLET_CARD_NGM, \ + .coin = "NGM", \ + .chain = "e-Money", \ + .icon = &coinNgm, \ + }, \ + { \ + .index = HOME_WALLET_CARD_IOV, \ + .coin = "IOV", \ + .chain = "Starname", \ + .icon = &coinIov, \ + }, \ + { \ + .index = HOME_WALLET_CARD_UMEE, \ + .coin = "UMEE", \ + .chain = "Umee", \ + .icon = &coinUmee, \ + }, \ + { \ + .index = HOME_WALLET_CARD_QCK, \ + .coin = "QCK", \ + .chain = "Quicksilver", \ + .icon = &coinQck, \ + }, \ + { \ + .index = HOME_WALLET_CARD_TGD, \ + .coin = "TGD", \ + .chain = "Tgrade", \ + .icon = &coinTgd, \ + } + +#endif +#endif \ No newline at end of file diff --git a/src/ui/gui_widgets/general/gui_ton_mnemonic_hint_widgets.c b/src/ui/gui_widgets/multi/general/gui_ton_mnemonic_hint_widgets.c similarity index 100% rename from src/ui/gui_widgets/general/gui_ton_mnemonic_hint_widgets.c rename to src/ui/gui_widgets/multi/general/gui_ton_mnemonic_hint_widgets.c diff --git a/src/ui/gui_widgets/general/gui_ton_mnemonic_hint_widgets.h b/src/ui/gui_widgets/multi/general/gui_ton_mnemonic_hint_widgets.h similarity index 100% rename from src/ui/gui_widgets/general/gui_ton_mnemonic_hint_widgets.h rename to src/ui/gui_widgets/multi/general/gui_ton_mnemonic_hint_widgets.h diff --git a/src/ui/gui_widgets/general/gui_home_widgets.c b/src/ui/gui_widgets/multi/gui_home_widgets.c similarity index 72% rename from src/ui/gui_widgets/general/gui_home_widgets.c rename to src/ui/gui_widgets/multi/gui_home_widgets.c index 71381e6b6..b668b31fc 100644 --- a/src/ui/gui_widgets/general/gui_home_widgets.c +++ b/src/ui/gui_widgets/multi/gui_home_widgets.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui.h" #include "gui_views.h" #include "gui_button.h" @@ -51,63 +50,12 @@ static bool g_isScrolling = false; static WalletState_t g_walletState[HOME_WALLET_CARD_BUTT] = { {HOME_WALLET_CARD_BTC, false, "BTC", true}, - {HOME_WALLET_CARD_ETH, false, "ETH", true}, - {HOME_WALLET_CARD_ZEC, false, "ZEC", true}, - {HOME_WALLET_CARD_SOL, false, "SOL", true}, - {HOME_WALLET_CARD_BNB, false, "BNB", false}, - {HOME_WALLET_CARD_HNT, false, "HNT", true}, - {HOME_WALLET_CARD_XRP, false, "XRP", true}, - {HOME_WALLET_CARD_ADA, false, "ADA", true}, - {HOME_WALLET_CARD_TON, false, "TON", false}, - {HOME_WALLET_CARD_DOT, false, "DOT", false}, - {HOME_WALLET_CARD_TRX, false, "TRX", true}, - {HOME_WALLET_CARD_LTC, false, "LTC", true}, - {HOME_WALLET_CARD_BCH, false, "BCH", true}, - {HOME_WALLET_CARD_APT, false, "APT", true}, - {HOME_WALLET_CARD_SUI, false, "SUI", true}, - {HOME_WALLET_CARD_DASH, false, "DASH", true}, - {HOME_WALLET_CARD_ARWEAVE, false, "AR", true}, - {HOME_WALLET_CARD_XLM, false, "XLM", true}, - {HOME_WALLET_CARD_COSMOS, false, "Cosmos Eco", true}, - {HOME_WALLET_CARD_TIA, false, "TIA", true}, - {HOME_WALLET_CARD_NTRN, false, "NTRN", true}, - {HOME_WALLET_CARD_DYM, false, "DYM", true}, - {HOME_WALLET_CARD_OSMO, false, "OSMO", true}, - {HOME_WALLET_CARD_INJ, false, "INJ", true}, - {HOME_WALLET_CARD_ATOM, false, "ATOM", true}, - {HOME_WALLET_CARD_CRO, false, "CRO", true}, - {HOME_WALLET_CARD_RUNE, false, "RUNE", true}, - {HOME_WALLET_CARD_KAVA, false, "KAVA", true}, - {HOME_WALLET_CARD_LUNC, false, "LUNC", true}, - {HOME_WALLET_CARD_AXL, false, "AXL", true}, - {HOME_WALLET_CARD_LUNA, false, "LUNA", true}, - {HOME_WALLET_CARD_AKT, false, "AKT", true}, - {HOME_WALLET_CARD_STRD, false, "STRD", true}, - {HOME_WALLET_CARD_SCRT, false, "SCRT", true}, - {HOME_WALLET_CARD_BLD, false, "BLD", true}, - {HOME_WALLET_CARD_CTK, false, "CTK", true}, - {HOME_WALLET_CARD_EVMOS, false, "EVMOS", true}, - {HOME_WALLET_CARD_STARS, false, "STARS", true}, - {HOME_WALLET_CARD_XPRT, false, "XPRT", true}, - {HOME_WALLET_CARD_SOMM, false, "SOMM", true}, - {HOME_WALLET_CARD_JUNO, false, "JUNO", true}, - {HOME_WALLET_CARD_IRIS, false, "IRIS", true}, - {HOME_WALLET_CARD_DVPN, false, "DVPN", true}, - {HOME_WALLET_CARD_ROWAN, false, "ROWAN", true}, - {HOME_WALLET_CARD_REGEN, false, "REGEN", true}, - {HOME_WALLET_CARD_BOOT, false, "BOOT", true}, - {HOME_WALLET_CARD_GRAV, false, "GRAV", true}, - {HOME_WALLET_CARD_IXO, false, "IXO", true}, - {HOME_WALLET_CARD_NGM, false, "NGM", true}, - {HOME_WALLET_CARD_IOV, false, "IOV", true}, - {HOME_WALLET_CARD_UMEE, false, "UMEE", true}, - {HOME_WALLET_CARD_QCK, false, "QCK", true}, - {HOME_WALLET_CARD_TGD, false, "TGD", true}, + HOME_WALLET_STATE_SURPLUS, }; static WalletState_t g_walletBakState[HOME_WALLET_CARD_BUTT] = {0}; static KeyboardWidget_t *g_keyboardWidget = NULL; -static void GuiInitWalletState() +static void GuiInitWalletState(void) { for (size_t i = 0; i < HOME_WALLET_CARD_BUTT; i++) { g_walletState[i].enable = false; @@ -153,318 +101,7 @@ static const ChainCoinCard_t g_coinCardArray[HOME_WALLET_CARD_BUTT] = { .chain = "Bitcoin", .icon = &coinBtc, }, - { - .index = HOME_WALLET_CARD_ETH, - .coin = "ETH", - .chain = "Ethereum", - .icon = &coinEth, - }, - { - .index = HOME_WALLET_CARD_ZEC, - .coin = "ZEC", - .chain = "Zcash", - .icon = &coinZec, - }, - { - .index = HOME_WALLET_CARD_SOL, - .coin = "SOL", - .chain = "Solana", - .icon = &coinSol, - }, - { - .index = HOME_WALLET_CARD_BNB, - .coin = "BNB", - .chain = "Binance", - .icon = &coinBnb, - }, - { - .index = HOME_WALLET_CARD_HNT, - .coin = "HNT", - .chain = "Helium", - .icon = &coinHelium, - }, - { - .index = HOME_WALLET_CARD_XRP, - .coin = "XRP", - .chain = "Ripple", - .icon = &coinXrp, - }, - { - .index = HOME_WALLET_CARD_ADA, - .coin = "ADA", - .chain = "Cardano", - .icon = &coinAda, - }, - { - .index = HOME_WALLET_CARD_TON, - .coin = "TON", - .chain = "The Open Network", - .icon = &coinTon, - }, - { - .index = HOME_WALLET_CARD_DOT, - .coin = "DOT", - .chain = "Polkadot", - .icon = &coinDot, - }, - { - .index = HOME_WALLET_CARD_TRX, - .coin = "TRX", - .chain = "TRON", - .icon = &coinTrx, - }, - { - .index = HOME_WALLET_CARD_LTC, - .coin = "LTC", - .chain = "Litecoin", - .icon = &coinLtc, - }, - { - .index = HOME_WALLET_CARD_BCH, - .coin = "BCH", - .chain = "Bitcoin Cash", - .icon = &coinBch, - }, - { - .index = HOME_WALLET_CARD_APT, - .coin = "APT", - .chain = "Aptos", - .icon = &coinApt, - }, - { - .index = HOME_WALLET_CARD_SUI, - .coin = "SUI", - .chain = "Sui", - .icon = &coinSui, - }, - { - .index = HOME_WALLET_CARD_DASH, - .coin = "DASH", - .chain = "Dash", - .icon = &coinDash, - }, - { - .index = HOME_WALLET_CARD_ARWEAVE, - .coin = "AR", - .chain = "Arweave", - .icon = &coinAr, - }, - { - .index = HOME_WALLET_CARD_XLM, - .coin = "XLM", - .chain = "Stellar", - .icon = &coinXlm, - }, - { - .index = HOME_WALLET_CARD_COSMOS, - .coin = "Cosmos Eco", - .chain = "", - .icon = &coinCosmos, - }, - { - .index = HOME_WALLET_CARD_TIA, - .coin = "TIA", - .chain = "Celestia", - .icon = &coinTia, - }, - { - .index = HOME_WALLET_CARD_NTRN, - .coin = "NTRN", - .chain = "Neutron", - .icon = &coinNtrn, - }, - { - .index = HOME_WALLET_CARD_DYM, - .coin = "DYM", - .chain = "Dymension", - .icon = &coinDym, - }, - { - .index = HOME_WALLET_CARD_OSMO, - .coin = "OSMO", - .chain = "Osmosis", - .icon = &coinOsmo, - }, - { - .index = HOME_WALLET_CARD_INJ, - .coin = "INJ", - .chain = "Injective", - .icon = &coinInj, - }, - { - .index = HOME_WALLET_CARD_ATOM, - .coin = "ATOM", - .chain = "Cosmos Hub", - .icon = &coinAtom, - }, - { - .index = HOME_WALLET_CARD_CRO, - .coin = "CRO", - .chain = "Cronos POS chain", - .icon = &coinCro, - }, - { - .index = HOME_WALLET_CARD_RUNE, - .coin = "RUNE", - .chain = "THORChain", - .icon = &coinRune, - }, - { - .index = HOME_WALLET_CARD_KAVA, - .coin = "KAVA", - .chain = "Kava", - .icon = &coinKava, - }, - { - .index = HOME_WALLET_CARD_LUNC, - .coin = "LUNC", - .chain = "Terra Classic", - .icon = &coinLunc, - }, - { - .index = HOME_WALLET_CARD_AXL, - .coin = "AXL", - .chain = "Axelar", - .icon = &coinAxl, - }, - { - .index = HOME_WALLET_CARD_LUNA, - .coin = "LUNA", - .chain = "Terra", - .icon = &coinLuna, - }, - { - .index = HOME_WALLET_CARD_AKT, - .coin = "AKT", - .chain = "Akash", - .icon = &coinAkt, - }, - { - .index = HOME_WALLET_CARD_STRD, - .coin = "STRD", - .chain = "Stride", - .icon = &coinStrd, - }, - { - .index = HOME_WALLET_CARD_SCRT, - .coin = "SCRT", - .chain = "Secret Network", - .icon = &coinScrt, - }, - { - .index = HOME_WALLET_CARD_BLD, - .coin = "BLD", - .chain = "Agoric", - .icon = &coinBld, - }, - { - .index = HOME_WALLET_CARD_CTK, - .coin = "CTK", - .chain = "Shentu", - .icon = &coinCtk, - }, - { - .index = HOME_WALLET_CARD_EVMOS, - .coin = "EVMOS", - .chain = "Evmos", - .icon = &coinEvmos, - }, - { - .index = HOME_WALLET_CARD_STARS, - .coin = "STARS", - .chain = "Stargaze", - .icon = &coinStars, - }, - { - .index = HOME_WALLET_CARD_XPRT, - .coin = "XPRT", - .chain = "Persistence", - .icon = &coinXprt, - }, - { - .index = HOME_WALLET_CARD_SOMM, - .coin = "SOMM", - .chain = "Sommelier", - .icon = &coinSomm, - }, - { - .index = HOME_WALLET_CARD_JUNO, - .coin = "JUNO", - .chain = "Juno", - .icon = &coinJuno, - }, - { - .index = HOME_WALLET_CARD_IRIS, - .coin = "IRIS", - .chain = "IRISnet", - .icon = &coinIris, - }, - { - .index = HOME_WALLET_CARD_DVPN, - .coin = "DVPN", - .chain = "Sentinel", - .icon = &coinDvpn, - }, - { - .index = HOME_WALLET_CARD_ROWAN, - .coin = "ROWAN", - .chain = "Sifchain", - .icon = &coinRowan, - }, - { - .index = HOME_WALLET_CARD_REGEN, - .coin = "REGEN", - .chain = "Regen", - .icon = &coinRegen, - }, - { - .index = HOME_WALLET_CARD_BOOT, - .coin = "BOOT", - .chain = "Bostrom", - .icon = &coinBoot, - }, - { - .index = HOME_WALLET_CARD_GRAV, - .coin = "GRAV", - .chain = "Gravity Bridge", - .icon = &coinGrav, - }, - { - .index = HOME_WALLET_CARD_IXO, - .coin = "IXO", - .chain = "ixo", - .icon = &coinIxo, - }, - { - .index = HOME_WALLET_CARD_NGM, - .coin = "NGM", - .chain = "e-Money", - .icon = &coinNgm, - }, - { - .index = HOME_WALLET_CARD_IOV, - .coin = "IOV", - .chain = "Starname", - .icon = &coinIov, - }, - { - .index = HOME_WALLET_CARD_UMEE, - .coin = "UMEE", - .chain = "Umee", - .icon = &coinUmee, - }, - { - .index = HOME_WALLET_CARD_QCK, - .coin = "QCK", - .chain = "Quicksilver", - .icon = &coinQck, - }, - { - .index = HOME_WALLET_CARD_TGD, - .coin = "TGD", - .chain = "Tgrade", - .icon = &coinTgd, - }, + HOME_WALLET_CARD_SURPLUS, }; @@ -1054,4 +691,3 @@ void GuiHomeDeInit(void) } GUI_DEL_OBJ(g_noticeWindow); } -#endif diff --git a/src/ui/gui_widgets/multi/gui_home_widgets.h b/src/ui/gui_widgets/multi/gui_home_widgets.h new file mode 100644 index 000000000..4377824ba --- /dev/null +++ b/src/ui/gui_widgets/multi/gui_home_widgets.h @@ -0,0 +1,51 @@ +#ifndef _GUI_HOME_WIDGETS_H +#define _GUI_HOME_WIDGETS_H + +#include "gui_model.h" +#include "lvgl.h" +#include "gui_keyboard_hintbox.h" +#include "gui_attention_hintbox.h" +#include "general/gui_general_home_widgets.h" +#include "cyberpunk/gui_cyberpunk_home_widgets.h" +#ifdef COMPILE_SIMULATOR +#include "gui_pending_hintbox.h" +#endif + +typedef enum { + HOME_WALLET_CARD_BTC, + HOME_WIDGETS_SURPLUS_CARD_ENUM, + HOME_WALLET_CARD_BUTT, // This represents the end of the array (the number of arrays) and needs to be placed at the end. +} HOME_WALLET_CARD_ENUM; + +typedef struct { + HOME_WALLET_CARD_ENUM index; + bool state; + const char *name; + bool enable; + lv_obj_t *checkBox; +} WalletState_t; + +typedef struct { + HOME_WALLET_CARD_ENUM index; + const char *coin; + const char *chain; + const lv_img_dsc_t *icon; +} ChainCoinCard_t; + +void GuiHomeRefresh(void); +void GuiHomeAreaInit(void); +void GuiHomeDisActive(void); +void GuiHomeSetWalletDesc(WalletDesc_t *wallet); +void GuiHomeRestart(void); +bool GuiHomePageIsTop(void); +void GuiHomePasswordErrorCount(void *param); +void GuiRemoveKeyboardWidget(void); +void RecalculateManageWalletState(void); +const ChainCoinCard_t* GetCoinCardByIndex(HOME_WALLET_CARD_ENUM index); +void GuiHomeDeInit(void); +void GuiShowRsaSetupasswordHintbox(void); +void GuiShowRsaInitializatioCompleteHintbox(void); +void ClearHomePageCurrentIndex(void); + +#endif /* _GUI_HOME_WIDGETS_H */ + diff --git a/src/ui/gui_widgets/general/gui_key_derivation_request_widgets.c b/src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.c similarity index 99% rename from src/ui/gui_widgets/general/gui_key_derivation_request_widgets.c rename to src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.c index 4aedff715..cc3b20859 100644 --- a/src/ui/gui_widgets/general/gui_key_derivation_request_widgets.c +++ b/src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui_key_derivation_request_widgets.h" #include "gui.h" #include "gui_page.h" @@ -1245,4 +1244,3 @@ static void RejectButtonHandler(lv_event_t *e) HandleURResultViaUSBFunc(data, strlen(data), GetCurrentUSParsingRequestID(), PRS_PARSING_REJECTED); GuiCLoseCurrentWorkingView(); } -#endif diff --git a/src/ui/gui_widgets/general/gui_key_derivation_request_widgets.h b/src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.h similarity index 100% rename from src/ui/gui_widgets/general/gui_key_derivation_request_widgets.h rename to src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.h diff --git a/src/ui/gui_widgets/general/gui_multi_accounts_receive_widgets.c b/src/ui/gui_widgets/multi/gui_multi_accounts_receive_widgets.c similarity index 100% rename from src/ui/gui_widgets/general/gui_multi_accounts_receive_widgets.c rename to src/ui/gui_widgets/multi/gui_multi_accounts_receive_widgets.c diff --git a/src/ui/gui_widgets/general/gui_multi_accounts_receive_widgets.h b/src/ui/gui_widgets/multi/gui_multi_accounts_receive_widgets.h similarity index 100% rename from src/ui/gui_widgets/general/gui_multi_accounts_receive_widgets.h rename to src/ui/gui_widgets/multi/gui_multi_accounts_receive_widgets.h diff --git a/src/ui/gui_widgets/general/gui_multi_path_coin_receive_widgets.c b/src/ui/gui_widgets/multi/gui_multi_path_coin_receive_widgets.c similarity index 100% rename from src/ui/gui_widgets/general/gui_multi_path_coin_receive_widgets.c rename to src/ui/gui_widgets/multi/gui_multi_path_coin_receive_widgets.c diff --git a/src/ui/gui_widgets/general/gui_multi_path_coin_receive_widgets.h b/src/ui/gui_widgets/multi/gui_multi_path_coin_receive_widgets.h similarity index 100% rename from src/ui/gui_widgets/general/gui_multi_path_coin_receive_widgets.h rename to src/ui/gui_widgets/multi/gui_multi_path_coin_receive_widgets.h diff --git a/src/ui/gui_widgets/general/gui_standard_receive_widgets.c b/src/ui/gui_widgets/multi/gui_standard_receive_widgets.c similarity index 99% rename from src/ui/gui_widgets/general/gui_standard_receive_widgets.c rename to src/ui/gui_widgets/multi/gui_standard_receive_widgets.c index 779989dc7..5eacb32e4 100644 --- a/src/ui/gui_widgets/general/gui_standard_receive_widgets.c +++ b/src/ui/gui_widgets/multi/gui_standard_receive_widgets.c @@ -719,8 +719,7 @@ static void RefreshQrCode(void) char addressString[256]; CutAndFormatString(addressString, sizeof(addressString), addressDataItem.address, 60); lv_label_set_text(g_standardReceiveWidgets.addressLabel, addressString); - } - else { + } else { lv_label_set_text(g_standardReceiveWidgets.addressLabel, addressDataItem.address); } lv_label_set_text_fmt(g_standardReceiveWidgets.addressCountLabel, "%s-%u", _("account_head"), addressDataItem.index); diff --git a/src/ui/gui_widgets/general/gui_standard_receive_widgets.h b/src/ui/gui_widgets/multi/gui_standard_receive_widgets.h similarity index 100% rename from src/ui/gui_widgets/general/gui_standard_receive_widgets.h rename to src/ui/gui_widgets/multi/gui_standard_receive_widgets.h diff --git a/src/ui/gui_widgets/general/gui_usb_transport_widgets.c b/src/ui/gui_widgets/multi/gui_usb_transport_widgets.c similarity index 100% rename from src/ui/gui_widgets/general/gui_usb_transport_widgets.c rename to src/ui/gui_widgets/multi/gui_usb_transport_widgets.c diff --git a/src/ui/gui_widgets/general/gui_usb_transport_widgets.h b/src/ui/gui_widgets/multi/gui_usb_transport_widgets.h similarity index 100% rename from src/ui/gui_widgets/general/gui_usb_transport_widgets.h rename to src/ui/gui_widgets/multi/gui_usb_transport_widgets.h diff --git a/src/ui/gui_widgets/setting/gui_wallet_setting_widgets.c b/src/ui/gui_widgets/setting/gui_wallet_setting_widgets.c index e54b48b36..951605257 100644 --- a/src/ui/gui_widgets/setting/gui_wallet_setting_widgets.c +++ b/src/ui/gui_widgets/setting/gui_wallet_setting_widgets.c @@ -24,7 +24,7 @@ #include "keystore.h" #ifdef BTC_ONLY -#include "gui_btc_home_widgets.h" +#include "gui_home_widgets.h" #endif /* DEFINES */ diff --git a/src/ui/lv_i18n/lv_i18n.c b/src/ui/lv_i18n/lv_i18n.c index 32b400447..f3bc593ac 100644 --- a/src/ui/lv_i18n/lv_i18n.c +++ b/src/ui/lv_i18n/lv_i18n.c @@ -9,13 +9,35 @@ #define UNUSED(x) (void)(x) -static inline uint32_t op_n(int32_t val) { return (uint32_t)(val < 0 ? -val : val); } -static inline uint32_t op_i(uint32_t val) { return val; } +static inline uint32_t op_n(int32_t val) +{ + return (uint32_t)(val < 0 ? -val : val); +} +static inline uint32_t op_i(uint32_t val) +{ + return val; +} // always zero, when decimal part not exists. -static inline uint32_t op_v(uint32_t val) { UNUSED(val); return 0;} -static inline uint32_t op_w(uint32_t val) { UNUSED(val); return 0; } -static inline uint32_t op_f(uint32_t val) { UNUSED(val); return 0; } -static inline uint32_t op_t(uint32_t val) { UNUSED(val); return 0; } +static inline uint32_t op_v(uint32_t val) +{ + UNUSED(val); + return 0; +} +static inline uint32_t op_w(uint32_t val) +{ + UNUSED(val); + return 0; +} +static inline uint32_t op_f(uint32_t val) +{ + UNUSED(val); + return 0; +} +static inline uint32_t op_t(uint32_t val) +{ + UNUSED(val); + return 0; +} const static lv_i18n_phrase_t en_singulars[] = { {"Address", "Address"}, @@ -877,9 +899,12 @@ const static lv_i18n_phrase_t en_singulars[] = { static uint8_t en_plural_fn(int32_t num) { - uint32_t n = op_n(num); UNUSED(n); - uint32_t i = op_i(n); UNUSED(i); - uint32_t v = op_v(n); UNUSED(v); + uint32_t n = op_n(num); + UNUSED(n); + uint32_t i = op_i(n); + UNUSED(i); + uint32_t v = op_v(n); + UNUSED(v); if ((i == 1 && v == 0)) return LV_I18N_PLURAL_TYPE_ONE; return LV_I18N_PLURAL_TYPE_OTHER; @@ -1752,9 +1777,12 @@ const static lv_i18n_phrase_t de_singulars[] = { static uint8_t de_plural_fn(int32_t num) { - uint32_t n = op_n(num); UNUSED(n); - uint32_t i = op_i(n); UNUSED(i); - uint32_t v = op_v(n); UNUSED(v); + uint32_t n = op_n(num); + UNUSED(n); + uint32_t i = op_i(n); + UNUSED(i); + uint32_t v = op_v(n); + UNUSED(v); if ((i == 1 && v == 0)) return LV_I18N_PLURAL_TYPE_ONE; return LV_I18N_PLURAL_TYPE_OTHER; @@ -2627,7 +2655,8 @@ const static lv_i18n_phrase_t es_singulars[] = { static uint8_t es_plural_fn(int32_t num) { - uint32_t n = op_n(num); UNUSED(n); + uint32_t n = op_n(num); + UNUSED(n); if ((n == 1)) return LV_I18N_PLURAL_TYPE_ONE; @@ -5247,9 +5276,12 @@ const static lv_i18n_phrase_t ru_singulars[] = { static uint8_t ru_plural_fn(int32_t num) { - uint32_t n = op_n(num); UNUSED(n); - uint32_t v = op_v(n); UNUSED(v); - uint32_t i = op_i(n); UNUSED(i); + uint32_t n = op_n(num); + UNUSED(n); + uint32_t v = op_v(n); + UNUSED(v); + uint32_t i = op_i(n); + UNUSED(i); uint32_t i10 = i % 10; uint32_t i100 = i % 100; if ((v == 0 && i10 == 1 && i100 != 11)) return LV_I18N_PLURAL_TYPE_ONE; @@ -6172,8 +6204,8 @@ void __lv_i18n_reset(void) */ int lv_i18n_init(const lv_i18n_language_pack_t * langs) { - if(langs == NULL) return -1; - if(langs[0] == NULL) return -1; + if (langs == NULL) return -1; + if (langs[0] == NULL) return -1; current_lang_pack = langs; current_lang = langs[0]; /*Automatically select the first language*/ @@ -6186,13 +6218,13 @@ int lv_i18n_init(const lv_i18n_language_pack_t * langs) */ int lv_i18n_set_locale(const char * l_name) { - if(current_lang_pack == NULL) return -1; + if (current_lang_pack == NULL) return -1; uint16_t i; - for(i = 0; current_lang_pack[i] != NULL; i++) { + for (i = 0; current_lang_pack[i] != NULL; i++) { // Found -> finish - if(strcmp(current_lang_pack[i]->locale_name, l_name) == 0) { + if (strcmp(current_lang_pack[i]->locale_name, l_name) == 0) { current_lang = current_lang_pack[i]; return 0; } @@ -6205,10 +6237,10 @@ int lv_i18n_set_locale(const char * l_name) static const char * __lv_i18n_get_text_core(lv_i18n_phrase_t * trans, const char * msg_id) { uint16_t i; - for(i = 0; trans[i].msg_id != NULL; i++) { - if(strcmp(trans[i].msg_id, msg_id) == 0) { + for (i = 0; trans[i].msg_id != NULL; i++) { + if (strcmp(trans[i].msg_id, msg_id) == 0) { /*The msg_id has found. Check the translation*/ - if(trans[i].translation) return trans[i].translation; + if (trans[i].translation) return trans[i].translation; } } @@ -6223,23 +6255,23 @@ static const char * __lv_i18n_get_text_core(lv_i18n_phrase_t * trans, const char */ const char * lv_i18n_get_text(const char * msg_id) { - if(current_lang == NULL) return msg_id; + if (current_lang == NULL) return msg_id; const lv_i18n_lang_t * lang = current_lang; const void * txt; // Search in current locale - if(lang->singulars != NULL) { + if (lang->singulars != NULL) { txt = __lv_i18n_get_text_core(lang->singulars, msg_id); if (txt != NULL) return txt; } // Try to fallback - if(lang == current_lang_pack[0]) return msg_id; + if (lang == current_lang_pack[0]) return msg_id; lang = current_lang_pack[0]; // Repeat search for default locale - if(lang->singulars != NULL) { + if (lang->singulars != NULL) { txt = __lv_i18n_get_text_core(lang->singulars, msg_id); if (txt != NULL) return txt; } @@ -6255,31 +6287,31 @@ const char * lv_i18n_get_text(const char * msg_id) */ const char * lv_i18n_get_text_plural(const char * msg_id, int32_t num) { - if(current_lang == NULL) return msg_id; + if (current_lang == NULL) return msg_id; const lv_i18n_lang_t * lang = current_lang; const void * txt; lv_i18n_plural_type_t ptype; // Search in current locale - if(lang->locale_plural_fn != NULL) { + if (lang->locale_plural_fn != NULL) { ptype = lang->locale_plural_fn(num); - if(lang->plurals[ptype] != NULL) { + if (lang->plurals[ptype] != NULL) { txt = __lv_i18n_get_text_core(lang->plurals[ptype], msg_id); if (txt != NULL) return txt; } } // Try to fallback - if(lang == current_lang_pack[0]) return msg_id; + if (lang == current_lang_pack[0]) return msg_id; lang = current_lang_pack[0]; // Repeat search for default locale - if(lang->locale_plural_fn != NULL) { + if (lang->locale_plural_fn != NULL) { ptype = lang->locale_plural_fn(num); - if(lang->plurals[ptype] != NULL) { + if (lang->plurals[ptype] != NULL) { txt = __lv_i18n_get_text_core(lang->plurals[ptype], msg_id); if (txt != NULL) return txt; } @@ -6294,6 +6326,6 @@ const char * lv_i18n_get_text_plural(const char * msg_id, int32_t num) */ const char * lv_i18n_get_current_locale(void) { - if(!current_lang) return NULL; + if (!current_lang) return NULL; return current_lang->locale_name; } diff --git a/test/test_cmd.c b/test/test_cmd.c index 38a4f48f9..f27e87213 100644 --- a/test/test_cmd.c +++ b/test/test_cmd.c @@ -43,6 +43,7 @@ #endif #include "log.h" #include "background_task.h" +#include "fetch_sensitive_data_task.h" #include "account_public_info.h" #include "version.h" #include "drv_motor.h" @@ -107,7 +108,6 @@ static void AesEncryptTestFunc(int argc, char *argv[]); static void HashAndSaltFunc(int argc, char *argv[]); static void Sha512Func(int argc, char *argv[]); static void KeyStoreTestFunc(int argc, char *argv[]); -static void GuiFrameDebugTestFunc(int argc, char *argv[]); #ifndef EXCLUDE_RUSTC static void RustGetMasterFingerprint(int argc, char *argv[]); static void RustTestParseCryptoPSBT(int argc, char *argv[]); @@ -275,7 +275,6 @@ const static UartTestCmdItem_t g_uartTestCmdTable[] = { {"hash and salt:", HashAndSaltFunc}, {"sha512:", Sha512Func}, {"key store test:", KeyStoreTestFunc}, - {"gui debug:", GuiFrameDebugTestFunc}, #ifndef EXCLUDE_RUSTC {"rust get mfp:", RustGetMasterFingerprint}, {"rust test parse psbt", RustTestParseCryptoPSBT}, @@ -990,11 +989,6 @@ static void KeyStoreTestFunc(int argc, char *argv[]) KeyStoreTest(argc, argv); } -static void GuiFrameDebugTestFunc(int argc, char *argv[]) -{ - GuiViewsTest(argc, argv); -} - #ifndef EXCLUDE_RUSTC static void RustGetMasterFingerprint(int argc, char *argv[]) diff --git a/ui_simulator/simulator_model.h b/ui_simulator/simulator_model.h index 61df0353c..26d9f3c9c 100644 --- a/ui_simulator/simulator_model.h +++ b/ui_simulator/simulator_model.h @@ -14,20 +14,6 @@ extern bool fingerRegisterState[3]; #define JSON_MAX_LEN (1024 * 100) #define ACCOUNT_PUBLIC_HOME_COIN_PATH "C:/assets/coin.json" -// typedef enum { -// RECOGNIZE_UNLOCK = 0, -// RECOGNIZE_SIGN, -// } Recognize_Type; - -// typedef struct { -// uint8_t unlockFlag; -// uint8_t reserve0[3]; -// uint8_t signFlag[3]; -// uint8_t fingerNum; -// uint8_t fingerId[3]; -// uint8_t reserve[21]; -// } FingerManagerInfo_t; - size_t xPortGetFreeHeapSize(void); int32_t CheckPasswordExisted(const char *password, uint8_t excludeIndex); uint8_t GetCurrentAccountIndex(void); @@ -56,4 +42,160 @@ bool GetEnsName(const char *addr, char *name); extern bool g_reboot; +#define GUI_ANALYZE_OBJ_SURPLUS \ + { \ + REMAPVIEW_ETH, \ + PC_SIMULATOR_PATH "/page_eth.json", \ + GuiGetEthData, \ + GetEthTransType, \ + FreeEthMemory, \ + }, \ + { \ + REMAPVIEW_ETH_PERSONAL_MESSAGE, \ + PC_SIMULATOR_PATH "/page_eth_person.json", \ + GuiGetEthPersonalMessage, \ + GetEthPersonalMessageType, \ + FreeEthMemory, \ + }, \ + { \ + REMAPVIEW_ETH_TYPEDDATA, \ + PC_SIMULATOR_PATH "/page_eth_type.json", \ + GuiGetEthTypeData, \ + NULL, \ + FreeEthMemory, \ + }, \ + { \ + REMAPVIEW_TRX, \ + PC_SIMULATOR_PATH "/page_eth.json", \ + GuiGetTrxData, \ + NULL, \ + FreeTrxMemory, \ + }, \ + { \ + REMAPVIEW_COSMOS, \ + PC_SIMULATOR_PATH "/page_cosmos.json", \ + GuiGetCosmosData, \ + GuiGetCosmosTmpType, \ + FreeCosmosMemory, \ + }, \ + { \ + REMAPVIEW_SUI, \ + PC_SIMULATOR_PATH "/page_sui.json", \ + GuiGetSuiData, \ + NULL, \ + FreeSuiMemory, \ + }, \ + { \ + REMAPVIEW_SUI_SIGN_MESSAGE_HASH, \ + PC_SIMULATOR_PATH "/page_sign_hash.json", \ + GuiGetSuiSignMessageHashData, \ + NULL, \ + FreeSuiMemory \ + }, \ + { \ + REMAPVIEW_SOL, \ + PC_SIMULATOR_PATH "/page_sol.json", \ + GuiGetSolData, \ + NULL, \ + FreeSolMemory, \ + }, \ + { \ + REMAPVIEW_SOL_MESSAGE, \ + PC_SIMULATOR_PATH "/page_sol_message.json", \ + GuiGetSolMessageData, \ + GetSolMessageType, \ + FreeSolMemory, \ + }, \ + { \ + REMAPVIEW_APT, \ + PC_SIMULATOR_PATH "/page_eth.json", \ + GuiGetAptosData, \ + NULL, \ + FreeAptosMemory, \ + }, \ + { \ + REMAPVIEW_ADA, \ + PC_SIMULATOR_PATH "/page_ada.json", \ + GuiGetAdaData, \ + NULL, \ + FreeAdaMemory, \ + }, \ + { \ + REMAPVIEW_ADA_SIGN_TX_HASH, \ + PC_SIMULATOR_PATH "/page_sign_ada_tx_hash.json", \ + GuiGetAdaSignTxHashData, \ + NULL, \ + FreeAdaMemory \ + }, \ + { \ + REMAPVIEW_ADA_SIGN_DATA, \ + PC_SIMULATOR_PATH "/page_ada_sign_data.json", \ + GuiGetAdaSignDataData, \ + NULL, \ + FreeAdaSignDataMemory, \ + }, \ + { \ + REMAPVIEW_ADA_CATALYST, \ + PC_SIMULATOR_PATH "/page_ada_catalyst.json", \ + GuiGetAdaCatalyst, \ + NULL, \ + FreeAdaCatalystMemory, \ + }, \ + { \ + REMAPVIEW_XRP, \ + PC_SIMULATOR_PATH "/page_xrp.json", \ + GuiGetXrpData, \ + NULL, \ + FreeXrpMemory, \ + }, \ + { \ + REMAPVIEW_AR, \ + PC_SIMULATOR_PATH "/page_ar.json", \ + GuiGetArData, \ + NULL, \ + FreeArMemory, \ + }, \ + { \ + REMAPVIEW_AR_MESSAGE, \ + PC_SIMULATOR_PATH "/page_ar_message.json", \ + GuiGetArData, \ + NULL, \ + FreeArMemory, \ + }, \ + { \ + REMAPVIEW_STELLAR, \ + PC_SIMULATOR_PATH "/page_stellar.json", \ + GuiGetStellarData, \ + NULL, \ + FreeStellarMemory, \ + }, \ + { \ + REMAPVIEW_STELLAR_HASH, \ + PC_SIMULATOR_PATH "/page_stellar_hash.json", \ + GuiGetStellarData, \ + NULL, \ + FreeStellarMemory, \ + }, \ + { \ + REMAPVIEW_AR_DATAITEM, \ + PC_SIMULATOR_PATH "/page_ar_data_item.json", \ + GuiGetArData, \ + NULL, \ + FreeArMemory, \ + }, \ + { \ + REMAPVIEW_TON, \ + PC_SIMULATOR_PATH "/page_ton.json", \ + GuiGetTonGUIData, \ + NULL, \ + FreeArMemory, \ + }, \ + { \ + REMAPVIEW_TON_SIGNPROOF, \ + PC_SIMULATOR_PATH "/page_ton_proof.json", \ + GuiGetTonProofGUIData, \ + NULL, \ + FreeArMemory, \ + } + #endif \ No newline at end of file From d2152609eaa672ff24a682a5cde3a7f06d35e96c Mon Sep 17 00:00:00 2001 From: ww3512687 <15809188520@163.com> Date: Wed, 25 Dec 2024 18:31:19 +0800 Subject: [PATCH 07/31] split chain --- CMakeLists.txt | 11 +-- src/ui/gui_analyze/gui_analyze.c | 2 - src/ui/gui_analyze/gui_resolve_ur.c | 8 +- .../multi/cyberpunk/gui_cyberpunk_analyze.c | 15 ++-- .../gui_chain/multi/{ => general}/gui_ada.c | 0 .../gui_chain/multi/{ => general}/gui_ada.h | 0 .../gui_chain/multi/{ => general}/gui_aptos.c | 0 .../gui_chain/multi/{ => general}/gui_aptos.h | 0 src/ui/gui_chain/multi/{ => general}/gui_ar.c | 0 src/ui/gui_chain/multi/{ => general}/gui_ar.h | 0 .../multi/{ => general}/gui_cosmos.c | 0 .../multi/{ => general}/gui_cosmos.h | 0 .../gui_chain/multi/{ => general}/gui_eth.c | 0 .../gui_chain/multi/{ => general}/gui_eth.h | 0 .../gui_chain/multi/{ => general}/gui_sol.c | 0 .../gui_chain/multi/{ => general}/gui_sol.h | 0 .../multi/{ => general}/gui_stellar.c | 0 .../multi/{ => general}/gui_stellar.h | 0 .../gui_chain/multi/{ => general}/gui_sui.c | 0 .../gui_chain/multi/{ => general}/gui_sui.h | 0 .../gui_chain/multi/{ => general}/gui_ton.c | 0 .../gui_chain/multi/{ => general}/gui_ton.h | 0 .../gui_chain/multi/{ => general}/gui_trx.c | 0 .../gui_chain/multi/{ => general}/gui_trx.h | 0 .../gui_chain/multi/{ => general}/gui_xrp.c | 0 .../gui_chain/multi/{ => general}/gui_xrp.h | 0 src/ui/gui_components/gui_status_bar.c | 10 ++- src/ui/gui_model/gui_model.h | 2 + src/ui/gui_views/gui_connect_wallet_view.c | 2 +- .../gui_wallet/multi/cyberpunk/gui_wallet.c | 76 +++++++++++++++++++ .../multi/{ => cyberpunk}/gui_wallet.h | 0 .../multi/{ => general}/gui_wallet.c | 0 src/ui/gui_wallet/multi/general/gui_wallet.h | 33 ++++++++ .../gui_widgets/gui_connect_wallet_widgets.c | 6 +- .../gui_widgets/gui_connect_wallet_widgets.h | 2 +- .../gui_transaction_detail_widgets.c | 2 +- src/ui/gui_widgets/gui_utxo_receive_widgets.c | 2 +- .../cyberpunk/gui_cyberpunk_home_widgets.c | 5 ++ .../general}/gui_change_path_type_widgets.c | 4 +- .../general}/gui_change_path_type_widgets.h | 1 + .../multi/general/gui_general_home_widgets.c | 5 ++ .../gui_key_derivation_request_widgets.c | 0 .../gui_key_derivation_request_widgets.h | 0 .../gui_multi_path_coin_receive_widgets.c | 2 - .../gui_multi_path_coin_receive_widgets.h | 0 .../gui_standard_receive_widgets.c | 2 - .../gui_standard_receive_widgets.h | 0 src/ui/gui_widgets/multi/gui_home_widgets.c | 45 ++++++----- ui_simulator/simulator_model.h | 14 ++++ 49 files changed, 195 insertions(+), 54 deletions(-) rename src/ui/gui_chain/multi/{ => general}/gui_ada.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_ada.h (100%) rename src/ui/gui_chain/multi/{ => general}/gui_aptos.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_aptos.h (100%) rename src/ui/gui_chain/multi/{ => general}/gui_ar.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_ar.h (100%) rename src/ui/gui_chain/multi/{ => general}/gui_cosmos.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_cosmos.h (100%) rename src/ui/gui_chain/multi/{ => general}/gui_eth.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_eth.h (100%) rename src/ui/gui_chain/multi/{ => general}/gui_sol.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_sol.h (100%) rename src/ui/gui_chain/multi/{ => general}/gui_stellar.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_stellar.h (100%) rename src/ui/gui_chain/multi/{ => general}/gui_sui.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_sui.h (100%) rename src/ui/gui_chain/multi/{ => general}/gui_ton.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_ton.h (100%) rename src/ui/gui_chain/multi/{ => general}/gui_trx.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_trx.h (100%) rename src/ui/gui_chain/multi/{ => general}/gui_xrp.c (100%) rename src/ui/gui_chain/multi/{ => general}/gui_xrp.h (100%) create mode 100644 src/ui/gui_wallet/multi/cyberpunk/gui_wallet.c rename src/ui/gui_wallet/multi/{ => cyberpunk}/gui_wallet.h (100%) rename src/ui/gui_wallet/multi/{ => general}/gui_wallet.c (100%) create mode 100644 src/ui/gui_wallet/multi/general/gui_wallet.h create mode 100644 src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.c rename src/ui/gui_widgets/{ => multi/general}/gui_change_path_type_widgets.c (99%) rename src/ui/gui_widgets/{ => multi/general}/gui_change_path_type_widgets.h (92%) create mode 100644 src/ui/gui_widgets/multi/general/gui_general_home_widgets.c rename src/ui/gui_widgets/multi/{ => general}/gui_key_derivation_request_widgets.c (100%) rename src/ui/gui_widgets/multi/{ => general}/gui_key_derivation_request_widgets.h (100%) rename src/ui/gui_widgets/multi/{ => general}/gui_multi_path_coin_receive_widgets.c (99%) rename src/ui/gui_widgets/multi/{ => general}/gui_multi_path_coin_receive_widgets.h (100%) rename src/ui/gui_widgets/multi/{ => general}/gui_standard_receive_widgets.c (99%) rename src/ui/gui_widgets/multi/{ => general}/gui_standard_receive_widgets.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d3866123..530d2bc31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ endif() set(CMAKE_C_FLAGS_DEBUG "-O0 -g2 -ggdb") set(CMAKE_C_FLAGS_RELEASE "-O3") -add_subdirectory(rust) +# add_subdirectory(rust) # add definition function(add_definition_with_message OPTION_NAME) @@ -61,7 +61,6 @@ set(WIDGET_PATH "multi") # if(CYBERPUNK) # set(WIDGET_SUBPATH "multi/cyberpunk") # add_compile_definitions(CYBERPUNK_VERSION) -# message(STATUS "Enabled option: CYBERPUNK_VERSION..............................") # elseif(BTC_ONLY) # set(WIDGET_SUBPATH "btc_only/multi_sig") # set(WIDGET_PATH "btc_only") @@ -71,8 +70,10 @@ set(WIDGET_PATH "multi") # add_compile_definitions(GENERAL_VERSION) # set(WIDGET_SUBPATH "multi/general") # endif() -add_compile_definitions(GENERAL_VERSION) -set(WIDGET_SUBPATH "multi/general") +# add_compile_definitions(GENERAL_VERSION) +# set(WIDGET_SUBPATH "multi/general") +set(WIDGET_SUBPATH "multi/cyberpunk") +add_compile_definitions(CYBERPUNK_VERSION) set(GUI_CUSTOM_INCLUDE_PATH src/ui/gui_widgets/${WIDGET_SUBPATH} @@ -377,7 +378,7 @@ else() ${UTILS} ${CRYPTO_SLIP39} ) - add_dependencies(${PROJECT_NAME} rust_c) + # add_dependencies(${PROJECT_NAME} rust_c) target_link_libraries(${PROJECT_NAME} PRIVATE SDL2 ${CMAKE_SOURCE_DIR}/ui_simulator/lib/rust-builds/librust_c.a) if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux") target_link_libraries(${PROJECT_NAME} PRIVATE m dl pthread ) diff --git a/src/ui/gui_analyze/gui_analyze.c b/src/ui/gui_analyze/gui_analyze.c index 4995a35a2..7bcb1cc79 100644 --- a/src/ui/gui_analyze/gui_analyze.c +++ b/src/ui/gui_analyze/gui_analyze.c @@ -5,8 +5,6 @@ #include "gui_analyze.h" #include "gui_chain.h" #include "gui_model.h" -#include "multi/general/gui_general_analyze.h" -#include "multi/cyberpunk/gui_cyberpunk_analyze.h" #ifndef COMPILE_SIMULATOR #include "safe_mem_lib.h" diff --git a/src/ui/gui_analyze/gui_resolve_ur.c b/src/ui/gui_analyze/gui_resolve_ur.c index 9202d36f0..f878b9ef1 100644 --- a/src/ui/gui_analyze/gui_resolve_ur.c +++ b/src/ui/gui_analyze/gui_resolve_ur.c @@ -9,10 +9,12 @@ #include "gui_api.h" #include "gui_views.h" -#ifndef BTC_ONLY +#ifdef BTC_ONLY #include "gui_key_derivation_request_widgets.h" -#else #include "gui_import_multisig_wallet_info_widgets.h" +#endif + +#ifdef GENERAL_VERSION #include "gui_create_multisig_wallet_widgets.h" #endif @@ -21,7 +23,7 @@ static SetChainData_t g_chainViewArray[] = { {REMAPVIEW_BTC, (SetChainDataFunc)GuiSetPsbtUrData}, {REMAPVIEW_BTC_MESSAGE, (SetChainDataFunc)GuiSetPsbtUrData}, #ifndef BTC_ONLY -#ifdef CYBERPUNK +#ifdef CYBERPUNK_VERSION {REMAPVIEW_ZCASH, (SetChainDataFunc)GuiSetZcashUrData}, #else {REMAPVIEW_ETH, (SetChainDataFunc)GuiSetEthUrData}, diff --git a/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c b/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c index 7a6500e42..1cc8335fb 100644 --- a/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c +++ b/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c @@ -1,12 +1,11 @@ #include "gui_chain.h" #include "gui_analyze.h" -// GetCustomContainerFunc GetOtherChainCustomFunc(char *funcName) -// { -// if (!strcmp(funcName, "GuiZcashOverview")) { -// // return GuiZcashOverview; -// return NULL; -// } +GetCustomContainerFunc GetOtherChainCustomFunc(char *funcName) +{ + if (!strcmp(funcName, "GuiZcashOverview")) { + return GuiZcashOverview; + } -// return NULL; -// } + return NULL; +} diff --git a/src/ui/gui_chain/multi/gui_ada.c b/src/ui/gui_chain/multi/general/gui_ada.c similarity index 100% rename from src/ui/gui_chain/multi/gui_ada.c rename to src/ui/gui_chain/multi/general/gui_ada.c diff --git a/src/ui/gui_chain/multi/gui_ada.h b/src/ui/gui_chain/multi/general/gui_ada.h similarity index 100% rename from src/ui/gui_chain/multi/gui_ada.h rename to src/ui/gui_chain/multi/general/gui_ada.h diff --git a/src/ui/gui_chain/multi/gui_aptos.c b/src/ui/gui_chain/multi/general/gui_aptos.c similarity index 100% rename from src/ui/gui_chain/multi/gui_aptos.c rename to src/ui/gui_chain/multi/general/gui_aptos.c diff --git a/src/ui/gui_chain/multi/gui_aptos.h b/src/ui/gui_chain/multi/general/gui_aptos.h similarity index 100% rename from src/ui/gui_chain/multi/gui_aptos.h rename to src/ui/gui_chain/multi/general/gui_aptos.h diff --git a/src/ui/gui_chain/multi/gui_ar.c b/src/ui/gui_chain/multi/general/gui_ar.c similarity index 100% rename from src/ui/gui_chain/multi/gui_ar.c rename to src/ui/gui_chain/multi/general/gui_ar.c diff --git a/src/ui/gui_chain/multi/gui_ar.h b/src/ui/gui_chain/multi/general/gui_ar.h similarity index 100% rename from src/ui/gui_chain/multi/gui_ar.h rename to src/ui/gui_chain/multi/general/gui_ar.h diff --git a/src/ui/gui_chain/multi/gui_cosmos.c b/src/ui/gui_chain/multi/general/gui_cosmos.c similarity index 100% rename from src/ui/gui_chain/multi/gui_cosmos.c rename to src/ui/gui_chain/multi/general/gui_cosmos.c diff --git a/src/ui/gui_chain/multi/gui_cosmos.h b/src/ui/gui_chain/multi/general/gui_cosmos.h similarity index 100% rename from src/ui/gui_chain/multi/gui_cosmos.h rename to src/ui/gui_chain/multi/general/gui_cosmos.h diff --git a/src/ui/gui_chain/multi/gui_eth.c b/src/ui/gui_chain/multi/general/gui_eth.c similarity index 100% rename from src/ui/gui_chain/multi/gui_eth.c rename to src/ui/gui_chain/multi/general/gui_eth.c diff --git a/src/ui/gui_chain/multi/gui_eth.h b/src/ui/gui_chain/multi/general/gui_eth.h similarity index 100% rename from src/ui/gui_chain/multi/gui_eth.h rename to src/ui/gui_chain/multi/general/gui_eth.h diff --git a/src/ui/gui_chain/multi/gui_sol.c b/src/ui/gui_chain/multi/general/gui_sol.c similarity index 100% rename from src/ui/gui_chain/multi/gui_sol.c rename to src/ui/gui_chain/multi/general/gui_sol.c diff --git a/src/ui/gui_chain/multi/gui_sol.h b/src/ui/gui_chain/multi/general/gui_sol.h similarity index 100% rename from src/ui/gui_chain/multi/gui_sol.h rename to src/ui/gui_chain/multi/general/gui_sol.h diff --git a/src/ui/gui_chain/multi/gui_stellar.c b/src/ui/gui_chain/multi/general/gui_stellar.c similarity index 100% rename from src/ui/gui_chain/multi/gui_stellar.c rename to src/ui/gui_chain/multi/general/gui_stellar.c diff --git a/src/ui/gui_chain/multi/gui_stellar.h b/src/ui/gui_chain/multi/general/gui_stellar.h similarity index 100% rename from src/ui/gui_chain/multi/gui_stellar.h rename to src/ui/gui_chain/multi/general/gui_stellar.h diff --git a/src/ui/gui_chain/multi/gui_sui.c b/src/ui/gui_chain/multi/general/gui_sui.c similarity index 100% rename from src/ui/gui_chain/multi/gui_sui.c rename to src/ui/gui_chain/multi/general/gui_sui.c diff --git a/src/ui/gui_chain/multi/gui_sui.h b/src/ui/gui_chain/multi/general/gui_sui.h similarity index 100% rename from src/ui/gui_chain/multi/gui_sui.h rename to src/ui/gui_chain/multi/general/gui_sui.h diff --git a/src/ui/gui_chain/multi/gui_ton.c b/src/ui/gui_chain/multi/general/gui_ton.c similarity index 100% rename from src/ui/gui_chain/multi/gui_ton.c rename to src/ui/gui_chain/multi/general/gui_ton.c diff --git a/src/ui/gui_chain/multi/gui_ton.h b/src/ui/gui_chain/multi/general/gui_ton.h similarity index 100% rename from src/ui/gui_chain/multi/gui_ton.h rename to src/ui/gui_chain/multi/general/gui_ton.h diff --git a/src/ui/gui_chain/multi/gui_trx.c b/src/ui/gui_chain/multi/general/gui_trx.c similarity index 100% rename from src/ui/gui_chain/multi/gui_trx.c rename to src/ui/gui_chain/multi/general/gui_trx.c diff --git a/src/ui/gui_chain/multi/gui_trx.h b/src/ui/gui_chain/multi/general/gui_trx.h similarity index 100% rename from src/ui/gui_chain/multi/gui_trx.h rename to src/ui/gui_chain/multi/general/gui_trx.h diff --git a/src/ui/gui_chain/multi/gui_xrp.c b/src/ui/gui_chain/multi/general/gui_xrp.c similarity index 100% rename from src/ui/gui_chain/multi/gui_xrp.c rename to src/ui/gui_chain/multi/general/gui_xrp.c diff --git a/src/ui/gui_chain/multi/gui_xrp.h b/src/ui/gui_chain/multi/general/gui_xrp.h similarity index 100% rename from src/ui/gui_chain/multi/gui_xrp.h rename to src/ui/gui_chain/multi/general/gui_xrp.h diff --git a/src/ui/gui_components/gui_status_bar.c b/src/ui/gui_components/gui_status_bar.c index 5cb165bc6..5aa0f47e7 100644 --- a/src/ui/gui_components/gui_status_bar.c +++ b/src/ui/gui_components/gui_status_bar.c @@ -64,7 +64,7 @@ static void RefreshStatusBar(void); const static CoinWalletInfo_t g_coinWalletBtn[] = { {HOME_WALLET_CARD_BTC, "", &coinBtc}, -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION {HOME_WALLET_CARD_ETH, "", &coinEth}, {HOME_WALLET_CARD_SOL, "", &coinSol}, {HOME_WALLET_CARD_BNB, "", &coinBnb}, {HOME_WALLET_CARD_HNT, "", &coinHelium}, {HOME_WALLET_CARD_XRP, "", &coinXrp}, @@ -74,12 +74,12 @@ const static CoinWalletInfo_t g_coinWalletBtn[] = { {HOME_WALLET_CARD_SUI, "", &coinSui}, {HOME_WALLET_CARD_DASH, "", &coinDash}, {HOME_WALLET_CARD_ARWEAVE, "", &coinAr}, {HOME_WALLET_CARD_XLM, "", &coinXlm}, {HOME_WALLET_CARD_COSMOS, "", &coinCosmos}, {HOME_WALLET_CARD_TIA, "", &coinTia}, - {HOME_WALLET_CARD_NTRN, "", &coinNtrn}, {HOME_WALLET_CARD_DYM, "", &coinDym}, + {HOME_WALLET_CARD_NTRN, "", &coinNtrn}, {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_KAVA, "", &coinKava}, {HOME_WALLET_CARD_LUNC, "", &coinLunc}, - {HOME_WALLET_CARD_AXL, "", &coinAxl}, {HOME_WALLET_CARD_ZEC, "", &coinZec}, + {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}, {HOME_WALLET_CARD_BLD, "", &coinBld}, {HOME_WALLET_CARD_CTK, "", &coinCtk}, @@ -93,6 +93,10 @@ const static CoinWalletInfo_t g_coinWalletBtn[] = { {HOME_WALLET_CARD_UMEE, "", &coinUmee}, {HOME_WALLET_CARD_QCK, "", &coinQck}, {HOME_WALLET_CARD_TGD, "", &coinTgd}, {HOME_WALLET_CARD_DOT, "", &coinDot}, #endif + +#ifdef CYBERPUNK_VERSION + {HOME_WALLET_CARD_ZEC, "", &coinZec}, +#endif }; const static CoinWalletInfo_t g_walletBtn[] = { diff --git a/src/ui/gui_model/gui_model.h b/src/ui/gui_model/gui_model.h index fffda79f6..521c36b6f 100644 --- a/src/ui/gui_model/gui_model.h +++ b/src/ui/gui_model/gui_model.h @@ -12,6 +12,8 @@ #include "log.h" #include "presetting.h" #include "anti_tamper.h" +#include "multi/general/gui_general_analyze.h" +#include "multi/cyberpunk/gui_cyberpunk_analyze.h" #else #include "simulator_model.h" #endif diff --git a/src/ui/gui_views/gui_connect_wallet_view.c b/src/ui/gui_views/gui_connect_wallet_view.c index bd3d36a65..26b2bbae7 100644 --- a/src/ui/gui_views/gui_connect_wallet_view.c +++ b/src/ui/gui_views/gui_connect_wallet_view.c @@ -31,7 +31,7 @@ int32_t GuiConnectWalletViewEventProcess(void* self, uint16_t usEvent, void* par case SIG_BACKGROUND_UR_UPDATE: GuiConnectWalletHandleURUpdate((char*)param, usLen); break; -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION case SIG_SETUP_RSA_PRIVATE_KEY_CONNECT_CONFIRM: GuiConnectShowRsaSetupasswordHintbox(); break; diff --git a/src/ui/gui_wallet/multi/cyberpunk/gui_wallet.c b/src/ui/gui_wallet/multi/cyberpunk/gui_wallet.c new file mode 100644 index 000000000..8bf29c43a --- /dev/null +++ b/src/ui/gui_wallet/multi/cyberpunk/gui_wallet.c @@ -0,0 +1,76 @@ +#include "stdio.h" +#include "gui_wallet.h" +#include "keystore.h" +#include "account_public_info.h" +#include "gui_connect_wallet_widgets.h" +#include "version.h" +#include "user_memory.h" +#include "gui_chain.h" +#include "presetting.h" +#include "version.h" + +static UREncodeResult *g_urEncode = NULL; + +UREncodeResult *GuiGetBlueWalletBtcData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[3]; + public_keys->data = keys; + public_keys->size = 3; + keys[0].path = "m/84'/0'/0'"; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_NATIVE_SEGWIT); + keys[1].path = "m/49'/0'/0'"; + keys[1].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC); + keys[2].path = "m/44'/0'/0'"; + keys[2].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_LEGACY); + UREncodeResult *urencode = get_connect_blue_wallet_ur(mfp, sizeof(mfp), public_keys); + CHECK_CHAIN_PRINT(urencode); + return urencode; +} + +UREncodeResult *GuiGetSparrowWalletBtcData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[4]; + public_keys->data = keys; + public_keys->size = 4; + keys[0].path = "m/84'/0'/0'"; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_NATIVE_SEGWIT); + keys[1].path = "m/49'/0'/0'"; + keys[1].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC); + keys[2].path = "m/44'/0'/0'"; + keys[2].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_LEGACY); + keys[3].path = "m/86'/0'/0'"; + keys[3].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_TAPROOT); + UREncodeResult *urencode = get_connect_sparrow_wallet_ur(mfp, sizeof(mfp), public_keys); + CHECK_CHAIN_PRINT(urencode); + return urencode; +} + +UREncodeResult *GuiGetSpecterWalletBtcData(void) +{ + uint8_t mfp[4] = {0}; + GetMasterFingerPrint(mfp); + PtrT_CSliceFFI_ExtendedPublicKey public_keys = SRAM_MALLOC(sizeof(CSliceFFI_ExtendedPublicKey)); + ExtendedPublicKey keys[2]; + public_keys->data = keys; + public_keys->size = 2; + keys[0].path = "m/84'/0'/0'"; + keys[0].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC_NATIVE_SEGWIT); + keys[1].path = "m/49'/0'/0'"; + keys[1].xpub = GetCurrentAccountPublicKey(XPUB_TYPE_BTC); + UREncodeResult *urencode = get_connect_specter_wallet_ur(mfp, sizeof(mfp), public_keys); + CHECK_CHAIN_PRINT(urencode); + return urencode; +} + +typedef UREncodeResult *MetamaskUrGetter(PtrBytes master_fingerprint, uint32_t master_fingerprint_length, enum ETHAccountType account_type, PtrT_CSliceFFI_ExtendedPublicKey public_keys); + +static UREncodeResult *get_unlimited_connect_metamask_ur(PtrBytes master_fingerprint, uint32_t master_fingerprint_length, enum ETHAccountType account_type, PtrT_CSliceFFI_ExtendedPublicKey public_keys) +{ + return get_connect_metamask_ur_unlimited(master_fingerprint, master_fingerprint_length, account_type, public_keys); +} \ No newline at end of file diff --git a/src/ui/gui_wallet/multi/gui_wallet.h b/src/ui/gui_wallet/multi/cyberpunk/gui_wallet.h similarity index 100% rename from src/ui/gui_wallet/multi/gui_wallet.h rename to src/ui/gui_wallet/multi/cyberpunk/gui_wallet.h diff --git a/src/ui/gui_wallet/multi/gui_wallet.c b/src/ui/gui_wallet/multi/general/gui_wallet.c similarity index 100% rename from src/ui/gui_wallet/multi/gui_wallet.c rename to src/ui/gui_wallet/multi/general/gui_wallet.c diff --git a/src/ui/gui_wallet/multi/general/gui_wallet.h b/src/ui/gui_wallet/multi/general/gui_wallet.h new file mode 100644 index 000000000..61dbe9c06 --- /dev/null +++ b/src/ui/gui_wallet/multi/general/gui_wallet.h @@ -0,0 +1,33 @@ +#ifndef GUI_WALLET_H +#define GUI_WALLET_H + +#include "rust.h" +#include "gui_chain.h" +#include "rsa.h" +#include "gui_attention_hintbox.h" + +UREncodeResult *GuiGetBlueWalletBtcData(void); +UREncodeResult *GuiGetSparrowWalletBtcData(void); +UREncodeResult *GuiGetSpecterWalletBtcData(void); +UREncodeResult *GuiGetKeplrDataByIndex(uint32_t index); +UREncodeResult *GuiGetLeapData(); +UREncodeResult *GuiGetArConnectData(void); +UREncodeResult *GuiGetCompanionAppData(void); +UREncodeResult *GuiGetOkxWalletData(void); +UREncodeResult *GuiGetBitgetWalletData(void); +UREncodeResult *GetMetamaskDataForAccountType(ETHAccountType accountType); +UREncodeResult *GetUnlimitedMetamaskDataForAccountType(ETHAccountType accountType); +UREncodeResult *GuiGetMetamaskData(void); +UREncodeResult *GuiGetFewchaDataByCoin(GuiChainCoinType coin); +UREncodeResult *GuiGetNightlyDataByCoin(GuiChainCoinType coin); +UREncodeResult *GuiGetPetraData(void); +UREncodeResult *GuiGetSolflareData(void); +UREncodeResult *GuiGetHeliumData(void); +UREncodeResult *GuiGetXBullData(void); +UREncodeResult *GuiGetBackpackData(void); +UREncodeResult *GuiGetXrpToolkitDataByIndex(uint16_t index); +UREncodeResult *GuiGetADADataByIndex(char *walletName); +UREncodeResult *GuiGetImTokenData(void); +UREncodeResult *GuiGetKeystoneWalletData(void); +UREncodeResult *GuiGetThorWalletBtcData(void); +#endif diff --git a/src/ui/gui_widgets/gui_connect_wallet_widgets.c b/src/ui/gui_widgets/gui_connect_wallet_widgets.c index 289263e56..9e49461ea 100644 --- a/src/ui/gui_widgets/gui_connect_wallet_widgets.c +++ b/src/ui/gui_widgets/gui_connect_wallet_widgets.c @@ -9,8 +9,9 @@ #include "gui_wallet.h" #include "rust.h" #include "user_memory.h" -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION #include "gui_multi_path_coin_receive_widgets.h" +#include "gui_connect_ada_widgets.h" #include "gui_keyboard_hintbox.h" #include "gui_pending_hintbox.h" #endif @@ -19,9 +20,6 @@ #include "gui_global_resources.h" #include "gui_page.h" #include "keystore.h" -#ifndef BTC_ONLY -#include "gui_connect_ada_widgets.h" -#endif #include "gui_select_address_widgets.h" #include "account_public_info.h" diff --git a/src/ui/gui_widgets/gui_connect_wallet_widgets.h b/src/ui/gui_widgets/gui_connect_wallet_widgets.h index df60d6404..76b21c174 100644 --- a/src/ui/gui_widgets/gui_connect_wallet_widgets.h +++ b/src/ui/gui_widgets/gui_connect_wallet_widgets.h @@ -4,7 +4,7 @@ #include "gui_views.h" #include "librust_c.h" #include "gui_attention_hintbox.h" -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION #include "gui_ar.h" #endif diff --git a/src/ui/gui_widgets/gui_transaction_detail_widgets.c b/src/ui/gui_widgets/gui_transaction_detail_widgets.c index 63b58232b..3daeca824 100644 --- a/src/ui/gui_widgets/gui_transaction_detail_widgets.c +++ b/src/ui/gui_widgets/gui_transaction_detail_widgets.c @@ -25,7 +25,7 @@ #include "gui_page.h" #include "account_manager.h" #include "gui_pending_hintbox.h" -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION #include "gui_eth.h" #include "general/eapdu_services/service_resolve_ur.h" #endif diff --git a/src/ui/gui_widgets/gui_utxo_receive_widgets.c b/src/ui/gui_widgets/gui_utxo_receive_widgets.c index 959691b58..fb669617b 100644 --- a/src/ui/gui_widgets/gui_utxo_receive_widgets.c +++ b/src/ui/gui_widgets/gui_utxo_receive_widgets.c @@ -177,7 +177,7 @@ static char **g_derivationPathDescs = NULL; static char **g_testNetderivationPathDescs = NULL; #endif -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION static const ChainPathItem_t g_chainPathItems[] = { {HOME_WALLET_CARD_BTC, ""}, {HOME_WALLET_CARD_LTC, "m/49'/2'/0'"}, diff --git a/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.c b/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.c new file mode 100644 index 000000000..a1327eee6 --- /dev/null +++ b/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.c @@ -0,0 +1,5 @@ +#include "gui_home_widgets.h" + +void CoinOtherDealHandler(HOME_WALLET_CARD_ENUM coin) +{ +} \ No newline at end of file diff --git a/src/ui/gui_widgets/gui_change_path_type_widgets.c b/src/ui/gui_widgets/multi/general/gui_change_path_type_widgets.c similarity index 99% rename from src/ui/gui_widgets/gui_change_path_type_widgets.c rename to src/ui/gui_widgets/multi/general/gui_change_path_type_widgets.c index dde12a944..9c0b435eb 100644 --- a/src/ui/gui_widgets/gui_change_path_type_widgets.c +++ b/src/ui/gui_widgets/multi/general/gui_change_path_type_widgets.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui_change_path_type_widgets.h" typedef struct { @@ -485,5 +484,4 @@ static void GetChangePathLabelHint(char* hint) default: break; } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ui/gui_widgets/gui_change_path_type_widgets.h b/src/ui/gui_widgets/multi/general/gui_change_path_type_widgets.h similarity index 92% rename from src/ui/gui_widgets/gui_change_path_type_widgets.h rename to src/ui/gui_widgets/multi/general/gui_change_path_type_widgets.h index edf5ecd0e..82e66b461 100644 --- a/src/ui/gui_widgets/gui_change_path_type_widgets.h +++ b/src/ui/gui_widgets/multi/general/gui_change_path_type_widgets.h @@ -6,6 +6,7 @@ #include "gui_framework.h" #include "assert.h" #include "gui_global_resources.h" +#include "gui_home_widgets.h" void GuiCreateSwitchPathTypeWidget(lv_obj_t *parent, HOME_WALLET_CARD_ENUM chain, lv_event_cb_t changed_cb); void GuiDestroySwitchPathTypeWidget(void); diff --git a/src/ui/gui_widgets/multi/general/gui_general_home_widgets.c b/src/ui/gui_widgets/multi/general/gui_general_home_widgets.c new file mode 100644 index 000000000..a1327eee6 --- /dev/null +++ b/src/ui/gui_widgets/multi/general/gui_general_home_widgets.c @@ -0,0 +1,5 @@ +#include "gui_home_widgets.h" + +void CoinOtherDealHandler(HOME_WALLET_CARD_ENUM coin) +{ +} \ No newline at end of file diff --git a/src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.c b/src/ui/gui_widgets/multi/general/gui_key_derivation_request_widgets.c similarity index 100% rename from src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.c rename to src/ui/gui_widgets/multi/general/gui_key_derivation_request_widgets.c diff --git a/src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.h b/src/ui/gui_widgets/multi/general/gui_key_derivation_request_widgets.h similarity index 100% rename from src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.h rename to src/ui/gui_widgets/multi/general/gui_key_derivation_request_widgets.h diff --git a/src/ui/gui_widgets/multi/gui_multi_path_coin_receive_widgets.c b/src/ui/gui_widgets/multi/general/gui_multi_path_coin_receive_widgets.c similarity index 99% rename from src/ui/gui_widgets/multi/gui_multi_path_coin_receive_widgets.c rename to src/ui/gui_widgets/multi/general/gui_multi_path_coin_receive_widgets.c index 43d4d4996..dcee15268 100644 --- a/src/ui/gui_widgets/multi/gui_multi_path_coin_receive_widgets.c +++ b/src/ui/gui_widgets/multi/general/gui_multi_path_coin_receive_widgets.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui_multi_path_coin_receive_widgets.h" #include "gui_status_bar.h" #include "gui_chain.h" @@ -1347,4 +1346,3 @@ static uint32_t GetCurrentSelectIndex() { return GetAccountReceiveIndex(GetCoinCardByIndex(g_chainCard)->coin); } -#endif diff --git a/src/ui/gui_widgets/multi/gui_multi_path_coin_receive_widgets.h b/src/ui/gui_widgets/multi/general/gui_multi_path_coin_receive_widgets.h similarity index 100% rename from src/ui/gui_widgets/multi/gui_multi_path_coin_receive_widgets.h rename to src/ui/gui_widgets/multi/general/gui_multi_path_coin_receive_widgets.h diff --git a/src/ui/gui_widgets/multi/gui_standard_receive_widgets.c b/src/ui/gui_widgets/multi/general/gui_standard_receive_widgets.c similarity index 99% rename from src/ui/gui_widgets/multi/gui_standard_receive_widgets.c rename to src/ui/gui_widgets/multi/general/gui_standard_receive_widgets.c index 5eacb32e4..760284fed 100644 --- a/src/ui/gui_widgets/multi/gui_standard_receive_widgets.c +++ b/src/ui/gui_widgets/multi/general/gui_standard_receive_widgets.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui_standard_receive_widgets.h" #include "gui_status_bar.h" #include "gui_chain.h" @@ -1203,4 +1202,3 @@ static uint32_t GetCurrentSelectIndex() } } } -#endif diff --git a/src/ui/gui_widgets/multi/gui_standard_receive_widgets.h b/src/ui/gui_widgets/multi/general/gui_standard_receive_widgets.h similarity index 100% rename from src/ui/gui_widgets/multi/gui_standard_receive_widgets.h rename to src/ui/gui_widgets/multi/general/gui_standard_receive_widgets.h diff --git a/src/ui/gui_widgets/multi/gui_home_widgets.c b/src/ui/gui_widgets/multi/gui_home_widgets.c index b668b31fc..e4a165b0d 100644 --- a/src/ui/gui_widgets/multi/gui_home_widgets.c +++ b/src/ui/gui_widgets/multi/gui_home_widgets.c @@ -282,6 +282,11 @@ static void GuiOpenARAddressNoticeWindow() lv_obj_align_to(img, lv_obj_get_child(g_noticeWindow, 1), LV_ALIGN_TOP_RIGHT, -36, 36); } +__attribute__((weak)) void CoinOtherDealHandler(HOME_WALLET_CARD_ENUM coin) +{ + return NULL; +} + static void CoinDealHandler(HOME_WALLET_CARD_ENUM coin) { if (coin >= HOME_WALLET_CARD_BUTT) { @@ -294,27 +299,31 @@ static void CoinDealHandler(HOME_WALLET_CARD_ENUM coin) case HOME_WALLET_CARD_BCH: GuiFrameOpenViewWithParam(&g_utxoReceiveView, &coin, sizeof(coin)); break; - case HOME_WALLET_CARD_ETH: - case HOME_WALLET_CARD_SOL: - case HOME_WALLET_CARD_HNT: - GuiFrameOpenViewWithParam(&g_multiPathCoinReceiveView, &coin, sizeof(coin)); - break; - case HOME_WALLET_CARD_ADA: - GuiFrameOpenViewWithParam(&g_multiAccountsReceiveView, &coin, sizeof(coin)); - break; - case HOME_WALLET_CARD_ARWEAVE: { - bool shouldGenerateArweaveXPub = IsArweaveSetupComplete(); - if (!shouldGenerateArweaveXPub) { - GuiOpenARAddressNoticeWindow(); - break; - } - GuiFrameOpenViewWithParam(&g_standardReceiveView, &coin, sizeof(coin)); - break; - } default: - GuiFrameOpenViewWithParam(&g_standardReceiveView, &coin, sizeof(coin)); + CoinOtherDealHandler(coin); break; } + // case HOME_WALLET_CARD_ETH: + // case HOME_WALLET_CARD_SOL: + // case HOME_WALLET_CARD_HNT: + // GuiFrameOpenViewWithParam(&g_multiPathCoinReceiveView, &coin, sizeof(coin)); + // break; + // case HOME_WALLET_CARD_ADA: + // GuiFrameOpenViewWithParam(&g_multiAccountsReceiveView, &coin, sizeof(coin)); + // break; + // case HOME_WALLET_CARD_ARWEAVE: { + // bool shouldGenerateArweaveXPub = IsArweaveSetupComplete(); + // if (!shouldGenerateArweaveXPub) { + // GuiOpenARAddressNoticeWindow(); + // break; + // } + // GuiFrameOpenViewWithParam(&g_standardReceiveView, &coin, sizeof(coin)); + // break; + // } + // default: + // GuiFrameOpenViewWithParam(&g_standardReceiveView, &coin, sizeof(coin)); + // break; + // } } void GuiRemoveKeyboardWidget(void) diff --git a/ui_simulator/simulator_model.h b/ui_simulator/simulator_model.h index 26d9f3c9c..9e3bb1258 100644 --- a/ui_simulator/simulator_model.h +++ b/ui_simulator/simulator_model.h @@ -42,6 +42,19 @@ bool GetEnsName(const char *addr, char *name); extern bool g_reboot; +#undef GUI_ANALYZE_OBJ_SURPLUS +#ifdef CYBERPUNK_VERSION +#define GUI_ANALYZE_OBJ_SURPLUS \ + { \ + REMAPVIEW_ZCASH, \ + PC_SIMULATOR_PATH "/page_zcash.json", \ + GuiGetZcashGUIData, \ + NULL, \ + FreeZcashMemory, \ + } +#endif + +#ifdef GENERAL_VERSION #define GUI_ANALYZE_OBJ_SURPLUS \ { \ REMAPVIEW_ETH, \ @@ -197,5 +210,6 @@ extern bool g_reboot; NULL, \ FreeArMemory, \ } +#endif #endif \ No newline at end of file From 4b27b6de087177e11957620666d03d7d9002ecd0 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 18:42:10 +0800 Subject: [PATCH 08/31] refactor: use features for code --- rust/.gitignore | 3 +- rust/BUILD.MD | 34 + rust/CMakeLists.txt | 12 +- rust/apps/arweave/src/lib.rs | 1 - rust/keystore/src/errors.rs | 1 - rust/rust_c/Cargo.toml | 15 +- rust/rust_c/build.rs | 10 +- rust/rust_c/cbindgen.toml | 13 + rust/rust_c/cbindgens/firmware/btc_only.toml | 33 - .../rust_c/cbindgens/firmware/multi_coin.toml | 74 - rust/rust_c/cbindgens/simulator/btc_only.toml | 35 - .../cbindgens/simulator/multi_coin.toml | 86 - rust/rust_c/librust_c.h | 2433 ----------------- rust/rust_c/src/common/errors.rs | 62 +- rust/rust_c/src/common/keystone.rs | 6 +- rust/rust_c/src/common/macros.rs | 172 +- rust/rust_c/src/common/structs.rs | 3 - rust/rust_c/src/common/ur.rs | 292 +- rust/rust_c/src/common/ur_ext.rs | 107 +- 19 files changed, 403 insertions(+), 2989 deletions(-) create mode 100644 rust/BUILD.MD delete mode 100644 rust/rust_c/cbindgens/firmware/btc_only.toml delete mode 100644 rust/rust_c/cbindgens/firmware/multi_coin.toml delete mode 100644 rust/rust_c/cbindgens/simulator/btc_only.toml delete mode 100644 rust/rust_c/cbindgens/simulator/multi_coin.toml delete mode 100644 rust/rust_c/librust_c.h diff --git a/rust/.gitignore b/rust/.gitignore index e330df76a..970fd171c 100644 --- a/rust/.gitignore +++ b/rust/.gitignore @@ -1,4 +1,5 @@ /target /**/target signer/build -.idea/ \ No newline at end of file +.idea/ +rust_c/bindings/ diff --git a/rust/BUILD.MD b/rust/BUILD.MD new file mode 100644 index 000000000..6e6db9547 --- /dev/null +++ b/rust/BUILD.MD @@ -0,0 +1,34 @@ +## Build + +BUILD_ENVIRONMENT: PRODUCTION, DEBUG, SIMULATOR +BUILD_VARIANT: BTC_ONLY, MULTI_COINS + +### Build for production + +```bash +cargo build --release -p rust_c --target thumbv7em-none-eabihf --no-default-features --features production-multi-coins +``` + +```bash +cargo build --release -p rust_c --target thumbv7em-none-eabihf --no-default-features --features production-btc-only +``` + +### Build for simulator + +```bash +cargo build --release -p rust_c --no-default-features --features simulator-multi-coins +``` + +```bash +cargo build --release -p rust_c --no-default-features --features simulator-btc-only +``` + +### Build for debug + +```bash +cargo build -p rust_c --target thumbv7em-none-eabihf --no-default-features --features debug-multi-coins +``` + +```bash +cargo build -p rust_c --target thumbv7em-none-eabihf --no-default-features --features debug-btc-only +``` diff --git a/rust/CMakeLists.txt b/rust/CMakeLists.txt index c49171367..9f44485c0 100644 --- a/rust/CMakeLists.txt +++ b/rust/CMakeLists.txt @@ -43,17 +43,17 @@ endif() set(FEATURE ${FEATURE_ENVIRONMENT}-${FEATURE_VARIANT}) -set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/${CBIDGEN_FOLDER}/${CBIDGEN_CONFIG_FILE}) -set(CBINDGEN_FLAG ${RUST_C_DIR} --config ${CBINDGEN_CONFIG_PATH} --output ${TARGET_PATH}/librust_c.h --lang c) +set(CBINDGEN_BINDINGS_TARGET ${RUST_C_DIR}/bindings/${FEATURE}/librust_c.h) +set(COPY_BINDINGS_TARGET cp ${CBINDGEN_BINDINGS_TARGET} ${TARGET_PATH}) # compile rust lib set(CARGO_FLAG --release -p rust_c --no-default-features) set(CARGO_FLAG ${CARGO_FLAG} --features ${FEATURE}) if(CARGO_ARM_TARGET) set(CARGO_FLAG ${CARGO_FLAG} --target ${CARGO_ARM_TARGET}) - set(COPY_COMMAND cp ${RUST_DIR}/target/${CARGO_ARM_TARGET}/release/${LIB_NAME} ${TARGET_PATH}) + set(COPY_BUILD_TARGET cp ${RUST_DIR}/target/${CARGO_ARM_TARGET}/release/${LIB_NAME} ${TARGET_PATH}) else() - set(COPY_COMMAND cp ${RUST_DIR}/target/release/${LIB_NAME} ${TARGET_PATH}) + set(COPY_BUILD_TARGET cp ${RUST_DIR}/target/release/${LIB_NAME} ${TARGET_PATH}) endif() message(STATUS "cargo build command: " ${CARGO_FLAG}) @@ -61,8 +61,8 @@ message(STATUS "cargo build command: " ${CARGO_FLAG}) #run build add_custom_target(rust_c ALL - COMMAND ${CBINDGEN_EXE} ${CBINDGEN_FLAG} COMMAND rustup run nightly-2024-01-31 ${RUST_CARGO_EXECUTABLE} build ${CARGO_FLAG} - COMMAND ${COPY_COMMAND} + COMMAND ${COPY_BUILD_TARGET} + COMMAND ${COPY_BINDINGS_TARGET} WORKING_DIRECTORY ${RUST_DIR} ) diff --git a/rust/apps/arweave/src/lib.rs b/rust/apps/arweave/src/lib.rs index 2d2d80c65..7e4869783 100644 --- a/rust/apps/arweave/src/lib.rs +++ b/rust/apps/arweave/src/lib.rs @@ -10,7 +10,6 @@ pub mod transaction; #[macro_use] extern crate alloc; -extern crate aes; #[cfg(test)] #[macro_use] diff --git a/rust/keystore/src/errors.rs b/rust/keystore/src/errors.rs index 6cf8c8125..598045621 100644 --- a/rust/keystore/src/errors.rs +++ b/rust/keystore/src/errors.rs @@ -1,7 +1,6 @@ use alloc::string::String; use thiserror; use thiserror::Error; -use zcash_vendor::orchard; pub type Result = core::result::Result; diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index 51aed7047..5a222bd2c 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -30,7 +30,7 @@ sim_qr_reader = { workspace = true, optional = true } keystore = { workspace = true } ur-registry = { workspace = true } ur-parse-lib = { workspace = true } -zcash_vendor = { workspace = true } +zcash_vendor = { workspace = true, optional = true } ed25519-bip32-core = { workspace = true } app_utils = { workspace = true } rust_tools = { workspace = true } @@ -62,6 +62,9 @@ simulator = ["dep:sim_qr_reader"] aptos = ["dep:app_aptos"] arweave = ["dep:app_arweave"] bitcoin = ["dep:app_bitcoin"] +ltc = [] +dash = [] +bch = [] cardano = ["dep:app_cardano"] cosmos = ["dep:app_cosmos"] ethereum = ["dep:app_ethereum"] @@ -72,7 +75,7 @@ sui = ["dep:app_sui"] ton = ["dep:app_ton"] tron = ["dep:app_tron"] xrp = ["dep:app_xrp"] -zcash = ["dep:app_zcash"] +zcash = ["dep:app_zcash", "dep:zcash_vendor"] test_cmd = [] debug-memory = ["multi-coins"] @@ -92,6 +95,9 @@ multi-coins = [ "stellar", "ton", "zcash", + "ltc", + "dash", + "bch", ] btc-only = ["bitcoin"] @@ -101,11 +107,12 @@ btc-only = ["bitcoin"] production-multi-coins = ["use-allocator", "multi-coins"] production-btc-only = ["use-allocator", "btc-only"] # debug -debug-multi-coins = ["test_cmd", "production-multi-coins"] -debug-btc-only = ["test_cmd", "production-btc-only"] +debug-multi-coins = ["test_cmd", "use-allocator", "multi-coins"] +debug-btc-only = ["test_cmd", "use-allocator", "btc-only"] # simulator simulator-multi-coins = ["simulator", "multi-coins"] simulator-btc-only = ["simulator", "btc-only"] +# make IDE happy default = ["simulator-multi-coins"] [dev-dependencies] diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index 18b73f5df..df90db38d 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -1,7 +1,9 @@ +use std::env; + fn main() { let mut config = cbindgen::Config::from_file("cbindgen.toml").expect("Failed to read cbindgen.toml"); - let features = vec![ + let features: Vec<&str> = vec![ #[cfg(feature = "production-multi-coins")] "production-multi-coins", #[cfg(feature = "production-btc-only")] @@ -15,7 +17,9 @@ fn main() { #[cfg(feature = "debug-btc-only")] "debug-btc-only", ]; - println!("cargo:warning={}", format!("features: {:?}", features)); + assert!(features.len() > 0, "No build variant enabled"); + assert!(features.len() == 1, "Multiple build variants enabled: {:?}", features); + let output_target = env::var("CBINDGEN_BINDINGS_TARGET").unwrap_or(format!("bindings/{}/librust_c.h", features[0])); config.parse.expand.features = Some(features.into_iter().map(|s| s.to_string()).collect()); let builder = cbindgen::Builder::new(); @@ -25,5 +29,5 @@ fn main() { .with_config(config) .generate() .expect("Failed to generate bindings") - .write_to_file("librust_c.h"); + .write_to_file(output_target); } diff --git a/rust/rust_c/cbindgen.toml b/rust/rust_c/cbindgen.toml index 75a59cfd1..af0fe7866 100644 --- a/rust/rust_c/cbindgen.toml +++ b/rust/rust_c/cbindgen.toml @@ -6,6 +6,19 @@ language = "C" [defines] "feature = multi-coins" = "BUILD_MULTI_COINS" +"feature = aptos" = "FEATURE_APTOS" +"feature = arweave" = "FEATURE_ARWEAVE" +"feature = bitcoin" = "FEATURE_BITCOIN" +"feature = cardano" = "FEATURE_CARDANO" +"feature = cosmos" = "FEATURE_COSMOS" +"feature = ethereum" = "FEATURE_ETHEREUM" +"feature = near" = "FEATURE_NEAR" +"feature = solana" = "FEATURE_SOLANA" +"feature = stellar" = "FEATURE_STELLAR" +"feature = ton" = "FEATURE_TON" +"feature = tron" = "FEATURE_TRON" +"feature = xrp" = "FEATURE_XRP" +"feature = zcash" = "FEATURE_ZCASH" [parse] extra_bindings = ["rust_c"] diff --git a/rust/rust_c/cbindgens/firmware/btc_only.toml b/rust/rust_c/cbindgens/firmware/btc_only.toml deleted file mode 100644 index 3b3033afd..000000000 --- a/rust/rust_c/cbindgens/firmware/btc_only.toml +++ /dev/null @@ -1,33 +0,0 @@ -include_guard = "_LIBRUST_C_H" - -after_includes = "#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" - -[defines] -"feature = multi-coins" = "BUILD_MULTI_COINS" - -[parse] -parse_deps = true -include = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", -] -extra_bindings = [ - "common_rust_c", - "bitcoin_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", -] - -[parse.expand] -crates = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", -] -default_features = false -features = ["btc-only"] \ No newline at end of file diff --git a/rust/rust_c/cbindgens/firmware/multi_coin.toml b/rust/rust_c/cbindgens/firmware/multi_coin.toml deleted file mode 100644 index f67e60d57..000000000 --- a/rust/rust_c/cbindgens/firmware/multi_coin.toml +++ /dev/null @@ -1,74 +0,0 @@ -include_guard = "_LIBRUST_C_H" - -after_includes = "#define BUILD_MULTI_COINS\n#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" - -[defines] -"feature = multi-coins" = "BUILD_MULTI_COINS" - -[parse] -parse_deps = true -include = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "ton_rust_c", - "zcash_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", -] -extra_bindings = [ - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "ton_rust_c", - "zcash_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", -] - -[parse.expand] -crates = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "ton_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "zcash_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", -] -default_features = true diff --git a/rust/rust_c/cbindgens/simulator/btc_only.toml b/rust/rust_c/cbindgens/simulator/btc_only.toml deleted file mode 100644 index 468af5cbd..000000000 --- a/rust/rust_c/cbindgens/simulator/btc_only.toml +++ /dev/null @@ -1,35 +0,0 @@ -include_guard = "_LIBRUST_C_H" - -after_includes = "#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" - -[defines] -"feature = multi-coins" = "BUILD_MULTI_COINS" - -[parse] -parse_deps = true -include = [ - "rust_c", -] -extra_bindings = [ - "common_rust_c", - "bitcoin_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "test_cmd", - "btc_test_cmd", - "simulator_rust_c" -] - -[parse.expand] -crates = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "test_cmd", - "btc_test_cmd", - "simulator_rust_c" -] -default_features = false -features = ["btc-only"] \ No newline at end of file diff --git a/rust/rust_c/cbindgens/simulator/multi_coin.toml b/rust/rust_c/cbindgens/simulator/multi_coin.toml deleted file mode 100644 index 234f46cfb..000000000 --- a/rust/rust_c/cbindgens/simulator/multi_coin.toml +++ /dev/null @@ -1,86 +0,0 @@ -include_guard = "_LIBRUST_C_H" - -after_includes = "#define BUILD_MULTI_COINS\n#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" - -[defines] -"feature = multi-coins" = "BUILD_MULTI_COINS" - -[parse] -parse_deps = true -include = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "ton_rust_c", - "zcash_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", - "test_cmd", - "btc_test_cmd", - "general_test_cmd", - "simulator_rust_c", -] -extra_bindings = [ - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "ton_rust_c", - "zcash_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", - "test_cmd", - "btc_test_cmd", - "general_test_cmd", - "simulator_rust_c", -] - -[parse.expand] -crates = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "ton_rust_c", - "zcash_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", - "test_cmd", - "btc_test_cmd", - "general_test_cmd", - "simulator_rust_c", -] -default_features = true diff --git a/rust/rust_c/librust_c.h b/rust/rust_c/librust_c.h deleted file mode 100644 index ef0e43e32..000000000 --- a/rust/rust_c/librust_c.h +++ /dev/null @@ -1,2433 +0,0 @@ -#ifndef _LIBRUST_C_H -#define _LIBRUST_C_H - -#include -#include -#include -#include -#define BUILD_MULTI_COINS -#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048 -#define ADDRESS_MAX_LEN 256 -#define PATH_ITEM_MAX_LEN 32 - -typedef enum ArweaveRequestType { - ArweaveRequestTypeTransaction = 1, - ArweaveRequestTypeDataItem, - ArweaveRequestTypeMessage, - ArweaveRequestTypeUnknown, -} ArweaveRequestType; - -#if defined(BUILD_MULTI_COINS) -typedef enum ETHAccountType { -#if defined(BUILD_MULTI_COINS) - Bip44Standard, -#endif -#if defined(BUILD_MULTI_COINS) - LedgerLive, -#endif -#if defined(BUILD_MULTI_COINS) - LedgerLegacy, -#endif -} ETHAccountType; -#endif - -typedef enum ErrorCodes { - Success = 0, - InvalidMasterFingerprint, - MasterFingerprintMismatch, - InvalidHDPath, - UnsupportedTransaction, - InvalidXPub, - SignFailure, - UnexpectedError, - InvalidHex, - WebAuthFailed, - InvalidData, - CborDecodeError = 20, - CborEncodeError, - URDecodeError, - UREncodeError, - NotSupportURTypeError, - NotAnUr, - URTypeUnspecified, - URProtobufDecodeError, - URProtobufEncodeError, - URGzipDecodeError, - URGzipEnCodeError, - KeystoreSeedError = 40, - KeystoreDerivationError, - KeystoreXPubError, - KeystoreInvalidDerivationPath, - KeystoreDeivePubkey, - KeystoreGenerateSigningKeyError, - KeystoreRSASignError, - KeystoreRSAVerifyError, - KeystoreInvalidDataError, - KeystoreZcashOrchardSignError, - BitcoinInvalidInput = 100, - BitcoinInvalidOutput, - BitcoinInvalidPsbt, - BitcoinInvalidTransaction, - BitcoinNoInputs, - BitcoinNoOutputs, - BitcoinNoMyInputs, - BitcoinInputValueTampered, - BitcoinSignFailure, - BitcoinAddressError, - BitcoinGetKeyError, - BitcoinSignLegacyTxError, - BitcoinUnsupportedTransaction, - BitcoinUnsupportedNetwork, - BitcoinTransactionConsensusEncodeError, - BitcoinPushBytesFailed, - BitcoinInvalidHex, - BitcoinBase58Error, - BitcoinKeystoreError, - BitcoinInvalidParseContext, - BitcoinInvalidRawTxCryptoBytes, - BitcoinInvalidTxData, - BitcoinUnsupportedScriptType, - BitcoinBech32DecodeError, - BitcoinWitnessProgramError, - BitcoinMultiSigWalletParseError, - BitcoinMultiSigWalletNotMyWallet, - BitcoinMultiSigWalletAddressCalError, - BitcoinMultiSigWalletImportXpubError, - BitcoinMultiSigWalletCrateError, - BitcoinMultiSigWalletFormatError, - BitcoinMultiSigNetworkError, - BitcoinMultiSigInputError, - BitcoinDerivePublicKeyError, - BitcoinWalletTypeError, - EthereumRlpDecodingError = 200, - EthereumInvalidTransaction, - EthereumSignFailure, - EthereumInvalidHDPath, - EthereumKeystoreError, - EthereumInvalidAddressError, - EthereumInvalidUtf8Error, - EthereumInvalidContractABI, - EthereumDecodeContractDataError, - EthereumInvalidTypedData, - EthereumHashTypedDataError, - TronInvalidRawTxCryptoBytes = 300, - TronInvalidParseContext, - TronBase58Error, - TronSignFailure, - TronProtobufError, - TronParseNumberError, - TronNoMyInputs, - CompanionAppProtobufError = 400, - CompanionAppInvalidParseContext, - CompanionAppSignTxFailed, - CompanionAppCheckTxFailed, - CardanoInvalidTransaction = 500, - CardanoAddressEncodingError, - SolanaAddressEncodingError = 600, - SolanaKeystoreError, - SolanaUnsupportedProgram, - SolanaInvalidData, - SolanaAccountNotFound, - SolanaProgramError, - SolanaParseTxError, - NearKeystoreError = 700, - NearSignFailure, - NearParseTxError, - XRPSignFailure = 800, - XRPInvalidData, - XRPParseTxError, - CosmosSignFailure = 900, - CosmosKeystoreError, - CosmosInvalidData, - CosmosParseTxError, - AptosSignFailure = 1000, - AptosKeystoreError, - AptosInvalidData, - AptosParseTxError, - SuiSignFailure = 1100, - SuiInvalidData, - SuiParseTxError, - ArweaveSignFailure = 1200, - ArweaveKeystoreError, - ArweaveInvalidData, - ArweaveParseTxError, - ArweaveParseAOTxError, - TonUnknownError = 1300, - TonMnemonicError, - TonTransactionError, - InvalidProof, - TonTransactionJsonError, - AddressError, - StellarAddressError = 1400, - StellarInvalidData, - StellarParseTxError, - StellarKeystoreError, - ZcashGenerateAddressError = 1500, - ZcashSigningError, - ZcashInvalidPczt, -} ErrorCodes; - -typedef enum NetworkType { - MainNet, - TestNet, -} NetworkType; - -typedef enum QRCodeType { - CryptoPSBT, - CryptoMultiAccounts, - CryptoAccount, - Bytes, - BtcSignRequest, - SeedSignerMessage, -#if defined(BUILD_MULTI_COINS) - KeystoneSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - EthSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - SolSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - NearSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoSignTxHashRequest, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoSignDataRequest, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoCatalystVotingRegistrationRequest, -#endif -#if defined(BUILD_MULTI_COINS) - CosmosSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - EvmSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - SuiSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - SuiSignHashRequest, -#endif -#if defined(BUILD_MULTI_COINS) - AptosSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - QRHardwareCall, -#endif -#if defined(BUILD_MULTI_COINS) - ArweaveSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - StellarSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - TonSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - ZcashPczt, -#endif - URTypeUnKnown, -} QRCodeType; - -typedef enum QRProtocol { - QRCodeTypeText, - QRCodeTypeUR, -} QRProtocol; - -typedef enum ViewType { - BtcNativeSegwitTx, - BtcSegwitTx, - BtcLegacyTx, - BtcTx, - BtcMsg, -#if defined(BUILD_MULTI_COINS) - LtcTx, -#endif -#if defined(BUILD_MULTI_COINS) - DashTx, -#endif -#if defined(BUILD_MULTI_COINS) - BchTx, -#endif -#if defined(BUILD_MULTI_COINS) - EthTx, -#endif -#if defined(BUILD_MULTI_COINS) - EthPersonalMessage, -#endif -#if defined(BUILD_MULTI_COINS) - EthTypedData, -#endif -#if defined(BUILD_MULTI_COINS) - TronTx, -#endif -#if defined(BUILD_MULTI_COINS) - SolanaTx, -#endif -#if defined(BUILD_MULTI_COINS) - SolanaMessage, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoTx, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoSignData, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoCatalystVotingRegistration, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoSignTxHash, -#endif -#if defined(BUILD_MULTI_COINS) - NearTx, -#endif -#if defined(BUILD_MULTI_COINS) - XRPTx, -#endif -#if defined(BUILD_MULTI_COINS) - CosmosTx, -#endif -#if defined(BUILD_MULTI_COINS) - CosmosEvmTx, -#endif -#if defined(BUILD_MULTI_COINS) - SuiTx, -#endif -#if defined(BUILD_MULTI_COINS) - SuiSignMessageHash, -#endif -#if defined(BUILD_MULTI_COINS) - ArweaveTx, -#endif -#if defined(BUILD_MULTI_COINS) - ArweaveMessage, -#endif -#if defined(BUILD_MULTI_COINS) - ArweaveDataItem, -#endif -#if defined(BUILD_MULTI_COINS) - StellarTx, -#endif -#if defined(BUILD_MULTI_COINS) - StellarHash, -#endif -#if defined(BUILD_MULTI_COINS) - TonTx, -#endif -#if defined(BUILD_MULTI_COINS) - TonSignProof, -#endif -#if defined(BUILD_MULTI_COINS) - ZcashTx, -#endif -#if defined(BUILD_MULTI_COINS) - AptosTx, -#endif - WebAuthResult, -#if defined(BUILD_MULTI_COINS) - KeyDerivationRequest, -#endif - ViewTypeUnKnown, -} ViewType; - -typedef char *PtrString; - -typedef struct SimpleResponse_u8 { - uint8_t *data; - uint32_t error_code; - PtrString error_message; -} SimpleResponse_u8; - -typedef uint8_t *PtrBytes; - -typedef struct SimpleResponse_c_char { - char *data; - uint32_t error_code; - PtrString error_message; -} SimpleResponse_c_char; - -typedef struct TransactionCheckResult { - uint32_t error_code; - PtrString error_message; -} TransactionCheckResult; - -typedef struct TransactionCheckResult *Ptr_TransactionCheckResult; - -typedef void *PtrVoid; - -typedef PtrVoid PtrUR; - -typedef PtrVoid PtrDecoder; - -typedef struct URParseResult { - bool is_multi_part; - uint32_t progress; - enum ViewType t; - enum QRCodeType ur_type; - PtrUR data; - PtrDecoder decoder; - uint32_t error_code; - PtrString error_message; -} URParseResult; - -typedef struct URParseResult *PtrT_URParseResult; - -typedef struct URParseMultiResult { - bool is_complete; - enum ViewType t; - enum QRCodeType ur_type; - uint32_t progress; - PtrUR data; - uint32_t error_code; - PtrString error_message; -} URParseMultiResult; - -typedef struct URParseMultiResult *PtrT_URParseMultiResult; - -typedef PtrVoid PtrEncoder; - -typedef struct UREncodeResult { - bool is_multi_part; - char *data; - PtrEncoder encoder; - uint32_t error_code; - char *error_message; -} UREncodeResult; - -typedef struct UREncodeResult *PtrT_UREncodeResult; - -typedef struct UREncodeMultiResult { - char *data; - uint32_t error_code; - char *error_message; -} UREncodeMultiResult; - -typedef struct UREncodeMultiResult *PtrT_UREncodeMultiResult; - -typedef struct SimpleResponse_u8 *PtrT_SimpleResponse_u8; - -typedef struct SimpleResponse_c_char *PtrT_SimpleResponse_c_char; - -typedef uint8_t *PtrT_u8; - -typedef struct VecFFI_u8 { - PtrT_u8 data; - size_t size; - size_t cap; -} VecFFI_u8; - -typedef struct VecFFI_u8 *PtrT_VecFFI_u8; - -typedef struct URParseResult *Ptr_URParseResult; - -typedef struct TransactionCheckResult *PtrT_TransactionCheckResult; - -typedef const void *ConstPtrVoid; - -typedef ConstPtrVoid ConstPtrUR; - -typedef struct ExtendedPublicKey { - PtrString path; - PtrString xpub; -} ExtendedPublicKey; - -typedef struct ExtendedPublicKey *PtrT_ExtendedPublicKey; - -typedef struct CSliceFFI_ExtendedPublicKey { - PtrT_ExtendedPublicKey data; - size_t size; -} CSliceFFI_ExtendedPublicKey; - -typedef struct CSliceFFI_ExtendedPublicKey *PtrT_CSliceFFI_ExtendedPublicKey; - -typedef struct AccountConfig { - PtrString hd_path; - PtrString x_pub; - int32_t address_length; - bool is_multi_sign; -} AccountConfig; - -typedef struct CoinConfig { - bool is_active; - PtrString coin_code; - struct AccountConfig *accounts; - uint32_t accounts_length; -} CoinConfig; - -typedef struct CoinConfig *PtrT_CoinConfig; - -typedef struct UREncodeResult *Ptr_UREncodeResult; - -typedef struct CSliceFFI_ExtendedPublicKey *Ptr_CSliceFFI_ExtendedPublicKey; - -#if defined(BUILD_MULTI_COINS) -typedef struct KeyDerivationSchema { - PtrString key_path; - PtrString curve; - PtrString algo; - PtrString chain_type; - bool is_ada; -} KeyDerivationSchema; -#endif - -typedef struct KeyDerivationSchema *PtrT_KeyDerivationSchema; - -typedef struct VecFFI_KeyDerivationSchema { - PtrT_KeyDerivationSchema data; - size_t size; - size_t cap; -} VecFFI_KeyDerivationSchema; - -typedef struct VecFFI_KeyDerivationSchema *Ptr_VecFFI_KeyDerivationSchema; - -#if defined(BUILD_MULTI_COINS) -typedef struct KeyDerivationRequestData { - Ptr_VecFFI_KeyDerivationSchema schemas; -} KeyDerivationRequestData; -#endif - -typedef struct KeyDerivationRequestData *Ptr_KeyDerivationRequestData; - -#if defined(BUILD_MULTI_COINS) -typedef struct QRHardwareCallData { - PtrString call_type; - PtrString origin; - Ptr_KeyDerivationRequestData key_derivation; - PtrString version; -} QRHardwareCallData; -#endif - -typedef struct Response_QRHardwareCallData { - struct QRHardwareCallData *data; - uint32_t error_code; - PtrString error_message; -} Response_QRHardwareCallData; - -typedef struct Response_QRHardwareCallData *Ptr_Response_QRHardwareCallData; - -typedef struct Response_bool { - bool *data; - uint32_t error_code; - PtrString error_message; -} Response_bool; - -#if defined(BUILD_MULTI_COINS) -typedef struct KeplrAccount { - PtrString name; - PtrString path; - PtrString xpub; -} KeplrAccount; -#endif - -typedef struct KeplrAccount *PtrT_KeplrAccount; - -typedef struct CSliceFFI_KeplrAccount { - PtrT_KeplrAccount data; - size_t size; -} CSliceFFI_KeplrAccount; - -typedef struct CSliceFFI_KeplrAccount *PtrT_CSliceFFI_KeplrAccount; - -typedef struct Response_QRHardwareCallData *PtrT_Response_QRHardwareCallData; - -typedef struct ZcashKey { - PtrString key_text; - PtrString key_name; - uint32_t index; -} ZcashKey; - -typedef struct ZcashKey *PtrT_ZcashKey; - -typedef struct CSliceFFI_ZcashKey { - PtrT_ZcashKey data; - size_t size; -} CSliceFFI_ZcashKey; - -typedef struct CSliceFFI_ZcashKey *Ptr_CSliceFFI_ZcashKey; - -typedef struct DisplayAptosTx { - PtrString detail; - bool is_msg; -} DisplayAptosTx; - -typedef struct TransactionParseResult_DisplayAptosTx { - struct DisplayAptosTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayAptosTx; - -typedef struct TransactionParseResult_DisplayAptosTx *PtrT_TransactionParseResult_DisplayAptosTx; - -typedef struct SimpleResponse_ArweaveRequestType { - enum ArweaveRequestType *data; - uint32_t error_code; - PtrString error_message; -} SimpleResponse_ArweaveRequestType; - -typedef struct DisplayArweaveMessage { - PtrString message; - PtrString raw_message; -} DisplayArweaveMessage; - -typedef struct TransactionParseResult_DisplayArweaveMessage { - struct DisplayArweaveMessage *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayArweaveMessage; - -typedef struct TransactionParseResult_DisplayArweaveMessage *PtrT_TransactionParseResult_DisplayArweaveMessage; - -typedef struct DisplayArweaveTx { - PtrString value; - PtrString fee; - PtrString from; - PtrString to; - PtrString detail; -} DisplayArweaveTx; - -typedef struct TransactionParseResult_DisplayArweaveTx { - struct DisplayArweaveTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayArweaveTx; - -typedef struct TransactionParseResult_DisplayArweaveTx *PtrT_TransactionParseResult_DisplayArweaveTx; - -typedef struct DisplayTag { - PtrString name; - PtrString value; -} DisplayTag; - -typedef struct DisplayTag *PtrT_DisplayTag; - -typedef struct VecFFI_DisplayTag { - PtrT_DisplayTag data; - size_t size; - size_t cap; -} VecFFI_DisplayTag; - -typedef struct VecFFI_DisplayTag *Ptr_VecFFI_DisplayTag; - -typedef struct DisplayArweaveDataItem { - PtrString owner; - PtrString target; - PtrString anchor; - Ptr_VecFFI_DisplayTag tags; - PtrString data; -} DisplayArweaveDataItem; - -typedef struct TransactionParseResult_DisplayArweaveDataItem { - struct DisplayArweaveDataItem *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayArweaveDataItem; - -typedef struct TransactionParseResult_DisplayArweaveDataItem *PtrT_TransactionParseResult_DisplayArweaveDataItem; - -typedef struct DisplayArweaveAOTransfer { - PtrString from; - PtrString to; - PtrString quantity; - PtrString token_id; - Ptr_VecFFI_DisplayTag other_info; -} DisplayArweaveAOTransfer; - -typedef struct TransactionParseResult_DisplayArweaveAOTransfer { - struct DisplayArweaveAOTransfer *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayArweaveAOTransfer; - -typedef struct TransactionParseResult_DisplayArweaveAOTransfer *PtrT_TransactionParseResult_DisplayArweaveAOTransfer; - -typedef struct DisplayTxOverviewInput { - PtrString address; -} DisplayTxOverviewInput; - -typedef struct DisplayTxOverviewInput *PtrT_DisplayTxOverviewInput; - -typedef struct VecFFI_DisplayTxOverviewInput { - PtrT_DisplayTxOverviewInput data; - size_t size; - size_t cap; -} VecFFI_DisplayTxOverviewInput; - -typedef struct VecFFI_DisplayTxOverviewInput *PtrT_VecFFI_DisplayTxOverviewInput; - -typedef struct DisplayTxOverviewOutput { - PtrString address; -} DisplayTxOverviewOutput; - -typedef struct DisplayTxOverviewOutput *PtrT_DisplayTxOverviewOutput; - -typedef struct VecFFI_DisplayTxOverviewOutput { - PtrT_DisplayTxOverviewOutput data; - size_t size; - size_t cap; -} VecFFI_DisplayTxOverviewOutput; - -typedef struct VecFFI_DisplayTxOverviewOutput *PtrT_VecFFI_DisplayTxOverviewOutput; - -typedef struct DisplayTxOverview { - PtrString total_output_amount; - PtrString fee_amount; - PtrString total_output_sat; - PtrString fee_sat; - PtrT_VecFFI_DisplayTxOverviewInput from; - PtrT_VecFFI_DisplayTxOverviewOutput to; - PtrString network; - bool is_multisig; - bool fee_larger_than_amount; - PtrString sign_status; - bool need_sign; -} DisplayTxOverview; - -typedef struct DisplayTxDetailInput { - bool has_address; - PtrString address; - PtrString amount; - bool is_mine; - PtrString path; - bool is_external; -} DisplayTxDetailInput; - -typedef struct DisplayTxDetailInput *PtrT_DisplayTxDetailInput; - -typedef struct VecFFI_DisplayTxDetailInput { - PtrT_DisplayTxDetailInput data; - size_t size; - size_t cap; -} VecFFI_DisplayTxDetailInput; - -typedef struct VecFFI_DisplayTxDetailInput *PtrT_VecFFI_DisplayTxDetailInput; - -typedef struct DisplayTxDetailOutput { - PtrString address; - PtrString amount; - bool is_mine; - PtrString path; - bool is_external; -} DisplayTxDetailOutput; - -typedef struct DisplayTxDetailOutput *PtrT_DisplayTxDetailOutput; - -typedef struct VecFFI_DisplayTxDetailOutput { - PtrT_DisplayTxDetailOutput data; - size_t size; - size_t cap; -} VecFFI_DisplayTxDetailOutput; - -typedef struct VecFFI_DisplayTxDetailOutput *PtrT_VecFFI_DisplayTxDetailOutput; - -typedef struct DisplayTxDetail { - PtrString total_input_amount; - PtrString total_output_amount; - PtrString fee_amount; - PtrT_VecFFI_DisplayTxDetailInput from; - PtrT_VecFFI_DisplayTxDetailOutput to; - PtrString network; - PtrString total_input_sat; - PtrString total_output_sat; - PtrString fee_sat; - PtrString sign_status; -} DisplayTxDetail; - -typedef struct DisplayTx { - struct DisplayTxOverview *overview; - struct DisplayTxDetail *detail; -} DisplayTx; - -typedef struct TransactionParseResult_DisplayTx { - struct DisplayTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayTx; - -typedef struct DisplayBtcMsg { - PtrString detail; - PtrString address; -} DisplayBtcMsg; - -typedef struct TransactionParseResult_DisplayBtcMsg { - struct DisplayBtcMsg *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayBtcMsg; - -typedef struct TransactionParseResult_DisplayBtcMsg *Ptr_TransactionParseResult_DisplayBtcMsg; - -typedef PtrString *PtrT_PtrString; - -typedef struct VecFFI_PtrString { - PtrT_PtrString data; - size_t size; - size_t cap; -} VecFFI_PtrString; - -typedef struct VecFFI_PtrString *PtrT_VecFFI_PtrString; - -typedef struct MultiSigXPubItem { - PtrString xfp; - PtrString xpub; -} MultiSigXPubItem; - -typedef struct MultiSigXPubItem *PtrT_MultiSigXPubItem; - -typedef struct VecFFI_MultiSigXPubItem { - PtrT_MultiSigXPubItem data; - size_t size; - size_t cap; -} VecFFI_MultiSigXPubItem; - -typedef struct VecFFI_MultiSigXPubItem *PtrT_VecFFI_MultiSigXPubItem; - -typedef struct MultiSigWallet { - PtrString creator; - PtrString name; - PtrString policy; - uint32_t threshold; - uint32_t total; - PtrT_VecFFI_PtrString derivations; - PtrString format; - PtrT_VecFFI_MultiSigXPubItem xpub_items; - PtrString verify_code; - PtrString config_text; - uint32_t network; -} MultiSigWallet; - -typedef struct MultiSigWallet *PtrT_MultiSigWallet; - -typedef struct Response_MultiSigWallet { - struct MultiSigWallet *data; - uint32_t error_code; - PtrString error_message; -} Response_MultiSigWallet; - -typedef struct Response_MultiSigWallet *Ptr_Response_MultiSigWallet; - -typedef struct SimpleResponse_c_char *Ptr_SimpleResponse_c_char; - -typedef struct MultiSigXPubInfoItem { - PtrString path; - PtrString xfp; - PtrString xpub; -} MultiSigXPubInfoItem; - -typedef struct MultiSigXPubInfoItem *PtrT_MultiSigXPubInfoItem; - -typedef struct MultisigSignResult { - Ptr_UREncodeResult ur_result; - PtrString sign_status; - bool is_completed; - PtrBytes psbt_hex; - uint32_t psbt_len; -} MultisigSignResult; - -typedef struct MultisigSignResult *PtrT_MultisigSignResult; - -typedef struct PsbtSignResult { - PtrString base_str; - PtrString hex_str; - PtrT_UREncodeResult ur_result; -} PsbtSignResult; - -typedef struct Response_PsbtSignResult { - struct PsbtSignResult *data; - uint32_t error_code; - PtrString error_message; -} Response_PsbtSignResult; - -typedef struct Response_PsbtSignResult *PtrT_Response_PsbtSignResult; - -typedef struct TransactionParseResult_DisplayTx *PtrT_TransactionParseResult_DisplayTx; - -typedef struct TransactionParseResult_DisplayBtcMsg *PtrT_TransactionParseResult_DisplayBtcMsg; - -typedef struct VecFFI_PtrString *Ptr_VecFFI_PtrString; - -typedef struct DisplayCardanoSignTxHash { - PtrString network; - Ptr_VecFFI_PtrString path; - PtrString tx_hash; - Ptr_VecFFI_PtrString address_list; -} DisplayCardanoSignTxHash; - -typedef struct TransactionParseResult_DisplayCardanoSignTxHash { - struct DisplayCardanoSignTxHash *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayCardanoSignTxHash; - -typedef struct TransactionParseResult_DisplayCardanoSignTxHash *PtrT_TransactionParseResult_DisplayCardanoSignTxHash; - -typedef struct DisplayCardanoSignData { - PtrString payload; - PtrString derivation_path; - PtrString message_hash; - PtrString xpub; -} DisplayCardanoSignData; - -typedef struct TransactionParseResult_DisplayCardanoSignData { - struct DisplayCardanoSignData *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayCardanoSignData; - -typedef struct TransactionParseResult_DisplayCardanoSignData *PtrT_TransactionParseResult_DisplayCardanoSignData; - -typedef struct DisplayCardanoCatalyst { - PtrString nonce; - PtrString stake_key; - PtrString rewards; - Ptr_VecFFI_PtrString vote_keys; -} DisplayCardanoCatalyst; - -typedef struct TransactionParseResult_DisplayCardanoCatalyst { - struct DisplayCardanoCatalyst *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayCardanoCatalyst; - -typedef struct TransactionParseResult_DisplayCardanoCatalyst *PtrT_TransactionParseResult_DisplayCardanoCatalyst; - -typedef struct DisplayCardanoFrom { - PtrString address; - PtrString amount; - bool has_path; - PtrString path; -} DisplayCardanoFrom; - -typedef struct DisplayCardanoFrom *PtrT_DisplayCardanoFrom; - -typedef struct VecFFI_DisplayCardanoFrom { - PtrT_DisplayCardanoFrom data; - size_t size; - size_t cap; -} VecFFI_DisplayCardanoFrom; - -typedef struct VecFFI_DisplayCardanoFrom *PtrT_VecFFI_DisplayCardanoFrom; - -typedef struct DisplayCardanoTo { - PtrString address; - PtrString amount; - bool has_assets; - PtrString assets_text; -} DisplayCardanoTo; - -typedef struct DisplayCardanoTo *PtrT_DisplayCardanoTo; - -typedef struct VecFFI_DisplayCardanoTo { - PtrT_DisplayCardanoTo data; - size_t size; - size_t cap; -} VecFFI_DisplayCardanoTo; - -typedef struct VecFFI_DisplayCardanoTo *PtrT_VecFFI_DisplayCardanoTo; - -typedef struct DisplayCertField { - PtrString label; - PtrString value; -} DisplayCertField; - -typedef struct DisplayCertField *PtrT_DisplayCertField; - -typedef struct VecFFI_DisplayCertField { - PtrT_DisplayCertField data; - size_t size; - size_t cap; -} VecFFI_DisplayCertField; - -typedef struct VecFFI_DisplayCertField *Ptr_VecFFI_DisplayCertField; - -typedef struct DisplayCardanoCertificate { - PtrString cert_type; - Ptr_VecFFI_DisplayCertField fields; -} DisplayCardanoCertificate; - -typedef struct DisplayCardanoCertificate *PtrT_DisplayCardanoCertificate; - -typedef struct VecFFI_DisplayCardanoCertificate { - PtrT_DisplayCardanoCertificate data; - size_t size; - size_t cap; -} VecFFI_DisplayCardanoCertificate; - -typedef struct VecFFI_DisplayCardanoCertificate *Ptr_VecFFI_DisplayCardanoCertificate; - -typedef struct DisplayCardanoWithdrawal { - PtrString address; - PtrString amount; -} DisplayCardanoWithdrawal; - -typedef struct DisplayCardanoWithdrawal *PtrT_DisplayCardanoWithdrawal; - -typedef struct VecFFI_DisplayCardanoWithdrawal { - PtrT_DisplayCardanoWithdrawal data; - size_t size; - size_t cap; -} VecFFI_DisplayCardanoWithdrawal; - -typedef struct VecFFI_DisplayCardanoWithdrawal *Ptr_VecFFI_DisplayCardanoWithdrawal; - -typedef struct DisplayVotingProcedure { - PtrString voter; - PtrString transaction_id; - PtrString index; - PtrString vote; -} DisplayVotingProcedure; - -typedef struct DisplayVotingProcedure *PtrT_DisplayVotingProcedure; - -typedef struct VecFFI_DisplayVotingProcedure { - PtrT_DisplayVotingProcedure data; - size_t size; - size_t cap; -} VecFFI_DisplayVotingProcedure; - -typedef struct VecFFI_DisplayVotingProcedure *Ptr_VecFFI_DisplayVotingProcedure; - -typedef struct DisplayVotingProposal { - PtrString anchor; -} DisplayVotingProposal; - -typedef struct DisplayVotingProposal *PtrT_DisplayVotingProposal; - -typedef struct VecFFI_DisplayVotingProposal { - PtrT_DisplayVotingProposal data; - size_t size; - size_t cap; -} VecFFI_DisplayVotingProposal; - -typedef struct VecFFI_DisplayVotingProposal *Ptr_VecFFI_DisplayVotingProposal; - -typedef struct DisplayCardanoTx { - PtrT_VecFFI_DisplayCardanoFrom from; - PtrT_VecFFI_DisplayCardanoTo to; - PtrString fee; - PtrString network; - PtrString total_input; - PtrString total_output; - Ptr_VecFFI_DisplayCardanoCertificate certificates; - Ptr_VecFFI_DisplayCardanoWithdrawal withdrawals; - PtrString auxiliary_data; - Ptr_VecFFI_DisplayVotingProcedure voting_procedures; - Ptr_VecFFI_DisplayVotingProposal voting_proposals; -} DisplayCardanoTx; - -typedef struct TransactionParseResult_DisplayCardanoTx { - struct DisplayCardanoTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayCardanoTx; - -typedef struct TransactionParseResult_DisplayCardanoTx *PtrT_TransactionParseResult_DisplayCardanoTx; - -typedef struct DisplayCosmosTxOverview { - PtrString display_type; - PtrString method; - PtrString network; - PtrString send_value; - PtrString send_from; - PtrString send_to; - PtrString delegate_value; - PtrString delegate_from; - PtrString delegate_to; - PtrString undelegate_value; - PtrString undelegate_to; - PtrString undelegate_validator; - PtrString redelegate_value; - PtrString redelegate_to; - PtrString redelegate_new_validator; - PtrString withdraw_reward_to; - PtrString withdraw_reward_validator; - PtrString transfer_from; - PtrString transfer_to; - PtrString transfer_value; - PtrString vote_voted; - PtrString vote_proposal; - PtrString vote_voter; - PtrString overview_list; -} DisplayCosmosTxOverview; - -typedef struct DisplayCosmosTxOverview *PtrT_DisplayCosmosTxOverview; - -typedef struct DisplayCosmosTx { - PtrT_DisplayCosmosTxOverview overview; - PtrString detail; -} DisplayCosmosTx; - -typedef struct TransactionParseResult_DisplayCosmosTx { - struct DisplayCosmosTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayCosmosTx; - -typedef struct TransactionParseResult_DisplayCosmosTx *PtrT_TransactionParseResult_DisplayCosmosTx; - -typedef struct DisplayETHOverview { - PtrString value; - PtrString max_txn_fee; - PtrString gas_price; - PtrString gas_limit; - PtrString from; - PtrString to; -} DisplayETHOverview; - -typedef struct DisplayETHOverview *PtrT_DisplayETHOverview; - -typedef struct DisplayETHDetail { - PtrString value; - PtrString max_txn_fee; - PtrString max_fee; - PtrString max_priority; - PtrString max_fee_price; - PtrString max_priority_price; - PtrString gas_price; - PtrString gas_limit; - PtrString from; - PtrString to; - PtrString input; -} DisplayETHDetail; - -typedef struct DisplayETHDetail *PtrT_DisplayETHDetail; - -typedef struct DisplayETH { - PtrString tx_type; - uint64_t chain_id; - PtrT_DisplayETHOverview overview; - PtrT_DisplayETHDetail detail; -} DisplayETH; - -typedef struct TransactionParseResult_DisplayETH { - struct DisplayETH *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayETH; - -typedef struct TransactionParseResult_DisplayETH *PtrT_TransactionParseResult_DisplayETH; - -typedef struct DisplayETHPersonalMessage { - PtrString raw_message; - PtrString utf8_message; - PtrString from; -} DisplayETHPersonalMessage; - -typedef struct TransactionParseResult_DisplayETHPersonalMessage { - struct DisplayETHPersonalMessage *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayETHPersonalMessage; - -typedef struct TransactionParseResult_DisplayETHPersonalMessage *PtrT_TransactionParseResult_DisplayETHPersonalMessage; - -typedef struct DisplayETHTypedData { - PtrString name; - PtrString version; - PtrString chain_id; - PtrString verifying_contract; - PtrString salt; - PtrString primary_type; - PtrString message; - PtrString from; -} DisplayETHTypedData; - -typedef struct TransactionParseResult_DisplayETHTypedData { - struct DisplayETHTypedData *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayETHTypedData; - -typedef struct TransactionParseResult_DisplayETHTypedData *PtrT_TransactionParseResult_DisplayETHTypedData; - -typedef struct EthParsedErc20Transaction { - PtrString to; - PtrString value; -} EthParsedErc20Transaction; - -typedef struct TransactionParseResult_EthParsedErc20Transaction { - struct EthParsedErc20Transaction *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_EthParsedErc20Transaction; - -typedef struct TransactionParseResult_EthParsedErc20Transaction *PtrT_TransactionParseResult_EthParsedErc20Transaction; - -typedef struct DisplayContractParam { - PtrString name; - PtrString value; -} DisplayContractParam; - -typedef struct DisplayContractParam *PtrT_DisplayContractParam; - -typedef struct VecFFI_DisplayContractParam { - PtrT_DisplayContractParam data; - size_t size; - size_t cap; -} VecFFI_DisplayContractParam; - -typedef struct VecFFI_DisplayContractParam *PtrT_VecFFI_DisplayContractParam; - -typedef struct DisplayContractData { - PtrString contract_name; - PtrString method_name; - PtrT_VecFFI_DisplayContractParam params; -} DisplayContractData; - -typedef struct Response_DisplayContractData { - struct DisplayContractData *data; - uint32_t error_code; - PtrString error_message; -} Response_DisplayContractData; - -typedef struct Response_DisplayContractData *Ptr_Response_DisplayContractData; - -typedef struct Response_DisplayContractData *PtrT_Response_DisplayContractData; - -typedef struct DisplayNearTxOverviewGeneralAction { - PtrString action; -} DisplayNearTxOverviewGeneralAction; - -typedef struct DisplayNearTxOverviewGeneralAction *PtrT_DisplayNearTxOverviewGeneralAction; - -typedef struct VecFFI_DisplayNearTxOverviewGeneralAction { - PtrT_DisplayNearTxOverviewGeneralAction data; - size_t size; - size_t cap; -} VecFFI_DisplayNearTxOverviewGeneralAction; - -typedef struct VecFFI_DisplayNearTxOverviewGeneralAction *PtrT_VecFFI_DisplayNearTxOverviewGeneralAction; - -typedef struct DisplayNearTxOverview { - PtrString display_type; - PtrString main_action; - PtrString transfer_value; - PtrString transfer_from; - PtrString transfer_to; - PtrT_VecFFI_DisplayNearTxOverviewGeneralAction action_list; -} DisplayNearTxOverview; - -typedef struct DisplayNearTxOverview *PtrT_DisplayNearTxOverview; - -typedef struct DisplayNearTx { - PtrString network; - PtrT_DisplayNearTxOverview overview; - PtrString detail; -} DisplayNearTx; - -typedef struct TransactionParseResult_DisplayNearTx { - struct DisplayNearTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayNearTx; - -typedef struct TransactionParseResult_DisplayNearTx *PtrT_TransactionParseResult_DisplayNearTx; - -typedef struct DisplaySolanaTxOverviewVotesOn { - PtrString slot; -} DisplaySolanaTxOverviewVotesOn; - -typedef struct DisplaySolanaTxOverviewVotesOn *PtrT_DisplaySolanaTxOverviewVotesOn; - -typedef struct VecFFI_DisplaySolanaTxOverviewVotesOn { - PtrT_DisplaySolanaTxOverviewVotesOn data; - size_t size; - size_t cap; -} VecFFI_DisplaySolanaTxOverviewVotesOn; - -typedef struct VecFFI_DisplaySolanaTxOverviewVotesOn *PtrT_VecFFI_DisplaySolanaTxOverviewVotesOn; - -typedef struct DisplaySolanaTxOverviewGeneral { - PtrString program; - PtrString method; -} DisplaySolanaTxOverviewGeneral; - -typedef struct DisplaySolanaTxOverviewGeneral *PtrT_DisplaySolanaTxOverviewGeneral; - -typedef struct VecFFI_DisplaySolanaTxOverviewGeneral { - PtrT_DisplaySolanaTxOverviewGeneral data; - size_t size; - size_t cap; -} VecFFI_DisplaySolanaTxOverviewGeneral; - -typedef struct VecFFI_DisplaySolanaTxOverviewGeneral *PtrT_VecFFI_DisplaySolanaTxOverviewGeneral; - -typedef struct Instruction { - PtrT_VecFFI_PtrString accounts; - PtrString data; - PtrString program_address; -} Instruction; - -typedef struct Instruction *PtrT_Instruction; - -typedef struct VecFFI_Instruction { - PtrT_Instruction data; - size_t size; - size_t cap; -} VecFFI_Instruction; - -typedef struct VecFFI_Instruction *PtrT_VecFFI_Instruction; - -typedef struct DisplaySolanaTxOverviewUnknownInstructions { - PtrT_VecFFI_PtrString overview_accounts; - PtrT_VecFFI_Instruction overview_instructions; -} DisplaySolanaTxOverviewUnknownInstructions; - -typedef struct DisplaySolanaTxOverviewUnknownInstructions *PtrT_DisplaySolanaTxOverviewUnknownInstructions; - -typedef struct ProgramOverviewTransfer { - PtrString value; - PtrString main_action; - PtrString from; - PtrString to; -} ProgramOverviewTransfer; - -typedef struct ProgramOverviewTransfer *PtrT_ProgramOverviewTransfer; - -typedef struct VecFFI_ProgramOverviewTransfer { - PtrT_ProgramOverviewTransfer data; - size_t size; - size_t cap; -} VecFFI_ProgramOverviewTransfer; - -typedef struct VecFFI_ProgramOverviewTransfer *PtrT_VecFFI_ProgramOverviewTransfer; - -typedef struct DisplaySolanaTxOverviewSquadsV4MultisigCreate { - PtrString wallet_name; - PtrString wallet_desc; - uint16_t threshold; - uintptr_t member_count; - PtrT_VecFFI_PtrString members; - PtrString total_value; - PtrT_VecFFI_ProgramOverviewTransfer transfers; -} DisplaySolanaTxOverviewSquadsV4MultisigCreate; - -typedef struct DisplaySolanaTxOverviewSquadsV4MultisigCreate *PtrT_DisplaySolanaTxOverviewSquadsV4MultisigCreate; - -typedef struct DisplaySolanaTxProposalOverview { - PtrString program; - PtrString method; - PtrString memo; - PtrString data; -} DisplaySolanaTxProposalOverview; - -typedef struct DisplaySolanaTxProposalOverview *PtrT_DisplaySolanaTxProposalOverview; - -typedef struct VecFFI_DisplaySolanaTxProposalOverview { - PtrT_DisplaySolanaTxProposalOverview data; - size_t size; - size_t cap; -} VecFFI_DisplaySolanaTxProposalOverview; - -typedef struct VecFFI_DisplaySolanaTxProposalOverview *PtrT_VecFFI_DisplaySolanaTxProposalOverview; - -typedef struct DisplaySolanaTxSplTokenTransferOverview { - PtrString source; - PtrString destination; - PtrString authority; - uint8_t decimals; - PtrString amount; - PtrString token_mint_account; - PtrString token_symbol; - PtrString token_name; -} DisplaySolanaTxSplTokenTransferOverview; - -typedef struct DisplaySolanaTxSplTokenTransferOverview *PtrT_DisplaySolanaTxSplTokenTransferOverview; - -typedef struct JupiterV6SwapTokenInfoOverview { - PtrString token_name; - PtrString token_symbol; - PtrString token_address; - PtrString token_amount; - bool exist_in_address_lookup_table; -} JupiterV6SwapTokenInfoOverview; - -typedef struct JupiterV6SwapTokenInfoOverview *PtrT_JupiterV6SwapTokenInfoOverview; - -typedef struct DisplaySolanaTxOverviewJupiterV6Swap { - PtrString program_name; - PtrString program_address; - PtrString instruction_name; - PtrT_JupiterV6SwapTokenInfoOverview token_a_overview; - PtrT_JupiterV6SwapTokenInfoOverview token_b_overview; - PtrString slippage_bps; - PtrString platform_fee_bps; -} DisplaySolanaTxOverviewJupiterV6Swap; - -typedef struct DisplaySolanaTxOverviewJupiterV6Swap *PtrT_DisplaySolanaTxOverviewJupiterV6Swap; - -typedef struct DisplaySolanaTxOverview { - PtrString display_type; - PtrString main_action; - PtrString transfer_value; - PtrString transfer_from; - PtrString transfer_to; - PtrT_VecFFI_DisplaySolanaTxOverviewVotesOn votes_on; - PtrString vote_account; - PtrT_VecFFI_DisplaySolanaTxOverviewGeneral general; - PtrT_DisplaySolanaTxOverviewUnknownInstructions unknown_instructions; - PtrT_DisplaySolanaTxOverviewSquadsV4MultisigCreate squads_multisig_create; - PtrT_VecFFI_DisplaySolanaTxProposalOverview squads_proposal; - PtrT_DisplaySolanaTxSplTokenTransferOverview spl_token_transfer; - PtrT_DisplaySolanaTxOverviewJupiterV6Swap jupiter_v6_swap; -} DisplaySolanaTxOverview; - -typedef struct DisplaySolanaTxOverview *PtrT_DisplaySolanaTxOverview; - -typedef struct DisplaySolanaTx { - PtrString network; - PtrT_DisplaySolanaTxOverview overview; - PtrString detail; -} DisplaySolanaTx; - -typedef struct TransactionParseResult_DisplaySolanaTx { - struct DisplaySolanaTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplaySolanaTx; - -typedef struct TransactionParseResult_DisplaySolanaTx *PtrT_TransactionParseResult_DisplaySolanaTx; - -typedef struct DisplaySolanaMessage { - PtrString raw_message; - PtrString utf8_message; - PtrString from; -} DisplaySolanaMessage; - -typedef struct TransactionParseResult_DisplaySolanaMessage { - struct DisplaySolanaMessage *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplaySolanaMessage; - -typedef struct TransactionParseResult_DisplaySolanaMessage *PtrT_TransactionParseResult_DisplaySolanaMessage; - -typedef struct DisplayStellarTx { - PtrString raw_message; -} DisplayStellarTx; - -typedef struct TransactionParseResult_DisplayStellarTx { - struct DisplayStellarTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayStellarTx; - -typedef struct TransactionParseResult_DisplayStellarTx *PtrT_TransactionParseResult_DisplayStellarTx; - -typedef struct DisplaySuiIntentMessage { - PtrString detail; -} DisplaySuiIntentMessage; - -typedef struct TransactionParseResult_DisplaySuiIntentMessage { - struct DisplaySuiIntentMessage *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplaySuiIntentMessage; - -typedef struct TransactionParseResult_DisplaySuiIntentMessage *PtrT_TransactionParseResult_DisplaySuiIntentMessage; - -typedef struct DisplaySuiSignMessageHash { - PtrString network; - PtrString path; - PtrString from_address; - PtrString message; -} DisplaySuiSignMessageHash; - -typedef struct TransactionParseResult_DisplaySuiSignMessageHash { - struct DisplaySuiSignMessageHash *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplaySuiSignMessageHash; - -typedef struct TransactionParseResult_DisplaySuiSignMessageHash *PtrT_TransactionParseResult_DisplaySuiSignMessageHash; - -typedef struct DisplayTonTransaction { - PtrString amount; - PtrString action; - PtrString to; - PtrString comment; - PtrString data_view; - PtrString raw_data; - PtrString contract_data; -} DisplayTonTransaction; - -typedef struct TransactionParseResult_DisplayTonTransaction { - struct DisplayTonTransaction *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayTonTransaction; - -typedef struct TransactionParseResult_DisplayTonTransaction *PtrT_TransactionParseResult_DisplayTonTransaction; - -typedef struct DisplayTonProof { - PtrString domain; - PtrString payload; - PtrString address; - PtrString raw_message; -} DisplayTonProof; - -typedef struct TransactionParseResult_DisplayTonProof { - struct DisplayTonProof *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayTonProof; - -typedef struct TransactionParseResult_DisplayTonProof *PtrT_TransactionParseResult_DisplayTonProof; - -typedef struct VecFFI_u8 *Ptr_VecFFI_u8; - -typedef struct DisplayTronOverview { - PtrString value; - PtrString method; - PtrString from; - PtrString to; - PtrString network; -} DisplayTronOverview; - -typedef struct DisplayTronDetail { - PtrString value; - PtrString method; - PtrString from; - PtrString to; - PtrString network; - PtrString token; - PtrString contract_address; -} DisplayTronDetail; - -typedef struct DisplayTron { - struct DisplayTronOverview *overview; - struct DisplayTronDetail *detail; -} DisplayTron; - -typedef struct TransactionParseResult_DisplayTron { - struct DisplayTron *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayTron; - -typedef struct TransactionParseResult_DisplayTron *PtrT_TransactionParseResult_DisplayTron; - -typedef struct DisplayXrpTxOverview { - PtrString display_type; - PtrString transaction_type; - PtrString from; - PtrString fee; - PtrString sequence; - PtrString value; - PtrString to; -} DisplayXrpTxOverview; - -typedef struct DisplayXrpTxOverview *PtrT_DisplayXrpTxOverview; - -typedef struct DisplayXrpTx { - PtrString network; - PtrT_DisplayXrpTxOverview overview; - PtrString detail; - PtrString signing_pubkey; -} DisplayXrpTx; - -typedef struct TransactionParseResult_DisplayXrpTx { - struct DisplayXrpTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayXrpTx; - -typedef struct TransactionParseResult_DisplayXrpTx *PtrT_TransactionParseResult_DisplayXrpTx; - -typedef struct DisplayFrom { - PtrString address; - PtrString value; - bool is_mine; -} DisplayFrom; - -typedef struct DisplayFrom *PtrT_DisplayFrom; - -typedef struct VecFFI_DisplayFrom { - PtrT_DisplayFrom data; - size_t size; - size_t cap; -} VecFFI_DisplayFrom; - -typedef struct VecFFI_DisplayFrom *Ptr_VecFFI_DisplayFrom; - -typedef struct DisplayTo { - PtrString address; - PtrString value; - bool is_change; - PtrString memo; -} DisplayTo; - -typedef struct DisplayTo *PtrT_DisplayTo; - -typedef struct VecFFI_DisplayTo { - PtrT_DisplayTo data; - size_t size; - size_t cap; -} VecFFI_DisplayTo; - -typedef struct VecFFI_DisplayTo *Ptr_VecFFI_DisplayTo; - -typedef struct DisplayTransparent { - Ptr_VecFFI_DisplayFrom from; - Ptr_VecFFI_DisplayTo to; -} DisplayTransparent; - -typedef struct DisplayTransparent *Ptr_DisplayTransparent; - -typedef struct DisplayOrchard { - Ptr_VecFFI_DisplayFrom from; - Ptr_VecFFI_DisplayTo to; -} DisplayOrchard; - -typedef struct DisplayOrchard *Ptr_DisplayOrchard; - -typedef struct DisplayPczt { - Ptr_DisplayTransparent transparent; - Ptr_DisplayOrchard orchard; - PtrString total_transfer_value; - PtrString fee_value; - bool has_sapling; -} DisplayPczt; - -typedef struct TransactionParseResult_DisplayPczt { - struct DisplayPczt *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayPczt; - -typedef struct TransactionParseResult_DisplayPczt *Ptr_TransactionParseResult_DisplayPczt; - -typedef struct TransactionParseResult_DisplayPczt *PtrT_TransactionParseResult_DisplayPczt; - -extern const uintptr_t FRAGMENT_MAX_LENGTH_DEFAULT; - -extern void LogRustMalloc(void *p, uint32_t size); - -extern void LogRustFree(void *p); - -extern void LogRustPanic(char *p); - -extern int32_t GenerateTRNGRandomness(uint8_t *randomness, uint8_t len); - -extern void *RustMalloc(int32_t size); - -extern void RustFree(void *p); - -struct SimpleResponse_u8 *get_master_fingerprint(PtrBytes seed, uint32_t seed_len); - -enum ErrorCodes dummy_function_to_export_error_codes(void); - -struct SimpleResponse_c_char *get_extended_pubkey_by_seed(PtrBytes seed, - uint32_t seed_len, - PtrString path); - -struct SimpleResponse_c_char *get_extended_pubkey_bytes_by_seed(PtrBytes seed, - uint32_t seed_len, - PtrString path); - -struct SimpleResponse_c_char *get_ed25519_pubkey_by_seed(PtrBytes seed, - uint32_t seed_len, - PtrString path); - -struct SimpleResponse_u8 *get_rsa_pubkey_by_seed(PtrBytes seed, uint32_t seed_len); - -struct SimpleResponse_c_char *get_bip32_ed25519_extended_pubkey(PtrBytes entropy, - uint32_t entropy_len, - PtrString passphrase, - PtrString path); - -struct SimpleResponse_c_char *get_ledger_bitbox02_master_key(PtrString mnemonic, - PtrString passphrase); - -struct SimpleResponse_c_char *get_icarus_master_key(PtrBytes entropy, - uint32_t entropy_len, - PtrString passphrase); - -struct SimpleResponse_c_char *derive_bip32_ed25519_extended_pubkey(PtrString master_key, - PtrString path); - -struct SimpleResponse_c_char *k1_sign_message_hash_by_private_key(PtrBytes private_key, - PtrBytes message_hash); - -bool k1_verify_signature(PtrBytes signature, PtrBytes message_hash, PtrBytes public_key); - -struct SimpleResponse_u8 *k1_generate_ecdh_sharekey(PtrBytes privkey, - uint32_t privkey_len, - PtrBytes pubkey, - uint32_t pubkey_len); - -struct SimpleResponse_u8 *k1_generate_pubkey_by_privkey(PtrBytes privkey, uint32_t privkey_len); - -struct SimpleResponse_u8 *pbkdf2_rust(PtrBytes password, PtrBytes salt, uint32_t iterations); - -struct SimpleResponse_u8 *pbkdf2_rust_64(PtrBytes password, PtrBytes salt, uint32_t iterations); - -Ptr_TransactionCheckResult tx_check_pass(void); - -struct SimpleResponse_c_char *rust_aes256_cbc_encrypt(PtrString data, - PtrString password, - PtrBytes iv, - uint32_t iv_len); - -struct SimpleResponse_c_char *rust_aes256_cbc_decrypt(PtrString hex_data, - PtrString password, - PtrBytes iv, - uint32_t iv_len); - -struct SimpleResponse_u8 *rust_derive_iv_from_seed(PtrBytes seed, uint32_t seed_len); - -void free_ur_parse_result(PtrT_URParseResult ur_parse_result); - -void free_ur_parse_multi_result(PtrT_URParseMultiResult ptr); - -void free_ur_encode_result(PtrT_UREncodeResult ptr); - -void free_ur_encode_muilt_result(PtrT_UREncodeMultiResult ptr); - -void free_simple_response_u8(PtrT_SimpleResponse_u8 ptr); - -void free_simple_response_c_char(PtrT_SimpleResponse_c_char ptr); - -void free_ptr_string(PtrString ptr); - -void free_rust_value(void *any_ptr); - -void free_VecFFI_u8(PtrT_VecFFI_u8 ptr); - -enum QRProtocol infer_qrcode_type(PtrString qrcode); - -Ptr_URParseResult parse_qrcode_text(PtrString qr); - -void free_TransactionCheckResult(PtrT_TransactionCheckResult ptr); - -struct UREncodeMultiResult *get_next_part(PtrEncoder ptr); - -struct URParseResult *parse_ur(PtrString ur); - -struct URParseMultiResult *receive(PtrString ur, PtrDecoder decoder); - -PtrString calculate_auth_code(ConstPtrUR web_auth_data, - PtrBytes rsa_key_n, - uint32_t rsa_key_n_len, - PtrBytes rsa_key_d, - uint32_t rsa_key_d_len); - -struct UREncodeResult *get_connect_blue_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); - -struct UREncodeResult *get_connect_sparrow_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); - -struct UREncodeResult *get_connect_specter_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); - -PtrT_UREncodeResult get_connect_companion_app_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - int32_t cold_version, - PtrT_CoinConfig coin_config, - uint32_t coin_config_length); - -Ptr_UREncodeResult get_okx_wallet_ur_btc_only(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString serial_number, - Ptr_CSliceFFI_ExtendedPublicKey public_keys, - PtrString device_type, - PtrString device_version); - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_metamask_ur_dynamic(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - enum ETHAccountType account_type, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - uintptr_t fragment_max_length_default, - uintptr_t fragment_max_length_other); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_metamask_ur_unlimited(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - enum ETHAccountType account_type, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_metamask_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - enum ETHAccountType account_type, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_Response_QRHardwareCallData parse_qr_hardware_call(PtrUR ur); -#endif - -#if defined(BUILD_MULTI_COINS) -struct Response_bool *check_hardware_call_path(PtrString path, PtrString chain_type); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult generate_key_derivation_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - Ptr_CSliceFFI_ExtendedPublicKey xpubs, - PtrString device_version); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_aptos_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_connect_arconnect_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrBytes p, - uint32_t p_len, - PtrBytes q, - uint32_t q_len); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_connect_arconnect_wallet_ur_from_xpub(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString xpub); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_backpack_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - Ptr_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_bitget_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString serial_number, - Ptr_CSliceFFI_ExtendedPublicKey public_keys, - PtrString device_type, - PtrString device_version); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_connect_imtoken_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString xpub, - PtrString wallet_name); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_keplr_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrT_CSliceFFI_KeplrAccount keplr_accounts); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_keystone_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString serial_number, - Ptr_CSliceFFI_ExtendedPublicKey public_keys, - PtrString device_type, - PtrString device_version); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_okx_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString serial_number, - Ptr_CSliceFFI_ExtendedPublicKey public_keys, - PtrString device_type, - PtrString device_version); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_solana_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -void free_Response_QRHardwareCallData(PtrT_Response_QRHardwareCallData ptr); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_sui_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_tonkeeper_wallet_ur(PtrString public_key, - PtrString wallet_name, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString path); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_xbull_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_xrp_toolkit_ur(PtrString hd_path, - PtrString root_x_pub, - PtrString root_path); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_zcash_wallet_ur(PtrBytes seed_fingerprint, - uint32_t seed_fingerprint_len, - Ptr_CSliceFFI_ZcashKey zcash_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_thor_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrString serial_number, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - PtrString device_type, - PtrString device_version); -#endif - -struct SimpleResponse_c_char *aptos_generate_address(PtrString pub_key); - -PtrT_TransactionCheckResult aptos_check_request(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length); - -PtrT_TransactionParseResult_DisplayAptosTx aptos_parse(PtrUR ptr); - -PtrT_UREncodeResult aptos_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len, PtrString pub_key); - -PtrString aptos_get_path(PtrUR ptr); - -struct SimpleResponse_c_char *test_aptos_parse(void); - -void free_TransactionParseResult_DisplayAptosTx(PtrT_TransactionParseResult_DisplayAptosTx ptr); - -struct SimpleResponse_u8 *generate_arweave_secret(PtrBytes seed, uint32_t seed_len); - -struct SimpleResponse_u8 *generate_arweave_public_key_from_primes(PtrBytes p, - uint32_t p_len, - PtrBytes q, - uint32_t q_len); - -struct SimpleResponse_c_char *generate_rsa_public_key(PtrBytes p, - uint32_t p_len, - PtrBytes q, - uint32_t q_len); - -struct SimpleResponse_u8 *aes256_encrypt_primes(PtrBytes seed, uint32_t seed_len, PtrBytes data); - -struct SimpleResponse_u8 *aes256_decrypt_primes(PtrBytes seed, uint32_t seed_len, PtrBytes data); - -struct SimpleResponse_c_char *arweave_get_address(PtrString xpub); - -struct SimpleResponse_c_char *fix_arweave_address(PtrString address); - -PtrT_TransactionCheckResult ar_check_tx(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); - -struct SimpleResponse_ArweaveRequestType *ar_request_type(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayArweaveMessage ar_message_parse(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayArweaveTx ar_parse(PtrUR ptr); - -PtrT_UREncodeResult ar_sign_tx(PtrUR ptr, PtrBytes p, uint32_t p_len, PtrBytes q, uint32_t q_len); - -bool ar_is_ao_transfer(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayArweaveDataItem ar_parse_data_item(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayArweaveAOTransfer ar_parse_ao_transfer(PtrUR ptr); - -void free_TransactionParseResult_DisplayArweaveTx(PtrT_TransactionParseResult_DisplayArweaveTx ptr); - -void free_TransactionParseResult_DisplayArweaveMessage(PtrT_TransactionParseResult_DisplayArweaveMessage ptr); - -struct SimpleResponse_c_char *utxo_get_address(PtrString hd_path, PtrString x_pub); - -struct SimpleResponse_c_char *xpub_convert_version(PtrString x_pub, PtrString target); - -struct TransactionParseResult_DisplayTx *utxo_parse_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub); - -struct UREncodeResult *utxo_sign_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub, - int32_t cold_version, - PtrBytes seed, - uint32_t seed_len); - -PtrT_TransactionCheckResult utxo_check_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub); - -PtrT_TransactionCheckResult btc_check_msg(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); - -struct TransactionParseResult_DisplayBtcMsg *btc_parse_msg(PtrUR ptr, - Ptr_CSliceFFI_ExtendedPublicKey xpubs, - PtrBytes master_fingerprint, - uint32_t length); - -struct UREncodeResult *btc_sign_msg(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -Ptr_TransactionParseResult_DisplayBtcMsg parse_seed_signer_message(PtrUR ptr, - Ptr_CSliceFFI_ExtendedPublicKey xpubs); - -struct UREncodeResult *sign_seed_signer_message(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -struct UREncodeResult *export_multi_sig_xpub_by_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - enum NetworkType network); - -struct UREncodeResult *export_multi_sig_wallet_by_ur_test(uint8_t *master_fingerprint, - uint32_t length, - PtrT_MultiSigWallet multi_sig_wallet); - -struct UREncodeResult *export_multi_sig_wallet_by_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrString config); - -Ptr_Response_MultiSigWallet import_multi_sig_wallet_by_ur(PtrUR ur, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -Ptr_Response_MultiSigWallet import_multi_sig_wallet_by_file(PtrString content, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -Ptr_SimpleResponse_c_char generate_address_for_multisig_wallet_config(PtrString wallet_config, - uint32_t account, - uint32_t index, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -Ptr_SimpleResponse_c_char generate_psbt_file_name(PtrBytes psbt_hex, - uint32_t psbt_len, - uint32_t time_stamp); - -Ptr_Response_MultiSigWallet parse_and_verify_multisig_config(PtrBytes seed, - uint32_t seed_len, - PtrString wallet_config, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -void free_MultiSigXPubInfoItem(PtrT_MultiSigXPubInfoItem ptr); - -void free_MultiSigWallet(PtrT_MultiSigWallet ptr); - -void free_MultisigSignResult(PtrT_MultisigSignResult ptr); - -struct TransactionParseResult_DisplayTx *btc_parse_psbt(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - PtrString multisig_wallet_config); - -struct UREncodeResult *btc_sign_psbt(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -struct UREncodeResult *btc_sign_psbt_unlimited(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -struct MultisigSignResult *btc_sign_multisig_psbt(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -struct MultisigSignResult *btc_export_multisig_psbt(PtrUR ptr); - -struct MultisigSignResult *btc_export_multisig_psbt_bytes(PtrBytes psbt_bytes, - uint32_t psbt_bytes_length); - -PtrT_TransactionCheckResult btc_check_psbt(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - PtrString verify_code, - PtrString multisig_wallet_config); - -PtrT_TransactionCheckResult btc_check_psbt_bytes(PtrBytes psbt_bytes, - uint32_t psbt_bytes_length, - PtrBytes master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - PtrString verify_code, - PtrString multisig_wallet_config); - -struct TransactionParseResult_DisplayTx *btc_parse_psbt_bytes(PtrBytes psbt_bytes, - uint32_t psbt_bytes_length, - PtrBytes master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - PtrString multisig_wallet_config); - -struct MultisigSignResult *btc_sign_multisig_psbt_bytes(PtrBytes psbt_bytes, - uint32_t psbt_bytes_length, - PtrBytes seed, - uint32_t seed_len, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -void free_Response_PsbtSignResult(PtrT_Response_PsbtSignResult ptr); - -void free_TransactionParseResult_DisplayTx(PtrT_TransactionParseResult_DisplayTx ptr); - -void free_TransactionParseResult_DisplayBtcMsg(PtrT_TransactionParseResult_DisplayBtcMsg ptr); - -Ptr_SimpleResponse_c_char cardano_catalyst_xpub(PtrUR ptr); - -PtrT_TransactionCheckResult cardano_check_catalyst(PtrUR ptr, PtrBytes master_fingerprint); - -PtrT_TransactionCheckResult cardano_check_catalyst_path_type(PtrUR ptr, PtrString cardano_xpub); - -Ptr_SimpleResponse_c_char cardano_get_catalyst_root_index(PtrUR ptr); - -Ptr_SimpleResponse_c_char cardano_get_sign_data_root_index(PtrUR ptr); - -PtrT_TransactionCheckResult cardano_check_sign_data_path_type(PtrUR ptr, PtrString cardano_xpub); - -PtrT_TransactionCheckResult cardano_check_sign_data(PtrUR ptr, PtrBytes master_fingerprint); - -PtrT_TransactionCheckResult cardano_check_tx(PtrUR ptr, - PtrBytes master_fingerprint, - PtrString cardano_xpub); - -PtrT_TransactionCheckResult cardano_check_tx_hash(PtrUR ptr, PtrBytes master_fingerprint); - -PtrT_TransactionParseResult_DisplayCardanoSignTxHash cardano_parse_sign_tx_hash(PtrUR ptr); - -Ptr_SimpleResponse_c_char cardano_get_path(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayCardanoSignData cardano_parse_sign_data(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayCardanoCatalyst cardano_parse_catalyst(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayCardanoTx cardano_parse_tx(PtrUR ptr, - PtrBytes master_fingerprint, - PtrString cardano_xpub); - -PtrT_UREncodeResult cardano_sign_catalyst_with_ledger_bitbox02(PtrUR ptr, - PtrString mnemonic, - PtrString passphrase); - -PtrT_UREncodeResult cardano_sign_catalyst(PtrUR ptr, - PtrBytes entropy, - uint32_t entropy_len, - PtrString passphrase); - -PtrT_UREncodeResult cardano_sign_sign_data_with_ledger_bitbox02(PtrUR ptr, - PtrString mnemonic, - PtrString passphrase); - -PtrT_UREncodeResult cardano_sign_sign_data(PtrUR ptr, - PtrBytes entropy, - uint32_t entropy_len, - PtrString passphrase); - -PtrT_UREncodeResult cardano_sign_tx_with_ledger_bitbox02(PtrUR ptr, - PtrBytes master_fingerprint, - PtrString cardano_xpub, - PtrString mnemonic, - PtrString passphrase, - bool enable_blind_sign); - -PtrT_UREncodeResult cardano_sign_tx(PtrUR ptr, - PtrBytes master_fingerprint, - PtrString cardano_xpub, - PtrBytes entropy, - uint32_t entropy_len, - PtrString passphrase, - bool enable_blind_sign); - -struct SimpleResponse_c_char *cardano_get_base_address(PtrString xpub, - uint32_t index, - uint8_t network_id); - -struct SimpleResponse_c_char *cardano_get_enterprise_address(PtrString xpub, - uint32_t index, - uint8_t network_id); - -struct SimpleResponse_c_char *cardano_get_stake_address(PtrString xpub, - uint32_t index, - uint8_t network_id); - -void free_TransactionParseResult_DisplayCardanoTx(PtrT_TransactionParseResult_DisplayCardanoTx ptr); - -void free_TransactionParseResult_DisplayCardanoCatalyst(PtrT_TransactionParseResult_DisplayCardanoCatalyst ptr); - -void free_TransactionParseResult_DisplayCardanoSignData(PtrT_TransactionParseResult_DisplayCardanoSignData ptr); - -void free_TransactionParseResult_DisplayCardanoSignTxHash(PtrT_TransactionParseResult_DisplayCardanoSignTxHash ptr); - -PtrT_TransactionCheckResult cosmos_check_tx(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length); - -struct SimpleResponse_c_char *cosmos_get_address(PtrString hd_path, - PtrString root_x_pub, - PtrString root_path, - PtrString prefix); - -PtrT_UREncodeResult cosmos_sign_tx(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes seed, - uint32_t seed_len); - -PtrT_TransactionParseResult_DisplayCosmosTx cosmos_parse_tx(PtrUR ptr, enum QRCodeType ur_type); - -void free_TransactionParseResult_DisplayCosmosTx(PtrT_TransactionParseResult_DisplayCosmosTx ptr); - -PtrT_TransactionCheckResult eth_check_ur_bytes(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length, - enum QRCodeType ur_type); - -PtrT_TransactionCheckResult eth_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); - -PtrString eth_get_root_path_bytes(PtrUR ptr); - -PtrString eth_get_root_path(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayETH eth_parse_bytes_data(PtrUR ptr, PtrString xpub); - -PtrT_TransactionParseResult_DisplayETH eth_parse(PtrUR ptr, PtrString xpub); - -PtrT_TransactionParseResult_DisplayETHPersonalMessage eth_parse_personal_message(PtrUR ptr, - PtrString xpub); - -PtrT_TransactionParseResult_DisplayETHTypedData eth_parse_typed_data(PtrUR ptr, PtrString xpub); - -PtrT_UREncodeResult eth_sign_tx_dynamic(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - uintptr_t fragment_length); - -PtrT_UREncodeResult eth_sign_tx_bytes(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes mfp, - uint32_t mfp_len); - -PtrT_UREncodeResult eth_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -PtrT_UREncodeResult eth_sign_tx_unlimited(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -PtrT_TransactionParseResult_EthParsedErc20Transaction eth_parse_erc20(PtrString input, - uint32_t decimal); - -Ptr_Response_DisplayContractData eth_parse_contract_data(PtrString input_data, - PtrString contract_json); - -Ptr_Response_DisplayContractData eth_parse_contract_data_by_method(PtrString input_data, - PtrString contract_name, - PtrString contract_method_json); - -struct SimpleResponse_c_char *eth_get_address(PtrString hd_path, - PtrString root_x_pub, - PtrString root_path); - -void free_TransactionParseResult_DisplayETH(PtrT_TransactionParseResult_DisplayETH ptr); - -void free_TransactionParseResult_DisplayETHPersonalMessage(PtrT_TransactionParseResult_DisplayETHPersonalMessage ptr); - -void free_TransactionParseResult_DisplayETHTypedData(PtrT_TransactionParseResult_DisplayETHTypedData ptr); - -void free_Response_DisplayContractData(PtrT_Response_DisplayContractData ptr); - -void free_TransactionParseResult_EthParsedErc20Transaction(PtrT_TransactionParseResult_EthParsedErc20Transaction ptr); - -PtrT_TransactionCheckResult near_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); - -PtrT_TransactionParseResult_DisplayNearTx near_parse_tx(PtrUR ptr); - -PtrT_UREncodeResult near_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -void free_TransactionParseResult_DisplayNearTx(PtrT_TransactionParseResult_DisplayNearTx ptr); - -struct SimpleResponse_c_char *solana_get_address(PtrString pubkey); - -PtrT_TransactionCheckResult solana_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); - -PtrT_TransactionParseResult_DisplaySolanaTx solana_parse_tx(PtrUR ptr); - -PtrT_UREncodeResult solana_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -PtrT_TransactionParseResult_DisplaySolanaMessage solana_parse_message(PtrUR ptr, PtrString pubkey); - -PtrString sol_get_path(PtrUR ptr); - -void free_TransactionParseResult_DisplaySolanaTx(PtrT_TransactionParseResult_DisplaySolanaTx ptr); - -void free_TransactionParseResult_DisplaySolanaMessage(PtrT_TransactionParseResult_DisplaySolanaMessage ptr); - -struct SimpleResponse_c_char *stellar_get_address(PtrString pubkey); - -PtrT_TransactionParseResult_DisplayStellarTx stellar_parse(PtrUR ptr); - -PtrT_TransactionCheckResult stellar_check_tx(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length); - -PtrT_UREncodeResult stellar_sign(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -void free_TransactionParseResult_DisplayStellarTx(PtrT_TransactionParseResult_DisplayStellarTx ptr); - -PtrT_TransactionCheckResult sui_check_request(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length); - -PtrT_TransactionCheckResult sui_check_sign_hash_request(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length); - -struct SimpleResponse_c_char *sui_generate_address(PtrString pub_key); - -PtrT_TransactionParseResult_DisplaySuiIntentMessage sui_parse_intent(PtrUR ptr); - -PtrT_TransactionParseResult_DisplaySuiSignMessageHash sui_parse_sign_message_hash(PtrUR ptr); - -PtrT_UREncodeResult sui_sign_hash(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -PtrT_UREncodeResult sui_sign_intent(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -void free_TransactionParseResult_DisplaySuiIntentMessage(PtrT_TransactionParseResult_DisplaySuiIntentMessage ptr); - -void free_TransactionParseResult_DisplaySuiSignMessageHash(PtrT_TransactionParseResult_DisplaySuiSignMessageHash ptr); - -PtrT_TransactionParseResult_DisplayTonTransaction ton_parse_transaction(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayTonProof ton_parse_proof(PtrUR ptr); - -PtrT_TransactionCheckResult ton_check_transaction(PtrUR ptr, PtrString public_key); - -PtrT_TransactionCheckResult ton_not_supported_error(void); - -PtrT_UREncodeResult ton_sign_transaction(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -PtrT_UREncodeResult ton_sign_proof(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -bool ton_verify_mnemonic(PtrString mnemonic); - -Ptr_VecFFI_u8 ton_mnemonic_to_entropy(PtrString mnemonic); - -struct SimpleResponse_u8 *ton_entropy_to_seed(PtrBytes entropy, uint32_t entropy_len); - -struct SimpleResponse_u8 *ton_mnemonic_to_seed(PtrString mnemonic); - -struct SimpleResponse_c_char *ton_seed_to_publickey(PtrBytes seed, uint32_t seed_len); - -struct SimpleResponse_c_char *ton_get_address(PtrString public_key); - -void free_TransactionParseResult_DisplayTonTransaction(PtrT_TransactionParseResult_DisplayTonTransaction ptr); - -void free_TransactionParseResult_DisplayTonProof(PtrT_TransactionParseResult_DisplayTonProof ptr); - -PtrT_TransactionCheckResult tron_check_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub); - -struct TransactionParseResult_DisplayTron *tron_parse_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub); - -struct UREncodeResult *tron_sign_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub, - int32_t cold_version, - PtrBytes seed, - uint32_t seed_len); - -struct SimpleResponse_c_char *tron_get_address(PtrString hd_path, PtrString x_pub); - -void free_TransactionParseResult_DisplayTron(PtrT_TransactionParseResult_DisplayTron ptr); - -struct SimpleResponse_c_char *xrp_get_address(PtrString hd_path, - PtrString root_x_pub, - PtrString root_path); - -PtrT_TransactionParseResult_DisplayXrpTx xrp_parse_tx(PtrUR ptr); - -PtrT_UREncodeResult xrp_sign_tx_bytes(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes mfp, - uint32_t mfp_len, - PtrString root_xpub); - -PtrT_UREncodeResult xrp_sign_tx(PtrUR ptr, PtrString hd_path, PtrBytes seed, uint32_t seed_len); - -PtrT_TransactionCheckResult xrp_check_tx(PtrUR ptr, PtrString root_xpub, PtrString cached_pubkey); - -bool is_keystone_xrp_tx(PtrUR ur_data_ptr); - -PtrT_TransactionCheckResult xrp_check_tx_bytes(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length, - enum QRCodeType ur_type); - -PtrT_TransactionParseResult_DisplayXrpTx xrp_parse_bytes_tx(PtrUR ptr); - -void free_TransactionParseResult_DisplayXrpTx(PtrT_TransactionParseResult_DisplayXrpTx ptr); - -struct SimpleResponse_c_char *derive_zcash_ufvk(PtrBytes seed, - uint32_t seed_len, - PtrString account_path); - -struct SimpleResponse_u8 *calculate_zcash_seed_fingerprint(PtrBytes seed, uint32_t seed_len); - -struct SimpleResponse_c_char *generate_zcash_default_address(PtrString ufvk_text); - -struct TransactionCheckResult *check_zcash_tx(PtrUR tx, - PtrString ufvk, - PtrBytes seed_fingerprint, - uint32_t account_index, - bool disabled); - -Ptr_TransactionParseResult_DisplayPczt parse_zcash_tx(PtrUR tx, - PtrString ufvk, - PtrBytes seed_fingerprint); - -struct UREncodeResult *sign_zcash_tx(PtrUR tx, PtrBytes seed, uint32_t seed_len); - -void free_TransactionParseResult_DisplayPczt(PtrT_TransactionParseResult_DisplayPczt ptr); - -#endif /* _LIBRUST_C_H */ diff --git a/rust/rust_c/src/common/errors.rs b/rust/rust_c/src/common/errors.rs index 22a81a7e3..e9f921201 100644 --- a/rust/rust_c/src/common/errors.rs +++ b/rust/rust_c/src/common/errors.rs @@ -1,35 +1,37 @@ use alloc::string::String; +use keystore::errors::KeystoreError; +use thiserror; +use thiserror::Error; +use ur_registry::error::URError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "bitcoin")] +use app_bitcoin::errors::BitcoinError; +#[cfg(feature = "aptos")] use app_aptos::errors::AptosError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "arweave")] use app_arweave::errors::ArweaveError; -use app_bitcoin::errors::BitcoinError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] use app_cardano::errors::CardanoError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] use app_cosmos::errors::CosmosError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] use app_ethereum::errors::EthereumError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "near")] use app_near::errors::NearError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] use app_solana::errors::SolanaError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] use app_stellar::errors::StellarError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] use app_sui::errors::SuiError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ton")] use app_ton::errors::TonError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "tron")] use app_tron::errors::TronError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "xrp")] use app_xrp::errors::XRPError; +#[cfg(feature = "zcash")] use app_zcash::errors::ZcashError; -use keystore::errors::KeystoreError; -use thiserror; -use thiserror::Error; -use ur_registry::error::URError; #[derive(Debug, Clone)] #[repr(C)] @@ -293,7 +295,7 @@ impl From<&RustCError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] impl From<&EthereumError> for ErrorCodes { fn from(value: &EthereumError) -> Self { match value { @@ -329,7 +331,7 @@ impl From<&KeystoreError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] impl From<&CardanoError> for ErrorCodes { fn from(value: &CardanoError) -> Self { match value { @@ -342,7 +344,7 @@ impl From<&CardanoError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] impl From<&SolanaError> for ErrorCodes { fn from(value: &SolanaError) -> Self { match value { @@ -357,7 +359,7 @@ impl From<&SolanaError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "near")] impl From<&NearError> for ErrorCodes { fn from(value: &NearError) -> Self { match value { @@ -369,7 +371,7 @@ impl From<&NearError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "arweave")] impl From<&ArweaveError> for ErrorCodes { fn from(value: &ArweaveError) -> Self { match value { @@ -384,7 +386,7 @@ impl From<&ArweaveError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] impl From<&StellarError> for ErrorCodes { fn from(value: &StellarError) -> Self { match value { @@ -396,7 +398,7 @@ impl From<&StellarError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] impl From<&CosmosError> for ErrorCodes { fn from(value: &CosmosError) -> Self { match value { @@ -410,7 +412,7 @@ impl From<&CosmosError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "aptos")] impl From<&AptosError> for ErrorCodes { fn from(value: &AptosError) -> Self { match value { @@ -422,7 +424,7 @@ impl From<&AptosError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "tron")] impl From<&TronError> for ErrorCodes { fn from(value: &TronError) -> Self { match value { @@ -439,7 +441,7 @@ impl From<&TronError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "xrp")] impl From<&XRPError> for ErrorCodes { fn from(value: &XRPError) -> Self { match value { @@ -452,7 +454,7 @@ impl From<&XRPError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] impl From<&SuiError> for ErrorCodes { fn from(value: &SuiError) -> Self { match value { @@ -464,7 +466,7 @@ impl From<&SuiError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ton")] impl From<&TonError> for ErrorCodes { fn from(value: &TonError) -> Self { match value { @@ -479,7 +481,7 @@ impl From<&TonError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "zcash")] impl From<&ZcashError> for ErrorCodes { fn from(value: &ZcashError) -> Self { match value { diff --git a/rust/rust_c/src/common/keystone.rs b/rust/rust_c/src/common/keystone.rs index beba14975..9f2deba7a 100644 --- a/rust/rust_c/src/common/keystone.rs +++ b/rust/rust_c/src/common/keystone.rs @@ -72,12 +72,13 @@ fn get_signed_tx( seed: &[u8], ) -> Result<(String, String), KeystoneError> { build_parse_context(master_fingerprint, x_pub).and_then(|context| { + #[cfg(feature = "bitcoin")] if app_bitcoin::network::Network::from_str(coin_code.as_str()).is_ok() { return app_bitcoin::sign_raw_tx(payload, context, seed) .map_err(|e| KeystoneError::SignTxFailed(e.to_string())); } match coin_code.as_str() { - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] "TRON" => app_tron::sign_raw_tx(payload, context, seed) .map_err(|e| KeystoneError::SignTxFailed(e.to_string())), _ => Err(KeystoneError::SignTxFailed(format!( @@ -99,6 +100,7 @@ pub fn build_check_result( match payload_content { Some(payload::Content::SignTx(sign_tx_content)) => { build_parse_context(master_fingerprint, x_pub).and_then(|context| { + #[cfg(feature = "bitcoin")] if app_bitcoin::network::Network::from_str(sign_tx_content.coin_code.as_str()) .is_ok() { @@ -106,7 +108,7 @@ pub fn build_check_result( .map_err(|e| KeystoneError::CheckTxFailed(e.to_string())); } match sign_tx_content.coin_code.as_str() { - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] "TRON" => app_tron::check_raw_tx(payload, context) .map_err(|e| KeystoneError::CheckTxFailed(e.to_string())), _ => Err(KeystoneError::CheckTxFailed(format!( diff --git a/rust/rust_c/src/common/macros.rs b/rust/rust_c/src/common/macros.rs index 50338ed0c..01b62cc4a 100644 --- a/rust/rust_c/src/common/macros.rs +++ b/rust/rust_c/src/common/macros.rs @@ -79,13 +79,6 @@ macro_rules! impl_new_error { } } } - - impl From for $name { - fn from(value: BitcoinError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } - impl From for $name { fn from(value: URError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) @@ -97,91 +90,95 @@ macro_rules! impl_new_error { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] - impl From for $name { - fn from(value: EthereumError) -> Self { + impl From for $name { + fn from(value: KeystoreError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - impl From for $name { - fn from(value: KeystoreError) -> Self { + impl From for $name { + fn from(value: super::errors::KeystoneError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + #[cfg(feature = "bitcoin")] + impl From for $name { + fn from(value: app_bitcoin::errors::BitcoinError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + #[cfg(feature = "ethereum")] + impl From for $name { + fn from(value: app_ethereum::errors::EthereumError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] impl From for $name { fn from(value: app_tron::errors::TronError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] impl From for $name { fn from(value: app_solana::errors::SolanaError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] impl From for $name { fn from(value: app_near::errors::NearError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] impl From for $name { fn from(value: app_aptos::errors::AptosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - impl From for $name { - fn from(value: super::errors::KeystoneError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] impl From for $name { fn from(value: app_cosmos::errors::CosmosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] impl From for $name { fn from(value: app_xrp::errors::XRPError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] impl From for $name { fn from(value: app_sui::errors::SuiError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] impl From for $name { fn from(value: app_cardano::errors::CardanoError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] impl From for $name { fn from(value: app_arweave::errors::ArweaveError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] impl From for $name { fn from(value: app_stellar::errors::StellarError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] impl From for $name { fn from(value: app_ton::errors::TonError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] impl From for $name { fn from(value: app_zcash::errors::ZcashError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) @@ -201,12 +198,6 @@ macro_rules! impl_new_error { } } - impl<$t: Free> From for $name<$t> { - fn from(value: BitcoinError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } - impl<$t: Free> From for $name<$t> { fn from(value: URError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) @@ -218,91 +209,97 @@ macro_rules! impl_new_error { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] - impl<$t: Free> From for $name<$t> { - fn from(value: EthereumError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } impl<$t: Free> From for $name<$t> { fn from(value: KeystoreError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + impl<$t: Free> From for $name<$t> { + fn from(value: super::errors::KeystoneError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + #[cfg(feature = "bitcoin")] + impl<$t: Free> From for $name<$t> { + fn from(value: app_bitcoin::errors::BitcoinError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + #[cfg(feature = "ethereum")] + impl<$t: Free> From for $name<$t> { + fn from(value: app_ethereum::errors::EthereumError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + + #[cfg(feature = "tron")] impl<$t: Free> From for $name<$t> { fn from(value: app_tron::errors::TronError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] impl<$t: Free> From for $name<$t> { fn from(value: app_solana::errors::SolanaError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] impl<$t: Free> From for $name<$t> { fn from(value: app_near::errors::NearError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] impl<$t: Free> From for $name<$t> { fn from(value: app_cosmos::errors::CosmosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] impl<$t: Free> From for $name<$t> { fn from(value: app_xrp::errors::XRPError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] impl<$t: Free> From for $name<$t> { fn from(value: app_aptos::errors::AptosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - impl<$t: Free> From for $name<$t> { - fn from(value: super::errors::KeystoneError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] impl<$t: Free> From for $name<$t> { fn from(value: app_sui::errors::SuiError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] impl<$t: Free> From for $name<$t> { fn from(value: app_cardano::errors::CardanoError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] impl<$t: Free> From for $name<$t> { fn from(value: app_arweave::errors::ArweaveError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] impl<$t: Free> From for $name<$t> { fn from(value: app_stellar::errors::StellarError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] impl<$t: Free> From for $name<$t> { fn from(value: app_ton::errors::TonError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] impl<$t: Free> From for $name<$t> { fn from(value: app_zcash::errors::ZcashError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) @@ -324,103 +321,100 @@ macro_rules! impl_simple_new_error { } } } - - impl<$t> From for $name<$t> { - fn from(value: BitcoinError) -> Self { + impl<$t> From for $name<$t> { + fn from(value: KeystoreError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - impl<$t> From for $name<$t> { - fn from(value: KeystoreError) -> Self { + impl<$t> From for $name<$t> { + fn from(value: RustCError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + #[cfg(feature = "bitcoin")] + impl<$t> From for $name<$t> { + fn from(value: app_bitcoin::errors::BitcoinError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] - impl<$t> From for $name<$t> { - fn from(value: EthereumError) -> Self { + #[cfg(feature = "ethereum")] + impl<$t> From for $name<$t> { + fn from(value: app_ethereum::errors::EthereumError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] impl<$t> From for $name<$t> { fn from(value: app_tron::errors::TronError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] impl<$t> From for $name<$t> { fn from(value: app_solana::errors::SolanaError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] impl<$t> From for $name<$t> { fn from(value: app_near::errors::NearError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] impl<$t> From for $name<$t> { fn from(value: app_aptos::errors::AptosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] impl<$t> From for $name<$t> { fn from(value: app_xrp::errors::XRPError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] impl<$t> From for $name<$t> { fn from(value: app_cosmos::errors::CosmosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] impl<$t> From for $name<$t> { fn from(value: app_sui::errors::SuiError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] impl<$t> From for $name<$t> { fn from(value: app_cardano::errors::CardanoError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] impl<$t> From for $name<$t> { fn from(value: app_arweave::errors::ArweaveError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] impl<$t> From for $name<$t> { fn from(value: app_stellar::errors::StellarError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] impl<$t> From for $name<$t> { fn from(value: app_ton::errors::TonError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] impl<$t> From for $name<$t> { fn from(value: app_zcash::errors::ZcashError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - impl<$t> From for $name<$t> { - fn from(value: RustCError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } }; } diff --git a/rust/rust_c/src/common/structs.rs b/rust/rust_c/src/common/structs.rs index 144b3f333..8e1d32a64 100644 --- a/rust/rust_c/src/common/structs.rs +++ b/rust/rust_c/src/common/structs.rs @@ -4,9 +4,6 @@ use super::errors::ErrorCodes; use super::errors::RustCError; use alloc::boxed::Box; use alloc::string::{String, ToString}; -use app_bitcoin::errors::BitcoinError; -#[cfg(feature = "multi-coins")] -use app_ethereum::errors::EthereumError; use core::ptr::null_mut; use cstr_core::CString; use keystore::errors::KeystoreError; diff --git a/rust/rust_c/src/common/ur.rs b/rust/rust_c/src/common/ur.rs index 3ee8a875e..280a5c7ac 100644 --- a/rust/rust_c/src/common/ur.rs +++ b/rust/rust_c/src/common/ur.rs @@ -3,15 +3,7 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; use core::ptr::null_mut; -#[cfg(feature = "multi-coins")] -use ur_registry::aptos::aptos_sign_request::AptosSignRequest; -#[cfg(feature = "multi-coins")] -use ur_registry::extend::qr_hardware_call::QRHardwareCall; -use ur_registry::zcash::zcash_pczt::ZcashPczt; -use app_bitcoin::errors::BitcoinError; -#[cfg(feature = "multi-coins")] -use app_ethereum::errors::EthereumError; use cstr_core::CString; use cty::c_char; use keystore::errors::KeystoreError; @@ -20,44 +12,52 @@ use ur_parse_lib::keystone_ur_decoder::{ URParseResult as InnerParseResult, }; use ur_parse_lib::keystone_ur_encoder::KeystoneUREncoder; -#[cfg(feature = "multi-coins")] -use ur_registry::arweave::arweave_sign_request::ArweaveSignRequest; use ur_registry::bytes::Bytes; -#[cfg(feature = "multi-coins")] +use ur_registry::error::{URError, URResult}; +use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; +use ur_registry::registry_types::URType as InnerURType; +use ur_registry::traits::RegistryItem; + +#[cfg(feature = "aptos")] +use ur_registry::aptos::aptos_sign_request::AptosSignRequest; +#[cfg(feature = "arweave")] +use ur_registry::arweave::arweave_sign_request::ArweaveSignRequest; +#[cfg(feature = "bitcoin")] +use ur_registry::bitcoin::btc_sign_request::BtcSignRequest; +#[cfg(feature = "cardano")] use ur_registry::cardano::{ cardano_catalyst_voting_registration::CardanoCatalystVotingRegistrationRequest, cardano_sign_data_request::CardanoSignDataRequest, cardano_sign_request::CardanoSignRequest, + cardano_sign_tx_hash_request::CardanoSignTxHashRequest, }; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] use ur_registry::cosmos::cosmos_sign_request::CosmosSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] use ur_registry::cosmos::evm_sign_request::EvmSignRequest; +#[cfg(feature = "bitcoin")] use ur_registry::crypto_account::CryptoAccount; +#[cfg(feature = "bitcoin")] use ur_registry::crypto_psbt::CryptoPSBT; -use ur_registry::error::{URError, URResult}; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] use ur_registry::ethereum::eth_sign_request::EthSignRequest; -use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; #[cfg(feature = "multi-coins")] -use ur_registry::keystone::keystone_sign_request::KeystoneSignRequest; +use ur_registry::extend::qr_hardware_call::QRHardwareCall; #[cfg(feature = "multi-coins")] +use ur_registry::keystone::keystone_sign_request::KeystoneSignRequest; +#[cfg(feature = "near")] use ur_registry::near::near_sign_request::NearSignRequest; -use ur_registry::registry_types::URType as InnerURType; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] use ur_registry::solana::sol_sign_request::SolSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] use ur_registry::stellar::stellar_sign_request::StellarSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] use ur_registry::sui::sui_sign_hash_request::SuiSignHashRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] use ur_registry::sui::sui_sign_request::SuiSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ton")] use ur_registry::ton::ton_sign_request::TonSignRequest; -use ur_registry::traits::RegistryItem; -use ur_registry::{ - bitcoin::btc_sign_request::BtcSignRequest, - cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest, -}; +#[cfg(feature = "zcash")] +use ur_registry::zcash::zcash_pczt::ZcashPczt; use super::errors::{ErrorCodes, RustCError}; use super::free::Free; @@ -186,67 +186,72 @@ impl_response!(UREncodeMultiResult); #[repr(C)] #[derive(Debug, Eq, PartialEq)] pub enum ViewType { + #[cfg(feature = "bitcoin")] BtcNativeSegwitTx, + #[cfg(feature = "bitcoin")] BtcSegwitTx, + #[cfg(feature = "bitcoin")] BtcLegacyTx, + #[cfg(feature = "bitcoin")] BtcTx, + #[cfg(feature = "bitcoin")] BtcMsg, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ltc")] LtcTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "dash")] DashTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "bch")] BchTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] EthTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] EthPersonalMessage, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] EthTypedData, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] TronTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] SolanaTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] SolanaMessage, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoSignData, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoCatalystVotingRegistration, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoSignTxHash, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] NearTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] XRPTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] CosmosTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] CosmosEvmTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] SuiTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] SuiSignMessageHash, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] ArweaveTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] ArweaveMessage, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] ArweaveDataItem, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] StellarTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] StellarHash, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] TonTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] TonSignProof, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] ZcashTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] AptosTx, WebAuthResult, #[cfg(feature = "multi-coins")] @@ -262,48 +267,51 @@ pub enum ViewType { #[repr(C)] pub enum QRCodeType { + #[cfg(feature = "bitcoin")] CryptoPSBT, CryptoMultiAccounts, + #[cfg(feature = "bitcoin")] CryptoAccount, Bytes, + #[cfg(feature = "bitcoin")] BtcSignRequest, SeedSignerMessage, #[cfg(feature = "multi-coins")] KeystoneSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] EthSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] SolSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] NearSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoSignTxHashRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoSignDataRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoCatalystVotingRegistrationRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] CosmosSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] EvmSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] SuiSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] SuiSignHashRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] AptosSignRequest, #[cfg(feature = "multi-coins")] QRHardwareCall, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] ArweaveSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] StellarSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] TonSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] ZcashPczt, URTypeUnKnown, } @@ -311,46 +319,49 @@ pub enum QRCodeType { impl QRCodeType { pub fn from(value: &InnerURType) -> Result { match value { + #[cfg(feature = "bitcoin")] InnerURType::CryptoPsbt(_) => Ok(QRCodeType::CryptoPSBT), InnerURType::CryptoMultiAccounts(_) => Ok(QRCodeType::CryptoMultiAccounts), + #[cfg(feature = "bitcoin")] InnerURType::CryptoAccount(_) => Ok(QRCodeType::CryptoAccount), InnerURType::Bytes(_) => Ok(QRCodeType::Bytes), + #[cfg(feature = "bitcoin")] InnerURType::BtcSignRequest(_) => Ok(QRCodeType::BtcSignRequest), #[cfg(feature = "multi-coins")] InnerURType::KeystoneSignRequest(_) => Ok(QRCodeType::KeystoneSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] InnerURType::EthSignRequest(_) => Ok(QRCodeType::EthSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] InnerURType::SolSignRequest(_) => Ok(QRCodeType::SolSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] InnerURType::NearSignRequest(_) => Ok(QRCodeType::NearSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] InnerURType::CosmosSignRequest(_) => Ok(QRCodeType::CosmosSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] InnerURType::EvmSignRequest(_) => Ok(QRCodeType::EvmSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] InnerURType::SuiSignRequest(_) => Ok(QRCodeType::SuiSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] InnerURType::SuiSignHashRequest(_) => Ok(QRCodeType::SuiSignHashRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] InnerURType::StellarSignRequest(_) => Ok(QRCodeType::StellarSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] InnerURType::ArweaveSignRequest(_) => Ok(QRCodeType::ArweaveSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] InnerURType::AptosSignRequest(_) => Ok(QRCodeType::AptosSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] InnerURType::CardanoSignRequest(_) => Ok(QRCodeType::CardanoSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] InnerURType::CardanoSignTxHashRequest(_) => Ok(QRCodeType::CardanoSignTxHashRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] InnerURType::CardanoSignDataRequest(_) => Ok(QRCodeType::CardanoSignDataRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] InnerURType::CardanoCatalystVotingRegistrationRequest(_) => { Ok(QRCodeType::CardanoCatalystVotingRegistrationRequest) } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] InnerURType::TonSignRequest(_) => Ok(QRCodeType::TonSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] InnerURType::ZcashPczt(_) => Ok(QRCodeType::ZcashPczt), #[cfg(feature = "multi-coins")] InnerURType::QRHardwareCall(_) => Ok(QRCodeType::QRHardwareCall), @@ -426,30 +437,33 @@ impl Free for URParseResult { fn free_ur(ur_type: &QRCodeType, data: PtrUR) { match ur_type { + #[cfg(feature = "bitcoin")] QRCodeType::CryptoPSBT => { free_ptr_with_type!(data, CryptoPSBT); } QRCodeType::CryptoMultiAccounts => { free_ptr_with_type!(data, CryptoMultiAccounts); } + #[cfg(feature = "bitcoin")] QRCodeType::CryptoAccount => { free_ptr_with_type!(data, CryptoAccount); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EthSignRequest => { free_ptr_with_type!(data, EthSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] QRCodeType::SolSignRequest => { free_ptr_with_type!(data, SolSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] QRCodeType::NearSignRequest => { free_ptr_with_type!(data, NearSignRequest); } QRCodeType::Bytes => { free_ptr_with_type!(data, Bytes); } + #[cfg(feature = "bitcoin")] QRCodeType::BtcSignRequest => { free_ptr_with_type!(data, BtcSignRequest); } @@ -457,49 +471,48 @@ fn free_ur(ur_type: &QRCodeType, data: PtrUR) { QRCodeType::KeystoneSignRequest => { free_ptr_with_type!(data, KeystoneSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] QRCodeType::CosmosSignRequest => { free_ptr_with_type!(data, CosmosSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EvmSignRequest => { free_ptr_with_type!(data, EvmSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignRequest => { free_ptr_with_type!(data, SuiSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignHashRequest => { free_ptr_with_type!(data, SuiSignHashRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] QRCodeType::StellarSignRequest => { free_ptr_with_type!(data, StellarSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] QRCodeType::ArweaveSignRequest => { free_ptr_with_type!(data, ArweaveSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] QRCodeType::AptosSignRequest => { free_ptr_with_type!(data, AptosSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignRequest => { free_ptr_with_type!(data, CardanoSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignDataRequest => { free_ptr_with_type!(data, CardanoSignDataRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignTxHashRequest => { free_ptr_with_type!(data, CardanoSignTxHashRequest); } - - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoCatalystVotingRegistrationRequest => { free_ptr_with_type!(data, CardanoCatalystVotingRegistrationRequest); } @@ -624,49 +637,52 @@ pub fn decode_ur(ur: String) -> URParseResult { }; match ur_type { + #[cfg(feature = "bitcoin")] QRCodeType::CryptoPSBT => _decode_ur::(ur, ur_type), + #[cfg(feature = "bitcoin")] QRCodeType::CryptoAccount => _decode_ur::(ur, ur_type), QRCodeType::CryptoMultiAccounts => _decode_ur::(ur, ur_type), QRCodeType::Bytes => _decode_ur::(ur, ur_type), + #[cfg(feature = "bitcoin")] QRCodeType::BtcSignRequest => _decode_ur::(ur, ur_type), #[cfg(feature = "multi-coins")] QRCodeType::KeystoneSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EthSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] QRCodeType::SolSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] QRCodeType::NearSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignTxHashRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignDataRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoCatalystVotingRegistrationRequest => { _decode_ur::(ur, ur_type) } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] QRCodeType::CosmosSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EvmSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignHashRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] QRCodeType::StellarSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] QRCodeType::ArweaveSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] QRCodeType::AptosSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] QRCodeType::TonSignRequest => _decode_ur::(ur, ur_type), + #[cfg(feature = "zcash")] + QRCodeType::ZcashPczt => _decode_ur::(ur, ur_type), #[cfg(feature = "multi-coins")] QRCodeType::QRHardwareCall => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] - QRCodeType::ZcashPczt => _decode_ur::(ur, ur_type), QRCodeType::URTypeUnKnown | QRCodeType::SeedSignerMessage => URParseResult::from( URError::NotSupportURTypeError("UnKnown ur type".to_string()), ), @@ -711,53 +727,55 @@ fn receive_ur(ur: String, decoder: &mut KeystoneURDecoder) -> URParseMultiResult Err(e) => return URParseMultiResult::from(e), }; match ur_type { + #[cfg(feature = "bitcoin")] QRCodeType::CryptoPSBT => _receive_ur::(ur, ur_type, decoder), + #[cfg(feature = "bitcoin")] QRCodeType::CryptoAccount => _receive_ur::(ur, ur_type, decoder), QRCodeType::CryptoMultiAccounts => _receive_ur::(ur, ur_type, decoder), QRCodeType::Bytes => _receive_ur::(ur, ur_type, decoder), + #[cfg(feature = "bitcoin")] QRCodeType::BtcSignRequest => _receive_ur::(ur, ur_type, decoder), #[cfg(feature = "multi-coins")] QRCodeType::KeystoneSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EthSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] QRCodeType::SolSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] QRCodeType::NearSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignTxHashRequest => { _receive_ur::(ur, ur_type, decoder) } - - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignDataRequest => { _receive_ur::(ur, ur_type, decoder) } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoCatalystVotingRegistrationRequest => { _receive_ur::(ur, ur_type, decoder) } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] QRCodeType::CosmosSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EvmSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignHashRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] QRCodeType::ArweaveSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] QRCodeType::StellarSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] QRCodeType::AptosSignRequest => _receive_ur::(ur, ur_type, decoder), #[cfg(feature = "multi-coins")] QRCodeType::QRHardwareCall => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] QRCodeType::TonSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] QRCodeType::ZcashPczt => _receive_ur::(ur, ur_type, decoder), QRCodeType::URTypeUnKnown | QRCodeType::SeedSignerMessage => URParseMultiResult::from( URError::NotSupportURTypeError("UnKnown ur type".to_string()), diff --git a/rust/rust_c/src/common/ur_ext.rs b/rust/rust_c/src/common/ur_ext.rs index c7c21d95a..5add8ae8d 100644 --- a/rust/rust_c/src/common/ur_ext.rs +++ b/rust/rust_c/src/common/ur_ext.rs @@ -3,51 +3,55 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; use serde_json::{from_slice, from_value, Value}; + +use ur_registry::bytes::Bytes; +use ur_registry::crypto_account::CryptoAccount; +use ur_registry::crypto_psbt::CryptoPSBT; +use ur_registry::error::URError; +use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; +use ur_registry::pb::protobuf_parser::{parse_protobuf, unzip}; +use ur_registry::pb::protoc; +use ur_registry::pb::protoc::Base; #[cfg(feature = "multi-coins")] +use ur_registry::extend::qr_hardware_call::{CallType, QRHardwareCall}; +#[cfg(feature = "aptos")] use ur_registry::aptos::aptos_sign_request::AptosSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "arweave")] use ur_registry::arweave::arweave_sign_request::{ArweaveSignRequest, SignType}; -use ur_registry::bytes::Bytes; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "bitcoin")] +use ur_registry::bitcoin::btc_sign_request::BtcSignRequest; +#[cfg(feature = "cardano")] use ur_registry::cardano::cardano_catalyst_voting_registration::CardanoCatalystVotingRegistrationRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] use ur_registry::cardano::cardano_sign_data_request::CardanoSignDataRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] use ur_registry::cardano::cardano_sign_request::CardanoSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] use ur_registry::cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] use ur_registry::cosmos::cosmos_sign_request::CosmosSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] use ur_registry::cosmos::evm_sign_request::EvmSignRequest; -use ur_registry::crypto_account::CryptoAccount; -use ur_registry::crypto_psbt::CryptoPSBT; -use ur_registry::error::URError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] use ur_registry::ethereum::eth_sign_request; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] use ur_registry::ethereum::eth_sign_request::EthSignRequest; -use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; -#[cfg(feature = "multi-coins")] -use ur_registry::extend::qr_hardware_call::{CallType, QRHardwareCall}; #[cfg(feature = "multi-coins")] use ur_registry::keystone::keystone_sign_request::KeystoneSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "near")] use ur_registry::near::near_sign_request::NearSignRequest; -use ur_registry::pb::protobuf_parser::{parse_protobuf, unzip}; -use ur_registry::pb::protoc; -use ur_registry::pb::protoc::Base; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] use ur_registry::solana::sol_sign_request::SolSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] use ur_registry::stellar::stellar_sign_request::{SignType as StellarSignType, StellarSignRequest}; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] +use ur_registry::sui::sui_sign_hash_request::SuiSignHashRequest; +#[cfg(feature = "sui")] use ur_registry::sui::sui_sign_request::SuiSignRequest; +#[cfg(feature = "ton")] use ur_registry::ton::ton_sign_request::{DataType, TonSignRequest}; +#[cfg(feature = "zcash")] use ur_registry::zcash::zcash_pczt::ZcashPczt; -use ur_registry::{ - bitcoin::btc_sign_request::BtcSignRequest, sui::sui_sign_hash_request::SuiSignHashRequest, -}; use super::ur::ViewType; @@ -77,14 +81,14 @@ impl InferViewType for CryptoAccount { } } -#[cfg(feature = "multi-coins")] +#[cfg(not(feature = "btc-only"))] impl InferViewType for CryptoAccount { fn infer(&self) -> Result { Ok(ViewType::ViewTypeUnKnown) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] impl InferViewType for EthSignRequest { fn infer(&self) -> Result { match self.get_data_type() { @@ -96,35 +100,35 @@ impl InferViewType for EthSignRequest { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] impl InferViewType for CosmosSignRequest { fn infer(&self) -> Result { Ok(ViewType::CosmosTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] impl InferViewType for EvmSignRequest { fn infer(&self) -> Result { Ok(ViewType::CosmosEvmTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] impl InferViewType for SuiSignRequest { fn infer(&self) -> Result { Ok(ViewType::SuiTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] impl InferViewType for SuiSignHashRequest { fn infer(&self) -> Result { Ok(ViewType::SuiSignMessageHash) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] impl InferViewType for StellarSignRequest { fn infer(&self) -> Result { match self.get_sign_type() { @@ -135,7 +139,7 @@ impl InferViewType for StellarSignRequest { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "arweave")] impl InferViewType for ArweaveSignRequest { fn infer(&self) -> Result { match self.get_sign_type() { @@ -146,7 +150,7 @@ impl InferViewType for ArweaveSignRequest { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ton")] impl InferViewType for TonSignRequest { fn infer(&self) -> Result { match self.get_data_type() { @@ -156,14 +160,14 @@ impl InferViewType for TonSignRequest { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "aptos")] impl InferViewType for AptosSignRequest { fn infer(&self) -> Result { Ok(ViewType::AptosTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "zcash")] impl InferViewType for ZcashPczt { fn infer(&self) -> Result { Ok(ViewType::ZcashTx) @@ -185,17 +189,17 @@ fn get_view_type_from_keystone(bytes: Vec) -> Result { "BTC_SEGWIT" => ViewType::BtcSegwitTx, "BTC_LEGACY" => ViewType::BtcLegacyTx, "BTC" => ViewType::BtcSegwitTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ltc")] "LTC" => ViewType::LtcTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "dash")] "DASH" => ViewType::DashTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "bch")] "BCH" => ViewType::BchTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] "ETH" => ViewType::EthTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] "TRON" => ViewType::TronTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] "XRP" => ViewType::XRPTx, _ => { return Err(URError::ProtobufDecodeError(format!( @@ -234,7 +238,7 @@ impl InferViewType for Bytes { return Ok(ViewType::WebAuthResult); } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] return Ok(ViewType::XRPTx); #[cfg(feature = "btc-only")] return Err(URError::UrDecodeError(format!("invalid data"))); @@ -255,16 +259,16 @@ impl InferViewType for Bytes { } } +#[cfg(feature = "bitcoin")] impl InferViewType for BtcSignRequest { fn infer(&self) -> Result { Ok(ViewType::BtcMsg) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] impl InferViewType for SolSignRequest { fn infer(&self) -> Result { - #[cfg(feature = "multi-coins")] if app_solana::validate_tx(&mut self.get_sign_data()) { return Ok(ViewType::SolanaTx); } @@ -272,35 +276,35 @@ impl InferViewType for SolSignRequest { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "near")] impl InferViewType for NearSignRequest { fn infer(&self) -> Result { Ok(ViewType::NearTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] impl InferViewType for CardanoSignRequest { fn infer(&self) -> Result { Ok(ViewType::CardanoTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] impl InferViewType for CardanoSignTxHashRequest { fn infer(&self) -> Result { Ok(ViewType::CardanoSignTxHash) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] impl InferViewType for CardanoSignDataRequest { fn infer(&self) -> Result { Ok(ViewType::CardanoSignData) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] impl InferViewType for CardanoCatalystVotingRegistrationRequest { fn infer(&self) -> Result { Ok(ViewType::CardanoCatalystVotingRegistration) @@ -326,6 +330,7 @@ mod tests { use super::InferViewType; use crate::common::ur::ViewType; + #[cfg(feature = "ltc")] #[test] fn test_parse_ur_type() { { From 0ecfcf08e94d7d1e23094a8279b97c3d86b98a06 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 18:58:34 +0800 Subject: [PATCH 09/31] fix: all build --- rust/rust_c/src/common/mod.rs | 120 +------------------------------ rust/rust_c/src/zcash/mod.rs | 131 ++++++++++++++++++++++++++++++++-- 2 files changed, 128 insertions(+), 123 deletions(-) diff --git a/rust/rust_c/src/common/mod.rs b/rust/rust_c/src/common/mod.rs index 840f8894f..60f4ef877 100644 --- a/rust/rust_c/src/common/mod.rs +++ b/rust/rust_c/src/common/mod.rs @@ -1,6 +1,3 @@ -use aes::cipher::block_padding::Pkcs7; -use aes::cipher::generic_array::GenericArray; -use aes::cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit}; use alloc::boxed::Box; use alloc::string::{String, ToString}; use core::ptr::null_mut; @@ -296,119 +293,4 @@ pub extern "C" fn pbkdf2_rust_64( #[no_mangle] pub extern "C" fn tx_check_pass() -> Ptr { TransactionCheckResult::new().c_ptr() -} - -type Aes256CbcEnc = cbc::Encryptor; -type Aes256CbcDec = cbc::Decryptor; - -#[no_mangle] -pub extern "C" fn rust_aes256_cbc_encrypt( - data: PtrString, - password: PtrString, - iv: PtrBytes, - iv_len: u32, -) -> *mut SimpleResponse { - let data = recover_c_char(data); - let data = data.as_bytes(); - let password = recover_c_char(password); - let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; - let key = sha256(password.as_bytes()); - let iv = GenericArray::from_slice(&iv); - let key = GenericArray::from_slice(&key); - let ct = Aes256CbcEnc::new(key, iv).encrypt_padded_vec_mut::(data); - SimpleResponse::success(convert_c_char(hex::encode(ct))).simple_c_ptr() -} - -#[no_mangle] -pub extern "C" fn rust_aes256_cbc_decrypt( - hex_data: PtrString, - password: PtrString, - iv: PtrBytes, - iv_len: u32, -) -> *mut SimpleResponse { - let hex_data = recover_c_char(hex_data); - let data = hex::decode(hex_data).unwrap(); - let password = recover_c_char(password); - let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; - let key = sha256(password.as_bytes()); - let iv = GenericArray::from_slice(&iv); - let key = GenericArray::from_slice(&key); - - match Aes256CbcDec::new(key, iv).decrypt_padded_vec_mut::(&data) { - Ok(pt) => { - SimpleResponse::success(convert_c_char(String::from_utf8(pt).unwrap())).simple_c_ptr() - } - Err(_e) => SimpleResponse::from(RustCError::InvalidHex("decrypt failed".to_string())) - .simple_c_ptr(), - } -} - -#[no_mangle] -pub extern "C" fn rust_derive_iv_from_seed( - seed: PtrBytes, - seed_len: u32, -) -> *mut SimpleResponse { - let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; - let iv_path = "m/44'/1557192335'/0'/2'/0'".to_string(); - let iv = get_private_key_by_seed(seed, &iv_path).unwrap(); - let mut iv_bytes = [0; 16]; - iv_bytes.copy_from_slice(&iv[..16]); - SimpleResponse::success(Box::into_raw(Box::new(iv_bytes)) as *mut u8).simple_c_ptr() -} - -#[cfg(test)] -mod tests { - use alloc::{string::String, vec::Vec}; - - use super::*; - - #[test] - fn test_aes256_cbc_encrypt() { - let mut data = convert_c_char("hello world".to_string()); - let mut password = convert_c_char("password".to_string()); - let mut seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let iv = rust_derive_iv_from_seed(seed.as_mut_ptr(), 64); - let mut iv = unsafe { slice::from_raw_parts_mut((*iv).data, 16) }; - let iv_len = 16; - let ct = rust_aes256_cbc_encrypt(data, password, iv.as_mut_ptr(), iv_len as u32); - let ct_vec = unsafe { (*ct).data }; - let value = recover_c_char(ct_vec); - assert_eq!(value, "639194f4bf964e15d8ea9c9bd9d96918"); - } - - #[test] - fn test_aes256_cbc_decrypt() { - let data = convert_c_char("639194f4bf964e15d8ea9c9bd9d96918".to_string()); - let password = convert_c_char("password".to_string()); - let mut seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let iv = rust_derive_iv_from_seed(seed.as_mut_ptr(), 64); - let iv = unsafe { slice::from_raw_parts_mut((*iv).data, 16) }; - let iv_len = 16; - let pt = rust_aes256_cbc_decrypt(data, password, iv.as_mut_ptr(), iv_len as u32); - assert!(!pt.is_null()); - let ct_vec = unsafe { (*pt).data }; - let value = recover_c_char(ct_vec); - assert_eq!(value, "hello world"); - } - - #[test] - fn test_dep_aes256() { - let mut data = b"hello world"; - let seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let iv_path = "m/44'/1557192335'/0'/2'/0'".to_string(); - let iv = get_private_key_by_seed(&seed, &iv_path).unwrap(); - let mut iv_bytes = [0; 16]; - iv_bytes.copy_from_slice(&iv[..16]); - let key = sha256(b"password"); - let iv = GenericArray::from_slice(&iv_bytes); - let key = GenericArray::from_slice(&key); - - let encrypter = Aes256CbcEnc::new(key, iv); - let decrypter = Aes256CbcDec::new(key, iv); - - let ct = encrypter.encrypt_padded_vec_mut::(data); - let pt = decrypter.decrypt_padded_vec_mut::(&ct).unwrap(); - - assert_eq!(String::from_utf8(pt).unwrap(), "hello world"); - } -} +} \ No newline at end of file diff --git a/rust/rust_c/src/zcash/mod.rs b/rust/rust_c/src/zcash/mod.rs index 95f1b28b6..2778b9efa 100644 --- a/rust/rust_c/src/zcash/mod.rs +++ b/rust/rust_c/src/zcash/mod.rs @@ -1,7 +1,5 @@ pub mod structs; -use alloc::{boxed::Box, format}; -use app_zcash::get_address; use crate::common::{ errors::RustCError, free::Free, @@ -10,10 +8,16 @@ use crate::common::{ ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}, utils::{convert_c_char, recover_c_char}, }; -use crate::{extract_ptr_with_type, make_free_method, }; +use crate::{extract_ptr_with_type, make_free_method}; +use alloc::{boxed::Box, format, string::String, string::ToString}; +use app_zcash::get_address; use core::slice; +use cryptoxide::hashing::sha256; use cty::c_char; -use keystore::algorithms::zcash::{calculate_seed_fingerprint, derive_ufvk}; +use keystore::algorithms::{ + secp256k1::get_private_key_by_seed, + zcash::{calculate_seed_fingerprint, derive_ufvk}, +}; use structs::DisplayPczt; use ur_registry::{traits::RegistryItem, zcash::zcash_pczt::ZcashPczt}; use zcash_vendor::zcash_protocol::consensus::MainNetwork; @@ -125,3 +129,122 @@ pub extern "C" fn sign_zcash_tx(tx: PtrUR, seed: PtrBytes, seed_len: u32) -> *mu } make_free_method!(TransactionParseResult); + +use aes::cipher::block_padding::Pkcs7; +use aes::cipher::generic_array::GenericArray; +use aes::cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit}; + +type Aes256CbcEnc = cbc::Encryptor; +type Aes256CbcDec = cbc::Decryptor; + +#[no_mangle] +pub extern "C" fn rust_aes256_cbc_encrypt( + data: PtrString, + password: PtrString, + iv: PtrBytes, + iv_len: u32, +) -> *mut SimpleResponse { + let data = recover_c_char(data); + let data = data.as_bytes(); + let password = recover_c_char(password); + let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; + let key = sha256(password.as_bytes()); + let iv = GenericArray::from_slice(&iv); + let key = GenericArray::from_slice(&key); + let ct = Aes256CbcEnc::new(key, iv).encrypt_padded_vec_mut::(data); + SimpleResponse::success(convert_c_char(hex::encode(ct))).simple_c_ptr() +} + +#[no_mangle] +pub extern "C" fn rust_aes256_cbc_decrypt( + hex_data: PtrString, + password: PtrString, + iv: PtrBytes, + iv_len: u32, +) -> *mut SimpleResponse { + let hex_data = recover_c_char(hex_data); + let data = hex::decode(hex_data).unwrap(); + let password = recover_c_char(password); + let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; + let key = sha256(password.as_bytes()); + let iv = GenericArray::from_slice(&iv); + let key = GenericArray::from_slice(&key); + + match Aes256CbcDec::new(key, iv).decrypt_padded_vec_mut::(&data) { + Ok(pt) => { + SimpleResponse::success(convert_c_char(String::from_utf8(pt).unwrap())).simple_c_ptr() + } + Err(_e) => SimpleResponse::from(RustCError::InvalidHex("decrypt failed".to_string())) + .simple_c_ptr(), + } +} + +#[no_mangle] +pub extern "C" fn rust_derive_iv_from_seed( + seed: PtrBytes, + seed_len: u32, +) -> *mut SimpleResponse { + let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; + let iv_path = "m/44'/1557192335'/0'/2'/0'".to_string(); + let iv = get_private_key_by_seed(seed, &iv_path).unwrap(); + let mut iv_bytes = [0; 16]; + iv_bytes.copy_from_slice(&iv[..16]); + SimpleResponse::success(Box::into_raw(Box::new(iv_bytes)) as *mut u8).simple_c_ptr() +} + +#[cfg(test)] +mod tests { + use alloc::{string::String, vec::Vec}; + + use super::*; + + #[test] + fn test_aes256_cbc_encrypt() { + let mut data = convert_c_char("hello world".to_string()); + let mut password = convert_c_char("password".to_string()); + let mut seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); + let iv = rust_derive_iv_from_seed(seed.as_mut_ptr(), 64); + let mut iv = unsafe { slice::from_raw_parts_mut((*iv).data, 16) }; + let iv_len = 16; + let ct = rust_aes256_cbc_encrypt(data, password, iv.as_mut_ptr(), iv_len as u32); + let ct_vec = unsafe { (*ct).data }; + let value = recover_c_char(ct_vec); + assert_eq!(value, "639194f4bf964e15d8ea9c9bd9d96918"); + } + + #[test] + fn test_aes256_cbc_decrypt() { + let data = convert_c_char("639194f4bf964e15d8ea9c9bd9d96918".to_string()); + let password = convert_c_char("password".to_string()); + let mut seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); + let iv = rust_derive_iv_from_seed(seed.as_mut_ptr(), 64); + let iv = unsafe { slice::from_raw_parts_mut((*iv).data, 16) }; + let iv_len = 16; + let pt = rust_aes256_cbc_decrypt(data, password, iv.as_mut_ptr(), iv_len as u32); + assert!(!pt.is_null()); + let ct_vec = unsafe { (*pt).data }; + let value = recover_c_char(ct_vec); + assert_eq!(value, "hello world"); + } + + #[test] + fn test_dep_aes256() { + let mut data = b"hello world"; + let seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); + let iv_path = "m/44'/1557192335'/0'/2'/0'".to_string(); + let iv = get_private_key_by_seed(&seed, &iv_path).unwrap(); + let mut iv_bytes = [0; 16]; + iv_bytes.copy_from_slice(&iv[..16]); + let key = sha256(b"password"); + let iv = GenericArray::from_slice(&iv_bytes); + let key = GenericArray::from_slice(&key); + + let encrypter = Aes256CbcEnc::new(key, iv); + let decrypter = Aes256CbcDec::new(key, iv); + + let ct = encrypter.encrypt_padded_vec_mut::(data); + let pt = decrypter.decrypt_padded_vec_mut::(&ct).unwrap(); + + assert_eq!(String::from_utf8(pt).unwrap(), "hello world"); + } +} From a16a58893bc5043d634127192988d431b1649aee Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 18:59:55 +0800 Subject: [PATCH 10/31] style: run rust fix --- rust/apps/cardano/src/governance.rs | 2 +- rust/apps/cardano/src/structs.rs | 47 +++++++++++------------ rust/apps/cardano/src/transaction.rs | 2 +- rust/apps/zcash/src/pczt/parse.rs | 2 +- rust/keystore/src/algorithms/zcash/mod.rs | 5 +-- rust/zcash_vendor/src/pczt_ext.rs | 6 +-- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/rust/apps/cardano/src/governance.rs b/rust/apps/cardano/src/governance.rs index 3b27bb832..335ff3821 100644 --- a/rust/apps/cardano/src/governance.rs +++ b/rust/apps/cardano/src/governance.rs @@ -5,7 +5,7 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; use cardano_serialization_lib::protocol_types::Address; use cryptoxide::hashing::blake2b_256; -use ed25519_bip32_core::{XPrv, XPub}; +use ed25519_bip32_core::{XPrv}; use hex; use ur_registry::cardano::cardano_delegation::CardanoDelegation; use ur_registry::cardano::governance::CardanoVotingRegistration; diff --git a/rust/apps/cardano/src/structs.rs b/rust/apps/cardano/src/structs.rs index 03408dadd..aaf8c83c0 100644 --- a/rust/apps/cardano/src/structs.rs +++ b/rust/apps/cardano/src/structs.rs @@ -1,4 +1,4 @@ -use crate::address::{derive_address, derive_pubkey_hash, AddressType}; +use crate::address::{derive_pubkey_hash}; use crate::errors::{CardanoError, R}; use alloc::collections::BTreeMap; use alloc::string::{String, ToString}; @@ -6,15 +6,14 @@ use alloc::vec; use alloc::vec::Vec; use app_utils::{impl_internal_struct, impl_public_struct}; use cardano_serialization_lib::protocol_types::{ - self, Address, BaseAddress, EnterpriseAddress, RewardAddress, + Address, BaseAddress, EnterpriseAddress, RewardAddress, }; -use cardano_serialization_lib::protocol_types::numeric::BigNum; -use cardano_serialization_lib::protocol_types::{Anchor, DRepKind}; -use cardano_serialization_lib::protocol_types::{Ed25519KeyHash, ScriptHash}; + +use cardano_serialization_lib::protocol_types::{DRepKind}; + use cardano_serialization_lib::{ - protocol_types::FixedTransaction as Transaction, protocol_types::VoteKind, Certificate, - CertificateKind, NetworkId, NetworkIdKind, + protocol_types::FixedTransaction as Transaction, protocol_types::VoteKind, NetworkIdKind, }; use alloc::format; @@ -190,7 +189,7 @@ impl ParsedCardanoSignData { xpub, }) } - Err(e) => Ok(Self { + Err(_e) => Ok(Self { payload: hex::encode(sign_data.clone()), derivation_path, message_hash: hex::encode(sign_data), @@ -510,12 +509,12 @@ impl ParsedCardanoTx { CertField { label: LABEL_HOT_KEY.to_string(), value: match _cert.committee_hot_credential().kind() { - Ed25519KeyHash => _cert + _Ed25519KeyHash => _cert .committee_hot_credential() .to_keyhash() .unwrap() .to_string(), - ScriptHash => _cert + _ScriptHash => _cert .committee_hot_credential() .to_scripthash() .unwrap() @@ -525,12 +524,12 @@ impl ParsedCardanoTx { CertField { label: LABEL_COLD_KEY.to_string(), value: match _cert.committee_cold_credential().kind() { - Ed25519KeyHash => _cert + _Ed25519KeyHash => _cert .committee_cold_credential() .to_keyhash() .unwrap() .to_string(), - ScriptHash => _cert + _ScriptHash => _cert .committee_cold_credential() .to_scripthash() .unwrap() @@ -547,12 +546,12 @@ impl ParsedCardanoTx { let mut fields = vec![CertField { label: LABEL_COLD_KEY.to_string(), value: match _cert.committee_cold_credential().kind() { - Ed25519KeyHash => _cert + _Ed25519KeyHash => _cert .committee_cold_credential() .to_keyhash() .unwrap() .to_string(), - ScriptHash => _cert + _ScriptHash => _cert .committee_cold_credential() .to_scripthash() .unwrap() @@ -577,7 +576,7 @@ impl ParsedCardanoTx { if let Some(_cert) = cert.as_drep_deregistration() { let deposit = normalize_coin(u64::from(&_cert.coin())); let (variant1, variant1_label) = match _cert.voting_credential().kind() { - Ed25519KeyHash => ( + _Ed25519KeyHash => ( _cert .voting_credential() .to_keyhash() @@ -586,7 +585,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - ScriptHash => ( + _ScriptHash => ( _cert .voting_credential() .to_scripthash() @@ -614,7 +613,7 @@ impl ParsedCardanoTx { if let Some(_cert) = cert.as_drep_registration() { let deposit = normalize_coin(u64::from(&_cert.coin())); let (variant1, variant1_label) = match _cert.voting_credential().kind() { - Ed25519KeyHash => ( + _Ed25519KeyHash => ( _cert .voting_credential() .to_keyhash() @@ -623,7 +622,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - ScriptHash => ( + _ScriptHash => ( _cert .voting_credential() .to_scripthash() @@ -668,7 +667,7 @@ impl ParsedCardanoTx { None => None, }; let (variant1, variant1_label) = match _cert.voting_credential().kind() { - Ed25519KeyHash => ( + _Ed25519KeyHash => ( _cert .voting_credential() .to_keyhash() @@ -677,7 +676,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - ScriptHash => ( + _ScriptHash => ( _cert .voting_credential() .to_scripthash() @@ -1039,7 +1038,7 @@ impl ParsedCardanoTx { fn parse_inputs( tx: &Transaction, context: &ParseContext, - network_id: u8, + _network_id: u8, ) -> R> { let inputs_len = tx.body().inputs().len(); let mut parsed_inputs: Vec = vec![]; @@ -1091,7 +1090,7 @@ impl ParsedCardanoTx { index.clone(), )?); - let mut address = utxo.address.clone(); + let address = utxo.address.clone(); let addr_in_utxo = Address::from_bech32(&utxo.address) .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?; @@ -1159,8 +1158,8 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::AddressEncodingError(e.to_string()))?, amount: normalize_coin(u64::from(&output.amount().coin())), value: u64::from(&output.amount().coin()), - assets: output.amount().multiasset().map(|v| { - let mut parsed_multi_assets = vec![]; + assets: output.amount().multiasset().map(|_v| { + let parsed_multi_assets = vec![]; // temporary comment multi assets parse logic because it consumes a lot of memory but we don't display it on UI // let len = v.keys().len(); diff --git a/rust/apps/cardano/src/transaction.rs b/rust/apps/cardano/src/transaction.rs index c5970141c..e5ce49ff9 100644 --- a/rust/apps/cardano/src/transaction.rs +++ b/rust/apps/cardano/src/transaction.rs @@ -6,7 +6,7 @@ use alloc::vec::Vec; use cardano_serialization_lib; use cardano_serialization_lib::protocol_types::{Ed25519Signature, PublicKey, Vkey, Vkeywitness}; use cryptoxide::hashing::blake2b_256; -use ed25519_bip32_core::{XPrv, XPub}; +use ed25519_bip32_core::{XPrv}; use hex; use ur_registry::crypto_key_path::CryptoKeyPath; diff --git a/rust/apps/zcash/src/pczt/parse.rs b/rust/apps/zcash/src/pczt/parse.rs index 3f003c998..a8e0457de 100644 --- a/rust/apps/zcash/src/pczt/parse.rs +++ b/rust/apps/zcash/src/pczt/parse.rs @@ -10,7 +10,7 @@ use zcash_vendor::{ orchard::{ self, keys::OutgoingViewingKey, note::Note, note_encryption::OrchardDomain, Address, }, - pczt::{self, roles::verifier::Verifier, sapling, Pczt}, + pczt::{self, roles::verifier::Verifier, Pczt}, ripemd::{Digest, Ripemd160}, sha2::Sha256, transparent::{self, address::TransparentAddress}, diff --git a/rust/keystore/src/algorithms/zcash/mod.rs b/rust/keystore/src/algorithms/zcash/mod.rs index cc3cbfbab..f59f74b7c 100644 --- a/rust/keystore/src/algorithms/zcash/mod.rs +++ b/rust/keystore/src/algorithms/zcash/mod.rs @@ -2,7 +2,6 @@ use core::str::FromStr; use alloc::{ string::{String, ToString}, - vec::Vec, }; use bitcoin::bip32::{ChildNumber, DerivationPath}; use hex; @@ -12,11 +11,11 @@ use rand_core::{CryptoRng, RngCore}; use zcash_vendor::{ orchard::{ self, - keys::{SpendAuthorizingKey, SpendValidatingKey, SpendingKey}, + keys::{SpendAuthorizingKey, SpendingKey}, }, pasta_curves::{group::ff::PrimeField, Fq}, zcash_keys::keys::UnifiedSpendingKey, - zcash_protocol::consensus::{self, MAIN_NETWORK}, + zcash_protocol::consensus::{self}, zip32::{self, fingerprint::SeedFingerprint, AccountId}, }; diff --git a/rust/zcash_vendor/src/pczt_ext.rs b/rust/zcash_vendor/src/pczt_ext.rs index 066258d4b..357758ec1 100644 --- a/rust/zcash_vendor/src/pczt_ext.rs +++ b/rust/zcash_vendor/src/pczt_ext.rs @@ -1,14 +1,14 @@ use crate::pczt::Pczt; -use alloc::collections::btree_map::BTreeMap; + use alloc::vec::Vec; use blake2b_simd::{Hash, Params, State}; -use orchard::pczt::Zip32Derivation; + use pczt::{ common::determine_lock_time, roles::low_level_signer::Signer, transparent::{Input, Output}, }; -use transparent::{pczt::Bip32Derivation, sighash::SignableInput}; +use transparent::{sighash::SignableInput}; use zcash_protocol::value::ZatBalance; /// TxId tree root personalization From f61832f9e51e70bdd16ebf881ae721be4cb0d32f Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 19:01:52 +0800 Subject: [PATCH 11/31] style: run rust fmt --- rust/apps/cardano/src/governance.rs | 2 +- rust/apps/cardano/src/structs.rs | 5 ++--- rust/apps/cardano/src/transaction.rs | 2 +- rust/keystore/src/algorithms/zcash/mod.rs | 4 +--- rust/rust_c/build.rs | 9 +++++++-- rust/rust_c/src/aptos/mod.rs | 14 ++++++------- rust/rust_c/src/aptos/structs.rs | 4 ++-- rust/rust_c/src/arweave/structs.rs | 14 ++++++------- rust/rust_c/src/bitcoin/address.rs | 6 +++--- rust/rust_c/src/bitcoin/legacy.rs | 4 ++-- rust/rust_c/src/bitcoin/msg.rs | 14 ++++++------- rust/rust_c/src/bitcoin/multi_sig/structs.rs | 6 +++--- rust/rust_c/src/bitcoin/psbt.rs | 8 ++++---- rust/rust_c/src/bitcoin/structs.rs | 4 ++-- rust/rust_c/src/cardano/address.rs | 4 ++-- rust/rust_c/src/cardano/mod.rs | 4 ++-- rust/rust_c/src/common/errors.rs | 4 ++-- rust/rust_c/src/common/free.rs | 2 +- rust/rust_c/src/common/mod.rs | 2 +- rust/rust_c/src/common/ur_ext.rs | 20 +++++++++---------- rust/rust_c/src/common/utils.rs | 2 +- rust/rust_c/src/cosmos/mod.rs | 14 ++++++------- rust/rust_c/src/ethereum/address.rs | 2 +- rust/rust_c/src/near/mod.rs | 10 +++++----- rust/rust_c/src/solana/mod.rs | 12 +++++------ rust/rust_c/src/stellar/mod.rs | 8 ++++---- rust/rust_c/src/sui/mod.rs | 8 ++++---- rust/rust_c/src/tron/mod.rs | 6 +++--- rust/rust_c/src/wallet/btc_only_wallet.rs | 4 ++-- rust/rust_c/src/wallet/mod.rs | 2 +- .../src/wallet/multi_coins_wallet/aptos.rs | 2 +- .../wallet/multi_coins_wallet/arconnect.rs | 6 +++--- .../src/wallet/multi_coins_wallet/backpack.rs | 4 ++-- .../src/wallet/multi_coins_wallet/bitget.rs | 4 ++-- .../src/wallet/multi_coins_wallet/imtoken.rs | 8 ++++---- .../src/wallet/multi_coins_wallet/keplr.rs | 10 +++++----- .../src/wallet/multi_coins_wallet/keystone.rs | 4 ++-- .../src/wallet/multi_coins_wallet/okx.rs | 4 ++-- .../src/wallet/multi_coins_wallet/solana.rs | 2 +- .../src/wallet/multi_coins_wallet/sui.rs | 8 ++++---- .../src/wallet/multi_coins_wallet/utils.rs | 6 +++--- .../src/wallet/multi_coins_wallet/xbull.rs | 2 +- .../wallet/multi_coins_wallet/xrp_toolkit.rs | 2 +- .../src/wallet/multi_coins_wallet/zcash.rs | 10 +++++----- rust/rust_c/src/xrp/mod.rs | 2 +- rust/zcash_vendor/src/pczt_ext.rs | 2 +- 46 files changed, 139 insertions(+), 137 deletions(-) diff --git a/rust/apps/cardano/src/governance.rs b/rust/apps/cardano/src/governance.rs index 335ff3821..a2797d531 100644 --- a/rust/apps/cardano/src/governance.rs +++ b/rust/apps/cardano/src/governance.rs @@ -5,7 +5,7 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; use cardano_serialization_lib::protocol_types::Address; use cryptoxide::hashing::blake2b_256; -use ed25519_bip32_core::{XPrv}; +use ed25519_bip32_core::XPrv; use hex; use ur_registry::cardano::cardano_delegation::CardanoDelegation; use ur_registry::cardano::governance::CardanoVotingRegistration; diff --git a/rust/apps/cardano/src/structs.rs b/rust/apps/cardano/src/structs.rs index aaf8c83c0..c46fe2d9c 100644 --- a/rust/apps/cardano/src/structs.rs +++ b/rust/apps/cardano/src/structs.rs @@ -1,4 +1,4 @@ -use crate::address::{derive_pubkey_hash}; +use crate::address::derive_pubkey_hash; use crate::errors::{CardanoError, R}; use alloc::collections::BTreeMap; use alloc::string::{String, ToString}; @@ -9,8 +9,7 @@ use cardano_serialization_lib::protocol_types::{ Address, BaseAddress, EnterpriseAddress, RewardAddress, }; - -use cardano_serialization_lib::protocol_types::{DRepKind}; +use cardano_serialization_lib::protocol_types::DRepKind; use cardano_serialization_lib::{ protocol_types::FixedTransaction as Transaction, protocol_types::VoteKind, NetworkIdKind, diff --git a/rust/apps/cardano/src/transaction.rs b/rust/apps/cardano/src/transaction.rs index e5ce49ff9..cb3e08568 100644 --- a/rust/apps/cardano/src/transaction.rs +++ b/rust/apps/cardano/src/transaction.rs @@ -6,7 +6,7 @@ use alloc::vec::Vec; use cardano_serialization_lib; use cardano_serialization_lib::protocol_types::{Ed25519Signature, PublicKey, Vkey, Vkeywitness}; use cryptoxide::hashing::blake2b_256; -use ed25519_bip32_core::{XPrv}; +use ed25519_bip32_core::XPrv; use hex; use ur_registry::crypto_key_path::CryptoKeyPath; diff --git a/rust/keystore/src/algorithms/zcash/mod.rs b/rust/keystore/src/algorithms/zcash/mod.rs index f59f74b7c..fcf7a1f8e 100644 --- a/rust/keystore/src/algorithms/zcash/mod.rs +++ b/rust/keystore/src/algorithms/zcash/mod.rs @@ -1,8 +1,6 @@ use core::str::FromStr; -use alloc::{ - string::{String, ToString}, -}; +use alloc::string::{String, ToString}; use bitcoin::bip32::{ChildNumber, DerivationPath}; use hex; use rand_chacha::rand_core::SeedableRng; diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index df90db38d..922b3c625 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -18,8 +18,13 @@ fn main() { "debug-btc-only", ]; assert!(features.len() > 0, "No build variant enabled"); - assert!(features.len() == 1, "Multiple build variants enabled: {:?}", features); - let output_target = env::var("CBINDGEN_BINDINGS_TARGET").unwrap_or(format!("bindings/{}/librust_c.h", features[0])); + assert!( + features.len() == 1, + "Multiple build variants enabled: {:?}", + features + ); + let output_target = env::var("CBINDGEN_BINDINGS_TARGET") + .unwrap_or(format!("bindings/{}/librust_c.h", features[0])); config.parse.expand.features = Some(features.into_iter().map(|s| s.to_string()).collect()); let builder = cbindgen::Builder::new(); diff --git a/rust/rust_c/src/aptos/mod.rs b/rust/rust_c/src/aptos/mod.rs index 7029ed6b9..d2ee3e8e9 100644 --- a/rust/rust_c/src/aptos/mod.rs +++ b/rust/rust_c/src/aptos/mod.rs @@ -1,4 +1,9 @@ -use structs::DisplayAptosTx; +use crate::common::errors::RustCError; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; use alloc::format; use alloc::slice; use alloc::string::ToString; @@ -6,15 +11,10 @@ use alloc::vec::Vec; use app_aptos; use app_aptos::errors::AptosError; use app_aptos::parser::is_tx; -use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; -use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use crate::common::utils::{convert_c_char, recover_c_char}; use cty::c_char; use hex; use hex::FromHex; +use structs::DisplayAptosTx; use ur_registry::aptos::aptos_sign_request::{AptosSignRequest, SignType}; use ur_registry::aptos::aptos_signature::AptosSignature; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/aptos/structs.rs b/rust/rust_c/src/aptos/structs.rs index f23d20dba..2f2b77acf 100644 --- a/rust/rust_c/src/aptos/structs.rs +++ b/rust/rust_c/src/aptos/structs.rs @@ -1,10 +1,10 @@ -use alloc::string::{String, ToString}; -use app_aptos::parser::AptosTx; use crate::common::free::Free; use crate::common::structs::TransactionParseResult; use crate::common::types::{PtrString, PtrT}; use crate::common::utils::convert_c_char; use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use alloc::string::{String, ToString}; +use app_aptos::parser::AptosTx; use serde_json::Value; #[repr(C)] diff --git a/rust/rust_c/src/arweave/structs.rs b/rust/rust_c/src/arweave/structs.rs index bec53ee75..d05d37825 100644 --- a/rust/rust_c/src/arweave/structs.rs +++ b/rust/rust_c/src/arweave/structs.rs @@ -1,15 +1,15 @@ -use core::ptr::null_mut; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{Ptr, PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, free_vec, impl_c_ptr, make_free_method}; use alloc::vec::Vec; use app_arweave::{ ao_transaction::AOTransferTransaction, data_item::{DataItem, Tag}, }; -use crate::common::free::Free; -use crate::common::structs::TransactionParseResult; -use crate::common::types::{Ptr, PtrString, PtrT}; -use crate::common::utils::convert_c_char; -use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method, free_vec}; -use crate::common::ffi::VecFFI; +use core::ptr::null_mut; #[repr(C)] pub enum ArweaveRequestType { diff --git a/rust/rust_c/src/bitcoin/address.rs b/rust/rust_c/src/bitcoin/address.rs index 655fea642..a0ac321cc 100644 --- a/rust/rust_c/src/bitcoin/address.rs +++ b/rust/rust_c/src/bitcoin/address.rs @@ -1,9 +1,9 @@ -use app_bitcoin; -use app_bitcoin::addresses::xyzpub; -use bitcoin::secp256k1::ffi::types::c_char; use crate::common::structs::SimpleResponse; use crate::common::types::PtrString; use crate::common::utils::{convert_c_char, recover_c_char}; +use app_bitcoin; +use app_bitcoin::addresses::xyzpub; +use bitcoin::secp256k1::ffi::types::c_char; use core::str::FromStr; #[no_mangle] diff --git a/rust/rust_c/src/bitcoin/legacy.rs b/rust/rust_c/src/bitcoin/legacy.rs index f0eae8f28..e7d23afed 100644 --- a/rust/rust_c/src/bitcoin/legacy.rs +++ b/rust/rust_c/src/bitcoin/legacy.rs @@ -1,12 +1,12 @@ use super::structs::DisplayTx; -use alloc::boxed::Box; -use alloc::slice; use crate::common::errors::RustCError; use crate::common::keystone; use crate::common::keystone::{build_parse_context, build_payload}; use crate::common::structs::{TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{QRCodeType, UREncodeResult}; +use alloc::boxed::Box; +use alloc::slice; #[no_mangle] pub extern "C" fn utxo_parse_keystone( diff --git a/rust/rust_c/src/bitcoin/msg.rs b/rust/rust_c/src/bitcoin/msg.rs index da66b535d..547cf0bfc 100644 --- a/rust/rust_c/src/bitcoin/msg.rs +++ b/rust/rust_c/src/bitcoin/msg.rs @@ -1,11 +1,4 @@ -use core::ptr::null_mut; use super::structs::DisplayBtcMsg; -use alloc::{ - slice, - string::{String, ToString}, - vec::Vec, -}; -use base64; use crate::common::{ errors::RustCError, ffi::CSliceFFI, @@ -16,6 +9,13 @@ use crate::common::{ utils::{convert_c_char, recover_c_array, recover_c_char}, }; use crate::extract_ptr_with_type; +use alloc::{ + slice, + string::{String, ToString}, + vec::Vec, +}; +use base64; +use core::ptr::null_mut; use keystore::algorithms::secp256k1; use ur_registry::bitcoin::btc_sign_request::{BtcSignRequest, DataType}; use ur_registry::bitcoin::btc_signature::BtcSignature; diff --git a/rust/rust_c/src/bitcoin/multi_sig/structs.rs b/rust/rust_c/src/bitcoin/multi_sig/structs.rs index 83b69a2b1..444d3f3f6 100644 --- a/rust/rust_c/src/bitcoin/multi_sig/structs.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/structs.rs @@ -2,15 +2,15 @@ use alloc::boxed::Box; use alloc::format; use alloc::string::ToString; -use alloc::vec::Vec; -use app_bitcoin::multi_sig::wallet::{BsmsWallet, MultiSigWalletConfig}; -use app_bitcoin::multi_sig::{MultiSigFormat, MultiSigType, MultiSigXPubInfo, Network}; use crate::common::ffi::VecFFI; use crate::common::free::Free; use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT}; use crate::common::ur::UREncodeResult; use crate::common::utils::{convert_c_char, recover_c_char}; use crate::{check_and_free_ptr, free_str_ptr, free_vec, impl_c_ptr, make_free_method}; +use alloc::vec::Vec; +use app_bitcoin::multi_sig::wallet::{BsmsWallet, MultiSigWalletConfig}; +use app_bitcoin::multi_sig::{MultiSigFormat, MultiSigType, MultiSigXPubInfo, Network}; #[repr(C)] pub enum NetworkType { diff --git a/rust/rust_c/src/bitcoin/psbt.rs b/rust/rust_c/src/bitcoin/psbt.rs index c96c9901d..41abaaa7b 100644 --- a/rust/rust_c/src/bitcoin/psbt.rs +++ b/rust/rust_c/src/bitcoin/psbt.rs @@ -7,11 +7,7 @@ use app_bitcoin::multi_sig::wallet::parse_wallet_config; use core::ptr::null_mut; use core::str::FromStr; -use app_bitcoin::parsed_tx::ParseContext; -use app_bitcoin::{self, parse_psbt_hex_sign_status, parse_psbt_sign_status}; -use bitcoin::bip32::{DerivationPath, Xpub}; use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; use crate::common::ffi::{CSliceFFI, VecFFI}; use crate::common::structs::{ ExtendedPublicKey, Response, TransactionCheckResult, TransactionParseResult, @@ -19,6 +15,10 @@ use crate::common::structs::{ use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH}; use crate::common::utils::{convert_c_char, recover_c_array, recover_c_char}; +use crate::extract_ptr_with_type; +use app_bitcoin::parsed_tx::ParseContext; +use app_bitcoin::{self, parse_psbt_hex_sign_status, parse_psbt_sign_status}; +use bitcoin::bip32::{DerivationPath, Xpub}; use hex; use ur_registry::crypto_psbt::CryptoPSBT; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/bitcoin/structs.rs b/rust/rust_c/src/bitcoin/structs.rs index 323d9c6ba..b99c31bf8 100644 --- a/rust/rust_c/src/bitcoin/structs.rs +++ b/rust/rust_c/src/bitcoin/structs.rs @@ -2,8 +2,6 @@ use alloc::boxed::Box; use alloc::vec::Vec; use core::ptr::null_mut; -use app_bitcoin; -use app_bitcoin::parsed_tx::{DetailTx, OverviewTx, ParsedInput, ParsedOutput, ParsedTx}; use crate::common::ffi::VecFFI; use crate::common::free::Free; use crate::common::structs::Response; @@ -12,6 +10,8 @@ use crate::common::types::{PtrString, PtrT}; use crate::common::ur::UREncodeResult; use crate::common::utils::convert_c_char; use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use app_bitcoin; +use app_bitcoin::parsed_tx::{DetailTx, OverviewTx, ParsedInput, ParsedOutput, ParsedTx}; #[repr(C)] pub struct PsbtSignResult { diff --git a/rust/rust_c/src/cardano/address.rs b/rust/rust_c/src/cardano/address.rs index bde4fa0a1..0b5bc3526 100644 --- a/rust/rust_c/src/cardano/address.rs +++ b/rust/rust_c/src/cardano/address.rs @@ -1,8 +1,8 @@ -use app_cardano; -use app_cardano::address::AddressType; use crate::common::structs::SimpleResponse; use crate::common::types::PtrString; use crate::common::utils::{convert_c_char, recover_c_char}; +use app_cardano; +use app_cardano::address::AddressType; use cty::c_char; #[no_mangle] diff --git a/rust/rust_c/src/cardano/mod.rs b/rust/rust_c/src/cardano/mod.rs index 9f34865ea..7d1058ad5 100644 --- a/rust/rust_c/src/cardano/mod.rs +++ b/rust/rust_c/src/cardano/mod.rs @@ -26,13 +26,13 @@ use ur_registry::cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest use ur_registry::cardano::cardano_signature::CardanoSignature; use ur_registry::crypto_key_path::CryptoKeyPath; -use structs::{DisplayCardanoCatalyst, DisplayCardanoSignData, DisplayCardanoTx}; use crate::common::errors::{RustCError, R}; -use crate::extract_ptr_with_type; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; +use structs::{DisplayCardanoCatalyst, DisplayCardanoSignData, DisplayCardanoTx}; use ur_registry::registry_types::{ CARDANO_CATALYST_VOTING_REGISTRATION_SIGNATURE, CARDANO_SIGNATURE, CARDANO_SIGN_DATA_SIGNATURE, }; diff --git a/rust/rust_c/src/common/errors.rs b/rust/rust_c/src/common/errors.rs index e9f921201..979742cea 100644 --- a/rust/rust_c/src/common/errors.rs +++ b/rust/rust_c/src/common/errors.rs @@ -4,12 +4,12 @@ use thiserror; use thiserror::Error; use ur_registry::error::URError; -#[cfg(feature = "bitcoin")] -use app_bitcoin::errors::BitcoinError; #[cfg(feature = "aptos")] use app_aptos::errors::AptosError; #[cfg(feature = "arweave")] use app_arweave::errors::ArweaveError; +#[cfg(feature = "bitcoin")] +use app_bitcoin::errors::BitcoinError; #[cfg(feature = "cardano")] use app_cardano::errors::CardanoError; #[cfg(feature = "cosmos")] diff --git a/rust/rust_c/src/common/free.rs b/rust/rust_c/src/common/free.rs index eeaa625ec..a4a2b9fea 100644 --- a/rust/rust_c/src/common/free.rs +++ b/rust/rust_c/src/common/free.rs @@ -1,8 +1,8 @@ use super::ffi::VecFFI; -use crate::make_free_method; use super::structs::SimpleResponse; use super::types::{PtrString, PtrT}; use super::ur::{UREncodeMultiResult, UREncodeResult, URParseMultiResult, URParseResult}; +use crate::make_free_method; use alloc::boxed::Box; use cty::{c_char, c_void}; diff --git a/rust/rust_c/src/common/mod.rs b/rust/rust_c/src/common/mod.rs index 60f4ef877..4f263908e 100644 --- a/rust/rust_c/src/common/mod.rs +++ b/rust/rust_c/src/common/mod.rs @@ -293,4 +293,4 @@ pub extern "C" fn pbkdf2_rust_64( #[no_mangle] pub extern "C" fn tx_check_pass() -> Ptr { TransactionCheckResult::new().c_ptr() -} \ No newline at end of file +} diff --git a/rust/rust_c/src/common/ur_ext.rs b/rust/rust_c/src/common/ur_ext.rs index 5add8ae8d..409766911 100644 --- a/rust/rust_c/src/common/ur_ext.rs +++ b/rust/rust_c/src/common/ur_ext.rs @@ -4,22 +4,13 @@ use alloc::vec::Vec; use serde_json::{from_slice, from_value, Value}; -use ur_registry::bytes::Bytes; -use ur_registry::crypto_account::CryptoAccount; -use ur_registry::crypto_psbt::CryptoPSBT; -use ur_registry::error::URError; -use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; -use ur_registry::pb::protobuf_parser::{parse_protobuf, unzip}; -use ur_registry::pb::protoc; -use ur_registry::pb::protoc::Base; -#[cfg(feature = "multi-coins")] -use ur_registry::extend::qr_hardware_call::{CallType, QRHardwareCall}; #[cfg(feature = "aptos")] use ur_registry::aptos::aptos_sign_request::AptosSignRequest; #[cfg(feature = "arweave")] use ur_registry::arweave::arweave_sign_request::{ArweaveSignRequest, SignType}; #[cfg(feature = "bitcoin")] use ur_registry::bitcoin::btc_sign_request::BtcSignRequest; +use ur_registry::bytes::Bytes; #[cfg(feature = "cardano")] use ur_registry::cardano::cardano_catalyst_voting_registration::CardanoCatalystVotingRegistrationRequest; #[cfg(feature = "cardano")] @@ -32,14 +23,23 @@ use ur_registry::cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest use ur_registry::cosmos::cosmos_sign_request::CosmosSignRequest; #[cfg(feature = "cosmos")] use ur_registry::cosmos::evm_sign_request::EvmSignRequest; +use ur_registry::crypto_account::CryptoAccount; +use ur_registry::crypto_psbt::CryptoPSBT; +use ur_registry::error::URError; #[cfg(feature = "ethereum")] use ur_registry::ethereum::eth_sign_request; #[cfg(feature = "ethereum")] use ur_registry::ethereum::eth_sign_request::EthSignRequest; +use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; +#[cfg(feature = "multi-coins")] +use ur_registry::extend::qr_hardware_call::{CallType, QRHardwareCall}; #[cfg(feature = "multi-coins")] use ur_registry::keystone::keystone_sign_request::KeystoneSignRequest; #[cfg(feature = "near")] use ur_registry::near::near_sign_request::NearSignRequest; +use ur_registry::pb::protobuf_parser::{parse_protobuf, unzip}; +use ur_registry::pb::protoc; +use ur_registry::pb::protoc::Base; #[cfg(feature = "solana")] use ur_registry::solana::sol_sign_request::SolSignRequest; #[cfg(feature = "stellar")] diff --git a/rust/rust_c/src/common/utils.rs b/rust/rust_c/src/common/utils.rs index 2759b7df1..2da337da9 100644 --- a/rust/rust_c/src/common/utils.rs +++ b/rust/rust_c/src/common/utils.rs @@ -1,9 +1,9 @@ use alloc::string::{String, ToString}; use core::slice; -use crate::extract_ptr_with_type; use super::ffi::CSliceFFI; use super::free::Free; +use crate::extract_ptr_with_type; use cstr_core::{CStr, CString}; use cty::c_char; diff --git a/rust/rust_c/src/cosmos/mod.rs b/rust/rust_c/src/cosmos/mod.rs index b412e80b8..d32a0385f 100644 --- a/rust/rust_c/src/cosmos/mod.rs +++ b/rust/rust_c/src/cosmos/mod.rs @@ -1,21 +1,21 @@ pub mod structs; -use structs::DisplayCosmosTx; +use crate::common::errors::RustCError; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; use app_cosmos::errors::CosmosError; use app_cosmos::transaction::structs::SignMode; use app_utils::normalize_path; -use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; -use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use crate::common::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use crate::common::utils::{convert_c_char, recover_c_char}; use core::slice; use cty::c_char; use either::Either; +use structs::DisplayCosmosTx; use ur_registry::cosmos::cosmos_sign_request::{CosmosSignRequest, DataType}; use ur_registry::cosmos::cosmos_signature::CosmosSignature; use ur_registry::cosmos::evm_sign_request::{EvmSignRequest, SignDataType}; diff --git a/rust/rust_c/src/ethereum/address.rs b/rust/rust_c/src/ethereum/address.rs index f8d91961e..56deddb99 100644 --- a/rust/rust_c/src/ethereum/address.rs +++ b/rust/rust_c/src/ethereum/address.rs @@ -2,10 +2,10 @@ use alloc::format; use app_ethereum; use cty::c_char; -use app_ethereum::errors::EthereumError; use crate::common::structs::SimpleResponse; use crate::common::types::PtrString; use crate::common::utils::{convert_c_char, recover_c_char}; +use app_ethereum::errors::EthereumError; #[no_mangle] pub extern "C" fn eth_get_address( diff --git a/rust/rust_c/src/near/mod.rs b/rust/rust_c/src/near/mod.rs index 5839deafd..c1d6dcbe3 100644 --- a/rust/rust_c/src/near/mod.rs +++ b/rust/rust_c/src/near/mod.rs @@ -1,12 +1,12 @@ -use structs::DisplayNearTx; -use alloc::string::ToString; -use alloc::{format, vec}; -use app_near::errors::NearError; use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; use crate::common::structs::{TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::extract_ptr_with_type; +use alloc::string::ToString; +use alloc::{format, vec}; +use app_near::errors::NearError; +use structs::DisplayNearTx; use ur_registry::near::near_sign_request::NearSignRequest; use ur_registry::near::near_signature::NearSignature; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/solana/mod.rs b/rust/rust_c/src/solana/mod.rs index ee30c3940..2a2287c8f 100644 --- a/rust/rust_c/src/solana/mod.rs +++ b/rust/rust_c/src/solana/mod.rs @@ -1,15 +1,15 @@ -use structs::{DisplaySolanaMessage, DisplaySolanaTx}; -use alloc::format; -use alloc::string::ToString; -use app_solana::errors::SolanaError; -use app_solana::parse_message; use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; +use alloc::format; +use alloc::string::ToString; +use app_solana::errors::SolanaError; +use app_solana::parse_message; use cty::c_char; +use structs::{DisplaySolanaMessage, DisplaySolanaTx}; use ur_registry::solana::sol_sign_request::SolSignRequest; use ur_registry::solana::sol_signature::SolSignature; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/stellar/mod.rs b/rust/rust_c/src/stellar/mod.rs index 8a234eb63..5c6c832c9 100644 --- a/rust/rust_c/src/stellar/mod.rs +++ b/rust/rust_c/src/stellar/mod.rs @@ -4,16 +4,16 @@ use alloc::slice; use alloc::string::ToString; use cty::c_char; -use structs::DisplayStellarTx; -use app_stellar::strkeys::{sign_hash, sign_signature_base}; -use app_stellar::{address::get_address, base_to_xdr}; use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; +use app_stellar::strkeys::{sign_hash, sign_signature_base}; +use app_stellar::{address::get_address, base_to_xdr}; use hex; +use structs::DisplayStellarTx; use ur_registry::stellar::stellar_sign_request::{SignType, StellarSignRequest}; use ur_registry::stellar::stellar_signature::StellarSignature; use ur_registry::traits::{RegistryItem, To}; diff --git a/rust/rust_c/src/sui/mod.rs b/rust/rust_c/src/sui/mod.rs index c7b36c5fb..b87948f19 100644 --- a/rust/rust_c/src/sui/mod.rs +++ b/rust/rust_c/src/sui/mod.rs @@ -9,16 +9,16 @@ use ur_registry::sui::sui_sign_request::SuiSignRequest; use ur_registry::sui::sui_signature::SuiSignature; use ur_registry::traits::RegistryItem; -use app_sui::errors::SuiError; -use app_utils::normalize_path; use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{convert_c_char, recover_c_char}; -use structs::DisplaySuiSignMessageHash; +use crate::extract_ptr_with_type; +use app_sui::errors::SuiError; +use app_utils::normalize_path; use structs::DisplaySuiIntentMessage; +use structs::DisplaySuiSignMessageHash; pub mod structs; diff --git a/rust/rust_c/src/tron/mod.rs b/rust/rust_c/src/tron/mod.rs index 6fc23da01..335e5cd3d 100644 --- a/rust/rust_c/src/tron/mod.rs +++ b/rust/rust_c/src/tron/mod.rs @@ -1,15 +1,15 @@ pub mod structs; -use structs::DisplayTron; -use alloc::boxed::Box; -use alloc::slice; use crate::common::errors::RustCError; use crate::common::keystone; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{QRCodeType, UREncodeResult}; use crate::common::utils::{convert_c_char, recover_c_char}; +use alloc::boxed::Box; +use alloc::slice; use cty::c_char; +use structs::DisplayTron; #[no_mangle] pub extern "C" fn tron_check_keystone( diff --git a/rust/rust_c/src/wallet/btc_only_wallet.rs b/rust/rust_c/src/wallet/btc_only_wallet.rs index 0d09372ac..ec4fad978 100644 --- a/rust/rust_c/src/wallet/btc_only_wallet.rs +++ b/rust/rust_c/src/wallet/btc_only_wallet.rs @@ -3,14 +3,14 @@ use alloc::vec::Vec; use alloc::{format, vec}; use app_utils::normalize_path; -use bitcoin::bip32::{DerivationPath, Xpub}; use crate::common::errors::RustCError; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use bitcoin::bip32::{DerivationPath, Xpub}; use core::slice; use core::str::FromStr; use cty::{int32_t, uint32_t}; diff --git a/rust/rust_c/src/wallet/mod.rs b/rust/rust_c/src/wallet/mod.rs index 3d89d7745..7c467be25 100644 --- a/rust/rust_c/src/wallet/mod.rs +++ b/rust/rust_c/src/wallet/mod.rs @@ -1,4 +1,4 @@ pub mod btc_only_wallet; pub use btc_only_wallet::*; #[cfg(feature = "multi-coins")] -pub mod multi_coins_wallet; \ No newline at end of file +pub mod multi_coins_wallet; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs index d51cecd5d..d47899fe0 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs @@ -8,13 +8,13 @@ use ur_registry::error::URError; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; use ur_registry::traits::RegistryItem; -use app_wallets::aptos::generate_sync_ur; use crate::common::errors::RustCError; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::PtrT; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use app_wallets::aptos::generate_sync_ur; #[no_mangle] pub extern "C" fn get_connect_aptos_wallet_ur( diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs index bba618c1d..886865601 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs @@ -1,9 +1,9 @@ -use alloc::slice; -use alloc::vec::Vec; -use app_arweave::generate_public_key_from_primes; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::recover_c_char; +use alloc::slice; +use alloc::vec::Vec; +use app_arweave::generate_public_key_from_primes; use cty::uint32_t; use hex; use ur_registry::arweave::arweave_crypto_account::ArweaveCryptoAccount; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs index 484d6a4ac..be5e0299a 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs @@ -1,10 +1,10 @@ -use alloc::{format, string::ToString}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::{Ptr, PtrBytes}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::recover_c_array; +use crate::extract_array; +use alloc::{format, string::ToString}; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs index 99986f7f0..cdc34eb7d 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs @@ -1,10 +1,10 @@ -use alloc::{format, string::ToString}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use alloc::{format, string::ToString}; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs b/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs index abeb7c4e9..b5d9fe656 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs @@ -1,10 +1,10 @@ -use alloc::format; -use alloc::string::ToString; -use app_wallets::metamask::ETHAccountTypeApp::Bip44Standard; -use crate::extract_array; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::UREncodeResult; use crate::common::utils::recover_c_char; +use crate::extract_array; +use alloc::format; +use alloc::string::ToString; +use app_wallets::metamask::ETHAccountTypeApp::Bip44Standard; use cty::uint32_t; use ur_registry::crypto_hd_key::CryptoHDKey; use ur_registry::error::URError; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs index 6e556da1d..56f5a94e2 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs @@ -1,13 +1,13 @@ use super::structs::KeplrAccount; -use alloc::format; -use alloc::string::ToString; -use alloc::vec::Vec; -use app_wallets::keplr::{generate_sync_ur, sync_info::SyncInfo}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::types::{PtrBytes, PtrT}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use alloc::format; +use alloc::string::ToString; +use alloc::vec::Vec; +use app_wallets::keplr::{generate_sync_ur, sync_info::SyncInfo}; use cty::uint32_t; use keystore::algorithms::secp256k1::derive_extend_public_key; use ur_registry::error::URError; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs index c00b99756..f244037f0 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs @@ -1,10 +1,10 @@ -use alloc::{format, string::ToString}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use alloc::{format, string::ToString}; use ur_registry::error::URError; use super::utils::normalize_xpub; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs index 79c5e28db..2ac622bee 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs @@ -1,10 +1,10 @@ -use alloc::{format, string::ToString}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use alloc::{format, string::ToString}; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs index 7c1bdf0db..1fa48c698 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs @@ -7,13 +7,13 @@ use hex; use ur_registry::error::URError; use ur_registry::traits::RegistryItem; -use app_wallets::solana::generate_sync_ur; use crate::common::errors::RustCError; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::PtrT; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use app_wallets::solana::generate_sync_ur; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; #[no_mangle] diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs index 7a8181135..93b2f5883 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs @@ -1,13 +1,13 @@ -use alloc::collections::BTreeMap; -use alloc::format; -use app_wallets::sui::generate_sync_ur; -use bitcoin::bip32::DerivationPath; use crate::common::errors::RustCError; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::PtrT; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use alloc::collections::BTreeMap; +use alloc::format; +use app_wallets::sui::generate_sync_ur; +use bitcoin::bip32::DerivationPath; use core::slice; use core::str::FromStr; use hex; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs b/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs index 3eb423dda..efff5fc38 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs @@ -1,11 +1,11 @@ use core::str::FromStr; -use alloc::vec; -use alloc::vec::Vec; -use app_utils::normalize_path; use crate::common::errors::RustCError; use crate::common::structs::ExtendedPublicKey; use crate::common::utils::recover_c_char; +use alloc::vec; +use alloc::vec::Vec; +use app_utils::normalize_path; use { bitcoin::bip32::{DerivationPath, Xpub}, hex, diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs index d7ee10f35..56001feca 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs @@ -7,13 +7,13 @@ use hex; use ur_registry::error::URError; use ur_registry::traits::RegistryItem; -use app_wallets::xbull::generate_sync_ur; use crate::common::errors::RustCError; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::PtrT; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use app_wallets::xbull::generate_sync_ur; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; #[no_mangle] diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs index d1dc8bd1c..749d5b633 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs @@ -1,7 +1,7 @@ -use app_wallets::xrp_toolkit::generate_sync_ur; use crate::common::types::PtrString; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::recover_c_char; +use app_wallets::xrp_toolkit::generate_sync_ur; use ur_registry::bytes::Bytes; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs b/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs index 85f5a0a12..550a4e0ae 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs @@ -1,13 +1,13 @@ -use alloc::string::ToString; -use alloc::vec::Vec; -use alloc::{format, slice}; -use app_wallets::zcash::{generate_sync_ur, UFVKInfo}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ZcashKey; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use alloc::string::ToString; +use alloc::vec::Vec; +use alloc::{format, slice}; +use app_wallets::zcash::{generate_sync_ur, UFVKInfo}; use ur_registry::bytes::Bytes; use ur_registry::error::URError; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/xrp/mod.rs b/rust/rust_c/src/xrp/mod.rs index 274b6dcf3..b96c286f6 100644 --- a/rust/rust_c/src/xrp/mod.rs +++ b/rust/rust_c/src/xrp/mod.rs @@ -18,12 +18,12 @@ use ur_registry::pb::protoc::sign_transaction::Transaction::XrpTx; use ur_registry::traits::RegistryItem; use crate::common::errors::{ErrorCodes, KeystoneError, RustCError}; -use crate::extract_ptr_with_type; use crate::common::keystone::build_payload; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; use structs::DisplayXrpTx; diff --git a/rust/zcash_vendor/src/pczt_ext.rs b/rust/zcash_vendor/src/pczt_ext.rs index 357758ec1..82f889028 100644 --- a/rust/zcash_vendor/src/pczt_ext.rs +++ b/rust/zcash_vendor/src/pczt_ext.rs @@ -8,7 +8,7 @@ use pczt::{ roles::low_level_signer::Signer, transparent::{Input, Output}, }; -use transparent::{sighash::SignableInput}; +use transparent::sighash::SignableInput; use zcash_protocol::value::ZatBalance; /// TxId tree root personalization From 77362c686340a14818a268ed0e5150dff4694b52 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 19:02:35 +0800 Subject: [PATCH 12/31] style: run cargo fix --- rust/apps/ton/src/structs.rs | 2 +- rust/apps/wallets/src/zcash.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/rust/apps/ton/src/structs.rs b/rust/apps/ton/src/structs.rs index 3bec7c915..fb0086550 100644 --- a/rust/apps/ton/src/structs.rs +++ b/rust/apps/ton/src/structs.rs @@ -8,7 +8,7 @@ use crate::utils::shorten_string; use crate::vendor::address::TonAddress; use crate::vendor::cell::BagOfCells; use alloc::string::{String, ToString}; -use alloc::vec; + use hex; use serde::Serialize; use serde_json::{self, json, Value}; diff --git a/rust/apps/wallets/src/zcash.rs b/rust/apps/wallets/src/zcash.rs index 82b53f229..a2eba6bc5 100644 --- a/rust/apps/wallets/src/zcash.rs +++ b/rust/apps/wallets/src/zcash.rs @@ -1,12 +1,10 @@ -use alloc::string::{String, ToString}; -use alloc::vec; +use alloc::string::{String}; + use alloc::vec::Vec; use app_utils::impl_public_struct; use ur_registry::{ - crypto_hd_key::CryptoHDKey, - crypto_key_path::CryptoKeyPath, - error::{URError, URResult}, + error::{URResult}, zcash::{ zcash_accounts::ZcashAccounts, zcash_unified_full_viewing_key::ZcashUnifiedFullViewingKey, }, From 81eb092bad6aafd6b37c103015be2f219dd52f27 Mon Sep 17 00:00:00 2001 From: soralit Date: Thu, 26 Dec 2024 09:06:36 +0800 Subject: [PATCH 13/31] style: apply clippy suggestions --- .../aptos/src/aptos_type/account_address.rs | 4 +- rust/apps/aptos/src/aptos_type/module.rs | 2 +- rust/apps/aptos/src/aptos_type/parser.rs | 16 +- .../aptos/src/aptos_type/safe_serialize.rs | 4 +- .../src/aptos_type/transaction_argument.rs | 2 +- rust/apps/aptos/src/aptos_type/value.rs | 4 +- rust/apps/aptos/src/errors.rs | 6 +- rust/apps/aptos/src/lib.rs | 8 +- rust/apps/aptos/src/parser.rs | 8 +- rust/apps/arweave/src/data_item.rs | 20 ++- rust/apps/arweave/src/deep_hash.rs | 4 +- rust/apps/arweave/src/errors.rs | 4 +- rust/apps/arweave/src/lib.rs | 14 +- rust/apps/arweave/src/tokens.rs | 7 +- rust/apps/arweave/src/transaction.rs | 9 +- rust/apps/cardano/src/address.rs | 12 +- rust/apps/cardano/src/governance.rs | 6 +- rust/apps/cardano/src/structs.rs | 31 ++-- rust/apps/cardano/src/transaction.rs | 8 +- rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs | 2 +- rust/apps/cosmos/src/lib.rs | 10 +- rust/apps/cosmos/src/proto_wrapper/fee.rs | 8 +- .../cosmos/src/proto_wrapper/mode_info.rs | 5 +- .../cosmos/src/proto_wrapper/msg/common.rs | 40 ++--- rust/apps/cosmos/src/proto_wrapper/msg/msg.rs | 51 +++---- .../cosmos/src/proto_wrapper/serde_helper.rs | 2 +- .../apps/cosmos/src/proto_wrapper/sign_doc.rs | 8 +- .../cosmos/src/proto_wrapper/signer_info.rs | 6 +- rust/apps/cosmos/src/transaction/detail.rs | 5 +- rust/apps/cosmos/src/transaction/mod.rs | 6 +- rust/apps/cosmos/src/transaction/overview.rs | 11 +- rust/apps/cosmos/src/transaction/utils.rs | 11 +- rust/apps/cosmos/src/utils.rs | 2 +- rust/apps/ethereum/src/abi.rs | 14 +- rust/apps/ethereum/src/eip1559_transaction.rs | 2 +- rust/apps/ethereum/src/erc20.rs | 2 +- rust/apps/ethereum/src/legacy_transaction.rs | 14 +- rust/apps/ethereum/src/lib.rs | 12 +- rust/apps/ethereum/src/structs.rs | 2 +- rust/apps/near/src/account_id/borsh.rs | 4 +- rust/apps/near/src/account_id/mod.rs | 2 +- rust/apps/near/src/account_id/serde.rs | 4 +- rust/apps/near/src/crypto/errors.rs | 2 +- rust/apps/near/src/crypto/mod.rs | 2 +- rust/apps/near/src/crypto/pubkey.rs | 6 +- rust/apps/near/src/errors.rs | 4 +- rust/apps/near/src/lib.rs | 2 +- rust/apps/near/src/parser/mod.rs | 2 +- rust/apps/near/src/parser/utils.rs | 18 +-- rust/apps/near/src/primitives_core/account.rs | 2 +- rust/apps/near/src/primitives_core/hash.rs | 7 +- .../near/src/primitives_core/serialize.rs | 2 +- rust/apps/stellar/src/address.rs | 2 +- rust/apps/stellar/src/lib.rs | 4 +- rust/apps/stellar/src/strkeys.rs | 8 +- rust/apps/sui/src/lib.rs | 8 +- rust/apps/ton/src/jettons.rs | 2 +- rust/apps/ton/src/lib.rs | 4 +- rust/apps/ton/src/messages/jetton.rs | 4 +- rust/apps/ton/src/messages/mod.rs | 20 ++- rust/apps/ton/src/messages/nft.rs | 4 +- rust/apps/ton/src/mnemonic.rs | 14 +- rust/apps/ton/src/structs.rs | 6 +- rust/apps/ton/src/transaction.rs | 4 +- rust/apps/ton/src/utils.rs | 2 +- rust/apps/ton/src/vendor/address/mod.rs | 2 +- rust/apps/tron/src/address.rs | 2 +- rust/apps/tron/src/errors.rs | 6 +- rust/apps/tron/src/transaction/parser.rs | 8 +- .../apps/tron/src/transaction/wrapped_tron.rs | 18 +-- rust/apps/utils/src/lib.rs | 14 +- rust/apps/wallets/src/aptos.rs | 2 +- rust/apps/wallets/src/backpack.rs | 30 ++-- rust/apps/wallets/src/bitget.rs | 44 +++--- rust/apps/wallets/src/blue_wallet.rs | 6 +- rust/apps/wallets/src/common.rs | 2 +- rust/apps/wallets/src/companion_app.rs | 12 +- rust/apps/wallets/src/keplr/mod.rs | 10 +- rust/apps/wallets/src/keystone.rs | 6 +- rust/apps/wallets/src/metamask.rs | 8 +- rust/apps/wallets/src/okx.rs | 16 +- rust/apps/wallets/src/solana.rs | 2 +- rust/apps/wallets/src/sui.rs | 2 +- rust/apps/wallets/src/thor_wallet.rs | 16 +- rust/apps/wallets/src/tonkeeper.rs | 2 +- rust/apps/wallets/src/utils.rs | 10 +- rust/apps/wallets/src/xbull.rs | 2 +- rust/apps/wallets/src/xrp_toolkit.rs | 4 +- rust/apps/xrp/src/address/mod.rs | 4 +- rust/apps/xrp/src/address/ripple_keypair.rs | 2 +- rust/apps/xrp/src/errors.rs | 4 +- rust/apps/xrp/src/lib.rs | 10 +- rust/apps/xrp/src/transaction/mod.rs | 10 +- rust/apps/zcash/src/lib.rs | 9 +- rust/apps/zcash/src/pczt/check.rs | 16 +- rust/apps/zcash/src/pczt/parse.rs | 50 +++--- rust/apps/zcash/src/pczt/sign.rs | 10 +- rust/rust_c/build.rs | 2 +- rust/rust_c/src/aptos/mod.rs | 8 +- rust/rust_c/src/arweave/mod.rs | 22 +-- rust/rust_c/src/bitcoin/msg.rs | 13 +- rust/rust_c/src/bitcoin/multi_sig/mod.rs | 18 +-- rust/rust_c/src/bitcoin/multi_sig/structs.rs | 98 ++++++------ rust/rust_c/src/bitcoin/psbt.rs | 34 ++--- rust/rust_c/src/bitcoin/structs.rs | 6 +- rust/rust_c/src/cardano/mod.rs | 46 +++--- rust/rust_c/src/cardano/structs.rs | 2 +- rust/rust_c/src/common/free.rs | 2 +- rust/rust_c/src/common/keystone.rs | 19 ++- rust/rust_c/src/common/macros.rs | 4 +- rust/rust_c/src/common/mod.rs | 12 +- rust/rust_c/src/common/qrcode/mod.rs | 10 +- rust/rust_c/src/common/ur.rs | 14 +- rust/rust_c/src/common/ur_ext.rs | 2 +- rust/rust_c/src/common/web_auth.rs | 20 +-- rust/rust_c/src/cosmos/mod.rs | 8 +- rust/rust_c/src/ethereum/abi.rs | 2 +- rust/rust_c/src/ethereum/mod.rs | 42 +++--- rust/rust_c/src/ethereum/structs.rs | 2 +- rust/rust_c/src/near/mod.rs | 2 +- rust/rust_c/src/solana/mod.rs | 6 +- rust/rust_c/src/stellar/mod.rs | 16 +- rust/rust_c/src/sui/mod.rs | 4 +- rust/rust_c/src/ton/mod.rs | 23 ++- rust/rust_c/src/ton/structs.rs | 6 +- rust/rust_c/src/wallet/btc_only_wallet.rs | 22 +-- .../src/wallet/multi_coins_wallet/aptos.rs | 4 +- .../wallet/multi_coins_wallet/arconnect.rs | 10 +- .../src/wallet/multi_coins_wallet/backpack.rs | 2 +- .../src/wallet/multi_coins_wallet/bitget.rs | 2 +- .../src/wallet/multi_coins_wallet/keplr.rs | 6 +- .../src/wallet/multi_coins_wallet/keystone.rs | 2 +- .../src/wallet/multi_coins_wallet/mod.rs | 16 +- .../src/wallet/multi_coins_wallet/okx.rs | 2 +- .../src/wallet/multi_coins_wallet/solana.rs | 4 +- .../src/wallet/multi_coins_wallet/structs.rs | 2 +- .../src/wallet/multi_coins_wallet/sui.rs | 4 +- .../wallet/multi_coins_wallet/thor_wallet.rs | 10 +- .../wallet/multi_coins_wallet/tonkeeper.rs | 2 +- .../src/wallet/multi_coins_wallet/xbull.rs | 4 +- .../wallet/multi_coins_wallet/xrp_toolkit.rs | 2 +- rust/rust_c/src/xrp/mod.rs | 21 ++- rust/rust_c/src/zcash/mod.rs | 10 +- rust/sim_qr_reader/src/lib.rs | 16 +- rust/zcash_vendor/src/pczt_ext.rs | 142 +++++++++--------- 145 files changed, 760 insertions(+), 826 deletions(-) diff --git a/rust/apps/aptos/src/aptos_type/account_address.rs b/rust/apps/aptos/src/aptos_type/account_address.rs index 87ec9c342..0280feabe 100644 --- a/rust/apps/aptos/src/aptos_type/account_address.rs +++ b/rust/apps/aptos/src/aptos_type/account_address.rs @@ -2,7 +2,7 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; use core::{convert::TryFrom, fmt, str::FromStr}; -use hex; + use hex::FromHex; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; @@ -32,7 +32,7 @@ impl AccountAddress { } pub fn short_str_lossless(&self) -> String { - let hex_str = hex::encode(&self.0).trim_start_matches('0').to_string(); + let hex_str = hex::encode(self.0).trim_start_matches('0').to_string(); if hex_str.is_empty() { "0".to_string() } else { diff --git a/rust/apps/aptos/src/aptos_type/module.rs b/rust/apps/aptos/src/aptos_type/module.rs index c8eb133ff..5e43c5d9f 100644 --- a/rust/apps/aptos/src/aptos_type/module.rs +++ b/rust/apps/aptos/src/aptos_type/module.rs @@ -4,7 +4,7 @@ use alloc::vec; use alloc::vec::Vec; use core::fmt; -use hex; + use serde::{Deserialize, Serialize}; #[derive(Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] diff --git a/rust/apps/aptos/src/aptos_type/parser.rs b/rust/apps/aptos/src/aptos_type/parser.rs index e6d34eecd..c7c08b230 100644 --- a/rust/apps/aptos/src/aptos_type/parser.rs +++ b/rust/apps/aptos/src/aptos_type/parser.rs @@ -15,7 +15,7 @@ use alloc::string::{String, ToString}; use alloc::vec; use alloc::vec::Vec; use core::iter::Peekable; -use hex; + #[derive(Eq, PartialEq, Debug)] enum Token { @@ -114,7 +114,7 @@ fn next_token(s: &str) -> crate::errors::Result> { ',' => (Token::Comma, 1), ':' => match it.next() { Some(':') => (Token::ColonColon, 2), - _ => return Err(AptosError::ParseTxError(format!("unrecognized token"))), + _ => return Err(AptosError::ParseTxError("unrecognized token".to_string())), }, '0' if it.peek() == Some(&'x') || it.peek() == Some(&'X') => { it.next().unwrap(); @@ -134,7 +134,7 @@ fn next_token(s: &str) -> crate::errors::Result> { let len = r.len(); (Token::Address(r), len) } - _ => return Err(AptosError::ParseTxError(format!("unrecognized token"))), + _ => return Err(AptosError::ParseTxError("unrecognized token".to_string())), } } c if c.is_ascii_digit() => next_number(c, it)?, @@ -145,7 +145,7 @@ fn next_token(s: &str) -> crate::errors::Result> { match it.next() { Some('"') => break, Some(c) if c.is_ascii() => r.push(c), - _ => return Err(AptosError::ParseTxError(format!("unrecognized token"))), + _ => return Err(AptosError::ParseTxError("unrecognized token".to_string())), } } let len = r.len() + 3; @@ -158,7 +158,7 @@ fn next_token(s: &str) -> crate::errors::Result> { match it.next() { Some('"') => break, Some(c) if c.is_ascii_hexdigit() => r.push(c), - _ => return Err(AptosError::ParseTxError(format!("unrecognized token"))), + _ => return Err(AptosError::ParseTxError("unrecognized token".to_string())), } } let len = r.len() + 3; @@ -190,7 +190,7 @@ fn next_token(s: &str) -> crate::errors::Result> { let len = r.len(); (name_token(r), len) } - _ => return Err(AptosError::ParseTxError(format!("unrecognized token"))), + _ => return Err(AptosError::ParseTxError("unrecognized token".to_string())), })), } } @@ -218,9 +218,7 @@ impl> Parser { fn next(&mut self) -> crate::errors::Result { match self.it.next() { Some(tok) => Ok(tok), - None => Err(AptosError::ParseTxError(format!( - "out of tokens, this should not happen" - ))), + None => Err(AptosError::ParseTxError("out of tokens, this should not happen".to_string())), } } diff --git a/rust/apps/aptos/src/aptos_type/safe_serialize.rs b/rust/apps/aptos/src/aptos_type/safe_serialize.rs index 40cdcdf80..ca3f3f104 100644 --- a/rust/apps/aptos/src/aptos_type/safe_serialize.rs +++ b/rust/apps/aptos/src/aptos_type/safe_serialize.rs @@ -13,8 +13,8 @@ where S: Serializer, T: Serialize, { - let res = t.serialize(s); - res + + t.serialize(s) } pub(crate) fn type_tag_recursive_deserialize<'de, D, T>(d: D) -> Result diff --git a/rust/apps/aptos/src/aptos_type/transaction_argument.rs b/rust/apps/aptos/src/aptos_type/transaction_argument.rs index 7297f140b..63843a680 100644 --- a/rust/apps/aptos/src/aptos_type/transaction_argument.rs +++ b/rust/apps/aptos/src/aptos_type/transaction_argument.rs @@ -3,7 +3,7 @@ use crate::aptos_type::value::MoveValue; use alloc::format; use alloc::vec::Vec; use core::{convert::TryFrom, fmt}; -use hex; + use serde::{Deserialize, Serialize}; #[derive(Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] diff --git a/rust/apps/aptos/src/aptos_type/value.rs b/rust/apps/aptos/src/aptos_type/value.rs index c99452815..170bd792b 100644 --- a/rust/apps/aptos/src/aptos_type/value.rs +++ b/rust/apps/aptos/src/aptos_type/value.rs @@ -3,7 +3,7 @@ use crate::aptos_type::identifier::Identifier; use crate::aptos_type::language_storage::{StructTag, TypeTag}; use crate::errors::AptosError; use alloc::boxed::Box; -use alloc::format; + use alloc::string::ToString; use alloc::vec::Vec; use core::{ @@ -557,7 +557,7 @@ impl TryInto for &MoveStructLayout { use MoveStructLayout::*; match self { Runtime(..) | CheckedRuntime { fields: _, tag: _ } | WithFields(..) => Err(AptosError::ParseTxError( - format!("Invalid MoveTypeLayout -> StructTag conversion--needed MoveLayoutType::WithTypes")) + "Invalid MoveTypeLayout -> StructTag conversion--needed MoveLayoutType::WithTypes".to_string()) ), WithTypes { type_, .. } => Ok(type_.clone()), } diff --git a/rust/apps/aptos/src/errors.rs b/rust/apps/aptos/src/errors.rs index cd5ad1306..c956ad4f7 100644 --- a/rust/apps/aptos/src/errors.rs +++ b/rust/apps/aptos/src/errors.rs @@ -26,13 +26,13 @@ impl From for AptosError { impl From for AptosError { fn from(value: hex::FromHexError) -> Self { - Self::InvalidData(format!("hex operation failed {}", value.to_string())) + Self::InvalidData(format!("hex operation failed {}", value)) } } impl From for AptosError { fn from(value: FromUtf8Error) -> Self { - Self::InvalidData(format!("utf8 operation failed {}", value.to_string())) + Self::InvalidData(format!("utf8 operation failed {}", value)) } } @@ -44,6 +44,6 @@ impl From for AptosError { impl From for AptosError { fn from(value: bcs::Error) -> Self { - Self::InvalidData(format!("bsc operation failed {}", value.to_string())) + Self::InvalidData(format!("bsc operation failed {}", value)) } } diff --git a/rust/apps/aptos/src/lib.rs b/rust/apps/aptos/src/lib.rs index 127166d7a..9c753d8ae 100644 --- a/rust/apps/aptos/src/lib.rs +++ b/rust/apps/aptos/src/lib.rs @@ -15,7 +15,7 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; use cryptoxide::hashing::sha3::Sha3_256; -use hex; + use parser::AptosTx; use crate::errors::Result; @@ -32,15 +32,15 @@ pub fn generate_address(pub_key: &str) -> Result { } pub fn parse_tx(data: &Vec) -> crate::errors::Result { - Ok(Parser::parse_tx(data)?) + Parser::parse_tx(data) } pub fn parse_msg(data: &Vec) -> crate::errors::Result { - Ok(Parser::parse_msg(data)?) + Parser::parse_msg(data) } pub fn sign(message: Vec, hd_path: &String, seed: &[u8]) -> errors::Result<[u8; 64]> { - keystore::algorithms::ed25519::slip10_ed25519::sign_message_by_seed(&seed, hd_path, &message) + keystore::algorithms::ed25519::slip10_ed25519::sign_message_by_seed(seed, hd_path, &message) .map_err(|e| errors::AptosError::KeystoreError(format!("sign failed {:?}", e.to_string()))) } diff --git a/rust/apps/aptos/src/parser.rs b/rust/apps/aptos/src/parser.rs index 70d04cbe7..e1cd787cf 100644 --- a/rust/apps/aptos/src/parser.rs +++ b/rust/apps/aptos/src/parser.rs @@ -32,7 +32,7 @@ pub fn is_tx(data: &Vec) -> bool { 0x6f, 0x66, 0x93, 0xbd, 0xdc, 0x1a, 0x9f, 0xec, 0x9e, 0x67, 0x4a, 0x46, 0x1e, 0xaa, 0x00, 0xb1, 0x93, ]; - return data.len() > 32 && data[..32] == tx_prefix; + data.len() > 32 && data[..32] == tx_prefix } impl Parser { @@ -42,7 +42,7 @@ impl Parser { data_parse = data[32..].to_vec(); } let tx: RawTransaction = bcs::from_bytes(&data_parse).map_err(|err| { - AptosError::ParseTxError(format!("bcs deserialize failed {}", err.to_string())) + AptosError::ParseTxError(format!("bcs deserialize failed {}", err)) })?; Ok(AptosTx::new(tx)) } @@ -73,14 +73,14 @@ impl AptosTx { Ok(v) => Ok(Value::String(v)), Err(e) => Err(AptosError::ParseTxError(format!( "to json failed {}", - e.to_string() + e ))), } } fn to_json_value(&self) -> Result { let value = serde_json::to_value(&self.tx) - .map_err(|e| AptosError::ParseTxError(format!("to json failed {}", e.to_string())))?; + .map_err(|e| AptosError::ParseTxError(format!("to json failed {}", e)))?; Ok(value) } diff --git a/rust/apps/arweave/src/data_item.rs b/rust/apps/arweave/src/data_item.rs index 953569234..45466900b 100644 --- a/rust/apps/arweave/src/data_item.rs +++ b/rust/apps/arweave/src/data_item.rs @@ -26,7 +26,7 @@ impl Tags { let value = avro_decode_string(&mut avro_bytes)?; tags.push(Tag { name, value }) } - return Ok(Tags { len, data: tags }); + Ok(Tags { len, data: tags }) } } @@ -43,7 +43,7 @@ fn avro_decode_long(reader: &mut Vec) -> Result { loop { if j > 9 { // if j * 7 > 64 - return Err(ArweaveError::AvroError(format!("Integer overflow"))); + return Err(ArweaveError::AvroError("Integer overflow".to_string())); } let head = reader.remove(0); buf[0] = head; @@ -64,10 +64,8 @@ fn avro_decode_long(reader: &mut Vec) -> Result { fn avro_decode_string(reader: &mut Vec) -> Result { let len = avro_decode_long(reader)?; let buf = reader.drain(..len as usize).collect(); - Ok( - String::from_utf8(buf) - .map_err(|e| ArweaveError::AvroError(format!("{}", e.to_string())))?, - ) + String::from_utf8(buf) + .map_err(|e| ArweaveError::AvroError(format!("{}", e))) } impl_public_struct!(DataItem { @@ -102,7 +100,7 @@ impl DataItem { let mut reader = binary.to_vec(); let signature_type = u16::from_le_bytes(reader.drain(..2).collect::>().try_into().map_err( - |_| ArweaveError::ParseTxError(format!("Invalid DataItem signature_type")), + |_| ArweaveError::ParseTxError("Invalid DataItem signature_type".to_string()), )?); if signature_type != SignatureType::ARWEAVE as u16 { @@ -132,12 +130,12 @@ impl DataItem { let tags_number = u64::from_le_bytes(reader.drain(..8).collect::>().try_into().map_err( - |_| ArweaveError::ParseTxError(format!("Invalid DataItem tags_number")), + |_| ArweaveError::ParseTxError("Invalid DataItem tags_number".to_string()), )?); let tags_bytes_number = u64::from_le_bytes(reader.drain(..8).collect::>().try_into().map_err( - |_| ArweaveError::ParseTxError(format!("Invalid DataItem tags_number")), + |_| ArweaveError::ParseTxError("Invalid DataItem tags_number".to_string()), )?); let raw_tags: Vec = reader.drain(..tags_bytes_number as usize).collect(); @@ -201,8 +199,8 @@ mod tests { ); assert_eq!(result.anchor, None); assert_eq!(result.tags.len, 8); - assert_eq!(result.tags.data.get(0).unwrap().name, "Action"); - assert_eq!(result.tags.data.get(0).unwrap().value, "Transfer"); + assert_eq!(result.tags.data.first().unwrap().name, "Action"); + assert_eq!(result.tags.data.first().unwrap().value, "Transfer"); assert_eq!(result.tags.data.get(7).unwrap().name, "Content-Type"); assert_eq!(result.tags.data.get(7).unwrap().value, "text/plain"); } diff --git a/rust/apps/arweave/src/deep_hash.rs b/rust/apps/arweave/src/deep_hash.rs index 3f296da6c..e528e39cc 100644 --- a/rust/apps/arweave/src/deep_hash.rs +++ b/rust/apps/arweave/src/deep_hash.rs @@ -23,9 +23,7 @@ pub fn hash_sha384(message: &[u8]) -> Result<[u8; 48], ArweaveError> { pub fn hash_all_sha384(messages: Vec<&[u8]>) -> Result<[u8; 48], ArweaveError> { let hash: Vec = messages .into_iter() - .map(|m| hash_sha384(m).unwrap()) - .into_iter() - .flatten() + .flat_map(|m| hash_sha384(m).unwrap()) .collect(); let hash = hash_sha384(&hash)?; Ok(hash) diff --git a/rust/apps/arweave/src/errors.rs b/rust/apps/arweave/src/errors.rs index 50b03091e..8164ed720 100644 --- a/rust/apps/arweave/src/errors.rs +++ b/rust/apps/arweave/src/errors.rs @@ -27,8 +27,8 @@ pub type Result = core::result::Result; impl From for ArweaveError { fn from(value: KeystoreError) -> Self { match value { - KeystoreError::DerivePubKey(data) => Self::KeystoreError(format!("{}", data)), - KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(format!("{}", data)), + KeystoreError::DerivePubKey(data) => Self::KeystoreError(data.to_string()), + KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(data.to_string()), KeystoreError::XPubError(data) => Self::KeystoreError(data), KeystoreError::SeedError(data) => Self::KeystoreError(data), KeystoreError::DerivationError(data) => Self::KeystoreError(data), diff --git a/rust/apps/arweave/src/lib.rs b/rust/apps/arweave/src/lib.rs index 7e4869783..7d874490d 100644 --- a/rust/apps/arweave/src/lib.rs +++ b/rust/apps/arweave/src/lib.rs @@ -20,14 +20,14 @@ use aes::cipher::block_padding::Pkcs7; use aes::cipher::{generic_array::GenericArray, BlockDecryptMut, BlockEncryptMut, KeyIvInit}; use alloc::string::{String, ToString}; use alloc::vec::Vec; -use base64; + use data_item::DataItem; -use hex; + use keystore::algorithms::rsa::get_rsa_secret_from_seed; use rsa::{BigUint, RsaPrivateKey}; -use serde_json; + use serde_json::{json, Value}; -use sha2; + use sha2::Digest; use transaction::{Base64, Transaction}; @@ -89,7 +89,7 @@ fn u64_to_ar(value: u64) -> String { let value = format!("{:.12}", value); let value = value.trim_end_matches('0').to_string(); if value.ends_with('.') { - format!("{} AR", value[..value.len() - 1].to_string()) + format!("{} AR", &value[..value.len() - 1]) } else { format!("{} AR", value) } @@ -143,13 +143,13 @@ pub fn parse(data: &Vec) -> Result { "quantity": u64_to_ar(tx.quantity), "reward": u64_to_ar(tx.reward), "data_size": tx.data_size, - "signature_data": tx.deep_hash().map_or_else(|e| format!("unable to deep hash transaction, reason: {}", e.to_string()), |data| hex::encode(data)), + "signature_data": tx.deep_hash().map_or_else(|e| format!("unable to deep hash transaction, reason: {}", e), hex::encode), }, "status": "success" }) } Err(e) => { - let readable = format!("unable to deserialize, reason: {}", e.to_string()); + let readable = format!("unable to deserialize, reason: {}", e); json!({ "status": "failed", "reason": readable diff --git a/rust/apps/arweave/src/tokens.rs b/rust/apps/arweave/src/tokens.rs index 599434de2..d7d2daf48 100644 --- a/rust/apps/arweave/src/tokens.rs +++ b/rust/apps/arweave/src/tokens.rs @@ -17,11 +17,11 @@ impl TokenInfo { let value = u64::from_str_radix(quantity, 10) .map_err(|_e| ArweaveError::ParseTxError(_e.to_string()))?; let divisor = 10u64.pow(self.get_decimal() as u32) as f64; - return Ok(format!( + Ok(format!( "{} {}", (value as f64) / divisor, self.get_symbol() - )); + )) } } @@ -63,6 +63,5 @@ lazy_static! { pub(crate) fn find_token(token_id: &str) -> Option { TOKENS .iter() - .find(|v| v.get_token_id().eq(token_id)) - .map(|v| v.clone()) + .find(|v| v.get_token_id().eq(token_id)).cloned() } diff --git a/rust/apps/arweave/src/transaction.rs b/rust/apps/arweave/src/transaction.rs index 72d50bfed..78b4e6309 100644 --- a/rust/apps/arweave/src/transaction.rs +++ b/rust/apps/arweave/src/transaction.rs @@ -132,7 +132,7 @@ impl FromUtf8Strs> for Tag { impl<'a> ToItems<'a, Vec>> for Vec> { fn to_deep_hash_item(&'a self) -> Result { - if self.len() > 0 { + if !self.is_empty() { Ok(DeepHashItem::List( self.iter() .map(|t| t.to_deep_hash_item().unwrap()) @@ -155,13 +155,10 @@ impl<'a> ToItems<'a, Tag> for Tag { /// A struct of [`Vec`] used for all data and address fields. #[derive(Debug, Clone, PartialEq)] +#[derive(Default)] pub struct Base64(pub Vec); -impl Default for Base64 { - fn default() -> Self { - Base64(vec![]) - } -} + impl fmt::Display for Base64 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/rust/apps/cardano/src/address.rs b/rust/apps/cardano/src/address.rs index 39700ff45..45651d6f1 100644 --- a/rust/apps/cardano/src/address.rs +++ b/rust/apps/cardano/src/address.rs @@ -53,12 +53,12 @@ pub fn derive_address( AddressType::Base => { let payment_key = xpub .derive(DerivationScheme::V2, change)? - .derive(DerivationScheme::V2, index.clone())? + .derive(DerivationScheme::V2, index)? .public_key(); let payment_key_hash = blake2b_224(&payment_key); let stake_key = xpub .derive(DerivationScheme::V2, 2)? - .derive(DerivationScheme::V2, stake_key_index.clone())? + .derive(DerivationScheme::V2, stake_key_index)? .public_key(); let stake_key_hash = blake2b_224(&stake_key); let address = BaseAddress::new( @@ -74,7 +74,7 @@ pub fn derive_address( AddressType::Stake => { let stake_key = xpub .derive(DerivationScheme::V2, 2)? - .derive(DerivationScheme::V2, stake_key_index.clone())? + .derive(DerivationScheme::V2, stake_key_index)? .public_key(); let stake_key_hash = blake2b_224(&stake_key); let address = RewardAddress::new( @@ -89,7 +89,7 @@ pub fn derive_address( AddressType::Enterprise => { let payment_key = xpub .derive(DerivationScheme::V2, 0)? - .derive(DerivationScheme::V2, index.clone())? + .derive(DerivationScheme::V2, index)? .public_key(); let payment_key_hash = blake2b_224(&payment_key); let address = EnterpriseAddress::new( @@ -111,7 +111,7 @@ pub fn derive_pubkey_hash(xpub: String, change: u32, index: u32) -> R<[u8; 28]> let payment_key = xpub .derive(DerivationScheme::V2, change)? - .derive(DerivationScheme::V2, index.clone())? + .derive(DerivationScheme::V2, index)? .public_key(); Ok(blake2b_224(&payment_key)) } @@ -122,7 +122,7 @@ mod tests { use alloc::string::ToString; use alloc::vec; use bech32; - use cardano_serialization_lib::protocol_types::{Address, BaseAddress}; + use cryptoxide::hashing::blake2b_224; use keystore; diff --git a/rust/apps/cardano/src/governance.rs b/rust/apps/cardano/src/governance.rs index a2797d531..1d1263258 100644 --- a/rust/apps/cardano/src/governance.rs +++ b/rust/apps/cardano/src/governance.rs @@ -96,7 +96,7 @@ pub fn parse_payment_address(payment_address: Vec) -> R { #[cfg(test)] mod tests { use super::*; - use ur_registry::crypto_key_path::PathComponent; + #[test] fn test_sign_voting_registration() { @@ -134,8 +134,8 @@ mod tests { CardanoDelegation::new(vote_pub_key1, 1), CardanoDelegation::new(vote_pub_key2, 2), ]; - let entropy = hex::decode("7a4362fd9792e60d97ee258f43fd21af").unwrap(); - let passphrase = b""; + let _entropy = hex::decode("7a4362fd9792e60d97ee258f43fd21af").unwrap(); + let _passphrase = b""; let delegations_vec = build_delegations(delegations).unwrap(); assert_eq!(delegations_vec.len(), 2); diff --git a/rust/apps/cardano/src/structs.rs b/rust/apps/cardano/src/structs.rs index c46fe2d9c..5d085c03e 100644 --- a/rust/apps/cardano/src/structs.rs +++ b/rust/apps/cardano/src/structs.rs @@ -319,10 +319,7 @@ impl ParsedCardanoTx { if tx.body().outputs().len() == 0 { return 1; } - match tx.body().outputs().get(0).address().network_id() { - Ok(id) => id, - Err(_) => 1, - } + tx.body().outputs().get(0).address().network_id().unwrap_or(1) } Some(id) => match id.kind() { NetworkIdKind::Mainnet => 1, @@ -661,10 +658,7 @@ impl ParsedCardanoTx { )); } if let Some(_cert) = cert.as_drep_update() { - let anchor_data_hash = match _cert.anchor() { - Some(anchor) => Some(anchor.anchor_data_hash().to_string()), - None => None, - }; + let anchor_data_hash = _cert.anchor().map(|anchor| anchor.anchor_data_hash().to_string()); let (variant1, variant1_label) = match _cert.voting_credential().kind() { _Ed25519KeyHash => ( _cert @@ -930,10 +924,7 @@ impl ParsedCardanoTx { None => { let cardano_from = CardanoFrom { address: address.clone(), - value: match input.value { - Some(v) => v, - None => 0, - }, + value: input.value.unwrap_or(0), amount: match input.value { Some(v) => normalize_coin(v), None => "Unknown amount".to_string(), @@ -954,14 +945,14 @@ impl ParsedCardanoTx { match map.get(&address) { Some(existing) => { let mut to = existing.clone(); - to.value = to.value + output.value; + to.value += output.value; to.amount = normalize_coin(to.value); if let Some(assets) = output.assets { for x in assets { match to.assets.get(&x.id) { Some(asset) => { let mut new_asset = asset.clone(); - new_asset.value = new_asset.value + x.value; + new_asset.value += x.value; new_asset.amount = normalize_value(new_asset.value); to.assets.insert(new_asset.id.clone(), new_asset); } @@ -1012,9 +1003,7 @@ impl ParsedCardanoTx { .get_cert_keys() .iter() .filter(|v| hex::encode(v.get_master_fingerprint()).eq(&mfp)) - .fold(false, |acc, cur| { - acc || hex::encode(cur.get_master_fingerprint()).eq(&mfp) - }); + .any(|cur| hex::encode(cur.get_master_fingerprint()).eq(&mfp)); if has_my_signer { return Ok(()); @@ -1085,8 +1074,8 @@ impl ParsedCardanoTx { //check utxo address with payment keyhash; let my_pubkey_hash = hex::encode(derive_pubkey_hash( context.get_cardano_xpub(), - change.clone(), - index.clone(), + *change, + *index, )?); let address = utxo.address.clone(); @@ -1243,7 +1232,7 @@ mod tests { #[test] fn test_parse_sign() { let sign_data = hex::decode("84a400828258204e3a6e7fdcb0d0efa17bf79c13aed2b4cb9baf37fb1aa2e39553d5bd720c5c99038258204e3a6e7fdcb0d0efa17bf79c13aed2b4cb9baf37fb1aa2e39553d5bd720c5c99040182a200581d6179df4c75f7616d7d1fd39cbc1a6ea6b40a0d7b89fea62fc0909b6c370119c350a200581d61c9b0c9761fd1dc0404abd55efc895026628b5035ac623c614fbad0310119c35002198ecb0300a0f5f6").unwrap(); - let request = CardanoSignRequest::new( + let _request = CardanoSignRequest::new( Some( hex::decode("9b1deb4d3b7d4bad9bdd2b0d7b3dcb6d") .unwrap() @@ -1273,6 +1262,6 @@ mod tests { assert_eq!(withdrawals.unwrap().len(), 0); let cardano_tx = ParsedCardanoTx::from_cardano_tx(tx, context); - assert_eq!(cardano_tx.is_ok(), true); + assert!(cardano_tx.is_ok()); } } diff --git a/rust/apps/cardano/src/transaction.rs b/rust/apps/cardano/src/transaction.rs index cb3e08568..7a8718cb5 100644 --- a/rust/apps/cardano/src/transaction.rs +++ b/rust/apps/cardano/src/transaction.rs @@ -184,13 +184,13 @@ pub fn sign_tx(tx: Vec, context: ParseContext, icarus_master_key: XPrv) -> R #[cfg(test)] mod test { use super::*; - use cardano_serialization_lib::Transaction; + extern crate std; - use crate::transaction::parse_tx; + use std::println; - use ur_registry::cardano::cardano_sign_data_signature::CardanoSignDataSignature; + use {cryptoxide::hashing::blake2b_256, hex}; #[test] @@ -214,7 +214,7 @@ mod test { let tx = cardano_serialization_lib::protocol_types::FixedTransaction::from_bytes(tx_bytes) .unwrap(); let body = tx.raw_body(); - let hash = blake2b_256(&body); + let _hash = blake2b_256(&body); } #[test] diff --git a/rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs b/rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs index bc46d8efe..a9deada8c 100644 --- a/rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs +++ b/rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs @@ -13,7 +13,7 @@ mod type_urls; pub use prost; pub use prost_types::Any; -pub use tendermint_proto as tendermint; + /// The version (commit hash) of the Cosmos SDK used when generating this library. pub const COSMOS_SDK_VERSION: &str = include_str!("prost/cosmos-sdk/COSMOS_SDK_COMMIT"); diff --git a/rust/apps/cosmos/src/lib.rs b/rust/apps/cosmos/src/lib.rs index bcc4654f1..b3c7231f9 100644 --- a/rust/apps/cosmos/src/lib.rs +++ b/rust/apps/cosmos/src/lib.rs @@ -17,7 +17,7 @@ use crate::transaction::structs::{ParsedCosmosTx, SignMode}; use crate::utils::{hash160, keccak256, sha256_digest}; use bech32::{Bech32, Hrp}; use bitcoin::secp256k1::{Message, PublicKey}; -use hex; + use keystore::algorithms::secp256k1::derive_public_key; mod cosmos_sdk_proto; @@ -76,7 +76,7 @@ pub fn sign_tx( if let Ok(message) = Message::from_slice(&hash) { let (_, signature) = keystore::algorithms::secp256k1::sign_message_by_seed( - &seed, path, &message, + seed, path, &message, ) .map_err(|e| CosmosError::KeystoreError(format!("sign failed {:?}", e.to_string())))?; return Ok(signature); @@ -90,7 +90,7 @@ pub fn derive_address( root_path: &str, prefix: &str, ) -> Result { - let root_path = if !root_path.ends_with("/") { + let root_path = if !root_path.ends_with('/') { root_path.to_string() + "/" } else { root_path.to_string() @@ -100,12 +100,12 @@ pub fn derive_address( .ok_or(CosmosError::InvalidHDPath(hd_path.to_string()))?; derive_public_key(&root_x_pub.to_string(), &format!("m/{}", sub_path)) .map(|public_key| generate_address(public_key, prefix)) - .map_err(|e| CosmosError::from(e))? + .map_err(CosmosError::from)? } #[cfg(test)] mod tests { - use hex; + use super::*; diff --git a/rust/apps/cosmos/src/proto_wrapper/fee.rs b/rust/apps/cosmos/src/proto_wrapper/fee.rs index 9568b386c..0cbd397b3 100644 --- a/rust/apps/cosmos/src/proto_wrapper/fee.rs +++ b/rust/apps/cosmos/src/proto_wrapper/fee.rs @@ -74,7 +74,7 @@ pub fn format_coin(coin: Coin) -> Option { } else { return Some(format!("{} {}", coin.amount, coin.denom)); } - return None; + None } pub fn parse_gas_limit(gas: &serde_json::Value) -> Result { @@ -85,10 +85,10 @@ pub fn parse_gas_limit(gas: &serde_json::Value) -> Result { if let Some(gas_limit) = gas.as_f64() { return Ok(gas_limit); } - return Err(CosmosError::InvalidData(format!( + Err(CosmosError::InvalidData(format!( "failed to parse gas {:?}", gas - ))); + ))) } pub fn format_fee_from_value(data: serde_json::Value) -> Result { @@ -133,5 +133,5 @@ pub fn format_fee_from_value(data: serde_json::Value) -> Result { gas_limit: gas_limit.to_string(), }); } - return Err(CosmosError::InvalidData("can not parse fee".to_string())); + Err(CosmosError::InvalidData("can not parse fee".to_string())) } diff --git a/rust/apps/cosmos/src/proto_wrapper/mode_info.rs b/rust/apps/cosmos/src/proto_wrapper/mode_info.rs index cad54a63e..29301dcad 100644 --- a/rust/apps/cosmos/src/proto_wrapper/mode_info.rs +++ b/rust/apps/cosmos/src/proto_wrapper/mode_info.rs @@ -91,10 +91,7 @@ impl TryFrom<&proto::cosmos::tx::v1beta1::mode_info::Multi> for Multi { fn try_from( proto: &proto::cosmos::tx::v1beta1::mode_info::Multi, ) -> Result { - let bitarray = match &proto.bitarray { - Some(value) => Some(value.into()), - None => None, - }; + let bitarray = proto.bitarray.as_ref().map(|value| value.into()); Ok(Multi { bitarray, diff --git a/rust/apps/cosmos/src/proto_wrapper/msg/common.rs b/rust/apps/cosmos/src/proto_wrapper/msg/common.rs index de88a73b1..d0e742485 100644 --- a/rust/apps/cosmos/src/proto_wrapper/msg/common.rs +++ b/rust/apps/cosmos/src/proto_wrapper/msg/common.rs @@ -24,13 +24,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro .map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgSend deserialize failed {}", - e.to_string() + e )) })?; let msg_send = MsgSendWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgSend deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_send)); @@ -40,13 +40,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgDelegate deserialize failed {}", - e.to_string() + e )) })?; let msg_delegate = MsgDelegateWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgDelegate deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_delegate)); @@ -56,13 +56,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgUndelegate deserialize failed {}", - e.to_string() + e )) })?; let msg_undelegate = MsgUnDelegateWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgUndelegate deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_undelegate)); @@ -72,13 +72,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; let msg_transfer = MsgTransferWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_transfer)); @@ -88,13 +88,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro proto::cosmos::gov::v1beta1::MsgVote::decode(&*message.value).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgVote deserialize failed {}", - e.to_string() + e )) })?; let msg_vote = MsgVoteWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgVote deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_vote)); @@ -104,14 +104,14 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; let msg_withdraw_reward = MsgWithdrawDelegatorRewardWrapper::try_from(&unpacked) .map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_withdraw_reward)); @@ -121,14 +121,14 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; let msg_redelegate = MsgBeginRedelegateWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_redelegate)); @@ -138,13 +138,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) })?; let msg_multi_send = MsgMultiSendWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_multi_send)); @@ -155,14 +155,14 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro .map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) })?; let msg_update_client = MsgUpdateClientWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_update_client)); @@ -173,14 +173,14 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro |e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) }, )?; let msg_exec = MsgExecWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_exec)); diff --git a/rust/apps/cosmos/src/proto_wrapper/msg/msg.rs b/rust/apps/cosmos/src/proto_wrapper/msg/msg.rs index 15f1ff2ec..7efdab3ce 100644 --- a/rust/apps/cosmos/src/proto_wrapper/msg/msg.rs +++ b/rust/apps/cosmos/src/proto_wrapper/msg/msg.rs @@ -17,10 +17,10 @@ pub struct NotSupportMessage { impl SerializeJson for NotSupportMessage { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { + let value = serde_json::to_value(self).map_err(|err| { CosmosError::ParseTxError(format!( "NotSupportMessage serialize failed {}", - err.to_string() + err )) })?; let msg = json!({ @@ -66,8 +66,8 @@ impl TryFrom<&proto::cosmos::bank::v1beta1::MsgSend> for MsgSend { impl SerializeJson for MsgSend { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgSend serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgSend serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), @@ -112,8 +112,8 @@ impl TryFrom<&proto::cosmos::staking::v1beta1::MsgDelegate> for MsgDelegate { impl SerializeJson for MsgDelegate { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgDelegate serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgDelegate serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), @@ -158,10 +158,10 @@ impl TryFrom<&proto::cosmos::staking::v1beta1::MsgUndelegate> for MsgUndelegate impl SerializeJson for MsgUndelegate { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { + let value = serde_json::to_value(self).map_err(|err| { CosmosError::ParseTxError(format!( "MsgUndelegate serialize failed {}", - err.to_string() + err )) })?; let msg = json!({ @@ -242,8 +242,8 @@ impl TryFrom<&proto::cosmos::gov::v1beta1::MsgVote> for MsgVote { impl SerializeJson for MsgVote { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgVote serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgVote serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), @@ -304,13 +304,10 @@ impl TryFrom<&proto::ibc::applications::transfer::v1::MsgTransfer> for MsgTransf None => None, }; - let timeout_height: Option = match &proto.timeout_height { - Some(height) => Some(Height { + let timeout_height: Option = proto.timeout_height.as_ref().map(|height| Height { revision_number: Some(height.revision_number), revision_height: Some(height.revision_height), - }), - None => None, - }; + }); Ok(MsgTransfer { source_port: proto.source_port.clone(), @@ -326,8 +323,8 @@ impl TryFrom<&proto::ibc::applications::transfer::v1::MsgTransfer> for MsgTransf impl SerializeJson for MsgTransfer { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgTransfer serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgTransfer serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), @@ -366,10 +363,10 @@ impl TryFrom<&proto::cosmos::distribution::v1beta1::MsgWithdrawDelegatorReward> impl SerializeJson for MsgWithdrawDelegatorReward { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { + let value = serde_json::to_value(self).map_err(|err| { CosmosError::ParseTxError(format!( "MsgWithdrawDelegatorReward serialize failed {}", - err.to_string() + err )) })?; let msg = json!({ @@ -407,10 +404,10 @@ impl TryFrom<&proto::ibc::core::client::v1::MsgUpdateClient> for MsgUpdateClient impl SerializeJson for MsgUpdateClient { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { + let value = serde_json::to_value(self).map_err(|err| { CosmosError::ParseTxError(format!( "MsgUpdateClient serialize failed {}", - err.to_string() + err )) })?; let msg = json!({ @@ -456,10 +453,10 @@ impl TryFrom<&proto::cosmos::staking::v1beta1::MsgBeginRedelegate> for MsgBeginR impl SerializeJson for MsgBeginRedelegate { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { + let value = serde_json::to_value(self).map_err(|err| { CosmosError::ParseTxError(format!( "MsgBeginRedelegate serialize failed {}", - err.to_string() + err )) })?; let msg = json!({ @@ -499,8 +496,8 @@ impl TryFrom<&proto::cosmos::authz::v1beta1::MsgExec> for MsgExec { impl SerializeJson for MsgExec { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgExec serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgExec serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), @@ -587,8 +584,8 @@ impl TryFrom<&proto::cosmos::bank::v1beta1::MsgMultiSend> for MsgMultiSend { impl SerializeJson for MsgMultiSend { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgMultiSend serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgMultiSend serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), diff --git a/rust/apps/cosmos/src/proto_wrapper/serde_helper.rs b/rust/apps/cosmos/src/proto_wrapper/serde_helper.rs index d29bbb04f..5401224b0 100644 --- a/rust/apps/cosmos/src/proto_wrapper/serde_helper.rs +++ b/rust/apps/cosmos/src/proto_wrapper/serde_helper.rs @@ -1,6 +1,6 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; -use base64; + pub fn from_base64(s: &str) -> Result, base64::DecodeError> { base64::decode(s) } diff --git a/rust/apps/cosmos/src/proto_wrapper/sign_doc.rs b/rust/apps/cosmos/src/proto_wrapper/sign_doc.rs index 7cf0cd813..5f54680fc 100644 --- a/rust/apps/cosmos/src/proto_wrapper/sign_doc.rs +++ b/rust/apps/cosmos/src/proto_wrapper/sign_doc.rs @@ -7,7 +7,7 @@ use crate::proto_wrapper::fee::Fee; use crate::proto_wrapper::msg::msg_serialize::Msg; use crate::{CosmosError, Result}; use alloc::boxed::Box; -use alloc::string::{String, ToString}; +use alloc::string::{String}; use alloc::vec::Vec; use serde::Serialize; @@ -26,7 +26,7 @@ impl SignDoc { Message::decode(Bytes::from(proto.body_bytes)).map_err(|e| { CosmosError::ParseTxError(format!( "proto TxBody deserialize failed {}", - e.to_string() + e )) })?; let body = Body::try_from(tx_body)?; @@ -35,7 +35,7 @@ impl SignDoc { Message::decode(Bytes::from(proto.auth_info_bytes)).map_err(|e| { CosmosError::ParseTxError(format!( "proto AuthInfo deserialize failed {}", - e.to_string() + e )) })?; let auth_info = AuthInfo::try_from(auth_info)?; @@ -54,7 +54,7 @@ impl SignDoc { Message::decode(Bytes::from(data.clone())).map_err(|e| { CosmosError::ParseTxError(format!( "proto SignDoc deserialize failed {}", - e.to_string() + e )) })?; SignDoc::from(proto_sign_doc) diff --git a/rust/apps/cosmos/src/proto_wrapper/signer_info.rs b/rust/apps/cosmos/src/proto_wrapper/signer_info.rs index e2ee7fe25..93d45ab07 100644 --- a/rust/apps/cosmos/src/proto_wrapper/signer_info.rs +++ b/rust/apps/cosmos/src/proto_wrapper/signer_info.rs @@ -77,7 +77,7 @@ impl TryFrom<&Any> for PublicKey { .map_err(|err| { CosmosError::ParseTxError(format!( "proto ed25519::PubKey deserialize failed {}", - err.to_string() + err )) })?; Ok(PublicKey { @@ -90,7 +90,7 @@ impl TryFrom<&Any> for PublicKey { Message::decode(&*any.value).map_err(|err| { CosmosError::ParseTxError(format!( "proto secp256k1::PubKey deserialize failed {}", - err.to_string() + err )) })?; Ok(PublicKey { @@ -100,7 +100,7 @@ impl TryFrom<&Any> for PublicKey { } other => Err(CosmosError::ParseTxError(format!( "{} is not supported!!!", - other.to_string() + other ))), } } diff --git a/rust/apps/cosmos/src/transaction/detail.rs b/rust/apps/cosmos/src/transaction/detail.rs index ef147735a..d2885bc83 100644 --- a/rust/apps/cosmos/src/transaction/detail.rs +++ b/rust/apps/cosmos/src/transaction/detail.rs @@ -37,8 +37,7 @@ impl TryFrom for DetailRedelegate { fn try_from(data: MsgBeginRedelegate) -> Result { let value = data - .amount - .and_then(|coin| Some(format_amount(vec![coin]))) + .amount.map(|coin| format_amount(vec![coin])) .unwrap_or("".to_string()); Ok(Self { method: "Re-delegate".to_string(), @@ -70,7 +69,7 @@ impl TryFrom for DetailTransfer { fn try_from(msg: MsgTransfer) -> Result { let value = msg .token - .and_then(|v| format_coin(v)) + .and_then(format_coin) .unwrap_or("".to_string()); Ok(Self { method: "IBC Transfer".to_string(), diff --git a/rust/apps/cosmos/src/transaction/mod.rs b/rust/apps/cosmos/src/transaction/mod.rs index 30c95f6c0..ecc526b0f 100644 --- a/rust/apps/cosmos/src/transaction/mod.rs +++ b/rust/apps/cosmos/src/transaction/mod.rs @@ -11,7 +11,7 @@ use crate::transaction::overview::{CommonOverview, CosmosTxOverview, MsgOverview use crate::transaction::structs::{CosmosTxDisplayType, DataType, ParsedCosmosTx}; use crate::transaction::utils::get_network_by_chain_id; -use rust_tools; + use self::detail::MsgDetail; @@ -48,7 +48,7 @@ impl ParsedCosmosTx { } } fn build_overview_from_amino(data: Value) -> Result { - let chain_id = data["chain_id"].as_str().unwrap_or(&""); + let chain_id = data["chain_id"].as_str().unwrap_or(""); let kind = CosmosTxOverview::from_value(&data["msgs"])?; let common = CommonOverview { network: get_network_by_chain_id(chain_id)?, @@ -61,7 +61,7 @@ impl ParsedCosmosTx { } fn build_detail_from_amino(data: Value) -> Result { - let chain_id = data["chain_id"].as_str().unwrap_or(&""); + let chain_id = data["chain_id"].as_str().unwrap_or(""); let common = CommonDetail { network: get_network_by_chain_id(chain_id)?, chain_id: chain_id.to_string(), diff --git a/rust/apps/cosmos/src/transaction/overview.rs b/rust/apps/cosmos/src/transaction/overview.rs index 2e1707383..e04fea841 100644 --- a/rust/apps/cosmos/src/transaction/overview.rs +++ b/rust/apps/cosmos/src/transaction/overview.rs @@ -54,8 +54,7 @@ impl TryFrom for OverviewDelegate { fn try_from(data: MsgDelegate) -> Result { let value = data - .amount - .and_then(|coin| Some(format_amount(vec![coin]))) + .amount.map(|coin| format_amount(vec![coin])) .unwrap_or("".to_string()); Ok(Self { method: "Delegate".to_string(), @@ -83,8 +82,7 @@ impl TryFrom for OverviewUndelegate { fn try_from(data: MsgUndelegate) -> Result { let value = data - .amount - .and_then(|coin| Some(format_amount(vec![coin]))) + .amount.map(|coin| format_amount(vec![coin])) .unwrap_or("".to_string()); Ok(Self { method: "Undelegate".to_string(), @@ -112,8 +110,7 @@ impl TryFrom for OverviewRedelegate { fn try_from(data: MsgBeginRedelegate) -> Result { let value = data - .amount - .and_then(|coin| Some(format_amount(vec![coin]))) + .amount.map(|coin| format_amount(vec![coin])) .unwrap_or("".to_string()); Ok(Self { method: "Re-delegate".to_string(), @@ -166,7 +163,7 @@ impl TryFrom for OverviewTransfer { fn try_from(msg: MsgTransfer) -> Result { let value = msg .token - .and_then(|v| format_coin(v)) + .and_then(format_coin) .unwrap_or("".to_string()); Ok(Self { method: "IBC Transfer".to_string(), diff --git a/rust/apps/cosmos/src/transaction/utils.rs b/rust/apps/cosmos/src/transaction/utils.rs index 191a17c9b..336ffb8af 100644 --- a/rust/apps/cosmos/src/transaction/utils.rs +++ b/rust/apps/cosmos/src/transaction/utils.rs @@ -6,9 +6,9 @@ use crate::errors::Result; pub fn detect_msg_type(msg_type: Option<&str>) -> &str { let msg_type_parts: Vec<&str> = msg_type - .unwrap_or(&"") - .split("/") - .flat_map(|s| s.split(".")) + .unwrap_or("") + .split('/') + .flat_map(|s| s.split('.')) .collect(); msg_type_parts[msg_type_parts.len() - 1] } @@ -51,15 +51,14 @@ pub fn get_network_by_chain_id(chain_id: &str) -> Result { map.insert("columbus", "Terra Classic"); map.insert("thorchain", "THORChain"); map.insert("neutron", "Neutron"); - let chain_id_parts: Vec<&str> = chain_id.split("-").collect(); + 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("-") } else { chain_id_parts[0].to_string() }; Ok(map - .get(chain_id_prefix.as_str()) - .and_then(|v| Some(v.to_string())) + .get(chain_id_prefix.as_str()).map(|v| v.to_string()) .unwrap_or("Cosmos Hub".to_string())) } diff --git a/rust/apps/cosmos/src/utils.rs b/rust/apps/cosmos/src/utils.rs index 127fc0a25..c5bf85095 100644 --- a/rust/apps/cosmos/src/utils.rs +++ b/rust/apps/cosmos/src/utils.rs @@ -4,7 +4,7 @@ use cryptoxide::hashing; use cryptoxide::ripemd160::Ripemd160; use cryptoxide::sha3::Keccak256; pub(crate) fn sha256_digest(data: &[u8]) -> Vec { - hashing::sha256(&data).to_vec() + hashing::sha256(data).to_vec() } fn ripemd160_digest(data: &[u8]) -> [u8; 20] { diff --git a/rust/apps/ethereum/src/abi.rs b/rust/apps/ethereum/src/abi.rs index 94b83e8ac..fc29d007c 100644 --- a/rust/apps/ethereum/src/abi.rs +++ b/rust/apps/ethereum/src/abi.rs @@ -110,7 +110,7 @@ fn _parse_by_function( _input.name.clone(), match _token { Token::Address(_) => { - format!("0x{}", _token.to_string()) + format!("0x{}", _token) } _ => _token.to_string(), }, @@ -150,13 +150,13 @@ mod tests { }"#; let contract_data = hex::decode("3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000064996e5f00000000000000000000000000000000000000000000000000000000000000020b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000f84605ccc515414000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f46b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000").unwrap(); let result = parse_contract_data(contract_data, json.to_string()); - assert_eq!(true, result.is_ok()); + assert!(result.is_ok()); let result = result.unwrap(); assert_eq!("UniversalRouter", result.contract_name); assert_eq!("execute", result.method_name); assert_eq!(3, result.params.len()); - assert_eq!(result.params.get(0).unwrap().name, "commands"); - assert_eq!(result.params.get(0).unwrap().value, "0b00"); + assert_eq!(result.params.first().unwrap().name, "commands"); + assert_eq!(result.params.first().unwrap().value, "0b00"); assert_eq!(result.params.get(1).unwrap().name, "inputs"); assert_eq!(result.params.get(1).unwrap().value, "[0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000002386f26fc10000,0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000f84605ccc515414000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f46b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000]"); assert_eq!(result.params.get(2).unwrap().name, "deadline"); @@ -177,13 +177,13 @@ mod tests { }"#; let data = hex::decode("3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000064996e5f00000000000000000000000000000000000000000000000000000000000000020b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000f84605ccc515414000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f46b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000").unwrap(); let result = parse_method_data(data, "UniversalRouter".to_string(), json.to_string()); - assert_eq!(true, result.is_ok()); + assert!(result.is_ok()); let result = result.unwrap(); assert_eq!("UniversalRouter", result.contract_name); assert_eq!("execute", result.method_name); assert_eq!(3, result.params.len()); - assert_eq!(result.params.get(0).unwrap().name, "commands"); - assert_eq!(result.params.get(0).unwrap().value, "0b00"); + assert_eq!(result.params.first().unwrap().name, "commands"); + assert_eq!(result.params.first().unwrap().value, "0b00"); assert_eq!(result.params.get(1).unwrap().name, "inputs"); assert_eq!(result.params.get(1).unwrap().value, "[0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000002386f26fc10000,0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000f84605ccc515414000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f46b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000]"); assert_eq!(result.params.get(2).unwrap().name, "deadline"); diff --git a/rust/apps/ethereum/src/eip1559_transaction.rs b/rust/apps/ethereum/src/eip1559_transaction.rs index e75ca89c5..4ccc1058b 100644 --- a/rust/apps/ethereum/src/eip1559_transaction.rs +++ b/rust/apps/ethereum/src/eip1559_transaction.rs @@ -7,7 +7,7 @@ use alloc::string::{String, ToString}; use core::ops::Mul; use ethereum_types::U256; -use hex; + use rlp::{Decodable, DecoderError, Rlp}; pub struct EIP1559Transaction { diff --git a/rust/apps/ethereum/src/erc20.rs b/rust/apps/ethereum/src/erc20.rs index 66b9e6476..a3d2b754a 100644 --- a/rust/apps/ethereum/src/erc20.rs +++ b/rust/apps/ethereum/src/erc20.rs @@ -45,7 +45,7 @@ pub fn parse_erc20(input: &str, decimal: u32) -> Resultwidth$}", remainder_decimal, width = decimal as usize); - format!("{}.{}", value_decimal.to_string(), padded_remainder) + format!("{}.{}", value_decimal, padded_remainder) .trim_end_matches('0') .to_string() } else { diff --git a/rust/apps/ethereum/src/legacy_transaction.rs b/rust/apps/ethereum/src/legacy_transaction.rs index 0462f3753..4a8c6fe70 100644 --- a/rust/apps/ethereum/src/legacy_transaction.rs +++ b/rust/apps/ethereum/src/legacy_transaction.rs @@ -5,7 +5,7 @@ use core::str::FromStr; use bytes::BytesMut; use ethereum_types::{H256, U256}; -use hex; + use rlp::{Decodable, DecoderError, Encodable, Rlp}; use ur_registry::pb::protoc::EthTx; @@ -254,7 +254,7 @@ impl Encodable for LegacyTransaction { s.append(&self.value); s.append(&self.input); // chain_id will remove when the signature is added - if let None = &self.signature { + if self.signature.is_none() { s.append(&self.chain_id()); s.append(&vec![]); s.append(&vec![]); @@ -367,7 +367,7 @@ mod tests { let signed_tx_hex = hex::encode(&signed_tx); // tx id === tx hash let signed_tx_hash = keccak256(&signed_tx); - let signed_tx_hash_hex = hex::encode(&signed_tx_hash); + let signed_tx_hash_hex = hex::encode(signed_tx_hash); assert_eq!( "fec8bfea5ec13ad726de928654cd1733b1d81d2d2916ac638e6b9a245f034ace".to_string(), @@ -409,7 +409,7 @@ mod tests { .to_string() ); let unsigned_tx_hash = keccak256(&unsigned_tx); - let unsigned_tx_hash_hex = hex::encode(&unsigned_tx_hash); + let _unsigned_tx_hash_hex = hex::encode(unsigned_tx_hash); // sign tx let r = "0x35df2b615912b8be79a13c9b0a1540ade55434ab68778a49943442a9e6d3141a".to_string(); let s = "0x0a6e33134ba47c1f1cda59ec3ef62a59d4da6a9d111eb4e447828574c1c94f66".to_string(); @@ -430,7 +430,7 @@ mod tests { // tx id === tx hash let signed_tx_hash = keccak256(&signed_tx); - let signed_tx_hash_hex = hex::encode(&signed_tx_hash); + let signed_tx_hash_hex = hex::encode(signed_tx_hash); assert_eq!( "c20d7398343b00d1bc5aaf8f6d9a879217003d6cc726053cd41fb960977cd066".to_string(), signed_tx_hash_hex @@ -471,10 +471,10 @@ mod tests { // raw tx let signed_tx = tx.encode_raw(); - let signed_tx_hex = hex::encode(&signed_tx); + let _signed_tx_hex = hex::encode(&signed_tx); // tx id === tx hash let signed_tx_hash = keccak256(&signed_tx); - let signed_tx_hash_hex = hex::encode(&signed_tx_hash); + let signed_tx_hash_hex = hex::encode(signed_tx_hash); assert_eq!( "e01dd745d8cc0983f288da28ab288f7d1be809164c83ae477bdb927d31f49a7c".to_string(), signed_tx_hash_hex diff --git a/rust/apps/ethereum/src/lib.rs b/rust/apps/ethereum/src/lib.rs index ed16cd17e..f00d51f10 100644 --- a/rust/apps/ethereum/src/lib.rs +++ b/rust/apps/ethereum/src/lib.rs @@ -9,9 +9,9 @@ use alloc::vec::Vec; use bitcoin::secp256k1::{Message, PublicKey}; pub use ethereum_types::{H160, U256}; -use hex; + pub use legacy_transaction::*; -use serde_json; + use crate::crypto::keccak256; use crate::eip1559_transaction::{EIP1559Transaction, ParsedEIP1559Transaction}; @@ -178,11 +178,11 @@ mod tests { extern crate std; - use core::str::FromStr; + - use hex; + use keystore::algorithms::secp256k1::get_public_key_by_seed; - use serde_json; + use crate::alloc::string::ToString; use crate::eip712::eip712::{Eip712, TypedData as Eip712TypedData}; @@ -596,7 +596,7 @@ mod tests { } } "#; - let typed_data: Eip712TypedData = serde_json::from_str(&utf8_msg).unwrap(); + let typed_data: Eip712TypedData = serde_json::from_str(utf8_msg).unwrap(); let hash = typed_data.encode_eip712().unwrap(); assert_eq!( "cosmos", diff --git a/rust/apps/ethereum/src/structs.rs b/rust/apps/ethereum/src/structs.rs index 4dfec0b70..0a38dc6a6 100644 --- a/rust/apps/ethereum/src/structs.rs +++ b/rust/apps/ethereum/src/structs.rs @@ -39,7 +39,7 @@ impl Encodable for TransactionAction { s.append_empty_data(); } } - () + } } diff --git a/rust/apps/near/src/account_id/borsh.rs b/rust/apps/near/src/account_id/borsh.rs index b778a6bd4..c2a141b0a 100644 --- a/rust/apps/near/src/account_id/borsh.rs +++ b/rust/apps/near/src/account_id/borsh.rs @@ -33,7 +33,7 @@ mod tests { #[test] fn test_is_valid_account_id() { - for account_id in OK_ACCOUNT_IDS.iter().cloned() { + for account_id in OK_ACCOUNT_IDS.iter() { let parsed_account_id = account_id.parse::().unwrap_or_else(|err| { panic!("Valid account id {:?} marked invalid: {}", account_id, err) }); @@ -53,7 +53,7 @@ mod tests { assert_eq!(serialized_account_id, str_serialized_account_id); } - for account_id in BAD_ACCOUNT_IDS.iter().cloned() { + for account_id in BAD_ACCOUNT_IDS.iter() { let str_serialized_account_id = account_id.try_to_vec().unwrap(); assert!( diff --git a/rust/apps/near/src/account_id/mod.rs b/rust/apps/near/src/account_id/mod.rs index 0134bdcbe..87b0c6f2f 100644 --- a/rust/apps/near/src/account_id/mod.rs +++ b/rust/apps/near/src/account_id/mod.rs @@ -243,7 +243,7 @@ mod tests { } for account_id in BAD_ACCOUNT_IDS.iter().cloned() { - if let Ok(_) = AccountId::validate(account_id) { + if AccountId::validate(account_id).is_ok() { panic!("Invalid account id {:?} marked valid", account_id); } } diff --git a/rust/apps/near/src/account_id/serde.rs b/rust/apps/near/src/account_id/serde.rs index 05733aee0..3817aac74 100644 --- a/rust/apps/near/src/account_id/serde.rs +++ b/rust/apps/near/src/account_id/serde.rs @@ -33,7 +33,7 @@ mod tests { #[test] fn test_is_valid_account_id() { - for account_id in OK_ACCOUNT_IDS.iter().cloned() { + for account_id in OK_ACCOUNT_IDS.iter() { let parsed_account_id = account_id.parse::().unwrap_or_else(|err| { panic!("Valid account id {:?} marked invalid: {}", account_id, err) }); @@ -51,7 +51,7 @@ mod tests { assert_eq!(serialized_account_id, json!(account_id)); } - for account_id in BAD_ACCOUNT_IDS.iter().cloned() { + for account_id in BAD_ACCOUNT_IDS.iter() { assert!( serde_json::from_value::(json!(account_id)).is_err(), "successfully deserialized invalid account ID {:?}", diff --git a/rust/apps/near/src/crypto/errors.rs b/rust/apps/near/src/crypto/errors.rs index 6acced938..375978e4d 100644 --- a/rust/apps/near/src/crypto/errors.rs +++ b/rust/apps/near/src/crypto/errors.rs @@ -1,5 +1,5 @@ use alloc::string::String; -use thiserror; + #[derive(Debug, Clone, thiserror::Error)] pub enum ParseKeyTypeError { diff --git a/rust/apps/near/src/crypto/mod.rs b/rust/apps/near/src/crypto/mod.rs index 488e06fab..5903499d1 100644 --- a/rust/apps/near/src/crypto/mod.rs +++ b/rust/apps/near/src/crypto/mod.rs @@ -1,4 +1,4 @@ mod errors; mod pubkey; -pub use pubkey::{KeyType, PublicKey}; +pub use pubkey::{PublicKey}; diff --git a/rust/apps/near/src/crypto/pubkey.rs b/rust/apps/near/src/crypto/pubkey.rs index 9f966961d..f51de10ca 100644 --- a/rust/apps/near/src/crypto/pubkey.rs +++ b/rust/apps/near/src/crypto/pubkey.rs @@ -108,7 +108,7 @@ impl AsRef<[u8]> for Secp256K1PublicKey { impl Debug for Secp256K1PublicKey { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), core::fmt::Error> { - write!(f, "{}", bs58::encode(&self.0.to_vec())) + write!(f, "{}", bs58::encode(self.0.as_ref())) } } @@ -150,7 +150,7 @@ impl TryFrom<&[u8]> for ED25519PublicKey { impl Debug for ED25519PublicKey { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), core::fmt::Error> { - write!(f, "{}", bs58::encode(&self.0.to_vec())) + write!(f, "{}", bs58::encode(self.0.as_ref())) } } @@ -298,7 +298,7 @@ impl From<&PublicKey> for String { PublicKey::SECP256K1(public_key) => format!( "{}:{}", KeyType::SECP256K1, - bs58::encode(&public_key.0.to_vec()) + bs58::encode(public_key.0.as_ref()) ), } } diff --git a/rust/apps/near/src/errors.rs b/rust/apps/near/src/errors.rs index abe90fbec..f9ca3d932 100644 --- a/rust/apps/near/src/errors.rs +++ b/rust/apps/near/src/errors.rs @@ -21,8 +21,8 @@ pub type Result = core::result::Result; impl From for NearError { fn from(value: KeystoreError) -> Self { match value { - KeystoreError::DerivePubKey(data) => Self::KeystoreError(format!("{}", data)), - KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(format!("{}", data)), + KeystoreError::DerivePubKey(data) => Self::KeystoreError(data.to_string()), + KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(data.to_string()), KeystoreError::XPubError(data) => Self::KeystoreError(data), KeystoreError::SeedError(data) => Self::KeystoreError(data), KeystoreError::DerivationError(data) => Self::KeystoreError(data), diff --git a/rust/apps/near/src/lib.rs b/rust/apps/near/src/lib.rs index 59a6fe890..dd15fbd16 100644 --- a/rust/apps/near/src/lib.rs +++ b/rust/apps/near/src/lib.rs @@ -34,7 +34,7 @@ pub fn parse(data: &Vec) -> Result { #[cfg(test)] mod tests { use super::*; - use hex; + use hex::ToHex; use ur_registry::near::near_sign_request::NearSignRequest; #[test] diff --git a/rust/apps/near/src/parser/mod.rs b/rust/apps/near/src/parser/mod.rs index b06ec7fab..38c9daac4 100644 --- a/rust/apps/near/src/parser/mod.rs +++ b/rust/apps/near/src/parser/mod.rs @@ -12,7 +12,7 @@ use crate::parser::utils::format_amount; use crate::parser::utils::Merge; use alloc::format; use alloc::string::{String, ToString}; -use alloc::vec; + use alloc::vec::Vec; use borsh::BorshDeserialize; use serde_json; diff --git a/rust/apps/near/src/parser/utils.rs b/rust/apps/near/src/parser/utils.rs index 4c0b31512..f811283d7 100644 --- a/rust/apps/near/src/parser/utils.rs +++ b/rust/apps/near/src/parser/utils.rs @@ -5,7 +5,7 @@ use serde::Serializer; pub const NEAR_THRESHOLD: u128 = 10000000000000000000; pub const NEAR_DIVIDER: f64 = 1_000_000_000_000_000_000_000_000f64; -pub const GAS_DIVIDER: f64 = 1000_000_000_000f64; +pub const GAS_DIVIDER: f64 = 1_000_000_000_000_f64; use serde_json; use serde_json::Value; @@ -22,15 +22,15 @@ impl Merge for serde_json::Value { fn merge(a: &mut Value, b: &Value) { match (a, b) { - (Value::Object(ref mut a), &Value::Object(ref b)) => { + (Value::Object(ref mut a), Value::Object(b)) => { for (k, v) in b { merge(a.entry(k).or_insert(Value::Null), v); } } - (Value::Array(ref mut a), &Value::Array(ref b)) => { + (Value::Array(ref mut a), Value::Array(b)) => { a.extend(b.clone()); } - (Value::Array(ref mut a), &Value::Object(ref b)) => { + (Value::Array(ref mut a), Value::Object(b)) => { a.extend([Value::Object(b.clone())]); } (a, b) => { @@ -40,25 +40,25 @@ fn merge(a: &mut Value, b: &Value) { } pub fn format_amount(value: u128) -> String { - return if value > NEAR_THRESHOLD { + if value > NEAR_THRESHOLD { format!("{} {}", (value as f64).div(NEAR_DIVIDER), "NEAR") } else { format!("{} {}", value, "Yocto") - }; + } } pub fn format_option_u128_amount(v: &Option, serializer: S) -> Result where S: Serializer, { - serializer.serialize_str(&format_amount(v.unwrap_or(u128::default()))) + serializer.serialize_str(&format_amount(v.unwrap_or_default())) } pub fn format_u128_amount(v: &u128, serializer: S) -> Result where S: Serializer, { - serializer.serialize_str(&format_amount(v.clone())) + serializer.serialize_str(&format_amount(*v)) } pub fn format_gas(value: u64) -> String { @@ -69,7 +69,7 @@ pub fn format_gas_amount(v: &u64, serializer: S) -> Result where S: Serializer, { - serializer.serialize_str(&format_gas(v.clone())) + serializer.serialize_str(&format_gas(*v)) } #[cfg(test)] diff --git a/rust/apps/near/src/primitives_core/account.rs b/rust/apps/near/src/primitives_core/account.rs index 84f42a387..742c1ee8e 100644 --- a/rust/apps/near/src/primitives_core/account.rs +++ b/rust/apps/near/src/primitives_core/account.rs @@ -123,7 +123,7 @@ impl BorshDeserialize for Account { // This should only ever happen if we have pre-transition account serialized in state // See test_account_size let deserialized_account = LegacyAccount::deserialize(buf)?; - if buf.len() != 0 { + if !buf.is_empty() { panic!("Tried deserializing a buffer that is not exactly the size of an account"); } Ok(Account { diff --git a/rust/apps/near/src/primitives_core/hash.rs b/rust/apps/near/src/primitives_core/hash.rs index b565189be..672910451 100644 --- a/rust/apps/near/src/primitives_core/hash.rs +++ b/rust/apps/near/src/primitives_core/hash.rs @@ -11,6 +11,7 @@ use cryptoxide::sha2; use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Default)] pub struct CryptoHash(pub [u8; 32]); impl CryptoHash { @@ -23,11 +24,7 @@ impl CryptoHash { } } -impl Default for CryptoHash { - fn default() -> Self { - CryptoHash(Default::default()) - } -} + impl borsh::BorshSerialize for CryptoHash { fn serialize(&self, writer: &mut W) -> Result<(), io::Error> { diff --git a/rust/apps/near/src/primitives_core/serialize.rs b/rust/apps/near/src/primitives_core/serialize.rs index 8e0bab355..2f38fac04 100644 --- a/rust/apps/near/src/primitives_core/serialize.rs +++ b/rust/apps/near/src/primitives_core/serialize.rs @@ -13,7 +13,7 @@ pub fn to_base(input: &Vec) -> String { } pub fn from_base(s: &str) -> Result, bs58::Error> { - bs58::decode(s).map_err(|e| bs58::Error::Decode(e)) + bs58::decode(s).map_err(bs58::Error::Decode) } pub fn to_base64>(input: T) -> String { diff --git a/rust/apps/stellar/src/address.rs b/rust/apps/stellar/src/address.rs index f2ce26813..6635cf218 100644 --- a/rust/apps/stellar/src/address.rs +++ b/rust/apps/stellar/src/address.rs @@ -66,7 +66,7 @@ mod tests { let address_error = StellarError::AddressError( "hex decode error Invalid character 'g' at position 63".to_string(), ); - let error: StellarError = address_error.into(); + let error: StellarError = address_error; let xpub = "5f5a723f0f3ef785387b016a8b61eb2713b02f429edadfacd96082d7da02959g"; let address_from_xpub = get_address(&xpub.to_string()); assert_eq!( diff --git a/rust/apps/stellar/src/lib.rs b/rust/apps/stellar/src/lib.rs index ab70e02d9..5bea76446 100644 --- a/rust/apps/stellar/src/lib.rs +++ b/rust/apps/stellar/src/lib.rs @@ -12,7 +12,7 @@ extern crate alloc; use crate::structs::Network; use alloc::string::String; use alloc::vec::Vec; -use base64; + pub fn get_network_from_base(base: &[u8]) -> Network { let network_id = &base[0..32]; @@ -30,7 +30,7 @@ pub fn base_to_xdr(base: &[u8]) -> String { #[cfg(test)] mod tests { - use hex; + extern crate std; use super::*; diff --git a/rust/apps/stellar/src/strkeys.rs b/rust/apps/stellar/src/strkeys.rs index ecc5c414d..86e8f8168 100644 --- a/rust/apps/stellar/src/strkeys.rs +++ b/rust/apps/stellar/src/strkeys.rs @@ -94,7 +94,7 @@ pub fn generate_stellar_private_key(seed: &[u8], path: &String) -> Result Result<[u8; 64]> { - keystore::algorithms::ed25519::slip10_ed25519::sign_message_by_seed(seed, path, &hash) + keystore::algorithms::ed25519::slip10_ed25519::sign_message_by_seed(seed, path, hash) } pub fn sign_signature_base(signature_base: &[u8], seed: &[u8], path: &String) -> Result<[u8; 64]> { @@ -105,7 +105,7 @@ pub fn sign_signature_base(signature_base: &[u8], seed: &[u8], path: &String) -> #[cfg(test)] mod tests { use super::*; - use alloc::string::{String, ToString}; + use alloc::string::{ToString}; use hex; #[test] @@ -137,7 +137,7 @@ mod tests { let signed = sign_hash(&hash, &seed, &path).unwrap(); assert_eq!( "baa7bcf26f8ed50d48e3d15d918f1ae684eaf7a2f876bd6913c78df59eeebcb9a5078628391c9e8d83430b9cc358a8548d0da6f0783a72743104a91e97c5f701", - hex::encode(&signed) + hex::encode(signed) ); } @@ -149,7 +149,7 @@ mod tests { let signed = sign_signature_base(&base, &seed, &path).unwrap(); assert_eq!( "baa7bcf26f8ed50d48e3d15d918f1ae684eaf7a2f876bd6913c78df59eeebcb9a5078628391c9e8d83430b9cc358a8548d0da6f0783a72743104a91e97c5f701", - hex::encode(&signed) + hex::encode(signed) ); } } diff --git a/rust/apps/sui/src/lib.rs b/rust/apps/sui/src/lib.rs index edd92afa9..656738e24 100644 --- a/rust/apps/sui/src/lib.rs +++ b/rust/apps/sui/src/lib.rs @@ -55,11 +55,11 @@ pub fn parse_intent(intent: &[u8]) -> Result { match IntentScope::try_from(intent[0])? { IntentScope::TransactionData => { let tx: IntentMessage = - bcs::from_bytes(&intent).map_err(|err| SuiError::from(err))?; + bcs::from_bytes(intent).map_err(SuiError::from)?; Ok(Intent::TransactionData(tx)) } IntentScope::PersonalMessage => { - let msg: IntentMessage = match bcs::from_bytes(&intent) { + let msg: IntentMessage = match bcs::from_bytes(intent) { Ok(msg) => msg, Err(_) => { if intent.len() < 4 { @@ -67,7 +67,7 @@ pub fn parse_intent(intent: &[u8]) -> Result { } let intent_bytes = intent[..3].to_vec(); IntentMessage::::new( - types::intent::Intent::from_str(hex::encode(&intent_bytes).as_str())?, + types::intent::Intent::from_str(hex::encode(intent_bytes).as_str())?, PersonalMessage { message: intent[3..].to_vec(), }, @@ -86,7 +86,7 @@ pub fn parse_intent(intent: &[u8]) -> Result { })) } _ => { - return Err(SuiError::InvalidData(String::from("unsupported intent"))); + Err(SuiError::InvalidData(String::from("unsupported intent"))) } } } diff --git a/rust/apps/ton/src/jettons.rs b/rust/apps/ton/src/jettons.rs index f2a61478c..73b65c6fd 100644 --- a/rust/apps/ton/src/jettons.rs +++ b/rust/apps/ton/src/jettons.rs @@ -47,5 +47,5 @@ pub fn get_jetton_amount_text(coins: String, contract_address: String) -> String .unwrap(); let value = u64::from_str_radix(&coins, 10).unwrap(); let divisor = 10u64.pow(target.decimal as u32) as f64; - return format!("{} {}", (value as f64) / divisor, target.symbol); + format!("{} {}", (value as f64) / divisor, target.symbol) } diff --git a/rust/apps/ton/src/lib.rs b/rust/apps/ton/src/lib.rs index f0cacf764..004eb37a7 100644 --- a/rust/apps/ton/src/lib.rs +++ b/rust/apps/ton/src/lib.rs @@ -31,7 +31,7 @@ pub fn ton_public_key_to_address(pk: Vec) -> Result { pub fn ton_compare_address_and_public_key(pk: Vec, address: String) -> bool { match TonWallet::derive_default(vendor::wallet::WalletVersion::V4R2, pk) { Ok(wallet) => match TonAddress::from_str(&address) { - Ok(address) => return wallet.address.eq(&address), + Ok(address) => wallet.address.eq(&address), Err(_e) => false, }, Err(_e) => false, @@ -40,7 +40,7 @@ pub fn ton_compare_address_and_public_key(pk: Vec, address: String) -> bool #[cfg(test)] mod tests { - use hex; + #[test] fn test_generate_address() { diff --git a/rust/apps/ton/src/messages/jetton.rs b/rust/apps/ton/src/messages/jetton.rs index 9e0754f3b..c7f931c5e 100644 --- a/rust/apps/ton/src/messages/jetton.rs +++ b/rust/apps/ton/src/messages/jetton.rs @@ -76,7 +76,7 @@ impl ParseCell for JettonTransferMessage { let mut ref_index = 0; let custom_payload = if parser.load_bit()? { let payload = Some(hex::encode(cell.reference(ref_index)?.data.clone())); - ref_index = ref_index + 1; + ref_index += 1; payload } else { None @@ -87,7 +87,7 @@ impl ParseCell for JettonTransferMessage { let comment = Comment::parse(child); let payload = Some(hex::encode(child.data.clone())); - ref_index = ref_index + 1; + ref_index += 1; (payload, comment.ok()) } else { (None, None) diff --git a/rust/apps/ton/src/messages/mod.rs b/rust/apps/ton/src/messages/mod.rs index 17d56dbff..1557f2f2c 100644 --- a/rust/apps/ton/src/messages/mod.rs +++ b/rust/apps/ton/src/messages/mod.rs @@ -2,7 +2,7 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; -use hex; + use serde::Serialize; use self::jetton::JettonMessage; @@ -37,7 +37,7 @@ impl ParseCell for SigningMessage { let messages: Result, TonCellError> = cell .references .iter() - .map(|cell| TransferMessage::parse(cell)) + .map(TransferMessage::parse) .collect(); Ok(Self { wallet_id, @@ -90,22 +90,20 @@ impl ParseCell for TransferMessage { let mut ref_index = 0; let state_init = if parser.load_bit()? { let init = Some(hex::encode(cell.reference(ref_index)?.data.clone())); - ref_index = ref_index + 1; + ref_index += 1; init } else { None }; let data = if parser.load_bit()? { Some(InternalMessage::parse(cell.reference(ref_index)?)) + } else if parser.remaining_bits() > 0 { + let mut builder = CellBuilder::new(); + let remaining_bits = parser.remaining_bits(); + builder.store_bits(remaining_bits, &parser.load_bits(remaining_bits)?)?; + Some(InternalMessage::parse(&builder.build()?.to_arc())) } else { - if parser.remaining_bits() > 0 { - let mut builder = CellBuilder::new(); - let remaining_bits = parser.remaining_bits(); - builder.store_bits(remaining_bits, &parser.load_bits(remaining_bits)?)?; - Some(InternalMessage::parse(&builder.build()?.to_arc())) - } else { - None - } + None }; Ok(Self { ihr_disabled, diff --git a/rust/apps/ton/src/messages/nft.rs b/rust/apps/ton/src/messages/nft.rs index 47a10ad21..8261deddc 100644 --- a/rust/apps/ton/src/messages/nft.rs +++ b/rust/apps/ton/src/messages/nft.rs @@ -56,7 +56,7 @@ impl ParseCell for NFTTransferMessage { let mut ref_index = 0; let custom_payload = if parser.load_bit()? { let payload = Some(hex::encode(cell.reference(ref_index)?.data.clone())); - ref_index = ref_index + 1; + ref_index += 1; payload } else { None @@ -67,7 +67,7 @@ impl ParseCell for NFTTransferMessage { let comment = Comment::parse(child); let payload = Some(hex::encode(child.data.clone())); - ref_index = ref_index + 1; + ref_index += 1; (payload, comment.ok()) } else { (None, None) diff --git a/rust/apps/ton/src/mnemonic.rs b/rust/apps/ton/src/mnemonic.rs index 049652924..cf3f49762 100644 --- a/rust/apps/ton/src/mnemonic.rs +++ b/rust/apps/ton/src/mnemonic.rs @@ -34,7 +34,7 @@ pub fn ton_mnemonic_validate( if seed[0] != 1 { return Err(MnemonicError::InvalidFirstByte(seed[0]).into()); } - let entropy = ton_mnemonic_to_entropy(&normalized_words, password); + let entropy = ton_mnemonic_to_entropy(normalized_words, password); pbkdf2_sha512( &entropy, "TON seed version".as_bytes(), @@ -101,12 +101,12 @@ pub fn ton_master_seed_to_public_key(master_seed: [u8; 64]) -> [u8; 32] { #[cfg(test)] mod tests { use alloc::{string::ToString, vec}; - use base64::Engine; + use hex; use super::*; extern crate std; - use std::{println, vec::Vec}; + use std::{vec::Vec}; #[test] fn test_ton_mnemonic_to_entropy() { @@ -137,15 +137,13 @@ mod tests { #[test] fn test_ton_mnemonic_invalid_mnemonic() { - let words = vec![ - "dose", "ice", "enrich", "trigger", "test", "dove", "century", "still", "betray", - "gas", "diet", "dune", - ] + let words = ["dose", "ice", "enrich", "trigger", "test", "dove", "century", "still", "betray", + "gas", "diet", "dune"] .iter() .map(|v| v.to_lowercase()) .collect(); let result = ton_mnemonic_to_master_seed(words, None); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), "Invalid TON Mnemonic, Invalid mnemonic word count (count: 12)" diff --git a/rust/apps/ton/src/structs.rs b/rust/apps/ton/src/structs.rs index fb0086550..6125ff561 100644 --- a/rust/apps/ton/src/structs.rs +++ b/rust/apps/ton/src/structs.rs @@ -27,7 +27,7 @@ pub struct TonTransaction { impl TonTransaction { pub fn parse(boc: BagOfCells) -> Result { let root = boc.single_root()?; - let signing_message = SigningMessage::parse(&root)?; + let signing_message = SigningMessage::parse(root)?; Self::try_from(&signing_message) } @@ -49,7 +49,7 @@ impl TryFrom<&SigningMessage> for TonTransaction { type Error = TonError; fn try_from(signing_message: &SigningMessage) -> Result { - if let None = signing_message.messages.get(0) { + if signing_message.messages.first().is_none() { return Err(TonError::InvalidTransaction( "transaction does not contain transfer info".to_string(), )); @@ -194,7 +194,7 @@ impl TonProof { for i in 0..8 { timestamp_bytes[i] = remaining[i + 40 + domain_len as usize]; } - index = index + 8; + index += 8; // need to transform to date time to display let _timestamp = i64::from_le_bytes(timestamp_bytes); diff --git a/rust/apps/ton/src/transaction.rs b/rust/apps/ton/src/transaction.rs index 15308c807..978de9cf4 100644 --- a/rust/apps/ton/src/transaction.rs +++ b/rust/apps/ton/src/transaction.rs @@ -97,10 +97,10 @@ mod tests { sk[i] = master_seed[i] } let signature = super::sign_transaction(&serial, sk).unwrap(); - println!("{}", hex::encode(&signature)); + println!("{}", hex::encode(signature)); println!( "tonkeeper://publish?boc={}", - urlencoding::encode(&STANDARD.encode(&signature)) + urlencoding::encode(&STANDARD.encode(signature)) ); } diff --git a/rust/apps/ton/src/utils.rs b/rust/apps/ton/src/utils.rs index ad2e72684..d48e406b5 100644 --- a/rust/apps/ton/src/utils.rs +++ b/rust/apps/ton/src/utils.rs @@ -25,7 +25,7 @@ pub(crate) fn shorten_string(text: String) -> String { let _ = _text.split_off(512); _text.push_str("......"); } - return _text; + _text } #[cfg(test)] diff --git a/rust/apps/ton/src/vendor/address/mod.rs b/rust/apps/ton/src/vendor/address/mod.rs index d83573198..b39d9fa52 100644 --- a/rust/apps/ton/src/vendor/address/mod.rs +++ b/rust/apps/ton/src/vendor/address/mod.rs @@ -484,7 +484,7 @@ mod tests { let address = "124"; let a = format!("\"{}\"", address); let deserial: serde_json::Result = serde_json::from_str(a.as_str()); - assert_eq!(true, deserial.is_err()); + assert!(deserial.is_err()); Ok(()) } diff --git a/rust/apps/tron/src/address.rs b/rust/apps/tron/src/address.rs index 8ba45bf81..f10c23902 100644 --- a/rust/apps/tron/src/address.rs +++ b/rust/apps/tron/src/address.rs @@ -21,7 +21,7 @@ macro_rules! check_hd_path { macro_rules! derivation_address_path { ($t: expr) => {{ let parts = $t.split("/").collect::>(); - let result: Result = match crate::check_hd_path!(parts) { + let result: Result = match $crate::check_hd_path!(parts) { Ok(_) => { let path = parts.as_slice()[parts.len() - 2..].to_vec().join("/"); Ok(format!("{}{}", "m/", path)) diff --git a/rust/apps/tron/src/errors.rs b/rust/apps/tron/src/errors.rs index 40a411a17..6b807040c 100644 --- a/rust/apps/tron/src/errors.rs +++ b/rust/apps/tron/src/errors.rs @@ -1,4 +1,4 @@ -use alloc::format; + use alloc::string::{String, ToString}; use bitcoin::base58::Error as Base58Error; use keystore::errors::KeystoreError; @@ -32,8 +32,8 @@ pub type Result = core::result::Result; impl From for TronError { fn from(value: KeystoreError) -> Self { match value { - KeystoreError::DerivePubKey(data) => Self::KeystoreError(format!("{}", data)), - KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(format!("{}", data)), + KeystoreError::DerivePubKey(data) => Self::KeystoreError(data.to_string()), + KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(data.to_string()), KeystoreError::XPubError(data) => Self::KeystoreError(data), KeystoreError::SeedError(data) => Self::KeystoreError(data), KeystoreError::DerivationError(data) => Self::KeystoreError(data), diff --git a/rust/apps/tron/src/transaction/parser.rs b/rust/apps/tron/src/transaction/parser.rs index 81bcc0578..a0ec03a6a 100644 --- a/rust/apps/tron/src/transaction/parser.rs +++ b/rust/apps/tron/src/transaction/parser.rs @@ -91,8 +91,8 @@ mod tests { assert_eq!("0.000001 TRX".to_string(), parsed_tx.detail.value); assert_eq!("TRX Transfer".to_string(), parsed_tx.detail.method); assert_eq!("TRX Transfer".to_string(), parsed_tx.overview.method); - assert_eq!(true, parsed_tx.detail.contract_address.is_empty()); - assert_eq!(true, parsed_tx.detail.token.is_empty()); + assert!(parsed_tx.detail.contract_address.is_empty()); + assert!(parsed_tx.detail.token.is_empty()); } #[test] @@ -125,7 +125,7 @@ mod tests { assert_eq!("0.001 BTT".to_string(), parsed_tx.detail.value); assert_eq!("TRC-10 Transfer".to_string(), parsed_tx.detail.method); assert_eq!("TRC-10 Transfer".to_string(), parsed_tx.overview.method); - assert_eq!(true, parsed_tx.detail.contract_address.is_empty()); + assert!(parsed_tx.detail.contract_address.is_empty()); assert_eq!("1002000".to_string(), parsed_tx.detail.token); } @@ -164,7 +164,7 @@ mod tests { "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t".to_string(), parsed_tx.detail.contract_address ); - assert_eq!(true, parsed_tx.detail.token.is_empty()); + assert!(parsed_tx.detail.token.is_empty()); } { let hex = "1f8b08000000000000036590bb4ec2500086158d212c4ae3409848638231697aaeeda993012f040a166c8074316d4f1b01a1da969b2383a3cfe0ec03b0bac81b38b8b8bab8b9b85a66bf7cc33f7ef9d32961b7199603ee158c30880337b8cdaf52e99490a648254405585ca632db66ebb2211c4080d6320901db9708f76dc9810c4b34c157180714a07cb62e135294a1468b32489461e1ebf169b580873ba5ef4d4134cbe7ba4ef98c5a555e1b75c65ed49df560db98f6f5f6b06359732d2f9aa7837034ad3f443066fde0a27d17e90a19d6303c0b5bb8177771248a666512c57a496db6260ebfbf31c60d7b6e065a87f6355c1f20ab3239da40fb10fce7b89139819e9ff47ac4610e5320f21dc401c19801e062c23d9ff89ae203e051c55535d725d4b63972806d3305a8d4657b9f3fcb5ceee3e5fd6d014bd9cc56f5ca14d2eb97ae9395132acfbf4ae1d5f803c61a369f5e010000"; diff --git a/rust/apps/tron/src/transaction/wrapped_tron.rs b/rust/apps/tron/src/transaction/wrapped_tron.rs index 808ede41e..bce69b5a1 100644 --- a/rust/apps/tron/src/transaction/wrapped_tron.rs +++ b/rust/apps/tron/src/transaction/wrapped_tron.rs @@ -43,7 +43,7 @@ pub struct WrappedTron { macro_rules! derivation_account_path { ($t: expr) => {{ let parts = $t.split("/").collect::>(); - let result: Result = match crate::check_hd_path!(parts) { + let result: Result = match $crate::check_hd_path!(parts) { Ok(_) => { let path = parts.as_slice()[1..parts.len() - 2].to_vec().join("/"); Ok(format!("{}{}", "m/", path)) @@ -92,7 +92,7 @@ impl WrappedTron { ) -> Result { let to_address = base58check_to_u8_slice(to)?; let owner_address = base58check_to_u8_slice(from)?; - return if token.to_uppercase() == "TRX" { + if token.to_uppercase() == "TRX" { let mut transfer_contract = TransferContract::default(); transfer_contract.owner_address = owner_address; transfer_contract.amount = amount; @@ -118,7 +118,7 @@ impl WrappedTron { "TransferAssetContract", None, ) - }; + } } fn build_transfer_contract( @@ -144,7 +144,7 @@ impl WrappedTron { raw.contract = vec![contract]; let mut transaction = Transaction::default(); transaction.raw_data = Some(raw); - return Ok(transaction); + Ok(transaction) } fn ref_with_latest_block( @@ -153,7 +153,7 @@ impl WrappedTron { is_trc_20: bool, ) -> Result { let number_buf: [u8; 8] = (latest_block.number as u64).to_be_bytes(); - let hash_buf = hex::decode(latest_block.hash.to_string()).map_err(|_e| { + let hash_buf = hex::decode(&latest_block.hash).map_err(|_e| { TronError::InvalidRawTxCryptoBytes(format!( "invalid latest block hash {}", latest_block.hash @@ -172,7 +172,7 @@ impl WrappedTron { raw_data.expiration = latest_block.timestamp + 600 * 5 * 1000; tx.raw_data = Some(raw_data); }; - return Ok(tx.to_owned()); + Ok(tx.to_owned()) } fn build_transfer_tx(tx_data: &protoc::TronTx) -> Result { @@ -199,7 +199,7 @@ impl WrappedTron { .ok_or(TronError::InvalidRawTxCryptoBytes( "empty latest block".to_string(), ))?; - return Self::ref_with_latest_block(tx, latest_block, false); + Self::ref_with_latest_block(tx, latest_block, false) } #[allow(deprecated)] @@ -314,7 +314,7 @@ impl WrappedTron { pub fn format_amount(&self) -> Result { let value = f64::from_str(self.value.as_str())?; let unit = self.format_unit()?; - Ok(format!("{} {}", value.div(self.divider as f64), unit)) + Ok(format!("{} {}", value.div(self.divider), unit)) } pub fn format_method(&self) -> Result { @@ -334,5 +334,5 @@ impl WrappedTron { } } -pub const DIVIDER: f64 = 1000000 as f64; +pub const DIVIDER: f64 = 1000000_f64; pub const NETWORK: &str = "TRON"; diff --git a/rust/apps/utils/src/lib.rs b/rust/apps/utils/src/lib.rs index 82a596a92..61334838b 100644 --- a/rust/apps/utils/src/lib.rs +++ b/rust/apps/utils/src/lib.rs @@ -8,14 +8,14 @@ pub use paste; use alloc::format; use alloc::string::String; -use unicode_blocks; + pub fn normalize_path(path: &String) -> String { let mut p = path.to_lowercase(); if !p.starts_with("m/") { p = format!("{}{}", "m/", p); } - if !p.starts_with("m") { + if !p.starts_with('m') { p = format!("{}{}", "m", p); } p @@ -27,7 +27,7 @@ pub fn is_cjk(utf8_string: &str) -> bool { return true; } } - return false; + false } #[cfg(test)] @@ -50,18 +50,18 @@ mod tests { fn test_is_cjk() { let utf8_string = "你好"; let result = is_cjk(utf8_string); - assert_eq!(result, true); + assert!(result); let utf8_string = "hello"; let result = is_cjk(utf8_string); - assert_eq!(result, false); + assert!(!result); let utf8_string = "こんにちは"; let result = is_cjk(utf8_string); - assert_eq!(result, true); + assert!(result); let utf8_string = "안녕하세요"; let result = is_cjk(utf8_string); - assert_eq!(result, true); + assert!(result); } } diff --git a/rust/apps/wallets/src/aptos.rs b/rust/apps/wallets/src/aptos.rs index 363eab39a..37d239531 100644 --- a/rust/apps/wallets/src/aptos.rs +++ b/rust/apps/wallets/src/aptos.rs @@ -11,7 +11,7 @@ pub fn generate_sync_ur( master_fingerprint: &[u8; 4], public_keys: BTreeMap, ) -> URResult { - generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, &"APT") + generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, "APT") } #[cfg(test)] diff --git a/rust/apps/wallets/src/backpack.rs b/rust/apps/wallets/src/backpack.rs index 769569190..c89fe9415 100644 --- a/rust/apps/wallets/src/backpack.rs +++ b/rust/apps/wallets/src/backpack.rs @@ -59,7 +59,7 @@ pub fn generate_crypto_multi_accounts( _ => { return Err(URError::UrEncodeError(format!( "Unknown key path: {}", - ele.path.to_string() + ele.path ))) } } @@ -83,8 +83,8 @@ fn generate_ed25519_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -114,8 +114,8 @@ fn generate_k1_normal_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -154,8 +154,8 @@ fn generate_eth_ledger_live_key( target_path .into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -207,23 +207,23 @@ mod tests { mfp, vec![ ExtendedPublicKey::new( - DerivationPath::from_str(&sol_pub_1_path).unwrap(), - hex::decode(&sol_pub_1).unwrap(), + DerivationPath::from_str(sol_pub_1_path).unwrap(), + hex::decode(sol_pub_1).unwrap(), ), ExtendedPublicKey::new( - DerivationPath::from_str(&sol_pub_2_path).unwrap(), - hex::decode(&sol_pub_2).unwrap(), + DerivationPath::from_str(sol_pub_2_path).unwrap(), + hex::decode(sol_pub_2).unwrap(), ), ExtendedPublicKey::new( - DerivationPath::from_str(ð_bip44_standard_xpub_path).unwrap(), - Xpub::from_str(ð_bip44_standard_xpub) + DerivationPath::from_str(eth_bip44_standard_xpub_path).unwrap(), + Xpub::from_str(eth_bip44_standard_xpub) .unwrap() .encode() .to_vec(), ), ExtendedPublicKey::new( - DerivationPath::from_str(ð_ledger_live_xpub_1_path).unwrap(), - Xpub::from_str(ð_ledger_live_xpub_1) + DerivationPath::from_str(eth_ledger_live_xpub_1_path).unwrap(), + Xpub::from_str(eth_ledger_live_xpub_1) .unwrap() .encode() .to_vec(), diff --git a/rust/apps/wallets/src/bitget.rs b/rust/apps/wallets/src/bitget.rs index 11d58091c..608e391a9 100644 --- a/rust/apps/wallets/src/bitget.rs +++ b/rust/apps/wallets/src/bitget.rs @@ -40,12 +40,10 @@ pub fn generate_crypto_multi_accounts( ) -> URResult { let device_id = get_device_id(serial_number); let mut keys = vec![]; - let k1_keys = vec![ - BTC_LEGACY_PREFIX.to_string(), + let k1_keys = [BTC_LEGACY_PREFIX.to_string(), BTC_SEGWIT_PREFIX.to_string(), BTC_NATIVE_SEGWIT_PREFIX.to_string(), - BTC_TAPROOT_PREFIX.to_string(), - ]; + BTC_TAPROOT_PREFIX.to_string()]; for ele in extended_public_keys { match ele.get_path() { _path if k1_keys.contains(&_path.to_string().to_lowercase()) => { @@ -93,7 +91,7 @@ pub fn generate_crypto_multi_accounts( _ => { return Err(URError::UrEncodeError(format!( "Unknown key path: {}", - ele.path.to_string() + ele.path ))) } } @@ -120,8 +118,8 @@ fn generate_k1_normal_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -174,8 +172,8 @@ fn generate_eth_ledger_live_key( target_path .into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -199,8 +197,8 @@ fn generate_ton_key(mfp: [u8; 4], key: ExtendedPublicKey) -> URResult get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -357,18 +355,18 @@ mod tests { mfp, "31206", vec![ - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_1_path).unwrap(), x_pub_1), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_2_path).unwrap(), x_pub_2), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_3_path).unwrap(), x_pub_3), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_4_path).unwrap(), x_pub_4), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_5_path).unwrap(), x_pub_5), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_6_path).unwrap(), x_pub_6), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_7_path).unwrap(), x_pub_7), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_8_path).unwrap(), x_pub_8), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_9_path).unwrap(), x_pub_9), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_10_path).unwrap(), x_pub_10), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_11_path).unwrap(), x_pub_11), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_12_path).unwrap(), x_pub_12), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_1_path).unwrap(), x_pub_1), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_2_path).unwrap(), x_pub_2), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_3_path).unwrap(), x_pub_3), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_4_path).unwrap(), x_pub_4), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_5_path).unwrap(), x_pub_5), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_6_path).unwrap(), x_pub_6), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_7_path).unwrap(), x_pub_7), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_8_path).unwrap(), x_pub_8), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_9_path).unwrap(), x_pub_9), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_10_path).unwrap(), x_pub_10), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_11_path).unwrap(), x_pub_11), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_12_path).unwrap(), x_pub_12), ], DEVICE_TYPE, "1.1.0", diff --git a/rust/apps/wallets/src/blue_wallet.rs b/rust/apps/wallets/src/blue_wallet.rs index 7e9d98435..8739fffc4 100644 --- a/rust/apps/wallets/src/blue_wallet.rs +++ b/rust/apps/wallets/src/blue_wallet.rs @@ -32,7 +32,7 @@ pub fn generate_crypto_account( )?); } - Ok(CryptoAccount::new(master_fingerprint.clone(), outputs)) + Ok(CryptoAccount::new(*master_fingerprint, outputs)) } fn get_path_level_number(path: &str, index: usize) -> Option { @@ -105,7 +105,7 @@ fn generate_crypto_hd_key( get_path_component(Some(coin_type), true)?, get_path_component(Some(0), true)?, ], - Some(master_fingerprint.clone()), + Some(*master_fingerprint), Some(bip32_extended_pub_key.depth as u32), ); @@ -133,7 +133,7 @@ fn generate_crypto_hd_key( } fn get_path_component(index: Option, hardened: bool) -> URResult { - PathComponent::new(index, hardened).map_err(|e| URError::CborEncodeError(e)) + PathComponent::new(index, hardened).map_err(URError::CborEncodeError) } #[cfg(test)] diff --git a/rust/apps/wallets/src/common.rs b/rust/apps/wallets/src/common.rs index 68df6e277..6e4c4cade 100644 --- a/rust/apps/wallets/src/common.rs +++ b/rust/apps/wallets/src/common.rs @@ -4,5 +4,5 @@ use ur_registry::{ }; pub fn get_path_component(index: Option, hardened: bool) -> URResult { - PathComponent::new(index, hardened).map_err(|e| URError::CborEncodeError(e)) + PathComponent::new(index, hardened).map_err(URError::CborEncodeError) } diff --git a/rust/apps/wallets/src/companion_app.rs b/rust/apps/wallets/src/companion_app.rs index a983d8320..a046e5eef 100644 --- a/rust/apps/wallets/src/companion_app.rs +++ b/rust/apps/wallets/src/companion_app.rs @@ -82,14 +82,14 @@ mod tests { use super::*; - const BTC_COIN_CODE: &'static str = "BTC"; - const BTC_PATH: &'static str = "M/49'/0'/0'"; + const BTC_COIN_CODE: &str = "BTC"; + const BTC_PATH: &str = "M/49'/0'/0'"; - const BTC_LEGACY_COIN_CODE: &'static str = "BTC_LEGACY"; - const BTC_LEGACY_PATH: &'static str = "M/44'/0'/0'"; + const BTC_LEGACY_COIN_CODE: &str = "BTC_LEGACY"; + const BTC_LEGACY_PATH: &str = "M/44'/0'/0'"; - const BTC_NATIVE_SEGWIT_COIN_CODE: &'static str = "BTC_NATIVE_SEGWIT"; - const BTC_NATIVE_SEGWIT_PATH: &'static str = "M/84'/0'/0'"; + const BTC_NATIVE_SEGWIT_COIN_CODE: &str = "BTC_NATIVE_SEGWIT"; + const BTC_NATIVE_SEGWIT_PATH: &str = "M/84'/0'/0'"; #[test] fn test_generate_crypto_account() { diff --git a/rust/apps/wallets/src/keplr/mod.rs b/rust/apps/wallets/src/keplr/mod.rs index b9fbd4d80..cba32a2c1 100644 --- a/rust/apps/wallets/src/keplr/mod.rs +++ b/rust/apps/wallets/src/keplr/mod.rs @@ -26,12 +26,12 @@ fn get_origin( ChildNumber::Hardened { index } => index, ChildNumber::Normal { index } => index, }; - PathComponent::new(Some(index.clone()), child_number.is_hardened()).unwrap() + PathComponent::new(Some(*index), child_number.is_hardened()).unwrap() }) .collect::>(); Ok(CryptoKeyPath::new( components, - Some(master_fingerprint.clone()), + Some(master_fingerprint), Some(depth), )) } @@ -40,9 +40,9 @@ pub fn generate_sync_ur( sync_infos: &Vec, ) -> URResult { let mut keys: Vec = Vec::new(); - sync_infos.into_iter().for_each(|sync_info| { + sync_infos.iter().for_each(|sync_info| { if let Ok(xpub) = bip32::Xpub::from_str(sync_info.xpub.as_str()) { - if let Ok(origin) = get_origin(sync_info, master_fingerprint.clone(), xpub.depth as u32) + if let Ok(origin) = get_origin(sync_info, *master_fingerprint, xpub.depth as u32) { let hd_key: CryptoHDKey = CryptoHDKey::new_extended_key( Some(false), @@ -60,7 +60,7 @@ pub fn generate_sync_ur( } }); Ok(CryptoMultiAccounts::new( - master_fingerprint.clone(), + *master_fingerprint, keys, Some(DEVICE_TYPE.to_string()), None, diff --git a/rust/apps/wallets/src/keystone.rs b/rust/apps/wallets/src/keystone.rs index e84954ef6..038ee3f16 100644 --- a/rust/apps/wallets/src/keystone.rs +++ b/rust/apps/wallets/src/keystone.rs @@ -92,7 +92,7 @@ pub fn generate_crypto_multi_accounts( _ => { return Err(URError::UrEncodeError(format!( "Unknown key path: {}", - ele.path.to_string() + ele.path ))) } } @@ -178,8 +178,8 @@ fn generate_k1_normal_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), diff --git a/rust/apps/wallets/src/metamask.rs b/rust/apps/wallets/src/metamask.rs index f31ed1bfa..bb0637bd4 100644 --- a/rust/apps/wallets/src/metamask.rs +++ b/rust/apps/wallets/src/metamask.rs @@ -47,7 +47,7 @@ pub fn generate_standard_legacy_hd_key( get_path_component(Some(ETH_COIN_TYPE), true)?, get_path_component(Some(0), true)?, ], - Some(master_fingerprint.clone()), + Some(*master_fingerprint), Some(bip32_extended_pub_key.depth as u32), ); @@ -92,7 +92,7 @@ pub fn generate_ledger_live_account( let output = generate_ledger_live_crypto_output(master_fingerprint, x.as_str(), i as u32)?; outputs.push(output); } - Ok(CryptoAccount::new(master_fingerprint.clone(), outputs)) + Ok(CryptoAccount::new(*master_fingerprint, outputs)) } fn generate_ledger_live_crypto_output( @@ -128,7 +128,7 @@ pub fn generate_ledger_live_hd_key( get_path_component(Some(0), false)?, get_path_component(Some(0), false)?, ], - Some(master_fingerprint.clone()), + Some(*master_fingerprint), Some(bip32_extended_pub_key.depth as u32), ); @@ -148,7 +148,7 @@ pub fn generate_ledger_live_hd_key( } fn get_path_component(index: Option, hardened: bool) -> URResult { - PathComponent::new(index, hardened).map_err(|e| URError::CborEncodeError(e)) + PathComponent::new(index, hardened).map_err(URError::CborEncodeError) } #[cfg(test)] diff --git a/rust/apps/wallets/src/okx.rs b/rust/apps/wallets/src/okx.rs index bacefd433..ad084f129 100644 --- a/rust/apps/wallets/src/okx.rs +++ b/rust/apps/wallets/src/okx.rs @@ -42,16 +42,14 @@ pub fn generate_crypto_multi_accounts( ) -> URResult { let device_id = get_device_id(serial_number); let mut keys = vec![]; - let k1_keys = vec![ - BTC_LEGACY_PREFIX.to_string(), + let k1_keys = [BTC_LEGACY_PREFIX.to_string(), BTC_SEGWIT_PREFIX.to_string(), BTC_NATIVE_SEGWIT_PREFIX.to_string(), BTC_TAPROOT_PREFIX.to_string(), TRX_PREFIX.to_string(), LTC_PREFIX.to_string(), BCH_PREFIX.to_string(), - DASH_PREFIX.to_string(), - ]; + DASH_PREFIX.to_string()]; for ele in extended_public_keys { match ele.get_path() { _path if k1_keys.contains(&_path.to_string().to_lowercase()) => { @@ -88,7 +86,7 @@ pub fn generate_crypto_multi_accounts( _ => { return Err(URError::UrEncodeError(format!( "Unknown key path: {}", - ele.path.to_string() + ele.path ))) } } @@ -114,8 +112,8 @@ fn generate_k1_normal_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -154,8 +152,8 @@ fn generate_eth_ledger_live_key( target_path .into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), diff --git a/rust/apps/wallets/src/solana.rs b/rust/apps/wallets/src/solana.rs index 346a9d761..5e58345b8 100644 --- a/rust/apps/wallets/src/solana.rs +++ b/rust/apps/wallets/src/solana.rs @@ -9,7 +9,7 @@ pub fn generate_sync_ur( master_fingerprint: &[u8; 4], public_keys: BTreeMap, ) -> URResult { - generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, &"SOL") + generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, "SOL") } #[cfg(test)] diff --git a/rust/apps/wallets/src/sui.rs b/rust/apps/wallets/src/sui.rs index 40005fa3f..1e80b0259 100644 --- a/rust/apps/wallets/src/sui.rs +++ b/rust/apps/wallets/src/sui.rs @@ -9,7 +9,7 @@ pub fn generate_sync_ur( master_fingerprint: &[u8; 4], public_keys: BTreeMap, ) -> URResult { - generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, &"SUI") + generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, "SUI") } #[cfg(test)] diff --git a/rust/apps/wallets/src/thor_wallet.rs b/rust/apps/wallets/src/thor_wallet.rs index 3898c8598..c09469c11 100644 --- a/rust/apps/wallets/src/thor_wallet.rs +++ b/rust/apps/wallets/src/thor_wallet.rs @@ -38,12 +38,10 @@ pub fn generate_crypto_multi_accounts( ) -> URResult { let device_id = get_device_id(serial_number); let mut keys = vec![]; - let k1_keys = vec![ - BTC_LEGACY_PREFIX.to_string(), + let k1_keys = [BTC_LEGACY_PREFIX.to_string(), BTC_SEGWIT_PREFIX.to_string(), BTC_NATIVE_SEGWIT_PREFIX.to_string(), - THORCHAIN_PREFIX.to_string(), - ]; + THORCHAIN_PREFIX.to_string()]; for ele in extended_public_keys { match ele.get_path() { _path if k1_keys.contains(&_path.to_string().to_lowercase()) => { @@ -80,7 +78,7 @@ pub fn generate_crypto_multi_accounts( _ => { return Err(URError::UrEncodeError(format!( "Unknown key path: {}", - ele.path.to_string() + ele.path ))) } } @@ -106,8 +104,8 @@ fn generate_k1_normal_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -146,8 +144,8 @@ fn generate_eth_ledger_live_key( target_path .into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), diff --git a/rust/apps/wallets/src/tonkeeper.rs b/rust/apps/wallets/src/tonkeeper.rs index e6667378a..21d9e76ef 100644 --- a/rust/apps/wallets/src/tonkeeper.rs +++ b/rust/apps/wallets/src/tonkeeper.rs @@ -19,7 +19,7 @@ pub fn generate_sync_ur( let key_path = info.path; let master_fingerprint = info.mfp; let crypto_key_path = CryptoKeyPath::from_path(key_path, Some(master_fingerprint)) - .map_err(|e| URError::UrEncodeError(e))?; + .map_err(URError::UrEncodeError)?; Ok(CryptoHDKey::new_extended_key( None, pubkey, diff --git a/rust/apps/wallets/src/utils.rs b/rust/apps/wallets/src/utils.rs index 1ef914172..1ce6e7d8b 100644 --- a/rust/apps/wallets/src/utils.rs +++ b/rust/apps/wallets/src/utils.rs @@ -2,7 +2,7 @@ use alloc::collections::BTreeMap; use alloc::string::{String, ToString}; use alloc::vec::Vec; use bitcoin::bip32::{ChildNumber, DerivationPath}; -use hex; + use ur_registry::crypto_hd_key::CryptoHDKey; use ur_registry::crypto_key_path::{CryptoKeyPath, PathComponent}; use ur_registry::error::{URError, URResult}; @@ -22,12 +22,12 @@ fn get_origin( ChildNumber::Hardened { index } => index, ChildNumber::Normal { index } => index, }; - PathComponent::new(Some(index.clone()), child_number.is_hardened()).unwrap() + PathComponent::new(Some(*index), child_number.is_hardened()).unwrap() }) .collect::>(); Ok(CryptoKeyPath::new( components, - Some(master_fingerprint.clone()), + Some(*master_fingerprint), Some(depth as u32), )) } @@ -59,7 +59,7 @@ pub fn generate_crypto_multi_accounts_sync_ur( } } Ok(CryptoMultiAccounts::new( - master_fingerprint.clone(), + *master_fingerprint, keys, Some(DEVICE_TYPE.to_string()), None, @@ -89,7 +89,7 @@ mod tests { let result = get_origin(&master_fingerprint, 2, path); assert!(result.is_ok()); let origin = result.unwrap(); - assert_eq!(origin.get_depth().unwrap(), 2 as u32); + assert_eq!(origin.get_depth().unwrap(), 2_u32); assert_eq!(origin.get_components().len(), 4); assert_eq!(origin.get_source_fingerprint().unwrap(), master_fingerprint); } diff --git a/rust/apps/wallets/src/xbull.rs b/rust/apps/wallets/src/xbull.rs index 6757cec3c..19a7da4e5 100644 --- a/rust/apps/wallets/src/xbull.rs +++ b/rust/apps/wallets/src/xbull.rs @@ -9,7 +9,7 @@ pub fn generate_sync_ur( master_fingerprint: &[u8; 4], public_keys: BTreeMap, ) -> URResult { - generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, &"STELLAR") + generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, "STELLAR") } #[cfg(test)] diff --git a/rust/apps/wallets/src/xrp_toolkit.rs b/rust/apps/wallets/src/xrp_toolkit.rs index a9f789429..903975cc7 100644 --- a/rust/apps/wallets/src/xrp_toolkit.rs +++ b/rust/apps/wallets/src/xrp_toolkit.rs @@ -8,7 +8,7 @@ use ur_registry::error::URError::UrEncodeError; use ur_registry::error::URResult; pub fn generate_sync_ur(hd_path: &str, root_x_pub: &str, root_path: &str) -> URResult { - let root_path = if !root_path.ends_with("/") { + let root_path = if !root_path.ends_with('/') { root_path.to_string() + "/" } else { root_path.to_string() @@ -25,7 +25,7 @@ pub fn generate_sync_ur(hd_path: &str, root_x_pub: &str, root_path: &str) -> URR let input_bytes = v.to_string().into_bytes(); return Ok(Bytes::new(input_bytes)); } - return Err(UrEncodeError("invalid data".to_string())); + Err(UrEncodeError("invalid data".to_string())) } #[cfg(test)] mod tests { diff --git a/rust/apps/xrp/src/address/mod.rs b/rust/apps/xrp/src/address/mod.rs index ca98cfbb2..a764dc055 100644 --- a/rust/apps/xrp/src/address/mod.rs +++ b/rust/apps/xrp/src/address/mod.rs @@ -8,7 +8,7 @@ pub(crate) mod ripple_address_codec; pub(crate) mod ripple_keypair; pub fn get_address(hd_path: &str, root_x_pub: &str, root_path: &str) -> R { - let root_path = if !root_path.ends_with("/") { + let root_path = if !root_path.ends_with('/') { root_path.to_string() + "/" } else { root_path.to_string() @@ -33,7 +33,7 @@ mod tests { let root_path = "44'/144'/0'"; { let path = "44'/144'/0'/0/0"; - let address = get_address(path, &extended_pub_key, root_path).unwrap(); + let address = get_address(path, extended_pub_key, root_path).unwrap(); assert_eq!("rHsMGQEkVNJmpGWs8XUBoTBiAAbwxZN5v3".to_string(), address); } { diff --git a/rust/apps/xrp/src/address/ripple_keypair.rs b/rust/apps/xrp/src/address/ripple_keypair.rs index ee5c22979..b0f8f4f70 100644 --- a/rust/apps/xrp/src/address/ripple_keypair.rs +++ b/rust/apps/xrp/src/address/ripple_keypair.rs @@ -7,7 +7,7 @@ use cryptoxide::hashing; use cryptoxide::ripemd160::Ripemd160; pub(crate) fn sha256_digest(data: &[u8]) -> Vec { - hashing::sha256(&data).to_vec() + hashing::sha256(data).to_vec() } fn ripemd160_digest(data: &[u8]) -> [u8; 20] { diff --git a/rust/apps/xrp/src/errors.rs b/rust/apps/xrp/src/errors.rs index 3af2ecc94..af46632c3 100644 --- a/rust/apps/xrp/src/errors.rs +++ b/rust/apps/xrp/src/errors.rs @@ -1,5 +1,5 @@ use alloc::format; -use alloc::string::{String, ToString}; +use alloc::string::{String}; use core::str::Utf8Error; use keystore::errors::KeystoreError; use serde_json::Error; @@ -24,7 +24,7 @@ pub type R = Result; impl From for XRPError { fn from(value: KeystoreError) -> Self { - Self::KeystoreError(format!("{}", value.to_string())) + Self::KeystoreError(format!("{}", value)) } } diff --git a/rust/apps/xrp/src/lib.rs b/rust/apps/xrp/src/lib.rs index bc6dd52b2..866bf0276 100644 --- a/rust/apps/xrp/src/lib.rs +++ b/rust/apps/xrp/src/lib.rs @@ -14,7 +14,7 @@ use core::str::FromStr; use bitcoin::bip32::{DerivationPath, Xpub}; use bitcoin::secp256k1; use bitcoin::secp256k1::Message; -use hex; + use serde_json::{from_slice, Value}; use crate::errors::{XRPError, R}; @@ -41,7 +41,7 @@ pub fn sign_tx(raw_hex: &[u8], hd_path: &String, seed: &[u8]) -> R> { )) })?; let (_, signature) = - keystore::algorithms::secp256k1::sign_message_by_seed(&seed, hd_path, &message) + keystore::algorithms::secp256k1::sign_message_by_seed(seed, hd_path, &message) .map_err(|e| XRPError::KeystoreError(format!("sign failed {:?}", e.to_string())))?; let signed_tx_str = wrapped_tx.generate_signed_tx(&signature)?; Ok(hex::decode(signed_tx_str)?.to_vec()) @@ -53,7 +53,7 @@ pub fn parse(raw_hex: &[u8]) -> R { } pub fn get_pubkey_path(root_xpub: &str, pubkey: &str, max_i: u32) -> R { - let xpub = Xpub::from_str(&root_xpub)?; + let xpub = Xpub::from_str(root_xpub)?; let k1 = secp256k1::Secp256k1::new(); let a_xpub = xpub.derive_pub(&k1, &DerivationPath::from_str("m/0")?)?; let pubkey_arr = hex::decode(pubkey)?; @@ -65,7 +65,7 @@ pub fn get_pubkey_path(root_xpub: &str, pubkey: &str, max_i: u32) -> R { return Ok(format!("{}:m/0/{}", pubkey, i)); } } - return Err(XRPError::InvalidData("pubkey not found".to_string())); + Err(XRPError::InvalidData("pubkey not found".to_string())) } pub fn check_tx(raw: &[u8], root_xpub: &str, cached_pubkey: &str) -> R { @@ -87,7 +87,7 @@ mod tests { let raw_hex = "7B2253657175656E6365223A312C22466565223A223230222C224163636F756E74223A22724C354259534C643839757A6A3469344A3437694C51673948776D65584537654374222C2244657374696E6174696F6E223A227248666F6631784E6245744A5973584E384D55626E66396946697843455938346B66222C2244657374696E6174696F6E546167223A313730303337333336342C22416D6F756E74223A2231303030303030222C225472616E73616374696F6E54797065223A225061796D656E74222C22466C616773223A323134373438333634382C225369676E696E675075624B6579223A22303331443638424331413134324536373636423242444642303036434346453133354546324530453245393441424235434635433941423631303437373646424145227D"; let seed = hex::decode("5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4").unwrap(); let signed_tx = sign_tx( - &hex::decode(raw_hex).unwrap().as_slice(), + hex::decode(raw_hex).unwrap().as_slice(), &hd_paths, seed.as_slice(), ) diff --git a/rust/apps/xrp/src/transaction/mod.rs b/rust/apps/xrp/src/transaction/mod.rs index b0ca599a7..a607e55db 100644 --- a/rust/apps/xrp/src/transaction/mod.rs +++ b/rust/apps/xrp/src/transaction/mod.rs @@ -4,8 +4,8 @@ use alloc::string::{String, ToString}; use bitcoin::secp256k1::ecdsa::Signature; use bytes::BytesMut; use cryptoxide::hashing; -use hex; -use rippled_binary_codec; + + use rippled_binary_codec::definition_fields::DefinitionFields; use serde_json::{from_slice, to_string, Value}; @@ -20,9 +20,9 @@ impl WrappedTxData { pub fn from_raw(input: &[u8]) -> R { let definition_fields = DefinitionFields::new(); let tx_data: Value = from_slice(input)?; - let signing_pubkey = tx_data["SigningPubKey"].as_str().unwrap_or(&"").to_string(); + let signing_pubkey = tx_data["SigningPubKey"].as_str().unwrap_or("").to_string(); if let Some(tag) = tx_data["DestinationTag"].as_i64() { - if tag > 0xffffffff || tag < 0 { + if !(0..=0xffffffff).contains(&tag) { return Err(XRPError::SignFailure(format!("invalid tag {:?}", tag))); } } @@ -106,7 +106,7 @@ mod tests { fn test_generate_unsigned_tx_3() { //xrp toolkit signrequest let input = "7B225472616E73616374696F6E54797065223A225061796D656E74222C22416D6F756E74223A223130303030303030222C2244657374696E6174696F6E223A2272396A79597745503472545278474341636857724C767742754A4646573853734D4A222C22466C616773223A323134373438333634382C224163636F756E74223A227247556D6B794C627671474633687758347177474864727A4C6459325170736B756D222C22466565223A223132222C2253657175656E6365223A37393939313835372C224C6173744C656467657253657175656E6365223A38303730373430342C225369676E696E675075624B6579223A22303346354335424231443139454337313044334437464144313939414631304346384243314431313334384535423337363543304230423943304245433332383739227D"; - let v: Value = from_slice(&hex::decode(input).unwrap().as_slice()).unwrap(); + let v: Value = from_slice(hex::decode(input).unwrap().as_slice()).unwrap(); let wrapped_tx = WrappedTxData::from_raw(v.to_string().into_bytes().as_slice()).unwrap(); let expected = String::from("88dfb47b27747e247bfaeade10c1cdecc64ca2298940cfe8e1b222971be8f41e"); diff --git a/rust/apps/zcash/src/lib.rs b/rust/apps/zcash/src/lib.rs index 3859cb402..484d10870 100644 --- a/rust/apps/zcash/src/lib.rs +++ b/rust/apps/zcash/src/lib.rs @@ -8,7 +8,6 @@ pub mod pczt; use errors::{Result, ZcashError}; use alloc::{ - format, string::{String, ToString}, vec::Vec, }; @@ -39,9 +38,9 @@ pub fn check_pczt( let ufvk = UnifiedFullViewingKey::decode(params, ufvk_text) .map_err(|e| ZcashError::InvalidDataError(e.to_string()))?; let pczt = - Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt(format!("invalid pczt data")))?; + Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt("invalid pczt data".to_string()))?; let account_index = zip32::AccountId::try_from(account_index) - .map_err(|_e| ZcashError::InvalidDataError(format!("invalid account index")))?; + .map_err(|_e| ZcashError::InvalidDataError("invalid account index".to_string()))?; pczt::check::check_pczt(params, seed_fingerprint, account_index, &ufvk, &pczt) } @@ -54,13 +53,13 @@ pub fn parse_pczt( let ufvk = UnifiedFullViewingKey::decode(params, ufvk_text) .map_err(|e| ZcashError::InvalidDataError(e.to_string()))?; let pczt = - Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt(format!("invalid pczt data")))?; + Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt("invalid pczt data".to_string()))?; pczt::parse::parse_pczt(params, seed_fingerprint, &ufvk, &pczt) } pub fn sign_pczt(pczt: &[u8], seed: &[u8]) -> Result> { let pczt = - Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt(format!("invalid pczt data")))?; + Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt("invalid pczt data".to_string()))?; pczt::sign::sign_pczt(pczt, seed) } diff --git a/rust/apps/zcash/src/pczt/check.rs b/rust/apps/zcash/src/pczt/check.rs index 9fef31fb3..95314b9e8 100644 --- a/rust/apps/zcash/src/pczt/check.rs +++ b/rust/apps/zcash/src/pczt/check.rs @@ -26,12 +26,12 @@ pub fn check_pczt( ))?; Verifier::new(pczt.clone()) .with_orchard(|bundle| { - check_orchard(params, &seed_fingerprint, account_index, &orchard, bundle) + check_orchard(params, seed_fingerprint, account_index, orchard, bundle) .map_err(pczt::roles::verifier::OrchardError::Custom) }) .map_err(|e| ZcashError::InvalidDataError(alloc::format!("{:?}", e)))? .with_transparent(|bundle| { - check_transparent(params, seed_fingerprint, account_index, &xpub, bundle) + check_transparent(params, seed_fingerprint, account_index, xpub, bundle) .map_err(pczt::roles::verifier::TransparentError::Custom) }) .map_err(|e| ZcashError::InvalidDataError(alloc::format!("{:?}", e)))?; @@ -75,7 +75,7 @@ fn check_transparent_input( match my_derivation { None => { //not my input, pass - return Ok(()); + Ok(()) } Some((pubkey, derivation)) => { // 2: derive my pubkey @@ -83,7 +83,7 @@ fn check_transparent_input( .derive_pubkey_at_bip32_path( params, account_index, - &derivation.derivation_path(), + derivation.derivation_path(), ) .map_err(|_| { ZcashError::InvalidPczt( @@ -207,7 +207,7 @@ fn check_transparent_output( match my_derivation { None => { //not my output, pass - return Ok(()); + Ok(()) } Some((pubkey, derivation)) => { // 2: derive my pubkey @@ -215,7 +215,7 @@ fn check_transparent_output( .derive_pubkey_at_bip32_path( params, account_index, - &derivation.derivation_path(), + derivation.derivation_path(), ) .map_err(|_| { ZcashError::InvalidPczt( @@ -287,7 +287,7 @@ fn check_action( seed_fingerprint, account_index, fvk, - &action.spend(), + action.spend(), )?; check_action_output(action) } @@ -379,7 +379,7 @@ mod tests { &pczt, ); - assert_eq!(true, result.is_ok()); + assert!(result.is_ok()); } } //TODO: add test for happy path diff --git a/rust/apps/zcash/src/pczt/parse.rs b/rust/apps/zcash/src/pczt/parse.rs index a8e0457de..aaae5d996 100644 --- a/rust/apps/zcash/src/pczt/parse.rs +++ b/rust/apps/zcash/src/pczt/parse.rs @@ -29,10 +29,10 @@ use crate::errors::ZcashError; use super::structs::{ParsedFrom, ParsedOrchard, ParsedPczt, ParsedTo, ParsedTransparent}; -const ZEC_DIVIDER: u32 = 1_000_000_00; +const ZEC_DIVIDER: u32 = 100_000_000; fn format_zec_value(value: f64) -> String { - let zec_value = format!("{:.8}", value as f64 / ZEC_DIVIDER as f64); + let zec_value = format!("{:.8}", value / ZEC_DIVIDER as f64); let zec_value = zec_value .trim_end_matches('0') .trim_end_matches('.') @@ -57,7 +57,7 @@ pub fn decode_output_enc_ciphertext( if let Some(ovk) = ovk { Ok(try_output_recovery_with_ovk( &domain, - &ovk, + ovk, action, action.cv_net(), &action.output().encrypted_note().out_ciphertext, @@ -122,7 +122,7 @@ pub fn parse_pczt( //total_input_value = total_output_value + fee_value //total_output_value = total_transfer_value + total_change_value - parsed_orchard.clone().and_then(|orchard| { + parsed_orchard.clone().map(|orchard| { total_change_value += orchard .get_to() .iter() @@ -136,10 +136,10 @@ pub fn parse_pczt( .get_to() .iter() .fold(0, |acc, to| acc + to.get_amount()); - Some(()) + }); - parsed_transparent.clone().and_then(|transparent| { + parsed_transparent.clone().map(|transparent| { total_change_value += transparent .get_to() .iter() @@ -153,7 +153,7 @@ pub fn parse_pczt( .get_to() .iter() .fold(0, |acc, to| acc + to.get_amount()); - Some(()) + }); //treat all sapling output as output value since we don't support sapling decoding yet @@ -169,7 +169,7 @@ pub fn parse_pczt( let sapling_value_sum: i64 = value_balance.into(); if sapling_value_sum < 0 { //value transfered to sapling pool - total_output_value = total_output_value.saturating_add(sapling_value_sum.abs() as u64) + total_output_value = total_output_value.saturating_add(sapling_value_sum.unsigned_abs()) } else { //value transfered from sapling pool //this should not happen with Zashi. @@ -179,7 +179,7 @@ pub fn parse_pczt( let total_transfer_value = format_zec_value((total_output_value - total_change_value) as f64); let fee_value = format_zec_value((total_input_value - total_output_value) as f64); - let has_sapling = pczt.sapling().spends().len() > 0 || pczt.sapling().outputs().len() > 0; + let has_sapling = !pczt.sapling().spends().is_empty() || !pczt.sapling().outputs().is_empty(); Ok(ParsedPczt::new( parsed_transparent, @@ -197,12 +197,12 @@ fn parse_transparent( ) -> Result, ZcashError> { let mut parsed_transparent = ParsedTransparent::new(vec![], vec![]); transparent.inputs().iter().try_for_each(|input| { - let parsed_from = parse_transparent_input(params, seed_fingerprint, &input)?; + let parsed_from = parse_transparent_input(params, seed_fingerprint, input)?; parsed_transparent.add_from(parsed_from); Ok::<_, ZcashError>(()) })?; transparent.outputs().iter().try_for_each(|output| { - let parsed_to = parse_transparent_output(seed_fingerprint, &output)?; + let parsed_to = parse_transparent_output(seed_fingerprint, output)?; parsed_transparent.add_to(parsed_to); Ok::<_, ZcashError>(()) })?; @@ -247,9 +247,9 @@ fn parse_transparent_input( )) } _ => { - return Err(ZcashError::InvalidPczt( + Err(ZcashError::InvalidPczt( "transparent input script pubkey mismatch".to_string(), - )); + )) } } } @@ -311,9 +311,9 @@ fn parse_transparent_output( )) } _ => { - return Err(ZcashError::InvalidPczt( + Err(ZcashError::InvalidPczt( "transparent output script pubkey mismatch".to_string(), - )); + )) } } } @@ -331,11 +331,11 @@ fn parse_orchard( if let Some(value) = spend.value() { //only adds non-dummy spend if value.inner() != 0 { - let parsed_from = parse_orchard_spend(seed_fingerprint, &spend)?; + let parsed_from = parse_orchard_spend(seed_fingerprint, spend)?; parsed_orchard.add_from(parsed_from); } } - let parsed_to = parse_orchard_output(params, ufvk, &action)?; + let parsed_to = parse_orchard_output(params, ufvk, action)?; if !parsed_to.get_is_dummy() { parsed_orchard.add_to(parsed_to); } @@ -561,7 +561,7 @@ mod tests { use zcash_vendor::zcash_protocol::consensus::MAIN_NETWORK; extern crate std; - use std::println; + #[test] fn test_format_zec_value() { @@ -601,7 +601,7 @@ mod tests { let result = parse_pczt(&MAIN_NETWORK, &fingerprint, &unified_fvk, &pczt); assert!(result.is_ok()); let result = result.unwrap(); - assert_eq!(result.get_has_sapling(), false); + assert!(!result.get_has_sapling()); assert_eq!(result.get_total_transfer_value(), "0.001 ZEC"); assert_eq!(result.get_fee_value(), "0.00015 ZEC"); let transparent = result.get_transparent(); @@ -614,8 +614,8 @@ mod tests { "t1XTwB8P1x4YipBtLhPWS13JPDQ5RMkMA6M" ); assert_eq!(transparent.get_to()[0].get_value(), "0.001 ZEC"); - assert_eq!(transparent.get_to()[0].get_is_change(), false); - assert_eq!(transparent.get_to()[0].get_is_dummy(), false); + assert!(!transparent.get_to()[0].get_is_change()); + assert!(!transparent.get_to()[0].get_is_dummy()); assert_eq!(transparent.get_to()[0].get_amount(), 100_000); let orchard = result.get_orchard(); assert!(orchard.is_some()); @@ -623,14 +623,14 @@ mod tests { assert_eq!(orchard.get_from().len(), 1); assert_eq!(orchard.get_from()[0].get_address(), None); assert_eq!(orchard.get_from()[0].get_value(), "0.14985 ZEC"); - assert_eq!(orchard.get_from()[0].get_is_mine(), true); + assert!(orchard.get_from()[0].get_is_mine()); assert_eq!(orchard.get_from()[0].get_amount(), 14985000); assert_eq!(orchard.get_to().len(), 1); assert_eq!(orchard.get_to()[0].get_address(), ""); assert_eq!(orchard.get_to()[0].get_value(), "0.1487 ZEC"); assert_eq!(orchard.get_to()[0].get_memo(), None); - assert_eq!(orchard.get_to()[0].get_is_change(), true); - assert_eq!(orchard.get_to()[0].get_is_dummy(), false); + assert!(orchard.get_to()[0].get_is_change()); + assert!(!orchard.get_to()[0].get_is_dummy()); assert_eq!(orchard.get_to()[0].get_amount(), 14870000); } @@ -649,7 +649,7 @@ mod tests { let result = parse_pczt(&MAIN_NETWORK, &fingerprint, &unified_fvk, &pczt); assert!(result.is_ok()); let result = result.unwrap(); - assert_eq!(result.get_has_sapling(), true); + assert!(result.get_has_sapling()); assert_eq!(result.get_total_transfer_value(), "0.001 ZEC"); assert_eq!(result.get_fee_value(), "0.0002 ZEC"); } diff --git a/rust/apps/zcash/src/pczt/sign.rs b/rust/apps/zcash/src/pczt/sign.rs index 9a7778c6b..3aa17804a 100644 --- a/rust/apps/zcash/src/pczt/sign.rs +++ b/rust/apps/zcash/src/pczt/sign.rs @@ -24,7 +24,7 @@ impl<'a> PcztSigner for SeedSigner<'a> { where F: FnOnce(SignableInput) -> [u8; 32], { - let fingerprint = calculate_seed_fingerprint(&self.seed) + let fingerprint = calculate_seed_fingerprint(self.seed) .map_err(|e| ZcashError::SigningError(e.to_string()))?; let key_path = input.bip32_derivation(); @@ -32,7 +32,7 @@ impl<'a> PcztSigner for SeedSigner<'a> { let path = key_path .iter() .find_map(|(pubkey, path)| { - let path_fingerprint = path.seed_fingerprint().clone(); + let path_fingerprint = *path.seed_fingerprint(); if fingerprint == path_fingerprint { let path = { let mut ret = "m".to_string(); @@ -45,7 +45,7 @@ impl<'a> PcztSigner for SeedSigner<'a> { } ret }; - match get_public_key_by_seed(&self.seed, &path) { + match get_public_key_by_seed(self.seed, &path) { Ok(my_pubkey) if my_pubkey.serialize().to_vec().eq(pubkey) => { Some(Ok(path)) } @@ -77,7 +77,7 @@ impl<'a> PcztSigner for SeedSigner<'a> { action: &mut orchard::pczt::Action, hash: Hash, ) -> Result<(), Self::Error> { - let fingerprint = calculate_seed_fingerprint(&self.seed) + let fingerprint = calculate_seed_fingerprint(self.seed) .map_err(|e| ZcashError::SigningError(e.to_string()))?; let derivation = action.spend().zip32_derivation().as_ref().ok_or_else(|| { @@ -87,7 +87,7 @@ impl<'a> PcztSigner for SeedSigner<'a> { if &fingerprint == derivation.seed_fingerprint() { sign_message_orchard( action, - &self.seed, + self.seed, hash.as_bytes().try_into().expect("correct length"), &derivation.derivation_path().clone(), OsRng, diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index 922b3c625..ecf326adc 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -17,7 +17,7 @@ fn main() { #[cfg(feature = "debug-btc-only")] "debug-btc-only", ]; - assert!(features.len() > 0, "No build variant enabled"); + assert!(!features.is_empty(), "No build variant enabled"); assert!( features.len() == 1, "Multiple build variants enabled: {:?}", diff --git a/rust/rust_c/src/aptos/mod.rs b/rust/rust_c/src/aptos/mod.rs index d2ee3e8e9..1ac7f84e7 100644 --- a/rust/rust_c/src/aptos/mod.rs +++ b/rust/rust_c/src/aptos/mod.rs @@ -8,11 +8,11 @@ use alloc::format; use alloc::slice; use alloc::string::ToString; use alloc::vec::Vec; -use app_aptos; + use app_aptos::errors::AptosError; use app_aptos::parser::is_tx; use cty::c_char; -use hex; + use hex::FromHex; use structs::DisplayAptosTx; use ur_registry::aptos::aptos_sign_request::{AptosSignRequest, SignType}; @@ -132,7 +132,7 @@ pub extern "C" fn aptos_sign_tx( UREncodeResult::encode( data, AptosSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, @@ -148,7 +148,7 @@ pub extern "C" fn aptos_get_path(ptr: PtrUR) -> PtrString { if let Some(path) = derivation_path.get_path() { return convert_c_char(path); } - return convert_c_char("".to_string()); + convert_c_char("".to_string()) } #[no_mangle] diff --git a/rust/rust_c/src/arweave/mod.rs b/rust/rust_c/src/arweave/mod.rs index 906ae6aea..ff1fc728b 100644 --- a/rust/rust_c/src/arweave/mod.rs +++ b/rust/rust_c/src/arweave/mod.rs @@ -19,10 +19,10 @@ use app_arweave::{ generate_public_key_from_primes, generate_secret, parse, }; use cty::c_char; -use hex; + use keystore::algorithms::ed25519::slip10_ed25519::get_private_key_by_seed; use keystore::algorithms::rsa::{sign_message, SigningOption}; -use serde_json; + use serde_json::Value; use ur_registry::arweave::arweave_sign_request::{ArweaveSignRequest, SaltLen, SignType}; use ur_registry::arweave::arweave_signature::ArweaveSignature; @@ -65,7 +65,7 @@ pub extern "C" fn generate_arweave_public_key_from_primes( let p = unsafe { slice::from_raw_parts(p, p_len as usize) }; let q = unsafe { slice::from_raw_parts(q, q_len as usize) }; let public = generate_public_key_from_primes(p, q).unwrap(); - return SimpleResponse::success(Box::into_raw(Box::new(public)) as *mut u8).simple_c_ptr(); + SimpleResponse::success(Box::into_raw(Box::new(public)) as *mut u8).simple_c_ptr() } #[no_mangle] @@ -78,7 +78,7 @@ pub extern "C" fn generate_rsa_public_key( let p = unsafe { slice::from_raw_parts(p, p_len as usize) }; let q = unsafe { slice::from_raw_parts(q, q_len as usize) }; let public = generate_public_key_from_primes(p, q).unwrap(); - return SimpleResponse::success(convert_c_char(hex::encode(public))).simple_c_ptr(); + SimpleResponse::success(convert_c_char(hex::encode(public))).simple_c_ptr() } #[no_mangle] @@ -93,8 +93,8 @@ pub extern "C" fn aes256_encrypt_primes( let encrypted_data = aes256_encrypt(&key, &iv, data).unwrap(); let mut result_bytes: [u8; 528] = [0; 528]; result_bytes.copy_from_slice(&encrypted_data); - return SimpleResponse::success(Box::into_raw(Box::new(result_bytes)) as *mut u8) - .simple_c_ptr(); + SimpleResponse::success(Box::into_raw(Box::new(result_bytes)) as *mut u8) + .simple_c_ptr() } #[no_mangle] @@ -124,14 +124,14 @@ pub extern "C" fn aes256_decrypt_primes( pub extern "C" fn arweave_get_address(xpub: PtrString) -> *mut SimpleResponse { let xpub = recover_c_char(xpub); let address = app_arweave::generate_address(hex::decode(xpub).unwrap()).unwrap(); - return SimpleResponse::success(convert_c_char(address)).simple_c_ptr(); + SimpleResponse::success(convert_c_char(address)).simple_c_ptr() } #[no_mangle] pub extern "C" fn fix_arweave_address(address: PtrString) -> *mut SimpleResponse { let address = recover_c_char(address); let fixed_address = fix_address(&address); - return SimpleResponse::success(convert_c_char(fixed_address)).simple_c_ptr(); + SimpleResponse::success(convert_c_char(fixed_address)).simple_c_ptr() } #[no_mangle] @@ -154,7 +154,7 @@ pub extern "C" fn ar_check_tx( return TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr(); } } - return TransactionCheckResult::from(RustCError::InvalidMasterFingerprint).c_ptr(); + TransactionCheckResult::from(RustCError::InvalidMasterFingerprint).c_ptr() } #[no_mangle] @@ -235,7 +235,7 @@ fn parse_sign_data(ptr: PtrUR) -> Result, ArweaveError> { Ok(data_item.deep_hash()?) } SignType::Message => { - return Ok(sign_data); + Ok(sign_data) } } } @@ -282,7 +282,7 @@ pub extern "C" fn ar_sign_tx( UREncodeResult::encode( data, ArweaveSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, diff --git a/rust/rust_c/src/bitcoin/msg.rs b/rust/rust_c/src/bitcoin/msg.rs index 547cf0bfc..9fdb538ae 100644 --- a/rust/rust_c/src/bitcoin/msg.rs +++ b/rust/rust_c/src/bitcoin/msg.rs @@ -73,11 +73,10 @@ pub extern "C" fn btc_parse_msg( .iter() .find(|key| { let xpub_path = recover_c_char(key.path); - return path.clone().starts_with(&xpub_path); + path.clone().starts_with(&xpub_path) }) .map(|v| recover_c_char(v.xpub)) - .map(|xpub| app_bitcoin::get_address(path, &xpub).ok()) - .flatten(); + .and_then(|xpub| app_bitcoin::get_address(path, &xpub).ok()); let msg = req.get_sign_data(); if let Ok(msg_uft8) = String::from_utf8(msg.to_vec()) { let display_msg = DisplayBtcMsg { @@ -133,7 +132,7 @@ pub extern "C" fn btc_sign_msg( return UREncodeResult::encode( data, BtcSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(); } @@ -165,7 +164,7 @@ pub extern "C" fn parse_seed_signer_message( .iter() .find(|key| { let xpub_path = recover_c_char(key.path); - return path.clone().starts_with(&xpub_path); + path.clone().starts_with(&xpub_path) }) .map(|v| recover_c_char(v.xpub)) .map(|xpub| app_bitcoin::get_address(path, &xpub)); @@ -204,9 +203,9 @@ pub extern "C" fn sign_seed_signer_message( let sig = app_bitcoin::sign_msg(&message, seed, &path); match sig { Ok(sig) => { - return UREncodeResult::text(base64::encode_config(&sig, base64::STANDARD)).c_ptr() + UREncodeResult::text(base64::encode_config(&sig, base64::STANDARD)).c_ptr() } - Err(e) => return UREncodeResult::from(e).c_ptr(), + Err(e) => UREncodeResult::from(e).c_ptr(), } } } diff --git a/rust/rust_c/src/bitcoin/multi_sig/mod.rs b/rust/rust_c/src/bitcoin/multi_sig/mod.rs index e29a6de58..e1648ebbb 100644 --- a/rust/rust_c/src/bitcoin/multi_sig/mod.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/mod.rs @@ -89,7 +89,7 @@ pub extern "C" fn export_multi_sig_xpub_by_ur( Ok(data) => UREncodeResult::encode( data, CryptoAccount::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -115,7 +115,7 @@ pub extern "C" fn export_multi_sig_wallet_by_ur_test( unsafe { let master_fingerprint = slice::from_raw_parts(master_fingerprint, length as usize); let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -138,7 +138,7 @@ pub extern "C" fn export_multi_sig_wallet_by_ur_test( UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, @@ -197,7 +197,7 @@ pub extern "C" fn export_multi_sig_wallet_by_ur( unsafe { let master_fingerprint = slice::from_raw_parts(master_fingerprint, length as usize); let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -225,7 +225,7 @@ pub extern "C" fn export_multi_sig_wallet_by_ur( UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, @@ -246,7 +246,7 @@ pub extern "C" fn import_multi_sig_wallet_by_ur( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -278,7 +278,7 @@ pub extern "C" fn import_multi_sig_wallet_by_file( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -311,7 +311,7 @@ pub extern "C" fn generate_address_for_multisig_wallet_config( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -371,7 +371,7 @@ pub extern "C" fn parse_and_verify_multisig_config( let seed = unsafe { core::slice::from_raw_parts(seed, seed_len as usize) }; let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { diff --git a/rust/rust_c/src/bitcoin/multi_sig/structs.rs b/rust/rust_c/src/bitcoin/multi_sig/structs.rs index 444d3f3f6..2932ea44f 100644 --- a/rust/rust_c/src/bitcoin/multi_sig/structs.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/structs.rs @@ -18,18 +18,18 @@ pub enum NetworkType { TestNet, } -impl Into for NetworkType { - fn into(self) -> Network { - match self { +impl From for Network { + fn from(val: NetworkType) -> Self { + match val { NetworkType::MainNet => Network::MainNet, NetworkType::TestNet => Network::TestNet, } } } -impl Into for &NetworkType { - fn into(self) -> Network { - match self { +impl From<&NetworkType> for Network { + fn from(val: &NetworkType) -> Self { + match val { NetworkType::MainNet => Network::MainNet, NetworkType::TestNet => Network::TestNet, } @@ -46,9 +46,9 @@ pub enum MultiSigFormatType { P2wshTest, } -impl Into for MultiSigFormatType { - fn into(self) -> MultiSigType { - match self { +impl From for MultiSigType { + fn from(val: MultiSigFormatType) -> Self { + match val { MultiSigFormatType::P2sh => MultiSigType::P2sh, MultiSigFormatType::P2wshP2sh => MultiSigType::P2wshP2sh, MultiSigFormatType::P2wsh => MultiSigType::P2wsh, @@ -59,9 +59,9 @@ impl Into for MultiSigFormatType { } } -impl Into for &MultiSigFormatType { - fn into(self) -> MultiSigType { - match self { +impl From<&MultiSigFormatType> for MultiSigType { + fn from(val: &MultiSigFormatType) -> Self { + match val { MultiSigFormatType::P2sh => MultiSigType::P2sh, MultiSigFormatType::P2wshP2sh => MultiSigType::P2wshP2sh, MultiSigFormatType::P2wsh => MultiSigType::P2wsh, @@ -72,9 +72,9 @@ impl Into for &MultiSigFormatType { } } -impl Into for MultiSigFormatType { - fn into(self) -> MultiSigFormat { - match self { +impl From for MultiSigFormat { + fn from(val: MultiSigFormatType) -> Self { + match val { MultiSigFormatType::P2sh => MultiSigFormat::P2sh, MultiSigFormatType::P2wshP2sh => MultiSigFormat::P2wshP2sh, MultiSigFormatType::P2wsh => MultiSigFormat::P2wsh, @@ -85,9 +85,9 @@ impl Into for MultiSigFormatType { } } -impl Into for &MultiSigFormatType { - fn into(self) -> MultiSigFormat { - match self { +impl From<&MultiSigFormatType> for MultiSigFormat { + fn from(val: &MultiSigFormatType) -> Self { + match val { MultiSigFormatType::P2sh => MultiSigFormat::P2sh, MultiSigFormatType::P2wshP2sh => MultiSigFormat::P2wshP2sh, MultiSigFormatType::P2wsh => MultiSigFormat::P2wsh, @@ -115,12 +115,12 @@ impl From for MultiSigXPubInfoItem { } } -impl Into for &MultiSigXPubInfoItem { - fn into(self) -> MultiSigXPubInfo { +impl From<&MultiSigXPubInfoItem> for MultiSigXPubInfo { + fn from(val: &MultiSigXPubInfoItem) -> Self { MultiSigXPubInfo { - path: recover_c_char(self.path), - xfp: recover_c_char(self.xfp), - xpub: recover_c_char(self.xpub), + path: recover_c_char(val.path), + xfp: recover_c_char(val.xfp), + xpub: recover_c_char(val.xpub), } } } @@ -135,13 +135,13 @@ impl From for MultiSigXPubInfoItem { } } -impl Into for &MultiSigXPubInfoItem { - fn into(self) -> BsmsWallet { +impl From<&MultiSigXPubInfoItem> for BsmsWallet { + fn from(val: &MultiSigXPubInfoItem) -> Self { BsmsWallet { bsms_version: "BSMS 1.0".to_string(), - derivation_path: recover_c_char(self.path), - xfp: recover_c_char(self.xfp), - extended_pubkey: recover_c_char(self.xpub), + derivation_path: recover_c_char(val.path), + xfp: recover_c_char(val.xfp), + extended_pubkey: recover_c_char(val.xpub), } } } @@ -172,11 +172,11 @@ impl From<&app_bitcoin::multi_sig::wallet::MultiSigXPubItem> for MultiSigXPubIte } } -impl Into for &MultiSigXPubItem { - fn into(self) -> app_bitcoin::multi_sig::wallet::MultiSigXPubItem { +impl From<&MultiSigXPubItem> for app_bitcoin::multi_sig::wallet::MultiSigXPubItem { + fn from(val: &MultiSigXPubItem) -> Self { app_bitcoin::multi_sig::wallet::MultiSigXPubItem { - xfp: recover_c_char(self.xfp), - xpub: recover_c_char(self.xpub), + xfp: recover_c_char(val.xfp), + xpub: recover_c_char(val.xpub), } } } @@ -228,7 +228,7 @@ impl From for MultiSigWallet { .xpub_items .clone() .iter() - .map(|v| MultiSigXPubItem::from(v)) + .map(MultiSigXPubItem::from) .collect::>(), ) .c_ptr(), @@ -239,18 +239,18 @@ impl From for MultiSigWallet { } } -impl Into for &mut MultiSigWallet { - fn into(self) -> MultiSigWalletConfig { +impl From<&mut MultiSigWallet> for MultiSigWalletConfig { + fn from(val: &mut MultiSigWallet) -> Self { MultiSigWalletConfig { - creator: recover_c_char(self.creator), - name: recover_c_char(self.name), - threshold: self.threshold, - total: self.total, + creator: recover_c_char(val.creator), + name: recover_c_char(val.name), + threshold: val.threshold, + total: val.total, derivations: { let rebuilt = unsafe { - let ptr = (*self.derivations).data; - let size = (*self.derivations).size; - let cap = (*self.derivations).cap; + let ptr = (*val.derivations).data; + let size = (*val.derivations).size; + let cap = (*val.derivations).cap; let ptr = ptr as PtrT; Vec::from_raw_parts(ptr, size, cap) @@ -261,22 +261,22 @@ impl Into for &mut MultiSigWallet { .map(|v| recover_c_char(*v)) .collect::>() }, - format: recover_c_char(self.format), + format: recover_c_char(val.format), xpub_items: { let rebuilt = unsafe { - let ptr = (*self.derivations).data; - let size = (*self.derivations).size; - let cap = (*self.derivations).cap; + let ptr = (*val.derivations).data; + let size = (*val.derivations).size; + let cap = (*val.derivations).cap; let ptr = ptr as PtrT; Vec::from_raw_parts(ptr, size, cap) }; rebuilt.iter().map(|v| v.into()).collect::>() }, - verify_code: recover_c_char(self.verify_code), - config_text: recover_c_char(self.config_text), - network: if self.network == 0 { + verify_code: recover_c_char(val.verify_code), + config_text: recover_c_char(val.config_text), + network: if val.network == 0 { Network::MainNet } else { Network::TestNet diff --git a/rust/rust_c/src/bitcoin/psbt.rs b/rust/rust_c/src/bitcoin/psbt.rs index 41abaaa7b..f716da368 100644 --- a/rust/rust_c/src/bitcoin/psbt.rs +++ b/rust/rust_c/src/bitcoin/psbt.rs @@ -66,7 +66,7 @@ fn btc_sign_psbt_dynamic( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -87,7 +87,7 @@ fn btc_sign_psbt_dynamic( Ok(data) => UREncodeResult::encode( data, CryptoPSBT::get_registry_type().get_type(), - fragment_length.clone(), + fragment_length, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -110,7 +110,7 @@ pub extern "C" fn btc_sign_psbt( seed_len, master_fingerprint, master_fingerprint_len, - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) } @@ -128,7 +128,7 @@ pub extern "C" fn btc_sign_psbt_unlimited( seed_len, master_fingerprint, master_fingerprint_len, - FRAGMENT_UNLIMITED_LENGTH.clone(), + FRAGMENT_UNLIMITED_LENGTH, ) } @@ -152,7 +152,7 @@ pub extern "C" fn btc_sign_multisig_psbt( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -189,7 +189,7 @@ pub extern "C" fn btc_sign_multisig_psbt( ur_result: UREncodeResult::encode( data, CryptoPSBT::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), sign_status: convert_c_char(sign_state.sign_status.unwrap_or("".to_string())), @@ -231,7 +231,7 @@ pub extern "C" fn btc_export_multisig_psbt(ptr: PtrUR) -> *mut MultisigSignResul ur_result: UREncodeResult::encode( psbt, CryptoPSBT::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), sign_status: convert_c_char(state.sign_status.unwrap_or("".to_string())), @@ -268,7 +268,7 @@ pub extern "C" fn btc_export_multisig_psbt_bytes( ur_result: UREncodeResult::encode( psbt, CryptoPSBT::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), sign_status: convert_c_char(state.sign_status.unwrap_or("".to_string())), @@ -409,7 +409,7 @@ pub extern "C" fn btc_sign_multisig_psbt_bytes( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -428,7 +428,8 @@ pub extern "C" fn btc_sign_multisig_psbt_bytes( let psbt = unsafe { let psbt = core::slice::from_raw_parts(psbt_bytes, psbt_bytes_length as usize); - let psbt = match get_psbt_bytes(psbt) { + + match get_psbt_bytes(psbt) { Ok(psbt) => psbt, Err(e) => { return MultisigSignResult { @@ -440,8 +441,7 @@ pub extern "C" fn btc_sign_multisig_psbt_bytes( } .c_ptr() } - }; - psbt + } }; let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; @@ -461,7 +461,7 @@ pub extern "C" fn btc_sign_multisig_psbt_bytes( ur_result: UREncodeResult::encode( data, CryptoPSBT::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), sign_status: convert_c_char(sign_state.sign_status.unwrap_or("".to_string())), @@ -498,7 +498,7 @@ fn parse_psbt( multisig_wallet_config: Option, ) -> *mut TransactionParseResult { let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -510,7 +510,7 @@ fn parse_psbt( Xpub::from_str(xpub.as_str()).map_err(|_e| RustCError::InvalidXPub); let derivation_path = DerivationPath::from_str(path.as_str()).map_err(|_e| RustCError::InvalidHDPath); - match extended_public_key.and_then(|k| derivation_path.and_then(|p| Ok((k, p)))) { + match extended_public_key.and_then(|k| derivation_path.map(|p| (k, p))) { Ok((k, p)) => { keys.insert(p, k); } @@ -548,7 +548,7 @@ fn check_psbt( multisig_wallet_config: Option, ) -> PtrT { let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -560,7 +560,7 @@ fn check_psbt( Xpub::from_str(xpub.as_str()).map_err(|_e| RustCError::InvalidXPub); let derivation_path = DerivationPath::from_str(path.as_str()).map_err(|_e| RustCError::InvalidHDPath); - match extended_public_key.and_then(|k| derivation_path.and_then(|p| Ok((k, p)))) { + match extended_public_key.and_then(|k| derivation_path.map(|p| (k, p))) { Ok((k, p)) => { keys.insert(p, k); } diff --git a/rust/rust_c/src/bitcoin/structs.rs b/rust/rust_c/src/bitcoin/structs.rs index b99c31bf8..1bc314d70 100644 --- a/rust/rust_c/src/bitcoin/structs.rs +++ b/rust/rust_c/src/bitcoin/structs.rs @@ -203,11 +203,11 @@ impl From for DisplayTxDetailInput { has_address: value.address.is_some(), address: value .address - .map(|v| convert_c_char(v)) + .map(convert_c_char) .unwrap_or(null_mut()), amount: convert_c_char(value.amount), is_mine: value.path.is_some(), - path: value.path.map(|v| convert_c_char(v)).unwrap_or(null_mut()), + path: value.path.map(convert_c_char).unwrap_or(null_mut()), is_external: value.is_external, } } @@ -219,7 +219,7 @@ impl From for DisplayTxDetailOutput { address: convert_c_char(value.address), amount: convert_c_char(value.amount), is_mine: value.path.is_some(), - path: value.path.map(|v| convert_c_char(v)).unwrap_or(null_mut()), + path: value.path.map(convert_c_char).unwrap_or(null_mut()), is_external: value.is_external, } } diff --git a/rust/rust_c/src/cardano/mod.rs b/rust/rust_c/src/cardano/mod.rs index 7d1058ad5..dc5a1e9e0 100644 --- a/rust/rust_c/src/cardano/mod.rs +++ b/rust/rust_c/src/cardano/mod.rs @@ -14,7 +14,7 @@ use bitcoin::bip32::DerivationPath; use core::str::FromStr; use cty::c_char; use ed25519_bip32_core::XPrv; -use hex; + use structs::DisplayCardanoSignTxHash; use ur_registry::cardano::cardano_catalyst_signature::CardanoCatalystSignature; @@ -109,7 +109,7 @@ pub extern "C" fn cardano_get_catalyst_root_index(ptr: PtrUR) -> Ptr SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid path"))) + None => SimpleResponse::from(CardanoError::InvalidTransaction("invalid path".to_string())) .simple_c_ptr(), } } @@ -123,7 +123,7 @@ pub extern "C" fn cardano_get_sign_data_root_index(ptr: PtrUR) -> Ptr SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid path"))) + None => SimpleResponse::from(CardanoError::InvalidTransaction("invalid path".to_string())) .simple_c_ptr(), } } @@ -187,7 +187,7 @@ pub extern "C" fn cardano_check_tx( let cardano_sign_reqeust = extract_ptr_with_type!(ptr, CardanoSignRequest); let tx_hex = cardano_sign_reqeust.get_sign_data(); let parse_context = - prepare_parse_context(&cardano_sign_reqeust, master_fingerprint, cardano_xpub); + prepare_parse_context(cardano_sign_reqeust, master_fingerprint, cardano_xpub); match parse_context { Ok(parse_context) => match app_cardano::transaction::check_tx(tx_hex, parse_context) { Ok(_) => TransactionCheckResult::new().c_ptr(), @@ -237,7 +237,7 @@ pub extern "C" fn cardano_parse_sign_tx_hash( #[no_mangle] pub extern "C" fn cardano_get_path(ptr: PtrUR) -> Ptr> { let cardano_sign_reqeust = extract_ptr_with_type!(ptr, CardanoSignRequest); - match cardano_sign_reqeust.get_cert_keys().get(0) { + match cardano_sign_reqeust.get_cert_keys().first() { Some(_data) => match _data.get_key_path().get_path() { Some(_path) => { if let Some(path) = parse_cardano_root_path(_path) { @@ -248,19 +248,19 @@ pub extern "C" fn cardano_get_path(ptr: PtrUR) -> Ptr> { }, None => {} }; - match cardano_sign_reqeust.get_utxos().get(0) { + match cardano_sign_reqeust.get_utxos().first() { Some(_data) => match _data.get_key_path().get_path() { Some(_path) => { if let Some(path) = parse_cardano_root_path(_path) { return SimpleResponse::success(convert_c_char(path)).simple_c_ptr(); } - SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid utxo"))) + SimpleResponse::from(CardanoError::InvalidTransaction("invalid utxo".to_string())) .simple_c_ptr() } - None => SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid utxo"))) + None => SimpleResponse::from(CardanoError::InvalidTransaction("invalid utxo".to_string())) .simple_c_ptr(), }, - None => SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid utxo"))) + None => SimpleResponse::from(CardanoError::InvalidTransaction("invalid utxo".to_string())) .simple_c_ptr(), } } @@ -269,7 +269,7 @@ fn parse_cardano_root_path(path: String) -> Option { let root_path = "1852'/1815'/"; match path.strip_prefix(root_path) { Some(path) => { - if let Some(index) = path.find("/") { + if let Some(index) = path.find('/') { let sub_path = &path[..index]; Some(format!("{}{}", root_path, sub_path)) } else { @@ -319,7 +319,7 @@ pub extern "C" fn cardano_parse_tx( let cardano_sign_reqeust = extract_ptr_with_type!(ptr, CardanoSignRequest); let tx_hex = cardano_sign_reqeust.get_sign_data(); let parse_context = - prepare_parse_context(&cardano_sign_reqeust, master_fingerprint, cardano_xpub); + prepare_parse_context(cardano_sign_reqeust, master_fingerprint, cardano_xpub); match parse_context { Ok(parse_context) => match app_cardano::transaction::parse_tx(tx_hex, parse_context) { Ok(v) => TransactionParseResult::success(DisplayCardanoTx::from(v).c_ptr()).c_ptr(), @@ -365,7 +365,9 @@ pub extern "C" fn cardano_sign_catalyst( fn cardano_sign_catalyst_by_icarus(ptr: PtrUR, icarus_master_key: XPrv) -> PtrT { let cardano_catalyst_request = extract_ptr_with_type!(ptr, CardanoCatalystVotingRegistrationRequest); - let result = governance::sign( + + + governance::sign( &cardano_catalyst_request .get_derivation_path() .get_path() @@ -390,15 +392,13 @@ fn cardano_sign_catalyst_by_icarus(ptr: PtrUR, icarus_master_key: XPrv) -> PtrT< UREncodeResult::encode( data, CARDANO_CATALYST_VOTING_REGISTRATION_SIGNATURE.get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, ) }, - ); - - return result; + ) } #[no_mangle] @@ -463,7 +463,7 @@ fn cardano_sign_sign_data_by_icarus(ptr: PtrUR, icarus_master_key: XPrv) -> PtrT UREncodeResult::encode( data, CARDANO_SIGN_DATA_SIGNATURE.get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, @@ -471,7 +471,7 @@ fn cardano_sign_sign_data_by_icarus(ptr: PtrUR, icarus_master_key: XPrv) -> PtrT }, ); - return result; + result } #[no_mangle] @@ -531,7 +531,7 @@ fn cardano_sign_tx_hash_by_icarus(ptr: PtrUR, icarus_master_key: XPrv) -> PtrT UREncodeResult::encode( v, CARDANO_SIGNATURE.get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -547,7 +547,7 @@ fn cardano_sign_tx_by_icarus( let cardano_sign_reqeust = extract_ptr_with_type!(ptr, CardanoSignRequest); let tx_hex = cardano_sign_reqeust.get_sign_data(); let parse_context = - prepare_parse_context(&cardano_sign_reqeust, master_fingerprint, cardano_xpub); + prepare_parse_context(cardano_sign_reqeust, master_fingerprint, cardano_xpub); match parse_context { Ok(parse_context) => { @@ -560,7 +560,7 @@ fn cardano_sign_tx_by_icarus( Ok(data) => UREncodeResult::encode( data, CARDANO_SIGNATURE.get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -632,7 +632,7 @@ fn get_cardano_derivation_path(path: CryptoKeyPath) -> R { let components = path.get_components(); let mut new_components = Vec::new(); for i in 3..components.len() { - new_components.push(components[i].clone()); + new_components.push(components[i]); } Ok(CryptoKeyPath::new( new_components, @@ -661,7 +661,7 @@ mod tests { None, ); let result = get_cardano_derivation_path(path); - assert_eq!(result.is_ok(), true); + assert!(result.is_ok()); assert_eq!(result.unwrap().get_path().unwrap(), "2/0"); } diff --git a/rust/rust_c/src/cardano/structs.rs b/rust/rust_c/src/cardano/structs.rs index 35b7f85c2..e971623b0 100644 --- a/rust/rust_c/src/cardano/structs.rs +++ b/rust/rust_c/src/cardano/structs.rs @@ -263,7 +263,7 @@ impl From for DisplayCardanoTx { .c_ptr(), auxiliary_data: value .get_auxiliary_data() - .map(|v| convert_c_char(v)) + .map(convert_c_char) .unwrap_or(null_mut()), voting_procedures: VecFFI::from( value diff --git a/rust/rust_c/src/common/free.rs b/rust/rust_c/src/common/free.rs index a4a2b9fea..b9bd3888d 100644 --- a/rust/rust_c/src/common/free.rs +++ b/rust/rust_c/src/common/free.rs @@ -57,7 +57,7 @@ macro_rules! free_ptr_with_type { ($x: expr, $name: ident) => { if (!$x.is_null()) { unsafe { - let x = crate::extract_ptr_with_type!($x, $name); + let x = $crate::extract_ptr_with_type!($x, $name); let _b = alloc::boxed::Box::from_raw(x); // drop(b); } diff --git a/rust/rust_c/src/common/keystone.rs b/rust/rust_c/src/common/keystone.rs index 9f2deba7a..e862aaafd 100644 --- a/rust/rust_c/src/common/keystone.rs +++ b/rust/rust_c/src/common/keystone.rs @@ -38,8 +38,7 @@ pub fn build_payload(ptr: PtrUR, ur_type: QRCodeType) -> Result return Err(KeystoneError::ProtobufError("invalid ur type".to_string())), }; unzip(bytes) - .and_then(|unzip_data| parse_protobuf(unzip_data)) - .and_then(|base: Base| Ok(base.data)) + .and_then(parse_protobuf).map(|base: Base| base.data) .map_err(|e| KeystoneError::ProtobufError(e.to_string()))? .ok_or(KeystoneError::ProtobufError("empty payload".to_string())) } @@ -53,8 +52,8 @@ pub fn build_parse_context( let xpub_str = convert_version(x_pub.as_str(), &Version::Xpub) .map_err(|e| KeystoneError::InvalidParseContext(e.to_string()))?; let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) - .map_err(|_| KeystoneError::InvalidParseContext(format!("invalid mfp")))?; + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) + .map_err(|_| KeystoneError::InvalidParseContext("invalid mfp".to_string()))?; let extended_pubkey = bitcoin::bip32::Xpub::from_str(&xpub_str).map_err(|_| { KeystoneError::InvalidParseContext(format!("invalid extended pub key {}", x_pub)) })?; @@ -119,9 +118,9 @@ pub fn build_check_result( }) } _ => { - return Err(KeystoneError::ProtobufError( + Err(KeystoneError::ProtobufError( "empty payload content".to_string(), - )); + )) } } } @@ -165,9 +164,9 @@ pub fn build_sign_result( zip(&data).map_err(|_| KeystoneError::ProtobufError("zip bytes failed".to_string())) } _ => { - return Err(KeystoneError::ProtobufError( + Err(KeystoneError::ProtobufError( "empty payload content".to_string(), - )); + )) } } } @@ -211,7 +210,7 @@ pub fn sign( Ok(data) => UREncodeResult::encode( data, KeystoneSignResult::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -227,7 +226,7 @@ pub fn sign( Ok(data) => UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/common/macros.rs b/rust/rust_c/src/common/macros.rs index 01b62cc4a..629729aec 100644 --- a/rust/rust_c/src/common/macros.rs +++ b/rust/rust_c/src/common/macros.rs @@ -482,7 +482,7 @@ macro_rules! make_free_method { app_utils::paste::item! { #[no_mangle] pub extern "C" fn [](ptr: PtrT<$t>) { - crate::check_and_free_ptr!(ptr) + $crate::check_and_free_ptr!(ptr) } } }; @@ -490,7 +490,7 @@ macro_rules! make_free_method { app_utils::paste::item! { #[no_mangle] pub extern "C" fn [](ptr: PtrT<$t1<$t2>>) { - crate::check_and_free_ptr!(ptr) + $crate::check_and_free_ptr!(ptr) } } }; diff --git a/rust/rust_c/src/common/mod.rs b/rust/rust_c/src/common/mod.rs index 4f263908e..b60681dae 100644 --- a/rust/rust_c/src/common/mod.rs +++ b/rust/rust_c/src/common/mod.rs @@ -9,7 +9,7 @@ use keystore::algorithms::ed25519::slip10_ed25519::get_private_key_by_seed; use bitcoin::hex::Case; use bitcoin_hashes::hex::DisplayHex; use cty::c_char; -use hex; + use hex::ToHex; use errors::ErrorCodes; @@ -97,7 +97,7 @@ pub extern "C" fn get_ed25519_pubkey_by_seed( let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; let path = recover_c_char(path); let extended_key = - keystore::algorithms::ed25519::slip10_ed25519::get_public_key_by_seed(&seed, &path); + keystore::algorithms::ed25519::slip10_ed25519::get_public_key_by_seed(seed, &path); match extended_key { Ok(result) => SimpleResponse::success(convert_c_char(hex::encode(result))).simple_c_ptr(), Err(e) => SimpleResponse::from(e).simple_c_ptr(), @@ -128,7 +128,7 @@ pub extern "C" fn get_bip32_ed25519_extended_pubkey( let passphrase = recover_c_char(passphrase); let extended_key = keystore::algorithms::ed25519::bip32_ed25519::get_extended_public_key_by_entropy( - &entropy, + entropy, passphrase.as_bytes(), &path, ); @@ -165,7 +165,7 @@ pub extern "C" fn get_icarus_master_key( let entropy = unsafe { slice::from_raw_parts(entropy, entropy_len as usize) }; let passphrase = recover_c_char(passphrase); let master_key = keystore::algorithms::ed25519::bip32_ed25519::get_icarus_master_key_by_entropy( - &entropy, + entropy, passphrase.as_bytes(), ); match master_key { @@ -274,7 +274,7 @@ pub extern "C" fn pbkdf2_rust( ) -> *mut SimpleResponse { let password_bytes = unsafe { slice::from_raw_parts(password, 32) }; let salt_bytes = unsafe { slice::from_raw_parts(salt, 32) }; - let output = keystore::algorithms::crypto::hkdf(&password_bytes, &salt_bytes, iterations); + let output = keystore::algorithms::crypto::hkdf(password_bytes, salt_bytes, iterations); SimpleResponse::success(Box::into_raw(Box::new(output)) as *mut u8).simple_c_ptr() } @@ -286,7 +286,7 @@ pub extern "C" fn pbkdf2_rust_64( ) -> *mut SimpleResponse { let password_bytes = unsafe { slice::from_raw_parts(password, 64) }; let salt_bytes = unsafe { slice::from_raw_parts(salt, 64) }; - let output = keystore::algorithms::crypto::hkdf64(&password_bytes, &salt_bytes, iterations); + let output = keystore::algorithms::crypto::hkdf64(password_bytes, salt_bytes, iterations); SimpleResponse::success(Box::into_raw(Box::new(output)) as *mut u8).simple_c_ptr() } diff --git a/rust/rust_c/src/common/qrcode/mod.rs b/rust/rust_c/src/common/qrcode/mod.rs index 4a132c8ca..2c31665d7 100644 --- a/rust/rust_c/src/common/qrcode/mod.rs +++ b/rust/rust_c/src/common/qrcode/mod.rs @@ -30,7 +30,7 @@ pub extern "C" fn infer_qrcode_type(qrcode: PtrString) -> QRProtocol { pub extern "C" fn parse_qrcode_text(qr: PtrString) -> Ptr { let value = recover_c_char(qr); if value.to_lowercase().starts_with("signmessage") { - let mut headers_and_message = value.split(":"); + let mut headers_and_message = value.split(':'); let headers = headers_and_message.next(); let message = headers_and_message.next(); if let (Some(headers), Some(message)) = (headers, message) { @@ -42,7 +42,7 @@ pub extern "C" fn parse_qrcode_text(qr: PtrString) -> Ptr { match encode { "ascii" => { let data = SeedSignerMessage::new( - path.replace("h", "'").to_string(), + path.replace('h', "'").to_string(), message.to_string(), MessageEncoding::ASCII, ); @@ -63,10 +63,8 @@ pub extern "C" fn parse_qrcode_text(qr: PtrString) -> Ptr { } } } - return URParseResult::from(RustCError::UnsupportedTransaction(format!( - "Invalid seed signer message format" - ))) + return URParseResult::from(RustCError::UnsupportedTransaction("Invalid seed signer message format".to_string())) .c_ptr(); } - URParseResult::from(RustCError::UnsupportedTransaction(format!("plain text"))).c_ptr() + URParseResult::from(RustCError::UnsupportedTransaction("plain text".to_string())).c_ptr() } diff --git a/rust/rust_c/src/common/ur.rs b/rust/rust_c/src/common/ur.rs index 280a5c7ac..7022f89d3 100644 --- a/rust/rust_c/src/common/ur.rs +++ b/rust/rust_c/src/common/ur.rs @@ -127,7 +127,7 @@ impl UREncodeResult { match result.encoder { Some(v) => Self::multi(result.data.to_uppercase(), v), None => { - Self::from(RustCError::UnexpectedError(format!("ur encoder is none"))) + Self::from(RustCError::UnexpectedError("ur encoder is none".to_string())) } } } else { @@ -611,10 +611,10 @@ fn _decode_ur, Error = URError> + InferViewTyp } else { match parse_result.data { Some(data) => { - return match InferViewType::infer(&data) { + match InferViewType::infer(&data) { Ok(t) => URParseResult::single(t, u, data), Err(e) => URParseResult::from(e), - }; + } } None => URParseResult::from(RustCError::UnexpectedError( "ur data is none".to_string(), @@ -623,7 +623,7 @@ fn _decode_ur, Error = URError> + InferViewTyp } } Err(e) => { - return URParseResult::from(e); + URParseResult::from(e) } } } @@ -700,10 +700,10 @@ fn _receive_ur, Error = URError> + InferViewTy if parse_result.is_complete { match parse_result.data { Some(data) => { - return match InferViewType::infer(&data) { + match InferViewType::infer(&data) { Ok(t) => URParseMultiResult::success(t, u, data), Err(e) => URParseMultiResult::from(e), - }; + } } None => URParseMultiResult::from(RustCError::UnexpectedError( "UR parsed completely but data is none".to_string(), @@ -714,7 +714,7 @@ fn _receive_ur, Error = URError> + InferViewTy } } Err(e) => { - return URParseMultiResult::from(e); + URParseMultiResult::from(e) } } } diff --git a/rust/rust_c/src/common/ur_ext.rs b/rust/rust_c/src/common/ur_ext.rs index 409766911..11a63eff4 100644 --- a/rust/rust_c/src/common/ur_ext.rs +++ b/rust/rust_c/src/common/ur_ext.rs @@ -232,7 +232,7 @@ impl InferViewType for Bytes { Ok(_v) => { if let Some(_type) = _v.pointer("/data/type") { let contract_name: String = from_value(_type.clone()).map_err(|e| { - URError::UrDecodeError(format!("invalid data, {}", e.to_string())) + URError::UrDecodeError(format!("invalid data, {}", e)) })?; if contract_name.eq("webAuth") { return Ok(ViewType::WebAuthResult); diff --git a/rust/rust_c/src/common/web_auth.rs b/rust/rust_c/src/common/web_auth.rs index f42b4a780..3a752f1a7 100644 --- a/rust/rust_c/src/common/web_auth.rs +++ b/rust/rust_c/src/common/web_auth.rs @@ -44,21 +44,21 @@ pub extern "C" fn calculate_auth_code( match _calculate_auth_code(&_value, rsa_key_n, rsa_key_d) { Ok(_result) => Ok(_result), Err(_err) => { - Err(RustCError::WebAuthFailed(format!("{}", _err.to_string()))) + Err(RustCError::WebAuthFailed(format!("{}", _err))) } } }, Err(_err) => { - Err(RustCError::WebAuthFailed(format!("{}", _err.to_string()))) + Err(RustCError::WebAuthFailed(format!("{}", _err))) } }, - Err(_err) => Err(RustCError::WebAuthFailed(format!("{}", _err.to_string()))), + Err(_err) => Err(RustCError::WebAuthFailed(format!("{}", _err))), } } else { - Err(RustCError::WebAuthFailed(format!("invalid json"))) + Err(RustCError::WebAuthFailed("invalid json".to_string())) } } - Err(_err) => Err(RustCError::WebAuthFailed(format!("{}", _err.to_string()))), + Err(_err) => Err(RustCError::WebAuthFailed(format!("{}", _err))), }; match result { Ok(_value) => convert_c_char(_value), @@ -91,26 +91,26 @@ fn _calculate_auth_code( d, vec![dummy_p, dummy_q], ) { - Ok(_key) => match _key.decrypt(rsa::Oaep::new::(), &encrypted_data) { + Ok(_key) => match _key.decrypt(rsa::Oaep::new::(), encrypted_data) { Ok(_value) => String::from_utf8(_value.clone()).map_err(|_err| { RustCError::WebAuthFailed(format!( "Invalid utf8 hex: {}, {}", hex::encode(_value), - _err.to_string() + _err )) }), Err(_err) => Err(RustCError::WebAuthFailed(format!( "RSA decryption failed: {}", - _err.to_string() + _err ))), }, Err(_err) => Err(RustCError::WebAuthFailed(format!( "RSA key recovery error: {}", - _err.to_string() + _err ))), } }, - _ => Err(RustCError::WebAuthFailed(format!("k1 verify failed"))), + _ => Err(RustCError::WebAuthFailed("k1 verify failed".to_string())), } } diff --git a/rust/rust_c/src/cosmos/mod.rs b/rust/rust_c/src/cosmos/mod.rs index d32a0385f..f61e2cf9f 100644 --- a/rust/rust_c/src/cosmos/mod.rs +++ b/rust/rust_c/src/cosmos/mod.rs @@ -53,7 +53,7 @@ fn build_sign_result( sign_request.get_sign_data().to_vec(), &path, SignMode::COSMOS, - &seed, + seed, )?; Ok(Either::Left(CosmosSignature::new( sign_request.get_request_id(), @@ -74,14 +74,14 @@ fn build_sign_result( sign_request.get_sign_data().to_vec(), &path, SignMode::EVM, - &seed, + seed, )?; Ok(Either::Right(EvmSignature::new( sign_request.get_request_id(), signature.to_vec(), ))) } - _ => return Err(CosmosError::SignFailure("invalid ur type".to_string())), + _ => Err(CosmosError::SignFailure("invalid ur type".to_string())), } } @@ -181,7 +181,7 @@ pub extern "C" fn cosmos_sign_tx( v.map_or_else( |e| UREncodeResult::from(e).c_ptr(), |data| { - UREncodeResult::encode(data, ur_tag, FRAGMENT_MAX_LENGTH_DEFAULT.clone()) + UREncodeResult::encode(data, ur_tag, FRAGMENT_MAX_LENGTH_DEFAULT) .c_ptr() }, ) diff --git a/rust/rust_c/src/ethereum/abi.rs b/rust/rust_c/src/ethereum/abi.rs index 677eb0824..254d40dbd 100644 --- a/rust/rust_c/src/ethereum/abi.rs +++ b/rust/rust_c/src/ethereum/abi.rs @@ -3,7 +3,7 @@ use crate::common::errors::RustCError; use crate::common::structs::Response; use crate::common::types::{Ptr, PtrString}; use crate::common::utils::recover_c_char; -use hex; + #[no_mangle] pub extern "C" fn eth_parse_contract_data( diff --git a/rust/rust_c/src/ethereum/mod.rs b/rust/rust_c/src/ethereum/mod.rs index a09687721..3d9d6c8a9 100644 --- a/rust/rust_c/src/ethereum/mod.rs +++ b/rust/rust_c/src/ethereum/mod.rs @@ -10,7 +10,7 @@ use app_ethereum::{ LegacyTransaction, TransactionSignature, }; use cryptoxide::hashing::keccak256; -use hex; + use keystore::algorithms::secp256k1::derive_public_key; use ur_registry::ethereum::eth_sign_request::EthSignRequest; use ur_registry::ethereum::eth_signature::EthSignature; @@ -60,9 +60,9 @@ pub extern "C" fn eth_check_ur_bytes( let xfp = payload.xfp; let xfp_vec: [u8; 4] = hex::decode(xfp).unwrap().try_into().unwrap(); if mfp == xfp_vec { - return TransactionCheckResult::new().c_ptr(); + TransactionCheckResult::new().c_ptr() } else { - return TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr(); + TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr() } } Err(e) => TransactionCheckResult::from(KeystoneError::ProtobufError(e.to_string())).c_ptr(), @@ -98,9 +98,9 @@ pub extern "C" fn eth_check( } }; if ur_mfp == mfp { - return TransactionCheckResult::new().c_ptr(); + TransactionCheckResult::new().c_ptr() } else { - return TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr(); + TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr() } } @@ -122,7 +122,7 @@ pub extern "C" fn eth_get_root_path_bytes(ptr: PtrUR) -> PtrString { .take(3) .collect::>() .join("/"); - return convert_c_char(root_path); + convert_c_char(root_path) } #[no_mangle] @@ -135,14 +135,14 @@ pub extern "C" fn eth_get_root_path(ptr: PtrUR) -> PtrString { return convert_c_char(root_path); } } - return convert_c_char("".to_string()); + convert_c_char("".to_string()) } fn parse_eth_root_path(path: String) -> Option { let root_path = "44'/60'/"; match path.strip_prefix(root_path) { Some(path) => { - if let Some(index) = path.find("/") { + if let Some(index) = path.find('/') { let sub_path = &path[..index]; Some(format!("{}{}", root_path, sub_path)) } else { @@ -157,11 +157,7 @@ fn parse_eth_sub_path(path: String) -> Option { let root_path = "44'/60'/"; match path.strip_prefix(root_path) { Some(path) => { - if let Some(index) = path.find("/") { - Some(path[index + 1..].to_string()) - } else { - None - } + path.find('/').map(|index| path[index + 1..].to_string()) } None => None, } @@ -177,7 +173,7 @@ fn try_get_eth_public_key( let _path = path.clone(); if let Some(sub_path) = parse_eth_sub_path(_path) { derive_public_key(&xpub, &format!("m/{}", sub_path)) - .map_err(|_e| RustCError::UnexpectedError(format!("unable to derive pubkey"))) + .map_err(|_e| RustCError::UnexpectedError("unable to derive pubkey".to_string())) } else { Err(RustCError::InvalidHDPath) } @@ -210,7 +206,7 @@ pub extern "C" fn eth_parse_bytes_data( .collect::>() .join("/"); let address = derive_address( - &sign_tx.hd_path.to_uppercase().trim_start_matches("M/"), + sign_tx.hd_path.to_uppercase().trim_start_matches("M/"), &xpub, root_path, ) @@ -254,7 +250,7 @@ pub extern "C" fn eth_parse( } } TransactionType::TypedTransaction => { - match crypto_eth.get_sign_data().get(0) { + match crypto_eth.get_sign_data().first() { Some(02) => { //remove envelop let payload = crypto_eth.get_sign_data()[1..].to_vec(); @@ -368,7 +364,7 @@ pub extern "C" fn eth_sign_tx_dynamic( TransactionType::Legacy => { app_ethereum::sign_legacy_tx(crypto_eth.get_sign_data().to_vec(), seed, &path) } - TransactionType::TypedTransaction => match crypto_eth.get_sign_data().get(0) { + TransactionType::TypedTransaction => match crypto_eth.get_sign_data().first() { Some(0x02) => { app_ethereum::sign_fee_markey_tx(crypto_eth.get_sign_data().to_vec(), seed, &path) } @@ -396,7 +392,7 @@ pub extern "C" fn eth_sign_tx_dynamic( let eth_signature = EthSignature::new( crypto_eth.get_request_id(), sig.serialize(), - Some(format!("{}", KEYSTONE)), + Some(KEYSTONE.to_string()), ); match eth_signature.try_into() { Err(e) => UREncodeResult::from(e).c_ptr(), @@ -486,14 +482,14 @@ pub extern "C" fn eth_sign_tx_bytes( UREncodeResult::encode( ur_registry::bytes::Bytes::new(zip_data).try_into().unwrap(), ur_registry::bytes::Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() } #[no_mangle] pub extern "C" fn eth_sign_tx(ptr: PtrUR, seed: PtrBytes, seed_len: u32) -> PtrT { - eth_sign_tx_dynamic(ptr, seed, seed_len, FRAGMENT_MAX_LENGTH_DEFAULT.clone()) + eth_sign_tx_dynamic(ptr, seed, seed_len, FRAGMENT_MAX_LENGTH_DEFAULT) } // _unlimited @@ -503,7 +499,7 @@ pub extern "C" fn eth_sign_tx_unlimited( seed: PtrBytes, seed_len: u32, ) -> PtrT { - eth_sign_tx_dynamic(ptr, seed, seed_len, FRAGMENT_UNLIMITED_LENGTH.clone()) + eth_sign_tx_dynamic(ptr, seed, seed_len, FRAGMENT_UNLIMITED_LENGTH) } #[no_mangle] @@ -540,9 +536,9 @@ mod tests { fn test_test() { let _path = "44'/60'/1'/0/0"; let root_path = "44'/60'/"; - let sub_path = match _path.strip_prefix(root_path) { + match _path.strip_prefix(root_path) { Some(path) => { - if let Some(index) = path.find("/") { + if let Some(index) = path.find('/') { println!("{}", &path[index..]); } } diff --git a/rust/rust_c/src/ethereum/structs.rs b/rust/rust_c/src/ethereum/structs.rs index f595fdc87..316e08368 100644 --- a/rust/rust_c/src/ethereum/structs.rs +++ b/rust/rust_c/src/ethereum/structs.rs @@ -373,7 +373,7 @@ impl From for DisplayContractData { value .get_params() .iter() - .map(|v| DisplayContractParam::from(v)) + .map(DisplayContractParam::from) .collect_vec(), ) .c_ptr(), diff --git a/rust/rust_c/src/near/mod.rs b/rust/rust_c/src/near/mod.rs index c1d6dcbe3..7ce7b5e80 100644 --- a/rust/rust_c/src/near/mod.rs +++ b/rust/rust_c/src/near/mod.rs @@ -95,7 +95,7 @@ pub extern "C" fn near_sign_tx(ptr: PtrUR, seed: PtrBytes, seed_len: u32) -> Ptr UREncodeResult::encode( data, NearSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, diff --git a/rust/rust_c/src/solana/mod.rs b/rust/rust_c/src/solana/mod.rs index 2a2287c8f..59e4f23f2 100644 --- a/rust/rust_c/src/solana/mod.rs +++ b/rust/rust_c/src/solana/mod.rs @@ -56,7 +56,7 @@ pub extern "C" fn solana_check( } let sol_sign_request = extract_ptr_with_type!(ptr, SolSignRequest); let mfp = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; - if let Some(mfp) = (mfp.try_into() as Result<[u8; 4], _>).ok() { + if let Ok(mfp) = (mfp.try_into() as Result<[u8; 4], _>) { let derivation_path: ur_registry::crypto_key_path::CryptoKeyPath = sol_sign_request.get_derivation_path(); if let Some(ur_mfp) = derivation_path.get_source_fingerprint() { @@ -99,7 +99,7 @@ pub extern "C" fn solana_sign_tx( UREncodeResult::encode( data, SolSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, @@ -134,5 +134,5 @@ pub extern "C" fn sol_get_path(ptr: PtrUR) -> PtrString { if let Some(path) = derivation_path.get_path() { return convert_c_char(path); } - return convert_c_char("".to_string()); + convert_c_char("".to_string()) } diff --git a/rust/rust_c/src/stellar/mod.rs b/rust/rust_c/src/stellar/mod.rs index 5c6c832c9..2b840598a 100644 --- a/rust/rust_c/src/stellar/mod.rs +++ b/rust/rust_c/src/stellar/mod.rs @@ -12,7 +12,7 @@ use crate::common::utils::{convert_c_char, recover_c_char}; use crate::extract_ptr_with_type; use app_stellar::strkeys::{sign_hash, sign_signature_base}; use app_stellar::{address::get_address, base_to_xdr}; -use hex; + use structs::DisplayStellarTx; use ur_registry::stellar::stellar_sign_request::{SignType, StellarSignRequest}; use ur_registry::stellar::stellar_signature::StellarSignature; @@ -35,7 +35,7 @@ pub extern "C" fn stellar_parse(ptr: PtrUR) -> PtrT base_to_xdr(&sign_request.get_sign_data()), - SignType::TransactionHash => hex::encode(&sign_request.get_sign_data()), + SignType::TransactionHash => hex::encode(sign_request.get_sign_data()), _ => { return TransactionParseResult::from(RustCError::UnsupportedTransaction( "Transaction".to_string(), @@ -61,7 +61,7 @@ pub extern "C" fn stellar_check_tx( } let mfp = unsafe { slice::from_raw_parts(master_fingerprint, 4) }; let sign_request = extract_ptr_with_type!(ptr, StellarSignRequest); - if let Some(mfp) = (mfp.try_into() as Result<[u8; 4], _>).ok() { + if let Ok(mfp) = (mfp.try_into() as Result<[u8; 4], _>) { let derivation_path: ur_registry::crypto_key_path::CryptoKeyPath = sign_request.get_derivation_path(); if let Some(ur_mfp) = derivation_path.get_source_fingerprint() { @@ -86,7 +86,7 @@ fn build_signature_data( UREncodeResult::encode( data, StellarSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() } @@ -98,19 +98,19 @@ pub extern "C" fn stellar_sign(ptr: PtrUR, seed: PtrBytes, seed_len: u32) -> Ptr let sign_data = sign_request.get_sign_data(); let path = sign_request.get_derivation_path().get_path().unwrap(); match sign_request.get_sign_type() { - SignType::Transaction => match sign_signature_base(&sign_data, &seed, &path) { + SignType::Transaction => match sign_signature_base(&sign_data, seed, &path) { Ok(signature) => build_signature_data(&signature, sign_request.to_owned()), Err(e) => UREncodeResult::from(e).c_ptr(), }, - SignType::TransactionHash => match sign_hash(&sign_data, &seed, &path) { + SignType::TransactionHash => match sign_hash(&sign_data, seed, &path) { Ok(signature) => build_signature_data(&signature, sign_request.to_owned()), Err(e) => UREncodeResult::from(e).c_ptr(), }, _ => { - return UREncodeResult::from(RustCError::UnsupportedTransaction( + UREncodeResult::from(RustCError::UnsupportedTransaction( "Transaction".to_string(), )) - .c_ptr(); + .c_ptr() } } } diff --git a/rust/rust_c/src/sui/mod.rs b/rust/rust_c/src/sui/mod.rs index b87948f19..beaf974e7 100644 --- a/rust/rust_c/src/sui/mod.rs +++ b/rust/rust_c/src/sui/mod.rs @@ -167,7 +167,7 @@ pub extern "C" fn sui_sign_hash(ptr: PtrUR, seed: PtrBytes, seed_len: u32) -> Pt UREncodeResult::encode( sig_data, SuiSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() } @@ -210,7 +210,7 @@ pub extern "C" fn sui_sign_intent( UREncodeResult::encode( sig_data, SuiSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() } diff --git a/rust/rust_c/src/ton/mod.rs b/rust/rust_c/src/ton/mod.rs index b1e21c599..7636de4b0 100644 --- a/rust/rust_c/src/ton/mod.rs +++ b/rust/rust_c/src/ton/mod.rs @@ -127,7 +127,7 @@ pub extern "C" fn ton_sign_transaction( ) -> PtrT { let ton_tx = extract_ptr_with_type!(ptr, TonSignRequest); let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; - let sk = match get_secret_key(&ton_tx, seed) { + let sk = match get_secret_key(ton_tx, seed) { Ok(_sk) => _sk, Err(e) => return UREncodeResult::from(e).c_ptr(), }; @@ -144,7 +144,7 @@ pub extern "C" fn ton_sign_transaction( Ok(v) => UREncodeResult::encode( v, TonSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), } @@ -161,7 +161,7 @@ pub extern "C" fn ton_sign_proof( ) -> PtrT { let ton_tx = extract_ptr_with_type!(ptr, TonSignRequest); let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; - let sk = match get_secret_key(&ton_tx, seed) { + let sk = match get_secret_key(ton_tx, seed) { Ok(_sk) => _sk, Err(e) => return UREncodeResult::from(e).c_ptr(), }; @@ -178,7 +178,7 @@ pub extern "C" fn ton_sign_proof( Ok(v) => UREncodeResult::encode( v, TonSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), } @@ -190,17 +190,14 @@ pub extern "C" fn ton_sign_proof( #[no_mangle] pub extern "C" fn ton_verify_mnemonic(mnemonic: PtrString) -> bool { let mnemonic = recover_c_char(mnemonic); - let words: Vec = mnemonic.split(" ").map(|v| v.to_lowercase()).collect(); - match ton_mnemonic_validate(&words, &None) { - Ok(_) => true, - Err(_) => false, - } + let words: Vec = mnemonic.split(' ').map(|v| v.to_lowercase()).collect(); + ton_mnemonic_validate(&words, &None).is_ok() } #[no_mangle] pub extern "C" fn ton_mnemonic_to_entropy(mnemonic: PtrString) -> Ptr> { let mnemonic = recover_c_char(mnemonic); - let words: Vec = mnemonic.split(" ").map(|v| v.to_lowercase()).collect(); + let words: Vec = mnemonic.split(' ').map(|v| v.to_lowercase()).collect(); let entropy = app_ton::mnemonic::ton_mnemonic_to_entropy(&words, &None); VecFFI::from(entropy).c_ptr() } @@ -218,7 +215,7 @@ pub extern "C" fn ton_entropy_to_seed( #[no_mangle] pub extern "C" fn ton_mnemonic_to_seed(mnemonic: PtrString) -> *mut SimpleResponse { let mnemonic = recover_c_char(mnemonic); - let words: Vec = mnemonic.split(" ").map(|v| v.to_lowercase()).collect(); + let words: Vec = mnemonic.split(' ').map(|v| v.to_lowercase()).collect(); let seed = app_ton::mnemonic::ton_mnemonic_to_master_seed(words, None); match seed { Ok(seed) => { @@ -239,9 +236,7 @@ pub extern "C" fn ton_seed_to_publickey( let public_key = app_ton::mnemonic::ton_master_seed_to_public_key(_seed); SimpleResponse::success(convert_c_char(hex::encode(public_key))).simple_c_ptr() } - Err(_e) => SimpleResponse::from(crate::common::errors::RustCError::InvalidData(format!( - "seed length should be 64" - ))) + Err(_e) => SimpleResponse::from(crate::common::errors::RustCError::InvalidData("seed length should be 64".to_string())) .simple_c_ptr(), } } diff --git a/rust/rust_c/src/ton/structs.rs b/rust/rust_c/src/ton/structs.rs index f3eb88584..8d6e4cfb7 100644 --- a/rust/rust_c/src/ton/structs.rs +++ b/rust/rust_c/src/ton/structs.rs @@ -31,18 +31,18 @@ impl From<&TonTransaction> for DisplayTonTransaction { comment: tx .comment .clone() - .map(|v| convert_c_char(v)) + .map(convert_c_char) .unwrap_or(null_mut()), data_view: tx .data_view .clone() - .map(|v| convert_c_char(v)) + .map(convert_c_char) .unwrap_or(null_mut()), raw_data: convert_c_char(tx.raw_data.clone()), contract_data: tx .contract_data .clone() - .map(|e| convert_c_char(e)) + .map(convert_c_char) .unwrap_or(null_mut()), } } diff --git a/rust/rust_c/src/wallet/btc_only_wallet.rs b/rust/rust_c/src/wallet/btc_only_wallet.rs index ec4fad978..9f30bd789 100644 --- a/rust/rust_c/src/wallet/btc_only_wallet.rs +++ b/rust/rust_c/src/wallet/btc_only_wallet.rs @@ -37,7 +37,7 @@ pub extern "C" fn get_connect_blue_wallet_ur( unsafe { let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let keys = recover_c_array(public_keys); - let key1 = keys.get(0); + let key1 = keys.first(); let key2 = keys.get(1); let key3 = keys.get(2); return if let (Some(k1), Some(k2), Some(k3)) = (key1, key2, key3) { @@ -71,7 +71,7 @@ pub extern "C" fn get_connect_blue_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoAccount::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -79,7 +79,7 @@ pub extern "C" fn get_connect_blue_wallet_ur( Err(e) => UREncodeResult::from(e).c_ptr(), } } else { - UREncodeResult::from(URError::UrEncodeError(format!("getting key error"))).c_ptr() + UREncodeResult::from(URError::UrEncodeError("getting key error".to_string())).c_ptr() }; } } @@ -100,7 +100,7 @@ pub extern "C" fn get_connect_sparrow_wallet_ur( unsafe { let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let keys = recover_c_array(public_keys); - let key1 = keys.get(0); + let key1 = keys.first(); let key2 = keys.get(1); let key3 = keys.get(2); let key4 = keys.get(3); @@ -142,7 +142,7 @@ pub extern "C" fn get_connect_sparrow_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoAccount::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -150,7 +150,7 @@ pub extern "C" fn get_connect_sparrow_wallet_ur( Err(e) => UREncodeResult::from(e).c_ptr(), } } else { - UREncodeResult::from(URError::UrEncodeError(format!("getting key error"))).c_ptr() + UREncodeResult::from(URError::UrEncodeError("getting key error".to_string())).c_ptr() }; } } @@ -171,7 +171,7 @@ pub extern "C" fn get_connect_specter_wallet_ur( unsafe { let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let keys = recover_c_array(public_keys); - let key1 = keys.get(0); + let key1 = keys.first(); let key2 = keys.get(1); return if let (Some(k1), Some(k2)) = (key1, key2) { let k1_x_pub = recover_c_char(k1.xpub); @@ -198,7 +198,7 @@ pub extern "C" fn get_connect_specter_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoAccount::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -206,7 +206,7 @@ pub extern "C" fn get_connect_specter_wallet_ur( Err(e) => UREncodeResult::from(e).c_ptr(), } } else { - UREncodeResult::from(URError::UrEncodeError(format!("getting key error"))).c_ptr() + UREncodeResult::from(URError::UrEncodeError("getting key error".to_string())).c_ptr() }; } } @@ -279,7 +279,7 @@ pub extern "C" fn get_connect_companion_app_ur( Ok(data) => UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -327,7 +327,7 @@ pub extern "C" fn get_okx_wallet_ur_btc_only( Ok(_v) => UREncodeResult::encode( _v, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs index d47899fe0..886a940d6 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs @@ -33,7 +33,7 @@ pub extern "C" fn get_connect_aptos_wallet_ur( let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let public_keys = recover_c_array(public_keys); let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -56,7 +56,7 @@ pub extern "C" fn get_connect_aptos_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs index 886865601..e8009941f 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs @@ -34,19 +34,19 @@ pub extern "C" fn get_connect_arconnect_wallet_ur( unsafe { slice::from_raw_parts(master_fingerprint, master_fingerprint_length as usize) }; let p = unsafe { slice::from_raw_parts(p, p_len as usize) }; let q = unsafe { slice::from_raw_parts(q, q_len as usize) }; - let public_key = generate_public_key_from_primes(&p, &q).unwrap(); + let public_key = generate_public_key_from_primes(p, q).unwrap(); let device = Option::None; let arweave_account = ArweaveCryptoAccount::new( vec_to_array(mfp.to_vec()).unwrap(), public_key.to_vec(), device, ); - return UREncodeResult::encode( + UREncodeResult::encode( arweave_account.to_bytes().unwrap(), ArweaveCryptoAccount::get_registry_type().get_type(), FRAGMENT_MAX_LENGTH_DEFAULT, ) - .c_ptr(); + .c_ptr() } #[no_mangle] @@ -64,12 +64,12 @@ pub extern "C" fn get_connect_arconnect_wallet_ur_from_xpub( hex::decode(xpub).unwrap(), device, ); - return UREncodeResult::encode( + UREncodeResult::encode( arweave_account.to_bytes().unwrap(), ArweaveCryptoAccount::get_registry_type().get_type(), FRAGMENT_MAX_LENGTH_DEFAULT, ) - .c_ptr(); + .c_ptr() } #[cfg(test)] diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs index be5e0299a..8f1e72c90 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs @@ -37,7 +37,7 @@ pub extern "C" fn get_backpack_wallet_ur( Ok(_v) => UREncodeResult::encode( _v, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs index cdc34eb7d..b4675b4f1 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs @@ -50,7 +50,7 @@ pub extern "C" fn get_bitget_wallet_ur( Ok(_v) => UREncodeResult::encode( _v, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs index 56f5a94e2..41be4fd10 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs @@ -35,10 +35,10 @@ pub extern "C" fn get_connect_keplr_wallet_ur( unsafe { let accounts: &[KeplrAccount] = recover_c_array(keplr_accounts); let sync_infos: Vec = accounts - .into_iter() + .iter() .map(|account| { let hd_path = recover_c_char(account.path); - let path_parts: Vec<&str> = hd_path.split("/").collect(); + let path_parts: Vec<&str> = hd_path.split('/').collect(); let path_len = path_parts.len(); SyncInfo { name: recover_c_char(account.name), @@ -62,7 +62,7 @@ pub extern "C" fn get_connect_keplr_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs index f244037f0..0d58eac24 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs @@ -48,7 +48,7 @@ pub extern "C" fn get_keystone_wallet_ur( Ok(_v) => UREncodeResult::encode( _v, "BYTES".to_string(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs index cadf86106..d78b25aed 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs @@ -116,12 +116,12 @@ pub extern "C" fn get_connect_metamask_ur_dynamic( } } Err(e) => { - return UREncodeResult::from(e).c_ptr(); + UREncodeResult::from(e).c_ptr() } } } _ => { - let key = keys.get(0).ok_or(RustCError::InvalidXPub); + let key = keys.first().ok_or(RustCError::InvalidXPub); match key { Ok(k) => { let result = app_wallets::metamask::generate_standard_legacy_hd_key( @@ -143,7 +143,7 @@ pub extern "C" fn get_connect_metamask_ur_dynamic( Err(e) => UREncodeResult::from(e).c_ptr(), } } - Err(e) => return UREncodeResult::from(e).c_ptr(), + Err(e) => UREncodeResult::from(e).c_ptr(), } } } @@ -162,8 +162,8 @@ pub extern "C" fn get_connect_metamask_ur_unlimited( master_fingerprint_length, account_type, public_keys, - FRAGMENT_UNLIMITED_LENGTH.clone(), - FRAGMENT_UNLIMITED_LENGTH.clone(), + FRAGMENT_UNLIMITED_LENGTH, + FRAGMENT_UNLIMITED_LENGTH, ) } @@ -179,7 +179,7 @@ pub extern "C" fn get_connect_metamask_ur( master_fingerprint_length, account_type, public_keys, - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, 240, ) } @@ -255,7 +255,7 @@ pub extern "C" fn check_hardware_call_path( _ => return Response::success(false).c_ptr(), }; let mut path = recover_c_char(path).to_lowercase(); - if !path.starts_with("m") { + if !path.starts_with('m') { path = format!("m/{}", path); } let result = path.starts_with(prefix); @@ -271,7 +271,7 @@ pub extern "C" fn generate_key_derivation_ur( ) -> Ptr { let mfp = extract_array!(master_fingerprint, u8, master_fingerprint_length); let mfp = match <&[u8; 4]>::try_from(mfp) { - Ok(mfp) => mfp.clone(), + Ok(mfp) => *mfp, Err(e) => return UREncodeResult::from(URError::UrEncodeError(e.to_string())).c_ptr(), }; let public_keys = unsafe { recover_c_array(xpubs) }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs index 2ac622bee..b041751cc 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs @@ -50,7 +50,7 @@ pub extern "C" fn get_okx_wallet_ur( Ok(_v) => UREncodeResult::encode( _v, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs index 1fa48c698..9e549244a 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs @@ -33,7 +33,7 @@ pub extern "C" fn get_connect_solana_wallet_ur( let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let public_keys = recover_c_array(public_keys); let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -56,7 +56,7 @@ pub extern "C" fn get_connect_solana_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs b/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs index 98b1b0fe2..dc847733c 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs @@ -71,7 +71,7 @@ impl TryFrom<&mut QRHardwareCall> for QRHardwareCallData { let schemas = data .get_schemas() .iter() - .map(|v| KeyDerivationSchema::try_from(v)) + .map(KeyDerivationSchema::try_from) .collect::, RustCError>>()?; // todo check path is valid diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs index 93b2f5883..7763c2f2e 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs @@ -32,7 +32,7 @@ pub extern "C" fn get_connect_sui_wallet_ur( let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let public_keys = recover_c_array(public_keys); let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -55,7 +55,7 @@ pub extern "C" fn get_connect_sui_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs index 06b844d77..d3f7cc53f 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs @@ -37,12 +37,12 @@ pub extern "C" fn get_connect_thor_wallet_ur( let serial_number = recover_c_char(serial_number); let device_type = recover_c_char(device_type); let device_version = recover_c_char(device_version); - let key1 = keys.get(0); + let key1 = keys.first(); let key2 = keys.get(1); let key3 = keys.get(2); let key4 = keys.get(3); let key5 = keys.get(4); - return if let (Some(_k1), Some(_k2), Some(_k3), Some(_k4), Some(_k5)) = + if let (Some(_k1), Some(_k2), Some(_k3), Some(_k4), Some(_k5)) = (key1, key2, key3, key4, key5) { let mfp = match <&[u8; 4]>::try_from(mfp) { @@ -65,7 +65,7 @@ pub extern "C" fn get_connect_thor_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -73,7 +73,7 @@ pub extern "C" fn get_connect_thor_wallet_ur( Err(e) => UREncodeResult::from(e).c_ptr(), } } else { - UREncodeResult::from(URError::UrEncodeError(format!("getting key error"))).c_ptr() - }; + UREncodeResult::from(URError::UrEncodeError("getting key error".to_string())).c_ptr() + } } } diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs b/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs index 48d7dff8d..6694f981f 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs @@ -48,7 +48,7 @@ pub extern "C" fn get_tonkeeper_wallet_ur( Ok(_v) => UREncodeResult::encode( _v, CryptoHDKey::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs index 56001feca..9aa8d76cd 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs @@ -33,7 +33,7 @@ pub extern "C" fn get_connect_xbull_wallet_ur( let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let public_keys = recover_c_array(public_keys); let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -56,7 +56,7 @@ pub extern "C" fn get_connect_xbull_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs index 749d5b633..7f1a0f227 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs @@ -20,7 +20,7 @@ pub extern "C" fn get_connect_xrp_toolkit_ur( Ok(data) => UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/xrp/mod.rs b/rust/rust_c/src/xrp/mod.rs index b96c286f6..36639b7c8 100644 --- a/rust/rust_c/src/xrp/mod.rs +++ b/rust/rust_c/src/xrp/mod.rs @@ -8,7 +8,7 @@ use app_xrp::errors::XRPError; use bitcoin::bip32::{DerivationPath, Xpub}; use bitcoin::secp256k1; use cty::c_char; -use hex; + use serde_json::Value; use ur_registry::bytes::Bytes; use ur_registry::pb; @@ -104,7 +104,7 @@ pub extern "C" fn xrp_sign_tx_bytes( let xpub = Xpub::from_str(&root_xpub).unwrap(); let k1 = secp256k1::Secp256k1::new(); // M/44'/144'/0'/0/0 -> 0/0 - let split_hd_path: Vec<&str> = hd_path.split("/").collect(); + let split_hd_path: Vec<&str> = hd_path.split('/').collect(); let derive_hd_path = format!("{}/{}", split_hd_path[4], split_hd_path[5]); let five_level_xpub = xpub .derive_pub( @@ -144,8 +144,8 @@ pub extern "C" fn xrp_sign_tx_bytes( // generate a qr code let sign_tx_result = ur_registry::pb::protoc::SignTransactionResult { sign_id: sign_tx.sign_id, - tx_id: format!("{}", tx_hash.to_uppercase()), - raw_tx: format!("{}", raw_tx_hex.clone()), + tx_id: tx_hash.to_uppercase().to_string(), + raw_tx: raw_tx_hex.clone().to_string(), }; let content = ur_registry::pb::protoc::payload::Content::SignTxResult(sign_tx_result); let payload = ur_registry::pb::protoc::Payload { @@ -168,7 +168,7 @@ pub extern "C" fn xrp_sign_tx_bytes( UREncodeResult::encode( ur_registry::bytes::Bytes::new(zip_data).try_into().unwrap(), ur_registry::bytes::Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() } @@ -187,7 +187,7 @@ pub extern "C" fn xrp_sign_tx( Ok(data) => UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -219,10 +219,7 @@ pub extern "C" fn xrp_check_tx( pub extern "C" fn is_keystone_xrp_tx(ur_data_ptr: PtrUR) -> bool { // if data can be parsed by protobuf, it is a keyston hot app version2 tx or it is a xrp tx let payload = build_payload(ur_data_ptr, QRCodeType::Bytes); - match payload { - Ok(_) => true, - Err(_) => false, - } + payload.is_ok() } #[no_mangle] @@ -244,9 +241,9 @@ pub extern "C" fn xrp_check_tx_bytes( let xfp = payload.xfp; let xfp_vec: [u8; 4] = hex::decode(xfp).unwrap().try_into().unwrap(); if mfp == xfp_vec { - return TransactionCheckResult::error(ErrorCodes::Success, "".to_string()).c_ptr(); + TransactionCheckResult::error(ErrorCodes::Success, "".to_string()).c_ptr() } else { - return TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr(); + TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr() } } Err(e) => TransactionCheckResult::from(KeystoneError::ProtobufError(e.to_string())).c_ptr(), diff --git a/rust/rust_c/src/zcash/mod.rs b/rust/rust_c/src/zcash/mod.rs index 2778b9efa..26a99ec15 100644 --- a/rust/rust_c/src/zcash/mod.rs +++ b/rust/rust_c/src/zcash/mod.rs @@ -73,9 +73,7 @@ pub extern "C" fn check_zcash_tx( disabled: bool, ) -> *mut TransactionCheckResult { if disabled { - return TransactionCheckResult::from(RustCError::UnsupportedTransaction(format!( - "zcash is not supported for slip39 and passphrase wallet now" - ))) + return TransactionCheckResult::from(RustCError::UnsupportedTransaction("zcash is not supported for slip39 and passphrase wallet now".to_string())) .c_ptr(); } let pczt = extract_ptr_with_type!(tx, ZcashPczt); @@ -120,7 +118,7 @@ pub extern "C" fn sign_zcash_tx(tx: PtrUR, seed: PtrBytes, seed_len: u32) -> *mu Ok(v) => UREncodeResult::encode( v, ZcashPczt::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), }, @@ -149,7 +147,7 @@ pub extern "C" fn rust_aes256_cbc_encrypt( let password = recover_c_char(password); let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; let key = sha256(password.as_bytes()); - let iv = GenericArray::from_slice(&iv); + let iv = GenericArray::from_slice(iv); let key = GenericArray::from_slice(&key); let ct = Aes256CbcEnc::new(key, iv).encrypt_padded_vec_mut::(data); SimpleResponse::success(convert_c_char(hex::encode(ct))).simple_c_ptr() @@ -167,7 +165,7 @@ pub extern "C" fn rust_aes256_cbc_decrypt( let password = recover_c_char(password); let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; let key = sha256(password.as_bytes()); - let iv = GenericArray::from_slice(&iv); + let iv = GenericArray::from_slice(iv); let key = GenericArray::from_slice(&key); match Aes256CbcDec::new(key, iv).decrypt_padded_vec_mut::(&data) { diff --git a/rust/sim_qr_reader/src/lib.rs b/rust/sim_qr_reader/src/lib.rs index 75122e9bf..12d94b7db 100644 --- a/rust/sim_qr_reader/src/lib.rs +++ b/rust/sim_qr_reader/src/lib.rs @@ -3,7 +3,7 @@ use image::DynamicImage; use quircs::{Code, Quirc}; use screenshots::Screen; use std::thread; -use std::time::{Duration, Instant}; +use std::time::{Duration}; #[cfg(target_os = "macos")] use cocoa::{appkit::NSScreen, base::nil, foundation::NSArray}; @@ -20,8 +20,8 @@ fn get_screen_scaling_factor() -> f64 { unsafe { let screens = NSScreen::screens(nil); let screen = NSArray::objectAtIndex(screens, 0); - let scale_factor = NSScreen::backingScaleFactor(screen); - scale_factor as f64 + + NSScreen::backingScaleFactor(screen) } #[cfg(target_os = "windows")] @@ -98,7 +98,7 @@ where if on_qr_code_detected(&content) { break; } - if let None = qr_area { + if qr_area.is_none() { qr_area = new_area; } if let Some(area) = qr_area { @@ -119,10 +119,10 @@ where fn get_qr_area(code: &Code, image: &DynamicImage) -> (i32, i32, u32, u32) { let points = code.corners; - let min_x = points.iter().map(|p| p.x).min().unwrap() as i32; - let min_y = points.iter().map(|p| p.y).min().unwrap() as i32; - let max_x = points.iter().map(|p| p.x).max().unwrap() as i32; - let max_y = points.iter().map(|p| p.y).max().unwrap() as i32; + let min_x = points.iter().map(|p| p.x).min().unwrap(); + let min_y = points.iter().map(|p| p.y).min().unwrap(); + let max_x = points.iter().map(|p| p.x).max().unwrap(); + let max_y = points.iter().map(|p| p.y).max().unwrap(); let width = (max_x - min_x) as u32; let height = (max_y - min_y) as u32; diff --git a/rust/zcash_vendor/src/pczt_ext.rs b/rust/zcash_vendor/src/pczt_ext.rs index 82f889028..c259f2962 100644 --- a/rust/zcash_vendor/src/pczt_ext.rs +++ b/rust/zcash_vendor/src/pczt_ext.rs @@ -110,7 +110,7 @@ fn is_transparent_coinbase(pczt: &Pczt) -> bool { } fn has_sapling(pczt: &Pczt) -> bool { - pczt.sapling().spends().len() > 0 || pczt.sapling().outputs().len() > 0 + !pczt.sapling().spends().is_empty() || !pczt.sapling().outputs().is_empty() } fn has_orchard(pczt: &Pczt) -> bool { @@ -156,15 +156,15 @@ fn digest_transparent_outputs(outputs: &[Output]) -> Hash { h.update(&value.to_le_bytes()); let len = output.script_pubkey().len(); h.update(&[len as u8]); - h.update(&output.script_pubkey()); + h.update(output.script_pubkey()); } h.finalize() } fn transparent_digest(pczt: &Pczt) -> TransparentDigests { TransparentDigests { - prevouts_digest: digest_transparent_prevouts(&pczt.transparent().inputs()), - sequence_digest: digest_transparent_sequence(&pczt.transparent().inputs()), - outputs_digest: digest_transparent_outputs(&pczt.transparent().outputs()), + prevouts_digest: digest_transparent_prevouts(pczt.transparent().inputs()), + sequence_digest: digest_transparent_sequence(pczt.transparent().inputs()), + outputs_digest: digest_transparent_outputs(pczt.transparent().outputs()), } } fn hash_transparent_tx_id(t_digests: Option) -> Hash { @@ -194,7 +194,7 @@ fn digest_orchard(pczt: &Pczt) -> Hash { nh.update(action.cv_net()); nh.update(action.spend().rk()); nh.update(&action.output().enc_ciphertext()[564..]); - nh.update(&action.output().out_ciphertext()); + nh.update(action.output().out_ciphertext()); } h.update(ch.finalize().as_bytes()); @@ -253,7 +253,7 @@ fn hash_sapling_outputs(pczt: &Pczt) -> Hash { nh.update(s_out.cv()); nh.update(&s_out.enc_ciphertext()[564..]); - nh.update(&s_out.out_ciphertext()); + nh.update(s_out.out_ciphertext()); } h.update(ch.finalize().as_bytes()); @@ -313,70 +313,68 @@ fn sheilded_sig_commitment(pczt: &Pczt, lock_time: u32, input_info: Option) -> Hash { if !has_transparent(pczt) { hash_transparent_tx_id(None) + } else if is_transparent_coinbase(pczt) || pczt.transparent().inputs().is_empty() { + hash_transparent_tx_id(Some(transparent_digest(pczt))) } else { - if is_transparent_coinbase(pczt) || pczt.transparent().inputs().is_empty() { - hash_transparent_tx_id(Some(transparent_digest(pczt))) - } else { - if let Some(input) = &input_info { - // this should have been checked earlier - assert_eq!(input.hash_type().encode(), SIGHASH_ALL); - } - //SIGHASH_ALL - let prevouts_digest = digest_transparent_prevouts(&pczt.transparent().inputs()); - - let amounts_digest = { - let mut h = hasher(ZCASH_TRANSPARENT_AMOUNTS_HASH_PERSONALIZATION); - pczt.transparent().inputs().iter().for_each(|input| { - h.update(&input.value().to_le_bytes()); - }); - h.finalize() - }; - - let scripts_digest = { - let mut h = hasher(ZCASH_TRANSPARENT_SCRIPTS_HASH_PERSONALIZATION); - pczt.transparent().inputs().iter().for_each(|input| { - //len should be a compact size - let len = input.script_pubkey().len(); - h.update(&[len as u8]); - h.update(&input.script_pubkey()); - }); - h.finalize() - }; - let sequence_digest = digest_transparent_sequence(&pczt.transparent().inputs()); - - let outputs_digest = digest_transparent_outputs(&pczt.transparent().outputs()); - - //S.2g.i: prevout (field encoding) - //S.2g.ii: value (8-byte signed little-endian) - //S.2g.iii: scriptPubKey (field encoding) - //S.2g.iv: nSequence (4-byte unsigned little-endian) - let mut ch = hasher(ZCASH_TRANSPARENT_INPUT_HASH_PERSONALIZATION); - if let Some(signable_input) = input_info { - let input = pczt - .transparent() - .inputs() - .get(*signable_input.index()) - .expect("valid by construction"); - ch.update(input.prevout_txid()); - ch.update(&input.prevout_index().to_le_bytes()); - ch.update(&signable_input.value().to_i64_le_bytes()); - let len = signable_input.script_pubkey().0.len(); - ch.update(&[len as u8]); - ch.update(&signable_input.script_pubkey().0); - ch.update(&input.sequence().unwrap_or(0xffffffff).to_le_bytes()); - } - let txin_sig_digest = ch.finalize(); - - let mut h = hasher(ZCASH_TRANSPARENT_HASH_PERSONALIZATION); - h.update(&[SIGHASH_ALL]); - h.update(prevouts_digest.as_bytes()); - h.update(amounts_digest.as_bytes()); - h.update(scripts_digest.as_bytes()); - h.update(sequence_digest.as_bytes()); - h.update(outputs_digest.as_bytes()); - h.update(txin_sig_digest.as_bytes()); + if let Some(input) = &input_info { + // this should have been checked earlier + assert_eq!(input.hash_type().encode(), SIGHASH_ALL); + } + //SIGHASH_ALL + let prevouts_digest = digest_transparent_prevouts(pczt.transparent().inputs()); + + let amounts_digest = { + let mut h = hasher(ZCASH_TRANSPARENT_AMOUNTS_HASH_PERSONALIZATION); + pczt.transparent().inputs().iter().for_each(|input| { + h.update(&input.value().to_le_bytes()); + }); + h.finalize() + }; + + let scripts_digest = { + let mut h = hasher(ZCASH_TRANSPARENT_SCRIPTS_HASH_PERSONALIZATION); + pczt.transparent().inputs().iter().for_each(|input| { + //len should be a compact size + let len = input.script_pubkey().len(); + h.update(&[len as u8]); + h.update(input.script_pubkey()); + }); h.finalize() + }; + let sequence_digest = digest_transparent_sequence(pczt.transparent().inputs()); + + let outputs_digest = digest_transparent_outputs(pczt.transparent().outputs()); + + //S.2g.i: prevout (field encoding) + //S.2g.ii: value (8-byte signed little-endian) + //S.2g.iii: scriptPubKey (field encoding) + //S.2g.iv: nSequence (4-byte unsigned little-endian) + let mut ch = hasher(ZCASH_TRANSPARENT_INPUT_HASH_PERSONALIZATION); + if let Some(signable_input) = input_info { + let input = pczt + .transparent() + .inputs() + .get(*signable_input.index()) + .expect("valid by construction"); + ch.update(input.prevout_txid()); + ch.update(&input.prevout_index().to_le_bytes()); + ch.update(&signable_input.value().to_i64_le_bytes()); + let len = signable_input.script_pubkey().0.len(); + ch.update(&[len as u8]); + ch.update(&signable_input.script_pubkey().0); + ch.update(&input.sequence().unwrap_or(0xffffffff).to_le_bytes()); } + let txin_sig_digest = ch.finalize(); + + let mut h = hasher(ZCASH_TRANSPARENT_HASH_PERSONALIZATION); + h.update(&[SIGHASH_ALL]); + h.update(prevouts_digest.as_bytes()); + h.update(amounts_digest.as_bytes()); + h.update(scripts_digest.as_bytes()); + h.update(sequence_digest.as_bytes()); + h.update(outputs_digest.as_bytes()); + h.update(txin_sig_digest.as_bytes()); + h.finalize() } } @@ -386,13 +384,13 @@ where T::Error: From, T::Error: From, { - Ok(llsigner + llsigner .sign_transparent_with::(|pczt, signable, tx_modifiable| { let lock_time = determine_lock_time(pczt.global(), pczt.transparent().inputs()) .map_err(|()| transparent::pczt::ParseError::InvalidRequiredHeightLocktime)?; signable .inputs_mut() - .into_iter() + .iter_mut() .enumerate() .try_for_each(|(i, input)| { signer.sign_transparent(i, input, |signable_input| { @@ -421,7 +419,7 @@ where .sign_orchard_with::(|pczt, signable, tx_modifiable| { let lock_time = determine_lock_time(pczt.global(), pczt.transparent().inputs()) .expect("didn't fail earlier"); - signable.actions_mut().into_iter().try_for_each(|action| { + signable.actions_mut().iter_mut().try_for_each(|action| { match action.spend().value().map(|v| v.inner()) { //dummy spend maybe Some(0) | None => { @@ -437,7 +435,7 @@ where } Ok(()) }) - })?) + }) } #[cfg(test)] From e040887edc79c46c9ed34f037d8d51d4fe0c2ab3 Mon Sep 17 00:00:00 2001 From: soralit Date: Thu, 26 Dec 2024 09:07:34 +0800 Subject: [PATCH 14/31] style: run cargo fix --- rust/apps/bitcoin/src/addresses/address.rs | 2 +- rust/apps/bitcoin/src/transactions/legacy/output.rs | 4 ++-- .../solana/src/solana_lib/jupiter_v6/instructions.rs | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rust/apps/bitcoin/src/addresses/address.rs b/rust/apps/bitcoin/src/addresses/address.rs index aac67770b..8f5accf4a 100644 --- a/rust/apps/bitcoin/src/addresses/address.rs +++ b/rust/apps/bitcoin/src/addresses/address.rs @@ -17,7 +17,7 @@ use bitcoin::address::AddressData as Payload; use bitcoin::blockdata::script; use bitcoin::script::PushBytesBuf; use bitcoin::secp256k1::{Secp256k1, XOnlyPublicKey}; -use bitcoin::{base58, Script, ScriptBuf, TapNodeHash}; +use bitcoin::{base58, ScriptBuf, TapNodeHash}; use bitcoin::{CompressedPublicKey, PublicKey}; use bitcoin::{PubkeyHash, ScriptHash}; use bitcoin::{WitnessProgram, WitnessVersion}; diff --git a/rust/apps/bitcoin/src/transactions/legacy/output.rs b/rust/apps/bitcoin/src/transactions/legacy/output.rs index e8c5b0696..07552b60d 100644 --- a/rust/apps/bitcoin/src/transactions/legacy/output.rs +++ b/rust/apps/bitcoin/src/transactions/legacy/output.rs @@ -3,8 +3,8 @@ use crate::collect; use crate::errors::{BitcoinError, Result}; use alloc::string::{String, ToString}; use alloc::vec::Vec; -use bitcoin::address::AddressData as Payload; -use bitcoin::{self, Amount, ScriptBuf}; + +use bitcoin::{self, Amount}; use core::str::FromStr; use ur_registry::pb::protoc; use ur_registry::pb::protoc::sign_transaction::Transaction::{BchTx, BtcTx, DashTx, LtcTx}; diff --git a/rust/apps/solana/src/solana_lib/jupiter_v6/instructions.rs b/rust/apps/solana/src/solana_lib/jupiter_v6/instructions.rs index 756b0b985..0ce4d0d59 100644 --- a/rust/apps/solana/src/solana_lib/jupiter_v6/instructions.rs +++ b/rust/apps/solana/src/solana_lib/jupiter_v6/instructions.rs @@ -1,7 +1,7 @@ use alloc::string::String; use alloc::vec::Vec; -use borsh::{from_slice, BorshDeserialize}; +use borsh::{BorshDeserialize}; use serde_derive::Serialize; use crate::solana_lib::solana_program::errors::ProgramError; @@ -240,25 +240,25 @@ impl Dispatch for JupiterInstructions { // sharedAccountsRoute methodId = sighash(SIGHASH_GLOBAL_NAMESPACE, "shared_accounts_route") borsh::from_slice::(ix_data) .map(JupiterInstructions::SharedAccountsRoute) - .map_err(|e| JupiterError::UnknownJupiterInstruction.into()) + .map_err(|_e| JupiterError::UnknownJupiterInstruction.into()) } "e517cb977ae3ad2a" => { // route methodId = sighash(SIGHASH_GLOBAL_NAMESPACE, "route") borsh::from_slice::(ix_data) .map(JupiterInstructions::Route) - .map_err(|e| JupiterError::UnknownJupiterInstruction.into()) + .map_err(|_e| JupiterError::UnknownJupiterInstruction.into()) } "d033ef977b2bed5c" => { // exactOutRoute methodId = sighash(SIGHASH_GLOBAL_NAMESPACE, "exact_out_route") borsh::from_slice::(ix_data) .map(JupiterInstructions::ExactOutRoute) - .map_err(|e| JupiterError::UnknownJupiterInstruction.into()) + .map_err(|_e| JupiterError::UnknownJupiterInstruction.into()) } "b0d169a89a7d453e" => { // sharedAccountsExactOutRoute methodId = sighash(SIGHASH_GLOBAL_NAMESPACE, "shared_accounts_exact_out_route") borsh::from_slice::(ix_data) .map(JupiterInstructions::SharedAccountsExactOutRoute) - .map_err(|e| JupiterError::UnknownJupiterInstruction.into()) + .map_err(|_e| JupiterError::UnknownJupiterInstruction.into()) } _ => Err(JupiterError::UnknownJupiterInstruction.into()), } From d9b3125157073d812cddc8e95cdcc77d8b723236 Mon Sep 17 00:00:00 2001 From: soralit Date: Thu, 26 Dec 2024 09:47:20 +0800 Subject: [PATCH 15/31] style: fix warnings --- rust/apps/arweave/src/data_item.rs | 1 + rust/apps/bitcoin/src/lib.rs | 2 +- .../src/transactions/psbt/wrapped_psbt.rs | 2 +- rust/apps/cardano/src/structs.rs | 49 ++++++------------- rust/apps/stellar/src/strkeys.rs | 1 + rust/apps/ton/src/messages/jetton.rs | 2 +- rust/apps/ton/src/messages/nft.rs | 2 +- rust/apps/ton/src/vendor/message/jetton.rs | 2 + rust/apps/ton/src/vendor/message/transfer.rs | 2 + rust/apps/ton/src/vendor/wallet/mod.rs | 2 + rust/rust_c/src/stellar/mod.rs | 2 +- .../wallet/multi_coins_wallet/arconnect.rs | 4 +- rust/zcash_vendor/src/pczt_ext.rs | 4 ++ 13 files changed, 33 insertions(+), 42 deletions(-) diff --git a/rust/apps/arweave/src/data_item.rs b/rust/apps/arweave/src/data_item.rs index 45466900b..83a0d9753 100644 --- a/rust/apps/arweave/src/data_item.rs +++ b/rust/apps/arweave/src/data_item.rs @@ -85,6 +85,7 @@ impl_public_struct!(DataItem { raw_data: Vec }); +#[allow(unused)] enum SignatureType { ARWEAVE = 1, ED25519, diff --git a/rust/apps/bitcoin/src/lib.rs b/rust/apps/bitcoin/src/lib.rs index 2e1173ed3..955fc914c 100644 --- a/rust/apps/bitcoin/src/lib.rs +++ b/rust/apps/bitcoin/src/lib.rs @@ -114,7 +114,7 @@ pub fn sign_raw_tx( let signed_tx = sign_legacy_tx(tx_data, seed)?; Ok(( hex::encode(signed_tx), - tx_data.transaction.txid().to_string(), + tx_data.transaction.compute_txid().to_string(), )) } diff --git a/rust/apps/bitcoin/src/transactions/psbt/wrapped_psbt.rs b/rust/apps/bitcoin/src/transactions/psbt/wrapped_psbt.rs index dcf4fca3e..3a5105926 100644 --- a/rust/apps/bitcoin/src/transactions/psbt/wrapped_psbt.rs +++ b/rust/apps/bitcoin/src/transactions/psbt/wrapped_psbt.rs @@ -104,7 +104,7 @@ impl WrappedPsbt { .input .get(index) .ok_or(BitcoinError::InvalidInput)?; - if !tx_in.previous_output.txid.eq(&prev_tx.txid()) { + if !tx_in.previous_output.txid.eq(&prev_tx.compute_txid()) { return Err(BitcoinError::InvalidInput); } let prevout = prev_tx.output.get(tx_in.previous_output.vout as usize); diff --git a/rust/apps/cardano/src/structs.rs b/rust/apps/cardano/src/structs.rs index 5d085c03e..5a40ee92a 100644 --- a/rust/apps/cardano/src/structs.rs +++ b/rust/apps/cardano/src/structs.rs @@ -11,6 +11,7 @@ use cardano_serialization_lib::protocol_types::{ use cardano_serialization_lib::protocol_types::DRepKind; +use cardano_serialization_lib::CredKind; use cardano_serialization_lib::{ protocol_types::FixedTransaction as Transaction, protocol_types::VoteKind, NetworkIdKind, }; @@ -100,6 +101,7 @@ const LABEL_POOL: &str = "Pool"; const LABEL_DEPOSIT: &str = "Deposit"; const LABEL_DREP: &str = "DRep"; const LABEL_VOTE: &str = "Vote"; +#[allow(unused)] const LABEL_ABCHOR: &str = "Anchor"; const LABEL_ANCHOR_URL: &str = "Anchor URL"; const LABEL_ANCHOR_DATA_HASH: &str = "Anchor Data Hash"; @@ -150,29 +152,6 @@ impl_public_struct!(ParsedCardanoMultiAsset { value: u64 }); -#[derive(Clone)] -enum CardanoCertAction { - Registration(Registration), - Deregistration(Deregistration), - Delegation(Delegation), -} - -#[derive(Clone)] -struct Registration { - stake_key: RewardAddress, -} - -#[derive(Clone)] -struct Deregistration { - stake_key: RewardAddress, -} - -#[derive(Clone)] -struct Delegation { - pool: String, - stake_key: RewardAddress, -} - impl ParsedCardanoSignData { pub fn build(sign_data: Vec, derivation_path: String, xpub: String) -> R { let sign_structure = CardanoSignStructure::from_cbor(sign_data.clone()); @@ -505,12 +484,12 @@ impl ParsedCardanoTx { CertField { label: LABEL_HOT_KEY.to_string(), value: match _cert.committee_hot_credential().kind() { - _Ed25519KeyHash => _cert + CredKind::Key => _cert .committee_hot_credential() .to_keyhash() .unwrap() .to_string(), - _ScriptHash => _cert + CredKind::Script => _cert .committee_hot_credential() .to_scripthash() .unwrap() @@ -520,12 +499,12 @@ impl ParsedCardanoTx { CertField { label: LABEL_COLD_KEY.to_string(), value: match _cert.committee_cold_credential().kind() { - _Ed25519KeyHash => _cert + CredKind::Key => _cert .committee_cold_credential() .to_keyhash() .unwrap() .to_string(), - _ScriptHash => _cert + CredKind::Script => _cert .committee_cold_credential() .to_scripthash() .unwrap() @@ -542,12 +521,12 @@ impl ParsedCardanoTx { let mut fields = vec![CertField { label: LABEL_COLD_KEY.to_string(), value: match _cert.committee_cold_credential().kind() { - _Ed25519KeyHash => _cert + CredKind::Key => _cert .committee_cold_credential() .to_keyhash() .unwrap() .to_string(), - _ScriptHash => _cert + CredKind::Script => _cert .committee_cold_credential() .to_scripthash() .unwrap() @@ -572,7 +551,7 @@ impl ParsedCardanoTx { if let Some(_cert) = cert.as_drep_deregistration() { let deposit = normalize_coin(u64::from(&_cert.coin())); let (variant1, variant1_label) = match _cert.voting_credential().kind() { - _Ed25519KeyHash => ( + CredKind::Key => ( _cert .voting_credential() .to_keyhash() @@ -581,7 +560,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - _ScriptHash => ( + CredKind::Script => ( _cert .voting_credential() .to_scripthash() @@ -609,7 +588,7 @@ impl ParsedCardanoTx { if let Some(_cert) = cert.as_drep_registration() { let deposit = normalize_coin(u64::from(&_cert.coin())); let (variant1, variant1_label) = match _cert.voting_credential().kind() { - _Ed25519KeyHash => ( + CredKind::Key => ( _cert .voting_credential() .to_keyhash() @@ -618,7 +597,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - _ScriptHash => ( + CredKind::Script => ( _cert .voting_credential() .to_scripthash() @@ -660,7 +639,7 @@ impl ParsedCardanoTx { if let Some(_cert) = cert.as_drep_update() { let anchor_data_hash = _cert.anchor().map(|anchor| anchor.anchor_data_hash().to_string()); let (variant1, variant1_label) = match _cert.voting_credential().kind() { - _Ed25519KeyHash => ( + CredKind::Key => ( _cert .voting_credential() .to_keyhash() @@ -669,7 +648,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - _ScriptHash => ( + CredKind::Script => ( _cert .voting_credential() .to_scripthash() diff --git a/rust/apps/stellar/src/strkeys.rs b/rust/apps/stellar/src/strkeys.rs index 86e8f8168..47e9b6ed3 100644 --- a/rust/apps/stellar/src/strkeys.rs +++ b/rust/apps/stellar/src/strkeys.rs @@ -5,6 +5,7 @@ use keystore::algorithms::ed25519::slip10_ed25519::get_private_key_by_seed; use keystore::errors::Result; #[derive(Clone, Copy, Debug, PartialEq)] +#[allow(non_camel_case_types)] pub enum StrKeyType { STRKEY_PUBKEY = 6 << 3, STRKEY_PRIVKEY = 18 << 3, diff --git a/rust/apps/ton/src/messages/jetton.rs b/rust/apps/ton/src/messages/jetton.rs index c7f931c5e..9db4469fb 100644 --- a/rust/apps/ton/src/messages/jetton.rs +++ b/rust/apps/ton/src/messages/jetton.rs @@ -21,6 +21,7 @@ pub const JETTON_TRANSFER: u32 = 0xf8a7ea5; // pub const JETTON_BURN_NOTIFICATION: u32 = 0x7bdd97de; #[derive(Clone, Debug, Serialize)] +#[non_exhaustive] pub enum JettonMessage { JettonTransferMessage(JettonTransferMessage), } @@ -87,7 +88,6 @@ impl ParseCell for JettonTransferMessage { let comment = Comment::parse(child); let payload = Some(hex::encode(child.data.clone())); - ref_index += 1; (payload, comment.ok()) } else { (None, None) diff --git a/rust/apps/ton/src/messages/nft.rs b/rust/apps/ton/src/messages/nft.rs index 8261deddc..e47716268 100644 --- a/rust/apps/ton/src/messages/nft.rs +++ b/rust/apps/ton/src/messages/nft.rs @@ -10,6 +10,7 @@ use super::{traits::ParseCell, Comment}; pub const NFT_TRANSFER: u32 = 0x5fcc3d14; #[derive(Clone, Debug, Serialize)] +#[non_exhaustive] pub enum NFTMessage { NFTTransferMessage(NFTTransferMessage), } @@ -67,7 +68,6 @@ impl ParseCell for NFTTransferMessage { let comment = Comment::parse(child); let payload = Some(hex::encode(child.data.clone())); - ref_index += 1; (payload, comment.ok()) } else { (None, None) diff --git a/rust/apps/ton/src/vendor/message/jetton.rs b/rust/apps/ton/src/vendor/message/jetton.rs index 4ac6985e2..9fe74131c 100644 --- a/rust/apps/ton/src/vendor/message/jetton.rs +++ b/rust/apps/ton/src/vendor/message/jetton.rs @@ -1,3 +1,5 @@ +#![allow(unused)] + use alloc::sync::Arc; use num_bigint::BigUint; diff --git a/rust/apps/ton/src/vendor/message/transfer.rs b/rust/apps/ton/src/vendor/message/transfer.rs index 9040cdd08..002eac3fc 100644 --- a/rust/apps/ton/src/vendor/message/transfer.rs +++ b/rust/apps/ton/src/vendor/message/transfer.rs @@ -1,3 +1,5 @@ +#![allow(unused)] + use alloc::sync::Arc; use num_bigint::BigUint; diff --git a/rust/apps/ton/src/vendor/wallet/mod.rs b/rust/apps/ton/src/vendor/wallet/mod.rs index c343dbb8f..df3822859 100644 --- a/rust/apps/ton/src/vendor/wallet/mod.rs +++ b/rust/apps/ton/src/vendor/wallet/mod.rs @@ -55,6 +55,7 @@ impl WalletVersion { Ok(Arc::new(data_cell)) } + #[allow(unused)] pub fn has_op(&self) -> bool { matches!(self, WalletVersion::V4R2) } @@ -69,6 +70,7 @@ pub struct TonWallet { } impl TonWallet { + #[allow(unused)] pub fn derive( workchain: i32, version: WalletVersion, diff --git a/rust/rust_c/src/stellar/mod.rs b/rust/rust_c/src/stellar/mod.rs index 2b840598a..d23855c2e 100644 --- a/rust/rust_c/src/stellar/mod.rs +++ b/rust/rust_c/src/stellar/mod.rs @@ -81,7 +81,7 @@ fn build_signature_data( sign_request: StellarSignRequest, ) -> PtrT { let data = StellarSignature::new(sign_request.get_request_id(), signature.to_vec()) - .to_bytes() + .try_into() .unwrap(); UREncodeResult::encode( data, diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs index e8009941f..41da4736f 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs @@ -42,7 +42,7 @@ pub extern "C" fn get_connect_arconnect_wallet_ur( device, ); UREncodeResult::encode( - arweave_account.to_bytes().unwrap(), + arweave_account.try_into().unwrap(), ArweaveCryptoAccount::get_registry_type().get_type(), FRAGMENT_MAX_LENGTH_DEFAULT, ) @@ -65,7 +65,7 @@ pub extern "C" fn get_connect_arconnect_wallet_ur_from_xpub( device, ); UREncodeResult::encode( - arweave_account.to_bytes().unwrap(), + arweave_account.try_into().unwrap(), ArweaveCryptoAccount::get_registry_type().get_type(), FRAGMENT_MAX_LENGTH_DEFAULT, ) diff --git a/rust/zcash_vendor/src/pczt_ext.rs b/rust/zcash_vendor/src/pczt_ext.rs index c259f2962..e08e9e25d 100644 --- a/rust/zcash_vendor/src/pczt_ext.rs +++ b/rust/zcash_vendor/src/pczt_ext.rs @@ -42,8 +42,11 @@ const ZCASH_SAPLING_OUTPUTS_COMPACT_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdSOu const ZCASH_SAPLING_OUTPUTS_MEMOS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdSOutM__Hash"; const ZCASH_SAPLING_OUTPUTS_NONCOMPACT_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdSOutN__Hash"; +#[allow(unused)] const ZCASH_AUTH_PERSONALIZATION_PREFIX: &[u8; 12] = b"ZTxAuthHash_"; +#[allow(unused)] const ZCASH_AUTH_SCRIPTS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxAuthTransHash"; +#[allow(unused)] const ZCASH_SAPLING_SIGS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxAuthSapliHash"; #[cfg(zcash_unstable = "zfuture")] const ZCASH_TZE_WITNESSES_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxAuthTZE__Hash"; @@ -52,6 +55,7 @@ const ZCASH_ORCHARD_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrchardHash"; const ZCASH_ORCHARD_ACTIONS_COMPACT_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcActCHash"; const ZCASH_ORCHARD_ACTIONS_MEMOS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcActMHash"; const ZCASH_ORCHARD_ACTIONS_NONCOMPACT_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcActNHash"; +#[allow(unused)] const ZCASH_ORCHARD_SIGS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxAuthOrchaHash"; const ZCASH_TRANSPARENT_INPUT_HASH_PERSONALIZATION: &[u8; 16] = b"Zcash___TxInHash"; From b10d0ec22a8d5944f5fb65d6be11c7a03df3844d Mon Sep 17 00:00:00 2001 From: ww3512687 <15809188520@163.com> Date: Thu, 26 Dec 2024 13:51:35 +0800 Subject: [PATCH 16/31] 1. split home widgets 2. split connect wallet --- CMakeLists.txt | 44 +- build.bat | 3 +- build.sh | 25 +- src/device_settings.c | 6 +- src/ui/gui_analyze/gui_resolve_ur.c | 9 +- .../multi/cyberpunk/gui_cyberpunk_analyze.c | 1 - src/ui/gui_chain/gui_chain.c | 2 + src/ui/gui_model/gui_model.c | 6 +- src/ui/gui_views/gui_home_view.c | 4 +- .../gui_key_derivation_request_view.c | 4 +- .../{general => }/gui_standard_receive_view.c | 0 .../{general => }/gui_usb_transport_view.c | 0 .../gui_wallet/multi/cyberpunk/gui_wallet.h | 1 - .../gui_widgets/gui_create_wallet_widgets.c | 4 +- src/ui/gui_widgets/gui_scan_widgets.c | 8 +- .../gui_widgets/gui_select_address_widgets.c | 2 +- .../gui_transaction_detail_widgets.c | 9 +- .../gui_transaction_signature_widgets.c | 4 +- src/ui/gui_widgets/gui_utxo_receive_widgets.c | 14 +- .../cyberpunk/gui_connect_wallet_widgets.c | 1477 +++++++++++++++++ .../cyberpunk/gui_cyberpunk_home_widgets.c | 502 +++++- .../cyberpunk/gui_cyberpunk_home_widgets.h | 2 + .../general}/gui_connect_wallet_widgets.c | 24 +- .../multi/general/gui_general_home_widgets.c | 683 +++++++- .../multi/general/gui_general_home_widgets.h | 5 +- .../gui_multi_accounts_receive_widgets.c | 0 .../gui_multi_accounts_receive_widgets.h | 0 .../{ => multi}/gui_connect_wallet_widgets.h | 32 +- src/ui/gui_widgets/multi/gui_home_widgets.c | 702 -------- src/ui/gui_widgets/multi/gui_home_widgets.h | 1 + .../gui_key_derivation_request_widgets.c | 184 +- .../gui_key_derivation_request_widgets.h | 0 .../gui_standard_receive_widgets.c | 69 +- .../gui_standard_receive_widgets.h | 0 .../eapdu_services/service_export_address.c | 2 + 35 files changed, 2893 insertions(+), 936 deletions(-) rename src/ui/gui_views/multi/{general => }/gui_key_derivation_request_view.c (98%) rename src/ui/gui_views/multi/{general => }/gui_standard_receive_view.c (100%) rename src/ui/gui_views/multi/{general => }/gui_usb_transport_view.c (100%) create mode 100644 src/ui/gui_widgets/multi/cyberpunk/gui_connect_wallet_widgets.c rename src/ui/gui_widgets/{ => multi/general}/gui_connect_wallet_widgets.c (99%) rename src/ui/gui_widgets/multi/{ => general}/gui_multi_accounts_receive_widgets.c (100%) rename src/ui/gui_widgets/multi/{ => general}/gui_multi_accounts_receive_widgets.h (100%) rename src/ui/gui_widgets/{ => multi}/gui_connect_wallet_widgets.h (89%) delete mode 100644 src/ui/gui_widgets/multi/gui_home_widgets.c rename src/ui/gui_widgets/multi/{general => }/gui_key_derivation_request_widgets.c (98%) rename src/ui/gui_widgets/multi/{general => }/gui_key_derivation_request_widgets.h (100%) rename src/ui/gui_widgets/multi/{general => }/gui_standard_receive_widgets.c (98%) rename src/ui/gui_widgets/multi/{general => }/gui_standard_receive_widgets.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 530d2bc31..bcc21d271 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ endif() set(CMAKE_C_FLAGS_DEBUG "-O0 -g2 -ggdb") set(CMAKE_C_FLAGS_RELEASE "-O3") -# add_subdirectory(rust) +add_subdirectory(rust) # add definition function(add_definition_with_message OPTION_NAME) @@ -58,22 +58,18 @@ set(CRYPTO_INCLUDE_PATH ) set(WIDGET_PATH "multi") -# if(CYBERPUNK) -# set(WIDGET_SUBPATH "multi/cyberpunk") -# add_compile_definitions(CYBERPUNK_VERSION) -# elseif(BTC_ONLY) -# set(WIDGET_SUBPATH "btc_only/multi_sig") -# set(WIDGET_PATH "btc_only") -# add_compile_definitions(BTC_ONLY) -# add_compile_definitions(EXCLUDE_RUSTC) -# else() -# add_compile_definitions(GENERAL_VERSION) -# set(WIDGET_SUBPATH "multi/general") -# endif() -# add_compile_definitions(GENERAL_VERSION) -# set(WIDGET_SUBPATH "multi/general") -set(WIDGET_SUBPATH "multi/cyberpunk") -add_compile_definitions(CYBERPUNK_VERSION) +if(CYBERPUNK) + set(WIDGET_SUBPATH "multi/cyberpunk") + add_compile_definitions(CYBERPUNK_VERSION) +elseif(BTC_ONLY) + set(WIDGET_SUBPATH "btc_only/multi_sig") + set(WIDGET_PATH "btc_only") + add_compile_definitions(BTC_ONLY) + add_compile_definitions(EXCLUDE_RUSTC) +else() + add_compile_definitions(GENERAL_VERSION) + set(WIDGET_SUBPATH "multi/general") +endif() set(GUI_CUSTOM_INCLUDE_PATH src/ui/gui_widgets/${WIDGET_SUBPATH} @@ -300,20 +296,6 @@ if(COMPILE_KEYSTONE) src/cm_backtrace/fault_handler/gcc/cmb_fault.s ) - message(STATUS "WEBUSB_PROTOCOL: ${WEBUSB_PROTOCOL}") - - # if(BTC_ONLY) - # set(excluded_directories - # src/ui/gui_chain/others - # src/ui/gui_widgets/general - # src/ui/gui_views/general - # src/webusb_protocol/general) - # else() - # set(excluded_directories - # src/ui/gui_views/btc_only - # src/ui/gui_widgets/btc_only) - # endif() - foreach(directory ${excluded_directories}) file(GLOB_RECURSE excluded_files "${directory}/*") list(REMOVE_ITEM objsrc ${excluded_files}) diff --git a/build.bat b/build.bat index 801d3f3eb..4061cf4cf 100644 --- a/build.bat +++ b/build.bat @@ -12,7 +12,7 @@ SET LANGUAGE_PATH=%CD%\src\ui\lv_i18n SET LANGUAGE_SCRIPT=py data_loader.py SET RUST_C_PATH=%CD%\rust\rust_c -SET "build_options=log copy production screen debug format release rebuild btc_only simulator language clean" +SET "build_options=log copy production screen debug format release rebuild btc_only cyberpunk simulator language clean" FOR %%O IN (%build_options%) DO SET "build_%%O=false" FOR %%i in (%*) DO ( @@ -54,6 +54,7 @@ IF "%build_language%"=="true" ( SET cmake_parm= IF "%build_production%"=="true" SET "cmake_parm=%cmake_parm% -DBUILD_PRODUCTION=true" IF "%build_btc_only%"=="true" SET "cmake_parm=%cmake_parm% -DBTC_ONLY=true" +IF "%build_cyberpunk%"=="true" SET "cmake_parm=%cmake_parm% -DCYBERPUNK=true" IF "%build_screen%"=="true" SET "cmake_parm=%cmake_parm% -DENABLE_SCREEN_SHOT=true" IF "%build_debug%"=="true" SET "cmake_parm=%cmake_parm% -DDEBUG_MEMORY=true" diff --git a/build.sh b/build.sh index c90e57eca..76b090047 100644 --- a/build.sh +++ b/build.sh @@ -83,31 +83,22 @@ execute_build() { cmake_parm="${cmake_parm} -DDEBUG_MEMORY=true" fi - echo "Building project.............." - echo "cmake_parm: $cmake_parm" if [[ "${build_options[simulator]}" == true ]]; then - echo "Building project---------------" mkdir -p "$BUILD_SIMULATOR_FOLDER" pushd "$BUILD_SIMULATOR_FOLDER" cmake -G "Unix Makefiles" -DBUILD_TYPE=Simulator $cmake_parm .. make -j16 popd else - echo "Building project.............." - mkdir -p "$BUILD_SIMULATOR_FOLDER" - pushd "$BUILD_SIMULATOR_FOLDER" - cmake -G "Unix Makefiles" -DBUILD_TYPE=Simulator $cmake_parm .. - make -j16 + pushd "$BUILD_FOLDER" + cmake -G "Unix Makefiles" $cmake_parm .. + if [[ "${build_options[log]}" == true ]]; then + make -j16 > makefile.log 2>&1 + else + make -j16 + fi + python3 padding_bin_file.py mh1903.bin popd - # pushd "$BUILD_FOLDER" - # cmake -G "Unix Makefiles" $cmake_parm .. - # if [[ "${build_options[log]}" == true ]]; then - # make -j16 > makefile.log 2>&1 - # else - # make -j16 - # fi - # python3 padding_bin_file.py mh1903.bin - # popd fi if [[ "${build_options[copy]}" == true ]]; then diff --git a/src/device_settings.c b/src/device_settings.c index de0b74773..bf66f5874 100644 --- a/src/device_settings.c +++ b/src/device_settings.c @@ -275,12 +275,10 @@ void WipeDevice(void) // reset all account address index in receive page { void GuiResetAllUtxoAddressIndex(void); -#ifndef BTC_ONLY + GuiResetAllUtxoAddressIndex(); +#ifdef GENERAL_VERSION void GuiResetAllEthAddressIndex(void); void GuiResetAllStandardAddressIndex(void); -#endif - GuiResetAllUtxoAddressIndex(); -#ifndef BTC_ONLY GuiResetAllEthAddressIndex(); GuiResetAllStandardAddressIndex(); #endif diff --git a/src/ui/gui_analyze/gui_resolve_ur.c b/src/ui/gui_analyze/gui_resolve_ur.c index f878b9ef1..37567135f 100644 --- a/src/ui/gui_analyze/gui_resolve_ur.c +++ b/src/ui/gui_analyze/gui_resolve_ur.c @@ -10,12 +10,12 @@ #include "gui_views.h" #ifdef BTC_ONLY -#include "gui_key_derivation_request_widgets.h" #include "gui_import_multisig_wallet_info_widgets.h" +#include "gui_create_multisig_wallet_widgets.h" #endif #ifdef GENERAL_VERSION -#include "gui_create_multisig_wallet_widgets.h" +#include "gui_key_derivation_request_widgets.h" #endif // The order of the enumeration must be guaranteed @@ -67,11 +67,12 @@ void handleURResult(URParseResult *urResult, URParseMultiResult *urMultiResult, case WebAuthResult: GuiSetWebAuthResultData(urResult, urMultiResult, is_multi); break; -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION case KeyDerivationRequest: GuiSetKeyDerivationRequestData(urResult, urMultiResult, is_multi); break; -#else +#endif +#ifdef BTC_ONLY // case MultisigWalletImport: // GuiSetMultisigImportWalletDataByQRCode(urResult, urMultiResult, is_multi); // break; diff --git a/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c b/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c index 1cc8335fb..7066cb2bd 100644 --- a/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c +++ b/src/ui/gui_analyze/multi/cyberpunk/gui_cyberpunk_analyze.c @@ -6,6 +6,5 @@ GetCustomContainerFunc GetOtherChainCustomFunc(char *funcName) if (!strcmp(funcName, "GuiZcashOverview")) { return GuiZcashOverview; } - return NULL; } diff --git a/src/ui/gui_chain/gui_chain.c b/src/ui/gui_chain/gui_chain.c index e4d9cdb02..f26d66486 100644 --- a/src/ui/gui_chain/gui_chain.c +++ b/src/ui/gui_chain/gui_chain.c @@ -100,9 +100,11 @@ PtrT_TransactionCheckResult CheckUrResult(uint8_t viewType) GuiChainCoinType ViewTypeToChainTypeSwitch(uint8_t viewType) { +#ifdef GENERAL_VERSION if (viewType == CosmosTx || viewType == CosmosEvmTx) { return GuiGetCosmosTxChain(); } +#endif const ViewHandlerEntry *entry = GetViewHandlerEntry(viewType); if (entry != NULL) { diff --git a/src/ui/gui_model/gui_model.c b/src/ui/gui_model/gui_model.c index c8a8f81c0..646b1068f 100644 --- a/src/ui/gui_model/gui_model.c +++ b/src/ui/gui_model/gui_model.c @@ -852,14 +852,12 @@ static int32_t ModelDelWallet(const void *inData, uint32_t inDataLen) if (ret == SUCCESS_CODE) { // reset address index in receive page { + GuiResetCurrentUtxoAddressIndex(accountIndex); void GuiResetCurrentUtxoAddressIndex(uint8_t index); -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION void GuiResetCurrentEthAddressIndex(uint8_t index); void GuiResetCurrentStandardAddressIndex(uint8_t index); void GuiResetCurrentMultiAccountsCache(uint8_t index); -#endif - GuiResetCurrentUtxoAddressIndex(accountIndex); -#ifndef BTC_ONLY GuiResetCurrentEthAddressIndex(accountIndex); GuiResetCurrentStandardAddressIndex(accountIndex); GuiResetCurrentMultiAccountsCache(accountIndex); diff --git a/src/ui/gui_views/gui_home_view.c b/src/ui/gui_views/gui_home_view.c index 3c151dff8..02ccee2c0 100644 --- a/src/ui/gui_views/gui_home_view.c +++ b/src/ui/gui_views/gui_home_view.c @@ -48,7 +48,7 @@ int32_t GuiHomeViewEventProcess(void *self, uint16_t usEvent, void *param, uint1 case SIG_INIT_GET_CURRENT_WALLET_DESC: GuiHomeSetWalletDesc((WalletDesc_t *)param); break; -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION case SIG_SETUP_RSA_PRIVATE_KEY_PARSER_CONFIRM: case SIG_SETUP_RSA_PRIVATE_KEY_RECEIVE_CONFIRM: GuiShowRsaSetupasswordHintbox(); @@ -85,10 +85,10 @@ int32_t GuiHomeViewEventProcess(void *self, uint16_t usEvent, void *param, uint1 case SIG_SETUP_RSA_PRIVATE_KEY_WITH_PASSWORD_PASS: GuiShowRsaInitializatioCompleteHintbox(); break; +#endif case SIG_CLEAR_HOME_PAGE_INDEX: ClearHomePageCurrentIndex(); break; -#endif case SIG_QRCODE_VIEW_SCAN_FAIL: GuiScanResult(false, param); break; diff --git a/src/ui/gui_views/multi/general/gui_key_derivation_request_view.c b/src/ui/gui_views/multi/gui_key_derivation_request_view.c similarity index 98% rename from src/ui/gui_views/multi/general/gui_key_derivation_request_view.c rename to src/ui/gui_views/multi/gui_key_derivation_request_view.c index 8f15fa291..e35ff4caa 100644 --- a/src/ui/gui_views/multi/general/gui_key_derivation_request_view.c +++ b/src/ui/gui_views/multi/gui_key_derivation_request_view.c @@ -1,4 +1,3 @@ -#ifndef BTC_ONLY #include "gui.h" #include "gui_obj.h" #include "gui_views.h" @@ -68,5 +67,4 @@ GUI_VIEW g_keyDerivationRequestView = { .isActive = false, .optimization = false, .pEvtHandler = GuiKeyDerivationRequestViewEventProcess, -}; -#endif +}; \ No newline at end of file diff --git a/src/ui/gui_views/multi/general/gui_standard_receive_view.c b/src/ui/gui_views/multi/gui_standard_receive_view.c similarity index 100% rename from src/ui/gui_views/multi/general/gui_standard_receive_view.c rename to src/ui/gui_views/multi/gui_standard_receive_view.c diff --git a/src/ui/gui_views/multi/general/gui_usb_transport_view.c b/src/ui/gui_views/multi/gui_usb_transport_view.c similarity index 100% rename from src/ui/gui_views/multi/general/gui_usb_transport_view.c rename to src/ui/gui_views/multi/gui_usb_transport_view.c diff --git a/src/ui/gui_wallet/multi/cyberpunk/gui_wallet.h b/src/ui/gui_wallet/multi/cyberpunk/gui_wallet.h index 61dbe9c06..9c36c28dd 100644 --- a/src/ui/gui_wallet/multi/cyberpunk/gui_wallet.h +++ b/src/ui/gui_wallet/multi/cyberpunk/gui_wallet.h @@ -16,7 +16,6 @@ UREncodeResult *GuiGetCompanionAppData(void); UREncodeResult *GuiGetOkxWalletData(void); UREncodeResult *GuiGetBitgetWalletData(void); UREncodeResult *GetMetamaskDataForAccountType(ETHAccountType accountType); -UREncodeResult *GetUnlimitedMetamaskDataForAccountType(ETHAccountType accountType); UREncodeResult *GuiGetMetamaskData(void); UREncodeResult *GuiGetFewchaDataByCoin(GuiChainCoinType coin); UREncodeResult *GuiGetNightlyDataByCoin(GuiChainCoinType coin); diff --git a/src/ui/gui_widgets/gui_create_wallet_widgets.c b/src/ui/gui_widgets/gui_create_wallet_widgets.c index 24370fd2c..862aa3274 100644 --- a/src/ui/gui_widgets/gui_create_wallet_widgets.c +++ b/src/ui/gui_widgets/gui_create_wallet_widgets.c @@ -477,7 +477,7 @@ static void OpenMoreHandler(lv_event_t *e) { MoreInfoTable_t moreInfoTable[] = { {.name = _("change_entropy"), .src = &imgConnect, .callBack = OpenChangeEntropyHandler, NULL}, -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION {.name = _("generate_ton_mnenonic"), .src = &imgTonPhrase, .callBack = TonPhraseButtonHandler, NULL}, #endif {.name = _("Tutorial"), .src = &imgTutorial, .callBack = QuestionMarkEventCb, NULL}, @@ -663,7 +663,7 @@ static void OpenChangeEntropyTutorialHandler(lv_event_t *e) GuiFrameOpenViewWithParam(&g_tutorialView, &index, sizeof(index)); } -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION static void TonPhraseButtonHandler(lv_event_t *e) { GUI_DEL_OBJ(g_openMoreHintBox); diff --git a/src/ui/gui_widgets/gui_scan_widgets.c b/src/ui/gui_widgets/gui_scan_widgets.c index 75f0a89fb..efd42a694 100644 --- a/src/ui/gui_widgets/gui_scan_widgets.c +++ b/src/ui/gui_widgets/gui_scan_widgets.c @@ -122,14 +122,16 @@ void GuiScanResult(bool result, void *param) GuiCLoseCurrentWorkingView(); GuiFrameOpenView(&g_webAuthResultView); } -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION if (g_qrcodeViewType == KeyDerivationRequest) { if (!GuiCheckIfTopView(&g_homeView)) { GuiCLoseCurrentWorkingView(); } GuiFrameOpenViewWithParam(&g_keyDerivationRequestView, NULL, 0); } -#else +#endif + +#ifdef BTC_ONLY if (g_qrcodeViewType == MultisigWalletImport) { GuiCLoseCurrentWorkingView(); GuiFrameOpenView(&g_importMultisigWalletInfoView); @@ -159,7 +161,7 @@ void GuiTransactionCheckPass(void) GuiModelTransactionCheckResultClear(); SetPageLockScreen(true); GuiCLoseCurrentWorkingView(); -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION if (g_chainType == CHAIN_ARWEAVE) { if (GetIsTempAccount()) { ThrowError(ERR_INVALID_QRCODE); diff --git a/src/ui/gui_widgets/gui_select_address_widgets.c b/src/ui/gui_widgets/gui_select_address_widgets.c index 39a757b74..501a363e3 100644 --- a/src/ui/gui_widgets/gui_select_address_widgets.c +++ b/src/ui/gui_widgets/gui_select_address_widgets.c @@ -244,7 +244,7 @@ static void SelectAddressHandler(lv_event_t *e) static void ModelGetAddress(uint32_t index, AddressDataItem_t *item) { switch (g_chainCoinType) { -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION case CHAIN_XRP: item->index = index; strcpy(item->address, GuiGetXrpAddressByIndex(index)); diff --git a/src/ui/gui_widgets/gui_transaction_detail_widgets.c b/src/ui/gui_widgets/gui_transaction_detail_widgets.c index 3daeca824..3e6714c7b 100644 --- a/src/ui/gui_widgets/gui_transaction_detail_widgets.c +++ b/src/ui/gui_widgets/gui_transaction_detail_widgets.c @@ -25,9 +25,9 @@ #include "gui_page.h" #include "account_manager.h" #include "gui_pending_hintbox.h" +#include "general/eapdu_services/service_resolve_ur.h" #ifdef GENERAL_VERSION #include "gui_eth.h" -#include "general/eapdu_services/service_resolve_ur.h" #endif #ifndef COMPILE_SIMULATOR #include "keystore.h" @@ -305,7 +305,7 @@ void GuiClearQrcodeSignCnt(void) static void GuiTransactionDetailNavBarInit() { SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, TransactionGoToHomeViewHandler, NULL); -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION if (IsMessageType(g_viewType)) { SetCoinWallet(g_pageWidget->navBarWidget, g_chainType, _("transaction_parse_confirm_message")); } else if (isTonSignProof(g_viewType)) { @@ -319,7 +319,7 @@ static void GuiTransactionDetailNavBarInit() } else { #endif SetCoinWallet(g_pageWidget->navBarWidget, g_chainType, NULL); -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION } #endif } @@ -405,8 +405,7 @@ static void RecognizeFailHandler(lv_timer_t *timer) static bool GuiCheckIsTransactionSign(void) { -#ifndef BTC_ONLY - printf("GetEthPermitCantSign(NULL, NULL) = %d\n", GetEthPermitCantSign(NULL, NULL)); +#ifdef GENERAL_VERSION if (GetEthPermitCantSign(NULL, NULL)) { return false; } diff --git a/src/ui/gui_widgets/gui_transaction_signature_widgets.c b/src/ui/gui_widgets/gui_transaction_signature_widgets.c index bf81a7d2e..91de56042 100644 --- a/src/ui/gui_widgets/gui_transaction_signature_widgets.c +++ b/src/ui/gui_widgets/gui_transaction_signature_widgets.c @@ -69,7 +69,7 @@ void GuiTransactionSignatureHandleURUpdate(char *data, uint16_t len) static void GuiTransactionSignatureNVSBarInit() { SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, GoToHomeViewHandler, NULL); -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION if (IsMessageType(g_viewType)) { SetCoinWallet(g_pageWidget->navBarWidget, g_chainType, _("transaction_parse_broadcast_message")); } else if (isTonSignProof(g_viewType)) { @@ -77,7 +77,7 @@ static void GuiTransactionSignatureNVSBarInit() } else { #endif SetCoinWallet(g_pageWidget->navBarWidget, g_chainType, NULL); -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION } #endif } diff --git a/src/ui/gui_widgets/gui_utxo_receive_widgets.c b/src/ui/gui_widgets/gui_utxo_receive_widgets.c index fb669617b..68ffcec7a 100644 --- a/src/ui/gui_widgets/gui_utxo_receive_widgets.c +++ b/src/ui/gui_widgets/gui_utxo_receive_widgets.c @@ -302,7 +302,7 @@ void GuiReceiveDeInit(void) static bool HasMoreBtn() { switch (g_chainCard) { -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION case HOME_WALLET_CARD_LTC: case HOME_WALLET_CARD_BCH: case HOME_WALLET_CARD_DASH: @@ -376,7 +376,7 @@ static void GetCurrentTitle(TitleItem_t *titleItem) titleItem->type = CHAIN_BTC; snprintf_s(titleItem->title, PATH_ITEM_MAX_LEN, _("receive_coin_fmt"), "BTC"); break; -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION case HOME_WALLET_CARD_LTC: titleItem->type = CHAIN_LTC; snprintf_s(titleItem->title, PATH_ITEM_MAX_LEN, _("receive_coin_fmt"), "LTC"); @@ -545,7 +545,7 @@ static void GetHint(char *hint) case HOME_WALLET_CARD_BTC: strcpy_s(hint, BUFFER_SIZE_256, _("receive_btc_alert_desc")); break; -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION case HOME_WALLET_CARD_LTC: snprintf_s(hint, BUFFER_SIZE_256, _("receive_coin_hint_fmt"), "LTC"); break; @@ -580,7 +580,7 @@ static uint32_t GetCurrentSelectIndex() switch (g_chainCard) { case HOME_WALLET_CARD_BTC: return g_btcSelectIndex[g_currentAccountIndex]; -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION case HOME_WALLET_CARD_LTC: return g_ltcSelectIndex[g_currentAccountIndex]; case HOME_WALLET_CARD_DASH: @@ -600,7 +600,7 @@ static void SetCurrentSelectIndex(uint32_t selectIndex) case HOME_WALLET_CARD_BTC: g_btcSelectIndex[g_currentAccountIndex] = selectIndex; break; -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION case HOME_WALLET_CARD_LTC: g_ltcSelectIndex[g_currentAccountIndex] = selectIndex; break; @@ -1380,12 +1380,14 @@ static ChainType GetChainTypeByIndex(uint32_t index) } break; } +#ifdef GENERAL_VERSION case HOME_WALLET_CARD_LTC: return XPUB_TYPE_LTC; case HOME_WALLET_CARD_DASH: return XPUB_TYPE_DASH; case HOME_WALLET_CARD_BCH: return XPUB_TYPE_BCH; +#endif default: break; } @@ -1421,7 +1423,7 @@ static void GetRootHdPath(char *hdPath, uint32_t maxLen) #endif strcpy_s(hdPath, maxLen, g_addressSettings[addrType].path); break; -#ifndef BTC_ONLY +#ifdef GENERAL_VERSION case HOME_WALLET_CARD_LTC: strcpy_s(hdPath, maxLen, g_chainPathItems[1].path); break; diff --git a/src/ui/gui_widgets/multi/cyberpunk/gui_connect_wallet_widgets.c b/src/ui/gui_widgets/multi/cyberpunk/gui_connect_wallet_widgets.c new file mode 100644 index 000000000..b0007fceb --- /dev/null +++ b/src/ui/gui_widgets/multi/cyberpunk/gui_connect_wallet_widgets.c @@ -0,0 +1,1477 @@ +#include "gui_connect_wallet_widgets.h" +#include "account_public_info.h" +#include "gui.h" +#include "gui_button.h" +#include "gui_hintbox.h" +#include "gui_keyboard.h" +#include "gui_status_bar.h" +#include "gui_views.h" +#include "gui_wallet.h" +#include "rust.h" +#include "user_memory.h" +#ifdef GENERAL_VERSION +#include "gui_multi_path_coin_receive_widgets.h" +#include "gui_connect_ada_widgets.h" +#include "gui_keyboard_hintbox.h" +#include "gui_pending_hintbox.h" +#endif +#include "account_manager.h" +#include "gui_animating_qrcode.h" +#include "gui_global_resources.h" +#include "gui_page.h" +#include "keystore.h" +#include "gui_select_address_widgets.h" +#include "account_public_info.h" + +#define DERIVATION_PATH_EG_LEN 2 + +typedef enum { + CONNECT_WALLET_SELECT_WALLET = 0, + CONNECT_WALLET_QRCODE, + + CONNECT_WALLET_BUTT, +} CONNECT_WALLET_ENUM; + +typedef struct ConnectWalletWidget { + uint32_t currentTile; + lv_obj_t *cont; + lv_obj_t *tileView; + WALLET_LIST_INDEX_ENUM walletIndex; + lv_obj_t *qrCode; +} ConnectWalletWidget_t; + + +WalletListItem_t g_walletListArray[] = { + {WALLET_LIST_ZASHI, &walletListZashi, true}, + {WALLET_LIST_BLUE, &walletListBlue, true}, + {WALLET_LIST_ZEUS, &walletListZeus, true}, + {WALLET_LIST_SPARROW, &walletListSparrow, true}, + {WALLET_LIST_UNISAT, &walletListUniSat, true}, +}; + +#ifndef BTC_ONLY +typedef struct { + int8_t index; + const char *coin; + const lv_img_dsc_t *icon; +} CoinCard_t; + +static const lv_img_dsc_t *g_metaMaskCoinArray[5] = { + &coinEth, &coinBnb, &coinAva, &coinMatic, &coinScroll, +}; + +static const lv_img_dsc_t *g_ethWalletCoinArray[4] = { + &coinEth, + &coinBnb, + &coinAva, + &coinMatic, +}; + +static const lv_img_dsc_t *g_okxWalletCoinArray[] = { + &coinBtc, &coinEth, &coinBnb, &coinMatic, &coinOkb, + &coinTrx, &coinLtc, &coinBch, &coinDash, +}; + +static const lv_img_dsc_t *g_bitgetWalletCoinArray[] = { + &coinBtc, &coinEth, &coinTon +}; + +static const lv_img_dsc_t *g_backpackWalletCoinArray[2] = { + &coinSol, &coinEth +}; + +static const lv_img_dsc_t *g_keystoneWalletCoinArray[] = { + &coinBtc, &coinEth, &coinBnb, &coinBch, + &coinDash, &coinLtc, &coinTrx, &coinXrp, +}; + +static const lv_img_dsc_t *g_blueWalletCoinArray[4] = { + &coinBtc, +}; + +static const lv_img_dsc_t *g_UniSatCoinArray[5] = { + &coinBtc, &coinOrdi, &coinSats, &coinMubi, &coinTrac, +}; + +static const lv_img_dsc_t *g_keplrCoinArray[8] = { + &coinAtom, &coinOsmo, &coinBld, &coinAkt, + &coinXprt, &coinAxl, &coinBoot, &coinCro, +}; + +static const lv_img_dsc_t *g_leapCoinArray[8] = { + &coinAtom, &coinOsmo, &coinInj, &coinStrd, &coinStars, &coinJuno, &coinScrt, &coinDym +}; + +static const lv_img_dsc_t *g_arconnectCoinArray[1] = { + &coinAr, +}; + +static const lv_img_dsc_t *g_xbullCoinArray[1] = { + &coinXlm, +}; + + + +static const lv_img_dsc_t *g_petraCoinArray[1] = { + &coinApt, +}; + +static const lv_img_dsc_t *g_nightlyCoinArray[1] = { + &coinSui, +}; + +static const lv_img_dsc_t *g_solfareCoinArray[1] = { + &coinSol, +}; + +static const lv_img_dsc_t *g_heliumCoinArray[2] = { + &coinSol, + &coinHelium, +}; + +static const lv_img_dsc_t *g_tonKeeperCoinArray[1] = { + &coinTon, +}; + +static const lv_img_dsc_t *g_zashiCoinArray[1] = { + &coinZec, +}; + +static const lv_img_dsc_t *g_ThorWalletCoinArray[3] = { + // todo thorchain will support bitcoin later + // &coinBtc, + &coinEth, + &coinRune, +}; + + +typedef struct { + const char *accountType; + const char *path; +} ChangeDerivationItem_t; + +const static ChangeDerivationItem_t g_changeDerivationList[] = { + {"BIP44 Standard", "#8E8E8E m/44'/60'/0'/0/##F5870A X#"}, + {"Ledger Live", "#8E8E8E m/44'/60'/##F5870A X##8E8E8E '/0/0#"}, + {"Ledger Legacy", "#8E8E8E m/44'/60'/0'/##F5870A X#"}, +}; + +const static ChangeDerivationItem_t g_solChangeDerivationList[] = { + {"Account-based Path", "#8E8E8E m/44'/501'/##F5870A X##8E8E8E '#"}, + {"Single Account Path", "#8E8E8E m/44'/501'#"}, + {"Sub-account Path", "#8E8E8E m/44'/501'/##F5870A X##8E8E8E '/0'#"}, +}; + +const static ChangeDerivationItem_t g_adaChangeDerivationList[] = { + {"Icarus", ""}, + {"Ledger/BitBox02", ""}, +}; + +static uint32_t g_currentSelectedPathIndex[3] = {0}; +static lv_obj_t *g_coinListCont = NULL; +static KeyboardWidget_t *g_keyboardWidget = NULL; +#endif + +static lv_obj_t *g_noticeWindow = NULL; +static ConnectWalletWidget_t g_connectWalletTileView; +static PageWidget_t *g_pageWidget; + +static void UpdategAddress(void); +static void GetEgAddress(void); +static void GetEthEgAddress(void); +static void initFewchaCoinsConfig(void); +static void OpenQRCodeHandler(lv_event_t *e); +static void ReturnShowQRHandler(lv_event_t *e); +static void UpdateFewchaCoinStateHandler(lv_event_t *e); +static void JumpSelectCoinPageHandler(lv_event_t *e); +static void ConfirmSelectFewchaCoinsHandler(lv_event_t *e); +void ConnectWalletReturnHandler(lv_event_t *e); +static void OpenMoreHandler(lv_event_t *e); +static uint32_t GetCurrentSelectedIndex(); +static bool HasSelectAddressWidget(); +static void ShowEgAddressCont(lv_obj_t *egCont); +static uint32_t GetDerivedPathTypeCount(); +static int GetAccountType(void); + +#ifndef BTC_ONLY +static char g_derivationPathAddr[LedgerLegacy + 1][DERIVATION_PATH_EG_LEN][64]; +static lv_obj_t *g_derivationCheck[LedgerLegacy + 1]; +static lv_obj_t *g_egAddress[DERIVATION_PATH_EG_LEN]; +static lv_obj_t *g_egAddressIndex[DERIVATION_PATH_EG_LEN]; +#endif + +static lv_obj_t *g_coinCont = NULL; +static lv_obj_t *g_coinTitleLabel = NULL; +static lv_obj_t *g_openMoreHintBox = NULL; +static lv_obj_t *g_bottomCont = NULL; +static lv_obj_t *g_manageImg = NULL; +static bool g_isCoinReselected = false; +static lv_obj_t *g_derivationPathCont = NULL; +#ifndef BTC_ONLY +static char **g_derivationPathDescs = NULL; +static lv_obj_t *g_derivationPathConfirmBtn = NULL; +static lv_obj_t *g_egCont = NULL; +#endif + +static void QRCodePause(bool); + +static void GuiInitWalletListArray() +{ + bool isTON = false; + bool isSLIP39 = false; + bool isTempAccount = false; + bool isRussian = false; + +#ifndef BTC_ONLY + isTON = (GetMnemonicType() == MNEMONIC_TYPE_TON); + isSLIP39 = (GetMnemonicType() == MNEMONIC_TYPE_SLIP39); + isTempAccount = GetIsTempAccount(); + isRussian = (LanguageGetIndex() == LANG_RU); +#else + int currentWalletIndex = GetCurrentWalletIndex(); +#endif + + for (size_t i = 0; i < NUMBER_OF_ARRAYS(g_walletListArray); i++) { + bool enable = true; + int index = g_walletListArray[i].index; + + bool passphraseExist = PassphraseExist(GetCurrentAccountIndex()); + MnemonicType mnemonicType = GetMnemonicType(); + bool isSlip39 = (mnemonicType == MNEMONIC_TYPE_SLIP39); + +#ifndef BTC_ONLY + if (isTON) { + enable = (index == WALLET_LIST_TONKEEPER); + } else { + switch (index) { + case WALLET_LIST_ETERNL: + case WALLET_LIST_VESPR: + case WALLET_LIST_TYPHON: + case WALLET_LIST_BEGIN: + enable = !isSLIP39; + break; + case WALLET_LIST_ARCONNECT: + enable = !isTempAccount; + break; + case WALLET_LIST_KEYSTONE: + enable = isRussian; + break; + case WALLET_LIST_ZASHI: + enable = !passphraseExist && !isSlip39; + break; + default: + break; + } + } +#else + if (currentWalletIndex != SINGLE_WALLET) { + if (index == WALLET_LIST_SPECTER || index == WALLET_LIST_UNISAT) { + enable = false; + } + } +#endif + + g_walletListArray[i].enable = enable; + } +} + +// static void GuiInitWalletListArray() +// { +// SetWalletListEnable(true); + +// ConfigureWalletEnabling(); +// } + +#ifndef BTC_ONLY +static bool IsEVMChain(int walletIndex) +{ + switch (walletIndex) { + case WALLET_LIST_METAMASK: + case WALLET_LIST_RABBY: + case WALLET_LIST_SAFE: + case WALLET_LIST_BLOCK_WALLET: + case WALLET_LIST_ZAPPER: + case WALLET_LIST_YEARN_FINANCE: + case WALLET_LIST_SUSHISWAP: + return true; + default: + return false; + } +} + +static bool IsSOL(int walletIndex) +{ + switch (walletIndex) { + case WALLET_LIST_SOLFARE: + case WALLET_LIST_HELIUM: + return true; + default: + return false; + } +} + + +#endif + +static void GuiARAddressCheckConfirmHandler(lv_event_t *event) +{ + GUI_DEL_OBJ(g_noticeWindow); + GuiCreateAttentionHintbox(SIG_SETUP_RSA_PRIVATE_KEY_CONNECT_CONFIRM); +} + +static void GuiOpenARAddressNoticeWindow() +{ + g_noticeWindow = GuiCreateGeneralHintBox(&imgWarn, _("ar_address_check"), _("ar_address_check_desc"), NULL, _("Not Now"), WHITE_COLOR_OPA20, _("Understand"), ORANGE_COLOR); + lv_obj_add_event_cb(lv_obj_get_child(g_noticeWindow, 0), CloseHintBoxHandler, LV_EVENT_CLICKED, &g_noticeWindow); + + lv_obj_t *btn = GuiGetHintBoxRightBtn(g_noticeWindow); + lv_obj_set_width(btn, 192); + lv_obj_set_style_text_font(lv_obj_get_child(btn, 0), &buttonFont, 0); + lv_obj_add_event_cb(btn, GuiARAddressCheckConfirmHandler, LV_EVENT_CLICKED, &g_noticeWindow); + + btn = GuiGetHintBoxLeftBtn(g_noticeWindow); + lv_obj_set_width(btn, 192); + lv_obj_set_style_text_font(lv_obj_get_child(btn, 0), &buttonFont, 0); + lv_obj_add_event_cb(btn, CloseHintBoxHandler, LV_EVENT_CLICKED, &g_noticeWindow); + + lv_obj_t *img = GuiCreateImg(g_noticeWindow, &imgClose); + lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE); + lv_obj_add_event_cb(img, CloseHintBoxHandler, LV_EVENT_CLICKED, &g_noticeWindow); + lv_obj_align_to(img, lv_obj_get_child(g_noticeWindow, 1), LV_ALIGN_TOP_RIGHT, -36, 36); +} + +static void OpenQRCodeHandler(lv_event_t *e) +{ + WalletListItem_t *wallet = lv_event_get_user_data(e); + g_connectWalletTileView.walletIndex = wallet->index; + g_isCoinReselected = false; + GuiEmitSignal(SIG_SETUP_VIEW_TILE_NEXT, NULL, 0); +} + +#ifndef BTC_ONLY +void GuiConnectWalletPasswordErrorCount(void *param) +{ + PasswordVerifyResult_t *passwordVerifyResult = (PasswordVerifyResult_t *)param; + GuiShowErrorNumber(g_keyboardWidget, passwordVerifyResult); +} + +void GuiConnectShowRsaSetupasswordHintbox(void) +{ + g_keyboardWidget = GuiCreateKeyboardWidget(g_pageWidget->contentZone); + SetKeyboardWidgetSelf(g_keyboardWidget, &g_keyboardWidget); + static uint16_t sig = SIG_SETUP_RSA_PRIVATE_KEY_WITH_PASSWORD; + SetKeyboardWidgetSig(g_keyboardWidget, &sig); +} + +static void ReturnShowQRHandler(lv_event_t *e) +{ + GUI_DEL_OBJ(g_coinListCont) + QRCodePause(false); + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, + ConnectWalletReturnHandler, NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_BAR_MORE_INFO, + OpenMoreHandler, NULL); +} + + +static void RefreshAddressIndex(uint32_t index) +{ + if (GetConnectWalletAccountIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex)) != index) { + SetConnectWalletAccountIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex), index); + GuiAnimatingQRCodeDestroyTimer(); + GuiConnectWalletSetQrdata(g_connectWalletTileView.walletIndex); + } else { + QRCodePause(false); + } + g_coinListCont = NULL; +} + +static void JumpSelectCoinPageHandler(lv_event_t *e) +{ + if (g_coinListCont != NULL) { + return; + } +#ifndef COMPILE_SIMULATOR + QRCodePause(true); +#endif + if (g_connectWalletTileView.walletIndex == WALLET_LIST_FEWCHA) { + } else if (HasSelectAddressWidget()) { + if (g_connectWalletTileView.walletIndex == WALLET_LIST_XRP_TOOLKIT) { + g_coinListCont = GuiCreateSelectAddressWidget( + CHAIN_XRP, GetConnectWalletAccountIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex)), + RefreshAddressIndex); + } else if (g_connectWalletTileView.walletIndex == WALLET_LIST_VESPR) { + g_coinListCont = GuiCreateSelectAddressWidget( + CHAIN_ADA, GetConnectWalletAccountIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex)), + RefreshAddressIndex); + } + } + if (g_connectWalletTileView.walletIndex == WALLET_LIST_KEPLR || g_connectWalletTileView.walletIndex == WALLET_LIST_MINT_SCAN) { + g_coinListCont = GuiCreateSelectAddressWidget( + CHAIN_ATOM, GetConnectWalletAccountIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex)), + RefreshAddressIndex); + } +} + +#endif + +static void GuiCreateSelectWalletWidget(lv_obj_t *parent) +{ + lv_obj_clear_flag(parent, LV_OBJ_FLAG_SCROLL_ELASTIC); + lv_obj_set_scrollbar_mode(parent, LV_SCROLLBAR_MODE_OFF); +#ifndef BTC_ONLY + bool isTon = GetMnemonicType() == MNEMONIC_TYPE_TON; + if (isTon) { + WalletListItem_t *t = NULL; + for (size_t i = 0; i < NUMBER_OF_ARRAYS(g_walletListArray); i++) { + if (g_walletListArray[i].index == WALLET_LIST_TONKEEPER) { + t = &g_walletListArray[i]; + break; + } + } + ASSERT(t != NULL); + lv_obj_t *img = GuiCreateImg(parent, t->img); + lv_obj_align(img, LV_ALIGN_TOP_MID, 0, 0); + lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE); + lv_obj_add_event_cb(img, OpenQRCodeHandler, LV_EVENT_CLICKED, + t); + } else { + int offsetY = 0; + for (int i = 0, j = 0; i < NUMBER_OF_ARRAYS(g_walletListArray); i++) { + if (!g_walletListArray[i].enable) { + continue; + } + lv_obj_t *img = GuiCreateImg(parent, g_walletListArray[i].img); + lv_obj_align(img, LV_ALIGN_TOP_MID, 0, offsetY); + lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE); + lv_obj_add_event_cb(img, OpenQRCodeHandler, LV_EVENT_CLICKED, + &g_walletListArray[i]); + j++; + offsetY = j * 107; + } + } +#else + lv_obj_t *img, *line, *alphaImg; + static lv_point_t points[2] = {{0, 0}, {408, 0}}; + line = GuiCreateLine(parent, points, 2); + lv_obj_align(line, LV_ALIGN_TOP_MID, 0, 0); + lv_obj_t *baseView = NULL; + for (int i = 0; i < NUMBER_OF_ARRAYS(g_walletListArray); i++) { + if (!g_walletListArray[i].enable) { + continue; + } + // temporary fix, when the multi-signature testnet is opened, the logic here + // needs to be rewritten + if (GetCurrentWalletIndex() == SINGLE_WALLET && GetIsTestNet() && + g_walletListArray[i].index == WALLET_LIST_BLUE) { + continue; + } + img = GuiCreateImg(parent, g_walletListArray[i].img); + if (baseView == NULL) { + lv_obj_align(img, LV_ALIGN_TOP_MID, 0, 9); + } else { + lv_obj_align_to(img, baseView, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); + } + baseView = img; + lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE); + lv_obj_add_event_cb(img, OpenQRCodeHandler, LV_EVENT_CLICKED, + &g_walletListArray[i]); + if (g_walletListArray[i].alpha) { + alphaImg = GuiCreateImg(img, &imgAlpha); + lv_obj_align(alphaImg, LV_ALIGN_RIGHT_MID, -219, 0); + } + line = GuiCreateLine(parent, points, 2); + lv_obj_align_to(line, baseView, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); + } +#endif +} + +#ifndef BTC_ONLY +static void GuiCreateSupportedNetworks(uint8_t index) +{ + if (g_coinCont != NULL && g_manageImg != NULL && g_coinTitleLabel != NULL) { + return; + } + lv_obj_clean(g_bottomCont); + if (index == WALLET_LIST_UNISAT) { + g_coinTitleLabel = GuiCreateNoticeLabel(g_bottomCont, _("connect_wallet_supported_tokens")); + } else { + g_coinTitleLabel = GuiCreateNoticeLabel(g_bottomCont, _("connect_wallet_supported_networks")); + } + lv_obj_align(g_coinTitleLabel, LV_ALIGN_TOP_LEFT, 36, 12); + lv_obj_add_event_cb(g_bottomCont, JumpSelectCoinPageHandler, LV_EVENT_CLICKED, NULL); + g_coinCont = GuiCreateContainerWithParent(g_bottomCont, 280, 30); + lv_obj_align(g_coinCont, LV_ALIGN_TOP_LEFT, 36, 50); + lv_obj_set_style_bg_color(g_coinCont, DARK_BG_COLOR, LV_PART_MAIN); + + g_manageImg = GuiCreateImg(g_bottomCont, &imgManage); + lv_obj_set_style_img_opa(g_manageImg, LV_OPA_30, LV_PART_MAIN); + lv_obj_align(g_manageImg, LV_ALIGN_BOTTOM_RIGHT, -45, -41); + lv_obj_add_flag(g_manageImg, LV_OBJ_FLAG_HIDDEN); +} +#endif + +static void GuiCreateQrCodeWidget(lv_obj_t *parent) +{ + lv_obj_t *label = GuiCreateIllustrateLabel(parent, _("connect_wallet_scan")); + lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 152 - GUI_MAIN_AREA_OFFSET); + lv_obj_set_style_text_opa(label, LV_OPA_60, LV_PART_MAIN); +#ifndef BTC_ONLY + lv_obj_t *qrCont = GuiCreateContainerWithParent(parent, 408, 490); +#else + lv_obj_t *qrCont = GuiCreateContainerWithParent(parent, 408, 408); +#endif + lv_obj_add_flag(qrCont, LV_OBJ_FLAG_CLICKABLE); + lv_obj_align_to(qrCont, label, LV_ALIGN_OUT_BOTTOM_MID, 0, 6); + lv_obj_set_style_bg_color(qrCont, DARK_BG_COLOR, LV_PART_MAIN); + lv_obj_set_style_radius(qrCont, 24, LV_PART_MAIN); + + lv_obj_t *qrBgCont = GuiCreateContainerWithParent(qrCont, 336, 336); + lv_obj_align(qrBgCont, LV_ALIGN_TOP_MID, 0, 36); + lv_obj_set_style_bg_color(qrBgCont, WHITE_COLOR, LV_PART_MAIN); + + lv_obj_t *qrcode = GuiCreateContainerWithParent(qrBgCont, 294, 294); + lv_obj_align(qrcode, LV_ALIGN_TOP_MID, 0, 21); + g_connectWalletTileView.qrCode = qrcode; + + g_bottomCont = GuiCreateContainerWithParent(qrCont, 408, 124); + lv_obj_align(g_bottomCont, LV_ALIGN_BOTTOM_MID, 0, 0); + lv_obj_set_style_bg_color(g_bottomCont, DARK_BG_COLOR, LV_PART_MAIN); + lv_obj_set_style_bg_opa(g_bottomCont, LV_OPA_0, + LV_STATE_DEFAULT | LV_PART_MAIN); +#ifndef BTC_ONLY + // GuiCreateSupportedNetworks(g_connectWalletTileView.walletIndex); +#else + if (GetCurrentWalletIndex() != SINGLE_WALLET) { + lv_obj_t *button = GuiCreateImgLabelAdaptButton(parent, _("multisig_connect_wallet_notice"), &imgTwoSmallKey, UnHandler, NULL); + lv_obj_align(button, LV_ALIGN_BOTTOM_MID, 0, -24); + lv_obj_set_style_text_opa(lv_obj_get_child(button, 1), LV_OPA_80, LV_PART_MAIN); + } +#endif +} + +#ifndef BTC_ONLY +static void AddMetaMaskCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; i < 5; i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_metaMaskCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } + + lv_obj_t *img = GuiCreateImg(g_coinCont, &imgMore); + lv_img_set_zoom(img, 150); + lv_img_set_pivot(img, 0, 0); + lv_obj_set_style_img_opa(img, LV_OPA_30, LV_PART_MAIN); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 132, 2); +} + +static void AddEthWalletCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; i < 4; i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_ethWalletCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } + lv_obj_t *img = GuiCreateImg(g_coinCont, &imgMore); + lv_img_set_zoom(img, 150); + lv_img_set_pivot(img, 0, 0); + lv_obj_set_style_img_opa(img, LV_OPA_30, LV_PART_MAIN); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 132, 2); +} + +static void AddOkxWalletCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; + i < sizeof(g_okxWalletCoinArray) / sizeof(g_okxWalletCoinArray[0]); + i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_okxWalletCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } + lv_obj_t *img = GuiCreateImg(g_coinCont, &imgMore); + lv_img_set_zoom(img, 150); + lv_img_set_pivot(img, 0, 0); + lv_obj_set_style_img_opa(img, LV_OPA_30, LV_PART_MAIN); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 132, 2); +} + +static void AddBitgetWalletCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; + i < sizeof(g_bitgetWalletCoinArray) / sizeof(g_bitgetWalletCoinArray[0]); + i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_bitgetWalletCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } +} + +static void AddKeystoneWalletCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; + i < sizeof(g_keystoneWalletCoinArray) / sizeof(g_keystoneWalletCoinArray[0]); + i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_keystoneWalletCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } + lv_obj_t *img = GuiCreateImg(g_coinCont, &imgMore); + lv_img_set_zoom(img, 150); + lv_img_set_pivot(img, 0, 0); + lv_obj_set_style_img_opa(img, LV_OPA_30, LV_PART_MAIN); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 132, 2); +} + +static void AddBlueWalletCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; i < 1; i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_blueWalletCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } +} + +static void AddUniSatWalletCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; i < 5; i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_UniSatCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } + // Add more + lv_obj_t *img = GuiCreateImg(g_coinCont, &imgMore); + lv_img_set_zoom(img, 150); + lv_img_set_pivot(img, 0, 0); + lv_obj_set_style_img_opa(img, LV_OPA_30, LV_PART_MAIN); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * 5, 2); +} + +static void AddArConnectCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + + lv_obj_t *img = GuiCreateImg(g_coinCont, g_arconnectCoinArray[0]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 0, 0); +} + +static void AddXBullCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + + lv_obj_t *img = GuiCreateImg(g_coinCont, g_xbullCoinArray[0]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 0, 0); +} + +static void AddZecCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; i < 1; i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_zashiCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } +} + +static void AddChainAddress(void) +{ + if (lv_obj_get_child_cnt(g_bottomCont) > 0) { + lv_obj_clean(g_bottomCont); + g_manageImg = NULL; + g_coinCont = NULL; + } + lv_obj_add_flag(g_bottomCont, LV_OBJ_FLAG_CLICKABLE); + + char name[BUFFER_SIZE_32] = {0}; + snprintf_s(name, sizeof(name), "%s-%d", _("account_head"), + GetConnectWalletAccountIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex))); + lv_obj_t *label = GuiCreateIllustrateLabel(g_bottomCont, name); + lv_obj_align(label, LV_ALIGN_TOP_LEFT, 36, 24); + + label = GuiCreateImg(g_bottomCont, &imgArrowRight); + lv_obj_align(label, LV_ALIGN_CENTER, 150, 0); +} + +static void AddKeplrCoinsAndAddressUI(void) +{ + if (lv_obj_get_child_cnt(g_bottomCont) > 0 && g_bottomCont != NULL) { + lv_obj_clean(g_bottomCont); + g_manageImg = NULL; + g_coinCont = NULL; + } + lv_obj_add_flag(g_bottomCont, LV_OBJ_FLAG_CLICKABLE); + g_coinTitleLabel = GuiCreateNoticeLabel(g_bottomCont, _("connect_wallet_supported_networks")); + lv_label_set_text(g_coinTitleLabel, _("connect_wallet_supported_networks")); + lv_obj_align(g_coinTitleLabel, LV_ALIGN_TOP_LEFT, 36, 10); + // supported network icons + for (int i = 0; i < 8; i++) { + lv_obj_t *img = GuiCreateImg(g_bottomCont, g_keplrCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 36 + 32 * i, 38); + } + + lv_obj_t *img = GuiCreateImg(g_bottomCont, &imgMore); + lv_img_set_zoom(img, 150); + lv_img_set_pivot(img, 0, 0); + lv_obj_set_style_img_opa(img, LV_OPA_30, LV_PART_MAIN); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 292, 38); + + // select address ui + lv_obj_add_flag(g_bottomCont, LV_OBJ_FLAG_CLICKABLE); + char name[BUFFER_SIZE_32] = {0}; + snprintf_s(name, sizeof(name), "%s-%d", _("account_head"), + GetConnectWalletAccountIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex))); + lv_obj_t *label = GuiCreateIllustrateLabel(g_bottomCont, name); + lv_obj_align(label, LV_ALIGN_TOP_LEFT, 36, 70); + + label = GuiCreateImg(g_bottomCont, &imgArrowRight); + lv_obj_align(label, LV_ALIGN_CENTER, 150, 30); +} + +static void AddLeapCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; i < 8; i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_leapCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } + // Add more + lv_obj_t *img = GuiCreateImg(g_coinCont, &imgMore); + lv_img_set_zoom(img, 150); + lv_img_set_pivot(img, 0, 0); + lv_obj_set_style_img_opa(img, LV_OPA_30, LV_PART_MAIN); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * 8, 2); +} + +static void AddSolflareCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; i < 1; i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_solfareCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } +} + +static void AddHeliumWalletCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + + for (int i = 0; i < 2; i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_heliumCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } +} + +static void AddBackpackWalletCoins(void) +{ + if (lv_obj_get_child_cnt(g_coinCont) > 0) { + lv_obj_clean(g_coinCont); + } + for (int i = 0; + i < sizeof(g_backpackWalletCoinArray) / sizeof(g_backpackWalletCoinArray[0]); + i++) { + lv_obj_t *img = GuiCreateImg(g_coinCont, g_backpackWalletCoinArray[i]); + lv_img_set_zoom(img, 110); + lv_img_set_pivot(img, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 32 * i, 0); + } +} +#endif + +void GuiConnectWalletInit(void) +{ + GuiInitWalletListArray(); + g_pageWidget = CreatePageWidget(); + lv_obj_t *cont = g_pageWidget->contentZone; + + lv_obj_t *tileView = GuiCreateTileView(cont); + lv_obj_t *tile = lv_tileview_add_tile(tileView, CONNECT_WALLET_SELECT_WALLET, + 0, LV_DIR_HOR); + GuiCreateSelectWalletWidget(tile); + + tile = lv_tileview_add_tile(tileView, CONNECT_WALLET_QRCODE, 0, LV_DIR_HOR); + GuiCreateQrCodeWidget(tile); + + g_connectWalletTileView.currentTile = CONNECT_WALLET_SELECT_WALLET; + g_connectWalletTileView.tileView = tileView; + g_connectWalletTileView.cont = cont; + + lv_obj_set_tile_id(g_connectWalletTileView.tileView, + g_connectWalletTileView.currentTile, 0, LV_ANIM_OFF); +} + +#ifndef BTC_ONLY +UREncodeResult *GuiGetZecData(void) +{ + uint8_t mfp[4]; + GetMasterFingerPrint(mfp); + CSliceFFI_ZcashKey *keys = SRAM_MALLOC(sizeof(CSliceFFI_ZcashKey)); + ZcashKey data[1]; + keys->data = data; + keys->size = 1; + char ufvk[384] = {'\0'}; + uint8_t sfp[32]; + GetZcashUFVK(GetCurrentAccountIndex(), ufvk, sfp); + data[0].key_text = ufvk; + data[0].key_name = GetWalletName(); + data[0].index = 0; + return get_connect_zcash_wallet_ur(sfp, 32, keys); +} + +void GuiPrepareArConnectWalletView(void) +{ + GuiDeleteKeyboardWidget(g_keyboardWidget); + GuiEmitSignal(SIG_SETUP_VIEW_TILE_NEXT, NULL, 0); +} + +void GuiSetupArConnectWallet(void) +{ + RsaGenerateKeyPair(false); +} + +#endif + +void GuiConnectWalletSetQrdata(WALLET_LIST_INDEX_ENUM index) +{ + GenerateUR func = NULL; + SetWallet(g_pageWidget->navBarWidget, index, NULL); +#ifndef BTC_ONLY + GuiCreateSupportedNetworks(index); + lv_label_set_text(g_coinTitleLabel, _("connect_wallet_supported_networks")); + lv_obj_clear_flag(g_bottomCont, LV_OBJ_FLAG_CLICKABLE); + lv_obj_add_flag(g_manageImg, LV_OBJ_FLAG_HIDDEN); +#endif + switch (index) { + case WALLET_LIST_BLUE: + func = GuiGetBlueWalletBtcData; + AddBlueWalletCoins(); + break; + // todo zeus wallet use same ur logic as sparrow wallet (m/49'/0'/0' 、 m/44'/0'/0' 、 m/84'/0'/0' and m/86'/0'/0' ) + case WALLET_LIST_ZEUS: + case WALLET_LIST_SPARROW: + func = GuiGetSparrowWalletBtcData; + AddBlueWalletCoins(); + break; + case WALLET_LIST_UNISAT: + func = GuiGetSparrowWalletBtcData; + AddUniSatWalletCoins(); + lv_label_set_text(g_coinTitleLabel, _("connect_wallet_supported_tokens")); + break; + case WALLET_LIST_ZASHI: + func = GuiGetZecData; + AddZecCoins(); + break; + default: + return; + } + if (func) { + GuiAnimatingQRCodeInit(g_connectWalletTileView.qrCode, func, true); + } +} + +static void QRCodePause(bool pause) +{ + GuiAnimatingQRCodeControl(pause); +} + +void GuiConnectWalletHandleURGenerate(char *data, uint16_t len) +{ + GuiAnimantingQRCodeFirstUpdate(data, len); +} + +void GuiConnectWalletHandleURUpdate(char *data, uint16_t len) +{ + GuiAnimatingQRCodeUpdate(data, len); +} + +void ConnectWalletReturnHandler(lv_event_t *e) +{ + // CloseQRTimer(); + GuiEmitSignal(SIG_SETUP_VIEW_TILE_PREV, NULL, 0); +} + +#ifndef BTC_ONLY +static int GetAccountType(void) +{ + return GetConnectWalletPathIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex)); +} + +static void SetAccountType(uint8_t index) +{ + // switch (g_connectWalletTileView.walletIndex) { + // case WALLET_LIST_SOLFARE: + // g_currentSOLPathIndex[GetCurrentAccountIndex()] = index; + // break; + // case WALLET_LIST_HELIUM: + // g_currentHeliumPathIndex[GetCurrentAccountIndex()] = index; + // break; + // case WALLET_LIST_VESPR: + // g_currentAdaPathIndex[GetCurrentAccountIndex()] = index; + // break; + // default: + // g_currentEthPathIndex[GetCurrentAccountIndex()] = index; + // break; + // } + + SetConnectWalletPathIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex), index); +} + +static bool IsSelectChanged(void) +{ + return GetCurrentSelectedIndex() != GetAccountType(); +} + +static bool HasSelectAddressWidget() +{ + switch (g_connectWalletTileView.walletIndex) { + case WALLET_LIST_XRP_TOOLKIT: + case WALLET_LIST_KEPLR: + case WALLET_LIST_VESPR: + case WALLET_LIST_MINT_SCAN: + return true; + break; + default: + return false; + } +} + +static void CloseDerivationHandler(lv_event_t *e) +{ + QRCodePause(false); + GUI_DEL_OBJ(g_derivationPathCont); + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, ReturnHandler, + NULL); + SetWallet(g_pageWidget->navBarWidget, g_connectWalletTileView.walletIndex, + NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_BAR_MORE_INFO, + OpenMoreHandler, &g_connectWalletTileView.walletIndex); +} + +static void ConfirmDerivationHandler(lv_event_t *e) +{ + lv_event_code_t code = lv_event_get_code(e); + if (code == LV_EVENT_CLICKED && IsSelectChanged()) { + SetAccountType(GetCurrentSelectedIndex()); + GuiAnimatingQRCodeDestroyTimer(); + GuiConnectWalletSetQrdata(g_connectWalletTileView.walletIndex); + GUI_DEL_OBJ(g_derivationPathCont); + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, ReturnHandler, + NULL); + SetWallet(g_pageWidget->navBarWidget, g_connectWalletTileView.walletIndex, + NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_BAR_MORE_INFO, + OpenMoreHandler, &g_connectWalletTileView.walletIndex); + } +} + +static void UpdateConfirmBtn(void) +{ + if (IsSelectChanged()) { + lv_obj_set_style_bg_opa(g_derivationPathConfirmBtn, LV_OPA_COVER, + LV_PART_MAIN); + lv_obj_set_style_text_opa(lv_obj_get_child(g_derivationPathConfirmBtn, 0), + LV_OPA_COVER, LV_PART_MAIN); + } else { + lv_obj_set_style_bg_opa(g_derivationPathConfirmBtn, LV_OPA_30, + LV_PART_MAIN); + lv_obj_set_style_text_opa(lv_obj_get_child(g_derivationPathConfirmBtn, 0), + LV_OPA_30, LV_PART_MAIN); + } +} + +static void GetEthEgAddress(void) +{ + SimpleResponse_c_char *result; + result = eth_get_address( + "44'/60'/0'/0/0", + GetCurrentAccountPublicKey(XPUB_TYPE_ETH_BIP44_STANDARD), "44'/60'/0'"); + CutAndFormatString(g_derivationPathAddr[Bip44Standard][0], BUFFER_SIZE_64, + result->data, 24); + free_simple_response_c_char(result); + + result = eth_get_address( + "44'/60'/0'/0/1", + GetCurrentAccountPublicKey(XPUB_TYPE_ETH_BIP44_STANDARD), "44'/60'/0'"); + CutAndFormatString(g_derivationPathAddr[Bip44Standard][1], BUFFER_SIZE_64, + result->data, 24); + free_simple_response_c_char(result); + + result = eth_get_address( + "44'/60'/0'/0/0", GetCurrentAccountPublicKey(XPUB_TYPE_ETH_LEDGER_LIVE_0), + "44'/60'/0'"); + CutAndFormatString(g_derivationPathAddr[LedgerLive][0], BUFFER_SIZE_64, + result->data, 24); + free_simple_response_c_char(result); + + result = eth_get_address( + "44'/60'/1'/0/0", GetCurrentAccountPublicKey(XPUB_TYPE_ETH_LEDGER_LIVE_1), + "44'/60'/1'"); + CutAndFormatString(g_derivationPathAddr[LedgerLive][1], BUFFER_SIZE_64, + result->data, 24); + free_simple_response_c_char(result); + + result = eth_get_address( + "44'/60'/0'/0", GetCurrentAccountPublicKey(XPUB_TYPE_ETH_LEDGER_LEGACY), + "44'/60'/0'"); + CutAndFormatString(g_derivationPathAddr[LedgerLegacy][0], BUFFER_SIZE_64, + result->data, 24); + free_simple_response_c_char(result); + + result = eth_get_address( + "44'/60'/0'/1", GetCurrentAccountPublicKey(XPUB_TYPE_ETH_LEDGER_LEGACY), + "44'/60'/0'"); + CutAndFormatString(g_derivationPathAddr[LedgerLegacy][1], BUFFER_SIZE_64, + result->data, 24); + free_simple_response_c_char(result); +} + +static void GetEgAddress(void) +{ + GetEthEgAddress(); +} + +static void UpdateEthEgAddress(uint8_t index) +{ + lv_label_set_text(g_egAddress[0], + (const char *)g_derivationPathAddr[index][0]); + lv_label_set_text(g_egAddress[1], + (const char *)g_derivationPathAddr[index][1]); +} + + + +static void UpdategAddress(void) +{ + UpdateEthEgAddress(GetCurrentSelectedIndex()); +} + +static void SetCurrentSelectedIndex(uint8_t index) +{ + g_currentSelectedPathIndex[GetCurrentAccountIndex()] = index; +} + +static uint32_t GetCurrentSelectedIndex() +{ + return g_currentSelectedPathIndex[GetCurrentAccountIndex()]; +} + +static void SelectDerivationHandler(lv_event_t *e) +{ + lv_obj_t *newCheckBox = lv_event_get_user_data(e); + for (int i = 0; i < GetDerivedPathTypeCount(); i++) { + if (newCheckBox == g_derivationCheck[i]) { + lv_obj_add_state(newCheckBox, LV_STATE_CHECKED); + SetCurrentSelectedIndex(i); + ShowEgAddressCont(g_egCont); + UpdateConfirmBtn(); + } else { + lv_obj_clear_state(g_derivationCheck[i], LV_STATE_CHECKED); + } + } +} +#endif + +static void OpenTutorialHandler(lv_event_t *e) +{ + QRCodePause(true); + + WALLET_LIST_INDEX_ENUM *wallet = lv_event_get_user_data(e); + GuiFrameOpenViewWithParam(&g_walletTutorialView, wallet, sizeof(wallet)); + GUI_DEL_OBJ(g_openMoreHintBox); +} + +#ifndef BTC_ONLY +static const char *GetDerivationPathSelectDes(void) +{ + switch (g_connectWalletTileView.walletIndex) { + case WALLET_LIST_SOLFARE: + case WALLET_LIST_HELIUM: + return _("derivation_path_select_sol"); + case WALLET_LIST_VESPR: + return _("derivation_path_select_ada"); + default: + return _("derivation_path_select_eth"); + } +} + +static const char *GetChangeDerivationAccountType(int i) +{ + switch (g_connectWalletTileView.walletIndex) { + case WALLET_LIST_VESPR: + if (i == 0) { + return _("receive_ada_more_t_standard"); + } else if (i == 1) { + return _("receive_ada_more_t_ledger"); + } + case WALLET_LIST_SOLFARE: + case WALLET_LIST_HELIUM: + if (i == 0) { + return _("receive_sol_more_t_base_path"); + } else if (i == 1) { + return _("receive_sol_more_t_single_path"); + } else if (i == 2) { + return _("receive_sol_more_t_sub_path"); + } + default: + return g_changeDerivationList[i].accountType; + } +} + +static const char *GetChangeDerivationPath(int i) +{ + switch (g_connectWalletTileView.walletIndex) { + case WALLET_LIST_SOLFARE: + case WALLET_LIST_HELIUM: + return g_solChangeDerivationList[i].path; + case WALLET_LIST_VESPR: + return g_adaChangeDerivationList[i].path; + default: + return g_changeDerivationList[i].path; + } +} + +static char *GetChangeDerivationPathDesc(void) +{ + return g_derivationPathDescs + [g_currentSelectedPathIndex[GetCurrentAccountIndex()]]; +} + +static void ShowEgAddressCont(lv_obj_t *egCont) +{ + if (egCont == NULL) { + printf("egCont is NULL, cannot show eg address\n"); + return; + } + lv_obj_clean(egCont); + + lv_obj_t *prevLabel = NULL, *label; + int egContHeight = 12; + char *desc = GetChangeDerivationPathDesc(); + if (desc != NULL && strnlen_s(desc, BUFFER_SIZE_128) > 0) { + label = GuiCreateNoticeLabel(egCont, desc); + lv_obj_set_width(label, 360); + lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); + lv_obj_align(label, LV_ALIGN_TOP_LEFT, 24, 12); + lv_obj_update_layout(label); + egContHeight += lv_obj_get_height(label); + prevLabel = label; + } + + label = GuiCreateNoticeLabel(egCont, _("derivation_path_address_eg")); + if (prevLabel != NULL) { + lv_obj_align_to(label, prevLabel, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 4); + } else { + lv_obj_align(label, LV_ALIGN_TOP_LEFT, 24, 12); + } + lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); + lv_obj_update_layout(label); + egContHeight = egContHeight + 4 + lv_obj_get_height(label); + prevLabel = label; + + lv_obj_t *index = GuiCreateNoticeLabel(egCont, _("0")); + lv_obj_align_to(index, prevLabel, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 4); + lv_label_set_long_mode(index, LV_LABEL_LONG_WRAP); + lv_obj_update_layout(index); + egContHeight = egContHeight + 4 + lv_obj_get_height(index); + g_egAddressIndex[0] = index; + prevLabel = index; + + label = GuiCreateIllustrateLabel(egCont, ""); + lv_obj_align_to(label, prevLabel, LV_ALIGN_OUT_RIGHT_MID, 12, 0); + g_egAddress[0] = label; + egContHeight += 12; + lv_obj_set_height(egCont, egContHeight); + GetEgAddress(); + UpdategAddress(); +} + +static uint32_t GetDerivedPathTypeCount() +{ + return 3; +} + +static void OpenDerivationPath() +{ + SetCurrentSelectedIndex(GetAccountType()); + + lv_obj_t *bgCont = GuiCreateContainer(lv_obj_get_width(lv_scr_act()), + lv_obj_get_height(lv_scr_act()) - + GUI_MAIN_AREA_OFFSET); + + lv_obj_align(bgCont, LV_ALIGN_DEFAULT, 0, GUI_MAIN_AREA_OFFSET); + + lv_obj_t *scrollCont = GuiCreateContainerWithParent( + bgCont, lv_obj_get_width(lv_scr_act()), + lv_obj_get_height(lv_scr_act()) - GUI_MAIN_AREA_OFFSET - 114); + lv_obj_align(scrollCont, LV_ALIGN_DEFAULT, 0, 0); + lv_obj_add_flag(scrollCont, LV_OBJ_FLAG_CLICKABLE); + lv_obj_add_flag(scrollCont, LV_OBJ_FLAG_SCROLLABLE); + + lv_obj_t *label = + GuiCreateNoticeLabel(scrollCont, GetDerivationPathSelectDes()); + lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 0); + uint16_t buttonHeight = 102; + lv_obj_t *cont = GuiCreateContainerWithParent(scrollCont, 408, (buttonHeight + 1) * GetDerivedPathTypeCount() - 1); + lv_obj_align(cont, LV_ALIGN_TOP_MID, 0, 84); + lv_obj_set_style_bg_color(cont, WHITE_COLOR, LV_PART_MAIN); + lv_obj_set_style_bg_opa(cont, LV_OPA_10 + LV_OPA_2, LV_PART_MAIN); + lv_obj_set_style_radius(cont, 24, LV_PART_MAIN); + for (int i = 0; i < GetDerivedPathTypeCount(); i++) { + lv_obj_t *accountType = + GuiCreateTextLabel(cont, GetChangeDerivationAccountType(i)); + lv_obj_t *path = GuiCreateIllustrateLabel(cont, GetChangeDerivationPath(i)); + lv_label_set_recolor(path, true); + lv_obj_t *checkBox = GuiCreateSingleCheckBox(cont, _("")); + lv_obj_set_size(checkBox, 45, 45); + g_derivationCheck[i] = checkBox; + if (i == GetCurrentSelectedIndex()) { + lv_obj_add_state(checkBox, LV_STATE_CHECKED); + } + GuiButton_t table[] = { + { + .obj = accountType, + .align = LV_ALIGN_DEFAULT, + .position = {24, 16}, + }, + { + .obj = path, + .align = LV_ALIGN_DEFAULT, + .position = {24, 56}, + }, + { + .obj = checkBox, + .align = LV_ALIGN_RIGHT_MID, + .position = {-24, 0}, + }, + }; + lv_obj_t *button = + GuiCreateButton(cont, 408, buttonHeight, table, NUMBER_OF_ARRAYS(table), + SelectDerivationHandler, g_derivationCheck[i]); + lv_obj_align(button, LV_ALIGN_TOP_MID, 0, i * buttonHeight); + if (i != 0) { + static lv_point_t points[2] = {{0, 0}, {360, 0}}; + lv_obj_t *line = (lv_obj_t *)GuiCreateLine(cont, points, 2); + lv_obj_align(line, LV_ALIGN_TOP_LEFT, 24, i * buttonHeight); + } + } + + lv_obj_t *egCont = GuiCreateContainerWithParent(scrollCont, 408, 186); + lv_obj_align_to(egCont, cont, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 24); + lv_obj_set_style_bg_color(egCont, WHITE_COLOR, LV_PART_MAIN); + lv_obj_set_style_bg_opa(egCont, LV_OPA_10 + LV_OPA_2, LV_PART_MAIN); + lv_obj_set_style_radius(egCont, 24, LV_PART_MAIN); + g_egCont = egCont; + ShowEgAddressCont(g_egCont); + SetMidBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_MID_LABEL, + _("derivation_path_change")); + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, + CloseDerivationHandler, NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, + NULL); + GUI_DEL_OBJ(g_openMoreHintBox); + + lv_obj_t *tmCont = GuiCreateContainerWithParent(bgCont, 480, 114); + lv_obj_align(tmCont, LV_ALIGN_BOTTOM_LEFT, 0, 0); + lv_obj_set_style_bg_color(tmCont, BLACK_COLOR, LV_PART_MAIN); + lv_obj_t *btn = GuiCreateBtn(tmCont, USR_SYMBOL_CHECK); + lv_obj_align(btn, LV_ALIGN_RIGHT_MID, -36, 0); + lv_obj_add_event_cb(btn, ConfirmDerivationHandler, LV_EVENT_CLICKED, NULL); + g_derivationPathConfirmBtn = btn; + UpdateConfirmBtn(); + + g_derivationPathCont = bgCont; +} + +static void ChangeDerivationPathHandler(lv_event_t *e) +{ + OpenDerivationPath(); + QRCodePause(true); +} +#endif + +static void OpenMoreHandler(lv_event_t *e) +{ + int hintboxHeight = 132; + lv_obj_t *btn = NULL; + WALLET_LIST_INDEX_ENUM *wallet = lv_event_get_user_data(e); + + g_openMoreHintBox = GuiCreateHintBox(hintboxHeight); + lv_obj_add_event_cb(lv_obj_get_child(g_openMoreHintBox, 0), + CloseHintBoxHandler, LV_EVENT_CLICKED, + &g_openMoreHintBox); + btn = GuiCreateSelectButton(g_openMoreHintBox, _("Tutorial"), &imgTutorial, + OpenTutorialHandler, wallet, true); + lv_obj_align(btn, LV_ALIGN_BOTTOM_MID, 0, -24); +} + +int8_t GuiConnectWalletNextTile(void) +{ + switch (g_connectWalletTileView.currentTile) { + case CONNECT_WALLET_SELECT_WALLET: + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, + ConnectWalletReturnHandler, NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_BAR_MORE_INFO, + OpenMoreHandler, &g_connectWalletTileView.walletIndex); + GuiConnectWalletSetQrdata(g_connectWalletTileView.walletIndex); + break; + case CONNECT_WALLET_QRCODE: + return 0; + } + + g_connectWalletTileView.currentTile++; + lv_obj_set_tile_id(g_connectWalletTileView.tileView, + g_connectWalletTileView.currentTile, 0, LV_ANIM_OFF); + return SUCCESS_CODE; +} + +int8_t GuiConnectWalletPrevTile(void) +{ + switch (g_connectWalletTileView.currentTile) { + case CONNECT_WALLET_SELECT_WALLET: + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, ReturnHandler, + NULL); + break; + case CONNECT_WALLET_QRCODE: + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_CLOSE, + CloseTimerCurrentViewHandler, NULL); + SetMidBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_MID_LABEL, + _("connect_wallet_choose_wallet")); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, + NULL); + GuiAnimatingQRCodeDestroyTimer(); + break; + } + g_connectWalletTileView.currentTile--; + lv_obj_set_tile_id(g_connectWalletTileView.tileView, + g_connectWalletTileView.currentTile, 0, LV_ANIM_OFF); + return SUCCESS_CODE; +} + +void GuiConnectWalletRefresh(void) +{ + GuiCloseAttentionHintbox(); + switch (g_connectWalletTileView.currentTile) { + case CONNECT_WALLET_SELECT_WALLET: + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_CLOSE, + CloseTimerCurrentViewHandler, NULL); + SetMidBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_MID_LABEL, + _("connect_wallet_choose_wallet")); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, + NULL); + break; + case CONNECT_WALLET_QRCODE: + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, + ConnectWalletReturnHandler, NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_BAR_MORE_INFO, + OpenMoreHandler, &g_connectWalletTileView.walletIndex); + SetWallet(g_pageWidget->navBarWidget, g_connectWalletTileView.walletIndex, + NULL); +#ifndef BTC_ONLY + if (g_coinListCont != NULL) { + if (g_connectWalletTileView.walletIndex == WALLET_LIST_FEWCHA) { + GUI_DEL_OBJ(g_coinListCont) + } else if (HasSelectAddressWidget()) { + GuiDestroySelectAddressWidget(); + if (g_connectWalletTileView.walletIndex == WALLET_LIST_XRP_TOOLKIT) { + g_coinListCont = GuiCreateSelectAddressWidget( + CHAIN_XRP, GetConnectWalletAccountIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex)), + RefreshAddressIndex); + } + + if (g_connectWalletTileView.walletIndex == WALLET_LIST_KEPLR || g_connectWalletTileView.walletIndex == WALLET_LIST_MINT_SCAN) { + g_coinListCont = GuiCreateSelectAddressWidget( + CHAIN_ATOM, GetConnectWalletAccountIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex)), + RefreshAddressIndex); + } + } + } +#endif + QRCodePause(false); + } +#ifndef BTC_ONLY + if (g_derivationPathCont != NULL) { + GUI_DEL_OBJ(g_derivationPathCont); + OpenDerivationPath(); + } +#endif +} +void GuiConnectWalletDeInit(void) +{ + GUI_DEL_OBJ(g_openMoreHintBox) + GUI_DEL_OBJ(g_manageImg); + GUI_DEL_OBJ(g_coinCont) + GUI_DEL_OBJ(g_derivationPathCont) + GUI_DEL_OBJ(g_noticeWindow) +#ifndef BTC_ONLY + if (g_coinListCont != NULL && HasSelectAddressWidget()) { + g_coinListCont = NULL; + GuiDestroySelectAddressWidget(); + } else { + GUI_DEL_OBJ(g_coinListCont) + } +#endif + CloseToTargetTileView(g_connectWalletTileView.currentTile, + CONNECT_WALLET_SELECT_WALLET); + GUI_DEL_OBJ(g_connectWalletTileView.cont) + if (g_pageWidget != NULL) { + DestroyPageWidget(g_pageWidget); + g_pageWidget = NULL; + } +} + +uint8_t GuiConnectWalletGetWalletIndex(void) +{ + return g_connectWalletTileView.walletIndex; +} \ No newline at end of file diff --git a/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.c b/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.c index a1327eee6..dce82869b 100644 --- a/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.c +++ b/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.c @@ -1,5 +1,503 @@ +#include "gui.h" +#include "gui_views.h" +#include "gui_button.h" +#include "gui_resource.h" +#include "gui_status_bar.h" +#include "gui_keyboard.h" #include "gui_home_widgets.h" +#include "user_memory.h" +#include "gui_hintbox.h" +#include "gui_obj.h" +#include "gui_analyze.h" +#include "gui_chain.h" +#include "account_public_info.h" +#include "gui_keyboard.h" +#include "gui_model.h" +#include "gui_web_auth_widgets.h" +#include "gui_setup_widgets.h" +#include "keystore.h" +#include "gui_page.h" +#include "account_manager.h" +#include "log_print.h" +#include "version.h" +#include "gui_pending_hintbox.h" -void CoinOtherDealHandler(HOME_WALLET_CARD_ENUM coin) +typedef enum { + GestureTop = 1, + GestureBottom = -1, + GestureNone = 0, +} HomeGesture_t; + +#define CARDS_PER_PAGE 6 + +static lv_obj_t *g_manageWalletLabel = NULL; +static lv_obj_t *g_homeWalletCardCont = NULL; +static lv_obj_t *g_homeViewCont = NULL; +static lv_obj_t *g_scanImg = NULL; +static lv_obj_t *g_manageCont = NULL; +static lv_obj_t *g_moreHintbox = NULL; +static bool g_isManageOpen = false; +static bool g_isManageClick = true; +static PageWidget_t *g_pageWidget; +static lv_timer_t *g_countDownTimer = NULL; // count down timer +static lv_obj_t *g_walletButton[HOME_WALLET_CARD_BUTT]; +static lv_obj_t *g_noticeWindow = NULL; +static uint8_t g_currentPage = 0; +static bool g_isScrolling = false; + +static WalletState_t g_walletState[HOME_WALLET_CARD_BUTT] = { + {HOME_WALLET_CARD_BTC, false, "BTC", true}, + HOME_WALLET_STATE_SURPLUS, +}; +static WalletState_t g_walletBakState[HOME_WALLET_CARD_BUTT] = {0}; + +static void GuiInitWalletState(void) +{ + for (size_t i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + g_walletState[i].enable = false; + g_walletState[i].state = false; + } + MnemonicType mnemonicType = GetMnemonicType(); + switch (mnemonicType) { + case MNEMONIC_TYPE_SLIP39: + for (size_t i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + g_walletState[i].enable = true; + } + g_walletState[HOME_WALLET_CARD_ZEC].enable = false; + break; + case MNEMONIC_TYPE_BIP39: + for (size_t i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + g_walletState[i].enable = true; + } + bool isPassphrase = PassphraseExist(GetCurrentAccountIndex()); + if (isPassphrase) { + g_walletState[HOME_WALLET_CARD_ZEC].enable = false; + g_walletState[HOME_WALLET_CARD_ZEC].state = false; + } + break; + default: + break; + } +} + +static const ChainCoinCard_t g_coinCardArray[HOME_WALLET_CARD_BUTT] = { + { + .index = HOME_WALLET_CARD_BTC, + .coin = "BTC", + .chain = "Bitcoin", + .icon = &coinBtc, + }, + HOME_WALLET_CARD_SURPLUS, + +}; + +static void CoinDealHandler(HOME_WALLET_CARD_ENUM coin); +static void AddFlagCountDownTimerHandler(lv_timer_t *timer); +void AccountPublicHomeCoinSet(WalletState_t *walletList, uint8_t count); +static void ResetScrollState(lv_timer_t * timer); +static void HomeScrollHandler(lv_event_t * e); + +static uint8_t GetSelectedWalletCount(void) +{ + uint8_t selectCnt = 0; + for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + if (g_walletState[i].state == true) { + selectCnt++; + } + } + return selectCnt; +} + +static void UpdateManageWalletState(bool needUpdate) +{ + char tempBuf[BUFFER_SIZE_32] = {0}; + uint8_t selectCnt = 0; + g_isManageOpen = false; + int total = 0; + for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + if (GetIsTempAccount() && g_walletState[i].index == HOME_WALLET_CARD_ZEC) { + continue; + } + + if (g_walletState[i].enable) { + total++; + } + if (g_walletBakState[i].state == true) { + selectCnt++; + lv_obj_add_state(g_walletState[i].checkBox, LV_STATE_CHECKED); + } else { + lv_obj_clear_state(g_walletState[i].checkBox, LV_STATE_CHECKED); + } + } + snprintf_s(tempBuf, sizeof(tempBuf), _("home_select_coin_count_fmt"), selectCnt, total); + lv_label_set_text(g_manageWalletLabel, tempBuf); + if (needUpdate) { + if (memcmp(g_walletState, g_walletBakState, sizeof(g_walletState))) { + memcpy(g_walletState, g_walletBakState, sizeof(g_walletBakState)); + AccountPublicHomeCoinSet(g_walletState, NUMBER_OF_ARRAYS(g_walletState)); + } + } +} + +bool GuiHomePageIsTop(void) +{ + return GuiCheckIfTopView(&g_homeView) && g_manageCont == NULL; +} + +void ReturnManageWalletHandler(lv_event_t *e) +{ + UpdateManageWalletState(false); + GUI_DEL_OBJ(g_manageCont); + GuiEmitSignal(GUI_EVENT_REFRESH, NULL, 0); +} + +static bool UpdateStartIndex(int8_t gesture, uint8_t totalCount) +{ + int8_t newPage = g_currentPage + gesture; + + if (newPage < 0 || newPage * CARDS_PER_PAGE >= totalCount) { + return false; + } + + g_currentPage = newPage; + return true; +} + +static void UpdateHomeConnectWalletCard(HomeGesture_t gesture) +{ + lv_obj_t *walletCardCont = g_homeWalletCardCont; + if (lv_obj_get_child_cnt(walletCardCont) > 0) { + lv_obj_clean(walletCardCont); + } + uint8_t currentCoinAmount = 0; + uint8_t totalCoinAmount = 0xFF; + totalCoinAmount = GetSelectedWalletCount(); + UpdateStartIndex(gesture, totalCoinAmount); + + for (int i = 0, j = 0; i < HOME_WALLET_CARD_BUTT; i++) { + if ((i - j) < g_currentPage * 6) { + continue; + } + + lv_obj_t *coinLabel = GuiCreateTextLabel(walletCardCont, g_coinCardArray[i].coin); + lv_obj_t *chainLabel = GuiCreateNoticeLabel(walletCardCont, g_coinCardArray[i].chain); + lv_obj_t *icon = GuiCreateImg(walletCardCont, g_coinCardArray[i].icon); + GuiButton_t table[3] = { + {.obj = icon, .align = LV_ALIGN_TOP_MID, .position = {0, 30},}, + {.obj = coinLabel, .align = LV_ALIGN_TOP_MID, .position = {0, 92},}, + {.obj = chainLabel, .align = LV_ALIGN_TOP_MID, .position = {0, 130},}, + }; + lv_obj_t *button = GuiCreateButton(walletCardCont, 208, 176, table, NUMBER_OF_ARRAYS(table), + NULL, (void *) & (g_coinCardArray[i].index)); + lv_obj_add_event_cb(button, HomeScrollHandler, LV_EVENT_ALL, (void *) & (g_coinCardArray[i].index)); + lv_obj_clear_flag(button, LV_OBJ_FLAG_GESTURE_BUBBLE); + lv_obj_align(button, LV_ALIGN_DEFAULT, 24 + ((i - j) % 2) * 224, + 144 - GUI_MAIN_AREA_OFFSET + (((i - j) % 6) / 2) * 192); + lv_obj_set_style_bg_color(button, WHITE_COLOR, LV_PART_MAIN); + lv_obj_set_style_bg_opa(button, LV_OPA_12, LV_PART_MAIN); + lv_obj_set_style_radius(button, 24, LV_PART_MAIN); + if (currentCoinAmount++ == 5) { + break; + } + } +} + +static void CoinDealHandler(HOME_WALLET_CARD_ENUM coin) +{ + if (coin >= HOME_WALLET_CARD_BUTT) { + return; + } + switch (coin) { + case HOME_WALLET_CARD_BTC: + GuiFrameOpenViewWithParam(&g_utxoReceiveView, &coin, sizeof(coin)); + break; + default: + GuiFrameOpenViewWithParam(&g_standardReceiveView, &coin, sizeof(coin)); + break; + } +} + +void RecalculateManageWalletState(void) +{ + WalletState_t walletState[HOME_WALLET_CARD_BUTT]; + memcpy(walletState, g_walletState, sizeof(g_walletState)); + AccountPublicHomeCoinGet(g_walletState, NUMBER_OF_ARRAYS(g_walletState)); + AccountPublicHomeCoinSet(walletState, NUMBER_OF_ARRAYS(walletState)); +} + +static void ManageCoinChainHandler(lv_event_t *e) +{ + bool state; + WalletState_t *wallet = lv_event_get_user_data(e); + lv_obj_t *parent = lv_obj_get_parent(lv_event_get_target(e)); + state = lv_obj_has_state(lv_obj_get_child(parent, lv_obj_get_child_cnt(parent) - 1), LV_STATE_CHECKED); + g_walletBakState[wallet->index].state = state; + UpdateManageWalletState(false); +} + +void ScanQrCodeHandler(lv_event_t *e) +{ + g_isManageClick = false; + if (g_countDownTimer != NULL) { + lv_timer_del(g_countDownTimer); + g_countDownTimer = NULL; + } + GuiFrameOpenView(lv_event_get_user_data(e)); +} + +void ConfirmManageAssetsHandler(lv_event_t *e) +{ + g_currentPage = 0; + UpdateManageWalletState(true); + UpdateHomeConnectWalletCard(GestureNone); + GUI_DEL_OBJ(g_manageCont) + GuiHomeRefresh(); +} + +static void OpenMoreViewHandler(lv_event_t *e) +{ + GUI_DEL_OBJ(g_moreHintbox) + GuiFrameOpenView(lv_event_get_user_data(e)); +} + +static void OpenMoreSettingHandler(lv_event_t *e) +{ + MoreInfoTable_t moreInfoTable[] = { + {.name = _("home_more_connect_wallet"), .src = &imgConnect, .callBack = OpenMoreViewHandler, &g_connectWalletView}, + {.name = _("device_setting_mid_btn"), .src = &imgSettings, .callBack = OpenMoreViewHandler, &g_settingView}, + }; + g_moreHintbox = GuiCreateMoreInfoHintBox(NULL, NULL, moreInfoTable, NUMBER_OF_ARRAYS(moreInfoTable), true, &g_moreHintbox); +} + +static void OpenManageAssetsHandler(lv_event_t *e) +{ + if (g_isManageClick == false) { + return; + } + memcpy(&g_walletBakState, &g_walletState, sizeof(g_walletState)); + g_manageCont = GuiCreateContainer(lv_obj_get_width(lv_scr_act()), lv_obj_get_height(lv_scr_act()) - + GUI_MAIN_AREA_OFFSET); + lv_obj_add_flag(g_manageCont, LV_OBJ_FLAG_CLICKABLE); + lv_obj_align(g_manageCont, LV_ALIGN_DEFAULT, 0, GUI_MAIN_AREA_OFFSET); + lv_obj_t *checkBoxCont = GuiCreateContainerWithParent(g_manageCont, lv_obj_get_width(lv_scr_act()), 542); + lv_obj_set_align(checkBoxCont, LV_ALIGN_DEFAULT); + lv_obj_add_flag(checkBoxCont, LV_OBJ_FLAG_SCROLLABLE); + lv_obj_set_scrollbar_mode(checkBoxCont, LV_SCROLLBAR_MODE_OFF); + + int heightIndex = 0; + for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + lv_obj_t *coinLabel = GuiCreateTextLabel(checkBoxCont, g_coinCardArray[i].coin); + lv_obj_t *chainLabel = GuiCreateNoticeLabel(checkBoxCont, g_coinCardArray[i].chain); + lv_obj_t *icon = GuiCreateImg(checkBoxCont, g_coinCardArray[i].icon); + lv_obj_t *checkbox = GuiCreateMultiCheckBox(checkBoxCont, _("")); + lv_obj_set_style_pad_top(checkbox, 32, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_size(checkbox, 446, 96); + g_walletState[i].checkBox = checkbox; + uint8_t tableLen = 4; + GuiButton_t table[4] = { + {.obj = icon, .align = LV_ALIGN_LEFT_MID, .position = {24, 0}}, + {.obj = coinLabel, .align = LV_ALIGN_DEFAULT, .position = {100, 13}}, + {.obj = chainLabel, .align = LV_ALIGN_DEFAULT, .position = {100, 53}}, + {.obj = checkbox, .align = LV_ALIGN_TOP_MID, .position = {-10, 0}}, + }; + + lv_obj_t *button = GuiCreateButton(checkBoxCont, 456, 96, table, tableLen, + ManageCoinChainHandler, &g_walletState[i]); + g_walletButton[i] = button; + if (!g_walletState[i].enable) { + lv_obj_add_flag(button, LV_OBJ_FLAG_HIDDEN); + continue; + } + lv_obj_align(button, LV_ALIGN_TOP_MID, 0, 96 * heightIndex); + heightIndex++; + } + + if (GetMnemonicType() == MNEMONIC_TYPE_TON) { + lv_obj_t *label = GuiCreateIllustrateLabel(checkBoxCont, _("import_ton_mnemonic_desc")); + lv_obj_set_width(label, 416); + lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); + lv_obj_align(label, LV_ALIGN_TOP_LEFT, 32, 144); + } + + lv_obj_t *btn = GuiCreateBtn(g_manageCont, USR_SYMBOL_CHECK); + lv_obj_add_event_cb(btn, ConfirmManageAssetsHandler, LV_EVENT_CLICKED, NULL); + lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -36, -24); + + lv_obj_t *label = GuiCreateTextLabel(g_manageCont, ""); + lv_obj_align_to(label, btn, LV_ALIGN_OUT_LEFT_MID, -300, 0); + lv_label_set_recolor(label, true); + + g_manageWalletLabel = label; + + UpdateManageWalletState(false); + + SetMidBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_MID_LABEL, _("home_manage_assets")); + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, ReturnManageWalletHandler, NULL); + // TODO: add search + // GuiNvsBarSetRightCb(NVS_BAR_SEARCH, NULL, NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, NULL); +} + +void GuiHomeSetWalletDesc(WalletDesc_t *wallet) +{ + GuiNvsBarSetWalletName((const char *)wallet->name); + GuiSetEmojiIconIndex(wallet->iconIndex); + SetStatusBarEmojiIndex(wallet->iconIndex); + GuiNvsBarSetWalletIcon(GuiGetEmojiIconImg()); +} + +static void HomeScrollHandler(lv_event_t * e) +{ + static lv_point_t touchStart; + static lv_point_t touchEnd; + +#define SWIPE_THRESHOLD 50 + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t * obj = lv_event_get_target(e); + + static bool isDragging = false; + + if (code == LV_EVENT_PRESSED) { + lv_indev_t * indev = lv_indev_get_act(); + lv_indev_get_point(indev, &touchStart); + isDragging = true; + } else if (code == LV_EVENT_PRESSING) { + if (isDragging) { + lv_indev_t * indev = lv_indev_get_act(); + lv_indev_get_point(indev, &touchEnd); + } + } else if (code == LV_EVENT_RELEASED) { + if (isDragging) { + lv_indev_t * indev = lv_indev_get_act(); + lv_indev_get_point(indev, &touchEnd); + int16_t diff_y = touchEnd.y - touchStart.y; + if (abs(diff_y) > SWIPE_THRESHOLD) { + if (diff_y < 0) { + UpdateHomeConnectWalletCard(GestureTop); + g_isScrolling = true; + } else { + UpdateHomeConnectWalletCard(GestureBottom); + g_isScrolling = true; + } + } else { + lv_obj_t *obj = lv_event_get_target(e); + if (obj != g_homeWalletCardCont) { + HOME_WALLET_CARD_ENUM coin; + coin = *(HOME_WALLET_CARD_ENUM *)lv_event_get_user_data(e); + CoinDealHandler(coin); + } + } + + lv_timer_t *timer = lv_timer_create(ResetScrollState, 200, NULL); + lv_timer_set_repeat_count(timer, 1); + isDragging = false; + } + } +} + +static void ResetScrollState(lv_timer_t * timer) +{ + g_isScrolling = false; + lv_timer_del(timer); +} + +void GuiHomeAreaInit(void) +{ + GuiInitWalletState(); + g_pageWidget = CreatePageWidget(); + g_homeViewCont = g_pageWidget->contentZone; + + lv_obj_t *walletCardCont = GuiCreateContainerWithParent(g_homeViewCont, lv_obj_get_width(lv_scr_act()), + lv_obj_get_height(lv_scr_act()) - GUI_MAIN_AREA_OFFSET); + lv_obj_add_event_cb(walletCardCont, HomeScrollHandler, LV_EVENT_ALL, NULL); + lv_obj_add_flag(walletCardCont, LV_EVENT_CLICKED); + lv_obj_set_align(walletCardCont, LV_ALIGN_DEFAULT); + lv_obj_clear_flag(walletCardCont, LV_OBJ_FLAG_GESTURE_BUBBLE); + lv_obj_set_scrollbar_mode(walletCardCont, LV_SCROLLBAR_MODE_OFF); + g_homeWalletCardCont = walletCardCont; + + lv_obj_t *img = GuiCreateImg(lv_scr_act(), &imgScan); + lv_obj_align(img, LV_ALIGN_BOTTOM_RIGHT, -32, -32); + lv_obj_add_event_cb(img, ScanQrCodeHandler, LV_EVENT_CLICKED, &g_scanView); + lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE); + g_scanImg = img; +} + +void GuiHomeDisActive(void) +{ + if (g_homeWalletCardCont != NULL) { + lv_obj_add_flag(g_homeWalletCardCont, LV_OBJ_FLAG_HIDDEN); + lv_obj_add_flag(g_scanImg, LV_OBJ_FLAG_HIDDEN); + } +} + +static void AddFlagCountDownTimerHandler(lv_timer_t *timer) +{ + g_isManageClick = true; + lv_timer_del(timer); + g_countDownTimer = NULL; + UNUSED(g_countDownTimer); +} + +void ClearHomePageCurrentIndex(void) +{ + g_currentPage = 0; +} + +void GuiHomeRestart(void) +{ + g_currentPage = 0; + GUI_DEL_OBJ(g_manageCont) + GUI_DEL_OBJ(g_noticeWindow) + GuiHomeRefresh(); +} + +void GuiHomeRefresh(void) +{ + static bool isFirstBeta = true; + if (GetCurrentAccountIndex() > 2) { + return; + } + GuiInitWalletState(); + g_countDownTimer = lv_timer_create(AddFlagCountDownTimerHandler, 500, NULL); + GuiSetSetupPhase(SETUP_PAHSE_DONE); + if (g_manageCont != NULL) { + SetMidBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_MID_LABEL, _("home_manage_assets")); + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, ReturnManageWalletHandler, NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, NULL); + } else { + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_MANAGE, OpenManageAssetsHandler, NULL); + SetNavBarMidBtn(g_pageWidget->navBarWidget, NVS_MID_BUTTON_BUTT, NULL, NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_BAR_MORE_INFO, OpenMoreSettingHandler, NULL); + } + if (g_homeWalletCardCont != NULL) { + lv_obj_clear_flag(g_homeWalletCardCont, LV_OBJ_FLAG_HIDDEN); + lv_obj_clear_flag(g_scanImg, LV_OBJ_FLAG_HIDDEN); + } + GUI_DEL_OBJ(g_moreHintbox) + AccountPublicHomeCoinGet(g_walletState, NUMBER_OF_ARRAYS(g_walletState)); + UpdateHomeConnectWalletCard(GestureNone); + if (isFirstBeta && SOFTWARE_VERSION_BUILD % 2) { + CreateBetaNotice(); + isFirstBeta = false; + } +} + +const ChainCoinCard_t *GetCoinCardByIndex(HOME_WALLET_CARD_ENUM index) +{ + for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + if (g_coinCardArray[i].index == index) { + return &g_coinCardArray[i]; + } + } + return NULL; +} + +void GuiHomeDeInit(void) { -} \ No newline at end of file + if (g_pageWidget != NULL) { + DestroyPageWidget(g_pageWidget); + g_pageWidget = NULL; + } + GUI_DEL_OBJ(g_noticeWindow); +} diff --git a/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.h b/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.h index 5305ca8c3..f4bd944e6 100644 --- a/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.h +++ b/src/ui/gui_widgets/multi/cyberpunk/gui_cyberpunk_home_widgets.h @@ -13,5 +13,7 @@ .icon = &coinZec, \ } +#define HOME_WALLET_HIDDEN_CARD_ENUM HOME_WALLET_CARD_BUTT + #endif /* _GUI_CYBERPUNK_HOME_WIDGETS_H */ #endif \ No newline at end of file diff --git a/src/ui/gui_widgets/gui_connect_wallet_widgets.c b/src/ui/gui_widgets/multi/general/gui_connect_wallet_widgets.c similarity index 99% rename from src/ui/gui_widgets/gui_connect_wallet_widgets.c rename to src/ui/gui_widgets/multi/general/gui_connect_wallet_widgets.c index 9e49461ea..dd79e040b 100644 --- a/src/ui/gui_widgets/gui_connect_wallet_widgets.c +++ b/src/ui/gui_widgets/multi/general/gui_connect_wallet_widgets.c @@ -32,6 +32,22 @@ typedef enum { CONNECT_WALLET_BUTT, } CONNECT_WALLET_ENUM; +typedef struct { + int8_t index; + bool state; + lv_obj_t *checkBox; + lv_obj_t *uncheckedImg; + lv_obj_t *checkedImg; +} CoinState_t; + +typedef struct ConnectWalletWidget { + uint32_t currentTile; + lv_obj_t *cont; + lv_obj_t *tileView; + WALLET_LIST_INDEX_ENUM walletIndex; + lv_obj_t *qrCode; +} ConnectWalletWidget_t; + WalletListItem_t g_walletListArray[] = { #ifndef BTC_ONLY {WALLET_LIST_KEYSTONE, &walletListKeystone, false}, @@ -79,14 +95,6 @@ WalletListItem_t g_walletListArray[] = { #endif }; -typedef struct ConnectWalletWidget { - uint32_t currentTile; - lv_obj_t *cont; - lv_obj_t *tileView; - WALLET_LIST_INDEX_ENUM walletIndex; - lv_obj_t *qrCode; -} ConnectWalletWidget_t; - #ifndef BTC_ONLY typedef struct { int8_t index; diff --git a/src/ui/gui_widgets/multi/general/gui_general_home_widgets.c b/src/ui/gui_widgets/multi/general/gui_general_home_widgets.c index a1327eee6..a357c0224 100644 --- a/src/ui/gui_widgets/multi/general/gui_general_home_widgets.c +++ b/src/ui/gui_widgets/multi/general/gui_general_home_widgets.c @@ -1,5 +1,684 @@ +#include "gui.h" +#include "gui_views.h" +#include "gui_button.h" +#include "gui_resource.h" +#include "gui_status_bar.h" +#include "gui_keyboard.h" #include "gui_home_widgets.h" +#include "user_memory.h" +#include "gui_hintbox.h" +#include "gui_obj.h" +#include "gui_analyze.h" +#include "gui_chain.h" +#include "account_public_info.h" +#include "gui_keyboard.h" +#include "gui_model.h" +#include "gui_web_auth_widgets.h" +#include "gui_setup_widgets.h" +#include "keystore.h" +#include "gui_page.h" +#include "account_manager.h" +#include "log_print.h" +#include "version.h" +#include "gui_pending_hintbox.h" -void CoinOtherDealHandler(HOME_WALLET_CARD_ENUM coin) +typedef enum { + GestureTop = 1, + GestureBottom = -1, + GestureNone = 0, +} HomeGesture_t; + +#define CARDS_PER_PAGE 6 + +static lv_obj_t *g_manageWalletLabel = NULL; +static lv_obj_t *g_homeWalletCardCont = NULL; +static lv_obj_t *g_homeViewCont = NULL; +static lv_obj_t *g_scanImg = NULL; +static lv_obj_t *g_manageCont = NULL; +static lv_obj_t *g_moreHintbox = NULL; +static bool g_isManageOpen = false; +static bool g_isManageClick = true; +static PageWidget_t *g_pageWidget; +static lv_timer_t *g_countDownTimer = NULL; // count down timer +static lv_obj_t *g_walletButton[HOME_WALLET_CARD_BUTT]; +static lv_obj_t *g_cosmosPulldownImg = NULL; +static lv_obj_t *g_endCosmosLine = NULL; +static lv_obj_t *g_lastCosmosLine = NULL; +static lv_obj_t *g_noticeWindow = NULL; +static uint8_t g_currentPage = 0; +static bool g_isScrolling = false; + +static WalletState_t g_walletState[HOME_WALLET_CARD_BUTT] = { + {HOME_WALLET_CARD_BTC, false, "BTC", true}, + HOME_WALLET_STATE_SURPLUS, +}; +static WalletState_t g_walletBakState[HOME_WALLET_CARD_BUTT] = {0}; +static KeyboardWidget_t *g_keyboardWidget = NULL; + +static void GuiInitWalletState(void) +{ + for (size_t i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + g_walletState[i].enable = false; + g_walletState[i].state = false; + } + MnemonicType mnemonicType = GetMnemonicType(); + switch (mnemonicType) { + case MNEMONIC_TYPE_SLIP39: + for (size_t i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + g_walletState[i].enable = true; + } + g_walletState[HOME_WALLET_CARD_BNB].enable = false; + g_walletState[HOME_WALLET_CARD_DOT].enable = false; + g_walletState[HOME_WALLET_CARD_ADA].enable = false; + g_walletState[HOME_WALLET_CARD_TON].enable = true; + break; + case MNEMONIC_TYPE_BIP39: + for (size_t i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + g_walletState[i].enable = true; + } + g_walletState[HOME_WALLET_CARD_BNB].enable = false; + g_walletState[HOME_WALLET_CARD_DOT].enable = false; + g_walletState[HOME_WALLET_CARD_ADA].enable = true; + g_walletState[HOME_WALLET_CARD_TON].enable = true; + break; + default: + g_walletState[HOME_WALLET_CARD_TON].enable = true; + g_walletState[HOME_WALLET_CARD_TON].state = true; + break; + } +} + +static const ChainCoinCard_t g_coinCardArray[HOME_WALLET_CARD_BUTT] = { + { + .index = HOME_WALLET_CARD_BTC, + .coin = "BTC", + .chain = "Bitcoin", + .icon = &coinBtc, + }, + HOME_WALLET_CARD_SURPLUS, + +}; + +static void CoinDealHandler(HOME_WALLET_CARD_ENUM coin); +static void AddFlagCountDownTimerHandler(lv_timer_t *timer); +void AccountPublicHomeCoinSet(WalletState_t *walletList, uint8_t count); +static void CloseArHintbox(void); +static void ResetScrollState(lv_timer_t * timer); +static void HomeScrollHandler(lv_event_t * e); + +static void CloseArHintbox(void) +{ + GuiCloseAttentionHintbox(); + if (g_keyboardWidget != NULL) { + GuiDeleteKeyboardWidget(g_keyboardWidget); + } +} + +static uint8_t GetSelectedWalletCount(void) +{ + uint8_t selectCnt = 0; + for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + if (g_walletState[i].index == HOME_WALLET_CARD_COSMOS) { + continue; + } + if (GetIsTempAccount() && g_walletState[i].index == HOME_WALLET_CARD_ARWEAVE) { + continue; + } + + if (g_walletState[i].state == true) { + selectCnt++; + } + } + return selectCnt; +} + +static void UpdateManageWalletState(bool needUpdate) +{ + char tempBuf[BUFFER_SIZE_32] = {0}; + uint8_t selectCnt = 0; + g_isManageOpen = false; + int total = 0; + for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + if (g_walletState[i].index == HOME_WALLET_CARD_COSMOS) { + continue; + } + if (GetIsTempAccount() && g_walletState[i].index == HOME_WALLET_CARD_ARWEAVE) { + continue; + } + + if (g_walletState[i].enable) { + total++; + } + if (g_walletBakState[i].state == true) { + selectCnt++; + lv_obj_add_state(g_walletState[i].checkBox, LV_STATE_CHECKED); + } else { + lv_obj_clear_state(g_walletState[i].checkBox, LV_STATE_CHECKED); + } + } + snprintf_s(tempBuf, sizeof(tempBuf), _("home_select_coin_count_fmt"), selectCnt, total); + lv_label_set_text(g_manageWalletLabel, tempBuf); + if (needUpdate) { + if (memcmp(g_walletState, g_walletBakState, sizeof(g_walletState))) { + memcpy(g_walletState, g_walletBakState, sizeof(g_walletBakState)); + AccountPublicHomeCoinSet(g_walletState, NUMBER_OF_ARRAYS(g_walletState)); + } + } +} + +bool GuiHomePageIsTop(void) +{ + return GuiCheckIfTopView(&g_homeView) && g_manageCont == NULL; +} + +void ReturnManageWalletHandler(lv_event_t *e) +{ + UpdateManageWalletState(false); + GUI_DEL_OBJ(g_lastCosmosLine) + GUI_DEL_OBJ(g_manageCont); + GuiEmitSignal(GUI_EVENT_REFRESH, NULL, 0); +} + +static bool UpdateStartIndex(int8_t gesture, uint8_t totalCount) +{ + int8_t newPage = g_currentPage + gesture; + + if (newPage < 0 || newPage * CARDS_PER_PAGE >= totalCount) { + return false; + } + + g_currentPage = newPage; + return true; +} + +static void UpdateHomeConnectWalletCard(HomeGesture_t gesture) +{ + lv_obj_t *walletCardCont = g_homeWalletCardCont; + if (lv_obj_get_child_cnt(walletCardCont) > 0) { + lv_obj_clean(walletCardCont); + } + uint8_t currentCoinAmount = 0; + uint8_t totalCoinAmount = 0xFF; + totalCoinAmount = GetSelectedWalletCount(); + UpdateStartIndex(gesture, totalCoinAmount); + + for (int i = 0, j = 0; i < HOME_WALLET_CARD_BUTT; i++) { + if (g_walletState[i].index == HOME_WALLET_CARD_COSMOS || + (g_walletState[i].index == HOME_WALLET_CARD_ARWEAVE && GetIsTempAccount()) || + g_walletState[i].state == false || + g_walletState[i].enable == false) { + j++; + continue; + } + + if ((i - j) < g_currentPage * 6) { + continue; + } + + lv_obj_t *coinLabel = GuiCreateTextLabel(walletCardCont, g_coinCardArray[i].coin); + lv_obj_t *chainLabel = GuiCreateNoticeLabel(walletCardCont, g_coinCardArray[i].chain); + lv_obj_t *icon = GuiCreateImg(walletCardCont, g_coinCardArray[i].icon); + GuiButton_t table[3] = { + {.obj = icon, .align = LV_ALIGN_TOP_MID, .position = {0, 30},}, + {.obj = coinLabel, .align = LV_ALIGN_TOP_MID, .position = {0, 92},}, + {.obj = chainLabel, .align = LV_ALIGN_TOP_MID, .position = {0, 130},}, + }; + lv_obj_t *button = GuiCreateButton(walletCardCont, 208, 176, table, NUMBER_OF_ARRAYS(table), + NULL, (void *) & (g_coinCardArray[i].index)); + lv_obj_add_event_cb(button, HomeScrollHandler, LV_EVENT_ALL, (void *) & (g_coinCardArray[i].index)); + lv_obj_clear_flag(button, LV_OBJ_FLAG_GESTURE_BUBBLE); + lv_obj_align(button, LV_ALIGN_DEFAULT, 24 + ((i - j) % 2) * 224, + 144 - GUI_MAIN_AREA_OFFSET + (((i - j) % 6) / 2) * 192); + lv_obj_set_style_bg_color(button, WHITE_COLOR, LV_PART_MAIN); + lv_obj_set_style_bg_opa(button, LV_OPA_12, LV_PART_MAIN); + lv_obj_set_style_radius(button, 24, LV_PART_MAIN); + if (currentCoinAmount++ == 5) { + break; + } + } +} + +void GuiShowRsaSetupasswordHintbox(void) +{ + g_keyboardWidget = GuiCreateKeyboardWidget(g_pageWidget->contentZone); + SetKeyboardWidgetSelf(g_keyboardWidget, &g_keyboardWidget); + static uint16_t sig = SIG_SETUP_RSA_PRIVATE_KEY_WITH_PASSWORD; + SetKeyboardWidgetSig(g_keyboardWidget, &sig); +} + +static void GuiARAddressCheckConfirmHandler(lv_event_t *event) +{ + GUI_DEL_OBJ(g_noticeWindow); + GuiCreateAttentionHintbox(SIG_SETUP_RSA_PRIVATE_KEY_RECEIVE_CONFIRM); +} + +static void GuiOpenARAddressNoticeWindow() +{ + g_noticeWindow = GuiCreateGeneralHintBox(&imgWarn, _("ar_address_check"), _("ar_address_check_desc"), NULL, _("Not Now"), WHITE_COLOR_OPA20, _("Understand"), ORANGE_COLOR); + lv_obj_add_event_cb(lv_obj_get_child(g_noticeWindow, 0), CloseHintBoxHandler, LV_EVENT_CLICKED, &g_noticeWindow); + + lv_obj_t *btn = GuiGetHintBoxRightBtn(g_noticeWindow); + lv_obj_set_width(btn, 192); + lv_obj_set_style_text_font(lv_obj_get_child(btn, 0), &buttonFont, 0); + lv_obj_add_event_cb(btn, GuiARAddressCheckConfirmHandler, LV_EVENT_CLICKED, &g_noticeWindow); + + btn = GuiGetHintBoxLeftBtn(g_noticeWindow); + lv_obj_set_width(btn, 192); + lv_obj_set_style_text_font(lv_obj_get_child(btn, 0), &buttonFont, 0); + lv_obj_add_event_cb(btn, CloseHintBoxHandler, LV_EVENT_CLICKED, &g_noticeWindow); + + lv_obj_t *img = GuiCreateImg(g_noticeWindow, &imgClose); + lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE); + lv_obj_add_event_cb(img, CloseHintBoxHandler, LV_EVENT_CLICKED, &g_noticeWindow); + lv_obj_align_to(img, lv_obj_get_child(g_noticeWindow, 1), LV_ALIGN_TOP_RIGHT, -36, 36); +} + +static void CoinDealHandler(HOME_WALLET_CARD_ENUM coin) +{ + if (coin >= HOME_WALLET_CARD_BUTT) { + return; + } + switch (coin) { + case HOME_WALLET_CARD_BTC: + case HOME_WALLET_CARD_LTC: + case HOME_WALLET_CARD_DASH: + case HOME_WALLET_CARD_BCH: + GuiFrameOpenViewWithParam(&g_utxoReceiveView, &coin, sizeof(coin)); + break; + case HOME_WALLET_CARD_ETH: + case HOME_WALLET_CARD_SOL: + case HOME_WALLET_CARD_HNT: + GuiFrameOpenViewWithParam(&g_multiPathCoinReceiveView, &coin, sizeof(coin)); + break; + case HOME_WALLET_CARD_ADA: + GuiFrameOpenViewWithParam(&g_multiAccountsReceiveView, &coin, sizeof(coin)); + break; + case HOME_WALLET_CARD_ARWEAVE: { + bool shouldGenerateArweaveXPub = IsArweaveSetupComplete(); + if (!shouldGenerateArweaveXPub) { + GuiOpenARAddressNoticeWindow(); + break; + } + GuiFrameOpenViewWithParam(&g_standardReceiveView, &coin, sizeof(coin)); + break; + } + default: + GuiFrameOpenViewWithParam(&g_standardReceiveView, &coin, sizeof(coin)); + break; + } +} + +void GuiRemoveKeyboardWidget(void) +{ + if (g_keyboardWidget != NULL) { + GuiDeleteKeyboardWidget(g_keyboardWidget); + } + GuiModelRsaGenerateKeyPair(); +} + +void RecalculateManageWalletState(void) +{ + WalletState_t walletState[HOME_WALLET_CARD_BUTT]; + memcpy(walletState, g_walletState, sizeof(g_walletState)); + AccountPublicHomeCoinGet(g_walletState, NUMBER_OF_ARRAYS(g_walletState)); + AccountPublicHomeCoinSet(walletState, NUMBER_OF_ARRAYS(walletState)); +} + +void GuiShowRsaInitializatioCompleteHintbox(void) +{ + GuiPendingHintBoxRemove(); + ClearSecretCache(); + GuiCreateInitializatioCompleteHintbox(); +} + +void GuiHomePasswordErrorCount(void *param) +{ + PasswordVerifyResult_t *passwordVerifyResult = (PasswordVerifyResult_t *)param; + GuiShowErrorNumber(g_keyboardWidget, passwordVerifyResult); +} + +static void UpdateCosmosEnable(bool en) +{ + void (*func)(lv_obj_t *, lv_obj_flag_t); + if (en) { + func = lv_obj_clear_flag; + lv_obj_add_flag(g_endCosmosLine, LV_OBJ_FLAG_HIDDEN); + lv_obj_clear_flag(g_lastCosmosLine, LV_OBJ_FLAG_HIDDEN); + } else { + func = lv_obj_add_flag; + lv_obj_clear_flag(g_endCosmosLine, LV_OBJ_FLAG_HIDDEN); + lv_obj_add_flag(g_lastCosmosLine, LV_OBJ_FLAG_HIDDEN); + } + for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + if (IsCosmosChain(g_coinCardArray[i].index)) { + func(g_walletButton[i], LV_OBJ_FLAG_HIDDEN); + } + } +} + +static void ManageCoinChainHandler(lv_event_t *e) +{ + bool state; + WalletState_t *wallet = lv_event_get_user_data(e); + if (wallet->index == HOME_WALLET_CARD_COSMOS) { + state = g_walletBakState[wallet->index].state; + if (state) { + lv_img_set_src(g_cosmosPulldownImg, &imgArrowRight); + } else { + lv_img_set_src(g_cosmosPulldownImg, &imgArrowDown); + } + UpdateCosmosEnable(!state); + g_walletBakState[wallet->index].state = !state; + } else { + lv_obj_t *parent = lv_obj_get_parent(lv_event_get_target(e)); + state = lv_obj_has_state(lv_obj_get_child(parent, lv_obj_get_child_cnt(parent) - 1), LV_STATE_CHECKED); + g_walletBakState[wallet->index].state = state; + UpdateManageWalletState(false); + } +} + +void ScanQrCodeHandler(lv_event_t *e) +{ + g_isManageClick = false; + if (g_countDownTimer != NULL) { + lv_timer_del(g_countDownTimer); + g_countDownTimer = NULL; + } + GuiFrameOpenView(lv_event_get_user_data(e)); +} + +void ConfirmManageAssetsHandler(lv_event_t *e) +{ + g_currentPage = 0; + UpdateManageWalletState(true); + UpdateHomeConnectWalletCard(GestureNone); + GUI_DEL_OBJ(g_lastCosmosLine) + GUI_DEL_OBJ(g_manageCont) + GuiHomeRefresh(); +} + +static void OpenMoreViewHandler(lv_event_t *e) +{ + GUI_DEL_OBJ(g_moreHintbox) + GuiFrameOpenView(lv_event_get_user_data(e)); +} + +static void OpenMoreSettingHandler(lv_event_t *e) +{ + MoreInfoTable_t moreInfoTable[] = { + {.name = _("home_more_connect_wallet"), .src = &imgConnect, .callBack = OpenMoreViewHandler, &g_connectWalletView}, + {.name = _("device_setting_mid_btn"), .src = &imgSettings, .callBack = OpenMoreViewHandler, &g_settingView}, + }; + g_moreHintbox = GuiCreateMoreInfoHintBox(NULL, NULL, moreInfoTable, NUMBER_OF_ARRAYS(moreInfoTable), true, &g_moreHintbox); +} + +static void OpenManageAssetsHandler(lv_event_t *e) +{ + if (g_isManageClick == false) { + return; + } + memcpy(&g_walletBakState, &g_walletState, sizeof(g_walletState)); + g_manageCont = GuiCreateContainer(lv_obj_get_width(lv_scr_act()), lv_obj_get_height(lv_scr_act()) - + GUI_MAIN_AREA_OFFSET); + lv_obj_add_flag(g_manageCont, LV_OBJ_FLAG_CLICKABLE); + lv_obj_align(g_manageCont, LV_ALIGN_DEFAULT, 0, GUI_MAIN_AREA_OFFSET); + lv_obj_t *checkBoxCont = GuiCreateContainerWithParent(g_manageCont, lv_obj_get_width(lv_scr_act()), 542); + lv_obj_set_align(checkBoxCont, LV_ALIGN_DEFAULT); + lv_obj_add_flag(checkBoxCont, LV_OBJ_FLAG_SCROLLABLE); + lv_obj_set_scrollbar_mode(checkBoxCont, LV_SCROLLBAR_MODE_OFF); + + int heightIndex = 0; + for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + if (GetIsTempAccount() && g_walletState[i].index == HOME_WALLET_CARD_ARWEAVE) { + continue; + } + lv_obj_t *coinLabel = GuiCreateTextLabel(checkBoxCont, g_coinCardArray[i].coin); + lv_obj_t *chainLabel = GuiCreateNoticeLabel(checkBoxCont, g_coinCardArray[i].chain); + lv_obj_t *icon = GuiCreateImg(checkBoxCont, g_coinCardArray[i].icon); + lv_obj_t *checkbox = GuiCreateMultiCheckBox(checkBoxCont, _("")); + lv_obj_set_style_pad_top(checkbox, 32, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_size(checkbox, 446, 96); + g_walletState[i].checkBox = checkbox; + uint8_t tableLen = 4; + GuiButton_t table[4] = { + {.obj = icon, .align = LV_ALIGN_LEFT_MID, .position = {24, 0}}, + {.obj = coinLabel, .align = LV_ALIGN_DEFAULT, .position = {100, 13}}, + {.obj = chainLabel, .align = LV_ALIGN_DEFAULT, .position = {100, 53}}, + {.obj = checkbox, .align = LV_ALIGN_TOP_MID, .position = {-10, 0}}, + }; + if (IsCosmosChain(g_coinCardArray[i].index)) { + table[0].position.x += 12; + table[1].position.x += 12; + table[2].position.x += 12; + } + + if (g_walletState[i].index == HOME_WALLET_CARD_COSMOS) { + // lv_obj_del(table[2].obj); + lv_obj_t *line = GuiCreateDividerLine(checkBoxCont); + lv_obj_align(line, LV_ALIGN_DEFAULT, 0, 96 * heightIndex); + g_endCosmosLine = GuiCreateDividerLine(checkBoxCont); + lv_obj_align(g_endCosmosLine, LV_ALIGN_DEFAULT, 0, 96 * (heightIndex + 1)); + lv_obj_t *cosmosCoinImg = GuiCreateImg(checkBoxCont, &coinCosmosEco); + table[2].obj = cosmosCoinImg; + table[2].align = LV_ALIGN_DEFAULT; + table[2].position.x = 100; + table[2].position.y = 53; + + lv_obj_del(table[3].obj); + g_cosmosPulldownImg = GuiCreateImg(checkBoxCont, &imgArrowRight); + table[3].obj = g_cosmosPulldownImg; + table[3].align = LV_ALIGN_RIGHT_MID; + table[3].position.x = -12; + table[3].position.y = 0; + } + + lv_obj_t *button = GuiCreateButton(checkBoxCont, 456, 96, table, tableLen, + ManageCoinChainHandler, &g_walletState[i]); + g_walletButton[i] = button; + if (IsCosmosChain(g_coinCardArray[i].index)) { + lv_obj_add_flag(button, LV_OBJ_FLAG_HIDDEN); + g_lastCosmosLine = GuiCreateDividerLine(checkBoxCont); + lv_obj_add_flag(g_lastCosmosLine, LV_OBJ_FLAG_HIDDEN); + lv_obj_align(g_lastCosmosLine, LV_ALIGN_DEFAULT, 0, 96 * (heightIndex + 1)); + } + if (!g_walletState[i].enable) { + lv_obj_add_flag(button, LV_OBJ_FLAG_HIDDEN); + continue; + } + lv_obj_align(button, LV_ALIGN_TOP_MID, 0, 96 * heightIndex); + heightIndex++; + } + + if (GetMnemonicType() == MNEMONIC_TYPE_TON) { + lv_obj_t *label = GuiCreateIllustrateLabel(checkBoxCont, _("import_ton_mnemonic_desc")); + lv_obj_set_width(label, 416); + lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); + lv_obj_align(label, LV_ALIGN_TOP_LEFT, 32, 144); + } + + lv_obj_t *btn = GuiCreateBtn(g_manageCont, USR_SYMBOL_CHECK); + lv_obj_add_event_cb(btn, ConfirmManageAssetsHandler, LV_EVENT_CLICKED, NULL); + lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -36, -24); + + lv_obj_t *label = GuiCreateTextLabel(g_manageCont, ""); + lv_obj_align_to(label, btn, LV_ALIGN_OUT_LEFT_MID, -300, 0); + lv_label_set_recolor(label, true); + + g_manageWalletLabel = label; + + UpdateManageWalletState(false); + + SetMidBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_MID_LABEL, _("home_manage_assets")); + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, ReturnManageWalletHandler, NULL); + // TODO: add search + // GuiNvsBarSetRightCb(NVS_BAR_SEARCH, NULL, NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, NULL); +} + +void GuiHomeSetWalletDesc(WalletDesc_t *wallet) +{ + GuiNvsBarSetWalletName((const char *)wallet->name); + GuiSetEmojiIconIndex(wallet->iconIndex); + SetStatusBarEmojiIndex(wallet->iconIndex); + GuiNvsBarSetWalletIcon(GuiGetEmojiIconImg()); +} + +static void HomeScrollHandler(lv_event_t * e) +{ + static lv_point_t touchStart; + static lv_point_t touchEnd; + +#define SWIPE_THRESHOLD 50 + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t * obj = lv_event_get_target(e); + + static bool isDragging = false; + + if (code == LV_EVENT_PRESSED) { + lv_indev_t * indev = lv_indev_get_act(); + lv_indev_get_point(indev, &touchStart); + isDragging = true; + } else if (code == LV_EVENT_PRESSING) { + if (isDragging) { + lv_indev_t * indev = lv_indev_get_act(); + lv_indev_get_point(indev, &touchEnd); + } + } else if (code == LV_EVENT_RELEASED) { + if (isDragging) { + lv_indev_t * indev = lv_indev_get_act(); + lv_indev_get_point(indev, &touchEnd); + int16_t diff_y = touchEnd.y - touchStart.y; + if (abs(diff_y) > SWIPE_THRESHOLD) { + if (diff_y < 0) { + UpdateHomeConnectWalletCard(GestureTop); + g_isScrolling = true; + } else { + UpdateHomeConnectWalletCard(GestureBottom); + g_isScrolling = true; + } + } else { + lv_obj_t *obj = lv_event_get_target(e); + if (obj != g_homeWalletCardCont) { + HOME_WALLET_CARD_ENUM coin; + coin = *(HOME_WALLET_CARD_ENUM *)lv_event_get_user_data(e); + CoinDealHandler(coin); + } + } + + lv_timer_t *timer = lv_timer_create(ResetScrollState, 200, NULL); + lv_timer_set_repeat_count(timer, 1); + isDragging = false; + } + } +} + +static void ResetScrollState(lv_timer_t * timer) +{ + g_isScrolling = false; + lv_timer_del(timer); +} + +void GuiHomeAreaInit(void) +{ + GuiInitWalletState(); + g_pageWidget = CreatePageWidget(); + g_homeViewCont = g_pageWidget->contentZone; + + lv_obj_t *walletCardCont = GuiCreateContainerWithParent(g_homeViewCont, lv_obj_get_width(lv_scr_act()), + lv_obj_get_height(lv_scr_act()) - GUI_MAIN_AREA_OFFSET); + lv_obj_add_event_cb(walletCardCont, HomeScrollHandler, LV_EVENT_ALL, NULL); + lv_obj_add_flag(walletCardCont, LV_EVENT_CLICKED); + lv_obj_set_align(walletCardCont, LV_ALIGN_DEFAULT); + lv_obj_clear_flag(walletCardCont, LV_OBJ_FLAG_GESTURE_BUBBLE); + lv_obj_set_scrollbar_mode(walletCardCont, LV_SCROLLBAR_MODE_OFF); + g_homeWalletCardCont = walletCardCont; + + lv_obj_t *img = GuiCreateImg(lv_scr_act(), &imgScan); + lv_obj_align(img, LV_ALIGN_BOTTOM_RIGHT, -32, -32); + lv_obj_add_event_cb(img, ScanQrCodeHandler, LV_EVENT_CLICKED, &g_scanView); + lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE); + g_scanImg = img; +} + +void GuiHomeDisActive(void) +{ + if (g_homeWalletCardCont != NULL) { + lv_obj_add_flag(g_homeWalletCardCont, LV_OBJ_FLAG_HIDDEN); + lv_obj_add_flag(g_scanImg, LV_OBJ_FLAG_HIDDEN); + } +} + +static void AddFlagCountDownTimerHandler(lv_timer_t *timer) +{ + g_isManageClick = true; + lv_timer_del(timer); + g_countDownTimer = NULL; + UNUSED(g_countDownTimer); +} + +void ClearHomePageCurrentIndex(void) +{ + g_currentPage = 0; +} + +void GuiHomeRestart(void) +{ + g_currentPage = 0; + GUI_DEL_OBJ(g_manageCont) + GUI_DEL_OBJ(g_noticeWindow) + GuiHomeRefresh(); +} + +void GuiHomeRefresh(void) +{ + static bool isFirstBeta = true; +#ifdef RUST_MEMORY_DEBUG + PrintRustMemoryStatus(); +#endif + if (GetCurrentAccountIndex() > 2) { + return; + } + GuiInitWalletState(); + g_countDownTimer = lv_timer_create(AddFlagCountDownTimerHandler, 500, NULL); + GuiSetSetupPhase(SETUP_PAHSE_DONE); + if (g_manageCont != NULL) { + SetMidBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_MID_LABEL, _("home_manage_assets")); + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, ReturnManageWalletHandler, NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, NULL); + } else { + SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_MANAGE, OpenManageAssetsHandler, NULL); + SetNavBarMidBtn(g_pageWidget->navBarWidget, NVS_MID_BUTTON_BUTT, NULL, NULL); + SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_BAR_MORE_INFO, OpenMoreSettingHandler, NULL); + } + if (g_homeWalletCardCont != NULL) { + lv_obj_clear_flag(g_homeWalletCardCont, LV_OBJ_FLAG_HIDDEN); + lv_obj_clear_flag(g_scanImg, LV_OBJ_FLAG_HIDDEN); + } + GUI_DEL_OBJ(g_moreHintbox) + AccountPublicHomeCoinGet(g_walletState, NUMBER_OF_ARRAYS(g_walletState)); + UpdateHomeConnectWalletCard(GestureNone); + if (isFirstBeta && SOFTWARE_VERSION_BUILD % 2) { + CreateBetaNotice(); + isFirstBeta = false; + } + CloseArHintbox(); +} + +const ChainCoinCard_t *GetCoinCardByIndex(HOME_WALLET_CARD_ENUM index) +{ + for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { + if (g_coinCardArray[i].index == index) { + return &g_coinCardArray[i]; + } + } + return NULL; +} + +void GuiHomeDeInit(void) { -} \ No newline at end of file + if (g_pageWidget != NULL) { + DestroyPageWidget(g_pageWidget); + g_pageWidget = NULL; + } + GUI_DEL_OBJ(g_noticeWindow); +} diff --git a/src/ui/gui_widgets/multi/general/gui_general_home_widgets.h b/src/ui/gui_widgets/multi/general/gui_general_home_widgets.h index 982a5914a..e3bbfa068 100644 --- a/src/ui/gui_widgets/multi/general/gui_general_home_widgets.h +++ b/src/ui/gui_widgets/multi/general/gui_general_home_widgets.h @@ -1,9 +1,8 @@ - #ifdef GENERAL_VERSION +#ifdef GENERAL_VERSION #ifndef _GUI_GENERAL_HOME_WIDGETS_H #define _GUI_GENERAL_HOME_WIDGETS_H #define HOME_WIDGETS_SURPLUS_CARD_ENUM HOME_WALLET_CARD_ETH, \ - HOME_WALLET_CARD_ZEC, \ HOME_WALLET_CARD_SOL, \ HOME_WALLET_CARD_BNB, \ HOME_WALLET_CARD_HNT, \ @@ -416,5 +415,7 @@ .icon = &coinTgd, \ } +#define HOME_WALLET_HIDDEN_CARD_ENUM HOME_WALLET_CARD_COSMOS + #endif #endif \ No newline at end of file diff --git a/src/ui/gui_widgets/multi/gui_multi_accounts_receive_widgets.c b/src/ui/gui_widgets/multi/general/gui_multi_accounts_receive_widgets.c similarity index 100% rename from src/ui/gui_widgets/multi/gui_multi_accounts_receive_widgets.c rename to src/ui/gui_widgets/multi/general/gui_multi_accounts_receive_widgets.c diff --git a/src/ui/gui_widgets/multi/gui_multi_accounts_receive_widgets.h b/src/ui/gui_widgets/multi/general/gui_multi_accounts_receive_widgets.h similarity index 100% rename from src/ui/gui_widgets/multi/gui_multi_accounts_receive_widgets.h rename to src/ui/gui_widgets/multi/general/gui_multi_accounts_receive_widgets.h diff --git a/src/ui/gui_widgets/gui_connect_wallet_widgets.h b/src/ui/gui_widgets/multi/gui_connect_wallet_widgets.h similarity index 89% rename from src/ui/gui_widgets/gui_connect_wallet_widgets.h rename to src/ui/gui_widgets/multi/gui_connect_wallet_widgets.h index 76b21c174..83eaadfee 100644 --- a/src/ui/gui_widgets/gui_connect_wallet_widgets.h +++ b/src/ui/gui_widgets/multi/gui_connect_wallet_widgets.h @@ -66,7 +66,16 @@ typedef struct { #endif } WalletListItem_t; -#ifndef BTC_ONLY +void GuiConnectWalletInit(void); +int8_t GuiConnectWalletNextTile(void); +int8_t GuiConnectWalletPrevTile(void); +void GuiConnectWalletRefresh(void); +void GuiConnectWalletDeInit(void); +void GuiConnectWalletSetQrdata(WALLET_LIST_INDEX_ENUM index); +void GuiConnectWalletHandleURGenerate(char *data, uint16_t len); +void GuiConnectWalletHandleURUpdate(char *data, uint16_t len); +uint8_t GuiConnectWalletGetWalletIndex(void); +#ifdef GENERAL_VERSION typedef enum { BTC, ETH, @@ -91,28 +100,7 @@ typedef enum SOLAccountType { SOLBip44Change, } SOLAccountType; -typedef struct { - int8_t index; - bool state; - lv_obj_t *checkBox; - lv_obj_t *uncheckedImg; - lv_obj_t *checkedImg; -} CoinState_t; -#endif - -void GuiConnectWalletInit(void); -int8_t GuiConnectWalletNextTile(void); -int8_t GuiConnectWalletPrevTile(void); -void GuiConnectWalletRefresh(void); -void GuiConnectWalletDeInit(void); -void GuiConnectWalletSetQrdata(WALLET_LIST_INDEX_ENUM index); -#ifndef BTC_ONLY ETHAccountType GetMetamaskAccountType(void); -#endif -void GuiConnectWalletHandleURGenerate(char *data, uint16_t len); -void GuiConnectWalletHandleURUpdate(char *data, uint16_t len); -uint8_t GuiConnectWalletGetWalletIndex(void); -#ifndef BTC_ONLY SOLAccountType GetSolflareAccountType(void); SOLAccountType GetHeliumAccountType(void); void GuiPrepareArConnectWalletView(void); diff --git a/src/ui/gui_widgets/multi/gui_home_widgets.c b/src/ui/gui_widgets/multi/gui_home_widgets.c deleted file mode 100644 index e4a165b0d..000000000 --- a/src/ui/gui_widgets/multi/gui_home_widgets.c +++ /dev/null @@ -1,702 +0,0 @@ -#include "gui.h" -#include "gui_views.h" -#include "gui_button.h" -#include "gui_resource.h" -#include "gui_status_bar.h" -#include "gui_keyboard.h" -#include "gui_home_widgets.h" -#include "user_memory.h" -#include "gui_hintbox.h" -#include "gui_obj.h" -#include "gui_analyze.h" -#include "gui_chain.h" -#include "account_public_info.h" -#include "gui_keyboard.h" -#include "gui_model.h" -#include "gui_web_auth_widgets.h" -#include "gui_setup_widgets.h" -#include "keystore.h" -#include "gui_page.h" -#include "account_manager.h" -#include "log_print.h" -#include "version.h" -#include "gui_pending_hintbox.h" - -typedef enum { - GestureTop = 1, - GestureBottom = -1, - GestureNone = 0, -} HomeGesture_t; - -#define CARDS_PER_PAGE 6 - -static lv_obj_t *g_manageWalletLabel = NULL; -static lv_obj_t *g_homeWalletCardCont = NULL; -static lv_obj_t *g_homeViewCont = NULL; -static lv_obj_t *g_scanImg = NULL; -static lv_obj_t *g_manageCont = NULL; -static lv_obj_t *g_moreHintbox = NULL; -static bool g_isManageOpen = false; -static bool g_isManageClick = true; -static PageWidget_t *g_pageWidget; -static lv_timer_t *g_countDownTimer = NULL; // count down timer -static lv_obj_t *g_walletButton[HOME_WALLET_CARD_BUTT]; -static lv_obj_t *g_cosmosPulldownImg = NULL; -static lv_obj_t *g_endCosmosLine = NULL; -static lv_obj_t *g_lastCosmosLine = NULL; -static lv_obj_t *g_noticeWindow = NULL; -static uint8_t g_currentPage = 0; -static bool g_isScrolling = false; - -static WalletState_t g_walletState[HOME_WALLET_CARD_BUTT] = { - {HOME_WALLET_CARD_BTC, false, "BTC", true}, - HOME_WALLET_STATE_SURPLUS, -}; -static WalletState_t g_walletBakState[HOME_WALLET_CARD_BUTT] = {0}; -static KeyboardWidget_t *g_keyboardWidget = NULL; - -static void GuiInitWalletState(void) -{ - for (size_t i = 0; i < HOME_WALLET_CARD_BUTT; i++) { - g_walletState[i].enable = false; - g_walletState[i].state = false; - } - MnemonicType mnemonicType = GetMnemonicType(); - switch (mnemonicType) { - case MNEMONIC_TYPE_SLIP39: - for (size_t i = 0; i < HOME_WALLET_CARD_BUTT; i++) { - g_walletState[i].enable = true; - } - g_walletState[HOME_WALLET_CARD_BNB].enable = false; - g_walletState[HOME_WALLET_CARD_DOT].enable = false; - g_walletState[HOME_WALLET_CARD_ADA].enable = false; - g_walletState[HOME_WALLET_CARD_ZEC].enable = false; - g_walletState[HOME_WALLET_CARD_TON].enable = true; - break; - case MNEMONIC_TYPE_BIP39: - for (size_t i = 0; i < HOME_WALLET_CARD_BUTT; i++) { - g_walletState[i].enable = true; - } - g_walletState[HOME_WALLET_CARD_BNB].enable = false; - g_walletState[HOME_WALLET_CARD_DOT].enable = false; - g_walletState[HOME_WALLET_CARD_ADA].enable = true; - g_walletState[HOME_WALLET_CARD_TON].enable = true; - bool isPassphrase = PassphraseExist(GetCurrentAccountIndex()); - if (isPassphrase) { - g_walletState[HOME_WALLET_CARD_ZEC].enable = false; - g_walletState[HOME_WALLET_CARD_ZEC].state = false; - } - break; - default: - g_walletState[HOME_WALLET_CARD_TON].enable = true; - g_walletState[HOME_WALLET_CARD_TON].state = true; - break; - } -} - -static const ChainCoinCard_t g_coinCardArray[HOME_WALLET_CARD_BUTT] = { - { - .index = HOME_WALLET_CARD_BTC, - .coin = "BTC", - .chain = "Bitcoin", - .icon = &coinBtc, - }, - HOME_WALLET_CARD_SURPLUS, - -}; - -static void CoinDealHandler(HOME_WALLET_CARD_ENUM coin); -static void AddFlagCountDownTimerHandler(lv_timer_t *timer); -void AccountPublicHomeCoinSet(WalletState_t *walletList, uint8_t count); -static void CloseArHintbox(void); -static void ResetScrollState(lv_timer_t * timer); -static void HomeScrollHandler(lv_event_t * e); - -static void CloseArHintbox(void) -{ - GuiCloseAttentionHintbox(); - if (g_keyboardWidget != NULL) { - GuiDeleteKeyboardWidget(g_keyboardWidget); - } -} - -static uint8_t GetSelectedWalletCount(void) -{ - uint8_t selectCnt = 0; - for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { - if (g_walletState[i].index == HOME_WALLET_CARD_COSMOS) { - continue; - } - if (GetIsTempAccount() && g_walletState[i].index == HOME_WALLET_CARD_ARWEAVE) { - continue; - } - - if (g_walletState[i].state == true) { - selectCnt++; - } - } - return selectCnt; -} - -static void UpdateManageWalletState(bool needUpdate) -{ - char tempBuf[BUFFER_SIZE_32] = {0}; - uint8_t selectCnt = 0; - g_isManageOpen = false; - int total = 0; - for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { - if (g_walletState[i].index == HOME_WALLET_CARD_COSMOS) { - continue; - } - if (GetIsTempAccount() && g_walletState[i].index == HOME_WALLET_CARD_ARWEAVE) { - continue; - } - if (GetIsTempAccount() && g_walletState[i].index == HOME_WALLET_CARD_ZEC) { - continue; - } - - if (g_walletState[i].enable) { - total++; - } - if (g_walletBakState[i].state == true) { - selectCnt++; - lv_obj_add_state(g_walletState[i].checkBox, LV_STATE_CHECKED); - } else { - lv_obj_clear_state(g_walletState[i].checkBox, LV_STATE_CHECKED); - } - } - snprintf_s(tempBuf, sizeof(tempBuf), _("home_select_coin_count_fmt"), selectCnt, total); - lv_label_set_text(g_manageWalletLabel, tempBuf); - if (needUpdate) { - if (memcmp(g_walletState, g_walletBakState, sizeof(g_walletState))) { - memcpy(g_walletState, g_walletBakState, sizeof(g_walletBakState)); - AccountPublicHomeCoinSet(g_walletState, NUMBER_OF_ARRAYS(g_walletState)); - } - } -} - -bool GuiHomePageIsTop(void) -{ - return GuiCheckIfTopView(&g_homeView) && g_manageCont == NULL; -} - -void ReturnManageWalletHandler(lv_event_t *e) -{ - UpdateManageWalletState(false); - GUI_DEL_OBJ(g_lastCosmosLine) - GUI_DEL_OBJ(g_manageCont); - GuiEmitSignal(GUI_EVENT_REFRESH, NULL, 0); -} - -static bool UpdateStartIndex(int8_t gesture, uint8_t totalCount) -{ - int8_t newPage = g_currentPage + gesture; - - if (newPage < 0 || newPage * CARDS_PER_PAGE >= totalCount) { - return false; - } - - g_currentPage = newPage; - return true; -} - -static void UpdateHomeConnectWalletCard(HomeGesture_t gesture) -{ - lv_obj_t *walletCardCont = g_homeWalletCardCont; - if (lv_obj_get_child_cnt(walletCardCont) > 0) { - lv_obj_clean(walletCardCont); - } - uint8_t currentCoinAmount = 0; - uint8_t totalCoinAmount = 0xFF; - totalCoinAmount = GetSelectedWalletCount(); - UpdateStartIndex(gesture, totalCoinAmount); - - for (int i = 0, j = 0; i < HOME_WALLET_CARD_BUTT; i++) { - if (g_walletState[i].index == HOME_WALLET_CARD_COSMOS || - (g_walletState[i].index == HOME_WALLET_CARD_ARWEAVE && GetIsTempAccount()) || - g_walletState[i].state == false || - g_walletState[i].enable == false) { - j++; - continue; - } - - if ((i - j) < g_currentPage * 6) { - continue; - } - - lv_obj_t *coinLabel = GuiCreateTextLabel(walletCardCont, g_coinCardArray[i].coin); - lv_obj_t *chainLabel = GuiCreateNoticeLabel(walletCardCont, g_coinCardArray[i].chain); - lv_obj_t *icon = GuiCreateImg(walletCardCont, g_coinCardArray[i].icon); - GuiButton_t table[3] = { - {.obj = icon, .align = LV_ALIGN_TOP_MID, .position = {0, 30},}, - {.obj = coinLabel, .align = LV_ALIGN_TOP_MID, .position = {0, 92},}, - {.obj = chainLabel, .align = LV_ALIGN_TOP_MID, .position = {0, 130},}, - }; - lv_obj_t *button = GuiCreateButton(walletCardCont, 208, 176, table, NUMBER_OF_ARRAYS(table), - NULL, (void *) & (g_coinCardArray[i].index)); - lv_obj_add_event_cb(button, HomeScrollHandler, LV_EVENT_ALL, (void *) & (g_coinCardArray[i].index)); - lv_obj_clear_flag(button, LV_OBJ_FLAG_GESTURE_BUBBLE); - lv_obj_align(button, LV_ALIGN_DEFAULT, 24 + ((i - j) % 2) * 224, - 144 - GUI_MAIN_AREA_OFFSET + (((i - j) % 6) / 2) * 192); - lv_obj_set_style_bg_color(button, WHITE_COLOR, LV_PART_MAIN); - lv_obj_set_style_bg_opa(button, LV_OPA_12, LV_PART_MAIN); - lv_obj_set_style_radius(button, 24, LV_PART_MAIN); - if (currentCoinAmount++ == 5) { - break; - } - } -} - -void GuiShowRsaSetupasswordHintbox(void) -{ - g_keyboardWidget = GuiCreateKeyboardWidget(g_pageWidget->contentZone); - SetKeyboardWidgetSelf(g_keyboardWidget, &g_keyboardWidget); - static uint16_t sig = SIG_SETUP_RSA_PRIVATE_KEY_WITH_PASSWORD; - SetKeyboardWidgetSig(g_keyboardWidget, &sig); -} - -static void GuiARAddressCheckConfirmHandler(lv_event_t *event) -{ - GUI_DEL_OBJ(g_noticeWindow); - GuiCreateAttentionHintbox(SIG_SETUP_RSA_PRIVATE_KEY_RECEIVE_CONFIRM); -} - -static void GuiOpenARAddressNoticeWindow() -{ - g_noticeWindow = GuiCreateGeneralHintBox(&imgWarn, _("ar_address_check"), _("ar_address_check_desc"), NULL, _("Not Now"), WHITE_COLOR_OPA20, _("Understand"), ORANGE_COLOR); - lv_obj_add_event_cb(lv_obj_get_child(g_noticeWindow, 0), CloseHintBoxHandler, LV_EVENT_CLICKED, &g_noticeWindow); - - lv_obj_t *btn = GuiGetHintBoxRightBtn(g_noticeWindow); - lv_obj_set_width(btn, 192); - lv_obj_set_style_text_font(lv_obj_get_child(btn, 0), &buttonFont, 0); - lv_obj_add_event_cb(btn, GuiARAddressCheckConfirmHandler, LV_EVENT_CLICKED, &g_noticeWindow); - - btn = GuiGetHintBoxLeftBtn(g_noticeWindow); - lv_obj_set_width(btn, 192); - lv_obj_set_style_text_font(lv_obj_get_child(btn, 0), &buttonFont, 0); - lv_obj_add_event_cb(btn, CloseHintBoxHandler, LV_EVENT_CLICKED, &g_noticeWindow); - - lv_obj_t *img = GuiCreateImg(g_noticeWindow, &imgClose); - lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE); - lv_obj_add_event_cb(img, CloseHintBoxHandler, LV_EVENT_CLICKED, &g_noticeWindow); - lv_obj_align_to(img, lv_obj_get_child(g_noticeWindow, 1), LV_ALIGN_TOP_RIGHT, -36, 36); -} - -__attribute__((weak)) void CoinOtherDealHandler(HOME_WALLET_CARD_ENUM coin) -{ - return NULL; -} - -static void CoinDealHandler(HOME_WALLET_CARD_ENUM coin) -{ - if (coin >= HOME_WALLET_CARD_BUTT) { - return; - } - switch (coin) { - case HOME_WALLET_CARD_BTC: - case HOME_WALLET_CARD_LTC: - case HOME_WALLET_CARD_DASH: - case HOME_WALLET_CARD_BCH: - GuiFrameOpenViewWithParam(&g_utxoReceiveView, &coin, sizeof(coin)); - break; - default: - CoinOtherDealHandler(coin); - break; - } - // case HOME_WALLET_CARD_ETH: - // case HOME_WALLET_CARD_SOL: - // case HOME_WALLET_CARD_HNT: - // GuiFrameOpenViewWithParam(&g_multiPathCoinReceiveView, &coin, sizeof(coin)); - // break; - // case HOME_WALLET_CARD_ADA: - // GuiFrameOpenViewWithParam(&g_multiAccountsReceiveView, &coin, sizeof(coin)); - // break; - // case HOME_WALLET_CARD_ARWEAVE: { - // bool shouldGenerateArweaveXPub = IsArweaveSetupComplete(); - // if (!shouldGenerateArweaveXPub) { - // GuiOpenARAddressNoticeWindow(); - // break; - // } - // GuiFrameOpenViewWithParam(&g_standardReceiveView, &coin, sizeof(coin)); - // break; - // } - // default: - // GuiFrameOpenViewWithParam(&g_standardReceiveView, &coin, sizeof(coin)); - // break; - // } -} - -void GuiRemoveKeyboardWidget(void) -{ - if (g_keyboardWidget != NULL) { - GuiDeleteKeyboardWidget(g_keyboardWidget); - } - GuiModelRsaGenerateKeyPair(); -} - -void RecalculateManageWalletState(void) -{ - WalletState_t walletState[HOME_WALLET_CARD_BUTT]; - memcpy(walletState, g_walletState, sizeof(g_walletState)); - AccountPublicHomeCoinGet(g_walletState, NUMBER_OF_ARRAYS(g_walletState)); - AccountPublicHomeCoinSet(walletState, NUMBER_OF_ARRAYS(walletState)); -} - -void GuiShowRsaInitializatioCompleteHintbox(void) -{ - GuiPendingHintBoxRemove(); - ClearSecretCache(); - GuiCreateInitializatioCompleteHintbox(); -} - -void GuiHomePasswordErrorCount(void *param) -{ - PasswordVerifyResult_t *passwordVerifyResult = (PasswordVerifyResult_t *)param; - GuiShowErrorNumber(g_keyboardWidget, passwordVerifyResult); -} - -static void UpdateCosmosEnable(bool en) -{ - void (*func)(lv_obj_t *, lv_obj_flag_t); - if (en) { - func = lv_obj_clear_flag; - lv_obj_add_flag(g_endCosmosLine, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_flag(g_lastCosmosLine, LV_OBJ_FLAG_HIDDEN); - } else { - func = lv_obj_add_flag; - lv_obj_clear_flag(g_endCosmosLine, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_flag(g_lastCosmosLine, LV_OBJ_FLAG_HIDDEN); - } - for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { - if (IsCosmosChain(g_coinCardArray[i].index)) { - func(g_walletButton[i], LV_OBJ_FLAG_HIDDEN); - } - } -} - -static void ManageCoinChainHandler(lv_event_t *e) -{ - bool state; - WalletState_t *wallet = lv_event_get_user_data(e); - if (wallet->index == HOME_WALLET_CARD_COSMOS) { - state = g_walletBakState[wallet->index].state; - if (state) { - lv_img_set_src(g_cosmosPulldownImg, &imgArrowRight); - } else { - lv_img_set_src(g_cosmosPulldownImg, &imgArrowDown); - } - UpdateCosmosEnable(!state); - g_walletBakState[wallet->index].state = !state; - } else { - lv_obj_t *parent = lv_obj_get_parent(lv_event_get_target(e)); - state = lv_obj_has_state(lv_obj_get_child(parent, lv_obj_get_child_cnt(parent) - 1), LV_STATE_CHECKED); - g_walletBakState[wallet->index].state = state; - UpdateManageWalletState(false); - } -} - -void ScanQrCodeHandler(lv_event_t *e) -{ - g_isManageClick = false; - if (g_countDownTimer != NULL) { - lv_timer_del(g_countDownTimer); - g_countDownTimer = NULL; - } - GuiFrameOpenView(lv_event_get_user_data(e)); -} - -void ConfirmManageAssetsHandler(lv_event_t *e) -{ - g_currentPage = 0; - UpdateManageWalletState(true); - UpdateHomeConnectWalletCard(GestureNone); - GUI_DEL_OBJ(g_lastCosmosLine) - GUI_DEL_OBJ(g_manageCont) - GuiHomeRefresh(); -} - -static void OpenMoreViewHandler(lv_event_t *e) -{ - GUI_DEL_OBJ(g_moreHintbox) - GuiFrameOpenView(lv_event_get_user_data(e)); -} - -static void OpenMoreSettingHandler(lv_event_t *e) -{ - MoreInfoTable_t moreInfoTable[] = { - {.name = _("home_more_connect_wallet"), .src = &imgConnect, .callBack = OpenMoreViewHandler, &g_connectWalletView}, - {.name = _("device_setting_mid_btn"), .src = &imgSettings, .callBack = OpenMoreViewHandler, &g_settingView}, - }; - g_moreHintbox = GuiCreateMoreInfoHintBox(NULL, NULL, moreInfoTable, NUMBER_OF_ARRAYS(moreInfoTable), true, &g_moreHintbox); -} - -static void OpenManageAssetsHandler(lv_event_t *e) -{ - if (g_isManageClick == false) { - return; - } - memcpy(&g_walletBakState, &g_walletState, sizeof(g_walletState)); - g_manageCont = GuiCreateContainer(lv_obj_get_width(lv_scr_act()), lv_obj_get_height(lv_scr_act()) - - GUI_MAIN_AREA_OFFSET); - lv_obj_add_flag(g_manageCont, LV_OBJ_FLAG_CLICKABLE); - lv_obj_align(g_manageCont, LV_ALIGN_DEFAULT, 0, GUI_MAIN_AREA_OFFSET); - lv_obj_t *checkBoxCont = GuiCreateContainerWithParent(g_manageCont, lv_obj_get_width(lv_scr_act()), 542); - lv_obj_set_align(checkBoxCont, LV_ALIGN_DEFAULT); - lv_obj_add_flag(checkBoxCont, LV_OBJ_FLAG_SCROLLABLE); - lv_obj_set_scrollbar_mode(checkBoxCont, LV_SCROLLBAR_MODE_OFF); - - int heightIndex = 0; - for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { - if (GetIsTempAccount() && g_walletState[i].index == HOME_WALLET_CARD_ARWEAVE) { - continue; - } - lv_obj_t *coinLabel = GuiCreateTextLabel(checkBoxCont, g_coinCardArray[i].coin); - lv_obj_t *chainLabel = GuiCreateNoticeLabel(checkBoxCont, g_coinCardArray[i].chain); - lv_obj_t *icon = GuiCreateImg(checkBoxCont, g_coinCardArray[i].icon); - lv_obj_t *checkbox = GuiCreateMultiCheckBox(checkBoxCont, _("")); - lv_obj_set_style_pad_top(checkbox, 32, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_size(checkbox, 446, 96); - g_walletState[i].checkBox = checkbox; - uint8_t tableLen = 4; - GuiButton_t table[4] = { - {.obj = icon, .align = LV_ALIGN_LEFT_MID, .position = {24, 0}}, - {.obj = coinLabel, .align = LV_ALIGN_DEFAULT, .position = {100, 13}}, - {.obj = chainLabel, .align = LV_ALIGN_DEFAULT, .position = {100, 53}}, - {.obj = checkbox, .align = LV_ALIGN_TOP_MID, .position = {-10, 0}}, - }; - if (IsCosmosChain(g_coinCardArray[i].index)) { - table[0].position.x += 12; - table[1].position.x += 12; - table[2].position.x += 12; - } - - if (g_walletState[i].index == HOME_WALLET_CARD_COSMOS) { - // lv_obj_del(table[2].obj); - lv_obj_t *line = GuiCreateDividerLine(checkBoxCont); - lv_obj_align(line, LV_ALIGN_DEFAULT, 0, 96 * heightIndex); - g_endCosmosLine = GuiCreateDividerLine(checkBoxCont); - lv_obj_align(g_endCosmosLine, LV_ALIGN_DEFAULT, 0, 96 * (heightIndex + 1)); - lv_obj_t *cosmosCoinImg = GuiCreateImg(checkBoxCont, &coinCosmosEco); - table[2].obj = cosmosCoinImg; - table[2].align = LV_ALIGN_DEFAULT; - table[2].position.x = 100; - table[2].position.y = 53; - - lv_obj_del(table[3].obj); - g_cosmosPulldownImg = GuiCreateImg(checkBoxCont, &imgArrowRight); - table[3].obj = g_cosmosPulldownImg; - table[3].align = LV_ALIGN_RIGHT_MID; - table[3].position.x = -12; - table[3].position.y = 0; - } - - lv_obj_t *button = GuiCreateButton(checkBoxCont, 456, 96, table, tableLen, - ManageCoinChainHandler, &g_walletState[i]); - g_walletButton[i] = button; - if (IsCosmosChain(g_coinCardArray[i].index)) { - lv_obj_add_flag(button, LV_OBJ_FLAG_HIDDEN); - g_lastCosmosLine = GuiCreateDividerLine(checkBoxCont); - lv_obj_add_flag(g_lastCosmosLine, LV_OBJ_FLAG_HIDDEN); - lv_obj_align(g_lastCosmosLine, LV_ALIGN_DEFAULT, 0, 96 * (heightIndex + 1)); - } - if (!g_walletState[i].enable) { - lv_obj_add_flag(button, LV_OBJ_FLAG_HIDDEN); - continue; - } - lv_obj_align(button, LV_ALIGN_TOP_MID, 0, 96 * heightIndex); - heightIndex++; - } - - if (GetMnemonicType() == MNEMONIC_TYPE_TON) { - lv_obj_t *label = GuiCreateIllustrateLabel(checkBoxCont, _("import_ton_mnemonic_desc")); - lv_obj_set_width(label, 416); - lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); - lv_obj_align(label, LV_ALIGN_TOP_LEFT, 32, 144); - } - - lv_obj_t *btn = GuiCreateBtn(g_manageCont, USR_SYMBOL_CHECK); - lv_obj_add_event_cb(btn, ConfirmManageAssetsHandler, LV_EVENT_CLICKED, NULL); - lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -36, -24); - - lv_obj_t *label = GuiCreateTextLabel(g_manageCont, ""); - lv_obj_align_to(label, btn, LV_ALIGN_OUT_LEFT_MID, -300, 0); - lv_label_set_recolor(label, true); - - g_manageWalletLabel = label; - - UpdateManageWalletState(false); - - SetMidBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_MID_LABEL, _("home_manage_assets")); - SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, ReturnManageWalletHandler, NULL); - // TODO: add search - // GuiNvsBarSetRightCb(NVS_BAR_SEARCH, NULL, NULL); - SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, NULL); -} - -void GuiHomeSetWalletDesc(WalletDesc_t *wallet) -{ - GuiNvsBarSetWalletName((const char *)wallet->name); - GuiSetEmojiIconIndex(wallet->iconIndex); - SetStatusBarEmojiIndex(wallet->iconIndex); - GuiNvsBarSetWalletIcon(GuiGetEmojiIconImg()); -} - -static void HomeScrollHandler(lv_event_t * e) -{ - static lv_point_t touchStart; - static lv_point_t touchEnd; - -#define SWIPE_THRESHOLD 50 - lv_event_code_t code = lv_event_get_code(e); - lv_obj_t * obj = lv_event_get_target(e); - - static bool isDragging = false; - - if (code == LV_EVENT_PRESSED) { - lv_indev_t * indev = lv_indev_get_act(); - lv_indev_get_point(indev, &touchStart); - isDragging = true; - } else if (code == LV_EVENT_PRESSING) { - if (isDragging) { - lv_indev_t * indev = lv_indev_get_act(); - lv_indev_get_point(indev, &touchEnd); - } - } else if (code == LV_EVENT_RELEASED) { - if (isDragging) { - lv_indev_t * indev = lv_indev_get_act(); - lv_indev_get_point(indev, &touchEnd); - int16_t diff_y = touchEnd.y - touchStart.y; - if (abs(diff_y) > SWIPE_THRESHOLD) { - if (diff_y < 0) { - UpdateHomeConnectWalletCard(GestureTop); - g_isScrolling = true; - } else { - UpdateHomeConnectWalletCard(GestureBottom); - g_isScrolling = true; - } - } else { - lv_obj_t *obj = lv_event_get_target(e); - if (obj != g_homeWalletCardCont) { - HOME_WALLET_CARD_ENUM coin; - coin = *(HOME_WALLET_CARD_ENUM *)lv_event_get_user_data(e); - CoinDealHandler(coin); - } - } - - lv_timer_t *timer = lv_timer_create(ResetScrollState, 200, NULL); - lv_timer_set_repeat_count(timer, 1); - isDragging = false; - } - } -} - -static void ResetScrollState(lv_timer_t * timer) -{ - g_isScrolling = false; - lv_timer_del(timer); -} - -void GuiHomeAreaInit(void) -{ - GuiInitWalletState(); - g_pageWidget = CreatePageWidget(); - g_homeViewCont = g_pageWidget->contentZone; - - lv_obj_t *walletCardCont = GuiCreateContainerWithParent(g_homeViewCont, lv_obj_get_width(lv_scr_act()), - lv_obj_get_height(lv_scr_act()) - GUI_MAIN_AREA_OFFSET); - lv_obj_add_event_cb(walletCardCont, HomeScrollHandler, LV_EVENT_ALL, NULL); - lv_obj_add_flag(walletCardCont, LV_EVENT_CLICKED); - lv_obj_set_align(walletCardCont, LV_ALIGN_DEFAULT); - lv_obj_clear_flag(walletCardCont, LV_OBJ_FLAG_GESTURE_BUBBLE); - lv_obj_set_scrollbar_mode(walletCardCont, LV_SCROLLBAR_MODE_OFF); - g_homeWalletCardCont = walletCardCont; - - lv_obj_t *img = GuiCreateImg(lv_scr_act(), &imgScan); - lv_obj_align(img, LV_ALIGN_BOTTOM_RIGHT, -32, -32); - lv_obj_add_event_cb(img, ScanQrCodeHandler, LV_EVENT_CLICKED, &g_scanView); - lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE); - g_scanImg = img; -} - -void GuiHomeDisActive(void) -{ - if (g_homeWalletCardCont != NULL) { - lv_obj_add_flag(g_homeWalletCardCont, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_flag(g_scanImg, LV_OBJ_FLAG_HIDDEN); - } -} - -static void AddFlagCountDownTimerHandler(lv_timer_t *timer) -{ - g_isManageClick = true; - lv_timer_del(timer); - g_countDownTimer = NULL; - UNUSED(g_countDownTimer); -} - -void ClearHomePageCurrentIndex(void) -{ - g_currentPage = 0; -} - -void GuiHomeRestart(void) -{ - g_currentPage = 0; - GUI_DEL_OBJ(g_manageCont) - GUI_DEL_OBJ(g_noticeWindow) - GuiHomeRefresh(); -} - -void GuiHomeRefresh(void) -{ - static bool isFirstBeta = true; -#ifdef RUST_MEMORY_DEBUG - PrintRustMemoryStatus(); -#endif - if (GetCurrentAccountIndex() > 2) { - return; - } - GuiInitWalletState(); - g_countDownTimer = lv_timer_create(AddFlagCountDownTimerHandler, 500, NULL); - GuiSetSetupPhase(SETUP_PAHSE_DONE); - if (g_manageCont != NULL) { - SetMidBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_MID_LABEL, _("home_manage_assets")); - SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, ReturnManageWalletHandler, NULL); - SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, NULL); - } else { - SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_MANAGE, OpenManageAssetsHandler, NULL); - SetNavBarMidBtn(g_pageWidget->navBarWidget, NVS_MID_BUTTON_BUTT, NULL, NULL); - SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_BAR_MORE_INFO, OpenMoreSettingHandler, NULL); - } - if (g_homeWalletCardCont != NULL) { - lv_obj_clear_flag(g_homeWalletCardCont, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_flag(g_scanImg, LV_OBJ_FLAG_HIDDEN); - } - GUI_DEL_OBJ(g_moreHintbox) - AccountPublicHomeCoinGet(g_walletState, NUMBER_OF_ARRAYS(g_walletState)); - UpdateHomeConnectWalletCard(GestureNone); - if (isFirstBeta && SOFTWARE_VERSION_BUILD % 2) { - CreateBetaNotice(); - isFirstBeta = false; - } - CloseArHintbox(); -} - -const ChainCoinCard_t *GetCoinCardByIndex(HOME_WALLET_CARD_ENUM index) -{ - for (int i = 0; i < HOME_WALLET_CARD_BUTT; i++) { - if (g_coinCardArray[i].index == index) { - return &g_coinCardArray[i]; - } - } - return NULL; -} - -void GuiHomeDeInit(void) -{ - if (g_pageWidget != NULL) { - DestroyPageWidget(g_pageWidget); - g_pageWidget = NULL; - } - GUI_DEL_OBJ(g_noticeWindow); -} diff --git a/src/ui/gui_widgets/multi/gui_home_widgets.h b/src/ui/gui_widgets/multi/gui_home_widgets.h index 4377824ba..43a224425 100644 --- a/src/ui/gui_widgets/multi/gui_home_widgets.h +++ b/src/ui/gui_widgets/multi/gui_home_widgets.h @@ -46,6 +46,7 @@ void GuiHomeDeInit(void); void GuiShowRsaSetupasswordHintbox(void); void GuiShowRsaInitializatioCompleteHintbox(void); void ClearHomePageCurrentIndex(void); +void ReturnManageWalletHandler(lv_event_t *e); #endif /* _GUI_HOME_WIDGETS_H */ diff --git a/src/ui/gui_widgets/multi/general/gui_key_derivation_request_widgets.c b/src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.c similarity index 98% rename from src/ui/gui_widgets/multi/general/gui_key_derivation_request_widgets.c rename to src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.c index cc3b20859..8b946549a 100644 --- a/src/ui/gui_widgets/multi/general/gui_key_derivation_request_widgets.c +++ b/src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.c @@ -1,4 +1,3 @@ -#include "gui_key_derivation_request_widgets.h" #include "gui.h" #include "gui_page.h" #include "librust_c.h" @@ -12,6 +11,10 @@ #include "secret_cache.h" #include "fingerprint_process.h" #include "version.h" +#include "gui_keyboard_hintbox.h" +#include "gui_lock_widgets.h" +#include "account_public_info.h" +#include "gui_key_derivation_request_widgets.h" typedef struct KeyDerivationWidget { uint8_t currentTile; @@ -37,8 +40,8 @@ typedef enum { typedef struct HardwareCallResult { bool isLegal; - char *title; - char *message; + const char *title; + const char *message; } HardwareCallResult_t; typedef enum HardwareCallV1AdaDerivationAlgo { @@ -66,7 +69,6 @@ static lv_obj_t *g_egCont = NULL; static lv_obj_t *g_egAddressIndex[2]; static lv_obj_t *g_egAddress[2]; static char g_derivationPathAddr[2][2][BUFFER_SIZE_128]; -static HardwareCallResult_t g_hardwareCallRes; static bool g_isUsb = false; static bool g_isUsbPassWordCheck = false; static bool g_hasAda = false; @@ -106,11 +108,13 @@ static void GuiConnectUsbCreateImg(lv_obj_t *parent); static void RejectButtonHandler(lv_event_t *e); static void ApproveButtonHandler(lv_event_t *e); static void GuiConnectUsbPasswordPass(void); -static AdaXPubType GetAccountType(void); -static void SaveHardwareCallVersion1AdaDerivationAlgo(lv_event_t *e); static KeyboardWidget_t *g_keyboardWidget = NULL; static void GuiShowKeyBoardDialog(lv_obj_t *parent); static HardwareCallResult_t CheckHardwareCallRequestIsLegal(void); +#ifdef GENERAL_VERSION +static void SaveHardwareCallVersion1AdaDerivationAlgo(lv_event_t *e); +static AdaXPubType GetAccountType(void); +#endif void GuiSetKeyDerivationRequestData(void *urResult, void *multiResult, bool is_multi) { @@ -130,6 +134,11 @@ void FreeKeyDerivationRequestMemory(void) } } +static char *GetChangeDerivationPathDesc(void) +{ + return GetDerivationPathDescs(ADA_DERIVATION_PATH_DESC)[GetCurrentSelectedIndex()]; +} + static void RecalcCurrentWalletIndex(char *origin) { if (strcmp("eternl", origin) == 0) { @@ -210,14 +219,18 @@ static void SelectDerivationHandler(lv_event_t *e) lv_obj_clear_state(g_derivationTypeCheck[!index], LV_STATE_CHECKED); SetCurrentSelectedIndex(index); ShowEgAddressCont(g_egCont); +#ifdef GENERAL_VERSION UpdateConfirmBtn(index != GetAccountType()); +#endif } static void OpenDerivationPath() { +#ifdef GENERAL_VERSION if (IsCardano()) { SetCurrentSelectedIndex(GetAccountType()); } +#endif lv_obj_t *bgCont = GuiCreateContainer(lv_obj_get_width(lv_scr_act()), lv_obj_get_height(lv_scr_act()) - @@ -261,9 +274,8 @@ static void OpenDerivationPath() .position = {-24, 0}, }, }; - lv_obj_t *button = - GuiCreateButton(cont, 408, 102, table, NUMBER_OF_ARRAYS(table), - SelectDerivationHandler, g_derivationTypeCheck[i]); + lv_obj_t *button = GuiCreateButton(cont, 408, 102, table, NUMBER_OF_ARRAYS(table), + SelectDerivationHandler, g_derivationTypeCheck[i]); lv_obj_align(button, LV_ALIGN_TOP_MID, 0, i * 102); if (i != 0) { static lv_point_t points[2] = {{0, 0}, {360, 0}}; @@ -292,11 +304,13 @@ static void OpenDerivationPath() lv_obj_set_style_bg_color(tmCont, BLACK_COLOR, LV_PART_MAIN); lv_obj_t *btn = GuiCreateBtn(tmCont, USR_SYMBOL_CHECK); lv_obj_align(btn, LV_ALIGN_RIGHT_MID, -36, 0); +#ifdef GENERAL_VERSION if (strcmp("1", g_callData->version) == 0) { lv_obj_add_event_cb(btn, SaveHardwareCallVersion1AdaDerivationAlgo, LV_EVENT_CLICKED, NULL); } else { - lv_obj_add_event_cb(btn, ConfirmDerivationHandler, LV_EVENT_CLICKED, NULL); } +#else +#endif g_derivationPathConfirmBtn = btn; UpdateConfirmBtn(false); @@ -564,6 +578,7 @@ static UREncodeResult *ModelGenerateSyncUR(void) } return generate_key_derivation_ur(mfp, 4, &keys, firmwareVersion); } +#ifdef GENERAL_VERSION ExtendedPublicKey xpubs[24]; for (size_t i = 0; i < g_callData->key_derivation->schemas->size; i++) { KeyDerivationSchema schema = g_callData->key_derivation->schemas->data[i]; @@ -580,41 +595,10 @@ static UREncodeResult *ModelGenerateSyncUR(void) printf("v0 path: %s, xpub: %s\n", keys.data[i].path, keys.data[i].xpub); } return generate_key_derivation_ur(mfp, 4, &keys, firmwareVersion); +#endif + return NULL; } -static uint8_t GetXPubIndexByPath(char *path) -{ - if (strcmp("1852'/1815'/0'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 0); - if (strcmp("1852'/1815'/1'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 1); - if (strcmp("1852'/1815'/2'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 2); - if (strcmp("1852'/1815'/3'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 3); - if (strcmp("1852'/1815'/4'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 4); - if (strcmp("1852'/1815'/5'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 5); - if (strcmp("1852'/1815'/6'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 6); - if (strcmp("1852'/1815'/7'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 7); - if (strcmp("1852'/1815'/8'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 8); - if (strcmp("1852'/1815'/9'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 9); - if (strcmp("1852'/1815'/10'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 10); - if (strcmp("1852'/1815'/11'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 11); - if (strcmp("1852'/1815'/12'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 12); - if (strcmp("1852'/1815'/13'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 13); - if (strcmp("1852'/1815'/14'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 14); - if (strcmp("1852'/1815'/15'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 15); - if (strcmp("1852'/1815'/16'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 16); - if (strcmp("1852'/1815'/17'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 17); - if (strcmp("1852'/1815'/18'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 18); - if (strcmp("1852'/1815'/19'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 19); - if (strcmp("1852'/1815'/20'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 20); - if (strcmp("1852'/1815'/21'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 21); - if (strcmp("1852'/1815'/22'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 22); - if (strcmp("1852'/1815'/23'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 23); - if (strcmp("M/44'/148'/0'", path) == 0) return XPUB_TYPE_STELLAR_0; - if (strcmp("M/44'/148'/1'", path) == 0) return XPUB_TYPE_STELLAR_1; - if (strcmp("M/44'/148'/2'", path) == 0) return XPUB_TYPE_STELLAR_2; - if (strcmp("M/44'/148'/3'", path) == 0) return XPUB_TYPE_STELLAR_3; - if (strcmp("M/44'/148'/4'", path) == 0) return XPUB_TYPE_STELLAR_4; - return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 0); -} static void GuiCreateHardwareCallApproveWidget(lv_obj_t *parent) { @@ -946,15 +930,6 @@ static uint32_t GetCurrentSelectedIndex() return g_currentSelectedPathIndex; } -static void SetAccountType(uint8_t index) -{ - SetConnectWalletPathIndex(g_response->data->origin, index); -} - -static AdaXPubType GetAccountType(void) -{ - return GetConnectWalletPathIndex(g_response->data->origin); -} static void UpdateConfirmBtn(bool update) { @@ -990,40 +965,11 @@ static bool IsCardano() } // hardware call version 1 need another CompareDerivationHandler -static void SaveHardwareCallVersion1AdaDerivationAlgo(lv_event_t *e) -{ - selected_ada_derivation_algo = GetCurrentSelectedIndex(); - // save the derivation path type to the json file that be saved in flash - SetConnectWalletPathIndex(g_response->data->origin, GetAccountType()); - SetAccountType(GetKeyDerivationAdaXPubType()); - CloseDerivationHandler(e); -} - -static void ConfirmDerivationHandler(lv_event_t *e) -{ - if (IsCardano()) { - SetConnectWalletPathIndex(g_response->data->origin, GetAccountType()); - SetAccountType(GetCurrentSelectedIndex()); - } - GuiAnimatingQRCodeDestroyTimer(); - GuiAnimatingQRCodeInit(g_keyDerivationTileView.qrCode, ModelGenerateSyncUR, true); - GuiKeyDerivationRequestNextTile(); - GUI_DEL_OBJ(g_derivationPathCont); - SetNavBarLeftBtn(g_keyDerivationTileView.pageWidget->navBarWidget, NVS_BAR_RETURN, CloseCurrentViewHandler, - NULL); - SetWallet(g_keyDerivationTileView.pageWidget->navBarWidget, g_walletIndex, - NULL); - SetNavBarRightBtn(g_keyDerivationTileView.pageWidget->navBarWidget, NVS_BAR_MORE_INFO, - OpenMoreHandler, &g_walletIndex); -} -static char *GetChangeDerivationPathDesc(void) -{ - return GetDerivationPathDescs(ADA_DERIVATION_PATH_DESC)[GetCurrentSelectedIndex()]; -} static void GetCardanoEgAddress(void) { +#ifdef GENERAL_VERSION char *xPub = NULL; xPub = GetCurrentAccountPublicKey(XPUB_TYPE_ADA_0); SimpleResponse_c_char *result = cardano_get_base_address(xPub, 0, 1); @@ -1048,6 +994,7 @@ static void GetCardanoEgAddress(void) CutAndFormatString(g_derivationPathAddr[LEDGER_ADA][1], BUFFER_SIZE_128, result->data, 24); free_simple_response_c_char(result); +#endif } static void UpdateCardanoEgAddress(uint8_t index) @@ -1244,3 +1191,76 @@ static void RejectButtonHandler(lv_event_t *e) HandleURResultViaUSBFunc(data, strlen(data), GetCurrentUSParsingRequestID(), PRS_PARSING_REJECTED); GuiCLoseCurrentWorkingView(); } + +#ifdef GENERAL_VERSION +static void SetAccountType(uint8_t index) +{ + SetConnectWalletPathIndex(g_response->data->origin, index); +} + +static AdaXPubType GetAccountType(void) +{ + return GetConnectWalletPathIndex(g_response->data->origin); +} + +static void SaveHardwareCallVersion1AdaDerivationAlgo(lv_event_t *e) +{ + selected_ada_derivation_algo = GetCurrentSelectedIndex(); + // save the derivation path type to the json file that be saved in flash + SetConnectWalletPathIndex(g_response->data->origin, GetAccountType()); + SetAccountType(GetKeyDerivationAdaXPubType()); + CloseDerivationHandler(e); +} + +static uint8_t GetXPubIndexByPath(char *path) +{ + if (strcmp("1852'/1815'/0'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 0); + if (strcmp("1852'/1815'/1'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 1); + if (strcmp("1852'/1815'/2'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 2); + if (strcmp("1852'/1815'/3'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 3); + if (strcmp("1852'/1815'/4'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 4); + if (strcmp("1852'/1815'/5'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 5); + if (strcmp("1852'/1815'/6'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 6); + if (strcmp("1852'/1815'/7'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 7); + if (strcmp("1852'/1815'/8'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 8); + if (strcmp("1852'/1815'/9'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 9); + if (strcmp("1852'/1815'/10'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 10); + if (strcmp("1852'/1815'/11'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 11); + if (strcmp("1852'/1815'/12'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 12); + if (strcmp("1852'/1815'/13'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 13); + if (strcmp("1852'/1815'/14'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 14); + if (strcmp("1852'/1815'/15'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 15); + if (strcmp("1852'/1815'/16'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 16); + if (strcmp("1852'/1815'/17'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 17); + if (strcmp("1852'/1815'/18'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 18); + if (strcmp("1852'/1815'/19'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 19); + if (strcmp("1852'/1815'/20'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 20); + if (strcmp("1852'/1815'/21'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 21); + if (strcmp("1852'/1815'/22'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 22); + if (strcmp("1852'/1815'/23'", path) == 0) return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 23); + if (strcmp("M/44'/148'/0'", path) == 0) return XPUB_TYPE_STELLAR_0; + if (strcmp("M/44'/148'/1'", path) == 0) return XPUB_TYPE_STELLAR_1; + if (strcmp("M/44'/148'/2'", path) == 0) return XPUB_TYPE_STELLAR_2; + if (strcmp("M/44'/148'/3'", path) == 0) return XPUB_TYPE_STELLAR_3; + if (strcmp("M/44'/148'/4'", path) == 0) return XPUB_TYPE_STELLAR_4; + return GetAdaXPubTypeByIndexAndDerivationType(GetConnectWalletPathIndex(g_response->data->origin), 0); +} + +static void ConfirmDerivationHandler(lv_event_t *e) +{ + if (IsCardano()) { + SetConnectWalletPathIndex(g_response->data->origin, GetAccountType()); + SetAccountType(GetCurrentSelectedIndex()); + } + GuiAnimatingQRCodeDestroyTimer(); + GuiAnimatingQRCodeInit(g_keyDerivationTileView.qrCode, ModelGenerateSyncUR, true); + GuiKeyDerivationRequestNextTile(); + GUI_DEL_OBJ(g_derivationPathCont); + SetNavBarLeftBtn(g_keyDerivationTileView.pageWidget->navBarWidget, NVS_BAR_RETURN, CloseCurrentViewHandler, + NULL); + SetWallet(g_keyDerivationTileView.pageWidget->navBarWidget, g_walletIndex, + NULL); + SetNavBarRightBtn(g_keyDerivationTileView.pageWidget->navBarWidget, NVS_BAR_MORE_INFO, + OpenMoreHandler, &g_walletIndex); +} +#endif diff --git a/src/ui/gui_widgets/multi/general/gui_key_derivation_request_widgets.h b/src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.h similarity index 100% rename from src/ui/gui_widgets/multi/general/gui_key_derivation_request_widgets.h rename to src/ui/gui_widgets/multi/gui_key_derivation_request_widgets.h diff --git a/src/ui/gui_widgets/multi/general/gui_standard_receive_widgets.c b/src/ui/gui_widgets/multi/gui_standard_receive_widgets.c similarity index 98% rename from src/ui/gui_widgets/multi/general/gui_standard_receive_widgets.c rename to src/ui/gui_widgets/multi/gui_standard_receive_widgets.c index 760284fed..bd2ee752a 100644 --- a/src/ui/gui_widgets/multi/general/gui_standard_receive_widgets.c +++ b/src/ui/gui_widgets/multi/gui_standard_receive_widgets.c @@ -171,6 +171,11 @@ static uint32_t g_thorChainSelectIndex[3] = {0}; static PageWidget_t *g_pageWidget; static bool g_inputAccountValid = true; +__attribute__((weak)) bool IsCosmosChain(uint8_t index) +{ + return false; +} + static void JumpToAccountHandler(lv_event_t *e) { GuiCreateGotoAddressWidgets(g_standardReceiveWidgets.tileSwitchAccount); @@ -514,9 +519,11 @@ lv_obj_t* CreateStandardReceiveQRCode(lv_obj_t* parent, uint16_t w, uint16_t h) static uint16_t GetAddrYExtend(void) { +#ifdef GENERAL_VERSION if (g_chainCard == HOME_WALLET_CARD_SUI || g_chainCard == HOME_WALLET_CARD_APT) { return 30; } +#endif return 0; } @@ -576,12 +583,14 @@ static void GuiCreateQrCodeWidget(lv_obj_t *parent) void GetAttentionText(char* text) { switch (g_chainCard) { +#ifdef GENERAL_VERSION case HOME_WALLET_CARD_TRX: strcpy_s(text, 1024, _("receive_trx_hint")); break; case HOME_WALLET_CARD_TON: strcpy_s(text, 1024, _("receive_ton_hint")); break; +#endif default: snprintf_s(text, 1024, _("receive_coin_hint_fmt"), GetCoinCardByIndex(g_chainCard)->coin); } @@ -700,6 +709,16 @@ static void RefreshQrCode(void) if (fullscreenQrcode) { lv_qrcode_update(fullscreenQrcode, addressDataItem.address, strnlen_s(addressDataItem.address, ADDRESS_MAX_LEN)); } + +#ifdef CYBERPUNK_VERSION + if (g_chainCard == HOME_WALLET_CARD_ZEC) { + char addressString[256]; + CutAndFormatString(addressString, sizeof(addressString), addressDataItem.address, 60); + lv_label_set_text(g_standardReceiveWidgets.addressLabel, addressString); + } +#endif + +#ifdef GENERAL_VERSION if (g_chainCard == HOME_WALLET_CARD_ARWEAVE) { SimpleResponse_c_char *fixedAddress = fix_arweave_address(addressDataItem.address); if (fixedAddress->error_code == 0) { @@ -714,13 +733,10 @@ static void RefreshQrCode(void) char address[128]; snprintf_s(address, 128, "%.22s\n%s", addressDataItem.address, &addressDataItem.address[22]); lv_label_set_text(g_standardReceiveWidgets.addressLabel, address); - } else if (g_chainCard == HOME_WALLET_CARD_ZEC) { - char addressString[256]; - CutAndFormatString(addressString, sizeof(addressString), addressDataItem.address, 60); - lv_label_set_text(g_standardReceiveWidgets.addressLabel, addressString); } else { lv_label_set_text(g_standardReceiveWidgets.addressLabel, addressDataItem.address); } +#endif lv_label_set_text_fmt(g_standardReceiveWidgets.addressCountLabel, "%s-%u", _("account_head"), addressDataItem.index); } @@ -766,6 +782,7 @@ static void RefreshSwitchAccount(void) static int GetMaxAddressIndex(void) { +#ifdef GENERAL_VERSION if (g_chainCard == HOME_WALLET_CARD_SUI || g_chainCard == HOME_WALLET_CARD_APT) { return 10; } @@ -775,6 +792,7 @@ static int GetMaxAddressIndex(void) if (g_chainCard == HOME_WALLET_CARD_XRP) { return 200; } +#endif return GENERAL_ADDRESS_INDEX_MAX; } @@ -836,6 +854,7 @@ static void ConfirmHandler(lv_event_t *e) static bool IsAccountSwitchable() { +#ifdef GENERAL_VERSION // all cosmos chain can switch account if (IsCosmosChain(g_chainCard)) { return true; @@ -851,6 +870,8 @@ static bool IsAccountSwitchable() default: return false; } +#endif + return false; } static bool HasMoreBtn() @@ -887,6 +908,16 @@ static void ModelGetAddress(uint32_t index, AddressDataItem_t *item) char *xPub, hdPath[BUFFER_SIZE_128]; SimpleResponse_c_char *result; +#ifdef CYBERPUNK_VERSION + if (g_chainCard == HOME_WALLET_CARD_ZEC) { + char ufvk[ZCASH_UFVK_MAX_LEN] = {'\0'}; + uint8_t sfp[32]; + GetZcashUFVK(GetCurrentAccountIndex(), ufvk, sfp); + result = generate_zcash_default_address(ufvk); + } +#endif + +#ifdef GENERAL_VERSION switch (g_chainCard) { case HOME_WALLET_CARD_TRX: xPub = GetCurrentAccountPublicKey(XPUB_TYPE_TRX); @@ -927,13 +958,6 @@ static void ModelGetAddress(uint32_t index, AddressDataItem_t *item) result = ton_get_address(xPub); break; } - case HOME_WALLET_CARD_ZEC: { - char ufvk[ZCASH_UFVK_MAX_LEN] = {'\0'}; - uint8_t sfp[32]; - GetZcashUFVK(GetCurrentAccountIndex(), ufvk, sfp); - result = generate_zcash_default_address(ufvk); - break; - } default: if (IsCosmosChain(g_chainCard)) { result = (SimpleResponse_c_char *) GetCosmosChainAddressByCoinTypeAndIndex(g_chainCard, index); @@ -942,6 +966,7 @@ static void ModelGetAddress(uint32_t index, AddressDataItem_t *item) return; } } +#endif if (result->error_code == 0) { item->index = index; strcpy_s(item->address, ADDRESS_MAX_LEN, result->data); @@ -1042,6 +1067,7 @@ void GuiResetAllStandardAddressIndex(void) static uint32_t* GetCosmosChainCurrentSelectIndex() { switch (g_chainCard) { +#ifdef GENERAL_VERSION case HOME_WALLET_CARD_TIA: return &g_tiaChainSelectIndex[GetCurrentAccountIndex()]; break; @@ -1144,7 +1170,7 @@ static uint32_t* GetCosmosChainCurrentSelectIndex() case HOME_WALLET_CARD_RUNE: return &g_thorChainSelectIndex[GetCurrentAccountIndex()]; break; - +#endif default: return NULL; } @@ -1152,6 +1178,7 @@ static uint32_t* GetCosmosChainCurrentSelectIndex() static void SetCurrentSelectIndex(uint32_t selectIndex) { +#ifdef GENERAL_VERSION switch (g_chainCard) { case HOME_WALLET_CARD_SUI: g_suiSelectIndex[GetCurrentAccountIndex()] = selectIndex; @@ -1175,6 +1202,7 @@ static void SetCurrentSelectIndex(uint32_t selectIndex) break; } } +#endif SetAccountReceiveIndex(GetCoinCardByIndex(g_chainCard)->coin, selectIndex); } @@ -1184,21 +1212,4 @@ static uint32_t GetCurrentSelectIndex() return 0; } return GetAccountReceiveIndex(GetCoinCardByIndex(g_chainCard)->coin); - switch (g_chainCard) { - case HOME_WALLET_CARD_SUI: - return g_suiSelectIndex[GetCurrentAccountIndex()]; - case HOME_WALLET_CARD_XLM: - return g_stellarSelectIndex[GetCurrentAccountIndex()]; - case HOME_WALLET_CARD_APT: - return g_aptosSelectIndex[GetCurrentAccountIndex()]; - case HOME_WALLET_CARD_XRP: - return g_xrpSelectIndex[GetCurrentAccountIndex()]; - default: - if (IsCosmosChain(g_chainCard)) { - uint32_t *ptr = GetCosmosChainCurrentSelectIndex(); - return *ptr; - } else { - return g_selectIndex[GetCurrentAccountIndex()]; - } - } } diff --git a/src/ui/gui_widgets/multi/general/gui_standard_receive_widgets.h b/src/ui/gui_widgets/multi/gui_standard_receive_widgets.h similarity index 100% rename from src/ui/gui_widgets/multi/general/gui_standard_receive_widgets.h rename to src/ui/gui_widgets/multi/gui_standard_receive_widgets.h diff --git a/src/webusb_protocol/general/eapdu_services/service_export_address.c b/src/webusb_protocol/general/eapdu_services/service_export_address.c index 74e4bfba7..0291ede2d 100644 --- a/src/webusb_protocol/general/eapdu_services/service_export_address.c +++ b/src/webusb_protocol/general/eapdu_services/service_export_address.c @@ -102,6 +102,7 @@ void ExportAddressReject() static void ExportEthAddress(uint16_t requestID, uint8_t n, ETHAccountType type) { #ifndef COMPILE_SIMULATOR +#ifdef GENERAL_VERSION UREncodeResult *urResult = GetUnlimitedMetamaskDataForAccountType(type); if (urResult->error_code != 0) { @@ -126,6 +127,7 @@ static void ExportEthAddress(uint16_t requestID, uint8_t n, ETHAccountType type) EXT_FREE(json_str); SRAM_FREE(result); #endif +#endif } static bool CheckExportAcceptable(EAPDURequestPayload_t *payload) From 878a1adec1136d42c4ef27d24c9eb78d2ce07a18 Mon Sep 17 00:00:00 2001 From: soralit Date: Thu, 26 Dec 2024 14:29:24 +0800 Subject: [PATCH 17/31] chore: add defines --- rust/rust_c/Cargo.toml | 22 +++++++++++----------- rust/rust_c/build.rs | 35 +++++++++++++++++++++++++++++++++++ rust/rust_c/cbindgen.toml | 6 +++++- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index 5a222bd2c..da3d035f8 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -81,23 +81,23 @@ test_cmd = [] debug-memory = ["multi-coins"] multi-coins = [ - "bitcoin", - "ethereum", - "solana", "aptos", - "near", - "cosmos", + "arweave", + "bch", + "bitcoin", "cardano", + "cosmos", + "dash", + "ethereum", + "ltc", + "near", + "solana", + "stellar", "sui", + "ton", "tron", "xrp", - "arweave", - "stellar", - "ton", "zcash", - "ltc", - "dash", - "bch", ] btc-only = ["bitcoin"] diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index ecf326adc..325d81c0c 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -17,6 +17,41 @@ fn main() { #[cfg(feature = "debug-btc-only")] "debug-btc-only", ]; + config.after_includes = config.after_includes.map(|mut v| { + #[cfg(feature = "aptos")] + v.push_str("#define FEATURE_APTOS\n"); + #[cfg(feature = "arweave")] + v.push_str("#define FEATURE_ARWEAVE\n"); + #[cfg(feature = "bch")] + v.push_str("#define FEATURE_BCH\n"); + #[cfg(feature = "bitcoin")] + v.push_str("#define FEATURE_BITCOIN\n"); + #[cfg(feature = "cardano")] + v.push_str("#define FEATURE_CARDANO\n"); + #[cfg(feature = "cosmos")] + v.push_str("#define FEATURE_COSMOS\n"); + #[cfg(feature = "dash")] + v.push_str("#define FEATURE_DASH\n"); + #[cfg(feature = "ethereum")] + v.push_str("#define FEATURE_ETHEREUM\n"); + #[cfg(feature = "ltc")] + v.push_str("#define FEATURE_LTC\n"); + #[cfg(feature = "near")] + v.push_str("#define FEATURE_NEAR\n"); + #[cfg(feature = "solana")] + v.push_str("#define FEATURE_SOLANA\n"); + #[cfg(feature = "stellar")] + v.push_str("#define FEATURE_STELLAR\n"); + #[cfg(feature = "ton")] + v.push_str("#define FEATURE_TON\n"); + #[cfg(feature = "tron")] + v.push_str("#define FEATURE_TRON\n"); + #[cfg(feature = "xrp")] + v.push_str("#define FEATURE_XRP\n"); + #[cfg(feature = "zcash")] + v.push_str("#define FEATURE_ZCASH\n"); + v + }); assert!(!features.is_empty(), "No build variant enabled"); assert!( features.len() == 1, diff --git a/rust/rust_c/cbindgen.toml b/rust/rust_c/cbindgen.toml index af0fe7866..ae2d7d1c0 100644 --- a/rust/rust_c/cbindgen.toml +++ b/rust/rust_c/cbindgen.toml @@ -1,17 +1,21 @@ include_guard = "_LIBRUST_C_H" -after_includes = "#define BUILD_MULTI_COINS\n#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" +after_includes = "#define BUILD_MULTI_COINS\n#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32\n" language = "C" [defines] "feature = multi-coins" = "BUILD_MULTI_COINS" + "feature = aptos" = "FEATURE_APTOS" "feature = arweave" = "FEATURE_ARWEAVE" +"feature = bch" = "FEATURE_BCH" "feature = bitcoin" = "FEATURE_BITCOIN" "feature = cardano" = "FEATURE_CARDANO" "feature = cosmos" = "FEATURE_COSMOS" +"feature = dash" = "FEATURE_DASH" "feature = ethereum" = "FEATURE_ETHEREUM" +"feature = ltc" = "FEATURE_LTC" "feature = near" = "FEATURE_NEAR" "feature = solana" = "FEATURE_SOLANA" "feature = stellar" = "FEATURE_STELLAR" From 0974721f74ee2208783a688254cb1dac1c96c58b Mon Sep 17 00:00:00 2001 From: soralit Date: Tue, 24 Dec 2024 16:22:38 +0800 Subject: [PATCH 18/31] chore: organize rust_c features --- rust/CMakeLists.txt | 101 ++++++++++-------- rust/rust_c.cmake | 38 ------- rust/rust_c/Cargo.toml | 76 ++++++++----- .../{release => firmware}/btc_only.toml | 0 .../{release => firmware}/multi_coin.toml | 0 rust/rust_c/src/lib.rs | 40 +++---- 6 files changed, 132 insertions(+), 123 deletions(-) delete mode 100644 rust/rust_c.cmake rename rust/rust_c/cbindgens/{release => firmware}/btc_only.toml (100%) rename rust/rust_c/cbindgens/{release => firmware}/multi_coin.toml (100%) diff --git a/rust/CMakeLists.txt b/rust/CMakeLists.txt index ccc78dbb2..c49171367 100644 --- a/rust/CMakeLists.txt +++ b/rust/CMakeLists.txt @@ -1,51 +1,68 @@ message(STATUS "compile rust") +set(LIB_NAME librust_c.a) -include(rust_c.cmake) +# set variables +find_program(RUST_CARGO_EXECUTABLE cargo) +find_program(BINDGEN_EXE bindgen) +find_program(CBINDGEN_EXE cbindgen) -if(NOT BUILD_TYPE STREQUAL "Simulator") - if(BTC_ONLY) - set(CARGO_FLAG --release --target ${CARGO_ARM_TARGET} -p rust_c --no-default-features --features firmware-btc-only) - else() - set(CARGO_FLAG --release --target ${CARGO_ARM_TARGET} -p rust_c --no-default-features --features firmware) - endif() +# BUILD_ENVIRONMENT: PRODUCTION, DEBUG, SIMULATOR +# BUILD_VARIANT: BTC_ONLY, MULTI_COINS +set(RUST_DIR ${CMAKE_SOURCE_DIR}/rust) +set(RUST_C_DIR ${RUST_DIR}/rust_c) - if(DEFINED DEBUG_MEMORY) - message(STATUS "build with DEBUG_MEMORY") - set(CARGO_FLAG ${CARGO_FLAG} --features debug-memory) - endif() +if(BUILD_ENVIRONMENT STREQUAL "SIMULATOR") + set(FEATURE_ENVIRONMENT "simulator") + set(CBIDGEN_FOLDER "simulator") + set(TARGET_PATH ${CMAKE_SOURCE_DIR}/ui_simulator/lib/rust-builds) +elseif(BUILD_ENVIRONMENT STREQUAL "PRODUCTION") + set(FEATURE_ENVIRONMENT "production") + set(CBIDGEN_FOLDER "firmware") + set(TARGET_PATH ${CMAKE_BINARY_DIR}/rust-builds) + set(CARGO_ARM_TARGET thumbv7em-none-eabihf) +else() + set(FEATURE_ENVIRONMENT "debug") + set(CBIDGEN_FOLDER "firmware") + set(TARGET_PATH ${CMAKE_BINARY_DIR}/rust-builds) + set(CARGO_ARM_TARGET thumbv7em-none-eabihf) +endif() - message(STATUS "cargo build command: " ${CARGO_FLAG}) - message(STATUS ${TARGET_PATH}) +message(STATUS "build target path: " ${TARGET_PATH}) +if(NOT EXISTS ${TARGET_PATH}) + file(MAKE_DIRECTORY ${TARGET_PATH}) +endif() - set(COPY_COMMAND cp ${RUST_DIR}/target/${CARGO_ARM_TARGET}/release/${LIB_NAME} ${TARGET_PATH}) +if(BUILD_VARIANT STREQUAL "BTC_ONLY") + set(FEATURE_VARIANT "btc-only") + set(CBIDGEN_CONFIG_FILE "btc_only.toml") +else() + set(FEATURE_VARIANT "multi-coins") + set(CBIDGEN_CONFIG_FILE "multi_coin.toml") +endif() + +set(FEATURE ${FEATURE_ENVIRONMENT}-${FEATURE_VARIANT}) - add_custom_target(rust_c ALL - COMMAND ${CBINDGEN_EXE} ${CBINDGEN_FLAG} - COMMAND rustup run nightly-2024-01-31 ${RUST_CARGO_EXECUTABLE} build ${CARGO_FLAG} - COMMAND ${COPY_COMMAND} - WORKING_DIRECTORY ${RUST_DIR} - ) +set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/${CBIDGEN_FOLDER}/${CBIDGEN_CONFIG_FILE}) +set(CBINDGEN_FLAG ${RUST_C_DIR} --config ${CBINDGEN_CONFIG_PATH} --output ${TARGET_PATH}/librust_c.h --lang c) + +# compile rust lib +set(CARGO_FLAG --release -p rust_c --no-default-features) +set(CARGO_FLAG ${CARGO_FLAG} --features ${FEATURE}) +if(CARGO_ARM_TARGET) + set(CARGO_FLAG ${CARGO_FLAG} --target ${CARGO_ARM_TARGET}) + set(COPY_COMMAND cp ${RUST_DIR}/target/${CARGO_ARM_TARGET}/release/${LIB_NAME} ${TARGET_PATH}) else() - if(BTC_ONLY) - set(CARGO_FLAG --release -p rust_c --no-default-features --features simulator_btc_only) - else() - set(CARGO_FLAG --release -p rust_c --no-default-features --features simulator) - endif() - - if(DEFINED DEBUG_MEMORY) - message(STATUS "build with DEBUG_MEMORY") - set(CARGO_FLAG ${CARGO_FLAG} --features debug-memory) - endif() - - message(STATUS "Cargo Flags: ${CARGO_FLAG}") - - set(COPY_COMMAND cp ${RUST_DIR}/target/release/${LIB_NAME} ${TARGET_PATH}) - - add_custom_target(rust_c ALL - COMMAND ${CBINDGEN_EXE} ${CBINDGEN_FLAG} - COMMAND rustup run nightly-2024-01-31 ${RUST_CARGO_EXECUTABLE} build ${CARGO_FLAG} - COMMAND ${COPY_COMMAND} - WORKING_DIRECTORY ${RUST_DIR} - ) -endif() \ No newline at end of file + set(COPY_COMMAND cp ${RUST_DIR}/target/release/${LIB_NAME} ${TARGET_PATH}) +endif() + +message(STATUS "cargo build command: " ${CARGO_FLAG}) +#TODO: add debug-momery if need + +#run build +add_custom_target(rust_c ALL + COMMAND ${CBINDGEN_EXE} ${CBINDGEN_FLAG} + COMMAND rustup run nightly-2024-01-31 ${RUST_CARGO_EXECUTABLE} build ${CARGO_FLAG} + COMMAND ${COPY_COMMAND} + WORKING_DIRECTORY ${RUST_DIR} +) diff --git a/rust/rust_c.cmake b/rust/rust_c.cmake deleted file mode 100644 index 0252dd4f5..000000000 --- a/rust/rust_c.cmake +++ /dev/null @@ -1,38 +0,0 @@ -set(LIB_NAME librust_c.a) - -find_program(RUST_CARGO_EXECUTABLE cargo) -find_program(BINDGEN_EXE bindgen) -find_program(CBINDGEN_EXE cbindgen) - -if(NOT BUILD_TYPE STREQUAL "Simulator") - set(TARGET_PATH ${CMAKE_BINARY_DIR}/rust-builds) -else() - set(TARGET_PATH ${CMAKE_SOURCE_DIR}/ui_simulator/lib/rust-builds) -endif() - -message(STATUS "build target path: " ${TARGET_PATH}) - -option(LIB_RUST_C "Set to switch to Compile the RUST_C library" OFF) - -if(NOT EXISTS ${TARGET_PATH}) - file(MAKE_DIRECTORY ${TARGET_PATH}) -endif() - -set(RUST_DIR ${CMAKE_SOURCE_DIR}/rust) -set(RUST_C_DIR ${RUST_DIR}/rust_c) -set(CARGO_ARM_TARGET thumbv7em-none-eabihf) - -if(COMPILE_SIMULATOR) - if(BTC_ONLY) - set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/simulator/btc_only.toml) - else() - set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/simulator/multi_coin.toml) - endif() -else() - if(BTC_ONLY) - set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/release/btc_only.toml) - else() - set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/release/multi_coin.toml) - endif() -endif() -set(CBINDGEN_FLAG ${RUST_C_DIR} --config ${CBINDGEN_CONFIG_PATH} --output ${TARGET_PATH}/librust_c.h --lang c) \ No newline at end of file diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index a33a310d8..9995cf9ca 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -34,16 +34,24 @@ getrandom = { workspace = true, features = ["custom"] } crate-type = ["staticlib"] [features] +# feature toggles use-allocator = [] -firmware = ["use-allocator", "multi-coins"] -firmware-btc-only = ["use-allocator", "btc-only"] -simulator = [ - "multi-coins", - "sui_rust_c/simulator", - "simulator_rust_c/multi-coins", -] -simulator_btc_only = ["btc-only", "simulator_rust_c/btc-only"] -default = ["simulator"] +simulator = [] +aptos = ["dep:aptos_rust_c"] +arweave = ["dep:arweave_rust_c"] +bitcoin = ["dep:bitcoin_rust_c"] +cardano = ["dep:cardano_rust_c"] +cosmos = ["dep:cosmos_rust_c"] +ethereum = ["dep:ethereum_rust_c"] +near = ["dep:near_rust_c"] +solana = ["dep:solana_rust_c"] +stellar = ["dep:stellar_rust_c"] +sui = ["dep:sui_rust_c"] +ton = ["dep:ton_rust_c"] +tron = ["dep:tron_rust_c"] +xrp = ["dep:xrp_rust_c"] +zcash = ["dep:zcash_rust_c"] +test_cmd = ["dep:test_cmd"] debug-memory = [ "multi-coins", @@ -66,29 +74,47 @@ debug-memory = [ multi-coins = [ "common_rust_c/multi-coins", + "bitcoin", "bitcoin_rust_c/multi-coins", "wallet_rust_c/multi-coins", - "test_cmd/multi-coins", - "ethereum_rust_c", - "solana_rust_c", - "aptos_rust_c", - "near_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "ton_rust_c", - "zcash_rust_c" + "ethereum", + "solana", + "aptos", + "near", + "cosmos", + "cardano", + "sui", + "tron", + "xrp", + "arweave", + "stellar", + "ton", + "zcash", ] + btc-only = [ "common_rust_c/btc-only", + "bitcoin", "bitcoin_rust_c/btc-only", "wallet_rust_c/btc-only", - "test_cmd/btc-only", ] -test_feature = [] + +# build variants +# production +production-multi-coins = ["use-allocator", "multi-coins"] +production-btc-only = ["use-allocator", "btc-only"] +# debug +debug-multi-coins = ["test_cmd", "test_cmd/multi-coins", "production-multi-coins"] +debug-btc-only = ["test_cmd", "test_cmd/btc-only", "production-btc-only"] +# simulator +simulator-multi-coins = [ + "simulator", + "multi-coins", + "sui_rust_c/simulator", + "simulator_rust_c/multi-coins", +] +simulator-btc-only = ["simulator", "btc-only", "simulator_rust_c/btc-only"] +default = ["debug-multi-coins"] + [dev-dependencies] keystore = { path = "../keystore" } diff --git a/rust/rust_c/cbindgens/release/btc_only.toml b/rust/rust_c/cbindgens/firmware/btc_only.toml similarity index 100% rename from rust/rust_c/cbindgens/release/btc_only.toml rename to rust/rust_c/cbindgens/firmware/btc_only.toml diff --git a/rust/rust_c/cbindgens/release/multi_coin.toml b/rust/rust_c/cbindgens/firmware/multi_coin.toml similarity index 100% rename from rust/rust_c/cbindgens/release/multi_coin.toml rename to rust/rust_c/cbindgens/firmware/multi_coin.toml diff --git a/rust/rust_c/src/lib.rs b/rust/rust_c/src/lib.rs index f0cd428df..21b9c1d5a 100644 --- a/rust/rust_c/src/lib.rs +++ b/rust/rust_c/src/lib.rs @@ -11,55 +11,59 @@ mod allocator; #[cfg(feature = "use-allocator")] mod my_alloc; -#[allow(unused)] -use bitcoin_rust_c; #[allow(unused)] use common_rust_c; #[allow(unused)] -use test_cmd; -#[allow(unused)] use wallet_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "test_cmd")] +#[allow(unused)] +use test_cmd; + +//chains +#[cfg(feature = "aptos")] #[allow(unused)] use aptos_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "arweave")] #[allow(unused)] use arweave_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "bitcoin")] +#[allow(unused)] +use bitcoin_rust_c; +#[cfg(feature = "cardano")] #[allow(unused)] use cardano_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] #[allow(unused)] use cosmos_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] #[allow(unused)] use ethereum_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "near")] #[allow(unused)] use near_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] #[allow(unused)] use solana_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] #[allow(unused)] use stellar_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] #[allow(unused)] use sui_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ton")] #[allow(unused)] use ton_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "tron")] #[allow(unused)] use tron_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "xrp")] #[allow(unused)] use xrp_rust_c; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "zcash")] #[allow(unused)] use zcash_rust_c; -#[cfg(any(feature = "simulator", feature = "simulator_btc_only"))] +#[cfg(feature = "simulator")] #[allow(unused)] use simulator_rust_c; From a838895b89adc4ba2875a1b0dcbb53f7a03189cb Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 14:06:52 +0800 Subject: [PATCH 19/31] chore: refactor cbindgen --- rust/rust_c/build.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 rust/rust_c/build.rs diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs new file mode 100644 index 000000000..a5ea27917 --- /dev/null +++ b/rust/rust_c/build.rs @@ -0,0 +1,72 @@ +fn main() { + let mut config = cbindgen::Config::default(); + config.language = cbindgen::Language::C; + let includes = vec![ + "common_rust_c", + "wallet_rust_c", + "btc_only_wallet_rust_c", + "multi_coins_wallet_rust_c", + #[cfg(feature = "aptos")] + "aptos_rust_c", + #[cfg(feature = "simulator")] + "simulator_rust_c", + #[cfg(feature = "arweave")] + "arweave_rust_c", + #[cfg(feature = "bitcoin")] + "bitcoin_rust_c", + #[cfg(feature = "cardano")] + "cardano_rust_c", + #[cfg(feature = "cosmos")] + "cosmos_rust_c", + #[cfg(feature = "ethereum")] + "ethereum_rust_c", + #[cfg(feature = "near")] + "near_rust_c", + #[cfg(feature = "solana")] + "solana_rust_c", + #[cfg(feature = "stellar")] + "stellar_rust_c", + #[cfg(feature = "sui")] + "sui_rust_c", + #[cfg(feature = "ton")] + "ton_rust_c", + #[cfg(feature = "tron")] + "tron_rust_c", + #[cfg(feature = "xrp")] + "xrp_rust_c", + #[cfg(feature = "zcash")] + "zcash_rust_c", + #[cfg(feature = "test_cmd")] + "test_cmd_rust_c", + #[cfg(feature = "test_cmd")] + "btc_test_cmd_rust_c", + #[cfg(feature = "test_cmd")] + "general_test_cmd_rust_c", + ]; + + let crates = includes + .into_iter() + .map(|s| s.to_string()) + .collect::>(); + + config.parse.include = Some(crates.clone()); + config.parse.parse_deps = true; + config.parse.expand.crates = crates; + let features = vec![ + #[cfg(feature = "btc-only")] + "btc_only", + #[cfg(feature = "multi-coins")] + "multi_coins", + ]; + + config.parse.expand.features = Some(features.into_iter().map(|s| s.to_string()).collect()); + + let builder = cbindgen::Builder::new(); + + builder + .with_crate(".") + .with_config(config) + .generate() + .expect("Failed to generate bindings") + .write_to_file("librust_c.h"); +} From 5f7ed316c93cc09c7d8cd05409833f2a44f81f63 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 16:29:29 +0800 Subject: [PATCH 20/31] chore: refactor chain interfaces --- rust/Cargo.lock | 507 ++++++------------ rust/Cargo.toml | 21 - rust/rust_c/Cargo.toml | 140 ++--- rust/rust_c/build.rs | 1 + rust/rust_c/src/aptos/Cargo.toml | 22 - rust/rust_c/src/aptos/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/aptos/{src => }/structs.rs | 0 rust/rust_c/src/arweave/Cargo.toml | 20 - .../rust_c/src/arweave/{src => }/data_item.rs | 2 +- .../rust_c/src/arweave/{src/lib.rs => mod.rs} | 9 +- rust/rust_c/src/arweave/{src => }/structs.rs | 1 - rust/rust_c/src/bitcoin/Cargo.toml | 27 - rust/rust_c/src/bitcoin/{src => }/address.rs | 0 rust/rust_c/src/bitcoin/{src => }/legacy.rs | 2 +- .../rust_c/src/bitcoin/{src/lib.rs => mod.rs} | 5 - rust/rust_c/src/bitcoin/{src => }/msg.rs | 3 +- .../src/bitcoin/{src => }/multi_sig/mod.rs | 2 +- .../bitcoin/{src => }/multi_sig/structs.rs | 0 rust/rust_c/src/bitcoin/{src => }/psbt.rs | 4 +- rust/rust_c/src/bitcoin/{src => }/structs.rs | 0 rust/rust_c/src/cardano/Cargo.toml | 24 - rust/rust_c/src/cardano/{src => }/address.rs | 0 .../rust_c/src/cardano/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/cardano/{src => }/structs.rs | 0 rust/rust_c/src/cosmos/Cargo.toml | 22 - rust/rust_c/src/cosmos/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/cosmos/{src => }/structs.rs | 0 rust/rust_c/src/ethereum/Cargo.toml | 25 - rust/rust_c/src/ethereum/{src => }/abi.rs | 2 +- rust/rust_c/src/ethereum/{src => }/address.rs | 0 .../src/ethereum/{src/lib.rs => mod.rs} | 7 +- rust/rust_c/src/ethereum/{src => }/structs.rs | 2 +- rust/rust_c/src/ethereum/{src => }/util.rs | 0 rust/rust_c/src/lib.rs | 37 +- rust/rust_c/src/near/Cargo.toml | 21 - rust/rust_c/src/near/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/near/{src => }/structs.rs | 0 rust/rust_c/src/simulator/Cargo.toml | 17 - .../src/simulator/{src/lib.rs => mod.rs} | 0 rust/rust_c/src/solana/Cargo.toml | 20 - rust/rust_c/src/solana/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/solana/{src => }/structs.rs | 0 rust/rust_c/src/stellar/Cargo.toml | 16 - .../rust_c/src/stellar/{src/lib.rs => mod.rs} | 5 +- rust/rust_c/src/stellar/{src => }/structs.rs | 0 rust/rust_c/src/sui/Cargo.toml | 21 - rust/rust_c/src/sui/{src/lib.rs => mod.rs} | 7 +- rust/rust_c/src/sui/{src => }/structs.rs | 0 rust/rust_c/src/test_cmd/Cargo.toml | 17 - .../src/lib.rs => btc_test_cmd.rs} | 3 - .../src/lib.rs => general_test_cmd.rs} | 0 rust/rust_c/src/test_cmd/mod.rs | 6 + .../src/test_cmd/src/btc_test_cmd/Cargo.toml | 24 - .../test_cmd/src/general_test_cmd/Cargo.toml | 28 - rust/rust_c/src/test_cmd/src/lib.rs | 12 - rust/rust_c/src/ton/Cargo.toml | 20 - rust/rust_c/src/ton/{src/lib.rs => mod.rs} | 3 - rust/rust_c/src/ton/{src => }/structs.rs | 0 rust/rust_c/src/tron/Cargo.toml | 19 - rust/rust_c/src/tron/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/tron/{src => }/structs.rs | 0 rust/rust_c/src/wallet/Cargo.toml | 16 - .../src/lib.rs => btc_only_wallet.rs} | 4 - rust/rust_c/src/wallet/mod.rs | 4 + .../src => multi_coins_wallet}/aptos.rs | 0 .../src => multi_coins_wallet}/arconnect.rs | 0 .../src => multi_coins_wallet}/backpack.rs | 0 .../src => multi_coins_wallet}/bitget.rs | 0 .../src => multi_coins_wallet}/imtoken.rs | 0 .../src => multi_coins_wallet}/keplr.rs | 2 +- .../src => multi_coins_wallet}/keystone.rs | 0 .../src/lib.rs => multi_coins_wallet/mod.rs} | 5 +- .../src => multi_coins_wallet}/okx.rs | 0 .../src => multi_coins_wallet}/solana.rs | 0 .../src => multi_coins_wallet}/structs.rs | 0 .../src => multi_coins_wallet}/sui.rs | 0 .../src => multi_coins_wallet}/thor_wallet.rs | 4 +- .../src => multi_coins_wallet}/tonkeeper.rs | 0 .../src => multi_coins_wallet}/utils.rs | 0 .../src => multi_coins_wallet}/xbull.rs | 0 .../src => multi_coins_wallet}/xrp_toolkit.rs | 0 .../src => multi_coins_wallet}/zcash.rs | 0 .../src/wallet/src/btc_only_wallet/Cargo.toml | 23 - rust/rust_c/src/wallet/src/lib.rs | 8 - .../wallet/src/multi_coins_wallet/Cargo.toml | 25 - rust/rust_c/src/xrp/Cargo.toml | 22 - rust/rust_c/src/xrp/{src/lib.rs => mod.rs} | 6 +- rust/rust_c/src/xrp/{src => }/structs.rs | 0 rust/rust_c/src/zcash/Cargo.toml | 20 - rust/rust_c/src/zcash/{src/lib.rs => mod.rs} | 9 +- rust/rust_c/src/zcash/{src => }/structs.rs | 0 91 files changed, 301 insertions(+), 1007 deletions(-) delete mode 100644 rust/rust_c/src/aptos/Cargo.toml rename rust/rust_c/src/aptos/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/aptos/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/arweave/Cargo.toml rename rust/rust_c/src/arweave/{src => }/data_item.rs (96%) rename rust/rust_c/src/arweave/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/arweave/{src => }/structs.rs (99%) delete mode 100644 rust/rust_c/src/bitcoin/Cargo.toml rename rust/rust_c/src/bitcoin/{src => }/address.rs (100%) rename rust/rust_c/src/bitcoin/{src => }/legacy.rs (98%) rename rust/rust_c/src/bitcoin/{src/lib.rs => mod.rs} (59%) rename rust/rust_c/src/bitcoin/{src => }/msg.rs (99%) rename rust/rust_c/src/bitcoin/{src => }/multi_sig/mod.rs (99%) rename rust/rust_c/src/bitcoin/{src => }/multi_sig/structs.rs (100%) rename rust/rust_c/src/bitcoin/{src => }/psbt.rs (99%) rename rust/rust_c/src/bitcoin/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/cardano/Cargo.toml rename rust/rust_c/src/cardano/{src => }/address.rs (100%) rename rust/rust_c/src/cardano/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/cardano/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/cosmos/Cargo.toml rename rust/rust_c/src/cosmos/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/cosmos/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/ethereum/Cargo.toml rename rust/rust_c/src/ethereum/{src => }/abi.rs (97%) rename rust/rust_c/src/ethereum/{src => }/address.rs (100%) rename rust/rust_c/src/ethereum/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/ethereum/{src => }/structs.rs (99%) rename rust/rust_c/src/ethereum/{src => }/util.rs (100%) delete mode 100644 rust/rust_c/src/near/Cargo.toml rename rust/rust_c/src/near/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/near/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/simulator/Cargo.toml rename rust/rust_c/src/simulator/{src/lib.rs => mod.rs} (100%) delete mode 100644 rust/rust_c/src/solana/Cargo.toml rename rust/rust_c/src/solana/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/solana/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/stellar/Cargo.toml rename rust/rust_c/src/stellar/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/stellar/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/sui/Cargo.toml rename rust/rust_c/src/sui/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/sui/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/test_cmd/Cargo.toml rename rust/rust_c/src/test_cmd/{src/btc_test_cmd/src/lib.rs => btc_test_cmd.rs} (99%) rename rust/rust_c/src/test_cmd/{src/general_test_cmd/src/lib.rs => general_test_cmd.rs} (100%) create mode 100644 rust/rust_c/src/test_cmd/mod.rs delete mode 100644 rust/rust_c/src/test_cmd/src/btc_test_cmd/Cargo.toml delete mode 100644 rust/rust_c/src/test_cmd/src/general_test_cmd/Cargo.toml delete mode 100644 rust/rust_c/src/test_cmd/src/lib.rs delete mode 100644 rust/rust_c/src/ton/Cargo.toml rename rust/rust_c/src/ton/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/ton/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/tron/Cargo.toml rename rust/rust_c/src/tron/{src/lib.rs => mod.rs} (97%) rename rust/rust_c/src/tron/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/wallet/Cargo.toml rename rust/rust_c/src/wallet/{src/btc_only_wallet/src/lib.rs => btc_only_wallet.rs} (99%) create mode 100644 rust/rust_c/src/wallet/mod.rs rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/aptos.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/arconnect.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/backpack.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/bitget.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/imtoken.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/keplr.rs (98%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/keystone.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src/lib.rs => multi_coins_wallet/mod.rs} (99%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/okx.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/solana.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/structs.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/sui.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/thor_wallet.rs (97%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/tonkeeper.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/utils.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/xbull.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/xrp_toolkit.rs (100%) rename rust/rust_c/src/wallet/{src/multi_coins_wallet/src => multi_coins_wallet}/zcash.rs (100%) delete mode 100644 rust/rust_c/src/wallet/src/btc_only_wallet/Cargo.toml delete mode 100644 rust/rust_c/src/wallet/src/lib.rs delete mode 100644 rust/rust_c/src/wallet/src/multi_coins_wallet/Cargo.toml delete mode 100644 rust/rust_c/src/xrp/Cargo.toml rename rust/rust_c/src/xrp/{src/lib.rs => mod.rs} (99%) rename rust/rust_c/src/xrp/{src => }/structs.rs (100%) delete mode 100644 rust/rust_c/src/zcash/Cargo.toml rename rust/rust_c/src/zcash/{src/lib.rs => mod.rs} (96%) rename rust/rust_c/src/zcash/{src => }/structs.rs (100%) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 02e8d7a4c..d112b6a8f 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -79,6 +79,55 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +dependencies = [ + "anstyle", + "windows-sys 0.59.0", +] + [[package]] name = "anyhow" version = "1.0.91" @@ -378,23 +427,6 @@ dependencies = [ "zcash_vendor", ] -[[package]] -name = "aptos_rust_c" -version = "0.1.0" -dependencies = [ - "app_aptos", - "app_utils", - "bitcoin", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "arrayref" version = "0.3.9" @@ -407,24 +439,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" -[[package]] -name = "arweave_rust_c" -version = "0.1.0" -dependencies = [ - "app_arweave", - "app_utils", - "bitcoin", - "common_rust_c", - "cryptoxide", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "ascii" version = "1.1.0" @@ -601,24 +615,6 @@ dependencies = [ "hex-conservative", ] -[[package]] -name = "bitcoin_rust_c" -version = "0.1.0" -dependencies = [ - "app_bitcoin", - "app_utils", - "base64 0.11.0", - "bitcoin", - "common_rust_c", - "cryptoxide", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -809,38 +805,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "btc_only_wallet_rust_c" -version = "0.1.0" -dependencies = [ - "app_utils", - "app_wallets", - "bitcoin", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "ur-registry", -] - -[[package]] -name = "btc_test_cmd" -version = "0.1.0" -dependencies = [ - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "ur-parse-lib", - "ur-registry", - "wallet_rust_c", -] - [[package]] name = "bumpalo" version = "3.16.0" @@ -906,24 +870,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "cardano_rust_c" -version = "0.1.0" -dependencies = [ - "app_cardano", - "app_utils", - "bitcoin", - "common_rust_c", - "cstr_core", - "cty", - "ed25519-bip32-core", - "hex", - "itertools 0.13.0", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "cbc" version = "0.1.2" @@ -933,6 +879,25 @@ dependencies = [ "cipher", ] +[[package]] +name = "cbindgen" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fce8dd7fcfcbf3a0a87d8f515194b49d6135acab73e18bd380d1d93bb1a15eb" +dependencies = [ + "clap", + "heck", + "indexmap 2.6.0", + "log", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.85", + "tempfile", + "toml 0.8.19", +] + [[package]] name = "cbor_event" version = "2.4.0" @@ -1007,6 +972,33 @@ dependencies = [ "zeroize", ] +[[package]] +name = "clap" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim 0.11.1", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + [[package]] name = "clear_on_drop" version = "0.2.5" @@ -1067,6 +1059,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "common_rust_c" version = "0.1.0" @@ -1180,22 +1178,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "cosmos_rust_c" -version = "0.1.0" -dependencies = [ - "app_cosmos", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "either", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "cpufeatures" version = "0.2.14" @@ -1596,26 +1578,6 @@ dependencies = [ "uint", ] -[[package]] -name = "ethereum_rust_c" -version = "0.1.0" -dependencies = [ - "app_ethereum", - "app_utils", - "bitcoin", - "common_rust_c", - "core2", - "cryptoxide", - "cstr_core", - "cty", - "hex", - "itertools 0.13.0", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "ethnum" version = "1.5.0" @@ -1872,21 +1834,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "general_test_cmd" -version = "0.1.0" -dependencies = [ - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "ur-registry", - "wallet_rust_c", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -2201,6 +2148,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.10.5" @@ -2501,45 +2454,12 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "multi_coins_wallet_rust_c" -version = "0.1.0" -dependencies = [ - "app_arweave", - "app_utils", - "app_wallets", - "bitcoin", - "common_rust_c", - "cstr_core", - "cty", - "ed25519-bip32-core", - "hex", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "multimap" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "near_rust_c" -version = "0.1.0" -dependencies = [ - "app_near", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "itertools 0.13.0", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "nix" version = "0.26.4" @@ -3017,7 +2937,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ - "toml", + "toml 0.5.11", ] [[package]] @@ -3450,28 +3370,42 @@ dependencies = [ name = "rust_c" version = "0.1.0" dependencies = [ - "aptos_rust_c", - "arweave_rust_c", - "bitcoin_rust_c", - "cardano_rust_c", + "app_aptos", + "app_arweave", + "app_bitcoin", + "app_cardano", + "app_cosmos", + "app_ethereum", + "app_near", + "app_solana", + "app_stellar", + "app_sui", + "app_ton", + "app_tron", + "app_utils", + "app_wallets", + "app_xrp", + "app_zcash", + "base64 0.11.0", + "bitcoin", + "cbindgen", "common_rust_c", - "cosmos_rust_c", + "core2", + "cryptoxide", "cstr_core", "cty", - "ethereum_rust_c", + "ed25519-bip32-core", + "either", "getrandom", + "hex", + "itertools 0.13.0", "keystore", - "near_rust_c", - "simulator_rust_c", - "solana_rust_c", - "stellar_rust_c", - "sui_rust_c", - "test_cmd", - "ton_rust_c", - "tron_rust_c", - "wallet_rust_c", - "xrp_rust_c", - "zcash_rust_c", + "rust_tools", + "serde_json", + "sim_qr_reader", + "ur-parse-lib", + "ur-registry", + "zcash_vendor", ] [[package]] @@ -3727,6 +3661,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + [[package]] name = "serde_with" version = "2.3.3" @@ -3873,16 +3816,6 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" -[[package]] -name = "simulator_rust_c" -version = "0.1.0" -dependencies = [ - "common_rust_c", - "cstr_core", - "cty", - "sim_qr_reader", -] - [[package]] name = "sinsemilla" version = "0.1.0" @@ -3906,21 +3839,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "solana_rust_c" -version = "0.1.0" -dependencies = [ - "app_solana", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "itertools 0.13.0", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "spin" version = "0.9.8" @@ -3952,20 +3870,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stellar_rust_c" -version = "0.1.0" -dependencies = [ - "app_stellar", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "ur-registry", -] - [[package]] name = "strsim" version = "0.10.0" @@ -4057,22 +3961,6 @@ dependencies = [ "thiserror-core", ] -[[package]] -name = "sui_rust_c" -version = "0.1.0" -dependencies = [ - "app_sui", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "syn" version = "1.0.109" @@ -4144,14 +4032,6 @@ dependencies = [ "time", ] -[[package]] -name = "test_cmd" -version = "0.1.0" -dependencies = [ - "btc_test_cmd", - "general_test_cmd", -] - [[package]] name = "thiserror" version = "1.0.65" @@ -4266,11 +4146,26 @@ dependencies = [ "serde", ] +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -4279,25 +4174,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap 2.6.0", + "serde", + "serde_spanned", "toml_datetime", "winnow", ] -[[package]] -name = "ton_rust_c" -version = "0.1.0" -dependencies = [ - "app_ton", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "ur-registry", -] - [[package]] name = "tracing" version = "0.1.40" @@ -4314,19 +4196,6 @@ version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -[[package]] -name = "tron_rust_c" -version = "0.1.0" -dependencies = [ - "app_tron", - "app_utils", - "common_rust_c", - "cstr_core", - "cty", - "keystore", - "rust_tools", -] - [[package]] name = "typenum" version = "1.17.0" @@ -4420,6 +4289,12 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "version_check" version = "0.9.5" @@ -4437,14 +4312,6 @@ dependencies = [ "syn 2.0.85", ] -[[package]] -name = "wallet_rust_c" -version = "0.1.0" -dependencies = [ - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -4904,23 +4771,6 @@ dependencies = [ "quick-xml 0.30.0", ] -[[package]] -name = "xrp_rust_c" -version = "0.1.0" -dependencies = [ - "app_utils", - "app_xrp", - "bitcoin", - "common_rust_c", - "cstr_core", - "cty", - "hex", - "keystore", - "rust_tools", - "serde_json", - "ur-registry", -] - [[package]] name = "zcash_address" version = "0.6.2" @@ -4990,21 +4840,6 @@ dependencies = [ "hex", ] -[[package]] -name = "zcash_rust_c" -version = "0.1.0" -dependencies = [ - "app_utils", - "app_zcash", - "common_rust_c", - "cstr_core", - "cty", - "keystore", - "rust_tools", - "ur-registry", - "zcash_vendor", -] - [[package]] name = "zcash_spec" version = "0.1.2" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 2db60a2e5..a44dca30d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -22,28 +22,7 @@ members = [ # C interface entry "rust_c", # rust_c libs - "rust_c/src/aptos", - "rust_c/src/arweave", - "rust_c/src/bitcoin", - "rust_c/src/cardano", "rust_c/src/common", - "rust_c/src/cosmos", - "rust_c/src/ethereum", - # "rust_c/src/kt_allocator", - "rust_c/src/near", - "rust_c/src/simulator", - "rust_c/src/solana", - "rust_c/src/stellar", - "rust_c/src/sui", - "rust_c/src/ton", - "rust_c/src/tron", - "rust_c/src/wallet", - "rust_c/src/xrp", - "rust_c/src/zcash", - - "rust_c/src/test_cmd", - "rust_c/src/test_cmd/src/btc_test_cmd", - "rust_c/src/test_cmd/src/general_test_cmd", # other "keystore", diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index 9995cf9ca..9eb10c19f 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -7,28 +7,54 @@ edition = "2021" [dependencies] common_rust_c = { path = "./src/common", optional = true, default-features = false } -bitcoin_rust_c = { path = "./src/bitcoin", default-features = false, optional = true } -wallet_rust_c = { path = "./src/wallet", default-features = false, optional = true } -test_cmd = { path = "./src/test_cmd", default-features = false, optional = true } -simulator_rust_c = { path = "./src/simulator", optional = true, default-features = false } - -ethereum_rust_c = { path = "./src/ethereum", optional = true } -solana_rust_c = { path = "./src/solana", optional = true } -aptos_rust_c = { path = "./src/aptos", optional = true } -near_rust_c = { path = "./src/near", optional = true } -cosmos_rust_c = { path = "./src/cosmos", optional = true } -cardano_rust_c = { path = "./src/cardano", optional = true } -sui_rust_c = { path = "./src/sui", optional = true } -tron_rust_c = { path = "./src/tron", optional = true } -xrp_rust_c = { path = "./src/xrp", optional = true } -arweave_rust_c = { path = "./src/arweave", optional = true } -stellar_rust_c = { path = "./src/stellar", optional = true } -ton_rust_c = { path = "./src/ton", optional = true } -zcash_rust_c = { path = "./src/zcash", optional = true } + cty = { workspace = true } cstr_core = { workspace = true } getrandom = { workspace = true, features = ["custom"] } +keystore = { workspace = true } +app_aptos = { workspace = true } +app_utils = { workspace = true } +rust_tools = { workspace = true } +serde_json = { workspace = true } +hex = { workspace = true } +bitcoin = { workspace = true } +ur-registry = { workspace = true } +app_arweave = { workspace = true } +cryptoxide = { workspace = true } +app_bitcoin = { workspace = true } +base64 = { workspace = true } +app_cardano = { workspace = true } +itertools = { workspace = true } +ed25519-bip32-core = { workspace = true } + +app_cosmos = { workspace = true, default-features = false } +either = { workspace = true } + +app_ethereum = { workspace = true } +core2 = { workspace = true } + +app_solana = { workspace = true } + +app_near = { workspace = true } + +app_sui = { workspace = true } + +app_stellar = { workspace = true } + +app_ton = { workspace = true } + +app_tron = { workspace = true } + +app_wallets = { workspace = true } + +ur-parse-lib = { workspace = true } + +app_xrp = { workspace = true } + +app_zcash = { workspace = true } +zcash_vendor = { workspace = true } +sim_qr_reader = { workspace = true } [lib] crate-type = ["staticlib"] @@ -37,46 +63,27 @@ crate-type = ["staticlib"] # feature toggles use-allocator = [] simulator = [] -aptos = ["dep:aptos_rust_c"] -arweave = ["dep:arweave_rust_c"] -bitcoin = ["dep:bitcoin_rust_c"] -cardano = ["dep:cardano_rust_c"] -cosmos = ["dep:cosmos_rust_c"] -ethereum = ["dep:ethereum_rust_c"] -near = ["dep:near_rust_c"] -solana = ["dep:solana_rust_c"] -stellar = ["dep:stellar_rust_c"] -sui = ["dep:sui_rust_c"] -ton = ["dep:ton_rust_c"] -tron = ["dep:tron_rust_c"] -xrp = ["dep:xrp_rust_c"] -zcash = ["dep:zcash_rust_c"] -test_cmd = ["dep:test_cmd"] - -debug-memory = [ - "multi-coins", - "common_rust_c/debug-memory", - "ethereum_rust_c/debug-memory", - "bitcoin_rust_c/debug-memory", - "wallet_rust_c/debug-memory", - "test_cmd/debug-memory", - "solana_rust_c/debug-memory", - "aptos_rust_c/debug-memory", - "near_rust_c/debug-memory", - "cosmos_rust_c/debug-memory", - "cardano_rust_c/debug-memory", - "sui_rust_c/debug-memory", - "tron_rust_c/debug-memory", - "xrp_rust_c/debug-memory", - "ton_rust_c/debug-memory", - "zcash_rust_c/debug-memory", -] +aptos = [] +arweave = [] +bitcoin = [] +cardano = [] +cosmos = [] +ethereum = [] +near = [] +solana = [] +stellar = [] +sui = [] +ton = [] +tron = [] +xrp = [] +zcash = [] +test_cmd = [] + +debug-memory = ["multi-coins", "common_rust_c/debug-memory"] multi-coins = [ "common_rust_c/multi-coins", "bitcoin", - "bitcoin_rust_c/multi-coins", - "wallet_rust_c/multi-coins", "ethereum", "solana", "aptos", @@ -92,29 +99,22 @@ multi-coins = [ "zcash", ] -btc-only = [ - "common_rust_c/btc-only", - "bitcoin", - "bitcoin_rust_c/btc-only", - "wallet_rust_c/btc-only", -] +btc-only = ["common_rust_c/btc-only", "bitcoin"] # build variants # production production-multi-coins = ["use-allocator", "multi-coins"] production-btc-only = ["use-allocator", "btc-only"] # debug -debug-multi-coins = ["test_cmd", "test_cmd/multi-coins", "production-multi-coins"] -debug-btc-only = ["test_cmd", "test_cmd/btc-only", "production-btc-only"] +debug-multi-coins = ["test_cmd", "production-multi-coins"] +debug-btc-only = ["test_cmd", "production-btc-only"] # simulator -simulator-multi-coins = [ - "simulator", - "multi-coins", - "sui_rust_c/simulator", - "simulator_rust_c/multi-coins", -] -simulator-btc-only = ["simulator", "btc-only", "simulator_rust_c/btc-only"] -default = ["debug-multi-coins"] +simulator-multi-coins = ["simulator", "multi-coins"] +simulator-btc-only = ["simulator", "btc-only"] +default = ["simulator-multi-coins"] [dev-dependencies] keystore = { path = "../keystore" } + +[build-dependencies] +cbindgen = "0.27.0" diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index a5ea27917..3f3060fae 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -1,4 +1,5 @@ fn main() { + return; let mut config = cbindgen::Config::default(); config.language = cbindgen::Language::C; let includes = vec![ diff --git a/rust/rust_c/src/aptos/Cargo.toml b/rust/rust_c/src/aptos/Cargo.toml deleted file mode 100644 index f0322cc47..000000000 --- a/rust/rust_c/src/aptos/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "aptos_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_aptos = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -common_rust_c = { path = "../common" } -serde_json = { workspace = true } -hex = { workspace = true } -bitcoin = { workspace = true } -ur-registry = { workspace = true } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/aptos/src/lib.rs b/rust/rust_c/src/aptos/mod.rs similarity index 98% rename from rust/rust_c/src/aptos/src/lib.rs rename to rust/rust_c/src/aptos/mod.rs index 217b74570..2f53993a4 100644 --- a/rust/rust_c/src/aptos/src/lib.rs +++ b/rust/rust_c/src/aptos/mod.rs @@ -1,8 +1,4 @@ -#![no_std] - -extern crate alloc; - -use crate::structs::DisplayAptosTx; +use structs::DisplayAptosTx; use alloc::format; use alloc::slice; use alloc::string::ToString; diff --git a/rust/rust_c/src/aptos/src/structs.rs b/rust/rust_c/src/aptos/structs.rs similarity index 100% rename from rust/rust_c/src/aptos/src/structs.rs rename to rust/rust_c/src/aptos/structs.rs diff --git a/rust/rust_c/src/arweave/Cargo.toml b/rust/rust_c/src/arweave/Cargo.toml deleted file mode 100644 index 8face4943..000000000 --- a/rust/rust_c/src/arweave/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "arweave_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_utils = { workspace = true } -app_arweave = { workspace = true } -rust_tools = { workspace = true } -common_rust_c = { path = "../common" } -cty = { workspace = true } -cstr_core = { workspace = true } -serde_json = { workspace = true } -hex = { workspace = true } -bitcoin = { workspace = true } -ur-registry = { workspace = true } -cryptoxide = { workspace = true } diff --git a/rust/rust_c/src/arweave/src/data_item.rs b/rust/rust_c/src/arweave/data_item.rs similarity index 96% rename from rust/rust_c/src/arweave/src/data_item.rs rename to rust/rust_c/src/arweave/data_item.rs index 25a3cc4d6..80ebe5a8b 100644 --- a/rust/rust_c/src/arweave/src/data_item.rs +++ b/rust/rust_c/src/arweave/data_item.rs @@ -6,7 +6,7 @@ use common_rust_c::{ }; use ur_registry::arweave::arweave_sign_request::ArweaveSignRequest; -use crate::structs::{DisplayArweaveAOTransfer, DisplayArweaveDataItem}; +use super::structs::{DisplayArweaveAOTransfer, DisplayArweaveDataItem}; #[no_mangle] pub extern "C" fn ar_is_ao_transfer(ptr: PtrUR) -> bool { diff --git a/rust/rust_c/src/arweave/src/lib.rs b/rust/rust_c/src/arweave/mod.rs similarity index 99% rename from rust/rust_c/src/arweave/src/lib.rs rename to rust/rust_c/src/arweave/mod.rs index b04a30c32..74903381f 100644 --- a/rust/rust_c/src/arweave/src/lib.rs +++ b/rust/rust_c/src/arweave/mod.rs @@ -1,8 +1,7 @@ -#![no_std] - -extern crate alloc; +pub mod structs; +pub mod data_item; -use crate::structs::{ArweaveRequestType, DisplayArweaveMessage, DisplayArweaveTx}; +use structs::{ArweaveRequestType, DisplayArweaveMessage, DisplayArweaveTx}; use alloc::boxed::Box; use alloc::slice; @@ -29,8 +28,6 @@ use ur_registry::arweave::arweave_sign_request::{ArweaveSignRequest, SaltLen, Si use ur_registry::arweave::arweave_signature::ArweaveSignature; use ur_registry::traits::RegistryItem; -pub mod data_item; -pub mod structs; fn generate_aes_key_iv(seed: &[u8]) -> ([u8; 32], [u8; 16]) { // The number 1557192335 is derived from the ASCII representation of "keystone" hashed with SHA-256, taking the first 32 bits with the highest bit set to 0. diff --git a/rust/rust_c/src/arweave/src/structs.rs b/rust/rust_c/src/arweave/structs.rs similarity index 99% rename from rust/rust_c/src/arweave/src/structs.rs rename to rust/rust_c/src/arweave/structs.rs index 963b515bd..1fc2be1d6 100644 --- a/rust/rust_c/src/arweave/src/structs.rs +++ b/rust/rust_c/src/arweave/structs.rs @@ -1,5 +1,4 @@ use core::ptr::null_mut; - use alloc::vec::Vec; use app_arweave::{ ao_transaction::AOTransferTransaction, diff --git a/rust/rust_c/src/bitcoin/Cargo.toml b/rust/rust_c/src/bitcoin/Cargo.toml deleted file mode 100644 index 902c85444..000000000 --- a/rust/rust_c/src/bitcoin/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "bitcoin_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_bitcoin = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -base64 = { workspace = true } -ur-registry = { workspace = true } -bitcoin = { workspace = true } -cryptoxide = { workspace = true } -hex = { workspace = true } - -common_rust_c = { path = "../common" } - -[features] -debug-memory = ["default"] -default = ["multi-coins"] -multi-coins = ["common_rust_c/multi-coins"] -btc-only = ["common_rust_c/btc-only"] diff --git a/rust/rust_c/src/bitcoin/src/address.rs b/rust/rust_c/src/bitcoin/address.rs similarity index 100% rename from rust/rust_c/src/bitcoin/src/address.rs rename to rust/rust_c/src/bitcoin/address.rs diff --git a/rust/rust_c/src/bitcoin/src/legacy.rs b/rust/rust_c/src/bitcoin/legacy.rs similarity index 98% rename from rust/rust_c/src/bitcoin/src/legacy.rs rename to rust/rust_c/src/bitcoin/legacy.rs index dcf0a0e6b..1979b16c7 100644 --- a/rust/rust_c/src/bitcoin/src/legacy.rs +++ b/rust/rust_c/src/bitcoin/legacy.rs @@ -1,4 +1,4 @@ -use crate::structs::DisplayTx; +use super::structs::DisplayTx; use alloc::boxed::Box; use alloc::slice; use common_rust_c::errors::RustCError; diff --git a/rust/rust_c/src/bitcoin/src/lib.rs b/rust/rust_c/src/bitcoin/mod.rs similarity index 59% rename from rust/rust_c/src/bitcoin/src/lib.rs rename to rust/rust_c/src/bitcoin/mod.rs index 102dfdb3b..1221afdff 100644 --- a/rust/rust_c/src/bitcoin/src/lib.rs +++ b/rust/rust_c/src/bitcoin/mod.rs @@ -1,8 +1,3 @@ -#![no_std] -#![feature(vec_into_raw_parts)] - -extern crate alloc; - pub mod address; pub mod legacy; pub mod msg; diff --git a/rust/rust_c/src/bitcoin/src/msg.rs b/rust/rust_c/src/bitcoin/msg.rs similarity index 99% rename from rust/rust_c/src/bitcoin/src/msg.rs rename to rust/rust_c/src/bitcoin/msg.rs index 53934386c..0a1e62fbf 100644 --- a/rust/rust_c/src/bitcoin/src/msg.rs +++ b/rust/rust_c/src/bitcoin/msg.rs @@ -1,6 +1,5 @@ use core::ptr::null_mut; - -use crate::structs::DisplayBtcMsg; +use super::structs::DisplayBtcMsg; use alloc::{ slice, string::{String, ToString}, diff --git a/rust/rust_c/src/bitcoin/src/multi_sig/mod.rs b/rust/rust_c/src/bitcoin/multi_sig/mod.rs similarity index 99% rename from rust/rust_c/src/bitcoin/src/multi_sig/mod.rs rename to rust/rust_c/src/bitcoin/multi_sig/mod.rs index 3f1d7aae7..e5ecf3be0 100644 --- a/rust/rust_c/src/bitcoin/src/multi_sig/mod.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/mod.rs @@ -29,7 +29,7 @@ use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; use common_rust_c::ur::{UREncodeResult, ViewType, FRAGMENT_MAX_LENGTH_DEFAULT}; use common_rust_c::utils::{convert_c_char, recover_c_array, recover_c_char}; -use crate::multi_sig::structs::{MultiSigWallet, NetworkType}; +use structs::{MultiSigWallet, NetworkType}; use common_rust_c::extract_ptr_with_type; use ur_registry::crypto_account::CryptoAccount; diff --git a/rust/rust_c/src/bitcoin/src/multi_sig/structs.rs b/rust/rust_c/src/bitcoin/multi_sig/structs.rs similarity index 100% rename from rust/rust_c/src/bitcoin/src/multi_sig/structs.rs rename to rust/rust_c/src/bitcoin/multi_sig/structs.rs diff --git a/rust/rust_c/src/bitcoin/src/psbt.rs b/rust/rust_c/src/bitcoin/psbt.rs similarity index 99% rename from rust/rust_c/src/bitcoin/src/psbt.rs rename to rust/rust_c/src/bitcoin/psbt.rs index 1e3f0faa6..1a8410495 100644 --- a/rust/rust_c/src/bitcoin/src/psbt.rs +++ b/rust/rust_c/src/bitcoin/psbt.rs @@ -23,8 +23,8 @@ use hex; use ur_registry::crypto_psbt::CryptoPSBT; use ur_registry::traits::RegistryItem; -use crate::multi_sig::structs::MultisigSignResult; -use crate::structs::DisplayTx; +use super::multi_sig::structs::MultisigSignResult; +use super::structs::DisplayTx; #[no_mangle] pub extern "C" fn btc_parse_psbt( diff --git a/rust/rust_c/src/bitcoin/src/structs.rs b/rust/rust_c/src/bitcoin/structs.rs similarity index 100% rename from rust/rust_c/src/bitcoin/src/structs.rs rename to rust/rust_c/src/bitcoin/structs.rs diff --git a/rust/rust_c/src/cardano/Cargo.toml b/rust/rust_c/src/cardano/Cargo.toml deleted file mode 100644 index 95fe47c17..000000000 --- a/rust/rust_c/src/cardano/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "cardano_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true} -app_cardano = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -itertools = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } -bitcoin = { workspace = true } -ed25519-bip32-core = { workspace = true } - -common_rust_c = { path = "../common" } - -[features] -debug-memory = [] \ No newline at end of file diff --git a/rust/rust_c/src/cardano/src/address.rs b/rust/rust_c/src/cardano/address.rs similarity index 100% rename from rust/rust_c/src/cardano/src/address.rs rename to rust/rust_c/src/cardano/address.rs diff --git a/rust/rust_c/src/cardano/src/lib.rs b/rust/rust_c/src/cardano/mod.rs similarity index 99% rename from rust/rust_c/src/cardano/src/lib.rs rename to rust/rust_c/src/cardano/mod.rs index 85f15025a..7e7a38f37 100644 --- a/rust/rust_c/src/cardano/src/lib.rs +++ b/rust/rust_c/src/cardano/mod.rs @@ -1,7 +1,3 @@ -#![no_std] - -extern crate alloc; - use alloc::{format, slice}; use alloc::{ string::{String, ToString}, @@ -30,7 +26,7 @@ use ur_registry::cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest use ur_registry::cardano::cardano_signature::CardanoSignature; use ur_registry::crypto_key_path::CryptoKeyPath; -use crate::structs::{DisplayCardanoCatalyst, DisplayCardanoSignData, DisplayCardanoTx}; +use structs::{DisplayCardanoCatalyst, DisplayCardanoSignData, DisplayCardanoTx}; use common_rust_c::errors::{RustCError, R}; use common_rust_c::extract_ptr_with_type; use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; diff --git a/rust/rust_c/src/cardano/src/structs.rs b/rust/rust_c/src/cardano/structs.rs similarity index 100% rename from rust/rust_c/src/cardano/src/structs.rs rename to rust/rust_c/src/cardano/structs.rs diff --git a/rust/rust_c/src/cosmos/Cargo.toml b/rust/rust_c/src/cosmos/Cargo.toml deleted file mode 100644 index b67ab6549..000000000 --- a/rust/rust_c/src/cosmos/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "cosmos_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_cosmos = { workspace = true, default-features = false } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -either = { workspace = true } -serde_json = { workspace = true } -ur-registry = { workspace = true } - -common_rust_c = { path = "../common" } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/cosmos/src/lib.rs b/rust/rust_c/src/cosmos/mod.rs similarity index 99% rename from rust/rust_c/src/cosmos/src/lib.rs rename to rust/rust_c/src/cosmos/mod.rs index 0686fc684..9306d783f 100644 --- a/rust/rust_c/src/cosmos/src/lib.rs +++ b/rust/rust_c/src/cosmos/mod.rs @@ -1,10 +1,6 @@ -#![no_std] - -extern crate alloc; - pub mod structs; -use crate::structs::DisplayCosmosTx; +use structs::DisplayCosmosTx; use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; diff --git a/rust/rust_c/src/cosmos/src/structs.rs b/rust/rust_c/src/cosmos/structs.rs similarity index 100% rename from rust/rust_c/src/cosmos/src/structs.rs rename to rust/rust_c/src/cosmos/structs.rs diff --git a/rust/rust_c/src/ethereum/Cargo.toml b/rust/rust_c/src/ethereum/Cargo.toml deleted file mode 100644 index e803d2db3..000000000 --- a/rust/rust_c/src/ethereum/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "ethereum_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true, default-features = false } -app_ethereum = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -itertools = { workspace = true } -hex = { workspace = true } -serde_json = { workspace = true } -ur-registry = { workspace = true } -core2 = { workspace = true } -cryptoxide = { workspace = true } -bitcoin = { workspace = true } -common_rust_c = { path = "../common" } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/ethereum/src/abi.rs b/rust/rust_c/src/ethereum/abi.rs similarity index 97% rename from rust/rust_c/src/ethereum/src/abi.rs rename to rust/rust_c/src/ethereum/abi.rs index 2311ad2d1..223ff412b 100644 --- a/rust/rust_c/src/ethereum/src/abi.rs +++ b/rust/rust_c/src/ethereum/abi.rs @@ -1,4 +1,4 @@ -use crate::structs::DisplayContractData; +use super::structs::DisplayContractData; use common_rust_c::errors::RustCError; use common_rust_c::structs::Response; use common_rust_c::types::{Ptr, PtrString}; diff --git a/rust/rust_c/src/ethereum/src/address.rs b/rust/rust_c/src/ethereum/address.rs similarity index 100% rename from rust/rust_c/src/ethereum/src/address.rs rename to rust/rust_c/src/ethereum/address.rs diff --git a/rust/rust_c/src/ethereum/src/lib.rs b/rust/rust_c/src/ethereum/mod.rs similarity index 99% rename from rust/rust_c/src/ethereum/src/lib.rs rename to rust/rust_c/src/ethereum/mod.rs index 66fa99f6f..99aa9d2f0 100644 --- a/rust/rust_c/src/ethereum/src/lib.rs +++ b/rust/rust_c/src/ethereum/mod.rs @@ -1,6 +1,3 @@ -#![no_std] -extern crate alloc; - use alloc::string::{String, ToString}; use alloc::vec::Vec; use alloc::{format, slice}; @@ -33,7 +30,7 @@ use common_rust_c::ur::{ use common_rust_c::utils::{convert_c_char, recover_c_char}; use common_rust_c::{extract_ptr_with_type, KEYSTONE}; -use crate::structs::{ +use structs::{ DisplayETH, DisplayETHPersonalMessage, DisplayETHTypedData, EthParsedErc20Transaction, TransactionType, }; @@ -41,7 +38,7 @@ use crate::structs::{ mod abi; pub mod address; pub mod structs; -mod util; +pub(crate) mod util; #[no_mangle] pub extern "C" fn eth_check_ur_bytes( diff --git a/rust/rust_c/src/ethereum/src/structs.rs b/rust/rust_c/src/ethereum/structs.rs similarity index 99% rename from rust/rust_c/src/ethereum/src/structs.rs rename to rust/rust_c/src/ethereum/structs.rs index 9cd768a30..c2d7f7667 100644 --- a/rust/rust_c/src/ethereum/src/structs.rs +++ b/rust/rust_c/src/ethereum/structs.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] use alloc::boxed::Box; -use crate::util::{calculate_max_txn_fee, convert_wei_to_eth}; +use super::util::{calculate_max_txn_fee, convert_wei_to_eth}; use alloc::string::{String, ToString}; use alloc::vec::Vec; use app_ethereum::abi::{ContractData, ContractMethodParam}; diff --git a/rust/rust_c/src/ethereum/src/util.rs b/rust/rust_c/src/ethereum/util.rs similarity index 100% rename from rust/rust_c/src/ethereum/src/util.rs rename to rust/rust_c/src/ethereum/util.rs diff --git a/rust/rust_c/src/lib.rs b/rust/rust_c/src/lib.rs index 21b9c1d5a..b066d5ecb 100644 --- a/rust/rust_c/src/lib.rs +++ b/rust/rust_c/src/lib.rs @@ -1,6 +1,7 @@ +#![feature(vec_into_raw_parts)] #![cfg_attr(feature = "use-allocator", no_std)] #![cfg_attr(feature = "use-allocator", feature(alloc_error_handler))] -#[cfg(feature = "use-allocator")] + extern crate alloc; mod bindings; @@ -14,56 +15,56 @@ mod my_alloc; #[allow(unused)] use common_rust_c; #[allow(unused)] -use wallet_rust_c; +mod wallet; #[cfg(feature = "test_cmd")] #[allow(unused)] -use test_cmd; +mod test_cmd; //chains #[cfg(feature = "aptos")] #[allow(unused)] -use aptos_rust_c; +mod aptos; #[cfg(feature = "arweave")] #[allow(unused)] -use arweave_rust_c; +mod arweave; #[cfg(feature = "bitcoin")] #[allow(unused)] -use bitcoin_rust_c; +mod bitcoin; #[cfg(feature = "cardano")] #[allow(unused)] -use cardano_rust_c; +mod cardano; #[cfg(feature = "cosmos")] #[allow(unused)] -use cosmos_rust_c; +mod cosmos; #[cfg(feature = "ethereum")] #[allow(unused)] -use ethereum_rust_c; +mod ethereum; #[cfg(feature = "near")] #[allow(unused)] -use near_rust_c; +mod near; #[cfg(feature = "solana")] #[allow(unused)] -use solana_rust_c; +mod solana; #[cfg(feature = "stellar")] #[allow(unused)] -use stellar_rust_c; +mod stellar; #[cfg(feature = "sui")] #[allow(unused)] -use sui_rust_c; +mod sui; #[cfg(feature = "ton")] #[allow(unused)] -use ton_rust_c; +mod ton; #[cfg(feature = "tron")] #[allow(unused)] -use tron_rust_c; +mod tron; #[cfg(feature = "xrp")] #[allow(unused)] -use xrp_rust_c; +mod xrp; #[cfg(feature = "zcash")] #[allow(unused)] -use zcash_rust_c; +mod zcash; #[cfg(feature = "simulator")] #[allow(unused)] -use simulator_rust_c; +mod simulator; diff --git a/rust/rust_c/src/near/Cargo.toml b/rust/rust_c/src/near/Cargo.toml deleted file mode 100644 index 116eef054..000000000 --- a/rust/rust_c/src/near/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "near_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true, default-features = false } -app_near = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -itertools = { workspace = true } -ur-registry = { workspace = true } - -common_rust_c = { path = "../common" } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/near/src/lib.rs b/rust/rust_c/src/near/mod.rs similarity index 98% rename from rust/rust_c/src/near/src/lib.rs rename to rust/rust_c/src/near/mod.rs index c1a63651f..6c63b7f65 100644 --- a/rust/rust_c/src/near/src/lib.rs +++ b/rust/rust_c/src/near/mod.rs @@ -1,8 +1,4 @@ -#![no_std] - -extern crate alloc; - -use crate::structs::DisplayNearTx; +use structs::DisplayNearTx; use alloc::string::ToString; use alloc::{format, vec}; use app_near::errors::NearError; diff --git a/rust/rust_c/src/near/src/structs.rs b/rust/rust_c/src/near/structs.rs similarity index 100% rename from rust/rust_c/src/near/src/structs.rs rename to rust/rust_c/src/near/structs.rs diff --git a/rust/rust_c/src/simulator/Cargo.toml b/rust/rust_c/src/simulator/Cargo.toml deleted file mode 100644 index 82d17e1ac..000000000 --- a/rust/rust_c/src/simulator/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "simulator_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -sim_qr_reader = { workspace = true } -cty = "0.2.2" -cstr_core = "0.2.6" -common_rust_c = { path = "../common", default-features = false } - -[features] -multi-coins = ["common_rust_c/multi-coins"] -btc-only = ["common_rust_c/btc-only"] -default = ["multi-coins"] \ No newline at end of file diff --git a/rust/rust_c/src/simulator/src/lib.rs b/rust/rust_c/src/simulator/mod.rs similarity index 100% rename from rust/rust_c/src/simulator/src/lib.rs rename to rust/rust_c/src/simulator/mod.rs diff --git a/rust/rust_c/src/solana/Cargo.toml b/rust/rust_c/src/solana/Cargo.toml deleted file mode 100644 index b32f5d2a7..000000000 --- a/rust/rust_c/src/solana/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "solana_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true, default-features = false } -app_solana = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -itertools = { workspace = true } -common_rust_c = { path = "../common" } -ur-registry = { workspace = true } -app_utils = { workspace = true } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/solana/src/lib.rs b/rust/rust_c/src/solana/mod.rs similarity index 98% rename from rust/rust_c/src/solana/src/lib.rs rename to rust/rust_c/src/solana/mod.rs index d18f61d15..7ea96109c 100644 --- a/rust/rust_c/src/solana/src/lib.rs +++ b/rust/rust_c/src/solana/mod.rs @@ -1,8 +1,4 @@ -#![no_std] - -extern crate alloc; - -use crate::structs::{DisplaySolanaMessage, DisplaySolanaTx}; +use structs::{DisplaySolanaMessage, DisplaySolanaTx}; use alloc::format; use alloc::string::ToString; use app_solana::errors::SolanaError; diff --git a/rust/rust_c/src/solana/src/structs.rs b/rust/rust_c/src/solana/structs.rs similarity index 100% rename from rust/rust_c/src/solana/src/structs.rs rename to rust/rust_c/src/solana/structs.rs diff --git a/rust/rust_c/src/stellar/Cargo.toml b/rust/rust_c/src/stellar/Cargo.toml deleted file mode 100644 index 40272beba..000000000 --- a/rust/rust_c/src/stellar/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "stellar_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_utils = { workspace = true } -app_stellar = { workspace = true } -common_rust_c = { path = "../common" } -cty = { workspace = true } -cstr_core = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } diff --git a/rust/rust_c/src/stellar/src/lib.rs b/rust/rust_c/src/stellar/mod.rs similarity index 98% rename from rust/rust_c/src/stellar/src/lib.rs rename to rust/rust_c/src/stellar/mod.rs index d2910a0f4..f8688edfd 100644 --- a/rust/rust_c/src/stellar/src/lib.rs +++ b/rust/rust_c/src/stellar/mod.rs @@ -1,13 +1,10 @@ -#![no_std] - -extern crate alloc; use alloc::borrow::ToOwned; use alloc::boxed::Box; use alloc::slice; use alloc::string::ToString; use cty::c_char; -use crate::structs::DisplayStellarTx; +use structs::DisplayStellarTx; use app_stellar::strkeys::{sign_hash, sign_signature_base}; use app_stellar::{address::get_address, base_to_xdr}; use common_rust_c::errors::RustCError; diff --git a/rust/rust_c/src/stellar/src/structs.rs b/rust/rust_c/src/stellar/structs.rs similarity index 100% rename from rust/rust_c/src/stellar/src/structs.rs rename to rust/rust_c/src/stellar/structs.rs diff --git a/rust/rust_c/src/sui/Cargo.toml b/rust/rust_c/src/sui/Cargo.toml deleted file mode 100644 index 3723fbc50..000000000 --- a/rust/rust_c/src/sui/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "sui_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_sui = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -serde_json = { workspace = true } -ur-registry = { workspace = true } -common_rust_c = { path = "../common" } -hex = { workspace = true } -[features] -debug-memory = [] -simulator = ["app_sui/simulator"] diff --git a/rust/rust_c/src/sui/src/lib.rs b/rust/rust_c/src/sui/mod.rs similarity index 98% rename from rust/rust_c/src/sui/src/lib.rs rename to rust/rust_c/src/sui/mod.rs index 5d33ce61c..cec7ad788 100644 --- a/rust/rust_c/src/sui/src/lib.rs +++ b/rust/rust_c/src/sui/mod.rs @@ -1,7 +1,3 @@ -#![no_std] - -extern crate alloc; - use alloc::string::{String, ToString}; use alloc::vec::Vec; use alloc::{format, vec}; @@ -22,8 +18,7 @@ use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use common_rust_c::utils::{convert_c_char, recover_c_char}; use structs::DisplaySuiSignMessageHash; - -use crate::structs::DisplaySuiIntentMessage; +use structs::DisplaySuiIntentMessage; pub mod structs; diff --git a/rust/rust_c/src/sui/src/structs.rs b/rust/rust_c/src/sui/structs.rs similarity index 100% rename from rust/rust_c/src/sui/src/structs.rs rename to rust/rust_c/src/sui/structs.rs diff --git a/rust/rust_c/src/test_cmd/Cargo.toml b/rust/rust_c/src/test_cmd/Cargo.toml deleted file mode 100644 index a42e0eaa9..000000000 --- a/rust/rust_c/src/test_cmd/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "test_cmd" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - - -[dependencies] -btc_test_cmd = {path = "./src/btc_test_cmd", default-features = false, optional = true} -general_test_cmd = {path = "./src/general_test_cmd", optional = true} - -[features] -debug-memory = ["default"] -default = ["multi-coins"] -multi-coins = ["btc_test_cmd/multi-coins","general_test_cmd/multi-coins"] -btc-only = ["btc_test_cmd/btc-only"] \ No newline at end of file diff --git a/rust/rust_c/src/test_cmd/src/btc_test_cmd/src/lib.rs b/rust/rust_c/src/test_cmd/btc_test_cmd.rs similarity index 99% rename from rust/rust_c/src/test_cmd/src/btc_test_cmd/src/lib.rs rename to rust/rust_c/src/test_cmd/btc_test_cmd.rs index 97091d21f..b0922b690 100644 --- a/rust/rust_c/src/test_cmd/src/btc_test_cmd/src/lib.rs +++ b/rust/rust_c/src/test_cmd/btc_test_cmd.rs @@ -1,6 +1,3 @@ -#![no_std] - -extern crate alloc; use alloc::boxed::Box; use alloc::string::{String, ToString}; diff --git a/rust/rust_c/src/test_cmd/src/general_test_cmd/src/lib.rs b/rust/rust_c/src/test_cmd/general_test_cmd.rs similarity index 100% rename from rust/rust_c/src/test_cmd/src/general_test_cmd/src/lib.rs rename to rust/rust_c/src/test_cmd/general_test_cmd.rs diff --git a/rust/rust_c/src/test_cmd/mod.rs b/rust/rust_c/src/test_cmd/mod.rs new file mode 100644 index 000000000..f428cdb9e --- /dev/null +++ b/rust/rust_c/src/test_cmd/mod.rs @@ -0,0 +1,6 @@ +#[allow(unused)] +pub mod btc_test_cmd; + +#[cfg(feature = "multi-coins")] +#[allow(unused)] +pub mod general_test_cmd; diff --git a/rust/rust_c/src/test_cmd/src/btc_test_cmd/Cargo.toml b/rust/rust_c/src/test_cmd/src/btc_test_cmd/Cargo.toml deleted file mode 100644 index 70f6da073..000000000 --- a/rust/rust_c/src/test_cmd/src/btc_test_cmd/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "btc_test_cmd" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } -ur-parse-lib = { workspace = true } - -common_rust_c = { path = "../../../common", default-features = false, optional = true } -wallet_rust_c = { path = "../../../wallet", default-features = false, optional = true } - -[features] -default = ["multi-coins"] -multi-coins = ["common_rust_c/multi-coins", "wallet_rust_c/multi-coins"] -btc-only = ["common_rust_c/btc-only", "wallet_rust_c/btc-only"] diff --git a/rust/rust_c/src/test_cmd/src/general_test_cmd/Cargo.toml b/rust/rust_c/src/test_cmd/src/general_test_cmd/Cargo.toml deleted file mode 100644 index 212872a13..000000000 --- a/rust/rust_c/src/test_cmd/src/general_test_cmd/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "general_test_cmd" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } -common_rust_c = { path = "../../../common" } -wallet_rust_c = { path = "../../../wallet" } - -[features] -default = ["multi-coins"] -multi-coins = [ - "common_rust_c/multi-coins", - "wallet_rust_c/multi-coins" -] -btc-only = [ - "common_rust_c/btc-only", - "wallet_rust_c/btc-only" -] \ No newline at end of file diff --git a/rust/rust_c/src/test_cmd/src/lib.rs b/rust/rust_c/src/test_cmd/src/lib.rs deleted file mode 100644 index 27eff21e0..000000000 --- a/rust/rust_c/src/test_cmd/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![no_std] -#![feature(vec_into_raw_parts)] -#![feature(error_in_core)] -#![allow(unused_unsafe)] -extern crate alloc; - -#[allow(unused)] -use btc_test_cmd; - -#[cfg(feature = "multi-coins")] -#[allow(unused)] -use general_test_cmd; diff --git a/rust/rust_c/src/ton/Cargo.toml b/rust/rust_c/src/ton/Cargo.toml deleted file mode 100644 index 0d475c163..000000000 --- a/rust/rust_c/src/ton/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "ton_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_ton = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -common_rust_c = { path = "../common" } -hex = { workspace = true } -ur-registry = { workspace = true } - -[features] -debug-memory = [] \ No newline at end of file diff --git a/rust/rust_c/src/ton/src/lib.rs b/rust/rust_c/src/ton/mod.rs similarity index 99% rename from rust/rust_c/src/ton/src/lib.rs rename to rust/rust_c/src/ton/mod.rs index bbc890145..6ad0a5ddf 100644 --- a/rust/rust_c/src/ton/src/lib.rs +++ b/rust/rust_c/src/ton/mod.rs @@ -1,6 +1,3 @@ -#![no_std] -extern crate alloc; - pub mod structs; use alloc::{ boxed::Box, diff --git a/rust/rust_c/src/ton/src/structs.rs b/rust/rust_c/src/ton/structs.rs similarity index 100% rename from rust/rust_c/src/ton/src/structs.rs rename to rust/rust_c/src/ton/structs.rs diff --git a/rust/rust_c/src/tron/Cargo.toml b/rust/rust_c/src/tron/Cargo.toml deleted file mode 100644 index a5d2b439b..000000000 --- a/rust/rust_c/src/tron/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "tron_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { path = "../../../keystore", default-features = false } -app_tron = { path = "../../../apps/tron" } -app_utils = { path = "../../../apps/utils" } -rust_tools = {path="../../../tools"} -cty = "0.2.2" -cstr_core = "0.2.6" - -common_rust_c = {path = "../common"} - -[features] -debug-memory = [] \ No newline at end of file diff --git a/rust/rust_c/src/tron/src/lib.rs b/rust/rust_c/src/tron/mod.rs similarity index 97% rename from rust/rust_c/src/tron/src/lib.rs rename to rust/rust_c/src/tron/mod.rs index 3029fac63..9882c819d 100644 --- a/rust/rust_c/src/tron/src/lib.rs +++ b/rust/rust_c/src/tron/mod.rs @@ -1,10 +1,6 @@ -#![no_std] - -extern crate alloc; - pub mod structs; -use crate::structs::DisplayTron; +use structs::DisplayTron; use alloc::boxed::Box; use alloc::slice; use common_rust_c::errors::RustCError; diff --git a/rust/rust_c/src/tron/src/structs.rs b/rust/rust_c/src/tron/structs.rs similarity index 100% rename from rust/rust_c/src/tron/src/structs.rs rename to rust/rust_c/src/tron/structs.rs diff --git a/rust/rust_c/src/wallet/Cargo.toml b/rust/rust_c/src/wallet/Cargo.toml deleted file mode 100644 index f9f54357b..000000000 --- a/rust/rust_c/src/wallet/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "wallet_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -btc_only_wallet_rust_c = {path = "src/btc_only_wallet", default-features = false, optional = true} -multi_coins_wallet_rust_c = {path = "./src/multi_coins_wallet", optional = true} - -[features] -debug-memory = ["default"] -default = ["multi-coins"] -multi-coins = ["btc_only_wallet_rust_c/multi-coins","multi_coins_wallet_rust_c"] -btc-only = ["btc_only_wallet_rust_c/btc-only"] \ No newline at end of file diff --git a/rust/rust_c/src/wallet/src/btc_only_wallet/src/lib.rs b/rust/rust_c/src/wallet/btc_only_wallet.rs similarity index 99% rename from rust/rust_c/src/wallet/src/btc_only_wallet/src/lib.rs rename to rust/rust_c/src/wallet/btc_only_wallet.rs index 4d80bf99e..f44fd9290 100644 --- a/rust/rust_c/src/wallet/src/btc_only_wallet/src/lib.rs +++ b/rust/rust_c/src/wallet/btc_only_wallet.rs @@ -1,7 +1,3 @@ -#![no_std] - -extern crate alloc; - use alloc::string::ToString; use alloc::vec::Vec; use alloc::{format, vec}; diff --git a/rust/rust_c/src/wallet/mod.rs b/rust/rust_c/src/wallet/mod.rs new file mode 100644 index 000000000..3d89d7745 --- /dev/null +++ b/rust/rust_c/src/wallet/mod.rs @@ -0,0 +1,4 @@ +pub mod btc_only_wallet; +pub use btc_only_wallet::*; +#[cfg(feature = "multi-coins")] +pub mod multi_coins_wallet; \ No newline at end of file diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/aptos.rs b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/aptos.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/arconnect.rs b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/arconnect.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/backpack.rs b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/backpack.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/bitget.rs b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/bitget.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/imtoken.rs b/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/imtoken.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/keplr.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs similarity index 98% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/keplr.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs index b50cbcd5e..665371b18 100644 --- a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/keplr.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs @@ -1,4 +1,4 @@ -use crate::structs::KeplrAccount; +use super::structs::KeplrAccount; use alloc::format; use alloc::string::ToString; use alloc::vec::Vec; diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/keystone.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/keystone.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/lib.rs b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs similarity index 99% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/lib.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/mod.rs index e895fe304..78082b49d 100644 --- a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/lib.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs @@ -1,6 +1,3 @@ -#![no_std] - -extern crate alloc; pub mod aptos; pub mod arconnect; pub mod backpack; @@ -49,7 +46,7 @@ use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UN use common_rust_c::utils::{recover_c_array, recover_c_char}; use common_rust_c::{extract_array, extract_ptr_with_type}; -use crate::structs::QRHardwareCallData; +use structs::QRHardwareCallData; #[repr(C)] pub enum ETHAccountType { diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/okx.rs b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/okx.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/okx.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/solana.rs b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/solana.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/solana.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/structs.rs b/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/structs.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/structs.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/sui.rs b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/sui.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/sui.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/thor_wallet.rs b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs similarity index 97% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/thor_wallet.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs index e854ee6c3..20053bd15 100644 --- a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/thor_wallet.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs @@ -1,5 +1,3 @@ -#![no_std] -extern crate alloc; use alloc::format; use alloc::string::ToString; use core::slice; @@ -15,7 +13,7 @@ use common_rust_c::types::{PtrString, PtrT}; use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use common_rust_c::utils::{recover_c_array, recover_c_char}; -use crate::utils::normalize_xpub; +use super::utils::normalize_xpub; #[no_mangle] pub extern "C" fn get_connect_thor_wallet_ur( diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/tonkeeper.rs b/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/tonkeeper.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/utils.rs b/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/utils.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/utils.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/xbull.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/xbull.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/xrp_toolkit.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/xrp_toolkit.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/zcash.rs b/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs similarity index 100% rename from rust/rust_c/src/wallet/src/multi_coins_wallet/src/zcash.rs rename to rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs diff --git a/rust/rust_c/src/wallet/src/btc_only_wallet/Cargo.toml b/rust/rust_c/src/wallet/src/btc_only_wallet/Cargo.toml deleted file mode 100644 index 12438747c..000000000 --- a/rust/rust_c/src/wallet/src/btc_only_wallet/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "btc_only_wallet_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_wallets = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -bitcoin = { workspace = true } -ur-registry = { workspace = true } -hex = { workspace = true } -common_rust_c = { path = "../../../common" } -app_utils = { workspace = true } - -[features] -default = ["multi-coins"] -multi-coins = ["common_rust_c/multi-coins"] -btc-only = ["common_rust_c/btc-only"] diff --git a/rust/rust_c/src/wallet/src/lib.rs b/rust/rust_c/src/wallet/src/lib.rs deleted file mode 100644 index 4b5b7a1d2..000000000 --- a/rust/rust_c/src/wallet/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![no_std] - -extern crate alloc; - -pub use btc_only_wallet_rust_c; -pub use btc_only_wallet_rust_c::*; -#[cfg(feature = "multi-coins")] -pub use multi_coins_wallet_rust_c; diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/Cargo.toml b/rust/rust_c/src/wallet/src/multi_coins_wallet/Cargo.toml deleted file mode 100644 index 621fe61e8..000000000 --- a/rust/rust_c/src/wallet/src/multi_coins_wallet/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "multi_coins_wallet_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_wallets = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -app_arweave = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -ur-registry = { workspace = true } -hex = { workspace = true } -bitcoin = { workspace = true } -common_rust_c = { path = "../../../common" } -ed25519-bip32-core = { workspace = true } - -[features] -default = ["multi-coins"] -multi-coins = [] -btc-only = [] \ No newline at end of file diff --git a/rust/rust_c/src/xrp/Cargo.toml b/rust/rust_c/src/xrp/Cargo.toml deleted file mode 100644 index a6889bec4..000000000 --- a/rust/rust_c/src/xrp/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "xrp_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_xrp = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -bitcoin = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } -serde_json = { workspace = true } -common_rust_c = { path = "../common" } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/xrp/src/lib.rs b/rust/rust_c/src/xrp/mod.rs similarity index 99% rename from rust/rust_c/src/xrp/src/lib.rs rename to rust/rust_c/src/xrp/mod.rs index 97f6b8f8c..ff99ef680 100644 --- a/rust/rust_c/src/xrp/src/lib.rs +++ b/rust/rust_c/src/xrp/mod.rs @@ -1,7 +1,3 @@ -#![no_std] - -extern crate alloc; - use alloc::format; use alloc::string::ToString; use alloc::vec::Vec; @@ -29,7 +25,7 @@ use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; use common_rust_c::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use common_rust_c::utils::{convert_c_char, recover_c_char}; -use crate::structs::DisplayXrpTx; +use structs::DisplayXrpTx; pub mod structs; diff --git a/rust/rust_c/src/xrp/src/structs.rs b/rust/rust_c/src/xrp/structs.rs similarity index 100% rename from rust/rust_c/src/xrp/src/structs.rs rename to rust/rust_c/src/xrp/structs.rs diff --git a/rust/rust_c/src/zcash/Cargo.toml b/rust/rust_c/src/zcash/Cargo.toml deleted file mode 100644 index f9d01f851..000000000 --- a/rust/rust_c/src/zcash/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "zcash_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -app_zcash = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -common_rust_c = { path = "../common" } -cty = { workspace = true } -ur-registry = { workspace = true } -cstr_core = { workspace = true } -zcash_vendor = { workspace = true } - -[features] -debug-memory = [] diff --git a/rust/rust_c/src/zcash/src/lib.rs b/rust/rust_c/src/zcash/mod.rs similarity index 96% rename from rust/rust_c/src/zcash/src/lib.rs rename to rust/rust_c/src/zcash/mod.rs index 3a4dc54e0..f66a89c08 100644 --- a/rust/rust_c/src/zcash/src/lib.rs +++ b/rust/rust_c/src/zcash/mod.rs @@ -1,6 +1,3 @@ -#![no_std] -extern crate alloc; - pub mod structs; use alloc::{boxed::Box, format}; @@ -24,7 +21,11 @@ use ur_registry::{traits::RegistryItem, zcash::zcash_pczt::ZcashPczt}; use zcash_vendor::zcash_protocol::consensus::MainNetwork; #[no_mangle] -pub extern "C" fn derive_zcash_ufvk(seed: PtrBytes, seed_len: u32, account_path: PtrString) -> *mut SimpleResponse { +pub extern "C" fn derive_zcash_ufvk( + seed: PtrBytes, + seed_len: u32, + account_path: PtrString, +) -> *mut SimpleResponse { let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; let account_path = recover_c_char(account_path); let ufvk_text = derive_ufvk(&MainNetwork, seed, &account_path); diff --git a/rust/rust_c/src/zcash/src/structs.rs b/rust/rust_c/src/zcash/structs.rs similarity index 100% rename from rust/rust_c/src/zcash/src/structs.rs rename to rust/rust_c/src/zcash/structs.rs From 6716a5b1cc22b996dc2f46cdd6e2d51ae869d8d4 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 16:55:48 +0800 Subject: [PATCH 21/31] chore: refactor common interfaces --- rust/Cargo.lock | 46 ++------ rust/Cargo.toml | 2 - rust/rust_c/Cargo.toml | 101 +++++++++--------- rust/rust_c/src/aptos/mod.rs | 12 +-- rust/rust_c/src/aptos/structs.rs | 10 +- rust/rust_c/src/arweave/data_item.rs | 6 +- rust/rust_c/src/arweave/mod.rs | 17 ++- rust/rust_c/src/arweave/structs.rs | 12 +-- rust/rust_c/src/bitcoin/address.rs | 6 +- rust/rust_c/src/bitcoin/legacy.rs | 12 +-- rust/rust_c/src/bitcoin/msg.rs | 4 +- rust/rust_c/src/bitcoin/multi_sig/mod.rs | 15 ++- rust/rust_c/src/bitcoin/multi_sig/structs.rs | 12 +-- rust/rust_c/src/bitcoin/psbt.rs | 14 +-- rust/rust_c/src/bitcoin/structs.rs | 16 +-- rust/rust_c/src/cardano/address.rs | 6 +- rust/rust_c/src/cardano/mod.rs | 12 +-- rust/rust_c/src/cardano/structs.rs | 12 +-- rust/rust_c/src/common/Cargo.toml | 50 --------- rust/rust_c/src/common/{src => }/errors.rs | 0 rust/rust_c/src/common/{src => }/ffi.rs | 4 +- rust/rust_c/src/common/{src => }/free.rs | 10 +- rust/rust_c/src/common/{src => }/keystone.rs | 10 +- rust/rust_c/src/common/{src => }/macros.rs | 12 +-- rust/rust_c/src/common/{src/lib.rs => mod.rs} | 14 +-- .../rust_c/src/common/{src => }/qrcode/mod.rs | 6 +- .../{src => }/qrcode/seed_signer_message.rs | 0 rust/rust_c/src/common/{src => }/structs.rs | 8 +- rust/rust_c/src/common/{src => }/types.rs | 2 +- rust/rust_c/src/common/{src => }/ur.rs | 10 +- rust/rust_c/src/common/{src => }/ur_ext.rs | 6 +- rust/rust_c/src/common/{src => }/utils.rs | 6 +- rust/rust_c/src/common/{src => }/web_auth.rs | 0 rust/rust_c/src/cosmos/mod.rs | 12 +-- rust/rust_c/src/cosmos/structs.rs | 10 +- rust/rust_c/src/ethereum/abi.rs | 8 +- rust/rust_c/src/ethereum/address.rs | 6 +- rust/rust_c/src/ethereum/mod.rs | 15 +-- rust/rust_c/src/ethereum/structs.rs | 12 +-- rust/rust_c/src/lib.rs | 2 +- rust/rust_c/src/near/mod.rs | 10 +- rust/rust_c/src/near/structs.rs | 12 +-- rust/rust_c/src/simulator/mod.rs | 2 +- rust/rust_c/src/solana/mod.rs | 12 +-- rust/rust_c/src/solana/structs.rs | 12 +-- rust/rust_c/src/stellar/mod.rs | 12 +-- rust/rust_c/src/stellar/structs.rs | 8 +- rust/rust_c/src/sui/mod.rs | 12 +-- rust/rust_c/src/sui/structs.rs | 10 +- rust/rust_c/src/test_cmd/btc_test_cmd.rs | 12 +-- rust/rust_c/src/test_cmd/general_test_cmd.rs | 12 +-- rust/rust_c/src/ton/mod.rs | 24 ++--- rust/rust_c/src/ton/structs.rs | 7 +- rust/rust_c/src/tron/mod.rs | 12 +-- rust/rust_c/src/tron/structs.rs | 10 +- rust/rust_c/src/wallet/btc_only_wallet.rs | 14 +-- .../src/wallet/multi_coins_wallet/aptos.rs | 12 +-- .../wallet/multi_coins_wallet/arconnect.rs | 6 +- .../src/wallet/multi_coins_wallet/backpack.rs | 12 +-- .../src/wallet/multi_coins_wallet/bitget.rs | 12 +-- .../src/wallet/multi_coins_wallet/imtoken.rs | 8 +- .../src/wallet/multi_coins_wallet/keplr.rs | 10 +- .../src/wallet/multi_coins_wallet/keystone.rs | 12 +-- .../src/wallet/multi_coins_wallet/mod.rs | 14 +-- .../src/wallet/multi_coins_wallet/okx.rs | 12 +-- .../src/wallet/multi_coins_wallet/solana.rs | 12 +-- .../src/wallet/multi_coins_wallet/structs.rs | 14 +-- .../src/wallet/multi_coins_wallet/sui.rs | 12 +-- .../wallet/multi_coins_wallet/thor_wallet.rs | 10 +- .../wallet/multi_coins_wallet/tonkeeper.rs | 8 +- .../src/wallet/multi_coins_wallet/utils.rs | 6 +- .../src/wallet/multi_coins_wallet/xbull.rs | 12 +-- .../wallet/multi_coins_wallet/xrp_toolkit.rs | 6 +- .../src/wallet/multi_coins_wallet/zcash.rs | 12 +-- rust/rust_c/src/xrp/mod.rs | 14 +-- rust/rust_c/src/xrp/structs.rs | 10 +- rust/rust_c/src/zcash/mod.rs | 6 +- rust/rust_c/src/zcash/structs.rs | 14 ++- 78 files changed, 415 insertions(+), 518 deletions(-) delete mode 100644 rust/rust_c/src/common/Cargo.toml rename rust/rust_c/src/common/{src => }/errors.rs (100%) rename rust/rust_c/src/common/{src => }/ffi.rs (94%) rename rust/rust_c/src/common/{src => }/free.rs (94%) rename rust/rust_c/src/common/{src => }/keystone.rs (97%) rename rust/rust_c/src/common/{src => }/macros.rs (98%) rename rust/rust_c/src/common/{src/lib.rs => mod.rs} (98%) rename rust/rust_c/src/common/{src => }/qrcode/mod.rs (94%) rename rust/rust_c/src/common/{src => }/qrcode/seed_signer_message.rs (100%) rename rust/rust_c/src/common/{src => }/structs.rs (97%) rename rust/rust_c/src/common/{src => }/types.rs (95%) rename rust/rust_c/src/common/{src => }/ur.rs (99%) rename rust/rust_c/src/common/{src => }/ur_ext.rs (99%) rename rust/rust_c/src/common/{src => }/utils.rs (85%) rename rust/rust_c/src/common/{src => }/web_auth.rs (100%) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index d112b6a8f..0b908bb18 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1065,45 +1065,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" -[[package]] -name = "common_rust_c" -version = "0.1.0" -dependencies = [ - "aes", - "app_aptos", - "app_arweave", - "app_bitcoin", - "app_cardano", - "app_cosmos", - "app_ethereum", - "app_near", - "app_solana", - "app_stellar", - "app_sui", - "app_ton", - "app_tron", - "app_utils", - "app_wallets", - "app_xrp", - "app_zcash", - "base64 0.11.0", - "bitcoin", - "bitcoin_hashes 0.14.0", - "cbc", - "cryptoxide", - "cstr_core", - "cty", - "hex", - "keystore", - "rsa", - "rust_tools", - "serde_json", - "sha1", - "thiserror-core", - "ur-parse-lib", - "ur-registry", -] - [[package]] name = "const-oid" version = "0.9.6" @@ -3370,6 +3331,7 @@ dependencies = [ name = "rust_c" version = "0.1.0" dependencies = [ + "aes", "app_aptos", "app_arweave", "app_bitcoin", @@ -3388,8 +3350,9 @@ dependencies = [ "app_zcash", "base64 0.11.0", "bitcoin", + "bitcoin_hashes 0.14.0", + "cbc", "cbindgen", - "common_rust_c", "core2", "cryptoxide", "cstr_core", @@ -3400,9 +3363,12 @@ dependencies = [ "hex", "itertools 0.13.0", "keystore", + "rsa", "rust_tools", "serde_json", + "sha1", "sim_qr_reader", + "thiserror-core", "ur-parse-lib", "ur-registry", "zcash_vendor", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index a44dca30d..231047af4 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -21,8 +21,6 @@ members = [ # C interface entry "rust_c", - # rust_c libs - "rust_c/src/common", # other "keystore", diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index 9eb10c19f..f1c38a8c4 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -6,55 +6,51 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -common_rust_c = { path = "./src/common", optional = true, default-features = false } - - +#external cty = { workspace = true } cstr_core = { workspace = true } getrandom = { workspace = true, features = ["custom"] } -keystore = { workspace = true } -app_aptos = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } serde_json = { workspace = true } hex = { workspace = true } bitcoin = { workspace = true } -ur-registry = { workspace = true } -app_arweave = { workspace = true } cryptoxide = { workspace = true } -app_bitcoin = { workspace = true } base64 = { workspace = true } -app_cardano = { workspace = true } itertools = { workspace = true } -ed25519-bip32-core = { workspace = true } - -app_cosmos = { workspace = true, default-features = false } either = { workspace = true } - -app_ethereum = { workspace = true } core2 = { workspace = true } - -app_solana = { workspace = true } - -app_near = { workspace = true } - -app_sui = { workspace = true } - -app_stellar = { workspace = true } - -app_ton = { workspace = true } - -app_tron = { workspace = true } - -app_wallets = { workspace = true } - +thiserror = { workspace = true } +bitcoin_hashes = { workspace = true } +rsa = { workspace = true } +sha1 = { workspace = true } +aes = { workspace = true } +cbc = { workspace = true } + +#keystone owned +keystore = { workspace = true } +sim_qr_reader = { workspace = true } +ur-registry = { workspace = true } ur-parse-lib = { workspace = true } - -app_xrp = { workspace = true } - -app_zcash = { workspace = true } zcash_vendor = { workspace = true } -sim_qr_reader = { workspace = true } +ed25519-bip32-core = { workspace = true } +app_utils = { workspace = true } +rust_tools = { workspace = true } + +#apps +app_bitcoin = { workspace = true, optional = true } +app_wallets = { workspace = true } +app_ethereum = { workspace = true, optional = true } +app_cardano = { workspace = true, optional = true } +app_tron = { workspace = true, optional = true } +app_solana = { workspace = true, optional = true } +app_near = { workspace = true, optional = true } +app_xrp = { workspace = true, optional = true } +app_cosmos = { workspace = true, optional = true } +app_aptos = { workspace = true, optional = true } +app_sui = { workspace = true, optional = true } +app_arweave = { workspace = true, optional = true } +app_stellar = { workspace = true, optional = true } +app_ton = { workspace = true, optional = true } +app_zcash = { workspace = true, optional = true } [lib] crate-type = ["staticlib"] @@ -63,26 +59,25 @@ crate-type = ["staticlib"] # feature toggles use-allocator = [] simulator = [] -aptos = [] -arweave = [] -bitcoin = [] -cardano = [] -cosmos = [] -ethereum = [] -near = [] -solana = [] -stellar = [] -sui = [] -ton = [] -tron = [] -xrp = [] -zcash = [] +aptos = ["dep:app_aptos"] +arweave = ["dep:app_arweave"] +bitcoin = ["dep:app_bitcoin"] +cardano = ["dep:app_cardano"] +cosmos = ["dep:app_cosmos"] +ethereum = ["dep:app_ethereum"] +near = ["dep:app_near"] +solana = ["dep:app_solana"] +stellar = ["dep:app_stellar"] +sui = ["dep:app_sui"] +ton = ["dep:app_ton"] +tron = ["dep:app_tron"] +xrp = ["dep:app_xrp"] +zcash = ["dep:app_zcash"] test_cmd = [] -debug-memory = ["multi-coins", "common_rust_c/debug-memory"] +debug-memory = ["multi-coins"] multi-coins = [ - "common_rust_c/multi-coins", "bitcoin", "ethereum", "solana", @@ -99,7 +94,7 @@ multi-coins = [ "zcash", ] -btc-only = ["common_rust_c/btc-only", "bitcoin"] +btc-only = ["bitcoin"] # build variants # production diff --git a/rust/rust_c/src/aptos/mod.rs b/rust/rust_c/src/aptos/mod.rs index 2f53993a4..7029ed6b9 100644 --- a/rust/rust_c/src/aptos/mod.rs +++ b/rust/rust_c/src/aptos/mod.rs @@ -6,12 +6,12 @@ use alloc::vec::Vec; use app_aptos; use app_aptos::errors::AptosError; use app_aptos::parser::is_tx; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use cty::c_char; use hex; use hex::FromHex; diff --git a/rust/rust_c/src/aptos/structs.rs b/rust/rust_c/src/aptos/structs.rs index 8101587ca..f23d20dba 100644 --- a/rust/rust_c/src/aptos/structs.rs +++ b/rust/rust_c/src/aptos/structs.rs @@ -1,10 +1,10 @@ use alloc::string::{String, ToString}; use app_aptos::parser::AptosTx; -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; use serde_json::Value; #[repr(C)] diff --git a/rust/rust_c/src/arweave/data_item.rs b/rust/rust_c/src/arweave/data_item.rs index 80ebe5a8b..1a11291bc 100644 --- a/rust/rust_c/src/arweave/data_item.rs +++ b/rust/rust_c/src/arweave/data_item.rs @@ -1,9 +1,9 @@ -use app_arweave::{ao_transaction::AOTransferTransaction, parse_data_item}; -use common_rust_c::{ - extract_ptr_with_type, +use crate::common::{ structs::TransactionParseResult, types::{PtrT, PtrUR}, }; +use crate::extract_ptr_with_type; +use app_arweave::{ao_transaction::AOTransferTransaction, parse_data_item}; use ur_registry::arweave::arweave_sign_request::ArweaveSignRequest; use super::structs::{DisplayArweaveAOTransfer, DisplayArweaveDataItem}; diff --git a/rust/rust_c/src/arweave/mod.rs b/rust/rust_c/src/arweave/mod.rs index 74903381f..906ae6aea 100644 --- a/rust/rust_c/src/arweave/mod.rs +++ b/rust/rust_c/src/arweave/mod.rs @@ -1,9 +1,15 @@ -pub mod structs; pub mod data_item; +pub mod structs; -use structs::{ArweaveRequestType, DisplayArweaveMessage, DisplayArweaveTx}; use alloc::boxed::Box; +use structs::{ArweaveRequestType, DisplayArweaveMessage, DisplayArweaveTx}; +use crate::common::errors::RustCError; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; use alloc::slice; use alloc::string::{String, ToString}; use alloc::vec::Vec; @@ -12,12 +18,6 @@ use app_arweave::{ aes256_decrypt, aes256_encrypt, errors::ArweaveError, fix_address, generate_public_key_from_primes, generate_secret, parse, }; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; use cty::c_char; use hex; use keystore::algorithms::ed25519::slip10_ed25519::get_private_key_by_seed; @@ -28,7 +28,6 @@ use ur_registry::arweave::arweave_sign_request::{ArweaveSignRequest, SaltLen, Si use ur_registry::arweave::arweave_signature::ArweaveSignature; use ur_registry::traits::RegistryItem; - fn generate_aes_key_iv(seed: &[u8]) -> ([u8; 32], [u8; 16]) { // The number 1557192335 is derived from the ASCII representation of "keystone" hashed with SHA-256, taking the first 32 bits with the highest bit set to 0. let key_path = "m/44'/1557192335'/0'/0'/0'".to_string(); diff --git a/rust/rust_c/src/arweave/structs.rs b/rust/rust_c/src/arweave/structs.rs index 1fc2be1d6..bec53ee75 100644 --- a/rust/rust_c/src/arweave/structs.rs +++ b/rust/rust_c/src/arweave/structs.rs @@ -4,12 +4,12 @@ use app_arweave::{ ao_transaction::AOTransferTransaction, data_item::{DataItem, Tag}, }; -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{Ptr, PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; -use common_rust_c::{ffi::VecFFI, free_vec}; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{Ptr, PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method, free_vec}; +use crate::common::ffi::VecFFI; #[repr(C)] pub enum ArweaveRequestType { diff --git a/rust/rust_c/src/bitcoin/address.rs b/rust/rust_c/src/bitcoin/address.rs index 336bfd941..655fea642 100644 --- a/rust/rust_c/src/bitcoin/address.rs +++ b/rust/rust_c/src/bitcoin/address.rs @@ -1,9 +1,9 @@ use app_bitcoin; use app_bitcoin::addresses::xyzpub; use bitcoin::secp256k1::ffi::types::c_char; -use common_rust_c::structs::SimpleResponse; -use common_rust_c::types::PtrString; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::structs::SimpleResponse; +use crate::common::types::PtrString; +use crate::common::utils::{convert_c_char, recover_c_char}; use core::str::FromStr; #[no_mangle] diff --git a/rust/rust_c/src/bitcoin/legacy.rs b/rust/rust_c/src/bitcoin/legacy.rs index 1979b16c7..f0eae8f28 100644 --- a/rust/rust_c/src/bitcoin/legacy.rs +++ b/rust/rust_c/src/bitcoin/legacy.rs @@ -1,12 +1,12 @@ use super::structs::DisplayTx; use alloc::boxed::Box; use alloc::slice; -use common_rust_c::errors::RustCError; -use common_rust_c::keystone; -use common_rust_c::keystone::{build_parse_context, build_payload}; -use common_rust_c::structs::{TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{QRCodeType, UREncodeResult}; +use crate::common::errors::RustCError; +use crate::common::keystone; +use crate::common::keystone::{build_parse_context, build_payload}; +use crate::common::structs::{TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{QRCodeType, UREncodeResult}; #[no_mangle] pub extern "C" fn utxo_parse_keystone( diff --git a/rust/rust_c/src/bitcoin/msg.rs b/rust/rust_c/src/bitcoin/msg.rs index 0a1e62fbf..da66b535d 100644 --- a/rust/rust_c/src/bitcoin/msg.rs +++ b/rust/rust_c/src/bitcoin/msg.rs @@ -6,9 +6,8 @@ use alloc::{ vec::Vec, }; use base64; -use common_rust_c::{ +use crate::common::{ errors::RustCError, - extract_ptr_with_type, ffi::CSliceFFI, qrcode::seed_signer_message::SeedSignerMessage, structs::{ExtendedPublicKey, TransactionCheckResult, TransactionParseResult}, @@ -16,6 +15,7 @@ use common_rust_c::{ ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}, utils::{convert_c_char, recover_c_array, recover_c_char}, }; +use crate::extract_ptr_with_type; use keystore::algorithms::secp256k1; use ur_registry::bitcoin::btc_sign_request::{BtcSignRequest, DataType}; use ur_registry::bitcoin::btc_signature::BtcSignature; diff --git a/rust/rust_c/src/bitcoin/multi_sig/mod.rs b/rust/rust_c/src/bitcoin/multi_sig/mod.rs index e5ecf3be0..e29a6de58 100644 --- a/rust/rust_c/src/bitcoin/multi_sig/mod.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/mod.rs @@ -18,20 +18,19 @@ use structs::{MultiSigFormatType, MultiSigXPubInfoItem}; use cryptoxide::hashing::sha256; use hex; - use ur_registry::bytes::Bytes; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; -use common_rust_c::structs::{ExtendedPublicKey, Response, SimpleResponse}; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, ViewType, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_array, recover_c_char}; +use crate::common::structs::{ExtendedPublicKey, Response, SimpleResponse}; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, ViewType, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_array, recover_c_char}; use structs::{MultiSigWallet, NetworkType}; -use common_rust_c::extract_ptr_with_type; +use crate::extract_ptr_with_type; use ur_registry::crypto_account::CryptoAccount; use ur_registry::error::URError; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/bitcoin/multi_sig/structs.rs b/rust/rust_c/src/bitcoin/multi_sig/structs.rs index dfe6a6ba1..83b69a2b1 100644 --- a/rust/rust_c/src/bitcoin/multi_sig/structs.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/structs.rs @@ -5,12 +5,12 @@ use alloc::string::ToString; use alloc::vec::Vec; use app_bitcoin::multi_sig::wallet::{BsmsWallet, MultiSigWalletConfig}; use app_bitcoin::multi_sig::{MultiSigFormat, MultiSigType, MultiSigXPubInfo, Network}; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::Free; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT}; -use common_rust_c::ur::UREncodeResult; -use common_rust_c::utils::{convert_c_char, recover_c_char}; -use common_rust_c::{check_and_free_ptr, free_str_ptr, free_vec, impl_c_ptr, make_free_method}; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT}; +use crate::common::ur::UREncodeResult; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::{check_and_free_ptr, free_str_ptr, free_vec, impl_c_ptr, make_free_method}; #[repr(C)] pub enum NetworkType { diff --git a/rust/rust_c/src/bitcoin/psbt.rs b/rust/rust_c/src/bitcoin/psbt.rs index 1a8410495..c96c9901d 100644 --- a/rust/rust_c/src/bitcoin/psbt.rs +++ b/rust/rust_c/src/bitcoin/psbt.rs @@ -10,15 +10,15 @@ use core::str::FromStr; use app_bitcoin::parsed_tx::ParseContext; use app_bitcoin::{self, parse_psbt_hex_sign_status, parse_psbt_sign_status}; use bitcoin::bip32::{DerivationPath, Xpub}; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::ffi::{CSliceFFI, VecFFI}; -use common_rust_c::structs::{ +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::ffi::{CSliceFFI, VecFFI}; +use crate::common::structs::{ ExtendedPublicKey, Response, TransactionCheckResult, TransactionParseResult, }; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH}; -use common_rust_c::utils::{convert_c_char, recover_c_array, recover_c_char}; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH}; +use crate::common::utils::{convert_c_char, recover_c_array, recover_c_char}; use hex; use ur_registry::crypto_psbt::CryptoPSBT; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/bitcoin/structs.rs b/rust/rust_c/src/bitcoin/structs.rs index fdf91375a..323d9c6ba 100644 --- a/rust/rust_c/src/bitcoin/structs.rs +++ b/rust/rust_c/src/bitcoin/structs.rs @@ -4,14 +4,14 @@ use core::ptr::null_mut; use app_bitcoin; use app_bitcoin::parsed_tx::{DetailTx, OverviewTx, ParsedInput, ParsedOutput, ParsedTx}; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::Free; -use common_rust_c::structs::Response; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::ur::UREncodeResult; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::structs::Response; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::ur::UREncodeResult; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct PsbtSignResult { diff --git a/rust/rust_c/src/cardano/address.rs b/rust/rust_c/src/cardano/address.rs index 1b58321a2..bde4fa0a1 100644 --- a/rust/rust_c/src/cardano/address.rs +++ b/rust/rust_c/src/cardano/address.rs @@ -1,8 +1,8 @@ use app_cardano; use app_cardano::address::AddressType; -use common_rust_c::structs::SimpleResponse; -use common_rust_c::types::PtrString; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::structs::SimpleResponse; +use crate::common::types::PtrString; +use crate::common::utils::{convert_c_char, recover_c_char}; use cty::c_char; #[no_mangle] diff --git a/rust/rust_c/src/cardano/mod.rs b/rust/rust_c/src/cardano/mod.rs index 7e7a38f37..9f34865ea 100644 --- a/rust/rust_c/src/cardano/mod.rs +++ b/rust/rust_c/src/cardano/mod.rs @@ -27,12 +27,12 @@ use ur_registry::cardano::cardano_signature::CardanoSignature; use ur_registry::crypto_key_path::CryptoKeyPath; use structs::{DisplayCardanoCatalyst, DisplayCardanoSignData, DisplayCardanoTx}; -use common_rust_c::errors::{RustCError, R}; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::{RustCError, R}; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use ur_registry::registry_types::{ CARDANO_CATALYST_VOTING_REGISTRATION_SIGNATURE, CARDANO_SIGNATURE, CARDANO_SIGN_DATA_SIGNATURE, }; diff --git a/rust/rust_c/src/cardano/structs.rs b/rust/rust_c/src/cardano/structs.rs index 70538b53b..35b7f85c2 100644 --- a/rust/rust_c/src/cardano/structs.rs +++ b/rust/rust_c/src/cardano/structs.rs @@ -10,12 +10,12 @@ use hex; use itertools::Itertools; use ur_registry::cardano::cardano_catalyst_voting_registration::CardanoCatalystVotingRegistrationRequest; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::{free_ptr_string, Free}; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{Ptr, PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{ +use crate::common::ffi::VecFFI; +use crate::common::free::{free_ptr_string, Free}; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{Ptr, PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{ check_and_free_ptr, free_str_ptr, free_vec, impl_c_ptr, impl_c_ptrs, make_free_method, }; diff --git a/rust/rust_c/src/common/Cargo.toml b/rust/rust_c/src/common/Cargo.toml deleted file mode 100644 index afd8edb06..000000000 --- a/rust/rust_c/src/common/Cargo.toml +++ /dev/null @@ -1,50 +0,0 @@ -[package] -name = "common_rust_c" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -keystore = { workspace = true } -cty = { workspace = true } -cstr_core = { workspace = true } -app_utils = { workspace = true } -rust_tools = { workspace = true } -base64 = { workspace = true } -thiserror = { workspace = true } -hex = { workspace = true } -ur-registry = { workspace = true } -serde_json = { workspace = true } -bitcoin = { workspace = true } -bitcoin_hashes = { workspace = true } -rsa = { workspace = true } -cryptoxide = { workspace = true } -ur-parse-lib = { workspace = true } -sha1 = { workspace = true } -aes = { workspace = true } -cbc = { workspace = true } - -app_bitcoin = { workspace = true } -app_wallets = { workspace = true } - -app_ethereum = { workspace = true, optional = true } -app_cardano = { workspace = true, optional = true } -app_tron = { workspace = true, optional = true } -app_solana = { workspace = true, optional = true } -app_near = { workspace = true, optional = true } -app_xrp = { workspace = true, optional = true } -app_cosmos = { workspace = true, optional = true } -app_aptos = { workspace = true, optional = true } -app_sui = { workspace = true, optional = true } -app_arweave = { workspace = true, optional = true } -app_stellar = { workspace = true, optional = true } -app_ton = { workspace = true, optional = true } -app_zcash = { workspace = true, optional = true } - -[features] -debug-memory = ["default"] -default = ["multi-coins"] -multi-coins = ["app_ethereum", "app_cardano", "app_tron", "app_solana", "app_near", "app_xrp", "app_cosmos", "app_aptos", "app_sui", "app_arweave", "app_ton", "app_stellar", "app_zcash"] -# -btc-only = [] \ No newline at end of file diff --git a/rust/rust_c/src/common/src/errors.rs b/rust/rust_c/src/common/errors.rs similarity index 100% rename from rust/rust_c/src/common/src/errors.rs rename to rust/rust_c/src/common/errors.rs diff --git a/rust/rust_c/src/common/src/ffi.rs b/rust/rust_c/src/common/ffi.rs similarity index 94% rename from rust/rust_c/src/common/src/ffi.rs rename to rust/rust_c/src/common/ffi.rs index 6c96f095d..cc992dc84 100644 --- a/rust/rust_c/src/common/src/ffi.rs +++ b/rust/rust_c/src/common/ffi.rs @@ -1,8 +1,8 @@ -use crate::free::{Free, SimpleFree}; +use super::free::{Free, SimpleFree}; use alloc::vec::Vec; use cty::size_t; -use crate::types::PtrT; +use super::types::PtrT; use crate::{impl_c_ptr, impl_simple_free}; #[repr(C)] diff --git a/rust/rust_c/src/common/src/free.rs b/rust/rust_c/src/common/free.rs similarity index 94% rename from rust/rust_c/src/common/src/free.rs rename to rust/rust_c/src/common/free.rs index d287c2b99..eeaa625ec 100644 --- a/rust/rust_c/src/common/src/free.rs +++ b/rust/rust_c/src/common/free.rs @@ -1,8 +1,8 @@ -use crate::ffi::VecFFI; +use super::ffi::VecFFI; use crate::make_free_method; -use crate::structs::SimpleResponse; -use crate::types::{PtrString, PtrT}; -use crate::ur::{UREncodeMultiResult, UREncodeResult, URParseMultiResult, URParseResult}; +use super::structs::SimpleResponse; +use super::types::{PtrString, PtrT}; +use super::ur::{UREncodeMultiResult, UREncodeResult, URParseMultiResult, URParseResult}; use alloc::boxed::Box; use cty::{c_char, c_void}; @@ -57,7 +57,7 @@ macro_rules! free_ptr_with_type { ($x: expr, $name: ident) => { if (!$x.is_null()) { unsafe { - let x = extract_ptr_with_type!($x, $name); + let x = crate::extract_ptr_with_type!($x, $name); let _b = alloc::boxed::Box::from_raw(x); // drop(b); } diff --git a/rust/rust_c/src/common/src/keystone.rs b/rust/rust_c/src/common/keystone.rs similarity index 97% rename from rust/rust_c/src/common/src/keystone.rs rename to rust/rust_c/src/common/keystone.rs index cfa49fb25..beba14975 100644 --- a/rust/rust_c/src/common/src/keystone.rs +++ b/rust/rust_c/src/common/keystone.rs @@ -1,9 +1,9 @@ -use crate::errors::{KeystoneError, RustCError}; +use super::errors::{KeystoneError, RustCError}; +use super::structs::TransactionCheckResult; +use super::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use super::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use super::utils::recover_c_char; use crate::extract_ptr_with_type; -use crate::structs::TransactionCheckResult; -use crate::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use crate::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use crate::utils::recover_c_char; use alloc::borrow::ToOwned; use alloc::format; use alloc::string::{String, ToString}; diff --git a/rust/rust_c/src/common/src/macros.rs b/rust/rust_c/src/common/macros.rs similarity index 98% rename from rust/rust_c/src/common/src/macros.rs rename to rust/rust_c/src/common/macros.rs index c9a2eed9c..50338ed0c 100644 --- a/rust/rust_c/src/common/src/macros.rs +++ b/rust/rust_c/src/common/macros.rs @@ -134,8 +134,8 @@ macro_rules! impl_new_error { } } - impl From for $name { - fn from(value: crate::errors::KeystoneError) -> Self { + impl From for $name { + fn from(value: super::errors::KeystoneError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } @@ -267,8 +267,8 @@ macro_rules! impl_new_error { } } - impl<$t: Free> From for $name<$t> { - fn from(value: crate::errors::KeystoneError) -> Self { + impl<$t: Free> From for $name<$t> { + fn from(value: super::errors::KeystoneError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } @@ -488,7 +488,7 @@ macro_rules! make_free_method { app_utils::paste::item! { #[no_mangle] pub extern "C" fn [](ptr: PtrT<$t>) { - check_and_free_ptr!(ptr) + crate::check_and_free_ptr!(ptr) } } }; @@ -496,7 +496,7 @@ macro_rules! make_free_method { app_utils::paste::item! { #[no_mangle] pub extern "C" fn [](ptr: PtrT<$t1<$t2>>) { - check_and_free_ptr!(ptr) + crate::check_and_free_ptr!(ptr) } } }; diff --git a/rust/rust_c/src/common/src/lib.rs b/rust/rust_c/src/common/mod.rs similarity index 98% rename from rust/rust_c/src/common/src/lib.rs rename to rust/rust_c/src/common/mod.rs index f1f972409..840f8894f 100644 --- a/rust/rust_c/src/common/src/lib.rs +++ b/rust/rust_c/src/common/mod.rs @@ -1,9 +1,3 @@ -#![no_std] -#![feature(vec_into_raw_parts)] -#![feature(error_in_core)] -#![allow(unused_unsafe)] -extern crate alloc; - use aes::cipher::block_padding::Pkcs7; use aes::cipher::generic_array::GenericArray; use aes::cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit}; @@ -25,10 +19,10 @@ use errors::ErrorCodes; use structs::{Response, TransactionCheckResult}; use types::Ptr; -use crate::errors::RustCError; -use crate::structs::SimpleResponse; -use crate::types::{PtrBytes, PtrString}; -use crate::utils::{convert_c_char, recover_c_char}; +use errors::RustCError; +use structs::SimpleResponse; +use types::{PtrBytes, PtrString}; +use utils::{convert_c_char, recover_c_char}; pub mod errors; pub mod ffi; diff --git a/rust/rust_c/src/common/src/qrcode/mod.rs b/rust/rust_c/src/common/qrcode/mod.rs similarity index 94% rename from rust/rust_c/src/common/src/qrcode/mod.rs rename to rust/rust_c/src/common/qrcode/mod.rs index faf4353e0..4a132c8ca 100644 --- a/rust/rust_c/src/common/src/qrcode/mod.rs +++ b/rust/rust_c/src/common/qrcode/mod.rs @@ -3,7 +3,7 @@ use seed_signer_message::{MessageEncoding, SeedSignerMessage}; pub mod seed_signer_message; -use crate::{ +use super::{ errors::RustCError, types::{Ptr, PtrString}, ur::URParseResult, @@ -47,8 +47,8 @@ pub extern "C" fn parse_qrcode_text(qr: PtrString) -> Ptr { MessageEncoding::ASCII, ); return URParseResult::single( - crate::ur::ViewType::BtcMsg, - crate::ur::QRCodeType::SeedSignerMessage, + super::ur::ViewType::BtcMsg, + super::ur::QRCodeType::SeedSignerMessage, data, ) .c_ptr(); diff --git a/rust/rust_c/src/common/src/qrcode/seed_signer_message.rs b/rust/rust_c/src/common/qrcode/seed_signer_message.rs similarity index 100% rename from rust/rust_c/src/common/src/qrcode/seed_signer_message.rs rename to rust/rust_c/src/common/qrcode/seed_signer_message.rs diff --git a/rust/rust_c/src/common/src/structs.rs b/rust/rust_c/src/common/structs.rs similarity index 97% rename from rust/rust_c/src/common/src/structs.rs rename to rust/rust_c/src/common/structs.rs index fc081fd76..144b3f333 100644 --- a/rust/rust_c/src/common/src/structs.rs +++ b/rust/rust_c/src/common/structs.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] -use crate::errors::ErrorCodes; -use crate::errors::RustCError; +use super::errors::ErrorCodes; +use super::errors::RustCError; use alloc::boxed::Box; use alloc::string::{String, ToString}; use app_bitcoin::errors::BitcoinError; @@ -12,8 +12,8 @@ use cstr_core::CString; use keystore::errors::KeystoreError; use ur_registry::error::URError; -use crate::free::Free; -use crate::types::{PtrString, PtrT}; +use super::free::Free; +use super::types::{PtrString, PtrT}; use crate::{ check_and_free_ptr, free_str_ptr, impl_c_ptr, impl_new_error, impl_response, impl_simple_c_ptr, impl_simple_new_error, make_free_method, diff --git a/rust/rust_c/src/common/src/types.rs b/rust/rust_c/src/common/types.rs similarity index 95% rename from rust/rust_c/src/common/src/types.rs rename to rust/rust_c/src/common/types.rs index 77ecec753..3c5c0b355 100644 --- a/rust/rust_c/src/common/src/types.rs +++ b/rust/rust_c/src/common/types.rs @@ -1,7 +1,7 @@ use alloc::boxed::Box; use core::ffi::c_void; -use crate::free::Free; +use super::free::Free; use cty::c_char; pub type PtrString = *mut c_char; diff --git a/rust/rust_c/src/common/src/ur.rs b/rust/rust_c/src/common/ur.rs similarity index 99% rename from rust/rust_c/src/common/src/ur.rs rename to rust/rust_c/src/common/ur.rs index 5abc99ddb..3ee8a875e 100644 --- a/rust/rust_c/src/common/src/ur.rs +++ b/rust/rust_c/src/common/ur.rs @@ -59,11 +59,11 @@ use ur_registry::{ cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest, }; -use crate::errors::{ErrorCodes, RustCError}; -use crate::free::Free; -use crate::types::{PtrDecoder, PtrEncoder, PtrString, PtrUR}; -use crate::ur_ext::InferViewType; -use crate::utils::{convert_c_char, recover_c_char}; +use super::errors::{ErrorCodes, RustCError}; +use super::free::Free; +use super::types::{PtrDecoder, PtrEncoder, PtrString, PtrUR}; +use super::ur_ext::InferViewType; +use super::utils::{convert_c_char, recover_c_char}; use crate::{ extract_ptr_with_type, free_ptr_with_type, free_str_ptr, impl_c_ptr, impl_new_error, impl_response, diff --git a/rust/rust_c/src/common/src/ur_ext.rs b/rust/rust_c/src/common/ur_ext.rs similarity index 99% rename from rust/rust_c/src/common/src/ur_ext.rs rename to rust/rust_c/src/common/ur_ext.rs index 07ae1a018..c7c21d95a 100644 --- a/rust/rust_c/src/common/src/ur_ext.rs +++ b/rust/rust_c/src/common/ur_ext.rs @@ -49,7 +49,7 @@ use ur_registry::{ bitcoin::btc_sign_request::BtcSignRequest, sui::sui_sign_hash_request::SuiSignHashRequest, }; -use crate::ur::ViewType; +use super::ur::ViewType; pub trait InferViewType { fn infer(&self) -> Result { @@ -323,8 +323,8 @@ mod tests { use hex::FromHex; use ur_registry::bytes::Bytes; - use crate::ur::ViewType; - use crate::ur_ext::InferViewType; + use super::InferViewType; + use crate::common::ur::ViewType; #[test] fn test_parse_ur_type() { diff --git a/rust/rust_c/src/common/src/utils.rs b/rust/rust_c/src/common/utils.rs similarity index 85% rename from rust/rust_c/src/common/src/utils.rs rename to rust/rust_c/src/common/utils.rs index 643255473..2759b7df1 100644 --- a/rust/rust_c/src/common/src/utils.rs +++ b/rust/rust_c/src/common/utils.rs @@ -2,12 +2,12 @@ use alloc::string::{String, ToString}; use core::slice; use crate::extract_ptr_with_type; -use crate::ffi::CSliceFFI; -use crate::free::Free; +use super::ffi::CSliceFFI; +use super::free::Free; use cstr_core::{CStr, CString}; use cty::c_char; -use crate::types::{PtrString, PtrT}; +use crate::common::types::{PtrString, PtrT}; pub fn convert_c_char(s: String) -> PtrString { CString::new(s.clone()).unwrap().into_raw() diff --git a/rust/rust_c/src/common/src/web_auth.rs b/rust/rust_c/src/common/web_auth.rs similarity index 100% rename from rust/rust_c/src/common/src/web_auth.rs rename to rust/rust_c/src/common/web_auth.rs diff --git a/rust/rust_c/src/cosmos/mod.rs b/rust/rust_c/src/cosmos/mod.rs index 9306d783f..b412e80b8 100644 --- a/rust/rust_c/src/cosmos/mod.rs +++ b/rust/rust_c/src/cosmos/mod.rs @@ -7,12 +7,12 @@ use alloc::vec::Vec; use app_cosmos::errors::CosmosError; use app_cosmos::transaction::structs::SignMode; use app_utils::normalize_path; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use core::slice; use cty::c_char; use either::Either; diff --git a/rust/rust_c/src/cosmos/structs.rs b/rust/rust_c/src/cosmos/structs.rs index 3dff8e20e..d2d2fb495 100644 --- a/rust/rust_c/src/cosmos/structs.rs +++ b/rust/rust_c/src/cosmos/structs.rs @@ -4,11 +4,11 @@ use app_cosmos::transaction::structs::{CosmosTxDisplayType, ParsedCosmosTx}; use core::ptr::null_mut; use serde_json; -use common_rust_c::free::{free_ptr_string, Free}; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, impl_c_ptr, make_free_method}; +use crate::common::free::{free_ptr_string, Free}; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct DisplayCosmosTx { diff --git a/rust/rust_c/src/ethereum/abi.rs b/rust/rust_c/src/ethereum/abi.rs index 223ff412b..677eb0824 100644 --- a/rust/rust_c/src/ethereum/abi.rs +++ b/rust/rust_c/src/ethereum/abi.rs @@ -1,8 +1,8 @@ use super::structs::DisplayContractData; -use common_rust_c::errors::RustCError; -use common_rust_c::structs::Response; -use common_rust_c::types::{Ptr, PtrString}; -use common_rust_c::utils::recover_c_char; +use crate::common::errors::RustCError; +use crate::common::structs::Response; +use crate::common::types::{Ptr, PtrString}; +use crate::common::utils::recover_c_char; use hex; #[no_mangle] diff --git a/rust/rust_c/src/ethereum/address.rs b/rust/rust_c/src/ethereum/address.rs index a5c168ab4..f8d91961e 100644 --- a/rust/rust_c/src/ethereum/address.rs +++ b/rust/rust_c/src/ethereum/address.rs @@ -3,9 +3,9 @@ use app_ethereum; use cty::c_char; use app_ethereum::errors::EthereumError; -use common_rust_c::structs::SimpleResponse; -use common_rust_c::types::PtrString; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::structs::SimpleResponse; +use crate::common::types::PtrString; +use crate::common::utils::{convert_c_char, recover_c_char}; #[no_mangle] pub extern "C" fn eth_get_address( diff --git a/rust/rust_c/src/ethereum/mod.rs b/rust/rust_c/src/ethereum/mod.rs index 99aa9d2f0..a09687721 100644 --- a/rust/rust_c/src/ethereum/mod.rs +++ b/rust/rust_c/src/ethereum/mod.rs @@ -20,15 +20,16 @@ use ur_registry::pb::protoc::payload::Content; use ur_registry::pb::protoc::sign_transaction::Transaction::EthTx; use ur_registry::traits::RegistryItem; -use common_rust_c::errors::{KeystoneError, RustCError}; -use common_rust_c::keystone::build_payload; -use common_rust_c::structs::{TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{ +use crate::common::errors::{KeystoneError, RustCError}; +use crate::common::keystone::build_payload; +use crate::common::structs::{TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{ QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH, }; -use common_rust_c::utils::{convert_c_char, recover_c_char}; -use common_rust_c::{extract_ptr_with_type, KEYSTONE}; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::common::KEYSTONE; +use crate::extract_ptr_with_type; use structs::{ DisplayETH, DisplayETHPersonalMessage, DisplayETHTypedData, EthParsedErc20Transaction, diff --git a/rust/rust_c/src/ethereum/structs.rs b/rust/rust_c/src/ethereum/structs.rs index c2d7f7667..f595fdc87 100644 --- a/rust/rust_c/src/ethereum/structs.rs +++ b/rust/rust_c/src/ethereum/structs.rs @@ -2,17 +2,17 @@ use alloc::boxed::Box; use super::util::{calculate_max_txn_fee, convert_wei_to_eth}; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::structs::{Response, TransactionParseResult}; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; use alloc::string::{String, ToString}; use alloc::vec::Vec; use app_ethereum::abi::{ContractData, ContractMethodParam}; use app_ethereum::erc20::encode_erc20_transfer_calldata; use app_ethereum::structs::{ParsedEthereumTransaction, PersonalMessage, TypedData}; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::Free; -use common_rust_c::structs::{Response, TransactionParseResult}; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; use core::ptr::null_mut; use core::str::FromStr; use itertools::Itertools; diff --git a/rust/rust_c/src/lib.rs b/rust/rust_c/src/lib.rs index b066d5ecb..4abc9335d 100644 --- a/rust/rust_c/src/lib.rs +++ b/rust/rust_c/src/lib.rs @@ -13,7 +13,7 @@ mod allocator; mod my_alloc; #[allow(unused)] -use common_rust_c; +mod common; #[allow(unused)] mod wallet; diff --git a/rust/rust_c/src/near/mod.rs b/rust/rust_c/src/near/mod.rs index 6c63b7f65..5839deafd 100644 --- a/rust/rust_c/src/near/mod.rs +++ b/rust/rust_c/src/near/mod.rs @@ -2,11 +2,11 @@ use structs::DisplayNearTx; use alloc::string::ToString; use alloc::{format, vec}; use app_near::errors::NearError; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use ur_registry::near::near_sign_request::NearSignRequest; use ur_registry::near::near_signature::NearSignature; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/near/structs.rs b/rust/rust_c/src/near/structs.rs index fe2ea7acf..0f8d4afa0 100644 --- a/rust/rust_c/src/near/structs.rs +++ b/rust/rust_c/src/near/structs.rs @@ -1,14 +1,14 @@ +use crate::common::ffi::VecFFI; +use crate::common::free::{free_ptr_string, Free}; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, impl_c_ptrs, make_free_method}; use alloc::boxed::Box; use alloc::string::ToString; use alloc::vec::Vec; use app_near::parser::overview::NearTxOverview; use app_near::parser::structs::{NearTxDisplayType, ParsedNearTx}; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::{free_ptr_string, Free}; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, impl_c_ptrs, make_free_method}; use core::ptr::null_mut; use itertools::Itertools; diff --git a/rust/rust_c/src/simulator/mod.rs b/rust/rust_c/src/simulator/mod.rs index 027a6f8e4..44e6c7b36 100644 --- a/rust/rust_c/src/simulator/mod.rs +++ b/rust/rust_c/src/simulator/mod.rs @@ -1,4 +1,4 @@ -use common_rust_c::utils::convert_c_char; +use crate::common::utils::convert_c_char; use cty::c_char; use sim_qr_reader::*; diff --git a/rust/rust_c/src/solana/mod.rs b/rust/rust_c/src/solana/mod.rs index 7ea96109c..ee30c3940 100644 --- a/rust/rust_c/src/solana/mod.rs +++ b/rust/rust_c/src/solana/mod.rs @@ -3,12 +3,12 @@ use alloc::format; use alloc::string::ToString; use app_solana::errors::SolanaError; use app_solana::parse_message; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use cty::c_char; use ur_registry::solana::sol_sign_request::SolSignRequest; use ur_registry::solana::sol_signature::SolSignature; diff --git a/rust/rust_c/src/solana/structs.rs b/rust/rust_c/src/solana/structs.rs index 7fd34e70d..6e520db7a 100644 --- a/rust/rust_c/src/solana/structs.rs +++ b/rust/rust_c/src/solana/structs.rs @@ -8,12 +8,12 @@ use app_solana::parser::structs::{ParsedSolanaTx, SolanaTxDisplayType}; use app_solana::structs::SolanaMessage; use itertools::Itertools; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, impl_c_ptrs, make_free_method}; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, impl_c_ptrs, make_free_method}; #[repr(C)] pub struct DisplaySolanaTx { diff --git a/rust/rust_c/src/stellar/mod.rs b/rust/rust_c/src/stellar/mod.rs index f8688edfd..8a234eb63 100644 --- a/rust/rust_c/src/stellar/mod.rs +++ b/rust/rust_c/src/stellar/mod.rs @@ -7,12 +7,12 @@ use cty::c_char; use structs::DisplayStellarTx; use app_stellar::strkeys::{sign_hash, sign_signature_base}; use app_stellar::{address::get_address, base_to_xdr}; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use hex; use ur_registry::stellar::stellar_sign_request::{SignType, StellarSignRequest}; use ur_registry::stellar::stellar_signature::StellarSignature; diff --git a/rust/rust_c/src/stellar/structs.rs b/rust/rust_c/src/stellar/structs.rs index 614a6fc57..70426ef50 100644 --- a/rust/rust_c/src/stellar/structs.rs +++ b/rust/rust_c/src/stellar/structs.rs @@ -1,8 +1,8 @@ -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct DisplayStellarTx { diff --git a/rust/rust_c/src/sui/mod.rs b/rust/rust_c/src/sui/mod.rs index cec7ad788..c7b36c5fb 100644 --- a/rust/rust_c/src/sui/mod.rs +++ b/rust/rust_c/src/sui/mod.rs @@ -11,12 +11,12 @@ use ur_registry::traits::RegistryItem; use app_sui::errors::SuiError; use app_utils::normalize_path; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_ptr_with_type; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use structs::DisplaySuiSignMessageHash; use structs::DisplaySuiIntentMessage; diff --git a/rust/rust_c/src/sui/structs.rs b/rust/rust_c/src/sui/structs.rs index dc4a8095c..9271c36f5 100644 --- a/rust/rust_c/src/sui/structs.rs +++ b/rust/rust_c/src/sui/structs.rs @@ -2,11 +2,11 @@ use alloc::string::String; use app_sui::Intent; use serde_json; -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct DisplaySuiIntentMessage { diff --git a/rust/rust_c/src/test_cmd/btc_test_cmd.rs b/rust/rust_c/src/test_cmd/btc_test_cmd.rs index b0922b690..b87971c13 100644 --- a/rust/rust_c/src/test_cmd/btc_test_cmd.rs +++ b/rust/rust_c/src/test_cmd/btc_test_cmd.rs @@ -8,15 +8,15 @@ use ur_registry::bytes::Bytes; use ur_registry::crypto_psbt::CryptoPSBT; use ur_registry::traits::RegistryItem; -use common_rust_c::errors::ErrorCodes; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::PtrDecoder; -use common_rust_c::ur::{ +use crate::common::errors::ErrorCodes; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::PtrDecoder; +use crate::common::ur::{ decode_ur, receive, QRCodeType, UREncodeResult, URParseMultiResult, URParseResult, ViewType, FRAGMENT_MAX_LENGTH_DEFAULT, }; -use common_rust_c::utils::convert_c_char; +use crate::common::utils::convert_c_char; use wallet_rust_c::get_connect_blue_wallet_ur; diff --git a/rust/rust_c/src/test_cmd/general_test_cmd.rs b/rust/rust_c/src/test_cmd/general_test_cmd.rs index c1f0db23d..1b0d7add9 100644 --- a/rust/rust_c/src/test_cmd/general_test_cmd.rs +++ b/rust/rust_c/src/test_cmd/general_test_cmd.rs @@ -22,15 +22,15 @@ use ur_registry::near::near_sign_request::NearSignRequest; use ur_registry::solana::sol_sign_request::SolSignRequest; use ur_registry::sui::sui_sign_request::SuiSignRequest; -use common_rust_c::errors::ErrorCodes; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{PtrBytes, PtrDecoder, PtrString}; -use common_rust_c::ur::{ +use crate::common::errors::ErrorCodes; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{PtrBytes, PtrDecoder, PtrString}; +use crate::common::ur::{ decode_ur, receive, QRCodeType, UREncodeResult, URParseMultiResult, URParseResult, ViewType, FRAGMENT_MAX_LENGTH_DEFAULT, }; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::utils::{convert_c_char, recover_c_char}; #[no_mangle] pub extern "C" fn test_get_bch_keystone_succeed_bytes() -> *mut URParseResult { diff --git a/rust/rust_c/src/ton/mod.rs b/rust/rust_c/src/ton/mod.rs index 6ad0a5ddf..b1e21c599 100644 --- a/rust/rust_c/src/ton/mod.rs +++ b/rust/rust_c/src/ton/mod.rs @@ -1,21 +1,21 @@ pub mod structs; -use alloc::{ - boxed::Box, - format, slice, - string::{String, ToString}, - vec::Vec, -}; -use app_ton::{mnemonic::ton_mnemonic_validate, ton_compare_address_and_public_key}; -use common_rust_c::{ +use crate::common::{ errors::RustCError, - extract_ptr_with_type, ffi::VecFFI, - impl_c_ptr, structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}, types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}, ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}, utils::recover_c_char, }; +use alloc::{ + boxed::Box, + format, slice, + string::{String, ToString}, + vec::Vec, +}; +use app_ton::{mnemonic::ton_mnemonic_validate, ton_compare_address_and_public_key}; + +use crate::{extract_ptr_with_type, impl_c_ptr}; use cty::c_char; use keystore::algorithms::ed25519; use rust_tools::convert_c_char; @@ -239,7 +239,7 @@ pub extern "C" fn ton_seed_to_publickey( let public_key = app_ton::mnemonic::ton_master_seed_to_public_key(_seed); SimpleResponse::success(convert_c_char(hex::encode(public_key))).simple_c_ptr() } - Err(_e) => SimpleResponse::from(common_rust_c::errors::RustCError::InvalidData(format!( + Err(_e) => SimpleResponse::from(crate::common::errors::RustCError::InvalidData(format!( "seed length should be 64" ))) .simple_c_ptr(), @@ -255,7 +255,7 @@ pub extern "C" fn ton_get_address(public_key: PtrString) -> *mut SimpleResponse< Err(e) => SimpleResponse::from(e).simple_c_ptr(), }, Err(e) => { - SimpleResponse::from(common_rust_c::errors::RustCError::InvalidHex(e.to_string())) + SimpleResponse::from(crate::common::errors::RustCError::InvalidHex(e.to_string())) .simple_c_ptr() } } diff --git a/rust/rust_c/src/ton/structs.rs b/rust/rust_c/src/ton/structs.rs index e580cd917..f3eb88584 100644 --- a/rust/rust_c/src/ton/structs.rs +++ b/rust/rust_c/src/ton/structs.rs @@ -1,14 +1,13 @@ use core::ptr::null_mut; -use app_ton::structs::{TonProof, TonTransaction}; -use common_rust_c::{ - check_and_free_ptr, +use crate::common::{ free::Free, - free_str_ptr, impl_c_ptr, make_free_method, structs::TransactionParseResult, types::{PtrString, PtrT}, utils::convert_c_char, }; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use app_ton::structs::{TonProof, TonTransaction}; #[repr(C)] pub struct DisplayTonTransaction { diff --git a/rust/rust_c/src/tron/mod.rs b/rust/rust_c/src/tron/mod.rs index 9882c819d..6fc23da01 100644 --- a/rust/rust_c/src/tron/mod.rs +++ b/rust/rust_c/src/tron/mod.rs @@ -3,12 +3,12 @@ pub mod structs; use structs::DisplayTron; use alloc::boxed::Box; use alloc::slice; -use common_rust_c::errors::RustCError; -use common_rust_c::keystone; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{QRCodeType, UREncodeResult}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::RustCError; +use crate::common::keystone; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{QRCodeType, UREncodeResult}; +use crate::common::utils::{convert_c_char, recover_c_char}; use cty::c_char; #[no_mangle] diff --git a/rust/rust_c/src/tron/structs.rs b/rust/rust_c/src/tron/structs.rs index ae26ceadd..9a2332ae7 100644 --- a/rust/rust_c/src/tron/structs.rs +++ b/rust/rust_c/src/tron/structs.rs @@ -1,11 +1,11 @@ use alloc::boxed::Box; use app_tron::{DetailTx, OverviewTx, ParsedTx}; -use common_rust_c::free::Free; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct DisplayTron { diff --git a/rust/rust_c/src/wallet/btc_only_wallet.rs b/rust/rust_c/src/wallet/btc_only_wallet.rs index f44fd9290..0d09372ac 100644 --- a/rust/rust_c/src/wallet/btc_only_wallet.rs +++ b/rust/rust_c/src/wallet/btc_only_wallet.rs @@ -4,13 +4,13 @@ use alloc::{format, vec}; use app_utils::normalize_path; use bitcoin::bip32::{DerivationPath, Xpub}; -use common_rust_c::errors::RustCError; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::errors::RustCError; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use core::slice; use core::str::FromStr; use cty::{int32_t, uint32_t}; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs index 81677c220..d51cecd5d 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs @@ -9,12 +9,12 @@ use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; use ur_registry::traits::RegistryItem; use app_wallets::aptos::generate_sync_ur; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::PtrT; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::PtrT; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; #[no_mangle] pub extern "C" fn get_connect_aptos_wallet_ur( diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs index ab9d6f600..bba618c1d 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs @@ -1,9 +1,9 @@ use alloc::slice; use alloc::vec::Vec; use app_arweave::generate_public_key_from_primes; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::recover_c_char; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::recover_c_char; use cty::uint32_t; use hex; use ur_registry::arweave::arweave_crypto_account::ArweaveCryptoAccount; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs index fd2664a72..484d6a4ac 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs @@ -1,10 +1,10 @@ use alloc::{format, string::ToString}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{Ptr, PtrBytes}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::recover_c_array; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{Ptr, PtrBytes}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::recover_c_array; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs index ad258565d..99986f7f0 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs @@ -1,10 +1,10 @@ use alloc::{format, string::ToString}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs b/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs index 41cb4ba67..abeb7c4e9 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs @@ -1,10 +1,10 @@ use alloc::format; use alloc::string::ToString; use app_wallets::metamask::ETHAccountTypeApp::Bip44Standard; -use common_rust_c::extract_array; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::UREncodeResult; -use common_rust_c::utils::recover_c_char; +use crate::extract_array; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::UREncodeResult; +use crate::common::utils::recover_c_char; use cty::uint32_t; use ur_registry::crypto_hd_key::CryptoHDKey; use ur_registry::error::URError; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs index 665371b18..6e556da1d 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs @@ -3,11 +3,11 @@ use alloc::format; use alloc::string::ToString; use alloc::vec::Vec; use app_wallets::keplr::{generate_sync_ur, sync_info::SyncInfo}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::types::{PtrBytes, PtrT}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::types::{PtrBytes, PtrT}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use cty::uint32_t; use keystore::algorithms::secp256k1::derive_extend_public_key; use ur_registry::error::URError; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs index 82017e7a3..c00b99756 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs @@ -1,10 +1,10 @@ use alloc::{format, string::ToString}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::error::URError; use super::utils::normalize_xpub; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs index 78082b49d..cadf86106 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs @@ -38,13 +38,13 @@ use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; use ur_registry::extend::qr_hardware_call::QRHardwareCall; use ur_registry::traits::RegistryItem; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::{ExtendedPublicKey, Response}; -use common_rust_c::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; -use common_rust_c::{extract_array, extract_ptr_with_type}; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::{ExtendedPublicKey, Response}; +use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH}; +use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::{extract_array, extract_ptr_with_type}; use structs::QRHardwareCallData; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs index b41c05d44..79c5e28db 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs @@ -1,10 +1,10 @@ use alloc::{format, string::ToString}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs index 1c364c4a5..7c1bdf0db 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs @@ -8,12 +8,12 @@ use ur_registry::error::URError; use ur_registry::traits::RegistryItem; use app_wallets::solana::generate_sync_ur; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::PtrT; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::PtrT; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; #[no_mangle] diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs b/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs index dc3fa2679..98b1b0fe2 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs @@ -6,13 +6,13 @@ use app_wallets::keplr::sync_info::SyncInfo; use ur_registry::extend::key_derivation_schema::{Curve, DerivationAlgo}; use ur_registry::extend::qr_hardware_call::{CallParams, CallType, QRHardwareCall}; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::VecFFI; -use common_rust_c::free::Free; -use common_rust_c::structs::Response; -use common_rust_c::types::{Ptr, PtrString, PtrT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::errors::RustCError; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::structs::Response; +use crate::common::types::{Ptr, PtrString, PtrT}; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct KeplrAccount { diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs index 1c09a0122..7a8181135 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs @@ -2,12 +2,12 @@ use alloc::collections::BTreeMap; use alloc::format; use app_wallets::sui::generate_sync_ur; use bitcoin::bip32::DerivationPath; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::PtrT; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::PtrT; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use core::slice; use core::str::FromStr; use hex; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs index 20053bd15..06b844d77 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs @@ -7,11 +7,11 @@ use ur_registry::error::URError; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; use ur_registry::traits::RegistryItem; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::{PtrString, PtrT}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use super::utils::normalize_xpub; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs b/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs index 32cff2018..48d7dff8d 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs @@ -1,11 +1,11 @@ -use alloc::string::ToString; -use app_wallets::tonkeeper::{generate_sync_ur, PathInfo}; -use common_rust_c::{ - extract_array, +use crate::common::{ types::{Ptr, PtrBytes, PtrString}, ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}, utils::recover_c_char, }; +use crate::extract_array; +use alloc::string::ToString; +use app_wallets::tonkeeper::{generate_sync_ur, PathInfo}; use { hex, ur_registry::{crypto_hd_key::CryptoHDKey, error::URError, traits::RegistryItem}, diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs b/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs index c7dae7b4d..3eb423dda 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs @@ -3,9 +3,9 @@ use core::str::FromStr; use alloc::vec; use alloc::vec::Vec; use app_utils::normalize_path; -use common_rust_c::errors::RustCError; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::utils::recover_c_char; +use crate::common::errors::RustCError; +use crate::common::structs::ExtendedPublicKey; +use crate::common::utils::recover_c_char; use { bitcoin::bip32::{DerivationPath, Xpub}, hex, diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs index 5ad9dda4c..d7ee10f35 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs @@ -8,12 +8,12 @@ use ur_registry::error::URError; use ur_registry::traits::RegistryItem; use app_wallets::xbull::generate_sync_ur; -use common_rust_c::errors::RustCError; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ExtendedPublicKey; -use common_rust_c::types::PtrT; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::common::errors::RustCError; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ExtendedPublicKey; +use crate::common::types::PtrT; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; #[no_mangle] diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs index 7678da767..d1dc8bd1c 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs @@ -1,7 +1,7 @@ use app_wallets::xrp_toolkit::generate_sync_ur; -use common_rust_c::types::PtrString; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::recover_c_char; +use crate::common::types::PtrString; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::recover_c_char; use ur_registry::bytes::Bytes; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs b/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs index 1b0e71116..85f5a0a12 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs @@ -2,12 +2,12 @@ use alloc::string::ToString; use alloc::vec::Vec; use alloc::{format, slice}; use app_wallets::zcash::{generate_sync_ur, UFVKInfo}; -use common_rust_c::extract_array; -use common_rust_c::ffi::CSliceFFI; -use common_rust_c::structs::ZcashKey; -use common_rust_c::types::{Ptr, PtrBytes, PtrString}; -use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use crate::common::ffi::CSliceFFI; +use crate::common::structs::ZcashKey; +use crate::common::types::{Ptr, PtrBytes, PtrString}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{recover_c_array, recover_c_char}; use ur_registry::bytes::Bytes; use ur_registry::error::URError; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/xrp/mod.rs b/rust/rust_c/src/xrp/mod.rs index ff99ef680..274b6dcf3 100644 --- a/rust/rust_c/src/xrp/mod.rs +++ b/rust/rust_c/src/xrp/mod.rs @@ -17,13 +17,13 @@ use ur_registry::pb::protoc::payload::Content; use ur_registry::pb::protoc::sign_transaction::Transaction::XrpTx; use ur_registry::traits::RegistryItem; -use common_rust_c::errors::{ErrorCodes, KeystoneError, RustCError}; -use common_rust_c::extract_ptr_with_type; -use common_rust_c::keystone::build_payload; -use common_rust_c::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use common_rust_c::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use common_rust_c::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use common_rust_c::utils::{convert_c_char, recover_c_char}; +use crate::common::errors::{ErrorCodes, KeystoneError, RustCError}; +use crate::extract_ptr_with_type; +use crate::common::keystone::build_payload; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; use structs::DisplayXrpTx; diff --git a/rust/rust_c/src/xrp/structs.rs b/rust/rust_c/src/xrp/structs.rs index dd68224ca..6535cbd7b 100644 --- a/rust/rust_c/src/xrp/structs.rs +++ b/rust/rust_c/src/xrp/structs.rs @@ -6,11 +6,11 @@ use app_xrp::parser::structs::{ParsedXrpTx, XrpTxDisplayType}; use serde_json; use ur_registry::pb::protoc::XrpTx; -use common_rust_c::free::{free_ptr_string, Free}; -use common_rust_c::structs::TransactionParseResult; -use common_rust_c::types::{PtrString, PtrT}; -use common_rust_c::utils::convert_c_char; -use common_rust_c::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use crate::common::free::{free_ptr_string, Free}; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; #[repr(C)] pub struct XRPHDPath { diff --git a/rust/rust_c/src/zcash/mod.rs b/rust/rust_c/src/zcash/mod.rs index f66a89c08..95f1b28b6 100644 --- a/rust/rust_c/src/zcash/mod.rs +++ b/rust/rust_c/src/zcash/mod.rs @@ -2,17 +2,15 @@ pub mod structs; use alloc::{boxed::Box, format}; use app_zcash::get_address; -use common_rust_c::{ - check_and_free_ptr, +use crate::common::{ errors::RustCError, - extract_ptr_with_type, free::Free, - make_free_method, structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}, types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}, ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}, utils::{convert_c_char, recover_c_char}, }; +use crate::{extract_ptr_with_type, make_free_method, }; use core::slice; use cty::c_char; use keystore::algorithms::zcash::{calculate_seed_fingerprint, derive_ufvk}; diff --git a/rust/rust_c/src/zcash/structs.rs b/rust/rust_c/src/zcash/structs.rs index 35aadcad7..266d24076 100644 --- a/rust/rust_c/src/zcash/structs.rs +++ b/rust/rust_c/src/zcash/structs.rs @@ -1,18 +1,16 @@ use core::ptr::null_mut; -use alloc::vec::Vec; -use app_zcash::pczt::structs::{ - ParsedFrom, ParsedOrchard, ParsedPczt, ParsedTo, ParsedTransparent, -}; -use common_rust_c::{ - extract_ptr_with_type, +use crate::common::{ ffi::VecFFI, free::Free, - free_ptr_with_type, free_str_ptr, free_vec, impl_c_ptr, impl_c_ptrs, types::{Ptr, PtrString}, utils::convert_c_char, }; - +use crate::{free_ptr_with_type, free_str_ptr, free_vec, impl_c_ptr, impl_c_ptrs}; +use alloc::vec::Vec; +use app_zcash::pczt::structs::{ + ParsedFrom, ParsedOrchard, ParsedPczt, ParsedTo, ParsedTransparent, +}; use cstr_core; #[repr(C)] From 6b5c429547539ee266c3ab0680b07a588711bda0 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 17:26:36 +0800 Subject: [PATCH 22/31] chore: refactor cbindgen --- rust/Cargo.lock | 1 - rust/rust_c/Cargo.toml | 6 +- rust/rust_c/build.rs | 74 +- rust/rust_c/cbindgen.toml | 15 + rust/rust_c/librust_c.h | 2433 ++++++++++++++++++++++ rust/rust_c/src/test_cmd/btc_test_cmd.rs | 2 +- rust/zcash_vendor/Cargo.toml | 1 - 7 files changed, 2467 insertions(+), 65 deletions(-) create mode 100644 rust/rust_c/cbindgen.toml create mode 100644 rust/rust_c/librust_c.h diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 0b908bb18..bbb743ccc 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -4841,7 +4841,6 @@ dependencies = [ name = "zcash_vendor" version = "0.1.0" dependencies = [ - "aes", "bech32 0.11.0", "bip32", "bitvec", diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index f1c38a8c4..51aed7047 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -26,8 +26,8 @@ aes = { workspace = true } cbc = { workspace = true } #keystone owned +sim_qr_reader = { workspace = true, optional = true } keystore = { workspace = true } -sim_qr_reader = { workspace = true } ur-registry = { workspace = true } ur-parse-lib = { workspace = true } zcash_vendor = { workspace = true } @@ -36,8 +36,8 @@ app_utils = { workspace = true } rust_tools = { workspace = true } #apps -app_bitcoin = { workspace = true, optional = true } app_wallets = { workspace = true } +app_bitcoin = { workspace = true, optional = true } app_ethereum = { workspace = true, optional = true } app_cardano = { workspace = true, optional = true } app_tron = { workspace = true, optional = true } @@ -58,7 +58,7 @@ crate-type = ["staticlib"] [features] # feature toggles use-allocator = [] -simulator = [] +simulator = ["dep:sim_qr_reader"] aptos = ["dep:app_aptos"] arweave = ["dep:app_arweave"] bitcoin = ["dep:app_bitcoin"] diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index 3f3060fae..18b73f5df 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -1,65 +1,21 @@ fn main() { - return; - let mut config = cbindgen::Config::default(); - config.language = cbindgen::Language::C; - let includes = vec![ - "common_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", - #[cfg(feature = "aptos")] - "aptos_rust_c", - #[cfg(feature = "simulator")] - "simulator_rust_c", - #[cfg(feature = "arweave")] - "arweave_rust_c", - #[cfg(feature = "bitcoin")] - "bitcoin_rust_c", - #[cfg(feature = "cardano")] - "cardano_rust_c", - #[cfg(feature = "cosmos")] - "cosmos_rust_c", - #[cfg(feature = "ethereum")] - "ethereum_rust_c", - #[cfg(feature = "near")] - "near_rust_c", - #[cfg(feature = "solana")] - "solana_rust_c", - #[cfg(feature = "stellar")] - "stellar_rust_c", - #[cfg(feature = "sui")] - "sui_rust_c", - #[cfg(feature = "ton")] - "ton_rust_c", - #[cfg(feature = "tron")] - "tron_rust_c", - #[cfg(feature = "xrp")] - "xrp_rust_c", - #[cfg(feature = "zcash")] - "zcash_rust_c", - #[cfg(feature = "test_cmd")] - "test_cmd_rust_c", - #[cfg(feature = "test_cmd")] - "btc_test_cmd_rust_c", - #[cfg(feature = "test_cmd")] - "general_test_cmd_rust_c", - ]; - - let crates = includes - .into_iter() - .map(|s| s.to_string()) - .collect::>(); - - config.parse.include = Some(crates.clone()); - config.parse.parse_deps = true; - config.parse.expand.crates = crates; + let mut config = + cbindgen::Config::from_file("cbindgen.toml").expect("Failed to read cbindgen.toml"); let features = vec![ - #[cfg(feature = "btc-only")] - "btc_only", - #[cfg(feature = "multi-coins")] - "multi_coins", + #[cfg(feature = "production-multi-coins")] + "production-multi-coins", + #[cfg(feature = "production-btc-only")] + "production-btc-only", + #[cfg(feature = "simulator-multi-coins")] + "simulator-multi-coins", + #[cfg(feature = "simulator-btc-only")] + "simulator-btc-only", + #[cfg(feature = "debug-multi-coins")] + "debug-multi-coins", + #[cfg(feature = "debug-btc-only")] + "debug-btc-only", ]; - + println!("cargo:warning={}", format!("features: {:?}", features)); config.parse.expand.features = Some(features.into_iter().map(|s| s.to_string()).collect()); let builder = cbindgen::Builder::new(); diff --git a/rust/rust_c/cbindgen.toml b/rust/rust_c/cbindgen.toml new file mode 100644 index 000000000..75a59cfd1 --- /dev/null +++ b/rust/rust_c/cbindgen.toml @@ -0,0 +1,15 @@ +include_guard = "_LIBRUST_C_H" + +after_includes = "#define BUILD_MULTI_COINS\n#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" + +language = "C" + +[defines] +"feature = multi-coins" = "BUILD_MULTI_COINS" + +[parse] +extra_bindings = ["rust_c"] + +[parse.expand] +crates = ["rust_c"] +default_features = false \ No newline at end of file diff --git a/rust/rust_c/librust_c.h b/rust/rust_c/librust_c.h new file mode 100644 index 000000000..ef0e43e32 --- /dev/null +++ b/rust/rust_c/librust_c.h @@ -0,0 +1,2433 @@ +#ifndef _LIBRUST_C_H +#define _LIBRUST_C_H + +#include +#include +#include +#include +#define BUILD_MULTI_COINS +#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048 +#define ADDRESS_MAX_LEN 256 +#define PATH_ITEM_MAX_LEN 32 + +typedef enum ArweaveRequestType { + ArweaveRequestTypeTransaction = 1, + ArweaveRequestTypeDataItem, + ArweaveRequestTypeMessage, + ArweaveRequestTypeUnknown, +} ArweaveRequestType; + +#if defined(BUILD_MULTI_COINS) +typedef enum ETHAccountType { +#if defined(BUILD_MULTI_COINS) + Bip44Standard, +#endif +#if defined(BUILD_MULTI_COINS) + LedgerLive, +#endif +#if defined(BUILD_MULTI_COINS) + LedgerLegacy, +#endif +} ETHAccountType; +#endif + +typedef enum ErrorCodes { + Success = 0, + InvalidMasterFingerprint, + MasterFingerprintMismatch, + InvalidHDPath, + UnsupportedTransaction, + InvalidXPub, + SignFailure, + UnexpectedError, + InvalidHex, + WebAuthFailed, + InvalidData, + CborDecodeError = 20, + CborEncodeError, + URDecodeError, + UREncodeError, + NotSupportURTypeError, + NotAnUr, + URTypeUnspecified, + URProtobufDecodeError, + URProtobufEncodeError, + URGzipDecodeError, + URGzipEnCodeError, + KeystoreSeedError = 40, + KeystoreDerivationError, + KeystoreXPubError, + KeystoreInvalidDerivationPath, + KeystoreDeivePubkey, + KeystoreGenerateSigningKeyError, + KeystoreRSASignError, + KeystoreRSAVerifyError, + KeystoreInvalidDataError, + KeystoreZcashOrchardSignError, + BitcoinInvalidInput = 100, + BitcoinInvalidOutput, + BitcoinInvalidPsbt, + BitcoinInvalidTransaction, + BitcoinNoInputs, + BitcoinNoOutputs, + BitcoinNoMyInputs, + BitcoinInputValueTampered, + BitcoinSignFailure, + BitcoinAddressError, + BitcoinGetKeyError, + BitcoinSignLegacyTxError, + BitcoinUnsupportedTransaction, + BitcoinUnsupportedNetwork, + BitcoinTransactionConsensusEncodeError, + BitcoinPushBytesFailed, + BitcoinInvalidHex, + BitcoinBase58Error, + BitcoinKeystoreError, + BitcoinInvalidParseContext, + BitcoinInvalidRawTxCryptoBytes, + BitcoinInvalidTxData, + BitcoinUnsupportedScriptType, + BitcoinBech32DecodeError, + BitcoinWitnessProgramError, + BitcoinMultiSigWalletParseError, + BitcoinMultiSigWalletNotMyWallet, + BitcoinMultiSigWalletAddressCalError, + BitcoinMultiSigWalletImportXpubError, + BitcoinMultiSigWalletCrateError, + BitcoinMultiSigWalletFormatError, + BitcoinMultiSigNetworkError, + BitcoinMultiSigInputError, + BitcoinDerivePublicKeyError, + BitcoinWalletTypeError, + EthereumRlpDecodingError = 200, + EthereumInvalidTransaction, + EthereumSignFailure, + EthereumInvalidHDPath, + EthereumKeystoreError, + EthereumInvalidAddressError, + EthereumInvalidUtf8Error, + EthereumInvalidContractABI, + EthereumDecodeContractDataError, + EthereumInvalidTypedData, + EthereumHashTypedDataError, + TronInvalidRawTxCryptoBytes = 300, + TronInvalidParseContext, + TronBase58Error, + TronSignFailure, + TronProtobufError, + TronParseNumberError, + TronNoMyInputs, + CompanionAppProtobufError = 400, + CompanionAppInvalidParseContext, + CompanionAppSignTxFailed, + CompanionAppCheckTxFailed, + CardanoInvalidTransaction = 500, + CardanoAddressEncodingError, + SolanaAddressEncodingError = 600, + SolanaKeystoreError, + SolanaUnsupportedProgram, + SolanaInvalidData, + SolanaAccountNotFound, + SolanaProgramError, + SolanaParseTxError, + NearKeystoreError = 700, + NearSignFailure, + NearParseTxError, + XRPSignFailure = 800, + XRPInvalidData, + XRPParseTxError, + CosmosSignFailure = 900, + CosmosKeystoreError, + CosmosInvalidData, + CosmosParseTxError, + AptosSignFailure = 1000, + AptosKeystoreError, + AptosInvalidData, + AptosParseTxError, + SuiSignFailure = 1100, + SuiInvalidData, + SuiParseTxError, + ArweaveSignFailure = 1200, + ArweaveKeystoreError, + ArweaveInvalidData, + ArweaveParseTxError, + ArweaveParseAOTxError, + TonUnknownError = 1300, + TonMnemonicError, + TonTransactionError, + InvalidProof, + TonTransactionJsonError, + AddressError, + StellarAddressError = 1400, + StellarInvalidData, + StellarParseTxError, + StellarKeystoreError, + ZcashGenerateAddressError = 1500, + ZcashSigningError, + ZcashInvalidPczt, +} ErrorCodes; + +typedef enum NetworkType { + MainNet, + TestNet, +} NetworkType; + +typedef enum QRCodeType { + CryptoPSBT, + CryptoMultiAccounts, + CryptoAccount, + Bytes, + BtcSignRequest, + SeedSignerMessage, +#if defined(BUILD_MULTI_COINS) + KeystoneSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + EthSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + SolSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + NearSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoSignTxHashRequest, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoSignDataRequest, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoCatalystVotingRegistrationRequest, +#endif +#if defined(BUILD_MULTI_COINS) + CosmosSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + EvmSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + SuiSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + SuiSignHashRequest, +#endif +#if defined(BUILD_MULTI_COINS) + AptosSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + QRHardwareCall, +#endif +#if defined(BUILD_MULTI_COINS) + ArweaveSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + StellarSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + TonSignRequest, +#endif +#if defined(BUILD_MULTI_COINS) + ZcashPczt, +#endif + URTypeUnKnown, +} QRCodeType; + +typedef enum QRProtocol { + QRCodeTypeText, + QRCodeTypeUR, +} QRProtocol; + +typedef enum ViewType { + BtcNativeSegwitTx, + BtcSegwitTx, + BtcLegacyTx, + BtcTx, + BtcMsg, +#if defined(BUILD_MULTI_COINS) + LtcTx, +#endif +#if defined(BUILD_MULTI_COINS) + DashTx, +#endif +#if defined(BUILD_MULTI_COINS) + BchTx, +#endif +#if defined(BUILD_MULTI_COINS) + EthTx, +#endif +#if defined(BUILD_MULTI_COINS) + EthPersonalMessage, +#endif +#if defined(BUILD_MULTI_COINS) + EthTypedData, +#endif +#if defined(BUILD_MULTI_COINS) + TronTx, +#endif +#if defined(BUILD_MULTI_COINS) + SolanaTx, +#endif +#if defined(BUILD_MULTI_COINS) + SolanaMessage, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoTx, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoSignData, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoCatalystVotingRegistration, +#endif +#if defined(BUILD_MULTI_COINS) + CardanoSignTxHash, +#endif +#if defined(BUILD_MULTI_COINS) + NearTx, +#endif +#if defined(BUILD_MULTI_COINS) + XRPTx, +#endif +#if defined(BUILD_MULTI_COINS) + CosmosTx, +#endif +#if defined(BUILD_MULTI_COINS) + CosmosEvmTx, +#endif +#if defined(BUILD_MULTI_COINS) + SuiTx, +#endif +#if defined(BUILD_MULTI_COINS) + SuiSignMessageHash, +#endif +#if defined(BUILD_MULTI_COINS) + ArweaveTx, +#endif +#if defined(BUILD_MULTI_COINS) + ArweaveMessage, +#endif +#if defined(BUILD_MULTI_COINS) + ArweaveDataItem, +#endif +#if defined(BUILD_MULTI_COINS) + StellarTx, +#endif +#if defined(BUILD_MULTI_COINS) + StellarHash, +#endif +#if defined(BUILD_MULTI_COINS) + TonTx, +#endif +#if defined(BUILD_MULTI_COINS) + TonSignProof, +#endif +#if defined(BUILD_MULTI_COINS) + ZcashTx, +#endif +#if defined(BUILD_MULTI_COINS) + AptosTx, +#endif + WebAuthResult, +#if defined(BUILD_MULTI_COINS) + KeyDerivationRequest, +#endif + ViewTypeUnKnown, +} ViewType; + +typedef char *PtrString; + +typedef struct SimpleResponse_u8 { + uint8_t *data; + uint32_t error_code; + PtrString error_message; +} SimpleResponse_u8; + +typedef uint8_t *PtrBytes; + +typedef struct SimpleResponse_c_char { + char *data; + uint32_t error_code; + PtrString error_message; +} SimpleResponse_c_char; + +typedef struct TransactionCheckResult { + uint32_t error_code; + PtrString error_message; +} TransactionCheckResult; + +typedef struct TransactionCheckResult *Ptr_TransactionCheckResult; + +typedef void *PtrVoid; + +typedef PtrVoid PtrUR; + +typedef PtrVoid PtrDecoder; + +typedef struct URParseResult { + bool is_multi_part; + uint32_t progress; + enum ViewType t; + enum QRCodeType ur_type; + PtrUR data; + PtrDecoder decoder; + uint32_t error_code; + PtrString error_message; +} URParseResult; + +typedef struct URParseResult *PtrT_URParseResult; + +typedef struct URParseMultiResult { + bool is_complete; + enum ViewType t; + enum QRCodeType ur_type; + uint32_t progress; + PtrUR data; + uint32_t error_code; + PtrString error_message; +} URParseMultiResult; + +typedef struct URParseMultiResult *PtrT_URParseMultiResult; + +typedef PtrVoid PtrEncoder; + +typedef struct UREncodeResult { + bool is_multi_part; + char *data; + PtrEncoder encoder; + uint32_t error_code; + char *error_message; +} UREncodeResult; + +typedef struct UREncodeResult *PtrT_UREncodeResult; + +typedef struct UREncodeMultiResult { + char *data; + uint32_t error_code; + char *error_message; +} UREncodeMultiResult; + +typedef struct UREncodeMultiResult *PtrT_UREncodeMultiResult; + +typedef struct SimpleResponse_u8 *PtrT_SimpleResponse_u8; + +typedef struct SimpleResponse_c_char *PtrT_SimpleResponse_c_char; + +typedef uint8_t *PtrT_u8; + +typedef struct VecFFI_u8 { + PtrT_u8 data; + size_t size; + size_t cap; +} VecFFI_u8; + +typedef struct VecFFI_u8 *PtrT_VecFFI_u8; + +typedef struct URParseResult *Ptr_URParseResult; + +typedef struct TransactionCheckResult *PtrT_TransactionCheckResult; + +typedef const void *ConstPtrVoid; + +typedef ConstPtrVoid ConstPtrUR; + +typedef struct ExtendedPublicKey { + PtrString path; + PtrString xpub; +} ExtendedPublicKey; + +typedef struct ExtendedPublicKey *PtrT_ExtendedPublicKey; + +typedef struct CSliceFFI_ExtendedPublicKey { + PtrT_ExtendedPublicKey data; + size_t size; +} CSliceFFI_ExtendedPublicKey; + +typedef struct CSliceFFI_ExtendedPublicKey *PtrT_CSliceFFI_ExtendedPublicKey; + +typedef struct AccountConfig { + PtrString hd_path; + PtrString x_pub; + int32_t address_length; + bool is_multi_sign; +} AccountConfig; + +typedef struct CoinConfig { + bool is_active; + PtrString coin_code; + struct AccountConfig *accounts; + uint32_t accounts_length; +} CoinConfig; + +typedef struct CoinConfig *PtrT_CoinConfig; + +typedef struct UREncodeResult *Ptr_UREncodeResult; + +typedef struct CSliceFFI_ExtendedPublicKey *Ptr_CSliceFFI_ExtendedPublicKey; + +#if defined(BUILD_MULTI_COINS) +typedef struct KeyDerivationSchema { + PtrString key_path; + PtrString curve; + PtrString algo; + PtrString chain_type; + bool is_ada; +} KeyDerivationSchema; +#endif + +typedef struct KeyDerivationSchema *PtrT_KeyDerivationSchema; + +typedef struct VecFFI_KeyDerivationSchema { + PtrT_KeyDerivationSchema data; + size_t size; + size_t cap; +} VecFFI_KeyDerivationSchema; + +typedef struct VecFFI_KeyDerivationSchema *Ptr_VecFFI_KeyDerivationSchema; + +#if defined(BUILD_MULTI_COINS) +typedef struct KeyDerivationRequestData { + Ptr_VecFFI_KeyDerivationSchema schemas; +} KeyDerivationRequestData; +#endif + +typedef struct KeyDerivationRequestData *Ptr_KeyDerivationRequestData; + +#if defined(BUILD_MULTI_COINS) +typedef struct QRHardwareCallData { + PtrString call_type; + PtrString origin; + Ptr_KeyDerivationRequestData key_derivation; + PtrString version; +} QRHardwareCallData; +#endif + +typedef struct Response_QRHardwareCallData { + struct QRHardwareCallData *data; + uint32_t error_code; + PtrString error_message; +} Response_QRHardwareCallData; + +typedef struct Response_QRHardwareCallData *Ptr_Response_QRHardwareCallData; + +typedef struct Response_bool { + bool *data; + uint32_t error_code; + PtrString error_message; +} Response_bool; + +#if defined(BUILD_MULTI_COINS) +typedef struct KeplrAccount { + PtrString name; + PtrString path; + PtrString xpub; +} KeplrAccount; +#endif + +typedef struct KeplrAccount *PtrT_KeplrAccount; + +typedef struct CSliceFFI_KeplrAccount { + PtrT_KeplrAccount data; + size_t size; +} CSliceFFI_KeplrAccount; + +typedef struct CSliceFFI_KeplrAccount *PtrT_CSliceFFI_KeplrAccount; + +typedef struct Response_QRHardwareCallData *PtrT_Response_QRHardwareCallData; + +typedef struct ZcashKey { + PtrString key_text; + PtrString key_name; + uint32_t index; +} ZcashKey; + +typedef struct ZcashKey *PtrT_ZcashKey; + +typedef struct CSliceFFI_ZcashKey { + PtrT_ZcashKey data; + size_t size; +} CSliceFFI_ZcashKey; + +typedef struct CSliceFFI_ZcashKey *Ptr_CSliceFFI_ZcashKey; + +typedef struct DisplayAptosTx { + PtrString detail; + bool is_msg; +} DisplayAptosTx; + +typedef struct TransactionParseResult_DisplayAptosTx { + struct DisplayAptosTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayAptosTx; + +typedef struct TransactionParseResult_DisplayAptosTx *PtrT_TransactionParseResult_DisplayAptosTx; + +typedef struct SimpleResponse_ArweaveRequestType { + enum ArweaveRequestType *data; + uint32_t error_code; + PtrString error_message; +} SimpleResponse_ArweaveRequestType; + +typedef struct DisplayArweaveMessage { + PtrString message; + PtrString raw_message; +} DisplayArweaveMessage; + +typedef struct TransactionParseResult_DisplayArweaveMessage { + struct DisplayArweaveMessage *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayArweaveMessage; + +typedef struct TransactionParseResult_DisplayArweaveMessage *PtrT_TransactionParseResult_DisplayArweaveMessage; + +typedef struct DisplayArweaveTx { + PtrString value; + PtrString fee; + PtrString from; + PtrString to; + PtrString detail; +} DisplayArweaveTx; + +typedef struct TransactionParseResult_DisplayArweaveTx { + struct DisplayArweaveTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayArweaveTx; + +typedef struct TransactionParseResult_DisplayArweaveTx *PtrT_TransactionParseResult_DisplayArweaveTx; + +typedef struct DisplayTag { + PtrString name; + PtrString value; +} DisplayTag; + +typedef struct DisplayTag *PtrT_DisplayTag; + +typedef struct VecFFI_DisplayTag { + PtrT_DisplayTag data; + size_t size; + size_t cap; +} VecFFI_DisplayTag; + +typedef struct VecFFI_DisplayTag *Ptr_VecFFI_DisplayTag; + +typedef struct DisplayArweaveDataItem { + PtrString owner; + PtrString target; + PtrString anchor; + Ptr_VecFFI_DisplayTag tags; + PtrString data; +} DisplayArweaveDataItem; + +typedef struct TransactionParseResult_DisplayArweaveDataItem { + struct DisplayArweaveDataItem *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayArweaveDataItem; + +typedef struct TransactionParseResult_DisplayArweaveDataItem *PtrT_TransactionParseResult_DisplayArweaveDataItem; + +typedef struct DisplayArweaveAOTransfer { + PtrString from; + PtrString to; + PtrString quantity; + PtrString token_id; + Ptr_VecFFI_DisplayTag other_info; +} DisplayArweaveAOTransfer; + +typedef struct TransactionParseResult_DisplayArweaveAOTransfer { + struct DisplayArweaveAOTransfer *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayArweaveAOTransfer; + +typedef struct TransactionParseResult_DisplayArweaveAOTransfer *PtrT_TransactionParseResult_DisplayArweaveAOTransfer; + +typedef struct DisplayTxOverviewInput { + PtrString address; +} DisplayTxOverviewInput; + +typedef struct DisplayTxOverviewInput *PtrT_DisplayTxOverviewInput; + +typedef struct VecFFI_DisplayTxOverviewInput { + PtrT_DisplayTxOverviewInput data; + size_t size; + size_t cap; +} VecFFI_DisplayTxOverviewInput; + +typedef struct VecFFI_DisplayTxOverviewInput *PtrT_VecFFI_DisplayTxOverviewInput; + +typedef struct DisplayTxOverviewOutput { + PtrString address; +} DisplayTxOverviewOutput; + +typedef struct DisplayTxOverviewOutput *PtrT_DisplayTxOverviewOutput; + +typedef struct VecFFI_DisplayTxOverviewOutput { + PtrT_DisplayTxOverviewOutput data; + size_t size; + size_t cap; +} VecFFI_DisplayTxOverviewOutput; + +typedef struct VecFFI_DisplayTxOverviewOutput *PtrT_VecFFI_DisplayTxOverviewOutput; + +typedef struct DisplayTxOverview { + PtrString total_output_amount; + PtrString fee_amount; + PtrString total_output_sat; + PtrString fee_sat; + PtrT_VecFFI_DisplayTxOverviewInput from; + PtrT_VecFFI_DisplayTxOverviewOutput to; + PtrString network; + bool is_multisig; + bool fee_larger_than_amount; + PtrString sign_status; + bool need_sign; +} DisplayTxOverview; + +typedef struct DisplayTxDetailInput { + bool has_address; + PtrString address; + PtrString amount; + bool is_mine; + PtrString path; + bool is_external; +} DisplayTxDetailInput; + +typedef struct DisplayTxDetailInput *PtrT_DisplayTxDetailInput; + +typedef struct VecFFI_DisplayTxDetailInput { + PtrT_DisplayTxDetailInput data; + size_t size; + size_t cap; +} VecFFI_DisplayTxDetailInput; + +typedef struct VecFFI_DisplayTxDetailInput *PtrT_VecFFI_DisplayTxDetailInput; + +typedef struct DisplayTxDetailOutput { + PtrString address; + PtrString amount; + bool is_mine; + PtrString path; + bool is_external; +} DisplayTxDetailOutput; + +typedef struct DisplayTxDetailOutput *PtrT_DisplayTxDetailOutput; + +typedef struct VecFFI_DisplayTxDetailOutput { + PtrT_DisplayTxDetailOutput data; + size_t size; + size_t cap; +} VecFFI_DisplayTxDetailOutput; + +typedef struct VecFFI_DisplayTxDetailOutput *PtrT_VecFFI_DisplayTxDetailOutput; + +typedef struct DisplayTxDetail { + PtrString total_input_amount; + PtrString total_output_amount; + PtrString fee_amount; + PtrT_VecFFI_DisplayTxDetailInput from; + PtrT_VecFFI_DisplayTxDetailOutput to; + PtrString network; + PtrString total_input_sat; + PtrString total_output_sat; + PtrString fee_sat; + PtrString sign_status; +} DisplayTxDetail; + +typedef struct DisplayTx { + struct DisplayTxOverview *overview; + struct DisplayTxDetail *detail; +} DisplayTx; + +typedef struct TransactionParseResult_DisplayTx { + struct DisplayTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayTx; + +typedef struct DisplayBtcMsg { + PtrString detail; + PtrString address; +} DisplayBtcMsg; + +typedef struct TransactionParseResult_DisplayBtcMsg { + struct DisplayBtcMsg *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayBtcMsg; + +typedef struct TransactionParseResult_DisplayBtcMsg *Ptr_TransactionParseResult_DisplayBtcMsg; + +typedef PtrString *PtrT_PtrString; + +typedef struct VecFFI_PtrString { + PtrT_PtrString data; + size_t size; + size_t cap; +} VecFFI_PtrString; + +typedef struct VecFFI_PtrString *PtrT_VecFFI_PtrString; + +typedef struct MultiSigXPubItem { + PtrString xfp; + PtrString xpub; +} MultiSigXPubItem; + +typedef struct MultiSigXPubItem *PtrT_MultiSigXPubItem; + +typedef struct VecFFI_MultiSigXPubItem { + PtrT_MultiSigXPubItem data; + size_t size; + size_t cap; +} VecFFI_MultiSigXPubItem; + +typedef struct VecFFI_MultiSigXPubItem *PtrT_VecFFI_MultiSigXPubItem; + +typedef struct MultiSigWallet { + PtrString creator; + PtrString name; + PtrString policy; + uint32_t threshold; + uint32_t total; + PtrT_VecFFI_PtrString derivations; + PtrString format; + PtrT_VecFFI_MultiSigXPubItem xpub_items; + PtrString verify_code; + PtrString config_text; + uint32_t network; +} MultiSigWallet; + +typedef struct MultiSigWallet *PtrT_MultiSigWallet; + +typedef struct Response_MultiSigWallet { + struct MultiSigWallet *data; + uint32_t error_code; + PtrString error_message; +} Response_MultiSigWallet; + +typedef struct Response_MultiSigWallet *Ptr_Response_MultiSigWallet; + +typedef struct SimpleResponse_c_char *Ptr_SimpleResponse_c_char; + +typedef struct MultiSigXPubInfoItem { + PtrString path; + PtrString xfp; + PtrString xpub; +} MultiSigXPubInfoItem; + +typedef struct MultiSigXPubInfoItem *PtrT_MultiSigXPubInfoItem; + +typedef struct MultisigSignResult { + Ptr_UREncodeResult ur_result; + PtrString sign_status; + bool is_completed; + PtrBytes psbt_hex; + uint32_t psbt_len; +} MultisigSignResult; + +typedef struct MultisigSignResult *PtrT_MultisigSignResult; + +typedef struct PsbtSignResult { + PtrString base_str; + PtrString hex_str; + PtrT_UREncodeResult ur_result; +} PsbtSignResult; + +typedef struct Response_PsbtSignResult { + struct PsbtSignResult *data; + uint32_t error_code; + PtrString error_message; +} Response_PsbtSignResult; + +typedef struct Response_PsbtSignResult *PtrT_Response_PsbtSignResult; + +typedef struct TransactionParseResult_DisplayTx *PtrT_TransactionParseResult_DisplayTx; + +typedef struct TransactionParseResult_DisplayBtcMsg *PtrT_TransactionParseResult_DisplayBtcMsg; + +typedef struct VecFFI_PtrString *Ptr_VecFFI_PtrString; + +typedef struct DisplayCardanoSignTxHash { + PtrString network; + Ptr_VecFFI_PtrString path; + PtrString tx_hash; + Ptr_VecFFI_PtrString address_list; +} DisplayCardanoSignTxHash; + +typedef struct TransactionParseResult_DisplayCardanoSignTxHash { + struct DisplayCardanoSignTxHash *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayCardanoSignTxHash; + +typedef struct TransactionParseResult_DisplayCardanoSignTxHash *PtrT_TransactionParseResult_DisplayCardanoSignTxHash; + +typedef struct DisplayCardanoSignData { + PtrString payload; + PtrString derivation_path; + PtrString message_hash; + PtrString xpub; +} DisplayCardanoSignData; + +typedef struct TransactionParseResult_DisplayCardanoSignData { + struct DisplayCardanoSignData *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayCardanoSignData; + +typedef struct TransactionParseResult_DisplayCardanoSignData *PtrT_TransactionParseResult_DisplayCardanoSignData; + +typedef struct DisplayCardanoCatalyst { + PtrString nonce; + PtrString stake_key; + PtrString rewards; + Ptr_VecFFI_PtrString vote_keys; +} DisplayCardanoCatalyst; + +typedef struct TransactionParseResult_DisplayCardanoCatalyst { + struct DisplayCardanoCatalyst *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayCardanoCatalyst; + +typedef struct TransactionParseResult_DisplayCardanoCatalyst *PtrT_TransactionParseResult_DisplayCardanoCatalyst; + +typedef struct DisplayCardanoFrom { + PtrString address; + PtrString amount; + bool has_path; + PtrString path; +} DisplayCardanoFrom; + +typedef struct DisplayCardanoFrom *PtrT_DisplayCardanoFrom; + +typedef struct VecFFI_DisplayCardanoFrom { + PtrT_DisplayCardanoFrom data; + size_t size; + size_t cap; +} VecFFI_DisplayCardanoFrom; + +typedef struct VecFFI_DisplayCardanoFrom *PtrT_VecFFI_DisplayCardanoFrom; + +typedef struct DisplayCardanoTo { + PtrString address; + PtrString amount; + bool has_assets; + PtrString assets_text; +} DisplayCardanoTo; + +typedef struct DisplayCardanoTo *PtrT_DisplayCardanoTo; + +typedef struct VecFFI_DisplayCardanoTo { + PtrT_DisplayCardanoTo data; + size_t size; + size_t cap; +} VecFFI_DisplayCardanoTo; + +typedef struct VecFFI_DisplayCardanoTo *PtrT_VecFFI_DisplayCardanoTo; + +typedef struct DisplayCertField { + PtrString label; + PtrString value; +} DisplayCertField; + +typedef struct DisplayCertField *PtrT_DisplayCertField; + +typedef struct VecFFI_DisplayCertField { + PtrT_DisplayCertField data; + size_t size; + size_t cap; +} VecFFI_DisplayCertField; + +typedef struct VecFFI_DisplayCertField *Ptr_VecFFI_DisplayCertField; + +typedef struct DisplayCardanoCertificate { + PtrString cert_type; + Ptr_VecFFI_DisplayCertField fields; +} DisplayCardanoCertificate; + +typedef struct DisplayCardanoCertificate *PtrT_DisplayCardanoCertificate; + +typedef struct VecFFI_DisplayCardanoCertificate { + PtrT_DisplayCardanoCertificate data; + size_t size; + size_t cap; +} VecFFI_DisplayCardanoCertificate; + +typedef struct VecFFI_DisplayCardanoCertificate *Ptr_VecFFI_DisplayCardanoCertificate; + +typedef struct DisplayCardanoWithdrawal { + PtrString address; + PtrString amount; +} DisplayCardanoWithdrawal; + +typedef struct DisplayCardanoWithdrawal *PtrT_DisplayCardanoWithdrawal; + +typedef struct VecFFI_DisplayCardanoWithdrawal { + PtrT_DisplayCardanoWithdrawal data; + size_t size; + size_t cap; +} VecFFI_DisplayCardanoWithdrawal; + +typedef struct VecFFI_DisplayCardanoWithdrawal *Ptr_VecFFI_DisplayCardanoWithdrawal; + +typedef struct DisplayVotingProcedure { + PtrString voter; + PtrString transaction_id; + PtrString index; + PtrString vote; +} DisplayVotingProcedure; + +typedef struct DisplayVotingProcedure *PtrT_DisplayVotingProcedure; + +typedef struct VecFFI_DisplayVotingProcedure { + PtrT_DisplayVotingProcedure data; + size_t size; + size_t cap; +} VecFFI_DisplayVotingProcedure; + +typedef struct VecFFI_DisplayVotingProcedure *Ptr_VecFFI_DisplayVotingProcedure; + +typedef struct DisplayVotingProposal { + PtrString anchor; +} DisplayVotingProposal; + +typedef struct DisplayVotingProposal *PtrT_DisplayVotingProposal; + +typedef struct VecFFI_DisplayVotingProposal { + PtrT_DisplayVotingProposal data; + size_t size; + size_t cap; +} VecFFI_DisplayVotingProposal; + +typedef struct VecFFI_DisplayVotingProposal *Ptr_VecFFI_DisplayVotingProposal; + +typedef struct DisplayCardanoTx { + PtrT_VecFFI_DisplayCardanoFrom from; + PtrT_VecFFI_DisplayCardanoTo to; + PtrString fee; + PtrString network; + PtrString total_input; + PtrString total_output; + Ptr_VecFFI_DisplayCardanoCertificate certificates; + Ptr_VecFFI_DisplayCardanoWithdrawal withdrawals; + PtrString auxiliary_data; + Ptr_VecFFI_DisplayVotingProcedure voting_procedures; + Ptr_VecFFI_DisplayVotingProposal voting_proposals; +} DisplayCardanoTx; + +typedef struct TransactionParseResult_DisplayCardanoTx { + struct DisplayCardanoTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayCardanoTx; + +typedef struct TransactionParseResult_DisplayCardanoTx *PtrT_TransactionParseResult_DisplayCardanoTx; + +typedef struct DisplayCosmosTxOverview { + PtrString display_type; + PtrString method; + PtrString network; + PtrString send_value; + PtrString send_from; + PtrString send_to; + PtrString delegate_value; + PtrString delegate_from; + PtrString delegate_to; + PtrString undelegate_value; + PtrString undelegate_to; + PtrString undelegate_validator; + PtrString redelegate_value; + PtrString redelegate_to; + PtrString redelegate_new_validator; + PtrString withdraw_reward_to; + PtrString withdraw_reward_validator; + PtrString transfer_from; + PtrString transfer_to; + PtrString transfer_value; + PtrString vote_voted; + PtrString vote_proposal; + PtrString vote_voter; + PtrString overview_list; +} DisplayCosmosTxOverview; + +typedef struct DisplayCosmosTxOverview *PtrT_DisplayCosmosTxOverview; + +typedef struct DisplayCosmosTx { + PtrT_DisplayCosmosTxOverview overview; + PtrString detail; +} DisplayCosmosTx; + +typedef struct TransactionParseResult_DisplayCosmosTx { + struct DisplayCosmosTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayCosmosTx; + +typedef struct TransactionParseResult_DisplayCosmosTx *PtrT_TransactionParseResult_DisplayCosmosTx; + +typedef struct DisplayETHOverview { + PtrString value; + PtrString max_txn_fee; + PtrString gas_price; + PtrString gas_limit; + PtrString from; + PtrString to; +} DisplayETHOverview; + +typedef struct DisplayETHOverview *PtrT_DisplayETHOverview; + +typedef struct DisplayETHDetail { + PtrString value; + PtrString max_txn_fee; + PtrString max_fee; + PtrString max_priority; + PtrString max_fee_price; + PtrString max_priority_price; + PtrString gas_price; + PtrString gas_limit; + PtrString from; + PtrString to; + PtrString input; +} DisplayETHDetail; + +typedef struct DisplayETHDetail *PtrT_DisplayETHDetail; + +typedef struct DisplayETH { + PtrString tx_type; + uint64_t chain_id; + PtrT_DisplayETHOverview overview; + PtrT_DisplayETHDetail detail; +} DisplayETH; + +typedef struct TransactionParseResult_DisplayETH { + struct DisplayETH *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayETH; + +typedef struct TransactionParseResult_DisplayETH *PtrT_TransactionParseResult_DisplayETH; + +typedef struct DisplayETHPersonalMessage { + PtrString raw_message; + PtrString utf8_message; + PtrString from; +} DisplayETHPersonalMessage; + +typedef struct TransactionParseResult_DisplayETHPersonalMessage { + struct DisplayETHPersonalMessage *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayETHPersonalMessage; + +typedef struct TransactionParseResult_DisplayETHPersonalMessage *PtrT_TransactionParseResult_DisplayETHPersonalMessage; + +typedef struct DisplayETHTypedData { + PtrString name; + PtrString version; + PtrString chain_id; + PtrString verifying_contract; + PtrString salt; + PtrString primary_type; + PtrString message; + PtrString from; +} DisplayETHTypedData; + +typedef struct TransactionParseResult_DisplayETHTypedData { + struct DisplayETHTypedData *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayETHTypedData; + +typedef struct TransactionParseResult_DisplayETHTypedData *PtrT_TransactionParseResult_DisplayETHTypedData; + +typedef struct EthParsedErc20Transaction { + PtrString to; + PtrString value; +} EthParsedErc20Transaction; + +typedef struct TransactionParseResult_EthParsedErc20Transaction { + struct EthParsedErc20Transaction *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_EthParsedErc20Transaction; + +typedef struct TransactionParseResult_EthParsedErc20Transaction *PtrT_TransactionParseResult_EthParsedErc20Transaction; + +typedef struct DisplayContractParam { + PtrString name; + PtrString value; +} DisplayContractParam; + +typedef struct DisplayContractParam *PtrT_DisplayContractParam; + +typedef struct VecFFI_DisplayContractParam { + PtrT_DisplayContractParam data; + size_t size; + size_t cap; +} VecFFI_DisplayContractParam; + +typedef struct VecFFI_DisplayContractParam *PtrT_VecFFI_DisplayContractParam; + +typedef struct DisplayContractData { + PtrString contract_name; + PtrString method_name; + PtrT_VecFFI_DisplayContractParam params; +} DisplayContractData; + +typedef struct Response_DisplayContractData { + struct DisplayContractData *data; + uint32_t error_code; + PtrString error_message; +} Response_DisplayContractData; + +typedef struct Response_DisplayContractData *Ptr_Response_DisplayContractData; + +typedef struct Response_DisplayContractData *PtrT_Response_DisplayContractData; + +typedef struct DisplayNearTxOverviewGeneralAction { + PtrString action; +} DisplayNearTxOverviewGeneralAction; + +typedef struct DisplayNearTxOverviewGeneralAction *PtrT_DisplayNearTxOverviewGeneralAction; + +typedef struct VecFFI_DisplayNearTxOverviewGeneralAction { + PtrT_DisplayNearTxOverviewGeneralAction data; + size_t size; + size_t cap; +} VecFFI_DisplayNearTxOverviewGeneralAction; + +typedef struct VecFFI_DisplayNearTxOverviewGeneralAction *PtrT_VecFFI_DisplayNearTxOverviewGeneralAction; + +typedef struct DisplayNearTxOverview { + PtrString display_type; + PtrString main_action; + PtrString transfer_value; + PtrString transfer_from; + PtrString transfer_to; + PtrT_VecFFI_DisplayNearTxOverviewGeneralAction action_list; +} DisplayNearTxOverview; + +typedef struct DisplayNearTxOverview *PtrT_DisplayNearTxOverview; + +typedef struct DisplayNearTx { + PtrString network; + PtrT_DisplayNearTxOverview overview; + PtrString detail; +} DisplayNearTx; + +typedef struct TransactionParseResult_DisplayNearTx { + struct DisplayNearTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayNearTx; + +typedef struct TransactionParseResult_DisplayNearTx *PtrT_TransactionParseResult_DisplayNearTx; + +typedef struct DisplaySolanaTxOverviewVotesOn { + PtrString slot; +} DisplaySolanaTxOverviewVotesOn; + +typedef struct DisplaySolanaTxOverviewVotesOn *PtrT_DisplaySolanaTxOverviewVotesOn; + +typedef struct VecFFI_DisplaySolanaTxOverviewVotesOn { + PtrT_DisplaySolanaTxOverviewVotesOn data; + size_t size; + size_t cap; +} VecFFI_DisplaySolanaTxOverviewVotesOn; + +typedef struct VecFFI_DisplaySolanaTxOverviewVotesOn *PtrT_VecFFI_DisplaySolanaTxOverviewVotesOn; + +typedef struct DisplaySolanaTxOverviewGeneral { + PtrString program; + PtrString method; +} DisplaySolanaTxOverviewGeneral; + +typedef struct DisplaySolanaTxOverviewGeneral *PtrT_DisplaySolanaTxOverviewGeneral; + +typedef struct VecFFI_DisplaySolanaTxOverviewGeneral { + PtrT_DisplaySolanaTxOverviewGeneral data; + size_t size; + size_t cap; +} VecFFI_DisplaySolanaTxOverviewGeneral; + +typedef struct VecFFI_DisplaySolanaTxOverviewGeneral *PtrT_VecFFI_DisplaySolanaTxOverviewGeneral; + +typedef struct Instruction { + PtrT_VecFFI_PtrString accounts; + PtrString data; + PtrString program_address; +} Instruction; + +typedef struct Instruction *PtrT_Instruction; + +typedef struct VecFFI_Instruction { + PtrT_Instruction data; + size_t size; + size_t cap; +} VecFFI_Instruction; + +typedef struct VecFFI_Instruction *PtrT_VecFFI_Instruction; + +typedef struct DisplaySolanaTxOverviewUnknownInstructions { + PtrT_VecFFI_PtrString overview_accounts; + PtrT_VecFFI_Instruction overview_instructions; +} DisplaySolanaTxOverviewUnknownInstructions; + +typedef struct DisplaySolanaTxOverviewUnknownInstructions *PtrT_DisplaySolanaTxOverviewUnknownInstructions; + +typedef struct ProgramOverviewTransfer { + PtrString value; + PtrString main_action; + PtrString from; + PtrString to; +} ProgramOverviewTransfer; + +typedef struct ProgramOverviewTransfer *PtrT_ProgramOverviewTransfer; + +typedef struct VecFFI_ProgramOverviewTransfer { + PtrT_ProgramOverviewTransfer data; + size_t size; + size_t cap; +} VecFFI_ProgramOverviewTransfer; + +typedef struct VecFFI_ProgramOverviewTransfer *PtrT_VecFFI_ProgramOverviewTransfer; + +typedef struct DisplaySolanaTxOverviewSquadsV4MultisigCreate { + PtrString wallet_name; + PtrString wallet_desc; + uint16_t threshold; + uintptr_t member_count; + PtrT_VecFFI_PtrString members; + PtrString total_value; + PtrT_VecFFI_ProgramOverviewTransfer transfers; +} DisplaySolanaTxOverviewSquadsV4MultisigCreate; + +typedef struct DisplaySolanaTxOverviewSquadsV4MultisigCreate *PtrT_DisplaySolanaTxOverviewSquadsV4MultisigCreate; + +typedef struct DisplaySolanaTxProposalOverview { + PtrString program; + PtrString method; + PtrString memo; + PtrString data; +} DisplaySolanaTxProposalOverview; + +typedef struct DisplaySolanaTxProposalOverview *PtrT_DisplaySolanaTxProposalOverview; + +typedef struct VecFFI_DisplaySolanaTxProposalOverview { + PtrT_DisplaySolanaTxProposalOverview data; + size_t size; + size_t cap; +} VecFFI_DisplaySolanaTxProposalOverview; + +typedef struct VecFFI_DisplaySolanaTxProposalOverview *PtrT_VecFFI_DisplaySolanaTxProposalOverview; + +typedef struct DisplaySolanaTxSplTokenTransferOverview { + PtrString source; + PtrString destination; + PtrString authority; + uint8_t decimals; + PtrString amount; + PtrString token_mint_account; + PtrString token_symbol; + PtrString token_name; +} DisplaySolanaTxSplTokenTransferOverview; + +typedef struct DisplaySolanaTxSplTokenTransferOverview *PtrT_DisplaySolanaTxSplTokenTransferOverview; + +typedef struct JupiterV6SwapTokenInfoOverview { + PtrString token_name; + PtrString token_symbol; + PtrString token_address; + PtrString token_amount; + bool exist_in_address_lookup_table; +} JupiterV6SwapTokenInfoOverview; + +typedef struct JupiterV6SwapTokenInfoOverview *PtrT_JupiterV6SwapTokenInfoOverview; + +typedef struct DisplaySolanaTxOverviewJupiterV6Swap { + PtrString program_name; + PtrString program_address; + PtrString instruction_name; + PtrT_JupiterV6SwapTokenInfoOverview token_a_overview; + PtrT_JupiterV6SwapTokenInfoOverview token_b_overview; + PtrString slippage_bps; + PtrString platform_fee_bps; +} DisplaySolanaTxOverviewJupiterV6Swap; + +typedef struct DisplaySolanaTxOverviewJupiterV6Swap *PtrT_DisplaySolanaTxOverviewJupiterV6Swap; + +typedef struct DisplaySolanaTxOverview { + PtrString display_type; + PtrString main_action; + PtrString transfer_value; + PtrString transfer_from; + PtrString transfer_to; + PtrT_VecFFI_DisplaySolanaTxOverviewVotesOn votes_on; + PtrString vote_account; + PtrT_VecFFI_DisplaySolanaTxOverviewGeneral general; + PtrT_DisplaySolanaTxOverviewUnknownInstructions unknown_instructions; + PtrT_DisplaySolanaTxOverviewSquadsV4MultisigCreate squads_multisig_create; + PtrT_VecFFI_DisplaySolanaTxProposalOverview squads_proposal; + PtrT_DisplaySolanaTxSplTokenTransferOverview spl_token_transfer; + PtrT_DisplaySolanaTxOverviewJupiterV6Swap jupiter_v6_swap; +} DisplaySolanaTxOverview; + +typedef struct DisplaySolanaTxOverview *PtrT_DisplaySolanaTxOverview; + +typedef struct DisplaySolanaTx { + PtrString network; + PtrT_DisplaySolanaTxOverview overview; + PtrString detail; +} DisplaySolanaTx; + +typedef struct TransactionParseResult_DisplaySolanaTx { + struct DisplaySolanaTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplaySolanaTx; + +typedef struct TransactionParseResult_DisplaySolanaTx *PtrT_TransactionParseResult_DisplaySolanaTx; + +typedef struct DisplaySolanaMessage { + PtrString raw_message; + PtrString utf8_message; + PtrString from; +} DisplaySolanaMessage; + +typedef struct TransactionParseResult_DisplaySolanaMessage { + struct DisplaySolanaMessage *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplaySolanaMessage; + +typedef struct TransactionParseResult_DisplaySolanaMessage *PtrT_TransactionParseResult_DisplaySolanaMessage; + +typedef struct DisplayStellarTx { + PtrString raw_message; +} DisplayStellarTx; + +typedef struct TransactionParseResult_DisplayStellarTx { + struct DisplayStellarTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayStellarTx; + +typedef struct TransactionParseResult_DisplayStellarTx *PtrT_TransactionParseResult_DisplayStellarTx; + +typedef struct DisplaySuiIntentMessage { + PtrString detail; +} DisplaySuiIntentMessage; + +typedef struct TransactionParseResult_DisplaySuiIntentMessage { + struct DisplaySuiIntentMessage *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplaySuiIntentMessage; + +typedef struct TransactionParseResult_DisplaySuiIntentMessage *PtrT_TransactionParseResult_DisplaySuiIntentMessage; + +typedef struct DisplaySuiSignMessageHash { + PtrString network; + PtrString path; + PtrString from_address; + PtrString message; +} DisplaySuiSignMessageHash; + +typedef struct TransactionParseResult_DisplaySuiSignMessageHash { + struct DisplaySuiSignMessageHash *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplaySuiSignMessageHash; + +typedef struct TransactionParseResult_DisplaySuiSignMessageHash *PtrT_TransactionParseResult_DisplaySuiSignMessageHash; + +typedef struct DisplayTonTransaction { + PtrString amount; + PtrString action; + PtrString to; + PtrString comment; + PtrString data_view; + PtrString raw_data; + PtrString contract_data; +} DisplayTonTransaction; + +typedef struct TransactionParseResult_DisplayTonTransaction { + struct DisplayTonTransaction *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayTonTransaction; + +typedef struct TransactionParseResult_DisplayTonTransaction *PtrT_TransactionParseResult_DisplayTonTransaction; + +typedef struct DisplayTonProof { + PtrString domain; + PtrString payload; + PtrString address; + PtrString raw_message; +} DisplayTonProof; + +typedef struct TransactionParseResult_DisplayTonProof { + struct DisplayTonProof *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayTonProof; + +typedef struct TransactionParseResult_DisplayTonProof *PtrT_TransactionParseResult_DisplayTonProof; + +typedef struct VecFFI_u8 *Ptr_VecFFI_u8; + +typedef struct DisplayTronOverview { + PtrString value; + PtrString method; + PtrString from; + PtrString to; + PtrString network; +} DisplayTronOverview; + +typedef struct DisplayTronDetail { + PtrString value; + PtrString method; + PtrString from; + PtrString to; + PtrString network; + PtrString token; + PtrString contract_address; +} DisplayTronDetail; + +typedef struct DisplayTron { + struct DisplayTronOverview *overview; + struct DisplayTronDetail *detail; +} DisplayTron; + +typedef struct TransactionParseResult_DisplayTron { + struct DisplayTron *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayTron; + +typedef struct TransactionParseResult_DisplayTron *PtrT_TransactionParseResult_DisplayTron; + +typedef struct DisplayXrpTxOverview { + PtrString display_type; + PtrString transaction_type; + PtrString from; + PtrString fee; + PtrString sequence; + PtrString value; + PtrString to; +} DisplayXrpTxOverview; + +typedef struct DisplayXrpTxOverview *PtrT_DisplayXrpTxOverview; + +typedef struct DisplayXrpTx { + PtrString network; + PtrT_DisplayXrpTxOverview overview; + PtrString detail; + PtrString signing_pubkey; +} DisplayXrpTx; + +typedef struct TransactionParseResult_DisplayXrpTx { + struct DisplayXrpTx *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayXrpTx; + +typedef struct TransactionParseResult_DisplayXrpTx *PtrT_TransactionParseResult_DisplayXrpTx; + +typedef struct DisplayFrom { + PtrString address; + PtrString value; + bool is_mine; +} DisplayFrom; + +typedef struct DisplayFrom *PtrT_DisplayFrom; + +typedef struct VecFFI_DisplayFrom { + PtrT_DisplayFrom data; + size_t size; + size_t cap; +} VecFFI_DisplayFrom; + +typedef struct VecFFI_DisplayFrom *Ptr_VecFFI_DisplayFrom; + +typedef struct DisplayTo { + PtrString address; + PtrString value; + bool is_change; + PtrString memo; +} DisplayTo; + +typedef struct DisplayTo *PtrT_DisplayTo; + +typedef struct VecFFI_DisplayTo { + PtrT_DisplayTo data; + size_t size; + size_t cap; +} VecFFI_DisplayTo; + +typedef struct VecFFI_DisplayTo *Ptr_VecFFI_DisplayTo; + +typedef struct DisplayTransparent { + Ptr_VecFFI_DisplayFrom from; + Ptr_VecFFI_DisplayTo to; +} DisplayTransparent; + +typedef struct DisplayTransparent *Ptr_DisplayTransparent; + +typedef struct DisplayOrchard { + Ptr_VecFFI_DisplayFrom from; + Ptr_VecFFI_DisplayTo to; +} DisplayOrchard; + +typedef struct DisplayOrchard *Ptr_DisplayOrchard; + +typedef struct DisplayPczt { + Ptr_DisplayTransparent transparent; + Ptr_DisplayOrchard orchard; + PtrString total_transfer_value; + PtrString fee_value; + bool has_sapling; +} DisplayPczt; + +typedef struct TransactionParseResult_DisplayPczt { + struct DisplayPczt *data; + uint32_t error_code; + PtrString error_message; +} TransactionParseResult_DisplayPczt; + +typedef struct TransactionParseResult_DisplayPczt *Ptr_TransactionParseResult_DisplayPczt; + +typedef struct TransactionParseResult_DisplayPczt *PtrT_TransactionParseResult_DisplayPczt; + +extern const uintptr_t FRAGMENT_MAX_LENGTH_DEFAULT; + +extern void LogRustMalloc(void *p, uint32_t size); + +extern void LogRustFree(void *p); + +extern void LogRustPanic(char *p); + +extern int32_t GenerateTRNGRandomness(uint8_t *randomness, uint8_t len); + +extern void *RustMalloc(int32_t size); + +extern void RustFree(void *p); + +struct SimpleResponse_u8 *get_master_fingerprint(PtrBytes seed, uint32_t seed_len); + +enum ErrorCodes dummy_function_to_export_error_codes(void); + +struct SimpleResponse_c_char *get_extended_pubkey_by_seed(PtrBytes seed, + uint32_t seed_len, + PtrString path); + +struct SimpleResponse_c_char *get_extended_pubkey_bytes_by_seed(PtrBytes seed, + uint32_t seed_len, + PtrString path); + +struct SimpleResponse_c_char *get_ed25519_pubkey_by_seed(PtrBytes seed, + uint32_t seed_len, + PtrString path); + +struct SimpleResponse_u8 *get_rsa_pubkey_by_seed(PtrBytes seed, uint32_t seed_len); + +struct SimpleResponse_c_char *get_bip32_ed25519_extended_pubkey(PtrBytes entropy, + uint32_t entropy_len, + PtrString passphrase, + PtrString path); + +struct SimpleResponse_c_char *get_ledger_bitbox02_master_key(PtrString mnemonic, + PtrString passphrase); + +struct SimpleResponse_c_char *get_icarus_master_key(PtrBytes entropy, + uint32_t entropy_len, + PtrString passphrase); + +struct SimpleResponse_c_char *derive_bip32_ed25519_extended_pubkey(PtrString master_key, + PtrString path); + +struct SimpleResponse_c_char *k1_sign_message_hash_by_private_key(PtrBytes private_key, + PtrBytes message_hash); + +bool k1_verify_signature(PtrBytes signature, PtrBytes message_hash, PtrBytes public_key); + +struct SimpleResponse_u8 *k1_generate_ecdh_sharekey(PtrBytes privkey, + uint32_t privkey_len, + PtrBytes pubkey, + uint32_t pubkey_len); + +struct SimpleResponse_u8 *k1_generate_pubkey_by_privkey(PtrBytes privkey, uint32_t privkey_len); + +struct SimpleResponse_u8 *pbkdf2_rust(PtrBytes password, PtrBytes salt, uint32_t iterations); + +struct SimpleResponse_u8 *pbkdf2_rust_64(PtrBytes password, PtrBytes salt, uint32_t iterations); + +Ptr_TransactionCheckResult tx_check_pass(void); + +struct SimpleResponse_c_char *rust_aes256_cbc_encrypt(PtrString data, + PtrString password, + PtrBytes iv, + uint32_t iv_len); + +struct SimpleResponse_c_char *rust_aes256_cbc_decrypt(PtrString hex_data, + PtrString password, + PtrBytes iv, + uint32_t iv_len); + +struct SimpleResponse_u8 *rust_derive_iv_from_seed(PtrBytes seed, uint32_t seed_len); + +void free_ur_parse_result(PtrT_URParseResult ur_parse_result); + +void free_ur_parse_multi_result(PtrT_URParseMultiResult ptr); + +void free_ur_encode_result(PtrT_UREncodeResult ptr); + +void free_ur_encode_muilt_result(PtrT_UREncodeMultiResult ptr); + +void free_simple_response_u8(PtrT_SimpleResponse_u8 ptr); + +void free_simple_response_c_char(PtrT_SimpleResponse_c_char ptr); + +void free_ptr_string(PtrString ptr); + +void free_rust_value(void *any_ptr); + +void free_VecFFI_u8(PtrT_VecFFI_u8 ptr); + +enum QRProtocol infer_qrcode_type(PtrString qrcode); + +Ptr_URParseResult parse_qrcode_text(PtrString qr); + +void free_TransactionCheckResult(PtrT_TransactionCheckResult ptr); + +struct UREncodeMultiResult *get_next_part(PtrEncoder ptr); + +struct URParseResult *parse_ur(PtrString ur); + +struct URParseMultiResult *receive(PtrString ur, PtrDecoder decoder); + +PtrString calculate_auth_code(ConstPtrUR web_auth_data, + PtrBytes rsa_key_n, + uint32_t rsa_key_n_len, + PtrBytes rsa_key_d, + uint32_t rsa_key_d_len); + +struct UREncodeResult *get_connect_blue_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); + +struct UREncodeResult *get_connect_sparrow_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); + +struct UREncodeResult *get_connect_specter_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); + +PtrT_UREncodeResult get_connect_companion_app_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + int32_t cold_version, + PtrT_CoinConfig coin_config, + uint32_t coin_config_length); + +Ptr_UREncodeResult get_okx_wallet_ur_btc_only(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString serial_number, + Ptr_CSliceFFI_ExtendedPublicKey public_keys, + PtrString device_type, + PtrString device_version); + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_metamask_ur_dynamic(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + enum ETHAccountType account_type, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + uintptr_t fragment_max_length_default, + uintptr_t fragment_max_length_other); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_metamask_ur_unlimited(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + enum ETHAccountType account_type, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_metamask_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + enum ETHAccountType account_type, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_Response_QRHardwareCallData parse_qr_hardware_call(PtrUR ur); +#endif + +#if defined(BUILD_MULTI_COINS) +struct Response_bool *check_hardware_call_path(PtrString path, PtrString chain_type); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult generate_key_derivation_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + Ptr_CSliceFFI_ExtendedPublicKey xpubs, + PtrString device_version); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_aptos_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_connect_arconnect_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrBytes p, + uint32_t p_len, + PtrBytes q, + uint32_t q_len); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_connect_arconnect_wallet_ur_from_xpub(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString xpub); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_backpack_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + Ptr_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_bitget_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString serial_number, + Ptr_CSliceFFI_ExtendedPublicKey public_keys, + PtrString device_type, + PtrString device_version); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_connect_imtoken_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString xpub, + PtrString wallet_name); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_keplr_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrT_CSliceFFI_KeplrAccount keplr_accounts); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_keystone_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString serial_number, + Ptr_CSliceFFI_ExtendedPublicKey public_keys, + PtrString device_type, + PtrString device_version); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_okx_wallet_ur(PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString serial_number, + Ptr_CSliceFFI_ExtendedPublicKey public_keys, + PtrString device_type, + PtrString device_version); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_solana_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +void free_Response_QRHardwareCallData(PtrT_Response_QRHardwareCallData ptr); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_sui_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +Ptr_UREncodeResult get_tonkeeper_wallet_ur(PtrString public_key, + PtrString wallet_name, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_length, + PtrString path); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_xbull_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_xrp_toolkit_ur(PtrString hd_path, + PtrString root_x_pub, + PtrString root_path); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_zcash_wallet_ur(PtrBytes seed_fingerprint, + uint32_t seed_fingerprint_len, + Ptr_CSliceFFI_ZcashKey zcash_keys); +#endif + +#if defined(BUILD_MULTI_COINS) +struct UREncodeResult *get_connect_thor_wallet_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrString serial_number, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + PtrString device_type, + PtrString device_version); +#endif + +struct SimpleResponse_c_char *aptos_generate_address(PtrString pub_key); + +PtrT_TransactionCheckResult aptos_check_request(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length); + +PtrT_TransactionParseResult_DisplayAptosTx aptos_parse(PtrUR ptr); + +PtrT_UREncodeResult aptos_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len, PtrString pub_key); + +PtrString aptos_get_path(PtrUR ptr); + +struct SimpleResponse_c_char *test_aptos_parse(void); + +void free_TransactionParseResult_DisplayAptosTx(PtrT_TransactionParseResult_DisplayAptosTx ptr); + +struct SimpleResponse_u8 *generate_arweave_secret(PtrBytes seed, uint32_t seed_len); + +struct SimpleResponse_u8 *generate_arweave_public_key_from_primes(PtrBytes p, + uint32_t p_len, + PtrBytes q, + uint32_t q_len); + +struct SimpleResponse_c_char *generate_rsa_public_key(PtrBytes p, + uint32_t p_len, + PtrBytes q, + uint32_t q_len); + +struct SimpleResponse_u8 *aes256_encrypt_primes(PtrBytes seed, uint32_t seed_len, PtrBytes data); + +struct SimpleResponse_u8 *aes256_decrypt_primes(PtrBytes seed, uint32_t seed_len, PtrBytes data); + +struct SimpleResponse_c_char *arweave_get_address(PtrString xpub); + +struct SimpleResponse_c_char *fix_arweave_address(PtrString address); + +PtrT_TransactionCheckResult ar_check_tx(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); + +struct SimpleResponse_ArweaveRequestType *ar_request_type(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayArweaveMessage ar_message_parse(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayArweaveTx ar_parse(PtrUR ptr); + +PtrT_UREncodeResult ar_sign_tx(PtrUR ptr, PtrBytes p, uint32_t p_len, PtrBytes q, uint32_t q_len); + +bool ar_is_ao_transfer(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayArweaveDataItem ar_parse_data_item(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayArweaveAOTransfer ar_parse_ao_transfer(PtrUR ptr); + +void free_TransactionParseResult_DisplayArweaveTx(PtrT_TransactionParseResult_DisplayArweaveTx ptr); + +void free_TransactionParseResult_DisplayArweaveMessage(PtrT_TransactionParseResult_DisplayArweaveMessage ptr); + +struct SimpleResponse_c_char *utxo_get_address(PtrString hd_path, PtrString x_pub); + +struct SimpleResponse_c_char *xpub_convert_version(PtrString x_pub, PtrString target); + +struct TransactionParseResult_DisplayTx *utxo_parse_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub); + +struct UREncodeResult *utxo_sign_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub, + int32_t cold_version, + PtrBytes seed, + uint32_t seed_len); + +PtrT_TransactionCheckResult utxo_check_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub); + +PtrT_TransactionCheckResult btc_check_msg(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); + +struct TransactionParseResult_DisplayBtcMsg *btc_parse_msg(PtrUR ptr, + Ptr_CSliceFFI_ExtendedPublicKey xpubs, + PtrBytes master_fingerprint, + uint32_t length); + +struct UREncodeResult *btc_sign_msg(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +Ptr_TransactionParseResult_DisplayBtcMsg parse_seed_signer_message(PtrUR ptr, + Ptr_CSliceFFI_ExtendedPublicKey xpubs); + +struct UREncodeResult *sign_seed_signer_message(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +struct UREncodeResult *export_multi_sig_xpub_by_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + enum NetworkType network); + +struct UREncodeResult *export_multi_sig_wallet_by_ur_test(uint8_t *master_fingerprint, + uint32_t length, + PtrT_MultiSigWallet multi_sig_wallet); + +struct UREncodeResult *export_multi_sig_wallet_by_ur(uint8_t *master_fingerprint, + uint32_t length, + PtrString config); + +Ptr_Response_MultiSigWallet import_multi_sig_wallet_by_ur(PtrUR ur, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +Ptr_Response_MultiSigWallet import_multi_sig_wallet_by_file(PtrString content, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +Ptr_SimpleResponse_c_char generate_address_for_multisig_wallet_config(PtrString wallet_config, + uint32_t account, + uint32_t index, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +Ptr_SimpleResponse_c_char generate_psbt_file_name(PtrBytes psbt_hex, + uint32_t psbt_len, + uint32_t time_stamp); + +Ptr_Response_MultiSigWallet parse_and_verify_multisig_config(PtrBytes seed, + uint32_t seed_len, + PtrString wallet_config, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +void free_MultiSigXPubInfoItem(PtrT_MultiSigXPubInfoItem ptr); + +void free_MultiSigWallet(PtrT_MultiSigWallet ptr); + +void free_MultisigSignResult(PtrT_MultisigSignResult ptr); + +struct TransactionParseResult_DisplayTx *btc_parse_psbt(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + PtrString multisig_wallet_config); + +struct UREncodeResult *btc_sign_psbt(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +struct UREncodeResult *btc_sign_psbt_unlimited(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +struct MultisigSignResult *btc_sign_multisig_psbt(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +struct MultisigSignResult *btc_export_multisig_psbt(PtrUR ptr); + +struct MultisigSignResult *btc_export_multisig_psbt_bytes(PtrBytes psbt_bytes, + uint32_t psbt_bytes_length); + +PtrT_TransactionCheckResult btc_check_psbt(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + PtrString verify_code, + PtrString multisig_wallet_config); + +PtrT_TransactionCheckResult btc_check_psbt_bytes(PtrBytes psbt_bytes, + uint32_t psbt_bytes_length, + PtrBytes master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + PtrString verify_code, + PtrString multisig_wallet_config); + +struct TransactionParseResult_DisplayTx *btc_parse_psbt_bytes(PtrBytes psbt_bytes, + uint32_t psbt_bytes_length, + PtrBytes master_fingerprint, + uint32_t length, + PtrT_CSliceFFI_ExtendedPublicKey public_keys, + PtrString multisig_wallet_config); + +struct MultisigSignResult *btc_sign_multisig_psbt_bytes(PtrBytes psbt_bytes, + uint32_t psbt_bytes_length, + PtrBytes seed, + uint32_t seed_len, + PtrBytes master_fingerprint, + uint32_t master_fingerprint_len); + +void free_Response_PsbtSignResult(PtrT_Response_PsbtSignResult ptr); + +void free_TransactionParseResult_DisplayTx(PtrT_TransactionParseResult_DisplayTx ptr); + +void free_TransactionParseResult_DisplayBtcMsg(PtrT_TransactionParseResult_DisplayBtcMsg ptr); + +Ptr_SimpleResponse_c_char cardano_catalyst_xpub(PtrUR ptr); + +PtrT_TransactionCheckResult cardano_check_catalyst(PtrUR ptr, PtrBytes master_fingerprint); + +PtrT_TransactionCheckResult cardano_check_catalyst_path_type(PtrUR ptr, PtrString cardano_xpub); + +Ptr_SimpleResponse_c_char cardano_get_catalyst_root_index(PtrUR ptr); + +Ptr_SimpleResponse_c_char cardano_get_sign_data_root_index(PtrUR ptr); + +PtrT_TransactionCheckResult cardano_check_sign_data_path_type(PtrUR ptr, PtrString cardano_xpub); + +PtrT_TransactionCheckResult cardano_check_sign_data(PtrUR ptr, PtrBytes master_fingerprint); + +PtrT_TransactionCheckResult cardano_check_tx(PtrUR ptr, + PtrBytes master_fingerprint, + PtrString cardano_xpub); + +PtrT_TransactionCheckResult cardano_check_tx_hash(PtrUR ptr, PtrBytes master_fingerprint); + +PtrT_TransactionParseResult_DisplayCardanoSignTxHash cardano_parse_sign_tx_hash(PtrUR ptr); + +Ptr_SimpleResponse_c_char cardano_get_path(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayCardanoSignData cardano_parse_sign_data(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayCardanoCatalyst cardano_parse_catalyst(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayCardanoTx cardano_parse_tx(PtrUR ptr, + PtrBytes master_fingerprint, + PtrString cardano_xpub); + +PtrT_UREncodeResult cardano_sign_catalyst_with_ledger_bitbox02(PtrUR ptr, + PtrString mnemonic, + PtrString passphrase); + +PtrT_UREncodeResult cardano_sign_catalyst(PtrUR ptr, + PtrBytes entropy, + uint32_t entropy_len, + PtrString passphrase); + +PtrT_UREncodeResult cardano_sign_sign_data_with_ledger_bitbox02(PtrUR ptr, + PtrString mnemonic, + PtrString passphrase); + +PtrT_UREncodeResult cardano_sign_sign_data(PtrUR ptr, + PtrBytes entropy, + uint32_t entropy_len, + PtrString passphrase); + +PtrT_UREncodeResult cardano_sign_tx_with_ledger_bitbox02(PtrUR ptr, + PtrBytes master_fingerprint, + PtrString cardano_xpub, + PtrString mnemonic, + PtrString passphrase, + bool enable_blind_sign); + +PtrT_UREncodeResult cardano_sign_tx(PtrUR ptr, + PtrBytes master_fingerprint, + PtrString cardano_xpub, + PtrBytes entropy, + uint32_t entropy_len, + PtrString passphrase, + bool enable_blind_sign); + +struct SimpleResponse_c_char *cardano_get_base_address(PtrString xpub, + uint32_t index, + uint8_t network_id); + +struct SimpleResponse_c_char *cardano_get_enterprise_address(PtrString xpub, + uint32_t index, + uint8_t network_id); + +struct SimpleResponse_c_char *cardano_get_stake_address(PtrString xpub, + uint32_t index, + uint8_t network_id); + +void free_TransactionParseResult_DisplayCardanoTx(PtrT_TransactionParseResult_DisplayCardanoTx ptr); + +void free_TransactionParseResult_DisplayCardanoCatalyst(PtrT_TransactionParseResult_DisplayCardanoCatalyst ptr); + +void free_TransactionParseResult_DisplayCardanoSignData(PtrT_TransactionParseResult_DisplayCardanoSignData ptr); + +void free_TransactionParseResult_DisplayCardanoSignTxHash(PtrT_TransactionParseResult_DisplayCardanoSignTxHash ptr); + +PtrT_TransactionCheckResult cosmos_check_tx(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length); + +struct SimpleResponse_c_char *cosmos_get_address(PtrString hd_path, + PtrString root_x_pub, + PtrString root_path, + PtrString prefix); + +PtrT_UREncodeResult cosmos_sign_tx(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes seed, + uint32_t seed_len); + +PtrT_TransactionParseResult_DisplayCosmosTx cosmos_parse_tx(PtrUR ptr, enum QRCodeType ur_type); + +void free_TransactionParseResult_DisplayCosmosTx(PtrT_TransactionParseResult_DisplayCosmosTx ptr); + +PtrT_TransactionCheckResult eth_check_ur_bytes(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length, + enum QRCodeType ur_type); + +PtrT_TransactionCheckResult eth_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); + +PtrString eth_get_root_path_bytes(PtrUR ptr); + +PtrString eth_get_root_path(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayETH eth_parse_bytes_data(PtrUR ptr, PtrString xpub); + +PtrT_TransactionParseResult_DisplayETH eth_parse(PtrUR ptr, PtrString xpub); + +PtrT_TransactionParseResult_DisplayETHPersonalMessage eth_parse_personal_message(PtrUR ptr, + PtrString xpub); + +PtrT_TransactionParseResult_DisplayETHTypedData eth_parse_typed_data(PtrUR ptr, PtrString xpub); + +PtrT_UREncodeResult eth_sign_tx_dynamic(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + uintptr_t fragment_length); + +PtrT_UREncodeResult eth_sign_tx_bytes(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes mfp, + uint32_t mfp_len); + +PtrT_UREncodeResult eth_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +PtrT_UREncodeResult eth_sign_tx_unlimited(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +PtrT_TransactionParseResult_EthParsedErc20Transaction eth_parse_erc20(PtrString input, + uint32_t decimal); + +Ptr_Response_DisplayContractData eth_parse_contract_data(PtrString input_data, + PtrString contract_json); + +Ptr_Response_DisplayContractData eth_parse_contract_data_by_method(PtrString input_data, + PtrString contract_name, + PtrString contract_method_json); + +struct SimpleResponse_c_char *eth_get_address(PtrString hd_path, + PtrString root_x_pub, + PtrString root_path); + +void free_TransactionParseResult_DisplayETH(PtrT_TransactionParseResult_DisplayETH ptr); + +void free_TransactionParseResult_DisplayETHPersonalMessage(PtrT_TransactionParseResult_DisplayETHPersonalMessage ptr); + +void free_TransactionParseResult_DisplayETHTypedData(PtrT_TransactionParseResult_DisplayETHTypedData ptr); + +void free_Response_DisplayContractData(PtrT_Response_DisplayContractData ptr); + +void free_TransactionParseResult_EthParsedErc20Transaction(PtrT_TransactionParseResult_EthParsedErc20Transaction ptr); + +PtrT_TransactionCheckResult near_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); + +PtrT_TransactionParseResult_DisplayNearTx near_parse_tx(PtrUR ptr); + +PtrT_UREncodeResult near_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +void free_TransactionParseResult_DisplayNearTx(PtrT_TransactionParseResult_DisplayNearTx ptr); + +struct SimpleResponse_c_char *solana_get_address(PtrString pubkey); + +PtrT_TransactionCheckResult solana_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); + +PtrT_TransactionParseResult_DisplaySolanaTx solana_parse_tx(PtrUR ptr); + +PtrT_UREncodeResult solana_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +PtrT_TransactionParseResult_DisplaySolanaMessage solana_parse_message(PtrUR ptr, PtrString pubkey); + +PtrString sol_get_path(PtrUR ptr); + +void free_TransactionParseResult_DisplaySolanaTx(PtrT_TransactionParseResult_DisplaySolanaTx ptr); + +void free_TransactionParseResult_DisplaySolanaMessage(PtrT_TransactionParseResult_DisplaySolanaMessage ptr); + +struct SimpleResponse_c_char *stellar_get_address(PtrString pubkey); + +PtrT_TransactionParseResult_DisplayStellarTx stellar_parse(PtrUR ptr); + +PtrT_TransactionCheckResult stellar_check_tx(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length); + +PtrT_UREncodeResult stellar_sign(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +void free_TransactionParseResult_DisplayStellarTx(PtrT_TransactionParseResult_DisplayStellarTx ptr); + +PtrT_TransactionCheckResult sui_check_request(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length); + +PtrT_TransactionCheckResult sui_check_sign_hash_request(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length); + +struct SimpleResponse_c_char *sui_generate_address(PtrString pub_key); + +PtrT_TransactionParseResult_DisplaySuiIntentMessage sui_parse_intent(PtrUR ptr); + +PtrT_TransactionParseResult_DisplaySuiSignMessageHash sui_parse_sign_message_hash(PtrUR ptr); + +PtrT_UREncodeResult sui_sign_hash(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +PtrT_UREncodeResult sui_sign_intent(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +void free_TransactionParseResult_DisplaySuiIntentMessage(PtrT_TransactionParseResult_DisplaySuiIntentMessage ptr); + +void free_TransactionParseResult_DisplaySuiSignMessageHash(PtrT_TransactionParseResult_DisplaySuiSignMessageHash ptr); + +PtrT_TransactionParseResult_DisplayTonTransaction ton_parse_transaction(PtrUR ptr); + +PtrT_TransactionParseResult_DisplayTonProof ton_parse_proof(PtrUR ptr); + +PtrT_TransactionCheckResult ton_check_transaction(PtrUR ptr, PtrString public_key); + +PtrT_TransactionCheckResult ton_not_supported_error(void); + +PtrT_UREncodeResult ton_sign_transaction(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +PtrT_UREncodeResult ton_sign_proof(PtrUR ptr, PtrBytes seed, uint32_t seed_len); + +bool ton_verify_mnemonic(PtrString mnemonic); + +Ptr_VecFFI_u8 ton_mnemonic_to_entropy(PtrString mnemonic); + +struct SimpleResponse_u8 *ton_entropy_to_seed(PtrBytes entropy, uint32_t entropy_len); + +struct SimpleResponse_u8 *ton_mnemonic_to_seed(PtrString mnemonic); + +struct SimpleResponse_c_char *ton_seed_to_publickey(PtrBytes seed, uint32_t seed_len); + +struct SimpleResponse_c_char *ton_get_address(PtrString public_key); + +void free_TransactionParseResult_DisplayTonTransaction(PtrT_TransactionParseResult_DisplayTonTransaction ptr); + +void free_TransactionParseResult_DisplayTonProof(PtrT_TransactionParseResult_DisplayTonProof ptr); + +PtrT_TransactionCheckResult tron_check_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub); + +struct TransactionParseResult_DisplayTron *tron_parse_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub); + +struct UREncodeResult *tron_sign_keystone(PtrUR ptr, + enum QRCodeType ur_type, + PtrBytes master_fingerprint, + uint32_t length, + PtrString x_pub, + int32_t cold_version, + PtrBytes seed, + uint32_t seed_len); + +struct SimpleResponse_c_char *tron_get_address(PtrString hd_path, PtrString x_pub); + +void free_TransactionParseResult_DisplayTron(PtrT_TransactionParseResult_DisplayTron ptr); + +struct SimpleResponse_c_char *xrp_get_address(PtrString hd_path, + PtrString root_x_pub, + PtrString root_path); + +PtrT_TransactionParseResult_DisplayXrpTx xrp_parse_tx(PtrUR ptr); + +PtrT_UREncodeResult xrp_sign_tx_bytes(PtrUR ptr, + PtrBytes seed, + uint32_t seed_len, + PtrBytes mfp, + uint32_t mfp_len, + PtrString root_xpub); + +PtrT_UREncodeResult xrp_sign_tx(PtrUR ptr, PtrString hd_path, PtrBytes seed, uint32_t seed_len); + +PtrT_TransactionCheckResult xrp_check_tx(PtrUR ptr, PtrString root_xpub, PtrString cached_pubkey); + +bool is_keystone_xrp_tx(PtrUR ur_data_ptr); + +PtrT_TransactionCheckResult xrp_check_tx_bytes(PtrUR ptr, + PtrBytes master_fingerprint, + uint32_t length, + enum QRCodeType ur_type); + +PtrT_TransactionParseResult_DisplayXrpTx xrp_parse_bytes_tx(PtrUR ptr); + +void free_TransactionParseResult_DisplayXrpTx(PtrT_TransactionParseResult_DisplayXrpTx ptr); + +struct SimpleResponse_c_char *derive_zcash_ufvk(PtrBytes seed, + uint32_t seed_len, + PtrString account_path); + +struct SimpleResponse_u8 *calculate_zcash_seed_fingerprint(PtrBytes seed, uint32_t seed_len); + +struct SimpleResponse_c_char *generate_zcash_default_address(PtrString ufvk_text); + +struct TransactionCheckResult *check_zcash_tx(PtrUR tx, + PtrString ufvk, + PtrBytes seed_fingerprint, + uint32_t account_index, + bool disabled); + +Ptr_TransactionParseResult_DisplayPczt parse_zcash_tx(PtrUR tx, + PtrString ufvk, + PtrBytes seed_fingerprint); + +struct UREncodeResult *sign_zcash_tx(PtrUR tx, PtrBytes seed, uint32_t seed_len); + +void free_TransactionParseResult_DisplayPczt(PtrT_TransactionParseResult_DisplayPczt ptr); + +#endif /* _LIBRUST_C_H */ diff --git a/rust/rust_c/src/test_cmd/btc_test_cmd.rs b/rust/rust_c/src/test_cmd/btc_test_cmd.rs index b87971c13..bd57e545d 100644 --- a/rust/rust_c/src/test_cmd/btc_test_cmd.rs +++ b/rust/rust_c/src/test_cmd/btc_test_cmd.rs @@ -18,7 +18,7 @@ use crate::common::ur::{ }; use crate::common::utils::convert_c_char; -use wallet_rust_c::get_connect_blue_wallet_ur; +use crate::wallet::get_connect_blue_wallet_ur; #[no_mangle] pub extern "C" fn test_get_crypto_psbt() -> *mut URParseResult { diff --git a/rust/zcash_vendor/Cargo.toml b/rust/zcash_vendor/Cargo.toml index b97af0b82..c3d66cdaa 100644 --- a/rust/zcash_vendor/Cargo.toml +++ b/rust/zcash_vendor/Cargo.toml @@ -23,7 +23,6 @@ pasta_curves = { version = "0.5.1", default-features = false, features = [ sinsemilla = "0.1" subtle = { version = "2.6", default-features = false } group = { version = "0.13.0" } -aes = { workspace = true } fpe = { version = "0.6", default-features = false, features = ["alloc"] } f4jumble = { version = "0.1.1", default-features = false, features = ["alloc"] } byteorder = { version = "1", default-features = false } From f8743b63d6a95dfe9ae3f240af930a926e6d00b7 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 18:42:10 +0800 Subject: [PATCH 23/31] refactor: use features for code --- rust/.gitignore | 3 +- rust/BUILD.MD | 34 + rust/CMakeLists.txt | 12 +- rust/apps/arweave/src/lib.rs | 1 - rust/keystore/src/errors.rs | 1 - rust/rust_c/Cargo.toml | 15 +- rust/rust_c/build.rs | 10 +- rust/rust_c/cbindgen.toml | 13 + rust/rust_c/cbindgens/firmware/btc_only.toml | 33 - .../rust_c/cbindgens/firmware/multi_coin.toml | 74 - rust/rust_c/cbindgens/simulator/btc_only.toml | 35 - .../cbindgens/simulator/multi_coin.toml | 86 - rust/rust_c/librust_c.h | 2433 ----------------- rust/rust_c/src/common/errors.rs | 62 +- rust/rust_c/src/common/keystone.rs | 6 +- rust/rust_c/src/common/macros.rs | 172 +- rust/rust_c/src/common/structs.rs | 3 - rust/rust_c/src/common/ur.rs | 292 +- rust/rust_c/src/common/ur_ext.rs | 107 +- 19 files changed, 403 insertions(+), 2989 deletions(-) create mode 100644 rust/BUILD.MD delete mode 100644 rust/rust_c/cbindgens/firmware/btc_only.toml delete mode 100644 rust/rust_c/cbindgens/firmware/multi_coin.toml delete mode 100644 rust/rust_c/cbindgens/simulator/btc_only.toml delete mode 100644 rust/rust_c/cbindgens/simulator/multi_coin.toml delete mode 100644 rust/rust_c/librust_c.h diff --git a/rust/.gitignore b/rust/.gitignore index e330df76a..970fd171c 100644 --- a/rust/.gitignore +++ b/rust/.gitignore @@ -1,4 +1,5 @@ /target /**/target signer/build -.idea/ \ No newline at end of file +.idea/ +rust_c/bindings/ diff --git a/rust/BUILD.MD b/rust/BUILD.MD new file mode 100644 index 000000000..6e6db9547 --- /dev/null +++ b/rust/BUILD.MD @@ -0,0 +1,34 @@ +## Build + +BUILD_ENVIRONMENT: PRODUCTION, DEBUG, SIMULATOR +BUILD_VARIANT: BTC_ONLY, MULTI_COINS + +### Build for production + +```bash +cargo build --release -p rust_c --target thumbv7em-none-eabihf --no-default-features --features production-multi-coins +``` + +```bash +cargo build --release -p rust_c --target thumbv7em-none-eabihf --no-default-features --features production-btc-only +``` + +### Build for simulator + +```bash +cargo build --release -p rust_c --no-default-features --features simulator-multi-coins +``` + +```bash +cargo build --release -p rust_c --no-default-features --features simulator-btc-only +``` + +### Build for debug + +```bash +cargo build -p rust_c --target thumbv7em-none-eabihf --no-default-features --features debug-multi-coins +``` + +```bash +cargo build -p rust_c --target thumbv7em-none-eabihf --no-default-features --features debug-btc-only +``` diff --git a/rust/CMakeLists.txt b/rust/CMakeLists.txt index c49171367..9f44485c0 100644 --- a/rust/CMakeLists.txt +++ b/rust/CMakeLists.txt @@ -43,17 +43,17 @@ endif() set(FEATURE ${FEATURE_ENVIRONMENT}-${FEATURE_VARIANT}) -set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/${CBIDGEN_FOLDER}/${CBIDGEN_CONFIG_FILE}) -set(CBINDGEN_FLAG ${RUST_C_DIR} --config ${CBINDGEN_CONFIG_PATH} --output ${TARGET_PATH}/librust_c.h --lang c) +set(CBINDGEN_BINDINGS_TARGET ${RUST_C_DIR}/bindings/${FEATURE}/librust_c.h) +set(COPY_BINDINGS_TARGET cp ${CBINDGEN_BINDINGS_TARGET} ${TARGET_PATH}) # compile rust lib set(CARGO_FLAG --release -p rust_c --no-default-features) set(CARGO_FLAG ${CARGO_FLAG} --features ${FEATURE}) if(CARGO_ARM_TARGET) set(CARGO_FLAG ${CARGO_FLAG} --target ${CARGO_ARM_TARGET}) - set(COPY_COMMAND cp ${RUST_DIR}/target/${CARGO_ARM_TARGET}/release/${LIB_NAME} ${TARGET_PATH}) + set(COPY_BUILD_TARGET cp ${RUST_DIR}/target/${CARGO_ARM_TARGET}/release/${LIB_NAME} ${TARGET_PATH}) else() - set(COPY_COMMAND cp ${RUST_DIR}/target/release/${LIB_NAME} ${TARGET_PATH}) + set(COPY_BUILD_TARGET cp ${RUST_DIR}/target/release/${LIB_NAME} ${TARGET_PATH}) endif() message(STATUS "cargo build command: " ${CARGO_FLAG}) @@ -61,8 +61,8 @@ message(STATUS "cargo build command: " ${CARGO_FLAG}) #run build add_custom_target(rust_c ALL - COMMAND ${CBINDGEN_EXE} ${CBINDGEN_FLAG} COMMAND rustup run nightly-2024-01-31 ${RUST_CARGO_EXECUTABLE} build ${CARGO_FLAG} - COMMAND ${COPY_COMMAND} + COMMAND ${COPY_BUILD_TARGET} + COMMAND ${COPY_BINDINGS_TARGET} WORKING_DIRECTORY ${RUST_DIR} ) diff --git a/rust/apps/arweave/src/lib.rs b/rust/apps/arweave/src/lib.rs index 2d2d80c65..7e4869783 100644 --- a/rust/apps/arweave/src/lib.rs +++ b/rust/apps/arweave/src/lib.rs @@ -10,7 +10,6 @@ pub mod transaction; #[macro_use] extern crate alloc; -extern crate aes; #[cfg(test)] #[macro_use] diff --git a/rust/keystore/src/errors.rs b/rust/keystore/src/errors.rs index 6cf8c8125..598045621 100644 --- a/rust/keystore/src/errors.rs +++ b/rust/keystore/src/errors.rs @@ -1,7 +1,6 @@ use alloc::string::String; use thiserror; use thiserror::Error; -use zcash_vendor::orchard; pub type Result = core::result::Result; diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index 51aed7047..5a222bd2c 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -30,7 +30,7 @@ sim_qr_reader = { workspace = true, optional = true } keystore = { workspace = true } ur-registry = { workspace = true } ur-parse-lib = { workspace = true } -zcash_vendor = { workspace = true } +zcash_vendor = { workspace = true, optional = true } ed25519-bip32-core = { workspace = true } app_utils = { workspace = true } rust_tools = { workspace = true } @@ -62,6 +62,9 @@ simulator = ["dep:sim_qr_reader"] aptos = ["dep:app_aptos"] arweave = ["dep:app_arweave"] bitcoin = ["dep:app_bitcoin"] +ltc = [] +dash = [] +bch = [] cardano = ["dep:app_cardano"] cosmos = ["dep:app_cosmos"] ethereum = ["dep:app_ethereum"] @@ -72,7 +75,7 @@ sui = ["dep:app_sui"] ton = ["dep:app_ton"] tron = ["dep:app_tron"] xrp = ["dep:app_xrp"] -zcash = ["dep:app_zcash"] +zcash = ["dep:app_zcash", "dep:zcash_vendor"] test_cmd = [] debug-memory = ["multi-coins"] @@ -92,6 +95,9 @@ multi-coins = [ "stellar", "ton", "zcash", + "ltc", + "dash", + "bch", ] btc-only = ["bitcoin"] @@ -101,11 +107,12 @@ btc-only = ["bitcoin"] production-multi-coins = ["use-allocator", "multi-coins"] production-btc-only = ["use-allocator", "btc-only"] # debug -debug-multi-coins = ["test_cmd", "production-multi-coins"] -debug-btc-only = ["test_cmd", "production-btc-only"] +debug-multi-coins = ["test_cmd", "use-allocator", "multi-coins"] +debug-btc-only = ["test_cmd", "use-allocator", "btc-only"] # simulator simulator-multi-coins = ["simulator", "multi-coins"] simulator-btc-only = ["simulator", "btc-only"] +# make IDE happy default = ["simulator-multi-coins"] [dev-dependencies] diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index 18b73f5df..df90db38d 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -1,7 +1,9 @@ +use std::env; + fn main() { let mut config = cbindgen::Config::from_file("cbindgen.toml").expect("Failed to read cbindgen.toml"); - let features = vec![ + let features: Vec<&str> = vec![ #[cfg(feature = "production-multi-coins")] "production-multi-coins", #[cfg(feature = "production-btc-only")] @@ -15,7 +17,9 @@ fn main() { #[cfg(feature = "debug-btc-only")] "debug-btc-only", ]; - println!("cargo:warning={}", format!("features: {:?}", features)); + assert!(features.len() > 0, "No build variant enabled"); + assert!(features.len() == 1, "Multiple build variants enabled: {:?}", features); + let output_target = env::var("CBINDGEN_BINDINGS_TARGET").unwrap_or(format!("bindings/{}/librust_c.h", features[0])); config.parse.expand.features = Some(features.into_iter().map(|s| s.to_string()).collect()); let builder = cbindgen::Builder::new(); @@ -25,5 +29,5 @@ fn main() { .with_config(config) .generate() .expect("Failed to generate bindings") - .write_to_file("librust_c.h"); + .write_to_file(output_target); } diff --git a/rust/rust_c/cbindgen.toml b/rust/rust_c/cbindgen.toml index 75a59cfd1..af0fe7866 100644 --- a/rust/rust_c/cbindgen.toml +++ b/rust/rust_c/cbindgen.toml @@ -6,6 +6,19 @@ language = "C" [defines] "feature = multi-coins" = "BUILD_MULTI_COINS" +"feature = aptos" = "FEATURE_APTOS" +"feature = arweave" = "FEATURE_ARWEAVE" +"feature = bitcoin" = "FEATURE_BITCOIN" +"feature = cardano" = "FEATURE_CARDANO" +"feature = cosmos" = "FEATURE_COSMOS" +"feature = ethereum" = "FEATURE_ETHEREUM" +"feature = near" = "FEATURE_NEAR" +"feature = solana" = "FEATURE_SOLANA" +"feature = stellar" = "FEATURE_STELLAR" +"feature = ton" = "FEATURE_TON" +"feature = tron" = "FEATURE_TRON" +"feature = xrp" = "FEATURE_XRP" +"feature = zcash" = "FEATURE_ZCASH" [parse] extra_bindings = ["rust_c"] diff --git a/rust/rust_c/cbindgens/firmware/btc_only.toml b/rust/rust_c/cbindgens/firmware/btc_only.toml deleted file mode 100644 index 3b3033afd..000000000 --- a/rust/rust_c/cbindgens/firmware/btc_only.toml +++ /dev/null @@ -1,33 +0,0 @@ -include_guard = "_LIBRUST_C_H" - -after_includes = "#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" - -[defines] -"feature = multi-coins" = "BUILD_MULTI_COINS" - -[parse] -parse_deps = true -include = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", -] -extra_bindings = [ - "common_rust_c", - "bitcoin_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", -] - -[parse.expand] -crates = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", -] -default_features = false -features = ["btc-only"] \ No newline at end of file diff --git a/rust/rust_c/cbindgens/firmware/multi_coin.toml b/rust/rust_c/cbindgens/firmware/multi_coin.toml deleted file mode 100644 index f67e60d57..000000000 --- a/rust/rust_c/cbindgens/firmware/multi_coin.toml +++ /dev/null @@ -1,74 +0,0 @@ -include_guard = "_LIBRUST_C_H" - -after_includes = "#define BUILD_MULTI_COINS\n#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" - -[defines] -"feature = multi-coins" = "BUILD_MULTI_COINS" - -[parse] -parse_deps = true -include = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "ton_rust_c", - "zcash_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", -] -extra_bindings = [ - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "ton_rust_c", - "zcash_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", -] - -[parse.expand] -crates = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "ton_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "zcash_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", -] -default_features = true diff --git a/rust/rust_c/cbindgens/simulator/btc_only.toml b/rust/rust_c/cbindgens/simulator/btc_only.toml deleted file mode 100644 index 468af5cbd..000000000 --- a/rust/rust_c/cbindgens/simulator/btc_only.toml +++ /dev/null @@ -1,35 +0,0 @@ -include_guard = "_LIBRUST_C_H" - -after_includes = "#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" - -[defines] -"feature = multi-coins" = "BUILD_MULTI_COINS" - -[parse] -parse_deps = true -include = [ - "rust_c", -] -extra_bindings = [ - "common_rust_c", - "bitcoin_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "test_cmd", - "btc_test_cmd", - "simulator_rust_c" -] - -[parse.expand] -crates = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "test_cmd", - "btc_test_cmd", - "simulator_rust_c" -] -default_features = false -features = ["btc-only"] \ No newline at end of file diff --git a/rust/rust_c/cbindgens/simulator/multi_coin.toml b/rust/rust_c/cbindgens/simulator/multi_coin.toml deleted file mode 100644 index 234f46cfb..000000000 --- a/rust/rust_c/cbindgens/simulator/multi_coin.toml +++ /dev/null @@ -1,86 +0,0 @@ -include_guard = "_LIBRUST_C_H" - -after_includes = "#define BUILD_MULTI_COINS\n#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" - -[defines] -"feature = multi-coins" = "BUILD_MULTI_COINS" - -[parse] -parse_deps = true -include = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "ton_rust_c", - "zcash_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", - "test_cmd", - "btc_test_cmd", - "general_test_cmd", - "simulator_rust_c", -] -extra_bindings = [ - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "ton_rust_c", - "zcash_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", - "test_cmd", - "btc_test_cmd", - "general_test_cmd", - "simulator_rust_c", -] - -[parse.expand] -crates = [ - "rust_c", - "common_rust_c", - "bitcoin_rust_c", - "ethereum_rust_c", - "solana_rust_c", - "ton_rust_c", - "zcash_rust_c", - "near_rust_c", - "aptos_rust_c", - "cosmos_rust_c", - "cardano_rust_c", - "sui_rust_c", - "tron_rust_c", - "xrp_rust_c", - "arweave_rust_c", - "stellar_rust_c", - "wallet_rust_c", - "btc_only_wallet_rust_c", - "multi_coins_wallet_rust_c", - "test_cmd", - "btc_test_cmd", - "general_test_cmd", - "simulator_rust_c", -] -default_features = true diff --git a/rust/rust_c/librust_c.h b/rust/rust_c/librust_c.h deleted file mode 100644 index ef0e43e32..000000000 --- a/rust/rust_c/librust_c.h +++ /dev/null @@ -1,2433 +0,0 @@ -#ifndef _LIBRUST_C_H -#define _LIBRUST_C_H - -#include -#include -#include -#include -#define BUILD_MULTI_COINS -#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048 -#define ADDRESS_MAX_LEN 256 -#define PATH_ITEM_MAX_LEN 32 - -typedef enum ArweaveRequestType { - ArweaveRequestTypeTransaction = 1, - ArweaveRequestTypeDataItem, - ArweaveRequestTypeMessage, - ArweaveRequestTypeUnknown, -} ArweaveRequestType; - -#if defined(BUILD_MULTI_COINS) -typedef enum ETHAccountType { -#if defined(BUILD_MULTI_COINS) - Bip44Standard, -#endif -#if defined(BUILD_MULTI_COINS) - LedgerLive, -#endif -#if defined(BUILD_MULTI_COINS) - LedgerLegacy, -#endif -} ETHAccountType; -#endif - -typedef enum ErrorCodes { - Success = 0, - InvalidMasterFingerprint, - MasterFingerprintMismatch, - InvalidHDPath, - UnsupportedTransaction, - InvalidXPub, - SignFailure, - UnexpectedError, - InvalidHex, - WebAuthFailed, - InvalidData, - CborDecodeError = 20, - CborEncodeError, - URDecodeError, - UREncodeError, - NotSupportURTypeError, - NotAnUr, - URTypeUnspecified, - URProtobufDecodeError, - URProtobufEncodeError, - URGzipDecodeError, - URGzipEnCodeError, - KeystoreSeedError = 40, - KeystoreDerivationError, - KeystoreXPubError, - KeystoreInvalidDerivationPath, - KeystoreDeivePubkey, - KeystoreGenerateSigningKeyError, - KeystoreRSASignError, - KeystoreRSAVerifyError, - KeystoreInvalidDataError, - KeystoreZcashOrchardSignError, - BitcoinInvalidInput = 100, - BitcoinInvalidOutput, - BitcoinInvalidPsbt, - BitcoinInvalidTransaction, - BitcoinNoInputs, - BitcoinNoOutputs, - BitcoinNoMyInputs, - BitcoinInputValueTampered, - BitcoinSignFailure, - BitcoinAddressError, - BitcoinGetKeyError, - BitcoinSignLegacyTxError, - BitcoinUnsupportedTransaction, - BitcoinUnsupportedNetwork, - BitcoinTransactionConsensusEncodeError, - BitcoinPushBytesFailed, - BitcoinInvalidHex, - BitcoinBase58Error, - BitcoinKeystoreError, - BitcoinInvalidParseContext, - BitcoinInvalidRawTxCryptoBytes, - BitcoinInvalidTxData, - BitcoinUnsupportedScriptType, - BitcoinBech32DecodeError, - BitcoinWitnessProgramError, - BitcoinMultiSigWalletParseError, - BitcoinMultiSigWalletNotMyWallet, - BitcoinMultiSigWalletAddressCalError, - BitcoinMultiSigWalletImportXpubError, - BitcoinMultiSigWalletCrateError, - BitcoinMultiSigWalletFormatError, - BitcoinMultiSigNetworkError, - BitcoinMultiSigInputError, - BitcoinDerivePublicKeyError, - BitcoinWalletTypeError, - EthereumRlpDecodingError = 200, - EthereumInvalidTransaction, - EthereumSignFailure, - EthereumInvalidHDPath, - EthereumKeystoreError, - EthereumInvalidAddressError, - EthereumInvalidUtf8Error, - EthereumInvalidContractABI, - EthereumDecodeContractDataError, - EthereumInvalidTypedData, - EthereumHashTypedDataError, - TronInvalidRawTxCryptoBytes = 300, - TronInvalidParseContext, - TronBase58Error, - TronSignFailure, - TronProtobufError, - TronParseNumberError, - TronNoMyInputs, - CompanionAppProtobufError = 400, - CompanionAppInvalidParseContext, - CompanionAppSignTxFailed, - CompanionAppCheckTxFailed, - CardanoInvalidTransaction = 500, - CardanoAddressEncodingError, - SolanaAddressEncodingError = 600, - SolanaKeystoreError, - SolanaUnsupportedProgram, - SolanaInvalidData, - SolanaAccountNotFound, - SolanaProgramError, - SolanaParseTxError, - NearKeystoreError = 700, - NearSignFailure, - NearParseTxError, - XRPSignFailure = 800, - XRPInvalidData, - XRPParseTxError, - CosmosSignFailure = 900, - CosmosKeystoreError, - CosmosInvalidData, - CosmosParseTxError, - AptosSignFailure = 1000, - AptosKeystoreError, - AptosInvalidData, - AptosParseTxError, - SuiSignFailure = 1100, - SuiInvalidData, - SuiParseTxError, - ArweaveSignFailure = 1200, - ArweaveKeystoreError, - ArweaveInvalidData, - ArweaveParseTxError, - ArweaveParseAOTxError, - TonUnknownError = 1300, - TonMnemonicError, - TonTransactionError, - InvalidProof, - TonTransactionJsonError, - AddressError, - StellarAddressError = 1400, - StellarInvalidData, - StellarParseTxError, - StellarKeystoreError, - ZcashGenerateAddressError = 1500, - ZcashSigningError, - ZcashInvalidPczt, -} ErrorCodes; - -typedef enum NetworkType { - MainNet, - TestNet, -} NetworkType; - -typedef enum QRCodeType { - CryptoPSBT, - CryptoMultiAccounts, - CryptoAccount, - Bytes, - BtcSignRequest, - SeedSignerMessage, -#if defined(BUILD_MULTI_COINS) - KeystoneSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - EthSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - SolSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - NearSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoSignTxHashRequest, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoSignDataRequest, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoCatalystVotingRegistrationRequest, -#endif -#if defined(BUILD_MULTI_COINS) - CosmosSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - EvmSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - SuiSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - SuiSignHashRequest, -#endif -#if defined(BUILD_MULTI_COINS) - AptosSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - QRHardwareCall, -#endif -#if defined(BUILD_MULTI_COINS) - ArweaveSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - StellarSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - TonSignRequest, -#endif -#if defined(BUILD_MULTI_COINS) - ZcashPczt, -#endif - URTypeUnKnown, -} QRCodeType; - -typedef enum QRProtocol { - QRCodeTypeText, - QRCodeTypeUR, -} QRProtocol; - -typedef enum ViewType { - BtcNativeSegwitTx, - BtcSegwitTx, - BtcLegacyTx, - BtcTx, - BtcMsg, -#if defined(BUILD_MULTI_COINS) - LtcTx, -#endif -#if defined(BUILD_MULTI_COINS) - DashTx, -#endif -#if defined(BUILD_MULTI_COINS) - BchTx, -#endif -#if defined(BUILD_MULTI_COINS) - EthTx, -#endif -#if defined(BUILD_MULTI_COINS) - EthPersonalMessage, -#endif -#if defined(BUILD_MULTI_COINS) - EthTypedData, -#endif -#if defined(BUILD_MULTI_COINS) - TronTx, -#endif -#if defined(BUILD_MULTI_COINS) - SolanaTx, -#endif -#if defined(BUILD_MULTI_COINS) - SolanaMessage, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoTx, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoSignData, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoCatalystVotingRegistration, -#endif -#if defined(BUILD_MULTI_COINS) - CardanoSignTxHash, -#endif -#if defined(BUILD_MULTI_COINS) - NearTx, -#endif -#if defined(BUILD_MULTI_COINS) - XRPTx, -#endif -#if defined(BUILD_MULTI_COINS) - CosmosTx, -#endif -#if defined(BUILD_MULTI_COINS) - CosmosEvmTx, -#endif -#if defined(BUILD_MULTI_COINS) - SuiTx, -#endif -#if defined(BUILD_MULTI_COINS) - SuiSignMessageHash, -#endif -#if defined(BUILD_MULTI_COINS) - ArweaveTx, -#endif -#if defined(BUILD_MULTI_COINS) - ArweaveMessage, -#endif -#if defined(BUILD_MULTI_COINS) - ArweaveDataItem, -#endif -#if defined(BUILD_MULTI_COINS) - StellarTx, -#endif -#if defined(BUILD_MULTI_COINS) - StellarHash, -#endif -#if defined(BUILD_MULTI_COINS) - TonTx, -#endif -#if defined(BUILD_MULTI_COINS) - TonSignProof, -#endif -#if defined(BUILD_MULTI_COINS) - ZcashTx, -#endif -#if defined(BUILD_MULTI_COINS) - AptosTx, -#endif - WebAuthResult, -#if defined(BUILD_MULTI_COINS) - KeyDerivationRequest, -#endif - ViewTypeUnKnown, -} ViewType; - -typedef char *PtrString; - -typedef struct SimpleResponse_u8 { - uint8_t *data; - uint32_t error_code; - PtrString error_message; -} SimpleResponse_u8; - -typedef uint8_t *PtrBytes; - -typedef struct SimpleResponse_c_char { - char *data; - uint32_t error_code; - PtrString error_message; -} SimpleResponse_c_char; - -typedef struct TransactionCheckResult { - uint32_t error_code; - PtrString error_message; -} TransactionCheckResult; - -typedef struct TransactionCheckResult *Ptr_TransactionCheckResult; - -typedef void *PtrVoid; - -typedef PtrVoid PtrUR; - -typedef PtrVoid PtrDecoder; - -typedef struct URParseResult { - bool is_multi_part; - uint32_t progress; - enum ViewType t; - enum QRCodeType ur_type; - PtrUR data; - PtrDecoder decoder; - uint32_t error_code; - PtrString error_message; -} URParseResult; - -typedef struct URParseResult *PtrT_URParseResult; - -typedef struct URParseMultiResult { - bool is_complete; - enum ViewType t; - enum QRCodeType ur_type; - uint32_t progress; - PtrUR data; - uint32_t error_code; - PtrString error_message; -} URParseMultiResult; - -typedef struct URParseMultiResult *PtrT_URParseMultiResult; - -typedef PtrVoid PtrEncoder; - -typedef struct UREncodeResult { - bool is_multi_part; - char *data; - PtrEncoder encoder; - uint32_t error_code; - char *error_message; -} UREncodeResult; - -typedef struct UREncodeResult *PtrT_UREncodeResult; - -typedef struct UREncodeMultiResult { - char *data; - uint32_t error_code; - char *error_message; -} UREncodeMultiResult; - -typedef struct UREncodeMultiResult *PtrT_UREncodeMultiResult; - -typedef struct SimpleResponse_u8 *PtrT_SimpleResponse_u8; - -typedef struct SimpleResponse_c_char *PtrT_SimpleResponse_c_char; - -typedef uint8_t *PtrT_u8; - -typedef struct VecFFI_u8 { - PtrT_u8 data; - size_t size; - size_t cap; -} VecFFI_u8; - -typedef struct VecFFI_u8 *PtrT_VecFFI_u8; - -typedef struct URParseResult *Ptr_URParseResult; - -typedef struct TransactionCheckResult *PtrT_TransactionCheckResult; - -typedef const void *ConstPtrVoid; - -typedef ConstPtrVoid ConstPtrUR; - -typedef struct ExtendedPublicKey { - PtrString path; - PtrString xpub; -} ExtendedPublicKey; - -typedef struct ExtendedPublicKey *PtrT_ExtendedPublicKey; - -typedef struct CSliceFFI_ExtendedPublicKey { - PtrT_ExtendedPublicKey data; - size_t size; -} CSliceFFI_ExtendedPublicKey; - -typedef struct CSliceFFI_ExtendedPublicKey *PtrT_CSliceFFI_ExtendedPublicKey; - -typedef struct AccountConfig { - PtrString hd_path; - PtrString x_pub; - int32_t address_length; - bool is_multi_sign; -} AccountConfig; - -typedef struct CoinConfig { - bool is_active; - PtrString coin_code; - struct AccountConfig *accounts; - uint32_t accounts_length; -} CoinConfig; - -typedef struct CoinConfig *PtrT_CoinConfig; - -typedef struct UREncodeResult *Ptr_UREncodeResult; - -typedef struct CSliceFFI_ExtendedPublicKey *Ptr_CSliceFFI_ExtendedPublicKey; - -#if defined(BUILD_MULTI_COINS) -typedef struct KeyDerivationSchema { - PtrString key_path; - PtrString curve; - PtrString algo; - PtrString chain_type; - bool is_ada; -} KeyDerivationSchema; -#endif - -typedef struct KeyDerivationSchema *PtrT_KeyDerivationSchema; - -typedef struct VecFFI_KeyDerivationSchema { - PtrT_KeyDerivationSchema data; - size_t size; - size_t cap; -} VecFFI_KeyDerivationSchema; - -typedef struct VecFFI_KeyDerivationSchema *Ptr_VecFFI_KeyDerivationSchema; - -#if defined(BUILD_MULTI_COINS) -typedef struct KeyDerivationRequestData { - Ptr_VecFFI_KeyDerivationSchema schemas; -} KeyDerivationRequestData; -#endif - -typedef struct KeyDerivationRequestData *Ptr_KeyDerivationRequestData; - -#if defined(BUILD_MULTI_COINS) -typedef struct QRHardwareCallData { - PtrString call_type; - PtrString origin; - Ptr_KeyDerivationRequestData key_derivation; - PtrString version; -} QRHardwareCallData; -#endif - -typedef struct Response_QRHardwareCallData { - struct QRHardwareCallData *data; - uint32_t error_code; - PtrString error_message; -} Response_QRHardwareCallData; - -typedef struct Response_QRHardwareCallData *Ptr_Response_QRHardwareCallData; - -typedef struct Response_bool { - bool *data; - uint32_t error_code; - PtrString error_message; -} Response_bool; - -#if defined(BUILD_MULTI_COINS) -typedef struct KeplrAccount { - PtrString name; - PtrString path; - PtrString xpub; -} KeplrAccount; -#endif - -typedef struct KeplrAccount *PtrT_KeplrAccount; - -typedef struct CSliceFFI_KeplrAccount { - PtrT_KeplrAccount data; - size_t size; -} CSliceFFI_KeplrAccount; - -typedef struct CSliceFFI_KeplrAccount *PtrT_CSliceFFI_KeplrAccount; - -typedef struct Response_QRHardwareCallData *PtrT_Response_QRHardwareCallData; - -typedef struct ZcashKey { - PtrString key_text; - PtrString key_name; - uint32_t index; -} ZcashKey; - -typedef struct ZcashKey *PtrT_ZcashKey; - -typedef struct CSliceFFI_ZcashKey { - PtrT_ZcashKey data; - size_t size; -} CSliceFFI_ZcashKey; - -typedef struct CSliceFFI_ZcashKey *Ptr_CSliceFFI_ZcashKey; - -typedef struct DisplayAptosTx { - PtrString detail; - bool is_msg; -} DisplayAptosTx; - -typedef struct TransactionParseResult_DisplayAptosTx { - struct DisplayAptosTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayAptosTx; - -typedef struct TransactionParseResult_DisplayAptosTx *PtrT_TransactionParseResult_DisplayAptosTx; - -typedef struct SimpleResponse_ArweaveRequestType { - enum ArweaveRequestType *data; - uint32_t error_code; - PtrString error_message; -} SimpleResponse_ArweaveRequestType; - -typedef struct DisplayArweaveMessage { - PtrString message; - PtrString raw_message; -} DisplayArweaveMessage; - -typedef struct TransactionParseResult_DisplayArweaveMessage { - struct DisplayArweaveMessage *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayArweaveMessage; - -typedef struct TransactionParseResult_DisplayArweaveMessage *PtrT_TransactionParseResult_DisplayArweaveMessage; - -typedef struct DisplayArweaveTx { - PtrString value; - PtrString fee; - PtrString from; - PtrString to; - PtrString detail; -} DisplayArweaveTx; - -typedef struct TransactionParseResult_DisplayArweaveTx { - struct DisplayArweaveTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayArweaveTx; - -typedef struct TransactionParseResult_DisplayArweaveTx *PtrT_TransactionParseResult_DisplayArweaveTx; - -typedef struct DisplayTag { - PtrString name; - PtrString value; -} DisplayTag; - -typedef struct DisplayTag *PtrT_DisplayTag; - -typedef struct VecFFI_DisplayTag { - PtrT_DisplayTag data; - size_t size; - size_t cap; -} VecFFI_DisplayTag; - -typedef struct VecFFI_DisplayTag *Ptr_VecFFI_DisplayTag; - -typedef struct DisplayArweaveDataItem { - PtrString owner; - PtrString target; - PtrString anchor; - Ptr_VecFFI_DisplayTag tags; - PtrString data; -} DisplayArweaveDataItem; - -typedef struct TransactionParseResult_DisplayArweaveDataItem { - struct DisplayArweaveDataItem *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayArweaveDataItem; - -typedef struct TransactionParseResult_DisplayArweaveDataItem *PtrT_TransactionParseResult_DisplayArweaveDataItem; - -typedef struct DisplayArweaveAOTransfer { - PtrString from; - PtrString to; - PtrString quantity; - PtrString token_id; - Ptr_VecFFI_DisplayTag other_info; -} DisplayArweaveAOTransfer; - -typedef struct TransactionParseResult_DisplayArweaveAOTransfer { - struct DisplayArweaveAOTransfer *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayArweaveAOTransfer; - -typedef struct TransactionParseResult_DisplayArweaveAOTransfer *PtrT_TransactionParseResult_DisplayArweaveAOTransfer; - -typedef struct DisplayTxOverviewInput { - PtrString address; -} DisplayTxOverviewInput; - -typedef struct DisplayTxOverviewInput *PtrT_DisplayTxOverviewInput; - -typedef struct VecFFI_DisplayTxOverviewInput { - PtrT_DisplayTxOverviewInput data; - size_t size; - size_t cap; -} VecFFI_DisplayTxOverviewInput; - -typedef struct VecFFI_DisplayTxOverviewInput *PtrT_VecFFI_DisplayTxOverviewInput; - -typedef struct DisplayTxOverviewOutput { - PtrString address; -} DisplayTxOverviewOutput; - -typedef struct DisplayTxOverviewOutput *PtrT_DisplayTxOverviewOutput; - -typedef struct VecFFI_DisplayTxOverviewOutput { - PtrT_DisplayTxOverviewOutput data; - size_t size; - size_t cap; -} VecFFI_DisplayTxOverviewOutput; - -typedef struct VecFFI_DisplayTxOverviewOutput *PtrT_VecFFI_DisplayTxOverviewOutput; - -typedef struct DisplayTxOverview { - PtrString total_output_amount; - PtrString fee_amount; - PtrString total_output_sat; - PtrString fee_sat; - PtrT_VecFFI_DisplayTxOverviewInput from; - PtrT_VecFFI_DisplayTxOverviewOutput to; - PtrString network; - bool is_multisig; - bool fee_larger_than_amount; - PtrString sign_status; - bool need_sign; -} DisplayTxOverview; - -typedef struct DisplayTxDetailInput { - bool has_address; - PtrString address; - PtrString amount; - bool is_mine; - PtrString path; - bool is_external; -} DisplayTxDetailInput; - -typedef struct DisplayTxDetailInput *PtrT_DisplayTxDetailInput; - -typedef struct VecFFI_DisplayTxDetailInput { - PtrT_DisplayTxDetailInput data; - size_t size; - size_t cap; -} VecFFI_DisplayTxDetailInput; - -typedef struct VecFFI_DisplayTxDetailInput *PtrT_VecFFI_DisplayTxDetailInput; - -typedef struct DisplayTxDetailOutput { - PtrString address; - PtrString amount; - bool is_mine; - PtrString path; - bool is_external; -} DisplayTxDetailOutput; - -typedef struct DisplayTxDetailOutput *PtrT_DisplayTxDetailOutput; - -typedef struct VecFFI_DisplayTxDetailOutput { - PtrT_DisplayTxDetailOutput data; - size_t size; - size_t cap; -} VecFFI_DisplayTxDetailOutput; - -typedef struct VecFFI_DisplayTxDetailOutput *PtrT_VecFFI_DisplayTxDetailOutput; - -typedef struct DisplayTxDetail { - PtrString total_input_amount; - PtrString total_output_amount; - PtrString fee_amount; - PtrT_VecFFI_DisplayTxDetailInput from; - PtrT_VecFFI_DisplayTxDetailOutput to; - PtrString network; - PtrString total_input_sat; - PtrString total_output_sat; - PtrString fee_sat; - PtrString sign_status; -} DisplayTxDetail; - -typedef struct DisplayTx { - struct DisplayTxOverview *overview; - struct DisplayTxDetail *detail; -} DisplayTx; - -typedef struct TransactionParseResult_DisplayTx { - struct DisplayTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayTx; - -typedef struct DisplayBtcMsg { - PtrString detail; - PtrString address; -} DisplayBtcMsg; - -typedef struct TransactionParseResult_DisplayBtcMsg { - struct DisplayBtcMsg *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayBtcMsg; - -typedef struct TransactionParseResult_DisplayBtcMsg *Ptr_TransactionParseResult_DisplayBtcMsg; - -typedef PtrString *PtrT_PtrString; - -typedef struct VecFFI_PtrString { - PtrT_PtrString data; - size_t size; - size_t cap; -} VecFFI_PtrString; - -typedef struct VecFFI_PtrString *PtrT_VecFFI_PtrString; - -typedef struct MultiSigXPubItem { - PtrString xfp; - PtrString xpub; -} MultiSigXPubItem; - -typedef struct MultiSigXPubItem *PtrT_MultiSigXPubItem; - -typedef struct VecFFI_MultiSigXPubItem { - PtrT_MultiSigXPubItem data; - size_t size; - size_t cap; -} VecFFI_MultiSigXPubItem; - -typedef struct VecFFI_MultiSigXPubItem *PtrT_VecFFI_MultiSigXPubItem; - -typedef struct MultiSigWallet { - PtrString creator; - PtrString name; - PtrString policy; - uint32_t threshold; - uint32_t total; - PtrT_VecFFI_PtrString derivations; - PtrString format; - PtrT_VecFFI_MultiSigXPubItem xpub_items; - PtrString verify_code; - PtrString config_text; - uint32_t network; -} MultiSigWallet; - -typedef struct MultiSigWallet *PtrT_MultiSigWallet; - -typedef struct Response_MultiSigWallet { - struct MultiSigWallet *data; - uint32_t error_code; - PtrString error_message; -} Response_MultiSigWallet; - -typedef struct Response_MultiSigWallet *Ptr_Response_MultiSigWallet; - -typedef struct SimpleResponse_c_char *Ptr_SimpleResponse_c_char; - -typedef struct MultiSigXPubInfoItem { - PtrString path; - PtrString xfp; - PtrString xpub; -} MultiSigXPubInfoItem; - -typedef struct MultiSigXPubInfoItem *PtrT_MultiSigXPubInfoItem; - -typedef struct MultisigSignResult { - Ptr_UREncodeResult ur_result; - PtrString sign_status; - bool is_completed; - PtrBytes psbt_hex; - uint32_t psbt_len; -} MultisigSignResult; - -typedef struct MultisigSignResult *PtrT_MultisigSignResult; - -typedef struct PsbtSignResult { - PtrString base_str; - PtrString hex_str; - PtrT_UREncodeResult ur_result; -} PsbtSignResult; - -typedef struct Response_PsbtSignResult { - struct PsbtSignResult *data; - uint32_t error_code; - PtrString error_message; -} Response_PsbtSignResult; - -typedef struct Response_PsbtSignResult *PtrT_Response_PsbtSignResult; - -typedef struct TransactionParseResult_DisplayTx *PtrT_TransactionParseResult_DisplayTx; - -typedef struct TransactionParseResult_DisplayBtcMsg *PtrT_TransactionParseResult_DisplayBtcMsg; - -typedef struct VecFFI_PtrString *Ptr_VecFFI_PtrString; - -typedef struct DisplayCardanoSignTxHash { - PtrString network; - Ptr_VecFFI_PtrString path; - PtrString tx_hash; - Ptr_VecFFI_PtrString address_list; -} DisplayCardanoSignTxHash; - -typedef struct TransactionParseResult_DisplayCardanoSignTxHash { - struct DisplayCardanoSignTxHash *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayCardanoSignTxHash; - -typedef struct TransactionParseResult_DisplayCardanoSignTxHash *PtrT_TransactionParseResult_DisplayCardanoSignTxHash; - -typedef struct DisplayCardanoSignData { - PtrString payload; - PtrString derivation_path; - PtrString message_hash; - PtrString xpub; -} DisplayCardanoSignData; - -typedef struct TransactionParseResult_DisplayCardanoSignData { - struct DisplayCardanoSignData *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayCardanoSignData; - -typedef struct TransactionParseResult_DisplayCardanoSignData *PtrT_TransactionParseResult_DisplayCardanoSignData; - -typedef struct DisplayCardanoCatalyst { - PtrString nonce; - PtrString stake_key; - PtrString rewards; - Ptr_VecFFI_PtrString vote_keys; -} DisplayCardanoCatalyst; - -typedef struct TransactionParseResult_DisplayCardanoCatalyst { - struct DisplayCardanoCatalyst *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayCardanoCatalyst; - -typedef struct TransactionParseResult_DisplayCardanoCatalyst *PtrT_TransactionParseResult_DisplayCardanoCatalyst; - -typedef struct DisplayCardanoFrom { - PtrString address; - PtrString amount; - bool has_path; - PtrString path; -} DisplayCardanoFrom; - -typedef struct DisplayCardanoFrom *PtrT_DisplayCardanoFrom; - -typedef struct VecFFI_DisplayCardanoFrom { - PtrT_DisplayCardanoFrom data; - size_t size; - size_t cap; -} VecFFI_DisplayCardanoFrom; - -typedef struct VecFFI_DisplayCardanoFrom *PtrT_VecFFI_DisplayCardanoFrom; - -typedef struct DisplayCardanoTo { - PtrString address; - PtrString amount; - bool has_assets; - PtrString assets_text; -} DisplayCardanoTo; - -typedef struct DisplayCardanoTo *PtrT_DisplayCardanoTo; - -typedef struct VecFFI_DisplayCardanoTo { - PtrT_DisplayCardanoTo data; - size_t size; - size_t cap; -} VecFFI_DisplayCardanoTo; - -typedef struct VecFFI_DisplayCardanoTo *PtrT_VecFFI_DisplayCardanoTo; - -typedef struct DisplayCertField { - PtrString label; - PtrString value; -} DisplayCertField; - -typedef struct DisplayCertField *PtrT_DisplayCertField; - -typedef struct VecFFI_DisplayCertField { - PtrT_DisplayCertField data; - size_t size; - size_t cap; -} VecFFI_DisplayCertField; - -typedef struct VecFFI_DisplayCertField *Ptr_VecFFI_DisplayCertField; - -typedef struct DisplayCardanoCertificate { - PtrString cert_type; - Ptr_VecFFI_DisplayCertField fields; -} DisplayCardanoCertificate; - -typedef struct DisplayCardanoCertificate *PtrT_DisplayCardanoCertificate; - -typedef struct VecFFI_DisplayCardanoCertificate { - PtrT_DisplayCardanoCertificate data; - size_t size; - size_t cap; -} VecFFI_DisplayCardanoCertificate; - -typedef struct VecFFI_DisplayCardanoCertificate *Ptr_VecFFI_DisplayCardanoCertificate; - -typedef struct DisplayCardanoWithdrawal { - PtrString address; - PtrString amount; -} DisplayCardanoWithdrawal; - -typedef struct DisplayCardanoWithdrawal *PtrT_DisplayCardanoWithdrawal; - -typedef struct VecFFI_DisplayCardanoWithdrawal { - PtrT_DisplayCardanoWithdrawal data; - size_t size; - size_t cap; -} VecFFI_DisplayCardanoWithdrawal; - -typedef struct VecFFI_DisplayCardanoWithdrawal *Ptr_VecFFI_DisplayCardanoWithdrawal; - -typedef struct DisplayVotingProcedure { - PtrString voter; - PtrString transaction_id; - PtrString index; - PtrString vote; -} DisplayVotingProcedure; - -typedef struct DisplayVotingProcedure *PtrT_DisplayVotingProcedure; - -typedef struct VecFFI_DisplayVotingProcedure { - PtrT_DisplayVotingProcedure data; - size_t size; - size_t cap; -} VecFFI_DisplayVotingProcedure; - -typedef struct VecFFI_DisplayVotingProcedure *Ptr_VecFFI_DisplayVotingProcedure; - -typedef struct DisplayVotingProposal { - PtrString anchor; -} DisplayVotingProposal; - -typedef struct DisplayVotingProposal *PtrT_DisplayVotingProposal; - -typedef struct VecFFI_DisplayVotingProposal { - PtrT_DisplayVotingProposal data; - size_t size; - size_t cap; -} VecFFI_DisplayVotingProposal; - -typedef struct VecFFI_DisplayVotingProposal *Ptr_VecFFI_DisplayVotingProposal; - -typedef struct DisplayCardanoTx { - PtrT_VecFFI_DisplayCardanoFrom from; - PtrT_VecFFI_DisplayCardanoTo to; - PtrString fee; - PtrString network; - PtrString total_input; - PtrString total_output; - Ptr_VecFFI_DisplayCardanoCertificate certificates; - Ptr_VecFFI_DisplayCardanoWithdrawal withdrawals; - PtrString auxiliary_data; - Ptr_VecFFI_DisplayVotingProcedure voting_procedures; - Ptr_VecFFI_DisplayVotingProposal voting_proposals; -} DisplayCardanoTx; - -typedef struct TransactionParseResult_DisplayCardanoTx { - struct DisplayCardanoTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayCardanoTx; - -typedef struct TransactionParseResult_DisplayCardanoTx *PtrT_TransactionParseResult_DisplayCardanoTx; - -typedef struct DisplayCosmosTxOverview { - PtrString display_type; - PtrString method; - PtrString network; - PtrString send_value; - PtrString send_from; - PtrString send_to; - PtrString delegate_value; - PtrString delegate_from; - PtrString delegate_to; - PtrString undelegate_value; - PtrString undelegate_to; - PtrString undelegate_validator; - PtrString redelegate_value; - PtrString redelegate_to; - PtrString redelegate_new_validator; - PtrString withdraw_reward_to; - PtrString withdraw_reward_validator; - PtrString transfer_from; - PtrString transfer_to; - PtrString transfer_value; - PtrString vote_voted; - PtrString vote_proposal; - PtrString vote_voter; - PtrString overview_list; -} DisplayCosmosTxOverview; - -typedef struct DisplayCosmosTxOverview *PtrT_DisplayCosmosTxOverview; - -typedef struct DisplayCosmosTx { - PtrT_DisplayCosmosTxOverview overview; - PtrString detail; -} DisplayCosmosTx; - -typedef struct TransactionParseResult_DisplayCosmosTx { - struct DisplayCosmosTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayCosmosTx; - -typedef struct TransactionParseResult_DisplayCosmosTx *PtrT_TransactionParseResult_DisplayCosmosTx; - -typedef struct DisplayETHOverview { - PtrString value; - PtrString max_txn_fee; - PtrString gas_price; - PtrString gas_limit; - PtrString from; - PtrString to; -} DisplayETHOverview; - -typedef struct DisplayETHOverview *PtrT_DisplayETHOverview; - -typedef struct DisplayETHDetail { - PtrString value; - PtrString max_txn_fee; - PtrString max_fee; - PtrString max_priority; - PtrString max_fee_price; - PtrString max_priority_price; - PtrString gas_price; - PtrString gas_limit; - PtrString from; - PtrString to; - PtrString input; -} DisplayETHDetail; - -typedef struct DisplayETHDetail *PtrT_DisplayETHDetail; - -typedef struct DisplayETH { - PtrString tx_type; - uint64_t chain_id; - PtrT_DisplayETHOverview overview; - PtrT_DisplayETHDetail detail; -} DisplayETH; - -typedef struct TransactionParseResult_DisplayETH { - struct DisplayETH *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayETH; - -typedef struct TransactionParseResult_DisplayETH *PtrT_TransactionParseResult_DisplayETH; - -typedef struct DisplayETHPersonalMessage { - PtrString raw_message; - PtrString utf8_message; - PtrString from; -} DisplayETHPersonalMessage; - -typedef struct TransactionParseResult_DisplayETHPersonalMessage { - struct DisplayETHPersonalMessage *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayETHPersonalMessage; - -typedef struct TransactionParseResult_DisplayETHPersonalMessage *PtrT_TransactionParseResult_DisplayETHPersonalMessage; - -typedef struct DisplayETHTypedData { - PtrString name; - PtrString version; - PtrString chain_id; - PtrString verifying_contract; - PtrString salt; - PtrString primary_type; - PtrString message; - PtrString from; -} DisplayETHTypedData; - -typedef struct TransactionParseResult_DisplayETHTypedData { - struct DisplayETHTypedData *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayETHTypedData; - -typedef struct TransactionParseResult_DisplayETHTypedData *PtrT_TransactionParseResult_DisplayETHTypedData; - -typedef struct EthParsedErc20Transaction { - PtrString to; - PtrString value; -} EthParsedErc20Transaction; - -typedef struct TransactionParseResult_EthParsedErc20Transaction { - struct EthParsedErc20Transaction *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_EthParsedErc20Transaction; - -typedef struct TransactionParseResult_EthParsedErc20Transaction *PtrT_TransactionParseResult_EthParsedErc20Transaction; - -typedef struct DisplayContractParam { - PtrString name; - PtrString value; -} DisplayContractParam; - -typedef struct DisplayContractParam *PtrT_DisplayContractParam; - -typedef struct VecFFI_DisplayContractParam { - PtrT_DisplayContractParam data; - size_t size; - size_t cap; -} VecFFI_DisplayContractParam; - -typedef struct VecFFI_DisplayContractParam *PtrT_VecFFI_DisplayContractParam; - -typedef struct DisplayContractData { - PtrString contract_name; - PtrString method_name; - PtrT_VecFFI_DisplayContractParam params; -} DisplayContractData; - -typedef struct Response_DisplayContractData { - struct DisplayContractData *data; - uint32_t error_code; - PtrString error_message; -} Response_DisplayContractData; - -typedef struct Response_DisplayContractData *Ptr_Response_DisplayContractData; - -typedef struct Response_DisplayContractData *PtrT_Response_DisplayContractData; - -typedef struct DisplayNearTxOverviewGeneralAction { - PtrString action; -} DisplayNearTxOverviewGeneralAction; - -typedef struct DisplayNearTxOverviewGeneralAction *PtrT_DisplayNearTxOverviewGeneralAction; - -typedef struct VecFFI_DisplayNearTxOverviewGeneralAction { - PtrT_DisplayNearTxOverviewGeneralAction data; - size_t size; - size_t cap; -} VecFFI_DisplayNearTxOverviewGeneralAction; - -typedef struct VecFFI_DisplayNearTxOverviewGeneralAction *PtrT_VecFFI_DisplayNearTxOverviewGeneralAction; - -typedef struct DisplayNearTxOverview { - PtrString display_type; - PtrString main_action; - PtrString transfer_value; - PtrString transfer_from; - PtrString transfer_to; - PtrT_VecFFI_DisplayNearTxOverviewGeneralAction action_list; -} DisplayNearTxOverview; - -typedef struct DisplayNearTxOverview *PtrT_DisplayNearTxOverview; - -typedef struct DisplayNearTx { - PtrString network; - PtrT_DisplayNearTxOverview overview; - PtrString detail; -} DisplayNearTx; - -typedef struct TransactionParseResult_DisplayNearTx { - struct DisplayNearTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayNearTx; - -typedef struct TransactionParseResult_DisplayNearTx *PtrT_TransactionParseResult_DisplayNearTx; - -typedef struct DisplaySolanaTxOverviewVotesOn { - PtrString slot; -} DisplaySolanaTxOverviewVotesOn; - -typedef struct DisplaySolanaTxOverviewVotesOn *PtrT_DisplaySolanaTxOverviewVotesOn; - -typedef struct VecFFI_DisplaySolanaTxOverviewVotesOn { - PtrT_DisplaySolanaTxOverviewVotesOn data; - size_t size; - size_t cap; -} VecFFI_DisplaySolanaTxOverviewVotesOn; - -typedef struct VecFFI_DisplaySolanaTxOverviewVotesOn *PtrT_VecFFI_DisplaySolanaTxOverviewVotesOn; - -typedef struct DisplaySolanaTxOverviewGeneral { - PtrString program; - PtrString method; -} DisplaySolanaTxOverviewGeneral; - -typedef struct DisplaySolanaTxOverviewGeneral *PtrT_DisplaySolanaTxOverviewGeneral; - -typedef struct VecFFI_DisplaySolanaTxOverviewGeneral { - PtrT_DisplaySolanaTxOverviewGeneral data; - size_t size; - size_t cap; -} VecFFI_DisplaySolanaTxOverviewGeneral; - -typedef struct VecFFI_DisplaySolanaTxOverviewGeneral *PtrT_VecFFI_DisplaySolanaTxOverviewGeneral; - -typedef struct Instruction { - PtrT_VecFFI_PtrString accounts; - PtrString data; - PtrString program_address; -} Instruction; - -typedef struct Instruction *PtrT_Instruction; - -typedef struct VecFFI_Instruction { - PtrT_Instruction data; - size_t size; - size_t cap; -} VecFFI_Instruction; - -typedef struct VecFFI_Instruction *PtrT_VecFFI_Instruction; - -typedef struct DisplaySolanaTxOverviewUnknownInstructions { - PtrT_VecFFI_PtrString overview_accounts; - PtrT_VecFFI_Instruction overview_instructions; -} DisplaySolanaTxOverviewUnknownInstructions; - -typedef struct DisplaySolanaTxOverviewUnknownInstructions *PtrT_DisplaySolanaTxOverviewUnknownInstructions; - -typedef struct ProgramOverviewTransfer { - PtrString value; - PtrString main_action; - PtrString from; - PtrString to; -} ProgramOverviewTransfer; - -typedef struct ProgramOverviewTransfer *PtrT_ProgramOverviewTransfer; - -typedef struct VecFFI_ProgramOverviewTransfer { - PtrT_ProgramOverviewTransfer data; - size_t size; - size_t cap; -} VecFFI_ProgramOverviewTransfer; - -typedef struct VecFFI_ProgramOverviewTransfer *PtrT_VecFFI_ProgramOverviewTransfer; - -typedef struct DisplaySolanaTxOverviewSquadsV4MultisigCreate { - PtrString wallet_name; - PtrString wallet_desc; - uint16_t threshold; - uintptr_t member_count; - PtrT_VecFFI_PtrString members; - PtrString total_value; - PtrT_VecFFI_ProgramOverviewTransfer transfers; -} DisplaySolanaTxOverviewSquadsV4MultisigCreate; - -typedef struct DisplaySolanaTxOverviewSquadsV4MultisigCreate *PtrT_DisplaySolanaTxOverviewSquadsV4MultisigCreate; - -typedef struct DisplaySolanaTxProposalOverview { - PtrString program; - PtrString method; - PtrString memo; - PtrString data; -} DisplaySolanaTxProposalOverview; - -typedef struct DisplaySolanaTxProposalOverview *PtrT_DisplaySolanaTxProposalOverview; - -typedef struct VecFFI_DisplaySolanaTxProposalOverview { - PtrT_DisplaySolanaTxProposalOverview data; - size_t size; - size_t cap; -} VecFFI_DisplaySolanaTxProposalOverview; - -typedef struct VecFFI_DisplaySolanaTxProposalOverview *PtrT_VecFFI_DisplaySolanaTxProposalOverview; - -typedef struct DisplaySolanaTxSplTokenTransferOverview { - PtrString source; - PtrString destination; - PtrString authority; - uint8_t decimals; - PtrString amount; - PtrString token_mint_account; - PtrString token_symbol; - PtrString token_name; -} DisplaySolanaTxSplTokenTransferOverview; - -typedef struct DisplaySolanaTxSplTokenTransferOverview *PtrT_DisplaySolanaTxSplTokenTransferOverview; - -typedef struct JupiterV6SwapTokenInfoOverview { - PtrString token_name; - PtrString token_symbol; - PtrString token_address; - PtrString token_amount; - bool exist_in_address_lookup_table; -} JupiterV6SwapTokenInfoOverview; - -typedef struct JupiterV6SwapTokenInfoOverview *PtrT_JupiterV6SwapTokenInfoOverview; - -typedef struct DisplaySolanaTxOverviewJupiterV6Swap { - PtrString program_name; - PtrString program_address; - PtrString instruction_name; - PtrT_JupiterV6SwapTokenInfoOverview token_a_overview; - PtrT_JupiterV6SwapTokenInfoOverview token_b_overview; - PtrString slippage_bps; - PtrString platform_fee_bps; -} DisplaySolanaTxOverviewJupiterV6Swap; - -typedef struct DisplaySolanaTxOverviewJupiterV6Swap *PtrT_DisplaySolanaTxOverviewJupiterV6Swap; - -typedef struct DisplaySolanaTxOverview { - PtrString display_type; - PtrString main_action; - PtrString transfer_value; - PtrString transfer_from; - PtrString transfer_to; - PtrT_VecFFI_DisplaySolanaTxOverviewVotesOn votes_on; - PtrString vote_account; - PtrT_VecFFI_DisplaySolanaTxOverviewGeneral general; - PtrT_DisplaySolanaTxOverviewUnknownInstructions unknown_instructions; - PtrT_DisplaySolanaTxOverviewSquadsV4MultisigCreate squads_multisig_create; - PtrT_VecFFI_DisplaySolanaTxProposalOverview squads_proposal; - PtrT_DisplaySolanaTxSplTokenTransferOverview spl_token_transfer; - PtrT_DisplaySolanaTxOverviewJupiterV6Swap jupiter_v6_swap; -} DisplaySolanaTxOverview; - -typedef struct DisplaySolanaTxOverview *PtrT_DisplaySolanaTxOverview; - -typedef struct DisplaySolanaTx { - PtrString network; - PtrT_DisplaySolanaTxOverview overview; - PtrString detail; -} DisplaySolanaTx; - -typedef struct TransactionParseResult_DisplaySolanaTx { - struct DisplaySolanaTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplaySolanaTx; - -typedef struct TransactionParseResult_DisplaySolanaTx *PtrT_TransactionParseResult_DisplaySolanaTx; - -typedef struct DisplaySolanaMessage { - PtrString raw_message; - PtrString utf8_message; - PtrString from; -} DisplaySolanaMessage; - -typedef struct TransactionParseResult_DisplaySolanaMessage { - struct DisplaySolanaMessage *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplaySolanaMessage; - -typedef struct TransactionParseResult_DisplaySolanaMessage *PtrT_TransactionParseResult_DisplaySolanaMessage; - -typedef struct DisplayStellarTx { - PtrString raw_message; -} DisplayStellarTx; - -typedef struct TransactionParseResult_DisplayStellarTx { - struct DisplayStellarTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayStellarTx; - -typedef struct TransactionParseResult_DisplayStellarTx *PtrT_TransactionParseResult_DisplayStellarTx; - -typedef struct DisplaySuiIntentMessage { - PtrString detail; -} DisplaySuiIntentMessage; - -typedef struct TransactionParseResult_DisplaySuiIntentMessage { - struct DisplaySuiIntentMessage *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplaySuiIntentMessage; - -typedef struct TransactionParseResult_DisplaySuiIntentMessage *PtrT_TransactionParseResult_DisplaySuiIntentMessage; - -typedef struct DisplaySuiSignMessageHash { - PtrString network; - PtrString path; - PtrString from_address; - PtrString message; -} DisplaySuiSignMessageHash; - -typedef struct TransactionParseResult_DisplaySuiSignMessageHash { - struct DisplaySuiSignMessageHash *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplaySuiSignMessageHash; - -typedef struct TransactionParseResult_DisplaySuiSignMessageHash *PtrT_TransactionParseResult_DisplaySuiSignMessageHash; - -typedef struct DisplayTonTransaction { - PtrString amount; - PtrString action; - PtrString to; - PtrString comment; - PtrString data_view; - PtrString raw_data; - PtrString contract_data; -} DisplayTonTransaction; - -typedef struct TransactionParseResult_DisplayTonTransaction { - struct DisplayTonTransaction *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayTonTransaction; - -typedef struct TransactionParseResult_DisplayTonTransaction *PtrT_TransactionParseResult_DisplayTonTransaction; - -typedef struct DisplayTonProof { - PtrString domain; - PtrString payload; - PtrString address; - PtrString raw_message; -} DisplayTonProof; - -typedef struct TransactionParseResult_DisplayTonProof { - struct DisplayTonProof *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayTonProof; - -typedef struct TransactionParseResult_DisplayTonProof *PtrT_TransactionParseResult_DisplayTonProof; - -typedef struct VecFFI_u8 *Ptr_VecFFI_u8; - -typedef struct DisplayTronOverview { - PtrString value; - PtrString method; - PtrString from; - PtrString to; - PtrString network; -} DisplayTronOverview; - -typedef struct DisplayTronDetail { - PtrString value; - PtrString method; - PtrString from; - PtrString to; - PtrString network; - PtrString token; - PtrString contract_address; -} DisplayTronDetail; - -typedef struct DisplayTron { - struct DisplayTronOverview *overview; - struct DisplayTronDetail *detail; -} DisplayTron; - -typedef struct TransactionParseResult_DisplayTron { - struct DisplayTron *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayTron; - -typedef struct TransactionParseResult_DisplayTron *PtrT_TransactionParseResult_DisplayTron; - -typedef struct DisplayXrpTxOverview { - PtrString display_type; - PtrString transaction_type; - PtrString from; - PtrString fee; - PtrString sequence; - PtrString value; - PtrString to; -} DisplayXrpTxOverview; - -typedef struct DisplayXrpTxOverview *PtrT_DisplayXrpTxOverview; - -typedef struct DisplayXrpTx { - PtrString network; - PtrT_DisplayXrpTxOverview overview; - PtrString detail; - PtrString signing_pubkey; -} DisplayXrpTx; - -typedef struct TransactionParseResult_DisplayXrpTx { - struct DisplayXrpTx *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayXrpTx; - -typedef struct TransactionParseResult_DisplayXrpTx *PtrT_TransactionParseResult_DisplayXrpTx; - -typedef struct DisplayFrom { - PtrString address; - PtrString value; - bool is_mine; -} DisplayFrom; - -typedef struct DisplayFrom *PtrT_DisplayFrom; - -typedef struct VecFFI_DisplayFrom { - PtrT_DisplayFrom data; - size_t size; - size_t cap; -} VecFFI_DisplayFrom; - -typedef struct VecFFI_DisplayFrom *Ptr_VecFFI_DisplayFrom; - -typedef struct DisplayTo { - PtrString address; - PtrString value; - bool is_change; - PtrString memo; -} DisplayTo; - -typedef struct DisplayTo *PtrT_DisplayTo; - -typedef struct VecFFI_DisplayTo { - PtrT_DisplayTo data; - size_t size; - size_t cap; -} VecFFI_DisplayTo; - -typedef struct VecFFI_DisplayTo *Ptr_VecFFI_DisplayTo; - -typedef struct DisplayTransparent { - Ptr_VecFFI_DisplayFrom from; - Ptr_VecFFI_DisplayTo to; -} DisplayTransparent; - -typedef struct DisplayTransparent *Ptr_DisplayTransparent; - -typedef struct DisplayOrchard { - Ptr_VecFFI_DisplayFrom from; - Ptr_VecFFI_DisplayTo to; -} DisplayOrchard; - -typedef struct DisplayOrchard *Ptr_DisplayOrchard; - -typedef struct DisplayPczt { - Ptr_DisplayTransparent transparent; - Ptr_DisplayOrchard orchard; - PtrString total_transfer_value; - PtrString fee_value; - bool has_sapling; -} DisplayPczt; - -typedef struct TransactionParseResult_DisplayPczt { - struct DisplayPczt *data; - uint32_t error_code; - PtrString error_message; -} TransactionParseResult_DisplayPczt; - -typedef struct TransactionParseResult_DisplayPczt *Ptr_TransactionParseResult_DisplayPczt; - -typedef struct TransactionParseResult_DisplayPczt *PtrT_TransactionParseResult_DisplayPczt; - -extern const uintptr_t FRAGMENT_MAX_LENGTH_DEFAULT; - -extern void LogRustMalloc(void *p, uint32_t size); - -extern void LogRustFree(void *p); - -extern void LogRustPanic(char *p); - -extern int32_t GenerateTRNGRandomness(uint8_t *randomness, uint8_t len); - -extern void *RustMalloc(int32_t size); - -extern void RustFree(void *p); - -struct SimpleResponse_u8 *get_master_fingerprint(PtrBytes seed, uint32_t seed_len); - -enum ErrorCodes dummy_function_to_export_error_codes(void); - -struct SimpleResponse_c_char *get_extended_pubkey_by_seed(PtrBytes seed, - uint32_t seed_len, - PtrString path); - -struct SimpleResponse_c_char *get_extended_pubkey_bytes_by_seed(PtrBytes seed, - uint32_t seed_len, - PtrString path); - -struct SimpleResponse_c_char *get_ed25519_pubkey_by_seed(PtrBytes seed, - uint32_t seed_len, - PtrString path); - -struct SimpleResponse_u8 *get_rsa_pubkey_by_seed(PtrBytes seed, uint32_t seed_len); - -struct SimpleResponse_c_char *get_bip32_ed25519_extended_pubkey(PtrBytes entropy, - uint32_t entropy_len, - PtrString passphrase, - PtrString path); - -struct SimpleResponse_c_char *get_ledger_bitbox02_master_key(PtrString mnemonic, - PtrString passphrase); - -struct SimpleResponse_c_char *get_icarus_master_key(PtrBytes entropy, - uint32_t entropy_len, - PtrString passphrase); - -struct SimpleResponse_c_char *derive_bip32_ed25519_extended_pubkey(PtrString master_key, - PtrString path); - -struct SimpleResponse_c_char *k1_sign_message_hash_by_private_key(PtrBytes private_key, - PtrBytes message_hash); - -bool k1_verify_signature(PtrBytes signature, PtrBytes message_hash, PtrBytes public_key); - -struct SimpleResponse_u8 *k1_generate_ecdh_sharekey(PtrBytes privkey, - uint32_t privkey_len, - PtrBytes pubkey, - uint32_t pubkey_len); - -struct SimpleResponse_u8 *k1_generate_pubkey_by_privkey(PtrBytes privkey, uint32_t privkey_len); - -struct SimpleResponse_u8 *pbkdf2_rust(PtrBytes password, PtrBytes salt, uint32_t iterations); - -struct SimpleResponse_u8 *pbkdf2_rust_64(PtrBytes password, PtrBytes salt, uint32_t iterations); - -Ptr_TransactionCheckResult tx_check_pass(void); - -struct SimpleResponse_c_char *rust_aes256_cbc_encrypt(PtrString data, - PtrString password, - PtrBytes iv, - uint32_t iv_len); - -struct SimpleResponse_c_char *rust_aes256_cbc_decrypt(PtrString hex_data, - PtrString password, - PtrBytes iv, - uint32_t iv_len); - -struct SimpleResponse_u8 *rust_derive_iv_from_seed(PtrBytes seed, uint32_t seed_len); - -void free_ur_parse_result(PtrT_URParseResult ur_parse_result); - -void free_ur_parse_multi_result(PtrT_URParseMultiResult ptr); - -void free_ur_encode_result(PtrT_UREncodeResult ptr); - -void free_ur_encode_muilt_result(PtrT_UREncodeMultiResult ptr); - -void free_simple_response_u8(PtrT_SimpleResponse_u8 ptr); - -void free_simple_response_c_char(PtrT_SimpleResponse_c_char ptr); - -void free_ptr_string(PtrString ptr); - -void free_rust_value(void *any_ptr); - -void free_VecFFI_u8(PtrT_VecFFI_u8 ptr); - -enum QRProtocol infer_qrcode_type(PtrString qrcode); - -Ptr_URParseResult parse_qrcode_text(PtrString qr); - -void free_TransactionCheckResult(PtrT_TransactionCheckResult ptr); - -struct UREncodeMultiResult *get_next_part(PtrEncoder ptr); - -struct URParseResult *parse_ur(PtrString ur); - -struct URParseMultiResult *receive(PtrString ur, PtrDecoder decoder); - -PtrString calculate_auth_code(ConstPtrUR web_auth_data, - PtrBytes rsa_key_n, - uint32_t rsa_key_n_len, - PtrBytes rsa_key_d, - uint32_t rsa_key_d_len); - -struct UREncodeResult *get_connect_blue_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); - -struct UREncodeResult *get_connect_sparrow_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); - -struct UREncodeResult *get_connect_specter_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); - -PtrT_UREncodeResult get_connect_companion_app_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - int32_t cold_version, - PtrT_CoinConfig coin_config, - uint32_t coin_config_length); - -Ptr_UREncodeResult get_okx_wallet_ur_btc_only(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString serial_number, - Ptr_CSliceFFI_ExtendedPublicKey public_keys, - PtrString device_type, - PtrString device_version); - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_metamask_ur_dynamic(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - enum ETHAccountType account_type, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - uintptr_t fragment_max_length_default, - uintptr_t fragment_max_length_other); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_metamask_ur_unlimited(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - enum ETHAccountType account_type, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_metamask_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - enum ETHAccountType account_type, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_Response_QRHardwareCallData parse_qr_hardware_call(PtrUR ur); -#endif - -#if defined(BUILD_MULTI_COINS) -struct Response_bool *check_hardware_call_path(PtrString path, PtrString chain_type); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult generate_key_derivation_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - Ptr_CSliceFFI_ExtendedPublicKey xpubs, - PtrString device_version); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_aptos_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_connect_arconnect_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrBytes p, - uint32_t p_len, - PtrBytes q, - uint32_t q_len); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_connect_arconnect_wallet_ur_from_xpub(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString xpub); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_backpack_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - Ptr_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_bitget_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString serial_number, - Ptr_CSliceFFI_ExtendedPublicKey public_keys, - PtrString device_type, - PtrString device_version); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_connect_imtoken_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString xpub, - PtrString wallet_name); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_keplr_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrT_CSliceFFI_KeplrAccount keplr_accounts); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_keystone_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString serial_number, - Ptr_CSliceFFI_ExtendedPublicKey public_keys, - PtrString device_type, - PtrString device_version); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_okx_wallet_ur(PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString serial_number, - Ptr_CSliceFFI_ExtendedPublicKey public_keys, - PtrString device_type, - PtrString device_version); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_solana_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -void free_Response_QRHardwareCallData(PtrT_Response_QRHardwareCallData ptr); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_sui_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -Ptr_UREncodeResult get_tonkeeper_wallet_ur(PtrString public_key, - PtrString wallet_name, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_length, - PtrString path); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_xbull_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_xrp_toolkit_ur(PtrString hd_path, - PtrString root_x_pub, - PtrString root_path); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_zcash_wallet_ur(PtrBytes seed_fingerprint, - uint32_t seed_fingerprint_len, - Ptr_CSliceFFI_ZcashKey zcash_keys); -#endif - -#if defined(BUILD_MULTI_COINS) -struct UREncodeResult *get_connect_thor_wallet_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrString serial_number, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - PtrString device_type, - PtrString device_version); -#endif - -struct SimpleResponse_c_char *aptos_generate_address(PtrString pub_key); - -PtrT_TransactionCheckResult aptos_check_request(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length); - -PtrT_TransactionParseResult_DisplayAptosTx aptos_parse(PtrUR ptr); - -PtrT_UREncodeResult aptos_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len, PtrString pub_key); - -PtrString aptos_get_path(PtrUR ptr); - -struct SimpleResponse_c_char *test_aptos_parse(void); - -void free_TransactionParseResult_DisplayAptosTx(PtrT_TransactionParseResult_DisplayAptosTx ptr); - -struct SimpleResponse_u8 *generate_arweave_secret(PtrBytes seed, uint32_t seed_len); - -struct SimpleResponse_u8 *generate_arweave_public_key_from_primes(PtrBytes p, - uint32_t p_len, - PtrBytes q, - uint32_t q_len); - -struct SimpleResponse_c_char *generate_rsa_public_key(PtrBytes p, - uint32_t p_len, - PtrBytes q, - uint32_t q_len); - -struct SimpleResponse_u8 *aes256_encrypt_primes(PtrBytes seed, uint32_t seed_len, PtrBytes data); - -struct SimpleResponse_u8 *aes256_decrypt_primes(PtrBytes seed, uint32_t seed_len, PtrBytes data); - -struct SimpleResponse_c_char *arweave_get_address(PtrString xpub); - -struct SimpleResponse_c_char *fix_arweave_address(PtrString address); - -PtrT_TransactionCheckResult ar_check_tx(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); - -struct SimpleResponse_ArweaveRequestType *ar_request_type(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayArweaveMessage ar_message_parse(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayArweaveTx ar_parse(PtrUR ptr); - -PtrT_UREncodeResult ar_sign_tx(PtrUR ptr, PtrBytes p, uint32_t p_len, PtrBytes q, uint32_t q_len); - -bool ar_is_ao_transfer(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayArweaveDataItem ar_parse_data_item(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayArweaveAOTransfer ar_parse_ao_transfer(PtrUR ptr); - -void free_TransactionParseResult_DisplayArweaveTx(PtrT_TransactionParseResult_DisplayArweaveTx ptr); - -void free_TransactionParseResult_DisplayArweaveMessage(PtrT_TransactionParseResult_DisplayArweaveMessage ptr); - -struct SimpleResponse_c_char *utxo_get_address(PtrString hd_path, PtrString x_pub); - -struct SimpleResponse_c_char *xpub_convert_version(PtrString x_pub, PtrString target); - -struct TransactionParseResult_DisplayTx *utxo_parse_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub); - -struct UREncodeResult *utxo_sign_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub, - int32_t cold_version, - PtrBytes seed, - uint32_t seed_len); - -PtrT_TransactionCheckResult utxo_check_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub); - -PtrT_TransactionCheckResult btc_check_msg(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); - -struct TransactionParseResult_DisplayBtcMsg *btc_parse_msg(PtrUR ptr, - Ptr_CSliceFFI_ExtendedPublicKey xpubs, - PtrBytes master_fingerprint, - uint32_t length); - -struct UREncodeResult *btc_sign_msg(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -Ptr_TransactionParseResult_DisplayBtcMsg parse_seed_signer_message(PtrUR ptr, - Ptr_CSliceFFI_ExtendedPublicKey xpubs); - -struct UREncodeResult *sign_seed_signer_message(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -struct UREncodeResult *export_multi_sig_xpub_by_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - enum NetworkType network); - -struct UREncodeResult *export_multi_sig_wallet_by_ur_test(uint8_t *master_fingerprint, - uint32_t length, - PtrT_MultiSigWallet multi_sig_wallet); - -struct UREncodeResult *export_multi_sig_wallet_by_ur(uint8_t *master_fingerprint, - uint32_t length, - PtrString config); - -Ptr_Response_MultiSigWallet import_multi_sig_wallet_by_ur(PtrUR ur, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -Ptr_Response_MultiSigWallet import_multi_sig_wallet_by_file(PtrString content, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -Ptr_SimpleResponse_c_char generate_address_for_multisig_wallet_config(PtrString wallet_config, - uint32_t account, - uint32_t index, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -Ptr_SimpleResponse_c_char generate_psbt_file_name(PtrBytes psbt_hex, - uint32_t psbt_len, - uint32_t time_stamp); - -Ptr_Response_MultiSigWallet parse_and_verify_multisig_config(PtrBytes seed, - uint32_t seed_len, - PtrString wallet_config, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -void free_MultiSigXPubInfoItem(PtrT_MultiSigXPubInfoItem ptr); - -void free_MultiSigWallet(PtrT_MultiSigWallet ptr); - -void free_MultisigSignResult(PtrT_MultisigSignResult ptr); - -struct TransactionParseResult_DisplayTx *btc_parse_psbt(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - PtrString multisig_wallet_config); - -struct UREncodeResult *btc_sign_psbt(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -struct UREncodeResult *btc_sign_psbt_unlimited(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -struct MultisigSignResult *btc_sign_multisig_psbt(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -struct MultisigSignResult *btc_export_multisig_psbt(PtrUR ptr); - -struct MultisigSignResult *btc_export_multisig_psbt_bytes(PtrBytes psbt_bytes, - uint32_t psbt_bytes_length); - -PtrT_TransactionCheckResult btc_check_psbt(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - PtrString verify_code, - PtrString multisig_wallet_config); - -PtrT_TransactionCheckResult btc_check_psbt_bytes(PtrBytes psbt_bytes, - uint32_t psbt_bytes_length, - PtrBytes master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - PtrString verify_code, - PtrString multisig_wallet_config); - -struct TransactionParseResult_DisplayTx *btc_parse_psbt_bytes(PtrBytes psbt_bytes, - uint32_t psbt_bytes_length, - PtrBytes master_fingerprint, - uint32_t length, - PtrT_CSliceFFI_ExtendedPublicKey public_keys, - PtrString multisig_wallet_config); - -struct MultisigSignResult *btc_sign_multisig_psbt_bytes(PtrBytes psbt_bytes, - uint32_t psbt_bytes_length, - PtrBytes seed, - uint32_t seed_len, - PtrBytes master_fingerprint, - uint32_t master_fingerprint_len); - -void free_Response_PsbtSignResult(PtrT_Response_PsbtSignResult ptr); - -void free_TransactionParseResult_DisplayTx(PtrT_TransactionParseResult_DisplayTx ptr); - -void free_TransactionParseResult_DisplayBtcMsg(PtrT_TransactionParseResult_DisplayBtcMsg ptr); - -Ptr_SimpleResponse_c_char cardano_catalyst_xpub(PtrUR ptr); - -PtrT_TransactionCheckResult cardano_check_catalyst(PtrUR ptr, PtrBytes master_fingerprint); - -PtrT_TransactionCheckResult cardano_check_catalyst_path_type(PtrUR ptr, PtrString cardano_xpub); - -Ptr_SimpleResponse_c_char cardano_get_catalyst_root_index(PtrUR ptr); - -Ptr_SimpleResponse_c_char cardano_get_sign_data_root_index(PtrUR ptr); - -PtrT_TransactionCheckResult cardano_check_sign_data_path_type(PtrUR ptr, PtrString cardano_xpub); - -PtrT_TransactionCheckResult cardano_check_sign_data(PtrUR ptr, PtrBytes master_fingerprint); - -PtrT_TransactionCheckResult cardano_check_tx(PtrUR ptr, - PtrBytes master_fingerprint, - PtrString cardano_xpub); - -PtrT_TransactionCheckResult cardano_check_tx_hash(PtrUR ptr, PtrBytes master_fingerprint); - -PtrT_TransactionParseResult_DisplayCardanoSignTxHash cardano_parse_sign_tx_hash(PtrUR ptr); - -Ptr_SimpleResponse_c_char cardano_get_path(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayCardanoSignData cardano_parse_sign_data(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayCardanoCatalyst cardano_parse_catalyst(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayCardanoTx cardano_parse_tx(PtrUR ptr, - PtrBytes master_fingerprint, - PtrString cardano_xpub); - -PtrT_UREncodeResult cardano_sign_catalyst_with_ledger_bitbox02(PtrUR ptr, - PtrString mnemonic, - PtrString passphrase); - -PtrT_UREncodeResult cardano_sign_catalyst(PtrUR ptr, - PtrBytes entropy, - uint32_t entropy_len, - PtrString passphrase); - -PtrT_UREncodeResult cardano_sign_sign_data_with_ledger_bitbox02(PtrUR ptr, - PtrString mnemonic, - PtrString passphrase); - -PtrT_UREncodeResult cardano_sign_sign_data(PtrUR ptr, - PtrBytes entropy, - uint32_t entropy_len, - PtrString passphrase); - -PtrT_UREncodeResult cardano_sign_tx_with_ledger_bitbox02(PtrUR ptr, - PtrBytes master_fingerprint, - PtrString cardano_xpub, - PtrString mnemonic, - PtrString passphrase, - bool enable_blind_sign); - -PtrT_UREncodeResult cardano_sign_tx(PtrUR ptr, - PtrBytes master_fingerprint, - PtrString cardano_xpub, - PtrBytes entropy, - uint32_t entropy_len, - PtrString passphrase, - bool enable_blind_sign); - -struct SimpleResponse_c_char *cardano_get_base_address(PtrString xpub, - uint32_t index, - uint8_t network_id); - -struct SimpleResponse_c_char *cardano_get_enterprise_address(PtrString xpub, - uint32_t index, - uint8_t network_id); - -struct SimpleResponse_c_char *cardano_get_stake_address(PtrString xpub, - uint32_t index, - uint8_t network_id); - -void free_TransactionParseResult_DisplayCardanoTx(PtrT_TransactionParseResult_DisplayCardanoTx ptr); - -void free_TransactionParseResult_DisplayCardanoCatalyst(PtrT_TransactionParseResult_DisplayCardanoCatalyst ptr); - -void free_TransactionParseResult_DisplayCardanoSignData(PtrT_TransactionParseResult_DisplayCardanoSignData ptr); - -void free_TransactionParseResult_DisplayCardanoSignTxHash(PtrT_TransactionParseResult_DisplayCardanoSignTxHash ptr); - -PtrT_TransactionCheckResult cosmos_check_tx(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length); - -struct SimpleResponse_c_char *cosmos_get_address(PtrString hd_path, - PtrString root_x_pub, - PtrString root_path, - PtrString prefix); - -PtrT_UREncodeResult cosmos_sign_tx(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes seed, - uint32_t seed_len); - -PtrT_TransactionParseResult_DisplayCosmosTx cosmos_parse_tx(PtrUR ptr, enum QRCodeType ur_type); - -void free_TransactionParseResult_DisplayCosmosTx(PtrT_TransactionParseResult_DisplayCosmosTx ptr); - -PtrT_TransactionCheckResult eth_check_ur_bytes(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length, - enum QRCodeType ur_type); - -PtrT_TransactionCheckResult eth_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); - -PtrString eth_get_root_path_bytes(PtrUR ptr); - -PtrString eth_get_root_path(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayETH eth_parse_bytes_data(PtrUR ptr, PtrString xpub); - -PtrT_TransactionParseResult_DisplayETH eth_parse(PtrUR ptr, PtrString xpub); - -PtrT_TransactionParseResult_DisplayETHPersonalMessage eth_parse_personal_message(PtrUR ptr, - PtrString xpub); - -PtrT_TransactionParseResult_DisplayETHTypedData eth_parse_typed_data(PtrUR ptr, PtrString xpub); - -PtrT_UREncodeResult eth_sign_tx_dynamic(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - uintptr_t fragment_length); - -PtrT_UREncodeResult eth_sign_tx_bytes(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes mfp, - uint32_t mfp_len); - -PtrT_UREncodeResult eth_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -PtrT_UREncodeResult eth_sign_tx_unlimited(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -PtrT_TransactionParseResult_EthParsedErc20Transaction eth_parse_erc20(PtrString input, - uint32_t decimal); - -Ptr_Response_DisplayContractData eth_parse_contract_data(PtrString input_data, - PtrString contract_json); - -Ptr_Response_DisplayContractData eth_parse_contract_data_by_method(PtrString input_data, - PtrString contract_name, - PtrString contract_method_json); - -struct SimpleResponse_c_char *eth_get_address(PtrString hd_path, - PtrString root_x_pub, - PtrString root_path); - -void free_TransactionParseResult_DisplayETH(PtrT_TransactionParseResult_DisplayETH ptr); - -void free_TransactionParseResult_DisplayETHPersonalMessage(PtrT_TransactionParseResult_DisplayETHPersonalMessage ptr); - -void free_TransactionParseResult_DisplayETHTypedData(PtrT_TransactionParseResult_DisplayETHTypedData ptr); - -void free_Response_DisplayContractData(PtrT_Response_DisplayContractData ptr); - -void free_TransactionParseResult_EthParsedErc20Transaction(PtrT_TransactionParseResult_EthParsedErc20Transaction ptr); - -PtrT_TransactionCheckResult near_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); - -PtrT_TransactionParseResult_DisplayNearTx near_parse_tx(PtrUR ptr); - -PtrT_UREncodeResult near_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -void free_TransactionParseResult_DisplayNearTx(PtrT_TransactionParseResult_DisplayNearTx ptr); - -struct SimpleResponse_c_char *solana_get_address(PtrString pubkey); - -PtrT_TransactionCheckResult solana_check(PtrUR ptr, PtrBytes master_fingerprint, uint32_t length); - -PtrT_TransactionParseResult_DisplaySolanaTx solana_parse_tx(PtrUR ptr); - -PtrT_UREncodeResult solana_sign_tx(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -PtrT_TransactionParseResult_DisplaySolanaMessage solana_parse_message(PtrUR ptr, PtrString pubkey); - -PtrString sol_get_path(PtrUR ptr); - -void free_TransactionParseResult_DisplaySolanaTx(PtrT_TransactionParseResult_DisplaySolanaTx ptr); - -void free_TransactionParseResult_DisplaySolanaMessage(PtrT_TransactionParseResult_DisplaySolanaMessage ptr); - -struct SimpleResponse_c_char *stellar_get_address(PtrString pubkey); - -PtrT_TransactionParseResult_DisplayStellarTx stellar_parse(PtrUR ptr); - -PtrT_TransactionCheckResult stellar_check_tx(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length); - -PtrT_UREncodeResult stellar_sign(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -void free_TransactionParseResult_DisplayStellarTx(PtrT_TransactionParseResult_DisplayStellarTx ptr); - -PtrT_TransactionCheckResult sui_check_request(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length); - -PtrT_TransactionCheckResult sui_check_sign_hash_request(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length); - -struct SimpleResponse_c_char *sui_generate_address(PtrString pub_key); - -PtrT_TransactionParseResult_DisplaySuiIntentMessage sui_parse_intent(PtrUR ptr); - -PtrT_TransactionParseResult_DisplaySuiSignMessageHash sui_parse_sign_message_hash(PtrUR ptr); - -PtrT_UREncodeResult sui_sign_hash(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -PtrT_UREncodeResult sui_sign_intent(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -void free_TransactionParseResult_DisplaySuiIntentMessage(PtrT_TransactionParseResult_DisplaySuiIntentMessage ptr); - -void free_TransactionParseResult_DisplaySuiSignMessageHash(PtrT_TransactionParseResult_DisplaySuiSignMessageHash ptr); - -PtrT_TransactionParseResult_DisplayTonTransaction ton_parse_transaction(PtrUR ptr); - -PtrT_TransactionParseResult_DisplayTonProof ton_parse_proof(PtrUR ptr); - -PtrT_TransactionCheckResult ton_check_transaction(PtrUR ptr, PtrString public_key); - -PtrT_TransactionCheckResult ton_not_supported_error(void); - -PtrT_UREncodeResult ton_sign_transaction(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -PtrT_UREncodeResult ton_sign_proof(PtrUR ptr, PtrBytes seed, uint32_t seed_len); - -bool ton_verify_mnemonic(PtrString mnemonic); - -Ptr_VecFFI_u8 ton_mnemonic_to_entropy(PtrString mnemonic); - -struct SimpleResponse_u8 *ton_entropy_to_seed(PtrBytes entropy, uint32_t entropy_len); - -struct SimpleResponse_u8 *ton_mnemonic_to_seed(PtrString mnemonic); - -struct SimpleResponse_c_char *ton_seed_to_publickey(PtrBytes seed, uint32_t seed_len); - -struct SimpleResponse_c_char *ton_get_address(PtrString public_key); - -void free_TransactionParseResult_DisplayTonTransaction(PtrT_TransactionParseResult_DisplayTonTransaction ptr); - -void free_TransactionParseResult_DisplayTonProof(PtrT_TransactionParseResult_DisplayTonProof ptr); - -PtrT_TransactionCheckResult tron_check_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub); - -struct TransactionParseResult_DisplayTron *tron_parse_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub); - -struct UREncodeResult *tron_sign_keystone(PtrUR ptr, - enum QRCodeType ur_type, - PtrBytes master_fingerprint, - uint32_t length, - PtrString x_pub, - int32_t cold_version, - PtrBytes seed, - uint32_t seed_len); - -struct SimpleResponse_c_char *tron_get_address(PtrString hd_path, PtrString x_pub); - -void free_TransactionParseResult_DisplayTron(PtrT_TransactionParseResult_DisplayTron ptr); - -struct SimpleResponse_c_char *xrp_get_address(PtrString hd_path, - PtrString root_x_pub, - PtrString root_path); - -PtrT_TransactionParseResult_DisplayXrpTx xrp_parse_tx(PtrUR ptr); - -PtrT_UREncodeResult xrp_sign_tx_bytes(PtrUR ptr, - PtrBytes seed, - uint32_t seed_len, - PtrBytes mfp, - uint32_t mfp_len, - PtrString root_xpub); - -PtrT_UREncodeResult xrp_sign_tx(PtrUR ptr, PtrString hd_path, PtrBytes seed, uint32_t seed_len); - -PtrT_TransactionCheckResult xrp_check_tx(PtrUR ptr, PtrString root_xpub, PtrString cached_pubkey); - -bool is_keystone_xrp_tx(PtrUR ur_data_ptr); - -PtrT_TransactionCheckResult xrp_check_tx_bytes(PtrUR ptr, - PtrBytes master_fingerprint, - uint32_t length, - enum QRCodeType ur_type); - -PtrT_TransactionParseResult_DisplayXrpTx xrp_parse_bytes_tx(PtrUR ptr); - -void free_TransactionParseResult_DisplayXrpTx(PtrT_TransactionParseResult_DisplayXrpTx ptr); - -struct SimpleResponse_c_char *derive_zcash_ufvk(PtrBytes seed, - uint32_t seed_len, - PtrString account_path); - -struct SimpleResponse_u8 *calculate_zcash_seed_fingerprint(PtrBytes seed, uint32_t seed_len); - -struct SimpleResponse_c_char *generate_zcash_default_address(PtrString ufvk_text); - -struct TransactionCheckResult *check_zcash_tx(PtrUR tx, - PtrString ufvk, - PtrBytes seed_fingerprint, - uint32_t account_index, - bool disabled); - -Ptr_TransactionParseResult_DisplayPczt parse_zcash_tx(PtrUR tx, - PtrString ufvk, - PtrBytes seed_fingerprint); - -struct UREncodeResult *sign_zcash_tx(PtrUR tx, PtrBytes seed, uint32_t seed_len); - -void free_TransactionParseResult_DisplayPczt(PtrT_TransactionParseResult_DisplayPczt ptr); - -#endif /* _LIBRUST_C_H */ diff --git a/rust/rust_c/src/common/errors.rs b/rust/rust_c/src/common/errors.rs index 22a81a7e3..e9f921201 100644 --- a/rust/rust_c/src/common/errors.rs +++ b/rust/rust_c/src/common/errors.rs @@ -1,35 +1,37 @@ use alloc::string::String; +use keystore::errors::KeystoreError; +use thiserror; +use thiserror::Error; +use ur_registry::error::URError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "bitcoin")] +use app_bitcoin::errors::BitcoinError; +#[cfg(feature = "aptos")] use app_aptos::errors::AptosError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "arweave")] use app_arweave::errors::ArweaveError; -use app_bitcoin::errors::BitcoinError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] use app_cardano::errors::CardanoError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] use app_cosmos::errors::CosmosError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] use app_ethereum::errors::EthereumError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "near")] use app_near::errors::NearError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] use app_solana::errors::SolanaError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] use app_stellar::errors::StellarError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] use app_sui::errors::SuiError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ton")] use app_ton::errors::TonError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "tron")] use app_tron::errors::TronError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "xrp")] use app_xrp::errors::XRPError; +#[cfg(feature = "zcash")] use app_zcash::errors::ZcashError; -use keystore::errors::KeystoreError; -use thiserror; -use thiserror::Error; -use ur_registry::error::URError; #[derive(Debug, Clone)] #[repr(C)] @@ -293,7 +295,7 @@ impl From<&RustCError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] impl From<&EthereumError> for ErrorCodes { fn from(value: &EthereumError) -> Self { match value { @@ -329,7 +331,7 @@ impl From<&KeystoreError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] impl From<&CardanoError> for ErrorCodes { fn from(value: &CardanoError) -> Self { match value { @@ -342,7 +344,7 @@ impl From<&CardanoError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] impl From<&SolanaError> for ErrorCodes { fn from(value: &SolanaError) -> Self { match value { @@ -357,7 +359,7 @@ impl From<&SolanaError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "near")] impl From<&NearError> for ErrorCodes { fn from(value: &NearError) -> Self { match value { @@ -369,7 +371,7 @@ impl From<&NearError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "arweave")] impl From<&ArweaveError> for ErrorCodes { fn from(value: &ArweaveError) -> Self { match value { @@ -384,7 +386,7 @@ impl From<&ArweaveError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] impl From<&StellarError> for ErrorCodes { fn from(value: &StellarError) -> Self { match value { @@ -396,7 +398,7 @@ impl From<&StellarError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] impl From<&CosmosError> for ErrorCodes { fn from(value: &CosmosError) -> Self { match value { @@ -410,7 +412,7 @@ impl From<&CosmosError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "aptos")] impl From<&AptosError> for ErrorCodes { fn from(value: &AptosError) -> Self { match value { @@ -422,7 +424,7 @@ impl From<&AptosError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "tron")] impl From<&TronError> for ErrorCodes { fn from(value: &TronError) -> Self { match value { @@ -439,7 +441,7 @@ impl From<&TronError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "xrp")] impl From<&XRPError> for ErrorCodes { fn from(value: &XRPError) -> Self { match value { @@ -452,7 +454,7 @@ impl From<&XRPError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] impl From<&SuiError> for ErrorCodes { fn from(value: &SuiError) -> Self { match value { @@ -464,7 +466,7 @@ impl From<&SuiError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ton")] impl From<&TonError> for ErrorCodes { fn from(value: &TonError) -> Self { match value { @@ -479,7 +481,7 @@ impl From<&TonError> for ErrorCodes { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "zcash")] impl From<&ZcashError> for ErrorCodes { fn from(value: &ZcashError) -> Self { match value { diff --git a/rust/rust_c/src/common/keystone.rs b/rust/rust_c/src/common/keystone.rs index beba14975..9f2deba7a 100644 --- a/rust/rust_c/src/common/keystone.rs +++ b/rust/rust_c/src/common/keystone.rs @@ -72,12 +72,13 @@ fn get_signed_tx( seed: &[u8], ) -> Result<(String, String), KeystoneError> { build_parse_context(master_fingerprint, x_pub).and_then(|context| { + #[cfg(feature = "bitcoin")] if app_bitcoin::network::Network::from_str(coin_code.as_str()).is_ok() { return app_bitcoin::sign_raw_tx(payload, context, seed) .map_err(|e| KeystoneError::SignTxFailed(e.to_string())); } match coin_code.as_str() { - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] "TRON" => app_tron::sign_raw_tx(payload, context, seed) .map_err(|e| KeystoneError::SignTxFailed(e.to_string())), _ => Err(KeystoneError::SignTxFailed(format!( @@ -99,6 +100,7 @@ pub fn build_check_result( match payload_content { Some(payload::Content::SignTx(sign_tx_content)) => { build_parse_context(master_fingerprint, x_pub).and_then(|context| { + #[cfg(feature = "bitcoin")] if app_bitcoin::network::Network::from_str(sign_tx_content.coin_code.as_str()) .is_ok() { @@ -106,7 +108,7 @@ pub fn build_check_result( .map_err(|e| KeystoneError::CheckTxFailed(e.to_string())); } match sign_tx_content.coin_code.as_str() { - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] "TRON" => app_tron::check_raw_tx(payload, context) .map_err(|e| KeystoneError::CheckTxFailed(e.to_string())), _ => Err(KeystoneError::CheckTxFailed(format!( diff --git a/rust/rust_c/src/common/macros.rs b/rust/rust_c/src/common/macros.rs index 50338ed0c..01b62cc4a 100644 --- a/rust/rust_c/src/common/macros.rs +++ b/rust/rust_c/src/common/macros.rs @@ -79,13 +79,6 @@ macro_rules! impl_new_error { } } } - - impl From for $name { - fn from(value: BitcoinError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } - impl From for $name { fn from(value: URError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) @@ -97,91 +90,95 @@ macro_rules! impl_new_error { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] - impl From for $name { - fn from(value: EthereumError) -> Self { + impl From for $name { + fn from(value: KeystoreError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - impl From for $name { - fn from(value: KeystoreError) -> Self { + impl From for $name { + fn from(value: super::errors::KeystoneError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + #[cfg(feature = "bitcoin")] + impl From for $name { + fn from(value: app_bitcoin::errors::BitcoinError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + #[cfg(feature = "ethereum")] + impl From for $name { + fn from(value: app_ethereum::errors::EthereumError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] impl From for $name { fn from(value: app_tron::errors::TronError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] impl From for $name { fn from(value: app_solana::errors::SolanaError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] impl From for $name { fn from(value: app_near::errors::NearError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] impl From for $name { fn from(value: app_aptos::errors::AptosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - impl From for $name { - fn from(value: super::errors::KeystoneError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] impl From for $name { fn from(value: app_cosmos::errors::CosmosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] impl From for $name { fn from(value: app_xrp::errors::XRPError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] impl From for $name { fn from(value: app_sui::errors::SuiError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] impl From for $name { fn from(value: app_cardano::errors::CardanoError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] impl From for $name { fn from(value: app_arweave::errors::ArweaveError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] impl From for $name { fn from(value: app_stellar::errors::StellarError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] impl From for $name { fn from(value: app_ton::errors::TonError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] impl From for $name { fn from(value: app_zcash::errors::ZcashError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) @@ -201,12 +198,6 @@ macro_rules! impl_new_error { } } - impl<$t: Free> From for $name<$t> { - fn from(value: BitcoinError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } - impl<$t: Free> From for $name<$t> { fn from(value: URError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) @@ -218,91 +209,97 @@ macro_rules! impl_new_error { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] - impl<$t: Free> From for $name<$t> { - fn from(value: EthereumError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } impl<$t: Free> From for $name<$t> { fn from(value: KeystoreError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + impl<$t: Free> From for $name<$t> { + fn from(value: super::errors::KeystoneError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + #[cfg(feature = "bitcoin")] + impl<$t: Free> From for $name<$t> { + fn from(value: app_bitcoin::errors::BitcoinError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + #[cfg(feature = "ethereum")] + impl<$t: Free> From for $name<$t> { + fn from(value: app_ethereum::errors::EthereumError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + + #[cfg(feature = "tron")] impl<$t: Free> From for $name<$t> { fn from(value: app_tron::errors::TronError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] impl<$t: Free> From for $name<$t> { fn from(value: app_solana::errors::SolanaError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] impl<$t: Free> From for $name<$t> { fn from(value: app_near::errors::NearError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] impl<$t: Free> From for $name<$t> { fn from(value: app_cosmos::errors::CosmosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] impl<$t: Free> From for $name<$t> { fn from(value: app_xrp::errors::XRPError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] impl<$t: Free> From for $name<$t> { fn from(value: app_aptos::errors::AptosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - impl<$t: Free> From for $name<$t> { - fn from(value: super::errors::KeystoneError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] impl<$t: Free> From for $name<$t> { fn from(value: app_sui::errors::SuiError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] impl<$t: Free> From for $name<$t> { fn from(value: app_cardano::errors::CardanoError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] impl<$t: Free> From for $name<$t> { fn from(value: app_arweave::errors::ArweaveError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] impl<$t: Free> From for $name<$t> { fn from(value: app_stellar::errors::StellarError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] impl<$t: Free> From for $name<$t> { fn from(value: app_ton::errors::TonError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] impl<$t: Free> From for $name<$t> { fn from(value: app_zcash::errors::ZcashError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) @@ -324,103 +321,100 @@ macro_rules! impl_simple_new_error { } } } - - impl<$t> From for $name<$t> { - fn from(value: BitcoinError) -> Self { + impl<$t> From for $name<$t> { + fn from(value: KeystoreError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - impl<$t> From for $name<$t> { - fn from(value: KeystoreError) -> Self { + impl<$t> From for $name<$t> { + fn from(value: RustCError) -> Self { + Self::error(ErrorCodes::from(&value), value.to_string()) + } + } + #[cfg(feature = "bitcoin")] + impl<$t> From for $name<$t> { + fn from(value: app_bitcoin::errors::BitcoinError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] - impl<$t> From for $name<$t> { - fn from(value: EthereumError) -> Self { + #[cfg(feature = "ethereum")] + impl<$t> From for $name<$t> { + fn from(value: app_ethereum::errors::EthereumError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] impl<$t> From for $name<$t> { fn from(value: app_tron::errors::TronError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] impl<$t> From for $name<$t> { fn from(value: app_solana::errors::SolanaError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] impl<$t> From for $name<$t> { fn from(value: app_near::errors::NearError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] impl<$t> From for $name<$t> { fn from(value: app_aptos::errors::AptosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] impl<$t> From for $name<$t> { fn from(value: app_xrp::errors::XRPError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] impl<$t> From for $name<$t> { fn from(value: app_cosmos::errors::CosmosError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] impl<$t> From for $name<$t> { fn from(value: app_sui::errors::SuiError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] impl<$t> From for $name<$t> { fn from(value: app_cardano::errors::CardanoError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] impl<$t> From for $name<$t> { fn from(value: app_arweave::errors::ArweaveError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] impl<$t> From for $name<$t> { fn from(value: app_stellar::errors::StellarError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] impl<$t> From for $name<$t> { fn from(value: app_ton::errors::TonError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] impl<$t> From for $name<$t> { fn from(value: app_zcash::errors::ZcashError) -> Self { Self::error(ErrorCodes::from(&value), value.to_string()) } } - - impl<$t> From for $name<$t> { - fn from(value: RustCError) -> Self { - Self::error(ErrorCodes::from(&value), value.to_string()) - } - } }; } diff --git a/rust/rust_c/src/common/structs.rs b/rust/rust_c/src/common/structs.rs index 144b3f333..8e1d32a64 100644 --- a/rust/rust_c/src/common/structs.rs +++ b/rust/rust_c/src/common/structs.rs @@ -4,9 +4,6 @@ use super::errors::ErrorCodes; use super::errors::RustCError; use alloc::boxed::Box; use alloc::string::{String, ToString}; -use app_bitcoin::errors::BitcoinError; -#[cfg(feature = "multi-coins")] -use app_ethereum::errors::EthereumError; use core::ptr::null_mut; use cstr_core::CString; use keystore::errors::KeystoreError; diff --git a/rust/rust_c/src/common/ur.rs b/rust/rust_c/src/common/ur.rs index 3ee8a875e..280a5c7ac 100644 --- a/rust/rust_c/src/common/ur.rs +++ b/rust/rust_c/src/common/ur.rs @@ -3,15 +3,7 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; use core::ptr::null_mut; -#[cfg(feature = "multi-coins")] -use ur_registry::aptos::aptos_sign_request::AptosSignRequest; -#[cfg(feature = "multi-coins")] -use ur_registry::extend::qr_hardware_call::QRHardwareCall; -use ur_registry::zcash::zcash_pczt::ZcashPczt; -use app_bitcoin::errors::BitcoinError; -#[cfg(feature = "multi-coins")] -use app_ethereum::errors::EthereumError; use cstr_core::CString; use cty::c_char; use keystore::errors::KeystoreError; @@ -20,44 +12,52 @@ use ur_parse_lib::keystone_ur_decoder::{ URParseResult as InnerParseResult, }; use ur_parse_lib::keystone_ur_encoder::KeystoneUREncoder; -#[cfg(feature = "multi-coins")] -use ur_registry::arweave::arweave_sign_request::ArweaveSignRequest; use ur_registry::bytes::Bytes; -#[cfg(feature = "multi-coins")] +use ur_registry::error::{URError, URResult}; +use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; +use ur_registry::registry_types::URType as InnerURType; +use ur_registry::traits::RegistryItem; + +#[cfg(feature = "aptos")] +use ur_registry::aptos::aptos_sign_request::AptosSignRequest; +#[cfg(feature = "arweave")] +use ur_registry::arweave::arweave_sign_request::ArweaveSignRequest; +#[cfg(feature = "bitcoin")] +use ur_registry::bitcoin::btc_sign_request::BtcSignRequest; +#[cfg(feature = "cardano")] use ur_registry::cardano::{ cardano_catalyst_voting_registration::CardanoCatalystVotingRegistrationRequest, cardano_sign_data_request::CardanoSignDataRequest, cardano_sign_request::CardanoSignRequest, + cardano_sign_tx_hash_request::CardanoSignTxHashRequest, }; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] use ur_registry::cosmos::cosmos_sign_request::CosmosSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] use ur_registry::cosmos::evm_sign_request::EvmSignRequest; +#[cfg(feature = "bitcoin")] use ur_registry::crypto_account::CryptoAccount; +#[cfg(feature = "bitcoin")] use ur_registry::crypto_psbt::CryptoPSBT; -use ur_registry::error::{URError, URResult}; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] use ur_registry::ethereum::eth_sign_request::EthSignRequest; -use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; #[cfg(feature = "multi-coins")] -use ur_registry::keystone::keystone_sign_request::KeystoneSignRequest; +use ur_registry::extend::qr_hardware_call::QRHardwareCall; #[cfg(feature = "multi-coins")] +use ur_registry::keystone::keystone_sign_request::KeystoneSignRequest; +#[cfg(feature = "near")] use ur_registry::near::near_sign_request::NearSignRequest; -use ur_registry::registry_types::URType as InnerURType; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] use ur_registry::solana::sol_sign_request::SolSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] use ur_registry::stellar::stellar_sign_request::StellarSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] use ur_registry::sui::sui_sign_hash_request::SuiSignHashRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] use ur_registry::sui::sui_sign_request::SuiSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ton")] use ur_registry::ton::ton_sign_request::TonSignRequest; -use ur_registry::traits::RegistryItem; -use ur_registry::{ - bitcoin::btc_sign_request::BtcSignRequest, - cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest, -}; +#[cfg(feature = "zcash")] +use ur_registry::zcash::zcash_pczt::ZcashPczt; use super::errors::{ErrorCodes, RustCError}; use super::free::Free; @@ -186,67 +186,72 @@ impl_response!(UREncodeMultiResult); #[repr(C)] #[derive(Debug, Eq, PartialEq)] pub enum ViewType { + #[cfg(feature = "bitcoin")] BtcNativeSegwitTx, + #[cfg(feature = "bitcoin")] BtcSegwitTx, + #[cfg(feature = "bitcoin")] BtcLegacyTx, + #[cfg(feature = "bitcoin")] BtcTx, + #[cfg(feature = "bitcoin")] BtcMsg, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ltc")] LtcTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "dash")] DashTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "bch")] BchTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] EthTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] EthPersonalMessage, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] EthTypedData, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] TronTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] SolanaTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] SolanaMessage, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoSignData, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoCatalystVotingRegistration, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoSignTxHash, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] NearTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] XRPTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] CosmosTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] CosmosEvmTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] SuiTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] SuiSignMessageHash, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] ArweaveTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] ArweaveMessage, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] ArweaveDataItem, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] StellarTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] StellarHash, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] TonTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] TonSignProof, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] ZcashTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] AptosTx, WebAuthResult, #[cfg(feature = "multi-coins")] @@ -262,48 +267,51 @@ pub enum ViewType { #[repr(C)] pub enum QRCodeType { + #[cfg(feature = "bitcoin")] CryptoPSBT, CryptoMultiAccounts, + #[cfg(feature = "bitcoin")] CryptoAccount, Bytes, + #[cfg(feature = "bitcoin")] BtcSignRequest, SeedSignerMessage, #[cfg(feature = "multi-coins")] KeystoneSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] EthSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] SolSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] NearSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoSignTxHashRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoSignDataRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] CardanoCatalystVotingRegistrationRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] CosmosSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] EvmSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] SuiSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] SuiSignHashRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] AptosSignRequest, #[cfg(feature = "multi-coins")] QRHardwareCall, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] ArweaveSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] StellarSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] TonSignRequest, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] ZcashPczt, URTypeUnKnown, } @@ -311,46 +319,49 @@ pub enum QRCodeType { impl QRCodeType { pub fn from(value: &InnerURType) -> Result { match value { + #[cfg(feature = "bitcoin")] InnerURType::CryptoPsbt(_) => Ok(QRCodeType::CryptoPSBT), InnerURType::CryptoMultiAccounts(_) => Ok(QRCodeType::CryptoMultiAccounts), + #[cfg(feature = "bitcoin")] InnerURType::CryptoAccount(_) => Ok(QRCodeType::CryptoAccount), InnerURType::Bytes(_) => Ok(QRCodeType::Bytes), + #[cfg(feature = "bitcoin")] InnerURType::BtcSignRequest(_) => Ok(QRCodeType::BtcSignRequest), #[cfg(feature = "multi-coins")] InnerURType::KeystoneSignRequest(_) => Ok(QRCodeType::KeystoneSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] InnerURType::EthSignRequest(_) => Ok(QRCodeType::EthSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] InnerURType::SolSignRequest(_) => Ok(QRCodeType::SolSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] InnerURType::NearSignRequest(_) => Ok(QRCodeType::NearSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] InnerURType::CosmosSignRequest(_) => Ok(QRCodeType::CosmosSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] InnerURType::EvmSignRequest(_) => Ok(QRCodeType::EvmSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] InnerURType::SuiSignRequest(_) => Ok(QRCodeType::SuiSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] InnerURType::SuiSignHashRequest(_) => Ok(QRCodeType::SuiSignHashRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] InnerURType::StellarSignRequest(_) => Ok(QRCodeType::StellarSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] InnerURType::ArweaveSignRequest(_) => Ok(QRCodeType::ArweaveSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] InnerURType::AptosSignRequest(_) => Ok(QRCodeType::AptosSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] InnerURType::CardanoSignRequest(_) => Ok(QRCodeType::CardanoSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] InnerURType::CardanoSignTxHashRequest(_) => Ok(QRCodeType::CardanoSignTxHashRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] InnerURType::CardanoSignDataRequest(_) => Ok(QRCodeType::CardanoSignDataRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] InnerURType::CardanoCatalystVotingRegistrationRequest(_) => { Ok(QRCodeType::CardanoCatalystVotingRegistrationRequest) } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] InnerURType::TonSignRequest(_) => Ok(QRCodeType::TonSignRequest), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] InnerURType::ZcashPczt(_) => Ok(QRCodeType::ZcashPczt), #[cfg(feature = "multi-coins")] InnerURType::QRHardwareCall(_) => Ok(QRCodeType::QRHardwareCall), @@ -426,30 +437,33 @@ impl Free for URParseResult { fn free_ur(ur_type: &QRCodeType, data: PtrUR) { match ur_type { + #[cfg(feature = "bitcoin")] QRCodeType::CryptoPSBT => { free_ptr_with_type!(data, CryptoPSBT); } QRCodeType::CryptoMultiAccounts => { free_ptr_with_type!(data, CryptoMultiAccounts); } + #[cfg(feature = "bitcoin")] QRCodeType::CryptoAccount => { free_ptr_with_type!(data, CryptoAccount); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EthSignRequest => { free_ptr_with_type!(data, EthSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] QRCodeType::SolSignRequest => { free_ptr_with_type!(data, SolSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] QRCodeType::NearSignRequest => { free_ptr_with_type!(data, NearSignRequest); } QRCodeType::Bytes => { free_ptr_with_type!(data, Bytes); } + #[cfg(feature = "bitcoin")] QRCodeType::BtcSignRequest => { free_ptr_with_type!(data, BtcSignRequest); } @@ -457,49 +471,48 @@ fn free_ur(ur_type: &QRCodeType, data: PtrUR) { QRCodeType::KeystoneSignRequest => { free_ptr_with_type!(data, KeystoneSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] QRCodeType::CosmosSignRequest => { free_ptr_with_type!(data, CosmosSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EvmSignRequest => { free_ptr_with_type!(data, EvmSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignRequest => { free_ptr_with_type!(data, SuiSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignHashRequest => { free_ptr_with_type!(data, SuiSignHashRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] QRCodeType::StellarSignRequest => { free_ptr_with_type!(data, StellarSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] QRCodeType::ArweaveSignRequest => { free_ptr_with_type!(data, ArweaveSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] QRCodeType::AptosSignRequest => { free_ptr_with_type!(data, AptosSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignRequest => { free_ptr_with_type!(data, CardanoSignRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignDataRequest => { free_ptr_with_type!(data, CardanoSignDataRequest); } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignTxHashRequest => { free_ptr_with_type!(data, CardanoSignTxHashRequest); } - - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoCatalystVotingRegistrationRequest => { free_ptr_with_type!(data, CardanoCatalystVotingRegistrationRequest); } @@ -624,49 +637,52 @@ pub fn decode_ur(ur: String) -> URParseResult { }; match ur_type { + #[cfg(feature = "bitcoin")] QRCodeType::CryptoPSBT => _decode_ur::(ur, ur_type), + #[cfg(feature = "bitcoin")] QRCodeType::CryptoAccount => _decode_ur::(ur, ur_type), QRCodeType::CryptoMultiAccounts => _decode_ur::(ur, ur_type), QRCodeType::Bytes => _decode_ur::(ur, ur_type), + #[cfg(feature = "bitcoin")] QRCodeType::BtcSignRequest => _decode_ur::(ur, ur_type), #[cfg(feature = "multi-coins")] QRCodeType::KeystoneSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EthSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] QRCodeType::SolSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] QRCodeType::NearSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignTxHashRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignDataRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoCatalystVotingRegistrationRequest => { _decode_ur::(ur, ur_type) } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] QRCodeType::CosmosSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EvmSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignHashRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] QRCodeType::StellarSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] QRCodeType::ArweaveSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] QRCodeType::AptosSignRequest => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] QRCodeType::TonSignRequest => _decode_ur::(ur, ur_type), + #[cfg(feature = "zcash")] + QRCodeType::ZcashPczt => _decode_ur::(ur, ur_type), #[cfg(feature = "multi-coins")] QRCodeType::QRHardwareCall => _decode_ur::(ur, ur_type), - #[cfg(feature = "multi-coins")] - QRCodeType::ZcashPczt => _decode_ur::(ur, ur_type), QRCodeType::URTypeUnKnown | QRCodeType::SeedSignerMessage => URParseResult::from( URError::NotSupportURTypeError("UnKnown ur type".to_string()), ), @@ -711,53 +727,55 @@ fn receive_ur(ur: String, decoder: &mut KeystoneURDecoder) -> URParseMultiResult Err(e) => return URParseMultiResult::from(e), }; match ur_type { + #[cfg(feature = "bitcoin")] QRCodeType::CryptoPSBT => _receive_ur::(ur, ur_type, decoder), + #[cfg(feature = "bitcoin")] QRCodeType::CryptoAccount => _receive_ur::(ur, ur_type, decoder), QRCodeType::CryptoMultiAccounts => _receive_ur::(ur, ur_type, decoder), QRCodeType::Bytes => _receive_ur::(ur, ur_type, decoder), + #[cfg(feature = "bitcoin")] QRCodeType::BtcSignRequest => _receive_ur::(ur, ur_type, decoder), #[cfg(feature = "multi-coins")] QRCodeType::KeystoneSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EthSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "solana")] QRCodeType::SolSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "near")] QRCodeType::NearSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignTxHashRequest => { _receive_ur::(ur, ur_type, decoder) } - - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoSignDataRequest => { _receive_ur::(ur, ur_type, decoder) } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cardano")] QRCodeType::CardanoCatalystVotingRegistrationRequest => { _receive_ur::(ur, ur_type, decoder) } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "cosmos")] QRCodeType::CosmosSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] QRCodeType::EvmSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "sui")] QRCodeType::SuiSignHashRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "arweave")] QRCodeType::ArweaveSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "stellar")] QRCodeType::StellarSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "aptos")] QRCodeType::AptosSignRequest => _receive_ur::(ur, ur_type, decoder), #[cfg(feature = "multi-coins")] QRCodeType::QRHardwareCall => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ton")] QRCodeType::TonSignRequest => _receive_ur::(ur, ur_type, decoder), - #[cfg(feature = "multi-coins")] + #[cfg(feature = "zcash")] QRCodeType::ZcashPczt => _receive_ur::(ur, ur_type, decoder), QRCodeType::URTypeUnKnown | QRCodeType::SeedSignerMessage => URParseMultiResult::from( URError::NotSupportURTypeError("UnKnown ur type".to_string()), diff --git a/rust/rust_c/src/common/ur_ext.rs b/rust/rust_c/src/common/ur_ext.rs index c7c21d95a..5add8ae8d 100644 --- a/rust/rust_c/src/common/ur_ext.rs +++ b/rust/rust_c/src/common/ur_ext.rs @@ -3,51 +3,55 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; use serde_json::{from_slice, from_value, Value}; + +use ur_registry::bytes::Bytes; +use ur_registry::crypto_account::CryptoAccount; +use ur_registry::crypto_psbt::CryptoPSBT; +use ur_registry::error::URError; +use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; +use ur_registry::pb::protobuf_parser::{parse_protobuf, unzip}; +use ur_registry::pb::protoc; +use ur_registry::pb::protoc::Base; #[cfg(feature = "multi-coins")] +use ur_registry::extend::qr_hardware_call::{CallType, QRHardwareCall}; +#[cfg(feature = "aptos")] use ur_registry::aptos::aptos_sign_request::AptosSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "arweave")] use ur_registry::arweave::arweave_sign_request::{ArweaveSignRequest, SignType}; -use ur_registry::bytes::Bytes; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "bitcoin")] +use ur_registry::bitcoin::btc_sign_request::BtcSignRequest; +#[cfg(feature = "cardano")] use ur_registry::cardano::cardano_catalyst_voting_registration::CardanoCatalystVotingRegistrationRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] use ur_registry::cardano::cardano_sign_data_request::CardanoSignDataRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] use ur_registry::cardano::cardano_sign_request::CardanoSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] use ur_registry::cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] use ur_registry::cosmos::cosmos_sign_request::CosmosSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] use ur_registry::cosmos::evm_sign_request::EvmSignRequest; -use ur_registry::crypto_account::CryptoAccount; -use ur_registry::crypto_psbt::CryptoPSBT; -use ur_registry::error::URError; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] use ur_registry::ethereum::eth_sign_request; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] use ur_registry::ethereum::eth_sign_request::EthSignRequest; -use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; -#[cfg(feature = "multi-coins")] -use ur_registry::extend::qr_hardware_call::{CallType, QRHardwareCall}; #[cfg(feature = "multi-coins")] use ur_registry::keystone::keystone_sign_request::KeystoneSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "near")] use ur_registry::near::near_sign_request::NearSignRequest; -use ur_registry::pb::protobuf_parser::{parse_protobuf, unzip}; -use ur_registry::pb::protoc; -use ur_registry::pb::protoc::Base; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] use ur_registry::solana::sol_sign_request::SolSignRequest; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] use ur_registry::stellar::stellar_sign_request::{SignType as StellarSignType, StellarSignRequest}; -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] +use ur_registry::sui::sui_sign_hash_request::SuiSignHashRequest; +#[cfg(feature = "sui")] use ur_registry::sui::sui_sign_request::SuiSignRequest; +#[cfg(feature = "ton")] use ur_registry::ton::ton_sign_request::{DataType, TonSignRequest}; +#[cfg(feature = "zcash")] use ur_registry::zcash::zcash_pczt::ZcashPczt; -use ur_registry::{ - bitcoin::btc_sign_request::BtcSignRequest, sui::sui_sign_hash_request::SuiSignHashRequest, -}; use super::ur::ViewType; @@ -77,14 +81,14 @@ impl InferViewType for CryptoAccount { } } -#[cfg(feature = "multi-coins")] +#[cfg(not(feature = "btc-only"))] impl InferViewType for CryptoAccount { fn infer(&self) -> Result { Ok(ViewType::ViewTypeUnKnown) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ethereum")] impl InferViewType for EthSignRequest { fn infer(&self) -> Result { match self.get_data_type() { @@ -96,35 +100,35 @@ impl InferViewType for EthSignRequest { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] impl InferViewType for CosmosSignRequest { fn infer(&self) -> Result { Ok(ViewType::CosmosTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cosmos")] impl InferViewType for EvmSignRequest { fn infer(&self) -> Result { Ok(ViewType::CosmosEvmTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] impl InferViewType for SuiSignRequest { fn infer(&self) -> Result { Ok(ViewType::SuiTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "sui")] impl InferViewType for SuiSignHashRequest { fn infer(&self) -> Result { Ok(ViewType::SuiSignMessageHash) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "stellar")] impl InferViewType for StellarSignRequest { fn infer(&self) -> Result { match self.get_sign_type() { @@ -135,7 +139,7 @@ impl InferViewType for StellarSignRequest { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "arweave")] impl InferViewType for ArweaveSignRequest { fn infer(&self) -> Result { match self.get_sign_type() { @@ -146,7 +150,7 @@ impl InferViewType for ArweaveSignRequest { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "ton")] impl InferViewType for TonSignRequest { fn infer(&self) -> Result { match self.get_data_type() { @@ -156,14 +160,14 @@ impl InferViewType for TonSignRequest { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "aptos")] impl InferViewType for AptosSignRequest { fn infer(&self) -> Result { Ok(ViewType::AptosTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "zcash")] impl InferViewType for ZcashPczt { fn infer(&self) -> Result { Ok(ViewType::ZcashTx) @@ -185,17 +189,17 @@ fn get_view_type_from_keystone(bytes: Vec) -> Result { "BTC_SEGWIT" => ViewType::BtcSegwitTx, "BTC_LEGACY" => ViewType::BtcLegacyTx, "BTC" => ViewType::BtcSegwitTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ltc")] "LTC" => ViewType::LtcTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "dash")] "DASH" => ViewType::DashTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "bch")] "BCH" => ViewType::BchTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "ethereum")] "ETH" => ViewType::EthTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "tron")] "TRON" => ViewType::TronTx, - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] "XRP" => ViewType::XRPTx, _ => { return Err(URError::ProtobufDecodeError(format!( @@ -234,7 +238,7 @@ impl InferViewType for Bytes { return Ok(ViewType::WebAuthResult); } } - #[cfg(feature = "multi-coins")] + #[cfg(feature = "xrp")] return Ok(ViewType::XRPTx); #[cfg(feature = "btc-only")] return Err(URError::UrDecodeError(format!("invalid data"))); @@ -255,16 +259,16 @@ impl InferViewType for Bytes { } } +#[cfg(feature = "bitcoin")] impl InferViewType for BtcSignRequest { fn infer(&self) -> Result { Ok(ViewType::BtcMsg) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "solana")] impl InferViewType for SolSignRequest { fn infer(&self) -> Result { - #[cfg(feature = "multi-coins")] if app_solana::validate_tx(&mut self.get_sign_data()) { return Ok(ViewType::SolanaTx); } @@ -272,35 +276,35 @@ impl InferViewType for SolSignRequest { } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "near")] impl InferViewType for NearSignRequest { fn infer(&self) -> Result { Ok(ViewType::NearTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] impl InferViewType for CardanoSignRequest { fn infer(&self) -> Result { Ok(ViewType::CardanoTx) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] impl InferViewType for CardanoSignTxHashRequest { fn infer(&self) -> Result { Ok(ViewType::CardanoSignTxHash) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] impl InferViewType for CardanoSignDataRequest { fn infer(&self) -> Result { Ok(ViewType::CardanoSignData) } } -#[cfg(feature = "multi-coins")] +#[cfg(feature = "cardano")] impl InferViewType for CardanoCatalystVotingRegistrationRequest { fn infer(&self) -> Result { Ok(ViewType::CardanoCatalystVotingRegistration) @@ -326,6 +330,7 @@ mod tests { use super::InferViewType; use crate::common::ur::ViewType; + #[cfg(feature = "ltc")] #[test] fn test_parse_ur_type() { { From dcbd809565267e98f85ddc25bfdce05a52c07b3e Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 18:58:34 +0800 Subject: [PATCH 24/31] fix: all build --- rust/rust_c/src/common/mod.rs | 120 +------------------------------ rust/rust_c/src/zcash/mod.rs | 131 ++++++++++++++++++++++++++++++++-- 2 files changed, 128 insertions(+), 123 deletions(-) diff --git a/rust/rust_c/src/common/mod.rs b/rust/rust_c/src/common/mod.rs index 840f8894f..60f4ef877 100644 --- a/rust/rust_c/src/common/mod.rs +++ b/rust/rust_c/src/common/mod.rs @@ -1,6 +1,3 @@ -use aes::cipher::block_padding::Pkcs7; -use aes::cipher::generic_array::GenericArray; -use aes::cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit}; use alloc::boxed::Box; use alloc::string::{String, ToString}; use core::ptr::null_mut; @@ -296,119 +293,4 @@ pub extern "C" fn pbkdf2_rust_64( #[no_mangle] pub extern "C" fn tx_check_pass() -> Ptr { TransactionCheckResult::new().c_ptr() -} - -type Aes256CbcEnc = cbc::Encryptor; -type Aes256CbcDec = cbc::Decryptor; - -#[no_mangle] -pub extern "C" fn rust_aes256_cbc_encrypt( - data: PtrString, - password: PtrString, - iv: PtrBytes, - iv_len: u32, -) -> *mut SimpleResponse { - let data = recover_c_char(data); - let data = data.as_bytes(); - let password = recover_c_char(password); - let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; - let key = sha256(password.as_bytes()); - let iv = GenericArray::from_slice(&iv); - let key = GenericArray::from_slice(&key); - let ct = Aes256CbcEnc::new(key, iv).encrypt_padded_vec_mut::(data); - SimpleResponse::success(convert_c_char(hex::encode(ct))).simple_c_ptr() -} - -#[no_mangle] -pub extern "C" fn rust_aes256_cbc_decrypt( - hex_data: PtrString, - password: PtrString, - iv: PtrBytes, - iv_len: u32, -) -> *mut SimpleResponse { - let hex_data = recover_c_char(hex_data); - let data = hex::decode(hex_data).unwrap(); - let password = recover_c_char(password); - let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; - let key = sha256(password.as_bytes()); - let iv = GenericArray::from_slice(&iv); - let key = GenericArray::from_slice(&key); - - match Aes256CbcDec::new(key, iv).decrypt_padded_vec_mut::(&data) { - Ok(pt) => { - SimpleResponse::success(convert_c_char(String::from_utf8(pt).unwrap())).simple_c_ptr() - } - Err(_e) => SimpleResponse::from(RustCError::InvalidHex("decrypt failed".to_string())) - .simple_c_ptr(), - } -} - -#[no_mangle] -pub extern "C" fn rust_derive_iv_from_seed( - seed: PtrBytes, - seed_len: u32, -) -> *mut SimpleResponse { - let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; - let iv_path = "m/44'/1557192335'/0'/2'/0'".to_string(); - let iv = get_private_key_by_seed(seed, &iv_path).unwrap(); - let mut iv_bytes = [0; 16]; - iv_bytes.copy_from_slice(&iv[..16]); - SimpleResponse::success(Box::into_raw(Box::new(iv_bytes)) as *mut u8).simple_c_ptr() -} - -#[cfg(test)] -mod tests { - use alloc::{string::String, vec::Vec}; - - use super::*; - - #[test] - fn test_aes256_cbc_encrypt() { - let mut data = convert_c_char("hello world".to_string()); - let mut password = convert_c_char("password".to_string()); - let mut seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let iv = rust_derive_iv_from_seed(seed.as_mut_ptr(), 64); - let mut iv = unsafe { slice::from_raw_parts_mut((*iv).data, 16) }; - let iv_len = 16; - let ct = rust_aes256_cbc_encrypt(data, password, iv.as_mut_ptr(), iv_len as u32); - let ct_vec = unsafe { (*ct).data }; - let value = recover_c_char(ct_vec); - assert_eq!(value, "639194f4bf964e15d8ea9c9bd9d96918"); - } - - #[test] - fn test_aes256_cbc_decrypt() { - let data = convert_c_char("639194f4bf964e15d8ea9c9bd9d96918".to_string()); - let password = convert_c_char("password".to_string()); - let mut seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let iv = rust_derive_iv_from_seed(seed.as_mut_ptr(), 64); - let iv = unsafe { slice::from_raw_parts_mut((*iv).data, 16) }; - let iv_len = 16; - let pt = rust_aes256_cbc_decrypt(data, password, iv.as_mut_ptr(), iv_len as u32); - assert!(!pt.is_null()); - let ct_vec = unsafe { (*pt).data }; - let value = recover_c_char(ct_vec); - assert_eq!(value, "hello world"); - } - - #[test] - fn test_dep_aes256() { - let mut data = b"hello world"; - let seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let iv_path = "m/44'/1557192335'/0'/2'/0'".to_string(); - let iv = get_private_key_by_seed(&seed, &iv_path).unwrap(); - let mut iv_bytes = [0; 16]; - iv_bytes.copy_from_slice(&iv[..16]); - let key = sha256(b"password"); - let iv = GenericArray::from_slice(&iv_bytes); - let key = GenericArray::from_slice(&key); - - let encrypter = Aes256CbcEnc::new(key, iv); - let decrypter = Aes256CbcDec::new(key, iv); - - let ct = encrypter.encrypt_padded_vec_mut::(data); - let pt = decrypter.decrypt_padded_vec_mut::(&ct).unwrap(); - - assert_eq!(String::from_utf8(pt).unwrap(), "hello world"); - } -} +} \ No newline at end of file diff --git a/rust/rust_c/src/zcash/mod.rs b/rust/rust_c/src/zcash/mod.rs index 95f1b28b6..2778b9efa 100644 --- a/rust/rust_c/src/zcash/mod.rs +++ b/rust/rust_c/src/zcash/mod.rs @@ -1,7 +1,5 @@ pub mod structs; -use alloc::{boxed::Box, format}; -use app_zcash::get_address; use crate::common::{ errors::RustCError, free::Free, @@ -10,10 +8,16 @@ use crate::common::{ ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}, utils::{convert_c_char, recover_c_char}, }; -use crate::{extract_ptr_with_type, make_free_method, }; +use crate::{extract_ptr_with_type, make_free_method}; +use alloc::{boxed::Box, format, string::String, string::ToString}; +use app_zcash::get_address; use core::slice; +use cryptoxide::hashing::sha256; use cty::c_char; -use keystore::algorithms::zcash::{calculate_seed_fingerprint, derive_ufvk}; +use keystore::algorithms::{ + secp256k1::get_private_key_by_seed, + zcash::{calculate_seed_fingerprint, derive_ufvk}, +}; use structs::DisplayPczt; use ur_registry::{traits::RegistryItem, zcash::zcash_pczt::ZcashPczt}; use zcash_vendor::zcash_protocol::consensus::MainNetwork; @@ -125,3 +129,122 @@ pub extern "C" fn sign_zcash_tx(tx: PtrUR, seed: PtrBytes, seed_len: u32) -> *mu } make_free_method!(TransactionParseResult); + +use aes::cipher::block_padding::Pkcs7; +use aes::cipher::generic_array::GenericArray; +use aes::cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit}; + +type Aes256CbcEnc = cbc::Encryptor; +type Aes256CbcDec = cbc::Decryptor; + +#[no_mangle] +pub extern "C" fn rust_aes256_cbc_encrypt( + data: PtrString, + password: PtrString, + iv: PtrBytes, + iv_len: u32, +) -> *mut SimpleResponse { + let data = recover_c_char(data); + let data = data.as_bytes(); + let password = recover_c_char(password); + let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; + let key = sha256(password.as_bytes()); + let iv = GenericArray::from_slice(&iv); + let key = GenericArray::from_slice(&key); + let ct = Aes256CbcEnc::new(key, iv).encrypt_padded_vec_mut::(data); + SimpleResponse::success(convert_c_char(hex::encode(ct))).simple_c_ptr() +} + +#[no_mangle] +pub extern "C" fn rust_aes256_cbc_decrypt( + hex_data: PtrString, + password: PtrString, + iv: PtrBytes, + iv_len: u32, +) -> *mut SimpleResponse { + let hex_data = recover_c_char(hex_data); + let data = hex::decode(hex_data).unwrap(); + let password = recover_c_char(password); + let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; + let key = sha256(password.as_bytes()); + let iv = GenericArray::from_slice(&iv); + let key = GenericArray::from_slice(&key); + + match Aes256CbcDec::new(key, iv).decrypt_padded_vec_mut::(&data) { + Ok(pt) => { + SimpleResponse::success(convert_c_char(String::from_utf8(pt).unwrap())).simple_c_ptr() + } + Err(_e) => SimpleResponse::from(RustCError::InvalidHex("decrypt failed".to_string())) + .simple_c_ptr(), + } +} + +#[no_mangle] +pub extern "C" fn rust_derive_iv_from_seed( + seed: PtrBytes, + seed_len: u32, +) -> *mut SimpleResponse { + let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; + let iv_path = "m/44'/1557192335'/0'/2'/0'".to_string(); + let iv = get_private_key_by_seed(seed, &iv_path).unwrap(); + let mut iv_bytes = [0; 16]; + iv_bytes.copy_from_slice(&iv[..16]); + SimpleResponse::success(Box::into_raw(Box::new(iv_bytes)) as *mut u8).simple_c_ptr() +} + +#[cfg(test)] +mod tests { + use alloc::{string::String, vec::Vec}; + + use super::*; + + #[test] + fn test_aes256_cbc_encrypt() { + let mut data = convert_c_char("hello world".to_string()); + let mut password = convert_c_char("password".to_string()); + let mut seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); + let iv = rust_derive_iv_from_seed(seed.as_mut_ptr(), 64); + let mut iv = unsafe { slice::from_raw_parts_mut((*iv).data, 16) }; + let iv_len = 16; + let ct = rust_aes256_cbc_encrypt(data, password, iv.as_mut_ptr(), iv_len as u32); + let ct_vec = unsafe { (*ct).data }; + let value = recover_c_char(ct_vec); + assert_eq!(value, "639194f4bf964e15d8ea9c9bd9d96918"); + } + + #[test] + fn test_aes256_cbc_decrypt() { + let data = convert_c_char("639194f4bf964e15d8ea9c9bd9d96918".to_string()); + let password = convert_c_char("password".to_string()); + let mut seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); + let iv = rust_derive_iv_from_seed(seed.as_mut_ptr(), 64); + let iv = unsafe { slice::from_raw_parts_mut((*iv).data, 16) }; + let iv_len = 16; + let pt = rust_aes256_cbc_decrypt(data, password, iv.as_mut_ptr(), iv_len as u32); + assert!(!pt.is_null()); + let ct_vec = unsafe { (*pt).data }; + let value = recover_c_char(ct_vec); + assert_eq!(value, "hello world"); + } + + #[test] + fn test_dep_aes256() { + let mut data = b"hello world"; + let seed = hex::decode("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); + let iv_path = "m/44'/1557192335'/0'/2'/0'".to_string(); + let iv = get_private_key_by_seed(&seed, &iv_path).unwrap(); + let mut iv_bytes = [0; 16]; + iv_bytes.copy_from_slice(&iv[..16]); + let key = sha256(b"password"); + let iv = GenericArray::from_slice(&iv_bytes); + let key = GenericArray::from_slice(&key); + + let encrypter = Aes256CbcEnc::new(key, iv); + let decrypter = Aes256CbcDec::new(key, iv); + + let ct = encrypter.encrypt_padded_vec_mut::(data); + let pt = decrypter.decrypt_padded_vec_mut::(&ct).unwrap(); + + assert_eq!(String::from_utf8(pt).unwrap(), "hello world"); + } +} From ce3f120c86799194181d6fd79dfb96a83135ae18 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 18:59:55 +0800 Subject: [PATCH 25/31] style: run rust fix --- rust/apps/cardano/src/governance.rs | 2 +- rust/apps/cardano/src/structs.rs | 47 +++++++++++------------ rust/apps/cardano/src/transaction.rs | 2 +- rust/apps/zcash/src/pczt/parse.rs | 2 +- rust/keystore/src/algorithms/zcash/mod.rs | 5 +-- rust/zcash_vendor/src/pczt_ext.rs | 6 +-- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/rust/apps/cardano/src/governance.rs b/rust/apps/cardano/src/governance.rs index 3b27bb832..335ff3821 100644 --- a/rust/apps/cardano/src/governance.rs +++ b/rust/apps/cardano/src/governance.rs @@ -5,7 +5,7 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; use cardano_serialization_lib::protocol_types::Address; use cryptoxide::hashing::blake2b_256; -use ed25519_bip32_core::{XPrv, XPub}; +use ed25519_bip32_core::{XPrv}; use hex; use ur_registry::cardano::cardano_delegation::CardanoDelegation; use ur_registry::cardano::governance::CardanoVotingRegistration; diff --git a/rust/apps/cardano/src/structs.rs b/rust/apps/cardano/src/structs.rs index 03408dadd..aaf8c83c0 100644 --- a/rust/apps/cardano/src/structs.rs +++ b/rust/apps/cardano/src/structs.rs @@ -1,4 +1,4 @@ -use crate::address::{derive_address, derive_pubkey_hash, AddressType}; +use crate::address::{derive_pubkey_hash}; use crate::errors::{CardanoError, R}; use alloc::collections::BTreeMap; use alloc::string::{String, ToString}; @@ -6,15 +6,14 @@ use alloc::vec; use alloc::vec::Vec; use app_utils::{impl_internal_struct, impl_public_struct}; use cardano_serialization_lib::protocol_types::{ - self, Address, BaseAddress, EnterpriseAddress, RewardAddress, + Address, BaseAddress, EnterpriseAddress, RewardAddress, }; -use cardano_serialization_lib::protocol_types::numeric::BigNum; -use cardano_serialization_lib::protocol_types::{Anchor, DRepKind}; -use cardano_serialization_lib::protocol_types::{Ed25519KeyHash, ScriptHash}; + +use cardano_serialization_lib::protocol_types::{DRepKind}; + use cardano_serialization_lib::{ - protocol_types::FixedTransaction as Transaction, protocol_types::VoteKind, Certificate, - CertificateKind, NetworkId, NetworkIdKind, + protocol_types::FixedTransaction as Transaction, protocol_types::VoteKind, NetworkIdKind, }; use alloc::format; @@ -190,7 +189,7 @@ impl ParsedCardanoSignData { xpub, }) } - Err(e) => Ok(Self { + Err(_e) => Ok(Self { payload: hex::encode(sign_data.clone()), derivation_path, message_hash: hex::encode(sign_data), @@ -510,12 +509,12 @@ impl ParsedCardanoTx { CertField { label: LABEL_HOT_KEY.to_string(), value: match _cert.committee_hot_credential().kind() { - Ed25519KeyHash => _cert + _Ed25519KeyHash => _cert .committee_hot_credential() .to_keyhash() .unwrap() .to_string(), - ScriptHash => _cert + _ScriptHash => _cert .committee_hot_credential() .to_scripthash() .unwrap() @@ -525,12 +524,12 @@ impl ParsedCardanoTx { CertField { label: LABEL_COLD_KEY.to_string(), value: match _cert.committee_cold_credential().kind() { - Ed25519KeyHash => _cert + _Ed25519KeyHash => _cert .committee_cold_credential() .to_keyhash() .unwrap() .to_string(), - ScriptHash => _cert + _ScriptHash => _cert .committee_cold_credential() .to_scripthash() .unwrap() @@ -547,12 +546,12 @@ impl ParsedCardanoTx { let mut fields = vec![CertField { label: LABEL_COLD_KEY.to_string(), value: match _cert.committee_cold_credential().kind() { - Ed25519KeyHash => _cert + _Ed25519KeyHash => _cert .committee_cold_credential() .to_keyhash() .unwrap() .to_string(), - ScriptHash => _cert + _ScriptHash => _cert .committee_cold_credential() .to_scripthash() .unwrap() @@ -577,7 +576,7 @@ impl ParsedCardanoTx { if let Some(_cert) = cert.as_drep_deregistration() { let deposit = normalize_coin(u64::from(&_cert.coin())); let (variant1, variant1_label) = match _cert.voting_credential().kind() { - Ed25519KeyHash => ( + _Ed25519KeyHash => ( _cert .voting_credential() .to_keyhash() @@ -586,7 +585,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - ScriptHash => ( + _ScriptHash => ( _cert .voting_credential() .to_scripthash() @@ -614,7 +613,7 @@ impl ParsedCardanoTx { if let Some(_cert) = cert.as_drep_registration() { let deposit = normalize_coin(u64::from(&_cert.coin())); let (variant1, variant1_label) = match _cert.voting_credential().kind() { - Ed25519KeyHash => ( + _Ed25519KeyHash => ( _cert .voting_credential() .to_keyhash() @@ -623,7 +622,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - ScriptHash => ( + _ScriptHash => ( _cert .voting_credential() .to_scripthash() @@ -668,7 +667,7 @@ impl ParsedCardanoTx { None => None, }; let (variant1, variant1_label) = match _cert.voting_credential().kind() { - Ed25519KeyHash => ( + _Ed25519KeyHash => ( _cert .voting_credential() .to_keyhash() @@ -677,7 +676,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - ScriptHash => ( + _ScriptHash => ( _cert .voting_credential() .to_scripthash() @@ -1039,7 +1038,7 @@ impl ParsedCardanoTx { fn parse_inputs( tx: &Transaction, context: &ParseContext, - network_id: u8, + _network_id: u8, ) -> R> { let inputs_len = tx.body().inputs().len(); let mut parsed_inputs: Vec = vec![]; @@ -1091,7 +1090,7 @@ impl ParsedCardanoTx { index.clone(), )?); - let mut address = utxo.address.clone(); + let address = utxo.address.clone(); let addr_in_utxo = Address::from_bech32(&utxo.address) .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?; @@ -1159,8 +1158,8 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::AddressEncodingError(e.to_string()))?, amount: normalize_coin(u64::from(&output.amount().coin())), value: u64::from(&output.amount().coin()), - assets: output.amount().multiasset().map(|v| { - let mut parsed_multi_assets = vec![]; + assets: output.amount().multiasset().map(|_v| { + let parsed_multi_assets = vec![]; // temporary comment multi assets parse logic because it consumes a lot of memory but we don't display it on UI // let len = v.keys().len(); diff --git a/rust/apps/cardano/src/transaction.rs b/rust/apps/cardano/src/transaction.rs index c5970141c..e5ce49ff9 100644 --- a/rust/apps/cardano/src/transaction.rs +++ b/rust/apps/cardano/src/transaction.rs @@ -6,7 +6,7 @@ use alloc::vec::Vec; use cardano_serialization_lib; use cardano_serialization_lib::protocol_types::{Ed25519Signature, PublicKey, Vkey, Vkeywitness}; use cryptoxide::hashing::blake2b_256; -use ed25519_bip32_core::{XPrv, XPub}; +use ed25519_bip32_core::{XPrv}; use hex; use ur_registry::crypto_key_path::CryptoKeyPath; diff --git a/rust/apps/zcash/src/pczt/parse.rs b/rust/apps/zcash/src/pczt/parse.rs index 3f003c998..a8e0457de 100644 --- a/rust/apps/zcash/src/pczt/parse.rs +++ b/rust/apps/zcash/src/pczt/parse.rs @@ -10,7 +10,7 @@ use zcash_vendor::{ orchard::{ self, keys::OutgoingViewingKey, note::Note, note_encryption::OrchardDomain, Address, }, - pczt::{self, roles::verifier::Verifier, sapling, Pczt}, + pczt::{self, roles::verifier::Verifier, Pczt}, ripemd::{Digest, Ripemd160}, sha2::Sha256, transparent::{self, address::TransparentAddress}, diff --git a/rust/keystore/src/algorithms/zcash/mod.rs b/rust/keystore/src/algorithms/zcash/mod.rs index cc3cbfbab..f59f74b7c 100644 --- a/rust/keystore/src/algorithms/zcash/mod.rs +++ b/rust/keystore/src/algorithms/zcash/mod.rs @@ -2,7 +2,6 @@ use core::str::FromStr; use alloc::{ string::{String, ToString}, - vec::Vec, }; use bitcoin::bip32::{ChildNumber, DerivationPath}; use hex; @@ -12,11 +11,11 @@ use rand_core::{CryptoRng, RngCore}; use zcash_vendor::{ orchard::{ self, - keys::{SpendAuthorizingKey, SpendValidatingKey, SpendingKey}, + keys::{SpendAuthorizingKey, SpendingKey}, }, pasta_curves::{group::ff::PrimeField, Fq}, zcash_keys::keys::UnifiedSpendingKey, - zcash_protocol::consensus::{self, MAIN_NETWORK}, + zcash_protocol::consensus::{self}, zip32::{self, fingerprint::SeedFingerprint, AccountId}, }; diff --git a/rust/zcash_vendor/src/pczt_ext.rs b/rust/zcash_vendor/src/pczt_ext.rs index 066258d4b..357758ec1 100644 --- a/rust/zcash_vendor/src/pczt_ext.rs +++ b/rust/zcash_vendor/src/pczt_ext.rs @@ -1,14 +1,14 @@ use crate::pczt::Pczt; -use alloc::collections::btree_map::BTreeMap; + use alloc::vec::Vec; use blake2b_simd::{Hash, Params, State}; -use orchard::pczt::Zip32Derivation; + use pczt::{ common::determine_lock_time, roles::low_level_signer::Signer, transparent::{Input, Output}, }; -use transparent::{pczt::Bip32Derivation, sighash::SignableInput}; +use transparent::{sighash::SignableInput}; use zcash_protocol::value::ZatBalance; /// TxId tree root personalization From 5ba462a7dee4a6215705cf9fa20f94f424649917 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 19:01:52 +0800 Subject: [PATCH 26/31] style: run rust fmt --- rust/apps/cardano/src/governance.rs | 2 +- rust/apps/cardano/src/structs.rs | 5 ++--- rust/apps/cardano/src/transaction.rs | 2 +- rust/keystore/src/algorithms/zcash/mod.rs | 4 +--- rust/rust_c/build.rs | 9 +++++++-- rust/rust_c/src/aptos/mod.rs | 14 ++++++------- rust/rust_c/src/aptos/structs.rs | 4 ++-- rust/rust_c/src/arweave/structs.rs | 14 ++++++------- rust/rust_c/src/bitcoin/address.rs | 6 +++--- rust/rust_c/src/bitcoin/legacy.rs | 4 ++-- rust/rust_c/src/bitcoin/msg.rs | 14 ++++++------- rust/rust_c/src/bitcoin/multi_sig/structs.rs | 6 +++--- rust/rust_c/src/bitcoin/psbt.rs | 8 ++++---- rust/rust_c/src/bitcoin/structs.rs | 4 ++-- rust/rust_c/src/cardano/address.rs | 4 ++-- rust/rust_c/src/cardano/mod.rs | 4 ++-- rust/rust_c/src/common/errors.rs | 4 ++-- rust/rust_c/src/common/free.rs | 2 +- rust/rust_c/src/common/mod.rs | 2 +- rust/rust_c/src/common/ur_ext.rs | 20 +++++++++---------- rust/rust_c/src/common/utils.rs | 2 +- rust/rust_c/src/cosmos/mod.rs | 14 ++++++------- rust/rust_c/src/ethereum/address.rs | 2 +- rust/rust_c/src/near/mod.rs | 10 +++++----- rust/rust_c/src/solana/mod.rs | 12 +++++------ rust/rust_c/src/stellar/mod.rs | 8 ++++---- rust/rust_c/src/sui/mod.rs | 8 ++++---- rust/rust_c/src/tron/mod.rs | 6 +++--- rust/rust_c/src/wallet/btc_only_wallet.rs | 4 ++-- rust/rust_c/src/wallet/mod.rs | 2 +- .../src/wallet/multi_coins_wallet/aptos.rs | 2 +- .../wallet/multi_coins_wallet/arconnect.rs | 6 +++--- .../src/wallet/multi_coins_wallet/backpack.rs | 4 ++-- .../src/wallet/multi_coins_wallet/bitget.rs | 4 ++-- .../src/wallet/multi_coins_wallet/imtoken.rs | 8 ++++---- .../src/wallet/multi_coins_wallet/keplr.rs | 10 +++++----- .../src/wallet/multi_coins_wallet/keystone.rs | 4 ++-- .../src/wallet/multi_coins_wallet/okx.rs | 4 ++-- .../src/wallet/multi_coins_wallet/solana.rs | 2 +- .../src/wallet/multi_coins_wallet/sui.rs | 8 ++++---- .../src/wallet/multi_coins_wallet/utils.rs | 6 +++--- .../src/wallet/multi_coins_wallet/xbull.rs | 2 +- .../wallet/multi_coins_wallet/xrp_toolkit.rs | 2 +- .../src/wallet/multi_coins_wallet/zcash.rs | 10 +++++----- rust/rust_c/src/xrp/mod.rs | 2 +- rust/zcash_vendor/src/pczt_ext.rs | 2 +- 46 files changed, 139 insertions(+), 137 deletions(-) diff --git a/rust/apps/cardano/src/governance.rs b/rust/apps/cardano/src/governance.rs index 335ff3821..a2797d531 100644 --- a/rust/apps/cardano/src/governance.rs +++ b/rust/apps/cardano/src/governance.rs @@ -5,7 +5,7 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; use cardano_serialization_lib::protocol_types::Address; use cryptoxide::hashing::blake2b_256; -use ed25519_bip32_core::{XPrv}; +use ed25519_bip32_core::XPrv; use hex; use ur_registry::cardano::cardano_delegation::CardanoDelegation; use ur_registry::cardano::governance::CardanoVotingRegistration; diff --git a/rust/apps/cardano/src/structs.rs b/rust/apps/cardano/src/structs.rs index aaf8c83c0..c46fe2d9c 100644 --- a/rust/apps/cardano/src/structs.rs +++ b/rust/apps/cardano/src/structs.rs @@ -1,4 +1,4 @@ -use crate::address::{derive_pubkey_hash}; +use crate::address::derive_pubkey_hash; use crate::errors::{CardanoError, R}; use alloc::collections::BTreeMap; use alloc::string::{String, ToString}; @@ -9,8 +9,7 @@ use cardano_serialization_lib::protocol_types::{ Address, BaseAddress, EnterpriseAddress, RewardAddress, }; - -use cardano_serialization_lib::protocol_types::{DRepKind}; +use cardano_serialization_lib::protocol_types::DRepKind; use cardano_serialization_lib::{ protocol_types::FixedTransaction as Transaction, protocol_types::VoteKind, NetworkIdKind, diff --git a/rust/apps/cardano/src/transaction.rs b/rust/apps/cardano/src/transaction.rs index e5ce49ff9..cb3e08568 100644 --- a/rust/apps/cardano/src/transaction.rs +++ b/rust/apps/cardano/src/transaction.rs @@ -6,7 +6,7 @@ use alloc::vec::Vec; use cardano_serialization_lib; use cardano_serialization_lib::protocol_types::{Ed25519Signature, PublicKey, Vkey, Vkeywitness}; use cryptoxide::hashing::blake2b_256; -use ed25519_bip32_core::{XPrv}; +use ed25519_bip32_core::XPrv; use hex; use ur_registry::crypto_key_path::CryptoKeyPath; diff --git a/rust/keystore/src/algorithms/zcash/mod.rs b/rust/keystore/src/algorithms/zcash/mod.rs index f59f74b7c..fcf7a1f8e 100644 --- a/rust/keystore/src/algorithms/zcash/mod.rs +++ b/rust/keystore/src/algorithms/zcash/mod.rs @@ -1,8 +1,6 @@ use core::str::FromStr; -use alloc::{ - string::{String, ToString}, -}; +use alloc::string::{String, ToString}; use bitcoin::bip32::{ChildNumber, DerivationPath}; use hex; use rand_chacha::rand_core::SeedableRng; diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index df90db38d..922b3c625 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -18,8 +18,13 @@ fn main() { "debug-btc-only", ]; assert!(features.len() > 0, "No build variant enabled"); - assert!(features.len() == 1, "Multiple build variants enabled: {:?}", features); - let output_target = env::var("CBINDGEN_BINDINGS_TARGET").unwrap_or(format!("bindings/{}/librust_c.h", features[0])); + assert!( + features.len() == 1, + "Multiple build variants enabled: {:?}", + features + ); + let output_target = env::var("CBINDGEN_BINDINGS_TARGET") + .unwrap_or(format!("bindings/{}/librust_c.h", features[0])); config.parse.expand.features = Some(features.into_iter().map(|s| s.to_string()).collect()); let builder = cbindgen::Builder::new(); diff --git a/rust/rust_c/src/aptos/mod.rs b/rust/rust_c/src/aptos/mod.rs index 7029ed6b9..d2ee3e8e9 100644 --- a/rust/rust_c/src/aptos/mod.rs +++ b/rust/rust_c/src/aptos/mod.rs @@ -1,4 +1,9 @@ -use structs::DisplayAptosTx; +use crate::common::errors::RustCError; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; use alloc::format; use alloc::slice; use alloc::string::ToString; @@ -6,15 +11,10 @@ use alloc::vec::Vec; use app_aptos; use app_aptos::errors::AptosError; use app_aptos::parser::is_tx; -use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; -use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use crate::common::utils::{convert_c_char, recover_c_char}; use cty::c_char; use hex; use hex::FromHex; +use structs::DisplayAptosTx; use ur_registry::aptos::aptos_sign_request::{AptosSignRequest, SignType}; use ur_registry::aptos::aptos_signature::AptosSignature; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/aptos/structs.rs b/rust/rust_c/src/aptos/structs.rs index f23d20dba..2f2b77acf 100644 --- a/rust/rust_c/src/aptos/structs.rs +++ b/rust/rust_c/src/aptos/structs.rs @@ -1,10 +1,10 @@ -use alloc::string::{String, ToString}; -use app_aptos::parser::AptosTx; use crate::common::free::Free; use crate::common::structs::TransactionParseResult; use crate::common::types::{PtrString, PtrT}; use crate::common::utils::convert_c_char; use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use alloc::string::{String, ToString}; +use app_aptos::parser::AptosTx; use serde_json::Value; #[repr(C)] diff --git a/rust/rust_c/src/arweave/structs.rs b/rust/rust_c/src/arweave/structs.rs index bec53ee75..d05d37825 100644 --- a/rust/rust_c/src/arweave/structs.rs +++ b/rust/rust_c/src/arweave/structs.rs @@ -1,15 +1,15 @@ -use core::ptr::null_mut; +use crate::common::ffi::VecFFI; +use crate::common::free::Free; +use crate::common::structs::TransactionParseResult; +use crate::common::types::{Ptr, PtrString, PtrT}; +use crate::common::utils::convert_c_char; +use crate::{check_and_free_ptr, free_str_ptr, free_vec, impl_c_ptr, make_free_method}; use alloc::vec::Vec; use app_arweave::{ ao_transaction::AOTransferTransaction, data_item::{DataItem, Tag}, }; -use crate::common::free::Free; -use crate::common::structs::TransactionParseResult; -use crate::common::types::{Ptr, PtrString, PtrT}; -use crate::common::utils::convert_c_char; -use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method, free_vec}; -use crate::common::ffi::VecFFI; +use core::ptr::null_mut; #[repr(C)] pub enum ArweaveRequestType { diff --git a/rust/rust_c/src/bitcoin/address.rs b/rust/rust_c/src/bitcoin/address.rs index 655fea642..a0ac321cc 100644 --- a/rust/rust_c/src/bitcoin/address.rs +++ b/rust/rust_c/src/bitcoin/address.rs @@ -1,9 +1,9 @@ -use app_bitcoin; -use app_bitcoin::addresses::xyzpub; -use bitcoin::secp256k1::ffi::types::c_char; use crate::common::structs::SimpleResponse; use crate::common::types::PtrString; use crate::common::utils::{convert_c_char, recover_c_char}; +use app_bitcoin; +use app_bitcoin::addresses::xyzpub; +use bitcoin::secp256k1::ffi::types::c_char; use core::str::FromStr; #[no_mangle] diff --git a/rust/rust_c/src/bitcoin/legacy.rs b/rust/rust_c/src/bitcoin/legacy.rs index f0eae8f28..e7d23afed 100644 --- a/rust/rust_c/src/bitcoin/legacy.rs +++ b/rust/rust_c/src/bitcoin/legacy.rs @@ -1,12 +1,12 @@ use super::structs::DisplayTx; -use alloc::boxed::Box; -use alloc::slice; use crate::common::errors::RustCError; use crate::common::keystone; use crate::common::keystone::{build_parse_context, build_payload}; use crate::common::structs::{TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{QRCodeType, UREncodeResult}; +use alloc::boxed::Box; +use alloc::slice; #[no_mangle] pub extern "C" fn utxo_parse_keystone( diff --git a/rust/rust_c/src/bitcoin/msg.rs b/rust/rust_c/src/bitcoin/msg.rs index da66b535d..547cf0bfc 100644 --- a/rust/rust_c/src/bitcoin/msg.rs +++ b/rust/rust_c/src/bitcoin/msg.rs @@ -1,11 +1,4 @@ -use core::ptr::null_mut; use super::structs::DisplayBtcMsg; -use alloc::{ - slice, - string::{String, ToString}, - vec::Vec, -}; -use base64; use crate::common::{ errors::RustCError, ffi::CSliceFFI, @@ -16,6 +9,13 @@ use crate::common::{ utils::{convert_c_char, recover_c_array, recover_c_char}, }; use crate::extract_ptr_with_type; +use alloc::{ + slice, + string::{String, ToString}, + vec::Vec, +}; +use base64; +use core::ptr::null_mut; use keystore::algorithms::secp256k1; use ur_registry::bitcoin::btc_sign_request::{BtcSignRequest, DataType}; use ur_registry::bitcoin::btc_signature::BtcSignature; diff --git a/rust/rust_c/src/bitcoin/multi_sig/structs.rs b/rust/rust_c/src/bitcoin/multi_sig/structs.rs index 83b69a2b1..444d3f3f6 100644 --- a/rust/rust_c/src/bitcoin/multi_sig/structs.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/structs.rs @@ -2,15 +2,15 @@ use alloc::boxed::Box; use alloc::format; use alloc::string::ToString; -use alloc::vec::Vec; -use app_bitcoin::multi_sig::wallet::{BsmsWallet, MultiSigWalletConfig}; -use app_bitcoin::multi_sig::{MultiSigFormat, MultiSigType, MultiSigXPubInfo, Network}; use crate::common::ffi::VecFFI; use crate::common::free::Free; use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT}; use crate::common::ur::UREncodeResult; use crate::common::utils::{convert_c_char, recover_c_char}; use crate::{check_and_free_ptr, free_str_ptr, free_vec, impl_c_ptr, make_free_method}; +use alloc::vec::Vec; +use app_bitcoin::multi_sig::wallet::{BsmsWallet, MultiSigWalletConfig}; +use app_bitcoin::multi_sig::{MultiSigFormat, MultiSigType, MultiSigXPubInfo, Network}; #[repr(C)] pub enum NetworkType { diff --git a/rust/rust_c/src/bitcoin/psbt.rs b/rust/rust_c/src/bitcoin/psbt.rs index c96c9901d..41abaaa7b 100644 --- a/rust/rust_c/src/bitcoin/psbt.rs +++ b/rust/rust_c/src/bitcoin/psbt.rs @@ -7,11 +7,7 @@ use app_bitcoin::multi_sig::wallet::parse_wallet_config; use core::ptr::null_mut; use core::str::FromStr; -use app_bitcoin::parsed_tx::ParseContext; -use app_bitcoin::{self, parse_psbt_hex_sign_status, parse_psbt_sign_status}; -use bitcoin::bip32::{DerivationPath, Xpub}; use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; use crate::common::ffi::{CSliceFFI, VecFFI}; use crate::common::structs::{ ExtendedPublicKey, Response, TransactionCheckResult, TransactionParseResult, @@ -19,6 +15,10 @@ use crate::common::structs::{ use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT, FRAGMENT_UNLIMITED_LENGTH}; use crate::common::utils::{convert_c_char, recover_c_array, recover_c_char}; +use crate::extract_ptr_with_type; +use app_bitcoin::parsed_tx::ParseContext; +use app_bitcoin::{self, parse_psbt_hex_sign_status, parse_psbt_sign_status}; +use bitcoin::bip32::{DerivationPath, Xpub}; use hex; use ur_registry::crypto_psbt::CryptoPSBT; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/bitcoin/structs.rs b/rust/rust_c/src/bitcoin/structs.rs index 323d9c6ba..b99c31bf8 100644 --- a/rust/rust_c/src/bitcoin/structs.rs +++ b/rust/rust_c/src/bitcoin/structs.rs @@ -2,8 +2,6 @@ use alloc::boxed::Box; use alloc::vec::Vec; use core::ptr::null_mut; -use app_bitcoin; -use app_bitcoin::parsed_tx::{DetailTx, OverviewTx, ParsedInput, ParsedOutput, ParsedTx}; use crate::common::ffi::VecFFI; use crate::common::free::Free; use crate::common::structs::Response; @@ -12,6 +10,8 @@ use crate::common::types::{PtrString, PtrT}; use crate::common::ur::UREncodeResult; use crate::common::utils::convert_c_char; use crate::{check_and_free_ptr, free_str_ptr, impl_c_ptr, make_free_method}; +use app_bitcoin; +use app_bitcoin::parsed_tx::{DetailTx, OverviewTx, ParsedInput, ParsedOutput, ParsedTx}; #[repr(C)] pub struct PsbtSignResult { diff --git a/rust/rust_c/src/cardano/address.rs b/rust/rust_c/src/cardano/address.rs index bde4fa0a1..0b5bc3526 100644 --- a/rust/rust_c/src/cardano/address.rs +++ b/rust/rust_c/src/cardano/address.rs @@ -1,8 +1,8 @@ -use app_cardano; -use app_cardano::address::AddressType; use crate::common::structs::SimpleResponse; use crate::common::types::PtrString; use crate::common::utils::{convert_c_char, recover_c_char}; +use app_cardano; +use app_cardano::address::AddressType; use cty::c_char; #[no_mangle] diff --git a/rust/rust_c/src/cardano/mod.rs b/rust/rust_c/src/cardano/mod.rs index 9f34865ea..7d1058ad5 100644 --- a/rust/rust_c/src/cardano/mod.rs +++ b/rust/rust_c/src/cardano/mod.rs @@ -26,13 +26,13 @@ use ur_registry::cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest use ur_registry::cardano::cardano_signature::CardanoSignature; use ur_registry::crypto_key_path::CryptoKeyPath; -use structs::{DisplayCardanoCatalyst, DisplayCardanoSignData, DisplayCardanoTx}; use crate::common::errors::{RustCError, R}; -use crate::extract_ptr_with_type; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; +use structs::{DisplayCardanoCatalyst, DisplayCardanoSignData, DisplayCardanoTx}; use ur_registry::registry_types::{ CARDANO_CATALYST_VOTING_REGISTRATION_SIGNATURE, CARDANO_SIGNATURE, CARDANO_SIGN_DATA_SIGNATURE, }; diff --git a/rust/rust_c/src/common/errors.rs b/rust/rust_c/src/common/errors.rs index e9f921201..979742cea 100644 --- a/rust/rust_c/src/common/errors.rs +++ b/rust/rust_c/src/common/errors.rs @@ -4,12 +4,12 @@ use thiserror; use thiserror::Error; use ur_registry::error::URError; -#[cfg(feature = "bitcoin")] -use app_bitcoin::errors::BitcoinError; #[cfg(feature = "aptos")] use app_aptos::errors::AptosError; #[cfg(feature = "arweave")] use app_arweave::errors::ArweaveError; +#[cfg(feature = "bitcoin")] +use app_bitcoin::errors::BitcoinError; #[cfg(feature = "cardano")] use app_cardano::errors::CardanoError; #[cfg(feature = "cosmos")] diff --git a/rust/rust_c/src/common/free.rs b/rust/rust_c/src/common/free.rs index eeaa625ec..a4a2b9fea 100644 --- a/rust/rust_c/src/common/free.rs +++ b/rust/rust_c/src/common/free.rs @@ -1,8 +1,8 @@ use super::ffi::VecFFI; -use crate::make_free_method; use super::structs::SimpleResponse; use super::types::{PtrString, PtrT}; use super::ur::{UREncodeMultiResult, UREncodeResult, URParseMultiResult, URParseResult}; +use crate::make_free_method; use alloc::boxed::Box; use cty::{c_char, c_void}; diff --git a/rust/rust_c/src/common/mod.rs b/rust/rust_c/src/common/mod.rs index 60f4ef877..4f263908e 100644 --- a/rust/rust_c/src/common/mod.rs +++ b/rust/rust_c/src/common/mod.rs @@ -293,4 +293,4 @@ pub extern "C" fn pbkdf2_rust_64( #[no_mangle] pub extern "C" fn tx_check_pass() -> Ptr { TransactionCheckResult::new().c_ptr() -} \ No newline at end of file +} diff --git a/rust/rust_c/src/common/ur_ext.rs b/rust/rust_c/src/common/ur_ext.rs index 5add8ae8d..409766911 100644 --- a/rust/rust_c/src/common/ur_ext.rs +++ b/rust/rust_c/src/common/ur_ext.rs @@ -4,22 +4,13 @@ use alloc::vec::Vec; use serde_json::{from_slice, from_value, Value}; -use ur_registry::bytes::Bytes; -use ur_registry::crypto_account::CryptoAccount; -use ur_registry::crypto_psbt::CryptoPSBT; -use ur_registry::error::URError; -use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; -use ur_registry::pb::protobuf_parser::{parse_protobuf, unzip}; -use ur_registry::pb::protoc; -use ur_registry::pb::protoc::Base; -#[cfg(feature = "multi-coins")] -use ur_registry::extend::qr_hardware_call::{CallType, QRHardwareCall}; #[cfg(feature = "aptos")] use ur_registry::aptos::aptos_sign_request::AptosSignRequest; #[cfg(feature = "arweave")] use ur_registry::arweave::arweave_sign_request::{ArweaveSignRequest, SignType}; #[cfg(feature = "bitcoin")] use ur_registry::bitcoin::btc_sign_request::BtcSignRequest; +use ur_registry::bytes::Bytes; #[cfg(feature = "cardano")] use ur_registry::cardano::cardano_catalyst_voting_registration::CardanoCatalystVotingRegistrationRequest; #[cfg(feature = "cardano")] @@ -32,14 +23,23 @@ use ur_registry::cardano::cardano_sign_tx_hash_request::CardanoSignTxHashRequest use ur_registry::cosmos::cosmos_sign_request::CosmosSignRequest; #[cfg(feature = "cosmos")] use ur_registry::cosmos::evm_sign_request::EvmSignRequest; +use ur_registry::crypto_account::CryptoAccount; +use ur_registry::crypto_psbt::CryptoPSBT; +use ur_registry::error::URError; #[cfg(feature = "ethereum")] use ur_registry::ethereum::eth_sign_request; #[cfg(feature = "ethereum")] use ur_registry::ethereum::eth_sign_request::EthSignRequest; +use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; +#[cfg(feature = "multi-coins")] +use ur_registry::extend::qr_hardware_call::{CallType, QRHardwareCall}; #[cfg(feature = "multi-coins")] use ur_registry::keystone::keystone_sign_request::KeystoneSignRequest; #[cfg(feature = "near")] use ur_registry::near::near_sign_request::NearSignRequest; +use ur_registry::pb::protobuf_parser::{parse_protobuf, unzip}; +use ur_registry::pb::protoc; +use ur_registry::pb::protoc::Base; #[cfg(feature = "solana")] use ur_registry::solana::sol_sign_request::SolSignRequest; #[cfg(feature = "stellar")] diff --git a/rust/rust_c/src/common/utils.rs b/rust/rust_c/src/common/utils.rs index 2759b7df1..2da337da9 100644 --- a/rust/rust_c/src/common/utils.rs +++ b/rust/rust_c/src/common/utils.rs @@ -1,9 +1,9 @@ use alloc::string::{String, ToString}; use core::slice; -use crate::extract_ptr_with_type; use super::ffi::CSliceFFI; use super::free::Free; +use crate::extract_ptr_with_type; use cstr_core::{CStr, CString}; use cty::c_char; diff --git a/rust/rust_c/src/cosmos/mod.rs b/rust/rust_c/src/cosmos/mod.rs index b412e80b8..d32a0385f 100644 --- a/rust/rust_c/src/cosmos/mod.rs +++ b/rust/rust_c/src/cosmos/mod.rs @@ -1,21 +1,21 @@ pub mod structs; -use structs::DisplayCosmosTx; +use crate::common::errors::RustCError; +use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; +use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; +use crate::common::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; use app_cosmos::errors::CosmosError; use app_cosmos::transaction::structs::SignMode; use app_utils::normalize_path; -use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; -use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; -use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; -use crate::common::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; -use crate::common::utils::{convert_c_char, recover_c_char}; use core::slice; use cty::c_char; use either::Either; +use structs::DisplayCosmosTx; use ur_registry::cosmos::cosmos_sign_request::{CosmosSignRequest, DataType}; use ur_registry::cosmos::cosmos_signature::CosmosSignature; use ur_registry::cosmos::evm_sign_request::{EvmSignRequest, SignDataType}; diff --git a/rust/rust_c/src/ethereum/address.rs b/rust/rust_c/src/ethereum/address.rs index f8d91961e..56deddb99 100644 --- a/rust/rust_c/src/ethereum/address.rs +++ b/rust/rust_c/src/ethereum/address.rs @@ -2,10 +2,10 @@ use alloc::format; use app_ethereum; use cty::c_char; -use app_ethereum::errors::EthereumError; use crate::common::structs::SimpleResponse; use crate::common::types::PtrString; use crate::common::utils::{convert_c_char, recover_c_char}; +use app_ethereum::errors::EthereumError; #[no_mangle] pub extern "C" fn eth_get_address( diff --git a/rust/rust_c/src/near/mod.rs b/rust/rust_c/src/near/mod.rs index 5839deafd..c1d6dcbe3 100644 --- a/rust/rust_c/src/near/mod.rs +++ b/rust/rust_c/src/near/mod.rs @@ -1,12 +1,12 @@ -use structs::DisplayNearTx; -use alloc::string::ToString; -use alloc::{format, vec}; -use app_near::errors::NearError; use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; use crate::common::structs::{TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use crate::extract_ptr_with_type; +use alloc::string::ToString; +use alloc::{format, vec}; +use app_near::errors::NearError; +use structs::DisplayNearTx; use ur_registry::near::near_sign_request::NearSignRequest; use ur_registry::near::near_signature::NearSignature; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/solana/mod.rs b/rust/rust_c/src/solana/mod.rs index ee30c3940..2a2287c8f 100644 --- a/rust/rust_c/src/solana/mod.rs +++ b/rust/rust_c/src/solana/mod.rs @@ -1,15 +1,15 @@ -use structs::{DisplaySolanaMessage, DisplaySolanaTx}; -use alloc::format; -use alloc::string::ToString; -use app_solana::errors::SolanaError; -use app_solana::parse_message; use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; +use alloc::format; +use alloc::string::ToString; +use app_solana::errors::SolanaError; +use app_solana::parse_message; use cty::c_char; +use structs::{DisplaySolanaMessage, DisplaySolanaTx}; use ur_registry::solana::sol_sign_request::SolSignRequest; use ur_registry::solana::sol_signature::SolSignature; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/stellar/mod.rs b/rust/rust_c/src/stellar/mod.rs index 8a234eb63..5c6c832c9 100644 --- a/rust/rust_c/src/stellar/mod.rs +++ b/rust/rust_c/src/stellar/mod.rs @@ -4,16 +4,16 @@ use alloc::slice; use alloc::string::ToString; use cty::c_char; -use structs::DisplayStellarTx; -use app_stellar::strkeys::{sign_hash, sign_signature_base}; -use app_stellar::{address::get_address, base_to_xdr}; use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; +use app_stellar::strkeys::{sign_hash, sign_signature_base}; +use app_stellar::{address::get_address, base_to_xdr}; use hex; +use structs::DisplayStellarTx; use ur_registry::stellar::stellar_sign_request::{SignType, StellarSignRequest}; use ur_registry::stellar::stellar_signature::StellarSignature; use ur_registry::traits::{RegistryItem, To}; diff --git a/rust/rust_c/src/sui/mod.rs b/rust/rust_c/src/sui/mod.rs index c7b36c5fb..b87948f19 100644 --- a/rust/rust_c/src/sui/mod.rs +++ b/rust/rust_c/src/sui/mod.rs @@ -9,16 +9,16 @@ use ur_registry::sui::sui_sign_request::SuiSignRequest; use ur_registry::sui::sui_signature::SuiSignature; use ur_registry::traits::RegistryItem; -use app_sui::errors::SuiError; -use app_utils::normalize_path; use crate::common::errors::RustCError; -use crate::extract_ptr_with_type; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{convert_c_char, recover_c_char}; -use structs::DisplaySuiSignMessageHash; +use crate::extract_ptr_with_type; +use app_sui::errors::SuiError; +use app_utils::normalize_path; use structs::DisplaySuiIntentMessage; +use structs::DisplaySuiSignMessageHash; pub mod structs; diff --git a/rust/rust_c/src/tron/mod.rs b/rust/rust_c/src/tron/mod.rs index 6fc23da01..335e5cd3d 100644 --- a/rust/rust_c/src/tron/mod.rs +++ b/rust/rust_c/src/tron/mod.rs @@ -1,15 +1,15 @@ pub mod structs; -use structs::DisplayTron; -use alloc::boxed::Box; -use alloc::slice; use crate::common::errors::RustCError; use crate::common::keystone; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{QRCodeType, UREncodeResult}; use crate::common::utils::{convert_c_char, recover_c_char}; +use alloc::boxed::Box; +use alloc::slice; use cty::c_char; +use structs::DisplayTron; #[no_mangle] pub extern "C" fn tron_check_keystone( diff --git a/rust/rust_c/src/wallet/btc_only_wallet.rs b/rust/rust_c/src/wallet/btc_only_wallet.rs index 0d09372ac..ec4fad978 100644 --- a/rust/rust_c/src/wallet/btc_only_wallet.rs +++ b/rust/rust_c/src/wallet/btc_only_wallet.rs @@ -3,14 +3,14 @@ use alloc::vec::Vec; use alloc::{format, vec}; use app_utils::normalize_path; -use bitcoin::bip32::{DerivationPath, Xpub}; use crate::common::errors::RustCError; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::{Ptr, PtrBytes, PtrString, PtrT}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use bitcoin::bip32::{DerivationPath, Xpub}; use core::slice; use core::str::FromStr; use cty::{int32_t, uint32_t}; diff --git a/rust/rust_c/src/wallet/mod.rs b/rust/rust_c/src/wallet/mod.rs index 3d89d7745..7c467be25 100644 --- a/rust/rust_c/src/wallet/mod.rs +++ b/rust/rust_c/src/wallet/mod.rs @@ -1,4 +1,4 @@ pub mod btc_only_wallet; pub use btc_only_wallet::*; #[cfg(feature = "multi-coins")] -pub mod multi_coins_wallet; \ No newline at end of file +pub mod multi_coins_wallet; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs index d51cecd5d..d47899fe0 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs @@ -8,13 +8,13 @@ use ur_registry::error::URError; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; use ur_registry::traits::RegistryItem; -use app_wallets::aptos::generate_sync_ur; use crate::common::errors::RustCError; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::PtrT; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use app_wallets::aptos::generate_sync_ur; #[no_mangle] pub extern "C" fn get_connect_aptos_wallet_ur( diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs index bba618c1d..886865601 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs @@ -1,9 +1,9 @@ -use alloc::slice; -use alloc::vec::Vec; -use app_arweave::generate_public_key_from_primes; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::recover_c_char; +use alloc::slice; +use alloc::vec::Vec; +use app_arweave::generate_public_key_from_primes; use cty::uint32_t; use hex; use ur_registry::arweave::arweave_crypto_account::ArweaveCryptoAccount; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs index 484d6a4ac..be5e0299a 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs @@ -1,10 +1,10 @@ -use alloc::{format, string::ToString}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::{Ptr, PtrBytes}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::recover_c_array; +use crate::extract_array; +use alloc::{format, string::ToString}; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs index 99986f7f0..cdc34eb7d 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs @@ -1,10 +1,10 @@ -use alloc::{format, string::ToString}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use alloc::{format, string::ToString}; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs b/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs index abeb7c4e9..b5d9fe656 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/imtoken.rs @@ -1,10 +1,10 @@ -use alloc::format; -use alloc::string::ToString; -use app_wallets::metamask::ETHAccountTypeApp::Bip44Standard; -use crate::extract_array; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::UREncodeResult; use crate::common::utils::recover_c_char; +use crate::extract_array; +use alloc::format; +use alloc::string::ToString; +use app_wallets::metamask::ETHAccountTypeApp::Bip44Standard; use cty::uint32_t; use ur_registry::crypto_hd_key::CryptoHDKey; use ur_registry::error::URError; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs index 6e556da1d..56f5a94e2 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs @@ -1,13 +1,13 @@ use super::structs::KeplrAccount; -use alloc::format; -use alloc::string::ToString; -use alloc::vec::Vec; -use app_wallets::keplr::{generate_sync_ur, sync_info::SyncInfo}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::types::{PtrBytes, PtrT}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use alloc::format; +use alloc::string::ToString; +use alloc::vec::Vec; +use app_wallets::keplr::{generate_sync_ur, sync_info::SyncInfo}; use cty::uint32_t; use keystore::algorithms::secp256k1::derive_extend_public_key; use ur_registry::error::URError; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs index c00b99756..f244037f0 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs @@ -1,10 +1,10 @@ -use alloc::{format, string::ToString}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use alloc::{format, string::ToString}; use ur_registry::error::URError; use super::utils::normalize_xpub; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs index 79c5e28db..2ac622bee 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs @@ -1,10 +1,10 @@ -use alloc::{format, string::ToString}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use alloc::{format, string::ToString}; use ur_registry::{ error::URError, extend::crypto_multi_accounts::CryptoMultiAccounts, traits::RegistryItem, }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs index 7c1bdf0db..1fa48c698 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs @@ -7,13 +7,13 @@ use hex; use ur_registry::error::URError; use ur_registry::traits::RegistryItem; -use app_wallets::solana::generate_sync_ur; use crate::common::errors::RustCError; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::PtrT; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use app_wallets::solana::generate_sync_ur; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; #[no_mangle] diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs index 7a8181135..93b2f5883 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs @@ -1,13 +1,13 @@ -use alloc::collections::BTreeMap; -use alloc::format; -use app_wallets::sui::generate_sync_ur; -use bitcoin::bip32::DerivationPath; use crate::common::errors::RustCError; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::PtrT; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use alloc::collections::BTreeMap; +use alloc::format; +use app_wallets::sui::generate_sync_ur; +use bitcoin::bip32::DerivationPath; use core::slice; use core::str::FromStr; use hex; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs b/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs index 3eb423dda..efff5fc38 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/utils.rs @@ -1,11 +1,11 @@ use core::str::FromStr; -use alloc::vec; -use alloc::vec::Vec; -use app_utils::normalize_path; use crate::common::errors::RustCError; use crate::common::structs::ExtendedPublicKey; use crate::common::utils::recover_c_char; +use alloc::vec; +use alloc::vec::Vec; +use app_utils::normalize_path; use { bitcoin::bip32::{DerivationPath, Xpub}, hex, diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs index d7ee10f35..56001feca 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs @@ -7,13 +7,13 @@ use hex; use ur_registry::error::URError; use ur_registry::traits::RegistryItem; -use app_wallets::xbull::generate_sync_ur; use crate::common::errors::RustCError; use crate::common::ffi::CSliceFFI; use crate::common::structs::ExtendedPublicKey; use crate::common::types::PtrT; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use app_wallets::xbull::generate_sync_ur; use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts; #[no_mangle] diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs index d1dc8bd1c..749d5b633 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs @@ -1,7 +1,7 @@ -use app_wallets::xrp_toolkit::generate_sync_ur; use crate::common::types::PtrString; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::recover_c_char; +use app_wallets::xrp_toolkit::generate_sync_ur; use ur_registry::bytes::Bytes; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs b/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs index 85f5a0a12..550a4e0ae 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/zcash.rs @@ -1,13 +1,13 @@ -use alloc::string::ToString; -use alloc::vec::Vec; -use alloc::{format, slice}; -use app_wallets::zcash::{generate_sync_ur, UFVKInfo}; -use crate::extract_array; use crate::common::ffi::CSliceFFI; use crate::common::structs::ZcashKey; use crate::common::types::{Ptr, PtrBytes, PtrString}; use crate::common::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{recover_c_array, recover_c_char}; +use crate::extract_array; +use alloc::string::ToString; +use alloc::vec::Vec; +use alloc::{format, slice}; +use app_wallets::zcash::{generate_sync_ur, UFVKInfo}; use ur_registry::bytes::Bytes; use ur_registry::error::URError; use ur_registry::traits::RegistryItem; diff --git a/rust/rust_c/src/xrp/mod.rs b/rust/rust_c/src/xrp/mod.rs index 274b6dcf3..b96c286f6 100644 --- a/rust/rust_c/src/xrp/mod.rs +++ b/rust/rust_c/src/xrp/mod.rs @@ -18,12 +18,12 @@ use ur_registry::pb::protoc::sign_transaction::Transaction::XrpTx; use ur_registry::traits::RegistryItem; use crate::common::errors::{ErrorCodes, KeystoneError, RustCError}; -use crate::extract_ptr_with_type; use crate::common::keystone::build_payload; use crate::common::structs::{SimpleResponse, TransactionCheckResult, TransactionParseResult}; use crate::common::types::{PtrBytes, PtrString, PtrT, PtrUR}; use crate::common::ur::{QRCodeType, UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; use crate::common::utils::{convert_c_char, recover_c_char}; +use crate::extract_ptr_with_type; use structs::DisplayXrpTx; diff --git a/rust/zcash_vendor/src/pczt_ext.rs b/rust/zcash_vendor/src/pczt_ext.rs index 357758ec1..82f889028 100644 --- a/rust/zcash_vendor/src/pczt_ext.rs +++ b/rust/zcash_vendor/src/pczt_ext.rs @@ -8,7 +8,7 @@ use pczt::{ roles::low_level_signer::Signer, transparent::{Input, Output}, }; -use transparent::{sighash::SignableInput}; +use transparent::sighash::SignableInput; use zcash_protocol::value::ZatBalance; /// TxId tree root personalization From 81f717ce4937fef6d0acb58c14edccd52ca00408 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 25 Dec 2024 19:02:35 +0800 Subject: [PATCH 27/31] style: run cargo fix --- rust/apps/ton/src/structs.rs | 2 +- rust/apps/wallets/src/zcash.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/rust/apps/ton/src/structs.rs b/rust/apps/ton/src/structs.rs index 3bec7c915..fb0086550 100644 --- a/rust/apps/ton/src/structs.rs +++ b/rust/apps/ton/src/structs.rs @@ -8,7 +8,7 @@ use crate::utils::shorten_string; use crate::vendor::address::TonAddress; use crate::vendor::cell::BagOfCells; use alloc::string::{String, ToString}; -use alloc::vec; + use hex; use serde::Serialize; use serde_json::{self, json, Value}; diff --git a/rust/apps/wallets/src/zcash.rs b/rust/apps/wallets/src/zcash.rs index 82b53f229..a2eba6bc5 100644 --- a/rust/apps/wallets/src/zcash.rs +++ b/rust/apps/wallets/src/zcash.rs @@ -1,12 +1,10 @@ -use alloc::string::{String, ToString}; -use alloc::vec; +use alloc::string::{String}; + use alloc::vec::Vec; use app_utils::impl_public_struct; use ur_registry::{ - crypto_hd_key::CryptoHDKey, - crypto_key_path::CryptoKeyPath, - error::{URError, URResult}, + error::{URResult}, zcash::{ zcash_accounts::ZcashAccounts, zcash_unified_full_viewing_key::ZcashUnifiedFullViewingKey, }, From 1658dd1a35e1e6adc61eaa1d6818ec50feed035f Mon Sep 17 00:00:00 2001 From: soralit Date: Thu, 26 Dec 2024 09:06:36 +0800 Subject: [PATCH 28/31] style: apply clippy suggestions --- .../aptos/src/aptos_type/account_address.rs | 4 +- rust/apps/aptos/src/aptos_type/module.rs | 2 +- rust/apps/aptos/src/aptos_type/parser.rs | 16 +- .../aptos/src/aptos_type/safe_serialize.rs | 4 +- .../src/aptos_type/transaction_argument.rs | 2 +- rust/apps/aptos/src/aptos_type/value.rs | 4 +- rust/apps/aptos/src/errors.rs | 6 +- rust/apps/aptos/src/lib.rs | 8 +- rust/apps/aptos/src/parser.rs | 8 +- rust/apps/arweave/src/data_item.rs | 20 ++- rust/apps/arweave/src/deep_hash.rs | 4 +- rust/apps/arweave/src/errors.rs | 4 +- rust/apps/arweave/src/lib.rs | 14 +- rust/apps/arweave/src/tokens.rs | 7 +- rust/apps/arweave/src/transaction.rs | 9 +- rust/apps/cardano/src/address.rs | 12 +- rust/apps/cardano/src/governance.rs | 6 +- rust/apps/cardano/src/structs.rs | 31 ++-- rust/apps/cardano/src/transaction.rs | 8 +- rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs | 2 +- rust/apps/cosmos/src/lib.rs | 10 +- rust/apps/cosmos/src/proto_wrapper/fee.rs | 8 +- .../cosmos/src/proto_wrapper/mode_info.rs | 5 +- .../cosmos/src/proto_wrapper/msg/common.rs | 40 ++--- rust/apps/cosmos/src/proto_wrapper/msg/msg.rs | 51 +++---- .../cosmos/src/proto_wrapper/serde_helper.rs | 2 +- .../apps/cosmos/src/proto_wrapper/sign_doc.rs | 8 +- .../cosmos/src/proto_wrapper/signer_info.rs | 6 +- rust/apps/cosmos/src/transaction/detail.rs | 5 +- rust/apps/cosmos/src/transaction/mod.rs | 6 +- rust/apps/cosmos/src/transaction/overview.rs | 11 +- rust/apps/cosmos/src/transaction/utils.rs | 11 +- rust/apps/cosmos/src/utils.rs | 2 +- rust/apps/ethereum/src/abi.rs | 14 +- rust/apps/ethereum/src/eip1559_transaction.rs | 2 +- rust/apps/ethereum/src/erc20.rs | 2 +- rust/apps/ethereum/src/legacy_transaction.rs | 14 +- rust/apps/ethereum/src/lib.rs | 12 +- rust/apps/ethereum/src/structs.rs | 2 +- rust/apps/near/src/account_id/borsh.rs | 4 +- rust/apps/near/src/account_id/mod.rs | 2 +- rust/apps/near/src/account_id/serde.rs | 4 +- rust/apps/near/src/crypto/errors.rs | 2 +- rust/apps/near/src/crypto/mod.rs | 2 +- rust/apps/near/src/crypto/pubkey.rs | 6 +- rust/apps/near/src/errors.rs | 4 +- rust/apps/near/src/lib.rs | 2 +- rust/apps/near/src/parser/mod.rs | 2 +- rust/apps/near/src/parser/utils.rs | 18 +-- rust/apps/near/src/primitives_core/account.rs | 2 +- rust/apps/near/src/primitives_core/hash.rs | 7 +- .../near/src/primitives_core/serialize.rs | 2 +- rust/apps/stellar/src/address.rs | 2 +- rust/apps/stellar/src/lib.rs | 4 +- rust/apps/stellar/src/strkeys.rs | 8 +- rust/apps/sui/src/lib.rs | 8 +- rust/apps/ton/src/jettons.rs | 2 +- rust/apps/ton/src/lib.rs | 4 +- rust/apps/ton/src/messages/jetton.rs | 4 +- rust/apps/ton/src/messages/mod.rs | 20 ++- rust/apps/ton/src/messages/nft.rs | 4 +- rust/apps/ton/src/mnemonic.rs | 14 +- rust/apps/ton/src/structs.rs | 6 +- rust/apps/ton/src/transaction.rs | 4 +- rust/apps/ton/src/utils.rs | 2 +- rust/apps/ton/src/vendor/address/mod.rs | 2 +- rust/apps/tron/src/address.rs | 2 +- rust/apps/tron/src/errors.rs | 6 +- rust/apps/tron/src/transaction/parser.rs | 8 +- .../apps/tron/src/transaction/wrapped_tron.rs | 18 +-- rust/apps/utils/src/lib.rs | 14 +- rust/apps/wallets/src/aptos.rs | 2 +- rust/apps/wallets/src/backpack.rs | 30 ++-- rust/apps/wallets/src/bitget.rs | 44 +++--- rust/apps/wallets/src/blue_wallet.rs | 6 +- rust/apps/wallets/src/common.rs | 2 +- rust/apps/wallets/src/companion_app.rs | 12 +- rust/apps/wallets/src/keplr/mod.rs | 10 +- rust/apps/wallets/src/keystone.rs | 6 +- rust/apps/wallets/src/metamask.rs | 8 +- rust/apps/wallets/src/okx.rs | 16 +- rust/apps/wallets/src/solana.rs | 2 +- rust/apps/wallets/src/sui.rs | 2 +- rust/apps/wallets/src/thor_wallet.rs | 16 +- rust/apps/wallets/src/tonkeeper.rs | 2 +- rust/apps/wallets/src/utils.rs | 10 +- rust/apps/wallets/src/xbull.rs | 2 +- rust/apps/wallets/src/xrp_toolkit.rs | 4 +- rust/apps/xrp/src/address/mod.rs | 4 +- rust/apps/xrp/src/address/ripple_keypair.rs | 2 +- rust/apps/xrp/src/errors.rs | 4 +- rust/apps/xrp/src/lib.rs | 10 +- rust/apps/xrp/src/transaction/mod.rs | 10 +- rust/apps/zcash/src/lib.rs | 9 +- rust/apps/zcash/src/pczt/check.rs | 16 +- rust/apps/zcash/src/pczt/parse.rs | 50 +++--- rust/apps/zcash/src/pczt/sign.rs | 10 +- rust/rust_c/build.rs | 2 +- rust/rust_c/src/aptos/mod.rs | 8 +- rust/rust_c/src/arweave/mod.rs | 22 +-- rust/rust_c/src/bitcoin/msg.rs | 13 +- rust/rust_c/src/bitcoin/multi_sig/mod.rs | 18 +-- rust/rust_c/src/bitcoin/multi_sig/structs.rs | 98 ++++++------ rust/rust_c/src/bitcoin/psbt.rs | 34 ++--- rust/rust_c/src/bitcoin/structs.rs | 6 +- rust/rust_c/src/cardano/mod.rs | 46 +++--- rust/rust_c/src/cardano/structs.rs | 2 +- rust/rust_c/src/common/free.rs | 2 +- rust/rust_c/src/common/keystone.rs | 19 ++- rust/rust_c/src/common/macros.rs | 4 +- rust/rust_c/src/common/mod.rs | 12 +- rust/rust_c/src/common/qrcode/mod.rs | 10 +- rust/rust_c/src/common/ur.rs | 14 +- rust/rust_c/src/common/ur_ext.rs | 2 +- rust/rust_c/src/common/web_auth.rs | 20 +-- rust/rust_c/src/cosmos/mod.rs | 8 +- rust/rust_c/src/ethereum/abi.rs | 2 +- rust/rust_c/src/ethereum/mod.rs | 42 +++--- rust/rust_c/src/ethereum/structs.rs | 2 +- rust/rust_c/src/near/mod.rs | 2 +- rust/rust_c/src/solana/mod.rs | 6 +- rust/rust_c/src/stellar/mod.rs | 16 +- rust/rust_c/src/sui/mod.rs | 4 +- rust/rust_c/src/ton/mod.rs | 23 ++- rust/rust_c/src/ton/structs.rs | 6 +- rust/rust_c/src/wallet/btc_only_wallet.rs | 22 +-- .../src/wallet/multi_coins_wallet/aptos.rs | 4 +- .../wallet/multi_coins_wallet/arconnect.rs | 10 +- .../src/wallet/multi_coins_wallet/backpack.rs | 2 +- .../src/wallet/multi_coins_wallet/bitget.rs | 2 +- .../src/wallet/multi_coins_wallet/keplr.rs | 6 +- .../src/wallet/multi_coins_wallet/keystone.rs | 2 +- .../src/wallet/multi_coins_wallet/mod.rs | 16 +- .../src/wallet/multi_coins_wallet/okx.rs | 2 +- .../src/wallet/multi_coins_wallet/solana.rs | 4 +- .../src/wallet/multi_coins_wallet/structs.rs | 2 +- .../src/wallet/multi_coins_wallet/sui.rs | 4 +- .../wallet/multi_coins_wallet/thor_wallet.rs | 10 +- .../wallet/multi_coins_wallet/tonkeeper.rs | 2 +- .../src/wallet/multi_coins_wallet/xbull.rs | 4 +- .../wallet/multi_coins_wallet/xrp_toolkit.rs | 2 +- rust/rust_c/src/xrp/mod.rs | 21 ++- rust/rust_c/src/zcash/mod.rs | 10 +- rust/sim_qr_reader/src/lib.rs | 16 +- rust/zcash_vendor/src/pczt_ext.rs | 142 +++++++++--------- 145 files changed, 760 insertions(+), 826 deletions(-) diff --git a/rust/apps/aptos/src/aptos_type/account_address.rs b/rust/apps/aptos/src/aptos_type/account_address.rs index 87ec9c342..0280feabe 100644 --- a/rust/apps/aptos/src/aptos_type/account_address.rs +++ b/rust/apps/aptos/src/aptos_type/account_address.rs @@ -2,7 +2,7 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; use core::{convert::TryFrom, fmt, str::FromStr}; -use hex; + use hex::FromHex; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; @@ -32,7 +32,7 @@ impl AccountAddress { } pub fn short_str_lossless(&self) -> String { - let hex_str = hex::encode(&self.0).trim_start_matches('0').to_string(); + let hex_str = hex::encode(self.0).trim_start_matches('0').to_string(); if hex_str.is_empty() { "0".to_string() } else { diff --git a/rust/apps/aptos/src/aptos_type/module.rs b/rust/apps/aptos/src/aptos_type/module.rs index c8eb133ff..5e43c5d9f 100644 --- a/rust/apps/aptos/src/aptos_type/module.rs +++ b/rust/apps/aptos/src/aptos_type/module.rs @@ -4,7 +4,7 @@ use alloc::vec; use alloc::vec::Vec; use core::fmt; -use hex; + use serde::{Deserialize, Serialize}; #[derive(Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] diff --git a/rust/apps/aptos/src/aptos_type/parser.rs b/rust/apps/aptos/src/aptos_type/parser.rs index e6d34eecd..c7c08b230 100644 --- a/rust/apps/aptos/src/aptos_type/parser.rs +++ b/rust/apps/aptos/src/aptos_type/parser.rs @@ -15,7 +15,7 @@ use alloc::string::{String, ToString}; use alloc::vec; use alloc::vec::Vec; use core::iter::Peekable; -use hex; + #[derive(Eq, PartialEq, Debug)] enum Token { @@ -114,7 +114,7 @@ fn next_token(s: &str) -> crate::errors::Result> { ',' => (Token::Comma, 1), ':' => match it.next() { Some(':') => (Token::ColonColon, 2), - _ => return Err(AptosError::ParseTxError(format!("unrecognized token"))), + _ => return Err(AptosError::ParseTxError("unrecognized token".to_string())), }, '0' if it.peek() == Some(&'x') || it.peek() == Some(&'X') => { it.next().unwrap(); @@ -134,7 +134,7 @@ fn next_token(s: &str) -> crate::errors::Result> { let len = r.len(); (Token::Address(r), len) } - _ => return Err(AptosError::ParseTxError(format!("unrecognized token"))), + _ => return Err(AptosError::ParseTxError("unrecognized token".to_string())), } } c if c.is_ascii_digit() => next_number(c, it)?, @@ -145,7 +145,7 @@ fn next_token(s: &str) -> crate::errors::Result> { match it.next() { Some('"') => break, Some(c) if c.is_ascii() => r.push(c), - _ => return Err(AptosError::ParseTxError(format!("unrecognized token"))), + _ => return Err(AptosError::ParseTxError("unrecognized token".to_string())), } } let len = r.len() + 3; @@ -158,7 +158,7 @@ fn next_token(s: &str) -> crate::errors::Result> { match it.next() { Some('"') => break, Some(c) if c.is_ascii_hexdigit() => r.push(c), - _ => return Err(AptosError::ParseTxError(format!("unrecognized token"))), + _ => return Err(AptosError::ParseTxError("unrecognized token".to_string())), } } let len = r.len() + 3; @@ -190,7 +190,7 @@ fn next_token(s: &str) -> crate::errors::Result> { let len = r.len(); (name_token(r), len) } - _ => return Err(AptosError::ParseTxError(format!("unrecognized token"))), + _ => return Err(AptosError::ParseTxError("unrecognized token".to_string())), })), } } @@ -218,9 +218,7 @@ impl> Parser { fn next(&mut self) -> crate::errors::Result { match self.it.next() { Some(tok) => Ok(tok), - None => Err(AptosError::ParseTxError(format!( - "out of tokens, this should not happen" - ))), + None => Err(AptosError::ParseTxError("out of tokens, this should not happen".to_string())), } } diff --git a/rust/apps/aptos/src/aptos_type/safe_serialize.rs b/rust/apps/aptos/src/aptos_type/safe_serialize.rs index 40cdcdf80..ca3f3f104 100644 --- a/rust/apps/aptos/src/aptos_type/safe_serialize.rs +++ b/rust/apps/aptos/src/aptos_type/safe_serialize.rs @@ -13,8 +13,8 @@ where S: Serializer, T: Serialize, { - let res = t.serialize(s); - res + + t.serialize(s) } pub(crate) fn type_tag_recursive_deserialize<'de, D, T>(d: D) -> Result diff --git a/rust/apps/aptos/src/aptos_type/transaction_argument.rs b/rust/apps/aptos/src/aptos_type/transaction_argument.rs index 7297f140b..63843a680 100644 --- a/rust/apps/aptos/src/aptos_type/transaction_argument.rs +++ b/rust/apps/aptos/src/aptos_type/transaction_argument.rs @@ -3,7 +3,7 @@ use crate::aptos_type::value::MoveValue; use alloc::format; use alloc::vec::Vec; use core::{convert::TryFrom, fmt}; -use hex; + use serde::{Deserialize, Serialize}; #[derive(Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] diff --git a/rust/apps/aptos/src/aptos_type/value.rs b/rust/apps/aptos/src/aptos_type/value.rs index c99452815..170bd792b 100644 --- a/rust/apps/aptos/src/aptos_type/value.rs +++ b/rust/apps/aptos/src/aptos_type/value.rs @@ -3,7 +3,7 @@ use crate::aptos_type::identifier::Identifier; use crate::aptos_type::language_storage::{StructTag, TypeTag}; use crate::errors::AptosError; use alloc::boxed::Box; -use alloc::format; + use alloc::string::ToString; use alloc::vec::Vec; use core::{ @@ -557,7 +557,7 @@ impl TryInto for &MoveStructLayout { use MoveStructLayout::*; match self { Runtime(..) | CheckedRuntime { fields: _, tag: _ } | WithFields(..) => Err(AptosError::ParseTxError( - format!("Invalid MoveTypeLayout -> StructTag conversion--needed MoveLayoutType::WithTypes")) + "Invalid MoveTypeLayout -> StructTag conversion--needed MoveLayoutType::WithTypes".to_string()) ), WithTypes { type_, .. } => Ok(type_.clone()), } diff --git a/rust/apps/aptos/src/errors.rs b/rust/apps/aptos/src/errors.rs index cd5ad1306..c956ad4f7 100644 --- a/rust/apps/aptos/src/errors.rs +++ b/rust/apps/aptos/src/errors.rs @@ -26,13 +26,13 @@ impl From for AptosError { impl From for AptosError { fn from(value: hex::FromHexError) -> Self { - Self::InvalidData(format!("hex operation failed {}", value.to_string())) + Self::InvalidData(format!("hex operation failed {}", value)) } } impl From for AptosError { fn from(value: FromUtf8Error) -> Self { - Self::InvalidData(format!("utf8 operation failed {}", value.to_string())) + Self::InvalidData(format!("utf8 operation failed {}", value)) } } @@ -44,6 +44,6 @@ impl From for AptosError { impl From for AptosError { fn from(value: bcs::Error) -> Self { - Self::InvalidData(format!("bsc operation failed {}", value.to_string())) + Self::InvalidData(format!("bsc operation failed {}", value)) } } diff --git a/rust/apps/aptos/src/lib.rs b/rust/apps/aptos/src/lib.rs index 127166d7a..9c753d8ae 100644 --- a/rust/apps/aptos/src/lib.rs +++ b/rust/apps/aptos/src/lib.rs @@ -15,7 +15,7 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; use cryptoxide::hashing::sha3::Sha3_256; -use hex; + use parser::AptosTx; use crate::errors::Result; @@ -32,15 +32,15 @@ pub fn generate_address(pub_key: &str) -> Result { } pub fn parse_tx(data: &Vec) -> crate::errors::Result { - Ok(Parser::parse_tx(data)?) + Parser::parse_tx(data) } pub fn parse_msg(data: &Vec) -> crate::errors::Result { - Ok(Parser::parse_msg(data)?) + Parser::parse_msg(data) } pub fn sign(message: Vec, hd_path: &String, seed: &[u8]) -> errors::Result<[u8; 64]> { - keystore::algorithms::ed25519::slip10_ed25519::sign_message_by_seed(&seed, hd_path, &message) + keystore::algorithms::ed25519::slip10_ed25519::sign_message_by_seed(seed, hd_path, &message) .map_err(|e| errors::AptosError::KeystoreError(format!("sign failed {:?}", e.to_string()))) } diff --git a/rust/apps/aptos/src/parser.rs b/rust/apps/aptos/src/parser.rs index 70d04cbe7..e1cd787cf 100644 --- a/rust/apps/aptos/src/parser.rs +++ b/rust/apps/aptos/src/parser.rs @@ -32,7 +32,7 @@ pub fn is_tx(data: &Vec) -> bool { 0x6f, 0x66, 0x93, 0xbd, 0xdc, 0x1a, 0x9f, 0xec, 0x9e, 0x67, 0x4a, 0x46, 0x1e, 0xaa, 0x00, 0xb1, 0x93, ]; - return data.len() > 32 && data[..32] == tx_prefix; + data.len() > 32 && data[..32] == tx_prefix } impl Parser { @@ -42,7 +42,7 @@ impl Parser { data_parse = data[32..].to_vec(); } let tx: RawTransaction = bcs::from_bytes(&data_parse).map_err(|err| { - AptosError::ParseTxError(format!("bcs deserialize failed {}", err.to_string())) + AptosError::ParseTxError(format!("bcs deserialize failed {}", err)) })?; Ok(AptosTx::new(tx)) } @@ -73,14 +73,14 @@ impl AptosTx { Ok(v) => Ok(Value::String(v)), Err(e) => Err(AptosError::ParseTxError(format!( "to json failed {}", - e.to_string() + e ))), } } fn to_json_value(&self) -> Result { let value = serde_json::to_value(&self.tx) - .map_err(|e| AptosError::ParseTxError(format!("to json failed {}", e.to_string())))?; + .map_err(|e| AptosError::ParseTxError(format!("to json failed {}", e)))?; Ok(value) } diff --git a/rust/apps/arweave/src/data_item.rs b/rust/apps/arweave/src/data_item.rs index 953569234..45466900b 100644 --- a/rust/apps/arweave/src/data_item.rs +++ b/rust/apps/arweave/src/data_item.rs @@ -26,7 +26,7 @@ impl Tags { let value = avro_decode_string(&mut avro_bytes)?; tags.push(Tag { name, value }) } - return Ok(Tags { len, data: tags }); + Ok(Tags { len, data: tags }) } } @@ -43,7 +43,7 @@ fn avro_decode_long(reader: &mut Vec) -> Result { loop { if j > 9 { // if j * 7 > 64 - return Err(ArweaveError::AvroError(format!("Integer overflow"))); + return Err(ArweaveError::AvroError("Integer overflow".to_string())); } let head = reader.remove(0); buf[0] = head; @@ -64,10 +64,8 @@ fn avro_decode_long(reader: &mut Vec) -> Result { fn avro_decode_string(reader: &mut Vec) -> Result { let len = avro_decode_long(reader)?; let buf = reader.drain(..len as usize).collect(); - Ok( - String::from_utf8(buf) - .map_err(|e| ArweaveError::AvroError(format!("{}", e.to_string())))?, - ) + String::from_utf8(buf) + .map_err(|e| ArweaveError::AvroError(format!("{}", e))) } impl_public_struct!(DataItem { @@ -102,7 +100,7 @@ impl DataItem { let mut reader = binary.to_vec(); let signature_type = u16::from_le_bytes(reader.drain(..2).collect::>().try_into().map_err( - |_| ArweaveError::ParseTxError(format!("Invalid DataItem signature_type")), + |_| ArweaveError::ParseTxError("Invalid DataItem signature_type".to_string()), )?); if signature_type != SignatureType::ARWEAVE as u16 { @@ -132,12 +130,12 @@ impl DataItem { let tags_number = u64::from_le_bytes(reader.drain(..8).collect::>().try_into().map_err( - |_| ArweaveError::ParseTxError(format!("Invalid DataItem tags_number")), + |_| ArweaveError::ParseTxError("Invalid DataItem tags_number".to_string()), )?); let tags_bytes_number = u64::from_le_bytes(reader.drain(..8).collect::>().try_into().map_err( - |_| ArweaveError::ParseTxError(format!("Invalid DataItem tags_number")), + |_| ArweaveError::ParseTxError("Invalid DataItem tags_number".to_string()), )?); let raw_tags: Vec = reader.drain(..tags_bytes_number as usize).collect(); @@ -201,8 +199,8 @@ mod tests { ); assert_eq!(result.anchor, None); assert_eq!(result.tags.len, 8); - assert_eq!(result.tags.data.get(0).unwrap().name, "Action"); - assert_eq!(result.tags.data.get(0).unwrap().value, "Transfer"); + assert_eq!(result.tags.data.first().unwrap().name, "Action"); + assert_eq!(result.tags.data.first().unwrap().value, "Transfer"); assert_eq!(result.tags.data.get(7).unwrap().name, "Content-Type"); assert_eq!(result.tags.data.get(7).unwrap().value, "text/plain"); } diff --git a/rust/apps/arweave/src/deep_hash.rs b/rust/apps/arweave/src/deep_hash.rs index 3f296da6c..e528e39cc 100644 --- a/rust/apps/arweave/src/deep_hash.rs +++ b/rust/apps/arweave/src/deep_hash.rs @@ -23,9 +23,7 @@ pub fn hash_sha384(message: &[u8]) -> Result<[u8; 48], ArweaveError> { pub fn hash_all_sha384(messages: Vec<&[u8]>) -> Result<[u8; 48], ArweaveError> { let hash: Vec = messages .into_iter() - .map(|m| hash_sha384(m).unwrap()) - .into_iter() - .flatten() + .flat_map(|m| hash_sha384(m).unwrap()) .collect(); let hash = hash_sha384(&hash)?; Ok(hash) diff --git a/rust/apps/arweave/src/errors.rs b/rust/apps/arweave/src/errors.rs index 50b03091e..8164ed720 100644 --- a/rust/apps/arweave/src/errors.rs +++ b/rust/apps/arweave/src/errors.rs @@ -27,8 +27,8 @@ pub type Result = core::result::Result; impl From for ArweaveError { fn from(value: KeystoreError) -> Self { match value { - KeystoreError::DerivePubKey(data) => Self::KeystoreError(format!("{}", data)), - KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(format!("{}", data)), + KeystoreError::DerivePubKey(data) => Self::KeystoreError(data.to_string()), + KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(data.to_string()), KeystoreError::XPubError(data) => Self::KeystoreError(data), KeystoreError::SeedError(data) => Self::KeystoreError(data), KeystoreError::DerivationError(data) => Self::KeystoreError(data), diff --git a/rust/apps/arweave/src/lib.rs b/rust/apps/arweave/src/lib.rs index 7e4869783..7d874490d 100644 --- a/rust/apps/arweave/src/lib.rs +++ b/rust/apps/arweave/src/lib.rs @@ -20,14 +20,14 @@ use aes::cipher::block_padding::Pkcs7; use aes::cipher::{generic_array::GenericArray, BlockDecryptMut, BlockEncryptMut, KeyIvInit}; use alloc::string::{String, ToString}; use alloc::vec::Vec; -use base64; + use data_item::DataItem; -use hex; + use keystore::algorithms::rsa::get_rsa_secret_from_seed; use rsa::{BigUint, RsaPrivateKey}; -use serde_json; + use serde_json::{json, Value}; -use sha2; + use sha2::Digest; use transaction::{Base64, Transaction}; @@ -89,7 +89,7 @@ fn u64_to_ar(value: u64) -> String { let value = format!("{:.12}", value); let value = value.trim_end_matches('0').to_string(); if value.ends_with('.') { - format!("{} AR", value[..value.len() - 1].to_string()) + format!("{} AR", &value[..value.len() - 1]) } else { format!("{} AR", value) } @@ -143,13 +143,13 @@ pub fn parse(data: &Vec) -> Result { "quantity": u64_to_ar(tx.quantity), "reward": u64_to_ar(tx.reward), "data_size": tx.data_size, - "signature_data": tx.deep_hash().map_or_else(|e| format!("unable to deep hash transaction, reason: {}", e.to_string()), |data| hex::encode(data)), + "signature_data": tx.deep_hash().map_or_else(|e| format!("unable to deep hash transaction, reason: {}", e), hex::encode), }, "status": "success" }) } Err(e) => { - let readable = format!("unable to deserialize, reason: {}", e.to_string()); + let readable = format!("unable to deserialize, reason: {}", e); json!({ "status": "failed", "reason": readable diff --git a/rust/apps/arweave/src/tokens.rs b/rust/apps/arweave/src/tokens.rs index 599434de2..d7d2daf48 100644 --- a/rust/apps/arweave/src/tokens.rs +++ b/rust/apps/arweave/src/tokens.rs @@ -17,11 +17,11 @@ impl TokenInfo { let value = u64::from_str_radix(quantity, 10) .map_err(|_e| ArweaveError::ParseTxError(_e.to_string()))?; let divisor = 10u64.pow(self.get_decimal() as u32) as f64; - return Ok(format!( + Ok(format!( "{} {}", (value as f64) / divisor, self.get_symbol() - )); + )) } } @@ -63,6 +63,5 @@ lazy_static! { pub(crate) fn find_token(token_id: &str) -> Option { TOKENS .iter() - .find(|v| v.get_token_id().eq(token_id)) - .map(|v| v.clone()) + .find(|v| v.get_token_id().eq(token_id)).cloned() } diff --git a/rust/apps/arweave/src/transaction.rs b/rust/apps/arweave/src/transaction.rs index 72d50bfed..78b4e6309 100644 --- a/rust/apps/arweave/src/transaction.rs +++ b/rust/apps/arweave/src/transaction.rs @@ -132,7 +132,7 @@ impl FromUtf8Strs> for Tag { impl<'a> ToItems<'a, Vec>> for Vec> { fn to_deep_hash_item(&'a self) -> Result { - if self.len() > 0 { + if !self.is_empty() { Ok(DeepHashItem::List( self.iter() .map(|t| t.to_deep_hash_item().unwrap()) @@ -155,13 +155,10 @@ impl<'a> ToItems<'a, Tag> for Tag { /// A struct of [`Vec`] used for all data and address fields. #[derive(Debug, Clone, PartialEq)] +#[derive(Default)] pub struct Base64(pub Vec); -impl Default for Base64 { - fn default() -> Self { - Base64(vec![]) - } -} + impl fmt::Display for Base64 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/rust/apps/cardano/src/address.rs b/rust/apps/cardano/src/address.rs index 39700ff45..45651d6f1 100644 --- a/rust/apps/cardano/src/address.rs +++ b/rust/apps/cardano/src/address.rs @@ -53,12 +53,12 @@ pub fn derive_address( AddressType::Base => { let payment_key = xpub .derive(DerivationScheme::V2, change)? - .derive(DerivationScheme::V2, index.clone())? + .derive(DerivationScheme::V2, index)? .public_key(); let payment_key_hash = blake2b_224(&payment_key); let stake_key = xpub .derive(DerivationScheme::V2, 2)? - .derive(DerivationScheme::V2, stake_key_index.clone())? + .derive(DerivationScheme::V2, stake_key_index)? .public_key(); let stake_key_hash = blake2b_224(&stake_key); let address = BaseAddress::new( @@ -74,7 +74,7 @@ pub fn derive_address( AddressType::Stake => { let stake_key = xpub .derive(DerivationScheme::V2, 2)? - .derive(DerivationScheme::V2, stake_key_index.clone())? + .derive(DerivationScheme::V2, stake_key_index)? .public_key(); let stake_key_hash = blake2b_224(&stake_key); let address = RewardAddress::new( @@ -89,7 +89,7 @@ pub fn derive_address( AddressType::Enterprise => { let payment_key = xpub .derive(DerivationScheme::V2, 0)? - .derive(DerivationScheme::V2, index.clone())? + .derive(DerivationScheme::V2, index)? .public_key(); let payment_key_hash = blake2b_224(&payment_key); let address = EnterpriseAddress::new( @@ -111,7 +111,7 @@ pub fn derive_pubkey_hash(xpub: String, change: u32, index: u32) -> R<[u8; 28]> let payment_key = xpub .derive(DerivationScheme::V2, change)? - .derive(DerivationScheme::V2, index.clone())? + .derive(DerivationScheme::V2, index)? .public_key(); Ok(blake2b_224(&payment_key)) } @@ -122,7 +122,7 @@ mod tests { use alloc::string::ToString; use alloc::vec; use bech32; - use cardano_serialization_lib::protocol_types::{Address, BaseAddress}; + use cryptoxide::hashing::blake2b_224; use keystore; diff --git a/rust/apps/cardano/src/governance.rs b/rust/apps/cardano/src/governance.rs index a2797d531..1d1263258 100644 --- a/rust/apps/cardano/src/governance.rs +++ b/rust/apps/cardano/src/governance.rs @@ -96,7 +96,7 @@ pub fn parse_payment_address(payment_address: Vec) -> R { #[cfg(test)] mod tests { use super::*; - use ur_registry::crypto_key_path::PathComponent; + #[test] fn test_sign_voting_registration() { @@ -134,8 +134,8 @@ mod tests { CardanoDelegation::new(vote_pub_key1, 1), CardanoDelegation::new(vote_pub_key2, 2), ]; - let entropy = hex::decode("7a4362fd9792e60d97ee258f43fd21af").unwrap(); - let passphrase = b""; + let _entropy = hex::decode("7a4362fd9792e60d97ee258f43fd21af").unwrap(); + let _passphrase = b""; let delegations_vec = build_delegations(delegations).unwrap(); assert_eq!(delegations_vec.len(), 2); diff --git a/rust/apps/cardano/src/structs.rs b/rust/apps/cardano/src/structs.rs index c46fe2d9c..5d085c03e 100644 --- a/rust/apps/cardano/src/structs.rs +++ b/rust/apps/cardano/src/structs.rs @@ -319,10 +319,7 @@ impl ParsedCardanoTx { if tx.body().outputs().len() == 0 { return 1; } - match tx.body().outputs().get(0).address().network_id() { - Ok(id) => id, - Err(_) => 1, - } + tx.body().outputs().get(0).address().network_id().unwrap_or(1) } Some(id) => match id.kind() { NetworkIdKind::Mainnet => 1, @@ -661,10 +658,7 @@ impl ParsedCardanoTx { )); } if let Some(_cert) = cert.as_drep_update() { - let anchor_data_hash = match _cert.anchor() { - Some(anchor) => Some(anchor.anchor_data_hash().to_string()), - None => None, - }; + let anchor_data_hash = _cert.anchor().map(|anchor| anchor.anchor_data_hash().to_string()); let (variant1, variant1_label) = match _cert.voting_credential().kind() { _Ed25519KeyHash => ( _cert @@ -930,10 +924,7 @@ impl ParsedCardanoTx { None => { let cardano_from = CardanoFrom { address: address.clone(), - value: match input.value { - Some(v) => v, - None => 0, - }, + value: input.value.unwrap_or(0), amount: match input.value { Some(v) => normalize_coin(v), None => "Unknown amount".to_string(), @@ -954,14 +945,14 @@ impl ParsedCardanoTx { match map.get(&address) { Some(existing) => { let mut to = existing.clone(); - to.value = to.value + output.value; + to.value += output.value; to.amount = normalize_coin(to.value); if let Some(assets) = output.assets { for x in assets { match to.assets.get(&x.id) { Some(asset) => { let mut new_asset = asset.clone(); - new_asset.value = new_asset.value + x.value; + new_asset.value += x.value; new_asset.amount = normalize_value(new_asset.value); to.assets.insert(new_asset.id.clone(), new_asset); } @@ -1012,9 +1003,7 @@ impl ParsedCardanoTx { .get_cert_keys() .iter() .filter(|v| hex::encode(v.get_master_fingerprint()).eq(&mfp)) - .fold(false, |acc, cur| { - acc || hex::encode(cur.get_master_fingerprint()).eq(&mfp) - }); + .any(|cur| hex::encode(cur.get_master_fingerprint()).eq(&mfp)); if has_my_signer { return Ok(()); @@ -1085,8 +1074,8 @@ impl ParsedCardanoTx { //check utxo address with payment keyhash; let my_pubkey_hash = hex::encode(derive_pubkey_hash( context.get_cardano_xpub(), - change.clone(), - index.clone(), + *change, + *index, )?); let address = utxo.address.clone(); @@ -1243,7 +1232,7 @@ mod tests { #[test] fn test_parse_sign() { let sign_data = hex::decode("84a400828258204e3a6e7fdcb0d0efa17bf79c13aed2b4cb9baf37fb1aa2e39553d5bd720c5c99038258204e3a6e7fdcb0d0efa17bf79c13aed2b4cb9baf37fb1aa2e39553d5bd720c5c99040182a200581d6179df4c75f7616d7d1fd39cbc1a6ea6b40a0d7b89fea62fc0909b6c370119c350a200581d61c9b0c9761fd1dc0404abd55efc895026628b5035ac623c614fbad0310119c35002198ecb0300a0f5f6").unwrap(); - let request = CardanoSignRequest::new( + let _request = CardanoSignRequest::new( Some( hex::decode("9b1deb4d3b7d4bad9bdd2b0d7b3dcb6d") .unwrap() @@ -1273,6 +1262,6 @@ mod tests { assert_eq!(withdrawals.unwrap().len(), 0); let cardano_tx = ParsedCardanoTx::from_cardano_tx(tx, context); - assert_eq!(cardano_tx.is_ok(), true); + assert!(cardano_tx.is_ok()); } } diff --git a/rust/apps/cardano/src/transaction.rs b/rust/apps/cardano/src/transaction.rs index cb3e08568..7a8718cb5 100644 --- a/rust/apps/cardano/src/transaction.rs +++ b/rust/apps/cardano/src/transaction.rs @@ -184,13 +184,13 @@ pub fn sign_tx(tx: Vec, context: ParseContext, icarus_master_key: XPrv) -> R #[cfg(test)] mod test { use super::*; - use cardano_serialization_lib::Transaction; + extern crate std; - use crate::transaction::parse_tx; + use std::println; - use ur_registry::cardano::cardano_sign_data_signature::CardanoSignDataSignature; + use {cryptoxide::hashing::blake2b_256, hex}; #[test] @@ -214,7 +214,7 @@ mod test { let tx = cardano_serialization_lib::protocol_types::FixedTransaction::from_bytes(tx_bytes) .unwrap(); let body = tx.raw_body(); - let hash = blake2b_256(&body); + let _hash = blake2b_256(&body); } #[test] diff --git a/rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs b/rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs index bc46d8efe..a9deada8c 100644 --- a/rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs +++ b/rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs @@ -13,7 +13,7 @@ mod type_urls; pub use prost; pub use prost_types::Any; -pub use tendermint_proto as tendermint; + /// The version (commit hash) of the Cosmos SDK used when generating this library. pub const COSMOS_SDK_VERSION: &str = include_str!("prost/cosmos-sdk/COSMOS_SDK_COMMIT"); diff --git a/rust/apps/cosmos/src/lib.rs b/rust/apps/cosmos/src/lib.rs index bcc4654f1..b3c7231f9 100644 --- a/rust/apps/cosmos/src/lib.rs +++ b/rust/apps/cosmos/src/lib.rs @@ -17,7 +17,7 @@ use crate::transaction::structs::{ParsedCosmosTx, SignMode}; use crate::utils::{hash160, keccak256, sha256_digest}; use bech32::{Bech32, Hrp}; use bitcoin::secp256k1::{Message, PublicKey}; -use hex; + use keystore::algorithms::secp256k1::derive_public_key; mod cosmos_sdk_proto; @@ -76,7 +76,7 @@ pub fn sign_tx( if let Ok(message) = Message::from_slice(&hash) { let (_, signature) = keystore::algorithms::secp256k1::sign_message_by_seed( - &seed, path, &message, + seed, path, &message, ) .map_err(|e| CosmosError::KeystoreError(format!("sign failed {:?}", e.to_string())))?; return Ok(signature); @@ -90,7 +90,7 @@ pub fn derive_address( root_path: &str, prefix: &str, ) -> Result { - let root_path = if !root_path.ends_with("/") { + let root_path = if !root_path.ends_with('/') { root_path.to_string() + "/" } else { root_path.to_string() @@ -100,12 +100,12 @@ pub fn derive_address( .ok_or(CosmosError::InvalidHDPath(hd_path.to_string()))?; derive_public_key(&root_x_pub.to_string(), &format!("m/{}", sub_path)) .map(|public_key| generate_address(public_key, prefix)) - .map_err(|e| CosmosError::from(e))? + .map_err(CosmosError::from)? } #[cfg(test)] mod tests { - use hex; + use super::*; diff --git a/rust/apps/cosmos/src/proto_wrapper/fee.rs b/rust/apps/cosmos/src/proto_wrapper/fee.rs index 9568b386c..0cbd397b3 100644 --- a/rust/apps/cosmos/src/proto_wrapper/fee.rs +++ b/rust/apps/cosmos/src/proto_wrapper/fee.rs @@ -74,7 +74,7 @@ pub fn format_coin(coin: Coin) -> Option { } else { return Some(format!("{} {}", coin.amount, coin.denom)); } - return None; + None } pub fn parse_gas_limit(gas: &serde_json::Value) -> Result { @@ -85,10 +85,10 @@ pub fn parse_gas_limit(gas: &serde_json::Value) -> Result { if let Some(gas_limit) = gas.as_f64() { return Ok(gas_limit); } - return Err(CosmosError::InvalidData(format!( + Err(CosmosError::InvalidData(format!( "failed to parse gas {:?}", gas - ))); + ))) } pub fn format_fee_from_value(data: serde_json::Value) -> Result { @@ -133,5 +133,5 @@ pub fn format_fee_from_value(data: serde_json::Value) -> Result { gas_limit: gas_limit.to_string(), }); } - return Err(CosmosError::InvalidData("can not parse fee".to_string())); + Err(CosmosError::InvalidData("can not parse fee".to_string())) } diff --git a/rust/apps/cosmos/src/proto_wrapper/mode_info.rs b/rust/apps/cosmos/src/proto_wrapper/mode_info.rs index cad54a63e..29301dcad 100644 --- a/rust/apps/cosmos/src/proto_wrapper/mode_info.rs +++ b/rust/apps/cosmos/src/proto_wrapper/mode_info.rs @@ -91,10 +91,7 @@ impl TryFrom<&proto::cosmos::tx::v1beta1::mode_info::Multi> for Multi { fn try_from( proto: &proto::cosmos::tx::v1beta1::mode_info::Multi, ) -> Result { - let bitarray = match &proto.bitarray { - Some(value) => Some(value.into()), - None => None, - }; + let bitarray = proto.bitarray.as_ref().map(|value| value.into()); Ok(Multi { bitarray, diff --git a/rust/apps/cosmos/src/proto_wrapper/msg/common.rs b/rust/apps/cosmos/src/proto_wrapper/msg/common.rs index de88a73b1..d0e742485 100644 --- a/rust/apps/cosmos/src/proto_wrapper/msg/common.rs +++ b/rust/apps/cosmos/src/proto_wrapper/msg/common.rs @@ -24,13 +24,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro .map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgSend deserialize failed {}", - e.to_string() + e )) })?; let msg_send = MsgSendWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgSend deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_send)); @@ -40,13 +40,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgDelegate deserialize failed {}", - e.to_string() + e )) })?; let msg_delegate = MsgDelegateWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgDelegate deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_delegate)); @@ -56,13 +56,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgUndelegate deserialize failed {}", - e.to_string() + e )) })?; let msg_undelegate = MsgUnDelegateWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgUndelegate deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_undelegate)); @@ -72,13 +72,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; let msg_transfer = MsgTransferWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_transfer)); @@ -88,13 +88,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro proto::cosmos::gov::v1beta1::MsgVote::decode(&*message.value).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgVote deserialize failed {}", - e.to_string() + e )) })?; let msg_vote = MsgVoteWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgVote deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_vote)); @@ -104,14 +104,14 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; let msg_withdraw_reward = MsgWithdrawDelegatorRewardWrapper::try_from(&unpacked) .map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_withdraw_reward)); @@ -121,14 +121,14 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; let msg_redelegate = MsgBeginRedelegateWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgTransfer deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_redelegate)); @@ -138,13 +138,13 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro MessageExt::from_any(message).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) })?; let msg_multi_send = MsgMultiSendWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_multi_send)); @@ -155,14 +155,14 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro .map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) })?; let msg_update_client = MsgUpdateClientWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_update_client)); @@ -173,14 +173,14 @@ pub fn map_messages(messages: &Vec) -> Result>, CosmosErro |e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) }, )?; let msg_exec = MsgExecWrapper::try_from(&unpacked).map_err(|e| { CosmosError::ParseTxError(format!( "proto MsgMultiSend deserialize failed {}", - e.to_string() + e )) })?; message_vec.push(Box::new(msg_exec)); diff --git a/rust/apps/cosmos/src/proto_wrapper/msg/msg.rs b/rust/apps/cosmos/src/proto_wrapper/msg/msg.rs index 15f1ff2ec..7efdab3ce 100644 --- a/rust/apps/cosmos/src/proto_wrapper/msg/msg.rs +++ b/rust/apps/cosmos/src/proto_wrapper/msg/msg.rs @@ -17,10 +17,10 @@ pub struct NotSupportMessage { impl SerializeJson for NotSupportMessage { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { + let value = serde_json::to_value(self).map_err(|err| { CosmosError::ParseTxError(format!( "NotSupportMessage serialize failed {}", - err.to_string() + err )) })?; let msg = json!({ @@ -66,8 +66,8 @@ impl TryFrom<&proto::cosmos::bank::v1beta1::MsgSend> for MsgSend { impl SerializeJson for MsgSend { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgSend serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgSend serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), @@ -112,8 +112,8 @@ impl TryFrom<&proto::cosmos::staking::v1beta1::MsgDelegate> for MsgDelegate { impl SerializeJson for MsgDelegate { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgDelegate serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgDelegate serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), @@ -158,10 +158,10 @@ impl TryFrom<&proto::cosmos::staking::v1beta1::MsgUndelegate> for MsgUndelegate impl SerializeJson for MsgUndelegate { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { + let value = serde_json::to_value(self).map_err(|err| { CosmosError::ParseTxError(format!( "MsgUndelegate serialize failed {}", - err.to_string() + err )) })?; let msg = json!({ @@ -242,8 +242,8 @@ impl TryFrom<&proto::cosmos::gov::v1beta1::MsgVote> for MsgVote { impl SerializeJson for MsgVote { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgVote serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgVote serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), @@ -304,13 +304,10 @@ impl TryFrom<&proto::ibc::applications::transfer::v1::MsgTransfer> for MsgTransf None => None, }; - let timeout_height: Option = match &proto.timeout_height { - Some(height) => Some(Height { + let timeout_height: Option = proto.timeout_height.as_ref().map(|height| Height { revision_number: Some(height.revision_number), revision_height: Some(height.revision_height), - }), - None => None, - }; + }); Ok(MsgTransfer { source_port: proto.source_port.clone(), @@ -326,8 +323,8 @@ impl TryFrom<&proto::ibc::applications::transfer::v1::MsgTransfer> for MsgTransf impl SerializeJson for MsgTransfer { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgTransfer serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgTransfer serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), @@ -366,10 +363,10 @@ impl TryFrom<&proto::cosmos::distribution::v1beta1::MsgWithdrawDelegatorReward> impl SerializeJson for MsgWithdrawDelegatorReward { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { + let value = serde_json::to_value(self).map_err(|err| { CosmosError::ParseTxError(format!( "MsgWithdrawDelegatorReward serialize failed {}", - err.to_string() + err )) })?; let msg = json!({ @@ -407,10 +404,10 @@ impl TryFrom<&proto::ibc::core::client::v1::MsgUpdateClient> for MsgUpdateClient impl SerializeJson for MsgUpdateClient { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { + let value = serde_json::to_value(self).map_err(|err| { CosmosError::ParseTxError(format!( "MsgUpdateClient serialize failed {}", - err.to_string() + err )) })?; let msg = json!({ @@ -456,10 +453,10 @@ impl TryFrom<&proto::cosmos::staking::v1beta1::MsgBeginRedelegate> for MsgBeginR impl SerializeJson for MsgBeginRedelegate { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { + let value = serde_json::to_value(self).map_err(|err| { CosmosError::ParseTxError(format!( "MsgBeginRedelegate serialize failed {}", - err.to_string() + err )) })?; let msg = json!({ @@ -499,8 +496,8 @@ impl TryFrom<&proto::cosmos::authz::v1beta1::MsgExec> for MsgExec { impl SerializeJson for MsgExec { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgExec serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgExec serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), @@ -587,8 +584,8 @@ impl TryFrom<&proto::cosmos::bank::v1beta1::MsgMultiSend> for MsgMultiSend { impl SerializeJson for MsgMultiSend { fn to_json(&self) -> Result { - let value = serde_json::to_value(&self).map_err(|err| { - CosmosError::ParseTxError(format!("MsgMultiSend serialize failed {}", err.to_string())) + let value = serde_json::to_value(self).map_err(|err| { + CosmosError::ParseTxError(format!("MsgMultiSend serialize failed {}", err)) })?; let msg = json!({ "type": Value::String(Self::TYPE_URL.to_string()), diff --git a/rust/apps/cosmos/src/proto_wrapper/serde_helper.rs b/rust/apps/cosmos/src/proto_wrapper/serde_helper.rs index d29bbb04f..5401224b0 100644 --- a/rust/apps/cosmos/src/proto_wrapper/serde_helper.rs +++ b/rust/apps/cosmos/src/proto_wrapper/serde_helper.rs @@ -1,6 +1,6 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; -use base64; + pub fn from_base64(s: &str) -> Result, base64::DecodeError> { base64::decode(s) } diff --git a/rust/apps/cosmos/src/proto_wrapper/sign_doc.rs b/rust/apps/cosmos/src/proto_wrapper/sign_doc.rs index 7cf0cd813..5f54680fc 100644 --- a/rust/apps/cosmos/src/proto_wrapper/sign_doc.rs +++ b/rust/apps/cosmos/src/proto_wrapper/sign_doc.rs @@ -7,7 +7,7 @@ use crate::proto_wrapper::fee::Fee; use crate::proto_wrapper::msg::msg_serialize::Msg; use crate::{CosmosError, Result}; use alloc::boxed::Box; -use alloc::string::{String, ToString}; +use alloc::string::{String}; use alloc::vec::Vec; use serde::Serialize; @@ -26,7 +26,7 @@ impl SignDoc { Message::decode(Bytes::from(proto.body_bytes)).map_err(|e| { CosmosError::ParseTxError(format!( "proto TxBody deserialize failed {}", - e.to_string() + e )) })?; let body = Body::try_from(tx_body)?; @@ -35,7 +35,7 @@ impl SignDoc { Message::decode(Bytes::from(proto.auth_info_bytes)).map_err(|e| { CosmosError::ParseTxError(format!( "proto AuthInfo deserialize failed {}", - e.to_string() + e )) })?; let auth_info = AuthInfo::try_from(auth_info)?; @@ -54,7 +54,7 @@ impl SignDoc { Message::decode(Bytes::from(data.clone())).map_err(|e| { CosmosError::ParseTxError(format!( "proto SignDoc deserialize failed {}", - e.to_string() + e )) })?; SignDoc::from(proto_sign_doc) diff --git a/rust/apps/cosmos/src/proto_wrapper/signer_info.rs b/rust/apps/cosmos/src/proto_wrapper/signer_info.rs index e2ee7fe25..93d45ab07 100644 --- a/rust/apps/cosmos/src/proto_wrapper/signer_info.rs +++ b/rust/apps/cosmos/src/proto_wrapper/signer_info.rs @@ -77,7 +77,7 @@ impl TryFrom<&Any> for PublicKey { .map_err(|err| { CosmosError::ParseTxError(format!( "proto ed25519::PubKey deserialize failed {}", - err.to_string() + err )) })?; Ok(PublicKey { @@ -90,7 +90,7 @@ impl TryFrom<&Any> for PublicKey { Message::decode(&*any.value).map_err(|err| { CosmosError::ParseTxError(format!( "proto secp256k1::PubKey deserialize failed {}", - err.to_string() + err )) })?; Ok(PublicKey { @@ -100,7 +100,7 @@ impl TryFrom<&Any> for PublicKey { } other => Err(CosmosError::ParseTxError(format!( "{} is not supported!!!", - other.to_string() + other ))), } } diff --git a/rust/apps/cosmos/src/transaction/detail.rs b/rust/apps/cosmos/src/transaction/detail.rs index ef147735a..d2885bc83 100644 --- a/rust/apps/cosmos/src/transaction/detail.rs +++ b/rust/apps/cosmos/src/transaction/detail.rs @@ -37,8 +37,7 @@ impl TryFrom for DetailRedelegate { fn try_from(data: MsgBeginRedelegate) -> Result { let value = data - .amount - .and_then(|coin| Some(format_amount(vec![coin]))) + .amount.map(|coin| format_amount(vec![coin])) .unwrap_or("".to_string()); Ok(Self { method: "Re-delegate".to_string(), @@ -70,7 +69,7 @@ impl TryFrom for DetailTransfer { fn try_from(msg: MsgTransfer) -> Result { let value = msg .token - .and_then(|v| format_coin(v)) + .and_then(format_coin) .unwrap_or("".to_string()); Ok(Self { method: "IBC Transfer".to_string(), diff --git a/rust/apps/cosmos/src/transaction/mod.rs b/rust/apps/cosmos/src/transaction/mod.rs index 30c95f6c0..ecc526b0f 100644 --- a/rust/apps/cosmos/src/transaction/mod.rs +++ b/rust/apps/cosmos/src/transaction/mod.rs @@ -11,7 +11,7 @@ use crate::transaction::overview::{CommonOverview, CosmosTxOverview, MsgOverview use crate::transaction::structs::{CosmosTxDisplayType, DataType, ParsedCosmosTx}; use crate::transaction::utils::get_network_by_chain_id; -use rust_tools; + use self::detail::MsgDetail; @@ -48,7 +48,7 @@ impl ParsedCosmosTx { } } fn build_overview_from_amino(data: Value) -> Result { - let chain_id = data["chain_id"].as_str().unwrap_or(&""); + let chain_id = data["chain_id"].as_str().unwrap_or(""); let kind = CosmosTxOverview::from_value(&data["msgs"])?; let common = CommonOverview { network: get_network_by_chain_id(chain_id)?, @@ -61,7 +61,7 @@ impl ParsedCosmosTx { } fn build_detail_from_amino(data: Value) -> Result { - let chain_id = data["chain_id"].as_str().unwrap_or(&""); + let chain_id = data["chain_id"].as_str().unwrap_or(""); let common = CommonDetail { network: get_network_by_chain_id(chain_id)?, chain_id: chain_id.to_string(), diff --git a/rust/apps/cosmos/src/transaction/overview.rs b/rust/apps/cosmos/src/transaction/overview.rs index 2e1707383..e04fea841 100644 --- a/rust/apps/cosmos/src/transaction/overview.rs +++ b/rust/apps/cosmos/src/transaction/overview.rs @@ -54,8 +54,7 @@ impl TryFrom for OverviewDelegate { fn try_from(data: MsgDelegate) -> Result { let value = data - .amount - .and_then(|coin| Some(format_amount(vec![coin]))) + .amount.map(|coin| format_amount(vec![coin])) .unwrap_or("".to_string()); Ok(Self { method: "Delegate".to_string(), @@ -83,8 +82,7 @@ impl TryFrom for OverviewUndelegate { fn try_from(data: MsgUndelegate) -> Result { let value = data - .amount - .and_then(|coin| Some(format_amount(vec![coin]))) + .amount.map(|coin| format_amount(vec![coin])) .unwrap_or("".to_string()); Ok(Self { method: "Undelegate".to_string(), @@ -112,8 +110,7 @@ impl TryFrom for OverviewRedelegate { fn try_from(data: MsgBeginRedelegate) -> Result { let value = data - .amount - .and_then(|coin| Some(format_amount(vec![coin]))) + .amount.map(|coin| format_amount(vec![coin])) .unwrap_or("".to_string()); Ok(Self { method: "Re-delegate".to_string(), @@ -166,7 +163,7 @@ impl TryFrom for OverviewTransfer { fn try_from(msg: MsgTransfer) -> Result { let value = msg .token - .and_then(|v| format_coin(v)) + .and_then(format_coin) .unwrap_or("".to_string()); Ok(Self { method: "IBC Transfer".to_string(), diff --git a/rust/apps/cosmos/src/transaction/utils.rs b/rust/apps/cosmos/src/transaction/utils.rs index 191a17c9b..336ffb8af 100644 --- a/rust/apps/cosmos/src/transaction/utils.rs +++ b/rust/apps/cosmos/src/transaction/utils.rs @@ -6,9 +6,9 @@ use crate::errors::Result; pub fn detect_msg_type(msg_type: Option<&str>) -> &str { let msg_type_parts: Vec<&str> = msg_type - .unwrap_or(&"") - .split("/") - .flat_map(|s| s.split(".")) + .unwrap_or("") + .split('/') + .flat_map(|s| s.split('.')) .collect(); msg_type_parts[msg_type_parts.len() - 1] } @@ -51,15 +51,14 @@ pub fn get_network_by_chain_id(chain_id: &str) -> Result { map.insert("columbus", "Terra Classic"); map.insert("thorchain", "THORChain"); map.insert("neutron", "Neutron"); - let chain_id_parts: Vec<&str> = chain_id.split("-").collect(); + 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("-") } else { chain_id_parts[0].to_string() }; Ok(map - .get(chain_id_prefix.as_str()) - .and_then(|v| Some(v.to_string())) + .get(chain_id_prefix.as_str()).map(|v| v.to_string()) .unwrap_or("Cosmos Hub".to_string())) } diff --git a/rust/apps/cosmos/src/utils.rs b/rust/apps/cosmos/src/utils.rs index 127fc0a25..c5bf85095 100644 --- a/rust/apps/cosmos/src/utils.rs +++ b/rust/apps/cosmos/src/utils.rs @@ -4,7 +4,7 @@ use cryptoxide::hashing; use cryptoxide::ripemd160::Ripemd160; use cryptoxide::sha3::Keccak256; pub(crate) fn sha256_digest(data: &[u8]) -> Vec { - hashing::sha256(&data).to_vec() + hashing::sha256(data).to_vec() } fn ripemd160_digest(data: &[u8]) -> [u8; 20] { diff --git a/rust/apps/ethereum/src/abi.rs b/rust/apps/ethereum/src/abi.rs index 94b83e8ac..fc29d007c 100644 --- a/rust/apps/ethereum/src/abi.rs +++ b/rust/apps/ethereum/src/abi.rs @@ -110,7 +110,7 @@ fn _parse_by_function( _input.name.clone(), match _token { Token::Address(_) => { - format!("0x{}", _token.to_string()) + format!("0x{}", _token) } _ => _token.to_string(), }, @@ -150,13 +150,13 @@ mod tests { }"#; let contract_data = hex::decode("3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000064996e5f00000000000000000000000000000000000000000000000000000000000000020b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000f84605ccc515414000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f46b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000").unwrap(); let result = parse_contract_data(contract_data, json.to_string()); - assert_eq!(true, result.is_ok()); + assert!(result.is_ok()); let result = result.unwrap(); assert_eq!("UniversalRouter", result.contract_name); assert_eq!("execute", result.method_name); assert_eq!(3, result.params.len()); - assert_eq!(result.params.get(0).unwrap().name, "commands"); - assert_eq!(result.params.get(0).unwrap().value, "0b00"); + assert_eq!(result.params.first().unwrap().name, "commands"); + assert_eq!(result.params.first().unwrap().value, "0b00"); assert_eq!(result.params.get(1).unwrap().name, "inputs"); assert_eq!(result.params.get(1).unwrap().value, "[0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000002386f26fc10000,0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000f84605ccc515414000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f46b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000]"); assert_eq!(result.params.get(2).unwrap().name, "deadline"); @@ -177,13 +177,13 @@ mod tests { }"#; let data = hex::decode("3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000064996e5f00000000000000000000000000000000000000000000000000000000000000020b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000f84605ccc515414000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f46b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000").unwrap(); let result = parse_method_data(data, "UniversalRouter".to_string(), json.to_string()); - assert_eq!(true, result.is_ok()); + assert!(result.is_ok()); let result = result.unwrap(); assert_eq!("UniversalRouter", result.contract_name); assert_eq!("execute", result.method_name); assert_eq!(3, result.params.len()); - assert_eq!(result.params.get(0).unwrap().name, "commands"); - assert_eq!(result.params.get(0).unwrap().value, "0b00"); + assert_eq!(result.params.first().unwrap().name, "commands"); + assert_eq!(result.params.first().unwrap().value, "0b00"); assert_eq!(result.params.get(1).unwrap().name, "inputs"); assert_eq!(result.params.get(1).unwrap().value, "[0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000002386f26fc10000,0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000f84605ccc515414000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f46b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000]"); assert_eq!(result.params.get(2).unwrap().name, "deadline"); diff --git a/rust/apps/ethereum/src/eip1559_transaction.rs b/rust/apps/ethereum/src/eip1559_transaction.rs index e75ca89c5..4ccc1058b 100644 --- a/rust/apps/ethereum/src/eip1559_transaction.rs +++ b/rust/apps/ethereum/src/eip1559_transaction.rs @@ -7,7 +7,7 @@ use alloc::string::{String, ToString}; use core::ops::Mul; use ethereum_types::U256; -use hex; + use rlp::{Decodable, DecoderError, Rlp}; pub struct EIP1559Transaction { diff --git a/rust/apps/ethereum/src/erc20.rs b/rust/apps/ethereum/src/erc20.rs index 66b9e6476..a3d2b754a 100644 --- a/rust/apps/ethereum/src/erc20.rs +++ b/rust/apps/ethereum/src/erc20.rs @@ -45,7 +45,7 @@ pub fn parse_erc20(input: &str, decimal: u32) -> Resultwidth$}", remainder_decimal, width = decimal as usize); - format!("{}.{}", value_decimal.to_string(), padded_remainder) + format!("{}.{}", value_decimal, padded_remainder) .trim_end_matches('0') .to_string() } else { diff --git a/rust/apps/ethereum/src/legacy_transaction.rs b/rust/apps/ethereum/src/legacy_transaction.rs index 0462f3753..4a8c6fe70 100644 --- a/rust/apps/ethereum/src/legacy_transaction.rs +++ b/rust/apps/ethereum/src/legacy_transaction.rs @@ -5,7 +5,7 @@ use core::str::FromStr; use bytes::BytesMut; use ethereum_types::{H256, U256}; -use hex; + use rlp::{Decodable, DecoderError, Encodable, Rlp}; use ur_registry::pb::protoc::EthTx; @@ -254,7 +254,7 @@ impl Encodable for LegacyTransaction { s.append(&self.value); s.append(&self.input); // chain_id will remove when the signature is added - if let None = &self.signature { + if self.signature.is_none() { s.append(&self.chain_id()); s.append(&vec![]); s.append(&vec![]); @@ -367,7 +367,7 @@ mod tests { let signed_tx_hex = hex::encode(&signed_tx); // tx id === tx hash let signed_tx_hash = keccak256(&signed_tx); - let signed_tx_hash_hex = hex::encode(&signed_tx_hash); + let signed_tx_hash_hex = hex::encode(signed_tx_hash); assert_eq!( "fec8bfea5ec13ad726de928654cd1733b1d81d2d2916ac638e6b9a245f034ace".to_string(), @@ -409,7 +409,7 @@ mod tests { .to_string() ); let unsigned_tx_hash = keccak256(&unsigned_tx); - let unsigned_tx_hash_hex = hex::encode(&unsigned_tx_hash); + let _unsigned_tx_hash_hex = hex::encode(unsigned_tx_hash); // sign tx let r = "0x35df2b615912b8be79a13c9b0a1540ade55434ab68778a49943442a9e6d3141a".to_string(); let s = "0x0a6e33134ba47c1f1cda59ec3ef62a59d4da6a9d111eb4e447828574c1c94f66".to_string(); @@ -430,7 +430,7 @@ mod tests { // tx id === tx hash let signed_tx_hash = keccak256(&signed_tx); - let signed_tx_hash_hex = hex::encode(&signed_tx_hash); + let signed_tx_hash_hex = hex::encode(signed_tx_hash); assert_eq!( "c20d7398343b00d1bc5aaf8f6d9a879217003d6cc726053cd41fb960977cd066".to_string(), signed_tx_hash_hex @@ -471,10 +471,10 @@ mod tests { // raw tx let signed_tx = tx.encode_raw(); - let signed_tx_hex = hex::encode(&signed_tx); + let _signed_tx_hex = hex::encode(&signed_tx); // tx id === tx hash let signed_tx_hash = keccak256(&signed_tx); - let signed_tx_hash_hex = hex::encode(&signed_tx_hash); + let signed_tx_hash_hex = hex::encode(signed_tx_hash); assert_eq!( "e01dd745d8cc0983f288da28ab288f7d1be809164c83ae477bdb927d31f49a7c".to_string(), signed_tx_hash_hex diff --git a/rust/apps/ethereum/src/lib.rs b/rust/apps/ethereum/src/lib.rs index ed16cd17e..f00d51f10 100644 --- a/rust/apps/ethereum/src/lib.rs +++ b/rust/apps/ethereum/src/lib.rs @@ -9,9 +9,9 @@ use alloc::vec::Vec; use bitcoin::secp256k1::{Message, PublicKey}; pub use ethereum_types::{H160, U256}; -use hex; + pub use legacy_transaction::*; -use serde_json; + use crate::crypto::keccak256; use crate::eip1559_transaction::{EIP1559Transaction, ParsedEIP1559Transaction}; @@ -178,11 +178,11 @@ mod tests { extern crate std; - use core::str::FromStr; + - use hex; + use keystore::algorithms::secp256k1::get_public_key_by_seed; - use serde_json; + use crate::alloc::string::ToString; use crate::eip712::eip712::{Eip712, TypedData as Eip712TypedData}; @@ -596,7 +596,7 @@ mod tests { } } "#; - let typed_data: Eip712TypedData = serde_json::from_str(&utf8_msg).unwrap(); + let typed_data: Eip712TypedData = serde_json::from_str(utf8_msg).unwrap(); let hash = typed_data.encode_eip712().unwrap(); assert_eq!( "cosmos", diff --git a/rust/apps/ethereum/src/structs.rs b/rust/apps/ethereum/src/structs.rs index 4dfec0b70..0a38dc6a6 100644 --- a/rust/apps/ethereum/src/structs.rs +++ b/rust/apps/ethereum/src/structs.rs @@ -39,7 +39,7 @@ impl Encodable for TransactionAction { s.append_empty_data(); } } - () + } } diff --git a/rust/apps/near/src/account_id/borsh.rs b/rust/apps/near/src/account_id/borsh.rs index b778a6bd4..c2a141b0a 100644 --- a/rust/apps/near/src/account_id/borsh.rs +++ b/rust/apps/near/src/account_id/borsh.rs @@ -33,7 +33,7 @@ mod tests { #[test] fn test_is_valid_account_id() { - for account_id in OK_ACCOUNT_IDS.iter().cloned() { + for account_id in OK_ACCOUNT_IDS.iter() { let parsed_account_id = account_id.parse::().unwrap_or_else(|err| { panic!("Valid account id {:?} marked invalid: {}", account_id, err) }); @@ -53,7 +53,7 @@ mod tests { assert_eq!(serialized_account_id, str_serialized_account_id); } - for account_id in BAD_ACCOUNT_IDS.iter().cloned() { + for account_id in BAD_ACCOUNT_IDS.iter() { let str_serialized_account_id = account_id.try_to_vec().unwrap(); assert!( diff --git a/rust/apps/near/src/account_id/mod.rs b/rust/apps/near/src/account_id/mod.rs index 0134bdcbe..87b0c6f2f 100644 --- a/rust/apps/near/src/account_id/mod.rs +++ b/rust/apps/near/src/account_id/mod.rs @@ -243,7 +243,7 @@ mod tests { } for account_id in BAD_ACCOUNT_IDS.iter().cloned() { - if let Ok(_) = AccountId::validate(account_id) { + if AccountId::validate(account_id).is_ok() { panic!("Invalid account id {:?} marked valid", account_id); } } diff --git a/rust/apps/near/src/account_id/serde.rs b/rust/apps/near/src/account_id/serde.rs index 05733aee0..3817aac74 100644 --- a/rust/apps/near/src/account_id/serde.rs +++ b/rust/apps/near/src/account_id/serde.rs @@ -33,7 +33,7 @@ mod tests { #[test] fn test_is_valid_account_id() { - for account_id in OK_ACCOUNT_IDS.iter().cloned() { + for account_id in OK_ACCOUNT_IDS.iter() { let parsed_account_id = account_id.parse::().unwrap_or_else(|err| { panic!("Valid account id {:?} marked invalid: {}", account_id, err) }); @@ -51,7 +51,7 @@ mod tests { assert_eq!(serialized_account_id, json!(account_id)); } - for account_id in BAD_ACCOUNT_IDS.iter().cloned() { + for account_id in BAD_ACCOUNT_IDS.iter() { assert!( serde_json::from_value::(json!(account_id)).is_err(), "successfully deserialized invalid account ID {:?}", diff --git a/rust/apps/near/src/crypto/errors.rs b/rust/apps/near/src/crypto/errors.rs index 6acced938..375978e4d 100644 --- a/rust/apps/near/src/crypto/errors.rs +++ b/rust/apps/near/src/crypto/errors.rs @@ -1,5 +1,5 @@ use alloc::string::String; -use thiserror; + #[derive(Debug, Clone, thiserror::Error)] pub enum ParseKeyTypeError { diff --git a/rust/apps/near/src/crypto/mod.rs b/rust/apps/near/src/crypto/mod.rs index 488e06fab..5903499d1 100644 --- a/rust/apps/near/src/crypto/mod.rs +++ b/rust/apps/near/src/crypto/mod.rs @@ -1,4 +1,4 @@ mod errors; mod pubkey; -pub use pubkey::{KeyType, PublicKey}; +pub use pubkey::{PublicKey}; diff --git a/rust/apps/near/src/crypto/pubkey.rs b/rust/apps/near/src/crypto/pubkey.rs index 9f966961d..f51de10ca 100644 --- a/rust/apps/near/src/crypto/pubkey.rs +++ b/rust/apps/near/src/crypto/pubkey.rs @@ -108,7 +108,7 @@ impl AsRef<[u8]> for Secp256K1PublicKey { impl Debug for Secp256K1PublicKey { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), core::fmt::Error> { - write!(f, "{}", bs58::encode(&self.0.to_vec())) + write!(f, "{}", bs58::encode(self.0.as_ref())) } } @@ -150,7 +150,7 @@ impl TryFrom<&[u8]> for ED25519PublicKey { impl Debug for ED25519PublicKey { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), core::fmt::Error> { - write!(f, "{}", bs58::encode(&self.0.to_vec())) + write!(f, "{}", bs58::encode(self.0.as_ref())) } } @@ -298,7 +298,7 @@ impl From<&PublicKey> for String { PublicKey::SECP256K1(public_key) => format!( "{}:{}", KeyType::SECP256K1, - bs58::encode(&public_key.0.to_vec()) + bs58::encode(public_key.0.as_ref()) ), } } diff --git a/rust/apps/near/src/errors.rs b/rust/apps/near/src/errors.rs index abe90fbec..f9ca3d932 100644 --- a/rust/apps/near/src/errors.rs +++ b/rust/apps/near/src/errors.rs @@ -21,8 +21,8 @@ pub type Result = core::result::Result; impl From for NearError { fn from(value: KeystoreError) -> Self { match value { - KeystoreError::DerivePubKey(data) => Self::KeystoreError(format!("{}", data)), - KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(format!("{}", data)), + KeystoreError::DerivePubKey(data) => Self::KeystoreError(data.to_string()), + KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(data.to_string()), KeystoreError::XPubError(data) => Self::KeystoreError(data), KeystoreError::SeedError(data) => Self::KeystoreError(data), KeystoreError::DerivationError(data) => Self::KeystoreError(data), diff --git a/rust/apps/near/src/lib.rs b/rust/apps/near/src/lib.rs index 59a6fe890..dd15fbd16 100644 --- a/rust/apps/near/src/lib.rs +++ b/rust/apps/near/src/lib.rs @@ -34,7 +34,7 @@ pub fn parse(data: &Vec) -> Result { #[cfg(test)] mod tests { use super::*; - use hex; + use hex::ToHex; use ur_registry::near::near_sign_request::NearSignRequest; #[test] diff --git a/rust/apps/near/src/parser/mod.rs b/rust/apps/near/src/parser/mod.rs index b06ec7fab..38c9daac4 100644 --- a/rust/apps/near/src/parser/mod.rs +++ b/rust/apps/near/src/parser/mod.rs @@ -12,7 +12,7 @@ use crate::parser::utils::format_amount; use crate::parser::utils::Merge; use alloc::format; use alloc::string::{String, ToString}; -use alloc::vec; + use alloc::vec::Vec; use borsh::BorshDeserialize; use serde_json; diff --git a/rust/apps/near/src/parser/utils.rs b/rust/apps/near/src/parser/utils.rs index 4c0b31512..f811283d7 100644 --- a/rust/apps/near/src/parser/utils.rs +++ b/rust/apps/near/src/parser/utils.rs @@ -5,7 +5,7 @@ use serde::Serializer; pub const NEAR_THRESHOLD: u128 = 10000000000000000000; pub const NEAR_DIVIDER: f64 = 1_000_000_000_000_000_000_000_000f64; -pub const GAS_DIVIDER: f64 = 1000_000_000_000f64; +pub const GAS_DIVIDER: f64 = 1_000_000_000_000_f64; use serde_json; use serde_json::Value; @@ -22,15 +22,15 @@ impl Merge for serde_json::Value { fn merge(a: &mut Value, b: &Value) { match (a, b) { - (Value::Object(ref mut a), &Value::Object(ref b)) => { + (Value::Object(ref mut a), Value::Object(b)) => { for (k, v) in b { merge(a.entry(k).or_insert(Value::Null), v); } } - (Value::Array(ref mut a), &Value::Array(ref b)) => { + (Value::Array(ref mut a), Value::Array(b)) => { a.extend(b.clone()); } - (Value::Array(ref mut a), &Value::Object(ref b)) => { + (Value::Array(ref mut a), Value::Object(b)) => { a.extend([Value::Object(b.clone())]); } (a, b) => { @@ -40,25 +40,25 @@ fn merge(a: &mut Value, b: &Value) { } pub fn format_amount(value: u128) -> String { - return if value > NEAR_THRESHOLD { + if value > NEAR_THRESHOLD { format!("{} {}", (value as f64).div(NEAR_DIVIDER), "NEAR") } else { format!("{} {}", value, "Yocto") - }; + } } pub fn format_option_u128_amount(v: &Option, serializer: S) -> Result where S: Serializer, { - serializer.serialize_str(&format_amount(v.unwrap_or(u128::default()))) + serializer.serialize_str(&format_amount(v.unwrap_or_default())) } pub fn format_u128_amount(v: &u128, serializer: S) -> Result where S: Serializer, { - serializer.serialize_str(&format_amount(v.clone())) + serializer.serialize_str(&format_amount(*v)) } pub fn format_gas(value: u64) -> String { @@ -69,7 +69,7 @@ pub fn format_gas_amount(v: &u64, serializer: S) -> Result where S: Serializer, { - serializer.serialize_str(&format_gas(v.clone())) + serializer.serialize_str(&format_gas(*v)) } #[cfg(test)] diff --git a/rust/apps/near/src/primitives_core/account.rs b/rust/apps/near/src/primitives_core/account.rs index 84f42a387..742c1ee8e 100644 --- a/rust/apps/near/src/primitives_core/account.rs +++ b/rust/apps/near/src/primitives_core/account.rs @@ -123,7 +123,7 @@ impl BorshDeserialize for Account { // This should only ever happen if we have pre-transition account serialized in state // See test_account_size let deserialized_account = LegacyAccount::deserialize(buf)?; - if buf.len() != 0 { + if !buf.is_empty() { panic!("Tried deserializing a buffer that is not exactly the size of an account"); } Ok(Account { diff --git a/rust/apps/near/src/primitives_core/hash.rs b/rust/apps/near/src/primitives_core/hash.rs index b565189be..672910451 100644 --- a/rust/apps/near/src/primitives_core/hash.rs +++ b/rust/apps/near/src/primitives_core/hash.rs @@ -11,6 +11,7 @@ use cryptoxide::sha2; use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Default)] pub struct CryptoHash(pub [u8; 32]); impl CryptoHash { @@ -23,11 +24,7 @@ impl CryptoHash { } } -impl Default for CryptoHash { - fn default() -> Self { - CryptoHash(Default::default()) - } -} + impl borsh::BorshSerialize for CryptoHash { fn serialize(&self, writer: &mut W) -> Result<(), io::Error> { diff --git a/rust/apps/near/src/primitives_core/serialize.rs b/rust/apps/near/src/primitives_core/serialize.rs index 8e0bab355..2f38fac04 100644 --- a/rust/apps/near/src/primitives_core/serialize.rs +++ b/rust/apps/near/src/primitives_core/serialize.rs @@ -13,7 +13,7 @@ pub fn to_base(input: &Vec) -> String { } pub fn from_base(s: &str) -> Result, bs58::Error> { - bs58::decode(s).map_err(|e| bs58::Error::Decode(e)) + bs58::decode(s).map_err(bs58::Error::Decode) } pub fn to_base64>(input: T) -> String { diff --git a/rust/apps/stellar/src/address.rs b/rust/apps/stellar/src/address.rs index f2ce26813..6635cf218 100644 --- a/rust/apps/stellar/src/address.rs +++ b/rust/apps/stellar/src/address.rs @@ -66,7 +66,7 @@ mod tests { let address_error = StellarError::AddressError( "hex decode error Invalid character 'g' at position 63".to_string(), ); - let error: StellarError = address_error.into(); + let error: StellarError = address_error; let xpub = "5f5a723f0f3ef785387b016a8b61eb2713b02f429edadfacd96082d7da02959g"; let address_from_xpub = get_address(&xpub.to_string()); assert_eq!( diff --git a/rust/apps/stellar/src/lib.rs b/rust/apps/stellar/src/lib.rs index ab70e02d9..5bea76446 100644 --- a/rust/apps/stellar/src/lib.rs +++ b/rust/apps/stellar/src/lib.rs @@ -12,7 +12,7 @@ extern crate alloc; use crate::structs::Network; use alloc::string::String; use alloc::vec::Vec; -use base64; + pub fn get_network_from_base(base: &[u8]) -> Network { let network_id = &base[0..32]; @@ -30,7 +30,7 @@ pub fn base_to_xdr(base: &[u8]) -> String { #[cfg(test)] mod tests { - use hex; + extern crate std; use super::*; diff --git a/rust/apps/stellar/src/strkeys.rs b/rust/apps/stellar/src/strkeys.rs index ecc5c414d..86e8f8168 100644 --- a/rust/apps/stellar/src/strkeys.rs +++ b/rust/apps/stellar/src/strkeys.rs @@ -94,7 +94,7 @@ pub fn generate_stellar_private_key(seed: &[u8], path: &String) -> Result Result<[u8; 64]> { - keystore::algorithms::ed25519::slip10_ed25519::sign_message_by_seed(seed, path, &hash) + keystore::algorithms::ed25519::slip10_ed25519::sign_message_by_seed(seed, path, hash) } pub fn sign_signature_base(signature_base: &[u8], seed: &[u8], path: &String) -> Result<[u8; 64]> { @@ -105,7 +105,7 @@ pub fn sign_signature_base(signature_base: &[u8], seed: &[u8], path: &String) -> #[cfg(test)] mod tests { use super::*; - use alloc::string::{String, ToString}; + use alloc::string::{ToString}; use hex; #[test] @@ -137,7 +137,7 @@ mod tests { let signed = sign_hash(&hash, &seed, &path).unwrap(); assert_eq!( "baa7bcf26f8ed50d48e3d15d918f1ae684eaf7a2f876bd6913c78df59eeebcb9a5078628391c9e8d83430b9cc358a8548d0da6f0783a72743104a91e97c5f701", - hex::encode(&signed) + hex::encode(signed) ); } @@ -149,7 +149,7 @@ mod tests { let signed = sign_signature_base(&base, &seed, &path).unwrap(); assert_eq!( "baa7bcf26f8ed50d48e3d15d918f1ae684eaf7a2f876bd6913c78df59eeebcb9a5078628391c9e8d83430b9cc358a8548d0da6f0783a72743104a91e97c5f701", - hex::encode(&signed) + hex::encode(signed) ); } } diff --git a/rust/apps/sui/src/lib.rs b/rust/apps/sui/src/lib.rs index edd92afa9..656738e24 100644 --- a/rust/apps/sui/src/lib.rs +++ b/rust/apps/sui/src/lib.rs @@ -55,11 +55,11 @@ pub fn parse_intent(intent: &[u8]) -> Result { match IntentScope::try_from(intent[0])? { IntentScope::TransactionData => { let tx: IntentMessage = - bcs::from_bytes(&intent).map_err(|err| SuiError::from(err))?; + bcs::from_bytes(intent).map_err(SuiError::from)?; Ok(Intent::TransactionData(tx)) } IntentScope::PersonalMessage => { - let msg: IntentMessage = match bcs::from_bytes(&intent) { + let msg: IntentMessage = match bcs::from_bytes(intent) { Ok(msg) => msg, Err(_) => { if intent.len() < 4 { @@ -67,7 +67,7 @@ pub fn parse_intent(intent: &[u8]) -> Result { } let intent_bytes = intent[..3].to_vec(); IntentMessage::::new( - types::intent::Intent::from_str(hex::encode(&intent_bytes).as_str())?, + types::intent::Intent::from_str(hex::encode(intent_bytes).as_str())?, PersonalMessage { message: intent[3..].to_vec(), }, @@ -86,7 +86,7 @@ pub fn parse_intent(intent: &[u8]) -> Result { })) } _ => { - return Err(SuiError::InvalidData(String::from("unsupported intent"))); + Err(SuiError::InvalidData(String::from("unsupported intent"))) } } } diff --git a/rust/apps/ton/src/jettons.rs b/rust/apps/ton/src/jettons.rs index f2a61478c..73b65c6fd 100644 --- a/rust/apps/ton/src/jettons.rs +++ b/rust/apps/ton/src/jettons.rs @@ -47,5 +47,5 @@ pub fn get_jetton_amount_text(coins: String, contract_address: String) -> String .unwrap(); let value = u64::from_str_radix(&coins, 10).unwrap(); let divisor = 10u64.pow(target.decimal as u32) as f64; - return format!("{} {}", (value as f64) / divisor, target.symbol); + format!("{} {}", (value as f64) / divisor, target.symbol) } diff --git a/rust/apps/ton/src/lib.rs b/rust/apps/ton/src/lib.rs index f0cacf764..004eb37a7 100644 --- a/rust/apps/ton/src/lib.rs +++ b/rust/apps/ton/src/lib.rs @@ -31,7 +31,7 @@ pub fn ton_public_key_to_address(pk: Vec) -> Result { pub fn ton_compare_address_and_public_key(pk: Vec, address: String) -> bool { match TonWallet::derive_default(vendor::wallet::WalletVersion::V4R2, pk) { Ok(wallet) => match TonAddress::from_str(&address) { - Ok(address) => return wallet.address.eq(&address), + Ok(address) => wallet.address.eq(&address), Err(_e) => false, }, Err(_e) => false, @@ -40,7 +40,7 @@ pub fn ton_compare_address_and_public_key(pk: Vec, address: String) -> bool #[cfg(test)] mod tests { - use hex; + #[test] fn test_generate_address() { diff --git a/rust/apps/ton/src/messages/jetton.rs b/rust/apps/ton/src/messages/jetton.rs index 9e0754f3b..c7f931c5e 100644 --- a/rust/apps/ton/src/messages/jetton.rs +++ b/rust/apps/ton/src/messages/jetton.rs @@ -76,7 +76,7 @@ impl ParseCell for JettonTransferMessage { let mut ref_index = 0; let custom_payload = if parser.load_bit()? { let payload = Some(hex::encode(cell.reference(ref_index)?.data.clone())); - ref_index = ref_index + 1; + ref_index += 1; payload } else { None @@ -87,7 +87,7 @@ impl ParseCell for JettonTransferMessage { let comment = Comment::parse(child); let payload = Some(hex::encode(child.data.clone())); - ref_index = ref_index + 1; + ref_index += 1; (payload, comment.ok()) } else { (None, None) diff --git a/rust/apps/ton/src/messages/mod.rs b/rust/apps/ton/src/messages/mod.rs index 17d56dbff..1557f2f2c 100644 --- a/rust/apps/ton/src/messages/mod.rs +++ b/rust/apps/ton/src/messages/mod.rs @@ -2,7 +2,7 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; -use hex; + use serde::Serialize; use self::jetton::JettonMessage; @@ -37,7 +37,7 @@ impl ParseCell for SigningMessage { let messages: Result, TonCellError> = cell .references .iter() - .map(|cell| TransferMessage::parse(cell)) + .map(TransferMessage::parse) .collect(); Ok(Self { wallet_id, @@ -90,22 +90,20 @@ impl ParseCell for TransferMessage { let mut ref_index = 0; let state_init = if parser.load_bit()? { let init = Some(hex::encode(cell.reference(ref_index)?.data.clone())); - ref_index = ref_index + 1; + ref_index += 1; init } else { None }; let data = if parser.load_bit()? { Some(InternalMessage::parse(cell.reference(ref_index)?)) + } else if parser.remaining_bits() > 0 { + let mut builder = CellBuilder::new(); + let remaining_bits = parser.remaining_bits(); + builder.store_bits(remaining_bits, &parser.load_bits(remaining_bits)?)?; + Some(InternalMessage::parse(&builder.build()?.to_arc())) } else { - if parser.remaining_bits() > 0 { - let mut builder = CellBuilder::new(); - let remaining_bits = parser.remaining_bits(); - builder.store_bits(remaining_bits, &parser.load_bits(remaining_bits)?)?; - Some(InternalMessage::parse(&builder.build()?.to_arc())) - } else { - None - } + None }; Ok(Self { ihr_disabled, diff --git a/rust/apps/ton/src/messages/nft.rs b/rust/apps/ton/src/messages/nft.rs index 47a10ad21..8261deddc 100644 --- a/rust/apps/ton/src/messages/nft.rs +++ b/rust/apps/ton/src/messages/nft.rs @@ -56,7 +56,7 @@ impl ParseCell for NFTTransferMessage { let mut ref_index = 0; let custom_payload = if parser.load_bit()? { let payload = Some(hex::encode(cell.reference(ref_index)?.data.clone())); - ref_index = ref_index + 1; + ref_index += 1; payload } else { None @@ -67,7 +67,7 @@ impl ParseCell for NFTTransferMessage { let comment = Comment::parse(child); let payload = Some(hex::encode(child.data.clone())); - ref_index = ref_index + 1; + ref_index += 1; (payload, comment.ok()) } else { (None, None) diff --git a/rust/apps/ton/src/mnemonic.rs b/rust/apps/ton/src/mnemonic.rs index 049652924..cf3f49762 100644 --- a/rust/apps/ton/src/mnemonic.rs +++ b/rust/apps/ton/src/mnemonic.rs @@ -34,7 +34,7 @@ pub fn ton_mnemonic_validate( if seed[0] != 1 { return Err(MnemonicError::InvalidFirstByte(seed[0]).into()); } - let entropy = ton_mnemonic_to_entropy(&normalized_words, password); + let entropy = ton_mnemonic_to_entropy(normalized_words, password); pbkdf2_sha512( &entropy, "TON seed version".as_bytes(), @@ -101,12 +101,12 @@ pub fn ton_master_seed_to_public_key(master_seed: [u8; 64]) -> [u8; 32] { #[cfg(test)] mod tests { use alloc::{string::ToString, vec}; - use base64::Engine; + use hex; use super::*; extern crate std; - use std::{println, vec::Vec}; + use std::{vec::Vec}; #[test] fn test_ton_mnemonic_to_entropy() { @@ -137,15 +137,13 @@ mod tests { #[test] fn test_ton_mnemonic_invalid_mnemonic() { - let words = vec![ - "dose", "ice", "enrich", "trigger", "test", "dove", "century", "still", "betray", - "gas", "diet", "dune", - ] + let words = ["dose", "ice", "enrich", "trigger", "test", "dove", "century", "still", "betray", + "gas", "diet", "dune"] .iter() .map(|v| v.to_lowercase()) .collect(); let result = ton_mnemonic_to_master_seed(words, None); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), "Invalid TON Mnemonic, Invalid mnemonic word count (count: 12)" diff --git a/rust/apps/ton/src/structs.rs b/rust/apps/ton/src/structs.rs index fb0086550..6125ff561 100644 --- a/rust/apps/ton/src/structs.rs +++ b/rust/apps/ton/src/structs.rs @@ -27,7 +27,7 @@ pub struct TonTransaction { impl TonTransaction { pub fn parse(boc: BagOfCells) -> Result { let root = boc.single_root()?; - let signing_message = SigningMessage::parse(&root)?; + let signing_message = SigningMessage::parse(root)?; Self::try_from(&signing_message) } @@ -49,7 +49,7 @@ impl TryFrom<&SigningMessage> for TonTransaction { type Error = TonError; fn try_from(signing_message: &SigningMessage) -> Result { - if let None = signing_message.messages.get(0) { + if signing_message.messages.first().is_none() { return Err(TonError::InvalidTransaction( "transaction does not contain transfer info".to_string(), )); @@ -194,7 +194,7 @@ impl TonProof { for i in 0..8 { timestamp_bytes[i] = remaining[i + 40 + domain_len as usize]; } - index = index + 8; + index += 8; // need to transform to date time to display let _timestamp = i64::from_le_bytes(timestamp_bytes); diff --git a/rust/apps/ton/src/transaction.rs b/rust/apps/ton/src/transaction.rs index 15308c807..978de9cf4 100644 --- a/rust/apps/ton/src/transaction.rs +++ b/rust/apps/ton/src/transaction.rs @@ -97,10 +97,10 @@ mod tests { sk[i] = master_seed[i] } let signature = super::sign_transaction(&serial, sk).unwrap(); - println!("{}", hex::encode(&signature)); + println!("{}", hex::encode(signature)); println!( "tonkeeper://publish?boc={}", - urlencoding::encode(&STANDARD.encode(&signature)) + urlencoding::encode(&STANDARD.encode(signature)) ); } diff --git a/rust/apps/ton/src/utils.rs b/rust/apps/ton/src/utils.rs index ad2e72684..d48e406b5 100644 --- a/rust/apps/ton/src/utils.rs +++ b/rust/apps/ton/src/utils.rs @@ -25,7 +25,7 @@ pub(crate) fn shorten_string(text: String) -> String { let _ = _text.split_off(512); _text.push_str("......"); } - return _text; + _text } #[cfg(test)] diff --git a/rust/apps/ton/src/vendor/address/mod.rs b/rust/apps/ton/src/vendor/address/mod.rs index d83573198..b39d9fa52 100644 --- a/rust/apps/ton/src/vendor/address/mod.rs +++ b/rust/apps/ton/src/vendor/address/mod.rs @@ -484,7 +484,7 @@ mod tests { let address = "124"; let a = format!("\"{}\"", address); let deserial: serde_json::Result = serde_json::from_str(a.as_str()); - assert_eq!(true, deserial.is_err()); + assert!(deserial.is_err()); Ok(()) } diff --git a/rust/apps/tron/src/address.rs b/rust/apps/tron/src/address.rs index 8ba45bf81..f10c23902 100644 --- a/rust/apps/tron/src/address.rs +++ b/rust/apps/tron/src/address.rs @@ -21,7 +21,7 @@ macro_rules! check_hd_path { macro_rules! derivation_address_path { ($t: expr) => {{ let parts = $t.split("/").collect::>(); - let result: Result = match crate::check_hd_path!(parts) { + let result: Result = match $crate::check_hd_path!(parts) { Ok(_) => { let path = parts.as_slice()[parts.len() - 2..].to_vec().join("/"); Ok(format!("{}{}", "m/", path)) diff --git a/rust/apps/tron/src/errors.rs b/rust/apps/tron/src/errors.rs index 40a411a17..6b807040c 100644 --- a/rust/apps/tron/src/errors.rs +++ b/rust/apps/tron/src/errors.rs @@ -1,4 +1,4 @@ -use alloc::format; + use alloc::string::{String, ToString}; use bitcoin::base58::Error as Base58Error; use keystore::errors::KeystoreError; @@ -32,8 +32,8 @@ pub type Result = core::result::Result; impl From for TronError { fn from(value: KeystoreError) -> Self { match value { - KeystoreError::DerivePubKey(data) => Self::KeystoreError(format!("{}", data)), - KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(format!("{}", data)), + KeystoreError::DerivePubKey(data) => Self::KeystoreError(data.to_string()), + KeystoreError::InvalidDerivationPath(data) => Self::KeystoreError(data.to_string()), KeystoreError::XPubError(data) => Self::KeystoreError(data), KeystoreError::SeedError(data) => Self::KeystoreError(data), KeystoreError::DerivationError(data) => Self::KeystoreError(data), diff --git a/rust/apps/tron/src/transaction/parser.rs b/rust/apps/tron/src/transaction/parser.rs index 81bcc0578..a0ec03a6a 100644 --- a/rust/apps/tron/src/transaction/parser.rs +++ b/rust/apps/tron/src/transaction/parser.rs @@ -91,8 +91,8 @@ mod tests { assert_eq!("0.000001 TRX".to_string(), parsed_tx.detail.value); assert_eq!("TRX Transfer".to_string(), parsed_tx.detail.method); assert_eq!("TRX Transfer".to_string(), parsed_tx.overview.method); - assert_eq!(true, parsed_tx.detail.contract_address.is_empty()); - assert_eq!(true, parsed_tx.detail.token.is_empty()); + assert!(parsed_tx.detail.contract_address.is_empty()); + assert!(parsed_tx.detail.token.is_empty()); } #[test] @@ -125,7 +125,7 @@ mod tests { assert_eq!("0.001 BTT".to_string(), parsed_tx.detail.value); assert_eq!("TRC-10 Transfer".to_string(), parsed_tx.detail.method); assert_eq!("TRC-10 Transfer".to_string(), parsed_tx.overview.method); - assert_eq!(true, parsed_tx.detail.contract_address.is_empty()); + assert!(parsed_tx.detail.contract_address.is_empty()); assert_eq!("1002000".to_string(), parsed_tx.detail.token); } @@ -164,7 +164,7 @@ mod tests { "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t".to_string(), parsed_tx.detail.contract_address ); - assert_eq!(true, parsed_tx.detail.token.is_empty()); + assert!(parsed_tx.detail.token.is_empty()); } { let hex = "1f8b08000000000000036590bb4ec2500086158d212c4ae3409848638231697aaeeda993012f040a166c8074316d4f1b01a1da969b2383a3cfe0ec03b0bac81b38b8b8bab8b9b85a66bf7cc33f7ef9d32961b7199603ee158c30880337b8cdaf52e99490a648254405585ca632db66ebb2211c4080d6320901db9708f76dc9810c4b34c157180714a07cb62e135294a1468b32489461e1ebf169b580873ba5ef4d4134cbe7ba4ef98c5a555e1b75c65ed49df560db98f6f5f6b06359732d2f9aa7837034ad3f443066fde0a27d17e90a19d6303c0b5bb8177771248a666512c57a496db6260ebfbf31c60d7b6e065a87f6355c1f20ab3239da40fb10fce7b89139819e9ff47ac4610e5320f21dc401c19801e062c23d9ff89ae203e051c55535d725d4b63972806d3305a8d4657b9f3fcb5ceee3e5fd6d014bd9cc56f5ca14d2eb97ae9395132acfbf4ae1d5f803c61a369f5e010000"; diff --git a/rust/apps/tron/src/transaction/wrapped_tron.rs b/rust/apps/tron/src/transaction/wrapped_tron.rs index 808ede41e..bce69b5a1 100644 --- a/rust/apps/tron/src/transaction/wrapped_tron.rs +++ b/rust/apps/tron/src/transaction/wrapped_tron.rs @@ -43,7 +43,7 @@ pub struct WrappedTron { macro_rules! derivation_account_path { ($t: expr) => {{ let parts = $t.split("/").collect::>(); - let result: Result = match crate::check_hd_path!(parts) { + let result: Result = match $crate::check_hd_path!(parts) { Ok(_) => { let path = parts.as_slice()[1..parts.len() - 2].to_vec().join("/"); Ok(format!("{}{}", "m/", path)) @@ -92,7 +92,7 @@ impl WrappedTron { ) -> Result { let to_address = base58check_to_u8_slice(to)?; let owner_address = base58check_to_u8_slice(from)?; - return if token.to_uppercase() == "TRX" { + if token.to_uppercase() == "TRX" { let mut transfer_contract = TransferContract::default(); transfer_contract.owner_address = owner_address; transfer_contract.amount = amount; @@ -118,7 +118,7 @@ impl WrappedTron { "TransferAssetContract", None, ) - }; + } } fn build_transfer_contract( @@ -144,7 +144,7 @@ impl WrappedTron { raw.contract = vec![contract]; let mut transaction = Transaction::default(); transaction.raw_data = Some(raw); - return Ok(transaction); + Ok(transaction) } fn ref_with_latest_block( @@ -153,7 +153,7 @@ impl WrappedTron { is_trc_20: bool, ) -> Result { let number_buf: [u8; 8] = (latest_block.number as u64).to_be_bytes(); - let hash_buf = hex::decode(latest_block.hash.to_string()).map_err(|_e| { + let hash_buf = hex::decode(&latest_block.hash).map_err(|_e| { TronError::InvalidRawTxCryptoBytes(format!( "invalid latest block hash {}", latest_block.hash @@ -172,7 +172,7 @@ impl WrappedTron { raw_data.expiration = latest_block.timestamp + 600 * 5 * 1000; tx.raw_data = Some(raw_data); }; - return Ok(tx.to_owned()); + Ok(tx.to_owned()) } fn build_transfer_tx(tx_data: &protoc::TronTx) -> Result { @@ -199,7 +199,7 @@ impl WrappedTron { .ok_or(TronError::InvalidRawTxCryptoBytes( "empty latest block".to_string(), ))?; - return Self::ref_with_latest_block(tx, latest_block, false); + Self::ref_with_latest_block(tx, latest_block, false) } #[allow(deprecated)] @@ -314,7 +314,7 @@ impl WrappedTron { pub fn format_amount(&self) -> Result { let value = f64::from_str(self.value.as_str())?; let unit = self.format_unit()?; - Ok(format!("{} {}", value.div(self.divider as f64), unit)) + Ok(format!("{} {}", value.div(self.divider), unit)) } pub fn format_method(&self) -> Result { @@ -334,5 +334,5 @@ impl WrappedTron { } } -pub const DIVIDER: f64 = 1000000 as f64; +pub const DIVIDER: f64 = 1000000_f64; pub const NETWORK: &str = "TRON"; diff --git a/rust/apps/utils/src/lib.rs b/rust/apps/utils/src/lib.rs index 82a596a92..61334838b 100644 --- a/rust/apps/utils/src/lib.rs +++ b/rust/apps/utils/src/lib.rs @@ -8,14 +8,14 @@ pub use paste; use alloc::format; use alloc::string::String; -use unicode_blocks; + pub fn normalize_path(path: &String) -> String { let mut p = path.to_lowercase(); if !p.starts_with("m/") { p = format!("{}{}", "m/", p); } - if !p.starts_with("m") { + if !p.starts_with('m') { p = format!("{}{}", "m", p); } p @@ -27,7 +27,7 @@ pub fn is_cjk(utf8_string: &str) -> bool { return true; } } - return false; + false } #[cfg(test)] @@ -50,18 +50,18 @@ mod tests { fn test_is_cjk() { let utf8_string = "你好"; let result = is_cjk(utf8_string); - assert_eq!(result, true); + assert!(result); let utf8_string = "hello"; let result = is_cjk(utf8_string); - assert_eq!(result, false); + assert!(!result); let utf8_string = "こんにちは"; let result = is_cjk(utf8_string); - assert_eq!(result, true); + assert!(result); let utf8_string = "안녕하세요"; let result = is_cjk(utf8_string); - assert_eq!(result, true); + assert!(result); } } diff --git a/rust/apps/wallets/src/aptos.rs b/rust/apps/wallets/src/aptos.rs index 363eab39a..37d239531 100644 --- a/rust/apps/wallets/src/aptos.rs +++ b/rust/apps/wallets/src/aptos.rs @@ -11,7 +11,7 @@ pub fn generate_sync_ur( master_fingerprint: &[u8; 4], public_keys: BTreeMap, ) -> URResult { - generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, &"APT") + generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, "APT") } #[cfg(test)] diff --git a/rust/apps/wallets/src/backpack.rs b/rust/apps/wallets/src/backpack.rs index 769569190..c89fe9415 100644 --- a/rust/apps/wallets/src/backpack.rs +++ b/rust/apps/wallets/src/backpack.rs @@ -59,7 +59,7 @@ pub fn generate_crypto_multi_accounts( _ => { return Err(URError::UrEncodeError(format!( "Unknown key path: {}", - ele.path.to_string() + ele.path ))) } } @@ -83,8 +83,8 @@ fn generate_ed25519_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -114,8 +114,8 @@ fn generate_k1_normal_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -154,8 +154,8 @@ fn generate_eth_ledger_live_key( target_path .into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -207,23 +207,23 @@ mod tests { mfp, vec![ ExtendedPublicKey::new( - DerivationPath::from_str(&sol_pub_1_path).unwrap(), - hex::decode(&sol_pub_1).unwrap(), + DerivationPath::from_str(sol_pub_1_path).unwrap(), + hex::decode(sol_pub_1).unwrap(), ), ExtendedPublicKey::new( - DerivationPath::from_str(&sol_pub_2_path).unwrap(), - hex::decode(&sol_pub_2).unwrap(), + DerivationPath::from_str(sol_pub_2_path).unwrap(), + hex::decode(sol_pub_2).unwrap(), ), ExtendedPublicKey::new( - DerivationPath::from_str(ð_bip44_standard_xpub_path).unwrap(), - Xpub::from_str(ð_bip44_standard_xpub) + DerivationPath::from_str(eth_bip44_standard_xpub_path).unwrap(), + Xpub::from_str(eth_bip44_standard_xpub) .unwrap() .encode() .to_vec(), ), ExtendedPublicKey::new( - DerivationPath::from_str(ð_ledger_live_xpub_1_path).unwrap(), - Xpub::from_str(ð_ledger_live_xpub_1) + DerivationPath::from_str(eth_ledger_live_xpub_1_path).unwrap(), + Xpub::from_str(eth_ledger_live_xpub_1) .unwrap() .encode() .to_vec(), diff --git a/rust/apps/wallets/src/bitget.rs b/rust/apps/wallets/src/bitget.rs index 11d58091c..608e391a9 100644 --- a/rust/apps/wallets/src/bitget.rs +++ b/rust/apps/wallets/src/bitget.rs @@ -40,12 +40,10 @@ pub fn generate_crypto_multi_accounts( ) -> URResult { let device_id = get_device_id(serial_number); let mut keys = vec![]; - let k1_keys = vec![ - BTC_LEGACY_PREFIX.to_string(), + let k1_keys = [BTC_LEGACY_PREFIX.to_string(), BTC_SEGWIT_PREFIX.to_string(), BTC_NATIVE_SEGWIT_PREFIX.to_string(), - BTC_TAPROOT_PREFIX.to_string(), - ]; + BTC_TAPROOT_PREFIX.to_string()]; for ele in extended_public_keys { match ele.get_path() { _path if k1_keys.contains(&_path.to_string().to_lowercase()) => { @@ -93,7 +91,7 @@ pub fn generate_crypto_multi_accounts( _ => { return Err(URError::UrEncodeError(format!( "Unknown key path: {}", - ele.path.to_string() + ele.path ))) } } @@ -120,8 +118,8 @@ fn generate_k1_normal_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -174,8 +172,8 @@ fn generate_eth_ledger_live_key( target_path .into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -199,8 +197,8 @@ fn generate_ton_key(mfp: [u8; 4], key: ExtendedPublicKey) -> URResult get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -357,18 +355,18 @@ mod tests { mfp, "31206", vec![ - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_1_path).unwrap(), x_pub_1), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_2_path).unwrap(), x_pub_2), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_3_path).unwrap(), x_pub_3), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_4_path).unwrap(), x_pub_4), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_5_path).unwrap(), x_pub_5), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_6_path).unwrap(), x_pub_6), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_7_path).unwrap(), x_pub_7), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_8_path).unwrap(), x_pub_8), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_9_path).unwrap(), x_pub_9), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_10_path).unwrap(), x_pub_10), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_11_path).unwrap(), x_pub_11), - ExtendedPublicKey::new(DerivationPath::from_str(&x_pub_12_path).unwrap(), x_pub_12), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_1_path).unwrap(), x_pub_1), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_2_path).unwrap(), x_pub_2), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_3_path).unwrap(), x_pub_3), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_4_path).unwrap(), x_pub_4), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_5_path).unwrap(), x_pub_5), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_6_path).unwrap(), x_pub_6), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_7_path).unwrap(), x_pub_7), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_8_path).unwrap(), x_pub_8), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_9_path).unwrap(), x_pub_9), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_10_path).unwrap(), x_pub_10), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_11_path).unwrap(), x_pub_11), + ExtendedPublicKey::new(DerivationPath::from_str(x_pub_12_path).unwrap(), x_pub_12), ], DEVICE_TYPE, "1.1.0", diff --git a/rust/apps/wallets/src/blue_wallet.rs b/rust/apps/wallets/src/blue_wallet.rs index 7e9d98435..8739fffc4 100644 --- a/rust/apps/wallets/src/blue_wallet.rs +++ b/rust/apps/wallets/src/blue_wallet.rs @@ -32,7 +32,7 @@ pub fn generate_crypto_account( )?); } - Ok(CryptoAccount::new(master_fingerprint.clone(), outputs)) + Ok(CryptoAccount::new(*master_fingerprint, outputs)) } fn get_path_level_number(path: &str, index: usize) -> Option { @@ -105,7 +105,7 @@ fn generate_crypto_hd_key( get_path_component(Some(coin_type), true)?, get_path_component(Some(0), true)?, ], - Some(master_fingerprint.clone()), + Some(*master_fingerprint), Some(bip32_extended_pub_key.depth as u32), ); @@ -133,7 +133,7 @@ fn generate_crypto_hd_key( } fn get_path_component(index: Option, hardened: bool) -> URResult { - PathComponent::new(index, hardened).map_err(|e| URError::CborEncodeError(e)) + PathComponent::new(index, hardened).map_err(URError::CborEncodeError) } #[cfg(test)] diff --git a/rust/apps/wallets/src/common.rs b/rust/apps/wallets/src/common.rs index 68df6e277..6e4c4cade 100644 --- a/rust/apps/wallets/src/common.rs +++ b/rust/apps/wallets/src/common.rs @@ -4,5 +4,5 @@ use ur_registry::{ }; pub fn get_path_component(index: Option, hardened: bool) -> URResult { - PathComponent::new(index, hardened).map_err(|e| URError::CborEncodeError(e)) + PathComponent::new(index, hardened).map_err(URError::CborEncodeError) } diff --git a/rust/apps/wallets/src/companion_app.rs b/rust/apps/wallets/src/companion_app.rs index a983d8320..a046e5eef 100644 --- a/rust/apps/wallets/src/companion_app.rs +++ b/rust/apps/wallets/src/companion_app.rs @@ -82,14 +82,14 @@ mod tests { use super::*; - const BTC_COIN_CODE: &'static str = "BTC"; - const BTC_PATH: &'static str = "M/49'/0'/0'"; + const BTC_COIN_CODE: &str = "BTC"; + const BTC_PATH: &str = "M/49'/0'/0'"; - const BTC_LEGACY_COIN_CODE: &'static str = "BTC_LEGACY"; - const BTC_LEGACY_PATH: &'static str = "M/44'/0'/0'"; + const BTC_LEGACY_COIN_CODE: &str = "BTC_LEGACY"; + const BTC_LEGACY_PATH: &str = "M/44'/0'/0'"; - const BTC_NATIVE_SEGWIT_COIN_CODE: &'static str = "BTC_NATIVE_SEGWIT"; - const BTC_NATIVE_SEGWIT_PATH: &'static str = "M/84'/0'/0'"; + const BTC_NATIVE_SEGWIT_COIN_CODE: &str = "BTC_NATIVE_SEGWIT"; + const BTC_NATIVE_SEGWIT_PATH: &str = "M/84'/0'/0'"; #[test] fn test_generate_crypto_account() { diff --git a/rust/apps/wallets/src/keplr/mod.rs b/rust/apps/wallets/src/keplr/mod.rs index b9fbd4d80..cba32a2c1 100644 --- a/rust/apps/wallets/src/keplr/mod.rs +++ b/rust/apps/wallets/src/keplr/mod.rs @@ -26,12 +26,12 @@ fn get_origin( ChildNumber::Hardened { index } => index, ChildNumber::Normal { index } => index, }; - PathComponent::new(Some(index.clone()), child_number.is_hardened()).unwrap() + PathComponent::new(Some(*index), child_number.is_hardened()).unwrap() }) .collect::>(); Ok(CryptoKeyPath::new( components, - Some(master_fingerprint.clone()), + Some(master_fingerprint), Some(depth), )) } @@ -40,9 +40,9 @@ pub fn generate_sync_ur( sync_infos: &Vec, ) -> URResult { let mut keys: Vec = Vec::new(); - sync_infos.into_iter().for_each(|sync_info| { + sync_infos.iter().for_each(|sync_info| { if let Ok(xpub) = bip32::Xpub::from_str(sync_info.xpub.as_str()) { - if let Ok(origin) = get_origin(sync_info, master_fingerprint.clone(), xpub.depth as u32) + if let Ok(origin) = get_origin(sync_info, *master_fingerprint, xpub.depth as u32) { let hd_key: CryptoHDKey = CryptoHDKey::new_extended_key( Some(false), @@ -60,7 +60,7 @@ pub fn generate_sync_ur( } }); Ok(CryptoMultiAccounts::new( - master_fingerprint.clone(), + *master_fingerprint, keys, Some(DEVICE_TYPE.to_string()), None, diff --git a/rust/apps/wallets/src/keystone.rs b/rust/apps/wallets/src/keystone.rs index e84954ef6..038ee3f16 100644 --- a/rust/apps/wallets/src/keystone.rs +++ b/rust/apps/wallets/src/keystone.rs @@ -92,7 +92,7 @@ pub fn generate_crypto_multi_accounts( _ => { return Err(URError::UrEncodeError(format!( "Unknown key path: {}", - ele.path.to_string() + ele.path ))) } } @@ -178,8 +178,8 @@ fn generate_k1_normal_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), diff --git a/rust/apps/wallets/src/metamask.rs b/rust/apps/wallets/src/metamask.rs index f31ed1bfa..bb0637bd4 100644 --- a/rust/apps/wallets/src/metamask.rs +++ b/rust/apps/wallets/src/metamask.rs @@ -47,7 +47,7 @@ pub fn generate_standard_legacy_hd_key( get_path_component(Some(ETH_COIN_TYPE), true)?, get_path_component(Some(0), true)?, ], - Some(master_fingerprint.clone()), + Some(*master_fingerprint), Some(bip32_extended_pub_key.depth as u32), ); @@ -92,7 +92,7 @@ pub fn generate_ledger_live_account( let output = generate_ledger_live_crypto_output(master_fingerprint, x.as_str(), i as u32)?; outputs.push(output); } - Ok(CryptoAccount::new(master_fingerprint.clone(), outputs)) + Ok(CryptoAccount::new(*master_fingerprint, outputs)) } fn generate_ledger_live_crypto_output( @@ -128,7 +128,7 @@ pub fn generate_ledger_live_hd_key( get_path_component(Some(0), false)?, get_path_component(Some(0), false)?, ], - Some(master_fingerprint.clone()), + Some(*master_fingerprint), Some(bip32_extended_pub_key.depth as u32), ); @@ -148,7 +148,7 @@ pub fn generate_ledger_live_hd_key( } fn get_path_component(index: Option, hardened: bool) -> URResult { - PathComponent::new(index, hardened).map_err(|e| URError::CborEncodeError(e)) + PathComponent::new(index, hardened).map_err(URError::CborEncodeError) } #[cfg(test)] diff --git a/rust/apps/wallets/src/okx.rs b/rust/apps/wallets/src/okx.rs index bacefd433..ad084f129 100644 --- a/rust/apps/wallets/src/okx.rs +++ b/rust/apps/wallets/src/okx.rs @@ -42,16 +42,14 @@ pub fn generate_crypto_multi_accounts( ) -> URResult { let device_id = get_device_id(serial_number); let mut keys = vec![]; - let k1_keys = vec![ - BTC_LEGACY_PREFIX.to_string(), + let k1_keys = [BTC_LEGACY_PREFIX.to_string(), BTC_SEGWIT_PREFIX.to_string(), BTC_NATIVE_SEGWIT_PREFIX.to_string(), BTC_TAPROOT_PREFIX.to_string(), TRX_PREFIX.to_string(), LTC_PREFIX.to_string(), BCH_PREFIX.to_string(), - DASH_PREFIX.to_string(), - ]; + DASH_PREFIX.to_string()]; for ele in extended_public_keys { match ele.get_path() { _path if k1_keys.contains(&_path.to_string().to_lowercase()) => { @@ -88,7 +86,7 @@ pub fn generate_crypto_multi_accounts( _ => { return Err(URError::UrEncodeError(format!( "Unknown key path: {}", - ele.path.to_string() + ele.path ))) } } @@ -114,8 +112,8 @@ fn generate_k1_normal_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -154,8 +152,8 @@ fn generate_eth_ledger_live_key( target_path .into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), diff --git a/rust/apps/wallets/src/solana.rs b/rust/apps/wallets/src/solana.rs index 346a9d761..5e58345b8 100644 --- a/rust/apps/wallets/src/solana.rs +++ b/rust/apps/wallets/src/solana.rs @@ -9,7 +9,7 @@ pub fn generate_sync_ur( master_fingerprint: &[u8; 4], public_keys: BTreeMap, ) -> URResult { - generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, &"SOL") + generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, "SOL") } #[cfg(test)] diff --git a/rust/apps/wallets/src/sui.rs b/rust/apps/wallets/src/sui.rs index 40005fa3f..1e80b0259 100644 --- a/rust/apps/wallets/src/sui.rs +++ b/rust/apps/wallets/src/sui.rs @@ -9,7 +9,7 @@ pub fn generate_sync_ur( master_fingerprint: &[u8; 4], public_keys: BTreeMap, ) -> URResult { - generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, &"SUI") + generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, "SUI") } #[cfg(test)] diff --git a/rust/apps/wallets/src/thor_wallet.rs b/rust/apps/wallets/src/thor_wallet.rs index 3898c8598..c09469c11 100644 --- a/rust/apps/wallets/src/thor_wallet.rs +++ b/rust/apps/wallets/src/thor_wallet.rs @@ -38,12 +38,10 @@ pub fn generate_crypto_multi_accounts( ) -> URResult { let device_id = get_device_id(serial_number); let mut keys = vec![]; - let k1_keys = vec![ - BTC_LEGACY_PREFIX.to_string(), + let k1_keys = [BTC_LEGACY_PREFIX.to_string(), BTC_SEGWIT_PREFIX.to_string(), BTC_NATIVE_SEGWIT_PREFIX.to_string(), - THORCHAIN_PREFIX.to_string(), - ]; + THORCHAIN_PREFIX.to_string()]; for ele in extended_public_keys { match ele.get_path() { _path if k1_keys.contains(&_path.to_string().to_lowercase()) => { @@ -80,7 +78,7 @@ pub fn generate_crypto_multi_accounts( _ => { return Err(URError::UrEncodeError(format!( "Unknown key path: {}", - ele.path.to_string() + ele.path ))) } } @@ -106,8 +104,8 @@ fn generate_k1_normal_key( let key_path = CryptoKeyPath::new( path.into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), @@ -146,8 +144,8 @@ fn generate_eth_ledger_live_key( target_path .into_iter() .map(|v| match v { - ChildNumber::Normal { index } => get_path_component(Some(index.clone()), false), - ChildNumber::Hardened { index } => get_path_component(Some(index.clone()), true), + ChildNumber::Normal { index } => get_path_component(Some(*index), false), + ChildNumber::Hardened { index } => get_path_component(Some(*index), true), }) .collect::>>()?, Some(mfp), diff --git a/rust/apps/wallets/src/tonkeeper.rs b/rust/apps/wallets/src/tonkeeper.rs index e6667378a..21d9e76ef 100644 --- a/rust/apps/wallets/src/tonkeeper.rs +++ b/rust/apps/wallets/src/tonkeeper.rs @@ -19,7 +19,7 @@ pub fn generate_sync_ur( let key_path = info.path; let master_fingerprint = info.mfp; let crypto_key_path = CryptoKeyPath::from_path(key_path, Some(master_fingerprint)) - .map_err(|e| URError::UrEncodeError(e))?; + .map_err(URError::UrEncodeError)?; Ok(CryptoHDKey::new_extended_key( None, pubkey, diff --git a/rust/apps/wallets/src/utils.rs b/rust/apps/wallets/src/utils.rs index 1ef914172..1ce6e7d8b 100644 --- a/rust/apps/wallets/src/utils.rs +++ b/rust/apps/wallets/src/utils.rs @@ -2,7 +2,7 @@ use alloc::collections::BTreeMap; use alloc::string::{String, ToString}; use alloc::vec::Vec; use bitcoin::bip32::{ChildNumber, DerivationPath}; -use hex; + use ur_registry::crypto_hd_key::CryptoHDKey; use ur_registry::crypto_key_path::{CryptoKeyPath, PathComponent}; use ur_registry::error::{URError, URResult}; @@ -22,12 +22,12 @@ fn get_origin( ChildNumber::Hardened { index } => index, ChildNumber::Normal { index } => index, }; - PathComponent::new(Some(index.clone()), child_number.is_hardened()).unwrap() + PathComponent::new(Some(*index), child_number.is_hardened()).unwrap() }) .collect::>(); Ok(CryptoKeyPath::new( components, - Some(master_fingerprint.clone()), + Some(*master_fingerprint), Some(depth as u32), )) } @@ -59,7 +59,7 @@ pub fn generate_crypto_multi_accounts_sync_ur( } } Ok(CryptoMultiAccounts::new( - master_fingerprint.clone(), + *master_fingerprint, keys, Some(DEVICE_TYPE.to_string()), None, @@ -89,7 +89,7 @@ mod tests { let result = get_origin(&master_fingerprint, 2, path); assert!(result.is_ok()); let origin = result.unwrap(); - assert_eq!(origin.get_depth().unwrap(), 2 as u32); + assert_eq!(origin.get_depth().unwrap(), 2_u32); assert_eq!(origin.get_components().len(), 4); assert_eq!(origin.get_source_fingerprint().unwrap(), master_fingerprint); } diff --git a/rust/apps/wallets/src/xbull.rs b/rust/apps/wallets/src/xbull.rs index 6757cec3c..19a7da4e5 100644 --- a/rust/apps/wallets/src/xbull.rs +++ b/rust/apps/wallets/src/xbull.rs @@ -9,7 +9,7 @@ pub fn generate_sync_ur( master_fingerprint: &[u8; 4], public_keys: BTreeMap, ) -> URResult { - generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, &"STELLAR") + generate_crypto_multi_accounts_sync_ur(master_fingerprint, public_keys, "STELLAR") } #[cfg(test)] diff --git a/rust/apps/wallets/src/xrp_toolkit.rs b/rust/apps/wallets/src/xrp_toolkit.rs index a9f789429..903975cc7 100644 --- a/rust/apps/wallets/src/xrp_toolkit.rs +++ b/rust/apps/wallets/src/xrp_toolkit.rs @@ -8,7 +8,7 @@ use ur_registry::error::URError::UrEncodeError; use ur_registry::error::URResult; pub fn generate_sync_ur(hd_path: &str, root_x_pub: &str, root_path: &str) -> URResult { - let root_path = if !root_path.ends_with("/") { + let root_path = if !root_path.ends_with('/') { root_path.to_string() + "/" } else { root_path.to_string() @@ -25,7 +25,7 @@ pub fn generate_sync_ur(hd_path: &str, root_x_pub: &str, root_path: &str) -> URR let input_bytes = v.to_string().into_bytes(); return Ok(Bytes::new(input_bytes)); } - return Err(UrEncodeError("invalid data".to_string())); + Err(UrEncodeError("invalid data".to_string())) } #[cfg(test)] mod tests { diff --git a/rust/apps/xrp/src/address/mod.rs b/rust/apps/xrp/src/address/mod.rs index ca98cfbb2..a764dc055 100644 --- a/rust/apps/xrp/src/address/mod.rs +++ b/rust/apps/xrp/src/address/mod.rs @@ -8,7 +8,7 @@ pub(crate) mod ripple_address_codec; pub(crate) mod ripple_keypair; pub fn get_address(hd_path: &str, root_x_pub: &str, root_path: &str) -> R { - let root_path = if !root_path.ends_with("/") { + let root_path = if !root_path.ends_with('/') { root_path.to_string() + "/" } else { root_path.to_string() @@ -33,7 +33,7 @@ mod tests { let root_path = "44'/144'/0'"; { let path = "44'/144'/0'/0/0"; - let address = get_address(path, &extended_pub_key, root_path).unwrap(); + let address = get_address(path, extended_pub_key, root_path).unwrap(); assert_eq!("rHsMGQEkVNJmpGWs8XUBoTBiAAbwxZN5v3".to_string(), address); } { diff --git a/rust/apps/xrp/src/address/ripple_keypair.rs b/rust/apps/xrp/src/address/ripple_keypair.rs index ee5c22979..b0f8f4f70 100644 --- a/rust/apps/xrp/src/address/ripple_keypair.rs +++ b/rust/apps/xrp/src/address/ripple_keypair.rs @@ -7,7 +7,7 @@ use cryptoxide::hashing; use cryptoxide::ripemd160::Ripemd160; pub(crate) fn sha256_digest(data: &[u8]) -> Vec { - hashing::sha256(&data).to_vec() + hashing::sha256(data).to_vec() } fn ripemd160_digest(data: &[u8]) -> [u8; 20] { diff --git a/rust/apps/xrp/src/errors.rs b/rust/apps/xrp/src/errors.rs index 3af2ecc94..af46632c3 100644 --- a/rust/apps/xrp/src/errors.rs +++ b/rust/apps/xrp/src/errors.rs @@ -1,5 +1,5 @@ use alloc::format; -use alloc::string::{String, ToString}; +use alloc::string::{String}; use core::str::Utf8Error; use keystore::errors::KeystoreError; use serde_json::Error; @@ -24,7 +24,7 @@ pub type R = Result; impl From for XRPError { fn from(value: KeystoreError) -> Self { - Self::KeystoreError(format!("{}", value.to_string())) + Self::KeystoreError(format!("{}", value)) } } diff --git a/rust/apps/xrp/src/lib.rs b/rust/apps/xrp/src/lib.rs index bc6dd52b2..866bf0276 100644 --- a/rust/apps/xrp/src/lib.rs +++ b/rust/apps/xrp/src/lib.rs @@ -14,7 +14,7 @@ use core::str::FromStr; use bitcoin::bip32::{DerivationPath, Xpub}; use bitcoin::secp256k1; use bitcoin::secp256k1::Message; -use hex; + use serde_json::{from_slice, Value}; use crate::errors::{XRPError, R}; @@ -41,7 +41,7 @@ pub fn sign_tx(raw_hex: &[u8], hd_path: &String, seed: &[u8]) -> R> { )) })?; let (_, signature) = - keystore::algorithms::secp256k1::sign_message_by_seed(&seed, hd_path, &message) + keystore::algorithms::secp256k1::sign_message_by_seed(seed, hd_path, &message) .map_err(|e| XRPError::KeystoreError(format!("sign failed {:?}", e.to_string())))?; let signed_tx_str = wrapped_tx.generate_signed_tx(&signature)?; Ok(hex::decode(signed_tx_str)?.to_vec()) @@ -53,7 +53,7 @@ pub fn parse(raw_hex: &[u8]) -> R { } pub fn get_pubkey_path(root_xpub: &str, pubkey: &str, max_i: u32) -> R { - let xpub = Xpub::from_str(&root_xpub)?; + let xpub = Xpub::from_str(root_xpub)?; let k1 = secp256k1::Secp256k1::new(); let a_xpub = xpub.derive_pub(&k1, &DerivationPath::from_str("m/0")?)?; let pubkey_arr = hex::decode(pubkey)?; @@ -65,7 +65,7 @@ pub fn get_pubkey_path(root_xpub: &str, pubkey: &str, max_i: u32) -> R { return Ok(format!("{}:m/0/{}", pubkey, i)); } } - return Err(XRPError::InvalidData("pubkey not found".to_string())); + Err(XRPError::InvalidData("pubkey not found".to_string())) } pub fn check_tx(raw: &[u8], root_xpub: &str, cached_pubkey: &str) -> R { @@ -87,7 +87,7 @@ mod tests { let raw_hex = "7B2253657175656E6365223A312C22466565223A223230222C224163636F756E74223A22724C354259534C643839757A6A3469344A3437694C51673948776D65584537654374222C2244657374696E6174696F6E223A227248666F6631784E6245744A5973584E384D55626E66396946697843455938346B66222C2244657374696E6174696F6E546167223A313730303337333336342C22416D6F756E74223A2231303030303030222C225472616E73616374696F6E54797065223A225061796D656E74222C22466C616773223A323134373438333634382C225369676E696E675075624B6579223A22303331443638424331413134324536373636423242444642303036434346453133354546324530453245393441424235434635433941423631303437373646424145227D"; let seed = hex::decode("5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4").unwrap(); let signed_tx = sign_tx( - &hex::decode(raw_hex).unwrap().as_slice(), + hex::decode(raw_hex).unwrap().as_slice(), &hd_paths, seed.as_slice(), ) diff --git a/rust/apps/xrp/src/transaction/mod.rs b/rust/apps/xrp/src/transaction/mod.rs index b0ca599a7..a607e55db 100644 --- a/rust/apps/xrp/src/transaction/mod.rs +++ b/rust/apps/xrp/src/transaction/mod.rs @@ -4,8 +4,8 @@ use alloc::string::{String, ToString}; use bitcoin::secp256k1::ecdsa::Signature; use bytes::BytesMut; use cryptoxide::hashing; -use hex; -use rippled_binary_codec; + + use rippled_binary_codec::definition_fields::DefinitionFields; use serde_json::{from_slice, to_string, Value}; @@ -20,9 +20,9 @@ impl WrappedTxData { pub fn from_raw(input: &[u8]) -> R { let definition_fields = DefinitionFields::new(); let tx_data: Value = from_slice(input)?; - let signing_pubkey = tx_data["SigningPubKey"].as_str().unwrap_or(&"").to_string(); + let signing_pubkey = tx_data["SigningPubKey"].as_str().unwrap_or("").to_string(); if let Some(tag) = tx_data["DestinationTag"].as_i64() { - if tag > 0xffffffff || tag < 0 { + if !(0..=0xffffffff).contains(&tag) { return Err(XRPError::SignFailure(format!("invalid tag {:?}", tag))); } } @@ -106,7 +106,7 @@ mod tests { fn test_generate_unsigned_tx_3() { //xrp toolkit signrequest let input = "7B225472616E73616374696F6E54797065223A225061796D656E74222C22416D6F756E74223A223130303030303030222C2244657374696E6174696F6E223A2272396A79597745503472545278474341636857724C767742754A4646573853734D4A222C22466C616773223A323134373438333634382C224163636F756E74223A227247556D6B794C627671474633687758347177474864727A4C6459325170736B756D222C22466565223A223132222C2253657175656E6365223A37393939313835372C224C6173744C656467657253657175656E6365223A38303730373430342C225369676E696E675075624B6579223A22303346354335424231443139454337313044334437464144313939414631304346384243314431313334384535423337363543304230423943304245433332383739227D"; - let v: Value = from_slice(&hex::decode(input).unwrap().as_slice()).unwrap(); + let v: Value = from_slice(hex::decode(input).unwrap().as_slice()).unwrap(); let wrapped_tx = WrappedTxData::from_raw(v.to_string().into_bytes().as_slice()).unwrap(); let expected = String::from("88dfb47b27747e247bfaeade10c1cdecc64ca2298940cfe8e1b222971be8f41e"); diff --git a/rust/apps/zcash/src/lib.rs b/rust/apps/zcash/src/lib.rs index 3859cb402..484d10870 100644 --- a/rust/apps/zcash/src/lib.rs +++ b/rust/apps/zcash/src/lib.rs @@ -8,7 +8,6 @@ pub mod pczt; use errors::{Result, ZcashError}; use alloc::{ - format, string::{String, ToString}, vec::Vec, }; @@ -39,9 +38,9 @@ pub fn check_pczt( let ufvk = UnifiedFullViewingKey::decode(params, ufvk_text) .map_err(|e| ZcashError::InvalidDataError(e.to_string()))?; let pczt = - Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt(format!("invalid pczt data")))?; + Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt("invalid pczt data".to_string()))?; let account_index = zip32::AccountId::try_from(account_index) - .map_err(|_e| ZcashError::InvalidDataError(format!("invalid account index")))?; + .map_err(|_e| ZcashError::InvalidDataError("invalid account index".to_string()))?; pczt::check::check_pczt(params, seed_fingerprint, account_index, &ufvk, &pczt) } @@ -54,13 +53,13 @@ pub fn parse_pczt( let ufvk = UnifiedFullViewingKey::decode(params, ufvk_text) .map_err(|e| ZcashError::InvalidDataError(e.to_string()))?; let pczt = - Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt(format!("invalid pczt data")))?; + Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt("invalid pczt data".to_string()))?; pczt::parse::parse_pczt(params, seed_fingerprint, &ufvk, &pczt) } pub fn sign_pczt(pczt: &[u8], seed: &[u8]) -> Result> { let pczt = - Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt(format!("invalid pczt data")))?; + Pczt::parse(pczt).map_err(|_e| ZcashError::InvalidPczt("invalid pczt data".to_string()))?; pczt::sign::sign_pczt(pczt, seed) } diff --git a/rust/apps/zcash/src/pczt/check.rs b/rust/apps/zcash/src/pczt/check.rs index 9fef31fb3..95314b9e8 100644 --- a/rust/apps/zcash/src/pczt/check.rs +++ b/rust/apps/zcash/src/pczt/check.rs @@ -26,12 +26,12 @@ pub fn check_pczt( ))?; Verifier::new(pczt.clone()) .with_orchard(|bundle| { - check_orchard(params, &seed_fingerprint, account_index, &orchard, bundle) + check_orchard(params, seed_fingerprint, account_index, orchard, bundle) .map_err(pczt::roles::verifier::OrchardError::Custom) }) .map_err(|e| ZcashError::InvalidDataError(alloc::format!("{:?}", e)))? .with_transparent(|bundle| { - check_transparent(params, seed_fingerprint, account_index, &xpub, bundle) + check_transparent(params, seed_fingerprint, account_index, xpub, bundle) .map_err(pczt::roles::verifier::TransparentError::Custom) }) .map_err(|e| ZcashError::InvalidDataError(alloc::format!("{:?}", e)))?; @@ -75,7 +75,7 @@ fn check_transparent_input( match my_derivation { None => { //not my input, pass - return Ok(()); + Ok(()) } Some((pubkey, derivation)) => { // 2: derive my pubkey @@ -83,7 +83,7 @@ fn check_transparent_input( .derive_pubkey_at_bip32_path( params, account_index, - &derivation.derivation_path(), + derivation.derivation_path(), ) .map_err(|_| { ZcashError::InvalidPczt( @@ -207,7 +207,7 @@ fn check_transparent_output( match my_derivation { None => { //not my output, pass - return Ok(()); + Ok(()) } Some((pubkey, derivation)) => { // 2: derive my pubkey @@ -215,7 +215,7 @@ fn check_transparent_output( .derive_pubkey_at_bip32_path( params, account_index, - &derivation.derivation_path(), + derivation.derivation_path(), ) .map_err(|_| { ZcashError::InvalidPczt( @@ -287,7 +287,7 @@ fn check_action( seed_fingerprint, account_index, fvk, - &action.spend(), + action.spend(), )?; check_action_output(action) } @@ -379,7 +379,7 @@ mod tests { &pczt, ); - assert_eq!(true, result.is_ok()); + assert!(result.is_ok()); } } //TODO: add test for happy path diff --git a/rust/apps/zcash/src/pczt/parse.rs b/rust/apps/zcash/src/pczt/parse.rs index a8e0457de..aaae5d996 100644 --- a/rust/apps/zcash/src/pczt/parse.rs +++ b/rust/apps/zcash/src/pczt/parse.rs @@ -29,10 +29,10 @@ use crate::errors::ZcashError; use super::structs::{ParsedFrom, ParsedOrchard, ParsedPczt, ParsedTo, ParsedTransparent}; -const ZEC_DIVIDER: u32 = 1_000_000_00; +const ZEC_DIVIDER: u32 = 100_000_000; fn format_zec_value(value: f64) -> String { - let zec_value = format!("{:.8}", value as f64 / ZEC_DIVIDER as f64); + let zec_value = format!("{:.8}", value / ZEC_DIVIDER as f64); let zec_value = zec_value .trim_end_matches('0') .trim_end_matches('.') @@ -57,7 +57,7 @@ pub fn decode_output_enc_ciphertext( if let Some(ovk) = ovk { Ok(try_output_recovery_with_ovk( &domain, - &ovk, + ovk, action, action.cv_net(), &action.output().encrypted_note().out_ciphertext, @@ -122,7 +122,7 @@ pub fn parse_pczt( //total_input_value = total_output_value + fee_value //total_output_value = total_transfer_value + total_change_value - parsed_orchard.clone().and_then(|orchard| { + parsed_orchard.clone().map(|orchard| { total_change_value += orchard .get_to() .iter() @@ -136,10 +136,10 @@ pub fn parse_pczt( .get_to() .iter() .fold(0, |acc, to| acc + to.get_amount()); - Some(()) + }); - parsed_transparent.clone().and_then(|transparent| { + parsed_transparent.clone().map(|transparent| { total_change_value += transparent .get_to() .iter() @@ -153,7 +153,7 @@ pub fn parse_pczt( .get_to() .iter() .fold(0, |acc, to| acc + to.get_amount()); - Some(()) + }); //treat all sapling output as output value since we don't support sapling decoding yet @@ -169,7 +169,7 @@ pub fn parse_pczt( let sapling_value_sum: i64 = value_balance.into(); if sapling_value_sum < 0 { //value transfered to sapling pool - total_output_value = total_output_value.saturating_add(sapling_value_sum.abs() as u64) + total_output_value = total_output_value.saturating_add(sapling_value_sum.unsigned_abs()) } else { //value transfered from sapling pool //this should not happen with Zashi. @@ -179,7 +179,7 @@ pub fn parse_pczt( let total_transfer_value = format_zec_value((total_output_value - total_change_value) as f64); let fee_value = format_zec_value((total_input_value - total_output_value) as f64); - let has_sapling = pczt.sapling().spends().len() > 0 || pczt.sapling().outputs().len() > 0; + let has_sapling = !pczt.sapling().spends().is_empty() || !pczt.sapling().outputs().is_empty(); Ok(ParsedPczt::new( parsed_transparent, @@ -197,12 +197,12 @@ fn parse_transparent( ) -> Result, ZcashError> { let mut parsed_transparent = ParsedTransparent::new(vec![], vec![]); transparent.inputs().iter().try_for_each(|input| { - let parsed_from = parse_transparent_input(params, seed_fingerprint, &input)?; + let parsed_from = parse_transparent_input(params, seed_fingerprint, input)?; parsed_transparent.add_from(parsed_from); Ok::<_, ZcashError>(()) })?; transparent.outputs().iter().try_for_each(|output| { - let parsed_to = parse_transparent_output(seed_fingerprint, &output)?; + let parsed_to = parse_transparent_output(seed_fingerprint, output)?; parsed_transparent.add_to(parsed_to); Ok::<_, ZcashError>(()) })?; @@ -247,9 +247,9 @@ fn parse_transparent_input( )) } _ => { - return Err(ZcashError::InvalidPczt( + Err(ZcashError::InvalidPczt( "transparent input script pubkey mismatch".to_string(), - )); + )) } } } @@ -311,9 +311,9 @@ fn parse_transparent_output( )) } _ => { - return Err(ZcashError::InvalidPczt( + Err(ZcashError::InvalidPczt( "transparent output script pubkey mismatch".to_string(), - )); + )) } } } @@ -331,11 +331,11 @@ fn parse_orchard( if let Some(value) = spend.value() { //only adds non-dummy spend if value.inner() != 0 { - let parsed_from = parse_orchard_spend(seed_fingerprint, &spend)?; + let parsed_from = parse_orchard_spend(seed_fingerprint, spend)?; parsed_orchard.add_from(parsed_from); } } - let parsed_to = parse_orchard_output(params, ufvk, &action)?; + let parsed_to = parse_orchard_output(params, ufvk, action)?; if !parsed_to.get_is_dummy() { parsed_orchard.add_to(parsed_to); } @@ -561,7 +561,7 @@ mod tests { use zcash_vendor::zcash_protocol::consensus::MAIN_NETWORK; extern crate std; - use std::println; + #[test] fn test_format_zec_value() { @@ -601,7 +601,7 @@ mod tests { let result = parse_pczt(&MAIN_NETWORK, &fingerprint, &unified_fvk, &pczt); assert!(result.is_ok()); let result = result.unwrap(); - assert_eq!(result.get_has_sapling(), false); + assert!(!result.get_has_sapling()); assert_eq!(result.get_total_transfer_value(), "0.001 ZEC"); assert_eq!(result.get_fee_value(), "0.00015 ZEC"); let transparent = result.get_transparent(); @@ -614,8 +614,8 @@ mod tests { "t1XTwB8P1x4YipBtLhPWS13JPDQ5RMkMA6M" ); assert_eq!(transparent.get_to()[0].get_value(), "0.001 ZEC"); - assert_eq!(transparent.get_to()[0].get_is_change(), false); - assert_eq!(transparent.get_to()[0].get_is_dummy(), false); + assert!(!transparent.get_to()[0].get_is_change()); + assert!(!transparent.get_to()[0].get_is_dummy()); assert_eq!(transparent.get_to()[0].get_amount(), 100_000); let orchard = result.get_orchard(); assert!(orchard.is_some()); @@ -623,14 +623,14 @@ mod tests { assert_eq!(orchard.get_from().len(), 1); assert_eq!(orchard.get_from()[0].get_address(), None); assert_eq!(orchard.get_from()[0].get_value(), "0.14985 ZEC"); - assert_eq!(orchard.get_from()[0].get_is_mine(), true); + assert!(orchard.get_from()[0].get_is_mine()); assert_eq!(orchard.get_from()[0].get_amount(), 14985000); assert_eq!(orchard.get_to().len(), 1); assert_eq!(orchard.get_to()[0].get_address(), ""); assert_eq!(orchard.get_to()[0].get_value(), "0.1487 ZEC"); assert_eq!(orchard.get_to()[0].get_memo(), None); - assert_eq!(orchard.get_to()[0].get_is_change(), true); - assert_eq!(orchard.get_to()[0].get_is_dummy(), false); + assert!(orchard.get_to()[0].get_is_change()); + assert!(!orchard.get_to()[0].get_is_dummy()); assert_eq!(orchard.get_to()[0].get_amount(), 14870000); } @@ -649,7 +649,7 @@ mod tests { let result = parse_pczt(&MAIN_NETWORK, &fingerprint, &unified_fvk, &pczt); assert!(result.is_ok()); let result = result.unwrap(); - assert_eq!(result.get_has_sapling(), true); + assert!(result.get_has_sapling()); assert_eq!(result.get_total_transfer_value(), "0.001 ZEC"); assert_eq!(result.get_fee_value(), "0.0002 ZEC"); } diff --git a/rust/apps/zcash/src/pczt/sign.rs b/rust/apps/zcash/src/pczt/sign.rs index 9a7778c6b..3aa17804a 100644 --- a/rust/apps/zcash/src/pczt/sign.rs +++ b/rust/apps/zcash/src/pczt/sign.rs @@ -24,7 +24,7 @@ impl<'a> PcztSigner for SeedSigner<'a> { where F: FnOnce(SignableInput) -> [u8; 32], { - let fingerprint = calculate_seed_fingerprint(&self.seed) + let fingerprint = calculate_seed_fingerprint(self.seed) .map_err(|e| ZcashError::SigningError(e.to_string()))?; let key_path = input.bip32_derivation(); @@ -32,7 +32,7 @@ impl<'a> PcztSigner for SeedSigner<'a> { let path = key_path .iter() .find_map(|(pubkey, path)| { - let path_fingerprint = path.seed_fingerprint().clone(); + let path_fingerprint = *path.seed_fingerprint(); if fingerprint == path_fingerprint { let path = { let mut ret = "m".to_string(); @@ -45,7 +45,7 @@ impl<'a> PcztSigner for SeedSigner<'a> { } ret }; - match get_public_key_by_seed(&self.seed, &path) { + match get_public_key_by_seed(self.seed, &path) { Ok(my_pubkey) if my_pubkey.serialize().to_vec().eq(pubkey) => { Some(Ok(path)) } @@ -77,7 +77,7 @@ impl<'a> PcztSigner for SeedSigner<'a> { action: &mut orchard::pczt::Action, hash: Hash, ) -> Result<(), Self::Error> { - let fingerprint = calculate_seed_fingerprint(&self.seed) + let fingerprint = calculate_seed_fingerprint(self.seed) .map_err(|e| ZcashError::SigningError(e.to_string()))?; let derivation = action.spend().zip32_derivation().as_ref().ok_or_else(|| { @@ -87,7 +87,7 @@ impl<'a> PcztSigner for SeedSigner<'a> { if &fingerprint == derivation.seed_fingerprint() { sign_message_orchard( action, - &self.seed, + self.seed, hash.as_bytes().try_into().expect("correct length"), &derivation.derivation_path().clone(), OsRng, diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index 922b3c625..ecf326adc 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -17,7 +17,7 @@ fn main() { #[cfg(feature = "debug-btc-only")] "debug-btc-only", ]; - assert!(features.len() > 0, "No build variant enabled"); + assert!(!features.is_empty(), "No build variant enabled"); assert!( features.len() == 1, "Multiple build variants enabled: {:?}", diff --git a/rust/rust_c/src/aptos/mod.rs b/rust/rust_c/src/aptos/mod.rs index d2ee3e8e9..1ac7f84e7 100644 --- a/rust/rust_c/src/aptos/mod.rs +++ b/rust/rust_c/src/aptos/mod.rs @@ -8,11 +8,11 @@ use alloc::format; use alloc::slice; use alloc::string::ToString; use alloc::vec::Vec; -use app_aptos; + use app_aptos::errors::AptosError; use app_aptos::parser::is_tx; use cty::c_char; -use hex; + use hex::FromHex; use structs::DisplayAptosTx; use ur_registry::aptos::aptos_sign_request::{AptosSignRequest, SignType}; @@ -132,7 +132,7 @@ pub extern "C" fn aptos_sign_tx( UREncodeResult::encode( data, AptosSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, @@ -148,7 +148,7 @@ pub extern "C" fn aptos_get_path(ptr: PtrUR) -> PtrString { if let Some(path) = derivation_path.get_path() { return convert_c_char(path); } - return convert_c_char("".to_string()); + convert_c_char("".to_string()) } #[no_mangle] diff --git a/rust/rust_c/src/arweave/mod.rs b/rust/rust_c/src/arweave/mod.rs index 906ae6aea..ff1fc728b 100644 --- a/rust/rust_c/src/arweave/mod.rs +++ b/rust/rust_c/src/arweave/mod.rs @@ -19,10 +19,10 @@ use app_arweave::{ generate_public_key_from_primes, generate_secret, parse, }; use cty::c_char; -use hex; + use keystore::algorithms::ed25519::slip10_ed25519::get_private_key_by_seed; use keystore::algorithms::rsa::{sign_message, SigningOption}; -use serde_json; + use serde_json::Value; use ur_registry::arweave::arweave_sign_request::{ArweaveSignRequest, SaltLen, SignType}; use ur_registry::arweave::arweave_signature::ArweaveSignature; @@ -65,7 +65,7 @@ pub extern "C" fn generate_arweave_public_key_from_primes( let p = unsafe { slice::from_raw_parts(p, p_len as usize) }; let q = unsafe { slice::from_raw_parts(q, q_len as usize) }; let public = generate_public_key_from_primes(p, q).unwrap(); - return SimpleResponse::success(Box::into_raw(Box::new(public)) as *mut u8).simple_c_ptr(); + SimpleResponse::success(Box::into_raw(Box::new(public)) as *mut u8).simple_c_ptr() } #[no_mangle] @@ -78,7 +78,7 @@ pub extern "C" fn generate_rsa_public_key( let p = unsafe { slice::from_raw_parts(p, p_len as usize) }; let q = unsafe { slice::from_raw_parts(q, q_len as usize) }; let public = generate_public_key_from_primes(p, q).unwrap(); - return SimpleResponse::success(convert_c_char(hex::encode(public))).simple_c_ptr(); + SimpleResponse::success(convert_c_char(hex::encode(public))).simple_c_ptr() } #[no_mangle] @@ -93,8 +93,8 @@ pub extern "C" fn aes256_encrypt_primes( let encrypted_data = aes256_encrypt(&key, &iv, data).unwrap(); let mut result_bytes: [u8; 528] = [0; 528]; result_bytes.copy_from_slice(&encrypted_data); - return SimpleResponse::success(Box::into_raw(Box::new(result_bytes)) as *mut u8) - .simple_c_ptr(); + SimpleResponse::success(Box::into_raw(Box::new(result_bytes)) as *mut u8) + .simple_c_ptr() } #[no_mangle] @@ -124,14 +124,14 @@ pub extern "C" fn aes256_decrypt_primes( pub extern "C" fn arweave_get_address(xpub: PtrString) -> *mut SimpleResponse { let xpub = recover_c_char(xpub); let address = app_arweave::generate_address(hex::decode(xpub).unwrap()).unwrap(); - return SimpleResponse::success(convert_c_char(address)).simple_c_ptr(); + SimpleResponse::success(convert_c_char(address)).simple_c_ptr() } #[no_mangle] pub extern "C" fn fix_arweave_address(address: PtrString) -> *mut SimpleResponse { let address = recover_c_char(address); let fixed_address = fix_address(&address); - return SimpleResponse::success(convert_c_char(fixed_address)).simple_c_ptr(); + SimpleResponse::success(convert_c_char(fixed_address)).simple_c_ptr() } #[no_mangle] @@ -154,7 +154,7 @@ pub extern "C" fn ar_check_tx( return TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr(); } } - return TransactionCheckResult::from(RustCError::InvalidMasterFingerprint).c_ptr(); + TransactionCheckResult::from(RustCError::InvalidMasterFingerprint).c_ptr() } #[no_mangle] @@ -235,7 +235,7 @@ fn parse_sign_data(ptr: PtrUR) -> Result, ArweaveError> { Ok(data_item.deep_hash()?) } SignType::Message => { - return Ok(sign_data); + Ok(sign_data) } } } @@ -282,7 +282,7 @@ pub extern "C" fn ar_sign_tx( UREncodeResult::encode( data, ArweaveSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, diff --git a/rust/rust_c/src/bitcoin/msg.rs b/rust/rust_c/src/bitcoin/msg.rs index 547cf0bfc..9fdb538ae 100644 --- a/rust/rust_c/src/bitcoin/msg.rs +++ b/rust/rust_c/src/bitcoin/msg.rs @@ -73,11 +73,10 @@ pub extern "C" fn btc_parse_msg( .iter() .find(|key| { let xpub_path = recover_c_char(key.path); - return path.clone().starts_with(&xpub_path); + path.clone().starts_with(&xpub_path) }) .map(|v| recover_c_char(v.xpub)) - .map(|xpub| app_bitcoin::get_address(path, &xpub).ok()) - .flatten(); + .and_then(|xpub| app_bitcoin::get_address(path, &xpub).ok()); let msg = req.get_sign_data(); if let Ok(msg_uft8) = String::from_utf8(msg.to_vec()) { let display_msg = DisplayBtcMsg { @@ -133,7 +132,7 @@ pub extern "C" fn btc_sign_msg( return UREncodeResult::encode( data, BtcSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(); } @@ -165,7 +164,7 @@ pub extern "C" fn parse_seed_signer_message( .iter() .find(|key| { let xpub_path = recover_c_char(key.path); - return path.clone().starts_with(&xpub_path); + path.clone().starts_with(&xpub_path) }) .map(|v| recover_c_char(v.xpub)) .map(|xpub| app_bitcoin::get_address(path, &xpub)); @@ -204,9 +203,9 @@ pub extern "C" fn sign_seed_signer_message( let sig = app_bitcoin::sign_msg(&message, seed, &path); match sig { Ok(sig) => { - return UREncodeResult::text(base64::encode_config(&sig, base64::STANDARD)).c_ptr() + UREncodeResult::text(base64::encode_config(&sig, base64::STANDARD)).c_ptr() } - Err(e) => return UREncodeResult::from(e).c_ptr(), + Err(e) => UREncodeResult::from(e).c_ptr(), } } } diff --git a/rust/rust_c/src/bitcoin/multi_sig/mod.rs b/rust/rust_c/src/bitcoin/multi_sig/mod.rs index e29a6de58..e1648ebbb 100644 --- a/rust/rust_c/src/bitcoin/multi_sig/mod.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/mod.rs @@ -89,7 +89,7 @@ pub extern "C" fn export_multi_sig_xpub_by_ur( Ok(data) => UREncodeResult::encode( data, CryptoAccount::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -115,7 +115,7 @@ pub extern "C" fn export_multi_sig_wallet_by_ur_test( unsafe { let master_fingerprint = slice::from_raw_parts(master_fingerprint, length as usize); let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -138,7 +138,7 @@ pub extern "C" fn export_multi_sig_wallet_by_ur_test( UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, @@ -197,7 +197,7 @@ pub extern "C" fn export_multi_sig_wallet_by_ur( unsafe { let master_fingerprint = slice::from_raw_parts(master_fingerprint, length as usize); let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -225,7 +225,7 @@ pub extern "C" fn export_multi_sig_wallet_by_ur( UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, @@ -246,7 +246,7 @@ pub extern "C" fn import_multi_sig_wallet_by_ur( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -278,7 +278,7 @@ pub extern "C" fn import_multi_sig_wallet_by_file( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -311,7 +311,7 @@ pub extern "C" fn generate_address_for_multisig_wallet_config( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -371,7 +371,7 @@ pub extern "C" fn parse_and_verify_multisig_config( let seed = unsafe { core::slice::from_raw_parts(seed, seed_len as usize) }; let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { diff --git a/rust/rust_c/src/bitcoin/multi_sig/structs.rs b/rust/rust_c/src/bitcoin/multi_sig/structs.rs index 444d3f3f6..2932ea44f 100644 --- a/rust/rust_c/src/bitcoin/multi_sig/structs.rs +++ b/rust/rust_c/src/bitcoin/multi_sig/structs.rs @@ -18,18 +18,18 @@ pub enum NetworkType { TestNet, } -impl Into for NetworkType { - fn into(self) -> Network { - match self { +impl From for Network { + fn from(val: NetworkType) -> Self { + match val { NetworkType::MainNet => Network::MainNet, NetworkType::TestNet => Network::TestNet, } } } -impl Into for &NetworkType { - fn into(self) -> Network { - match self { +impl From<&NetworkType> for Network { + fn from(val: &NetworkType) -> Self { + match val { NetworkType::MainNet => Network::MainNet, NetworkType::TestNet => Network::TestNet, } @@ -46,9 +46,9 @@ pub enum MultiSigFormatType { P2wshTest, } -impl Into for MultiSigFormatType { - fn into(self) -> MultiSigType { - match self { +impl From for MultiSigType { + fn from(val: MultiSigFormatType) -> Self { + match val { MultiSigFormatType::P2sh => MultiSigType::P2sh, MultiSigFormatType::P2wshP2sh => MultiSigType::P2wshP2sh, MultiSigFormatType::P2wsh => MultiSigType::P2wsh, @@ -59,9 +59,9 @@ impl Into for MultiSigFormatType { } } -impl Into for &MultiSigFormatType { - fn into(self) -> MultiSigType { - match self { +impl From<&MultiSigFormatType> for MultiSigType { + fn from(val: &MultiSigFormatType) -> Self { + match val { MultiSigFormatType::P2sh => MultiSigType::P2sh, MultiSigFormatType::P2wshP2sh => MultiSigType::P2wshP2sh, MultiSigFormatType::P2wsh => MultiSigType::P2wsh, @@ -72,9 +72,9 @@ impl Into for &MultiSigFormatType { } } -impl Into for MultiSigFormatType { - fn into(self) -> MultiSigFormat { - match self { +impl From for MultiSigFormat { + fn from(val: MultiSigFormatType) -> Self { + match val { MultiSigFormatType::P2sh => MultiSigFormat::P2sh, MultiSigFormatType::P2wshP2sh => MultiSigFormat::P2wshP2sh, MultiSigFormatType::P2wsh => MultiSigFormat::P2wsh, @@ -85,9 +85,9 @@ impl Into for MultiSigFormatType { } } -impl Into for &MultiSigFormatType { - fn into(self) -> MultiSigFormat { - match self { +impl From<&MultiSigFormatType> for MultiSigFormat { + fn from(val: &MultiSigFormatType) -> Self { + match val { MultiSigFormatType::P2sh => MultiSigFormat::P2sh, MultiSigFormatType::P2wshP2sh => MultiSigFormat::P2wshP2sh, MultiSigFormatType::P2wsh => MultiSigFormat::P2wsh, @@ -115,12 +115,12 @@ impl From for MultiSigXPubInfoItem { } } -impl Into for &MultiSigXPubInfoItem { - fn into(self) -> MultiSigXPubInfo { +impl From<&MultiSigXPubInfoItem> for MultiSigXPubInfo { + fn from(val: &MultiSigXPubInfoItem) -> Self { MultiSigXPubInfo { - path: recover_c_char(self.path), - xfp: recover_c_char(self.xfp), - xpub: recover_c_char(self.xpub), + path: recover_c_char(val.path), + xfp: recover_c_char(val.xfp), + xpub: recover_c_char(val.xpub), } } } @@ -135,13 +135,13 @@ impl From for MultiSigXPubInfoItem { } } -impl Into for &MultiSigXPubInfoItem { - fn into(self) -> BsmsWallet { +impl From<&MultiSigXPubInfoItem> for BsmsWallet { + fn from(val: &MultiSigXPubInfoItem) -> Self { BsmsWallet { bsms_version: "BSMS 1.0".to_string(), - derivation_path: recover_c_char(self.path), - xfp: recover_c_char(self.xfp), - extended_pubkey: recover_c_char(self.xpub), + derivation_path: recover_c_char(val.path), + xfp: recover_c_char(val.xfp), + extended_pubkey: recover_c_char(val.xpub), } } } @@ -172,11 +172,11 @@ impl From<&app_bitcoin::multi_sig::wallet::MultiSigXPubItem> for MultiSigXPubIte } } -impl Into for &MultiSigXPubItem { - fn into(self) -> app_bitcoin::multi_sig::wallet::MultiSigXPubItem { +impl From<&MultiSigXPubItem> for app_bitcoin::multi_sig::wallet::MultiSigXPubItem { + fn from(val: &MultiSigXPubItem) -> Self { app_bitcoin::multi_sig::wallet::MultiSigXPubItem { - xfp: recover_c_char(self.xfp), - xpub: recover_c_char(self.xpub), + xfp: recover_c_char(val.xfp), + xpub: recover_c_char(val.xpub), } } } @@ -228,7 +228,7 @@ impl From for MultiSigWallet { .xpub_items .clone() .iter() - .map(|v| MultiSigXPubItem::from(v)) + .map(MultiSigXPubItem::from) .collect::>(), ) .c_ptr(), @@ -239,18 +239,18 @@ impl From for MultiSigWallet { } } -impl Into for &mut MultiSigWallet { - fn into(self) -> MultiSigWalletConfig { +impl From<&mut MultiSigWallet> for MultiSigWalletConfig { + fn from(val: &mut MultiSigWallet) -> Self { MultiSigWalletConfig { - creator: recover_c_char(self.creator), - name: recover_c_char(self.name), - threshold: self.threshold, - total: self.total, + creator: recover_c_char(val.creator), + name: recover_c_char(val.name), + threshold: val.threshold, + total: val.total, derivations: { let rebuilt = unsafe { - let ptr = (*self.derivations).data; - let size = (*self.derivations).size; - let cap = (*self.derivations).cap; + let ptr = (*val.derivations).data; + let size = (*val.derivations).size; + let cap = (*val.derivations).cap; let ptr = ptr as PtrT; Vec::from_raw_parts(ptr, size, cap) @@ -261,22 +261,22 @@ impl Into for &mut MultiSigWallet { .map(|v| recover_c_char(*v)) .collect::>() }, - format: recover_c_char(self.format), + format: recover_c_char(val.format), xpub_items: { let rebuilt = unsafe { - let ptr = (*self.derivations).data; - let size = (*self.derivations).size; - let cap = (*self.derivations).cap; + let ptr = (*val.derivations).data; + let size = (*val.derivations).size; + let cap = (*val.derivations).cap; let ptr = ptr as PtrT; Vec::from_raw_parts(ptr, size, cap) }; rebuilt.iter().map(|v| v.into()).collect::>() }, - verify_code: recover_c_char(self.verify_code), - config_text: recover_c_char(self.config_text), - network: if self.network == 0 { + verify_code: recover_c_char(val.verify_code), + config_text: recover_c_char(val.config_text), + network: if val.network == 0 { Network::MainNet } else { Network::TestNet diff --git a/rust/rust_c/src/bitcoin/psbt.rs b/rust/rust_c/src/bitcoin/psbt.rs index 41abaaa7b..f716da368 100644 --- a/rust/rust_c/src/bitcoin/psbt.rs +++ b/rust/rust_c/src/bitcoin/psbt.rs @@ -66,7 +66,7 @@ fn btc_sign_psbt_dynamic( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -87,7 +87,7 @@ fn btc_sign_psbt_dynamic( Ok(data) => UREncodeResult::encode( data, CryptoPSBT::get_registry_type().get_type(), - fragment_length.clone(), + fragment_length, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -110,7 +110,7 @@ pub extern "C" fn btc_sign_psbt( seed_len, master_fingerprint, master_fingerprint_len, - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) } @@ -128,7 +128,7 @@ pub extern "C" fn btc_sign_psbt_unlimited( seed_len, master_fingerprint, master_fingerprint_len, - FRAGMENT_UNLIMITED_LENGTH.clone(), + FRAGMENT_UNLIMITED_LENGTH, ) } @@ -152,7 +152,7 @@ pub extern "C" fn btc_sign_multisig_psbt( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -189,7 +189,7 @@ pub extern "C" fn btc_sign_multisig_psbt( ur_result: UREncodeResult::encode( data, CryptoPSBT::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), sign_status: convert_c_char(sign_state.sign_status.unwrap_or("".to_string())), @@ -231,7 +231,7 @@ pub extern "C" fn btc_export_multisig_psbt(ptr: PtrUR) -> *mut MultisigSignResul ur_result: UREncodeResult::encode( psbt, CryptoPSBT::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), sign_status: convert_c_char(state.sign_status.unwrap_or("".to_string())), @@ -268,7 +268,7 @@ pub extern "C" fn btc_export_multisig_psbt_bytes( ur_result: UREncodeResult::encode( psbt, CryptoPSBT::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), sign_status: convert_c_char(state.sign_status.unwrap_or("".to_string())), @@ -409,7 +409,7 @@ pub extern "C" fn btc_sign_multisig_psbt_bytes( } let master_fingerprint = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; let master_fingerprint = match bitcoin::bip32::Fingerprint::from_str( - hex::encode(master_fingerprint.to_vec()).as_str(), + hex::encode(master_fingerprint).as_str(), ) .map_err(|_e| RustCError::InvalidMasterFingerprint) { @@ -428,7 +428,8 @@ pub extern "C" fn btc_sign_multisig_psbt_bytes( let psbt = unsafe { let psbt = core::slice::from_raw_parts(psbt_bytes, psbt_bytes_length as usize); - let psbt = match get_psbt_bytes(psbt) { + + match get_psbt_bytes(psbt) { Ok(psbt) => psbt, Err(e) => { return MultisigSignResult { @@ -440,8 +441,7 @@ pub extern "C" fn btc_sign_multisig_psbt_bytes( } .c_ptr() } - }; - psbt + } }; let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; @@ -461,7 +461,7 @@ pub extern "C" fn btc_sign_multisig_psbt_bytes( ur_result: UREncodeResult::encode( data, CryptoPSBT::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), sign_status: convert_c_char(sign_state.sign_status.unwrap_or("".to_string())), @@ -498,7 +498,7 @@ fn parse_psbt( multisig_wallet_config: Option, ) -> *mut TransactionParseResult { let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -510,7 +510,7 @@ fn parse_psbt( Xpub::from_str(xpub.as_str()).map_err(|_e| RustCError::InvalidXPub); let derivation_path = DerivationPath::from_str(path.as_str()).map_err(|_e| RustCError::InvalidHDPath); - match extended_public_key.and_then(|k| derivation_path.and_then(|p| Ok((k, p)))) { + match extended_public_key.and_then(|k| derivation_path.map(|p| (k, p))) { Ok((k, p)) => { keys.insert(p, k); } @@ -548,7 +548,7 @@ fn check_psbt( multisig_wallet_config: Option, ) -> PtrT { let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -560,7 +560,7 @@ fn check_psbt( Xpub::from_str(xpub.as_str()).map_err(|_e| RustCError::InvalidXPub); let derivation_path = DerivationPath::from_str(path.as_str()).map_err(|_e| RustCError::InvalidHDPath); - match extended_public_key.and_then(|k| derivation_path.and_then(|p| Ok((k, p)))) { + match extended_public_key.and_then(|k| derivation_path.map(|p| (k, p))) { Ok((k, p)) => { keys.insert(p, k); } diff --git a/rust/rust_c/src/bitcoin/structs.rs b/rust/rust_c/src/bitcoin/structs.rs index b99c31bf8..1bc314d70 100644 --- a/rust/rust_c/src/bitcoin/structs.rs +++ b/rust/rust_c/src/bitcoin/structs.rs @@ -203,11 +203,11 @@ impl From for DisplayTxDetailInput { has_address: value.address.is_some(), address: value .address - .map(|v| convert_c_char(v)) + .map(convert_c_char) .unwrap_or(null_mut()), amount: convert_c_char(value.amount), is_mine: value.path.is_some(), - path: value.path.map(|v| convert_c_char(v)).unwrap_or(null_mut()), + path: value.path.map(convert_c_char).unwrap_or(null_mut()), is_external: value.is_external, } } @@ -219,7 +219,7 @@ impl From for DisplayTxDetailOutput { address: convert_c_char(value.address), amount: convert_c_char(value.amount), is_mine: value.path.is_some(), - path: value.path.map(|v| convert_c_char(v)).unwrap_or(null_mut()), + path: value.path.map(convert_c_char).unwrap_or(null_mut()), is_external: value.is_external, } } diff --git a/rust/rust_c/src/cardano/mod.rs b/rust/rust_c/src/cardano/mod.rs index 7d1058ad5..dc5a1e9e0 100644 --- a/rust/rust_c/src/cardano/mod.rs +++ b/rust/rust_c/src/cardano/mod.rs @@ -14,7 +14,7 @@ use bitcoin::bip32::DerivationPath; use core::str::FromStr; use cty::c_char; use ed25519_bip32_core::XPrv; -use hex; + use structs::DisplayCardanoSignTxHash; use ur_registry::cardano::cardano_catalyst_signature::CardanoCatalystSignature; @@ -109,7 +109,7 @@ pub extern "C" fn cardano_get_catalyst_root_index(ptr: PtrUR) -> Ptr SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid path"))) + None => SimpleResponse::from(CardanoError::InvalidTransaction("invalid path".to_string())) .simple_c_ptr(), } } @@ -123,7 +123,7 @@ pub extern "C" fn cardano_get_sign_data_root_index(ptr: PtrUR) -> Ptr SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid path"))) + None => SimpleResponse::from(CardanoError::InvalidTransaction("invalid path".to_string())) .simple_c_ptr(), } } @@ -187,7 +187,7 @@ pub extern "C" fn cardano_check_tx( let cardano_sign_reqeust = extract_ptr_with_type!(ptr, CardanoSignRequest); let tx_hex = cardano_sign_reqeust.get_sign_data(); let parse_context = - prepare_parse_context(&cardano_sign_reqeust, master_fingerprint, cardano_xpub); + prepare_parse_context(cardano_sign_reqeust, master_fingerprint, cardano_xpub); match parse_context { Ok(parse_context) => match app_cardano::transaction::check_tx(tx_hex, parse_context) { Ok(_) => TransactionCheckResult::new().c_ptr(), @@ -237,7 +237,7 @@ pub extern "C" fn cardano_parse_sign_tx_hash( #[no_mangle] pub extern "C" fn cardano_get_path(ptr: PtrUR) -> Ptr> { let cardano_sign_reqeust = extract_ptr_with_type!(ptr, CardanoSignRequest); - match cardano_sign_reqeust.get_cert_keys().get(0) { + match cardano_sign_reqeust.get_cert_keys().first() { Some(_data) => match _data.get_key_path().get_path() { Some(_path) => { if let Some(path) = parse_cardano_root_path(_path) { @@ -248,19 +248,19 @@ pub extern "C" fn cardano_get_path(ptr: PtrUR) -> Ptr> { }, None => {} }; - match cardano_sign_reqeust.get_utxos().get(0) { + match cardano_sign_reqeust.get_utxos().first() { Some(_data) => match _data.get_key_path().get_path() { Some(_path) => { if let Some(path) = parse_cardano_root_path(_path) { return SimpleResponse::success(convert_c_char(path)).simple_c_ptr(); } - SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid utxo"))) + SimpleResponse::from(CardanoError::InvalidTransaction("invalid utxo".to_string())) .simple_c_ptr() } - None => SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid utxo"))) + None => SimpleResponse::from(CardanoError::InvalidTransaction("invalid utxo".to_string())) .simple_c_ptr(), }, - None => SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid utxo"))) + None => SimpleResponse::from(CardanoError::InvalidTransaction("invalid utxo".to_string())) .simple_c_ptr(), } } @@ -269,7 +269,7 @@ fn parse_cardano_root_path(path: String) -> Option { let root_path = "1852'/1815'/"; match path.strip_prefix(root_path) { Some(path) => { - if let Some(index) = path.find("/") { + if let Some(index) = path.find('/') { let sub_path = &path[..index]; Some(format!("{}{}", root_path, sub_path)) } else { @@ -319,7 +319,7 @@ pub extern "C" fn cardano_parse_tx( let cardano_sign_reqeust = extract_ptr_with_type!(ptr, CardanoSignRequest); let tx_hex = cardano_sign_reqeust.get_sign_data(); let parse_context = - prepare_parse_context(&cardano_sign_reqeust, master_fingerprint, cardano_xpub); + prepare_parse_context(cardano_sign_reqeust, master_fingerprint, cardano_xpub); match parse_context { Ok(parse_context) => match app_cardano::transaction::parse_tx(tx_hex, parse_context) { Ok(v) => TransactionParseResult::success(DisplayCardanoTx::from(v).c_ptr()).c_ptr(), @@ -365,7 +365,9 @@ pub extern "C" fn cardano_sign_catalyst( fn cardano_sign_catalyst_by_icarus(ptr: PtrUR, icarus_master_key: XPrv) -> PtrT { let cardano_catalyst_request = extract_ptr_with_type!(ptr, CardanoCatalystVotingRegistrationRequest); - let result = governance::sign( + + + governance::sign( &cardano_catalyst_request .get_derivation_path() .get_path() @@ -390,15 +392,13 @@ fn cardano_sign_catalyst_by_icarus(ptr: PtrUR, icarus_master_key: XPrv) -> PtrT< UREncodeResult::encode( data, CARDANO_CATALYST_VOTING_REGISTRATION_SIGNATURE.get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, ) }, - ); - - return result; + ) } #[no_mangle] @@ -463,7 +463,7 @@ fn cardano_sign_sign_data_by_icarus(ptr: PtrUR, icarus_master_key: XPrv) -> PtrT UREncodeResult::encode( data, CARDANO_SIGN_DATA_SIGNATURE.get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, @@ -471,7 +471,7 @@ fn cardano_sign_sign_data_by_icarus(ptr: PtrUR, icarus_master_key: XPrv) -> PtrT }, ); - return result; + result } #[no_mangle] @@ -531,7 +531,7 @@ fn cardano_sign_tx_hash_by_icarus(ptr: PtrUR, icarus_master_key: XPrv) -> PtrT UREncodeResult::encode( v, CARDANO_SIGNATURE.get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -547,7 +547,7 @@ fn cardano_sign_tx_by_icarus( let cardano_sign_reqeust = extract_ptr_with_type!(ptr, CardanoSignRequest); let tx_hex = cardano_sign_reqeust.get_sign_data(); let parse_context = - prepare_parse_context(&cardano_sign_reqeust, master_fingerprint, cardano_xpub); + prepare_parse_context(cardano_sign_reqeust, master_fingerprint, cardano_xpub); match parse_context { Ok(parse_context) => { @@ -560,7 +560,7 @@ fn cardano_sign_tx_by_icarus( Ok(data) => UREncodeResult::encode( data, CARDANO_SIGNATURE.get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -632,7 +632,7 @@ fn get_cardano_derivation_path(path: CryptoKeyPath) -> R { let components = path.get_components(); let mut new_components = Vec::new(); for i in 3..components.len() { - new_components.push(components[i].clone()); + new_components.push(components[i]); } Ok(CryptoKeyPath::new( new_components, @@ -661,7 +661,7 @@ mod tests { None, ); let result = get_cardano_derivation_path(path); - assert_eq!(result.is_ok(), true); + assert!(result.is_ok()); assert_eq!(result.unwrap().get_path().unwrap(), "2/0"); } diff --git a/rust/rust_c/src/cardano/structs.rs b/rust/rust_c/src/cardano/structs.rs index 35b7f85c2..e971623b0 100644 --- a/rust/rust_c/src/cardano/structs.rs +++ b/rust/rust_c/src/cardano/structs.rs @@ -263,7 +263,7 @@ impl From for DisplayCardanoTx { .c_ptr(), auxiliary_data: value .get_auxiliary_data() - .map(|v| convert_c_char(v)) + .map(convert_c_char) .unwrap_or(null_mut()), voting_procedures: VecFFI::from( value diff --git a/rust/rust_c/src/common/free.rs b/rust/rust_c/src/common/free.rs index a4a2b9fea..b9bd3888d 100644 --- a/rust/rust_c/src/common/free.rs +++ b/rust/rust_c/src/common/free.rs @@ -57,7 +57,7 @@ macro_rules! free_ptr_with_type { ($x: expr, $name: ident) => { if (!$x.is_null()) { unsafe { - let x = crate::extract_ptr_with_type!($x, $name); + let x = $crate::extract_ptr_with_type!($x, $name); let _b = alloc::boxed::Box::from_raw(x); // drop(b); } diff --git a/rust/rust_c/src/common/keystone.rs b/rust/rust_c/src/common/keystone.rs index 9f2deba7a..e862aaafd 100644 --- a/rust/rust_c/src/common/keystone.rs +++ b/rust/rust_c/src/common/keystone.rs @@ -38,8 +38,7 @@ pub fn build_payload(ptr: PtrUR, ur_type: QRCodeType) -> Result return Err(KeystoneError::ProtobufError("invalid ur type".to_string())), }; unzip(bytes) - .and_then(|unzip_data| parse_protobuf(unzip_data)) - .and_then(|base: Base| Ok(base.data)) + .and_then(parse_protobuf).map(|base: Base| base.data) .map_err(|e| KeystoneError::ProtobufError(e.to_string()))? .ok_or(KeystoneError::ProtobufError("empty payload".to_string())) } @@ -53,8 +52,8 @@ pub fn build_parse_context( let xpub_str = convert_version(x_pub.as_str(), &Version::Xpub) .map_err(|e| KeystoneError::InvalidParseContext(e.to_string()))?; let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) - .map_err(|_| KeystoneError::InvalidParseContext(format!("invalid mfp")))?; + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) + .map_err(|_| KeystoneError::InvalidParseContext("invalid mfp".to_string()))?; let extended_pubkey = bitcoin::bip32::Xpub::from_str(&xpub_str).map_err(|_| { KeystoneError::InvalidParseContext(format!("invalid extended pub key {}", x_pub)) })?; @@ -119,9 +118,9 @@ pub fn build_check_result( }) } _ => { - return Err(KeystoneError::ProtobufError( + Err(KeystoneError::ProtobufError( "empty payload content".to_string(), - )); + )) } } } @@ -165,9 +164,9 @@ pub fn build_sign_result( zip(&data).map_err(|_| KeystoneError::ProtobufError("zip bytes failed".to_string())) } _ => { - return Err(KeystoneError::ProtobufError( + Err(KeystoneError::ProtobufError( "empty payload content".to_string(), - )); + )) } } } @@ -211,7 +210,7 @@ pub fn sign( Ok(data) => UREncodeResult::encode( data, KeystoneSignResult::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -227,7 +226,7 @@ pub fn sign( Ok(data) => UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/common/macros.rs b/rust/rust_c/src/common/macros.rs index 01b62cc4a..629729aec 100644 --- a/rust/rust_c/src/common/macros.rs +++ b/rust/rust_c/src/common/macros.rs @@ -482,7 +482,7 @@ macro_rules! make_free_method { app_utils::paste::item! { #[no_mangle] pub extern "C" fn [](ptr: PtrT<$t>) { - crate::check_and_free_ptr!(ptr) + $crate::check_and_free_ptr!(ptr) } } }; @@ -490,7 +490,7 @@ macro_rules! make_free_method { app_utils::paste::item! { #[no_mangle] pub extern "C" fn [](ptr: PtrT<$t1<$t2>>) { - crate::check_and_free_ptr!(ptr) + $crate::check_and_free_ptr!(ptr) } } }; diff --git a/rust/rust_c/src/common/mod.rs b/rust/rust_c/src/common/mod.rs index 4f263908e..b60681dae 100644 --- a/rust/rust_c/src/common/mod.rs +++ b/rust/rust_c/src/common/mod.rs @@ -9,7 +9,7 @@ use keystore::algorithms::ed25519::slip10_ed25519::get_private_key_by_seed; use bitcoin::hex::Case; use bitcoin_hashes::hex::DisplayHex; use cty::c_char; -use hex; + use hex::ToHex; use errors::ErrorCodes; @@ -97,7 +97,7 @@ pub extern "C" fn get_ed25519_pubkey_by_seed( let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; let path = recover_c_char(path); let extended_key = - keystore::algorithms::ed25519::slip10_ed25519::get_public_key_by_seed(&seed, &path); + keystore::algorithms::ed25519::slip10_ed25519::get_public_key_by_seed(seed, &path); match extended_key { Ok(result) => SimpleResponse::success(convert_c_char(hex::encode(result))).simple_c_ptr(), Err(e) => SimpleResponse::from(e).simple_c_ptr(), @@ -128,7 +128,7 @@ pub extern "C" fn get_bip32_ed25519_extended_pubkey( let passphrase = recover_c_char(passphrase); let extended_key = keystore::algorithms::ed25519::bip32_ed25519::get_extended_public_key_by_entropy( - &entropy, + entropy, passphrase.as_bytes(), &path, ); @@ -165,7 +165,7 @@ pub extern "C" fn get_icarus_master_key( let entropy = unsafe { slice::from_raw_parts(entropy, entropy_len as usize) }; let passphrase = recover_c_char(passphrase); let master_key = keystore::algorithms::ed25519::bip32_ed25519::get_icarus_master_key_by_entropy( - &entropy, + entropy, passphrase.as_bytes(), ); match master_key { @@ -274,7 +274,7 @@ pub extern "C" fn pbkdf2_rust( ) -> *mut SimpleResponse { let password_bytes = unsafe { slice::from_raw_parts(password, 32) }; let salt_bytes = unsafe { slice::from_raw_parts(salt, 32) }; - let output = keystore::algorithms::crypto::hkdf(&password_bytes, &salt_bytes, iterations); + let output = keystore::algorithms::crypto::hkdf(password_bytes, salt_bytes, iterations); SimpleResponse::success(Box::into_raw(Box::new(output)) as *mut u8).simple_c_ptr() } @@ -286,7 +286,7 @@ pub extern "C" fn pbkdf2_rust_64( ) -> *mut SimpleResponse { let password_bytes = unsafe { slice::from_raw_parts(password, 64) }; let salt_bytes = unsafe { slice::from_raw_parts(salt, 64) }; - let output = keystore::algorithms::crypto::hkdf64(&password_bytes, &salt_bytes, iterations); + let output = keystore::algorithms::crypto::hkdf64(password_bytes, salt_bytes, iterations); SimpleResponse::success(Box::into_raw(Box::new(output)) as *mut u8).simple_c_ptr() } diff --git a/rust/rust_c/src/common/qrcode/mod.rs b/rust/rust_c/src/common/qrcode/mod.rs index 4a132c8ca..2c31665d7 100644 --- a/rust/rust_c/src/common/qrcode/mod.rs +++ b/rust/rust_c/src/common/qrcode/mod.rs @@ -30,7 +30,7 @@ pub extern "C" fn infer_qrcode_type(qrcode: PtrString) -> QRProtocol { pub extern "C" fn parse_qrcode_text(qr: PtrString) -> Ptr { let value = recover_c_char(qr); if value.to_lowercase().starts_with("signmessage") { - let mut headers_and_message = value.split(":"); + let mut headers_and_message = value.split(':'); let headers = headers_and_message.next(); let message = headers_and_message.next(); if let (Some(headers), Some(message)) = (headers, message) { @@ -42,7 +42,7 @@ pub extern "C" fn parse_qrcode_text(qr: PtrString) -> Ptr { match encode { "ascii" => { let data = SeedSignerMessage::new( - path.replace("h", "'").to_string(), + path.replace('h', "'").to_string(), message.to_string(), MessageEncoding::ASCII, ); @@ -63,10 +63,8 @@ pub extern "C" fn parse_qrcode_text(qr: PtrString) -> Ptr { } } } - return URParseResult::from(RustCError::UnsupportedTransaction(format!( - "Invalid seed signer message format" - ))) + return URParseResult::from(RustCError::UnsupportedTransaction("Invalid seed signer message format".to_string())) .c_ptr(); } - URParseResult::from(RustCError::UnsupportedTransaction(format!("plain text"))).c_ptr() + URParseResult::from(RustCError::UnsupportedTransaction("plain text".to_string())).c_ptr() } diff --git a/rust/rust_c/src/common/ur.rs b/rust/rust_c/src/common/ur.rs index 280a5c7ac..7022f89d3 100644 --- a/rust/rust_c/src/common/ur.rs +++ b/rust/rust_c/src/common/ur.rs @@ -127,7 +127,7 @@ impl UREncodeResult { match result.encoder { Some(v) => Self::multi(result.data.to_uppercase(), v), None => { - Self::from(RustCError::UnexpectedError(format!("ur encoder is none"))) + Self::from(RustCError::UnexpectedError("ur encoder is none".to_string())) } } } else { @@ -611,10 +611,10 @@ fn _decode_ur, Error = URError> + InferViewTyp } else { match parse_result.data { Some(data) => { - return match InferViewType::infer(&data) { + match InferViewType::infer(&data) { Ok(t) => URParseResult::single(t, u, data), Err(e) => URParseResult::from(e), - }; + } } None => URParseResult::from(RustCError::UnexpectedError( "ur data is none".to_string(), @@ -623,7 +623,7 @@ fn _decode_ur, Error = URError> + InferViewTyp } } Err(e) => { - return URParseResult::from(e); + URParseResult::from(e) } } } @@ -700,10 +700,10 @@ fn _receive_ur, Error = URError> + InferViewTy if parse_result.is_complete { match parse_result.data { Some(data) => { - return match InferViewType::infer(&data) { + match InferViewType::infer(&data) { Ok(t) => URParseMultiResult::success(t, u, data), Err(e) => URParseMultiResult::from(e), - }; + } } None => URParseMultiResult::from(RustCError::UnexpectedError( "UR parsed completely but data is none".to_string(), @@ -714,7 +714,7 @@ fn _receive_ur, Error = URError> + InferViewTy } } Err(e) => { - return URParseMultiResult::from(e); + URParseMultiResult::from(e) } } } diff --git a/rust/rust_c/src/common/ur_ext.rs b/rust/rust_c/src/common/ur_ext.rs index 409766911..11a63eff4 100644 --- a/rust/rust_c/src/common/ur_ext.rs +++ b/rust/rust_c/src/common/ur_ext.rs @@ -232,7 +232,7 @@ impl InferViewType for Bytes { Ok(_v) => { if let Some(_type) = _v.pointer("/data/type") { let contract_name: String = from_value(_type.clone()).map_err(|e| { - URError::UrDecodeError(format!("invalid data, {}", e.to_string())) + URError::UrDecodeError(format!("invalid data, {}", e)) })?; if contract_name.eq("webAuth") { return Ok(ViewType::WebAuthResult); diff --git a/rust/rust_c/src/common/web_auth.rs b/rust/rust_c/src/common/web_auth.rs index f42b4a780..3a752f1a7 100644 --- a/rust/rust_c/src/common/web_auth.rs +++ b/rust/rust_c/src/common/web_auth.rs @@ -44,21 +44,21 @@ pub extern "C" fn calculate_auth_code( match _calculate_auth_code(&_value, rsa_key_n, rsa_key_d) { Ok(_result) => Ok(_result), Err(_err) => { - Err(RustCError::WebAuthFailed(format!("{}", _err.to_string()))) + Err(RustCError::WebAuthFailed(format!("{}", _err))) } } }, Err(_err) => { - Err(RustCError::WebAuthFailed(format!("{}", _err.to_string()))) + Err(RustCError::WebAuthFailed(format!("{}", _err))) } }, - Err(_err) => Err(RustCError::WebAuthFailed(format!("{}", _err.to_string()))), + Err(_err) => Err(RustCError::WebAuthFailed(format!("{}", _err))), } } else { - Err(RustCError::WebAuthFailed(format!("invalid json"))) + Err(RustCError::WebAuthFailed("invalid json".to_string())) } } - Err(_err) => Err(RustCError::WebAuthFailed(format!("{}", _err.to_string()))), + Err(_err) => Err(RustCError::WebAuthFailed(format!("{}", _err))), }; match result { Ok(_value) => convert_c_char(_value), @@ -91,26 +91,26 @@ fn _calculate_auth_code( d, vec![dummy_p, dummy_q], ) { - Ok(_key) => match _key.decrypt(rsa::Oaep::new::(), &encrypted_data) { + Ok(_key) => match _key.decrypt(rsa::Oaep::new::(), encrypted_data) { Ok(_value) => String::from_utf8(_value.clone()).map_err(|_err| { RustCError::WebAuthFailed(format!( "Invalid utf8 hex: {}, {}", hex::encode(_value), - _err.to_string() + _err )) }), Err(_err) => Err(RustCError::WebAuthFailed(format!( "RSA decryption failed: {}", - _err.to_string() + _err ))), }, Err(_err) => Err(RustCError::WebAuthFailed(format!( "RSA key recovery error: {}", - _err.to_string() + _err ))), } }, - _ => Err(RustCError::WebAuthFailed(format!("k1 verify failed"))), + _ => Err(RustCError::WebAuthFailed("k1 verify failed".to_string())), } } diff --git a/rust/rust_c/src/cosmos/mod.rs b/rust/rust_c/src/cosmos/mod.rs index d32a0385f..f61e2cf9f 100644 --- a/rust/rust_c/src/cosmos/mod.rs +++ b/rust/rust_c/src/cosmos/mod.rs @@ -53,7 +53,7 @@ fn build_sign_result( sign_request.get_sign_data().to_vec(), &path, SignMode::COSMOS, - &seed, + seed, )?; Ok(Either::Left(CosmosSignature::new( sign_request.get_request_id(), @@ -74,14 +74,14 @@ fn build_sign_result( sign_request.get_sign_data().to_vec(), &path, SignMode::EVM, - &seed, + seed, )?; Ok(Either::Right(EvmSignature::new( sign_request.get_request_id(), signature.to_vec(), ))) } - _ => return Err(CosmosError::SignFailure("invalid ur type".to_string())), + _ => Err(CosmosError::SignFailure("invalid ur type".to_string())), } } @@ -181,7 +181,7 @@ pub extern "C" fn cosmos_sign_tx( v.map_or_else( |e| UREncodeResult::from(e).c_ptr(), |data| { - UREncodeResult::encode(data, ur_tag, FRAGMENT_MAX_LENGTH_DEFAULT.clone()) + UREncodeResult::encode(data, ur_tag, FRAGMENT_MAX_LENGTH_DEFAULT) .c_ptr() }, ) diff --git a/rust/rust_c/src/ethereum/abi.rs b/rust/rust_c/src/ethereum/abi.rs index 677eb0824..254d40dbd 100644 --- a/rust/rust_c/src/ethereum/abi.rs +++ b/rust/rust_c/src/ethereum/abi.rs @@ -3,7 +3,7 @@ use crate::common::errors::RustCError; use crate::common::structs::Response; use crate::common::types::{Ptr, PtrString}; use crate::common::utils::recover_c_char; -use hex; + #[no_mangle] pub extern "C" fn eth_parse_contract_data( diff --git a/rust/rust_c/src/ethereum/mod.rs b/rust/rust_c/src/ethereum/mod.rs index a09687721..3d9d6c8a9 100644 --- a/rust/rust_c/src/ethereum/mod.rs +++ b/rust/rust_c/src/ethereum/mod.rs @@ -10,7 +10,7 @@ use app_ethereum::{ LegacyTransaction, TransactionSignature, }; use cryptoxide::hashing::keccak256; -use hex; + use keystore::algorithms::secp256k1::derive_public_key; use ur_registry::ethereum::eth_sign_request::EthSignRequest; use ur_registry::ethereum::eth_signature::EthSignature; @@ -60,9 +60,9 @@ pub extern "C" fn eth_check_ur_bytes( let xfp = payload.xfp; let xfp_vec: [u8; 4] = hex::decode(xfp).unwrap().try_into().unwrap(); if mfp == xfp_vec { - return TransactionCheckResult::new().c_ptr(); + TransactionCheckResult::new().c_ptr() } else { - return TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr(); + TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr() } } Err(e) => TransactionCheckResult::from(KeystoneError::ProtobufError(e.to_string())).c_ptr(), @@ -98,9 +98,9 @@ pub extern "C" fn eth_check( } }; if ur_mfp == mfp { - return TransactionCheckResult::new().c_ptr(); + TransactionCheckResult::new().c_ptr() } else { - return TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr(); + TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr() } } @@ -122,7 +122,7 @@ pub extern "C" fn eth_get_root_path_bytes(ptr: PtrUR) -> PtrString { .take(3) .collect::>() .join("/"); - return convert_c_char(root_path); + convert_c_char(root_path) } #[no_mangle] @@ -135,14 +135,14 @@ pub extern "C" fn eth_get_root_path(ptr: PtrUR) -> PtrString { return convert_c_char(root_path); } } - return convert_c_char("".to_string()); + convert_c_char("".to_string()) } fn parse_eth_root_path(path: String) -> Option { let root_path = "44'/60'/"; match path.strip_prefix(root_path) { Some(path) => { - if let Some(index) = path.find("/") { + if let Some(index) = path.find('/') { let sub_path = &path[..index]; Some(format!("{}{}", root_path, sub_path)) } else { @@ -157,11 +157,7 @@ fn parse_eth_sub_path(path: String) -> Option { let root_path = "44'/60'/"; match path.strip_prefix(root_path) { Some(path) => { - if let Some(index) = path.find("/") { - Some(path[index + 1..].to_string()) - } else { - None - } + path.find('/').map(|index| path[index + 1..].to_string()) } None => None, } @@ -177,7 +173,7 @@ fn try_get_eth_public_key( let _path = path.clone(); if let Some(sub_path) = parse_eth_sub_path(_path) { derive_public_key(&xpub, &format!("m/{}", sub_path)) - .map_err(|_e| RustCError::UnexpectedError(format!("unable to derive pubkey"))) + .map_err(|_e| RustCError::UnexpectedError("unable to derive pubkey".to_string())) } else { Err(RustCError::InvalidHDPath) } @@ -210,7 +206,7 @@ pub extern "C" fn eth_parse_bytes_data( .collect::>() .join("/"); let address = derive_address( - &sign_tx.hd_path.to_uppercase().trim_start_matches("M/"), + sign_tx.hd_path.to_uppercase().trim_start_matches("M/"), &xpub, root_path, ) @@ -254,7 +250,7 @@ pub extern "C" fn eth_parse( } } TransactionType::TypedTransaction => { - match crypto_eth.get_sign_data().get(0) { + match crypto_eth.get_sign_data().first() { Some(02) => { //remove envelop let payload = crypto_eth.get_sign_data()[1..].to_vec(); @@ -368,7 +364,7 @@ pub extern "C" fn eth_sign_tx_dynamic( TransactionType::Legacy => { app_ethereum::sign_legacy_tx(crypto_eth.get_sign_data().to_vec(), seed, &path) } - TransactionType::TypedTransaction => match crypto_eth.get_sign_data().get(0) { + TransactionType::TypedTransaction => match crypto_eth.get_sign_data().first() { Some(0x02) => { app_ethereum::sign_fee_markey_tx(crypto_eth.get_sign_data().to_vec(), seed, &path) } @@ -396,7 +392,7 @@ pub extern "C" fn eth_sign_tx_dynamic( let eth_signature = EthSignature::new( crypto_eth.get_request_id(), sig.serialize(), - Some(format!("{}", KEYSTONE)), + Some(KEYSTONE.to_string()), ); match eth_signature.try_into() { Err(e) => UREncodeResult::from(e).c_ptr(), @@ -486,14 +482,14 @@ pub extern "C" fn eth_sign_tx_bytes( UREncodeResult::encode( ur_registry::bytes::Bytes::new(zip_data).try_into().unwrap(), ur_registry::bytes::Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() } #[no_mangle] pub extern "C" fn eth_sign_tx(ptr: PtrUR, seed: PtrBytes, seed_len: u32) -> PtrT { - eth_sign_tx_dynamic(ptr, seed, seed_len, FRAGMENT_MAX_LENGTH_DEFAULT.clone()) + eth_sign_tx_dynamic(ptr, seed, seed_len, FRAGMENT_MAX_LENGTH_DEFAULT) } // _unlimited @@ -503,7 +499,7 @@ pub extern "C" fn eth_sign_tx_unlimited( seed: PtrBytes, seed_len: u32, ) -> PtrT { - eth_sign_tx_dynamic(ptr, seed, seed_len, FRAGMENT_UNLIMITED_LENGTH.clone()) + eth_sign_tx_dynamic(ptr, seed, seed_len, FRAGMENT_UNLIMITED_LENGTH) } #[no_mangle] @@ -540,9 +536,9 @@ mod tests { fn test_test() { let _path = "44'/60'/1'/0/0"; let root_path = "44'/60'/"; - let sub_path = match _path.strip_prefix(root_path) { + match _path.strip_prefix(root_path) { Some(path) => { - if let Some(index) = path.find("/") { + if let Some(index) = path.find('/') { println!("{}", &path[index..]); } } diff --git a/rust/rust_c/src/ethereum/structs.rs b/rust/rust_c/src/ethereum/structs.rs index f595fdc87..316e08368 100644 --- a/rust/rust_c/src/ethereum/structs.rs +++ b/rust/rust_c/src/ethereum/structs.rs @@ -373,7 +373,7 @@ impl From for DisplayContractData { value .get_params() .iter() - .map(|v| DisplayContractParam::from(v)) + .map(DisplayContractParam::from) .collect_vec(), ) .c_ptr(), diff --git a/rust/rust_c/src/near/mod.rs b/rust/rust_c/src/near/mod.rs index c1d6dcbe3..7ce7b5e80 100644 --- a/rust/rust_c/src/near/mod.rs +++ b/rust/rust_c/src/near/mod.rs @@ -95,7 +95,7 @@ pub extern "C" fn near_sign_tx(ptr: PtrUR, seed: PtrBytes, seed_len: u32) -> Ptr UREncodeResult::encode( data, NearSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, diff --git a/rust/rust_c/src/solana/mod.rs b/rust/rust_c/src/solana/mod.rs index 2a2287c8f..59e4f23f2 100644 --- a/rust/rust_c/src/solana/mod.rs +++ b/rust/rust_c/src/solana/mod.rs @@ -56,7 +56,7 @@ pub extern "C" fn solana_check( } let sol_sign_request = extract_ptr_with_type!(ptr, SolSignRequest); let mfp = unsafe { core::slice::from_raw_parts(master_fingerprint, 4) }; - if let Some(mfp) = (mfp.try_into() as Result<[u8; 4], _>).ok() { + if let Ok(mfp) = (mfp.try_into() as Result<[u8; 4], _>) { let derivation_path: ur_registry::crypto_key_path::CryptoKeyPath = sol_sign_request.get_derivation_path(); if let Some(ur_mfp) = derivation_path.get_source_fingerprint() { @@ -99,7 +99,7 @@ pub extern "C" fn solana_sign_tx( UREncodeResult::encode( data, SolSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() }, @@ -134,5 +134,5 @@ pub extern "C" fn sol_get_path(ptr: PtrUR) -> PtrString { if let Some(path) = derivation_path.get_path() { return convert_c_char(path); } - return convert_c_char("".to_string()); + convert_c_char("".to_string()) } diff --git a/rust/rust_c/src/stellar/mod.rs b/rust/rust_c/src/stellar/mod.rs index 5c6c832c9..2b840598a 100644 --- a/rust/rust_c/src/stellar/mod.rs +++ b/rust/rust_c/src/stellar/mod.rs @@ -12,7 +12,7 @@ use crate::common::utils::{convert_c_char, recover_c_char}; use crate::extract_ptr_with_type; use app_stellar::strkeys::{sign_hash, sign_signature_base}; use app_stellar::{address::get_address, base_to_xdr}; -use hex; + use structs::DisplayStellarTx; use ur_registry::stellar::stellar_sign_request::{SignType, StellarSignRequest}; use ur_registry::stellar::stellar_signature::StellarSignature; @@ -35,7 +35,7 @@ pub extern "C" fn stellar_parse(ptr: PtrUR) -> PtrT base_to_xdr(&sign_request.get_sign_data()), - SignType::TransactionHash => hex::encode(&sign_request.get_sign_data()), + SignType::TransactionHash => hex::encode(sign_request.get_sign_data()), _ => { return TransactionParseResult::from(RustCError::UnsupportedTransaction( "Transaction".to_string(), @@ -61,7 +61,7 @@ pub extern "C" fn stellar_check_tx( } let mfp = unsafe { slice::from_raw_parts(master_fingerprint, 4) }; let sign_request = extract_ptr_with_type!(ptr, StellarSignRequest); - if let Some(mfp) = (mfp.try_into() as Result<[u8; 4], _>).ok() { + if let Ok(mfp) = (mfp.try_into() as Result<[u8; 4], _>) { let derivation_path: ur_registry::crypto_key_path::CryptoKeyPath = sign_request.get_derivation_path(); if let Some(ur_mfp) = derivation_path.get_source_fingerprint() { @@ -86,7 +86,7 @@ fn build_signature_data( UREncodeResult::encode( data, StellarSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() } @@ -98,19 +98,19 @@ pub extern "C" fn stellar_sign(ptr: PtrUR, seed: PtrBytes, seed_len: u32) -> Ptr let sign_data = sign_request.get_sign_data(); let path = sign_request.get_derivation_path().get_path().unwrap(); match sign_request.get_sign_type() { - SignType::Transaction => match sign_signature_base(&sign_data, &seed, &path) { + SignType::Transaction => match sign_signature_base(&sign_data, seed, &path) { Ok(signature) => build_signature_data(&signature, sign_request.to_owned()), Err(e) => UREncodeResult::from(e).c_ptr(), }, - SignType::TransactionHash => match sign_hash(&sign_data, &seed, &path) { + SignType::TransactionHash => match sign_hash(&sign_data, seed, &path) { Ok(signature) => build_signature_data(&signature, sign_request.to_owned()), Err(e) => UREncodeResult::from(e).c_ptr(), }, _ => { - return UREncodeResult::from(RustCError::UnsupportedTransaction( + UREncodeResult::from(RustCError::UnsupportedTransaction( "Transaction".to_string(), )) - .c_ptr(); + .c_ptr() } } } diff --git a/rust/rust_c/src/sui/mod.rs b/rust/rust_c/src/sui/mod.rs index b87948f19..beaf974e7 100644 --- a/rust/rust_c/src/sui/mod.rs +++ b/rust/rust_c/src/sui/mod.rs @@ -167,7 +167,7 @@ pub extern "C" fn sui_sign_hash(ptr: PtrUR, seed: PtrBytes, seed_len: u32) -> Pt UREncodeResult::encode( sig_data, SuiSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() } @@ -210,7 +210,7 @@ pub extern "C" fn sui_sign_intent( UREncodeResult::encode( sig_data, SuiSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() } diff --git a/rust/rust_c/src/ton/mod.rs b/rust/rust_c/src/ton/mod.rs index b1e21c599..7636de4b0 100644 --- a/rust/rust_c/src/ton/mod.rs +++ b/rust/rust_c/src/ton/mod.rs @@ -127,7 +127,7 @@ pub extern "C" fn ton_sign_transaction( ) -> PtrT { let ton_tx = extract_ptr_with_type!(ptr, TonSignRequest); let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; - let sk = match get_secret_key(&ton_tx, seed) { + let sk = match get_secret_key(ton_tx, seed) { Ok(_sk) => _sk, Err(e) => return UREncodeResult::from(e).c_ptr(), }; @@ -144,7 +144,7 @@ pub extern "C" fn ton_sign_transaction( Ok(v) => UREncodeResult::encode( v, TonSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), } @@ -161,7 +161,7 @@ pub extern "C" fn ton_sign_proof( ) -> PtrT { let ton_tx = extract_ptr_with_type!(ptr, TonSignRequest); let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) }; - let sk = match get_secret_key(&ton_tx, seed) { + let sk = match get_secret_key(ton_tx, seed) { Ok(_sk) => _sk, Err(e) => return UREncodeResult::from(e).c_ptr(), }; @@ -178,7 +178,7 @@ pub extern "C" fn ton_sign_proof( Ok(v) => UREncodeResult::encode( v, TonSignature::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), } @@ -190,17 +190,14 @@ pub extern "C" fn ton_sign_proof( #[no_mangle] pub extern "C" fn ton_verify_mnemonic(mnemonic: PtrString) -> bool { let mnemonic = recover_c_char(mnemonic); - let words: Vec = mnemonic.split(" ").map(|v| v.to_lowercase()).collect(); - match ton_mnemonic_validate(&words, &None) { - Ok(_) => true, - Err(_) => false, - } + let words: Vec = mnemonic.split(' ').map(|v| v.to_lowercase()).collect(); + ton_mnemonic_validate(&words, &None).is_ok() } #[no_mangle] pub extern "C" fn ton_mnemonic_to_entropy(mnemonic: PtrString) -> Ptr> { let mnemonic = recover_c_char(mnemonic); - let words: Vec = mnemonic.split(" ").map(|v| v.to_lowercase()).collect(); + let words: Vec = mnemonic.split(' ').map(|v| v.to_lowercase()).collect(); let entropy = app_ton::mnemonic::ton_mnemonic_to_entropy(&words, &None); VecFFI::from(entropy).c_ptr() } @@ -218,7 +215,7 @@ pub extern "C" fn ton_entropy_to_seed( #[no_mangle] pub extern "C" fn ton_mnemonic_to_seed(mnemonic: PtrString) -> *mut SimpleResponse { let mnemonic = recover_c_char(mnemonic); - let words: Vec = mnemonic.split(" ").map(|v| v.to_lowercase()).collect(); + let words: Vec = mnemonic.split(' ').map(|v| v.to_lowercase()).collect(); let seed = app_ton::mnemonic::ton_mnemonic_to_master_seed(words, None); match seed { Ok(seed) => { @@ -239,9 +236,7 @@ pub extern "C" fn ton_seed_to_publickey( let public_key = app_ton::mnemonic::ton_master_seed_to_public_key(_seed); SimpleResponse::success(convert_c_char(hex::encode(public_key))).simple_c_ptr() } - Err(_e) => SimpleResponse::from(crate::common::errors::RustCError::InvalidData(format!( - "seed length should be 64" - ))) + Err(_e) => SimpleResponse::from(crate::common::errors::RustCError::InvalidData("seed length should be 64".to_string())) .simple_c_ptr(), } } diff --git a/rust/rust_c/src/ton/structs.rs b/rust/rust_c/src/ton/structs.rs index f3eb88584..8d6e4cfb7 100644 --- a/rust/rust_c/src/ton/structs.rs +++ b/rust/rust_c/src/ton/structs.rs @@ -31,18 +31,18 @@ impl From<&TonTransaction> for DisplayTonTransaction { comment: tx .comment .clone() - .map(|v| convert_c_char(v)) + .map(convert_c_char) .unwrap_or(null_mut()), data_view: tx .data_view .clone() - .map(|v| convert_c_char(v)) + .map(convert_c_char) .unwrap_or(null_mut()), raw_data: convert_c_char(tx.raw_data.clone()), contract_data: tx .contract_data .clone() - .map(|e| convert_c_char(e)) + .map(convert_c_char) .unwrap_or(null_mut()), } } diff --git a/rust/rust_c/src/wallet/btc_only_wallet.rs b/rust/rust_c/src/wallet/btc_only_wallet.rs index ec4fad978..9f30bd789 100644 --- a/rust/rust_c/src/wallet/btc_only_wallet.rs +++ b/rust/rust_c/src/wallet/btc_only_wallet.rs @@ -37,7 +37,7 @@ pub extern "C" fn get_connect_blue_wallet_ur( unsafe { let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let keys = recover_c_array(public_keys); - let key1 = keys.get(0); + let key1 = keys.first(); let key2 = keys.get(1); let key3 = keys.get(2); return if let (Some(k1), Some(k2), Some(k3)) = (key1, key2, key3) { @@ -71,7 +71,7 @@ pub extern "C" fn get_connect_blue_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoAccount::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -79,7 +79,7 @@ pub extern "C" fn get_connect_blue_wallet_ur( Err(e) => UREncodeResult::from(e).c_ptr(), } } else { - UREncodeResult::from(URError::UrEncodeError(format!("getting key error"))).c_ptr() + UREncodeResult::from(URError::UrEncodeError("getting key error".to_string())).c_ptr() }; } } @@ -100,7 +100,7 @@ pub extern "C" fn get_connect_sparrow_wallet_ur( unsafe { let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let keys = recover_c_array(public_keys); - let key1 = keys.get(0); + let key1 = keys.first(); let key2 = keys.get(1); let key3 = keys.get(2); let key4 = keys.get(3); @@ -142,7 +142,7 @@ pub extern "C" fn get_connect_sparrow_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoAccount::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -150,7 +150,7 @@ pub extern "C" fn get_connect_sparrow_wallet_ur( Err(e) => UREncodeResult::from(e).c_ptr(), } } else { - UREncodeResult::from(URError::UrEncodeError(format!("getting key error"))).c_ptr() + UREncodeResult::from(URError::UrEncodeError("getting key error".to_string())).c_ptr() }; } } @@ -171,7 +171,7 @@ pub extern "C" fn get_connect_specter_wallet_ur( unsafe { let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let keys = recover_c_array(public_keys); - let key1 = keys.get(0); + let key1 = keys.first(); let key2 = keys.get(1); return if let (Some(k1), Some(k2)) = (key1, key2) { let k1_x_pub = recover_c_char(k1.xpub); @@ -198,7 +198,7 @@ pub extern "C" fn get_connect_specter_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoAccount::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -206,7 +206,7 @@ pub extern "C" fn get_connect_specter_wallet_ur( Err(e) => UREncodeResult::from(e).c_ptr(), } } else { - UREncodeResult::from(URError::UrEncodeError(format!("getting key error"))).c_ptr() + UREncodeResult::from(URError::UrEncodeError("getting key error".to_string())).c_ptr() }; } } @@ -279,7 +279,7 @@ pub extern "C" fn get_connect_companion_app_ur( Ok(data) => UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -327,7 +327,7 @@ pub extern "C" fn get_okx_wallet_ur_btc_only( Ok(_v) => UREncodeResult::encode( _v, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs index d47899fe0..886a940d6 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/aptos.rs @@ -33,7 +33,7 @@ pub extern "C" fn get_connect_aptos_wallet_ur( let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let public_keys = recover_c_array(public_keys); let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -56,7 +56,7 @@ pub extern "C" fn get_connect_aptos_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs index 886865601..e8009941f 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs @@ -34,19 +34,19 @@ pub extern "C" fn get_connect_arconnect_wallet_ur( unsafe { slice::from_raw_parts(master_fingerprint, master_fingerprint_length as usize) }; let p = unsafe { slice::from_raw_parts(p, p_len as usize) }; let q = unsafe { slice::from_raw_parts(q, q_len as usize) }; - let public_key = generate_public_key_from_primes(&p, &q).unwrap(); + let public_key = generate_public_key_from_primes(p, q).unwrap(); let device = Option::None; let arweave_account = ArweaveCryptoAccount::new( vec_to_array(mfp.to_vec()).unwrap(), public_key.to_vec(), device, ); - return UREncodeResult::encode( + UREncodeResult::encode( arweave_account.to_bytes().unwrap(), ArweaveCryptoAccount::get_registry_type().get_type(), FRAGMENT_MAX_LENGTH_DEFAULT, ) - .c_ptr(); + .c_ptr() } #[no_mangle] @@ -64,12 +64,12 @@ pub extern "C" fn get_connect_arconnect_wallet_ur_from_xpub( hex::decode(xpub).unwrap(), device, ); - return UREncodeResult::encode( + UREncodeResult::encode( arweave_account.to_bytes().unwrap(), ArweaveCryptoAccount::get_registry_type().get_type(), FRAGMENT_MAX_LENGTH_DEFAULT, ) - .c_ptr(); + .c_ptr() } #[cfg(test)] diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs index be5e0299a..8f1e72c90 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/backpack.rs @@ -37,7 +37,7 @@ pub extern "C" fn get_backpack_wallet_ur( Ok(_v) => UREncodeResult::encode( _v, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs index cdc34eb7d..b4675b4f1 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/bitget.rs @@ -50,7 +50,7 @@ pub extern "C" fn get_bitget_wallet_ur( Ok(_v) => UREncodeResult::encode( _v, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs index 56f5a94e2..41be4fd10 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keplr.rs @@ -35,10 +35,10 @@ pub extern "C" fn get_connect_keplr_wallet_ur( unsafe { let accounts: &[KeplrAccount] = recover_c_array(keplr_accounts); let sync_infos: Vec = accounts - .into_iter() + .iter() .map(|account| { let hd_path = recover_c_char(account.path); - let path_parts: Vec<&str> = hd_path.split("/").collect(); + let path_parts: Vec<&str> = hd_path.split('/').collect(); let path_len = path_parts.len(); SyncInfo { name: recover_c_char(account.name), @@ -62,7 +62,7 @@ pub extern "C" fn get_connect_keplr_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs index f244037f0..0d58eac24 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/keystone.rs @@ -48,7 +48,7 @@ pub extern "C" fn get_keystone_wallet_ur( Ok(_v) => UREncodeResult::encode( _v, "BYTES".to_string(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs index cadf86106..d78b25aed 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/mod.rs @@ -116,12 +116,12 @@ pub extern "C" fn get_connect_metamask_ur_dynamic( } } Err(e) => { - return UREncodeResult::from(e).c_ptr(); + UREncodeResult::from(e).c_ptr() } } } _ => { - let key = keys.get(0).ok_or(RustCError::InvalidXPub); + let key = keys.first().ok_or(RustCError::InvalidXPub); match key { Ok(k) => { let result = app_wallets::metamask::generate_standard_legacy_hd_key( @@ -143,7 +143,7 @@ pub extern "C" fn get_connect_metamask_ur_dynamic( Err(e) => UREncodeResult::from(e).c_ptr(), } } - Err(e) => return UREncodeResult::from(e).c_ptr(), + Err(e) => UREncodeResult::from(e).c_ptr(), } } } @@ -162,8 +162,8 @@ pub extern "C" fn get_connect_metamask_ur_unlimited( master_fingerprint_length, account_type, public_keys, - FRAGMENT_UNLIMITED_LENGTH.clone(), - FRAGMENT_UNLIMITED_LENGTH.clone(), + FRAGMENT_UNLIMITED_LENGTH, + FRAGMENT_UNLIMITED_LENGTH, ) } @@ -179,7 +179,7 @@ pub extern "C" fn get_connect_metamask_ur( master_fingerprint_length, account_type, public_keys, - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, 240, ) } @@ -255,7 +255,7 @@ pub extern "C" fn check_hardware_call_path( _ => return Response::success(false).c_ptr(), }; let mut path = recover_c_char(path).to_lowercase(); - if !path.starts_with("m") { + if !path.starts_with('m') { path = format!("m/{}", path); } let result = path.starts_with(prefix); @@ -271,7 +271,7 @@ pub extern "C" fn generate_key_derivation_ur( ) -> Ptr { let mfp = extract_array!(master_fingerprint, u8, master_fingerprint_length); let mfp = match <&[u8; 4]>::try_from(mfp) { - Ok(mfp) => mfp.clone(), + Ok(mfp) => *mfp, Err(e) => return UREncodeResult::from(URError::UrEncodeError(e.to_string())).c_ptr(), }; let public_keys = unsafe { recover_c_array(xpubs) }; diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs index 2ac622bee..b041751cc 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/okx.rs @@ -50,7 +50,7 @@ pub extern "C" fn get_okx_wallet_ur( Ok(_v) => UREncodeResult::encode( _v, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs index 1fa48c698..9e549244a 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/solana.rs @@ -33,7 +33,7 @@ pub extern "C" fn get_connect_solana_wallet_ur( let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let public_keys = recover_c_array(public_keys); let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -56,7 +56,7 @@ pub extern "C" fn get_connect_solana_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs b/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs index 98b1b0fe2..dc847733c 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/structs.rs @@ -71,7 +71,7 @@ impl TryFrom<&mut QRHardwareCall> for QRHardwareCallData { let schemas = data .get_schemas() .iter() - .map(|v| KeyDerivationSchema::try_from(v)) + .map(KeyDerivationSchema::try_from) .collect::, RustCError>>()?; // todo check path is valid diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs index 93b2f5883..7763c2f2e 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/sui.rs @@ -32,7 +32,7 @@ pub extern "C" fn get_connect_sui_wallet_ur( let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let public_keys = recover_c_array(public_keys); let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -55,7 +55,7 @@ pub extern "C" fn get_connect_sui_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs index 06b844d77..d3f7cc53f 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/thor_wallet.rs @@ -37,12 +37,12 @@ pub extern "C" fn get_connect_thor_wallet_ur( let serial_number = recover_c_char(serial_number); let device_type = recover_c_char(device_type); let device_version = recover_c_char(device_version); - let key1 = keys.get(0); + let key1 = keys.first(); let key2 = keys.get(1); let key3 = keys.get(2); let key4 = keys.get(3); let key5 = keys.get(4); - return if let (Some(_k1), Some(_k2), Some(_k3), Some(_k4), Some(_k5)) = + if let (Some(_k1), Some(_k2), Some(_k3), Some(_k4), Some(_k5)) = (key1, key2, key3, key4, key5) { let mfp = match <&[u8; 4]>::try_from(mfp) { @@ -65,7 +65,7 @@ pub extern "C" fn get_connect_thor_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -73,7 +73,7 @@ pub extern "C" fn get_connect_thor_wallet_ur( Err(e) => UREncodeResult::from(e).c_ptr(), } } else { - UREncodeResult::from(URError::UrEncodeError(format!("getting key error"))).c_ptr() - }; + UREncodeResult::from(URError::UrEncodeError("getting key error".to_string())).c_ptr() + } } } diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs b/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs index 48d7dff8d..6694f981f 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/tonkeeper.rs @@ -48,7 +48,7 @@ pub extern "C" fn get_tonkeeper_wallet_ur( Ok(_v) => UREncodeResult::encode( _v, CryptoHDKey::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(_e) => UREncodeResult::from(_e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs index 56001feca..9aa8d76cd 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xbull.rs @@ -33,7 +33,7 @@ pub extern "C" fn get_connect_xbull_wallet_ur( let mfp = slice::from_raw_parts(master_fingerprint, length as usize); let public_keys = recover_c_array(public_keys); let master_fingerprint = - bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp.to_vec()).as_str()) + bitcoin::bip32::Fingerprint::from_str(hex::encode(mfp).as_str()) .map_err(|_e| RustCError::InvalidMasterFingerprint); match master_fingerprint { Ok(fp) => { @@ -56,7 +56,7 @@ pub extern "C" fn get_connect_xbull_wallet_ur( Ok(data) => UREncodeResult::encode( data, CryptoMultiAccounts::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs index 749d5b633..7f1a0f227 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/xrp_toolkit.rs @@ -20,7 +20,7 @@ pub extern "C" fn get_connect_xrp_toolkit_ur( Ok(data) => UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), diff --git a/rust/rust_c/src/xrp/mod.rs b/rust/rust_c/src/xrp/mod.rs index b96c286f6..36639b7c8 100644 --- a/rust/rust_c/src/xrp/mod.rs +++ b/rust/rust_c/src/xrp/mod.rs @@ -8,7 +8,7 @@ use app_xrp::errors::XRPError; use bitcoin::bip32::{DerivationPath, Xpub}; use bitcoin::secp256k1; use cty::c_char; -use hex; + use serde_json::Value; use ur_registry::bytes::Bytes; use ur_registry::pb; @@ -104,7 +104,7 @@ pub extern "C" fn xrp_sign_tx_bytes( let xpub = Xpub::from_str(&root_xpub).unwrap(); let k1 = secp256k1::Secp256k1::new(); // M/44'/144'/0'/0/0 -> 0/0 - let split_hd_path: Vec<&str> = hd_path.split("/").collect(); + let split_hd_path: Vec<&str> = hd_path.split('/').collect(); let derive_hd_path = format!("{}/{}", split_hd_path[4], split_hd_path[5]); let five_level_xpub = xpub .derive_pub( @@ -144,8 +144,8 @@ pub extern "C" fn xrp_sign_tx_bytes( // generate a qr code let sign_tx_result = ur_registry::pb::protoc::SignTransactionResult { sign_id: sign_tx.sign_id, - tx_id: format!("{}", tx_hash.to_uppercase()), - raw_tx: format!("{}", raw_tx_hex.clone()), + tx_id: tx_hash.to_uppercase().to_string(), + raw_tx: raw_tx_hex.clone().to_string(), }; let content = ur_registry::pb::protoc::payload::Content::SignTxResult(sign_tx_result); let payload = ur_registry::pb::protoc::Payload { @@ -168,7 +168,7 @@ pub extern "C" fn xrp_sign_tx_bytes( UREncodeResult::encode( ur_registry::bytes::Bytes::new(zip_data).try_into().unwrap(), ur_registry::bytes::Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr() } @@ -187,7 +187,7 @@ pub extern "C" fn xrp_sign_tx( Ok(data) => UREncodeResult::encode( data, Bytes::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), Err(e) => UREncodeResult::from(e).c_ptr(), @@ -219,10 +219,7 @@ pub extern "C" fn xrp_check_tx( pub extern "C" fn is_keystone_xrp_tx(ur_data_ptr: PtrUR) -> bool { // if data can be parsed by protobuf, it is a keyston hot app version2 tx or it is a xrp tx let payload = build_payload(ur_data_ptr, QRCodeType::Bytes); - match payload { - Ok(_) => true, - Err(_) => false, - } + payload.is_ok() } #[no_mangle] @@ -244,9 +241,9 @@ pub extern "C" fn xrp_check_tx_bytes( let xfp = payload.xfp; let xfp_vec: [u8; 4] = hex::decode(xfp).unwrap().try_into().unwrap(); if mfp == xfp_vec { - return TransactionCheckResult::error(ErrorCodes::Success, "".to_string()).c_ptr(); + TransactionCheckResult::error(ErrorCodes::Success, "".to_string()).c_ptr() } else { - return TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr(); + TransactionCheckResult::from(RustCError::MasterFingerprintMismatch).c_ptr() } } Err(e) => TransactionCheckResult::from(KeystoneError::ProtobufError(e.to_string())).c_ptr(), diff --git a/rust/rust_c/src/zcash/mod.rs b/rust/rust_c/src/zcash/mod.rs index 2778b9efa..26a99ec15 100644 --- a/rust/rust_c/src/zcash/mod.rs +++ b/rust/rust_c/src/zcash/mod.rs @@ -73,9 +73,7 @@ pub extern "C" fn check_zcash_tx( disabled: bool, ) -> *mut TransactionCheckResult { if disabled { - return TransactionCheckResult::from(RustCError::UnsupportedTransaction(format!( - "zcash is not supported for slip39 and passphrase wallet now" - ))) + return TransactionCheckResult::from(RustCError::UnsupportedTransaction("zcash is not supported for slip39 and passphrase wallet now".to_string())) .c_ptr(); } let pczt = extract_ptr_with_type!(tx, ZcashPczt); @@ -120,7 +118,7 @@ pub extern "C" fn sign_zcash_tx(tx: PtrUR, seed: PtrBytes, seed_len: u32) -> *mu Ok(v) => UREncodeResult::encode( v, ZcashPczt::get_registry_type().get_type(), - FRAGMENT_MAX_LENGTH_DEFAULT.clone(), + FRAGMENT_MAX_LENGTH_DEFAULT, ) .c_ptr(), }, @@ -149,7 +147,7 @@ pub extern "C" fn rust_aes256_cbc_encrypt( let password = recover_c_char(password); let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; let key = sha256(password.as_bytes()); - let iv = GenericArray::from_slice(&iv); + let iv = GenericArray::from_slice(iv); let key = GenericArray::from_slice(&key); let ct = Aes256CbcEnc::new(key, iv).encrypt_padded_vec_mut::(data); SimpleResponse::success(convert_c_char(hex::encode(ct))).simple_c_ptr() @@ -167,7 +165,7 @@ pub extern "C" fn rust_aes256_cbc_decrypt( let password = recover_c_char(password); let iv = unsafe { slice::from_raw_parts(iv, iv_len as usize) }; let key = sha256(password.as_bytes()); - let iv = GenericArray::from_slice(&iv); + let iv = GenericArray::from_slice(iv); let key = GenericArray::from_slice(&key); match Aes256CbcDec::new(key, iv).decrypt_padded_vec_mut::(&data) { diff --git a/rust/sim_qr_reader/src/lib.rs b/rust/sim_qr_reader/src/lib.rs index 75122e9bf..12d94b7db 100644 --- a/rust/sim_qr_reader/src/lib.rs +++ b/rust/sim_qr_reader/src/lib.rs @@ -3,7 +3,7 @@ use image::DynamicImage; use quircs::{Code, Quirc}; use screenshots::Screen; use std::thread; -use std::time::{Duration, Instant}; +use std::time::{Duration}; #[cfg(target_os = "macos")] use cocoa::{appkit::NSScreen, base::nil, foundation::NSArray}; @@ -20,8 +20,8 @@ fn get_screen_scaling_factor() -> f64 { unsafe { let screens = NSScreen::screens(nil); let screen = NSArray::objectAtIndex(screens, 0); - let scale_factor = NSScreen::backingScaleFactor(screen); - scale_factor as f64 + + NSScreen::backingScaleFactor(screen) } #[cfg(target_os = "windows")] @@ -98,7 +98,7 @@ where if on_qr_code_detected(&content) { break; } - if let None = qr_area { + if qr_area.is_none() { qr_area = new_area; } if let Some(area) = qr_area { @@ -119,10 +119,10 @@ where fn get_qr_area(code: &Code, image: &DynamicImage) -> (i32, i32, u32, u32) { let points = code.corners; - let min_x = points.iter().map(|p| p.x).min().unwrap() as i32; - let min_y = points.iter().map(|p| p.y).min().unwrap() as i32; - let max_x = points.iter().map(|p| p.x).max().unwrap() as i32; - let max_y = points.iter().map(|p| p.y).max().unwrap() as i32; + let min_x = points.iter().map(|p| p.x).min().unwrap(); + let min_y = points.iter().map(|p| p.y).min().unwrap(); + let max_x = points.iter().map(|p| p.x).max().unwrap(); + let max_y = points.iter().map(|p| p.y).max().unwrap(); let width = (max_x - min_x) as u32; let height = (max_y - min_y) as u32; diff --git a/rust/zcash_vendor/src/pczt_ext.rs b/rust/zcash_vendor/src/pczt_ext.rs index 82f889028..c259f2962 100644 --- a/rust/zcash_vendor/src/pczt_ext.rs +++ b/rust/zcash_vendor/src/pczt_ext.rs @@ -110,7 +110,7 @@ fn is_transparent_coinbase(pczt: &Pczt) -> bool { } fn has_sapling(pczt: &Pczt) -> bool { - pczt.sapling().spends().len() > 0 || pczt.sapling().outputs().len() > 0 + !pczt.sapling().spends().is_empty() || !pczt.sapling().outputs().is_empty() } fn has_orchard(pczt: &Pczt) -> bool { @@ -156,15 +156,15 @@ fn digest_transparent_outputs(outputs: &[Output]) -> Hash { h.update(&value.to_le_bytes()); let len = output.script_pubkey().len(); h.update(&[len as u8]); - h.update(&output.script_pubkey()); + h.update(output.script_pubkey()); } h.finalize() } fn transparent_digest(pczt: &Pczt) -> TransparentDigests { TransparentDigests { - prevouts_digest: digest_transparent_prevouts(&pczt.transparent().inputs()), - sequence_digest: digest_transparent_sequence(&pczt.transparent().inputs()), - outputs_digest: digest_transparent_outputs(&pczt.transparent().outputs()), + prevouts_digest: digest_transparent_prevouts(pczt.transparent().inputs()), + sequence_digest: digest_transparent_sequence(pczt.transparent().inputs()), + outputs_digest: digest_transparent_outputs(pczt.transparent().outputs()), } } fn hash_transparent_tx_id(t_digests: Option) -> Hash { @@ -194,7 +194,7 @@ fn digest_orchard(pczt: &Pczt) -> Hash { nh.update(action.cv_net()); nh.update(action.spend().rk()); nh.update(&action.output().enc_ciphertext()[564..]); - nh.update(&action.output().out_ciphertext()); + nh.update(action.output().out_ciphertext()); } h.update(ch.finalize().as_bytes()); @@ -253,7 +253,7 @@ fn hash_sapling_outputs(pczt: &Pczt) -> Hash { nh.update(s_out.cv()); nh.update(&s_out.enc_ciphertext()[564..]); - nh.update(&s_out.out_ciphertext()); + nh.update(s_out.out_ciphertext()); } h.update(ch.finalize().as_bytes()); @@ -313,70 +313,68 @@ fn sheilded_sig_commitment(pczt: &Pczt, lock_time: u32, input_info: Option) -> Hash { if !has_transparent(pczt) { hash_transparent_tx_id(None) + } else if is_transparent_coinbase(pczt) || pczt.transparent().inputs().is_empty() { + hash_transparent_tx_id(Some(transparent_digest(pczt))) } else { - if is_transparent_coinbase(pczt) || pczt.transparent().inputs().is_empty() { - hash_transparent_tx_id(Some(transparent_digest(pczt))) - } else { - if let Some(input) = &input_info { - // this should have been checked earlier - assert_eq!(input.hash_type().encode(), SIGHASH_ALL); - } - //SIGHASH_ALL - let prevouts_digest = digest_transparent_prevouts(&pczt.transparent().inputs()); - - let amounts_digest = { - let mut h = hasher(ZCASH_TRANSPARENT_AMOUNTS_HASH_PERSONALIZATION); - pczt.transparent().inputs().iter().for_each(|input| { - h.update(&input.value().to_le_bytes()); - }); - h.finalize() - }; - - let scripts_digest = { - let mut h = hasher(ZCASH_TRANSPARENT_SCRIPTS_HASH_PERSONALIZATION); - pczt.transparent().inputs().iter().for_each(|input| { - //len should be a compact size - let len = input.script_pubkey().len(); - h.update(&[len as u8]); - h.update(&input.script_pubkey()); - }); - h.finalize() - }; - let sequence_digest = digest_transparent_sequence(&pczt.transparent().inputs()); - - let outputs_digest = digest_transparent_outputs(&pczt.transparent().outputs()); - - //S.2g.i: prevout (field encoding) - //S.2g.ii: value (8-byte signed little-endian) - //S.2g.iii: scriptPubKey (field encoding) - //S.2g.iv: nSequence (4-byte unsigned little-endian) - let mut ch = hasher(ZCASH_TRANSPARENT_INPUT_HASH_PERSONALIZATION); - if let Some(signable_input) = input_info { - let input = pczt - .transparent() - .inputs() - .get(*signable_input.index()) - .expect("valid by construction"); - ch.update(input.prevout_txid()); - ch.update(&input.prevout_index().to_le_bytes()); - ch.update(&signable_input.value().to_i64_le_bytes()); - let len = signable_input.script_pubkey().0.len(); - ch.update(&[len as u8]); - ch.update(&signable_input.script_pubkey().0); - ch.update(&input.sequence().unwrap_or(0xffffffff).to_le_bytes()); - } - let txin_sig_digest = ch.finalize(); - - let mut h = hasher(ZCASH_TRANSPARENT_HASH_PERSONALIZATION); - h.update(&[SIGHASH_ALL]); - h.update(prevouts_digest.as_bytes()); - h.update(amounts_digest.as_bytes()); - h.update(scripts_digest.as_bytes()); - h.update(sequence_digest.as_bytes()); - h.update(outputs_digest.as_bytes()); - h.update(txin_sig_digest.as_bytes()); + if let Some(input) = &input_info { + // this should have been checked earlier + assert_eq!(input.hash_type().encode(), SIGHASH_ALL); + } + //SIGHASH_ALL + let prevouts_digest = digest_transparent_prevouts(pczt.transparent().inputs()); + + let amounts_digest = { + let mut h = hasher(ZCASH_TRANSPARENT_AMOUNTS_HASH_PERSONALIZATION); + pczt.transparent().inputs().iter().for_each(|input| { + h.update(&input.value().to_le_bytes()); + }); + h.finalize() + }; + + let scripts_digest = { + let mut h = hasher(ZCASH_TRANSPARENT_SCRIPTS_HASH_PERSONALIZATION); + pczt.transparent().inputs().iter().for_each(|input| { + //len should be a compact size + let len = input.script_pubkey().len(); + h.update(&[len as u8]); + h.update(input.script_pubkey()); + }); h.finalize() + }; + let sequence_digest = digest_transparent_sequence(pczt.transparent().inputs()); + + let outputs_digest = digest_transparent_outputs(pczt.transparent().outputs()); + + //S.2g.i: prevout (field encoding) + //S.2g.ii: value (8-byte signed little-endian) + //S.2g.iii: scriptPubKey (field encoding) + //S.2g.iv: nSequence (4-byte unsigned little-endian) + let mut ch = hasher(ZCASH_TRANSPARENT_INPUT_HASH_PERSONALIZATION); + if let Some(signable_input) = input_info { + let input = pczt + .transparent() + .inputs() + .get(*signable_input.index()) + .expect("valid by construction"); + ch.update(input.prevout_txid()); + ch.update(&input.prevout_index().to_le_bytes()); + ch.update(&signable_input.value().to_i64_le_bytes()); + let len = signable_input.script_pubkey().0.len(); + ch.update(&[len as u8]); + ch.update(&signable_input.script_pubkey().0); + ch.update(&input.sequence().unwrap_or(0xffffffff).to_le_bytes()); } + let txin_sig_digest = ch.finalize(); + + let mut h = hasher(ZCASH_TRANSPARENT_HASH_PERSONALIZATION); + h.update(&[SIGHASH_ALL]); + h.update(prevouts_digest.as_bytes()); + h.update(amounts_digest.as_bytes()); + h.update(scripts_digest.as_bytes()); + h.update(sequence_digest.as_bytes()); + h.update(outputs_digest.as_bytes()); + h.update(txin_sig_digest.as_bytes()); + h.finalize() } } @@ -386,13 +384,13 @@ where T::Error: From, T::Error: From, { - Ok(llsigner + llsigner .sign_transparent_with::(|pczt, signable, tx_modifiable| { let lock_time = determine_lock_time(pczt.global(), pczt.transparent().inputs()) .map_err(|()| transparent::pczt::ParseError::InvalidRequiredHeightLocktime)?; signable .inputs_mut() - .into_iter() + .iter_mut() .enumerate() .try_for_each(|(i, input)| { signer.sign_transparent(i, input, |signable_input| { @@ -421,7 +419,7 @@ where .sign_orchard_with::(|pczt, signable, tx_modifiable| { let lock_time = determine_lock_time(pczt.global(), pczt.transparent().inputs()) .expect("didn't fail earlier"); - signable.actions_mut().into_iter().try_for_each(|action| { + signable.actions_mut().iter_mut().try_for_each(|action| { match action.spend().value().map(|v| v.inner()) { //dummy spend maybe Some(0) | None => { @@ -437,7 +435,7 @@ where } Ok(()) }) - })?) + }) } #[cfg(test)] From cd96baf9e4693abdfbfd04f8945266416585f71c Mon Sep 17 00:00:00 2001 From: soralit Date: Thu, 26 Dec 2024 09:07:34 +0800 Subject: [PATCH 29/31] style: run cargo fix --- rust/apps/bitcoin/src/addresses/address.rs | 2 +- rust/apps/bitcoin/src/transactions/legacy/output.rs | 4 ++-- .../solana/src/solana_lib/jupiter_v6/instructions.rs | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rust/apps/bitcoin/src/addresses/address.rs b/rust/apps/bitcoin/src/addresses/address.rs index aac67770b..8f5accf4a 100644 --- a/rust/apps/bitcoin/src/addresses/address.rs +++ b/rust/apps/bitcoin/src/addresses/address.rs @@ -17,7 +17,7 @@ use bitcoin::address::AddressData as Payload; use bitcoin::blockdata::script; use bitcoin::script::PushBytesBuf; use bitcoin::secp256k1::{Secp256k1, XOnlyPublicKey}; -use bitcoin::{base58, Script, ScriptBuf, TapNodeHash}; +use bitcoin::{base58, ScriptBuf, TapNodeHash}; use bitcoin::{CompressedPublicKey, PublicKey}; use bitcoin::{PubkeyHash, ScriptHash}; use bitcoin::{WitnessProgram, WitnessVersion}; diff --git a/rust/apps/bitcoin/src/transactions/legacy/output.rs b/rust/apps/bitcoin/src/transactions/legacy/output.rs index e8c5b0696..07552b60d 100644 --- a/rust/apps/bitcoin/src/transactions/legacy/output.rs +++ b/rust/apps/bitcoin/src/transactions/legacy/output.rs @@ -3,8 +3,8 @@ use crate::collect; use crate::errors::{BitcoinError, Result}; use alloc::string::{String, ToString}; use alloc::vec::Vec; -use bitcoin::address::AddressData as Payload; -use bitcoin::{self, Amount, ScriptBuf}; + +use bitcoin::{self, Amount}; use core::str::FromStr; use ur_registry::pb::protoc; use ur_registry::pb::protoc::sign_transaction::Transaction::{BchTx, BtcTx, DashTx, LtcTx}; diff --git a/rust/apps/solana/src/solana_lib/jupiter_v6/instructions.rs b/rust/apps/solana/src/solana_lib/jupiter_v6/instructions.rs index 756b0b985..0ce4d0d59 100644 --- a/rust/apps/solana/src/solana_lib/jupiter_v6/instructions.rs +++ b/rust/apps/solana/src/solana_lib/jupiter_v6/instructions.rs @@ -1,7 +1,7 @@ use alloc::string::String; use alloc::vec::Vec; -use borsh::{from_slice, BorshDeserialize}; +use borsh::{BorshDeserialize}; use serde_derive::Serialize; use crate::solana_lib::solana_program::errors::ProgramError; @@ -240,25 +240,25 @@ impl Dispatch for JupiterInstructions { // sharedAccountsRoute methodId = sighash(SIGHASH_GLOBAL_NAMESPACE, "shared_accounts_route") borsh::from_slice::(ix_data) .map(JupiterInstructions::SharedAccountsRoute) - .map_err(|e| JupiterError::UnknownJupiterInstruction.into()) + .map_err(|_e| JupiterError::UnknownJupiterInstruction.into()) } "e517cb977ae3ad2a" => { // route methodId = sighash(SIGHASH_GLOBAL_NAMESPACE, "route") borsh::from_slice::(ix_data) .map(JupiterInstructions::Route) - .map_err(|e| JupiterError::UnknownJupiterInstruction.into()) + .map_err(|_e| JupiterError::UnknownJupiterInstruction.into()) } "d033ef977b2bed5c" => { // exactOutRoute methodId = sighash(SIGHASH_GLOBAL_NAMESPACE, "exact_out_route") borsh::from_slice::(ix_data) .map(JupiterInstructions::ExactOutRoute) - .map_err(|e| JupiterError::UnknownJupiterInstruction.into()) + .map_err(|_e| JupiterError::UnknownJupiterInstruction.into()) } "b0d169a89a7d453e" => { // sharedAccountsExactOutRoute methodId = sighash(SIGHASH_GLOBAL_NAMESPACE, "shared_accounts_exact_out_route") borsh::from_slice::(ix_data) .map(JupiterInstructions::SharedAccountsExactOutRoute) - .map_err(|e| JupiterError::UnknownJupiterInstruction.into()) + .map_err(|_e| JupiterError::UnknownJupiterInstruction.into()) } _ => Err(JupiterError::UnknownJupiterInstruction.into()), } From 7de3ede7d99b5171aee3e647208ffe38fb4d5dd2 Mon Sep 17 00:00:00 2001 From: soralit Date: Thu, 26 Dec 2024 09:47:20 +0800 Subject: [PATCH 30/31] style: fix warnings --- rust/apps/arweave/src/data_item.rs | 1 + rust/apps/bitcoin/src/lib.rs | 2 +- .../src/transactions/psbt/wrapped_psbt.rs | 2 +- rust/apps/cardano/src/structs.rs | 49 ++++++------------- rust/apps/stellar/src/strkeys.rs | 1 + rust/apps/ton/src/messages/jetton.rs | 2 +- rust/apps/ton/src/messages/nft.rs | 2 +- rust/apps/ton/src/vendor/message/jetton.rs | 2 + rust/apps/ton/src/vendor/message/transfer.rs | 2 + rust/apps/ton/src/vendor/wallet/mod.rs | 2 + rust/rust_c/src/stellar/mod.rs | 2 +- .../wallet/multi_coins_wallet/arconnect.rs | 4 +- rust/zcash_vendor/src/pczt_ext.rs | 4 ++ 13 files changed, 33 insertions(+), 42 deletions(-) diff --git a/rust/apps/arweave/src/data_item.rs b/rust/apps/arweave/src/data_item.rs index 45466900b..83a0d9753 100644 --- a/rust/apps/arweave/src/data_item.rs +++ b/rust/apps/arweave/src/data_item.rs @@ -85,6 +85,7 @@ impl_public_struct!(DataItem { raw_data: Vec }); +#[allow(unused)] enum SignatureType { ARWEAVE = 1, ED25519, diff --git a/rust/apps/bitcoin/src/lib.rs b/rust/apps/bitcoin/src/lib.rs index 2e1173ed3..955fc914c 100644 --- a/rust/apps/bitcoin/src/lib.rs +++ b/rust/apps/bitcoin/src/lib.rs @@ -114,7 +114,7 @@ pub fn sign_raw_tx( let signed_tx = sign_legacy_tx(tx_data, seed)?; Ok(( hex::encode(signed_tx), - tx_data.transaction.txid().to_string(), + tx_data.transaction.compute_txid().to_string(), )) } diff --git a/rust/apps/bitcoin/src/transactions/psbt/wrapped_psbt.rs b/rust/apps/bitcoin/src/transactions/psbt/wrapped_psbt.rs index dcf4fca3e..3a5105926 100644 --- a/rust/apps/bitcoin/src/transactions/psbt/wrapped_psbt.rs +++ b/rust/apps/bitcoin/src/transactions/psbt/wrapped_psbt.rs @@ -104,7 +104,7 @@ impl WrappedPsbt { .input .get(index) .ok_or(BitcoinError::InvalidInput)?; - if !tx_in.previous_output.txid.eq(&prev_tx.txid()) { + if !tx_in.previous_output.txid.eq(&prev_tx.compute_txid()) { return Err(BitcoinError::InvalidInput); } let prevout = prev_tx.output.get(tx_in.previous_output.vout as usize); diff --git a/rust/apps/cardano/src/structs.rs b/rust/apps/cardano/src/structs.rs index 5d085c03e..5a40ee92a 100644 --- a/rust/apps/cardano/src/structs.rs +++ b/rust/apps/cardano/src/structs.rs @@ -11,6 +11,7 @@ use cardano_serialization_lib::protocol_types::{ use cardano_serialization_lib::protocol_types::DRepKind; +use cardano_serialization_lib::CredKind; use cardano_serialization_lib::{ protocol_types::FixedTransaction as Transaction, protocol_types::VoteKind, NetworkIdKind, }; @@ -100,6 +101,7 @@ const LABEL_POOL: &str = "Pool"; const LABEL_DEPOSIT: &str = "Deposit"; const LABEL_DREP: &str = "DRep"; const LABEL_VOTE: &str = "Vote"; +#[allow(unused)] const LABEL_ABCHOR: &str = "Anchor"; const LABEL_ANCHOR_URL: &str = "Anchor URL"; const LABEL_ANCHOR_DATA_HASH: &str = "Anchor Data Hash"; @@ -150,29 +152,6 @@ impl_public_struct!(ParsedCardanoMultiAsset { value: u64 }); -#[derive(Clone)] -enum CardanoCertAction { - Registration(Registration), - Deregistration(Deregistration), - Delegation(Delegation), -} - -#[derive(Clone)] -struct Registration { - stake_key: RewardAddress, -} - -#[derive(Clone)] -struct Deregistration { - stake_key: RewardAddress, -} - -#[derive(Clone)] -struct Delegation { - pool: String, - stake_key: RewardAddress, -} - impl ParsedCardanoSignData { pub fn build(sign_data: Vec, derivation_path: String, xpub: String) -> R { let sign_structure = CardanoSignStructure::from_cbor(sign_data.clone()); @@ -505,12 +484,12 @@ impl ParsedCardanoTx { CertField { label: LABEL_HOT_KEY.to_string(), value: match _cert.committee_hot_credential().kind() { - _Ed25519KeyHash => _cert + CredKind::Key => _cert .committee_hot_credential() .to_keyhash() .unwrap() .to_string(), - _ScriptHash => _cert + CredKind::Script => _cert .committee_hot_credential() .to_scripthash() .unwrap() @@ -520,12 +499,12 @@ impl ParsedCardanoTx { CertField { label: LABEL_COLD_KEY.to_string(), value: match _cert.committee_cold_credential().kind() { - _Ed25519KeyHash => _cert + CredKind::Key => _cert .committee_cold_credential() .to_keyhash() .unwrap() .to_string(), - _ScriptHash => _cert + CredKind::Script => _cert .committee_cold_credential() .to_scripthash() .unwrap() @@ -542,12 +521,12 @@ impl ParsedCardanoTx { let mut fields = vec![CertField { label: LABEL_COLD_KEY.to_string(), value: match _cert.committee_cold_credential().kind() { - _Ed25519KeyHash => _cert + CredKind::Key => _cert .committee_cold_credential() .to_keyhash() .unwrap() .to_string(), - _ScriptHash => _cert + CredKind::Script => _cert .committee_cold_credential() .to_scripthash() .unwrap() @@ -572,7 +551,7 @@ impl ParsedCardanoTx { if let Some(_cert) = cert.as_drep_deregistration() { let deposit = normalize_coin(u64::from(&_cert.coin())); let (variant1, variant1_label) = match _cert.voting_credential().kind() { - _Ed25519KeyHash => ( + CredKind::Key => ( _cert .voting_credential() .to_keyhash() @@ -581,7 +560,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - _ScriptHash => ( + CredKind::Script => ( _cert .voting_credential() .to_scripthash() @@ -609,7 +588,7 @@ impl ParsedCardanoTx { if let Some(_cert) = cert.as_drep_registration() { let deposit = normalize_coin(u64::from(&_cert.coin())); let (variant1, variant1_label) = match _cert.voting_credential().kind() { - _Ed25519KeyHash => ( + CredKind::Key => ( _cert .voting_credential() .to_keyhash() @@ -618,7 +597,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - _ScriptHash => ( + CredKind::Script => ( _cert .voting_credential() .to_scripthash() @@ -660,7 +639,7 @@ impl ParsedCardanoTx { if let Some(_cert) = cert.as_drep_update() { let anchor_data_hash = _cert.anchor().map(|anchor| anchor.anchor_data_hash().to_string()); let (variant1, variant1_label) = match _cert.voting_credential().kind() { - _Ed25519KeyHash => ( + CredKind::Key => ( _cert .voting_credential() .to_keyhash() @@ -669,7 +648,7 @@ impl ParsedCardanoTx { .map_err(|e| CardanoError::InvalidTransaction(e.to_string()))?, LABEL_DREP.to_string(), ), - _ScriptHash => ( + CredKind::Script => ( _cert .voting_credential() .to_scripthash() diff --git a/rust/apps/stellar/src/strkeys.rs b/rust/apps/stellar/src/strkeys.rs index 86e8f8168..47e9b6ed3 100644 --- a/rust/apps/stellar/src/strkeys.rs +++ b/rust/apps/stellar/src/strkeys.rs @@ -5,6 +5,7 @@ use keystore::algorithms::ed25519::slip10_ed25519::get_private_key_by_seed; use keystore::errors::Result; #[derive(Clone, Copy, Debug, PartialEq)] +#[allow(non_camel_case_types)] pub enum StrKeyType { STRKEY_PUBKEY = 6 << 3, STRKEY_PRIVKEY = 18 << 3, diff --git a/rust/apps/ton/src/messages/jetton.rs b/rust/apps/ton/src/messages/jetton.rs index c7f931c5e..9db4469fb 100644 --- a/rust/apps/ton/src/messages/jetton.rs +++ b/rust/apps/ton/src/messages/jetton.rs @@ -21,6 +21,7 @@ pub const JETTON_TRANSFER: u32 = 0xf8a7ea5; // pub const JETTON_BURN_NOTIFICATION: u32 = 0x7bdd97de; #[derive(Clone, Debug, Serialize)] +#[non_exhaustive] pub enum JettonMessage { JettonTransferMessage(JettonTransferMessage), } @@ -87,7 +88,6 @@ impl ParseCell for JettonTransferMessage { let comment = Comment::parse(child); let payload = Some(hex::encode(child.data.clone())); - ref_index += 1; (payload, comment.ok()) } else { (None, None) diff --git a/rust/apps/ton/src/messages/nft.rs b/rust/apps/ton/src/messages/nft.rs index 8261deddc..e47716268 100644 --- a/rust/apps/ton/src/messages/nft.rs +++ b/rust/apps/ton/src/messages/nft.rs @@ -10,6 +10,7 @@ use super::{traits::ParseCell, Comment}; pub const NFT_TRANSFER: u32 = 0x5fcc3d14; #[derive(Clone, Debug, Serialize)] +#[non_exhaustive] pub enum NFTMessage { NFTTransferMessage(NFTTransferMessage), } @@ -67,7 +68,6 @@ impl ParseCell for NFTTransferMessage { let comment = Comment::parse(child); let payload = Some(hex::encode(child.data.clone())); - ref_index += 1; (payload, comment.ok()) } else { (None, None) diff --git a/rust/apps/ton/src/vendor/message/jetton.rs b/rust/apps/ton/src/vendor/message/jetton.rs index 4ac6985e2..9fe74131c 100644 --- a/rust/apps/ton/src/vendor/message/jetton.rs +++ b/rust/apps/ton/src/vendor/message/jetton.rs @@ -1,3 +1,5 @@ +#![allow(unused)] + use alloc::sync::Arc; use num_bigint::BigUint; diff --git a/rust/apps/ton/src/vendor/message/transfer.rs b/rust/apps/ton/src/vendor/message/transfer.rs index 9040cdd08..002eac3fc 100644 --- a/rust/apps/ton/src/vendor/message/transfer.rs +++ b/rust/apps/ton/src/vendor/message/transfer.rs @@ -1,3 +1,5 @@ +#![allow(unused)] + use alloc::sync::Arc; use num_bigint::BigUint; diff --git a/rust/apps/ton/src/vendor/wallet/mod.rs b/rust/apps/ton/src/vendor/wallet/mod.rs index c343dbb8f..df3822859 100644 --- a/rust/apps/ton/src/vendor/wallet/mod.rs +++ b/rust/apps/ton/src/vendor/wallet/mod.rs @@ -55,6 +55,7 @@ impl WalletVersion { Ok(Arc::new(data_cell)) } + #[allow(unused)] pub fn has_op(&self) -> bool { matches!(self, WalletVersion::V4R2) } @@ -69,6 +70,7 @@ pub struct TonWallet { } impl TonWallet { + #[allow(unused)] pub fn derive( workchain: i32, version: WalletVersion, diff --git a/rust/rust_c/src/stellar/mod.rs b/rust/rust_c/src/stellar/mod.rs index 2b840598a..d23855c2e 100644 --- a/rust/rust_c/src/stellar/mod.rs +++ b/rust/rust_c/src/stellar/mod.rs @@ -81,7 +81,7 @@ fn build_signature_data( sign_request: StellarSignRequest, ) -> PtrT { let data = StellarSignature::new(sign_request.get_request_id(), signature.to_vec()) - .to_bytes() + .try_into() .unwrap(); UREncodeResult::encode( data, diff --git a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs index e8009941f..41da4736f 100644 --- a/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs +++ b/rust/rust_c/src/wallet/multi_coins_wallet/arconnect.rs @@ -42,7 +42,7 @@ pub extern "C" fn get_connect_arconnect_wallet_ur( device, ); UREncodeResult::encode( - arweave_account.to_bytes().unwrap(), + arweave_account.try_into().unwrap(), ArweaveCryptoAccount::get_registry_type().get_type(), FRAGMENT_MAX_LENGTH_DEFAULT, ) @@ -65,7 +65,7 @@ pub extern "C" fn get_connect_arconnect_wallet_ur_from_xpub( device, ); UREncodeResult::encode( - arweave_account.to_bytes().unwrap(), + arweave_account.try_into().unwrap(), ArweaveCryptoAccount::get_registry_type().get_type(), FRAGMENT_MAX_LENGTH_DEFAULT, ) diff --git a/rust/zcash_vendor/src/pczt_ext.rs b/rust/zcash_vendor/src/pczt_ext.rs index c259f2962..e08e9e25d 100644 --- a/rust/zcash_vendor/src/pczt_ext.rs +++ b/rust/zcash_vendor/src/pczt_ext.rs @@ -42,8 +42,11 @@ const ZCASH_SAPLING_OUTPUTS_COMPACT_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdSOu const ZCASH_SAPLING_OUTPUTS_MEMOS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdSOutM__Hash"; const ZCASH_SAPLING_OUTPUTS_NONCOMPACT_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdSOutN__Hash"; +#[allow(unused)] const ZCASH_AUTH_PERSONALIZATION_PREFIX: &[u8; 12] = b"ZTxAuthHash_"; +#[allow(unused)] const ZCASH_AUTH_SCRIPTS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxAuthTransHash"; +#[allow(unused)] const ZCASH_SAPLING_SIGS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxAuthSapliHash"; #[cfg(zcash_unstable = "zfuture")] const ZCASH_TZE_WITNESSES_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxAuthTZE__Hash"; @@ -52,6 +55,7 @@ const ZCASH_ORCHARD_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrchardHash"; const ZCASH_ORCHARD_ACTIONS_COMPACT_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcActCHash"; const ZCASH_ORCHARD_ACTIONS_MEMOS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcActMHash"; const ZCASH_ORCHARD_ACTIONS_NONCOMPACT_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcActNHash"; +#[allow(unused)] const ZCASH_ORCHARD_SIGS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxAuthOrchaHash"; const ZCASH_TRANSPARENT_INPUT_HASH_PERSONALIZATION: &[u8; 16] = b"Zcash___TxInHash"; From f4562889de89f143a1b68a02b43207cb5c3df0b5 Mon Sep 17 00:00:00 2001 From: soralit Date: Thu, 26 Dec 2024 14:29:24 +0800 Subject: [PATCH 31/31] chore: add defines --- rust/rust_c/Cargo.toml | 22 +++++++++++----------- rust/rust_c/build.rs | 35 +++++++++++++++++++++++++++++++++++ rust/rust_c/cbindgen.toml | 6 +++++- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/rust/rust_c/Cargo.toml b/rust/rust_c/Cargo.toml index 5a222bd2c..da3d035f8 100644 --- a/rust/rust_c/Cargo.toml +++ b/rust/rust_c/Cargo.toml @@ -81,23 +81,23 @@ test_cmd = [] debug-memory = ["multi-coins"] multi-coins = [ - "bitcoin", - "ethereum", - "solana", "aptos", - "near", - "cosmos", + "arweave", + "bch", + "bitcoin", "cardano", + "cosmos", + "dash", + "ethereum", + "ltc", + "near", + "solana", + "stellar", "sui", + "ton", "tron", "xrp", - "arweave", - "stellar", - "ton", "zcash", - "ltc", - "dash", - "bch", ] btc-only = ["bitcoin"] diff --git a/rust/rust_c/build.rs b/rust/rust_c/build.rs index ecf326adc..325d81c0c 100644 --- a/rust/rust_c/build.rs +++ b/rust/rust_c/build.rs @@ -17,6 +17,41 @@ fn main() { #[cfg(feature = "debug-btc-only")] "debug-btc-only", ]; + config.after_includes = config.after_includes.map(|mut v| { + #[cfg(feature = "aptos")] + v.push_str("#define FEATURE_APTOS\n"); + #[cfg(feature = "arweave")] + v.push_str("#define FEATURE_ARWEAVE\n"); + #[cfg(feature = "bch")] + v.push_str("#define FEATURE_BCH\n"); + #[cfg(feature = "bitcoin")] + v.push_str("#define FEATURE_BITCOIN\n"); + #[cfg(feature = "cardano")] + v.push_str("#define FEATURE_CARDANO\n"); + #[cfg(feature = "cosmos")] + v.push_str("#define FEATURE_COSMOS\n"); + #[cfg(feature = "dash")] + v.push_str("#define FEATURE_DASH\n"); + #[cfg(feature = "ethereum")] + v.push_str("#define FEATURE_ETHEREUM\n"); + #[cfg(feature = "ltc")] + v.push_str("#define FEATURE_LTC\n"); + #[cfg(feature = "near")] + v.push_str("#define FEATURE_NEAR\n"); + #[cfg(feature = "solana")] + v.push_str("#define FEATURE_SOLANA\n"); + #[cfg(feature = "stellar")] + v.push_str("#define FEATURE_STELLAR\n"); + #[cfg(feature = "ton")] + v.push_str("#define FEATURE_TON\n"); + #[cfg(feature = "tron")] + v.push_str("#define FEATURE_TRON\n"); + #[cfg(feature = "xrp")] + v.push_str("#define FEATURE_XRP\n"); + #[cfg(feature = "zcash")] + v.push_str("#define FEATURE_ZCASH\n"); + v + }); assert!(!features.is_empty(), "No build variant enabled"); assert!( features.len() == 1, diff --git a/rust/rust_c/cbindgen.toml b/rust/rust_c/cbindgen.toml index af0fe7866..ae2d7d1c0 100644 --- a/rust/rust_c/cbindgen.toml +++ b/rust/rust_c/cbindgen.toml @@ -1,17 +1,21 @@ include_guard = "_LIBRUST_C_H" -after_includes = "#define BUILD_MULTI_COINS\n#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32" +after_includes = "#define BUILD_MULTI_COINS\n#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MAX_LEN 256\n#define PATH_ITEM_MAX_LEN 32\n" language = "C" [defines] "feature = multi-coins" = "BUILD_MULTI_COINS" + "feature = aptos" = "FEATURE_APTOS" "feature = arweave" = "FEATURE_ARWEAVE" +"feature = bch" = "FEATURE_BCH" "feature = bitcoin" = "FEATURE_BITCOIN" "feature = cardano" = "FEATURE_CARDANO" "feature = cosmos" = "FEATURE_COSMOS" +"feature = dash" = "FEATURE_DASH" "feature = ethereum" = "FEATURE_ETHEREUM" +"feature = ltc" = "FEATURE_LTC" "feature = near" = "FEATURE_NEAR" "feature = solana" = "FEATURE_SOLANA" "feature = stellar" = "FEATURE_STELLAR"