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