Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
docker/lnd
docker/lnurl-server-data
docker/lnurl-server/data
docker/.trezor-user-env
artifacts
WARP.md
.ai
Expand Down
129 changes: 129 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,137 @@ BACKEND=local ./scripts/build-ios-sim.sh
BACKEND=regtest ./scripts/build-ios-sim.sh
```

Optional Trezor Bridge support is disabled by default and can be enabled per build:

```bash
# Android emulator, local backend
TREZOR_BRIDGE=true ./scripts/build-android-apk.sh

# Android physical device, local backend
TREZOR_BRIDGE=true TREZOR_BRIDGE_URL=http://127.0.0.1:21325 ./scripts/build-android-apk.sh

# Android emulator, staging regtest backend
BACKEND=regtest TREZOR_BRIDGE=true ./scripts/build-android-apk.sh

# iOS simulator, local backend
TREZOR_BRIDGE=true TREZOR_ELECTRUM_URL=tcp://127.0.0.1:60001 ./scripts/build-ios-sim.sh

# iOS simulator, staging regtest backend
BACKEND=regtest TREZOR_BRIDGE=true ./scripts/build-ios-sim.sh
```

---

### 🔐 Manual Trezor Emulator Setup

The local docker setup includes an opt-in Trezor User Env fixture for manual hardware-wallet checks. It starts the official Trezor emulator and Bridge, but it is not part of the default `docker compose up -d` stack.

Default emulator state:

- Model: `T2T1`
- Firmware: `2-main`
- Bridge: `node-bridge`
- Mnemonic: random 12-word BIP39 phrase generated on each `start`
- PIN: empty
- Passphrase protection: off
- Label: `Bitkit Test Trezor`

Start the emulator:

```bash
./scripts/trezor-emulator start
./scripts/trezor-emulator status
```

`start` prints the generated mnemonic and the first native regtest receive address (`m/84h/1h/0h/0/0`) so it can be funded during manual checks.
`start` refuses to wipe/reseed an already-running emulator. Use `stop` before starting a new one.

For CI or scripts, use JSON output:

```bash
./scripts/trezor-emulator start --json > artifacts/trezor-emulator.json
./scripts/trezor-emulator status --json
```

`status --json` returns the current receive address metadata, but not the mnemonic.

Use the deterministic seed when you want to reuse known history/funds:

```bash
TREZOR_RANDOM_MNEMONIC=false ./scripts/trezor-emulator start
```

Or provide an explicit seed:

```bash
TREZOR_MNEMONIC="all all all all all all all all all all all all" ./scripts/trezor-emulator start
```

Override the printed address coin/path when needed:

```bash
TREZOR_ADDRESS_COIN=Testnet TREZOR_ADDRESS_PATH="m/84h/1h/0h/0/0" ./scripts/trezor-emulator start
```

Useful URLs:

- User Env dashboard: `http://localhost:9002`
- Trezor Bridge: `http://localhost:21325`

The Trezor User Env image is pinned in `docker/docker-compose.yml` so the emulator Bridge keeps the raw message format expected by current Bitkit builds.

#### Android Emulator

```bash
# Local backend
cd docker
docker compose up -d
cd ..
./scripts/trezor-emulator start
TREZOR_BRIDGE=true ./scripts/build-android-apk.sh
npm run e2e:android

# Staging regtest backend
./scripts/trezor-emulator start
BACKEND=regtest TREZOR_BRIDGE=true ./scripts/build-android-apk.sh
BACKEND=regtest npm run e2e:android
```

For manual checks, open Bitkit and use the app's developer Trezor screen to scan and connect to `Bitkit Test Trezor`.

#### Android Physical Device

```bash
./scripts/trezor-emulator start
./scripts/trezor-emulator adb
TREZOR_BRIDGE=true TREZOR_BRIDGE_URL=http://127.0.0.1:21325 ./scripts/build-android-apk.sh
```

#### iOS Simulator

