Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 3 additions & 2 deletions .yarnrc.yml
Comment thread
NeOMakinG marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
nodeLinker: node-modules

npmRegistryServer: "https://registry.npmjs.org"
npmAuthToken: "${NPM_AUTH-fallback}"

npmRegistryServer: "http://127.0.0.1:4873"

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
Expand All @@ -15,4 +17,3 @@ unsafeHttpWhitelist:
- 127.0.0.1

yarnPath: .yarn/releases/yarn-3.5.0.cjs
npmAuthToken: ${NPM_AUTH-fallback}
115 changes: 115 additions & 0 deletions TRON_LEDGER_IMPLEMENTATION.md
Comment thread
NeOMakinG marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Tron Ledger Support Integration

## Overview
This document tracks the integration of Ledger hardware wallet support for Tron (TRX) in shapeshiftWeb.

## Expected Changes

### 1. hdwallet Dependency Update
- Update `@shapeshiftoss/hdwallet-ledger` to version with Tron support
- No code changes required in shapeshiftWeb

## How It Works

### Automatic Detection
The existing infrastructure in shapeshiftWeb automatically detects Ledger Tron support:

1. **Wallet Support Detection** (`src/hooks/useWalletSupportsChain/useWalletSupportsChain.ts`)
- Uses `supportsTron(wallet)` type guard from hdwallet-core
- Returns true if wallet implements TronWallet interface

2. **Account Discovery** (`src/lib/account/tron.ts`)
- Calls `wallet.tronGetAddress()` for Ledger wallets
- Uses standard BIP44 path: `m/44'/195'/0'/0/0`

3. **Transaction Signing** (`src/components/Modals/Send/utils.ts`)
- Tron chain adapter calls `wallet.tronSignTx()`
- Ledger signs with rawDataHex from unsigned transaction

### Wallet Flow
```
User connects Ledger
useWalletSupportsChain checks supportsTron(wallet) → true
Tron appears as supported chain
deriveTronAccountIdsAndMetadata calls wallet.tronGetAddress()
User can send TRX/TRC20 tokens
Chain adapter calls wallet.tronSignTx()
Transaction broadcasted
```

## Testing Checklist

### Prerequisites
- [ ] Ledger device with Tron app installed
- [ ] hdwallet updated to version with Tron support
- [ ] Tron feature flag enabled (`VITE_FEATURE_TRON=true`)

### Test Cases
- [ ] Ledger appears as option when connecting wallet
- [ ] Tron chain shows as supported for Ledger
- [ ] Can derive Tron address from Ledger
- [ ] Address matches expected format (base58, starts with 'T')
- [ ] Can view Tron balance
- [ ] Can send native TRX from Ledger
- [ ] Can send TRC20 tokens from Ledger
- [ ] Ledger displays correct transaction details
- [ ] User can approve/reject on device
- [ ] Signed transaction broadcasts successfully
- [ ] Transaction appears in portfolio after confirmation

## Verification Steps

### 1. Check Wallet Detection
```javascript
// In browser console after connecting Ledger
import { supportsTron } from '@shapeshiftoss/hdwallet-core';
console.log('Ledger supports Tron:', supportsTron(wallet));
```

### 2. Check Account Discovery
```javascript
// Look for Tron accounts in Redux state
window.store.getState().portfolio.accountIds
// Should include tron:T... account IDs for Ledger
```

### 3. Check Transaction Building
- Navigate to Send modal
- Select Tron or TRC20 token
- Enter amount and recipient
- Click Review
- Verify Ledger prompts for approval
- Approve on device
- Verify transaction broadcasts

## Known Limitations
- Requires Ledger Tron app to be installed and open
- User must approve address display on device for first use
- Transaction signing requires device confirmation

## Troubleshooting

### "Wrong App" Error
- Ensure Tron app is open on Ledger device
- Check SLIP44 mapping includes 195: "Tron"

