diff --git a/docs/README.md b/docs/README.md index 19115f5e..3b06c5bd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -47,6 +47,7 @@ on purpose ([giza-rebrand.md](./giza-rebrand.md)). | [lightning/README.md](./lightning/README.md) | the remediation plans for the review of the group Lightning wallet — seven findings, one phased plan each, and the order to build them in | | [../testing/regtest/README.md](../testing/regtest/README.md) | running the group Lightning wallet end to end on a regtest network of bitcoind, electrs and two eclair nodes — the prerequisites and ports, where the run's output and eclair's log end up, and what each failure means. Not part of `check` or CI | | [marmot-v2.md](./marmot-v2.md) | bringing the group layer onto the Marmot current profile after the quartz 1.15.2 bump — the nine rules that reach this app, why the room's id and the routing id have to become two values, nine phases from reading both profiles to publishing before applying, and the one fork the library cannot yet settle | +| [giza-wallet-removal.md](./giza-wallet-removal.md) | taking every wallet out of Giza, phased and not yet built. Covers why a Giza member declines a Bennu peer's wallet proposal instead of ignoring or signing it, why the wallet's kinds are retired rather than freed, why a recovery phrase stays as a key backup that has to derive the same npub and id byte for byte, and why the threshold crypto keeps the build tied to the wallet library until the last phase | | [giza-rebrand.md](./giza-rebrand.md) | forking Bennu as Giza under `mobi.giza` — what carries the name, what must not be renamed and why, why the desktop data directory changes first, and how the fork keeps merging from Bennu | Start with the ceremony if you are new to this area; the Marmot notes all assume it. diff --git a/docs/giza-wallet-removal.md b/docs/giza-wallet-removal.md new file mode 100644 index 00000000..6ccbaaea --- /dev/null +++ b/docs/giza-wallet-removal.md @@ -0,0 +1,740 @@ +# Removing the wallets from Giza + +Giza takes out every wallet it inherited from Bennu: + +- the group's on-chain wallet; +- its guardians and the subgroup wallet policy; +- the guarded wallets a group keeps for its members; +- the group Lightning wallet and its Iceberg ceremony; +- the Lightning node that starts behind every profile made from a recovery phrase. + +What is left is a chat app with groups. Those groups hold a FROST threshold key and sign +events with it, and they can still make subgroups. + +This plan is phased. It is **not built**. It was written against `caf1fb18` on +`claude/giza-wallet-removal-plan-2668ff`. 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. + +Read these first: + +- [giza-rebrand.md](./giza-rebrand.md). Its D1 (Giza keeps merging from Bennu) and D2 (one network) + are the two decisions this plan leans on hardest. Its constraint 2 changes meaning once the + node is gone. +- [ceremony-creation.md](./ceremony-creation.md), Phases 7 and 8. This app has removed a feature + before: the nip30303 documents, 103 files and twelve tables. That removal is the template for + the deletion phases here, including its manual migration and its "names only" rows. +- [nsec-sign-in.md](./nsec-sign-in.md) and [multiple-profiles.md](./multiple-profiles.md). They + explain why a profile's key is not the wallet's, and how close the code already is to + treating it that way. + +## What the wallets are, measured + +| area | where | main lines | +|---|---|---| +| wallet events and tags (kinds 30331–30337, 30350–30366; tags `wallet`, `guardian`, `guardian_delay`) | `nostr/wallet/`, `nostr/lightning/`, four files in `nostr/subgroup/` | ~1,740 | +| wallet-only managers: group Lightning (10), Iceberg (2), group wallet (2), guardians (2), member wallets (2) | `managers/` | ~6,140 | +| chains, spends, Electrum, rollouts, Lightning wire | `wallet/`, `wallet/lightning/`, `text/ProposedSpend.kt` | ~2,930 | +| 16 entities, 6 DAOs, 4 repositories, one migration | `database/`, `repository/` | ~1,140 | +| 13 screens, 14 view models, their UI states, 12 routes, 4 widgets | `ui/` | ~7,910 | +| wallet code *inside* shared files (FROST, chat lines, subgroups, DKG, detail screen, nav host) | see [The entanglements](#the-entanglements) | ~2,000 | +| **total** | | **~21,900 of ~92,000** | +| tests: 67 wallet-only files | `commonTest`, `jvmTest` | ~13,250 | +| strings: names only wallet files read, plus wallet strings that shared screens read | `strings.xml` | 306 + ~40 | +| regtest network | `testing/regtest/`, two regtest tests | ~950 | + +About a quarter of the app's main code goes, plus more of its tests than that. + +**The personal node has no screen.** No balance, send or receive in the app reads it. +`SovereignWalletViewModel.loadSovereignData` sets `balanceInSatoshis = 0 // TODO`. The node does +three things: + +1. It is how a recovery-phrase profile's key used to be found. Since + [multiple-profiles.md](./multiple-profiles.md) Phase 1 it is only a cross-check, because the + key is now read from the credentials file. +2. It lends its Electrum client to the group wallets (`wallet/IdentityElectrum.kt:41`). +3. It has side effects: two WorkManager jobs on Android, node event monitors, and payment + notifications. + +Removing it takes nothing away that a person can see. Every cold start loses an Electrum +connection and an LSP connection. + +## The constraints the plan follows + +### 1. The threshold crypto comes in through the wallet library + +ChillDKG, FROST, MuSig2 and Iceberg live in the `threshold` fork of bitcoin-kmp and +secp256k1-kmp. Stock bitcoin-kmp has none of them. `composeApp/build.gradle.kts:54-64` says the +stock secp256k1 "has no ChillDKG module". That fork is reached only through the +`lightning-kmp-app` composite build: + +`settings.gradle.kts` → `:library` → lightning-kmp → bitcoin-kmp → secp256k1-kmp + +The `lightning-kmp-app` dependency cannot simply be dropped, because the group key, which +stays, needs what is at the bottom of it. Phase 7 re-points the build. Until then the +composite build stays and carries what it no longer has to. + +### 2. A recovery-phrase profile's key is a BIP32 derivation through the node's key manager + +The key comes from `StoredIdentity.nostrPrivateKeyOf(words)` (`identity/StoredIdentity.kt:85-89`). +It builds a lightning-kmp `LocalKeyManager` and calls the library's `nostrPrivateKey()`, which +derives NIP-06's `m/44'/1237'/0'/0/0`. The constructor checks an LSP swap-in xpub against the +chain, so even reading a key needs `LSP.from(chain)`. + +The profile's id comes from the node key, not the nostr key: `WalletId(nodeId)`, the hash160 of +the key at lightning-kmp's `nodeKeyBasePath`. That id names the profile's preference files +(`userprefs_.preferences_pb`, `internalprefs_.preferences_pb`) and its saved metadata. + +Both values have to come out **byte for byte** the same after `LocalKeyManager` is gone. If the +npub changes, the person becomes someone else. If the id changes, their preferences are +silently lost. Phase 0 pins both before anything is touched. + +`NodeParamsManager.chain` is a constant, `Chain.Mainnet`, so the derivation has only ever taken +the mainnet branch. The testnet branch (`m/44'/1237'/1'/0/0`) has no profile behind it. + +### 3. Giza and Bennu share a network, and Bennu keeps its wallets + +A group can hold Bennu and Giza members at once (rebrand D2). After this plan, a Bennu member +can still: + +- propose a spend in that group; +- open a guarded wallet for a member; +- start an Iceberg ceremony; +- make a subgroup of a guarded group. + +A Giza member receives all of these and has to do something with them. Three facts decide what +that is: + +- **Today every one of these is checked before it is signed.** + `FrostSigningManager.acceptProposal` (`managers/FrostSigningManager.kt:572-629`) checks: + - that a birth certificate grants exactly the guardian keys this group would grant; + - that a member-wallet certificate is one the group's policy allows; + - that a group-wallet statement matches the parent's decision. + + A Giza device with that code deleted can no longer make any of these checks. +- **A device that signs what it cannot check is a rubber stamp.** In a 2-of-3 group with one + Giza member, that member's approval plus one dishonest Bennu member is a quorum. So the rule + this plan follows is to **fail closed**: Giza declines what it can no longer read, and does not + approve it. +- **A decline is counted, and silence is not.** `DECLINE` (kind 30330) is "one refusal among + however many the key can do without" + (`FrostSigningManager.kt:2855-2867`). A device that ignores a proposal looks like "a phone in a + pocket". A device that declines lets the rest of the group know how many signers are left. + +### 4. A removed kind's number is not free + +The nip30303 removal happened because two features shared kind numbers +([ceremony-creation.md](./ceremony-creation.md), F13). The wallet's kinds are 30331–30337 and +30350–30366. Bennu goes on using them. If Giza ever puts anything else on those numbers, it +collides with every Bennu peer. They are retired, not freed (Phase 1). + +### 5. The tags that stay are the `mantra/` ones + +Every `bennu/…` derivation tag in the app is wallet code. There are twelve: + +- `GroupWalletDerivation.kt:85` +- `GuardianDerivation.kt:89,92` +- `GroupLightningDerivation.kt:48` +- `IcebergDkg.kt:72-76` +- `GroupLightningCoSigner.kt:86` +- `MemberWalletDerivation.kt:58` +- `MemberWalletRequestEvent.kt:87` + +The two that stay are `mantra/shared-key/tweak/v1` (`SharedKeyDerivation.kt:76`) and +`mantra/chilldkg/host-key/v1` (`ChillDkgRitualManager.kt:106`). They derive the room id and the +DKG host key, so the rebrand's warning applies to them unchanged. + +Once the wallet code is gone, `brand-audit.sh` no longer needs its `"bennu/` exception. Taking +the exception out (Phase 8) means a Bennu merge that brings a wallet derivation back fails the +build. + +## The entanglements + +Most of the wallet is in files of its own and goes in one stroke. The work is in the shared files +it was threaded through. + +| shared file | wallet in it | what stays | +|---|---|---| +| `managers/FrostSigningManager.kt` (3,742) | ~970 lines:
- the contiguous spend/sweep block at :668-1556
- inbound dispatch to `acceptSpendProposal` and `acceptSweepProposal` at :416-431
- the three wallet checks in `acceptProposal` at :572-629
- `when(subject)` arms at :1885, :2082, :3044
- `inputIndex` at :2243 | event signing, batch signing, resend, decline | +| `database/model/types/FrostSigningSubject.kt` | `TRANSACTION`, `SWEEP` | `EVENTS` | +| `database/model/ChatMessage.kt` (1,647) | ~400 lines:
- `TYPE_ICEBERG_*`, `TYPE_LIGHTNING_*` and the wallet types
- ten wallet entries in `GROUP_IDENTITY_TYPES`
- `lightningFactKey`
- the notice handlers that call `GuardianManager` and `MemberWalletManager` at :1128-1192
- the wallet arms of `applyInnerEvent` at :1367 and :1456-1620 | every chat, ceremony and signing line | +| `ui/composable/widgets/chat/ChatTranscript.kt` | the Iceberg and Lightning blocks, banner, icons and tints; `onOpenIcebergCeremony`, `onOpenLightningWallet` | the rest | +| `managers/SubgroupManager.kt` | ~150 lines: `guardiansOf`, `walletPolicyOf`, `grantFor`, `refuseCertificate`, and the policy and guardian computation in `proposeBirthCertificate` (:252-306) | subgroup birth, lineage, `refuseKeyState` | +| `nostr/subgroup/SubgroupBirthCertificateEvent.kt` | `GuardianTag`, `WalletPolicyTag`, `parseWalletPolicy`, `parseGuardians` | `certifies()`, which never reads the wallet tags (:232-254) | +| `managers/GroupKeyStateManager.kt` | one gate at :426-438 that drops a key state whose certificate's policy does not read | everything else | +| `managers/ChillDkgRitualManager.kt`, `nostr/dkg/DkgRitualEvents.kt`, `DkgRepository` | the `wallet` and `guardian_delay` tags on a subgroup ceremony's proposal, and their validation and storage | the ceremony | +| `SelectSubgroupAdminsScreen` / view model / state, `DkgJoinApprovalScreen` | `WalletPolicyChooser`, `GuardianDelayChooser`, the policy and delay lines | choosing admins | +| `text/ProposedEvent.kt` | the guardian and policy lines on a certificate (:73-99), and the arms for 30331, 30334, 30337, 30355, 30356, 30363 (:102-205) | the other summaries | +| `FrostSigningScreen`, `FrostSigningViewModel`, `FrostSigningUIState`, `ProposalListViewModel` | `WhatIsBeingSpent`, `WhatIsBeingSwept`, `isSpend`/`isSweep`, `ProposedSpend` | the event review | +| `repository/ChatRepository.kt` and its database implementation | eleven methods (:94-145, :373-405) | the rest | +| `ChatRoomDetailScreen` / view model / state | the wallet-policy label, the on-chain and Lightning rows, `SignedWorkRow`, the member-wallet section and rows, and the copy about losing a Lightning share on removal | the room | +| `ActiveProfileScreen`, `ProfilePreviewScreen` | "wallets your groups guard" | the profile | +| `ChatMessageListViewModel`, `ChatRoomMessagingScreen`, `HomeScreen` | `lightningRepository` threaded through; Lightning asks and Iceberg ceremonies | the list | +| `database/dao/NostrDao.kt` | the Lightning dispatch arms (:1607-1652) | the rest | +| `ui/composable/navigation/GizaNavHost.kt` (1,615) | ~450 lines:
- Electrum, chain clients, on-chain wallets, Lightning nodes and the transaction watcher (:269-357)
- the Lightning and Iceberg destinations (:723-799) and the wallet destinations (:1322-1444)
- `lightningRepository` threaded into five places | navigation | +| `identity/*`, `SovereignWallet*`, `extensions/Phoenix*.kt`, the three `NavigationViewModel` actuals, `GizaApplication`, `MainActivity` | the node's start, stop and scheduling; `Identity.business`; `WalletAttached` | the identity and its stores | + +Unaffected (confirmed): + +- `MarmotInboundManager` +- `LiveSubscriptionManager` +- `ChronicleManager` (it carries no kinds) +- `GroupKeyStateEvent` +- `SharedKeyDerivation` +- `DkgRitualScreen` +- the two `m3-audit` floors: 24 adaptive uses against a floor of 12, and the 2 navigation + components. None of them is in a wallet screen. + +**The rollout flags are not a switch.** `GroupWalletRollout` and `GroupLightningRollout` are +compile-time constants, all `true`. Setting them to false would still leave all of the following +running: + +- the transcript's wallet lines; +- FROST's wallet checks; +- the subgroup policy picker; +- the member-wallet sections, gated only by `couldGuard` in `ChatRoomDetailViewModel.kt:98`; +- `GroupOnchainWallets` and `GroupTransactionWatcher`, which the nav host builds unconditionally + at :300 and :350. + +Phase 1 cannot be "flip the flags". + +## Decisions + +| # | question | recommended | the alternative, and what it costs | +|---|---|---|---| +| W1 | Does Giza keep merging from Bennu (rebrand D1, Phase 9)? | **No.** From the end of Phase 1, Giza **cherry-picks** Bennu's non-wallet fixes instead of merging. | Keep merging. Every Bennu commit to a deleted file becomes a modify/delete conflict. Every Bennu wallet change to a shared file (FROST, chat lines, the nav host, the detail screen) becomes a real conflict. Giza's database also has to stay schema-for-schema with Bennu's, so Phase 5 drops nothing: it keeps the 16 entity classes as a frozen file and leaves the tables empty. | +| W2 | What becomes of the recovery phrase? | **Keep it as a key backup.** Create and restore with twelve words as now. Derive only the NIP-06 key and the old id. Strip every mention of funds from the copy. | nsec only. Simpler, but a Bennu user can no longer move to Giza with the same npub, which is the reason the rebrand kept the tags. Twelve words are also a friendlier backup than an nsec, and NIP-06 is nostr's own standard for them. | +| W3 | A Lightning invoice in a note | **Show it as a link** that opens the device's own wallet (`lightning:` through `UriHandler`). | Keep the decoded card. It needs lightning-kmp's `Bolt11Invoice`, which Phase 7 otherwise drops. Paying from the card is already dead: `NoteActions.onPayInvoice` is never assigned. | +| W4 | A Bennu peer's wallet proposal in a mixed group | **Decline it, with a reason**, and show one line saying Giza does not sign for wallets (constraint 3). | Ignore it. That is silent, so the group waits on Giza. Or keep enough checking code to sign, which keeps most of `GuardianManager`, `GuardianDerivation` and the policy reads, and so most of Phase 3. | +| W5 | Making a subgroup of a group whose certificate says `wallet=guarded` | **Giza does not offer it there**, and says why. A Bennu signer refuses an unguarded child of a guarded parent (`SubgroupManager.kt:401-405`), so the ceremony could never finish. | Offer it and let it fail at signing. | +| W6 | The library | **Replace the composite build** (Phase 7): depend on the bitcoin-kmp `threshold` fork directly, and move the identity storage the app still needs into `composeApp`. | Keep `lightning-kmp-app` and use only its storage. The node, SQLDelight and WorkManager stay in the dependency graph, on Android's manifest merge, and in every build. | +| W7 | The 23 wallet design notes (15, plus the 8 in `lightning/`) | **Move them to `docs/retired/`** with a line at the top saying they describe Bennu's wallets. Take them out of the index. | Delete them. They are the only account of what Bennu peers are doing in a mixed group, which a Giza maintainer will need. | + +The phases below assume the recommended column. Where another choice changes a phase, the phase +says so. + +## Phase 0: before any code + +No behaviour changes in this phase. + +1. **Confirm Giza has not shipped.** Rebrand Phase 7 left the store records undone, and + `versionCode = 1`. If a release has gone out by the time this plan starts, insert a **drain + release** before Phase 1: + - receiving off: no new addresses, invoices, wallets or channel opens; + - send, sweep and close kept; + - a banner with a date; + - the removal ships only after that date. + + Ask everyone who has run a Giza development build with a wallet to empty it now. Phase 5 + drops `MemberWallet` and `GroupLightningSeed`, which hold "the only copy of keys that coins + may sit behind" (`GizaDatabase.kt:537-541`). A group node's channel databases on disk are + left alone, never deleted (Phase 2). +2. **Baseline.** Record: + - the `jvmTest` totals; + - the `m3-audit` report, saved; + - a clean `brand-audit.sh --check`. + + Every later phase compares against these numbers. +3. **Pin the identity, through the code that is about to go.** Add to `ForkCompatibilityTest`, + for one fixed twelve-word phrase: + - the npub, through `StoredIdentity.nostrPublicKeyOf`; + - the profile id, through `WalletId(LocalKeyManager(…).nodeKeys.nodeKey.publicKey)`, whatever + the exact accessor is; + - the DKG host key derived from that npub. + + The values come from today's code, which is the only definition there is. Phase 6 reproduces + them without `LocalKeyManager` and must pass these tests unchanged. +4. **Confirm what a refusal sends.** When `acceptProposal` returns `null` (as at :581 or :594), + find out whether the device publishes a `DECLINE` or just drops the proposal. If it is silent, + Phase 1 adds the decline. Do the same for an Iceberg ceremony proposal: find out whether + kinds 30350–30354 carry a refusal at all. +5. Settle W1–W7. + +## Phase 1: Giza neither offers nor signs a wallet + +**About two days. This is the only phase that changes behaviour.** Phases 2–7 delete code +behind it. Each of them leaves the app doing exactly what it did at the end of this phase, and +this phase's tests are what show that. + +**Retired kinds.** Add `nostr/RetiredKinds.kt`: + +- `WALLET = 30331..30337`; +- `GROUP_LIGHTNING = 30350..30366`; +- the `chain`, `account`, `sweep` and `guarded` tags of a 30332; +- a comment saying the numbers are Bennu's and stay reserved (constraint 4). + +Add a test that asserts no live kind set (`FrostSigningEvents.ALL`, `DkgRitualEvents`, +`ChronicleKinds`, `GroupKeyStateEvent`, `SubgroupBirthCertificateEvent`) overlaps it. The +constants are written out rather than read from the wallet classes, for the reason +`RemoveDocumentsMigration` gives: they must keep their meaning after those classes are deleted. + +**Fail closed.** In `FrostSigningManager.acceptProposal`, before any wallet check runs, decline +(per Phase 0.4) any proposal that meets one of these: + +- its subject is `TRANSACTION` or `SWEEP`, or it is a 30332; +- one of its items rebuilds to a kind in `RetiredKinds`; +- it rebuilds to a 30329 birth certificate carrying any `guardian` tag, or a `wallet` tag other + than `unguarded`. + +Each case gets its own reason. A plain certificate (no wallet tags, or `unguarded`) is still +signed. `certifies()` already ignores the wallet tags. + +Iceberg ceremony proposals are not joined. If that ceremony has a way to refuse, use it; +otherwise the line below is all there is. + +**Lines, not bubbles.** For each kind in `RetiredKinds`, `ChatMessage.applyInnerEvent` writes: + +- for the three statements (30331 group wallet, 30355 Lightning wallet, 30334 member wallet), + one system line: *"%1$s proposed a wallet. Giza doesn't take part in wallets, so you + declined."* +- for everything else, the protocol and wallet traffic, `null`, following the precedent of the + metadata kinds at :1630-1635. + +Without this, once Phase 2 shrinks `GroupLightningEvents.PROTOCOL`, a Bennu operator's traffic +becomes raw-JSON bubbles (`unsupported()`, :1645). + +**Entry points off.** Remove: + +- the two wallet rows, the member-wallet section and the policy label from `ChatRoomDetailScreen`; +- the member-wallet sections from `ActiveProfileScreen` and `ProfilePreviewScreen`; +- the Lightning asks from `ChatMessageListViewModel`; +- `WalletPolicyChooser` and `GuardianDelayChooser` from subgroup creation, which now always + proposes with no wallet tags; +- subgroup creation in a guarded room (W5): the action is shown disabled, with a reason, in + sentence case and from the catalogue. + +In `GizaNavHost`, the nav host stops building `GroupOnchainWallets`, `GroupLightningNodes` and +`GroupTransactionWatcher`. The wallet routes stay registered for now, and nothing navigates to +them. + +**Tests.** These survive every later phase. Phases 2–7 must not edit them, except to remove +imports. + +- A Bennu spend proposal, a guarded certificate and a 30334 are each declined, with the decline + published. +- A plain certificate and a 30326 are still signed. +- Each retired kind gives its line or nothing, and never `unsupported`. +- `ChatRoomDetailScreen` in a room with a group wallet shows no wallet row. + +**Audit.** The budgets can only fall. The new strings are in sentence case and in the catalogue. + +## Phase 2: the group Lightning wallet and Iceberg + +**About two days. It is the largest subtree, and the one that needs the node, the LSP, +SQLDelight and the regtest network.** + +Delete outright: + +- events: `nostr/lightning/*`; +- managers: `managers/GroupLightning*` (10), `IcebergDkg`, `IcebergRitualManager`, + `GroupIcebergTransport`; +- the rest of `wallet/`: `wallet/lightning/*`, `GroupLightningRollout`; +- repositories: `GroupLightningRepository` and its database implementation; +- database: `IcebergCoSigning.kt`, `GroupLightningRecords.kt`, `GroupLightningSeed`, + `IcebergKeySession`, `IcebergParticipantMessage`, and their DAOs; +- UI: the four `GroupLightning*` screens and `IcebergCeremonyScreen`, with their view models, + states and routes. + +Edit: + +- `NostrDao`'s dispatch arms; +- `ChatMessage`: the `TYPE_ICEBERG_*` and `TYPE_LIGHTNING_*` constants, `lightningFactKey`, and + the arms; +- `ChatTranscript`'s blocks; +- the `lightningRepository` threading through Home, chat, the list view model and the nav host; +- the removal copy on the detail screen (:207, :732-735); +- `GroupSignedEventDao.observeCountByChatRoomIdAndKind` and + `ChatMessageDao.getLightningFactLine`, which only the node used; +- the nav host's group node databases (:324-327). Stop opening them. **Do not delete the files**: + if Phase 0 found a node with channels, they are its state. + +The entity classes stay declared until Phase 5, so the schema does not move here. Only their DAOs +and readers go. Under W1's alternative they stay for good. + +**Existing chat rows keep their types as names only.** Follow the `TYPE_LEGACY_GROUP_*` +precedent (`ChatMessage.kt:484-502`): a type missing from `GROUP_IDENTITY_TYPES` renders as a +chat bubble. Phase 5 may delete the rows. Until then they stay system lines. + +Tests: + +- **Delete** the group-Lightning, Iceberg, co-signing, liquidity and sweep tests, plus + `FakeGroupNode`, `GroupLightningRegtestJvmTest`, `LiquidityPurchaseRegtestJvmTest` and + `LightningProtocolLinesMigrationJvmTest`. The migration itself stays, because a migration is + history. +- **Re-fixture** the four UI tests that pass `NO_OP_GROUP_LIGHTNING_REPOSITORY`: `ChatPaneLayout`, + `ChatPaneSelection`, `NavigateBackButton` and `ReadOnlyEntrances`. +- **Edit** `ProtocolKindDispatchJvmTest` (:189-212) to assert the Phase 1 behaviour instead. +- **Delete** `testing/regtest/` and its wiring in `composeApp/build.gradle.kts:388-393`. +- Take the regtest section out of `CLAUDE.md`, and the regtest row out of the docs index. + +## Phase 3: member wallets, guardians and the subgroup wallet policy + +**About two days. The most entangled phase: subgroups stay, and they carried the policy.** + +Delete outright: + +- events: `nostr/wallet/{MemberWallet*, GuardedWalletNoticeEvent, GroupKeyNoticeEvent}`. + `GroupKeyNoticeEvent`'s name is generic, but its only use is member-wallet keys; +- tags: `nostr/subgroup/{SubgroupWalletPolicy, tags/WalletPolicyTag, tags/GuardianTag, + tags/GuardianDelayTag}`; +- managers: `GuardianManager`, `GuardianDerivation`, `MemberWalletManager`, + `MemberWalletDerivation`; +- repositories: `MemberWalletRepository` and its database implementation, `MemberWalletDao`; +- UI: the five member-wallet screens with their view models, states and routes; + `PersonGuardedWallets`, `GuardianDelayInput`, `GuardianDelayChooser`, `DelayText`. + +Edit: + +- `SubgroupManager`: the ~150 lines listed above. `refuseCertificate` goes. Phase 1's decline + already covers what it guarded. +- `SubgroupBirthCertificateEvent`: assembly writes no wallet tags. `parseWalletPolicy` and + `parseGuardians` go. +- `GroupKeyStateManager:426-438`: the gate goes. A certificate whose policy Giza cannot read is + one Giza takes no wallet decision from, so there is nothing for the gate to protect. + Certificates already stored still verify, because the signature covers whatever tags they + carry. +- `ChillDkgRitualManager`, `DkgRitualEvents`, `DkgRepository`: a Giza proposal sends no `wallet` + or `guardian_delay` tag. An *inbound* proposal that carries them gets the same treatment as + W5. Giza does not join a ceremony for a guarded child it would then have to refuse to certify. + Say so in the join screen rather than failing at round 2. +- `DkgJoinApprovalScreen`: drop the policy and delay lines. +- `ChatMessage`: the notice handlers at :1128-1192 and the wallet arms. +- `ChatRepository`: the guardian and member-wallet methods among its eleven. +- `text/ProposedEvent.kt`: the certificate's guardian and policy lines. + +Tests: + +- **Delete** the member-wallet, guardian, guarded-notice, `GroupKeyNotice` and + `GuardingGroupName` tests, and `LineageExample`. +- **Cut the wallet cases** out of these, rather than deleting the files: + - `SubgroupManagerJvmTest` (~17 of 41); + - `SubgroupCeremonyInParentRoomTest` (~7 of 18); + - `SubgroupBirthCertificateEventTest` (~5 of 19); + - `SelectSubgroupAdminsViewModelJvmTest` (~12 of 15; what is left may be thin enough to fold + into another test); + - `GroupKeyStateTest` (:899-911). +- **Keep** one test that a stored certificate *with* guardian tags still certifies, so that + removing the parsing never turns into refusing Bennu's certificates. +- **Strip** the member-wallet helpers from `GroupFixtures` (:74-86). +- `StringCatalogueJvmTest` (:81-89): the delay plurals go with their strings. + +## Phase 4: the group's on-chain wallet, and FROST back to events only + +**About two days.** + +Delete outright: + +- `nostr/wallet/GroupWallet*`; +- `managers/GroupWalletDerivation` and `GroupWalletManager`; +- in `wallet/`: `GroupOnchainWallet(s)`, `GroupSpend`, `GroupSpendBuilder`, + `GroupTransactionWatcher`, `GroupChainClients`, `IdentityElectrum`, `StandaloneElectrum`, + `GroupWalletRollout`. That empties `wallet/`; +- `text/ProposedSpend.kt`; +- the `GroupTransaction` DAO; +- UI: `GroupWalletScreen`, `GroupWalletAddressesScreen` and `GroupSendScreen`, with their view + models, states and routes. + +Edit: + +- `FrostSigningManager`: the spend and sweep block (:668-1556) and every `when(subject)` arm. + `FrostSigningSubject` keeps only `EVENTS`, under W1's recommendation. Phase 5 removes the old + rows, so the enum converter never meets a name it cannot read. +- `FrostSigningRepository` (:236-274, :343-364) and its database implementation (:137-205). +- `FrostSigningScreen`, `FrostSigningViewModel`, `FrostSigningUIState`, + `ProposalListViewModel`. +- The rest of `ChatRepository`'s eleven methods. +- `ChatMessage`'s 30331 arm. Phase 1 already turned the inbound one into a line. +- `fr.acinq.bitcoin.Chain` imports in the chat and FROST repositories. +- The dead `extensions/Credentials.kt` `urlToLnUrlHrp`, and the never-wired `NoteActions.onZap` + and `onPayInvoice`. + +Zap *receipts* (the `Zap` entity, kind 9735) stay. Other people's zaps are social data, not a +wallet. + +`readableContent()` and the 48dp rule are unaffected. Only whole screens leave. + +Tests: delete the group-wallet, spend, address, transaction-watcher and Electrum tests, and +`FakeElectrum`. `GroupSignedWorkRowsJvmTest` tests only the two detail rows that are now gone, so +it goes too. Re-fixture `ChronicleEventTest` (:190-191) and `ChronicleAssemblyJvmTest` (:444), +which use 30331 as their example of a kind the chronicle refuses. Any kind in `RetiredKinds` +does the same job, and says why it is refused better. + +**Audit:** both floors are unchanged. Record the budgets. + +## Phase 5: schema 35 → 36 + +**Half a day. Only under W1's recommendation. Under the alternative, skip this phase and keep +the entity classes, so that the schema stays Bennu's.** + +The migration is `MIGRATION_35_36`, written by hand, modelled on `RemoveDocumentsMigration`, with +the kinds and type names written out: + +1. Delete `ChatMessage` rows of the wallet, Iceberg and Lightning types. +2. Delete `FrostSigningSession` rows whose `subject` is not `EVENTS`. `GroupTransaction` and the + items cascade. +3. Drop the 16 tables, children before parents: + - the seven Iceberg co-signing tables; + - the three Lightning record tables; + - `IcebergParticipantMessage`, `IcebergKeySession`, `GroupLightningSeed`; + - `MemberWalletSpend`, `MemberWallet`; + - `GroupTransaction`. +4. Drop the columns `FrostSigningItem.inputIndex`, `DkgSession.walletPolicy`, + `DkgSession.guardianDelay` and `ChatMessage.lightningFactKey`. `DROP COLUMN` is safe for the + reason `RemoveDocumentsMigration` gives: the bundled SQLite. Check that none of these columns + is in an index or a foreign key; SQLite refuses to drop one that is. + +Once the rows are gone, the "names only" type constants from Phase 2 can go too. + +`GroupSignedEvent` keeps any rows of wallet kinds, as it kept the document kinds. Deleting what a +group signed is not this migration's call. + +Tests: a migration test from a 35 fixture with rows in every dropped table and every deleted +chat type. The schema JSON for 36 is committed. Afterwards, check that `GizaDatabase`'s version +and the newest file in `schemas/` agree, which is the check the rebrand asks for. + +## Phase 6: the node behind a recovery phrase + +**About a day and a half.** + +The identity keeps its kinds: `Mnemonic`, `NostrSecret` and read-only. Each comes from its own +store as now. What goes is `Identity.business`, and everything that starts, stops or schedules a +node. + +- **Derivation.** `StoredIdentity.nostrPrivateKeyOf(words)` derives with bitcoin-kmp's + `DeterministicWallet` from `MnemonicCode.toSeed(words, "")`. NIP-06's path is hard-coded for + mainnet; constraint 2 says why that is not a narrowing. The node id is derived the same way + for `WalletId`. **Phase 0's pins must pass unchanged.** If they don't, this phase stops. +- **Delete:** + - `SovereignWalletStartupViewModel.startupNode`; + - `extensions/Phoenix.kt` and its three actuals; + - `updateBusinessActiveInUI`, `stopPlatformBusiness`; + - the cross-check in `setActiveWallet`; + - `exchangeRates`; + - the `PhoenixBusiness` field. + + `switchToIdentity`'s "stop the node" branch goes too, so a switch is just the restart + multiple-profiles describes. +- **Android:** + - `GizaApplication` no longer implements `LightningApplication` and no longer calls + `BusinessManager.initialize`. + - `MainActivity` drops `NFCActivity` and `stopHceService`; the service was never declared. + - The manifest drops `POST_NOTIFICATIONS`, since only the node posted notifications. Merged + entries from WorkManager go once Phase 7 removes the library. +- **Desktop and iOS:** the `BusinessManager` actuals go. `JvmKeyStore` and the passphrase gate + stay. They protect the credentials, not a wallet. +- **`WalletAttached`:** forgetting a phrase-backed profile was refused because "a key with a + wallet attached has funds behind it". With no wallet, forgetting is the same as for an nsec, + plus the phrase's entry in `seed.dat`. Keep the confirmation stronger than for an nsec: the + words are the only backup, and forgetting a profile on its last device loses it. Say exactly + that. +- **Copy:** + - `starting_wallet`, the "Wallet" badge in `WalletsSelector`, and the restore warning about + running one seed in two apps all go. + - The two-apps warning now says only that Bennu's wallet for this phrase stays in Bennu. + - The ~30 recovery-phrase strings that promise funds or coins are reworded, among them + `i_understand_that_if_i_lose_this_phone_and`, `download_and_securely_store_everything` and + `these_are_your_keys_keep_them_safe_so_they`. + - `KeyRecoveryScreen`'s cloud backup and emergency kit placeholders go. They were wallet + backups. +- **Keep:** + - `WalletId`, the name and the id rule: multiple-profiles refused to rename it, for reasons + that still hold; + - the preference files and `DEFAULT_WALLET_ID`; + - `seed.dat`'s format. + + Renaming any of these would turn a deletion into a migration of everyone's preferences. + +Tests: identity tests that built a `PhoenixBusiness` "that was never started, which is enough +for the switch to have something to stop" lose that half. The `NavigationIdentityRouting`, +`IdentitySwitch` and `MultipleProfilesRoundTrip` assertions about the node become assertions +that nothing was started. + +## Phase 7: off the `lightning-kmp-app` composite + +**Three to four days, and the only phase with real build risk. It can be scheduled on its own, +any time after Phase 6.** + +What the app still takes from the library, all of it storage: + +| keep, moved into `composeApp` under `identity/storage/` | why it must stay byte-identical | +|---|---| +| the `keyStoreEncryption` / `keyStoreDecryption` expects, with the Android `KeystoreHelper`, the JVM `JvmKeyStore` (BouncyCastle Argon2) and the iOS `KeyChainHelper` / `CCCipher` actuals | the alias `PHOENIX_KEY_NO_AUTH` and the iOS keychain service `Machankura` encrypt every file a profile has | +| `NostrCredentialManager`, `NostrCredential`, `EncryptedNostrCredentials`, `LegacyNostrKeysFile`, `EncryptedNostrKeys`, `Decrypt*Result` | the file names and formats of `nostr-credentials.dat` and `nostr-keys.dat` | +| `SeedManager` (read, write, `getDatadir`), `EncryptedSeed`, `MnemonicLanguage` | `node-data/seed.dat` | +| `DataStoreManager`, `GlobalPrefs`, `UserPrefs`, `InternalPrefs`, with the preference-path actuals | the `*.preferences_pb` names. Drop only the wallet keys (fiat, units, Electrum, LSP, liquidity, swap, FCM) | +| `AtomicFileWrite`, `DecryptionFailure`, the `TechnicalExtensions` actuals, `PlatformContext` | used by all of the above | +| `Parser.parseEmailLikeAddress` | NIP-05 in `StartDirectMessageToNpubOrNip05Dialog.kt:144` | + +Each moved file keeps its package. `fr.acinq.phoenix…` stays `fr.acinq.phoenix…` under +`composeApp/src/*/kotlin/fr/acinq/phoenix/`, with the GPL notice and a comment saying where it +came from. Renaming the packages would only make the move harder to review, and nothing outside +reads them. A later, separate change can rename them. + +**The build:** + +1. Bring the bitcoin-kmp `threshold` fork in as its own submodule. Today it sits at + `lightning-kmp-app/experimental/lightning-kmp/experimental/bitcoin-kmp`, three submodules + deep. Point `includeBuild` at it, with the substitution for + `fr.acinq.secp256k1:secp256k1-kmp-jni-android` that bitcoin-kmp's own settings already + declare. +2. Keep the `isMacOsX` iOS gate (`composeApp/build.gradle.kts:32-48`). secp256k1-kmp's cinterop + is why it exists, not lightning-kmp. +3. Drop: + - `implementation("fr.acinq.phoenix:lightning-kmp-app:1.0.0")` and its `includeBuild`; + - the SQLDelight runtime, coroutines extensions and drivers, which only Phoenix's databases + used; + - the dead catalogue entries `libs.lightning.kmp.core` and `libs.plugins.sqldelight`. +4. W3: `ContentSegment.LightningInvoiceSegment` keeps the bolt11 regex (`Constants.kt:27`) and + loses the decode. `LightningInvoiceCard` becomes a link. +5. Check that `fr.acinq.lightning` returns no results. The only `fr.acinq.phoenix` imports + should be the moved files. + +**Checks:** + +- `./gradlew check` on Linux. +- An Android debug build installed over a Phase 6 build. The same profiles must open: this + proves the keystore and file names. +- A desktop build opening a Phase 6 data directory. +- **An iOS build on a Mac.** The rebrand could not do one on Linux, and this phase changes the iOS + keychain code's home. Until a Mac build passes, this phase is not done. +- Read the merged Android manifest. WorkManager's `SystemJobService` and `InitializationProvider` + should be gone. + +## Phase 8: documents and guards + +**A day.** + +- **`docs/`.** Move the wallet notes to `docs/retired/` (W7): + - group-chain-wallet, group-send-an-amount, group-wallet-addresses, group-wallet-guardians; + - subgroup-wallet-policy, member-wallet-delay, guardian-delay; + - member-guarded-wallets, guarded-wallet-forwarding, member-wallet-guarding-group, + guarded-wallet-funding; + - standalone-electrum; + - group-lightning-wallet, group-lightning-transcript, group-lightning-liquidity, and + `lightning/`. + + Each gets one opening line: *Describes Bennu's wallets, which Giza removed; see + giza-wallet-removal.md.* The index loses their rows and gains a "Retired" paragraph that + points at the folder. + + Notes that only *mention* wallets get a sentence where they would now mislead: + - subgroups and shared-key-derivation; + - frost-batch-signing (its PSBT half); + - nsec-sign-in and multiple-profiles (the node); + - jvm-target; + - giza-rebrand (constraint 2, Phase 8's mixed-wallet row, Phase 9 per W1). +- **`README.md`.** Drop the four wallet bullets: group wallet, guardians, group Lightning, and "A + wallet of your own". Profiles lose "over Tor and use its own Electrum server", since nothing + that remains connects to Electrum. +- **`CLAUDE.md`:** + - "The app is Giza" now names only the `mantra/` tags; + - the regtest block is already gone from Phase 2; + - the screen count ("43 screens") is updated in it and in + `material-design-conformance.md`. +- **`brand-audit.sh`.** Remove the `"bennu/` exception. The two `mantra/` tags were never covered + by it. +- **`docs/scripts/wallet-audit.sh --check`, wired into `check` and CI** beside the brand guard. + It fails on any of: + - a kind in `RetiredKinds` outside `RetiredKinds.kt`, the migrations and the tests that assert + the decline; + - an import of `fr.acinq.lightning`; + - a file named `*Wallet*`, `*Lightning*`, `*Iceberg*` or `*Guardian*` under `composeApp/src`, + except `widgets/wallet/` (profile pickers, kept) and `WalletId`; + - the strings `sats` or `satoshi` in `strings.xml`. + + Like the brand guard, it exists so that a cherry-pick from Bennu that brings a wallet back + fails the build rather than shipping. +- **`ForkCompatibilityTest`.** Drop the five wallet pins (:53-105). Keep the host-key and + shared-key pins and Phase 0's identity pins. + +## Phase 9: the two apps together, again + +**Half a day on devices.** It replaces rebrand Phase 8's wallet rows. + +| check | passes when | +|---|---| +| a Bennu seed restored in Giza | same npub and same DKG host key, and no Electrum or LSP connection at start (read it in the log) | +| a mixed 2-of-3 group with one Giza member, where Bennu proposes a spend | Giza shows one line and declines; the two Bennu members still spend | +| the same group, where Bennu opens a guarded member wallet | Giza declines the certificate, and the Bennu pair certifies it | +| a Bennu operator's Lightning wallet in a mixed room | no raw-JSON bubble on the Giza device, in a session of an hour | +| a subgroup of a guarded Bennu group | Giza does not offer it; a Bennu-proposed one shows Giza's reason at the join screen | +| a subgroup of an unguarded group, with all members on Giza | certified, carrying no wallet tag, and Bennu members of the parent sign it | + +Under W1's recommendation, rebrand Phase 9 becomes a cherry-pick procedure: + +```bash +git cherry-pick -x +``` + +```bash +docs/scripts/giza-rename.sh +``` + +Then `./gradlew check`, which now includes the wallet guard. A Bennu commit that adds a schema +version is ported by hand under Giza's next number, never merged. + +## What this does not do + +- **It does not change the protocol.** The kinds are retired, not reused. The `mantra/` tags are + untouched. A Bennu peer sees a Giza member who declines wallets, not a stranger. +- **It does not move a group's funds.** A Bennu group that holds coins and has Giza members keeps + them. If honest Bennu signers fall short of the threshold, the coins wait. A Giza member's + FROST share lives in Giza's database, and restoring the phrase in Bennu does not bring it + along. That is in Risks. +- **It does not touch Bennu.** Bennu could show "this member's app doesn't sign for wallets" + rather than a bare decline. That would be Bennu's change, and is not planned here. +- **It does not remove the FROST key, ChillDKG, subgroups or the chronicle.** A group's threshold + key still signs its events and certifies its children. +- **It does not delete files on disk:** `seed.dat`, a node's channel databases, the group nodes' + `group-*` databases. Phase 5 drops tables. Files that might be a node's state are left for the + person to remove. + +## Order and size + +| phase | needs | size | +|---|---|---| +| 0 | — | half a day, plus the decisions | +| 1 | 0 | 2 days | +| 2 | 1 | 2 days | +| 3 | 1 | 2 days | +| 4 | 1; 3 first if both edit `ChatRepository` at once | 2 days | +| 5 | 2, 3, 4 | half a day | +| 6 | 0 (its pins) | 1.5 days | +| 7 | 2, 4, 6 | 3–4 days, plus a Mac | +| 8 | 7 for the wallet guard's import rule; the docs moves can go any time after 1 | 1 day | +| 9 | 8, and a Bennu build | half a day | + +About two and a half weeks. + +- **Phase 1 is one change and lands first.** It is the only one a person can see, and the + phases after it are only correct if it has already landed. +- **Phases 2, 3 and 4 are mostly separate files.** They meet in `ChatMessage.kt`, + `ChatTranscript.kt`, `ChatRepository.kt`, `GizaNavHost.kt` and `FrostSigningManager.kt`. + Land them one after another. Running them at the same time would cost more in conflicts than + it saves. +- **Phase 6 can run beside 2–4.** It touches identity, startup and the platform shells, which + none of them do. +- **Phase 7 is the one to keep on its own branch until the iOS build passes.** + +## Risks and open questions + +- **A wallet group that needs its Giza members.** Most of the "does not do" list follows from + W4, and this is its cost. A Bennu group whose threshold needs a Giza member's share cannot + spend while that member stays on Giza, and the share cannot move to Bennu. Phase 1's line + should say this where it matters: *"With you declining, this group can't reach its threshold + of %1$d."* Whether that sentence is worth the threshold arithmetic in the transcript is open. + No mixed group exists today, because Giza has not shipped. +- **Old Giza builds.** A Giza development build from before Phase 1, in a group with a + post-Phase 1 Giza device, is a Bennu peer for every purpose here. Nothing extra is needed. +- **Phase 0.4's answer.** If refusals are silent today, Phase 1 grows by the decline. If the + Iceberg ceremony has no refusal, a Bennu ceremony with a Giza participant waits until it times + out. Confirm how long that is, and say it in the line. +- **W1 decides more than it looks.** If Giza keeps merging, Phase 5 goes and the entity classes + stay. Phases 2–4 also get harder to keep, because every Bennu wallet change to a shared file + arrives as a conflict in code Giza has already removed. Make this decision first, and on + purpose. +- **`LocalKeyManager`'s node-key path.** Phase 6 rebuilds the id from a path read out of + lightning-kmp (`nodeKeyBasePath`, `m/50'/0'` on mainnet, then the node key under it). Phase 0 + pins the *result* so that Phase 6 cannot get the path subtly wrong and still pass. +- **iOS was not built on Linux**, as in the rebrand. Phases 6 and 7 change `iosMain` and are not + done until an Xcode build passes.