From 22a4d574db08939c17c31107372fe0794a165a41 Mon Sep 17 00:00:00 2001 From: Alexander Cyon <116169792+CyonAlexRDX@users.noreply.github.com> Date: Thu, 23 Jan 2025 17:23:18 +0100 Subject: [PATCH] Allow canonical BIP32 string in `FromStr` (#354) * FromStr parsing of DerivationPaths and friends now use 'lenient' parsing - accepting CANONICAL BIP32 string repr. * polish * introduce concept of CAP43 * fix * rename tests * tests and comments * fix Kotlin * Release 1.1.119 account-for-display@1.1.119 addresses@1.1.119 assert-json@1.1.119 build-info@1.1.119 bytes@1.1.119 cap26-models@1.1.119 clients@1.1.119 core-collections@1.1.119 core-misc@1.1.119 core-utils@1.1.119 drivers@1.1.119 ecc@1.1.119 encryption@1.1.119 entity-by-address@1.1.119 entity-foundation@1.1.119 error@1.1.119 factor-instances-provider@1.1.119 factors@1.1.119 factors-supporting-types@1.1.119 gateway-client-and-api@1.1.119 gateway-models@1.1.119 has-sample-values@1.1.119 hash@1.1.119 hierarchical-deterministic@1.1.119 home-cards@1.1.119 host-info@1.1.119 http-client@1.1.119 identified-vec-of@1.1.119 interactors@1.1.119 key-derivation-traits@1.1.119 keys-collector@1.1.119 manifests@1.1.119 metadata@1.1.119 network@1.1.119 next-derivation-index-ephemeral@1.1.119 numeric@1.1.119 prelude@1.1.119 profile@1.1.119 profile-account@1.1.119 profile-account-or-persona@1.1.119 profile-app-preferences@1.1.119 profile-base-entity@1.1.119 profile-gateway@1.1.119 profile-logic@1.1.119 profile-persona@1.1.119 profile-persona-data@1.1.119 profile-security-structures@1.1.119 profile-state-holder@1.1.119 profile-supporting-types@1.1.119 radix-connect@1.1.119 radix-connect-models@1.1.119 sargon@1.1.119 sargon-os@1.1.119 sargon-os-accounts@1.1.119 sargon-os-derive-public-keys@1.1.119 sargon-os-factors@1.1.119 sargon-os-security-center@1.1.119 sargon-os-signing@1.1.119 sargon-os-transaction@1.1.119 sargon-uniffi@1.1.119 sargon-uniffi-conversion-macros@1.1.119 security-center@1.1.119 short-string@1.1.119 signing@1.1.119 signing-traits@1.1.119 sub-systems@1.1.119 time-utils@1.1.119 transaction-foundation@1.1.119 transaction-models@1.1.119 Generated by cargo-workspaces --------- Co-authored-by: Matias Bzurovski --- Cargo.lock | 168 +++++++++--------- .../DerivationPath+Wrap+Functions.swift | 10 ++ .../Crypto/DerivationPathTests.swift | 20 +++ crates/app/home-cards/Cargo.toml | 2 +- crates/app/key-derivation-traits/Cargo.toml | 2 +- crates/app/radix-connect-models/Cargo.toml | 2 +- crates/app/radix-connect/Cargo.toml | 2 +- crates/app/security-center/Cargo.toml | 2 +- crates/app/signing-traits/Cargo.toml | 2 +- crates/app/signing/Cargo.toml | 2 +- crates/common/build-info/Cargo.toml | 2 +- crates/common/bytes/Cargo.toml | 2 +- crates/common/entity-foundation/Cargo.toml | 2 +- crates/common/host-info/Cargo.toml | 2 +- crates/common/identified-vec-of/Cargo.toml | 2 +- crates/common/metadata/Cargo.toml | 2 +- crates/common/network/Cargo.toml | 2 +- crates/common/numeric/Cargo.toml | 2 +- crates/common/short-string/Cargo.toml | 2 +- crates/core/assert-json/Cargo.toml | 2 +- crates/core/collections/Cargo.toml | 2 +- crates/core/error/Cargo.toml | 2 +- crates/core/has-sample-values/Cargo.toml | 2 +- crates/core/misc/Cargo.toml | 2 +- crates/core/prelude/Cargo.toml | 2 +- crates/core/time-utils/Cargo.toml | 2 +- crates/core/utils/Cargo.toml | 2 +- crates/crypto/addresses/Cargo.toml | 2 +- crates/crypto/cap26-models/Cargo.toml | 2 +- crates/crypto/ecc/Cargo.toml | 2 +- crates/crypto/encryption/Cargo.toml | 2 +- crates/crypto/hash/Cargo.toml | 2 +- crates/crypto/hd/Cargo.toml | 2 +- crates/crypto/hd/src/bip32/hd_path.rs | 46 +++-- .../crypto/hd/src/bip32/hd_path_component.rs | 30 ++-- .../bip32/key_space/components/hardened.rs | 23 +-- .../bip32/key_space/components/securified.rs | 52 ++++-- .../bip32/key_space/components/unhardened.rs | 10 +- .../key_space/components/unsecurified.rs | 18 +- .../components/unsecurified_hardened.rs | 20 +-- .../hd/src/bip32/key_space/key_space.rs | 8 +- .../hd/src/bip32/traits/from_bip32_str.rs | 90 +++++++--- .../is_path_component_string_convertible.rs | 6 +- .../hd/src/bip32/traits/to_bip32_str.rs | 19 +- crates/crypto/hd/src/bip44/bip44_like_path.rs | 26 +-- .../crypto/hd/src/cap26/paths/account_path.rs | 33 ++-- .../crypto/hd/src/cap26/paths/get_id_path.rs | 14 +- .../hd/src/cap26/paths/identity_path.rs | 22 +-- .../hd/src/derivation/derivation_path.rs | 90 +++++----- crates/factors/factors/Cargo.toml | 2 +- crates/factors/instances-provider/Cargo.toml | 2 +- crates/factors/keys-collector/Cargo.toml | 2 +- .../Cargo.toml | 2 +- .../src/agnostic_paths/index_agnostic_path.rs | 4 +- crates/factors/supporting-types/Cargo.toml | 2 +- crates/gateway/client-and-api/Cargo.toml | 2 +- crates/gateway/models/Cargo.toml | 2 +- .../profile/logic/logic_SPLIT_ME/Cargo.toml | 2 +- .../models/account-for-display/Cargo.toml | 2 +- .../models/account-or-persona/Cargo.toml | 2 +- crates/profile/models/account/Cargo.toml | 2 +- .../profile/models/app-preferences/Cargo.toml | 2 +- crates/profile/models/base-entity/Cargo.toml | 2 +- crates/profile/models/gateway/Cargo.toml | 2 +- crates/profile/models/persona-data/Cargo.toml | 2 +- crates/profile/models/persona/Cargo.toml | 2 +- .../models/profile_SPLIT_ME/Cargo.toml | 2 +- .../models/security-structures/Cargo.toml | 2 +- .../models/supporting-types/Cargo.toml | 2 +- .../traits/entity-by-address/Cargo.toml | 2 +- crates/sargon/Cargo.toml | 2 +- crates/sargon/tests/vectors/main.rs | 4 +- crates/system/clients/clients/Cargo.toml | 2 +- crates/system/clients/http/Cargo.toml | 2 +- crates/system/drivers/Cargo.toml | 2 +- crates/system/interactors/Cargo.toml | 2 +- crates/system/os/accounts/Cargo.toml | 2 +- .../system/os/derive-public-keys/Cargo.toml | 2 +- crates/system/os/factors/Cargo.toml | 2 +- crates/system/os/os/Cargo.toml | 2 +- crates/system/os/security-center/Cargo.toml | 2 +- crates/system/os/signing/Cargo.toml | 2 +- crates/system/os/transaction/Cargo.toml | 2 +- crates/system/profile-state-holder/Cargo.toml | 2 +- crates/system/sub-systems/Cargo.toml | 2 +- crates/transaction/foundation/Cargo.toml | 2 +- crates/transaction/manifests/Cargo.toml | 2 +- crates/transaction/models/Cargo.toml | 2 +- crates/uniffi/conversion-macros/Cargo.toml | 2 +- crates/uniffi/uniffi_SPLIT_ME/Cargo.toml | 2 +- .../bip32/hd_path_component.rs | 6 +- .../derivation/derivation_path.rs | 16 +- .../sargon/extensions/DerivationPath.kt | 6 +- .../com/radixdlt/sargon/DerivationPathTest.kt | 6 +- 94 files changed, 514 insertions(+), 371 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef34c204f..e93fef64c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "account-for-display" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "derive_more", @@ -49,10 +49,10 @@ dependencies = [ [[package]] name = "addresses" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", - "bytes 1.1.118", + "bytes 1.1.119", "cap26-models", "core-utils", "derive_more", @@ -246,7 +246,7 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "assert-json" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json-diff", "error", @@ -546,7 +546,7 @@ dependencies = [ [[package]] name = "build-info" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", "cargo_toml", @@ -573,7 +573,7 @@ checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce" [[package]] name = "bytes" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", "delegate", @@ -607,7 +607,7 @@ dependencies = [ [[package]] name = "cap26-models" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", "derive_more", @@ -748,7 +748,7 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "clients" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "async-trait", @@ -808,7 +808,7 @@ checksum = "0d8a42181e0652c2997ae4d217f25b63c5337a52fd2279736e97b832fa0a3cff" [[package]] name = "core-collections" -version = "1.1.118" +version = "1.1.119" dependencies = [ "has-sample-values", "indexmap 2.7.0", @@ -835,7 +835,7 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "core-misc" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", "core-utils", @@ -855,7 +855,7 @@ dependencies = [ [[package]] name = "core-utils" -version = "1.1.118" +version = "1.1.119" dependencies = [ "error", "iso8601-timestamp", @@ -1084,7 +1084,7 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "drivers" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "addresses", @@ -1108,10 +1108,10 @@ dependencies = [ [[package]] name = "ecc" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", - "bytes 1.1.118", + "bytes 1.1.119", "derive_more", "enum-as-inner", "error", @@ -1210,11 +1210,11 @@ dependencies = [ [[package]] name = "encryption" -version = "1.1.118" +version = "1.1.119" dependencies = [ "aes-gcm", "assert-json", - "bytes 1.1.118", + "bytes 1.1.119", "derive_more", "error", "has-sample-values", @@ -1231,7 +1231,7 @@ dependencies = [ [[package]] name = "entity-by-address" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "error", @@ -1243,7 +1243,7 @@ dependencies = [ [[package]] name = "entity-foundation" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", "derive_more", @@ -1318,7 +1318,7 @@ dependencies = [ [[package]] name = "error" -version = "1.1.118" +version = "1.1.119" dependencies = [ "derive_more", "log", @@ -1377,7 +1377,7 @@ dependencies = [ [[package]] name = "factor-instances-provider" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "addresses", @@ -1403,9 +1403,9 @@ dependencies = [ [[package]] name = "factors" -version = "1.1.118" +version = "1.1.119" dependencies = [ - "bytes 1.1.118", + "bytes 1.1.119", "cap26-models", "core-collections", "core-misc", @@ -1440,7 +1440,7 @@ dependencies = [ [[package]] name = "factors-supporting-types" -version = "1.1.118" +version = "1.1.119" dependencies = [ "async-trait", "error", @@ -1593,7 +1593,7 @@ dependencies = [ [[package]] name = "gateway-client-and-api" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "addresses", @@ -1613,7 +1613,7 @@ dependencies = [ [[package]] name = "gateway-models" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "assert-json", @@ -1718,7 +1718,7 @@ dependencies = [ [[package]] name = "has-sample-values" -version = "1.1.118" +version = "1.1.119" dependencies = [ "error", "indexmap 2.7.0", @@ -1729,9 +1729,9 @@ dependencies = [ [[package]] name = "hash" -version = "1.1.118" +version = "1.1.119" dependencies = [ - "bytes 1.1.118", + "bytes 1.1.119", "derive_more", "prelude", "radix-common", @@ -1795,11 +1795,11 @@ dependencies = [ [[package]] name = "hierarchical-deterministic" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", "bip39", - "bytes 1.1.118", + "bytes 1.1.119", "cap26-models", "derive_more", "ecc", @@ -1842,13 +1842,13 @@ dependencies = [ [[package]] name = "home-cards" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "addresses", "async-trait", "base64", - "bytes 1.1.118", + "bytes 1.1.119", "core-utils", "derive_more", "drivers", @@ -1868,7 +1868,7 @@ dependencies = [ [[package]] name = "host-info" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", "derive_more", @@ -1915,10 +1915,10 @@ dependencies = [ [[package]] name = "http-client" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", - "bytes 1.1.118", + "bytes 1.1.119", "core-utils", "drivers", "error", @@ -2143,7 +2143,7 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "identified-vec-of" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", "derive_more", @@ -2216,7 +2216,7 @@ dependencies = [ [[package]] name = "interactors" -version = "1.1.118" +version = "1.1.119" dependencies = [ "async-trait", "derive_more", @@ -2336,7 +2336,7 @@ dependencies = [ [[package]] name = "key-derivation-traits" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "async-trait", @@ -2354,7 +2354,7 @@ dependencies = [ [[package]] name = "keys-collector" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "addresses", @@ -2443,7 +2443,7 @@ dependencies = [ [[package]] name = "manifests" -version = "1.1.118" +version = "1.1.119" dependencies = [ "account-for-display", "addresses", @@ -2484,7 +2484,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "metadata" -version = "1.1.118" +version = "1.1.119" dependencies = [ "derive_more", "has-sample-values", @@ -2584,7 +2584,7 @@ dependencies = [ [[package]] name = "network" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", "enum-iterator", @@ -2600,7 +2600,7 @@ dependencies = [ [[package]] name = "next-derivation-index-ephemeral" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "assert-json", @@ -2676,9 +2676,9 @@ dependencies = [ [[package]] name = "numeric" -version = "1.1.118" +version = "1.1.119" dependencies = [ - "bytes 1.1.118", + "bytes 1.1.119", "delegate", "derive_more", "enum-iterator", @@ -2898,7 +2898,7 @@ dependencies = [ [[package]] name = "prelude" -version = "1.1.118" +version = "1.1.119" dependencies = [ "radix-engine", "radix-engine-toolkit", @@ -2935,7 +2935,7 @@ dependencies = [ [[package]] name = "profile" -version = "1.1.118" +version = "1.1.119" dependencies = [ "account-for-display", "addresses", @@ -2979,7 +2979,7 @@ dependencies = [ [[package]] name = "profile-account" -version = "1.1.118" +version = "1.1.119" dependencies = [ "account-for-display", "addresses", @@ -2999,7 +2999,7 @@ dependencies = [ [[package]] name = "profile-account-or-persona" -version = "1.1.118" +version = "1.1.119" dependencies = [ "cap26-models", "derive_more", @@ -3016,7 +3016,7 @@ dependencies = [ [[package]] name = "profile-app-preferences" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "core-misc", @@ -3039,7 +3039,7 @@ dependencies = [ [[package]] name = "profile-base-entity" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "derive_more", @@ -3062,7 +3062,7 @@ dependencies = [ [[package]] name = "profile-gateway" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "assert-json", @@ -3086,7 +3086,7 @@ dependencies = [ [[package]] name = "profile-logic" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "derive_more", @@ -3108,7 +3108,7 @@ dependencies = [ [[package]] name = "profile-persona" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "cap26-models", @@ -3129,7 +3129,7 @@ dependencies = [ [[package]] name = "profile-persona-data" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "assert-json", @@ -3148,7 +3148,7 @@ dependencies = [ [[package]] name = "profile-security-structures" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "cap26-models", @@ -3176,7 +3176,7 @@ dependencies = [ [[package]] name = "profile-state-holder" -version = "1.1.118" +version = "1.1.119" dependencies = [ "derive_more", "error", @@ -3191,7 +3191,7 @@ dependencies = [ [[package]] name = "profile-supporting-types" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "derive_more", @@ -3280,14 +3280,14 @@ dependencies = [ [[package]] name = "radix-connect" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "addresses", "assert-json", "async-trait", "base64", - "bytes 1.1.118", + "bytes 1.1.119", "core-misc", "core-utils", "derive_more", @@ -3315,10 +3315,10 @@ dependencies = [ [[package]] name = "radix-connect-models" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", - "bytes 1.1.118", + "bytes 1.1.119", "core-misc", "derive_more", "error", @@ -3760,7 +3760,7 @@ dependencies = [ [[package]] name = "sargon" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "addresses", @@ -3825,7 +3825,7 @@ dependencies = [ [[package]] name = "sargon-os" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "async-trait", @@ -3852,7 +3852,7 @@ dependencies = [ [[package]] name = "sargon-os-accounts" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "addresses", @@ -3875,7 +3875,7 @@ dependencies = [ [[package]] name = "sargon-os-derive-public-keys" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "async-trait", @@ -3894,7 +3894,7 @@ dependencies = [ [[package]] name = "sargon-os-factors" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "async-trait", @@ -3922,7 +3922,7 @@ dependencies = [ [[package]] name = "sargon-os-security-center" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "derive_more", @@ -3938,7 +3938,7 @@ dependencies = [ [[package]] name = "sargon-os-signing" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "async-trait", @@ -3964,7 +3964,7 @@ dependencies = [ [[package]] name = "sargon-os-transaction" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "async-std", @@ -3993,7 +3993,7 @@ dependencies = [ [[package]] name = "sargon-uniffi" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "addresses", @@ -4050,7 +4050,7 @@ dependencies = [ [[package]] name = "sargon-uniffi-conversion-macros" -version = "1.1.118" +version = "1.1.119" dependencies = [ "proc-macro2", "quote", @@ -4223,7 +4223,7 @@ dependencies = [ [[package]] name = "security-center" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", "assert-json", @@ -4391,7 +4391,7 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "short-string" -version = "1.1.118" +version = "1.1.119" dependencies = [ "arraystring", "assert-json", @@ -4426,13 +4426,13 @@ dependencies = [ [[package]] name = "signing" -version = "1.1.118" +version = "1.1.119" dependencies = [ "actix-rt", "addresses", "assert-json", "async-trait", - "bytes 1.1.118", + "bytes 1.1.119", "cap26-models", "core-collections", "core-misc", @@ -4464,10 +4464,10 @@ dependencies = [ [[package]] name = "signing-traits" -version = "1.1.118" +version = "1.1.119" dependencies = [ "async-trait", - "bytes 1.1.118", + "bytes 1.1.119", "core-collections", "derive_more", "ecc", @@ -4632,7 +4632,7 @@ dependencies = [ [[package]] name = "sub-systems" -version = "1.1.118" +version = "1.1.119" dependencies = [ "derive_more", "drivers", @@ -4791,7 +4791,7 @@ dependencies = [ [[package]] name = "time-utils" -version = "1.1.118" +version = "1.1.119" dependencies = [ "iso8601-timestamp", "prelude", @@ -4941,10 +4941,10 @@ dependencies = [ [[package]] name = "transaction-foundation" -version = "1.1.118" +version = "1.1.119" dependencies = [ "assert-json", - "bytes 1.1.118", + "bytes 1.1.119", "derive_more", "has-sample-values", "paste", @@ -4956,10 +4956,10 @@ dependencies = [ [[package]] name = "transaction-models" -version = "1.1.118" +version = "1.1.119" dependencies = [ "addresses", - "bytes 1.1.118", + "bytes 1.1.119", "cargo_toml", "core-collections", "core-misc", diff --git a/apple/Sources/Sargon/Extensions/Methods/Crypto/Derivation/DerivationPath+Wrap+Functions.swift b/apple/Sources/Sargon/Extensions/Methods/Crypto/Derivation/DerivationPath+Wrap+Functions.swift index 3128f49a2..46fcc96af 100644 --- a/apple/Sources/Sargon/Extensions/Methods/Crypto/Derivation/DerivationPath+Wrap+Functions.swift +++ b/apple/Sources/Sargon/Extensions/Methods/Crypto/Derivation/DerivationPath+Wrap+Functions.swift @@ -6,10 +6,20 @@ extension DerivationPath { derivationPathToHdPath(path: self) } + /// Returns a CAP 43 String representation of this `DerivationPath`. + /// Useful when we need to log or debug, but should **never** be used when communicating with external APIs. public func toString() -> String { derivationPathToString(path: self) } + /// Returns a BIP 32 String representation of this `DerivationPath`. + /// Needed to communicate with external APIs such as Arculus or Ledger. + public func toBip32String() -> String { + derivationPathToBip32String(path: self) + } + + /// Attempts to build a DerivationPath from a CAP 43 or BIP 32 representation. + /// The initializer is lenient, so it will attempt with the latter if the first fails public init(string: String) throws { self = try newDerivationPathFromString(string: string) } diff --git a/apple/Tests/TestCases/Crypto/DerivationPathTests.swift b/apple/Tests/TestCases/Crypto/DerivationPathTests.swift index a7935d95f..8bf9c9ff9 100644 --- a/apple/Tests/TestCases/Crypto/DerivationPathTests.swift +++ b/apple/Tests/TestCases/Crypto/DerivationPathTests.swift @@ -78,4 +78,24 @@ final class DerivationPathTests: HDPathProtocolTest { "m/44H/1022H/2H/618H/1460H/42H" ) } + + func test_to_bip32() throws { + // Build from CAP43 syntax + var sut = try SUT(string: "m/44H/1022H/1H/525H/1460H/0S") + XCTAssertEqual(sut.toBip32String(), "m/44H/1022H/1H/525H/1460H/1073741824H") + + // Build from BIP32 syntax + sut = try SUT(string: "m/44H/1022H/1H/525H/1460H/2H") + XCTAssertEqual(sut.toBip32String(), "m/44H/1022H/1H/525H/1460H/2H") + } + + func test_to_string() throws { + // Build from CAP43 syntax + var sut = try SUT(string: "m/44H/1022H/1H/525H/1460H/0S") + XCTAssertEqual(sut.toString(), "m/44H/1022H/1H/525H/1460H/0S") + + // Build from BIP32 syntax + sut = try SUT(string: "m/44H/1022H/1H/525H/1460H/2H") + XCTAssertEqual(sut.toString(), "m/44H/1022H/1H/525H/1460H/2H") + } } diff --git a/crates/app/home-cards/Cargo.toml b/crates/app/home-cards/Cargo.toml index 15267c42c..7d8fd704b 100644 --- a/crates/app/home-cards/Cargo.toml +++ b/crates/app/home-cards/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home-cards" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/app/key-derivation-traits/Cargo.toml b/crates/app/key-derivation-traits/Cargo.toml index 4455a9c62..ea868625d 100644 --- a/crates/app/key-derivation-traits/Cargo.toml +++ b/crates/app/key-derivation-traits/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "key-derivation-traits" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/app/radix-connect-models/Cargo.toml b/crates/app/radix-connect-models/Cargo.toml index b6f1b8cca..1ce09ffa8 100644 --- a/crates/app/radix-connect-models/Cargo.toml +++ b/crates/app/radix-connect-models/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "radix-connect-models" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/app/radix-connect/Cargo.toml b/crates/app/radix-connect/Cargo.toml index dc53d8238..1f4d87309 100644 --- a/crates/app/radix-connect/Cargo.toml +++ b/crates/app/radix-connect/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "radix-connect" -version = "1.1.118" +version = "1.1.119" edition = "2021" diff --git a/crates/app/security-center/Cargo.toml b/crates/app/security-center/Cargo.toml index 9ba275037..897f4dfa8 100644 --- a/crates/app/security-center/Cargo.toml +++ b/crates/app/security-center/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "security-center" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/app/signing-traits/Cargo.toml b/crates/app/signing-traits/Cargo.toml index 0b2823fed..6920e7330 100644 --- a/crates/app/signing-traits/Cargo.toml +++ b/crates/app/signing-traits/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "signing-traits" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/app/signing/Cargo.toml b/crates/app/signing/Cargo.toml index a267184d4..c46cb0d61 100644 --- a/crates/app/signing/Cargo.toml +++ b/crates/app/signing/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "signing" -version = "1.1.118" +version = "1.1.119" edition = "2021" diff --git a/crates/common/build-info/Cargo.toml b/crates/common/build-info/Cargo.toml index a2301c91b..1f8908385 100644 --- a/crates/common/build-info/Cargo.toml +++ b/crates/common/build-info/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "build-info" -version = "1.1.118" +version = "1.1.119" edition = "2021" build = "build.rs" diff --git a/crates/common/bytes/Cargo.toml b/crates/common/bytes/Cargo.toml index a7f69ebf8..d7194437c 100644 --- a/crates/common/bytes/Cargo.toml +++ b/crates/common/bytes/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bytes" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/common/entity-foundation/Cargo.toml b/crates/common/entity-foundation/Cargo.toml index 0d0b45447..80ea456df 100644 --- a/crates/common/entity-foundation/Cargo.toml +++ b/crates/common/entity-foundation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "entity-foundation" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/common/host-info/Cargo.toml b/crates/common/host-info/Cargo.toml index 79584f0d5..8a13bbf83 100644 --- a/crates/common/host-info/Cargo.toml +++ b/crates/common/host-info/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "host-info" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/common/identified-vec-of/Cargo.toml b/crates/common/identified-vec-of/Cargo.toml index 3e1f31e42..ea598a9ac 100644 --- a/crates/common/identified-vec-of/Cargo.toml +++ b/crates/common/identified-vec-of/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "identified-vec-of" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/common/metadata/Cargo.toml b/crates/common/metadata/Cargo.toml index d1aa2de34..be1853b5e 100644 --- a/crates/common/metadata/Cargo.toml +++ b/crates/common/metadata/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "metadata" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/common/network/Cargo.toml b/crates/common/network/Cargo.toml index a146284d9..d0ce57f5d 100644 --- a/crates/common/network/Cargo.toml +++ b/crates/common/network/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "network" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/common/numeric/Cargo.toml b/crates/common/numeric/Cargo.toml index bc29a8b61..e813261cf 100644 --- a/crates/common/numeric/Cargo.toml +++ b/crates/common/numeric/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "numeric" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/common/short-string/Cargo.toml b/crates/common/short-string/Cargo.toml index 1b7aed0b2..15be512e2 100644 --- a/crates/common/short-string/Cargo.toml +++ b/crates/common/short-string/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "short-string" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/core/assert-json/Cargo.toml b/crates/core/assert-json/Cargo.toml index c1e503373..2de808d0d 100644 --- a/crates/core/assert-json/Cargo.toml +++ b/crates/core/assert-json/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "assert-json" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/core/collections/Cargo.toml b/crates/core/collections/Cargo.toml index b042b2fb2..0c0a8c96c 100644 --- a/crates/core/collections/Cargo.toml +++ b/crates/core/collections/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-collections" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/core/error/Cargo.toml b/crates/core/error/Cargo.toml index 2e43877b6..b6c9f69ad 100644 --- a/crates/core/error/Cargo.toml +++ b/crates/core/error/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "error" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/core/has-sample-values/Cargo.toml b/crates/core/has-sample-values/Cargo.toml index b7530bac4..61b5b9ba3 100644 --- a/crates/core/has-sample-values/Cargo.toml +++ b/crates/core/has-sample-values/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "has-sample-values" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/core/misc/Cargo.toml b/crates/core/misc/Cargo.toml index 5752a17f4..a30bf5af8 100644 --- a/crates/core/misc/Cargo.toml +++ b/crates/core/misc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-misc" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/core/prelude/Cargo.toml b/crates/core/prelude/Cargo.toml index 43745ecd4..a0fab9703 100644 --- a/crates/core/prelude/Cargo.toml +++ b/crates/core/prelude/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "prelude" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/core/time-utils/Cargo.toml b/crates/core/time-utils/Cargo.toml index 4efac4373..0bed085c2 100644 --- a/crates/core/time-utils/Cargo.toml +++ b/crates/core/time-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "time-utils" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/core/utils/Cargo.toml b/crates/core/utils/Cargo.toml index 10cbcdb69..7559ea9c9 100644 --- a/crates/core/utils/Cargo.toml +++ b/crates/core/utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-utils" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/crypto/addresses/Cargo.toml b/crates/crypto/addresses/Cargo.toml index 21a2c61e1..a097f2d39 100644 --- a/crates/crypto/addresses/Cargo.toml +++ b/crates/crypto/addresses/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "addresses" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/crypto/cap26-models/Cargo.toml b/crates/crypto/cap26-models/Cargo.toml index 27a5e17dd..37da7af4c 100644 --- a/crates/crypto/cap26-models/Cargo.toml +++ b/crates/crypto/cap26-models/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cap26-models" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/crypto/ecc/Cargo.toml b/crates/crypto/ecc/Cargo.toml index f3299b225..5fe0f8ab8 100644 --- a/crates/crypto/ecc/Cargo.toml +++ b/crates/crypto/ecc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ecc" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/crypto/encryption/Cargo.toml b/crates/crypto/encryption/Cargo.toml index 122b2d4ad..3475a57da 100644 --- a/crates/crypto/encryption/Cargo.toml +++ b/crates/crypto/encryption/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "encryption" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/crypto/hash/Cargo.toml b/crates/crypto/hash/Cargo.toml index b29309411..709ca81f1 100644 --- a/crates/crypto/hash/Cargo.toml +++ b/crates/crypto/hash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hash" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/crypto/hd/Cargo.toml b/crates/crypto/hd/Cargo.toml index d816c253a..cb85cbdd4 100644 --- a/crates/crypto/hd/Cargo.toml +++ b/crates/crypto/hd/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hierarchical-deterministic" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/crypto/hd/src/bip32/hd_path.rs b/crates/crypto/hd/src/bip32/hd_path.rs index e7e5ee953..dc33fd73d 100644 --- a/crates/crypto/hd/src/bip32/hd_path.rs +++ b/crates/crypto/hd/src/bip32/hd_path.rs @@ -15,8 +15,8 @@ use crate::prelude::*; DeserializeFromStr, SerializeDisplay, )] -#[display("{}", self.to_bip32_string())] -#[debug("{}", self.to_bip32_string_debug())] +#[display("{}", self.to_cap43_string())] +#[debug("{}", self.to_cap43_string_debug())] pub struct HDPath { pub components: Vec, } @@ -29,8 +29,8 @@ impl HDPath { } } -impl FromBIP32Str for HDPath { - fn from_bip32_string(s: impl AsRef) -> Result { +impl FromCAP43String for HDPath { + fn from_cap43_string(s: impl AsRef) -> Result { let s = s.as_ref(); let mut s = s; if s.starts_with(&format!("m{}", Self::SEPARATOR)) { @@ -45,7 +45,7 @@ impl FromBIP32Str for HDPath { let components = s .split(Self::SEPARATOR) .filter(|s| !s.is_empty()) - .map(HDPathComponent::from_bip32_string) + .map(HDPathComponent::from_cap43_string) .collect::>>()?; Ok(Self::new(components)) } @@ -66,7 +66,7 @@ impl HDPath { path.into_iter().join(Self::SEPARATOR) } - pub fn to_bip32_string_with( + pub fn to_cap43_string_with( &self, include_head: bool, canonicalize_entity_index: bool, @@ -85,30 +85,30 @@ impl HDPath { }) } - pub fn to_bip32_string_debug_with(&self, include_head: bool) -> String { + pub fn to_cap43_string_debug_with(&self, include_head: bool) -> String { self.to_string_map_with(include_head, |(_, c)| format!("{:?}", c)) } - /// This method returns the canonical bip32 representation of the path. + /// String representation of the path using BIP32 notation. /// 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 + /// Such paths need to be on 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) + pub fn to_bip32_string(&self) -> String { + self.to_cap43_string_with(true, true) } } -impl ToBIP32Str for HDPath { - fn to_bip32_string(&self) -> String { - self.to_bip32_string_with(true, false) +impl ToCAP43String for HDPath { + fn to_cap43_string(&self) -> String { + self.to_cap43_string_with(true, false) } - fn to_bip32_string_debug(&self) -> String { - self.to_bip32_string_debug_with(true) + fn to_cap43_string_debug(&self) -> String { + self.to_cap43_string_debug_with(true) } } @@ -116,7 +116,7 @@ impl FromStr for HDPath { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_cap43_string(s) } } @@ -235,4 +235,16 @@ mod tests { assert_json_value_fails::(json!("m/44X")); assert_json_value_fails::(json!("super invalid path")); } + + #[test] + fn from_bip32_str() { + let canonical = "m/44H/1022H/1H/525H/1460H/1073741824H"; + let sut = SUT::from_str(canonical).unwrap(); + assert_eq!( + DerivationPath::from(AccountPath::try_from(sut.clone()).unwrap()) + .to_bip32_string(), + canonical + ); + assert_eq!(sut.to_cap43_string(), "m/44H/1022H/1H/525H/1460H/0S"); + } } diff --git a/crates/crypto/hd/src/bip32/hd_path_component.rs b/crates/crypto/hd/src/bip32/hd_path_component.rs index 4e5de3799..fdd341c96 100644 --- a/crates/crypto/hd/src/bip32/hd_path_component.rs +++ b/crates/crypto/hd/src/bip32/hd_path_component.rs @@ -71,12 +71,12 @@ impl Ord for HDPathComponent { } } -impl ToBIP32Str for HDPathComponent { - fn to_bip32_string(&self) -> String { +impl ToCAP43String for HDPathComponent { + fn to_cap43_string(&self) -> String { format!("{}", self) } - fn to_bip32_string_debug(&self) -> String { + fn to_cap43_string_debug(&self) -> String { format!("{:?}", self) } } @@ -168,19 +168,21 @@ impl HDPathComponent { } } -impl FromBIP32Str for HDPathComponent { - fn from_bip32_string(s: impl AsRef) -> Result { +impl FromCAP43String for HDPathComponent { + fn from_cap43_string(s: impl AsRef) -> Result { let s = s.as_ref(); - SecurifiedU30::from_bip32_string(s) + SecurifiedU30::from_string_lenient(s) .map(Self::securified) - .or(Unsecurified::from_bip32_string(s).map(Self::Unsecurified)) + .or_else(|_| { + Unsecurified::from_cap43_string(s).map(Self::Unsecurified) + }) } } impl FromStr for HDPathComponent { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_cap43_string(s) } } @@ -462,7 +464,7 @@ mod tests { } #[test] - fn from_str_valid_0_hardened_canonical() { + fn from_str_valid_0_hardened_verbose_syntax() { assert_eq!( "0H".parse::().unwrap(), SUT::from_global_key_space(GLOBAL_OFFSET_HARDENED).unwrap() @@ -470,7 +472,7 @@ mod tests { } #[test] - fn from_str_valid_1_hardened_canonical() { + fn from_str_valid_1_hardened_verbose_syntax() { assert_eq!( "1H".parse::().unwrap(), SUT::from_global_key_space(1 + GLOBAL_OFFSET_HARDENED).unwrap() @@ -478,7 +480,7 @@ mod tests { } #[test] - fn from_str_valid_2_hardened_non_canonical() { + fn from_str_valid_2_hardened_non_verbose_syntax() { assert_eq!( "2'".parse::().unwrap(), SUT::from_global_key_space(2 + GLOBAL_OFFSET_HARDENED).unwrap() @@ -486,7 +488,7 @@ mod tests { } #[test] - fn from_str_valid_3_hardened_non_canonical() { + fn from_str_valid_3_hardened_non_verbose_syntax() { assert_eq!( "3'".parse::().unwrap(), SUT::from_global_key_space(3 + GLOBAL_OFFSET_HARDENED).unwrap() @@ -515,7 +517,7 @@ mod tests { assert_eq!( SUT::from_global_key_space(0) .unwrap() - .to_bip32_string_debug(), + .to_cap43_string_debug(), "0" ); } @@ -529,7 +531,7 @@ mod tests { assert_eq!( SUT::from_global_key_space(U30_MAX) .unwrap() - .to_bip32_string(), + .to_cap43_string(), "1073741823" ); } diff --git a/crates/crypto/hd/src/bip32/key_space/components/hardened.rs b/crates/crypto/hd/src/bip32/key_space/components/hardened.rs index c789d0525..989ab298b 100644 --- a/crates/crypto/hd/src/bip32/key_space/components/hardened.rs +++ b/crates/crypto/hd/src/bip32/key_space/components/hardened.rs @@ -148,12 +148,15 @@ impl FromGlobalKeySpace for Hardened { } } -impl FromBIP32Str for Hardened { - fn from_bip32_string(s: impl AsRef) -> Result { +pub const HARDENED_SUFFIX_BIP32: &str = "H"; +pub const HARDENED_SUFFIX_BIP44: &str = "'"; + +impl FromCAP43String for Hardened { + fn from_cap43_string(s: impl AsRef) -> Result { let s = s.as_ref(); - SecurifiedU30::from_bip32_string(s) + SecurifiedU30::from_cap43_string(s) .map(Self::Securified) - .or(UnsecurifiedHardened::from_bip32_string(s) + .or(UnsecurifiedHardened::from_cap43_string(s) .map(Self::Unsecurified)) } } @@ -195,7 +198,7 @@ impl TryFrom for Hardened { impl FromStr for Hardened { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_cap43_string(s) } } @@ -283,7 +286,7 @@ mod tests { } #[test] - fn from_str_valid_1_securified_canonical() { + fn from_str_valid_1_securified_verbose_syntax() { assert_eq!( "1S".parse::().unwrap(), SUT::from_global_key_space(1 + GLOBAL_OFFSET_HARDENED_SECURIFIED) @@ -291,7 +294,7 @@ mod tests { ); } #[test] - fn from_str_valid_1_securified_non_canonical() { + fn from_str_valid_1_securified_shorthand_syntax() { assert_eq!( "1^".parse::().unwrap(), SUT::from_global_key_space(1 + GLOBAL_OFFSET_HARDENED_SECURIFIED) @@ -300,7 +303,7 @@ mod tests { } #[test] - fn from_str_valid_1_hardened_canonical() { + fn from_str_valid_1_hardened_verbose_syntax() { assert_eq!( "1H".parse::().unwrap(), SUT::from_global_key_space(1 + GLOBAL_OFFSET_HARDENED).unwrap() @@ -308,7 +311,7 @@ mod tests { } #[test] - fn from_str_valid_2_hardened_non_canonical() { + fn from_str_valid_2_hardened_shorthand_syntax() { assert_eq!( "2'".parse::().unwrap(), SUT::from_global_key_space(2 + GLOBAL_OFFSET_HARDENED).unwrap() @@ -316,7 +319,7 @@ mod tests { } #[test] - fn from_str_valid_3_hardened_non_canonical() { + fn from_str_valid_3_hardened_shorthand_syntax() { assert_eq!( "3'".parse::().unwrap(), SUT::from_global_key_space(3 + GLOBAL_OFFSET_HARDENED).unwrap() diff --git a/crates/crypto/hd/src/bip32/key_space/components/securified.rs b/crates/crypto/hd/src/bip32/key_space/components/securified.rs index 523760481..4175c27b1 100644 --- a/crates/crypto/hd/src/bip32/key_space/components/securified.rs +++ b/crates/crypto/hd/src/bip32/key_space/components/securified.rs @@ -57,8 +57,8 @@ use crate::prelude::*; derive_more::Debug, )] #[deref(forward)] -#[display("{}", self.to_bip32_string())] -#[debug("{}", self.to_bip32_string_debug())] +#[display("{}", self.to_cap43_string())] +#[debug("{}", self.to_cap43_string_debug())] pub struct SecurifiedU30(pub U30); impl SecurifiedU30 { @@ -133,13 +133,34 @@ impl TryFrom for SecurifiedU30 { } } impl IsPathComponentStringConvertible for SecurifiedU30 { - const CANONICAL_SUFFIX: &'static str = "S"; - const NON_CANONICAL_SUFFIX: &'static str = "^"; + const VERBOSE_SYNTAX_SUFFIX: &'static str = "S"; + const SHORTHAND_SYNTAX_SUFFIX: &'static str = "^"; +} + +impl SecurifiedU30 { + /// Accepts `1073741824H` which will be interpreted as `0S` + /// and `1073741825H` which will be interpreted as `1S` etc. + fn from_bip32_str(s: &str) -> Result { + let offsetted = Self::value_in_local_keyspace_from_cap43_string_with_acceptable_suffixes(s, + vec![ + HARDENED_SUFFIX_BIP32, + HARDENED_SUFFIX_BIP44, + ])?; + let unoffsetted = offsetted + .checked_sub(RELATIVELY_LOCAL_OFFSET_SECURIFIED) + .ok_or(CommonError::IndexOverflow)?; + Self::from_local_key_space(unoffsetted) + } + + /// Tries to parse a CAP43 string and falls back to BIP32 + pub(crate) fn from_string_lenient(s: &str) -> Result { + Self::from_cap43_string(s).or_else(|_| Self::from_bip32_str(s)) + } } impl FromStr for SecurifiedU30 { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_string_lenient(s) } } @@ -168,6 +189,14 @@ mod tests { assert!(SUT::sample() < SUT::sample_other()); } + #[test] + fn from_canonical_bip32() { + assert_eq!( + SUT::from_bip32_str("1073741825H").unwrap(), + SUT::from_local_key_space(U31::ONE).unwrap() + ); + } + #[test] fn hash() { assert_eq!( @@ -196,7 +225,7 @@ mod tests { } #[test] - fn from_str_valid_canonical_0() { + fn from_str_valid_verbose_syntax_0() { assert_eq!( "0S".parse::().unwrap(), SUT::from_local_key_space(U31::ZERO).unwrap() @@ -204,7 +233,7 @@ mod tests { } #[test] - fn from_str_valid_canonical_1() { + fn from_str_valid_verbose_syntax_1() { assert_eq!( "1S".parse::().unwrap(), SUT::from_local_key_space(U31::ONE).unwrap() @@ -212,7 +241,7 @@ mod tests { } #[test] - fn from_str_valid_canonical_max() { + fn from_str_valid_verbose_syntax_max() { assert_eq!( "1073741823S".parse::().unwrap(), SUT::from_local_key_space(U30_MAX).unwrap() @@ -220,7 +249,7 @@ mod tests { } #[test] - fn from_str_valid_uncanonical_0() { + fn from_str_valid_shorthand_syntax_0() { assert_eq!( "0^".parse::().unwrap(), SUT::from_local_key_space(U31::ZERO).unwrap() @@ -228,7 +257,7 @@ mod tests { } #[test] - fn from_str_valid_uncanonical_1() { + fn from_str_valid_shorthand_syntax_1() { assert_eq!( "1^".parse::().unwrap(), SUT::from_local_key_space(U31::ONE).unwrap() @@ -236,7 +265,7 @@ mod tests { } #[test] - fn from_str_valid_uncanonical_max() { + fn from_str_valid_shorthand_syntax_max() { assert_eq!( "1073741823^".parse::().unwrap(), SUT::from_local_key_space(U30_MAX).unwrap() @@ -377,7 +406,6 @@ mod tests { assert_json_value_fails::(json!("^")); assert_json_value_fails::(json!("S")); assert_json_value_fails::(json!("2")); - assert_json_value_fails::(json!("2'")); assert_json_value_fails::(json!("2X")); assert_json_value_fails::(json!(" ")); } diff --git a/crates/crypto/hd/src/bip32/key_space/components/unhardened.rs b/crates/crypto/hd/src/bip32/key_space/components/unhardened.rs index 77503ece1..8e4e52595 100644 --- a/crates/crypto/hd/src/bip32/key_space/components/unhardened.rs +++ b/crates/crypto/hd/src/bip32/key_space/components/unhardened.rs @@ -45,8 +45,8 @@ use crate::prelude::*; derive_more::Debug, )] #[deref(forward)] -#[display("{}", self.to_bip32_string())] -#[debug("{}", self.to_bip32_string_debug())] +#[display("{}", self.to_cap43_string())] +#[debug("{}", self.to_cap43_string_debug())] pub struct Unhardened(pub U31); impl Unhardened { @@ -120,14 +120,14 @@ impl TryFrom for Unhardened { } impl IsPathComponentStringConvertible for Unhardened { - const CANONICAL_SUFFIX: &'static str = ""; - const NON_CANONICAL_SUFFIX: &'static str = ""; + const VERBOSE_SYNTAX_SUFFIX: &'static str = ""; + const SHORTHAND_SYNTAX_SUFFIX: &'static str = ""; } impl FromStr for Unhardened { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_cap43_string(s) } } diff --git a/crates/crypto/hd/src/bip32/key_space/components/unsecurified.rs b/crates/crypto/hd/src/bip32/key_space/components/unsecurified.rs index a3c6c5b96..f1e966a9b 100644 --- a/crates/crypto/hd/src/bip32/key_space/components/unsecurified.rs +++ b/crates/crypto/hd/src/bip32/key_space/components/unsecurified.rs @@ -153,19 +153,19 @@ impl TryFrom for Unsecurified { } } -impl FromBIP32Str for Unsecurified { - fn from_bip32_string(s: impl AsRef) -> Result { +impl FromCAP43String for Unsecurified { + fn from_cap43_string(s: impl AsRef) -> Result { let s = s.as_ref(); - UnsecurifiedHardened::from_bip32_string(s) + UnsecurifiedHardened::from_cap43_string(s) .map(Self::Hardened) - .or(Unhardened::from_bip32_string(s).map(Self::Unhardened)) + .or(Unhardened::from_cap43_string(s).map(Self::Unhardened)) } } impl FromStr for Unsecurified { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_cap43_string(s) } } @@ -303,7 +303,7 @@ mod tests { } #[test] - fn from_str_valid_0_hardened_canonical() { + fn from_str_valid_0_hardened_verbose_syntax() { assert_eq!( "0H".parse::().unwrap(), SUT::from_global_key_space(GLOBAL_OFFSET_HARDENED).unwrap() @@ -311,7 +311,7 @@ mod tests { } #[test] - fn from_str_valid_1_hardened_canonical() { + fn from_str_valid_1_hardened_verbose_syntax() { assert_eq!( "1H".parse::().unwrap(), SUT::from_global_key_space(1 + GLOBAL_OFFSET_HARDENED).unwrap() @@ -319,7 +319,7 @@ mod tests { } #[test] - fn from_str_valid_2_hardened_non_canonical() { + fn from_str_valid_2_hardened_shorthand_syntax() { assert_eq!( "2'".parse::().unwrap(), SUT::from_global_key_space(2 + GLOBAL_OFFSET_HARDENED).unwrap() @@ -327,7 +327,7 @@ mod tests { } #[test] - fn from_str_valid_3_hardened_non_canonical() { + fn from_str_valid_3_hardened_shorthand_syntax() { assert_eq!( "3'".parse::().unwrap(), SUT::from_global_key_space(3 + GLOBAL_OFFSET_HARDENED).unwrap() diff --git a/crates/crypto/hd/src/bip32/key_space/components/unsecurified_hardened.rs b/crates/crypto/hd/src/bip32/key_space/components/unsecurified_hardened.rs index c2da2ab19..9f4447fdb 100644 --- a/crates/crypto/hd/src/bip32/key_space/components/unsecurified_hardened.rs +++ b/crates/crypto/hd/src/bip32/key_space/components/unsecurified_hardened.rs @@ -45,8 +45,8 @@ use crate::prelude::*; derive_more::Debug, )] #[deref(forward)] -#[display("{}", self.to_bip32_string())] -#[debug("{}", self.to_bip32_string_debug())] +#[display("{}", self.to_cap43_string())] +#[debug("{}", self.to_cap43_string_debug())] pub struct UnsecurifiedHardened(pub U30); impl UnsecurifiedHardened { @@ -103,13 +103,9 @@ impl TryFrom for UnsecurifiedHardened { } } -pub const UNSECURIFIED_HARDENED_CANONICAL_SUFFIX: &str = "H"; -pub const UNSECURIFIED_HARDENED_NON_CANONICAL_SUFFIX: &str = "'"; impl IsPathComponentStringConvertible for UnsecurifiedHardened { - const CANONICAL_SUFFIX: &'static str = - UNSECURIFIED_HARDENED_CANONICAL_SUFFIX; - const NON_CANONICAL_SUFFIX: &'static str = - UNSECURIFIED_HARDENED_NON_CANONICAL_SUFFIX; + const VERBOSE_SYNTAX_SUFFIX: &'static str = HARDENED_SUFFIX_BIP32; + const SHORTHAND_SYNTAX_SUFFIX: &'static str = HARDENED_SUFFIX_BIP44; } impl HasIndexInLocalKeySpace for UnsecurifiedHardened { @@ -145,7 +141,7 @@ impl TryFrom for UnsecurifiedHardened { impl FromStr for UnsecurifiedHardened { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_cap43_string(s) } } @@ -189,7 +185,7 @@ mod tests { } #[test] - fn from_str_valid_canonical_0() { + fn from_str_valid_verbose_syntax_0() { assert_eq!( "0H".parse::().unwrap(), SUT::from_local_key_space(U31::ZERO).unwrap() @@ -197,7 +193,7 @@ mod tests { } #[test] - fn from_str_valid_canonical_1() { + fn from_str_valid_verbose_syntax_1() { assert_eq!( "1H".parse::().unwrap(), SUT::from_local_key_space(U31::ONE).unwrap() @@ -205,7 +201,7 @@ mod tests { } #[test] - fn from_str_valid_canonical_max() { + fn from_str_valid_verbose_syntax_max() { assert_eq!( "1073741823H".parse::().unwrap(), SUT::from_local_key_space(U30_MAX).unwrap() diff --git a/crates/crypto/hd/src/bip32/key_space/key_space.rs b/crates/crypto/hd/src/bip32/key_space/key_space.rs index fac189575..2cec312f6 100644 --- a/crates/crypto/hd/src/bip32/key_space/key_space.rs +++ b/crates/crypto/hd/src/bip32/key_space/key_space.rs @@ -13,12 +13,12 @@ use crate::prelude::*; derive_more::Display, )] pub enum KeySpace { - #[debug("{}", if *is_hardened { UnsecurifiedHardened::NON_CANONICAL_SUFFIX } else { "" })] - #[display("{}", if *is_hardened { UnsecurifiedHardened::CANONICAL_SUFFIX } else { "" })] + #[debug("{}", if *is_hardened { UnsecurifiedHardened::SHORTHAND_SYNTAX_SUFFIX } else { "" })] + #[display("{}", if *is_hardened { UnsecurifiedHardened::VERBOSE_SYNTAX_SUFFIX } else { "" })] Unsecurified { is_hardened: bool }, - #[debug("{}", SecurifiedU30::NON_CANONICAL_SUFFIX)] - #[display("{}", SecurifiedU30::CANONICAL_SUFFIX)] + #[debug("{}", SecurifiedU30::SHORTHAND_SYNTAX_SUFFIX)] + #[display("{}", SecurifiedU30::VERBOSE_SYNTAX_SUFFIX)] Securified, } diff --git a/crates/crypto/hd/src/bip32/traits/from_bip32_str.rs b/crates/crypto/hd/src/bip32/traits/from_bip32_str.rs index 766d36357..efa98b804 100644 --- a/crates/crypto/hd/src/bip32/traits/from_bip32_str.rs +++ b/crates/crypto/hd/src/bip32/traits/from_bip32_str.rs @@ -1,27 +1,24 @@ use crate::prelude::*; -pub trait FromBIP32Str: Sized { - fn from_bip32_string(s: impl AsRef) -> Result; -} +pub trait ValueInLocalKeyspaceFromBIP32Str: Sized { + fn value_in_local_keyspace_from_cap43_string( + s: impl AsRef, + ) -> Result; + + fn value_in_local_keyspace_from_cap43_string_with_acceptable_suffixes( + s: impl AsRef, + acceptable_suffixes: Vec<&str>, + ) -> Result { + assert!(!acceptable_suffixes.is_empty()); -impl FromBIP32Str - for T -{ - /// Parse a BIP32 path string into a `T`. - /// - /// e.g: - /// ``` - /// extern crate sargon; - /// use sargon::prelude::*; - /// - /// assert!(AccountPath::from_bip32_string("m/44'/1022'/1'/525'/1460'/1'").is_ok()); - /// ``` - fn from_bip32_string(s: impl AsRef) -> Result { let s = s.as_ref(); - let suffix_min_len = std::cmp::min( - T::CANONICAL_SUFFIX.len(), - T::NON_CANONICAL_SUFFIX.len(), - ); + + let suffix_min_len = acceptable_suffixes + .iter() + .map(|s| s.len()) + .min() + .expect("at least one suffix"); + let min_len = suffix_min_len + 1; let e = CommonError::InvalidBIP32Path { bad_value: s.to_string(), @@ -31,12 +28,57 @@ impl FromBIP32Str } if suffix_min_len > 0 { let suffix = &s[s.len() - suffix_min_len..]; - if !T::ACCEPTABLE_SUFFIXES.contains(&suffix) { + if !acceptable_suffixes.contains(&suffix) { return Err(e); } } - let value: u32 = - s[..s.len() - suffix_min_len].parse().map_err(|_| e)?; - T::from_local_key_space(value) + s[..s.len() - suffix_min_len].parse().map_err(|_| e) + } +} + +/// CAP43 string [described here][doc] +/// +/// [doc]: https://radixdlt.atlassian.net/wiki/spaces/AT/pages/3880058888/CAP-43+Sargon+HD+Path+string+notation +pub trait FromCAP43String: Sized { + fn from_cap43_string(s: impl AsRef) -> Result; +} + +impl FromCAP43String + for T +{ + /// Parse a BIP32 path string into a `Self`. + /// + /// e.g: + /// ``` + /// extern crate sargon; + /// use sargon::prelude::*; + /// + /// assert!(AccountPath::from_cap43_string("m/44'/1022'/1'/525'/1460'/1'").is_ok()); + /// ``` + fn from_cap43_string(s: impl AsRef) -> Result { + let value = Self::value_in_local_keyspace_from_cap43_string(s)?; + Self::from_local_key_space(value) + } +} + +impl ValueInLocalKeyspaceFromBIP32Str + for T +{ + /// Parse a BIP32 path string into a `u32` raw value without any offsets. + /// + /// e.g: + /// ``` + /// extern crate sargon; + /// use sargon::prelude::*; + /// + /// assert!(AccountPath::from_cap43_string("m/44'/1022'/1'/525'/1460'/1'").is_ok()); + /// ``` + fn value_in_local_keyspace_from_cap43_string( + s: impl AsRef, + ) -> Result { + Self::value_in_local_keyspace_from_cap43_string_with_acceptable_suffixes( + s, + T::ACCEPTABLE_SUFFIXES.to_vec(), + ) } } diff --git a/crates/crypto/hd/src/bip32/traits/is_path_component_string_convertible.rs b/crates/crypto/hd/src/bip32/traits/is_path_component_string_convertible.rs index 51d45512e..8b6fe81f8 100644 --- a/crates/crypto/hd/src/bip32/traits/is_path_component_string_convertible.rs +++ b/crates/crypto/hd/src/bip32/traits/is_path_component_string_convertible.rs @@ -1,6 +1,6 @@ pub trait IsPathComponentStringConvertible { - const CANONICAL_SUFFIX: &'static str; - const NON_CANONICAL_SUFFIX: &'static str; + const VERBOSE_SYNTAX_SUFFIX: &'static str; + const SHORTHAND_SYNTAX_SUFFIX: &'static str; const ACCEPTABLE_SUFFIXES: [&'static str; 2] = - [Self::CANONICAL_SUFFIX, Self::NON_CANONICAL_SUFFIX]; + [Self::VERBOSE_SYNTAX_SUFFIX, Self::SHORTHAND_SYNTAX_SUFFIX]; } diff --git a/crates/crypto/hd/src/bip32/traits/to_bip32_str.rs b/crates/crypto/hd/src/bip32/traits/to_bip32_str.rs index 3c126c8d4..b40db77c7 100644 --- a/crates/crypto/hd/src/bip32/traits/to_bip32_str.rs +++ b/crates/crypto/hd/src/bip32/traits/to_bip32_str.rs @@ -1,26 +1,29 @@ use crate::prelude::*; -pub trait ToBIP32Str: Sized { - fn to_bip32_string(&self) -> String; - fn to_bip32_string_debug(&self) -> String; +/// [CAP43][doc] uses `iS` instead of `{i+2^30}H` - for values in securified key space. +/// +/// [doc]: https://radixdlt.atlassian.net/wiki/spaces/AT/pages/3880058888/CAP-43+Sargon+HD+Path+string+notation +pub trait ToCAP43String: Sized { + fn to_cap43_string(&self) -> String; + fn to_cap43_string_debug(&self) -> String; } -impl ToBIP32Str for T +impl ToCAP43String for T where T: IsPathComponentStringConvertible + IsInLocalKeySpace, { - fn to_bip32_string(&self) -> String { + fn to_cap43_string(&self) -> String { format!( "{}{}", u32::from(self.index_in_local_key_space()), - T::CANONICAL_SUFFIX + T::VERBOSE_SYNTAX_SUFFIX ) } - fn to_bip32_string_debug(&self) -> String { + fn to_cap43_string_debug(&self) -> String { format!( "{}{}", u32::from(self.index_in_local_key_space()), - T::NON_CANONICAL_SUFFIX + T::SHORTHAND_SYNTAX_SUFFIX ) } } diff --git a/crates/crypto/hd/src/bip44/bip44_like_path.rs b/crates/crypto/hd/src/bip44/bip44_like_path.rs index a400581b5..33070d073 100644 --- a/crates/crypto/hd/src/bip44/bip44_like_path.rs +++ b/crates/crypto/hd/src/bip44/bip44_like_path.rs @@ -38,8 +38,8 @@ use crate::prelude::*; derive_more::Debug, derive_more::Display, )] -#[display("{}", self.to_bip32_string())] -#[debug("{}", self.to_bip32_string_debug())] +#[display("{}", self.to_cap43_string())] +#[debug("{}", self.to_cap43_string_debug())] pub struct BIP44LikePath { pub account: HDPathComponent, pub change: HDPathComponent, @@ -150,24 +150,24 @@ impl TryFrom for BIP44LikePath { } } -impl ToBIP32Str for BIP44LikePath { - fn to_bip32_string(&self) -> String { - self.to_hd_path().to_bip32_string() +impl ToCAP43String for BIP44LikePath { + fn to_cap43_string(&self) -> String { + self.to_hd_path().to_cap43_string() } - fn to_bip32_string_debug(&self) -> String { - self.to_hd_path().to_bip32_string_debug() + fn to_cap43_string_debug(&self) -> String { + self.to_hd_path().to_cap43_string_debug() } } -impl FromBIP32Str for BIP44LikePath { - fn from_bip32_string(s: impl AsRef) -> Result { - HDPath::from_bip32_string(s).and_then(Self::try_from) +impl FromCAP43String for BIP44LikePath { + fn from_cap43_string(s: impl AsRef) -> Result { + HDPath::from_cap43_string(s).and_then(Self::try_from) } } impl FromStr for BIP44LikePath { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_cap43_string(s) } } @@ -243,7 +243,7 @@ mod tests { } #[test] - fn from_str_hardened_non_canonical() { + fn from_str_hardened_shorthand_syntax() { let sut = SUT::from_str("m/44'/1022'/0'/0/8'").unwrap(); assert_eq!( sut.index, @@ -265,7 +265,7 @@ mod tests { } #[test] - fn from_str_unhardened_non_canonical() { + fn from_str_unhardened_shorthand_syntax() { let sut = SUT::from_str("m/44'/1022'/0'/0/6").unwrap(); assert_eq!( sut.index, diff --git a/crates/crypto/hd/src/cap26/paths/account_path.rs b/crates/crypto/hd/src/cap26/paths/account_path.rs index 4706f24ba..3f5cedbe8 100644 --- a/crates/crypto/hd/src/cap26/paths/account_path.rs +++ b/crates/crypto/hd/src/cap26/paths/account_path.rs @@ -62,8 +62,8 @@ use crate::prelude::*; DeserializeFromStr, derive_more::Display, )] -#[display("{}", self.to_bip32_string())] -#[debug("{}", self.to_bip32_string_debug())] +#[display("{}", self.to_cap43_string())] +#[debug("{}", self.to_cap43_string_debug())] pub struct AccountPath { pub network_id: NetworkID, pub key_kind: CAP26KeyKind, @@ -144,25 +144,25 @@ impl HasEntityKind for AccountPath { } } -impl ToBIP32Str for AccountPath { - fn to_bip32_string(&self) -> String { - self.to_hd_path().to_bip32_string() +impl ToCAP43String for AccountPath { + fn to_cap43_string(&self) -> String { + self.to_hd_path().to_cap43_string() } - fn to_bip32_string_debug(&self) -> String { - self.to_hd_path().to_bip32_string_debug() + fn to_cap43_string_debug(&self) -> String { + self.to_hd_path().to_cap43_string_debug() } } -impl FromBIP32Str for AccountPath { - fn from_bip32_string(s: impl AsRef) -> Result { - HDPath::from_bip32_string(s).and_then(Self::try_from) +impl FromCAP43String for AccountPath { + fn from_cap43_string(s: impl AsRef) -> Result { + HDPath::from_cap43_string(s).and_then(Self::try_from) } } impl FromStr for AccountPath { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_cap43_string(s) } } @@ -437,4 +437,15 @@ mod tests { let b: AccountPath = "m/44H/1022H/1H/525H/1678H/0H".parse().unwrap(); assert_ne!(a, b); } + + #[test] + fn from_bip32_str() { + let canonical = "m/44H/1022H/1H/525H/1460H/1073741824H"; + let sut = SUT::from_str(canonical).unwrap(); + assert_eq!( + DerivationPath::from(sut.clone()).to_bip32_string(), + canonical + ); + assert_eq!(sut.to_cap43_string(), "m/44H/1022H/1H/525H/1460H/0S"); + } } diff --git a/crates/crypto/hd/src/cap26/paths/get_id_path.rs b/crates/crypto/hd/src/cap26/paths/get_id_path.rs index 8a76c18e1..0c0b16bb1 100644 --- a/crates/crypto/hd/src/cap26/paths/get_id_path.rs +++ b/crates/crypto/hd/src/cap26/paths/get_id_path.rs @@ -1,8 +1,8 @@ use crate::prelude::*; #[derive(Clone, Default, derive_more::Debug, derive_more::Display)] -#[display("{}", self.to_bip32_string())] -#[debug("{}", self.to_bip32_string_debug())] +#[display("{}", self.to_cap43_string())] +#[debug("{}", self.to_cap43_string_debug())] pub struct GetIDPath; impl GetIDPath { @@ -21,12 +21,12 @@ impl GetIDPath { } } -impl ToBIP32Str for GetIDPath { - fn to_bip32_string(&self) -> String { - self.to_hd_path().to_bip32_string() +impl ToCAP43String for GetIDPath { + fn to_cap43_string(&self) -> String { + self.to_hd_path().to_cap43_string() } - fn to_bip32_string_debug(&self) -> String { - self.to_hd_path().to_bip32_string_debug() + fn to_cap43_string_debug(&self) -> String { + self.to_hd_path().to_cap43_string_debug() } } diff --git a/crates/crypto/hd/src/cap26/paths/identity_path.rs b/crates/crypto/hd/src/cap26/paths/identity_path.rs index 073044845..1e1137bfb 100644 --- a/crates/crypto/hd/src/cap26/paths/identity_path.rs +++ b/crates/crypto/hd/src/cap26/paths/identity_path.rs @@ -62,8 +62,8 @@ use crate::prelude::*; DeserializeFromStr, derive_more::Display, )] -#[display("{}", self.to_bip32_string())] -#[debug("{}", self.to_bip32_string_debug())] +#[display("{}", self.to_cap43_string())] +#[debug("{}", self.to_cap43_string_debug())] pub struct IdentityPath { pub network_id: NetworkID, pub key_kind: CAP26KeyKind, @@ -145,25 +145,25 @@ impl HasEntityKind for IdentityPath { } } -impl ToBIP32Str for IdentityPath { - fn to_bip32_string(&self) -> String { - self.to_hd_path().to_bip32_string() +impl ToCAP43String for IdentityPath { + fn to_cap43_string(&self) -> String { + self.to_hd_path().to_cap43_string() } - fn to_bip32_string_debug(&self) -> String { - self.to_hd_path().to_bip32_string_debug() + fn to_cap43_string_debug(&self) -> String { + self.to_hd_path().to_cap43_string_debug() } } -impl FromBIP32Str for IdentityPath { - fn from_bip32_string(s: impl AsRef) -> Result { - HDPath::from_bip32_string(s).and_then(Self::try_from) +impl FromCAP43String for IdentityPath { + fn from_cap43_string(s: impl AsRef) -> Result { + HDPath::from_cap43_string(s).and_then(Self::try_from) } } impl FromStr for IdentityPath { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_cap43_string(s) } } diff --git a/crates/crypto/hd/src/derivation/derivation_path.rs b/crates/crypto/hd/src/derivation/derivation_path.rs index 5a5e2300a..b827a23fb 100644 --- a/crates/crypto/hd/src/derivation/derivation_path.rs +++ b/crates/crypto/hd/src/derivation/derivation_path.rs @@ -45,7 +45,7 @@ macro_rules! path_union { impl FromStr for $union_name { type Err = CommonError; fn from_str(s: &str) -> Result { - Self::from_bip32_string(s) + Self::from_cap43_string(s) } } @@ -59,8 +59,8 @@ macro_rules! path_union { } } - pub fn to_canonical_bip32_string(&self) -> String { - self.to_hd_path().to_canonical_bip32_string() + pub fn to_bip32_string(&self) -> String { + self.to_hd_path().to_bip32_string() } } impl From<$union_name> for HDPath { @@ -69,21 +69,21 @@ macro_rules! path_union { } } - impl ToBIP32Str for $union_name { - fn to_bip32_string(&self) -> String { - self.to_hd_path().to_bip32_string() + impl ToCAP43String for $union_name { + fn to_cap43_string(&self) -> String { + self.to_hd_path().to_cap43_string() } - fn to_bip32_string_debug(&self) -> String { - self.to_hd_path().to_bip32_string_debug() + fn to_cap43_string_debug(&self) -> String { + self.to_hd_path().to_cap43_string_debug() } } - impl FromBIP32Str for $union_name { - fn from_bip32_string(s: impl AsRef) -> Result { + impl FromCAP43String for $union_name { + fn from_cap43_string(s: impl AsRef) -> Result { let s = s.as_ref(); Result::::Err(CommonError::InvalidBIP32Path { bad_value: s.to_owned() }) $( - .or($variant_type::from_bip32_string(s).map(Self::[< $variant_name:snake >])) + .or_else(|_| $variant_type::from_cap43_string(s).map(Self::[< $variant_name:snake >])) )+ } @@ -251,42 +251,42 @@ mod tests { type SUT = DerivationPath; #[test] - fn test_to_bip32_string_is_display_account() { + fn test_to_cap43_string_is_display_account() { let sut = SUT::Account { value: AccountPath::sample(), }; - assert_eq!(sut.to_bip32_string(), format!("{}", sut)); + assert_eq!(sut.to_cap43_string(), format!("{}", sut)); } #[test] - fn test_to_bip32_string_is_debug_account() { + fn test_to_cap43_string_debug_is_debug_account() { let sut = SUT::Account { value: AccountPath::sample(), }; - assert_eq!(sut.to_bip32_string_debug(), format!("{:?}", sut)); + assert_eq!(sut.to_cap43_string_debug(), format!("{:?}", sut)); } #[test] - fn test_to_bip32_string_is_display_identity() { + fn test_to_cap43_string_is_display_identity() { let sut = SUT::Identity { value: IdentityPath::sample(), }; - assert_eq!(sut.to_bip32_string(), format!("{}", sut)); + assert_eq!(sut.to_cap43_string(), format!("{}", sut)); } #[test] - fn test_to_bip32_string_is_debug_identity() { + fn test_to_cap43_string_debug_is_debug_identity() { let sut = SUT::Identity { value: IdentityPath::sample(), }; - assert_eq!(sut.to_bip32_string_debug(), format!("{:?}", sut)); + assert_eq!(sut.to_cap43_string_debug(), format!("{:?}", sut)); } #[test] fn string_roundtrip_account_from_account() { let value = AccountPath::sample(); - let s = value.to_bip32_string(); - let path2 = SUT::from_bip32_string(&s).unwrap(); + let s = value.to_cap43_string(); + let path2 = SUT::from_cap43_string(&s).unwrap(); assert_eq!(SUT::Account { value }, path2); } @@ -295,16 +295,16 @@ mod tests { let sut = SUT::Account { value: AccountPath::sample(), }; - let s = sut.to_bip32_string(); - let value = AccountPath::from_bip32_string(&s).unwrap(); + let s = sut.to_cap43_string(); + let value = AccountPath::from_cap43_string(&s).unwrap(); assert_eq!(SUT::Account { value }, sut) } #[test] fn string_roundtrip_identity_from_identity() { let value = IdentityPath::sample(); - let s = value.to_bip32_string(); - let path2 = SUT::from_bip32_string(&s).unwrap(); + let s = value.to_cap43_string(); + let path2 = SUT::from_cap43_string(&s).unwrap(); assert_eq!(SUT::Identity { value }, path2); } @@ -313,16 +313,16 @@ mod tests { let sut = SUT::Identity { value: IdentityPath::sample(), }; - let s = sut.to_bip32_string(); - let value = IdentityPath::from_bip32_string(&s).unwrap(); + let s = sut.to_cap43_string(); + let value = IdentityPath::from_cap43_string(&s).unwrap(); assert_eq!(SUT::Identity { value }, sut) } #[test] fn string_roundtrip_bip44_from_bip44() { let value = BIP44LikePath::sample(); - let s = value.to_bip32_string(); - let path2 = SUT::from_bip32_string(&s).unwrap(); + let s = value.to_cap43_string(); + let path2 = SUT::from_cap43_string(&s).unwrap(); assert_eq!(SUT::Bip44Like { value }, path2); } @@ -331,8 +331,8 @@ mod tests { let sut = SUT::Bip44Like { value: BIP44LikePath::sample(), }; - let s = sut.to_bip32_string(); - let value = BIP44LikePath::from_bip32_string(&s).unwrap(); + let s = sut.to_cap43_string(); + let value = BIP44LikePath::from_cap43_string(&s).unwrap(); assert_eq!(SUT::Bip44Like { value }, sut) } @@ -351,15 +351,23 @@ mod tests { }; assert_eq!( - sut.to_bip32_string(), + sut.to_cap43_string(), "m/44H/1022H/1H/525H/1460H/1073741823H" ); assert_eq!( - sut.to_canonical_bip32_string(), + sut.to_bip32_string(), "m/44H/1022H/1H/525H/1460H/1073741823H" ); } + #[test] + fn from_bip32_str() { + let canonical = "m/44H/1022H/1H/525H/1460H/1073741824H"; + let sut = SUT::from_str(canonical).unwrap(); + assert_eq!(sut.to_bip32_string(), canonical); + assert_eq!(sut.to_cap43_string(), "m/44H/1022H/1H/525H/1460H/0S"); + } + #[test] fn string_representation_of_canonical_and_non_canonical_for_securified_derivation_path_zero( ) { @@ -372,19 +380,19 @@ mod tests { ), }; - assert_eq!(sut.to_bip32_string(), "m/44H/1022H/1H/525H/1460H/0S"); + assert_eq!(sut.to_cap43_string(), "m/44H/1022H/1H/525H/1460H/0S"); assert_eq!( - sut.to_canonical_bip32_string(), + sut.to_bip32_string(), "m/44H/1022H/1H/525H/1460H/1073741824H" ); assert_eq!( - sut.to_canonical_bip32_string(), + sut.to_bip32_string(), format!("m/44H/1022H/1H/525H/1460H/{}H", 2u32.pow(30)) ); } #[test] - fn string_representation_of_canonical_and_non_canonical_for_securified_derivation_path_2( + fn string_representation_of_canonical_and_shorthand_syntax_for_securified_derivation_path_2( ) { let sut = SUT::Account { value: AccountPath::new( @@ -395,15 +403,15 @@ mod tests { ), }; - assert_eq!(sut.to_bip32_string(), "m/44H/1022H/1H/525H/1460H/2S"); + assert_eq!(sut.to_cap43_string(), "m/44H/1022H/1H/525H/1460H/2S"); assert_eq!( - sut.to_canonical_bip32_string(), + sut.to_bip32_string(), "m/44H/1022H/1H/525H/1460H/1073741826H" ) } #[test] - fn string_representation_of_canonical_and_non_canonical_for_unsecurified_derivation_path( + fn string_representation_of_canonical_and_shorthand_syntax_for_unsecurified_derivation_path( ) { let sut = SUT::Account { value: AccountPath::new( @@ -414,7 +422,7 @@ mod tests { ), }; - assert_eq!(sut.to_bip32_string(), sut.to_canonical_bip32_string()); + assert_eq!(sut.to_cap43_string(), sut.to_bip32_string()); } #[test] diff --git a/crates/factors/factors/Cargo.toml b/crates/factors/factors/Cargo.toml index af97a9494..0f01a99b6 100644 --- a/crates/factors/factors/Cargo.toml +++ b/crates/factors/factors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "factors" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/factors/instances-provider/Cargo.toml b/crates/factors/instances-provider/Cargo.toml index 925b5b12f..d7b024465 100644 --- a/crates/factors/instances-provider/Cargo.toml +++ b/crates/factors/instances-provider/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "factor-instances-provider" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/factors/keys-collector/Cargo.toml b/crates/factors/keys-collector/Cargo.toml index fbcd674ac..681ce0ae4 100644 --- a/crates/factors/keys-collector/Cargo.toml +++ b/crates/factors/keys-collector/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "keys-collector" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/factors/next-derivation-index-ephemeral/Cargo.toml b/crates/factors/next-derivation-index-ephemeral/Cargo.toml index 1ba4bb7a5..f27d1ce9a 100644 --- a/crates/factors/next-derivation-index-ephemeral/Cargo.toml +++ b/crates/factors/next-derivation-index-ephemeral/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "next-derivation-index-ephemeral" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/factors/next-derivation-index-ephemeral/src/agnostic_paths/index_agnostic_path.rs b/crates/factors/next-derivation-index-ephemeral/src/agnostic_paths/index_agnostic_path.rs index 4f423082f..1bec97d18 100644 --- a/crates/factors/next-derivation-index-ephemeral/src/agnostic_paths/index_agnostic_path.rs +++ b/crates/factors/next-derivation-index-ephemeral/src/agnostic_paths/index_agnostic_path.rs @@ -40,7 +40,7 @@ impl FromStr for IndexAgnosticPath { let key_space = KeySpace::from_str(&key_space_component)?; let parts = parts[..3].to_vec(); let s = parts.join(HDPath::SEPARATOR); - let hd_path = HDPath::from_bip32_string(s)?; + let hd_path = HDPath::from_cap43_string(s)?; let components = hd_path.components(); let network_id = NetworkID::try_from(components[0])?; @@ -73,7 +73,7 @@ impl IndexAgnosticPath { } fn _to_str(&self) -> String { - let base = self._to_hd_path().to_bip32_string_with(false, false); + let base = self._to_hd_path().to_cap43_string_with(false, false); format!("{}/{}{}", base, self.key_space, Self::COMPONENT_SUFFIX) } } diff --git a/crates/factors/supporting-types/Cargo.toml b/crates/factors/supporting-types/Cargo.toml index 073665988..706ecaaad 100644 --- a/crates/factors/supporting-types/Cargo.toml +++ b/crates/factors/supporting-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "factors-supporting-types" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/gateway/client-and-api/Cargo.toml b/crates/gateway/client-and-api/Cargo.toml index 80427ae5c..6bfa60c86 100644 --- a/crates/gateway/client-and-api/Cargo.toml +++ b/crates/gateway/client-and-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gateway-client-and-api" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/gateway/models/Cargo.toml b/crates/gateway/models/Cargo.toml index 565d9be26..55bd50a11 100644 --- a/crates/gateway/models/Cargo.toml +++ b/crates/gateway/models/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gateway-models" -version = "1.1.118" +version = "1.1.119" edition = "2021" diff --git a/crates/profile/logic/logic_SPLIT_ME/Cargo.toml b/crates/profile/logic/logic_SPLIT_ME/Cargo.toml index c272fdab0..4e65c4a31 100644 --- a/crates/profile/logic/logic_SPLIT_ME/Cargo.toml +++ b/crates/profile/logic/logic_SPLIT_ME/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-logic" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/models/account-for-display/Cargo.toml b/crates/profile/models/account-for-display/Cargo.toml index 580e4dc02..af342790b 100644 --- a/crates/profile/models/account-for-display/Cargo.toml +++ b/crates/profile/models/account-for-display/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "account-for-display" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/models/account-or-persona/Cargo.toml b/crates/profile/models/account-or-persona/Cargo.toml index a04c9324b..73886a322 100644 --- a/crates/profile/models/account-or-persona/Cargo.toml +++ b/crates/profile/models/account-or-persona/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-account-or-persona" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/models/account/Cargo.toml b/crates/profile/models/account/Cargo.toml index f1f6d969c..3d0fab4a2 100644 --- a/crates/profile/models/account/Cargo.toml +++ b/crates/profile/models/account/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-account" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/models/app-preferences/Cargo.toml b/crates/profile/models/app-preferences/Cargo.toml index 7f397eae6..2c2953a84 100644 --- a/crates/profile/models/app-preferences/Cargo.toml +++ b/crates/profile/models/app-preferences/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-app-preferences" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/models/base-entity/Cargo.toml b/crates/profile/models/base-entity/Cargo.toml index d81e45eb9..4616c8419 100644 --- a/crates/profile/models/base-entity/Cargo.toml +++ b/crates/profile/models/base-entity/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-base-entity" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/models/gateway/Cargo.toml b/crates/profile/models/gateway/Cargo.toml index 25a4460a8..61f572e75 100644 --- a/crates/profile/models/gateway/Cargo.toml +++ b/crates/profile/models/gateway/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-gateway" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/models/persona-data/Cargo.toml b/crates/profile/models/persona-data/Cargo.toml index 572f946de..6d345b48a 100644 --- a/crates/profile/models/persona-data/Cargo.toml +++ b/crates/profile/models/persona-data/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-persona-data" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/models/persona/Cargo.toml b/crates/profile/models/persona/Cargo.toml index ab140f11d..d103f63c4 100644 --- a/crates/profile/models/persona/Cargo.toml +++ b/crates/profile/models/persona/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-persona" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/models/profile_SPLIT_ME/Cargo.toml b/crates/profile/models/profile_SPLIT_ME/Cargo.toml index 73bdbedcf..8da4a7fbb 100644 --- a/crates/profile/models/profile_SPLIT_ME/Cargo.toml +++ b/crates/profile/models/profile_SPLIT_ME/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile" -version = "1.1.118" +version = "1.1.119" edition = "2021" diff --git a/crates/profile/models/security-structures/Cargo.toml b/crates/profile/models/security-structures/Cargo.toml index 09a63c549..1ca4dc31c 100644 --- a/crates/profile/models/security-structures/Cargo.toml +++ b/crates/profile/models/security-structures/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-security-structures" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/models/supporting-types/Cargo.toml b/crates/profile/models/supporting-types/Cargo.toml index d56f0c49b..e56d370ee 100644 --- a/crates/profile/models/supporting-types/Cargo.toml +++ b/crates/profile/models/supporting-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-supporting-types" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/profile/traits/entity-by-address/Cargo.toml b/crates/profile/traits/entity-by-address/Cargo.toml index 60b06682c..7ad27fb91 100644 --- a/crates/profile/traits/entity-by-address/Cargo.toml +++ b/crates/profile/traits/entity-by-address/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "entity-by-address" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/sargon/Cargo.toml b/crates/sargon/Cargo.toml index 7c410d7c5..b2e942deb 100644 --- a/crates/sargon/Cargo.toml +++ b/crates/sargon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon" -version = "1.1.118" +version = "1.1.119" edition = "2021" resolver = "2" # features enabled in integration test diff --git a/crates/sargon/tests/vectors/main.rs b/crates/sargon/tests/vectors/main.rs index 14713735f..8bf37bb63 100644 --- a/crates/sargon/tests/vectors/main.rs +++ b/crates/sargon/tests/vectors/main.rs @@ -142,12 +142,12 @@ mod cap26_tests { // Test display let derivation_path = DerivationPath::from(account_path.clone()); pretty_assertions::assert_eq!( - derivation_path.to_canonical_bip32_string(), + derivation_path.to_bip32_string(), path_canonical_notation ); if let Some(path_securified_notation) = path_securified_notation { pretty_assertions::assert_eq!( - derivation_path.to_bip32_string(), + derivation_path.to_cap43_string(), path_securified_notation ); pretty_assertions::assert_eq!( diff --git a/crates/system/clients/clients/Cargo.toml b/crates/system/clients/clients/Cargo.toml index 69571a33a..f8072434b 100644 --- a/crates/system/clients/clients/Cargo.toml +++ b/crates/system/clients/clients/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clients" -version = "1.1.118" +version = "1.1.119" edition = "2021" diff --git a/crates/system/clients/http/Cargo.toml b/crates/system/clients/http/Cargo.toml index b0a10fad1..b3b4bbc8c 100644 --- a/crates/system/clients/http/Cargo.toml +++ b/crates/system/clients/http/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "http-client" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/system/drivers/Cargo.toml b/crates/system/drivers/Cargo.toml index 57c377f20..b2851f69e 100644 --- a/crates/system/drivers/Cargo.toml +++ b/crates/system/drivers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "drivers" -version = "1.1.118" +version = "1.1.119" edition = "2021" diff --git a/crates/system/interactors/Cargo.toml b/crates/system/interactors/Cargo.toml index df0a6bf43..4925f6de4 100644 --- a/crates/system/interactors/Cargo.toml +++ b/crates/system/interactors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "interactors" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/system/os/accounts/Cargo.toml b/crates/system/os/accounts/Cargo.toml index 1e0d761bd..5e5548d2f 100644 --- a/crates/system/os/accounts/Cargo.toml +++ b/crates/system/os/accounts/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon-os-accounts" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/system/os/derive-public-keys/Cargo.toml b/crates/system/os/derive-public-keys/Cargo.toml index 76a5b3bcc..fed592368 100644 --- a/crates/system/os/derive-public-keys/Cargo.toml +++ b/crates/system/os/derive-public-keys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon-os-derive-public-keys" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/system/os/factors/Cargo.toml b/crates/system/os/factors/Cargo.toml index 53b662d32..a56bcf005 100644 --- a/crates/system/os/factors/Cargo.toml +++ b/crates/system/os/factors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon-os-factors" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/system/os/os/Cargo.toml b/crates/system/os/os/Cargo.toml index a76e6576f..50fb76121 100644 --- a/crates/system/os/os/Cargo.toml +++ b/crates/system/os/os/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon-os" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/system/os/security-center/Cargo.toml b/crates/system/os/security-center/Cargo.toml index f82bfb8a1..4996439c7 100644 --- a/crates/system/os/security-center/Cargo.toml +++ b/crates/system/os/security-center/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon-os-security-center" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/system/os/signing/Cargo.toml b/crates/system/os/signing/Cargo.toml index c7c7b1f93..8d43f92ee 100644 --- a/crates/system/os/signing/Cargo.toml +++ b/crates/system/os/signing/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon-os-signing" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/system/os/transaction/Cargo.toml b/crates/system/os/transaction/Cargo.toml index 1a35230c4..9ced834e7 100644 --- a/crates/system/os/transaction/Cargo.toml +++ b/crates/system/os/transaction/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon-os-transaction" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/system/profile-state-holder/Cargo.toml b/crates/system/profile-state-holder/Cargo.toml index 52e3b84bb..690453cfc 100644 --- a/crates/system/profile-state-holder/Cargo.toml +++ b/crates/system/profile-state-holder/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "profile-state-holder" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/system/sub-systems/Cargo.toml b/crates/system/sub-systems/Cargo.toml index 71f0b2be6..d5e0c8471 100644 --- a/crates/system/sub-systems/Cargo.toml +++ b/crates/system/sub-systems/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sub-systems" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/transaction/foundation/Cargo.toml b/crates/transaction/foundation/Cargo.toml index a6f91d9d4..48e54e263 100644 --- a/crates/transaction/foundation/Cargo.toml +++ b/crates/transaction/foundation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "transaction-foundation" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/transaction/manifests/Cargo.toml b/crates/transaction/manifests/Cargo.toml index c623bea0a..766f95e5f 100644 --- a/crates/transaction/manifests/Cargo.toml +++ b/crates/transaction/manifests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "manifests" -version = "1.1.118" +version = "1.1.119" edition = "2021" diff --git a/crates/transaction/models/Cargo.toml b/crates/transaction/models/Cargo.toml index c263edbcd..da3090f92 100644 --- a/crates/transaction/models/Cargo.toml +++ b/crates/transaction/models/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "transaction-models" -version = "1.1.118" +version = "1.1.119" edition = "2021" diff --git a/crates/uniffi/conversion-macros/Cargo.toml b/crates/uniffi/conversion-macros/Cargo.toml index 3712f68d6..64f24df2f 100644 --- a/crates/uniffi/conversion-macros/Cargo.toml +++ b/crates/uniffi/conversion-macros/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "sargon-uniffi-conversion-macros" -version = "1.1.118" +version = "1.1.119" edition = "2021" [dependencies] diff --git a/crates/uniffi/uniffi_SPLIT_ME/Cargo.toml b/crates/uniffi/uniffi_SPLIT_ME/Cargo.toml index 8f00827f2..c16c9eaf6 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/Cargo.toml +++ b/crates/uniffi/uniffi_SPLIT_ME/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon-uniffi" -version = "1.1.118" +version = "1.1.119" edition = "2021" build = "build.rs" diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/hierarchical_deterministic/bip32/hd_path_component.rs b/crates/uniffi/uniffi_SPLIT_ME/src/hierarchical_deterministic/bip32/hd_path_component.rs index f83482306..81183d574 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/hierarchical_deterministic/bip32/hd_path_component.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/hierarchical_deterministic/bip32/hd_path_component.rs @@ -4,7 +4,7 @@ use sargon::{ IsKeySpaceAware, }; -use sargon::{FromGlobalKeySpace, IsMappableToGlobalKeySpace, ToBIP32Str}; +use sargon::{FromGlobalKeySpace, IsMappableToGlobalKeySpace, ToCAP43String}; #[derive(Clone, Debug, PartialEq, Eq, Hash, uniffi::Enum)] pub enum HDPathComponent { @@ -81,14 +81,14 @@ pub fn hd_path_component_to_hardened( #[uniffi::export] pub fn hd_path_component_to_bip32_string(component: HDPathComponent) -> String { - component.into_internal().to_bip32_string() + component.into_internal().to_cap43_string() } #[uniffi::export] pub fn hd_path_component_to_bip32_string_debug( component: HDPathComponent, ) -> String { - component.into_internal().to_bip32_string_debug() + component.into_internal().to_cap43_string_debug() } #[uniffi::export] diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/hierarchical_deterministic/derivation/derivation_path.rs b/crates/uniffi/uniffi_SPLIT_ME/src/hierarchical_deterministic/derivation/derivation_path.rs index 37cbfe7d7..16fbe303f 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/hierarchical_deterministic/derivation/derivation_path.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/hierarchical_deterministic/derivation/derivation_path.rs @@ -36,9 +36,17 @@ pub fn derivation_path_to_string(path: &DerivationPath) -> String { path.into_internal().to_string() } +/// String representation of the path using BIP32 notation. +/// 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 on 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. #[uniffi::export] -pub fn derivation_path_to_canonical_bip32_string( - path: &DerivationPath, -) -> String { - path.into_internal().to_canonical_bip32_string() +pub fn derivation_path_to_bip32_string(path: &DerivationPath) -> String { + path.into_internal().to_bip32_string() } diff --git a/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/DerivationPath.kt b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/DerivationPath.kt index 8ef512f0d..8541b4a28 100644 --- a/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/DerivationPath.kt +++ b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/DerivationPath.kt @@ -10,7 +10,7 @@ import com.radixdlt.sargon.HdPathComponent import com.radixdlt.sargon.IdentityPath import com.radixdlt.sargon.NetworkId import com.radixdlt.sargon.Slip10Curve -import com.radixdlt.sargon.derivationPathToCanonicalBip32String +import com.radixdlt.sargon.derivationPathToBip32String import com.radixdlt.sargon.derivationPathToHdPath import com.radixdlt.sargon.derivationPathToString import com.radixdlt.sargon.newDerivationPathFromString @@ -37,8 +37,8 @@ fun DerivationPath.Companion.initForEntity( val DerivationPath.displayString get() = derivationPathToString(path = this) -val DerivationPath.bip32CanonicalString: String - get() = derivationPathToCanonicalBip32String(path = this) +val DerivationPath.bip32String: String + get() = derivationPathToBip32String(path = this) val DerivationPath.path: HdPath get() = derivationPathToHdPath(path = this) diff --git a/jvm/sargon-android/src/test/java/com/radixdlt/sargon/DerivationPathTest.kt b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/DerivationPathTest.kt index b01682e16..56df39c24 100644 --- a/jvm/sargon-android/src/test/java/com/radixdlt/sargon/DerivationPathTest.kt +++ b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/DerivationPathTest.kt @@ -1,7 +1,7 @@ package com.radixdlt.sargon import com.radixdlt.sargon.extensions.asGeneral -import com.radixdlt.sargon.extensions.bip32CanonicalString +import com.radixdlt.sargon.extensions.bip32String import com.radixdlt.sargon.extensions.curve import com.radixdlt.sargon.extensions.displayString import com.radixdlt.sargon.extensions.init @@ -72,7 +72,7 @@ class DerivationPathTest: SampleTestable { ) assertEquals( "m/44H/1022H/1H/525H/1460H/1073741824H", - accountPathInSecurifiedSpace.bip32CanonicalString + accountPathInSecurifiedSpace.bip32String ) val accountPathInUnsecurifiedSpace = AccountPath.init( @@ -87,7 +87,7 @@ class DerivationPathTest: SampleTestable { ) assertEquals( "m/44H/1022H/1H/525H/1460H/0H", - accountPathInUnsecurifiedSpace.bip32CanonicalString + accountPathInUnsecurifiedSpace.bip32String ) }