### Address Derivation Fails
- Verify BIP44 path: `m/44'/195'/0'/0/0`
- Check hw-app-trx is properly installed
- Confirm Ledger transport is connected

### Signature Invalid
- Ensure rawDataHex format is correct
- Verify signature format matches expected (65 bytes)
- Check serialization: rawDataHex + signature

## References
- [Tron Chain Adapter](/packages/chain-adapters/src/tron/TronChainAdapter.ts)
- [Tron Account Discovery](/src/lib/account/tron.ts)
- [Wallet Support Hook](/src/hooks/useWalletSupportsChain/useWalletSupportsChain.ts)
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,24 @@
"@shapeshiftoss/chain-adapters": "workspace:^",
"@shapeshiftoss/contracts": "workspace:^",
"@shapeshiftoss/errors": "workspace:^",
"@shapeshiftoss/hdwallet-coinbase": "1.62.18",
"@shapeshiftoss/hdwallet-core": "1.62.18",
"@shapeshiftoss/hdwallet-gridplus": "1.62.18",
"@shapeshiftoss/hdwallet-keepkey": "1.62.18",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.62.18",
"@shapeshiftoss/hdwallet-keplr": "1.62.18",
"@shapeshiftoss/hdwallet-ledger": "1.62.18",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.62.18",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.62.18",
"@shapeshiftoss/hdwallet-metamask-multichain": "1.62.18",
"@shapeshiftoss/hdwallet-native": "1.62.18",
"@shapeshiftoss/hdwallet-native-vault": "1.62.18",
"@shapeshiftoss/hdwallet-phantom": "1.62.18",
"@shapeshiftoss/hdwallet-trezor": "1.62.18",
"@shapeshiftoss/hdwallet-trezor-connect": "1.62.18",
"@shapeshiftoss/hdwallet-vultisig": "1.62.18",
"@shapeshiftoss/hdwallet-walletconnect": "1.62.18",
"@shapeshiftoss/hdwallet-walletconnectv2": "1.62.18",
"@shapeshiftoss/hdwallet-coinbase": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-core": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-gridplus": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-keepkey": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-keplr": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-ledger": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-metamask-multichain": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-native": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-native-vault": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-phantom": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-trezor": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-trezor-connect": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-vultisig": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-walletconnect": "1.62.18-tron-ledger.1",
"@shapeshiftoss/hdwallet-walletconnectv2": "1.62.18-tron-ledger.1",
"@shapeshiftoss/swapper": "workspace:^",
"@shapeshiftoss/types": "workspace:^",
"@shapeshiftoss/unchained-client": "workspace:^",
Expand Down
1 change: 1 addition & 0 deletions packages/caip/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const ASSET_NAMESPACE = {
slip44: 'slip44',
splToken: 'token',
trc20: 'trc20',
trc10: 'trc10',
suiCoin: 'coin',
} as const

Expand Down
8 changes: 4 additions & 4 deletions packages/unchained-client/src/tron/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export class TronApi {

// Get TRC10 tokens from assetV2
if (data.assetV2) {
for (const [key, value] of Object.entries(data.assetV2)) {
data.assetV2.forEach(token => {
tokens.push({
contractAddress: key,
balance: String(value),
contractAddress: token.key,
balance: String(token.value),
})
}
})
}

// Get TRC20 tokens from TronGrid API
Expand Down
2 changes: 2 additions & 0 deletions src/context/WalletProvider/Ledger/constants.ts
Comment thread
NeOMakinG marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
mayachainAssetId,
solAssetId,
thorchainAssetId,
tronAssetId,
} from '@shapeshiftoss/caip'
import { uniq } from 'lodash'

Expand All @@ -32,6 +33,7 @@ export const availableLedgerAppAssetIds = [
cosmosAssetId,
solAssetId,
mayachainAssetId,
tronAssetId,
]

export const availableLedgerAppChainIds = availableLedgerAppAssetIds.map(
Expand Down
Loading