From 84be1c5beb19ff7e337eb82c4d91b51e8c06ed1c Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Wed, 18 Nov 2026 16:03:47 +0200 Subject: [PATCH] refactor: no node behind a recovery phrase (wallet removal, Phase 6) PhraseKeys derives a phrase's nostr key (NIP-06, m/44'/1237'/0'/0/0) and its profile id (hash160 of m/50'/0', the old node key) with bitcoin-kmp's DeterministicWallet. ForkCompatibilityTest's Phase 0 pins pass unchanged through it, so the same phrase is the same person with the same preference files. No profile starts a node: Identity.business, startupNode and its state machine, the platform start/schedule/stop actuals, LightningApplication, BusinessManager.initialize, the NFC hooks and POST_NOTIFICATIONS go. A switch is clearing the identity and nothing else. Copy that promised funds or a wallet is reworded, and the switcher's badge says Recovery phrase. Forgetting a phrase profile is still refused (now PhraseAttached): the phrase would derive the key again, and offering it is new UI. iosMain was edited without an iOS build. Co-Authored-By: Claude Opus 5.5 --- .../src/androidMain/AndroidManifest.xml | 2 - .../mobi/giza/android/GizaApplication.kt | 10 +- .../kotlin/mobi/giza/android/MainActivity.kt | 23 +- .../compose/extensions/Phoenix.android.kt | 17 -- .../view/model/NavigationViewModel.android.kt | 7 - .../composeResources/values/strings.xml | 36 +-- .../mobi/giza/compose/extensions/Phoenix.kt | 5 - .../giza/compose/identity/ForgetIdentity.kt | 12 +- .../mobi/giza/compose/identity/Identity.kt | 8 +- .../giza/compose/identity/IdentityWriter.kt | 29 +- .../mobi/giza/compose/identity/PhraseKeys.kt | 43 +++ .../giza/compose/identity/StoredIdentity.kt | 17 +- .../ui/composable/KeyRecoveryScreen.kt | 20 +- .../compose/ui/composable/SignInScreen.kt | 8 +- .../SovereignWalletStartupScreen.kt | 278 +++++++----------- .../widgets/wallet/WalletsSelector.kt | 4 +- .../ui/view/model/NostrSecretViewModel.kt | 2 +- .../compose/ui/view/model/SignOutViewModel.kt | 2 +- .../model/SovereignWalletStartupViewModel.kt | 57 ---- .../ui/view/model/SovereignWalletViewModel.kt | 72 +---- .../compose/managers/ForkCompatibilityTest.kt | 23 +- .../giza/compose/extensions/Phoenix.ios.kt | 18 -- .../ui/view/model/NavigationViewModel.ios.kt | 7 - .../giza/compose/extensions/Phoenix.jvm.kt | 37 --- .../ui/view/model/NavigationViewModel.jvm.kt | 22 +- .../database/dao/OwnedRequestQueueJvmTest.kt | 1 - .../identity/AddProfileFromInsideJvmTest.kt | 3 +- .../compose/identity/ForgetIdentityJvmTest.kt | 4 +- .../compose/identity/IdentitySwitchJvmTest.kt | 43 +-- .../compose/identity/IdentityWriterJvmTest.kt | 4 +- .../MultipleProfilesRoundTripJvmTest.kt | 28 +- .../identity/NpubPreviewRoundTripJvmTest.kt | 2 - .../identity/NsecRestoreRoundTripJvmTest.kt | 3 - .../RelaysSocketManagerSwitchJvmTest.kt | 1 - .../ui/composable/ProfilesScreenJvmTest.kt | 9 +- .../model/CreateSharedKeyViewModelJvmTest.kt | 1 - .../view/model/DkgRitualViewModelJvmTest.kt | 2 - .../model/NavigationIdentityRoutingJvmTest.kt | 6 - .../view/model/NostrSecretViewModelJvmTest.kt | 1 - docs/giza-wallet-removal.md | 6 +- 40 files changed, 255 insertions(+), 618 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/PhraseKeys.kt diff --git a/composeApp/src/androidMain/AndroidManifest.xml b/composeApp/src/androidMain/AndroidManifest.xml index 1899d4fc..dc20c74b 100644 --- a/composeApp/src/androidMain/AndroidManifest.xml +++ b/composeApp/src/androidMain/AndroidManifest.xml @@ -4,8 +4,6 @@ - - by preferencesDataStore(name = "globalprefs") -class GizaApplication: Application(), LightningApplication { +class GizaApplication: Application() { private lateinit var globalPrefs: GlobalPrefs private lateinit var phoenixGlobal: PhoenixGlobal @@ -23,15 +21,13 @@ class GizaApplication: Application(), LightningApplication { phoenixGlobal = PhoenixGlobal(PlatformContext(applicationContext)) globalPrefs = GlobalPrefs(applicationContext.globalPrefs) - BusinessManager.initialize(this) - } - override fun getGlobalPrefs(): GlobalPrefs { + fun getGlobalPrefs(): GlobalPrefs { return globalPrefs } - override fun getPhoenixGlobal(): PhoenixGlobal { + fun getPhoenixGlobal(): PhoenixGlobal { return phoenixGlobal } } \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/mobi/giza/android/MainActivity.kt b/composeApp/src/androidMain/kotlin/mobi/giza/android/MainActivity.kt index 2eae0eb1..2658f868 100644 --- a/composeApp/src/androidMain/kotlin/mobi/giza/android/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/mobi/giza/android/MainActivity.kt @@ -1,22 +1,16 @@ package mobi.giza.android -import android.content.Intent -import android.nfc.NfcAdapter import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.navigation.compose.rememberNavController -import fr.acinq.phoenix.NFCActivity import mobi.giza.compose.PlatformContext import mobi.giza.compose.GizaApp import mobi.giza.compose.GizaGlobal import fr.acinq.phoenix.PhoenixGlobal -import fr.acinq.phoenix.android.services.HceService -class MainActivity : ComponentActivity(), NFCActivity { - - private var nfcAdapter: NfcAdapter? = null +class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { enableEdgeToEdge() @@ -41,17 +35,4 @@ class MainActivity : ComponentActivity(), NFCActivity { ) } } - - override fun stopHceService() { - stopService(Intent(this@MainActivity, HceService::class.java)) - } - - override fun stopNfcReader() { - if (com.machankura.compose.ui.composable.widgets.nfc.NfcStateRepository.isReading()) { - com.machankura.compose.ui.composable.widgets.nfc.NfcStateRepository.updateState( - com.machankura.compose.ui.composable.widgets.nfc.NfcState.Inactive) - } - nfcAdapter?.disableReaderMode(this@MainActivity) - } - -} \ No newline at end of file +} diff --git a/composeApp/src/androidMain/kotlin/mobi/giza/compose/extensions/Phoenix.android.kt b/composeApp/src/androidMain/kotlin/mobi/giza/compose/extensions/Phoenix.android.kt index 46b5bd98..4f2908a3 100644 --- a/composeApp/src/androidMain/kotlin/mobi/giza/compose/extensions/Phoenix.android.kt +++ b/composeApp/src/androidMain/kotlin/mobi/giza/compose/extensions/Phoenix.android.kt @@ -2,26 +2,9 @@ package mobi.giza.compose.extensions import mobi.giza.android.GizaApplication import fr.acinq.phoenix.PhoenixGlobal -import fr.acinq.phoenix.android.BusinessManager -import fr.acinq.phoenix.android.services.ChannelsWatcher -import fr.acinq.phoenix.android.services.ContactsPhotoCleaner -import fr.acinq.phoenix.data.StartBusinessResult import fr.acinq.phoenix.utils.preferences.GlobalPrefs -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.withContext - -actual suspend fun platformStartupLogic(words: List): StartBusinessResult { - return withContext(Dispatchers.Default) { - BusinessManager.startNewBusiness(words, isHeadless = false) - } -} - -actual fun schedulePlatformLogic(phoenixGlobal: PhoenixGlobal) { - ChannelsWatcher.schedule(phoenixGlobal.ctx.applicationContext) - ContactsPhotoCleaner.schedule(phoenixGlobal.ctx.applicationContext) -} actual fun getShowIntroFlow(phoenixGlobal: PhoenixGlobal): Flow { val machankuraApplication = phoenixGlobal.ctx.applicationContext as GizaApplication return machankuraApplication.getGlobalPrefs().getShowIntro diff --git a/composeApp/src/androidMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.android.kt b/composeApp/src/androidMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.android.kt index bb394251..5ad4b4b5 100644 --- a/composeApp/src/androidMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.android.kt +++ b/composeApp/src/androidMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.android.kt @@ -2,20 +2,13 @@ package mobi.giza.compose.ui.view.model import mobi.giza.android.GizaApplication import fr.acinq.phoenix.PhoenixGlobal -import fr.acinq.phoenix.android.BusinessManager import fr.acinq.phoenix.data.DecryptSeedResult import fr.acinq.phoenix.data.WalletId import fr.acinq.phoenix.managers.SeedManager import fr.acinq.phoenix.utils.preferences.UserWalletMetadata import kotlinx.coroutines.flow.Flow -actual fun updateBusinessActiveInUI(walletId: WalletId) { - BusinessManager.updateBusinessActiveInUI(walletId) -} -actual fun stopPlatformBusiness(walletId: WalletId) { - BusinessManager.stopBusiness(walletId) -} actual fun loadAndDecryptSeed(phoenixGlobal: PhoenixGlobal): DecryptSeedResult { return SeedManager.loadAndDecrypt( diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index 01ca6ae3..8c7e88a5 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -70,7 +70,7 @@ Display recovery phrase Don't sign Download - Download and securely store everything needed to recover this profile and the coins it holds. + Download and securely store everything needed to recover this profile. Edit profile Emergency kit ENDED @@ -93,7 +93,7 @@ How many admins have to approve a change? How many members will it take to sign? I have saved my recovery phrase somewhere safe. - I understand that if I lose this phone and my recovery phrase, I lose this profile and the funds in its wallet. + I understand that if I lose this phone and my recovery phrase, I lose this profile. If you are new to Giza or just want to create a fresh profile Input npub... or nip05 Introduce yourself @@ -140,7 +140,7 @@ Network relays No proposal is being signed. No proposal is waiting on members. - No wallet is open on this device, so there is no phrase to show. + This profile was not opened from a recovery phrase on this device, so there is no phrase to show. Not backed up yet New chat Next @@ -231,7 +231,6 @@ Couldn't load this group. Couldn't read your keys. Couldn't start the key ceremony. - Startup error Taking part with these members Tap to load Tell friends to join you so your feed stays lively and fresh. @@ -240,8 +239,8 @@ The ceremony was abandoned. The group can hold one key together, split so that no single member holds it. Signing with it takes a quorum. The group has a shared key. - The recovery phrase (sometimes called a seed) is a list of 12 English words. It is the only way back to this profile: the key that signs as you, and the wallet that holds your coins, are both derived from it.\n\nOnly you have this phrase. Keep it private — nobody from Giza will ever ask you for it.\n\nDo not lose it. Write it down and keep it somewhere safe that is not this phone. If you lose both the phone and the phrase, this profile and its funds are gone for good. - These are your keys. Keep them safe so they can keep unlocking this profile and its coins, even when you lose or change your phone. + The recovery phrase (sometimes called a seed) is a list of 12 English words. It is the only way back to this profile: the key that signs as you is derived from it.\n\nOnly you have this phrase. Keep it private — nobody from Giza will ever ask you for it.\n\nDo not lose it. Write it down and keep it somewhere safe that is not this phone. If you lose both the phone and the phrase, this profile is gone for good. + These are your keys. Keep them safe so they can keep unlocking this profile, even when you lose or change your phone. This device holds no phrase for the profile that is signed in. This decides who can change the group later. You can't switch afterwards. This group has not been asked to sign anything yet. @@ -283,7 +282,7 @@ What should people know about you? What vibrations do you want to send out? What will be discussed in this chat room. - Write down and secure the 12 word phrase that this profile and its wallet are derived from. + Write down and secure the 12 word phrase that this profile is derived from. Who will you be passing the aux to? You You agreed. @@ -298,7 +297,7 @@ YOLO You will be in full control of this profile. If you would like to use it for the long term please remember to backup the profile/keys. Your profile is almost ready... just getting it's first cryptographic signature together. - Your share of it is on this device only. Your wallet backup restores it — nobody else's share can. + Your share of it is on this device only. Nobody else's share can stand in for it. Add people to %1$s Ask all %1$s again @@ -388,9 +387,9 @@ A password-protected key (ncryptsec) is not supported yet. Decrypt it in the app it came from and paste the nsec. Enter a recovery phrase or an nsec to sign in. Paste - Recognised as a nostr secret key. No wallet comes with it. - Recognised as a recovery phrase. It also restores the wallet. - Once it is restored here, stop using this phrase in any other app or on any other device. One wallet running in two places at once can lose funds. + Recognised as a nostr secret key. + Recognised as a recovery phrase. + Giza keeps no wallet. Restoring the phrase here brings back the profile it signs as, and nothing else. Recognised as a public key. You will see this profile and the people it follows; messages stay closed and nothing can be sent. Paste the nsec later to open it. Recovery phrase, nsec or npub Sign in with a recovery phrase, an nsec, or an npub to look around @@ -428,7 +427,7 @@ Nostr secret key Remove the key from this device. The profile stays on the relays. Store the nsec that signs as this profile. There is no phrase behind it: the key is the whole backup. - The nsec is the key that signs as you. This profile was signed in with it rather than made from a recovery phrase, so there is no phrase to write down and no wallet attached: the key is the whole of the backup.\n\nOnly you have it. Keep it private — nobody from Giza will ever ask you for it.\n\nDo not lose it. Store it somewhere safe that is not this phone. If you lose both the phone and the key, this profile is gone for good. + The nsec is the key that signs as you. This profile was signed in with it rather than made from a recovery phrase, so there is no phrase to write down: the key is the whole of the backup.\n\nOnly you have it. Keep it private — nobody from Giza will ever ask you for it.\n\nDo not lose it. Store it somewhere safe that is not this phone. If you lose both the phone and the key, this profile is gone for good. This device holds no nostr secret key for the profile that is open. If it was made from a recovery phrase, the phrase is its backup. Unlocking your key… You have not backed up your nostr secret key @@ -436,19 +435,16 @@ You said you stored it New note - + Choose a profile Could not load the profiles on this device Decrypting… Opening profile… Preparing profiles… - Starting wallet… Unlock to continue Loading profiles… Switch profile - Wallet Create a new profile Sign in with a key @@ -461,12 +457,4 @@ You already have a chat with %1$s. Checking whether %1$s can receive messages here. %1$s hasn't set up encrypted messaging yet. Try again later, or ask them to open Giza. - - - - - - - - diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/extensions/Phoenix.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/extensions/Phoenix.kt index a571977f..e9f70b9e 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/extensions/Phoenix.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/extensions/Phoenix.kt @@ -1,15 +1,10 @@ package mobi.giza.compose.extensions import fr.acinq.phoenix.PhoenixGlobal -import fr.acinq.phoenix.data.StartBusinessResult import fr.acinq.phoenix.utils.preferences.GlobalPrefs import kotlinx.coroutines.flow.Flow -expect suspend fun platformStartupLogic(words: List): StartBusinessResult - -expect fun schedulePlatformLogic(phoenixGlobal: PhoenixGlobal) - expect fun getShowIntroFlow(phoenixGlobal: PhoenixGlobal): Flow expect fun getGlobalPrefs(phoenixGlobal: PhoenixGlobal): GlobalPrefs diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/ForgetIdentity.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/ForgetIdentity.kt index 4c788bdf..ae8ce555 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/ForgetIdentity.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/ForgetIdentity.kt @@ -12,8 +12,10 @@ import mobi.giza.compose.repository.NostrRepository * that the two exits a read-only identity has -- sign out, and *use a different key* on * the not-found screen -- run the same sequence rather than a copy of it. The first step * is the same call for both credential kinds since the credentials file; only a profile - * with a wallet attached is refused, because removing a seed is a wallet question this - * does not answer, and because the seed would derive the key again. + * made from a recovery phrase is refused, because the phrase would derive the key again + * and this does not remove phrases. There is no wallet behind one any more + * (docs/giza-wallet-removal.md), so removing the phrase as well is now only a question + * of how strongly to confirm it -- not yet asked. * * The two writers are injected as functions so the sequence can be pinned in a test * without a key store, as the nsec view model's already is. @@ -24,8 +26,8 @@ object ForgetIdentity { /** The device no longer holds anything for the identity. */ data object Forgotten : Outcome - /** A profile with a wallet attached: the seed derives its key, and this does not remove seeds. */ - data object WalletAttached : Outcome + /** A profile made from a recovery phrase: the phrase derives its key, and this does not remove phrases. */ + data object PhraseAttached : Outcome /** The credentials file could not be read; nothing was changed. */ data object CannotForget : Outcome @@ -44,7 +46,7 @@ object ForgetIdentity { nostrRepository.forgetLocalAccount(identity.nostrPublicKey) Outcome.Forgotten } - is IdentityWriter.ForgetNostrCredentialResult.WalletAttached -> Outcome.WalletAttached + is IdentityWriter.ForgetNostrCredentialResult.PhraseAttached -> Outcome.PhraseAttached is IdentityWriter.ForgetNostrCredentialResult.CannotLoadKeys -> Outcome.CannotForget } } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/Identity.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/Identity.kt index 7f68fddf..305e47f4 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/Identity.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/Identity.kt @@ -7,7 +7,6 @@ import fr.acinq.bitcoin.Crypto import fr.acinq.bitcoin.PrivateKey import fr.acinq.bitcoin.XonlyPublicKey import fr.acinq.bitcoin.byteVector -import fr.acinq.phoenix.PhoenixBusiness import fr.acinq.phoenix.data.WalletId import fr.acinq.phoenix.managers.nostrPublicKeyHex import fr.acinq.phoenix.utils.preferences.InternalPrefs @@ -63,7 +62,6 @@ enum class IdentityKind { * its preferences. Same shape as a wallet's, so nothing downstream can tell the * kinds apart by the id -- the kind is here, where it can be asked. * @param nostrPrivateKey null only for [IdentityKind.NostrPublic]. - * @param business the running node. Non-null only for [IdentityKind.Mnemonic]. */ data class Identity( val id: WalletId, @@ -79,7 +77,6 @@ data class Identity( val nostrPrivateKey: PrivateKey?, val userPrefs: UserPrefs, val internalPrefs: InternalPrefs, - val business: PhoenixBusiness?, ) { /** * What the notary, the pumps and every write entrance ask. @@ -110,7 +107,6 @@ data class Identity( nostrPrivateKey: PrivateKey, userPrefs: UserPrefs, internalPrefs: InternalPrefs, - business: PhoenixBusiness?, ): Identity { require(kind != IdentityKind.NostrPublic) { "a read-only identity has no secret to sign with" } return Identity( @@ -120,11 +116,10 @@ data class Identity( nostrPrivateKey = nostrPrivateKey, userPrefs = userPrefs, internalPrefs = internalPrefs, - business = business, ) } - /** An identity the device holds only the public key of. No secret, no node. */ + /** An identity the device holds only the public key of. No secret. */ fun readOnly( id: WalletId, nostrPublicKey: HexKey, @@ -137,7 +132,6 @@ data class Identity( nostrPrivateKey = null, userPrefs = userPrefs, internalPrefs = internalPrefs, - business = null, ) } } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/IdentityWriter.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/IdentityWriter.kt index 8ed82c46..f0e9b02c 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/IdentityWriter.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/IdentityWriter.kt @@ -2,10 +2,7 @@ package mobi.giza.compose.identity import co.touchlab.kermit.Logger import com.vitorpamplona.quartz.nip01Core.core.HexKey -import fr.acinq.bitcoin.MnemonicCode import fr.acinq.bitcoin.PrivateKey -import fr.acinq.lightning.crypto.LocalKeyManager -import fr.acinq.lightning.utils.toByteVector import fr.acinq.phoenix.PhoenixGlobal import fr.acinq.phoenix.data.ElectrumConfig import fr.acinq.phoenix.data.WalletId @@ -33,7 +30,7 @@ import mobi.giza.compose.ui.view.model.WritingSeedState * preferences every kind reads. * * [writeMnemonic] was an `expect` with three byte-identical actuals -- android, jvm, ios -- - * using nothing but commonMain: SeedManager, EncryptedSeed, LocalKeyManager, + * using nothing but commonMain: SeedManager, EncryptedSeed, PhraseKeys, * DataStoreManager, AppVersion. It was an expect because something once needed to * differ and nothing does now, so it is one function here, and the second writer sits * next to it rather than being triplicated in turn. @@ -120,10 +117,9 @@ object IdentityWriter { // Null when nostr-credentials.dat exists and cannot be read; an empty map when it is absent. val existingCredentials = NostrCredentialManager.loadAndDecryptOrNull(phoenixGlobal) - val seed = MnemonicCode.toSeed(mnemonics, "").toByteVector() - val keyManager = LocalKeyManager(seed, NodeParamsManager.chain, NodeParamsManager.remoteSwapInXpub) - val newWalletId = WalletId(keyManager.nodeKeys.nodeKey.publicKey) - val newNostrPublicKey = keyManager.nostrPrivateKey().nostrPublicKeyHex() + val newWalletId = PhraseKeys.profileId(mnemonics) + val newNostrPrivateKey = PhraseKeys.nostrPrivateKey(mnemonics) + val newNostrPublicKey = newNostrPrivateKey.nostrPublicKeyHex() when { existingSeeds == null || existingCredentials == null -> { @@ -170,7 +166,7 @@ object IdentityWriter { NostrCredentialManager.writeToDisk( phoenixGlobal, EncryptedNostrCredentials.encrypt( - existingCredentials + (newNostrPublicKey to NostrCredential.Secret(keyManager.nostrPrivateKey())) + existingCredentials + (newNostrPublicKey to NostrCredential.Secret(newNostrPrivateKey)) ), ) val newSeedMap = existingSeeds + (newWalletId to mnemonics) @@ -314,13 +310,12 @@ object IdentityWriter { data object Forgotten : ForgetNostrCredentialResult() /** - * A seed derives the key: the profile has a wallet attached, and removing a seed is - * a wallet question this does not answer. Also the answer for a key that is not in + * A recovery phrase derives the key, and this does not remove phrases. Also the answer for a key that is not in * `nostr-credentials.dat` at all, which since the repair can only be a seed's key * the repair could not write -- and either way, taking the entry would not take the * key: the seed would derive it again and the next listing would put it back. */ - data object WalletAttached : ForgetNostrCredentialResult() + data object PhraseAttached : ForgetNostrCredentialResult() data object CannotLoadKeys : ForgetNostrCredentialResult() } @@ -329,8 +324,8 @@ object IdentityWriter { * The inverse of [writeNostrKey] and [writeNostrPublicKey] alike: removes the entry, * whichever kind it is, from `nostr-credentials.dat` and deletes the identity's * preference files. The profile stays on the relays, and the same key can be signed - * in again. Only for a profile with no wallet attached -- see - * [ForgetNostrCredentialResult.WalletAttached]. + * in again. Only for a profile not made from a recovery phrase -- see + * [ForgetNostrCredentialResult.PhraseAttached]. */ suspend fun forgetNostrCredential( log: Logger, @@ -345,12 +340,12 @@ object IdentityWriter { return ForgetNostrCredentialResult.CannotLoadKeys } if (seeds.containsKey(nostrPublicKey)) { - log.i("asked to forget a key a seed derives; the wallet has to go first") - return ForgetNostrCredentialResult.WalletAttached + log.i("asked to forget a key a recovery phrase derives; the phrase would derive it again") + return ForgetNostrCredentialResult.PhraseAttached } if (!existing.containsKey(nostrPublicKey)) { log.i("asked to forget a key that is not a credential on this device") - return ForgetNostrCredentialResult.WalletAttached + return ForgetNostrCredentialResult.PhraseAttached } NostrCredentialManager.writeToDisk(phoenixGlobal, EncryptedNostrCredentials.encrypt(existing - nostrPublicKey)) diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/PhraseKeys.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/PhraseKeys.kt new file mode 100644 index 00000000..27825505 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/PhraseKeys.kt @@ -0,0 +1,43 @@ +package mobi.giza.compose.identity + +import fr.acinq.bitcoin.DeterministicWallet +import fr.acinq.bitcoin.KeyPath +import fr.acinq.bitcoin.MnemonicCode +import fr.acinq.bitcoin.PrivateKey +import fr.acinq.bitcoin.byteVector +import fr.acinq.phoenix.data.WalletId + +/** + * What a recovery phrase derives, now that it backs a key and no wallet + * (docs/giza-wallet-removal.md, Phase 6). + * + * Two things, and both have to come out byte for byte as they did when lightning-kmp's + * `LocalKeyManager` derived them, or a phrase restored here is somebody else: + * + * - the nostr key, at NIP-06's `m/44'/1237'/0'/0/0`. `LocalKeyManager` took account + * `1'` off mainnet, but its chain was a constant, `Chain.Mainnet`, so no profile was + * ever made on the other branch; + * - the profile's id: the hash160 of the key at `m/50'/0'`, which was the node key + * (`LocalKeyManager.nodeKeyBasePath` on mainnet). The node is gone; the id is not, + * because it names the profile's preference files and saved metadata, and a new id + * would lose them without a word. + * + * Plain BIP32 over the BIP39 seed with an empty passphrase, which is what + * `LocalKeyManager` did underneath. `ForkCompatibilityTest` pins both on NIP-06's own + * test vector. + */ +object PhraseKeys { + private val NOSTR_KEY_PATH = KeyPath("m/44'/1237'/0'/0/0") + private val PROFILE_ID_PATH = KeyPath("m/50'/0'") + + /** The nostr key [words] derive. */ + fun nostrPrivateKey(words: List): PrivateKey = + master(words).derivePrivateKey(NOSTR_KEY_PATH).privateKey + + /** The id a profile made from [words] is filed under. */ + fun profileId(words: List): WalletId = + WalletId(master(words).derivePrivateKey(PROFILE_ID_PATH).publicKey) + + private fun master(words: List): DeterministicWallet.ExtendedPrivateKey = + DeterministicWallet.generate(MnemonicCode.toSeed(words, "").byteVector()) +} diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/StoredIdentity.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/StoredIdentity.kt index 016c5e32..9ddca818 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/StoredIdentity.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/identity/StoredIdentity.kt @@ -3,14 +3,10 @@ package mobi.giza.compose.identity import co.touchlab.kermit.Logger import com.vitorpamplona.quartz.nip01Core.core.HexKey import fr.acinq.bitcoin.ByteVector32 -import fr.acinq.bitcoin.MnemonicCode import fr.acinq.bitcoin.PrivateKey import fr.acinq.bitcoin.XonlyPublicKey -import fr.acinq.bitcoin.byteVector -import fr.acinq.lightning.crypto.LocalKeyManager import fr.acinq.phoenix.data.UserWallet import fr.acinq.phoenix.data.WalletId -import fr.acinq.phoenix.managers.NodeParamsManager import fr.acinq.phoenix.managers.nostrPrivateKey import fr.acinq.phoenix.managers.nostrPublicKeyHex import fr.acinq.phoenix.security.NostrCredential @@ -77,16 +73,11 @@ sealed interface StoredIdentity { companion object { /** - * The nostr key a wallet's words derive, at the NIP-06 path. `SeedManager.loadAndDecrypt` - * has already built exactly this key manager to learn the node id, so this is the - * second derivation of it, not a new cost. It is what attaches a seed to its - * credential, and what the credential is repaired from when a seed has none. + * The nostr key a recovery phrase derives, at the NIP-06 path -- see [PhraseKeys]. + * It is what attaches a seed to its credential, and what the credential is + * repaired from when a seed has none. */ - fun nostrPrivateKeyOf(words: List): PrivateKey = LocalKeyManager( - seed = MnemonicCode.toSeed(words, "").byteVector(), - chain = NodeParamsManager.chain, - remoteSwapInExtendedPublicKey = NodeParamsManager.remoteSwapInXpub, - ).nostrPrivateKey() + fun nostrPrivateKeyOf(words: List): PrivateKey = PhraseKeys.nostrPrivateKey(words) /** The x-only public key of [nostrPrivateKeyOf]. */ fun nostrPublicKeyOf(words: List): HexKey = nostrPrivateKeyOf(words).nostrPublicKeyHex() diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/KeyRecoveryScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/KeyRecoveryScreen.kt index a97ea03e..d558a638 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/KeyRecoveryScreen.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/KeyRecoveryScreen.kt @@ -77,9 +77,9 @@ import mobi.giza.compose.ui.theme.spacing /** * Everything that can put this profile back on another phone. * - * A Giza profile is its key: the npub that signs and, for a wallet, the coins - * it holds, both come out of one secret that never leaves the device -- twelve - * words, or a bare nostr key that was signed in with. There is no account to + * A Giza profile is its key: the npub that signs comes out of one secret that + * never leaves the device -- twelve words, or a bare nostr key that was signed in + * with. There is no account to * reset, so this screen is the only thing standing between a lost phone and a * lost identity -- it exists to get the user to take a backup while they still * can. @@ -129,12 +129,10 @@ fun KeyRecoveryScreen( horizontalAlignment = Alignment.CenterHorizontally ) { Text( - // A bare-key identity has no coins to speak of. Exhaustive rather than - // `else`: the `else` here used to mean "mnemonic", and a kind added later - // would have fallen into it and been promised coins. A read-only identity - // is never offered this screen (docs/npub-sign-in.md, Phase 5); it reads - // as the bare-key kind so that, if it ever is, the sentence is at least - // not about a wallet. + // The same sentence for every kind since the wallets went + // (docs/giza-wallet-removal.md); kept exhaustive so a kind added + // later is a decision rather than a fall-through. A read-only identity + // is never offered this screen (docs/npub-sign-in.md, Phase 5). text = when (activeIdentity?.kind) { IdentityKind.NostrSecret, IdentityKind.NostrPublic -> stringResource(Res.string.these_are_your_keys_keep_them_safe_no_wallet) @@ -155,8 +153,8 @@ fun KeyRecoveryScreen( item { // The backup an identity has depends on what it was made from. Twelve words - // for a wallet; for a bare key there is no phrase, and the key is the whole - // backup. Same flags underneath -- they are per identity and mean "this + // for a phrase profile; for a bare key there is no phrase, and the key is the + // whole backup. Same flags underneath -- they are per identity and mean "this // identity's secret is not backed up" for whichever secret it is. when (activeIdentity?.kind) { IdentityKind.NostrSecret -> KeyRecoveryOption( diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SignInScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SignInScreen.kt index 3fdb2898..46b9fdeb 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SignInScreen.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SignInScreen.kt @@ -274,10 +274,10 @@ private fun Confirm( text = stringResource(Res.string.recognised_as_a_recovery_phrase_it_also), style = MaterialTheme.typography.bodyMedium, ) - // A phrase restored here may still be running somewhere else -- in Bennu, - // which shares the derivation, or on another device. Two copies of one - // Lightning wallet sign two versions of one channel, and the older one - // broadcast is a revoked state (docs/giza-rebrand.md, constraint 2). + // A phrase restored here may also be a wallet in Bennu, which shares the + // derivation. Giza runs no node, so the danger of one wallet in two places + // is not Giza's to warn about; what it can say is that nothing but the + // profile comes back here (docs/giza-wallet-removal.md, Phase 6). Text( text = stringResource(Res.string.once_restored_here_stop_using_this_phrase), style = MaterialTheme.typography.bodyMedium, diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SovereignWalletStartupScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SovereignWalletStartupScreen.kt index d18e18d6..e7a8702c 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SovereignWalletStartupScreen.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SovereignWalletStartupScreen.kt @@ -1,7 +1,6 @@ package mobi.giza.compose.ui.composable import androidx.compose.foundation.layout.* -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -41,8 +40,6 @@ import mobi.giza.compose.resources.loading_preferences import mobi.giza.compose.resources.lock_prompt_coming_soon import mobi.giza.compose.resources.opening_profile import mobi.giza.compose.resources.preparing_profiles -import mobi.giza.compose.resources.starting_wallet -import mobi.giza.compose.resources.startup_error import mobi.giza.compose.resources.unlock_to_continue import mobi.giza.compose.ui.view.state.StartupChoice @@ -129,177 +126,126 @@ fun SovereignWalletStartupScreen( } } else -> { - when (val startupState = sovereignWalletStartupViewModel.state.value) { - is mobi.giza.compose.ui.view.model.StartupViewState.Init -> { - // The table is StartupChoice's, where it can be read and - // tested; the one thing decided here is that the saved default - // is only a default when it names a wallet. - var loadingIdentity by remember { - mutableStateOf( - StartupChoice.resolve( - force = forceWalletId, - desired = desiredWalletId, - startImmediately = startWalletImmediately, - identities = availableIdentities, - default = defaultWallet.value as? WalletId, - ) +// The table is StartupChoice's, where it can be read and + // tested; the one thing decided here is that the saved default + // is only a default when it names a wallet. + var loadingIdentity by remember { + mutableStateOf( + StartupChoice.resolve( + force = forceWalletId, + desired = desiredWalletId, + startImmediately = startWalletImmediately, + identities = availableIdentities, + default = defaultWallet.value as? WalletId, ) - } - when (val stored = loadingIdentity) { - null -> { - val profiles by rememberProfilesOf( - publicKeys = availableIdentities.values.map { it.nostrPublicKey }, - nostrRepository = nostrRepository, - ) - mobi.giza.compose.ui.composable.widgets.wallet.WalletsSelector( - wallets = availableIdentities, - walletsMetadata = availableWalletMetadata, - activeWalletId = null, - profiles = profiles, - onWalletClick = { - sovereignWalletViewModel.switchToIdentity( - it.id - ); loadingIdentity = it - }, - canEdit = false, - modifier = Modifier.padding(horizontal = MaterialTheme.spacing.space300), - topContent = { - Spacer(Modifier.height(MaterialTheme.spacing.space800)) - Text( - text = stringResource(Res.string.choose_a_profile), - style = MaterialTheme.typography.headlineSmall - ) - Spacer(Modifier.height(MaterialTheme.spacing.space200)) - }, - bottomContent = { - AddProfileRows( - onSignIn = onNavigateToSignIn, - onCreateProfile = onNavigateToCreateProfile, - caption = false, - ) - // m3-spacing-exempt: room to scroll the - // last row clear of the bottom of the - // window, not a step in the spacing - // rhythm. The scale tops out at 72dp and - // rounding to it would put the last row - // back under the edge. - Spacer(Modifier.height(128.dp)) - } - ) - } - else -> { - val metadata = remember { availableWalletMetadata.getByWalletIdOrDefault(stored.id) } - val dataStoreManager = DataStoreManager( - ctx = sovereignWalletViewModel.phoenixGlobal.ctx, - chain = NodeParamsManager.chain - ) - // The screen-lock gate wraps both kinds. It only ever needed the - // id, to read the lock preferences, so it sits outside the branch - // and a future lock is not something to remember to add twice. - LoadWallet( - identity = stored, - metadata = metadata, - userPrefs = dataStoreManager.loadUserPrefsForWallet(stored.id), - promptScreenLockImmediately = startWalletImmediately, - doLoadWallet = { identity -> - when (identity) { - is StoredIdentity.Mnemonic -> { - // The node starts for the wallet attached to this profile -- - // its preferences, its metadata, the channel watcher -- and no - // longer for the key, which the identity reads from the - // credential the node is handed to cross-check. - sovereignWalletStartupViewModel.startupNode(walletId = identity.id, words = identity.userWallet.words, onStartupSuccess = { - sovereignWalletViewModel.setActiveWallet(stored = identity, business = it) - onSuccessfulStartup.invoke() - }) - } - is StoredIdentity.NostrSecret -> { - // No node to start, so no platformStartupLogic, no - // schedulePlatformLogic and no StartupViewState: the - // identity is active the moment it is read. Setting it - // recomposes into the `activeIdentity != null` branch - // above, which is what reports the startup. - sovereignWalletViewModel.setActiveIdentity( - Identity.signing( - id = identity.id, - kind = IdentityKind.NostrSecret, - nostrPrivateKey = identity.privateKey, - userPrefs = dataStoreManager.loadUserPrefsForWallet(identity.id), - internalPrefs = dataStoreManager.loadInternalPrefsForWallet(identity.id), - business = null, - ) - ) - } - is StoredIdentity.NostrPublic -> { - // Nothing to start and nothing to decrypt: the - // public key is the whole of what the device - // holds, and the identity is active the moment - // it is read, as the nsec branch above is. - sovereignWalletViewModel.setActiveIdentity( - Identity.readOnly( - id = identity.id, - nostrPublicKey = identity.nostrPublicKey, - userPrefs = dataStoreManager.loadUserPrefsForWallet(identity.id), - internalPrefs = dataStoreManager.loadInternalPrefsForWallet(identity.id), - ) - ) - } - } - loadingIdentity = null - }, - // only show back-to-selector button if there's more than one identity - goToWalletSelector = availableIdentities.takeIf { it.size > 1 }?.let { - { loadingIdentity = null; sovereignWalletViewModel.startWalletImmediately.value = false } - } - ) - } - } - } - is mobi.giza.compose.ui.view.model.StartupViewState.StartingBusiness -> { - // The one place the word "wallet" stays: only the branch with - // a wallet attached reaches this state, and what is starting is - // a Lightning node. A bare-key profile never sees it. - LoadingDataIndicator( - text = stringResource(Res.string.starting_wallet) ) } - is mobi.giza.compose.ui.view.model.StartupViewState.BusinessActive -> { - LoadingDataIndicator( - text = stringResource(Res.string.opening_profile) - ) - } - is mobi.giza.compose.ui.view.model.StartupViewState.Error -> { - - Column(horizontalAlignment = Alignment.CenterHorizontally) { - Text( - text = stringResource(Res.string.startup_error) + when (val stored = loadingIdentity) { + null -> { + val profiles by rememberProfilesOf( + publicKeys = availableIdentities.values.map { it.nostrPublicKey }, + nostrRepository = nostrRepository, ) - - when (startupState) { - is mobi.giza.compose.ui.view.model.StartupViewState.Error.Generic -> { - startupState.cause?.message?.let { message -> - Text( - text = message, - ) - } + mobi.giza.compose.ui.composable.widgets.wallet.WalletsSelector( + wallets = availableIdentities, + walletsMetadata = availableWalletMetadata, + activeWalletId = null, + profiles = profiles, + onWalletClick = { + sovereignWalletViewModel.switchToIdentity( + it.id + ); loadingIdentity = it + }, + canEdit = false, + modifier = Modifier.padding(horizontal = MaterialTheme.spacing.space300), + topContent = { + Spacer(Modifier.height(MaterialTheme.spacing.space800)) + Text( + text = stringResource(Res.string.choose_a_profile), + style = MaterialTheme.typography.headlineSmall + ) + Spacer(Modifier.height(MaterialTheme.spacing.space200)) + }, + bottomContent = { + AddProfileRows( + onSignIn = onNavigateToSignIn, + onCreateProfile = onNavigateToCreateProfile, + caption = false, + ) + // m3-spacing-exempt: room to scroll the + // last row clear of the bottom of the + // window, not a step in the spacing + // rhythm. The scale tops out at 72dp and + // rounding to it would put the last row + // back under the edge. + Spacer(Modifier.height(128.dp)) + } + ) + } + else -> { + val metadata = remember { availableWalletMetadata.getByWalletIdOrDefault(stored.id) } + val dataStoreManager = DataStoreManager( + ctx = sovereignWalletViewModel.phoenixGlobal.ctx, + chain = NodeParamsManager.chain + ) + // The screen-lock gate wraps both kinds. It only ever needed the + // id, to read the lock preferences, so it sits outside the branch + // and a future lock is not something to remember to add twice. + LoadWallet( + identity = stored, + metadata = metadata, + userPrefs = dataStoreManager.loadUserPrefsForWallet(stored.id), + promptScreenLockImmediately = startWalletImmediately, + doLoadWallet = { identity -> + when (identity) { + // A key the device holds, from a recovery phrase or pasted + // as an nsec: no node to start (docs/giza-wallet-removal.md, + // Phase 6), so the identity is active the moment it is read. + // Setting it recomposes into the `activeIdentity != null` + // branch above, which is what reports the startup. + is StoredIdentity.Mnemonic -> sovereignWalletViewModel.setActiveIdentity( + Identity.signing( + id = identity.id, + kind = IdentityKind.Mnemonic, + nostrPrivateKey = identity.privateKey, + userPrefs = dataStoreManager.loadUserPrefsForWallet(identity.id), + internalPrefs = dataStoreManager.loadInternalPrefsForWallet(identity.id), + ) + ) + is StoredIdentity.NostrSecret -> sovereignWalletViewModel.setActiveIdentity( + Identity.signing( + id = identity.id, + kind = IdentityKind.NostrSecret, + nostrPrivateKey = identity.privateKey, + userPrefs = dataStoreManager.loadUserPrefsForWallet(identity.id), + internalPrefs = dataStoreManager.loadInternalPrefsForWallet(identity.id), + ) + ) + is StoredIdentity.NostrPublic -> { + // Nothing to start and nothing to decrypt: the + // public key is the whole of what the device + // holds, and the identity is active the moment + // it is read, as the nsec branch above is. + sovereignWalletViewModel.setActiveIdentity( + Identity.readOnly( + id = identity.id, + nostrPublicKey = identity.nostrPublicKey, + userPrefs = dataStoreManager.loadUserPrefsForWallet(identity.id), + internalPrefs = dataStoreManager.loadInternalPrefsForWallet(identity.id), + ) + ) + } + } + loadingIdentity = null + }, + // only show back-to-selector button if there's more than one identity + goToWalletSelector = availableIdentities.takeIf { it.size > 1 }?.let { + { loadingIdentity = null; sovereignWalletViewModel.startWalletImmediately.value = false } } - } - Spacer(Modifier.height(MaterialTheme.spacing.space200)) - HorizontalDivider( - modifier = Modifier.width(50.dp) ) - Spacer(Modifier.height(MaterialTheme.spacing.space300)) -// BorderButton( -// text = stringResource(R.string.startup_error_try_again), -// icon = R.drawable.ic_reset, -// onClick = onTryAgainClick -// ) - Spacer(Modifier.height(MaterialTheme.spacing.space100)) -// StartErrorShareLogsButton() } } - - } + } } } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/wallet/WalletsSelector.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/wallet/WalletsSelector.kt index df4002f2..cde4c274 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/wallet/WalletsSelector.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/wallet/WalletsSelector.kt @@ -51,7 +51,7 @@ import fr.acinq.phoenix.utils.preferences.getByWalletIdOrDefault import mobi.giza.compose.extensions.hexToNpubHrp import mobi.giza.compose.resources.Res import mobi.giza.compose.resources.read_only -import mobi.giza.compose.resources.wallet +import mobi.giza.compose.resources.recovery_phrase import org.jetbrains.compose.resources.stringResource import mobi.giza.compose.database.model.Profile import mobi.giza.compose.identity.StoredIdentity @@ -194,7 +194,7 @@ private fun AvailableWalletView( Text(text = npub, maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.displayMedium.copy(fontFamily = FontFamily.Monospace, fontSize = 12.sp)) } val held = when (identity) { - is StoredIdentity.Mnemonic -> Res.string.wallet + is StoredIdentity.Mnemonic -> Res.string.recovery_phrase is StoredIdentity.NostrPublic -> Res.string.read_only is StoredIdentity.NostrSecret -> null } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/NostrSecretViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/NostrSecretViewModel.kt index 04a1f6da..38af5f24 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/NostrSecretViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/NostrSecretViewModel.kt @@ -186,7 +186,7 @@ class NostrSecretViewModel( _forgetting.value = NostrSecretUIState.Forgetting.Idle withContext(Dispatchers.Main) { onForgotten() } } - is ForgetIdentity.Outcome.WalletAttached, + is ForgetIdentity.Outcome.PhraseAttached, is ForgetIdentity.Outcome.CannotForget -> { _forgetting.value = NostrSecretUIState.Forgetting.Failed } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SignOutViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SignOutViewModel.kt index fcd9f07c..51680ea0 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SignOutViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SignOutViewModel.kt @@ -76,7 +76,7 @@ class SignOutViewModel( _state.value = State.Idle withContext(Dispatchers.Main) { onSignedOut() } } - is ForgetIdentity.Outcome.WalletAttached, + is ForgetIdentity.Outcome.PhraseAttached, is ForgetIdentity.Outcome.CannotForget -> { _state.value = State.Failed } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SovereignWalletStartupViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SovereignWalletStartupViewModel.kt index 812ae238..ab5addf2 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SovereignWalletStartupViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SovereignWalletStartupViewModel.kt @@ -1,73 +1,16 @@ package mobi.giza.compose.ui.view.model -import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory -import co.touchlab.kermit.Logger -import fr.acinq.phoenix.PhoenixBusiness import fr.acinq.phoenix.PhoenixGlobal -import fr.acinq.phoenix.data.StartBusinessResult -import fr.acinq.phoenix.data.WalletId -import kotlinx.coroutines.CoroutineExceptionHandler -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.IO import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.launch -sealed class StartupViewState { - data object Init : StartupViewState() - data class StartingBusiness(val walletId: WalletId) : StartupViewState() - data class BusinessActive(val walletId: WalletId): StartupViewState() - - sealed class Error: StartupViewState() { - abstract val walletId: WalletId - data class Generic(override val walletId: WalletId, val cause: Throwable?): Error() - } -} - class SovereignWalletStartupViewModel( val phoenixGlobal: PhoenixGlobal ): ViewModel() { - private val log = Logger.withTag("SovereignWalletStartupViewModel") - - val state = mutableStateOf(StartupViewState.Init) - - fun startupNode(walletId: WalletId, words: List, onStartupSuccess: (PhoenixBusiness) -> Unit) { - if (state.value !is StartupViewState.Init) { - return - } - - viewModelScope.launch(Dispatchers.IO + CoroutineExceptionHandler { _, e -> - log.e("error when initialising startup-view: ", throwable = e) - state.value = StartupViewState.Error.Generic(walletId = walletId, cause = e) - }) { - state.value = StartupViewState.StartingBusiness(walletId) - - val startResult: StartBusinessResult = - mobi.giza.compose.extensions.platformStartupLogic( - words - ) - - mobi.giza.compose.extensions.schedulePlatformLogic( - phoenixGlobal = phoenixGlobal, - ) - when (startResult) { - is StartBusinessResult.Success -> { - state.value = StartupViewState.BusinessActive(walletId) - launch(Dispatchers.Main) { - onStartupSuccess(startResult.business) - } - } - is StartBusinessResult.Failure.Generic -> state.value = StartupViewState.Error.Generic(walletId = walletId, cause = startResult.cause) - is StartBusinessResult.Failure.LoadWalletError -> state.value = StartupViewState.Error.Generic(walletId = walletId, cause = null) - } - } - } - fun getShowIntroFlow(): Flow { return mobi.giza.compose.extensions.getShowIntroFlow(phoenixGlobal) } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SovereignWalletViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SovereignWalletViewModel.kt index d0337a90..0268320a 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SovereignWalletViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SovereignWalletViewModel.kt @@ -10,7 +10,6 @@ import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory import co.touchlab.kermit.Logger import fr.acinq.lightning.logging.error -import fr.acinq.phoenix.PhoenixBusiness import fr.acinq.phoenix.PhoenixGlobal import com.vitorpamplona.quartz.nip01Core.core.HexKey import fr.acinq.bitcoin.PrivateKey @@ -21,26 +20,20 @@ import fr.acinq.phoenix.data.ElectrumConfig import fr.acinq.phoenix.data.ListWalletState import fr.acinq.phoenix.data.UserWallet import fr.acinq.phoenix.data.WalletId -import fr.acinq.phoenix.managers.DataStoreManager import fr.acinq.phoenix.managers.NostrCredentialManager import fr.acinq.phoenix.security.NostrCredential import fr.acinq.phoenix.managers.nostrPrivateKey import fr.acinq.phoenix.utils.preferences.GlobalPrefs import fr.acinq.phoenix.utils.preferences.UserWalletMetadata import kotlinx.coroutines.CoroutineExceptionHandler -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.IO import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.first -import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import mobi.giza.compose.identity.Identity -import mobi.giza.compose.identity.IdentityKind import mobi.giza.compose.identity.IdentityWriter import mobi.giza.compose.identity.SeedCredentials import mobi.giza.compose.identity.StoredIdentity @@ -57,14 +50,6 @@ sealed class WritingSeedState { } } -expect fun updateBusinessActiveInUI(walletId: WalletId) - -/** - * Stops the node running for [walletId], if one is. The inverse of what the startup - * screen's mnemonic branch starts; an `expect` for the reason [updateBusinessActiveInUI] - * is, which is that `BusinessManager` is a per-platform object. - */ -expect fun stopPlatformBusiness(walletId: WalletId) expect fun loadAndDecryptSeed(phoenixGlobal: PhoenixGlobal): DecryptSeedResult expect fun getAvailableWalletsMeta(phoenixGlobal: PhoenixGlobal): Flow> @@ -81,9 +66,6 @@ expect suspend fun saveAvailableWalletMeta( class SovereignWalletViewModel( val phoenixGlobal: PhoenixGlobal, - // We might end up only using the machankuraWalletRepository in the future where we send the walletId in each request. - /** Injected so that a switch can be pinned in a test without a node to stop. */ - private val stopBusiness: (WalletId) -> Unit = ::stopPlatformBusiness, ): ViewModel() { private val log = Logger.withTag("SovereignWalletViewModel") @@ -121,10 +103,6 @@ class SovereignWalletViewModel( private val _activeIdentity = MutableStateFlow(null) val activeIdentity = _activeIdentity.asStateFlow() - @OptIn(ExperimentalCoroutinesApi::class) - val exchangeRates = phoenixGlobal.currencyManager.ratesFlow - .stateIn(viewModelScope, started = SharingStarted.Lazily, initialValue = emptyList()) - var walletUIState: mobi.giza.compose.ui.view.state.SovereignWalletUIState by mutableStateOf( mobi.giza.compose.ui.view.state.SovereignWalletUIState.Loading) private set @@ -181,44 +159,6 @@ class SovereignWalletViewModel( } } - /** - * Activates a profile with a wallet attached, once its node has started. - * - * The key is the credential's, not the node's. The node still derives it -- and is - * asked to, as a cross-check -- but the credentials file is what the app signs with - * now, and a node that disagrees with it is the one corruption worth refusing to run - * under: the throw lands in the startup view model's handler and shows as a startup - * error. It cannot happen for a file the repair wrote, since that derived the key - * from the same seed. - */ - fun setActiveWallet(stored: StoredIdentity.Mnemonic, business: PhoenixBusiness) { - val walletId = stored.id - val keyManager = business.walletManager.keyManager.value - if (keyManager == null) { - // `startNewBusiness` loads the wallet before it reports success, so a business - // handed here without a key manager is a programming error rather than a state - // to route around. Leaving the identity unset sends the UI back to startup. - log.e { "business for wallet=$walletId started without a key manager" } - return - } - check(keyManager.nostrPrivateKey() == stored.privateKey) { - "the node for wallet=$walletId derives a different nostr key than its credential holds" - } - val dataStoreManager = DataStoreManager(business) - - setActiveIdentity( - Identity.signing( - id = walletId, - kind = IdentityKind.Mnemonic, - nostrPrivateKey = stored.privateKey, - userPrefs = dataStoreManager.loadUserPrefsForWallet(walletId = walletId), - internalPrefs = dataStoreManager.loadInternalPrefsForWallet(walletId = walletId), - business = business, - ) - ) - updateBusinessActiveInUI(walletId) - } - /** * Reads both stores, repairs the credentials file so that every seed's key is in it, * and publishes the merged list, registering metadata for any id seen for the first @@ -378,21 +318,13 @@ class SovereignWalletViewModel( * and the flag was only ever the user saying *show me the list*. Nothing set it back * before because nothing could switch. * - * The identity is cleared **before** the node is stopped: clearing cancels every - * collector that could reach the business, so the stop finds nothing reading it. - * The test is `business != null`, not the kind -- whether the profile being left has - * a node behind it is the fact, and the kind is how it currently comes to be true. - * `previous.id` is the wallet's id when a wallet is attached, which is why the - * manager can take it. + * There is no node to stop behind any profile since docs/giza-wallet-removal.md, + * Phase 6: clearing the identity is the whole of it. */ fun switchToIdentity(id: WalletId) { - val previous = _activeIdentity.value _desiredWalletId.value = id startWalletImmediately.value = true _activeIdentity.value = null - if (previous?.business != null) { - viewModelScope.launch(Dispatchers.IO) { stopBusiness(previous.id) } - } } /** Clears the active identity. It does not affect [desiredWalletId]. The UI may still auto-open a specific wallet, if [desiredWalletId] is not null. */ diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/ForkCompatibilityTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/ForkCompatibilityTest.kt index 69c64705..7992e517 100644 --- a/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/ForkCompatibilityTest.kt +++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/ForkCompatibilityTest.kt @@ -3,12 +3,8 @@ package mobi.giza.compose.managers import fr.acinq.bitcoin.ByteVector32 import fr.acinq.bitcoin.PrivateKey import fr.acinq.secp256k1.Hex +import mobi.giza.compose.identity.PhraseKeys import mobi.giza.compose.identity.StoredIdentity -import fr.acinq.lightning.crypto.LocalKeyManager -import fr.acinq.phoenix.data.WalletId -import fr.acinq.phoenix.managers.NodeParamsManager -import fr.acinq.bitcoin.MnemonicCode -import fr.acinq.bitcoin.byteVector import kotlin.test.Test import kotlin.test.assertEquals @@ -52,23 +48,18 @@ class ForkCompatibilityTest { // NIP-06's own test vector, and the id this app files a recovery phrase's profile under. // - // Pinned through the code docs/giza-wallet-removal.md Phase 6 replaces: lightning-kmp's - // LocalKeyManager, which derives the nostr key at m/44'/1237'/0'/0/0 and the node key the - // id is the hash160 of. Phase 6 derives both without it, and has to land on these values - // byte for byte -- a different npub is a different person, and a different id loses the - // profile's preference files without a word. + // Pinned in Phase 0 through lightning-kmp's LocalKeyManager, which derived the nostr key at + // m/44'/1237'/0'/0/0 and the node key the id is the hash160 of; since Phase 6 through + // PhraseKeys, which derives both without it (docs/giza-wallet-removal.md). The values did + // not move, and must not: a different npub is a different person, and a different id loses + // the profile's preference files without a word. @Test fun `a recovery phrase's npub, profile id and host key`() { val words = PHRASE.split(" ") val secret = StoredIdentity.nostrPrivateKeyOf(words) assertEquals(PINNED_PHRASE_SECRET, secret.value.toHex()) assertEquals(PINNED_PHRASE_NPUB, StoredIdentity.nostrPublicKeyOf(words)) - val nodeId = LocalKeyManager( - seed = MnemonicCode.toSeed(words, "").byteVector(), - chain = NodeParamsManager.chain, - remoteSwapInExtendedPublicKey = NodeParamsManager.remoteSwapInXpub, - ).nodeKeys.nodeKey.publicKey - assertEquals(PINNED_PHRASE_PROFILE_ID, WalletId(nodeId).nodeIdHash) + assertEquals(PINNED_PHRASE_PROFILE_ID, PhraseKeys.profileId(words).nodeIdHash) assertEquals(PINNED_PHRASE_HOST_KEY, ChillDkgRitualManager.deriveHostPublicKey(secret.value.toByteArray()).toString()) } diff --git a/composeApp/src/iosMain/kotlin/mobi/giza/compose/extensions/Phoenix.ios.kt b/composeApp/src/iosMain/kotlin/mobi/giza/compose/extensions/Phoenix.ios.kt index 35d4af80..5d8c0814 100644 --- a/composeApp/src/iosMain/kotlin/mobi/giza/compose/extensions/Phoenix.ios.kt +++ b/composeApp/src/iosMain/kotlin/mobi/giza/compose/extensions/Phoenix.ios.kt @@ -1,28 +1,10 @@ package mobi.giza.compose.extensions -import co.touchlab.kermit.Logger import fr.acinq.bitcoin.Chain import fr.acinq.phoenix.PhoenixGlobal -import fr.acinq.phoenix.data.StartBusinessResult -import fr.acinq.phoenix.ios.BusinessManager import fr.acinq.phoenix.managers.DataStoreManager import fr.acinq.phoenix.utils.preferences.GlobalPrefs -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.withContext - - -actual suspend fun platformStartupLogic( - words: List -): StartBusinessResult { - return withContext(Dispatchers.Main) { - BusinessManager.startNewBusiness(words, isHeadless = false) - } -} - -actual fun schedulePlatformLogic(phoenixGlobal: PhoenixGlobal) { - Logger.withTag("schedulePlatformLogic").e { "schedulePlatformLogic not implemented" } -} actual fun getShowIntroFlow(phoenixGlobal: PhoenixGlobal): Flow { return DataStoreManager( diff --git a/composeApp/src/iosMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.ios.kt b/composeApp/src/iosMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.ios.kt index a2ec7373..2fcfc312 100644 --- a/composeApp/src/iosMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.ios.kt +++ b/composeApp/src/iosMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.ios.kt @@ -4,20 +4,13 @@ import fr.acinq.bitcoin.Chain import fr.acinq.phoenix.PhoenixGlobal import fr.acinq.phoenix.data.DecryptSeedResult import fr.acinq.phoenix.data.WalletId -import fr.acinq.phoenix.ios.BusinessManager import fr.acinq.phoenix.managers.DataStoreManager import fr.acinq.phoenix.managers.SeedManager import fr.acinq.phoenix.utils.preferences.UserWalletMetadata import kotlinx.coroutines.flow.Flow -actual fun updateBusinessActiveInUI(walletId: WalletId) { - BusinessManager.updateBusinessActiveInUI(walletId) -} -actual fun stopPlatformBusiness(walletId: WalletId) { - BusinessManager.stopBusiness(walletId) -} actual fun loadAndDecryptSeed(phoenixGlobal: PhoenixGlobal): DecryptSeedResult { return SeedManager.loadAndDecrypt( diff --git a/composeApp/src/jvmMain/kotlin/mobi/giza/compose/extensions/Phoenix.jvm.kt b/composeApp/src/jvmMain/kotlin/mobi/giza/compose/extensions/Phoenix.jvm.kt index f112dbd4..7f765936 100644 --- a/composeApp/src/jvmMain/kotlin/mobi/giza/compose/extensions/Phoenix.jvm.kt +++ b/composeApp/src/jvmMain/kotlin/mobi/giza/compose/extensions/Phoenix.jvm.kt @@ -1,45 +1,8 @@ package mobi.giza.compose.extensions -import co.touchlab.kermit.Logger import fr.acinq.phoenix.PhoenixGlobal -import fr.acinq.phoenix.data.StartBusinessResult -import fr.acinq.phoenix.jvm.BusinessManager import fr.acinq.phoenix.utils.preferences.GlobalPrefs -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.withContext - -/** - * `Dispatchers.Default`, following android rather than ios -- ios hops to Main, and there is - * no reason for the jvm to start a lightning node on the ui thread. - */ -actual suspend fun platformStartupLogic(words: List): StartBusinessResult { - return withContext(Dispatchers.Default) { - BusinessManager.startNewBusiness(words, isHeadless = false) - } -} - -/** - * **Nothing is scheduled, and that has a consequence worth stating.** - * - * Android schedules two WorkManager jobs here: `ChannelsWatcher`, which wakes periodically - * to check whether a channel has been force-closed while the app was shut, and - * `ContactsPhotoCleaner`. Ios schedules neither and logs that it does not. - * - * The jvm has no equivalent, and not for want of an api -- a desktop application simply has - * no process once its window closes, so there is nothing for a scheduler to wake. Running - * the watcher in-process would be worse than not running it: it would only ever fire while - * the app was already open and watching anyway, which is the case that needs no help. - * - * The exposure is real. A desktop wallet that stays closed past a force-close deadline does - * not notice. Anything that closes it -- a system daemon, a scheduled task -- has to live - * outside this process, which is why this logs rather than pretending. - */ -actual fun schedulePlatformLogic(phoenixGlobal: PhoenixGlobal) { - Logger.withTag("schedulePlatformLogic").w { - "no background scheduling on the jvm target: channels are only watched while the app is open" - } -} actual fun getShowIntroFlow(phoenixGlobal: PhoenixGlobal): Flow { return JvmGlobalPrefs.of(phoenixGlobal).getShowIntro diff --git a/composeApp/src/jvmMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.jvm.kt b/composeApp/src/jvmMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.jvm.kt index acec9b27..37ce6c62 100644 --- a/composeApp/src/jvmMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.jvm.kt +++ b/composeApp/src/jvmMain/kotlin/mobi/giza/compose/ui/view/model/NavigationViewModel.jvm.kt @@ -1,31 +1,21 @@ -// The ios actuals with one import changed: BusinessManager, ported to the library's jvmMain. -// The seed writer that used to be the bulk of this file was byte-identical on all three -// platforms and now lives once, in commonMain, as IdentityWriter.writeMnemonic. +// The ios actuals, with the jvm's own global prefs. The seed writer that used to be the bulk +// of this file was byte-identical on all three platforms and now lives once, in commonMain, +// as IdentityWriter.writeMnemonic. // -// What is left is kept as a copy for the same reason the ported BusinessManager is: sharing -// it means an intermediate source set between iosMain and jvmMain, which is a change to how -// the module is wired rather than to what it does. +// What is left is kept as a copy rather than shared: sharing it means an intermediate source +// set between iosMain and jvmMain, which is a change to how the module is wired rather than to +// what it does. package mobi.giza.compose.ui.view.model import fr.acinq.phoenix.PhoenixGlobal import fr.acinq.phoenix.data.DecryptSeedResult import fr.acinq.phoenix.data.WalletId -import fr.acinq.phoenix.jvm.BusinessManager import fr.acinq.phoenix.managers.SeedManager import fr.acinq.phoenix.utils.preferences.UserWalletMetadata import kotlinx.coroutines.flow.Flow import mobi.giza.compose.extensions.JvmGlobalPrefs - -actual fun updateBusinessActiveInUI(walletId: WalletId) { - BusinessManager.updateBusinessActiveInUI(walletId) -} - -actual fun stopPlatformBusiness(walletId: WalletId) { - BusinessManager.stopBusiness(walletId) -} - actual fun loadAndDecryptSeed(phoenixGlobal: PhoenixGlobal): DecryptSeedResult { return SeedManager.loadAndDecrypt( phoenixGlobal diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/dao/OwnedRequestQueueJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/dao/OwnedRequestQueueJvmTest.kt index 2715e09f..18ea854b 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/dao/OwnedRequestQueueJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/dao/OwnedRequestQueueJvmTest.kt @@ -110,7 +110,6 @@ class OwnedRequestQueueJvmTest { nostrPrivateKey = key, userPrefs = UserPrefs(PreferenceDataStoreFactory.createWithPath { prefsFile("user") }), internalPrefs = InternalPrefs(PreferenceDataStoreFactory.createWithPath { prefsFile("internal") }), - business = null, ) @Test diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/AddProfileFromInsideJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/AddProfileFromInsideJvmTest.kt index 48357bab..9041c8f1 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/AddProfileFromInsideJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/AddProfileFromInsideJvmTest.kt @@ -88,7 +88,7 @@ class AddProfileFromInsideJvmTest { appDir.deleteRecursively() } - private fun sovereign() = SovereignWalletViewModel(phoenixGlobal, stopBusiness = {}) + private fun sovereign() = SovereignWalletViewModel(phoenixGlobal) private fun signInViewModel(sovereign: SovereignWalletViewModel) = SignInToProfileViewModel( nostrRepository = nostrRepository, @@ -105,7 +105,6 @@ class AddProfileFromInsideJvmTest { nostrPrivateKey = stored.privateKey, userPrefs = dataStoreManager.loadUserPrefsForWallet(stored.id), internalPrefs = dataStoreManager.loadInternalPrefsForWallet(stored.id), - business = null, ) } diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/ForgetIdentityJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/ForgetIdentityJvmTest.kt index e5013003..6a8420f9 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/ForgetIdentityJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/ForgetIdentityJvmTest.kt @@ -77,9 +77,9 @@ class ForgetIdentityJvmTest { fun `a profile with a wallet attached is refused before anything else is touched`() = runBlocking { val recorder = Recorder() - val outcome = forget(recorder, IdentityWriter.ForgetNostrCredentialResult.WalletAttached) + val outcome = forget(recorder, IdentityWriter.ForgetNostrCredentialResult.PhraseAttached) - assertEquals(ForgetIdentity.Outcome.WalletAttached, outcome) + assertEquals(ForgetIdentity.Outcome.PhraseAttached, outcome) assertEquals(listOf("forgetNostrCredential"), recorder.effects) } diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/IdentitySwitchJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/IdentitySwitchJvmTest.kt index fb245da8..4e9f0898 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/IdentitySwitchJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/IdentitySwitchJvmTest.kt @@ -4,7 +4,6 @@ import androidx.room3.Room import co.touchlab.kermit.Logger import fr.acinq.bitcoin.PrivateKey import fr.acinq.lightning.Lightning -import fr.acinq.phoenix.PhoenixBusiness import fr.acinq.phoenix.PhoenixGlobal import fr.acinq.phoenix.data.WalletId import fr.acinq.phoenix.jvm.BusinessManager @@ -55,12 +54,6 @@ import kotlin.time.Clock * the identity clears, the machine goes to startup, B is activated the way startup * does -- and a kind 1 queued for A now waits. Switch back, and it goes out. * - * And the one effect a switch has outside the identity flow: the node of the profile - * being left is stopped, once, and only when there was one. The manager is injected as - * a recorder, since a node cannot be started here; a `PhoenixBusiness` can be built - * without one, because everything in it is lazy, and that is enough to make the branch - * true. - * * Then Phase 3's half: every activation saves which profile is open, so that a cold * boot -- a fresh view model over the same directory -- resolves to it without asking; * and a forget tail clears it, so the boot after shows the list. @@ -81,7 +74,6 @@ class IdentitySwitchJvmTest { private val keyA = PrivateKey(Lightning.randomBytes(32)) private val keyB = PrivateKey(Lightning.randomBytes(32)) - private val stopped = mutableListOf() @BeforeTest fun setUp() { @@ -121,7 +113,6 @@ class IdentitySwitchJvmTest { nostrPrivateKey = stored.privateKey, userPrefs = dataStoreManager.loadUserPrefsForWallet(stored.id), internalPrefs = dataStoreManager.loadInternalPrefsForWallet(stored.id), - business = null, ) } @@ -140,7 +131,7 @@ class IdentitySwitchJvmTest { val idA = signIn(keyA) val idB = signIn(keyB) - val sovereign = SovereignWalletViewModel(phoenixGlobal, stopBusiness = { stopped += it }) + val sovereign = SovereignWalletViewModel(phoenixGlobal) withTimeout(15_000) { sovereign.availableIdentities.first { it.size == 2 } } val storedA = assertIs(sovereign.availableIdentities.value[idA]) val storedB = assertIs(sovereign.availableIdentities.value[idB]) @@ -187,39 +178,14 @@ class IdentitySwitchJvmTest { sovereign.setActiveIdentity(activated(storedA)) withTimeout(15_000) { nostrRepository.observeUnsignedNostrEvents(keyA.nostrPublicKeyHex()).first { it.isEmpty() } } - assertEquals(emptyList(), stopped, "bare keys have no node to stop") assertTrue(BusinessManager.businessFlow.value.isEmpty()) } - @Test - fun `leaving a profile with a node behind it stops that node, once`() = runBlocking { - val sovereign = SovereignWalletViewModel(phoenixGlobal, stopBusiness = { stopped += it }) - val dataStoreManager = DataStoreManager(phoenixGlobal.ctx, chain = NodeParamsManager.chain) - val walletId = WalletId("ab".repeat(20)) - val withNode = Identity.signing( - id = walletId, - kind = IdentityKind.Mnemonic, - nostrPrivateKey = keyA, - userPrefs = dataStoreManager.loadUserPrefsForWallet(walletId), - internalPrefs = dataStoreManager.loadInternalPrefsForWallet(walletId), - business = PhoenixBusiness(phoenixGlobal), - ) - val other = StoredIdentity.nostrSecret(keyB).id - - sovereign.setActiveIdentity(withNode) - sovereign.switchToIdentity(other) - withTimeout(5_000) { while (stopped.isEmpty()) delay(20) } - - assertEquals(listOf(walletId), stopped) - assertNull(sovereign.activeIdentity.value) - assertEquals(other, sovereign.desiredWalletId.value) - } - @Test fun `the last profile opened is the one a cold boot resolves, until it is forgotten`() = runBlocking { val idA = signIn(keyA) val idB = signIn(keyB) - val first = SovereignWalletViewModel(phoenixGlobal, stopBusiness = { stopped += it }) + val first = SovereignWalletViewModel(phoenixGlobal) withTimeout(15_000) { first.availableIdentities.first { it.size == 2 } } val storedA = assertIs(first.availableIdentities.value[idA]) val storedB = assertIs(first.availableIdentities.value[idB]) @@ -236,7 +202,7 @@ class IdentitySwitchJvmTest { // A cold boot: a fresh view model over the same directory, nothing desired, // nothing forced, and the user has not asked for the list. - val booted = SovereignWalletViewModel(phoenixGlobal, stopBusiness = { stopped += it }) + val booted = SovereignWalletViewModel(phoenixGlobal) withTimeout(15_000) { booted.availableIdentities.first { it.size == 2 } } val resolved = StartupChoice.resolve( force = null, @@ -263,7 +229,7 @@ class IdentitySwitchJvmTest { @Test fun `switching from nothing, or from a bare key, stops nothing`() = runBlocking { - val sovereign = SovereignWalletViewModel(phoenixGlobal, stopBusiness = { stopped += it }) + val sovereign = SovereignWalletViewModel(phoenixGlobal) val target = StoredIdentity.nostrSecret(keyB).id sovereign.switchToIdentity(target) @@ -271,6 +237,5 @@ class IdentitySwitchJvmTest { sovereign.switchToIdentity(target) delay(500) - assertEquals(emptyList(), stopped) } } diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/IdentityWriterJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/IdentityWriterJvmTest.kt index 301252c7..03e3bdfa 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/IdentityWriterJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/IdentityWriterJvmTest.kt @@ -244,7 +244,7 @@ class IdentityWriterJvmTest { write(first) val other = StoredIdentity.nostrSecret(second) - assertIs( + assertIs( IdentityWriter.forgetNostrCredential(log, phoenixGlobal, other.id, other.nostrPublicKey) ) assertEquals(1, credentials()?.size) @@ -270,7 +270,7 @@ class IdentityWriterJvmTest { // Refused with the wallet's id, not the bare key's: the id the profile is listed under. assertEquals(phrase.walletId, assertIs(write(phrase.nostrKey)).id) assertEquals(phrase.walletId, assertIs(writePublic(phrase.nostrKey)).id) - assertIs( + assertIs( IdentityWriter.forgetNostrCredential(log, phoenixGlobal, id, phrase.nostrPublicKey) ) assertEquals(1, credentials()?.size, "the forget changed nothing") diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/MultipleProfilesRoundTripJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/MultipleProfilesRoundTripJvmTest.kt index b4bf7da5..d4c27c9f 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/MultipleProfilesRoundTripJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/MultipleProfilesRoundTripJvmTest.kt @@ -3,7 +3,6 @@ package mobi.giza.compose.identity import androidx.room3.Room import fr.acinq.bitcoin.PrivateKey import fr.acinq.lightning.Lightning -import fr.acinq.phoenix.PhoenixBusiness import fr.acinq.phoenix.PhoenixGlobal import fr.acinq.phoenix.data.EmptyWalletId import fr.acinq.phoenix.data.WalletId @@ -59,9 +58,8 @@ import kotlin.time.Clock * database with a real key store. * * A is made from a phrase, the way Landing makes the first profile: both files written, - * listed once with a wallet attached. A is opened with a node behind it -- a - * PhoenixBusiness that was never started, which is enough to make it one the switch - * has to stop. B's npub is signed in from inside; the switch stops A's node, B is open + * listed once with the phrase attached. No profile has a node behind it since + * docs/giza-wallet-removal.md, Phase 6. B's npub is signed in from inside; B is open * and read-only, and the machine routes it from its placeholder. A kind 1 queued for A * while B is open waits, and goes out when A is back. C is created from inside as a bare * key, with no node. B and C are forgotten; one profile remains, the default is cleared, @@ -81,7 +79,6 @@ class MultipleProfilesRoundTripJvmTest { private val marmotRepository = DatabaseMarmotRepository(db, scope) private val keyB = PrivateKey(Lightning.randomBytes(32)) - private val stopped = mutableListOf() @BeforeTest fun setUp() { @@ -125,19 +122,17 @@ class MultipleProfilesRoundTripJvmTest { return withTimeout(15_000) { created.await() } } - /** What startup does for each kind, minus the node: a wallet-attached profile gets a business it can stop. */ + /** What startup does for each kind: a key, or a public key -- and no node for any of them. */ private fun activated(stored: StoredIdentity): Identity = when (stored) { is StoredIdentity.Mnemonic -> Identity.signing( id = stored.id, kind = IdentityKind.Mnemonic, nostrPrivateKey = stored.privateKey, userPrefs = dataStoreManager.loadUserPrefsForWallet(stored.id), internalPrefs = dataStoreManager.loadInternalPrefsForWallet(stored.id), - business = PhoenixBusiness(phoenixGlobal), ) is StoredIdentity.NostrSecret -> Identity.signing( id = stored.id, kind = IdentityKind.NostrSecret, nostrPrivateKey = stored.privateKey, userPrefs = dataStoreManager.loadUserPrefsForWallet(stored.id), internalPrefs = dataStoreManager.loadInternalPrefsForWallet(stored.id), - business = null, ) is StoredIdentity.NostrPublic -> Identity.readOnly( id = stored.id, nostrPublicKey = stored.nostrPublicKey, @@ -172,7 +167,7 @@ class MultipleProfilesRoundTripJvmTest { @Test fun `several profiles, both ways, and a boot`() = runBlocking { - val sovereign = SovereignWalletViewModel(phoenixGlobal, stopBusiness = { stopped += it }) + val sovereign = SovereignWalletViewModel(phoenixGlobal) val navigation = NavigationViewModel( activeIdentityStateFlow = sovereign.activeIdentity, initialNavigationUIState = NavigationUIState.Loading(""), @@ -201,14 +196,12 @@ class MultipleProfilesRoundTripJvmTest { sovereign.setActiveIdentity(activated(storedA)) navigation.awaitRoutedTo(storedA.nostrPublicKey) - // B, an npub, signed in from inside: the switch stops A's node; B is open, read-only, and routed. + // B, an npub, signed in from inside: B is open, read-only, and routed. val signedInB = assertIs( signIn.commit(SignInCredential.NostrPublicKey(keyB.nostrPublicKeyHex())) ) val storedB = assertIs(listed(sovereign, 2)[signedInB.id]) sovereign.switchToIdentity(signedInB.id) - withTimeout(5_000) { while (stopped.isEmpty()) delay(20) } - assertEquals(listOf(idA), stopped, "leaving A stopped A's node") sovereign.setActiveIdentity(activated(storedB)) assertIs(navigation.awaitRoutedTo(storedB.nostrPublicKey)) assertTrue(BusinessManager.businessFlow.value.isEmpty(), "nothing was ever started for a public key") @@ -218,19 +211,16 @@ class MultipleProfilesRoundTripJvmTest { delay(3_000) assertEquals(1, notesQueuedFor(storedA.nostrPublicKey).size, "not B's to sign") - // Back to A: routed, and the note goes out. B had no node, so nothing more was stopped. + // Back to A: routed, and the note goes out. sovereign.switchToIdentity(idA) sovereign.setActiveIdentity(activated(storedA)) navigation.awaitRoutedTo(storedA.nostrPublicKey) withTimeout(15_000) { nostrRepository.observeUnsignedNostrEvents(storedA.nostrPublicKey).first { rows -> rows.none { it.kind == 1 } } } - assertEquals(listOf(idA), stopped) - // C, created from inside: a bare key, no node, and the switch stops A's node again. + // C, created from inside: a bare key. val idC = create(sovereign.bareKeyProfileWriter(), "Cy") val storedC = assertIs(listed(sovereign, 3)[idC], "a key, not a second wallet") sovereign.switchToIdentity(idC) - withTimeout(5_000) { while (stopped.size < 2) delay(20) } - assertEquals(listOf(idA, idA), stopped) sovereign.setActiveIdentity(activated(storedC)) navigation.awaitRoutedTo(storedC.nostrPublicKey) assertTrue(BusinessManager.businessFlow.value.isEmpty(), "no node for a bare key") @@ -260,13 +250,13 @@ class MultipleProfilesRoundTripJvmTest { // And A cannot be forgotten: a wallet is attached. assertEquals( - ForgetIdentity.Outcome.WalletAttached, + ForgetIdentity.Outcome.PhraseAttached, ForgetIdentity.forget(activated(storedA), nostrRepository, { sovereign.forgetNostrCredential(it) }, { sovereign.hideIdentityMetadata(it) }), ) // A cold boot: a fresh view model over the same directory. The repair finds nothing // to do, A is listed alone, and startup opens it without asking. - val booted = SovereignWalletViewModel(phoenixGlobal, stopBusiness = { stopped += it }) + val booted = SovereignWalletViewModel(phoenixGlobal) val identities = withTimeout(15_000) { booted.availableIdentities.first { it.isNotEmpty() } } assertEquals(setOf(idA), identities.keys) assertEquals(storedA.privateKey, assertIs(identities[idA]).privateKey, "listed from the credential, not derived") diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/NpubPreviewRoundTripJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/NpubPreviewRoundTripJvmTest.kt index cef518a1..f4052a81 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/NpubPreviewRoundTripJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/NpubPreviewRoundTripJvmTest.kt @@ -201,7 +201,6 @@ class NpubPreviewRoundTripJvmTest { assertEquals(emptyList(), nostrRepository.observeUnsignedNostrEvents(publicKey).first(), "nothing is queued for a signature") assertEquals(emptyList(), db.marmotKeyPackageBundleDao().getAllMarmotKeyPackageBundles(publicKey), "no key package bundle was made") assertNull(db.broadcastNostrEventRequestDao().observeBroadcastNostrEventRequestsByStatus("pending").first(), "nothing is waiting for a relay") - assertNull(identity.business) assertTrue(BusinessManager.businessFlow.value.isEmpty(), "no PhoenixBusiness was started for a public key") } @@ -224,7 +223,6 @@ class NpubPreviewRoundTripJvmTest { nostrPrivateKey = stored.privateKey, userPrefs = dataStoreManager.loadUserPrefsForWallet(stored.id), internalPrefs = dataStoreManager.loadInternalPrefsForWallet(stored.id), - business = null, ) val activeIdentity = MutableStateFlow(identity) NotaryViewModel( diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/NsecRestoreRoundTripJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/NsecRestoreRoundTripJvmTest.kt index 1583da84..b2a311b1 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/NsecRestoreRoundTripJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/identity/NsecRestoreRoundTripJvmTest.kt @@ -37,7 +37,6 @@ import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertIs -import kotlin.test.assertNull import kotlin.test.assertTrue import kotlin.time.Instant @@ -132,7 +131,6 @@ class NsecRestoreRoundTripJvmTest { nostrPrivateKey = stored.privateKey, userPrefs = dataStoreManager.loadUserPrefsForWallet(stored.id), internalPrefs = dataStoreManager.loadInternalPrefsForWallet(stored.id), - business = null, ) val activeIdentity = MutableStateFlow(null) val device = Device(placeholder(identity.nostrPublicKey)) @@ -167,7 +165,6 @@ class NsecRestoreRoundTripJvmTest { } // 6. Nothing Lightning ran. - assertNull(identity.business) assertTrue(BusinessManager.businessFlow.value.isEmpty(), "no PhoenixBusiness was started for a bare key") } } diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/network/relays/RelaysSocketManagerSwitchJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/network/relays/RelaysSocketManagerSwitchJvmTest.kt index 338f4874..066e2c6f 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/network/relays/RelaysSocketManagerSwitchJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/network/relays/RelaysSocketManagerSwitchJvmTest.kt @@ -76,7 +76,6 @@ class RelaysSocketManagerSwitchJvmTest { nostrPrivateKey = key, userPrefs = UserPrefs(prefsStore("user")), internalPrefs = InternalPrefs(prefsStore("internal")), - business = null, ) private fun relays(key: PrivateKey, vararg urls: String) = diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ProfilesScreenJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ProfilesScreenJvmTest.kt index bae9b697..571c612f 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ProfilesScreenJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ProfilesScreenJvmTest.kt @@ -42,9 +42,9 @@ import kotlin.test.assertTrue /** * The switcher, drawn -- Phase 4 of docs/multiple-profiles.md. * - * Three profiles: A, with a wallet attached and open; B, a bare key; C, read only. What + * Three profiles: A, made from a recovery phrase and open; B, a bare key; C, read only. What * is pinned is what each row says before the tap -- the nostr name where the device has - * one and the npub where it does not, *wallet* and *read only* where they apply and + * one and the npub where it does not, *recovery phrase* and *read only* where they apply and * nothing for the plain case -- that the open one sits above the others, and that * tapping another row is exactly one call with its id while tapping the open one is * none. On the unmerged tree throughout, as `ReadOnlyEntrancesJvmTest` explains. @@ -71,7 +71,6 @@ class ProfilesScreenJvmTest { nostrPrivateKey = keyA, userPrefs = UserPrefs(PreferenceDataStoreFactory.createWithPath { prefsFile("user") }), internalPrefs = InternalPrefs(PreferenceDataStoreFactory.createWithPath { prefsFile("internal") }), - business = null, ) /** A has a kind 0; B and C do not. */ @@ -121,10 +120,10 @@ class ProfilesScreenJvmTest { setContent { Screen(viewModel()) } awaitLoaded() - // A by its nostr name, with its npub under it and a wallet attached. + // A by its nostr name, with its npub under it, made from a recovery phrase. onNodeWithText("Alice", useUnmergedTree = true).assertIsDisplayed() onNodeWithText(a.nostrPublicKey.hexToNpubHrp(), useUnmergedTree = true).assertIsDisplayed() - onNodeWithText("Wallet", useUnmergedTree = true).assertIsDisplayed() + onNodeWithText("Recovery phrase", useUnmergedTree = true).assertIsDisplayed() // B and C by their npub, since the device has no kind 0 for either; only C carries a label. onNodeWithText(b.nostrPublicKey.hexToNpubHrp(), useUnmergedTree = true).assertIsDisplayed() onNodeWithText(c.nostrPublicKey.hexToNpubHrp(), useUnmergedTree = true).assertIsDisplayed() diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/CreateSharedKeyViewModelJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/CreateSharedKeyViewModelJvmTest.kt index f8a6bb39..b06c8ff3 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/CreateSharedKeyViewModelJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/CreateSharedKeyViewModelJvmTest.kt @@ -144,7 +144,6 @@ class CreateSharedKeyViewModelJvmTest { nostrPrivateKey = key, userPrefs = UserPrefs(prefsStore("user")), internalPrefs = InternalPrefs(prefsStore("internal")), - business = null, ) ), chatRepository = chatRepository(room), diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModelJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModelJvmTest.kt index fe5a0cd1..c543fb1f 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModelJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModelJvmTest.kt @@ -17,7 +17,6 @@ import kotlinx.coroutines.awaitAll import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.UnconfinedTestDispatcher @@ -179,7 +178,6 @@ class DkgRitualViewModelJvmTest { nostrPrivateKey = key, userPrefs = UserPrefs(prefsStore("user")), internalPrefs = InternalPrefs(prefsStore("internal")), - business = null, ) ), chatRepository = chatRepository, diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/NavigationIdentityRoutingJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/NavigationIdentityRoutingJvmTest.kt index 9d88b952..bc9e9368 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/NavigationIdentityRoutingJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/NavigationIdentityRoutingJvmTest.kt @@ -76,7 +76,6 @@ class NavigationIdentityRoutingJvmTest { nostrPrivateKey = privateKey, userPrefs = UserPrefs(prefsStore("user")), internalPrefs = InternalPrefs(prefsStore("internal")), - business = null, ) /** The same key, held as a public key only: same id, no secret, no node. */ @@ -202,7 +201,6 @@ class NavigationIdentityRoutingJvmTest { assertEquals(signing.nostrPublicKey, readOnly.nostrPublicKey) assertEquals(signing.id, readOnly.id) assertNull(readOnly.nostrPrivateKey) - assertNull(readOnly.business) assertFalse(readOnly.canSign) assertTrue(signing.canSign) assertEquals(IdentityKind.NostrPublic, readOnly.kind) @@ -253,7 +251,6 @@ class NavigationIdentityRoutingJvmTest { nostrPrivateKey = privateKey, userPrefs = prefs, internalPrefs = internal, - business = null, ) } // A read-only kind that nonetheless carries a key. @@ -265,7 +262,6 @@ class NavigationIdentityRoutingJvmTest { nostrPrivateKey = privateKey, userPrefs = prefs, internalPrefs = internal, - business = null, ) } // A signing kind with no key to sign with. @@ -277,7 +273,6 @@ class NavigationIdentityRoutingJvmTest { nostrPrivateKey = null, userPrefs = prefs, internalPrefs = internal, - business = null, ) } // And the factory refuses to build a "signing" read-only identity at all. @@ -288,7 +283,6 @@ class NavigationIdentityRoutingJvmTest { nostrPrivateKey = privateKey, userPrefs = prefs, internalPrefs = internal, - business = null, ) } } diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/NostrSecretViewModelJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/NostrSecretViewModelJvmTest.kt index bc8be598..f80d01eb 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/NostrSecretViewModelJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/NostrSecretViewModelJvmTest.kt @@ -74,7 +74,6 @@ class NostrSecretViewModelJvmTest { nostrPrivateKey = privateKey, userPrefs = UserPrefs(prefsStore("user")), internalPrefs = InternalPrefs(prefsStore("internal")), - business = null, ) private fun viewModel( diff --git a/docs/giza-wallet-removal.md b/docs/giza-wallet-removal.md index bd3ab2c9..1b3af8d9 100644 --- a/docs/giza-wallet-removal.md +++ b/docs/giza-wallet-removal.md @@ -24,7 +24,8 @@ written against `caf1fb18`. | 2 | built. 63 files deleted: the Lightning events, managers, Iceberg, `wallet/lightning/`, the repository, five screens with their view models, states and routes, and the regtest network with its build wiring and its section in `CLAUDE.md`. Its four DAOs go; the entities stay for Phase 5. The 147 strings Phases 1 and 2 left unread go. `jvmTest` 1,440 run, 0 failed, 0 skipped; `m3-audit` floors unchanged | | 3 | built, as **member wallets only** (see below). The member-wallet events (30334, 30335, 30336, 30337), `MemberWalletManager`, `MemberWalletDerivation`, the repository and DAO, five screens with their view models, states and routes, and their 74 strings. `GuardianManager` stops reading member certificates. `jvmTest` 1,311 run, 0 failed (one `IdentitySwitchJvmTest` timeout under the full suite's load, which passes three times in three alone and at baseline) | | 4 | built: the on-chain wallet, its guardians and the subgroup wallet policy, together. `wallet/` (Electrum included), `nostr/wallet/`, the policy and guardian tags, `GroupWalletDerivation`, `GroupWalletManager`, `GuardianDerivation`, `GuardianManager`, `ProposedSpend`, three screens with their view models, states and routes, and FROST's spend half. Every 30332 is filed declined without being read. Certificates and ceremonies carry no wallet tag, and a guarded subgroup's ceremony is filed and not joined (W5). The last `bennu/` derivation tag is gone from the code, and with it the last wallet pins. `jvmTest` 1,148 run, 0 failed | -| 5 | built: `MIGRATION_35_36` drops the sixteen tables, the three columns, the wallets' 32 line types and every signing session over a transaction or a sweep, with their items and messages; `schemas/…/36.json` is committed. The line-type constants and the transcript's arms for them go with the rows. `RemoveWalletsMigrationJvmTest` checks the shape against Room's v36 and the rows kept and deleted. `jvmTest` 1,150 run, 0 failed | Paths below are under +| 5 | built: `MIGRATION_35_36` drops the sixteen tables, the three columns, the wallets' 32 line types and every signing session over a transaction or a sweep, with their items and messages; `schemas/…/36.json` is committed. The line-type constants and the transcript's arms for them go with the rows. `RemoveWalletsMigrationJvmTest` checks the shape against Room's v36 and the rows kept and deleted. `jvmTest` 1,150 run, 0 failed | +| 6 | built. `PhraseKeys` derives a phrase's nostr key and profile id with bitcoin-kmp's `DeterministicWallet` and lands on Phase 0's pins unchanged; `StoredIdentity` and `IdentityWriter` use it. No node starts for any profile: `Identity.business`, `startupNode`, the start-state machine, `platformStartupLogic`, `schedulePlatformLogic`, `updateBusinessActiveInUI` and `stopPlatformBusiness` go, with `LightningApplication`, `BusinessManager.initialize`, the NFC hooks and `POST_NOTIFICATIONS`. Copy that promised funds is reworded, and the switcher's *Wallet* badge says *Recovery phrase*. Android compiles; **the two iOS actuals were edited without an iOS build**. `jvmTest` 1,149 run, 0 failed but the `IdentitySwitchJvmTest` timeout seen in Phase 3 (passes alone) | Paths below are under `composeApp/src/commonMain/kotlin/mobi/giza/compose/` unless they say otherwise. Line numbers were right at that commit; confirm them with a grep before using them. @@ -55,6 +56,9 @@ Where the build chose differently from the phases as written: | `DkgSession.walletPolicy` and `guardianDelay` are dropped in Phase 5 | only `guardianDelay`. `walletPolicy` stays as the `wallet` tag a Bennu ceremony carried, raw, because the join screen reads it to say why Giza does not join a guarded subgroup's ceremony | | `SubgroupManager.refuseKeyState` goes with the policy | it stays, as `WalletRefusal` over the certificate a key state carries; and `WalletRefusal` reads that certificate too, so such a key state is declined out loud rather than dropped | | the `GroupKeyStateManager` gate goes | and nothing replaces it: a certificate's wallet tags decide nothing on a Giza device, so a key state is kept as it came, whatever they say | +| `WalletAttached` gives way: forgetting a phrase profile removes its `seed.dat` entry too, behind a stronger confirmation | **not built.** The refusal stays, renamed `PhraseAttached` for what it now means: the phrase would derive the key again. No screen offers to forget a phrase profile, so making it possible is new UI rather than removal, and is left as a follow-up | +| `KeyRecoveryScreen`'s cloud backup and emergency kit placeholders go, as wallet backups | they stay. They are placeholders for backing up the *profile*; only the copy under them promised coins, and that is reworded | +| the library keeps deriving nothing after Phase 6 | `SeedManager.loadAndDecrypt` in the library still builds a `LocalKeyManager` to name each seed's id while listing. It lands on the same id; Phase 7, which moves `SeedManager` into the app, moves it onto `PhraseKeys` | | a retired kind's arm becomes one line or none | the arms the wallet kinds already have keep writing their own lines until their phases delete them; the fallback catches each kind as its arm goes. `ProtocolKindDispatchJvmTest` asserts no retired kind is ever `unsupported`, at every phase | ## What the wallets are, measured