Skip to content

Commit f84fa7b

Browse files
committed
feat: migrate ledger provider to use hub
1 parent 8882aa3 commit f84fa7b

File tree

19 files changed

+407
-96
lines changed

19 files changed

+407
-96
lines changed

wallets/core/src/namespaces/evm/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import type { BlockchainMeta } from 'rango-types';
99
export interface EvmActions
1010
extends AutoImplementedActionsByRecommended,
1111
CommonActions {
12-
connect: (chain?: Chain | ChainId) => Promise<AccountsWithActiveChain>;
12+
connect: (
13+
chain?: Chain | ChainId,
14+
options?: ConnectOptions
15+
) => Promise<AccountsWithActiveChain>;
1316
canEagerConnect: () => Promise<boolean>;
1417
canSwitchNetwork: (params: CanSwitchNetworkParams) => boolean;
1518
}
@@ -25,4 +28,5 @@ export type Chain = AddEthereumChainParameter;
2528

2629
export type ConnectOptions = {
2730
switchOrAddNetwork?: (instance: ProviderAPI, chain: ChainId | Chain) => void;
31+
derivationPath?: string;
2832
};

wallets/core/src/namespaces/solana/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
export interface SolanaActions
88
extends AutoImplementedActionsByRecommended,
99
CommonActions {
10-
connect: () => Promise<Accounts>;
10+
connect: (options?: ConnectOptions) => Promise<Accounts>;
1111
canEagerConnect: () => Promise<boolean>;
1212
}
1313

@@ -20,3 +20,7 @@ export interface SolanaActions
2020
*/
2121
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2222
export type ProviderAPI = Record<string, any>;
23+
24+
export type ConnectOptions = {
25+
derivationPath?: string;
26+
};

wallets/provider-all/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as frontier from '@rango-dev/provider-frontier';
1818
import * as halo from '@rango-dev/provider-halo';
1919
import * as keplr from '@rango-dev/provider-keplr';
2020
import * as leapCosmos from '@rango-dev/provider-leap-cosmos';
21-
import * as ledger from '@rango-dev/provider-ledger';
21+
import { versions as ledger } from '@rango-dev/provider-ledger';
2222
import * as mathwallet from '@rango-dev/provider-math-wallet';
2323
import * as metamask from '@rango-dev/provider-metamask';
2424
import * as okx from '@rango-dev/provider-okx';
@@ -125,7 +125,7 @@ export const allProviders = (
125125
lazyProvider(legacyProviderImportsToVersionsInterface(frontier)),
126126
lazyProvider(legacyProviderImportsToVersionsInterface(taho)),
127127
lazyProvider(legacyProviderImportsToVersionsInterface(braavos)),
128-
lazyProvider(legacyProviderImportsToVersionsInterface(ledger)),
128+
ledger,
129129
rabby,
130130
lazyProvider(legacyProviderImportsToVersionsInterface(trezor)),
131131
lazyProvider(legacyProviderImportsToVersionsInterface(solflare)),

wallets/provider-ledger/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"version": "0.20.0",
44
"license": "MIT",
55
"type": "module",
6-
"source": "./src/index.ts",
7-
"main": "./dist/index.js",
6+
"source": "./src/mod.ts",
7+
"main": "./dist/mod.js",
88
"exports": {
9-
".": "./dist/index.js"
9+
".": "./dist/mod.js"
1010
},
11-
"typings": "dist/index.d.ts",
11+
"typings": "dist/mod.d.ts",
1212
"files": [
1313
"dist",
1414
"src"
1515
],
1616
"scripts": {
17-
"build": "node ../../scripts/build/command.mjs --path wallets/provider-ledger --splitting --external-all-except @ledgerhq/errors,@ledgerhq/hw-app-eth,@ledgerhq/hw-app-solana,@ledgerhq/hw-transport-webhid,@ledgerhq/types-cryptoassets,@ledgerhq/types-devices,",
17+
"build": "node ../../scripts/build/command.mjs --path wallets/provider-ledger --splitting --external-all-except @ledgerhq/errors,@ledgerhq/hw-app-eth,@ledgerhq/hw-app-solana,@ledgerhq/hw-transport-webhid,@ledgerhq/types-cryptoassets,@ledgerhq/types-devices --inputs src/mod.ts",
1818
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
1919
"clean": "rimraf dist",
2020
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
@@ -38,4 +38,4 @@
3838
"publishConfig": {
3939
"access": "public"
4040
}
41-
}
41+
}

