#!/usr/bin/env bash # JesusOS MAIN Bitcoin wallet V2, original Android Termux only. # Reuses V1 wallet and cryptography; V2 adds private offline backup proof/restore. # No remote seed copies, new logins, wallet custody, sending, or mining start. set -euo pipefail umask 077 wallet="$HOME/jesusos-sovereign-wallet" watch="$wallet/watch.json" main="$wallet/jesusos-sovereign-btc-wallet-v1.mjs" recovery="$wallet/jesusos-sovereign-btc-wallet-recovery-v2.mjs" legacy="$HOME/jesusos-sovereign-btc-wallet-installer-v1.sh" base='https://jesusos.online/_cdn/static' v1sha='640b264d7fd19596ad9d6c35c28471548b9cf6fdbb19ee213109567ea6216e42' v2sha='77c31fe313d86533be66a7c6d09473d4a7db98d05bfea5c9f8f20a73261573d4' echo '=== JesusOS MAIN · sovereign BTC original Android wallet · V2 ===' echo 'No ChatGPT API, bank, exchange, outside login, wallet custody, or mining requirement.' echo 'HeavenCoin, local status 3340, mining relay and reporter are NEVER restarted.' for c in curl node npm sha256sum mktemp; do command -v "$c" >/dev/null || { echo "Required original Termux command missing: $c" >&2;exit 2; } done if [[ -L "$wallet" ]]; then echo 'Refusing symlink wallet directory.' >&2;exit 3;fi if [[ -e "$wallet" && ! -d "$wallet" ]]; then echo 'Unexpected wallet directory type.' >&2;exit 3;fi if [[ -L "$watch" || -L "$main" || -L "$recovery" ]];then echo 'Refusing symlink target in original wallet.' >&2;exit 3;fi tmp='' cleanup(){ if [[ -n "$tmp" ]];then rm -f "$tmp";fi; } trap cleanup EXIT verify_download(){ local url="$1" target="$2" expected="$3" if [[ -f "$target" ]]; then printf '%s %s\n' "$expected" "$target" | sha256sum -c --status || { echo 'Existing source differs from pinned JesusOS build. Preserved, cannot automatically overwrite.' >&2;exit 4; } return fi tmp=$(mktemp "$HOME/.jesusos-btc-XXXXXX") curl --fail --silent --show-error --location --max-time 30 "$url" -o "$tmp" printf '%s %s\n' "$expected" "$tmp" | sha256sum -c --status || { echo 'Source integrity error; NOTHING executed or overwritten.' >&2;exit 4; } chmod 600 "$tmp" mv -n "$tmp" "$target" tmp='' printf '%s %s\n' "$expected" "$target" | sha256sum -c --status || { echo 'Installed source integrity error; stopped safely.' >&2;exit 4; } } # This preserves an already-created original BTC wallet and its public watch file. if [[ ! -d "$wallet" || -f "$watch" ]];then verify_download "$base/jesusos-sovereign-btc-wallet-installer-v1.txt" "$legacy" "$v1sha" echo 'Reusing verified JesusOS wallet V1 bootstrap and pinned crypto libraries.' bash "$legacy" else echo 'Existing wallet directory without watch.json: possible lost wallet or canceled earlier setup.' echo 'No automatic creation of a different wallet. Restore original paper words first if they exist.' fi if [[ ! -d "$wallet" ]];then echo 'Wallet directory absent; no recovery action attempted.';exit 0;fi chmod 700 "$wallet" verify_download "$base/jesusos-sovereign-btc-wallet-recovery-v2.txt" "$recovery" "$v2sha" node --check "$recovery" node "$recovery" --selftest echo if [[ -f "$watch" ]];then node "$recovery" --audit if [[ ! -t 0 ]];then echo 'No interactive terminal for private backup verification; no further action.';exit 0;fi answer='' read -r -p 'Verify ALL 24 paper recovery words locally with hidden input now? Type YES to check, anything else skips: ' answer if [[ "$answer" == 'YES' ]];then node "$recovery" --verify-backup else echo 'Backup verification skipped; existing Bitcoin wallet and services untouched.' fi else echo 'No original watch.json file found. Never replace a lost wallet without checking the paper recovery.' if [[ ! -t 0 ]];then exit 0;fi answer='' read -r -p 'Type RESTORE to recover the ORIGINAL paper-backed wallet, NEW to run owner-approved first-time wallet creation, anything else cancels: ' answer if [[ "$answer" == 'RESTORE' ]];then node "$recovery" --restore elif [[ "$answer" == 'NEW' ]];then echo 'This creates a fresh new BTC wallet only if no earlier wallet funds need recovering.' verify_download "$base/jesusos-sovereign-btc-wallet-installer-v1.txt" "$legacy" "$v1sha" bash "$legacy" else echo 'No wallet created or changed.';fi fi echo 'JesusOS BTC wallet readiness sequence complete. No funds spent, signed, or transferred.'