-
Notifications
You must be signed in to change notification settings - Fork 169
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
feat: add support for 24 word recovery phrases #1346
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.appcompat.widget.Toolbar | ||
android:id="@+id/titleBar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:navigationIcon="@drawable/ic_arrow_back" /> | ||
|
||
<LinearLayout | ||
android:id="@+id/register_panel" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
android:layout_marginTop="20dp" | ||
android:paddingHorizontal="20dp" | ||
android:paddingBottom="62dp" | ||
app:layout_constraintTop_toBottomOf="@id/titleBar"> | ||
|
||
<TextView | ||
android:id="@+id/title" | ||
style="@style/Headline5" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="?attr/actionBarSize" | ||
android:text="@string/select_security_level_title" | ||
android:textAlignment="gravity" /> | ||
|
||
<TextView | ||
android:id="@+id/description_1" | ||
style="@style/Body2" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="12dp" | ||
android:gravity="start" | ||
android:textAlignment="gravity" | ||
android:text="@string/select_security_level_message" /> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:id="@+id/twelve_words_option" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/register_panel" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="15dp" | ||
android:background="@drawable/light_grey_border_item" | ||
android:paddingHorizontal="20dp" | ||
android:paddingVertical="12dp"> | ||
|
||
<TextView | ||
android:id="@+id/twelve_words_option_title" | ||
style="@style/Subtitle1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/select_security_level_12_words_title" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<TextView | ||
android:id="@+id/twelve_words_option_message" | ||
style="@style/Caption.Secondary" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="20dp" | ||
android:text="@string/select_security_level_12_words_message" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/twelve_words_option_title" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:id="@+id/twenty_four_words_option" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/intermediate_cl" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="15dp" | ||
android:background="@drawable/light_grey_border_item" | ||
android:paddingHorizontal="20dp" | ||
android:paddingVertical="12dp"> | ||
|
||
<TextView | ||
android:id="@+id/non_contested_name_title" | ||
style="@style/Subtitle1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/select_security_level_24_words_title" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<TextView | ||
android:id="@+id/non_contested_name_description" | ||
style="@style/Caption.Secondary" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="20dp" | ||
android:text="@string/select_security_level_24_words_message" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/non_contested_name_title" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
|
||
</LinearLayout> | ||
|
||
<Button | ||
android:id="@+id/continue_btn" | ||
style="@style/Button.Primary.Large.Blue" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="20dp" | ||
android:text="@string/button_continue" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" /> | ||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -26,6 +26,7 @@ import android.os.Build | |||||||||||||||||||||||||||||||||||||||||||||||
import android.os.Bundle | ||||||||||||||||||||||||||||||||||||||||||||||||
import android.text.TextUtils | ||||||||||||||||||||||||||||||||||||||||||||||||
import android.widget.Toast | ||||||||||||||||||||||||||||||||||||||||||||||||
import androidx.activity.result.contract.ActivityResultContracts | ||||||||||||||||||||||||||||||||||||||||||||||||
import androidx.activity.viewModels | ||||||||||||||||||||||||||||||||||||||||||||||||
import androidx.activity.viewModels | ||||||||||||||||||||||||||||||||||||||||||||||||
import androidx.core.view.isVisible | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -40,6 +41,7 @@ import de.schildbach.wallet.ui.main.MainActivity | |||||||||||||||||||||||||||||||||||||||||||||||
import de.schildbach.wallet.security.PinRetryController | ||||||||||||||||||||||||||||||||||||||||||||||||
import de.schildbach.wallet_test.BuildConfig | ||||||||||||||||||||||||||||||||||||||||||||||||
import de.schildbach.wallet.security.SecurityGuard | ||||||||||||||||||||||||||||||||||||||||||||||||
import de.schildbach.wallet.ui.onboarding.SelectSecurityLevelActivity | ||||||||||||||||||||||||||||||||||||||||||||||||
import de.schildbach.wallet_test.R | ||||||||||||||||||||||||||||||||||||||||||||||||
import de.schildbach.wallet_test.databinding.ActivityOnboardingBinding | ||||||||||||||||||||||||||||||||||||||||||||||||
import de.schildbach.wallet_test.databinding.ActivityOnboardingPermLockBinding | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -111,6 +113,16 @@ class OnboardingActivity : RestoreFromFileActivity() { | |||||||||||||||||||||||||||||||||||||||||||||||
@Inject | ||||||||||||||||||||||||||||||||||||||||||||||||
lateinit var pinRetryController: PinRetryController | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
private val selectWordCountLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> | ||||||||||||||||||||||||||||||||||||||||||||||||
if (result.resultCode == RESULT_OK) { | ||||||||||||||||||||||||||||||||||||||||||||||||
val onboardingInvite = intent.getParcelableExtra<InvitationLinkData>(EXTRA_INVITE) | ||||||||||||||||||||||||||||||||||||||||||||||||
viewModel.createNewWallet( | ||||||||||||||||||||||||||||||||||||||||||||||||
onboardingInvite, | ||||||||||||||||||||||||||||||||||||||||||||||||
result.data!!.extras!!.getInt(SelectSecurityLevelActivity.EXTRA_WORD_COUNT) | ||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+116
to
+124
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. Handle potential null values safely. Using double non-null assertions (!!) on result.data and extras can lead to runtime crashes. private val selectWordCountLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == RESULT_OK) {
+ val wordCount = result.data?.extras?.getInt(SelectSecurityLevelActivity.EXTRA_WORD_COUNT)
+ if (wordCount == null) {
+ log.error("Failed to get word count from SelectSecurityLevelActivity result")
+ return@registerForActivityResult
+ }
val onboardingInvite = intent.getParcelableExtra<InvitationLinkData>(EXTRA_INVITE)
viewModel.createNewWallet(
onboardingInvite,
- result.data!!.extras!!.getInt(SelectSecurityLevelActivity.EXTRA_WORD_COUNT)
+ wordCount
)
}
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
override fun onCreate(savedInstanceState: Bundle?) { | ||||||||||||||||||||||||||||||||||||||||||||||||
super.onCreate(savedInstanceState) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -243,8 +255,9 @@ class OnboardingActivity : RestoreFromFileActivity() { | |||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
private fun initView() { | ||||||||||||||||||||||||||||||||||||||||||||||||
binding.createNewWallet.setOnClickListener { | ||||||||||||||||||||||||||||||||||||||||||||||||
val onboardingInvite = intent.getParcelableExtra<InvitationLinkData>(EXTRA_INVITE) | ||||||||||||||||||||||||||||||||||||||||||||||||
viewModel.createNewWallet(onboardingInvite) | ||||||||||||||||||||||||||||||||||||||||||||||||
selectWordCountLauncher.launch( | ||||||||||||||||||||||||||||||||||||||||||||||||
Intent(this, SelectSecurityLevelActivity::class.java) | ||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
binding.recoveryWallet.setOnClickListener { | ||||||||||||||||||||||||||||||||||||||||||||||||
walletApplication.initEnvironmentIfNeeded() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -56,9 +56,9 @@ class OnboardingViewModel @Inject constructor( | |||||||||||||||||||
internal val finishUnecryptedWalletUpgradeAction = SingleLiveEvent<Unit>() | ||||||||||||||||||||
internal val startActivityAction = SingleLiveEvent<Intent>() | ||||||||||||||||||||
|
||||||||||||||||||||
fun createNewWallet(onboardingInvite: InvitationLinkData?) { | ||||||||||||||||||||
fun createNewWallet(onboardingInvite: InvitationLinkData?, seedWordCount: Int) { | ||||||||||||||||||||
walletApplication.initEnvironmentIfNeeded() | ||||||||||||||||||||
val wallet = walletFactory.create(Constants.NETWORK_PARAMETERS) | ||||||||||||||||||||
val wallet = walletFactory.create(Constants.NETWORK_PARAMETERS, seedWordCount) | ||||||||||||||||||||
Comment on lines
+59
to
+61
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. 🛠️ Refactor suggestion Validate seedWordCount parameter. Add validation to ensure only supported word counts (12 or 24) are accepted. fun createNewWallet(onboardingInvite: InvitationLinkData?, seedWordCount: Int) {
+ require(seedWordCount == 12 || seedWordCount == 24) { "Unsupported word count: $seedWordCount" }
walletApplication.initEnvironmentIfNeeded()
val wallet = walletFactory.create(Constants.NETWORK_PARAMETERS, seedWordCount) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
log.info("successfully created new wallet") | ||||||||||||||||||||
walletApplication.setWallet(wallet) | ||||||||||||||||||||
configuration.armBackupSeedReminder() | ||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -116,7 +116,7 @@ object GoogleDriveService { | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
fun getSigninAccount(context: Context?): GoogleSignInAccount? { | ||||||||||||||||||||||||||||
val opts = getGoogleSigninOptions() | ||||||||||||||||||||||||||||
val account = GoogleSignIn.getLastSignedInAccount(context) | ||||||||||||||||||||||||||||
val account = GoogleSignIn.getLastSignedInAccount(context!!) | ||||||||||||||||||||||||||||
Comment on lines
117
to
+119
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. Replace non-null assertion with safe null handling. Using fun getSigninAccount(context: Context?): GoogleSignInAccount? {
val opts = getGoogleSigninOptions()
- val account = GoogleSignIn.getLastSignedInAccount(context!!)
+ if (context == null) {
+ log.warn("getSigninAccount called with null context")
+ return null
+ }
+ val account = GoogleSignIn.getLastSignedInAccount(context) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
val permissions = arrayOf(Scope(DriveScopes.DRIVE_FILE)) | ||||||||||||||||||||||||||||
return if (GoogleSignIn.hasPermissions(account, *permissions)) { | ||||||||||||||||||||||||||||
account | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package de.schildbach.wallet.ui.onboarding | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import de.schildbach.wallet_test.databinding.ActivityPhrasewordcountBinding | ||
import org.dash.wallet.common.SecureActivity | ||
|
||
class SelectSecurityLevelActivity : SecureActivity() { | ||
private lateinit var binding: ActivityPhrasewordcountBinding | ||
private var selectedWordCount: Int = 12 | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityPhrasewordcountBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
binding.titleBar.setOnClickListener { | ||
setResult(RESULT_CANCELED) | ||
finish() | ||
} | ||
|
||
binding.twelveWordsOption.setOnClickListener { | ||
setMode(12) | ||
} | ||
|
||
binding.twentyFourWordsOption.setOnClickListener { | ||
setMode(24) | ||
} | ||
|
||
binding.continueBtn.setOnClickListener { | ||
setResult(RESULT_OK, Intent().apply { putExtra(EXTRA_WORD_COUNT, selectedWordCount) }) | ||
finish() | ||
} | ||
setMode(12) | ||
} | ||
|
||
private fun setMode(wordCount: Int) { | ||
if (wordCount == 12) { | ||
binding.twelveWordsOption.isSelected = true | ||
binding.twentyFourWordsOption.isSelected = false | ||
selectedWordCount = 12 | ||
} else { | ||
binding.twelveWordsOption.isSelected = false | ||
binding.twentyFourWordsOption.isSelected = true | ||
selectedWordCount = 24 | ||
} | ||
} | ||
|
||
companion object { | ||
const val EXTRA_WORD_COUNT = "extra_word_count" | ||
} | ||
} |
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.
🛠️ Refactor suggestion
Add content descriptions for accessibility.
Both option containers need content descriptions to improve accessibility for screen readers.
Also applies to: 74-104