```bash
# Local backend
cd docker
docker compose up -d
cd ..
./scripts/trezor-emulator start
TREZOR_BRIDGE=true TREZOR_ELECTRUM_URL=tcp://127.0.0.1:60001 ./scripts/build-ios-sim.sh
npm run e2e:ios

# Staging regtest backend
./scripts/trezor-emulator start
BACKEND=regtest TREZOR_BRIDGE=true ./scripts/build-ios-sim.sh
BACKEND=regtest npm run e2e:ios
```

Stop the emulator when finished:

```bash
./scripts/trezor-emulator stop
```

Backend and Trezor are independent. `BACKEND=local` uses local Bitcoin/Electrum, while `BACKEND=regtest` uses remote staging regtest services. The Trezor emulator always provides only the device and Bridge. Fund or mine against the same backend the app was built for.

### 🧪 Running tests

**Important:** The `BACKEND` environment variable controls which infrastructure the tests use for blockchain operations (deposits, mining blocks):
Expand Down
2 changes: 2 additions & 0 deletions ci_run_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ if [[ "${BACKEND:-local}" != "mainnet" ]]; then
adb reverse tcp:30001 tcp:30001
# homegate port
adb reverse tcp:6288 tcp:6288
# trezor bridge port
adb reverse tcp:21325 tcp:21325
fi
# show touches
adb shell settings put system show_touches 1
Expand Down
37 changes: 37 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
x-trezor-user-env-image: &trezor_user_env_image ghcr.io/trezor/trezor-user-env@sha256:15871ebb234bf7c0197cfcd31ddc2edbe90173cd6386fc0283fafe05bf888c06

services:
bitcoind:
container_name: bitcoin
Expand Down Expand Up @@ -199,6 +201,41 @@ services:
ports:
- '6288:8080'

trezor-user-env-mac:
image: *trezor_user_env_image
profiles:
- trezor
ports:
- '9001:9001' # User Env controller websocket
- '9002:9002' # User Env dashboard
- '21325:21325' # Trezor Bridge legacy port used by Bitkit
- '21328:21328' # Trezor Bridge current port
- '15900:5900' # VNC port, offset to avoid local VNC conflicts
- '6080:6080' # noVNC web viewer
- '9003:9003' # MCP server SSE transport
environment:
- MACOS=1
- REGTEST_RPC_URL=http://host.docker.internal:43782
volumes:
- './.trezor-user-env/trezor-suite:/trezor-user-env/trezor-suite'
- './.trezor-user-env/logs/screens:/trezor-user-env/logs/screens'
- './.trezor-user-env/logs/mcp-screenshots:/trezor-user-env/logs/mcp-screenshots'
- './.trezor-user-env/firmware/user_downloaded:/trezor-user-env/src/binaries/firmware/bin/user_downloaded'

trezor-user-env-linux:
container_name: trezor-user-env.unix
image: *trezor_user_env_image
profiles:
- trezor-linux
network_mode: 'host'
environment:
- PHYSICAL_TREZOR=${PHYSICAL_TREZOR:-}
volumes:
- './.trezor-user-env/trezor-suite:/trezor-user-env/trezor-suite'
- './.trezor-user-env/logs/screens:/trezor-user-env/logs/screens'
- './.trezor-user-env/logs/mcp-screenshots:/trezor-user-env/logs/mcp-screenshots'
- './.trezor-user-env/firmware/user_downloaded:/trezor-user-env/src/binaries/firmware/bin/user_downloaded'

volumes:
bitcoin_home:

Expand Down
2 changes: 2 additions & 0 deletions scripts/adb-reverse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ for d in $(adb devices | awk 'NR>1 && $2=="device" {print $1}'); do
adb -s "$d" reverse tcp:9735 tcp:9735
adb -s "$d" reverse tcp:30001 tcp:30001
adb -s "$d" reverse tcp:6288 tcp:6288
adb -s "$d" reverse tcp:21325 tcp:21325

done

echo "Done."
12 changes: 10 additions & 2 deletions scripts/build-android-apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
# ./scripts/build-android-apk.sh
# BACKEND=regtest ./scripts/build-android-apk.sh
# BACKEND=mainnet ./scripts/build-android-apk.sh
# TREZOR_BRIDGE=true ./scripts/build-android-apk.sh
# TREZOR_BRIDGE=true TREZOR_BRIDGE_URL=http://127.0.0.1:21325 ./scripts/build-android-apk.sh
set -euo pipefail

