-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] ABW-2121 Save accounts needing recovery in UserDefaults #685
Merged
CyonAlexRDX
merged 100 commits into
main
from
ABW-2121_accounts_needing_recovery_in_UserDefaults
Sep 4, 2023
Merged
Changes from all commits
Commits
Show all changes
100 commits
Select commit
Hold shift + click to select a range
8f03e1a
Versioning of SecurityQuestionsFactorSource SealedMnemonic
CyonAlexRDX 5d53cba
wip
CyonAlexRDX bcb9b3c
Merge branch 'main' into ABW-1674_import_export_profile_as_file_w_enc…
CyonAlexRDX 9a84b39
WIP
CyonAlexRDX 40485fe
WIP
CyonAlexRDX 2cd7e17
WIP
CyonAlexRDX 70fba81
WIP
CyonAlexRDX 1c5d309
WIP
CyonAlexRDX 5eea02a
WIP
CyonAlexRDX a3b169e
WIP
CyonAlexRDX 195efb3
WIP
CyonAlexRDX ce2a1b2
WIP
CyonAlexRDX 3bd771e
WIP
CyonAlexRDX 2a44945
WIP
CyonAlexRDX f5573aa
WIP
CyonAlexRDX 1aac7be
WIP
CyonAlexRDX e37e9e5
WIP
CyonAlexRDX 4076cc1
WIP
CyonAlexRDX 53e0241
WIP
CyonAlexRDX 1190d78
WIP
CyonAlexRDX a9357ac
WIP
CyonAlexRDX 8002ac9
WIP
CyonAlexRDX 22d4898
WIP
CyonAlexRDX 0341f99
WIP
CyonAlexRDX 40c6f8d
WIP
CyonAlexRDX 14fb993
WIP
CyonAlexRDX 416aeac
WIP
CyonAlexRDX 5648282
WIP
CyonAlexRDX 61d8d97
WIP
CyonAlexRDX 9c85639
WIP
CyonAlexRDX 6b1b81e
Merge branch 'main' into ABW-1674_import_export_profile_as_file_w_enc…
CyonAlexRDX 559954c
WIP
CyonAlexRDX 94905d2
WIP
CyonAlexRDX e5ed61a
WIP
CyonAlexRDX 3a8028a
WIP
CyonAlexRDX 4ca3eee
WIP
CyonAlexRDX 6d77cf5
WIP
CyonAlexRDX 8b0f73c
WIP
CyonAlexRDX 49e18c3
WIP
CyonAlexRDX f313a53
WIP
CyonAlexRDX d72aada
WIP
CyonAlexRDX 0072337
WIP
CyonAlexRDX bb484b8
WIP
CyonAlexRDX b322e35
WIP
CyonAlexRDX 57e4759
WIP
CyonAlexRDX e3bd635
WIP
CyonAlexRDX 073c292
WIP
CyonAlexRDX d583ad3
WIP
CyonAlexRDX e0f0f57
WIP
CyonAlexRDX ff105eb
WIP
CyonAlexRDX 8ca6aff
WIP
CyonAlexRDX 3db69e6
WIP
CyonAlexRDX 10ac8bf
WIP
CyonAlexRDX a15cdd5
WIP
CyonAlexRDX cb28994
WIP
CyonAlexRDX 89d951d
WIP
CyonAlexRDX 2c1bef4
WIP
CyonAlexRDX 77d521b
Review fix
CyonAlexRDX def2a55
Review fix2
CyonAlexRDX a25bfa3
Review fix3
CyonAlexRDX 81616ac
not destructive button roles for encrypt dialog
CyonAlexRDX 4b0708b
WIP
CyonAlexRDX 7622f58
Important bug fix for Import Olympia and add methods in userdefaults …
CyonAlexRDX 371aa8f
Merge branch 'main' into ABW-1674_import_export_profile_as_file_w_enc…
CyonAlexRDX 4e6b346
WIP
CyonAlexRDX 49845f1
WIP
CyonAlexRDX 1584e4f
Merge branch 'ABW-1674_import_export_profile_as_file_w_encryption' in…
CyonAlexRDX 8b81655
merge
CyonAlexRDX 1ec156f
WIP
CyonAlexRDX a690958
WIP
CyonAlexRDX 2013da8
WIP
CyonAlexRDX b18ef74
WIP
CyonAlexRDX c4c488d
WIP
CyonAlexRDX 7d5852b
WIP
CyonAlexRDX ef57969
WIP
CyonAlexRDX e5af536
WIP
CyonAlexRDX 2c097cf
WIP
CyonAlexRDX c3ea819
WIP
CyonAlexRDX 3f80392
WIP
CyonAlexRDX 89cda5e
WIP
CyonAlexRDX 431c5e4
WIP
CyonAlexRDX 75d4410
WIP
CyonAlexRDX 3c14dee
WIP
CyonAlexRDX f3cb6f4
WIP
CyonAlexRDX 31c36ca
WIP
CyonAlexRDX b1ef3e2
WIP
CyonAlexRDX 2205361
Merge branch 'main' into ABW-2121_accounts_needing_recovery_in_UserDe…
CyonAlexRDX b500287
display BIP39 Passphrase in readonly mode if it is not empty, always,
CyonAlexRDX 40b162c
Merge branch 'main' into ABW-2121_accounts_needing_recovery_in_UserDe…
CyonAlexRDX b90f40c
fix bug
CyonAlexRDX 01b19a2
Merge branch 'main' into ABW-2121_accounts_needing_recovery_in_UserDe…
CyonAlexRDX c737bef
commit package resolved
CyonAlexRDX 7841024
Merge branch 'main' into ABW-2121_accounts_needing_recovery_in_UserDe…
CyonAlexRDX b75e2a4
WIP
CyonAlexRDX e5b1f4b
Merge branch 'main' into ABW-2121_accounts_needing_recovery_in_UserDe…
CyonAlexRDX d26e72b
fix presentation bug
CyonAlexRDX 8c5bc02
update account details UI regarding prompts
CyonAlexRDX d423010
fix PR comments
CyonAlexRDX 16e55ed
merge
CyonAlexRDX 776a42c
merge
CyonAlexRDX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ extension FactorSourcesClient { | |
public typealias GetFactorSources = @Sendable () async throws -> FactorSources | ||
public typealias FactorSourcesAsyncSequence = @Sendable () async -> AnyAsyncSequence<FactorSources> | ||
public typealias AddPrivateHDFactorSource = @Sendable (AddPrivateHDFactorSourceRequest) async throws -> FactorSourceID | ||
public typealias CheckIfHasOlympiaFactorSourceForAccounts = @Sendable (NonEmpty<OrderedSet<OlympiaAccountToMigrate>>) async -> FactorSourceID.FromHash? | ||
public typealias CheckIfHasOlympiaFactorSourceForAccounts = @Sendable (BIP39.WordCount, NonEmpty<OrderedSet<OlympiaAccountToMigrate>>) async -> FactorSourceID.FromHash? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wordcount is now part of the FactorSourceID so can be used to filter |
||
public typealias SaveFactorSource = @Sendable (FactorSource) async throws -> Void | ||
public typealias UpdateFactorSource = @Sendable (FactorSource) async throws -> Void | ||
public typealias GetSigningFactors = @Sendable (GetSigningFactorsRequest) async throws -> SigningFactors | ||
|
@@ -257,10 +257,7 @@ extension MnemonicWithPassphrase { | |
) throws -> Bool { | ||
let hdRoot = try self.hdRoot() | ||
|
||
for account in accounts { | ||
let path = account.0 | ||
let publicKey = account.1 | ||
|
||
for (path, publicKey) in accounts { | ||
let derivedPublicKey: SLIP10.PublicKey = try { | ||
switch publicKey.curve { | ||
case .secp256k1: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,28 +66,38 @@ extension FactorSourcesClient: DependencyKey { | |
|
||
return factorSourceID | ||
}, | ||
checkIfHasOlympiaFactorSourceForAccounts: { softwareAccounts -> FactorSourceID.FromHash? in | ||
checkIfHasOlympiaFactorSourceForAccounts: { wordCount, softwareAccounts -> FactorSourceID.FromHash? in | ||
guard softwareAccounts.allSatisfy({ $0.accountType == .software }) else { | ||
assertionFailure("Unexpectedly received hardware account, unable to verify.") | ||
return nil | ||
} | ||
do { | ||
// Might be empty, if it is, we will just return nil (for-loop below not run). | ||
let factorSourceIDs = try await getFactorSources() | ||
let olympiaDeviceFactorSources: [DeviceFactorSource] = try await getFactorSources() | ||
.filter(\.supportsOlympia) | ||
.filter { $0.kind == .device } | ||
.map(\.id) | ||
.compactMap { | ||
guard | ||
let deviceFactorSource = try? $0.extract(as: DeviceFactorSource.self), | ||
deviceFactorSource.hint.mnemonicWordCount == wordCount | ||
else { | ||
return nil | ||
} | ||
return deviceFactorSource | ||
} | ||
|
||
let factorSourceIDs = olympiaDeviceFactorSources.map(\.id) | ||
|
||
for factorSourceID in factorSourceIDs { | ||
guard let mnemonic = try await secureStorageClient.loadMnemonicByFactorSourceID(factorSourceID, .importOlympiaAccounts) else { | ||
guard let mnemonic = try await secureStorageClient.loadMnemonicByFactorSourceID(factorSourceID.embed(), .importOlympiaAccounts) else { | ||
continue | ||
} | ||
guard try mnemonic.validatePublicKeys(of: softwareAccounts) else { | ||
guard (try? mnemonic.validatePublicKeys(of: softwareAccounts)) == true else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. important bug fix solving validation of accounts when user has multiple mnemonics |
||
continue | ||
} | ||
// YES Managed to validate all software accounts against existing factor source | ||
loggerGlobal.debug("Existing factor source found for selected Olympia software accounts.") | ||
return factorSourceID.extract(FactorSourceID.FromHash.self) | ||
return factorSourceID | ||
} | ||
|
||
return nil // Did not find any Olympia `.device` factor sources | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Sources/Core/FeaturePrelude/UserDefaultsClient+AccountRecovery.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import EngineKit // AccountAddress | ||
import Prelude // UserDefaultsClient | ||
import Profile | ||
|
||
extension UserDefaultsClient { | ||
public func addAccountsThatNeedRecovery(accounts new: OrderedSet<AccountAddress>) async throws { | ||
var accounts = getAddressesOfAccountsThatNeedRecovery() | ||
accounts.append(contentsOf: new) | ||
try await save(codable: accounts, forKey: .accountsThatNeedRecovery) | ||
} | ||
|
||
public func removeFromListOfAccountsThatNeedRecovery(accounts toRemove: OrderedSet<AccountAddress>) async throws { | ||
var accounts = getAddressesOfAccountsThatNeedRecovery() | ||
accounts.subtract(toRemove) | ||
try await save(codable: accounts, forKey: .accountsThatNeedRecovery) | ||
} | ||
|
||
public func getAddressesOfAccountsThatNeedRecovery() -> OrderedSet<AccountAddress> { | ||
(try? loadCodable(key: .accountsThatNeedRecovery)) ?? OrderedSet<AccountAddress>() | ||
} | ||
|
||
public func removeAccountsThatNeedRecovery() async { | ||
await setData(nil, .accountsThatNeedRecovery) | ||
} | ||
} | ||
|
||
extension UserDefaultsClient { | ||
public func addFactorSourceIDOfBackedUpMnemonic(_ factorSourceID: FactorSourceID.FromHash) async throws { | ||
var ids = getFactorSourceIDOfBackedUpMnemonics() | ||
ids.append(factorSourceID) | ||
try await save(codable: ids, forKey: .mnemonicsUserClaimsToHaveBackedUp) | ||
} | ||
|
||
public func getFactorSourceIDOfBackedUpMnemonics() -> OrderedSet<FactorSourceID.FromHash> { | ||
(try? loadCodable(key: .mnemonicsUserClaimsToHaveBackedUp)) ?? OrderedSet<FactorSourceID.FromHash>() | ||
} | ||
|
||
public func removeAllFactorSourceIDsOfBackedUpMnemonics() async { | ||
await setData(nil, .mnemonicsUserClaimsToHaveBackedUp) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sort alphabetically