wallets/provider-ledger/readme.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
# @rango-dev/provider-ledger
1+
# Ledger
2+
3+
Ledger integration for hub.
4+
[Homepage](https://www.ledger.com/) | [Docs](https://developers.ledger.com/)
5+
6+
## Implementation notes/limitations
7+
8+
### Group
9+
10+
#### ⚠️ EVM
11+
12+
We only support Ethereum for now.
13+
14+
---
15+
16+
More wallet information can be found in [readme.md](../readme.md).
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { type ProviderInfo } from '@rango-dev/wallets-core';
2+
import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
3+
import { Networks } from '@rango-dev/wallets-shared';
4+
import { type BlockchainMeta } from 'rango-types';
5+
6+
export const EVM_SUPPORTED_CHAINS = [
7+
LegacyNetworks.ETHEREUM,
8+
LegacyNetworks.POLYGON,
9+
LegacyNetworks.BASE,
10+
];
11+
12+
export const HEXADECIMAL_BASE = 16;
13+
export const WALLET_ID = 'ledger';
14+
15+
export const info: ProviderInfo = {
16+
name: 'Ledger',
17+
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/ledger/icon.svg',
18+
extensions: {
19+
homepage:
20+
'https://support.ledger.com/hc/en-us/articles/4404389606417-Download-and-install-Ledger-Live?docs=true',
21+
},
22+
properties: [
23+
{
24+
name: 'namespaces',
25+
value: {
26+
selection: 'single',
27+
data: [
28+
{
29+
label: 'Ethereum',
30+
value: 'EVM',
31+
id: 'ETH',
32+
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
33+
allBlockchains.filter(
34+
(chain) => chain.name === Networks.ETHEREUM
35+
),
36+
},
37+
{
38+
label: 'Solana',
39+
value: 'Solana',
40+
id: 'SOLANA',
41+
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
42+
allBlockchains.filter((chain) => chain.name === Networks.SOLANA),
43+
},
44+
],
45+
},
46+
},
47+
{
48+
name: 'derivationPath',
49+
value: {
50+
data: [
51+
{
52+
id: 'metamask',
53+
label: `Metamask (m/44'/60'/0'/0/index)`,
54+
namespace: 'EVM',
55+
generateDerivationPath: (index: string) => `44'/60'/0'/0/${index}`,
56+
},
57+
{
58+
id: 'ledgerLive',
59+
label: `LedgerLive (m/44'/60'/index'/0/0)`,
60+
namespace: 'EVM',
61+
generateDerivationPath: (index: string) => `44'/60'/${index}'/0/0`,
62+
},
63+
{
64+
id: 'legacy',
65+
label: `Legacy (m/44'/60'/0'/index)`,
66+
namespace: 'EVM',
67+
generateDerivationPath: (index: string) => `44'/60'/0'/${index}`,
68+
},
69+
{
70+
id: `(m/44'/501'/index')`,
71+
label: `(m/44'/501'/index')`,
72+
namespace: 'Solana',
73+
generateDerivationPath: (index: string) => `44'/501'/${index}'`,
74+
},
75+
{
76+
id: `(m/44'/501'/0'/index)`,
77+
label: `(m/44'/501'/0'/index)`,
78+
namespace: 'Solana',
79+
generateDerivationPath: (index: string) => `44'/501'/0'/${index}`,
80+
},
81+
],
82+
},
83+
},
84+
],
85+
};

wallets/provider-ledger/src/index.ts renamed to wallets/provider-ledger/src/legacy/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
12
import type {
23
Connect,
34
Disconnect,
@@ -8,14 +9,15 @@ import type {
89
import { Networks, WalletTypes } from '@rango-dev/wallets-shared';
910
import { type BlockchainMeta, type SignerFactory } from 'rango-types';
1011

12+
import { setDerivationPath } from '../state.js';
1113
import {
1214
getEthereumAccounts,
13-
getLedgerInstance,
15+
ledger as getLedgerInstance,
1416
getSolanaAccounts,
1517
transportDisconnect,
16-
} from './helpers.js';
18+
} from '../utils.js';
19+
1720
import signer from './signer.js';
18-
import { setDerivationPath } from './state.js';
1921

2022
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2123
type InstanceType = any;
@@ -154,3 +156,13 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
154156
},
155157
};
156158
};
159+
160+
const buildLegacyProvider: () => LegacyProviderInterface = () => ({
161+
config,
162+
getInstance,
163+
connect,
164+
getSigners,
165+
getWalletInfo,
166+
});
167+
168+
export { buildLegacyProvider };

wallets/provider-ledger/src/signers/ethereum.ts renamed to wallets/provider-ledger/src/legacy/signers/ethereum.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { DEFAULT_ETHEREUM_RPC_URL } from '@rango-dev/wallets-shared';
77
import { JsonRpcProvider, Transaction } from 'ethers';
88
import { SignerError, SignerErrorCode } from 'rango-types';
99

10+
import { getDerivationPath } from '../../state.js';
1011
import {
1112
getLedgerError,
1213
transportConnect,
1314
transportDisconnect,
14-
} from '../helpers.js';
15-
import { getDerivationPath } from '../state.js';
15+
} from '../../utils.js';
1616

1717
export class EthereumSigner implements GenericSigner<EvmTransaction> {
1818
async signMessage(msg: string): Promise<string> {

wallets/provider-ledger/src/signers/solana.ts renamed to wallets/provider-ledger/src/legacy/signers/solana.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { generalSolanaTransactionExecutor } from '@rango-dev/signer-solana';
77
import { PublicKey } from '@solana/web3.js';
88
import { SignerError, SignerErrorCode } from 'rango-types';
99

10+
import { getDerivationPath } from '../../state.js';
1011
import {
1112
getLedgerError,
1213
transportConnect,
1314
transportDisconnect,
14-
} from '../helpers.js';
15-
import { getDerivationPath } from '../state.js';
15+
} from '../../utils.js';
1616

1717
export function isVersionedTransaction(
1818
transaction: Transaction | VersionedTransaction

0 commit comments

Comments
 (0)