Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/support leap wallet #93

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion libs/ur-parse-lib/src/keystone_ur_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,18 @@ mod tests {
res.data
)
}

//
#[test]
fn test_encode_sol_hardware_call() {
let data = "a4010002d90515a10184d90516a301d90130a10186182cf5183cf500f502000463455448d90516a301d90130a10186182cf51901f5f500f502010463534f4cd90516a301d90130a10186182cf51901f5f501f502000463534f4cd90516a301d90130a1018a182cf51901f5f500f500f400f402010463534f4c036b4c6561702057616c6c65740401";
let data = Vec::from_hex(data).unwrap();
// hardware call
let res = probe_encode(&data, 400, QRHardwareCall::get_registry_type().get_type()).unwrap();
assert_eq!(
"ur:qr-hardware-call/oxadaeaotaahbzoyadlrtaahcmotadtaaddyoyadlncsdwykcsfnykaeykaoaeaaiafeghfdtaahcmotadtaaddyoyadlncsdwykcfadykykaeykaoadaaiagugwgstaahcmotadtaaddyoyadlncsdwykcfadykykadykaoaeaaiagugwgstaahcmotadtaaddyoyadlecsdwykcfadykykaeykaewkaewkaoadaaiagugwgsaxjegsihhsjocxhghsjzjzihjyaaadfnfxcmfy",
res.data
)
}
#[test]
fn test_encode_cosmos_hardware_call() {
let data = "a3010002d90515a10182d90516a101d90130a10186182cf500f500f5d90516a201d90130a1018a182cf51901f5f500f500f500f502010400";
Expand Down
17 changes: 6 additions & 11 deletions libs/ur-registry-ffi/src/cardano/cardano_sign_request.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use hex;
use serde::Deserialize;
use serde_json::json;
use ur_registry::cardano::cardano_cert_key::CardanoCertKey;
use ur_registry::cardano::cardano_sign_request::CardanoSignRequest;
use ur_registry::cardano::cardano_utxo::CardanoUTXO;
use ur_registry::crypto_key_path::CryptoKeyPath;
use ur_registry::cardano::cardano_utxo::{CardanoUTXO};
use ur_registry::cardano::cardano_cert_key::{CardanoCertKey};
use uuid::Uuid;
use ur_registry::cardano::cardano_sign_request::CardanoSignRequest;
use serde::Deserialize;

use crate::export;
use crate::util_internal::string_helper::remove_prefix_0x;
Expand Down Expand Up @@ -154,7 +154,6 @@ export! {
}
}


#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -193,9 +192,7 @@ mod tests {

assert_eq!(
expect_result,
generate_cardano_sign_request(
request_id, sign_data, utxos, cert_keys, origin
)
generate_cardano_sign_request(request_id, sign_data, utxos, cert_keys, origin)
);
}

Expand Down Expand Up @@ -226,9 +223,7 @@ mod tests {

assert_eq!(
expect_result,
generate_cardano_sign_request(
request_id, sign_data, utxos, cert_keys, origin
)
generate_cardano_sign_request(request_id, sign_data, utxos, cert_keys, origin)
);
}
}
31 changes: 26 additions & 5 deletions libs/ur-registry-ffi/src/evm/evm_sign_request.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use hex;
use serde::Deserialize;
use serde_json::json;
use ur_registry::crypto_key_path::CryptoKeyPath;
use uuid::Uuid;
use ur_registry::cosmos::evm_sign_request::{EvmSignRequest, SignDataType};
use ur_registry::crypto_key_path::CryptoKeyPath;
use ur_registry::registry_types::EVM_SIGN_REQUEST;
use uuid::Uuid;

use crate::export;
use crate::util_internal::string_helper::remove_prefix_0x;
Expand Down Expand Up @@ -115,7 +115,14 @@ mod tests {

assert_eq!(
expect_result,
generate_evm_sign_request(request_id, sign_data, data_type, custom_chain_identifier, account, origin)
generate_evm_sign_request(
request_id,
sign_data,
data_type,
custom_chain_identifier,
account,
origin
)
);
}

Expand All @@ -132,7 +139,14 @@ mod tests {

assert_eq!(
expect_result,
generate_evm_sign_request(request_id, sign_data, data_type, custom_chain_identifier, account, origin)
generate_evm_sign_request(
request_id,
sign_data,
data_type,
custom_chain_identifier,
account,
origin
)
);
}