E2E_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
ANDROID_ROOT="$(cd "$E2E_ROOT/../bitkit-android" && pwd)"

BACKEND="${BACKEND:-local}"
TREZOR_BRIDGE="${TREZOR_BRIDGE:-false}"
TREZOR_BRIDGE_URL="${TREZOR_BRIDGE_URL:-http://10.0.2.2:21325}"
E2E_BACKEND="local"
GRADLE_TASK="assembleDevDebug"
APK_FLAVOR_DIR="dev/debug"
Expand All @@ -40,10 +44,14 @@ else
echo "ERROR: Unsupported BACKEND value: $BACKEND" >&2
exit 1
fi
echo "Building Android APK (BACKEND=$BACKEND, E2E_BACKEND=$E2E_BACKEND, GRADLE_TASK=$GRADLE_TASK)..."
echo "Building Android APK (BACKEND=$BACKEND, E2E_BACKEND=$E2E_BACKEND, TREZOR_BRIDGE=$TREZOR_BRIDGE, TREZOR_BRIDGE_URL=$TREZOR_BRIDGE_URL, GRADLE_TASK=$GRADLE_TASK)..."

pushd "$ANDROID_ROOT" >/dev/null
E2E=true E2E_BACKEND="$E2E_BACKEND" ./gradlew "$GRADLE_TASK" --no-daemon --stacktrace
E2E=true \
E2E_BACKEND="$E2E_BACKEND" \
TREZOR_BRIDGE="$TREZOR_BRIDGE" \
TREZOR_BRIDGE_URL="$TREZOR_BRIDGE_URL" \
./gradlew "$GRADLE_TASK" --no-daemon --stacktrace
popd >/dev/null

# Find the universal APK
Expand Down
13 changes: 13 additions & 0 deletions scripts/build-ios-sim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
# Usage:
# ./scripts/build-ios-sim.sh
# BACKEND=regtest ./scripts/build-ios-sim.sh
# TREZOR_BRIDGE=true ./scripts/build-ios-sim.sh
# TREZOR_BRIDGE=true BACKEND=regtest ./scripts/build-ios-sim.sh
set -euo pipefail
E2E_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
IOS_ROOT="$(cd "$E2E_ROOT/../bitkit-ios" && pwd)"

BACKEND="${BACKEND:-local}"
TREZOR_BRIDGE="${TREZOR_BRIDGE:-false}"
TREZOR_BRIDGE_URL="${TREZOR_BRIDGE_URL:-http://127.0.0.1:21325}"
TREZOR_ELECTRUM_URL="${TREZOR_ELECTRUM_URL:-}"
E2E_BACKEND="local"
E2E_NETWORK="regtest"
XCODE_EXTRA_ARGS=()
Expand All @@ -35,9 +40,17 @@ fi
XCODE_EXTRA_ARGS+=(
"E2E_BACKEND=$E2E_BACKEND"
"E2E_NETWORK=$E2E_NETWORK"
"TREZOR_BRIDGE=$TREZOR_BRIDGE"
"TREZOR_BRIDGE_URL=$TREZOR_BRIDGE_URL"
"SWIFT_ACTIVE_COMPILATION_CONDITIONS=\$(inherited) E2E_BUILD"
)

if [[ -n "$TREZOR_ELECTRUM_URL" ]]; then
XCODE_EXTRA_ARGS+=("TREZOR_ELECTRUM_URL=$TREZOR_ELECTRUM_URL")
fi

echo "Building iOS simulator app (BACKEND=$BACKEND, E2E_BACKEND=$E2E_BACKEND, TREZOR_BRIDGE=$TREZOR_BRIDGE, TREZOR_BRIDGE_URL=$TREZOR_BRIDGE_URL)..."

xcodebuild \
-project "$IOS_ROOT/Bitkit.xcodeproj" \
-scheme Bitkit \
Expand Down
Loading