From 28ac8b8f857e9afc67247ada17fd1470ad0e259f Mon Sep 17 00:00:00 2001 From: sergiupuhalschi-rdx <164897324+sergiupuhalschi-rdx@users.noreply.github.com> Date: Fri, 17 Jan 2025 13:13:39 +0200 Subject: [PATCH] Security Shield builder API updates (#343) * Uniffi expose primary threshold * Add remove all override factors function * Update shield validation * Add time period as recovery emergency fallback * Add samples. Add test * Add samples. Add test * Add extensions * Add swift tests * Expose functions and add tests * PR review * Version bump --- Cargo.lock | 166 ++++++++-------- .../MFA/TimePeriod+Wrap+Functions.swift | 12 ++ .../MFA/TimePeriodUnit+Wrap+Functions.swift | 8 + .../Profile/MFA/Threshold+SampleValues.swift | 9 + .../Profile/MFA/TimePeriod+SampleValues.swift | 9 + .../MFA/SecurityShieldBuilder+Swifified.swift | 6 +- .../Profile/MFA/Threshold+Swiftified.swift | 4 + .../Profile/MFA/TimePeriod+Swiftified.swift | 4 + .../Sources/Sargon/Util/SharedConstants.swift | 4 + .../MFA/SecurityShieldsBuilderTests.swift | 54 +++-- .../Profile/MFA/ThresholdTests.swift | 7 + .../Profile/MFA/TimePeriodTests.swift | 12 ++ .../Profile/MFA/TimePeriodUnitTests.swift | 12 ++ crates/app/home-cards/Cargo.toml | 2 +- crates/app/key-derivation-traits/Cargo.toml | 2 +- crates/app/radix-connect-models/Cargo.toml | 2 +- crates/app/radix-connect/Cargo.toml | 2 +- crates/app/security-center/Cargo.toml | 2 +- crates/app/signing-traits/Cargo.toml | 2 +- crates/app/signing/Cargo.toml | 2 +- crates/common/build-info/Cargo.toml | 2 +- crates/common/bytes/Cargo.toml | 2 +- crates/common/entity-foundation/Cargo.toml | 2 +- crates/common/host-info/Cargo.toml | 2 +- crates/common/identified-vec-of/Cargo.toml | 2 +- crates/common/metadata/Cargo.toml | 2 +- crates/common/network/Cargo.toml | 2 +- crates/common/numeric/Cargo.toml | 2 +- crates/common/short-string/Cargo.toml | 2 +- crates/core/assert-json/Cargo.toml | 2 +- crates/core/collections/Cargo.toml | 2 +- crates/core/error/Cargo.toml | 2 +- crates/core/has-sample-values/Cargo.toml | 2 +- crates/core/misc/Cargo.toml | 2 +- crates/core/prelude/Cargo.toml | 2 +- crates/core/time-utils/Cargo.toml | 2 +- crates/core/utils/Cargo.toml | 2 +- crates/core/utils/src/constants.rs | 6 + 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 +- crates/factors/instances-provider/Cargo.toml | 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 +- .../models/account-for-display/Cargo.toml | 2 +- .../models/account-or-persona/Cargo.toml | 2 +- crates/profile/models/account/Cargo.toml | 2 +- .../profile/models/app-preferences/Cargo.toml | 2 +- crates/profile/models/base-entity/Cargo.toml | 2 +- crates/profile/models/gateway/Cargo.toml | 2 +- crates/profile/models/persona-data/Cargo.toml | 2 +- crates/profile/models/persona/Cargo.toml | 2 +- .../models/profile_SPLIT_ME/Cargo.toml | 2 +- .../models/security-structures/Cargo.toml | 2 +- .../models/security-structures/src/lib.rs | 4 + .../matrices/builder/matrix_builder.rs | 11 +- .../builder/matrix_builder_unit_tests.rs | 15 ++ .../roles/abstract_role_builder_or_built.rs | 7 +- .../security_shield_builder.rs | 187 +++++++++++++++--- .../security-structures/src/threshold.rs | 13 ++ .../security-structures/src/time_period.rs | 101 ++++++++++ .../src/time_period_unit.rs | 40 ++++ .../models/supporting-types/Cargo.toml | 2 +- .../traits/entity-by-address/Cargo.toml | 2 +- crates/sargon/Cargo.toml | 2 +- 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 +- crates/system/os/factors/Cargo.toml | 2 +- crates/system/os/os/Cargo.toml | 2 +- crates/system/os/security-center/Cargo.toml | 2 +- crates/system/os/signing/Cargo.toml | 2 +- crates/system/os/transaction/Cargo.toml | 2 +- crates/system/profile-state-holder/Cargo.toml | 2 +- crates/system/sub-systems/Cargo.toml | 2 +- crates/transaction/foundation/Cargo.toml | 2 +- crates/transaction/manifests/Cargo.toml | 2 +- crates/transaction/models/Cargo.toml | 2 +- crates/uniffi/conversion-macros/Cargo.toml | 2 +- crates/uniffi/uniffi_SPLIT_ME/Cargo.toml | 2 +- .../src/core/utils/constants.rs | 12 +- .../mfa/security_structures/models/mod.rs | 4 + .../security_structures/models/threshold.rs | 10 + .../security_structures/models/time_period.rs | 33 ++++ .../models/time_period_unit.rs | 13 ++ .../security_shield_builder.rs | 77 ++++++-- .../sargon/extensions/SharedConstants.kt | 13 +- .../radixdlt/sargon/extensions/TimePeriod.kt | 10 + .../sargon/extensions/TimePeriodUnit.kt | 7 + .../sargon/samples/ThresholdSample.kt | 14 ++ .../sargon/samples/TimePeriodSample.kt | 14 ++ .../java/com/radixdlt/sargon/ThresholdTest.kt | 10 + .../com/radixdlt/sargon/TimePeriodTest.kt | 26 +++ .../com/radixdlt/sargon/TimePeriodUnitTest.kt | 13 ++ 104 files changed, 845 insertions(+), 238 deletions(-) create mode 100644 apple/Sources/Sargon/Extensions/Methods/Profile/MFA/TimePeriod+Wrap+Functions.swift create mode 100644 apple/Sources/Sargon/Extensions/Methods/Profile/MFA/TimePeriodUnit+Wrap+Functions.swift create mode 100644 apple/Sources/Sargon/Extensions/SampleValues/Profile/MFA/Threshold+SampleValues.swift create mode 100644 apple/Sources/Sargon/Extensions/SampleValues/Profile/MFA/TimePeriod+SampleValues.swift create mode 100644 apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/Threshold+Swiftified.swift create mode 100644 apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/TimePeriod+Swiftified.swift create mode 100644 apple/Tests/TestCases/Profile/MFA/ThresholdTests.swift create mode 100644 apple/Tests/TestCases/Profile/MFA/TimePeriodTests.swift create mode 100644 apple/Tests/TestCases/Profile/MFA/TimePeriodUnitTests.swift create mode 100644 crates/profile/models/security-structures/src/time_period.rs create mode 100644 crates/profile/models/security-structures/src/time_period_unit.rs create mode 100644 crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/time_period.rs create mode 100644 crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/time_period_unit.rs create mode 100644 jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/TimePeriod.kt create mode 100644 jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/TimePeriodUnit.kt create mode 100644 jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/ThresholdSample.kt create mode 100644 jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/TimePeriodSample.kt create mode 100644 jvm/sargon-android/src/test/java/com/radixdlt/sargon/ThresholdTest.kt create mode 100644 jvm/sargon-android/src/test/java/com/radixdlt/sargon/TimePeriodTest.kt create mode 100644 jvm/sargon-android/src/test/java/com/radixdlt/sargon/TimePeriodUnitTest.kt diff --git a/Cargo.lock b/Cargo.lock index eda3f3cb7..17a85df18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "account-for-display" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "derive_more", @@ -48,10 +48,10 @@ dependencies = [ [[package]] name = "addresses" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", - "bytes 1.1.108", + "bytes 1.1.109", "cap26-models", "core-utils", "derive_more", @@ -242,7 +242,7 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "assert-json" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json-diff", "error", @@ -550,7 +550,7 @@ dependencies = [ [[package]] name = "build-info" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", "cargo_toml 0.15.3 (git+https://gitlab.com/lib.rs/cargo_toml?rev=e498c94fc42a660c1ca1a28999ce1d757cfe77fe)", @@ -583,7 +583,7 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", "delegate", @@ -622,7 +622,7 @@ dependencies = [ [[package]] name = "cap26-models" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", "derive_more", @@ -806,7 +806,7 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "clients" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "async-trait", @@ -866,7 +866,7 @@ checksum = "0d8a42181e0652c2997ae4d217f25b63c5337a52fd2279736e97b832fa0a3cff" [[package]] name = "core-collections" -version = "1.1.108" +version = "1.1.109" dependencies = [ "has-sample-values", "indexmap 2.7.0", @@ -893,7 +893,7 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "core-misc" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", "core-utils", @@ -913,7 +913,7 @@ dependencies = [ [[package]] name = "core-utils" -version = "1.1.108" +version = "1.1.109" dependencies = [ "error", "iso8601-timestamp", @@ -1139,7 +1139,7 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "drivers" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "addresses", @@ -1163,10 +1163,10 @@ dependencies = [ [[package]] name = "ecc" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", - "bytes 1.1.108", + "bytes 1.1.109", "derive_more", "enum-as-inner", "error", @@ -1267,11 +1267,11 @@ dependencies = [ [[package]] name = "encryption" -version = "1.1.108" +version = "1.1.109" dependencies = [ "aes-gcm", "assert-json", - "bytes 1.1.108", + "bytes 1.1.109", "derive_more", "error", "has-sample-values", @@ -1288,7 +1288,7 @@ dependencies = [ [[package]] name = "entity-by-address" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "error", @@ -1300,7 +1300,7 @@ dependencies = [ [[package]] name = "entity-foundation" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", "derive_more", @@ -1372,7 +1372,7 @@ dependencies = [ [[package]] name = "error" -version = "1.1.108" +version = "1.1.109" dependencies = [ "derive_more", "log", @@ -1431,7 +1431,7 @@ dependencies = [ [[package]] name = "factor-instances-provider" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "addresses", @@ -1457,9 +1457,9 @@ dependencies = [ [[package]] name = "factors" -version = "1.1.108" +version = "1.1.109" dependencies = [ - "bytes 1.1.108", + "bytes 1.1.109", "cap26-models", "core-collections", "core-misc", @@ -1494,7 +1494,7 @@ dependencies = [ [[package]] name = "factors-supporting-types" -version = "1.1.108" +version = "1.1.109" dependencies = [ "async-trait", "error", @@ -1675,7 +1675,7 @@ dependencies = [ [[package]] name = "gateway-client-and-api" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "addresses", @@ -1695,7 +1695,7 @@ dependencies = [ [[package]] name = "gateway-models" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "assert-json", @@ -1800,7 +1800,7 @@ dependencies = [ [[package]] name = "has-sample-values" -version = "1.1.108" +version = "1.1.109" dependencies = [ "error", "indexmap 2.7.0", @@ -1811,9 +1811,9 @@ dependencies = [ [[package]] name = "hash" -version = "1.1.108" +version = "1.1.109" dependencies = [ - "bytes 1.1.108", + "bytes 1.1.109", "derive_more", "prelude", "radix-common", @@ -1882,11 +1882,11 @@ source = "git+https://github.com/KokaKiwi/rust-hex/?rev=b2b4370b5bf021b98ee7adc9 [[package]] name = "hierarchical-deterministic" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", "bip39", - "bytes 1.1.108", + "bytes 1.1.109", "cap26-models", "derive_more", "ecc", @@ -1928,13 +1928,13 @@ dependencies = [ [[package]] name = "home-cards" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "addresses", "async-trait", "base64 0.22.1 (git+https://github.com/marshallpierce/rust-base64.git?rev=e14400697453bcc85997119b874bc03d9601d0af)", - "bytes 1.1.108", + "bytes 1.1.109", "core-utils", "derive_more", "drivers", @@ -1954,7 +1954,7 @@ dependencies = [ [[package]] name = "host-info" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", "derive_more", @@ -2001,10 +2001,10 @@ dependencies = [ [[package]] name = "http-client" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", - "bytes 1.1.108", + "bytes 1.1.109", "core-utils", "drivers", "error", @@ -2229,7 +2229,7 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "identified-vec-of" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", "derive_more", @@ -2302,7 +2302,7 @@ dependencies = [ [[package]] name = "interactors" -version = "1.1.108" +version = "1.1.109" dependencies = [ "async-trait", "derive_more", @@ -2432,7 +2432,7 @@ dependencies = [ [[package]] name = "key-derivation-traits" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "async-trait", @@ -2450,7 +2450,7 @@ dependencies = [ [[package]] name = "keys-collector" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "addresses", @@ -2539,7 +2539,7 @@ dependencies = [ [[package]] name = "manifests" -version = "1.1.108" +version = "1.1.109" dependencies = [ "account-for-display", "addresses", @@ -2579,7 +2579,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "metadata" -version = "1.1.108" +version = "1.1.109" dependencies = [ "derive_more", "has-sample-values", @@ -2679,7 +2679,7 @@ dependencies = [ [[package]] name = "network" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", "enum-iterator", @@ -2695,7 +2695,7 @@ dependencies = [ [[package]] name = "next-derivation-index-ephemeral" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "assert-json", @@ -2771,9 +2771,9 @@ dependencies = [ [[package]] name = "numeric" -version = "1.1.108" +version = "1.1.109" dependencies = [ - "bytes 1.1.108", + "bytes 1.1.109", "delegate", "derive_more", "enum-iterator", @@ -3011,7 +3011,7 @@ dependencies = [ [[package]] name = "prelude" -version = "1.1.108" +version = "1.1.109" dependencies = [ "radix-engine", "radix-engine-toolkit", @@ -3046,7 +3046,7 @@ dependencies = [ [[package]] name = "profile" -version = "1.1.108" +version = "1.1.109" dependencies = [ "account-for-display", "addresses", @@ -3090,7 +3090,7 @@ dependencies = [ [[package]] name = "profile-account" -version = "1.1.108" +version = "1.1.109" dependencies = [ "account-for-display", "addresses", @@ -3110,7 +3110,7 @@ dependencies = [ [[package]] name = "profile-account-or-persona" -version = "1.1.108" +version = "1.1.109" dependencies = [ "cap26-models", "derive_more", @@ -3127,7 +3127,7 @@ dependencies = [ [[package]] name = "profile-app-preferences" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "core-misc", @@ -3150,7 +3150,7 @@ dependencies = [ [[package]] name = "profile-base-entity" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "derive_more", @@ -3173,7 +3173,7 @@ dependencies = [ [[package]] name = "profile-gateway" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "assert-json", @@ -3197,7 +3197,7 @@ dependencies = [ [[package]] name = "profile-logic" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "derive_more", @@ -3219,7 +3219,7 @@ dependencies = [ [[package]] name = "profile-persona" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "cap26-models", @@ -3240,7 +3240,7 @@ dependencies = [ [[package]] name = "profile-persona-data" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "assert-json", @@ -3259,7 +3259,7 @@ dependencies = [ [[package]] name = "profile-security-structures" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "cap26-models", @@ -3286,7 +3286,7 @@ dependencies = [ [[package]] name = "profile-state-holder" -version = "1.1.108" +version = "1.1.109" dependencies = [ "derive_more", "error", @@ -3301,7 +3301,7 @@ dependencies = [ [[package]] name = "profile-supporting-types" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "derive_more", @@ -3390,14 +3390,14 @@ dependencies = [ [[package]] name = "radix-connect" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "addresses", "assert-json", "async-trait", "base64 0.22.1 (git+https://github.com/marshallpierce/rust-base64.git?rev=e14400697453bcc85997119b874bc03d9601d0af)", - "bytes 1.1.108", + "bytes 1.1.109", "core-misc", "core-utils", "derive_more", @@ -3425,10 +3425,10 @@ dependencies = [ [[package]] name = "radix-connect-models" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", - "bytes 1.1.108", + "bytes 1.1.109", "core-misc", "derive_more", "error", @@ -3912,7 +3912,7 @@ dependencies = [ [[package]] name = "sargon" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "addresses", @@ -3977,7 +3977,7 @@ dependencies = [ [[package]] name = "sargon-os" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "async-trait", @@ -4004,7 +4004,7 @@ dependencies = [ [[package]] name = "sargon-os-accounts" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "addresses", @@ -4027,7 +4027,7 @@ dependencies = [ [[package]] name = "sargon-os-factors" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "async-trait", @@ -4050,7 +4050,7 @@ dependencies = [ [[package]] name = "sargon-os-security-center" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "derive_more", @@ -4066,7 +4066,7 @@ dependencies = [ [[package]] name = "sargon-os-signing" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "async-trait", @@ -4092,7 +4092,7 @@ dependencies = [ [[package]] name = "sargon-os-transaction" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "async-std", @@ -4121,7 +4121,7 @@ dependencies = [ [[package]] name = "sargon-uniffi" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "addresses", @@ -4178,7 +4178,7 @@ dependencies = [ [[package]] name = "sargon-uniffi-conversion-macros" -version = "1.1.108" +version = "1.1.109" dependencies = [ "proc-macro2", "quote", @@ -4352,7 +4352,7 @@ dependencies = [ [[package]] name = "security-center" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", "assert-json", @@ -4557,7 +4557,7 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "short-string" -version = "1.1.108" +version = "1.1.109" dependencies = [ "arraystring", "assert-json", @@ -4592,13 +4592,13 @@ dependencies = [ [[package]] name = "signing" -version = "1.1.108" +version = "1.1.109" dependencies = [ "actix-rt", "addresses", "assert-json", "async-trait", - "bytes 1.1.108", + "bytes 1.1.109", "cap26-models", "core-collections", "core-misc", @@ -4630,10 +4630,10 @@ dependencies = [ [[package]] name = "signing-traits" -version = "1.1.108" +version = "1.1.109" dependencies = [ "async-trait", - "bytes 1.1.108", + "bytes 1.1.109", "core-collections", "derive_more", "ecc", @@ -4796,7 +4796,7 @@ dependencies = [ [[package]] name = "sub-systems" -version = "1.1.108" +version = "1.1.109" dependencies = [ "derive_more", "drivers", @@ -4970,7 +4970,7 @@ dependencies = [ [[package]] name = "time-utils" -version = "1.1.108" +version = "1.1.109" dependencies = [ "iso8601-timestamp", "prelude", @@ -5099,10 +5099,10 @@ dependencies = [ [[package]] name = "transaction-foundation" -version = "1.1.108" +version = "1.1.109" dependencies = [ "assert-json", - "bytes 1.1.108", + "bytes 1.1.109", "derive_more", "has-sample-values", "paste 1.0.14", @@ -5114,10 +5114,10 @@ dependencies = [ [[package]] name = "transaction-models" -version = "1.1.108" +version = "1.1.109" dependencies = [ "addresses", - "bytes 1.1.108", + "bytes 1.1.109", "cargo_toml 0.15.3 (git+https://gitlab.com/lib.rs/cargo_toml?rev=e498c94fc42a660c1ca1a28999ce1d757cfe77fe)", "core-collections", "core-misc", diff --git a/apple/Sources/Sargon/Extensions/Methods/Profile/MFA/TimePeriod+Wrap+Functions.swift b/apple/Sources/Sargon/Extensions/Methods/Profile/MFA/TimePeriod+Wrap+Functions.swift new file mode 100644 index 000000000..bd0e602ea --- /dev/null +++ b/apple/Sources/Sargon/Extensions/Methods/Profile/MFA/TimePeriod+Wrap+Functions.swift @@ -0,0 +1,12 @@ +import Foundation +import SargonUniFFI + +extension TimePeriod { + public init(days: Int) { + self = newTimePeriodWithDays(value: UInt16(days)) + } + + public func days() -> Int { + Int(timePeriodToDays(timePeriod: self)) + } +} diff --git a/apple/Sources/Sargon/Extensions/Methods/Profile/MFA/TimePeriodUnit+Wrap+Functions.swift b/apple/Sources/Sargon/Extensions/Methods/Profile/MFA/TimePeriodUnit+Wrap+Functions.swift new file mode 100644 index 000000000..ab23c0da0 --- /dev/null +++ b/apple/Sources/Sargon/Extensions/Methods/Profile/MFA/TimePeriodUnit+Wrap+Functions.swift @@ -0,0 +1,8 @@ +import Foundation +import SargonUniFFI + +extension TimePeriodUnit { + public var values: [Int] { + Array(1 ... Int(constantMaxRecoveryConfirmationFallbackPeriodUnits())) + } +} diff --git a/apple/Sources/Sargon/Extensions/SampleValues/Profile/MFA/Threshold+SampleValues.swift b/apple/Sources/Sargon/Extensions/SampleValues/Profile/MFA/Threshold+SampleValues.swift new file mode 100644 index 000000000..614f24eba --- /dev/null +++ b/apple/Sources/Sargon/Extensions/SampleValues/Profile/MFA/Threshold+SampleValues.swift @@ -0,0 +1,9 @@ +import Foundation +import SargonUniFFI + +#if DEBUG +extension Threshold { + public static let sample: Self = newThresholdSample() + public static let sampleOther: Self = newThresholdSampleOther() +} +#endif // DEBUG diff --git a/apple/Sources/Sargon/Extensions/SampleValues/Profile/MFA/TimePeriod+SampleValues.swift b/apple/Sources/Sargon/Extensions/SampleValues/Profile/MFA/TimePeriod+SampleValues.swift new file mode 100644 index 000000000..8822894c9 --- /dev/null +++ b/apple/Sources/Sargon/Extensions/SampleValues/Profile/MFA/TimePeriod+SampleValues.swift @@ -0,0 +1,9 @@ +import Foundation +import SargonUniFFI + +#if DEBUG +extension TimePeriod { + public static let sample: Self = newTimePeriodSample() + public static let sampleOther: Self = newTimePeriodSampleOther() +} +#endif // DEBUG diff --git a/apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/SecurityShieldBuilder+Swifified.swift b/apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/SecurityShieldBuilder+Swifified.swift index 40264c4ff..a82b1d474 100644 --- a/apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/SecurityShieldBuilder+Swifified.swift +++ b/apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/SecurityShieldBuilder+Swifified.swift @@ -4,11 +4,11 @@ extension SecurityShieldBuilder { public typealias Factor = FactorSourceID /// Confirmation Role - public var numberOfDaysUntilAutoConfirm: UInt16 { - getNumberOfDaysUntilAutoConfirm() + public var timePeriodUntilAutoConfirm: TimePeriod { + getTimePeriodUntilAutoConfirm() } - public var threshold: UInt8 { + public var threshold: Threshold { getPrimaryThreshold() } diff --git a/apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/Threshold+Swiftified.swift b/apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/Threshold+Swiftified.swift new file mode 100644 index 000000000..02cf95acf --- /dev/null +++ b/apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/Threshold+Swiftified.swift @@ -0,0 +1,4 @@ +import Foundation +import SargonUniFFI + +extension Threshold: SargonModel {} diff --git a/apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/TimePeriod+Swiftified.swift b/apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/TimePeriod+Swiftified.swift new file mode 100644 index 000000000..b3cd2b7b3 --- /dev/null +++ b/apple/Sources/Sargon/Extensions/Swiftified/Profile/MFA/TimePeriod+Swiftified.swift @@ -0,0 +1,4 @@ +import Foundation +import SargonUniFFI + +extension TimePeriod: SargonModel {} diff --git a/apple/Sources/Sargon/Util/SharedConstants.swift b/apple/Sources/Sargon/Util/SharedConstants.swift index 36e7c00ee..04f555f7f 100644 --- a/apple/Sources/Sargon/Util/SharedConstants.swift +++ b/apple/Sources/Sargon/Util/SharedConstants.swift @@ -12,3 +12,7 @@ extension Account { extension Persona { public static let nameMaxLength = Int(constantEntityNameMaxLength()) } + +extension DisplayName { + public static let maxLength = Int(constantDisplayNameMaxLength()) +} diff --git a/apple/Tests/TestCases/Profile/MFA/SecurityShieldsBuilderTests.swift b/apple/Tests/TestCases/Profile/MFA/SecurityShieldsBuilderTests.swift index 3fd67378c..9505791ab 100644 --- a/apple/Tests/TestCases/Profile/MFA/SecurityShieldsBuilderTests.swift +++ b/apple/Tests/TestCases/Profile/MFA/SecurityShieldsBuilderTests.swift @@ -18,17 +18,17 @@ struct ShieldTests { @Test("threshold") func threshold() { var builder = SecurityShieldBuilder() - #expect(builder.threshold == 0) + #expect(builder.threshold == Threshold.all) builder = builder.setThreshold(threshold: Threshold.specific(42)) - #expect(builder.threshold == 42) + #expect(builder.threshold == Threshold.specific(42)) } @Test("days") func days() { var builder = SecurityShieldBuilder() - #expect(builder.numberOfDaysUntilAutoConfirm == 14) - builder = builder.setNumberOfDaysUntilAutoConfirm(numberOfDays: 237) - #expect(builder.numberOfDaysUntilAutoConfirm == 237) + #expect(builder.timePeriodUntilAutoConfirm == TimePeriod(days: 14)) + builder = builder.setTimePeriodUntilAutoConfirm(timePeriod: TimePeriod(days: 237)) + #expect(builder.timePeriodUntilAutoConfirm == TimePeriod(days: 237)) } @Test("empty primary threshold") @@ -74,23 +74,25 @@ struct ShieldTests { .addFactorSourceToRecoveryOverride(factorSourceId: y) #expect(builder.recoveryRoleFactors == [y]) - #expect(builder.threshold == 3) + #expect(builder.threshold == Threshold.specific(3)) builder = builder.removeFactorFromPrimary(factorSourceId: x, factorListKind: FactorListKind.threshold) - #expect(builder.threshold == 2) + #expect(builder.threshold == Threshold.specific(2)) builder = builder.removeFactorFromAllRoles(factorSourceId: y) #expect(builder.recoveryRoleFactors == []) // assert `y` is removed from Recovery and Primary - #expect(builder.threshold == 1) + #expect(builder.threshold == Threshold.specific(1)) builder = builder.removeFactorFromPrimary(factorSourceId: z, factorListKind: FactorListKind.threshold) - #expect(builder.threshold == 0) + #expect(builder.threshold == Threshold.all) #expect(builder.primaryRoleThresholdFactors == []) } @Test("basic validation") func basicValidation() throws { var builder = SecurityShieldBuilder() + #expect(builder.validate() == .MissingAuthSigningFactor) + builder = builder.setAuthenticationSigningFactor(new: .sampleDevice) #expect(builder.validate() == .PrimaryRoleMustHaveAtLeastOneFactor) builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice) .addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice) // did not get added, duplicates are not allowed @@ -112,17 +114,9 @@ struct ShieldTests { #expect((try? builder.build()) != nil) } - @Test("primary role with threshold factors cannot have a threshold value of zero") - func primaryRoleWithThresholdFactorsCannotHaveAThresholdValueOfZero() throws { - var builder = SecurityShieldBuilder() - .addFactorSourceToPrimaryThreshold(factorSourceId: .sampleLedger) - .setThreshold(threshold: Threshold.specific(0)) - #expect(builder.validate() == .PrimaryRoleWithThresholdFactorsCannotHaveAThresholdValueOfZero) - } - @Test("cannot add forbidden FactorSourceKinds") func preventAddOfForbiddenFactorSourceKinds() throws { - var builder = SecurityShieldBuilder() + let builder = SecurityShieldBuilder() // Primary .addFactorSourceToPrimaryThreshold(factorSourceId: .sampleTrustedContact) // Verboten .addFactorSourceToPrimaryThreshold(factorSourceId: .sampleSecurityQuestions) // Verboten @@ -161,14 +155,14 @@ struct ShieldTests { @Test("Primary password never alone") func primaryPasswordNeverAlone() { var builder = SecurityShieldBuilder() + .setAuthenticationSigningFactor(new: .sampleDevice) .addFactorSourceToPrimaryOverride(factorSourceId: .samplePassword) // not allowed #expect(builder.primaryRoleOverrideFactors.isEmpty) builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .samplePassword) #expect(builder.validate() == .PrimaryRoleWithPasswordInThresholdListMustHaveAnotherFactor) - builder = builder.setThreshold(threshold: Threshold.specific(0)) + builder = builder.setThreshold(threshold: Threshold.all) - #expect(builder.validate() == .PrimaryRoleWithThresholdFactorsCannotHaveAThresholdValueOfZero) builder = builder.setThreshold(threshold: Threshold.specific(1)) #expect(builder.validate() == .PrimaryRoleWithPasswordInThresholdListMustHaveAnotherFactor) builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleLedger) @@ -178,7 +172,7 @@ struct ShieldTests { builder = builder.addFactorSourceToRecoveryOverride(factorSourceId: .sampleArculus) .addFactorSourceToConfirmationOverride(factorSourceId: .sampleArculusOther) - builder.setAuthenticationSigningFactor(new: .sampleDevice) + builder = builder.setAuthenticationSigningFactor(new: .sampleDevice) let shield = try! builder.build() @@ -191,14 +185,16 @@ struct ShieldTests { func build() throws { var builder = SecurityShieldBuilder() .setName(name: "S.H.I.E.L.D.") - .setNumberOfDaysUntilAutoConfirm(numberOfDays: 42) + .setTimePeriodUntilAutoConfirm(timePeriod: TimePeriod(days: 42)) + #expect(builder.validate() == .MissingAuthSigningFactor) + builder = builder.setAuthenticationSigningFactor(new: .sampleDevice) #expect(builder.validate() == .PrimaryRoleMustHaveAtLeastOneFactor) // Primary - #expect(builder.threshold == 0) - builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice) // bumps threshold - #expect(builder.threshold == 1) + #expect(builder.threshold == Threshold.all) + builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice) + #expect(builder.threshold == Threshold.all) builder = builder.addFactorSourceToPrimaryOverride(factorSourceId: .sampleArculus) .addFactorSourceToPrimaryOverride(factorSourceId: .sampleArculusOther) // Recovery @@ -210,7 +206,7 @@ struct ShieldTests { .removeFactorFromPrimary(factorSourceId: .sampleArculusOther, factorListKind: FactorListKind.override) .removeFactorFromRecovery(factorSourceId: .sampleLedgerOther) - builder.setAuthenticationSigningFactor(new: .sampleDevice) + builder = builder.setAuthenticationSigningFactor(new: .sampleDevice) // Validate #expect(builder.validate() == nil) @@ -234,7 +230,7 @@ struct ShieldTests { @Test("selected primary threshold factors status") func selectedPrimaryThresholdFactorsStatusInvalid() { - var builder = SecurityShieldBuilder() + let builder = SecurityShieldBuilder() .addFactorSourceToPrimaryThreshold(factorSourceId: .samplePassword) #expect(builder.selectedPrimaryThresholdFactorsStatus() == .invalid(reason: SelectedPrimaryThresholdFactorsStatusInvalidReason.cannotBeUsedAlone(factorSourceKind: FactorSourceKind.password))) @@ -246,11 +242,11 @@ struct ShieldTests { #expect(builder.selectedPrimaryThresholdFactorsStatus() == .insufficient) - builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice) + builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice) #expect(builder.selectedPrimaryThresholdFactorsStatus() == .suboptimal) - builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleLedger) + builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleLedger) #expect(builder.selectedPrimaryThresholdFactorsStatus() == .optimal) } diff --git a/apple/Tests/TestCases/Profile/MFA/ThresholdTests.swift b/apple/Tests/TestCases/Profile/MFA/ThresholdTests.swift new file mode 100644 index 000000000..c155118c7 --- /dev/null +++ b/apple/Tests/TestCases/Profile/MFA/ThresholdTests.swift @@ -0,0 +1,7 @@ +import CustomDump +import Foundation +import Sargon +import SargonUniFFI +import XCTest + +final class ThresholdTests: Test {} diff --git a/apple/Tests/TestCases/Profile/MFA/TimePeriodTests.swift b/apple/Tests/TestCases/Profile/MFA/TimePeriodTests.swift new file mode 100644 index 000000000..4248bb2c0 --- /dev/null +++ b/apple/Tests/TestCases/Profile/MFA/TimePeriodTests.swift @@ -0,0 +1,12 @@ +import CustomDump +import Foundation +import Sargon +import SargonUniFFI +import XCTest + +final class TimePeriodTests: Test { + func test() { + let sut = SUT(days: 1) + XCTAssertEqual(sut.days(), 1) + } +} diff --git a/apple/Tests/TestCases/Profile/MFA/TimePeriodUnitTests.swift b/apple/Tests/TestCases/Profile/MFA/TimePeriodUnitTests.swift new file mode 100644 index 000000000..3da4b7580 --- /dev/null +++ b/apple/Tests/TestCases/Profile/MFA/TimePeriodUnitTests.swift @@ -0,0 +1,12 @@ +import CustomDump +import Foundation +import Sargon +import SargonUniFFI +import XCTest + +final class TimePeriodUnitTests: TestCase { + func test() { + let sut = TimePeriodUnit.days + XCTAssertEqual(sut.values, Array(1 ... 9999)) + } +} diff --git a/crates/app/home-cards/Cargo.toml b/crates/app/home-cards/Cargo.toml index 48d9b5bdd..75796b4d6 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/app/key-derivation-traits/Cargo.toml b/crates/app/key-derivation-traits/Cargo.toml index 95599663f..0d3e3221d 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/app/radix-connect-models/Cargo.toml b/crates/app/radix-connect-models/Cargo.toml index 3aab962a4..44c988d5b 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/app/radix-connect/Cargo.toml b/crates/app/radix-connect/Cargo.toml index 5c18cb3cc..6b13a804e 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.108" +version = "1.1.109" edition = "2021" diff --git a/crates/app/security-center/Cargo.toml b/crates/app/security-center/Cargo.toml index 3ec092d66..79d5e9b75 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/app/signing-traits/Cargo.toml b/crates/app/signing-traits/Cargo.toml index 7b8cd5ee0..aafa43f95 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/app/signing/Cargo.toml b/crates/app/signing/Cargo.toml index 44e62dad4..e85528476 100644 --- a/crates/app/signing/Cargo.toml +++ b/crates/app/signing/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "signing" -version = "1.1.108" +version = "1.1.109" edition = "2021" diff --git a/crates/common/build-info/Cargo.toml b/crates/common/build-info/Cargo.toml index 01d9d1cf6..6fbc277fd 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.108" +version = "1.1.109" edition = "2021" build = "build.rs" diff --git a/crates/common/bytes/Cargo.toml b/crates/common/bytes/Cargo.toml index 3b99ebed5..880230d8a 100644 --- a/crates/common/bytes/Cargo.toml +++ b/crates/common/bytes/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bytes" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/common/entity-foundation/Cargo.toml b/crates/common/entity-foundation/Cargo.toml index 1d167bcdd..ff52832ab 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/common/host-info/Cargo.toml b/crates/common/host-info/Cargo.toml index 27f1d2ac5..bce159297 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/common/identified-vec-of/Cargo.toml b/crates/common/identified-vec-of/Cargo.toml index 51b76e545..31a8d15f3 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/common/metadata/Cargo.toml b/crates/common/metadata/Cargo.toml index 95563930c..f75e301d4 100644 --- a/crates/common/metadata/Cargo.toml +++ b/crates/common/metadata/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "metadata" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/common/network/Cargo.toml b/crates/common/network/Cargo.toml index 3c1c0721d..8b8db8bd2 100644 --- a/crates/common/network/Cargo.toml +++ b/crates/common/network/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "network" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/common/numeric/Cargo.toml b/crates/common/numeric/Cargo.toml index 8c055598f..8ffbc7d0e 100644 --- a/crates/common/numeric/Cargo.toml +++ b/crates/common/numeric/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "numeric" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/common/short-string/Cargo.toml b/crates/common/short-string/Cargo.toml index b4a54acb0..9013f253f 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/core/assert-json/Cargo.toml b/crates/core/assert-json/Cargo.toml index bfef86351..40007b3c7 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/core/collections/Cargo.toml b/crates/core/collections/Cargo.toml index c830a2eb6..6e0c51b85 100644 --- a/crates/core/collections/Cargo.toml +++ b/crates/core/collections/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-collections" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/core/error/Cargo.toml b/crates/core/error/Cargo.toml index 969b377fa..8b79caed6 100644 --- a/crates/core/error/Cargo.toml +++ b/crates/core/error/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "error" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/core/has-sample-values/Cargo.toml b/crates/core/has-sample-values/Cargo.toml index ae3b3b104..1085535e2 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/core/misc/Cargo.toml b/crates/core/misc/Cargo.toml index 025db805c..5ba9c2ef5 100644 --- a/crates/core/misc/Cargo.toml +++ b/crates/core/misc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-misc" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/core/prelude/Cargo.toml b/crates/core/prelude/Cargo.toml index e30feec21..719a43a51 100644 --- a/crates/core/prelude/Cargo.toml +++ b/crates/core/prelude/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "prelude" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/core/time-utils/Cargo.toml b/crates/core/time-utils/Cargo.toml index 38642add2..80ae48425 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/core/utils/Cargo.toml b/crates/core/utils/Cargo.toml index b27bf4be3..7308b20ac 100644 --- a/crates/core/utils/Cargo.toml +++ b/crates/core/utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-utils" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/core/utils/src/constants.rs b/crates/core/utils/src/constants.rs index 344436c4a..e54bea9f7 100644 --- a/crates/core/utils/src/constants.rs +++ b/crates/core/utils/src/constants.rs @@ -31,6 +31,12 @@ pub const POLLING_DELAY_INCREMENT_IN_SECONDS: u64 = 1; /// Number of minutes per day. pub const MINUTES_PER_DAY: u32 = 24 * 60; +/// Number of days per week. +pub const DAYS_PER_WEEK: u16 = 7; + +/// Number of days per year. +pub const DAYS_PER_YEAR: u16 = 365; + #[cfg(test)] mod tests { use super::*; diff --git a/crates/crypto/addresses/Cargo.toml b/crates/crypto/addresses/Cargo.toml index 8b6e75219..0bcbab6f5 100644 --- a/crates/crypto/addresses/Cargo.toml +++ b/crates/crypto/addresses/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "addresses" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/crypto/cap26-models/Cargo.toml b/crates/crypto/cap26-models/Cargo.toml index e12b85485..917046ab7 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/crypto/ecc/Cargo.toml b/crates/crypto/ecc/Cargo.toml index 1054af6b2..15b383f63 100644 --- a/crates/crypto/ecc/Cargo.toml +++ b/crates/crypto/ecc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ecc" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/crypto/encryption/Cargo.toml b/crates/crypto/encryption/Cargo.toml index d98f88674..b35061e05 100644 --- a/crates/crypto/encryption/Cargo.toml +++ b/crates/crypto/encryption/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "encryption" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/crypto/hash/Cargo.toml b/crates/crypto/hash/Cargo.toml index e87ddef0e..92564991f 100644 --- a/crates/crypto/hash/Cargo.toml +++ b/crates/crypto/hash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hash" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/crypto/hd/Cargo.toml b/crates/crypto/hd/Cargo.toml index aab6cd8b3..40bf88dae 100644 --- a/crates/crypto/hd/Cargo.toml +++ b/crates/crypto/hd/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hierarchical-deterministic" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/factors/factors/Cargo.toml b/crates/factors/factors/Cargo.toml index b3ff78b5a..aca8aa1fd 100644 --- a/crates/factors/factors/Cargo.toml +++ b/crates/factors/factors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "factors" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/factors/instances-provider/Cargo.toml b/crates/factors/instances-provider/Cargo.toml index d65d99dee..c2c60c7f9 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/factors/keys-collector/Cargo.toml b/crates/factors/keys-collector/Cargo.toml index a0d854c2c..19bf6ebe4 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/factors/next-derivation-index-ephemeral/Cargo.toml b/crates/factors/next-derivation-index-ephemeral/Cargo.toml index 6445793c4..8929b6db9 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/factors/supporting-types/Cargo.toml b/crates/factors/supporting-types/Cargo.toml index bf1bdaddd..6f6b7ac3a 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/gateway/client-and-api/Cargo.toml b/crates/gateway/client-and-api/Cargo.toml index 5f44561cb..fbf4f72b6 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/gateway/models/Cargo.toml b/crates/gateway/models/Cargo.toml index 8a0a36528..d117e5f53 100644 --- a/crates/gateway/models/Cargo.toml +++ b/crates/gateway/models/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gateway-models" -version = "1.1.108" +version = "1.1.109" edition = "2021" diff --git a/crates/profile/logic/logic_SPLIT_ME/Cargo.toml b/crates/profile/logic/logic_SPLIT_ME/Cargo.toml index 617d0c5ce..68d7f91a8 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/models/account-for-display/Cargo.toml b/crates/profile/models/account-for-display/Cargo.toml index 62d548df8..936c9879d 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/models/account-or-persona/Cargo.toml b/crates/profile/models/account-or-persona/Cargo.toml index f6bc2bea9..4508c3164 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/models/account/Cargo.toml b/crates/profile/models/account/Cargo.toml index 9924543f5..bd0d3a929 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/models/app-preferences/Cargo.toml b/crates/profile/models/app-preferences/Cargo.toml index 25896ab5c..4f4db4e86 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/models/base-entity/Cargo.toml b/crates/profile/models/base-entity/Cargo.toml index c9b8604d0..01e813599 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/models/gateway/Cargo.toml b/crates/profile/models/gateway/Cargo.toml index 28bc229ae..a389e5646 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/models/persona-data/Cargo.toml b/crates/profile/models/persona-data/Cargo.toml index 3d58a2947..65e4696a5 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/models/persona/Cargo.toml b/crates/profile/models/persona/Cargo.toml index 9bdfa5c40..6707198cd 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/models/profile_SPLIT_ME/Cargo.toml b/crates/profile/models/profile_SPLIT_ME/Cargo.toml index 0bca61f20..145f1fb2a 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.108" +version = "1.1.109" edition = "2021" diff --git a/crates/profile/models/security-structures/Cargo.toml b/crates/profile/models/security-structures/Cargo.toml index 5c66a13e7..4afcfc150 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/models/security-structures/src/lib.rs b/crates/profile/models/security-structures/src/lib.rs index 8c3c4e014..e18644041 100644 --- a/crates/profile/models/security-structures/src/lib.rs +++ b/crates/profile/models/security-structures/src/lib.rs @@ -4,11 +4,15 @@ mod factor_list_kind; mod role_kind; mod roles_matrices_structures; mod threshold; +mod time_period; +mod time_period_unit; pub mod prelude { pub use crate::factor_list_kind::*; pub use crate::role_kind::*; pub use crate::roles_matrices_structures::*; + pub use crate::time_period::*; + pub use crate::time_period_unit::*; pub use addresses::prelude::*; pub use cap26_models::prelude::*; diff --git a/crates/profile/models/security-structures/src/roles_matrices_structures/matrices/builder/matrix_builder.rs b/crates/profile/models/security-structures/src/roles_matrices_structures/matrices/builder/matrix_builder.rs index 00f29d4a8..f83e083f6 100644 --- a/crates/profile/models/security-structures/src/roles_matrices_structures/matrices/builder/matrix_builder.rs +++ b/crates/profile/models/security-structures/src/roles_matrices_structures/matrices/builder/matrix_builder.rs @@ -372,8 +372,8 @@ impl MatrixBuilder { .into_matrix_err(RoleKind::Primary) } - pub fn get_threshold(&self) -> u8 { - self.primary_role.get_threshold_value() + pub fn get_threshold(&self) -> Threshold { + self.primary_role.get_threshold() } pub fn set_number_of_days_until_auto_confirm( @@ -420,6 +420,13 @@ impl MatrixBuilder { ) } + pub fn remove_all_factors_from_primary_override( + &mut self, + ) -> MatrixBuilderMutateResult { + self.primary_role.remove_all_override_factors(); + Ok(()) + } + pub fn remove_factor_from_recovery( &mut self, factor_source_id: &FactorSourceID, diff --git a/crates/profile/models/security-structures/src/roles_matrices_structures/matrices/builder/matrix_builder_unit_tests.rs b/crates/profile/models/security-structures/src/roles_matrices_structures/matrices/builder/matrix_builder_unit_tests.rs index 8a8d60863..978716396 100644 --- a/crates/profile/models/security-structures/src/roles_matrices_structures/matrices/builder/matrix_builder_unit_tests.rs +++ b/crates/profile/models/security-structures/src/roles_matrices_structures/matrices/builder/matrix_builder_unit_tests.rs @@ -424,6 +424,21 @@ mod remove { assert_eq!(res, Ok(())); } + #[test] + fn remove_all_from_primary_override_is_ok() { + let mut sut = make(); + sut.add_factor_source_to_primary_override( + FactorSourceID::sample_device(), + ) + .unwrap(); + sut.add_factor_source_to_primary_override( + FactorSourceID::sample_ledger(), + ) + .unwrap(); + let res = sut.remove_all_factors_from_primary_override(); + assert_eq!(res, Ok(())); + } + #[test] fn remove_from_recovery_is_ok() { let mut sut = make(); diff --git a/crates/profile/models/security-structures/src/roles_matrices_structures/roles/abstract_role_builder_or_built.rs b/crates/profile/models/security-structures/src/roles_matrices_structures/roles/abstract_role_builder_or_built.rs index c60fcbb59..a560734cc 100644 --- a/crates/profile/models/security-structures/src/roles_matrices_structures/roles/abstract_role_builder_or_built.rs +++ b/crates/profile/models/security-structures/src/roles_matrices_structures/roles/abstract_role_builder_or_built.rs @@ -81,13 +81,18 @@ pub(crate) type RoleBuilder = impl AbstractRoleBuilderOrBuilt { - /// Removes all factors from this role and set threshold to 0. + /// Removes all factors from this role and set threshold to `All`. pub fn reset(&mut self) { self.threshold_factors.clear(); self.threshold = Threshold::All; self.override_factors.clear(); } + /// Removes all override factors from this role. + pub fn remove_all_override_factors(&mut self) { + self.override_factors.clear(); + } + pub fn role(&self) -> RoleKind { RoleKind::from_u8(ROLE).expect("RoleKind should be valid") } diff --git a/crates/profile/models/security-structures/src/roles_matrices_structures/security_shield_builder.rs b/crates/profile/models/security-structures/src/roles_matrices_structures/security_shield_builder.rs index d43d1660c..7dd24bc9a 100644 --- a/crates/profile/models/security-structures/src/roles_matrices_structures/security_shield_builder.rs +++ b/crates/profile/models/security-structures/src/roles_matrices_structures/security_shield_builder.rs @@ -131,6 +131,9 @@ impl std::hash::Hash for SecurityShieldBuilder { } impl SecurityShieldBuilder { + /// Maximum number of units (days, weeks, years) for the security structure recovery confirmation fallback period. + pub const MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS: u16 = 9999; + pub fn new(mode: SecurityShieldBuilderMode) -> Self { let matrix_builder = MatrixBuilder::new(); let name = RwLock::new("My Shield".to_owned()); @@ -191,6 +194,30 @@ impl HasSampleValues for SecurityShieldBuilder { } } +impl SecurityShieldBuilder { + pub fn sample_strict_with_auth_signing() -> Self { + Self::with_details( + SecurityShieldBuilderMode::Strict, + RwLock::new(MatrixBuilder::new()), + RwLock::new("My Shield".to_owned()), + RwLock::new(Some(FactorSourceID::sample_ledger())), + SecurityStructureID::from(Uuid::new_v4()), + now(), + ) + } + + pub fn sample_lenient_with_auth_signing() -> Self { + Self::with_details( + SecurityShieldBuilderMode::Lenient, + RwLock::new(MatrixBuilder::new()), + RwLock::new("My Shield".to_owned()), + RwLock::new(Some(FactorSourceID::sample_ledger())), + SecurityStructureID::from(Uuid::new_v4()), + now(), + ) + } +} + impl SecurityShieldBuilder { fn get(&self, access: impl Fn(&MatrixBuilder) -> R) -> R { let binding = self.matrix_builder.read().unwrap(); @@ -236,12 +263,24 @@ impl SecurityShieldBuilder { // ==== GET / READ ==== // ==================== impl SecurityShieldBuilder { - pub fn get_threshold(&self) -> u8 { + pub fn get_threshold(&self) -> Threshold { self.get(|builder| builder.get_threshold()) } - pub fn get_number_of_days_until_auto_confirm(&self) -> u16 { - self.get(|builder| builder.get_number_of_days_until_auto_confirm()) + pub fn get_threshold_values(&self) -> Vec { + self.get(|builder| { + Threshold::values( + builder.get_primary_threshold_factors().len() as u8 + ) + }) + } + + pub fn get_time_period_until_auto_confirm(&self) -> TimePeriod { + self.get(|builder| { + TimePeriod::with_days( + builder.get_number_of_days_until_auto_confirm(), + ) + }) } pub fn get_name(&self) -> String { @@ -359,6 +398,11 @@ impl SecurityShieldBuilder { }) } + /// Removes all factors from the override list of the primary role. + pub fn remove_all_factors_from_primary_override(&self) -> &Self { + self.set(|builder| builder.remove_all_factors_from_primary_override()) + } + /// Removes factor **only** from the recovery role. pub fn remove_factor_from_recovery( &self, @@ -389,12 +433,12 @@ impl SecurityShieldBuilder { self.set(|builder| builder.set_threshold(threshold)) } - pub fn set_number_of_days_until_auto_confirm( + pub fn set_time_period_until_auto_confirm( &self, - number_of_days: u16, + time_period: TimePeriod, ) -> &Self { self.set(|builder| { - builder.set_number_of_days_until_auto_confirm(number_of_days) + builder.set_number_of_days_until_auto_confirm(time_period.days()) }) } @@ -651,6 +695,12 @@ impl SecurityShieldBuilder { return Some(SecurityShieldBuilderInvalidReason::ShieldNameInvalid); } + if self.get_authentication_signing_factor().is_none() { + return Some( + SecurityShieldBuilderInvalidReason::MissingAuthSigningFactor, + ); + } + if let Some(matrix_invalid_reason) = self.get(|builder| { let r = builder.validate(); r.as_shield_validation() @@ -658,12 +708,6 @@ impl SecurityShieldBuilder { return Some(matrix_invalid_reason); } - if self.get_authentication_signing_factor().is_none() { - return Some( - SecurityShieldBuilderInvalidReason::MissingAuthSigningFactor, - ); - } - None } @@ -867,7 +911,7 @@ mod tests { sut.add_factor_source_to_primary_threshold( FactorSourceID::sample_device(), ); - assert_eq!(sut.get_threshold(), 42); + assert_eq!(sut.get_threshold(), Threshold::Specific(42)); } #[test] @@ -913,6 +957,39 @@ mod tests { assert_eq!(sut.get_authentication_signing_factor().unwrap(), valid); } + #[test] + fn test_get_time_period_until_auto_confirm() { + let sut = SUT::strict(); + assert_eq!( + sut.get_time_period_until_auto_confirm(), + TimePeriod::with_days(14) + ); + sut.set_time_period_until_auto_confirm(TimePeriod::with_days(42)); + assert_eq!( + sut.get_time_period_until_auto_confirm(), + TimePeriod::with_days(42) + ); + } + + #[test] + fn test_threshold_values() { + let sut = SUT::strict(); + sut.add_factor_source_to_primary_threshold( + FactorSourceID::sample_device(), + ); + + assert_eq!(sut.get_threshold_values(), vec![Threshold::All]); + + sut.add_factor_source_to_primary_threshold( + FactorSourceID::sample_ledger(), + ); + + assert_eq!( + sut.get_threshold_values(), + vec![Threshold::All, Threshold::Specific(1)] + ); + } + #[test] fn test() { let sut = SUT::default(); @@ -923,7 +1000,7 @@ mod tests { FactorSourceID::sample_device(), )) // Primary - .set_number_of_days_until_auto_confirm(42) + .set_time_period_until_auto_confirm(TimePeriod::with_days(42)) .add_factor_source_to_primary_threshold( FactorSourceID::sample_device(), ) @@ -1240,7 +1317,7 @@ mod tests { #[test] fn selected_primary_threshold_factors_status() { - let sut = SUT::default(); + let sut = SUT::sample_lenient_with_auth_signing(); pretty_assertions::assert_eq!( sut.selected_primary_threshold_factors_status(), @@ -1273,6 +1350,31 @@ mod tests { SelectedPrimaryThresholdFactorsStatus::Optimal ); } + + #[test] + fn remove_all_factors_from_primary_override() { + let sut = SUT::default(); + + let _ = sut + .add_factor_source_to_primary_override( + FactorSourceID::sample_device(), + ) + .add_factor_source_to_primary_override( + FactorSourceID::sample_device_other(), + ); + + pretty_assertions::assert_eq!( + sut.get_primary_override_factors(), + vec![ + FactorSourceID::sample_device(), + FactorSourceID::sample_device_other(), + ] + ); + + sut.remove_all_factors_from_primary_override(); + + assert!(sut.get_primary_override_factors().is_empty()); + } } #[cfg(test)] @@ -1284,8 +1386,36 @@ mod test_invalid { type SUT = SecurityShieldBuilder; #[test] - fn primary_role_must_have_at_least_one_factor() { + fn must_have_auth_signing_factor() { let sut = SUT::strict(); + assert_eq!( + sut.validate().unwrap(), + SecurityShieldBuilderInvalidReason::MissingAuthSigningFactor + ); + } + + #[test] + fn missing_auth_signing_takes_precedence_over_roles_validation() { + let sut = SUT::strict(); + + sut.add_factor_source_to_primary_threshold( + FactorSourceID::sample_device(), + ) + .add_factor_source_to_recovery_override(FactorSourceID::sample_device()) + // This addition results in SingleFactorUsedInPrimaryMustNotBeUsedInAnyOtherRole matrix invalid reason + .add_factor_source_to_confirmation_override( + FactorSourceID::sample_device(), + ); + + assert_eq!( + sut.validate().unwrap(), + SecurityShieldBuilderInvalidReason::MissingAuthSigningFactor + ); + } + + #[test] + fn primary_role_must_have_at_least_one_factor() { + let sut = SUT::sample_strict_with_auth_signing(); assert_eq!( sut.validate().unwrap(), SecurityShieldBuilderInvalidReason::PrimaryRoleMustHaveAtLeastOneFactor @@ -1298,12 +1428,11 @@ mod test_invalid { #[test] fn primary_role_with_threshold_cannot_be_zero_with_factors() { - let sut = SUT::strict(); + let sut = SUT::sample_strict_with_auth_signing(); sut.add_factor_source_to_primary_threshold( - // bumped threshold FactorSourceID::sample_device(), ); - assert_eq!(sut.get_threshold(), 1); + assert_eq!(sut.get_threshold(), Threshold::All); sut.set_threshold(Threshold::zero()); assert_eq!( sut.validate().unwrap(), @@ -1317,7 +1446,7 @@ mod test_invalid { #[test] fn recovery_role_must_have_at_least_one_factor() { - let sut = SUT::strict(); + let sut = SUT::sample_strict_with_auth_signing(); sut.add_factor_source_to_primary_override( FactorSourceID::sample_device(), ); @@ -1333,7 +1462,7 @@ mod test_invalid { #[test] fn confirmation_role_must_have_at_least_one_factor() { - let sut = SUT::strict(); + let sut = SUT::sample_strict_with_auth_signing(); sut.add_factor_source_to_primary_override( FactorSourceID::sample_device(), ); @@ -1432,7 +1561,7 @@ mod test_invalid { #[test] fn number_of_auto_confirm_days_invalid() { let sut = valid(); - sut.set_number_of_days_until_auto_confirm(0); + sut.set_time_period_until_auto_confirm(TimePeriod::with_days(0)); assert_eq!( sut.validate().unwrap(), SecurityShieldBuilderInvalidReason::NumberOfDaysUntilAutoConfirmMustBeGreaterThanZero @@ -1441,7 +1570,7 @@ mod test_invalid { #[test] fn recovery_and_confirmation_factors_overlap() { - let sut = SUT::strict(); + let sut = SUT::sample_strict_with_auth_signing(); sut.add_factor_source_to_primary_override( FactorSourceID::sample_device(), ); @@ -1460,7 +1589,7 @@ mod test_invalid { #[test] fn single_factor_used_in_primary_must_not_be_used_in_any_other_role_in_recovery( ) { - let sut = SUT::strict(); + let sut = SUT::sample_strict_with_auth_signing(); let same = FactorSourceID::sample_ledger(); sut.add_factor_source_to_primary_override(same); @@ -1479,7 +1608,7 @@ mod test_invalid { #[test] fn single_factor_used_in_primary_must_not_be_used_in_any_other_role_in_confirmation( ) { - let sut = SUT::strict(); + let sut = SUT::sample_strict_with_auth_signing(); let same = FactorSourceID::sample_ledger(); sut.add_factor_source_to_primary_override(same); @@ -1498,7 +1627,7 @@ mod test_invalid { #[test] fn primary_role_with_password_in_threshold_list_must_threshold_greater_than_one( ) { - let sut = SUT::strict(); + let sut = SUT::sample_strict_with_auth_signing(); sut.add_factor_source_to_recovery_override( FactorSourceID::sample_ledger(), @@ -1527,7 +1656,7 @@ mod test_invalid { #[test] fn primary_role_with_password_in_threshold_list_must_have_another_factor() { - let sut = SUT::strict(); + let sut = SUT::sample_strict_with_auth_signing(); sut.add_factor_source_to_recovery_override( FactorSourceID::sample_ledger(), @@ -1553,7 +1682,7 @@ mod test_invalid { #[test] fn two_different_password_only_not_valid_for_primary() { - let sut = SUT::strict(); + let sut = SUT::sample_strict_with_auth_signing(); sut.add_factor_source_to_recovery_override( FactorSourceID::sample_ledger(), @@ -1578,7 +1707,7 @@ mod test_invalid { #[test] fn primary_role_with_password_in_override_does_not_get_added() { - let sut = SUT::strict(); + let sut = SUT::sample_strict_with_auth_signing(); sut.add_factor_source_to_recovery_override( FactorSourceID::sample_ledger(), diff --git a/crates/profile/models/security-structures/src/threshold.rs b/crates/profile/models/security-structures/src/threshold.rs index 8c67095a7..1769ebe8c 100644 --- a/crates/profile/models/security-structures/src/threshold.rs +++ b/crates/profile/models/security-structures/src/threshold.rs @@ -23,6 +23,13 @@ impl Threshold { Threshold::Specific(value) => *value, } } + + /// Returns the selectable values for a threshold. + pub fn values(max_threshold: u8) -> Vec { + std::iter::once(Threshold::All) + .chain((1..=max_threshold - 1).rev().map(Threshold::Specific)) + .collect() + } } impl HasSampleValues for Threshold { @@ -66,4 +73,10 @@ mod tests { assert_json_value_eq_after_roundtrip(&model, json!({"specific": 2})); assert_json_roundtrip(&model); } + + #[test] + fn values() { + let res = SUT::values(3); + assert_eq!(res, vec![SUT::All, SUT::Specific(2), SUT::Specific(1)]); + } } diff --git a/crates/profile/models/security-structures/src/time_period.rs b/crates/profile/models/security-structures/src/time_period.rs new file mode 100644 index 000000000..4da860f68 --- /dev/null +++ b/crates/profile/models/security-structures/src/time_period.rs @@ -0,0 +1,101 @@ +use crate::prelude::*; + +/// Time period expressed by a number of `TimePeriodUnit`. +/// +/// Used to represent in the hosts UI the time period until the recovery role is auto confirmed +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +pub struct TimePeriod { + pub value: u16, + pub unit: TimePeriodUnit, +} + +impl TimePeriod { + pub fn with_days(value: u16) -> Self { + if (value % DAYS_PER_YEAR) == 0 { + Self { + value: value / DAYS_PER_YEAR, + unit: TimePeriodUnit::Years, + } + } else if (value % DAYS_PER_WEEK) == 0 { + Self { + value: value / DAYS_PER_WEEK, + unit: TimePeriodUnit::Weeks, + } + } else { + Self { + value, + unit: TimePeriodUnit::Days, + } + } + } + + pub fn days(&self) -> u16 { + match self.unit { + TimePeriodUnit::Days => self.value, + TimePeriodUnit::Weeks => self.value * DAYS_PER_WEEK, + TimePeriodUnit::Years => self.value * DAYS_PER_YEAR, + } + } +} + +impl HasSampleValues for TimePeriod { + fn sample() -> Self { + Self { + value: 1, + unit: TimePeriodUnit::Days, + } + } + + fn sample_other() -> Self { + Self { + value: 1, + unit: TimePeriodUnit::Weeks, + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[allow(clippy::upper_case_acronyms)] + type SUT = TimePeriod; + + #[test] + fn equality() { + assert_eq!(SUT::sample(), SUT::sample()); + assert_eq!(SUT::sample_other(), SUT::sample_other()); + } + + #[test] + fn inequality() { + assert_ne!(SUT::sample(), SUT::sample_other()); + } + + #[test] + fn days_conversion() { + let mut sut = SUT::with_days(DAYS_PER_YEAR); + assert_eq!(sut.days(), DAYS_PER_YEAR); + assert_eq!(sut.value, 1); + assert_eq!(sut.unit, TimePeriodUnit::Years); + + sut = SUT::with_days(1095); + assert_eq!(sut.days(), 1095); + assert_eq!(sut.value, 3); + assert_eq!(sut.unit, TimePeriodUnit::Years); + + sut = SUT::with_days(DAYS_PER_WEEK); + assert_eq!(sut.days(), DAYS_PER_WEEK); + assert_eq!(sut.value, 1); + assert_eq!(sut.unit, TimePeriodUnit::Weeks); + + sut = SUT::with_days(14); + assert_eq!(sut.days(), 14); + assert_eq!(sut.value, 2); + assert_eq!(sut.unit, TimePeriodUnit::Weeks); + + sut = SUT::with_days(400); + assert_eq!(sut.days(), 400); + assert_eq!(sut.unit, TimePeriodUnit::Days); + } +} diff --git a/crates/profile/models/security-structures/src/time_period_unit.rs b/crates/profile/models/security-structures/src/time_period_unit.rs new file mode 100644 index 000000000..12d34d177 --- /dev/null +++ b/crates/profile/models/security-structures/src/time_period_unit.rs @@ -0,0 +1,40 @@ +use crate::prelude::*; + +/// Time period unit expressed in days, weeks, or years. +/// +/// Used to represent in the hosts UI the time period. +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +pub enum TimePeriodUnit { + Days, + Weeks, + Years, +} + +impl HasSampleValues for TimePeriodUnit { + fn sample() -> Self { + TimePeriodUnit::Days + } + + fn sample_other() -> Self { + TimePeriodUnit::Weeks + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[allow(clippy::upper_case_acronyms)] + type SUT = TimePeriodUnit; + + #[test] + fn equality() { + assert_eq!(SUT::sample(), SUT::sample()); + assert_eq!(SUT::sample_other(), SUT::sample_other()); + } + + #[test] + fn inequality() { + assert_ne!(SUT::sample(), SUT::sample_other()); + } +} diff --git a/crates/profile/models/supporting-types/Cargo.toml b/crates/profile/models/supporting-types/Cargo.toml index c0b5e2f3b..1cb0e1a82 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/profile/traits/entity-by-address/Cargo.toml b/crates/profile/traits/entity-by-address/Cargo.toml index 2ba0ce9d1..1f16243d1 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/sargon/Cargo.toml b/crates/sargon/Cargo.toml index fce87e3cc..bc2b3c50f 100644 --- a/crates/sargon/Cargo.toml +++ b/crates/sargon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon" -version = "1.1.108" +version = "1.1.109" edition = "2021" resolver = "2" # features enabled in integration test diff --git a/crates/system/clients/clients/Cargo.toml b/crates/system/clients/clients/Cargo.toml index 977ea07d8..5ba87a935 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.108" +version = "1.1.109" edition = "2021" diff --git a/crates/system/clients/http/Cargo.toml b/crates/system/clients/http/Cargo.toml index 2c25da6ff..554d44487 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/system/drivers/Cargo.toml b/crates/system/drivers/Cargo.toml index 501f21004..02223b3fa 100644 --- a/crates/system/drivers/Cargo.toml +++ b/crates/system/drivers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "drivers" -version = "1.1.108" +version = "1.1.109" edition = "2021" diff --git a/crates/system/interactors/Cargo.toml b/crates/system/interactors/Cargo.toml index c76154bb5..ea1aadda9 100644 --- a/crates/system/interactors/Cargo.toml +++ b/crates/system/interactors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "interactors" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/system/os/accounts/Cargo.toml b/crates/system/os/accounts/Cargo.toml index 576bbf9c9..b76228f0e 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/system/os/factors/Cargo.toml b/crates/system/os/factors/Cargo.toml index a7c404495..41902cf64 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/system/os/os/Cargo.toml b/crates/system/os/os/Cargo.toml index 0308b3f69..237727799 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/system/os/security-center/Cargo.toml b/crates/system/os/security-center/Cargo.toml index 91b25a63f..f22c97bc4 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/system/os/signing/Cargo.toml b/crates/system/os/signing/Cargo.toml index 290ba56fb..20997dce5 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/system/os/transaction/Cargo.toml b/crates/system/os/transaction/Cargo.toml index cd2a8152b..72a8bebcd 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/system/profile-state-holder/Cargo.toml b/crates/system/profile-state-holder/Cargo.toml index 3754b0f80..15f2fb773 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/system/sub-systems/Cargo.toml b/crates/system/sub-systems/Cargo.toml index e02852d6b..c0ae6a562 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/transaction/foundation/Cargo.toml b/crates/transaction/foundation/Cargo.toml index a158f7040..88d4cd4f0 100644 --- a/crates/transaction/foundation/Cargo.toml +++ b/crates/transaction/foundation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "transaction-foundation" -version = "1.1.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/transaction/manifests/Cargo.toml b/crates/transaction/manifests/Cargo.toml index b83378e84..eed2e777e 100644 --- a/crates/transaction/manifests/Cargo.toml +++ b/crates/transaction/manifests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "manifests" -version = "1.1.108" +version = "1.1.109" edition = "2021" diff --git a/crates/transaction/models/Cargo.toml b/crates/transaction/models/Cargo.toml index 07f84356c..1a17a804b 100644 --- a/crates/transaction/models/Cargo.toml +++ b/crates/transaction/models/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "transaction-models" -version = "1.1.108" +version = "1.1.109" edition = "2021" diff --git a/crates/uniffi/conversion-macros/Cargo.toml b/crates/uniffi/conversion-macros/Cargo.toml index 6f4bb83bf..b33a3fe17 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.108" +version = "1.1.109" edition = "2021" [dependencies] diff --git a/crates/uniffi/uniffi_SPLIT_ME/Cargo.toml b/crates/uniffi/uniffi_SPLIT_ME/Cargo.toml index db1311fee..4530d83a8 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.108" +version = "1.1.109" edition = "2021" build = "build.rs" diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/core/utils/constants.rs b/crates/uniffi/uniffi_SPLIT_ME/src/core/utils/constants.rs index 7e9177d8d..8b90f051a 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/core/utils/constants.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/core/utils/constants.rs @@ -1,9 +1,19 @@ #[uniffi::export] -pub fn constant_entity_name_max_length() -> u64 { +pub fn constant_display_name_max_length() -> u64 { sargon::DisplayName::MAX_LEN as u64 } +#[uniffi::export] +pub fn constant_entity_name_max_length() -> u64 { + constant_display_name_max_length() +} + #[uniffi::export] pub fn constant_min_required_xrd_for_account_deletion() -> f64 { sargon::MIN_REQUIRED_XRD_FOR_ACCOUNT_DELETION } + +#[uniffi::export] +pub fn constant_max_recovery_confirmation_fallback_period_units() -> u16 { + sargon::SecurityShieldBuilder::MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS +} diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/mod.rs b/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/mod.rs index 678a68a1d..9a17af6b0 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/mod.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/mod.rs @@ -2,8 +2,12 @@ mod factor_list_kind; mod factor_source_in_role_builder_validation_status; mod role_kind; mod threshold; +mod time_period; +mod time_period_unit; pub use factor_list_kind::*; pub use factor_source_in_role_builder_validation_status::*; pub use role_kind::*; pub use threshold::*; +pub use time_period::*; +pub use time_period_unit::*; diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/threshold.rs b/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/threshold.rs index 175e4dc63..c549a3655 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/threshold.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/threshold.rs @@ -12,3 +12,13 @@ pub enum Threshold { /// A specific number of factors in the threshold factors list must be used to perform some function with Specific(u8), } + +#[uniffi::export] +pub fn new_threshold_sample() -> Threshold { + InternalThreshold::sample().into() +} + +#[uniffi::export] +pub fn new_threshold_sample_other() -> Threshold { + InternalThreshold::sample_other().into() +} diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/time_period.rs b/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/time_period.rs new file mode 100644 index 000000000..2a249fb4d --- /dev/null +++ b/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/time_period.rs @@ -0,0 +1,33 @@ +use crate::prelude::*; +use sargon::TimePeriod as InternalTimePeriod; + +/// Time period unit expressed in days, weeks, or years. +/// +/// Used to represent in the hosts UI the time period. +#[derive(Clone, PartialEq, Eq, Hash, InternalConversion, uniffi::Record)] +pub struct TimePeriod { + /// The value of the time period. + pub value: u16, + /// The unit of the time period. + pub unit: TimePeriodUnit, +} + +#[uniffi::export] +pub fn new_time_period_sample() -> TimePeriod { + InternalTimePeriod::sample().into() +} + +#[uniffi::export] +pub fn new_time_period_sample_other() -> TimePeriod { + InternalTimePeriod::sample_other().into() +} + +#[uniffi::export] +pub fn new_time_period_with_days(value: u16) -> TimePeriod { + InternalTimePeriod::with_days(value).into() +} + +#[uniffi::export] +pub fn time_period_to_days(time_period: &TimePeriod) -> u16 { + time_period.into_internal().days() +} diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/time_period_unit.rs b/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/time_period_unit.rs new file mode 100644 index 000000000..7a91bd6a1 --- /dev/null +++ b/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/models/time_period_unit.rs @@ -0,0 +1,13 @@ +use crate::prelude::*; +use sargon::TimePeriodUnit as InternalTimePeriodUnit; + +/// A unit for the emergency fallback period. +/// Primarily used by hosts for UI representation. +#[derive( + Clone, Copy, Debug, PartialEq, Eq, Hash, InternalConversion, uniffi::Enum, +)] +pub enum TimePeriodUnit { + Days, + Weeks, + Years, +} diff --git a/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/security_shield_builder.rs b/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/security_shield_builder.rs index bb7ee8895..d1378597b 100644 --- a/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/security_shield_builder.rs +++ b/crates/uniffi/uniffi_SPLIT_ME/src/profile/mfa/security_structures/security_shield_builder.rs @@ -2,12 +2,11 @@ #![allow(dead_code)] #![allow(unused_variables)] +use crate::prelude::*; #[cfg(test)] use sargon::FactorSourceWithExtraSampleValues; use std::{borrow::Borrow, sync::Arc}; -use crate::prelude::*; - /// A builder of `SecurityStructureOfFactorSourceIds` a.k.a. `SecurityShield`, /// which contains a MatrixOfFactorSourceIds - with primary, recovery, and /// confirmation roles. @@ -92,12 +91,20 @@ impl SecurityShieldBuilder { // ==================== #[uniffi::export] impl SecurityShieldBuilder { - pub fn get_primary_threshold(&self) -> u8 { - self.get(|builder| builder.get_threshold()) + pub fn get_primary_threshold(&self) -> Threshold { + self.get(|builder| builder.get_threshold()).into() } - pub fn get_number_of_days_until_auto_confirm(&self) -> u16 { - self.get(|builder| builder.get_number_of_days_until_auto_confirm()) + pub fn get_primary_threshold_values(&self) -> Vec { + self.get(|builder| builder.get_threshold_values()) + .into_iter() + .map(|threshold| threshold.into()) + .collect() + } + + pub fn get_time_period_until_auto_confirm(&self) -> TimePeriod { + self.get(|builder| builder.get_time_period_until_auto_confirm()) + .into() } pub fn get_name(&self) -> String { @@ -169,6 +176,12 @@ impl SecurityShieldBuilder { }) } + pub fn remove_all_factors_from_primary_override( + self: Arc, + ) -> Arc { + self.set(|builder| builder.remove_all_factors_from_primary_override()) + } + pub fn remove_factor_from_recovery( self: Arc, factor_source_id: FactorSourceID, @@ -193,12 +206,13 @@ impl SecurityShieldBuilder { self.set(|builder| builder.set_threshold(threshold.into())) } - pub fn set_number_of_days_until_auto_confirm( + pub fn set_time_period_until_auto_confirm( self: Arc, - number_of_days: u16, + time_period: TimePeriod, ) -> Arc { self.set(|builder| { - builder.set_number_of_days_until_auto_confirm(number_of_days) + builder + .set_time_period_until_auto_confirm(time_period.clone().into()) }) } @@ -622,10 +636,19 @@ mod tests { assert_eq!(sut.clone().get_name(), "My Shield"); sut = sut.set_name("S.H.I.E.L.D.".to_owned()); - assert_eq!(sut.clone().get_number_of_days_until_auto_confirm(), 14); - sut = sut.set_number_of_days_until_auto_confirm(u16::MAX); assert_eq!( - sut.clone().get_number_of_days_until_auto_confirm(), + time_period_to_days( + &sut.clone().get_time_period_until_auto_confirm() + ), + 14 + ); + sut = sut.set_time_period_until_auto_confirm( + new_time_period_with_days(u16::MAX), + ); + assert_eq!( + time_period_to_days( + &sut.clone().get_time_period_until_auto_confirm() + ), u16::MAX ); // Primary @@ -654,16 +677,18 @@ mod tests { // Threshold increases when adding a factor, because it's being set to All by default sut = sut.add_factor_source_to_primary_threshold( - // should bump threshold to 1 FactorSourceID::sample_device(), ); - assert_eq!(sut.clone().get_primary_threshold(), 1); + assert_eq!(sut.clone().get_primary_threshold(), Threshold::All); sut = sut.add_factor_source_to_primary_threshold( - // should bump threshold to 2 FactorSourceID::sample_password_other(), ); - assert_eq!(sut.clone().get_primary_threshold(), 2); + assert_eq!(sut.clone().get_primary_threshold(), Threshold::All); + assert_eq!( + sut.clone().get_primary_threshold_values(), + vec![Threshold::All, Threshold::Specific(1)] + ); sut = sut .remove_factor_from_primary( @@ -679,16 +704,15 @@ mod tests { sut = sut.set_threshold(Threshold::Specific(1)); sut = sut.add_factor_source_to_primary_threshold( - // should also bump threshold to 1 FactorSourceID::sample_device(), ); - assert_eq!(sut.clone().get_primary_threshold(), 1); + assert_eq!(sut.clone().get_primary_threshold(), Threshold::Specific(1)); sut = sut.add_factor_source_to_primary_threshold( // should NOT bump threshold FactorSourceID::sample_password_other(), ); - assert_eq!(sut.clone().get_primary_threshold(), 1); + assert_eq!(sut.clone().get_primary_threshold(), Threshold::Specific(1)); sut = sut.remove_factor_from_primary( FactorSourceID::sample_password_other(), FactorListKind::Threshold, @@ -714,6 +738,17 @@ mod tests { ] ); + sut = sut.remove_all_factors_from_primary_override(); + assert!(sut.clone().get_primary_override_factors().is_empty()); + + sut = sut + .add_factor_source_to_primary_override( + FactorSourceID::sample_arculus(), + ) + .add_factor_source_to_primary_override( + FactorSourceID::sample_arculus_other(), + ); + // Recovery let sim_rec = sut.clone().validation_for_addition_of_factor_source_to_recovery_override_for_each(vec![ @@ -926,7 +961,9 @@ mod tests { let days_to_auto_confirm = 237; sut = sut .set_name(name.to_owned()) - .set_number_of_days_until_auto_confirm(days_to_auto_confirm) + .set_time_period_until_auto_confirm( + new_time_period_with_days(days_to_auto_confirm).into(), + ) .add_factor_source_to_primary_threshold( FactorSource::sample_device_babylon().id(), ) diff --git a/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/SharedConstants.kt b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/SharedConstants.kt index 2a9362e34..6aeaccd2b 100644 --- a/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/SharedConstants.kt +++ b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/SharedConstants.kt @@ -1,20 +1,29 @@ package com.radixdlt.sargon.extensions import com.radixdlt.sargon.Account +import com.radixdlt.sargon.DisplayName import com.radixdlt.sargon.Persona import com.radixdlt.sargon.annotation.KoverIgnore +import com.radixdlt.sargon.constantDisplayNameMaxLength import com.radixdlt.sargon.constantEntityNameMaxLength import com.radixdlt.sargon.constantMinRequiredXrdForAccountDeletion +import com.radixdlt.sargon.extensions.SharedConstants.displayNameMaxLength +import com.radixdlt.sargon.extensions.SharedConstants.entityNameMaxLength @KoverIgnore object SharedConstants { val minRequiredXrdForAccountDeletion = constantMinRequiredXrdForAccountDeletion() + val entityNameMaxLength = constantEntityNameMaxLength().toLong() + val displayNameMaxLength = constantDisplayNameMaxLength().toLong() } @KoverIgnore val Account.Companion.nameMaxLength: Long - get() = constantEntityNameMaxLength().toLong() + get() = entityNameMaxLength @KoverIgnore val Persona.Companion.nameMaxLength: Long - get() = constantEntityNameMaxLength().toLong() \ No newline at end of file + get() = entityNameMaxLength + +val DisplayName.Companion.maxLength: Long + get() = displayNameMaxLength \ No newline at end of file diff --git a/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/TimePeriod.kt b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/TimePeriod.kt new file mode 100644 index 000000000..5ce9be8e2 --- /dev/null +++ b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/TimePeriod.kt @@ -0,0 +1,10 @@ +package com.radixdlt.sargon.extensions + +import com.radixdlt.sargon.TimePeriod +import com.radixdlt.sargon.newTimePeriodWithDays +import com.radixdlt.sargon.timePeriodToDays + +fun TimePeriod.Companion.init(days: Int): TimePeriod = newTimePeriodWithDays(days.toUShort()) + +val TimePeriod.days + get() = timePeriodToDays(this).toInt() \ No newline at end of file diff --git a/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/TimePeriodUnit.kt b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/TimePeriodUnit.kt new file mode 100644 index 000000000..77a8c2aee --- /dev/null +++ b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/TimePeriodUnit.kt @@ -0,0 +1,7 @@ +package com.radixdlt.sargon.extensions + +import com.radixdlt.sargon.TimePeriodUnit +import com.radixdlt.sargon.constantMaxRecoveryConfirmationFallbackPeriodUnits + +val TimePeriodUnit.values + get() = (1..constantMaxRecoveryConfirmationFallbackPeriodUnits().toInt()).toList() \ No newline at end of file diff --git a/jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/ThresholdSample.kt b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/ThresholdSample.kt new file mode 100644 index 000000000..f3fa7cbf1 --- /dev/null +++ b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/ThresholdSample.kt @@ -0,0 +1,14 @@ +package com.radixdlt.sargon.samples + +import com.radixdlt.sargon.Threshold +import com.radixdlt.sargon.annotation.UsesSampleValues +import com.radixdlt.sargon.newThresholdSample +import com.radixdlt.sargon.newThresholdSampleOther + +@UsesSampleValues +val Threshold.Companion.sample: Sample + get() = object : Sample { + override fun invoke(): Threshold = newThresholdSample() + + override fun other(): Threshold = newThresholdSampleOther() + } \ No newline at end of file diff --git a/jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/TimePeriodSample.kt b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/TimePeriodSample.kt new file mode 100644 index 000000000..984d01745 --- /dev/null +++ b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/TimePeriodSample.kt @@ -0,0 +1,14 @@ +package com.radixdlt.sargon.samples + +import com.radixdlt.sargon.TimePeriod +import com.radixdlt.sargon.annotation.UsesSampleValues +import com.radixdlt.sargon.newTimePeriodSample +import com.radixdlt.sargon.newTimePeriodSampleOther + +@UsesSampleValues +val TimePeriod.Companion.sample: Sample + get() = object : Sample { + override fun invoke(): TimePeriod = newTimePeriodSample() + + override fun other(): TimePeriod = newTimePeriodSampleOther() + } \ No newline at end of file diff --git a/jvm/sargon-android/src/test/java/com/radixdlt/sargon/ThresholdTest.kt b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/ThresholdTest.kt new file mode 100644 index 000000000..ebd03b2ef --- /dev/null +++ b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/ThresholdTest.kt @@ -0,0 +1,10 @@ +package com.radixdlt.sargon + +import com.radixdlt.sargon.samples.Sample +import com.radixdlt.sargon.samples.sample + +class ThresholdTest: SampleTestable { + + override val samples: List> + get() = listOf(Threshold.sample) +} \ No newline at end of file diff --git a/jvm/sargon-android/src/test/java/com/radixdlt/sargon/TimePeriodTest.kt b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/TimePeriodTest.kt new file mode 100644 index 000000000..56f953e31 --- /dev/null +++ b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/TimePeriodTest.kt @@ -0,0 +1,26 @@ +package com.radixdlt.sargon + +import com.radixdlt.sargon.extensions.days +import com.radixdlt.sargon.extensions.init +import com.radixdlt.sargon.samples.Sample +import com.radixdlt.sargon.samples.sample +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class TimePeriodTest: SampleTestable { + + override val samples: List> + get() = listOf(TimePeriod.sample) + + @Test + fun test() { + assertEquals( + TimePeriod.init(1), + TimePeriod.sample() + ) + assertEquals( + TimePeriod.init(5).days, + 5 + ) + } +} \ No newline at end of file diff --git a/jvm/sargon-android/src/test/java/com/radixdlt/sargon/TimePeriodUnitTest.kt b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/TimePeriodUnitTest.kt new file mode 100644 index 000000000..433f3f74a --- /dev/null +++ b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/TimePeriodUnitTest.kt @@ -0,0 +1,13 @@ +package com.radixdlt.sargon + +import com.radixdlt.sargon.extensions.values +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class TimePeriodUnitTest { + + @Test + fun test() { + assertEquals(TimePeriodUnit.DAYS.values, (1..9999).toList()) + } +} \ No newline at end of file