Expand All @@ -155,7 +169,14 @@ mod tests {

assert_eq!(
expect_result,
generate_evm_sign_request(request_id, sign_data, data_type, custom_chain_identifier, account, origin)
generate_evm_sign_request(
request_id,
sign_data,
data_type,
custom_chain_identifier,
account,
origin
)
);
}
}
2 changes: 1 addition & 1 deletion libs/ur-registry-ffi/src/evm/evm_signature.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Error;
use hex;
use serde_json::json;
use ur_registry::{registry_types::EVM_SIGNATURE, cosmos::evm_signature::EvmSignature};
use ur_registry::{cosmos::evm_signature::EvmSignature, registry_types::EVM_SIGNATURE};
use uuid::Uuid;

use crate::export;
Expand Down
13 changes: 6 additions & 7 deletions libs/ur-registry-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
pub mod aptos;
pub mod arweave;
pub mod bitcoin;
pub mod cardano;
pub mod cosmos;
pub mod evm;
pub mod ethereum;
pub mod evm;
mod export;
pub mod sync;
pub mod keystone;
pub mod near;
pub mod solana;
pub mod stellar;
pub mod sui;
pub mod sync;
pub mod ton;
pub mod tron;
pub mod cardano;
mod util_internal;
pub mod utils;
pub mod sui;
pub mod ton;
pub mod stellar;


ffi_support::define_string_destructor!(keystone_sdk_destroy_string);
12 changes: 9 additions & 3 deletions libs/ur-registry-ffi/src/stellar/stellar_sign_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ mod tests {

assert_eq!(
expect_result,
generate_stellar_sign_request(request_id, sign_data, path, xfp, address, origin, sign_type)
generate_stellar_sign_request(
request_id, sign_data, path, xfp, address, origin, sign_type
)
);
}

Expand All @@ -105,7 +107,9 @@ mod tests {

assert_eq!(
err_result_derivation_path,
generate_stellar_sign_request(request_id, sign_data, path, xfp, address, origin, sign_type)
generate_stellar_sign_request(
request_id, sign_data, path, xfp, address, origin, sign_type
)
);
}

Expand All @@ -123,7 +127,9 @@ mod tests {

assert_eq!(
err_result,
generate_stellar_sign_request(request_id, sign_data, path, xfp, address, origin, sign_type)
generate_stellar_sign_request(
request_id, sign_data, path, xfp, address, origin, sign_type
)
);
}
}
2 changes: 1 addition & 1 deletion libs/ur-registry-ffi/src/sui/sui_signature.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Error;
use hex;
use serde_json::json;
use ur_registry::sui::sui_signature::SuiSignature;
use ur_registry::registry_types::SUI_SIGNATURE;
use ur_registry::sui::sui_signature::SuiSignature;
use uuid::Uuid;

use crate::export;
Expand Down
6 changes: 3 additions & 3 deletions libs/ur-registry-ffi/src/sync/crypto_account.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::export;
use crate::sync::crypto_multi_accounts::MultiAccounts;
use anyhow::format_err;
use anyhow::Error;
use hex;
use serde_json::json;
use ur_registry::crypto_account::CryptoAccount;
use ur_registry::crypto_output::CryptoOutput;
use ur_registry::registry_types::{CRYPTO_ACCOUNT};
use ur_registry::registry_types::CRYPTO_ACCOUNT;
use ur_registry::traits::From;
use crate::sync::crypto_multi_accounts::MultiAccounts;

impl Into<MultiAccounts> for CryptoAccount {
fn into(self) -> MultiAccounts {
Expand All @@ -22,7 +22,7 @@ impl Into<MultiAccounts> for CryptoAccount {
keys: hd_keys,
device: None,
device_id: None,
device_version: None
device_version: None,
}
}
}
Expand Down
27 changes: 16 additions & 11 deletions libs/ur-registry-ffi/src/sync/crypto_hd_key.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
use crate::export;
use crate::util_internal::account_helper::gen_extra_data;
use crate::util_internal::chain::map_coin_type;
use anyhow::format_err;
use anyhow::Error;
use hex;
use serde::{Deserialize, Serialize};
use serde_json::json;
use ur_registry::crypto_hd_key::CryptoHDKey;
use ur_registry::registry_types::{CRYPTO_HDKEY};
use ur_registry::registry_types::CRYPTO_HDKEY;
use ur_registry::traits::From;
use crate::util_internal::account_helper::gen_extra_data;
use crate::util_internal::chain::map_coin_type;


