Files
giza-kmp/docs/scripts/wallet-audit.sh
T
Kgothatso NgakoandClaude Opus 5.5 f367294cb1 feat: a new profile from Landing is backed by a recovery code (recovery-code-v3, Phase 7)
recoveryCodeProfileWriter replaces seedProfileWriter, and
CreateProfileRoute.withWallet becomes withBackup. Nothing in the app
makes words from random bytes any more; wallet-audit fails on
MnemonicCode.toMnemonics outside RecoveryCodeKeys. A code, or its
exported words, restores the same npub and id on an empty device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:27:29 +02:00

73 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# That the wallets stay removed: docs/giza-wallet-removal.md, Phase 8.
#
# docs/scripts/wallet-audit.sh lists the lines that break a rule
# docs/scripts/wallet-audit.sh --check and exits 1 if there are any
#
# Giza keeps no wallet, and Bennu, which it takes fixes from, keeps several. Five rules
# catch one coming back:
#
# 1. a retired kind's number (30331-30337, 30350-30366) in the app's own code. They
# are Bennu's and stay reserved -- RetiredKinds.kt says why. Allowed in that file,
# in the migrations (which have to keep meaning what they meant) and in tests, which
# assert that Giza declines them;
# 2. an import of lightning-kmp (`fr.acinq.lightning`). Nothing in the app needs it;
# 3. a source file named for one of the wallets' own pieces -- the group wallet, the
# Lightning wallet, Iceberg, guardians, member and guarded wallets, spends,
# transactions, Electrum. Named rather than every *Wallet*: the profile pickers under
# widgets/wallet/ and the SovereignWallet* startup kept Phoenix-era names, and the
# files that decline a wallet (WalletRefusal, RemoveWalletsMigration) are about one;
# 4. an amount in sats in a string a person reads;
# 5. a phrase made from random bytes (`MnemonicCode.toMnemonics`) in the app's code. A new
# profile is backed by a recovery code (docs/recovery-code-v3.md), whose 24 words are
# made in RecoveryCodeKeys.kt and nowhere else. Phrases are restored, never made.
#
# Needs only bash and git, like the other two audits, so the CI budgets job can run it.
set -uo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/../.." || exit 1
CHECK=0
[[ "${1:-}" == "--check" ]] && CHECK=1
MAIN=(composeApp/src/commonMain composeApp/src/androidMain composeApp/src/jvmMain composeApp/src/iosMain)
kinds=$(
git grep -nE '\b303(3[1-7]|5[0-9]|6[0-6])\b' -- "${MAIN[@]}" \
':!*/nostr/RetiredKinds.kt' ':!*/database/migrations/*'
)
lightning=$(git grep -nE '^import fr\.acinq\.lightning' -- composeApp)
files=$(
git ls-files composeApp/src \
| grep -E '/(GroupWallet|GroupLightning|Iceberg|Guardian|GuardedWallet|MemberWallet|MemberSend|GroupSend|GroupSpend|GroupTransaction|GroupOnchain|GroupChainClients|StandaloneElectrum|IdentityElectrum|ProposedSpend)[A-Za-z]*\.kt$'
)
sats=$(git grep -niE '>[^<]*\b(sats?|satoshis?)\b' -- composeApp/src/commonMain/composeResources)
phrases=$(git grep -nE 'MnemonicCode\.toMnemonics' -- "${MAIN[@]}" ':!*/identity/recoverycode/RecoveryCodeKeys.kt')
report() {
local title=$1 lines=$2 n=0
[[ -n "$lines" ]] && n=$(printf '%s\n' "$lines" | wc -l)
echo "$title: $n"
[[ -n "$lines" ]] && printf '%s\n' "$lines" | sed 's/^/ /'
total=$((total + n))
}
total=0
report "Retired wallet kinds in the app's code" "$kinds"
report "lightning-kmp imports" "$lightning"
report "Files named for a wallet's pieces" "$files"
report "Amounts in sats in the strings" "$sats"
report "Phrases made from random bytes" "$phrases"
if (( CHECK && total > 0 )); then
echo "Giza keeps no wallet. See docs/giza-wallet-removal.md before bringing one back." >&2
exit 1
fi
exit 0