From 4653813ac37ec378062b44bd5ce7acec125f9570 Mon Sep 17 00:00:00 2001 From: matiasbzurovski <164921079+matiasbzurovski@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:51:39 +0100 Subject: [PATCH] [ABW-4135] Export method to derive public keys (#350) * WIP * extension for Subintent * additions for auth intent * export method to get Hash from AuthIntentHash * remove export * allow to create account with specific Factor Source * export method to create account with specific factor source * only pre derive VECI * export method to create Persona * specify network id when creating account * WIP * Rename variant * fixes after rebase * revert cache filling quantiites changes * tests and improvements * treat main babylon device factor source as 'main_bdfs' rather than 'bdfs' * remove is_main_bdfs() from FactorSourceCommon * remove unwanted change * Release 1.1.118 account-for-display@1.1.118 addresses@1.1.118 assert-json@1.1.118 build-info@1.1.118 bytes@1.1.118 cap26-models@1.1.118 clients@1.1.118 core-collections@1.1.118 core-misc@1.1.118 core-utils@1.1.118 drivers@1.1.118 ecc@1.1.118 encryption@1.1.118 entity-by-address@1.1.118 entity-foundation@1.1.118 error@1.1.118 factor-instances-provider@1.1.118 factors@1.1.118 factors-supporting-types@1.1.118 gateway-client-and-api@1.1.118 gateway-models@1.1.118 has-sample-values@1.1.118 hash@1.1.118 hierarchical-deterministic@1.1.118 home-cards@1.1.118 host-info@1.1.118 http-client@1.1.118 identified-vec-of@1.1.118 interactors@1.1.118 key-derivation-traits@1.1.118 keys-collector@1.1.118 manifests@1.1.118 metadata@1.1.118 network@1.1.118 next-derivation-index-ephemeral@1.1.118 numeric@1.1.118 prelude@1.1.118 profile@1.1.118 profile-account@1.1.118 profile-account-or-persona@1.1.118 profile-app-preferences@1.1.118 profile-base-entity@1.1.118 profile-gateway@1.1.118 profile-logic@1.1.118 profile-persona@1.1.118 profile-persona-data@1.1.118 profile-security-structures@1.1.118 profile-state-holder@1.1.118 profile-supporting-types@1.1.118 radix-connect@1.1.118 radix-connect-models@1.1.118 sargon@1.1.118 sargon-os@1.1.118 sargon-os-accounts@1.1.118 sargon-os-derive-public-keys@1.1.118 sargon-os-factors@1.1.118 sargon-os-security-center@1.1.118 sargon-os-signing@1.1.118 sargon-os-transaction@1.1.118 sargon-uniffi@1.1.118 sargon-uniffi-conversion-macros@1.1.118 security-center@1.1.118 short-string@1.1.118 signing@1.1.118 signing-traits@1.1.118 sub-systems@1.1.118 time-utils@1.1.118 transaction-foundation@1.1.118 transaction-models@1.1.118 Generated by cargo-workspaces --------- Co-authored-by: micbakos-rdx --- Cargo.lock | 186 ++++++++++-------- Cargo.toml | 3 + ...essOfAccountOrPersona+Wrap+Functions.swift | 7 + .../CompiledSubintent+Wrap+Functions.swift | 4 + ...iledTransactionIntent+Wrap+Functions.swift | 4 + ...etInteractionMetadata+Wrap+Functions.swift | 16 ++ .../AuthIntent+Wrap+Functions.swift | 8 + ...lletInteractionMetadata+SampleValues.swift | 9 + ...WalletInteractionMetadata+Swiftified.swift | 8 + .../SargonOS/SargonOS+SargonOSProtocol.swift | 29 ++- .../SargonOS/SargonOS+Static+Shared.swift | 9 +- .../Sargon/SargonOS/SargonOSProtocol.swift | 12 +- apple/Sources/Sargon/SargonOS/TestOS.swift | 7 +- .../SargonOS/SargonOSTests.swift | 11 +- .../SargonOS/TestOSTests.swift | 4 +- .../AddressOfAccountOrPersonaTests.swift | 12 +- crates/app/home-cards/Cargo.toml | 2 +- crates/app/key-derivation-traits/Cargo.toml | 2 +- .../src/derivation_purpose.rs | 3 + 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/factors/factors/Cargo.toml | 2 +- .../factors/src/factor_source_common.rs | 10 - .../device_factor_source.rs | 17 +- crates/factors/instances-provider/Cargo.toml | 2 +- .../next_derivation_entity_index_assigner.rs | 2 +- crates/factors/keys-collector/Cargo.toml | 2 +- .../Cargo.toml | 2 +- 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 +- .../src/logic/query_factor_sources.rs | 10 +- .../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 +- .../profile_SPLIT_ME/src/v100/profile.rs | 2 +- .../models/security-structures/Cargo.toml | 2 +- .../models/supporting-types/Cargo.toml | 2 +- .../traits/entity-by-address/Cargo.toml | 2 +- crates/sargon/Cargo.toml | 3 +- crates/sargon/src/lib.rs | 1 + 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 | 30 +++ .../system/os/derive-public-keys/src/lib.rs | 24 +++ .../src/sargon_os_derive_public_keys.rs | 166 ++++++++++++++++ .../os/derive-public-keys/src/support/mod.rs | 3 + .../derive-public-keys/src/support/source.rs | 11 ++ crates/system/os/factors/Cargo.toml | 2 +- .../sargon_os_apply_shield.rs | 26 +-- .../os/factors/src/test_instances_provider.rs | 34 ++-- crates/system/os/os/Cargo.toml | 2 +- crates/system/os/os/src/os_testing_support.rs | 8 +- crates/system/os/os/src/sargon_os.rs | 14 +- crates/system/os/os/src/sargon_os_accounts.rs | 97 +++++---- crates/system/os/os/src/sargon_os_factors.rs | 22 ++- crates/system/os/os/src/sargon_os_personas.rs | 114 +++++++---- crates/system/os/os/src/sargon_os_profile.rs | 4 +- 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 +- .../src/keys_collector/derivation_purpose.rs | 3 + .../dapp_metadata/interaction_metadata.rs | 14 ++ .../sargon_os/entities/sargon_os_accounts.rs | 59 ++++-- .../src/system/sargon_os/mod.rs | 4 + .../sargon_os/sargon_os_derive_public_keys.rs | 30 +++ .../src/system/sargon_os/sargon_os_factors.rs | 4 +- .../system/sargon_os/sargon_os_personas.rs | 46 +++++ 111 files changed, 879 insertions(+), 345 deletions(-) create mode 100644 apple/Sources/Sargon/Extensions/Methods/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+Wrap+Functions.swift create mode 100644 apple/Sources/Sargon/Extensions/Methods/Signing/Authentication/AuthIntent+Wrap+Functions.swift create mode 100644 apple/Sources/Sargon/Extensions/SampleValues/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+SampleValues.swift create mode 100644 apple/Sources/Sargon/Extensions/Swiftified/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+Swiftified.swift create mode 100644 crates/system/os/derive-public-keys/Cargo.toml create mode 100644 crates/system/os/derive-public-keys/src/lib.rs create mode 100644 crates/system/os/derive-public-keys/src/sargon_os_derive_public_keys.rs create mode 100644 crates/system/os/derive-public-keys/src/support/mod.rs create mode 100644 crates/system/os/derive-public-keys/src/support/source.rs create mode 100644 crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_derive_public_keys.rs create mode 100644 crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_personas.rs diff --git a/Cargo.lock b/Cargo.lock index b79a8080a..ef34c204f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "account-for-display" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "derive_more", @@ -49,10 +49,10 @@ dependencies = [ [[package]] name = "addresses" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", - "bytes 1.1.117", + "bytes 1.1.118", "cap26-models", "core-utils", "derive_more", @@ -246,7 +246,7 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "assert-json" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json-diff", "error", @@ -546,7 +546,7 @@ dependencies = [ [[package]] name = "build-info" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", "cargo_toml", @@ -573,7 +573,7 @@ checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce" [[package]] name = "bytes" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", "delegate", @@ -607,7 +607,7 @@ dependencies = [ [[package]] name = "cap26-models" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", "derive_more", @@ -748,7 +748,7 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "clients" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "async-trait", @@ -808,7 +808,7 @@ checksum = "0d8a42181e0652c2997ae4d217f25b63c5337a52fd2279736e97b832fa0a3cff" [[package]] name = "core-collections" -version = "1.1.117" +version = "1.1.118" dependencies = [ "has-sample-values", "indexmap 2.7.0", @@ -835,7 +835,7 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "core-misc" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", "core-utils", @@ -855,7 +855,7 @@ dependencies = [ [[package]] name = "core-utils" -version = "1.1.117" +version = "1.1.118" dependencies = [ "error", "iso8601-timestamp", @@ -1084,7 +1084,7 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "drivers" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "addresses", @@ -1108,10 +1108,10 @@ dependencies = [ [[package]] name = "ecc" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", - "bytes 1.1.117", + "bytes 1.1.118", "derive_more", "enum-as-inner", "error", @@ -1210,11 +1210,11 @@ dependencies = [ [[package]] name = "encryption" -version = "1.1.117" +version = "1.1.118" dependencies = [ "aes-gcm", "assert-json", - "bytes 1.1.117", + "bytes 1.1.118", "derive_more", "error", "has-sample-values", @@ -1231,7 +1231,7 @@ dependencies = [ [[package]] name = "entity-by-address" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "error", @@ -1243,7 +1243,7 @@ dependencies = [ [[package]] name = "entity-foundation" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", "derive_more", @@ -1318,7 +1318,7 @@ dependencies = [ [[package]] name = "error" -version = "1.1.117" +version = "1.1.118" dependencies = [ "derive_more", "log", @@ -1377,7 +1377,7 @@ dependencies = [ [[package]] name = "factor-instances-provider" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "addresses", @@ -1403,9 +1403,9 @@ dependencies = [ [[package]] name = "factors" -version = "1.1.117" +version = "1.1.118" dependencies = [ - "bytes 1.1.117", + "bytes 1.1.118", "cap26-models", "core-collections", "core-misc", @@ -1440,7 +1440,7 @@ dependencies = [ [[package]] name = "factors-supporting-types" -version = "1.1.117" +version = "1.1.118" dependencies = [ "async-trait", "error", @@ -1593,7 +1593,7 @@ dependencies = [ [[package]] name = "gateway-client-and-api" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "addresses", @@ -1613,7 +1613,7 @@ dependencies = [ [[package]] name = "gateway-models" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "assert-json", @@ -1718,7 +1718,7 @@ dependencies = [ [[package]] name = "has-sample-values" -version = "1.1.117" +version = "1.1.118" dependencies = [ "error", "indexmap 2.7.0", @@ -1729,9 +1729,9 @@ dependencies = [ [[package]] name = "hash" -version = "1.1.117" +version = "1.1.118" dependencies = [ - "bytes 1.1.117", + "bytes 1.1.118", "derive_more", "prelude", "radix-common", @@ -1795,11 +1795,11 @@ dependencies = [ [[package]] name = "hierarchical-deterministic" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", "bip39", - "bytes 1.1.117", + "bytes 1.1.118", "cap26-models", "derive_more", "ecc", @@ -1842,13 +1842,13 @@ dependencies = [ [[package]] name = "home-cards" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "addresses", "async-trait", "base64", - "bytes 1.1.117", + "bytes 1.1.118", "core-utils", "derive_more", "drivers", @@ -1868,7 +1868,7 @@ dependencies = [ [[package]] name = "host-info" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", "derive_more", @@ -1915,10 +1915,10 @@ dependencies = [ [[package]] name = "http-client" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", - "bytes 1.1.117", + "bytes 1.1.118", "core-utils", "drivers", "error", @@ -2143,7 +2143,7 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "identified-vec-of" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", "derive_more", @@ -2216,7 +2216,7 @@ dependencies = [ [[package]] name = "interactors" -version = "1.1.117" +version = "1.1.118" dependencies = [ "async-trait", "derive_more", @@ -2336,7 +2336,7 @@ dependencies = [ [[package]] name = "key-derivation-traits" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "async-trait", @@ -2354,7 +2354,7 @@ dependencies = [ [[package]] name = "keys-collector" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "addresses", @@ -2443,7 +2443,7 @@ dependencies = [ [[package]] name = "manifests" -version = "1.1.117" +version = "1.1.118" dependencies = [ "account-for-display", "addresses", @@ -2484,7 +2484,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "metadata" -version = "1.1.117" +version = "1.1.118" dependencies = [ "derive_more", "has-sample-values", @@ -2584,7 +2584,7 @@ dependencies = [ [[package]] name = "network" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", "enum-iterator", @@ -2600,7 +2600,7 @@ dependencies = [ [[package]] name = "next-derivation-index-ephemeral" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "assert-json", @@ -2676,9 +2676,9 @@ dependencies = [ [[package]] name = "numeric" -version = "1.1.117" +version = "1.1.118" dependencies = [ - "bytes 1.1.117", + "bytes 1.1.118", "delegate", "derive_more", "enum-iterator", @@ -2898,7 +2898,7 @@ dependencies = [ [[package]] name = "prelude" -version = "1.1.117" +version = "1.1.118" dependencies = [ "radix-engine", "radix-engine-toolkit", @@ -2935,7 +2935,7 @@ dependencies = [ [[package]] name = "profile" -version = "1.1.117" +version = "1.1.118" dependencies = [ "account-for-display", "addresses", @@ -2979,7 +2979,7 @@ dependencies = [ [[package]] name = "profile-account" -version = "1.1.117" +version = "1.1.118" dependencies = [ "account-for-display", "addresses", @@ -2999,7 +2999,7 @@ dependencies = [ [[package]] name = "profile-account-or-persona" -version = "1.1.117" +version = "1.1.118" dependencies = [ "cap26-models", "derive_more", @@ -3016,7 +3016,7 @@ dependencies = [ [[package]] name = "profile-app-preferences" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "core-misc", @@ -3039,7 +3039,7 @@ dependencies = [ [[package]] name = "profile-base-entity" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "derive_more", @@ -3062,7 +3062,7 @@ dependencies = [ [[package]] name = "profile-gateway" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "assert-json", @@ -3086,7 +3086,7 @@ dependencies = [ [[package]] name = "profile-logic" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "derive_more", @@ -3108,7 +3108,7 @@ dependencies = [ [[package]] name = "profile-persona" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "cap26-models", @@ -3129,7 +3129,7 @@ dependencies = [ [[package]] name = "profile-persona-data" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "assert-json", @@ -3148,7 +3148,7 @@ dependencies = [ [[package]] name = "profile-security-structures" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "cap26-models", @@ -3176,7 +3176,7 @@ dependencies = [ [[package]] name = "profile-state-holder" -version = "1.1.117" +version = "1.1.118" dependencies = [ "derive_more", "error", @@ -3191,7 +3191,7 @@ dependencies = [ [[package]] name = "profile-supporting-types" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "derive_more", @@ -3280,14 +3280,14 @@ dependencies = [ [[package]] name = "radix-connect" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "addresses", "assert-json", "async-trait", "base64", - "bytes 1.1.117", + "bytes 1.1.118", "core-misc", "core-utils", "derive_more", @@ -3315,10 +3315,10 @@ dependencies = [ [[package]] name = "radix-connect-models" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", - "bytes 1.1.117", + "bytes 1.1.118", "core-misc", "derive_more", "error", @@ -3760,7 +3760,7 @@ dependencies = [ [[package]] name = "sargon" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "addresses", @@ -3805,6 +3805,7 @@ dependencies = [ "radix-transactions", "sargon-os", "sargon-os-accounts", + "sargon-os-derive-public-keys", "sargon-os-factors", "sargon-os-security-center", "sargon-os-signing", @@ -3824,7 +3825,7 @@ dependencies = [ [[package]] name = "sargon-os" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "async-trait", @@ -3851,7 +3852,7 @@ dependencies = [ [[package]] name = "sargon-os-accounts" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "addresses", @@ -3872,9 +3873,28 @@ dependencies = [ "transaction-models", ] +[[package]] +name = "sargon-os-derive-public-keys" +version = "1.1.118" +dependencies = [ + "actix-rt", + "async-trait", + "clients", + "derive_more", + "drivers", + "error", + "interactors", + "key-derivation-traits", + "keys-collector", + "log", + "prelude", + "profile", + "sargon-os", +] + [[package]] name = "sargon-os-factors" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "async-trait", @@ -3902,7 +3922,7 @@ dependencies = [ [[package]] name = "sargon-os-security-center" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "derive_more", @@ -3918,7 +3938,7 @@ dependencies = [ [[package]] name = "sargon-os-signing" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "async-trait", @@ -3944,7 +3964,7 @@ dependencies = [ [[package]] name = "sargon-os-transaction" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "async-std", @@ -3973,7 +3993,7 @@ dependencies = [ [[package]] name = "sargon-uniffi" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "addresses", @@ -4030,7 +4050,7 @@ dependencies = [ [[package]] name = "sargon-uniffi-conversion-macros" -version = "1.1.117" +version = "1.1.118" dependencies = [ "proc-macro2", "quote", @@ -4203,7 +4223,7 @@ dependencies = [ [[package]] name = "security-center" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", "assert-json", @@ -4371,7 +4391,7 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "short-string" -version = "1.1.117" +version = "1.1.118" dependencies = [ "arraystring", "assert-json", @@ -4406,13 +4426,13 @@ dependencies = [ [[package]] name = "signing" -version = "1.1.117" +version = "1.1.118" dependencies = [ "actix-rt", "addresses", "assert-json", "async-trait", - "bytes 1.1.117", + "bytes 1.1.118", "cap26-models", "core-collections", "core-misc", @@ -4444,10 +4464,10 @@ dependencies = [ [[package]] name = "signing-traits" -version = "1.1.117" +version = "1.1.118" dependencies = [ "async-trait", - "bytes 1.1.117", + "bytes 1.1.118", "core-collections", "derive_more", "ecc", @@ -4612,7 +4632,7 @@ dependencies = [ [[package]] name = "sub-systems" -version = "1.1.117" +version = "1.1.118" dependencies = [ "derive_more", "drivers", @@ -4771,7 +4791,7 @@ dependencies = [ [[package]] name = "time-utils" -version = "1.1.117" +version = "1.1.118" dependencies = [ "iso8601-timestamp", "prelude", @@ -4921,10 +4941,10 @@ dependencies = [ [[package]] name = "transaction-foundation" -version = "1.1.117" +version = "1.1.118" dependencies = [ "assert-json", - "bytes 1.1.117", + "bytes 1.1.118", "derive_more", "has-sample-values", "paste", @@ -4936,10 +4956,10 @@ dependencies = [ [[package]] name = "transaction-models" -version = "1.1.117" +version = "1.1.118" dependencies = [ "addresses", - "bytes 1.1.117", + "bytes 1.1.118", "cargo_toml", "core-collections", "core-misc", diff --git a/Cargo.toml b/Cargo.toml index 3bdf3055d..12ff6ee5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,6 +76,7 @@ members = [ "crates/system/profile-state-holder", "crates/system/interactors", "crates/system/os/accounts", + "crates/system/os/derive-public-keys", "crates/system/os/factors", "crates/system/os/os", "crates/system/os/security-center", @@ -167,6 +168,7 @@ default-members = [ "crates/system/profile-state-holder", "crates/system/interactors", "crates/system/os/accounts", + "crates/system/os/derive-public-keys", "crates/system/os/factors", "crates/system/os/os", "crates/system/os/security-center", @@ -275,6 +277,7 @@ sub-systems = { path = "crates/system/sub-systems" } profile-state-holder = { path = "crates/system/profile-state-holder" } interactors = { path = "crates/system/interactors" } sargon-os-accounts = { path = "crates/system/os/accounts" } +sargon-os-derive-public-keys = { path = "crates/system/os/derive-public-keys" } sargon-os-factors = { path = "crates/system/os/factors" } sargon-os = { path = "crates/system/os/os" } sargon-os-security-center = { path = "crates/system/os/security-center" } diff --git a/apple/Sources/Sargon/Extensions/Methods/Address/AddressOfAccountOrPersona+Wrap+Functions.swift b/apple/Sources/Sargon/Extensions/Methods/Address/AddressOfAccountOrPersona+Wrap+Functions.swift index 78389c58d..3258ddf62 100644 --- a/apple/Sources/Sargon/Extensions/Methods/Address/AddressOfAccountOrPersona+Wrap+Functions.swift +++ b/apple/Sources/Sargon/Extensions/Methods/Address/AddressOfAccountOrPersona+Wrap+Functions.swift @@ -17,6 +17,13 @@ extension AddressOfAccountOrPersona { public func formatted(_ format: AddressFormat) -> String { addressOfAccountOrPersonaFormatted(address: self, format: format) } + + public var accountAddress: AccountAddress? { + switch self { + case let .account(address): address + case .identity: nil + } + } } #if DEBUG diff --git a/apple/Sources/Sargon/Extensions/Methods/RET/CompiledSubintent+Wrap+Functions.swift b/apple/Sources/Sargon/Extensions/Methods/RET/CompiledSubintent+Wrap+Functions.swift index 4e56b33a7..c499fb75b 100644 --- a/apple/Sources/Sargon/Extensions/Methods/RET/CompiledSubintent+Wrap+Functions.swift +++ b/apple/Sources/Sargon/Extensions/Methods/RET/CompiledSubintent+Wrap+Functions.swift @@ -5,4 +5,8 @@ extension CompiledSubintent { public var data: Data { compiledSubintentBytes(compiledIntent: self) } + + public func decompile() -> Subintent { + compiledSubintentDecompile(compiledIntent: self) + } } diff --git a/apple/Sources/Sargon/Extensions/Methods/RET/CompiledTransactionIntent+Wrap+Functions.swift b/apple/Sources/Sargon/Extensions/Methods/RET/CompiledTransactionIntent+Wrap+Functions.swift index c72146d62..d66bd5252 100644 --- a/apple/Sources/Sargon/Extensions/Methods/RET/CompiledTransactionIntent+Wrap+Functions.swift +++ b/apple/Sources/Sargon/Extensions/Methods/RET/CompiledTransactionIntent+Wrap+Functions.swift @@ -5,4 +5,8 @@ extension CompiledTransactionIntent { public var data: Data { compiledTransactionIntentBytes(compiledIntent: self) } + + public func decompile() -> TransactionIntent { + compiledTransactionIntentDecompile(compiledIntent: self) + } } diff --git a/apple/Sources/Sargon/Extensions/Methods/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+Wrap+Functions.swift b/apple/Sources/Sargon/Extensions/Methods/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+Wrap+Functions.swift new file mode 100644 index 000000000..09033dbf6 --- /dev/null +++ b/apple/Sources/Sargon/Extensions/Methods/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+Wrap+Functions.swift @@ -0,0 +1,16 @@ +import Foundation +import SargonUniFFI + +extension DappToWalletInteractionMetadata { + public init(jsonData: some DataProtocol) throws { + self = try newDappToWalletInteractionMetadataFromJsonBytes( + jsonBytes: Data(jsonData) + ) + } + + public func jsonData() -> Data { + dappToWalletInteractionMetadataToJsonBytes( + dappToWalletInteractionMetadata: self + ) + } +} diff --git a/apple/Sources/Sargon/Extensions/Methods/Signing/Authentication/AuthIntent+Wrap+Functions.swift b/apple/Sources/Sargon/Extensions/Methods/Signing/Authentication/AuthIntent+Wrap+Functions.swift new file mode 100644 index 000000000..8b50329d7 --- /dev/null +++ b/apple/Sources/Sargon/Extensions/Methods/Signing/Authentication/AuthIntent+Wrap+Functions.swift @@ -0,0 +1,8 @@ +import Foundation +import SargonUniFFI + +extension AuthIntent { + public func hash() -> AuthIntentHash { + authIntentGetHash(authIntent: self) + } +} diff --git a/apple/Sources/Sargon/Extensions/SampleValues/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+SampleValues.swift b/apple/Sources/Sargon/Extensions/SampleValues/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+SampleValues.swift new file mode 100644 index 000000000..b7b18c6a2 --- /dev/null +++ b/apple/Sources/Sargon/Extensions/SampleValues/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+SampleValues.swift @@ -0,0 +1,9 @@ +import Foundation +import SargonUniFFI + +#if DEBUG +extension DappToWalletInteractionMetadata { + public static let sample: Self = newDappToWalletInteractionMetadataSample() + public static let sampleOther: Self = newDappToWalletInteractionMetadataSampleOther() +} +#endif // DEBUG diff --git a/apple/Sources/Sargon/Extensions/Swiftified/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+Swiftified.swift b/apple/Sources/Sargon/Extensions/Swiftified/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+Swiftified.swift new file mode 100644 index 000000000..dab436194 --- /dev/null +++ b/apple/Sources/Sargon/Extensions/Swiftified/RadixConnect/WalletInteraction/DappToWalletInteractionMetadata+Swiftified.swift @@ -0,0 +1,8 @@ +import Foundation +import SargonUniFFI + +// MARK: - DappToWalletInteractionMetadata + SargonObjectCodable +extension DappToWalletInteractionMetadata: SargonObjectCodable {} + +// MARK: - DappToWalletInteractionMetadata + SargonModel +extension DappToWalletInteractionMetadata: SargonModel {} diff --git a/apple/Sources/Sargon/SargonOS/SargonOS+SargonOSProtocol.swift b/apple/Sources/Sargon/SargonOS/SargonOS+SargonOSProtocol.swift index 7b73efaec..af490b32b 100644 --- a/apple/Sources/Sargon/SargonOS/SargonOS+SargonOSProtocol.swift +++ b/apple/Sources/Sargon/SargonOS/SargonOS+SargonOSProtocol.swift @@ -9,8 +9,33 @@ extension SargonOS: SargonOSProtocol { extension SargonOS { @discardableResult public func createAccount( - named accountName: DisplayName + factorSource: FactorSource, + networkId: NetworkID?, + name: DisplayName ) async throws -> Account { - try await createAndSaveNewAccount(networkId: currentNetworkID, name: accountName) + try await createAndSaveNewAccountWithFactorSource(factorSource: factorSource, networkId: networkId ?? currentNetworkID, name: name) + } + + @discardableResult + public func createAccountWithBDFS( + networkId: NetworkID?, + name: DisplayName + ) async throws -> Account { + try await createAndSaveNewAccountWithMainBdfs(networkId: networkId ?? currentNetworkID, name: name) + } + + public func createPersona( + factorSource: FactorSource, + name: DisplayName, + personaData: PersonaData? + ) async throws -> Persona { + try await createAndSaveNewPersonaWithFactorSource(factorSource: factorSource, networkId: currentNetworkID, name: name, personaData: personaData) + } + + public func createPersonaWithBDFS( + name: DisplayName, + personaData: PersonaData? + ) async throws -> Persona { + try await createAndSaveNewPersonaWithMainBdfs(networkId: currentNetworkID, name: name, personaData: personaData) } } diff --git a/apple/Sources/Sargon/SargonOS/SargonOS+Static+Shared.swift b/apple/Sources/Sargon/SargonOS/SargonOS+Static+Shared.swift index d07d485d5..e45be10be 100644 --- a/apple/Sources/Sargon/SargonOS/SargonOS+Static+Shared.swift +++ b/apple/Sources/Sargon/SargonOS/SargonOS+Static+Shared.swift @@ -11,7 +11,7 @@ struct SargonOSAlreadyBooted: LocalizedError { extension SargonOS { public nonisolated(unsafe) static var shared: SargonOS { guard let shared = _shared else { - fatalError("`SargonOS.shared` not created, create it with `SargonOS.creatingShared:bootingWith` and pass it a `BIOS`.") + fatalError("`SargonOS.shared` not created, create it with `SargonOS.creatingShared:bootingWith:hostInteractor` and pass it a `BIOS` and a `HostInteractor`.") } return shared } @@ -19,10 +19,12 @@ extension SargonOS { /// Can be access later with `OS.shared` @discardableResult public static func creatingShared( - bootingWith bios: BIOS + bootingWith bios: BIOS, + hostInteractor: HostInteractor ) async throws -> SargonOS { try await _creatingShared( bootingWith: bios, + hostInteractor: hostInteractor, isEmulatingFreshInstall: false ) } @@ -33,6 +35,7 @@ extension SargonOS { @discardableResult static func _creatingShared( bootingWith bios: BIOS, + hostInteractor: HostInteractor, isEmulatingFreshInstall: Bool ) async throws -> SargonOS { if !isEmulatingFreshInstall, _shared != nil { @@ -40,7 +43,7 @@ extension SargonOS { } let shared = await SargonOS.boot( bios: bios, - interactor: ThrowingHostInteractor.shared + interactor: hostInteractor ) Self._shared = shared return shared diff --git a/apple/Sources/Sargon/SargonOS/SargonOSProtocol.swift b/apple/Sources/Sargon/SargonOS/SargonOSProtocol.swift index ed0b31907..1be9066e0 100644 --- a/apple/Sources/Sargon/SargonOS/SargonOSProtocol.swift +++ b/apple/Sources/Sargon/SargonOS/SargonOSProtocol.swift @@ -6,17 +6,19 @@ import SargonUniFFI public protocol SargonOSProtocol { var os: SargonOS { get } - func createAccount( - named accountName: DisplayName + func createAccountWithBDFS( + networkId: NetworkID?, + name: DisplayName ) async throws -> Account } // MARK: Forward calls to `os` extension SargonOSProtocol { - public func createAccount( - named accountName: DisplayName + public func createAccountWithBDFS( + networkId: NetworkID?, + name: DisplayName ) async throws -> Account { - try await os.createAccount(named: accountName) + try await os.createAccountWithBDFS(networkId: networkId, name: name) } } diff --git a/apple/Sources/Sargon/SargonOS/TestOS.swift b/apple/Sources/Sargon/SargonOS/TestOS.swift index 33751d5c3..ef79688f5 100644 --- a/apple/Sources/Sargon/SargonOS/TestOS.swift +++ b/apple/Sources/Sargon/SargonOS/TestOS.swift @@ -57,8 +57,9 @@ extension TestOS { ) } ?? nextAccountName() - let _ = try await os.createAccount( - named: accountName + let _ = try await os.createAccountWithBDFS( + networkId: nil, + name: accountName ) return self } @@ -68,7 +69,7 @@ extension TestOS { count: UInt16, namePrefix: DisplayName ) async throws -> Self { - let _ = try await os.batchCreateManyAccountsThenSaveOnce(count: count, networkId: currentNetworkID, namePrefix: namePrefix.value) + let _ = try await os.batchCreateManyAccountsWithMainBdfsThenSaveOnce(count: count, networkId: currentNetworkID, namePrefix: namePrefix.value) return self } } diff --git a/apple/Tests/IntegrationTests/SargonOS/SargonOSTests.swift b/apple/Tests/IntegrationTests/SargonOS/SargonOSTests.swift index 4cbd708fb..1d866b243 100644 --- a/apple/Tests/IntegrationTests/SargonOS/SargonOSTests.swift +++ b/apple/Tests/IntegrationTests/SargonOS/SargonOSTests.swift @@ -27,7 +27,8 @@ final class SargonOSTests: OSTest { secureStorageDriver: Insecure︕!TestOnly︕!Ephemeral︕!SecureStorage( keychainService: "test" ) - ) + ), + hostInteractor: ThrowingHostInteractor.shared ) XCTAssertTrue(SUT.shared === sut) } @@ -38,9 +39,9 @@ final class SargonOSTests: OSTest { keychainService: "test" ) ) - let _ = try await SUT.creatingShared(bootingWith: bios) + let _ = try await SUT.creatingShared(bootingWith: bios, hostInteractor: ThrowingHostInteractor.shared) do { - let _ = try await SUT.creatingShared(bootingWith: bios) + let _ = try await SUT.creatingShared(bootingWith: bios, hostInteractor: ThrowingHostInteractor.shared) XCTFail("Should have thrown") } catch let err as SargonOSAlreadyBooted { XCTAssertEqual(err.errorDescription, "Radix Wallet core already initialized, should not have been initialized twice. This is a Radix developer error.") @@ -53,8 +54,8 @@ final class SargonOSTests: OSTest { keychainService: "test" ) ) - let first = try await SUT.creatingShared(bootingWith: bios) - let second = try await SUT._creatingShared(bootingWith: bios, isEmulatingFreshInstall: true) + let first = try await SUT.creatingShared(bootingWith: bios, hostInteractor: ThrowingHostInteractor.shared) + let second = try await SUT._creatingShared(bootingWith: bios, hostInteractor: ThrowingHostInteractor.shared, isEmulatingFreshInstall: true) XCTAssertFalse(first === second) XCTAssertTrue(SUT.shared === second) } diff --git a/apple/Tests/IntegrationTests/SargonOS/TestOSTests.swift b/apple/Tests/IntegrationTests/SargonOS/TestOSTests.swift index 0f03c61ae..7b28a3ac3 100644 --- a/apple/Tests/IntegrationTests/SargonOS/TestOSTests.swift +++ b/apple/Tests/IntegrationTests/SargonOS/TestOSTests.swift @@ -61,7 +61,7 @@ final class TestOSTests: OSTest { let sut = await TestOS() try await sut.os.newWallet(shouldPreDeriveInstances: false) let displayName: DisplayName = "New" - let account = try await sut.createAccount(named: displayName) + let account = try await sut.createAccountWithBDFS(networkId: nil, name: displayName) XCTAssertEqual(account.displayName, displayName) XCTAssertEqual(try sut.accountsForDisplayOnCurrentNetwork, [AccountForDisplay(account)]) } @@ -70,7 +70,7 @@ final class TestOSTests: OSTest { let sut = await TestOS() try await sut.os.newWallet(shouldPreDeriveInstances: false) let displayName: DisplayName = "New" - let account = try await sut.createAccount(named: displayName) + let account = try await sut.createAccountWithBDFS(networkId: nil, name: displayName) let lookedUp = try sut.accountByAddress(account.address) XCTAssertEqual(lookedUp, account) } diff --git a/apple/Tests/TestCases/Address/AddressOfAccountOrPersonaTests.swift b/apple/Tests/TestCases/Address/AddressOfAccountOrPersonaTests.swift index dbec49f83..beb1963bf 100644 --- a/apple/Tests/TestCases/Address/AddressOfAccountOrPersonaTests.swift +++ b/apple/Tests/TestCases/Address/AddressOfAccountOrPersonaTests.swift @@ -4,4 +4,14 @@ import Sargon import SargonUniFFI import XCTest -final class AddressOfAccountOrPersonaTests: AddressTest {} +final class AddressOfAccountOrPersonaTests: AddressTest { + func testAccountAddress() throws { + let accountAddress = AccountAddress.sample + + var sut = SUT.account(accountAddress) + XCTAssertEqual(sut.accountAddress, accountAddress) + + sut = SUT.identity(.sample) + XCTAssertNil(sut.accountAddress) + } +} diff --git a/crates/app/home-cards/Cargo.toml b/crates/app/home-cards/Cargo.toml index 11e34d7a0..15267c42c 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/app/key-derivation-traits/Cargo.toml b/crates/app/key-derivation-traits/Cargo.toml index 472165fce..4455a9c62 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/app/key-derivation-traits/src/derivation_purpose.rs b/crates/app/key-derivation-traits/src/derivation_purpose.rs index 183c13011..c7654cdfb 100644 --- a/crates/app/key-derivation-traits/src/derivation_purpose.rs +++ b/crates/app/key-derivation-traits/src/derivation_purpose.rs @@ -27,6 +27,9 @@ pub enum DerivationPurpose { /// When adding a new factor source, initiates keys collection /// for collecting various factor instances. PreDerivingKeys, + + /// When deriving accounts for recovery. + AccountRecovery, } impl DerivationPurpose { diff --git a/crates/app/radix-connect-models/Cargo.toml b/crates/app/radix-connect-models/Cargo.toml index 6af4c3d00..b6f1b8cca 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/app/radix-connect/Cargo.toml b/crates/app/radix-connect/Cargo.toml index 8dd5c426f..dc53d8238 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.117" +version = "1.1.118" edition = "2021" diff --git a/crates/app/security-center/Cargo.toml b/crates/app/security-center/Cargo.toml index c4187468c..9ba275037 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/app/signing-traits/Cargo.toml b/crates/app/signing-traits/Cargo.toml index e86260fdc..0b2823fed 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/app/signing/Cargo.toml b/crates/app/signing/Cargo.toml index f4a78c38d..a267184d4 100644 --- a/crates/app/signing/Cargo.toml +++ b/crates/app/signing/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "signing" -version = "1.1.117" +version = "1.1.118" edition = "2021" diff --git a/crates/common/build-info/Cargo.toml b/crates/common/build-info/Cargo.toml index 8766e0c03..a2301c91b 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.117" +version = "1.1.118" edition = "2021" build = "build.rs" diff --git a/crates/common/bytes/Cargo.toml b/crates/common/bytes/Cargo.toml index 02eb7a2b7..a7f69ebf8 100644 --- a/crates/common/bytes/Cargo.toml +++ b/crates/common/bytes/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bytes" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/common/entity-foundation/Cargo.toml b/crates/common/entity-foundation/Cargo.toml index 7e2e9fbdb..0d0b45447 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/common/host-info/Cargo.toml b/crates/common/host-info/Cargo.toml index 5d5529bcd..79584f0d5 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/common/identified-vec-of/Cargo.toml b/crates/common/identified-vec-of/Cargo.toml index 652a0a828..3e1f31e42 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/common/metadata/Cargo.toml b/crates/common/metadata/Cargo.toml index 41b5143f8..d1aa2de34 100644 --- a/crates/common/metadata/Cargo.toml +++ b/crates/common/metadata/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "metadata" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/common/network/Cargo.toml b/crates/common/network/Cargo.toml index c24be22f3..a146284d9 100644 --- a/crates/common/network/Cargo.toml +++ b/crates/common/network/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "network" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/common/numeric/Cargo.toml b/crates/common/numeric/Cargo.toml index 6eb6e3bd7..bc29a8b61 100644 --- a/crates/common/numeric/Cargo.toml +++ b/crates/common/numeric/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "numeric" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/common/short-string/Cargo.toml b/crates/common/short-string/Cargo.toml index de63e7380..1b7aed0b2 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/core/assert-json/Cargo.toml b/crates/core/assert-json/Cargo.toml index 929dc31bd..c1e503373 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/core/collections/Cargo.toml b/crates/core/collections/Cargo.toml index 70540c3cb..b042b2fb2 100644 --- a/crates/core/collections/Cargo.toml +++ b/crates/core/collections/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-collections" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/core/error/Cargo.toml b/crates/core/error/Cargo.toml index c9c695df5..2e43877b6 100644 --- a/crates/core/error/Cargo.toml +++ b/crates/core/error/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "error" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/core/has-sample-values/Cargo.toml b/crates/core/has-sample-values/Cargo.toml index fae53c3ee..b7530bac4 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/core/misc/Cargo.toml b/crates/core/misc/Cargo.toml index 3bef30c2a..5752a17f4 100644 --- a/crates/core/misc/Cargo.toml +++ b/crates/core/misc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-misc" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/core/prelude/Cargo.toml b/crates/core/prelude/Cargo.toml index 499ac0f44..43745ecd4 100644 --- a/crates/core/prelude/Cargo.toml +++ b/crates/core/prelude/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "prelude" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/core/time-utils/Cargo.toml b/crates/core/time-utils/Cargo.toml index 7137912f6..4efac4373 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/core/utils/Cargo.toml b/crates/core/utils/Cargo.toml index 251ba1ad1..10cbcdb69 100644 --- a/crates/core/utils/Cargo.toml +++ b/crates/core/utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-utils" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/crypto/addresses/Cargo.toml b/crates/crypto/addresses/Cargo.toml index d2cc67a57..21a2c61e1 100644 --- a/crates/crypto/addresses/Cargo.toml +++ b/crates/crypto/addresses/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "addresses" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/crypto/cap26-models/Cargo.toml b/crates/crypto/cap26-models/Cargo.toml index dc751d156..27a5e17dd 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/crypto/ecc/Cargo.toml b/crates/crypto/ecc/Cargo.toml index 394be43a3..f3299b225 100644 --- a/crates/crypto/ecc/Cargo.toml +++ b/crates/crypto/ecc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ecc" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/crypto/encryption/Cargo.toml b/crates/crypto/encryption/Cargo.toml index dd07ae596..122b2d4ad 100644 --- a/crates/crypto/encryption/Cargo.toml +++ b/crates/crypto/encryption/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "encryption" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/crypto/hash/Cargo.toml b/crates/crypto/hash/Cargo.toml index 955568122..b29309411 100644 --- a/crates/crypto/hash/Cargo.toml +++ b/crates/crypto/hash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hash" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/crypto/hd/Cargo.toml b/crates/crypto/hd/Cargo.toml index 6bfe9a793..d816c253a 100644 --- a/crates/crypto/hd/Cargo.toml +++ b/crates/crypto/hd/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hierarchical-deterministic" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/factors/factors/Cargo.toml b/crates/factors/factors/Cargo.toml index 6b382b396..af97a9494 100644 --- a/crates/factors/factors/Cargo.toml +++ b/crates/factors/factors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "factors" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/factors/factors/src/factor_source_common.rs b/crates/factors/factors/src/factor_source_common.rs index 8a50a46df..ff577eb8e 100644 --- a/crates/factors/factors/src/factor_source_common.rs +++ b/crates/factors/factors/src/factor_source_common.rs @@ -100,11 +100,6 @@ impl FactorSourceCommon { self.crypto_parameters.supports_olympia() } - /// Checks if it is Main Babylon Device Factor Source (BDFS). - pub fn is_main_bdfs(&self) -> bool { - self.supports_babylon() && self.is_main() - } - /// Checks if it is a main factor source. pub fn is_main(&self) -> bool { self.flags.contains_by_id(&FactorSourceFlag::Main) @@ -182,11 +177,6 @@ mod tests { assert!(FactorSourceCommon::default().supports_babylon()); } - #[test] - fn new_main_bdfs() { - assert!(FactorSourceCommon::new_main_bdfs().is_main_bdfs()); - } - #[test] fn json_roundtrip() { let date = Timestamp::parse("2023-09-11T16:05:56.000Z").unwrap(); diff --git a/crates/factors/factors/src/factor_sources/device_factor_source/device_factor_source.rs b/crates/factors/factors/src/factor_sources/device_factor_source/device_factor_source.rs index 266a9921d..484e5a11e 100644 --- a/crates/factors/factors/src/factor_sources/device_factor_source/device_factor_source.rs +++ b/crates/factors/factors/src/factor_sources/device_factor_source/device_factor_source.rs @@ -117,7 +117,7 @@ impl DeviceFactorSource { /// Checks if its Main Babylon Device Factor Source (BDFS). pub fn is_main_bdfs(&self) -> bool { - self.common.is_main_bdfs() + self.common.supports_babylon() && self.common.is_main() } } @@ -200,13 +200,26 @@ mod tests { } #[test] - fn main_babylon() { + fn is_main_bdfs() { assert!(SUT::babylon( true, &MnemonicWithPassphrase::sample(), &HostInfo::sample() ) .is_main_bdfs()); + + assert!(!SUT::babylon( + false, + &MnemonicWithPassphrase::sample(), + &HostInfo::sample() + ) + .is_main_bdfs()); + + assert!(!SUT::olympia( + &MnemonicWithPassphrase::sample_device_12_words(), + &HostInfo::sample_other() + ) + .is_main_bdfs()); } #[test] diff --git a/crates/factors/instances-provider/Cargo.toml b/crates/factors/instances-provider/Cargo.toml index de8c5be33..925b5b12f 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/factors/instances-provider/src/next_index_assigner/next_derivation_entity_index_assigner.rs b/crates/factors/instances-provider/src/next_index_assigner/next_derivation_entity_index_assigner.rs index 8c6a2025b..6f957379d 100644 --- a/crates/factors/instances-provider/src/next_index_assigner/next_derivation_entity_index_assigner.rs +++ b/crates/factors/instances-provider/src/next_index_assigner/next_derivation_entity_index_assigner.rs @@ -103,7 +103,7 @@ mod tests { fn next_success() { let network_id = NetworkID::Mainnet; let profile = Arc::new(Profile::sample()); - let bdfs = profile.bdfs(); + let bdfs = profile.main_bdfs(); let cache = FactorInstancesCache::default(); let sut = SUT::new(network_id, profile, cache); diff --git a/crates/factors/keys-collector/Cargo.toml b/crates/factors/keys-collector/Cargo.toml index 34e998100..fbcd674ac 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/factors/next-derivation-index-ephemeral/Cargo.toml b/crates/factors/next-derivation-index-ephemeral/Cargo.toml index 3104a5dfb..1ba4bb7a5 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/factors/supporting-types/Cargo.toml b/crates/factors/supporting-types/Cargo.toml index 52f8081ae..073665988 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/gateway/client-and-api/Cargo.toml b/crates/gateway/client-and-api/Cargo.toml index ad29ca3d7..80427ae5c 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/gateway/models/Cargo.toml b/crates/gateway/models/Cargo.toml index 87ed8bc9c..565d9be26 100644 --- a/crates/gateway/models/Cargo.toml +++ b/crates/gateway/models/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gateway-models" -version = "1.1.117" +version = "1.1.118" edition = "2021" diff --git a/crates/profile/logic/logic_SPLIT_ME/Cargo.toml b/crates/profile/logic/logic_SPLIT_ME/Cargo.toml index 3e3fd12af..c272fdab0 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/logic/logic_SPLIT_ME/src/logic/query_factor_sources.rs b/crates/profile/logic/logic_SPLIT_ME/src/logic/query_factor_sources.rs index 57f714cd8..032202105 100644 --- a/crates/profile/logic/logic_SPLIT_ME/src/logic/query_factor_sources.rs +++ b/crates/profile/logic/logic_SPLIT_ME/src/logic/query_factor_sources.rs @@ -22,7 +22,7 @@ pub trait ProfileFactorSourceQuerying { kind: FactorSourceKind, ) -> Option; - fn bdfs(&self) -> DeviceFactorSource { + fn main_bdfs(&self) -> DeviceFactorSource { let device_factor_sources = self.device_factor_sources(); let explicit_main = device_factor_sources .clone() @@ -239,13 +239,13 @@ mod tests { fn bdfs_success_without_explicit_main_flag() { let profile = Profile::sample_no_factor_source_explicitly_marked_as_main(); - assert_eq!(profile.bdfs().id, DeviceFactorSource::sample().id); + assert_eq!(profile.main_bdfs().id, DeviceFactorSource::sample().id); } #[test] fn bdfs_success_with_explicit_main_flag() { let profile = Profile::sample(); - assert_eq!(profile.bdfs().id, DeviceFactorSource::sample().id); + assert_eq!(profile.main_bdfs().id, DeviceFactorSource::sample().id); } #[test] @@ -254,7 +254,7 @@ mod tests { )] fn bdfs_fail_for_invalid_profile_without_device_factor_source() { let profile = Profile::sample_no_device_factor_source(); - profile.bdfs(); + profile.main_bdfs(); } #[test] @@ -263,7 +263,7 @@ mod tests { )] fn bdfs_fail_for_invalid_profile_without_babylon_device_factor_source() { let profile = Profile::sample_no_babylon_device_factor_source(); - profile.bdfs(); + profile.main_bdfs(); } #[test] diff --git a/crates/profile/models/account-for-display/Cargo.toml b/crates/profile/models/account-for-display/Cargo.toml index c77aecb0b..580e4dc02 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/models/account-or-persona/Cargo.toml b/crates/profile/models/account-or-persona/Cargo.toml index 0aac385d3..a04c9324b 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/models/account/Cargo.toml b/crates/profile/models/account/Cargo.toml index e82887f23..f1f6d969c 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/models/app-preferences/Cargo.toml b/crates/profile/models/app-preferences/Cargo.toml index d27e0f939..7f397eae6 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/models/base-entity/Cargo.toml b/crates/profile/models/base-entity/Cargo.toml index 204a28f32..d81e45eb9 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/models/gateway/Cargo.toml b/crates/profile/models/gateway/Cargo.toml index 40cd71e6f..25a4460a8 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/models/persona-data/Cargo.toml b/crates/profile/models/persona-data/Cargo.toml index a992e1e2d..572f946de 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/models/persona/Cargo.toml b/crates/profile/models/persona/Cargo.toml index 1cfa8b3c4..ab140f11d 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/models/profile_SPLIT_ME/Cargo.toml b/crates/profile/models/profile_SPLIT_ME/Cargo.toml index 8fc8c64f2..73bdbedcf 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.117" +version = "1.1.118" edition = "2021" diff --git a/crates/profile/models/profile_SPLIT_ME/src/v100/profile.rs b/crates/profile/models/profile_SPLIT_ME/src/v100/profile.rs index 9d913f88b..b7b2bc919 100644 --- a/crates/profile/models/profile_SPLIT_ME/src/v100/profile.rs +++ b/crates/profile/models/profile_SPLIT_ME/src/v100/profile.rs @@ -167,7 +167,7 @@ impl Profile { /// The Profile is initialized with a Mainnet ProfileNetwork, and some [Accounts] in it. /// /// # Panics - /// Panics if the `device_factor_source` is not a BDFS and not marked "main". + /// Panics if the `device_factor_source` is not the main BDFS. pub fn from_device_factor_source( device_factor_source: DeviceFactorSource, host_id: HostId, diff --git a/crates/profile/models/security-structures/Cargo.toml b/crates/profile/models/security-structures/Cargo.toml index 8aef829c6..09a63c549 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/models/supporting-types/Cargo.toml b/crates/profile/models/supporting-types/Cargo.toml index 0777c1aa9..d56f0c49b 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/profile/traits/entity-by-address/Cargo.toml b/crates/profile/traits/entity-by-address/Cargo.toml index a427cd8b7..60b06682c 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/sargon/Cargo.toml b/crates/sargon/Cargo.toml index b18a93e6f..7c410d7c5 100644 --- a/crates/sargon/Cargo.toml +++ b/crates/sargon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon" -version = "1.1.117" +version = "1.1.118" edition = "2021" resolver = "2" # features enabled in integration test @@ -47,6 +47,7 @@ signing-traits = { workspace = true } sargon-os = { path = "../system/os/os" } sargon-os-transaction = { path = "../system/os/transaction" } sargon-os-accounts = { workspace = true } +sargon-os-derive-public-keys = { workspace = true } sargon-os-factors = { workspace = true } sargon-os-security-center = { workspace = true } sargon-os-signing = { workspace = true } diff --git a/crates/sargon/src/lib.rs b/crates/sargon/src/lib.rs index 2da961f8d..3498c6e1c 100644 --- a/crates/sargon/src/lib.rs +++ b/crates/sargon/src/lib.rs @@ -15,6 +15,7 @@ pub mod prelude { pub use radix_connect_models::prelude::*; pub use sargon_os::prelude::*; pub use sargon_os_accounts::prelude::*; + pub use sargon_os_derive_public_keys::prelude::*; pub use sargon_os_factors::prelude::*; pub use sargon_os_security_center::prelude::*; pub use sargon_os_signing::prelude::*; diff --git a/crates/system/clients/clients/Cargo.toml b/crates/system/clients/clients/Cargo.toml index c62c938e1..69571a33a 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.117" +version = "1.1.118" edition = "2021" diff --git a/crates/system/clients/http/Cargo.toml b/crates/system/clients/http/Cargo.toml index 7de70a43c..b0a10fad1 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/system/drivers/Cargo.toml b/crates/system/drivers/Cargo.toml index 471261fbb..57c377f20 100644 --- a/crates/system/drivers/Cargo.toml +++ b/crates/system/drivers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "drivers" -version = "1.1.117" +version = "1.1.118" edition = "2021" diff --git a/crates/system/interactors/Cargo.toml b/crates/system/interactors/Cargo.toml index 616d88150..df0a6bf43 100644 --- a/crates/system/interactors/Cargo.toml +++ b/crates/system/interactors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "interactors" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/system/os/accounts/Cargo.toml b/crates/system/os/accounts/Cargo.toml index 65babdbbe..1e0d761bd 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/system/os/derive-public-keys/Cargo.toml b/crates/system/os/derive-public-keys/Cargo.toml new file mode 100644 index 000000000..76a5b3bcc --- /dev/null +++ b/crates/system/os/derive-public-keys/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "sargon-os-derive-public-keys" +version = "1.1.118" +edition = "2021" + +[dependencies] +# === SARGON CRATES === +prelude = { workspace = true } +sargon-os = { path = "../../../system/os/os" } +error = { workspace = true } +key-derivation-traits = { workspace = true } +keys-collector = { workspace = true } +profile = { workspace = true } + +# ==== RADIX DEPENDENCIES ==== +# None + +# ==== EXTERNAL DEPENDENCIES ==== +actix-rt = { workspace = true } +async-trait = { workspace = true } +derive_more = { workspace = true } +log = { workspace = true } + +[dev-dependencies] +# === SARGON CRATES === +prelude = { workspace = true } +drivers = { workspace = true } +interactors = { workspace = true } +clients = { workspace = true } +key-derivation-traits = { workspace = true } diff --git a/crates/system/os/derive-public-keys/src/lib.rs b/crates/system/os/derive-public-keys/src/lib.rs new file mode 100644 index 000000000..bc609a003 --- /dev/null +++ b/crates/system/os/derive-public-keys/src/lib.rs @@ -0,0 +1,24 @@ +mod sargon_os_derive_public_keys; +mod support; + +pub mod prelude { + pub use crate::sargon_os_derive_public_keys::*; + pub use crate::support::*; + + pub(crate) use profile::prelude::*; + pub(crate) use sargon_os::prelude::*; + + pub(crate) use key_derivation_traits::prelude::*; + pub(crate) use keys_collector::prelude::*; + + #[cfg(test)] + pub(crate) use testing::*; + + #[cfg(test)] + mod testing { + pub(crate) use clients::prelude::*; + pub(crate) use interactors::prelude::*; + } +} + +pub use prelude::*; diff --git a/crates/system/os/derive-public-keys/src/sargon_os_derive_public_keys.rs b/crates/system/os/derive-public-keys/src/sargon_os_derive_public_keys.rs new file mode 100644 index 000000000..a33b16b20 --- /dev/null +++ b/crates/system/os/derive-public-keys/src/sargon_os_derive_public_keys.rs @@ -0,0 +1,166 @@ +use crate::prelude::*; + +#[async_trait::async_trait] +pub trait OsDerivePublicKeys { + async fn derive_public_keys( + &self, + derivation_paths: Vec, + source: DerivePublicKeysSource, + ) -> Result>; +} + +#[async_trait::async_trait] +impl OsDerivePublicKeys for SargonOS { + async fn derive_public_keys( + &self, + derivation_paths: Vec, + source: DerivePublicKeysSource, + ) -> Result> { + match source { + DerivePublicKeysSource::Mnemonic(mnemonic_with_passphrase) => { + let public_keys = mnemonic_with_passphrase + .derive_public_keys_vec(derivation_paths); + Ok(public_keys) + } + DerivePublicKeysSource::FactorSource( + factor_source_id_from_hash, + ) => { + let id = FactorSourceID::from(factor_source_id_from_hash); + let factor_source = + self.factor_sources()?.get_id(id).cloned().ok_or( + CommonError::ProfileDoesNotContainFactorSourceWithID { + bad_value: id.to_string(), + }, + )?; + + let collector = KeysCollector::new( + vec![factor_source], + IndexMap::just(( + factor_source_id_from_hash, + IndexSet::from_iter(derivation_paths), + )), + self.keys_derivation_interactor(), + DerivationPurpose::AccountRecovery, + )?; + + let pf_derived = + collector.collect_keys().await.factors_by_source; + let result: Vec = + pf_derived + .get(&factor_source_id_from_hash) + .map(|set| { + set.iter().cloned().map(|a| a.public_key).collect() + }) + .unwrap_or(Vec::new()); + Ok(result) + } + } + } +} + +#[cfg(test)] +#[allow(non_snake_case)] +mod test { + use super::*; + + #[allow(clippy::upper_case_acronyms)] + type SUT = SargonOS; + + #[actix_rt::test] + async fn mnemonic__success() { + let sut = boot(None).await; + + let mnemonic_with_passphrase = MnemonicWithPassphrase::sample(); + let source = + DerivePublicKeysSource::Mnemonic(mnemonic_with_passphrase.clone()); + let result = sut + .derive_public_keys(sample_derivation_paths(), source) + .await + .unwrap(); + + assert_eq!( + result, + mnemonic_with_passphrase + .derive_public_keys_vec(sample_derivation_paths()) + ); + } + + #[actix_rt::test] + async fn factor_source__without_profile() { + let sut = boot(None).await; + + let source = DerivePublicKeysSource::FactorSource( + FactorSourceIDFromHash::sample(), + ); + let result = sut + .derive_public_keys(sample_derivation_paths(), source) + .await + .expect_err("Expected error"); + + assert_eq!( + result, + CommonError::ProfileStateNotLoaded { + current_state: "None".to_string() + } + ); + } + + #[actix_rt::test] + async fn factor_source__factor_source_missing() { + let sut = boot(Profile::sample()).await; + + let factor_source_not_in_profile = + FactorSourceIDFromHash::sample_password(); + let source = DerivePublicKeysSource::FactorSource( + factor_source_not_in_profile.clone(), + ); + let result = sut + .derive_public_keys(sample_derivation_paths(), source) + .await + .expect_err("Expected error"); + + assert_eq!( + result, + CommonError::ProfileDoesNotContainFactorSourceWithID { + bad_value: factor_source_not_in_profile.to_string(), + } + ); + } + + #[actix_rt::test] + async fn factor_source__device_success() { + let sut = boot(Profile::sample()).await; + + let source = DerivePublicKeysSource::FactorSource( + FactorSourceIDFromHash::sample_device(), + ); + let result = sut + .derive_public_keys(vec![DerivationPath::sample()], source) + .await + .unwrap(); + + assert_eq!(result, vec![HierarchicalDeterministicPublicKey::sample(),]); + } + + fn sample_derivation_paths() -> Vec { + vec![DerivationPath::sample(), DerivationPath::sample_other()] + } + + async fn boot(profile: impl Into>) -> Arc { + let secure_storage_driver = EphemeralSecureStorage::new(); + + if let Some(profile) = profile.into() { + let secure_storage_client = + SecureStorageClient::new(secure_storage_driver.clone()); + secure_storage_client.save_profile(&profile).await.unwrap(); + } + + let test_drivers = Drivers::with_secure_storage(secure_storage_driver); + let mut clients = Clients::new(Bios::new(test_drivers)); + clients.factor_instances_cache = + FactorInstancesCacheClient::in_memory(); + + let interactors = Interactors::new_from_clients(&clients); + SUT::boot_with_clients_and_interactor(clients, interactors).await + } +} diff --git a/crates/system/os/derive-public-keys/src/support/mod.rs b/crates/system/os/derive-public-keys/src/support/mod.rs new file mode 100644 index 000000000..75eb5a6b8 --- /dev/null +++ b/crates/system/os/derive-public-keys/src/support/mod.rs @@ -0,0 +1,3 @@ +mod source; + +pub use source::*; diff --git a/crates/system/os/derive-public-keys/src/support/source.rs b/crates/system/os/derive-public-keys/src/support/source.rs new file mode 100644 index 000000000..c35d2009b --- /dev/null +++ b/crates/system/os/derive-public-keys/src/support/source.rs @@ -0,0 +1,11 @@ +use crate::prelude::*; + +/// The source of the public keys to derive. +#[derive(Clone, Debug, PartialEq)] +pub enum DerivePublicKeysSource { + /// Derive the public keys from a known mnemonic. + Mnemonic(MnemonicWithPassphrase), + + /// Derive the public keys from a factor source added to Profile. + FactorSource(FactorSourceIDFromHash), +} diff --git a/crates/system/os/factors/Cargo.toml b/crates/system/os/factors/Cargo.toml index 51f7c2120..53b662d32 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/system/os/factors/src/apply_security_shield/sargon_os_apply_shield.rs b/crates/system/os/factors/src/apply_security_shield/sargon_os_apply_shield.rs index e97082052..0eaf4a505 100644 --- a/crates/system/os/factors/src/apply_security_shield/sargon_os_apply_shield.rs +++ b/crates/system/os/factors/src/apply_security_shield/sargon_os_apply_shield.rs @@ -407,7 +407,7 @@ mod tests { async fn add_unsafe_shield_with_matrix( os: &SargonOS, ) -> Result { - let bdsf = os.bdfs()?; + let bdsf = os.main_bdfs()?; let shield_of_ids = unsafe_shield_with_bdfs(&bdsf.into()); os.add_security_structure_of_factor_source_ids(&shield_of_ids) .await?; @@ -427,16 +427,17 @@ mod tests { let shield_id = add_unsafe_shield(&os).await.unwrap(); let network = NetworkID::Mainnet; let account = os - .create_and_save_new_account_with_bdfs( + .create_and_save_new_account_with_main_bdfs( network, DisplayName::sample(), ) .await .unwrap(); let persona = os - .create_and_save_new_persona_with_bdfs( + .create_and_save_new_persona_with_main_bdfs( network, DisplayName::sample_other(), + None, ) .await .unwrap(); @@ -484,16 +485,17 @@ mod tests { let shield_id = shield.id(); let network = NetworkID::Mainnet; let account = os - .create_and_save_new_account_with_bdfs( + .create_and_save_new_account_with_main_bdfs( network, DisplayName::sample(), ) .await .unwrap(); let persona = os - .create_and_save_new_persona_with_bdfs( + .create_and_save_new_persona_with_main_bdfs( network, DisplayName::sample_other(), + None, ) .await .unwrap(); @@ -641,7 +643,7 @@ mod tests { let shield_id = add_unsafe_shield(&os).await.unwrap(); let network = NetworkID::Mainnet; let mut account = os - .create_and_save_new_account_with_bdfs( + .create_and_save_new_account_with_main_bdfs( network, DisplayName::sample(), ) @@ -677,7 +679,7 @@ mod tests { let shield_id = add_unsafe_shield(&os).await.unwrap(); let network = NetworkID::Mainnet; let mut account = os - .create_and_save_new_account_with_bdfs( + .create_and_save_new_account_with_main_bdfs( network, DisplayName::sample(), ) @@ -719,9 +721,10 @@ mod tests { let shield_id = add_unsafe_shield(&os).await.unwrap(); let network = NetworkID::Mainnet; let mut persona = os - .create_and_save_new_persona_with_bdfs( + .create_and_save_new_persona_with_main_bdfs( network, DisplayName::sample(), + None, ) .await .unwrap(); @@ -755,9 +758,10 @@ mod tests { let shield_id = add_unsafe_shield(&os).await.unwrap(); let network = NetworkID::Mainnet; let mut persona = os - .create_and_save_new_persona_with_bdfs( + .create_and_save_new_persona_with_main_bdfs( network, DisplayName::sample(), + None, ) .await .unwrap(); @@ -799,7 +803,7 @@ mod tests { let shield_id = add_unsafe_shield(&os).await.unwrap(); let network = NetworkID::Mainnet; let mut account = os - .create_and_save_new_account_with_bdfs( + .create_and_save_new_account_with_main_bdfs( network, DisplayName::sample(), ) @@ -851,7 +855,7 @@ mod tests { let network = NetworkID::Mainnet; let mut account = os - .create_and_save_new_account_with_bdfs( + .create_and_save_new_account_with_main_bdfs( network, DisplayName::sample(), ) diff --git a/crates/system/os/factors/src/test_instances_provider.rs b/crates/system/os/factors/src/test_instances_provider.rs index 4c1eff143..2f4ac1675 100644 --- a/crates/system/os/factors/src/test_instances_provider.rs +++ b/crates/system/os/factors/src/test_instances_provider.rs @@ -133,7 +133,7 @@ async fn create_accounts_when_last_is_used_cache_is_fill_only_with_account_vecis .assert_is_full(NetworkID::Mainnet, bdfs.id_from_hash()); let prefix = "Acco"; let (_, derivation_outcome) = os - .batch_create_many_accounts_with_bdfs_with_derivation_outcome_then_save_once(CACHE_FILLING_QUANTITY as u16, NetworkID::Mainnet, prefix.to_owned()) + .batch_create_many_accounts_with_main_bdfs_with_derivation_outcome_then_save_once(CACHE_FILLING_QUANTITY as u16, NetworkID::Mainnet, prefix.to_owned()) .await .unwrap(); assert_eq!(derivation_outcome.debug_was_cached.len(), 0); @@ -375,7 +375,7 @@ impl AllHdFactorsFromRole for ConfirmationRoleWithFactorInstances { #[actix_rt::test] async fn cache_is_unchanged_in_case_of_failure() { let os = SargonOS::fast_boot().await; - let bdfs = FactorSource::from(os.bdfs().unwrap()); + let bdfs = FactorSource::from(os.main_bdfs().unwrap()); let factor_sources = os.profile().unwrap().factor_sources.clone(); assert_eq!( factor_sources.clone().into_iter().collect_vec(), @@ -384,7 +384,7 @@ async fn cache_is_unchanged_in_case_of_failure() { let n = CACHE_FILLING_QUANTITY / 2; - let (_, derivation_outcome) = os.batch_create_many_accounts_with_bdfs_with_derivation_outcome_then_save_once(3 * n as u16, NetworkID::Mainnet, "Acco".to_owned()).await.unwrap(); + let (_, derivation_outcome) = os.batch_create_many_accounts_with_main_bdfs_with_derivation_outcome_then_save_once(3 * n as u16, NetworkID::Mainnet, "Acco".to_owned()).await.unwrap(); assert_eq!(derivation_outcome.debug_was_derived.len(), 3 * n); // `n` missing + CACHE filling 2*n more. let all_accounts = os @@ -512,7 +512,7 @@ async fn cache_is_unchanged_in_case_of_failure() { c.serializable_snapshot(), cache_before_fail.serializable_snapshot() ); - assert_eq!(os.bdfs().unwrap().id_from_hash(), bdfs.id_from_hash()); + assert_eq!(os.main_bdfs().unwrap().id_from_hash(), bdfs.id_from_hash()); let res = os ._provide_instances_using_shield_for_entities_by_address_without_consuming_cache( @@ -539,17 +539,19 @@ async fn cache_is_unchanged_in_case_of_failure() { async fn test_assert_factor_instances_invalid() { let os = SargonOS::fast_boot().await; let alice = os - .create_and_save_new_mainnet_account_with_bdfs(DisplayName::sample()) + .create_and_save_new_mainnet_account_with_main_bdfs( + DisplayName::sample(), + ) .await .unwrap(); let bob = os - .create_and_save_new_mainnet_account_with_bdfs( + .create_and_save_new_mainnet_account_with_main_bdfs( DisplayName::sample_other(), ) .await .unwrap(); - let bdfs = FactorSource::from(os.bdfs().unwrap()); + let bdfs = FactorSource::from(os.main_bdfs().unwrap()); // This is NOT a valid Matrix! But for the purpose of this test, it's fine. // We are not testing valid matrices here... we are testing the factor @@ -690,7 +692,7 @@ async fn adding_accounts_different_networks_different_factor_sources() { DerivationPreset::all().len() * CACHE_FILLING_QUANTITY ); - let fs_device = FactorSource::from(os.bdfs().unwrap()); + let fs_device = FactorSource::from(os.main_bdfs().unwrap()); let fs_arculus = FactorSource::sample_arculus(); let fs_ledger = FactorSource::sample_ledger(); @@ -889,7 +891,7 @@ async fn test_securified_accounts() { let bob = os.create_and_save_new_mainnet_account("Bob").await.unwrap(); assert_ne!(alice.address(), bob.address()); - let bdfs = FactorSource::from(os.bdfs().unwrap()); + let bdfs = FactorSource::from(os.main_bdfs().unwrap()); let ledger = FactorSource::sample_ledger(); let arculus = FactorSource::sample_arculus(); let password = FactorSource::sample_password(); @@ -1179,7 +1181,7 @@ async fn securify_accounts_when_cache_is_half_full_single_factor_source() { let os = SargonOS::fast_boot().await; let profile = os.profile().unwrap(); - let bdfs = FactorSource::from(os.bdfs().unwrap()); + let bdfs = FactorSource::from(os.main_bdfs().unwrap()); let factor_sources = profile.factor_sources.clone(); assert_eq!( factor_sources.clone().into_iter().collect_vec(), @@ -1188,7 +1190,7 @@ async fn securify_accounts_when_cache_is_half_full_single_factor_source() { let n = CACHE_FILLING_QUANTITY / 2; - os.batch_create_many_accounts_with_bdfs_then_save_once( + os.batch_create_many_accounts_with_main_bdfs_then_save_once( 3 * n as u16, NetworkID::Mainnet, "Acco".to_owned(), @@ -1354,7 +1356,7 @@ async fn securify_accounts_when_cache_is_half_full_multiple_factor_sources() { let n = CACHE_FILLING_QUANTITY / 2; - let (_, derivation_outcome) = os.batch_create_many_accounts_with_bdfs_with_derivation_outcome_then_save_once(3 * n as u16, NetworkID::Mainnet, "Acco".to_owned()).await.unwrap(); + let (_, derivation_outcome) = os.batch_create_many_accounts_with_main_bdfs_with_derivation_outcome_then_save_once(3 * n as u16, NetworkID::Mainnet, "Acco".to_owned()).await.unwrap(); assert_eq!(derivation_outcome.debug_was_derived.len(), 3 * n); // `n` missing + CACHE filling 2*n more. @@ -1852,7 +1854,7 @@ async fn securified_personas() { .unwrap(); assert_ne!(batman.address(), satoshi.address()); - let bdfs = FactorSource::from(os.bdfs().unwrap()); + let bdfs = FactorSource::from(os.main_bdfs().unwrap()); let ledger = FactorSource::sample_ledger(); let arculus = FactorSource::sample_arculus(); let password = FactorSource::sample_password(); @@ -2157,7 +2159,7 @@ async fn securified_all_accounts_next_veci_does_not_start_at_zero() { DerivationPreset::all().len() * CACHE_FILLING_QUANTITY ); - let bdfs = FactorSource::from(os.bdfs().unwrap()); + let bdfs = FactorSource::from(os.main_bdfs().unwrap()); let arculus = FactorSource::sample_arculus(); let ledger = FactorSource::sample_ledger(); @@ -2184,7 +2186,7 @@ async fn securified_all_accounts_next_veci_does_not_start_at_zero() { // first create CACHE_FILLING_QUANTITY many "unnamed" accounts - let (_, derivation_outcome) = os.batch_create_many_accounts_with_bdfs_with_derivation_outcome_then_save_once(CACHE_FILLING_QUANTITY as u16, network, "Acco".to_owned()).await.unwrap(); + let (_, derivation_outcome) = os.batch_create_many_accounts_with_main_bdfs_with_derivation_outcome_then_save_once(CACHE_FILLING_QUANTITY as u16, network, "Acco".to_owned()).await.unwrap(); assert!(derivation_outcome.debug_was_derived.is_empty()); let unnamed_accounts = os @@ -2830,7 +2832,7 @@ async fn securified_accounts_and_personas_mixed_asymmetric_indices() { os.clear_cache().await; // CLEAR CACHE - let (more_unnamed_accounts, _) = os.batch_create_many_accounts_with_bdfs_with_derivation_outcome_then_save_once(2 * CACHE_FILLING_QUANTITY as u16, network, "more accounts".to_owned()).await.unwrap(); + let (more_unnamed_accounts, _) = os.batch_create_many_accounts_with_main_bdfs_with_derivation_outcome_then_save_once(2 * CACHE_FILLING_QUANTITY as u16, network, "more accounts".to_owned()).await.unwrap(); let (more_unnamed_personas, _) = os.batch_create_many_personas_with_bdfs_with_derivation_outcome_then_save_once(2 * CACHE_FILLING_QUANTITY as u16, network, "more personas".to_owned()).await.unwrap(); diff --git a/crates/system/os/os/Cargo.toml b/crates/system/os/os/Cargo.toml index 9799bc265..a76e6576f 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/system/os/os/src/os_testing_support.rs b/crates/system/os/os/src/os_testing_support.rs index 30ae106de..14cbc9e10 100644 --- a/crates/system/os/os/src/os_testing_support.rs +++ b/crates/system/os/os/src/os_testing_support.rs @@ -6,7 +6,7 @@ use crate::prelude::*; impl SargonOS { pub async fn with_bdfs() -> (Arc, FactorSource) { let os = Self::fast_boot().await; - let bdfs = os.bdfs().unwrap(); + let bdfs = os.main_bdfs().unwrap(); (os, bdfs.into()) } @@ -15,7 +15,7 @@ impl SargonOS { name: impl AsRef, ) -> Result<(Account, FactorInstancesProviderOutcomeForFactor)> { let display_name = DisplayName::new(name)?; - self.create_and_save_new_mainnet_account_with_bdfs_with_derivation_outcome(display_name).await + self.create_and_save_new_mainnet_account_with_main_bdfs_with_derivation_outcome(display_name).await } pub async fn create_and_save_new_mainnet_persona( @@ -43,7 +43,7 @@ impl SargonOS { name: impl AsRef, ) -> Result<(Persona, FactorInstancesProviderOutcomeForFactor)> { let display_name = DisplayName::new(name)?; - self.create_and_save_new_persona_with_factor_source_with_derivation_outcome(factor_source, network_id, display_name).await + self.create_and_save_new_persona_with_factor_source_with_derivation_outcome(factor_source, network_id, display_name, None).await } pub async fn create_and_save_new_account_with_factor_with_derivation_outcome( @@ -61,6 +61,6 @@ impl SargonOS { name: impl AsRef, ) -> Result<(Persona, FactorInstancesProviderOutcomeForFactor)> { let display_name = DisplayName::new(name)?; - self.create_and_save_new_mainnet_persona_with_bdfs_with_derivation_outcome(display_name).await + self.create_and_save_new_mainnet_persona_with_main_bdfs_with_derivation_outcome(display_name).await } } diff --git a/crates/system/os/os/src/sargon_os.rs b/crates/system/os/os/src/sargon_os.rs index f71c534ba..2f565a987 100644 --- a/crates/system/os/os/src/sargon_os.rs +++ b/crates/system/os/os/src/sargon_os.rs @@ -681,7 +681,7 @@ mod tests { os.new_wallet(false).await.unwrap(); let profile = os.profile().unwrap(); - let bdfs = profile.bdfs(); + let bdfs = profile.main_bdfs(); assert!(os .clients @@ -700,7 +700,10 @@ mod tests { os.import_wallet(&profile_to_import, false).await.unwrap(); - assert_eq!(os.profile().unwrap().bdfs(), profile_to_import.bdfs()); + assert_eq!( + os.profile().unwrap().main_bdfs(), + profile_to_import.main_bdfs() + ); } #[actix_rt::test] @@ -710,7 +713,10 @@ mod tests { os.import_wallet(&profile_to_import, true).await.unwrap(); - assert_ne!(os.profile().unwrap().bdfs(), profile_to_import.bdfs()); + assert_ne!( + os.profile().unwrap().main_bdfs(), + profile_to_import.main_bdfs() + ); } #[actix_rt::test] @@ -806,7 +812,7 @@ mod tests { SUT::boot_with_clients_and_interactor(clients, interactors).await; os.new_wallet(false).await.unwrap(); let profile = os.profile().unwrap(); - let bdfs = profile.bdfs(); + let bdfs = profile.main_bdfs(); os.delete_wallet().await.unwrap(); diff --git a/crates/system/os/os/src/sargon_os_accounts.rs b/crates/system/os/os/src/sargon_os_accounts.rs index b1bc9490b..98d0dc1ed 100644 --- a/crates/system/os/os/src/sargon_os_accounts.rs +++ b/crates/system/os/os/src/sargon_os_accounts.rs @@ -35,14 +35,14 @@ impl SargonOS { } /// Creates a new unsaved mainnet account named "Unnamed {N}", where `N` is the - /// index of the next account for the BDFS. + /// index of the next account for the main BDFS. /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::FactorSourceUpdated }` - pub async fn create_unsaved_unnamed_mainnet_account_with_bdfs( + pub async fn create_unsaved_unnamed_mainnet_account_with_main_bdfs( &self, ) -> Result { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_unsaved_unnamed_mainnet_account_with_factor_source( bdfs.into(), ) @@ -66,13 +66,12 @@ impl SargonOS { .await } - /// Uses `create_unsaved_account` specifying `NetworkID::Mainnet` using - /// the specified `factor_source`. - pub async fn create_unsaved_mainnet_account_with_bdfs( + /// Uses `create_unsaved_account` specifying `NetworkID::Mainnet` using main BDFS. + pub async fn create_unsaved_mainnet_account_with_main_bdfs( &self, name: DisplayName, ) -> Result { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_unsaved_mainnet_account_with_factor_source( bdfs.into(), name, @@ -107,12 +106,12 @@ impl SargonOS { /// of the factor source has been updated. /// /// Also emits `EventNotification::ProfileModified { change: EventProfileModified::FactorSourceUpdated { id } }` - pub async fn create_unsaved_account_with_bdfs( + pub async fn create_unsaved_account_with_main_bdfs( &self, network_id: NetworkID, name: DisplayName, ) -> Result { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_unsaved_account_with_factor_source( bdfs.into(), network_id, @@ -188,14 +187,14 @@ impl SargonOS { Ok((account, instances_in_cache_consumer, derivation_outcome)) } - /// Create a new mainnet Account named "Unnamed" using BDFS and adds it to the active Profile. + /// Create a new mainnet Account named "Unnamed" using main BDFS and adds it to the active Profile. /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::AccountAdded }` - pub async fn create_and_save_new_unnamed_mainnet_account_with_bdfs( + pub async fn create_and_save_new_unnamed_mainnet_account_with_main_bdfs( &self, ) -> Result { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_and_save_new_unnamed_mainnet_account_with_factor_source( bdfs.into(), ) @@ -217,22 +216,22 @@ impl SargonOS { .await } - /// Create a new mainnet Account using the BDFS and adds it to the active Profile. + /// Create a new mainnet Account using the main BDFS and adds it to the active Profile. /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::AccountAdded }` - pub async fn create_and_save_new_mainnet_account_with_bdfs( + pub async fn create_and_save_new_mainnet_account_with_main_bdfs( &self, name: DisplayName, ) -> Result { - self.create_and_save_new_mainnet_account_with_bdfs_with_derivation_outcome(name).await.map(|(x, _)| x) + self.create_and_save_new_mainnet_account_with_main_bdfs_with_derivation_outcome(name).await.map(|(x, _)| x) } - pub async fn create_and_save_new_mainnet_account_with_bdfs_with_derivation_outcome( + pub async fn create_and_save_new_mainnet_account_with_main_bdfs_with_derivation_outcome( &self, name: DisplayName, ) -> Result<(Account, FactorInstancesProviderOutcomeForFactor)> { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_and_save_new_mainnet_account_with_factor_source_with_derivation_outcome( bdfs.into(), name, @@ -265,16 +264,16 @@ impl SargonOS { .await } - /// Create a new Account and adds it to the active Profile. + /// Create a new Account using main BDFS and adds it to the active Profile. /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::AccountAdded }` - pub async fn create_and_save_new_account_with_bdfs( + pub async fn create_and_save_new_account_with_main_bdfs( &self, network_id: NetworkID, name: DisplayName, ) -> Result { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_and_save_new_account_with_factor_source( bdfs.into(), network_id, @@ -324,7 +323,7 @@ impl SargonOS { Ok((account, derivation_outcome)) } - /// Creates account using BDFS + /// Creates account using main BDFS. /// The account names will be ` ` /// /// # Emits Event @@ -332,22 +331,22 @@ impl SargonOS { /// /// And also emits `Event::ProfileSaved` after having successfully written the JSON /// of the active profile to secure storage. - pub async fn batch_create_many_accounts_with_bdfs_then_save_once( + pub async fn batch_create_many_accounts_with_main_bdfs_then_save_once( &self, count: u16, network_id: NetworkID, name_prefix: String, ) -> Result { - self.batch_create_many_accounts_with_bdfs_with_derivation_outcome_then_save_once(count, network_id, name_prefix).await.map(|(x, _) |x) + self.batch_create_many_accounts_with_main_bdfs_with_derivation_outcome_then_save_once(count, network_id, name_prefix).await.map(|(x, _) |x) } - pub async fn batch_create_many_accounts_with_bdfs_with_derivation_outcome_then_save_once( + pub async fn batch_create_many_accounts_with_main_bdfs_with_derivation_outcome_then_save_once( &self, count: u16, network_id: NetworkID, name_prefix: String, ) -> Result<(Accounts, FactorInstancesProviderOutcomeForFactor)> { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.batch_create_many_accounts_with_factor_source_with_derivation_outcome_then_save_once( bdfs.into(), count, @@ -403,14 +402,14 @@ impl SargonOS { /// # Emits Event /// Emits `Event::FactorSourceUpdated { id: FactorSourceID }` since the date in /// `factor_source.common.last_used` is updated. - pub async fn batch_create_unsaved_accounts_with_bdfs_consuming_factor_instances( + pub async fn batch_create_unsaved_accounts_with_main_bdfs_consuming_factor_instances( &self, network_id: NetworkID, count: u16, name_prefix: String, ) -> Result { let (accounts, instances_in_cache_consumer) = self - .batch_create_unsaved_accounts_with_bdfs( + .batch_create_unsaved_accounts_with_main_bdfs( network_id, count, name_prefix, @@ -428,13 +427,13 @@ impl SargonOS { /// # Emits Event /// Emits `Event::FactorSourceUpdated { id: FactorSourceID }` since the date in /// `factor_source.common.last_used` is updated. - pub async fn batch_create_unsaved_accounts_with_bdfs( + pub async fn batch_create_unsaved_accounts_with_main_bdfs( &self, network_id: NetworkID, count: u16, name_prefix: String, ) -> Result<(Accounts, InstancesInCacheConsumer)> { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.batch_create_unsaved_accounts_with_factor_source( bdfs.into(), network_id, @@ -915,7 +914,7 @@ mod tests { // ACT let unsaved_account = os .with_timeout(|x| { - x.create_unsaved_mainnet_account_with_bdfs( + x.create_unsaved_mainnet_account_with_main_bdfs( DisplayName::new("Alice").unwrap(), ) }) @@ -935,14 +934,14 @@ mod tests { // ACT let first = os .with_timeout(|x| { - x.create_unsaved_unnamed_mainnet_account_with_bdfs() + x.create_unsaved_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); let second = os .with_timeout(|x| { - x.create_unsaved_account_with_bdfs( + x.create_unsaved_account_with_main_bdfs( NetworkID::Mainnet, DisplayName::new("Unnamed").unwrap(), ) @@ -962,7 +961,7 @@ mod tests { // ACT let account = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); @@ -982,7 +981,7 @@ mod tests { // ACT let account = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); @@ -1009,14 +1008,14 @@ mod tests { // ACT let _ = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); let second = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); @@ -1044,7 +1043,7 @@ mod tests { // ACT let n: u32 = 3; os.with_timeout(|x| { - x.batch_create_many_accounts_with_bdfs_then_save_once( + x.batch_create_many_accounts_with_main_bdfs_then_save_once( n as u16, NetworkID::Mainnet, "test".to_owned(), @@ -1072,7 +1071,7 @@ mod tests { } #[actix_rt::test] - async fn test_batch_create_unsaved_accounts_with_bdfs_consuming_factor_instances( + async fn test_batch_create_unsaved_accounts_with_main_bdfs_consuming_factor_instances( ) { // ARRANGE let os = SUT::fast_boot_bdfs(MnemonicWithPassphrase::sample()).await; @@ -1082,7 +1081,7 @@ mod tests { let n = 50; let accounts = os .with_timeout(|x| { - x.batch_create_unsaved_accounts_with_bdfs_consuming_factor_instances( + x.batch_create_unsaved_accounts_with_main_bdfs_consuming_factor_instances( network, n as u16, "acco".to_owned() @@ -1145,7 +1144,7 @@ mod tests { // ACT let n: u32 = 3; os.with_timeout(|x| { - x.batch_create_many_accounts_with_bdfs_then_save_once( + x.batch_create_many_accounts_with_main_bdfs_then_save_once( n as u16, NetworkID::Mainnet, "test".to_owned(), @@ -1179,7 +1178,7 @@ mod tests { // ACT let n = AppearanceID::all().len() as u32 * 2; os.with_timeout(|x| { - x.batch_create_many_accounts_with_bdfs_then_save_once( + x.batch_create_many_accounts_with_main_bdfs_then_save_once( n as u16, NetworkID::Mainnet, "test".to_owned(), @@ -1208,7 +1207,7 @@ mod tests { // ACT os.with_timeout(|x| { - x.batch_create_unsaved_accounts_with_bdfs( + x.batch_create_unsaved_accounts_with_main_bdfs( NetworkID::Mainnet, 3, "test".to_owned(), @@ -1241,7 +1240,7 @@ mod tests { // ACT os.with_timeout(|x| { - x.create_unsaved_unnamed_mainnet_account_with_bdfs() + x.create_unsaved_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); @@ -1272,7 +1271,7 @@ mod tests { // ACT os.with_timeout(|x| x.new_wallet(false)).await.unwrap(); os.with_timeout(|x| { - x.create_and_save_new_account_with_bdfs( + x.create_and_save_new_account_with_main_bdfs( NetworkID::Mainnet, DisplayName::sample(), ) @@ -1570,7 +1569,7 @@ mod tests { // ACT let account = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); @@ -1589,7 +1588,7 @@ mod tests { let _ = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); @@ -1612,7 +1611,7 @@ mod tests { // ACT let account = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); @@ -1632,7 +1631,7 @@ mod tests { // ACT let account = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); @@ -1650,7 +1649,7 @@ mod tests { // so that we have at least one network (with one account) let _ = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); diff --git a/crates/system/os/os/src/sargon_os_factors.rs b/crates/system/os/os/src/sargon_os_factors.rs index 91adc6bba..494fe607e 100644 --- a/crates/system/os/os/src/sargon_os_factors.rs +++ b/crates/system/os/os/src/sargon_os_factors.rs @@ -13,8 +13,9 @@ pub enum DeviceFactorSourceType { impl SargonOS { /// Returns the "main Babylon" `DeviceFactorSource` of the current account as /// a `DeviceFactorSource`. - pub fn bdfs(&self) -> Result { - self.profile_state_holder.access_profile_with(|p| p.bdfs()) + pub fn main_bdfs(&self) -> Result { + self.profile_state_holder + .access_profile_with(|p| p.main_bdfs()) } /// Returns all the factor sources @@ -270,7 +271,7 @@ impl SargonOS { let is_any_of_new_factors_main_bdfs = new_factors_only.iter().any(|x| x.is_main_bdfs()); - let id_of_old_bdfs = self.bdfs()?.factor_source_id(); + let id_of_old_bdfs = self.main_bdfs()?.factor_source_id(); for factor_source in new_factors_only.iter() { if !factor_source.factor_source_id().is_hash() { @@ -296,7 +297,7 @@ impl SargonOS { self.update_factor_source_remove_flag_main(id_of_old_bdfs) .await?; assert!(ids_of_factors_to_add - .contains(&self.bdfs()?.factor_source_id())) + .contains(&self.main_bdfs()?.factor_source_id())) } Ok(ids_of_new_factor_sources.into_iter().collect_vec()) @@ -554,7 +555,7 @@ mod tests { let os = SUT::fast_boot_bdfs(mwp.clone()).await; // ACT - let loaded = os.bdfs().unwrap(); + let loaded = os.main_bdfs().unwrap(); // ASSERT assert_eq!( @@ -651,7 +652,7 @@ mod tests { // ARRANGE let os = SUT::fast_boot().await; - let old_bdfs_id = os.bdfs().unwrap().factor_source_id(); + let old_bdfs_id = os.main_bdfs().unwrap().factor_source_id(); let new_bdfs = DeviceFactorSource::babylon( true, &MnemonicWithPassphrase::sample(), @@ -669,7 +670,7 @@ mod tests { // ASSERT assert!(inserted); - assert_eq!(os.bdfs().unwrap(), new_bdfs); + assert_eq!(os.main_bdfs().unwrap(), new_bdfs); let old_bdfs = os .profile() .unwrap() @@ -688,7 +689,7 @@ mod tests { let mwp = MnemonicWithPassphrase::sample(); let os = SUT::fast_boot_bdfs(mwp.clone()).await; - let bdfs = os.bdfs().unwrap(); + let bdfs = os.main_bdfs().unwrap(); // ACT let inserted = os @@ -750,7 +751,8 @@ mod tests { .unwrap(); // ASSERT - assert!(!bdfs.common.is_main_bdfs()); + assert!(!bdfs.is_main_bdfs()); + assert!(!bdfs.common.is_main()); assert!(bdfs.common.supports_babylon()); } @@ -771,7 +773,7 @@ mod tests { .unwrap(); // ASSERT - assert!(!dfs.common.is_main_bdfs()); + assert!(!dfs.common.is_main()); assert!(!dfs.common.supports_babylon()); assert!(dfs.common.supports_olympia()); assert_eq!( diff --git a/crates/system/os/os/src/sargon_os_personas.rs b/crates/system/os/os/src/sargon_os_personas.rs index d59de0d54..fe3218da8 100644 --- a/crates/system/os/os/src/sargon_os_personas.rs +++ b/crates/system/os/os/src/sargon_os_personas.rs @@ -19,14 +19,14 @@ impl SargonOS { self.profile_state_holder.persona_by_address(address) } - /// Creates a new unsaved mainnet persona named "Unnamed". + /// Creates a new unsaved mainnet persona named "Unnamed" using main bdfs. /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::FactorSourceUpdated }` - pub async fn create_unsaved_unnamed_mainnet_persona_with_bdfs( + pub async fn create_unsaved_unnamed_mainnet_persona_with_main_bdfs( &self, ) -> Result<(Persona, InstancesInCacheConsumer)> { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_unsaved_unnamed_mainnet_persona_with_factor_source( bdfs.into(), ) @@ -50,13 +50,12 @@ impl SargonOS { .await } - /// Uses `create_unsaved_persona` specifying `NetworkID::Mainnet` using - /// the specified `factor_source`. - pub async fn create_unsaved_mainnet_persona_with_bdfs( + /// Uses `create_unsaved_persona` specifying `NetworkID::Mainnet` using main BDFS. + pub async fn create_unsaved_mainnet_persona_with_main_bdfs( &self, name: DisplayName, ) -> Result<(Persona, InstancesInCacheConsumer)> { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_unsaved_mainnet_persona_with_factor_source( bdfs.into(), name, @@ -91,12 +90,12 @@ impl SargonOS { /// of the factor source has been updated. /// /// Also emits `EventNotification::ProfileModified { change: EventProfileModified::FactorSourceUpdated { id } }` - pub async fn create_unsaved_persona_with_bdfs( + pub async fn create_unsaved_persona_with_main_bdfs( &self, network_id: NetworkID, name: DisplayName, ) -> Result<(Persona, InstancesInCacheConsumer)> { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_unsaved_persona_with_factor_source( bdfs.into(), network_id, @@ -169,14 +168,14 @@ impl SargonOS { Ok((persona, instances_in_cache_consumer, derivation_outcome)) } - /// Create a new mainnet Persona named "Unnamed" using BDFS and adds it to the active Profile. + /// Create a new mainnet Persona named "Unnamed" using main BDFS and adds it to the active Profile. /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::PersonaAdded }` - pub async fn create_and_save_new_unnamed_mainnet_persona_with_bdfs( + pub async fn create_and_save_new_unnamed_mainnet_persona_with_main_bdfs( &self, ) -> Result { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_and_save_new_unnamed_mainnet_persona_with_factor_source( bdfs.into(), ) @@ -198,22 +197,22 @@ impl SargonOS { .await } - /// Create a new mainnet Persona using the BDFS and adds it to the active Profile. + /// Create a new mainnet Persona using the mian BDFS and adds it to the active Profile. /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::PersonaAdded }` - pub async fn create_and_save_new_mainnet_persona_with_bdfs( + pub async fn create_and_save_new_mainnet_persona_with_main_bdfs( &self, name: DisplayName, ) -> Result { - self.create_and_save_new_mainnet_persona_with_bdfs_with_derivation_outcome(name).await.map(|(x, _)| x) + self.create_and_save_new_mainnet_persona_with_main_bdfs_with_derivation_outcome(name).await.map(|(x, _)| x) } - pub async fn create_and_save_new_mainnet_persona_with_bdfs_with_derivation_outcome( + pub async fn create_and_save_new_mainnet_persona_with_main_bdfs_with_derivation_outcome( &self, name: DisplayName, ) -> Result<(Persona, FactorInstancesProviderOutcomeForFactor)> { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_and_save_new_mainnet_persona_with_factor_source_with_derivation_outcome( bdfs.into(), name, @@ -242,24 +241,27 @@ impl SargonOS { factor_source, NetworkID::Mainnet, name, + None, ) .await } - /// Create a new Persona and adds it to the active Profile. + /// Create a new Persona with main BDFS and adds it to the active Profile. /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::PersonaAdded }` - pub async fn create_and_save_new_persona_with_bdfs( + pub async fn create_and_save_new_persona_with_main_bdfs( &self, network_id: NetworkID, name: DisplayName, + persona_data: Option, ) -> Result { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.create_and_save_new_persona_with_factor_source( bdfs.into(), network_id, name, + persona_data, ) .await } @@ -273,8 +275,9 @@ impl SargonOS { factor_source: FactorSource, network_id: NetworkID, name: DisplayName, + persona_data: Option, ) -> Result { - self.create_and_save_new_persona_with_factor_source_with_derivation_outcome(factor_source, network_id, name).await.map(|(x, _)| x) + self.create_and_save_new_persona_with_factor_source_with_derivation_outcome(factor_source, network_id, name, persona_data).await.map(|(x, _)| x) } pub async fn create_and_save_new_persona_with_factor_source_with_derivation_outcome( @@ -282,9 +285,10 @@ impl SargonOS { factor_source: FactorSource, network_id: NetworkID, name: DisplayName, + persona_data: Option, ) -> Result<(Persona, FactorInstancesProviderOutcomeForFactor)> { debug!("Creating persona."); - let (persona, instances_in_cache_consumer, derivation_outcome) = self + let (mut persona, instances_in_cache_consumer, derivation_outcome) = self .create_unsaved_persona_with_factor_source_with_derivation_outcome( factor_source, network_id, @@ -293,6 +297,11 @@ impl SargonOS { .await?; debug!("Created persona, now saving it to profile."); + // If PersonaData is set, assign it before saving it into Profile + if let Some(persona_data) = persona_data { + persona.persona_data = persona_data; + } + // First try save Persona into Profile... self.add_persona(persona.clone()).await?; // ... if success, then delete FactorInstance from cache! @@ -328,7 +337,7 @@ impl SargonOS { network_id: NetworkID, name_prefix: String, ) -> Result<(Personas, FactorInstancesProviderOutcomeForFactor)> { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.batch_create_many_personas_with_factor_source_with_derivation_outcome_then_save_once( bdfs.into(), count, @@ -390,7 +399,7 @@ impl SargonOS { count: u16, name_prefix: String, ) -> Result<(Personas, InstancesInCacheConsumer)> { - let bdfs = self.bdfs()?; + let bdfs = self.main_bdfs()?; self.batch_create_unsaved_personas_with_factor_source( bdfs.into(), network_id, @@ -589,7 +598,7 @@ mod tests { // ACT let (mut unsaved_persona, _) = os .with_timeout(|x| { - x.create_unsaved_mainnet_persona_with_bdfs( + x.create_unsaved_mainnet_persona_with_main_bdfs( DisplayName::new("Satoshi").unwrap(), ) }) @@ -625,7 +634,7 @@ mod tests { let (second, _) = os .with_timeout(|x| { - x.create_unsaved_persona_with_bdfs( + x.create_unsaved_persona_with_main_bdfs( NetworkID::Mainnet, DisplayName::new("Unnamed").unwrap(), ) @@ -646,7 +655,7 @@ mod tests { // ACT let (first, instances_in_cache_consumer) = os .with_timeout(|x| { - x.create_unsaved_unnamed_mainnet_persona_with_bdfs() + x.create_unsaved_unnamed_mainnet_persona_with_main_bdfs() }) .await .unwrap(); @@ -656,7 +665,7 @@ mod tests { let (second, _) = os .with_timeout(|x| { - x.create_unsaved_unnamed_mainnet_persona_with_bdfs() + x.create_unsaved_unnamed_mainnet_persona_with_main_bdfs() }) .await .unwrap(); @@ -673,7 +682,31 @@ mod tests { // ACT let persona = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_persona_with_bdfs() + x.create_and_save_new_unnamed_mainnet_persona_with_main_bdfs() + }) + .await + .unwrap(); + + // ASSERT + assert_eq!( + os.profile().unwrap().networks[0].personas, + Personas::just(persona) + ); + } + + #[actix_rt::test] + async fn test_create_and_save_new_persona_sets_persona_data() { + // ARRANGE + let os = SUT::fast_boot().await; + + // ACT + let persona = os + .with_timeout(|x| { + x.create_and_save_new_persona_with_main_bdfs( + NetworkID::Mainnet, + DisplayName::sample(), + Some(PersonaData::sample()), + ) }) .await .unwrap(); @@ -683,6 +716,10 @@ mod tests { os.profile().unwrap().networks[0].personas, Personas::just(persona) ); + assert_eq!( + os.profile().unwrap().networks[0].personas[0].persona_data, + PersonaData::sample() + ); } #[actix_rt::test] @@ -693,7 +730,7 @@ mod tests { // ACT let persona = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_persona_with_bdfs() + x.create_and_save_new_unnamed_mainnet_persona_with_main_bdfs() }) .await .unwrap(); @@ -720,14 +757,14 @@ mod tests { // ACT let _ = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_persona_with_bdfs() + x.create_and_save_new_unnamed_mainnet_persona_with_main_bdfs() }) .await .unwrap(); let second = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_persona_with_bdfs() + x.create_and_save_new_unnamed_mainnet_persona_with_main_bdfs() }) .await .unwrap(); @@ -881,7 +918,7 @@ mod tests { // ACT os.with_timeout(|x| { - x.create_unsaved_unnamed_mainnet_persona_with_bdfs() + x.create_unsaved_unnamed_mainnet_persona_with_main_bdfs() }) .await .unwrap(); @@ -913,9 +950,10 @@ mod tests { // ACT os.with_timeout(|x| x.new_wallet(false)).await.unwrap(); os.with_timeout(|x| { - x.create_and_save_new_persona_with_bdfs( + x.create_and_save_new_persona_with_main_bdfs( NetworkID::Mainnet, DisplayName::sample(), + None, ) }) .await @@ -1156,7 +1194,7 @@ mod tests { // ACT let persona = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_persona_with_bdfs() + x.create_and_save_new_unnamed_mainnet_persona_with_main_bdfs() }) .await .unwrap(); @@ -1175,7 +1213,7 @@ mod tests { let _ = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_persona_with_bdfs() + x.create_and_save_new_unnamed_mainnet_persona_with_main_bdfs() }) .await .unwrap(); @@ -1198,7 +1236,7 @@ mod tests { // ACT let persona = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_persona_with_bdfs() + x.create_and_save_new_unnamed_mainnet_persona_with_main_bdfs() }) .await .unwrap(); @@ -1216,7 +1254,7 @@ mod tests { // so that we have at least one network (with one persona) let _ = os .with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_persona_with_bdfs() + x.create_and_save_new_unnamed_mainnet_persona_with_main_bdfs() }) .await .unwrap(); diff --git a/crates/system/os/os/src/sargon_os_profile.rs b/crates/system/os/os/src/sargon_os_profile.rs index 494bbf817..6f2c42958 100644 --- a/crates/system/os/os/src/sargon_os_profile.rs +++ b/crates/system/os/os/src/sargon_os_profile.rs @@ -241,7 +241,7 @@ mod tests { // ACT os.with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); @@ -257,7 +257,7 @@ mod tests { // ACT os.with_timeout(|x| { - x.create_and_save_new_unnamed_mainnet_account_with_bdfs() + x.create_and_save_new_unnamed_mainnet_account_with_main_bdfs() }) .await .unwrap(); diff --git a/crates/system/os/security-center/Cargo.toml b/crates/system/os/security-center/Cargo.toml index 060dd1d5f..f82bfb8a1 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/system/os/signing/Cargo.toml b/crates/system/os/signing/Cargo.toml index eb8fdd06b..c7c7b1f93 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/system/os/transaction/Cargo.toml b/crates/system/os/transaction/Cargo.toml index 25c93057d..1a35230c4 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/system/profile-state-holder/Cargo.toml b/crates/system/profile-state-holder/Cargo.toml index e9518654c..52e3b84bb 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/system/sub-systems/Cargo.toml b/crates/system/sub-systems/Cargo.toml index 5860a1289..71f0b2be6 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/transaction/foundation/Cargo.toml b/crates/transaction/foundation/Cargo.toml index 7ad1e369a..a6f91d9d4 100644 --- a/crates/transaction/foundation/Cargo.toml +++ b/crates/transaction/foundation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "transaction-foundation" -version = "1.1.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/transaction/manifests/Cargo.toml b/crates/transaction/manifests/Cargo.toml index 2ee2a404b..c623bea0a 100644 --- a/crates/transaction/manifests/Cargo.toml +++ b/crates/transaction/manifests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "manifests" -version = "1.1.117" +version = "1.1.118" edition = "2021" diff --git a/crates/transaction/models/Cargo.toml b/crates/transaction/models/Cargo.toml index f6d933664..c263edbcd 100644 --- a/crates/transaction/models/Cargo.toml +++ b/crates/transaction/models/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "transaction-models" -version = "1.1.117" +version = "1.1.118" edition = "2021" diff --git a/crates/uniffi/conversion-macros/Cargo.toml b/crates/uniffi/conversion-macros/Cargo.toml index 8d87f5222..3712f68d6 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.117" +version = "1.1.118" edition = "2021" [dependencies] diff --git a/crates/uniffi/uniffi_SPLIT_ME/Cargo.toml b/crates/uniffi/uniffi_SPLIT_ME/Cargo.toml index 831ecd577..8f00827f2 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.117" +version = "1.1.118" edition = "2021" build = "build.rs" diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/keys_collector/derivation_purpose.rs b/crates/uniffi/uniffi_SPLIT_ME/src/keys_collector/derivation_purpose.rs index 8e81de364..cff7db511 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/keys_collector/derivation_purpose.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/keys_collector/derivation_purpose.rs @@ -30,4 +30,7 @@ pub enum DerivationPurpose { /// When adding a new factor source, initiates keys collection /// for collecting various factor instances. PreDerivingKeys, + + /// When deriving accounts for recovery + AccountRecovery, } diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/radix_connect/wallet_interaction/dapp_wallet_interaction/dapp_to_wallet/dapp_metadata/interaction_metadata.rs b/crates/uniffi/uniffi_SPLIT_ME/src/radix_connect/wallet_interaction/dapp_wallet_interaction/dapp_to_wallet/dapp_metadata/interaction_metadata.rs index a796ac64f..a24a7960a 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/radix_connect/wallet_interaction/dapp_wallet_interaction/dapp_to_wallet/dapp_metadata/interaction_metadata.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/radix_connect/wallet_interaction/dapp_wallet_interaction/dapp_to_wallet/dapp_metadata/interaction_metadata.rs @@ -8,3 +8,17 @@ pub struct DappToWalletInteractionMetadata { pub origin: DappOrigin, pub dapp_definition_address: DappDefinitionAddress, } + +json_data_convertible!(DappToWalletInteractionMetadata); + +#[uniffi::export] +pub fn new_dapp_to_wallet_interaction_metadata_sample( +) -> DappToWalletInteractionMetadata { + InternalDappToWalletInteractionMetadata::sample().into() +} + +#[uniffi::export] +pub fn new_dapp_to_wallet_interaction_metadata_sample_other( +) -> DappToWalletInteractionMetadata { + InternalDappToWalletInteractionMetadata::sample_other().into() +} diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/entities/sargon_os_accounts.rs b/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/entities/sargon_os_accounts.rs index 4f1f4e1a7..450e98ae9 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/entities/sargon_os_accounts.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/entities/sargon_os_accounts.rs @@ -38,22 +38,22 @@ impl SargonOS { /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::FactorSourceUpdated }` - pub async fn create_unsaved_unnamed_mainnet_account( + pub async fn create_unsaved_unnamed_mainnet_account_with_main_bdfs( &self, ) -> Result { self.wrapped - .create_unsaved_unnamed_mainnet_account_with_bdfs() + .create_unsaved_unnamed_mainnet_account_with_main_bdfs() .await .into_result() } - /// Uses `create_unsaved_account` specifying `NetworkID::Mainnet`. - pub async fn create_unsaved_mainnet_account( + /// Uses `create_unsaved_account` specifying `NetworkID::Mainnet` using main BDFS. + pub async fn create_unsaved_mainnet_account_with_main_bdfs( &self, name: DisplayName, ) -> Result { self.wrapped - .create_unsaved_mainnet_account_with_bdfs(name.into_internal()) + .create_unsaved_mainnet_account_with_main_bdfs(name.into_internal()) .await .into_result() } @@ -70,13 +70,13 @@ impl SargonOS { /// of the factor source has been updated. /// /// Also emits `EventNotification::ProfileModified { change: EventProfileModified::FactorSourceUpdated { id } }` - pub async fn create_unsaved_account( + pub async fn create_unsaved_account_with_main_bdfs( &self, network_id: NetworkID, name: DisplayName, ) -> Result { self.wrapped - .create_unsaved_account_with_bdfs( + .create_unsaved_account_with_main_bdfs( network_id.into_internal(), name.into_internal(), ) @@ -84,29 +84,31 @@ impl SargonOS { .into_result() } - /// Create a new mainnet Account named "Unnamed" and adds it to the active Profile. + /// Create a new mainnet Account named "Unnamed" using main BDFS and adds it to the active Profile. /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::AccountAdded }` - pub async fn create_and_save_new_unnamed_mainnet_account( + pub async fn create_and_save_new_unnamed_mainnet_account_with_main_bdfs( &self, ) -> Result { self.wrapped - .create_and_save_new_unnamed_mainnet_account_with_bdfs() + .create_and_save_new_unnamed_mainnet_account_with_main_bdfs() .await .into_result() } - /// Create a new mainnet Account and adds it to the active Profile. + /// Create a new mainnet Account using the main BDFS and adds it to the active Profile. /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::AccountAdded }` - pub async fn create_and_save_new_mainnet_account( + pub async fn create_and_save_new_mainnet_account_with_main_bdfs( &self, name: DisplayName, ) -> Result { self.wrapped - .create_and_save_new_mainnet_account_with_bdfs(name.into_internal()) + .create_and_save_new_mainnet_account_with_main_bdfs( + name.into_internal(), + ) .await .into_result() } @@ -115,13 +117,33 @@ impl SargonOS { /// /// # Emits Event /// Emits `Event::ProfileModified { change: EventProfileModified::AccountAdded }` - pub async fn create_and_save_new_account( + pub async fn create_and_save_new_account_with_factor_source( + &self, + factor_source: FactorSource, + network_id: NetworkID, + name: DisplayName, + ) -> Result { + self.wrapped + .create_and_save_new_account_with_factor_source( + factor_source.into_internal(), + network_id.into_internal(), + name.into_internal(), + ) + .await + .into_result() + } + + /// Create a new Account using main BDFS and adds it to the active Profile. + /// + /// # Emits Event + /// Emits `Event::ProfileModified { change: EventProfileModified::AccountAdded }` + pub async fn create_and_save_new_account_with_main_bdfs( &self, network_id: NetworkID, name: DisplayName, ) -> Result { self.wrapped - .create_and_save_new_account_with_bdfs( + .create_and_save_new_account_with_main_bdfs( network_id.into_internal(), name.into_internal(), ) @@ -129,6 +151,7 @@ impl SargonOS { .into_result() } + /// Creates account using main BDFS. /// The account names will be ` ` /// /// # Emits Event @@ -136,14 +159,14 @@ impl SargonOS { /// /// And also emits `Event::ProfileSaved` after having successfully written the JSON /// of the active profile to secure storage. - pub async fn batch_create_many_accounts_then_save_once( + pub async fn batch_create_many_accounts_with_main_bdfs_then_save_once( &self, count: u16, network_id: NetworkID, name_prefix: String, ) -> Result<()> { self.wrapped - .batch_create_many_accounts_with_bdfs_then_save_once( + .batch_create_many_accounts_with_main_bdfs_then_save_once( count, network_id.into_internal(), name_prefix, @@ -168,7 +191,7 @@ impl SargonOS { name_prefix: String, ) -> Result> { self.wrapped - .batch_create_unsaved_accounts_with_bdfs_consuming_factor_instances( + .batch_create_unsaved_accounts_with_main_bdfs_consuming_factor_instances( network_id.into_internal(), count, name_prefix, diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/mod.rs b/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/mod.rs index 8955d1714..d5111db72 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/mod.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/mod.rs @@ -2,9 +2,11 @@ mod entities; mod pre_authorization; mod profile_state_holder; mod sargon_os; +mod sargon_os_derive_public_keys; mod sargon_os_entities_linked_to_factor_source; mod sargon_os_factors; mod sargon_os_gateway; +mod sargon_os_personas; mod sargon_os_profile; mod sargon_os_security_center; mod sargon_os_security_structures; @@ -15,9 +17,11 @@ pub use entities::*; pub use pre_authorization::*; pub use profile_state_holder::*; pub use sargon_os::*; +pub use sargon_os_derive_public_keys::*; pub use sargon_os_entities_linked_to_factor_source::*; pub use sargon_os_factors::*; pub use sargon_os_gateway::*; +pub use sargon_os_personas::*; pub use sargon_os_profile::*; pub use sargon_os_security_center::*; pub use sargon_os_security_structures::*; diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_derive_public_keys.rs b/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_derive_public_keys.rs new file mode 100644 index 000000000..ea24691b7 --- /dev/null +++ b/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_derive_public_keys.rs @@ -0,0 +1,30 @@ +use crate::prelude::*; +use sargon::DerivePublicKeysSource as InternalDerivePublicKeysSource; +use sargon::OsDerivePublicKeys; + +#[uniffi::export] +impl SargonOS { + pub async fn derive_public_keys( + &self, + derivation_paths: Vec, + source: DerivePublicKeysSource, + ) -> Result> { + self.wrapped + .derive_public_keys( + derivation_paths.into_internal(), + source.into_internal(), + ) + .await + .into_iter_result() + } +} + +/// The source of the public keys to derive. +#[derive(Clone, PartialEq, InternalConversion, uniffi::Enum)] +pub enum DerivePublicKeysSource { + /// Derive the public keys from a known mnemonic. + Mnemonic(MnemonicWithPassphrase), + + /// Derive the public keys from a factor source added to Profile. + FactorSource(FactorSourceIDFromHash), +} diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_factors.rs b/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_factors.rs index de0650991..0a21a40a6 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_factors.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_factors.rs @@ -45,8 +45,8 @@ impl From impl SargonOS { /// Returns the "main Babylon" `DeviceFactorSource` of the current account as /// a `DeviceFactorSource`. - pub fn bdfs(&self) -> Result { - self.wrapped.bdfs().into_result() + pub fn main_bdfs(&self) -> Result { + self.wrapped.main_bdfs().into_result() } /// Returns all the factor sources diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_personas.rs b/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_personas.rs new file mode 100644 index 000000000..1ae1811e8 --- /dev/null +++ b/crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/sargon_os_personas.rs @@ -0,0 +1,46 @@ +use crate::prelude::*; + +#[uniffi::export] +impl SargonOS { + /// Create a new Persona and adds it to the active Profile. + /// + /// # Emits Event + /// Emits `Event::ProfileModified { change: EventProfileModified::PersonaAdded }` + pub async fn create_and_save_new_persona_with_factor_source( + &self, + factor_source: FactorSource, + network_id: NetworkID, + name: DisplayName, + persona_data: Option, + ) -> Result { + self.wrapped + .create_and_save_new_persona_with_factor_source( + factor_source.into_internal(), + network_id.into_internal(), + name.into_internal(), + persona_data.map(|v| v.into_internal()), + ) + .await + .into_result() + } + + /// Create a new Persona with main BDFS and adds it to the active Profile. + /// + /// # Emits Event + /// Emits `Event::ProfileModified { change: EventProfileModified::PersonaAdded }` + pub async fn create_and_save_new_persona_with_main_bdfs( + &self, + network_id: NetworkID, + name: DisplayName, + persona_data: Option, + ) -> Result { + self.wrapped + .create_and_save_new_persona_with_main_bdfs( + network_id.into_internal(), + name.into_internal(), + persona_data.map(|v| v.into_internal()), + ) + .await + .into_result() + } +}