#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct OkxExtra {
pub chain_id: u32
pub chain_id: u32,
}

#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct AccountExtra {
pub okx: OkxExtra
pub okx: OkxExtra,
}

#[derive(Default, Clone, Debug, Serialize, Deserialize)]
Expand All @@ -33,7 +32,7 @@ pub struct Account {
note: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
xfp: Option<String>,
extra: AccountExtra
extra: AccountExtra,
}

impl core::convert::From<&CryptoHDKey> for Account {
Expand All @@ -59,8 +58,15 @@ impl core::convert::From<&CryptoHDKey> for Account {
xpub = value.get_bip32_key();
}

let source_fingerprint = value.get_origin().unwrap_or_default().get_source_fingerprint();
let xfp = if source_fingerprint.is_some() { Some(hex::encode(source_fingerprint.unwrap())) } else { None };
let source_fingerprint = value
.get_origin()
.unwrap_or_default()
.get_source_fingerprint();
let xfp = if source_fingerprint.is_some() {
Some(hex::encode(source_fingerprint.unwrap()))
} else {
None
};

Account {
chain: map_coin_type(coin_type),
Expand All @@ -71,12 +77,11 @@ impl core::convert::From<&CryptoHDKey> for Account {
extended_public_key: xpub,
note: value.get_note(),
xfp,
extra: gen_extra_data(coin_type)
extra: gen_extra_data(coin_type),
}
}
}


export! {
@Java_com_keystone_sdk_KeystoneNativeSDK_parseCryptoHDKey
fn parse_crypto_hd_key(ur_type: &str, cbor_hex: &str) -> String {
Expand Down
2 changes: 1 addition & 1 deletion libs/ur-registry-ffi/src/sync/crypto_multi_accounts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::export;
use crate::sync::crypto_hd_key::Account;
use anyhow::format_err;
use anyhow::Error;
use hex;
Expand All @@ -7,7 +8,6 @@ use serde_json::json;
use ur_registry::extend::crypto_multi_accounts::CryptoMultiAccounts;
use ur_registry::registry_types::CRYPTO_MULTI_ACCOUNTS;
use ur_registry::traits::From;
use crate::sync::crypto_hd_key::Account;

pub type Bytes = Vec<u8>;
pub type Fingerprint = [u8; 4];
Expand Down
2 changes: 1 addition & 1 deletion libs/ur-registry-ffi/src/sync/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod crypto_hd_key;
pub mod crypto_account;
pub mod crypto_hd_key;
pub mod crypto_multi_accounts;
2 changes: 1 addition & 1 deletion libs/ur-registry-ffi/src/ton/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod ton_sign_request;
pub mod ton_signature;
pub mod ton_signature;
2 changes: 1 addition & 1 deletion libs/ur-registry-ffi/src/ton/ton_signature.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Error;
use hex;
use serde_json::json;
use ur_registry::ton::ton_signature::TonSignature;
use ur_registry::registry_types::TON_SIGNATURE;
use ur_registry::ton::ton_signature::TonSignature;
use uuid::Uuid;

use crate::export;
Expand Down
7 changes: 4 additions & 3 deletions libs/ur-registry-ffi/src/util_internal/account_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ fn okx_chain_id_map(coin_type: u32) -> u32 {
pub fn gen_extra_data(coin_type: u32) -> AccountExtra {
let okx_chain_id = okx_chain_id_map(coin_type);
return AccountExtra {
okx: OkxExtra { chain_id: okx_chain_id },
}
okx: OkxExtra {
chain_id: okx_chain_id,
},
};
}

#[cfg(test)]
Expand All @@ -26,7 +28,6 @@ mod tests {
assert_eq!(expect_chain_id, gen_extra_data(coin_type).okx.chain_id);
}


#[test]
fn test_map_eth_chain_id_to_1() {
let coin_type = 60;
Expand Down
2 changes: 1 addition & 1 deletion libs/ur-registry-ffi/src/util_internal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod chain;
pub mod account_helper;
pub mod chain;
pub mod string_helper;
4 changes: 1 addition & 3 deletions libs/ur-registry-ffi/src/util_internal/string_helper.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
pub fn remove_prefix<'a>(s: &'a str, prefix: &str) -> &'a str {
match s.strip_prefix(prefix) {
Some(s) => s,
None => s
None => s,
}
}


pub fn remove_prefix_0x(s: &str) -> &str {
remove_prefix(s, "0x")
}


#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading
Loading