Skip to content

Commit

Permalink
Swap: Check address is in hex (32 bytes) and not in base58
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Dec 20, 2024
1 parent 5e91134 commit 6f893f1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "near"
version = "2.3.1"
version = "2.3.2"
authors = ["dj8yf0μl", "polyprogrammist"]
edition = "2021"

Expand Down
33 changes: 13 additions & 20 deletions src/swap.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand All @@ -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(
&params.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(&params.ref_address[..params.ref_address_len]);

if address.eq(ref_address.unwrap()) {
res = 1i32;
}
}
Err(_) => {
Expand Down Expand Up @@ -79,7 +73,6 @@ pub fn swap_main(arg0: u32) {

match handle_apdu(&mut comm, ins, &params) {
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));
Expand Down
2 changes: 1 addition & 1 deletion tests/test_version_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6f893f1

Please sign in to comment.