-
Notifications
You must be signed in to change notification settings - Fork 38
Add Key Teleport receive flow (#654) #687
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
Open
pradhyum6144
wants to merge
9
commits into
bitcoinppl:master
Choose a base branch
from
pradhyum6144:feat-654-keyteleport-receive
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bebbed0
Add cove-keyteleport crate: Key Teleport crypto primitives (mnemonic/…
pradhyum6144 990aa68
Remove unused _receiver_pubkey field from SenderSession
pradhyum6144 d32a1a5
Apply rustfmt formatting to cove-keyteleport crate
pradhyum6144 620be06
Add Key Teleport receive flow for mnemonic/xprv import (#654)
pradhyum6144 c63ebac
Apply rustfmt to key_teleport and router
pradhyum6144 8f1350c
Fix CI failures and address code review feedback (#654)
pradhyum6144 b02219d
Fix iOS Swift exhaustive switch errors for new Key Teleport types
pradhyum6144 a838138
Address code review feedback on Key Teleport receive flow
pradhyum6144 7d1f08d
Rename KtFileType to KeyTeleportFileType and use bbqr Encoding type
pradhyum6144 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
77 changes: 77 additions & 0 deletions
77
...pp/src/main/java/org/bitcoinppl/cove/flows/KeyTeleportFlow/KeyTeleportReceiveContainer.kt
This file contains hidden or 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,77 @@ | ||
| package org.bitcoinppl.cove.flows.KeyTeleportFlow | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.DisposableEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import org.bitcoinppl.cove.AppManager | ||
| import org.bitcoinppl.cove_core.KeyTeleportPayloadKind | ||
| import org.bitcoinppl.cove_core.KeyTeleportReceiveRoute | ||
| import org.bitcoinppl.cove_core.KeyTeleportReceiverSession | ||
| import org.bitcoinppl.cove_core.NewWalletRoute | ||
| import org.bitcoinppl.cove_core.Route | ||
| import org.bitcoinppl.cove_core.RouteFactory | ||
|
|
||
| private fun ktRoute(inner: KeyTeleportReceiveRoute): Route = | ||
| Route.NewWallet(NewWalletRoute.KeyTeleportReceive(inner)) | ||
|
|
||
| @Composable | ||
| fun KeyTeleportReceiveContainer( | ||
| app: AppManager, | ||
| route: KeyTeleportReceiveRoute, | ||
| ) { | ||
| var session by remember { mutableStateOf<KeyTeleportReceiverSession?>(null) } | ||
|
|
||
| DisposableEffect(Unit) { | ||
| session = KeyTeleportReceiverSession.new() | ||
| onDispose { session?.destroy() } | ||
| } | ||
|
|
||
| val s = session ?: return | ||
|
|
||
| when (route) { | ||
| is KeyTeleportReceiveRoute.ShowQr -> { | ||
| KeyTeleportReceiveShowQrScreen( | ||
| app = app, | ||
| session = s, | ||
| onContinue = { app.pushRoute(ktRoute(KeyTeleportReceiveRoute.ScanSender)) }, | ||
| ) | ||
| } | ||
|
|
||
| is KeyTeleportReceiveRoute.ScanSender -> { | ||
| KeyTeleportReceiveScanSenderScreen( | ||
| app = app, | ||
| onScanned = { senderPacketBbqr -> | ||
| app.pushRoute( | ||
| ktRoute(KeyTeleportReceiveRoute.EnterPassword(senderPacketBbqr)), | ||
| ) | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| is KeyTeleportReceiveRoute.EnterPassword -> { | ||
| KeyTeleportReceivePasswordScreen( | ||
| app = app, | ||
| session = s, | ||
| senderPacketBbqr = route.senderPacketBbqr, | ||
| onDecoded = { payloadKind, wordsOrXprv -> | ||
| app.pushRoute( | ||
| ktRoute( | ||
| KeyTeleportReceiveRoute.ReviewImport(payloadKind, wordsOrXprv), | ||
| ), | ||
| ) | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| is KeyTeleportReceiveRoute.ReviewImport -> { | ||
| KeyTeleportReceiveImportScreen( | ||
| app = app, | ||
| payloadKind = route.payloadKind, | ||
| wordsOrXprv = route.wordsOrXprv, | ||
| ) | ||
| } | ||
| } | ||
| } |
209 changes: 209 additions & 0 deletions
209
...src/main/java/org/bitcoinppl/cove/flows/KeyTeleportFlow/KeyTeleportReceiveImportScreen.kt
This file contains hidden or 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,209 @@ | ||
| package org.bitcoinppl.cove.flows.KeyTeleportFlow | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.border | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.ExperimentalLayoutApi | ||
| import androidx.compose.foundation.layout.FlowRow | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.rememberScrollState | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.foundation.verticalScroll | ||
| import androidx.compose.material.icons.Icons | ||
| import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.CenterAlignedTopAppBar | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.IconButton | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Scaffold | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TopAppBarDefaults | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.text.font.FontFamily | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.compose.ui.unit.sp | ||
| import org.bitcoinppl.cove.AppManager | ||
| import org.bitcoinppl.cove.ImportWalletManager | ||
| import org.bitcoinppl.cove.Log | ||
| import org.bitcoinppl.cove.TaggedItem | ||
| import org.bitcoinppl.cove_core.AppAlertState | ||
| import org.bitcoinppl.cove_core.ImportWalletException | ||
| import org.bitcoinppl.cove_core.KeyTeleportPayloadKind | ||
| import org.bitcoinppl.cove_core.Route | ||
|
|
||
| private const val TAG = "KeyTeleportImportScreen" | ||
|
|
||
| @OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) | ||
| @Composable | ||
| fun KeyTeleportReceiveImportScreen( | ||
| app: AppManager, | ||
| payloadKind: KeyTeleportPayloadKind, | ||
| wordsOrXprv: String, | ||
| ) { | ||
| var isImporting by remember { mutableStateOf(false) } | ||
|
|
||
| val isMnemonic = payloadKind == KeyTeleportPayloadKind.MNEMONIC | ||
| val words = if (isMnemonic) wordsOrXprv.split(" ") else emptyList() | ||
|
|
||
| fun doImport() { | ||
| if (isImporting) return | ||
| isImporting = true | ||
|
|
||
| try { | ||
| if (isMnemonic) { | ||
| val manager = ImportWalletManager() | ||
| val wordGroups = listOf(words) | ||
| val metadata = manager.importWallet(wordGroups) | ||
| manager.close() | ||
| app.rust.selectWallet(metadata.id) | ||
| app.resetRoute(Route.SelectedWallet(metadata.id)) | ||
| app.alertState = TaggedItem(AppAlertState.ImportedSuccessfully) | ||
| } else { | ||
| // XPRV — use cold wallet xpub import path | ||
| val wallet = org.bitcoinppl.cove_core.Wallet.newFromXpub(wordsOrXprv) | ||
| val id = wallet.id() | ||
| wallet.close() | ||
| app.rust.selectWallet(id) | ||
| app.alertState = TaggedItem(AppAlertState.ImportedSuccessfully) | ||
| } | ||
|
greptile-apps[bot] marked this conversation as resolved.
Outdated
greptile-apps[bot] marked this conversation as resolved.
Outdated
|
||
| } catch (e: ImportWalletException.WalletAlreadyExists) { | ||
| Log.w(TAG, "Wallet already exists: ${e.v1}") | ||
| app.alertState = TaggedItem(AppAlertState.DuplicateWallet(e.v1)) | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Import failed", e) | ||
| app.alertState = TaggedItem( | ||
| AppAlertState.General( | ||
| title = "Import Failed", | ||
| message = e.message ?: "Unknown error", | ||
| ), | ||
| ) | ||
| } finally { | ||
| isImporting = false | ||
| } | ||
| } | ||
|
|
||
| Scaffold( | ||
| topBar = { | ||
| CenterAlignedTopAppBar( | ||
| title = { Text("Review & Import", fontWeight = FontWeight.SemiBold) }, | ||
| navigationIcon = { | ||
| IconButton(onClick = { app.popRoute() }) { | ||
| Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") | ||
| } | ||
| }, | ||
| colors = TopAppBarDefaults.centerAlignedTopAppBarColors( | ||
| containerColor = Color.Transparent, | ||
| ), | ||
| ) | ||
| }, | ||
| ) { paddingValues -> | ||
| Column( | ||
| modifier = Modifier | ||
| .fillMaxSize() | ||
| .padding(paddingValues) | ||
| .padding(horizontal = 24.dp) | ||
| .verticalScroll(rememberScrollState()), | ||
| horizontalAlignment = Alignment.CenterHorizontally, | ||
| verticalArrangement = Arrangement.spacedBy(16.dp), | ||
| ) { | ||
| Spacer(modifier = Modifier.height(8.dp)) | ||
|
|
||
| Text( | ||
| text = if (isMnemonic) "Received mnemonic (${words.size} words)" else "Received XPRV", | ||
| style = MaterialTheme.typography.titleMedium, | ||
| textAlign = TextAlign.Center, | ||
| ) | ||
|
|
||
| Text( | ||
| text = "Review the received secret before importing. Once imported, this will create a new wallet on your device.", | ||
| style = MaterialTheme.typography.bodyMedium, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| textAlign = TextAlign.Center, | ||
| ) | ||
|
|
||
| if (isMnemonic) { | ||
| // show word grid | ||
| FlowRow( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .border( | ||
| 1.dp, | ||
| MaterialTheme.colorScheme.outline, | ||
| RoundedCornerShape(12.dp), | ||
| ) | ||
| .padding(12.dp), | ||
| horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
| verticalArrangement = Arrangement.spacedBy(8.dp), | ||
| ) { | ||
| words.forEachIndexed { index, word -> | ||
| Row( | ||
| modifier = Modifier | ||
| .background( | ||
| MaterialTheme.colorScheme.surfaceVariant, | ||
| RoundedCornerShape(6.dp), | ||
| ) | ||
| .padding(horizontal = 8.dp, vertical = 4.dp), | ||
| horizontalArrangement = Arrangement.spacedBy(4.dp), | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| ) { | ||
| Text( | ||
| text = "${index + 1}.", | ||
| fontSize = 12.sp, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| ) | ||
| Text( | ||
| text = word, | ||
| fontFamily = FontFamily.Monospace, | ||
| fontWeight = FontWeight.Medium, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| // show xprv (truncated) | ||
| Text( | ||
| text = wordsOrXprv, | ||
| fontFamily = FontFamily.Monospace, | ||
| fontSize = 11.sp, | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .border( | ||
| 1.dp, | ||
| MaterialTheme.colorScheme.outline, | ||
| RoundedCornerShape(12.dp), | ||
| ) | ||
| .padding(12.dp), | ||
| ) | ||
| } | ||
|
|
||
| Spacer(modifier = Modifier.weight(1f)) | ||
|
|
||
| Button( | ||
| onClick = { doImport() }, | ||
| enabled = !isImporting, | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .padding(bottom = 24.dp), | ||
| ) { | ||
| Text(if (isImporting) "Importing…" else "Import Wallet") | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.