Skip to content
Draft
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
19 changes: 18 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,22 @@
"mode": "auto"
}
],
"typescript.tsdk": "./packages/core-mobile/node_modules/typescript/lib"
"typescript.tsdk": "./packages/core-mobile/node_modules/typescript/lib",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
65 changes: 65 additions & 0 deletions docs/ledger-flows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Ledger Integration Documentation

This directory contains documentation for the current Ledger device integration in Core Mobile.

## Contents

1. [Ledger Connection Flow](./ledger-connection.md)
- Device discovery and connection
- Account setup process
- Error handling

2. [Transaction Signing Flow](./transaction-signing.md)
- Transaction signing overview
- Chain-specific implementations
- Error handling

## Key Components

### Services
- `LedgerService`: Manages device connection and app detection
- `LedgerWallet`: Implements wallet interface for Ledger devices
- `WalletService`: Coordinates transaction signing across wallet types

### Hooks
- `useLedgerWallet`: React hook for Ledger device management

### UI Components
- `ConnectWallet`: Device discovery and connection UI
- `ConfirmAddresses`: Account setup and verification UI

## Dependencies

- `@ledgerhq/react-native-hw-transport-ble`: Bluetooth transport
- `@ledgerhq/hw-app-solana`: Solana app integration
- `@avalabs/hw-app-avalanche`: Avalanche app integration
- `@ledgerhq/hw-app-eth`: Ethereum app integration

## Implementation Notes

1. **Bluetooth Connectivity**
- Uses BLE for device communication
- Implements connection monitoring
- Handles connection recovery

2. **Multi-Chain Support**
- Supports EVM, Solana, and Avalanche chains
- Handles app switching
- Manages different transaction formats

3. **Security Considerations**
- Implements secure device pairing
- Validates addresses and transactions
- Handles sensitive data appropriately

4. **Error Handling**
- Comprehensive error types
- User-friendly error messages
- Recovery procedures

## Recent Updates

- Successfully implemented legacy transaction format for EVM chains
- Added proper RLP encoding for transactions
- Implemented correct signature handling
- Added connection monitoring and recovery
167 changes: 167 additions & 0 deletions docs/ledger-flows/ledger-connection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Ledger Connection Flow

This document describes the current implementation of Ledger device connection and account setup in Core Mobile.

## Device Discovery and Connection

### Flow Diagram

```mermaid
sequenceDiagram
box User Interface
participant User
end
box Core Mobile
participant App
end
box External Devices
participant BLE
participant Ledger
end

User->>App: Initiate Add Ledger
App->>BLE: Check Bluetooth Status

alt Bluetooth Disabled
BLE-->>App: Status: Disabled
App-->>User: Show Enable Bluetooth Prompt
User->>BLE: Enable Bluetooth
end

App->>BLE: Request Permissions

alt Permissions Denied
BLE-->>App: Permission Denied
App-->>User: Show Permission Request
User->>BLE: Grant Permissions
end

App->>BLE: Start Device Scan
BLE->>Ledger: Discover Devices
Ledger-->>BLE: Device Info
BLE-->>App: Available Devices
App-->>User: Display Device List

Note over User,App: User selects device from list

User->>App: Select Device
App->>Ledger: Initiate Connection
Ledger-->>App: Connection Established
App-->>User: Show Success & Continue
```

## Account Setup Flow

### Flow Diagram

```mermaid
sequenceDiagram
box User Interface
participant User
end
box Core Mobile
participant App
participant Store
end
box External Device
participant Ledger
end

User->>App: Continue to Address Setup

Note over App,Ledger: Solana Setup Phase
App->>Ledger: Request Solana App
Ledger-->>User: Prompt: Open Solana App
User->>Ledger: Open Solana App
App->>Ledger: Get Solana Keys
Ledger-->>App: Solana Public Keys

Note over App,Ledger: Avalanche Setup Phase
App->>Ledger: Request Avalanche App
Ledger-->>User: Prompt: Open Avalanche App
User->>Ledger: Open Avalanche App
App->>Ledger: Get Avalanche Keys
Ledger-->>App: Avalanche Public Keys

Note over App,Store: Storage Phase
App->>Store: Create Wallet Entry
Store-->>App: Wallet Created
App->>Store: Create Account Entry
Store-->>App: Account Created

App-->>User: Show Success
```

## Error Handling

### Flow Diagram

```mermaid
stateDiagram-v2
direction LR

[*] --> CheckBluetooth

state "Bluetooth Check" as CheckBluetooth {
[*] --> Checking
Checking --> Available
Checking --> Disabled
Disabled --> Settings
Settings --> Checking
}

state "Permission Check" as PermissionCheck {
[*] --> Requesting
Requesting --> Granted
Requesting --> Denied
Denied --> RequestAgain
RequestAgain --> Requesting
}

state "Device Connection" as DeviceConnection {
[*] --> Scanning
Scanning --> Found
Scanning --> NotFound
Found --> Connecting
Connecting --> Connected
Connecting --> Failed
}

CheckBluetooth --> PermissionCheck: Available
PermissionCheck --> DeviceConnection: Granted
DeviceConnection --> [*]: Connected

state "Error Recovery" as ErrorRecovery {
[*] --> IdentifyError
IdentifyError --> ShowMessage
ShowMessage --> RecoverySteps
RecoverySteps --> [*]
}

Disabled --> ErrorRecovery
Denied --> ErrorRecovery
Failed --> ErrorRecovery
NotFound --> ErrorRecovery

ErrorRecovery --> CheckBluetooth: Retry
```

### Error Types and Handling

1. **Bluetooth Errors**
- Bluetooth unavailable
- Bluetooth disabled
- Permission denied

2. **Connection Errors**
- Device not found
- Connection timeout
- Pairing removed
- Connection lost

3. **App Errors**
- App not open
- Wrong app open
- App version mismatch

Each error type has specific handling and user messaging to guide through recovery steps.
Loading