From 6f893f1f1dc62a0a1011535476130c1c0c3e07ff Mon Sep 17 00:00:00 2001 From: GroM Date: Fri, 20 Dec 2024 10:12:25 +0100 Subject: [PATCH] Swap: Check address is in hex (32 bytes) and not in base58 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/swap.rs | 33 +++++++++++++-------------------- tests/test_version_cmd.py | 2 +- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 635277f..8a1c687 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -446,7 +446,7 @@ dependencies = [ [[package]] name = "near" -version = "2.3.1" +version = "2.3.2" dependencies = [ "borsh", "bs58", diff --git a/Cargo.toml b/Cargo.toml index 9ad554b..4fea02f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "near" -version = "2.3.1" +version = "2.3.2" authors = ["dj8yf0μl", "polyprogrammist"] edition = "2021" diff --git a/src/swap.rs b/src/swap.rs index 70e4372..2c3bfa9 100644 --- a/src/swap.rs +++ b/src/swap.rs @@ -1,13 +1,13 @@ -use crate::utils::{ - crypto::{PathBip32, PublicKeyBe}, - types::base58_buf::Base58Buf, -}; +use crate::utils::crypto::{PathBip32, PublicKeyBe}; use near_token::{NearToken, TokenBuffer}; use ledger_device_sdk::{ ecc, io::Comm, - libcall::{self, swap, swap::CreateTxParams}, + libcall::{ + self, + swap::{self, CreateTxParams}, + }, testing::debug_print, }; @@ -27,20 +27,14 @@ pub fn swap_main(arg0: u32) { Ok(path) => match ecc::Ed25519::derive_from_path_slip10(&path.0).public_key() { Ok(pk) => { let pk = PublicKeyBe::from_little_endian(pk); - let mut bs58_buf: Base58Buf<50> = Base58Buf::new(); - match bs58_buf.encode(&pk.0) { - Ok(_) => { - if bs58_buf.as_str().eq(core::str::from_utf8( - ¶ms.ref_address[..params.ref_address_len], - ) - .unwrap()) - { - res = 1i32; - } - } - Err(_) => { - debug_print("PK base58 encoding failure\n"); - } + + let mut buf = [0u8; 64]; + let address = pk.display_str_hex(&mut buf); + let ref_address = + core::str::from_utf8(¶ms.ref_address[..params.ref_address_len]); + + if address.eq(ref_address.unwrap()) { + res = 1i32; } } Err(_) => { @@ -79,7 +73,6 @@ pub fn swap_main(arg0: u32) { match handle_apdu(&mut comm, ins, ¶ms) { Ok(sig) => { - debug_print("send back signature APDU\n"); comm.append(&sig); comm.swap_reply_ok(); swap::swap_return(swap::SwapResult::CreateTxResult(&mut params, 1)); diff --git a/tests/test_version_cmd.py b/tests/test_version_cmd.py index 40bd822..983ee5e 100644 --- a/tests/test_version_cmd.py +++ b/tests/test_version_cmd.py @@ -9,4 +9,4 @@ def test_get_version_cmd(backend): version = client.get_version().data assert len(version) == 3 # Assert that we have received the correct app version compared as Makefile data - assert (version[0], version[1], version[2]) == (2, 3, 1) + assert (version[0], version[1], version[2]) == (2, 3, 2)