Skip to content

Commit

Permalink
Add UniFFI exported "method" for DerivationPath `to_canonical_bip32…
Browse files Browse the repository at this point in the history
…_string` (#348)
  • Loading branch information
micbakos-rdx authored Jan 22, 2025
1 parent 7b6476e commit 0365519
Show file tree
Hide file tree
Showing 82 changed files with 630 additions and 245 deletions.
166 changes: 83 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0" }


# ==== EXTERNAL DEPENDENCIES ====
actix-rt = { version = "2.10.0", default-features = false, features = ["macros"] }
actix-rt = { version = "2.10.0", default-features = false, features = [
"macros",
] }
aes-gcm = { version = "=0.10.3", default-features = false, features = [
"aes",
"alloc",
Expand All @@ -331,7 +333,7 @@ bip39 = { version = "=2.0.0", default-features = true, features = [

camino = { version = "1.0.8", default-features = false }
cargo_toml = { version = "0.15.3", default-features = false }
clap = { version = "4.5.1", default-features = false, features = [
clap = { version = "4.5.1", default-features = false, features = [
"std",
"derive",
] }
Expand Down Expand Up @@ -370,22 +372,26 @@ log = { version = "0.4.20", default-features = false }
once_cell = { version = "1.19.0", default-features = false }
paste = { version = "1.0.14", default-features = false }
preinterpret = { version = "0.2.0", default-features = false }
pretty_assertions = { version = "1.4.0", default-features = false, features = ["std"] }
pretty_assertions = { version = "1.4.0", default-features = false, features = [
"std",
] }
pretty_env_logger = { version = "0.5.0", default-features = false }
rand = { version = "0.8.5", default-features = false, features = ["getrandom"] }
regex = { version = "1.9.3", default-features = false }
reqwest = { version = "0.12.3", default-features = false, features = [
"native-tls-vendored",
] }
serde_with = { version = "3.4.0", default-features = false }
serde = { version = "1.0.193", default-features = false, features = ["derive", "rc", "std"] }
serde = { version = "1.0.193", default-features = false, features = [
"derive",
"rc",
"std",
] }
serde_json = { version = "1.0.108", default-features = false, features = [
"preserve_order",
] }
serde_repr = { version = "0.1.17", default-features = false }
strum = { version = "0.26.1", default-features = false, features = [
"derive",
] }
strum = { version = "0.26.1", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.50", default-features = false }
url = { version = "2.5.0", default-features = false, features = ["serde"] }
uniffi = { git = "https://github.com/mozilla/uniffi-rs/", rev = "9127d4d9cfb8ff8372e70f2e4e0eb36bc06f146d", features = [
Expand Down
2 changes: 1 addition & 1 deletion crates/app/home-cards/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "home-cards"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/key-derivation-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "key-derivation-traits"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/radix-connect-models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-connect-models"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/radix-connect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-connect"
version = "1.1.114"
version = "1.1.115"
edition = "2021"


Expand Down
2 changes: 1 addition & 1 deletion crates/app/security-center/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "security-center"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/signing-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "signing-traits"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/signing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "signing"
version = "1.1.114"
version = "1.1.115"
edition = "2021"


Expand Down
2 changes: 1 addition & 1 deletion crates/common/build-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "build-info"
version = "1.1.114"
version = "1.1.115"
edition = "2021"
build = "build.rs"

Expand Down
2 changes: 1 addition & 1 deletion crates/common/bytes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bytes"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/entity-foundation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "entity-foundation"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/host-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "host-info"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/identified-vec-of/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "identified-vec-of"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/metadata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "metadata"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/network/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "network"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/numeric/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "numeric"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/short-string/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "short-string"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/assert-json/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "assert-json"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/collections/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-collections"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/error/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "error"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/has-sample-values/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "has-sample-values"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/misc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-misc"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/prelude/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prelude"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/time-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "time-utils"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-utils"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/addresses/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "addresses"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/cap26-models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cap26-models"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/ecc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ecc"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/encryption/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "encryption"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/hash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hash"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/hd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hierarchical-deterministic"
version = "1.1.114"
version = "1.1.115"
edition = "2021"

[dependencies]
Expand Down
42 changes: 36 additions & 6 deletions crates/crypto/hd/src/bip32/hd_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,57 @@ impl HDPath {
pub const SEPARATOR: &str = "/";
fn to_string_map_with<F>(&self, include_head: bool, map: F) -> String
where
F: Fn(&HDPathComponent) -> String,
F: Fn((usize, &HDPathComponent)) -> String,
{
let head = "m".to_owned();
let mut path = self.components().iter().map(map).collect_vec();
let mut path =
self.components().iter().enumerate().map(map).collect_vec();
if include_head {
path.splice(0..0, vec![head]);
}
path.into_iter().join(Self::SEPARATOR)
}

pub fn to_bip32_string_with(&self, include_head: bool) -> String {
self.to_string_map_with(include_head, |c| format!("{}", c))
pub fn to_bip32_string_with(
&self,
include_head: bool,
canonicalize_entity_index: bool,
) -> String {
self.to_string_map_with(include_head, |(i, c)| {
if canonicalize_entity_index
&& i == CAP26_PATH_ENTITY_INDEX_POS
&& c.is_securified()
{
let securified = c.as_securified().unwrap();
let local = u32::from(securified.index_in_local_key_space());
format!("{}H", local + RELATIVELY_LOCAL_OFFSET_SECURIFIED)
} else {
format!("{}", c)
}
})
}

pub fn to_bip32_string_debug_with(&self, include_head: bool) -> String {
self.to_string_map_with(include_head, |c| format!("{:?}", c))
self.to_string_map_with(include_head, |(_, c)| format!("{:?}", c))
}

/// This method returns the canonical bip32 representation of the path.
/// In sargon, paths in the securified space are printed with the `S` notation after the index,
/// for readability purposes.
///
/// The notation `{i}S` means `{i + 2^30}H`, and since `H` means `+ 2^31` we can
/// verbosely express `{i}S` as `{i + 2^30 + 2^31} (without the H)
///
/// Such paths need to be canonicalized in bip32 notation meaning that
/// an index of `"{i}S"` => `"{i + 2^30}H"` when communication with other external APIs,
/// e.g. using Ledger hardware wallet or Arculus.
pub fn to_canonical_bip32_string(&self) -> String {
self.to_bip32_string_with(true, true)
}
}
impl ToBIP32Str for HDPath {
fn to_bip32_string(&self) -> String {
self.to_bip32_string_with(true)
self.to_bip32_string_with(true, false)
}
fn to_bip32_string_debug(&self) -> String {
self.to_bip32_string_debug_with(true)
Expand Down
5 changes: 4 additions & 1 deletion crates/crypto/hd/src/cap26/paths/unvalidated_cap26_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ impl TryFrom<HDPathComponent> for NetworkID {
}
}

pub const CAP26_PATH_ENTITY_INDEX_POS: usize = 5;

impl TryFrom<HDPath> for UnvalidatedCAP26Path {
type Error = CommonError;

Expand Down Expand Up @@ -51,7 +53,8 @@ impl TryFrom<HDPath> for UnvalidatedCAP26Path {
let entity_kind = CAP26EntityKind::try_from(components[3])?;
let key_kind = CAP26KeyKind::try_from(components[4])?;

let hardened = Hardened::try_from(components[5])?;
let hardened =
Hardened::try_from(components[CAP26_PATH_ENTITY_INDEX_POS])?;

Ok(UnvalidatedCAP26Path {
network_id,
Expand Down
Loading

0 comments on commit 0365519

Please sign in to comment.