-
Notifications
You must be signed in to change notification settings - Fork 8
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
Adapt wallet to the changes on HDPathComponent
#1225
Conversation
@@ -98,19 +99,19 @@ sealed interface AccessFactorSourcesInput { | |||
|
|||
val factorSource: FactorSource | |||
val isForLegacyOlympia: Boolean | |||
val nextDerivationPathOffset: UInt // is used as pointer when user clicks "scan the next 50" | |||
val nextDerivationPathIndex: HdPathComponent // is used as pointer when user clicks "scan the next 50" |
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.
Wrapped the value with HdPathComponent
. A simple UInt
has no meaning with no context. We need to know if this index is calculated in the local key space or in the global.
@@ -180,7 +186,7 @@ class DeriveAccountsViewModel @Inject constructor( | |||
accessFactorSourcesIOHandler.setOutput( | |||
output = AccessFactorSourcesOutput.DerivedAccountsWithNextDerivationPath( | |||
derivedAccounts = derivedAccounts, | |||
nextDerivationPathOffset = indicesToScan.last() + 1u | |||
nextDerivationPathIndex = HdPathComponent.init(indicesToScan.last().indexInGlobalKeySpace + 1u) |
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.
Next value is derived from the previous one + 1.
val Persona.derivationPathEntityIndex: HDPathValue | ||
get() = securityState.transactionSigningFactorInstance.publicKey.derivationPath.nonHardenedIndex | ||
val Persona.derivationPathEntityIndex: HdPathComponent | ||
get() = securityState.transactionSigningFactorInstance.publicKey.derivationPath.path.components.last() |
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.
last()
should never throw since we don't allow empty derivation path component array.
} else { | ||
accountsControlledByFactorSource.maxOf { it.derivationPathEntityIndex } + 1u | ||
val global = accountsControlledByFactorSource.maxOf { it.derivationPathEntityIndex.indexInGlobalKeySpace } + 1u |
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.
The next is the max of all the keys in global key space for simplicity.
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.
we note that this code is obsolete very soon, made obsolete by FactorInstancesProvider in Sargon (soon to be migrated into Sargon from Sargon-MFA. radixdlt/sargon-mfa#18 )
} | ||
?.toSet().orEmpty() | ||
|
||
val indicesToScan = mutableSetOf<HDPathValue>() | ||
val startIndex = nextDerivationPathOffset | ||
val indicesToScan = LinkedHashSet<HdPathComponent>() |
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.
Later in code we use the last()
method. Sets
don't keep the insertion order, but LinkedHashSet
s do. Better to keep the new indices in a set that retains the insertion order.
...on/wallet/android/presentation/accessfactorsources/deriveaccounts/DeriveAccountsViewModel.kt
Outdated
Show resolved
Hide resolved
...on/wallet/android/presentation/accessfactorsources/deriveaccounts/DeriveAccountsViewModel.kt
Outdated
Show resolved
Hide resolved
@@ -180,7 +186,7 @@ class DeriveAccountsViewModel @Inject constructor( | |||
accessFactorSourcesIOHandler.setOutput( | |||
output = AccessFactorSourcesOutput.DerivedAccountsWithNextDerivationPath( | |||
derivedAccounts = derivedAccounts, | |||
nextDerivationPathOffset = indicesToScan.last() + 1u | |||
nextDerivationPathIndex = HdPathComponent.init(globalKeySpace = indicesToScan.last().indexInGlobalKeySpace + 1u) |
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.
Here and...
@@ -206,15 +212,15 @@ class DeriveAccountsViewModel @Inject constructor( | |||
accessFactorSourcesIOHandler.setOutput( | |||
output = AccessFactorSourcesOutput.DerivedAccountsWithNextDerivationPath( | |||
derivedAccounts = derivedAccounts, | |||
nextDerivationPathOffset = indicesToScan.last() + 1u | |||
nextDerivationPathIndex = HdPathComponent.init(globalKeySpace = indicesToScan.last().indexInGlobalKeySpace + 1u) |
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.
... also here last()
was used. That is why I think LinkedHashSet
should be used.
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.
LGTM
|
Description
For more information about sargon's changes take a look at this PR.
In general a simple
HDPathValue
is no more. Values have been scoped so we can differentiate between them.Key areas that are affected:
(1) Calculating the next derivation path of a new entity when creating it.
(2) Rederiving public keys when doing the account recovery scan
(3) Importing from legacy wallet
(4) Creating auth-signing derivation paths from transaction signing.
How to test