Skip to content

Commit 96a0984

Browse files
committed
feat: add more trezor paths, export path type, add ledger bluetooth
1 parent 13df0aa commit 96a0984

6 files changed

Lines changed: 223 additions & 17 deletions

File tree

packages/hw-wallets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@ledgerhq/hw-app-eth": "^6.45.5",
5757
"@ledgerhq/hw-app-solana": "^7.4.1",
5858
"@ledgerhq/hw-transport": "^6.31.5",
59+
"@ledgerhq/hw-transport-web-ble": "^6.29.5",
5960
"@ledgerhq/hw-transport-webusb": "^6.29.5",
6061
"@ledgerhq/live-common": "^34.20.0",
6162
"@polkadot/types": "^16.1.1",

packages/hw-wallets/src/configs.ts

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ const bip44Paths = {
6161
basePath: "m/44'/137'/0'/0",
6262
label: "Rootstock",
6363
},
64+
rootstockTestnet: {
65+
path: "m/44'/37310'/0'/0/{index}",
66+
basePath: "m/44'/37310'/0'/0",
67+
label: 'Rootstock Testnet'
68+
},
6469
ethereumClassic: {
6570
path: "m/44'/61'/0'/0/{index}",
6671
basePath: "m/44'/61'/0'/0",
@@ -116,5 +121,141 @@ const bip44Paths = {
116121
basePath: "m/44'/3'/0'/0",
117122
label: "Dogecoin",
118123
},
124+
// Additional paths from MyEtherWallet
125+
poaNetwork: {
126+
path: "m/44'/60'/0'/0/{index}",
127+
basePath: "m/44'/60'/0'/0",
128+
label: 'POA network'
129+
},
130+
expanse: {
131+
path: "m/44'/40'/0'/0/{index}",
132+
basePath: "m/44'/40'/0'/0",
133+
label: 'Expanse'
134+
},
135+
ubiq: {
136+
path: "m/44'/108'/0'/0/{index}",
137+
basePath: "m/44'/108'/0'/0",
138+
label: 'Ubiq'
139+
},
140+
ellaism: {
141+
path: "m/44'/163'/0'/0/{index}",
142+
basePath: "m/44'/163'/0'/0",
143+
label: 'Ellaism'
144+
},
145+
etherGem: {
146+
path: "m/44'/1987'/0'/0/{index}",
147+
basePath: "m/44'/1987'/0'/0",
148+
label: 'EtherGem'
149+
},
150+
callisto: {
151+
path: "m/44'/820'/0'/0/{index}",
152+
basePath: "m/44'/820'/0'/0",
153+
label: 'Callisto'
154+
},
155+
ethereumSocial: {
156+
path: "m/44'/1128'/0'/0/{index}",
157+
basePath: "m/44'/1128'/0'/0",
158+
label: 'Ethereum Social'
159+
},
160+
musicoin: {
161+
path: "m/44'/184'/0'/0/{index}",
162+
basePath: "m/44'/184'/0'/0",
163+
label: 'Musicoin'
164+
},
165+
goChain: {
166+
path: "m/44'/6060'/0'/0/{index}",
167+
basePath: "m/44'/6060'/0'/0",
168+
label: 'GoChain'
169+
},
170+
eosClassic: {
171+
path: "m/44'/2018'/0'/0/{index}",
172+
basePath: "m/44'/2018'/0'/0",
173+
label: 'EOS Classic'
174+
},
175+
akroma: {
176+
path: "m/44'/200625'/0'/0/{index}",
177+
basePath: "m/44'/200625'/0'/0",
178+
label: 'Akroma'
179+
},
180+
etherSocialNetwork: {
181+
path: "m/44'/31102'/0'/0/{index}",
182+
basePath: "m/44'/31102'/0'/0",
183+
label: 'EtherSocial Network'
184+
},
185+
pirl: {
186+
path: "m/44'/164'/0'/0/{index}",
187+
basePath: "m/44'/164'/0'/0",
188+
label: 'PIRL'
189+
},
190+
ether1: {
191+
path: "m/44'/1313114'/0'/0/{index}",
192+
basePath: "m/44'/1313114'/0'/0",
193+
label: 'Ether-1'
194+
},
195+
atheios: {
196+
path: "m/44'/1620'/0'/0/{index}",
197+
basePath: "m/44'/1620'/0'/0",
198+
label: 'Atheios'
199+
},
200+
tomoChain: {
201+
path: "m/44'/889'/0'/0/{index}",
202+
basePath: "m/44'/889'/0'/0",
203+
label: 'TomoChain'
204+
},
205+
mixBlockchain: {
206+
path: "m/44'/76'/0'/0/{index}",
207+
basePath: "m/44'/76'/0'/0",
208+
label: 'Mix Blockchain'
209+
},
210+
iolite: {
211+
path: "m/44'/1171337'/0'/0/{index}",
212+
basePath: "m/44'/1171337'/0'/0",
213+
label: 'Iolite'
214+
},
215+
thundercore: {
216+
path: "m/44'/1001'/0'/0/{index}",
217+
basePath: "m/44'/1001'/0'/0",
218+
label: 'ThunderCore'
219+
},
220+
solidum: {
221+
path: "m/44'/997'/0'/0/{index}",
222+
basePath: "m/44'/997'/0'/0",
223+
label: 'Solidum'
224+
},
225+
metadium: {
226+
path: "m/44'/916'/0'/0/{index}",
227+
basePath: "m/44'/916'/0'/0",
228+
label: 'Metadium'
229+
},
230+
reoscChain: {
231+
path: "m/44'/2894'/0'/0/{index}",
232+
basePath: "m/44'/2894'/0'/0",
233+
label: 'REOSC'
234+
},
235+
dexon: {
236+
path: "m/44'/237'/0'/0/{index}",
237+
basePath: "m/44'/237'/0'/0",
238+
label: 'DEXON Network'
239+
},
240+
lightstreamsNetwork: {
241+
path: "m/44'/60'/0'/{index}",
242+
basePath: "m/44'/60'/0'",
243+
label: 'Lightstreams Network'
244+
},
245+
mintmeComCoin: {
246+
path: "m/44'/227'/0'/0/{index}",
247+
basePath: "m/44'/227'/0'/0",
248+
label: 'MintMe.com Coin'
249+
},
250+
ethercore: {
251+
path: "m/44'/466'/0'/0/{index}",
252+
basePath: "m/44'/466'/0'/0",
253+
label: 'EtherCore'
254+
},
255+
binanceChain: {
256+
path: "m/44'/714'/{index}",
257+
basePath: "m/44'/714'",
258+
label: 'Binance Chain'
259+
},
119260
};
120261
export { walletConfigs, MessengerName, ledgerAppNames, bip44Paths };

packages/hw-wallets/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,13 @@ class HWwalletManager {
114114
export default HWwalletManager;
115115

116116
export { ledgerAppNames };
117+
118+
export type {
119+
AddressResponse,
120+
getAddressRequest,
121+
HWWalletProvider,
122+
isConnectedRequest,
123+
PathType,
124+
SignMessageRequest,
125+
SignTransactionRequest,
126+
}

packages/hw-wallets/src/ledger/ethereum/index.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type Transport from "@ledgerhq/hw-transport";
22
import webUsbTransport from "@ledgerhq/hw-transport-webusb";
3+
import bleTransport from '@ledgerhq/hw-transport-web-ble';
34
import ledgerService from "@ledgerhq/hw-app-eth/lib/services/ledger";
45
import { HWwalletCapabilities, NetworkNames } from "@enkryptcom/types";
56
import EthApp from "@ledgerhq/hw-app-eth";
@@ -34,17 +35,31 @@ class LedgerEthereum implements HWWalletProvider {
3435

3536
async init(): Promise<boolean> {
3637
if (!this.transport) {
37-
const support = await webUsbTransport.isSupported();
38-
if (support) {
39-
this.transport = await webUsbTransport.openConnected().then((res) => {
40-
if (!res) return webUsbTransport.create();
41-
return res;
42-
});
43-
} else {
44-
return Promise.reject(
45-
new Error("ledger-ethereum: webusb is not supported"),
46-
);
38+
try {
39+
const BLEsupport = await bleTransport.isSupported();
40+
if (BLEsupport) {
41+
const transport = await bleTransport.create();
42+
transport.on("disconnect", () => { // connection wasnt succesful
43+
this.transport = null;
44+
})
45+
this.transport = transport;
46+
}
47+
48+
} catch {
49+
const support = await webUsbTransport.isSupported();
50+
if (support) {
51+
this.transport = await webUsbTransport.openConnected().then((res) => {
52+
if (!res) return webUsbTransport.create();
53+
return res;
54+
});
55+
56+
} else {
57+
return Promise.reject(
58+
new Error("ledger-ethereum: webusb is not supported"),
59+
);
60+
}
4761
}
62+
4863
}
4964
return true;
5065
}
@@ -142,7 +157,7 @@ class LedgerEthereum implements HWWalletProvider {
142157

143158
close(): Promise<void> {
144159
// eslint-disable-next-line @typescript-eslint/no-empty-function
145-
return this.transport.close().catch(() => {});
160+
return this.transport.close().catch(() => { });
146161
}
147162

148163
isConnected(networkName: NetworkNames): Promise<boolean> {

packages/hw-wallets/src/trezor/ethereum/configs.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NetworkNames } from "@enkryptcom/types";
22
import { bip44Paths } from "../../configs";
33

44
const DEFAULT_PATHS = [bip44Paths.ethereum];
5-
const supportedPaths = {
5+
const networkBasedSupportedPaths = {
66
[NetworkNames.Ethereum]: DEFAULT_PATHS,
77
[NetworkNames.Matic]: DEFAULT_PATHS,
88
[NetworkNames.Avalanche]: DEFAULT_PATHS,
@@ -28,4 +28,39 @@ const supportedPaths = {
2828
[NetworkNames.Telos]: DEFAULT_PATHS,
2929
[NetworkNames.Blast]: DEFAULT_PATHS,
3030
};
31-
export { supportedPaths };
31+
const ALL_SUPPORTED_PATHS = [
32+
bip44Paths.ethereum,
33+
bip44Paths.ethereumTestnet,
34+
bip44Paths.ethereumClassic,
35+
bip44Paths.rootstock,
36+
Object.assign({}, bip44Paths.ethereumLedger, { label: "Ethereum - Ledger" }), // specify ledger
37+
bip44Paths.ethereumLedgerLive,
38+
bip44Paths.poaNetwork,
39+
bip44Paths.expanse,
40+
bip44Paths.ubiq,
41+
bip44Paths.ellaism,
42+
bip44Paths.etherGem,
43+
bip44Paths.callisto,
44+
bip44Paths.ethereumSocial,
45+
bip44Paths.musicoin,
46+
bip44Paths.goChain,
47+
bip44Paths.eosClassic,
48+
bip44Paths.akroma,
49+
bip44Paths.etherSocialNetwork,
50+
bip44Paths.pirl,
51+
bip44Paths.ether1,
52+
bip44Paths.atheios,
53+
bip44Paths.tomoChain,
54+
bip44Paths.mixBlockchain,
55+
bip44Paths.iolite,
56+
bip44Paths.thundercore,
57+
bip44Paths.solidum,
58+
bip44Paths.metadium,
59+
bip44Paths.reoscChain,
60+
bip44Paths.dexon,
61+
bip44Paths.lightstreamsNetwork,
62+
bip44Paths.mintmeComCoin,
63+
bip44Paths.ethercore,
64+
bip44Paths.binanceChain,
65+
];
66+
export { networkBasedSupportedPaths, ALL_SUPPORTED_PATHS };

packages/hw-wallets/src/trezor/ethereum/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@ import {
1212
SignMessageRequest,
1313
SignTransactionRequest,
1414
} from "../../types";
15-
import { supportedPaths } from "./configs";
15+
import { networkBasedSupportedPaths } from "./configs";
1616
import getTrezorConnect from "../trezorConnect";
1717

1818
class TrezorEthereum implements HWWalletProvider {
1919
network: NetworkNames;
2020
TrezorConnect: TrezorConnect;
2121
HDNodes: Record<string, HDKey>;
22+
isExtension: boolean;
2223

2324
constructor(network: NetworkNames) {
2425
this.network = network;
2526
this.HDNodes = {};
27+
this.isExtension = !!(
28+
chrome && chrome.runtime && chrome.runtime.getPlatformInfo
29+
);
2630
}
2731

2832
async init(): Promise<boolean> {
@@ -31,7 +35,7 @@ class TrezorEthereum implements HWWalletProvider {
3135
}
3236

3337
async getAddress(options: getAddressRequest): Promise<AddressResponse> {
34-
if (!supportedPaths[this.network])
38+
if (this.isExtension && !networkBasedSupportedPaths[this.network])
3539
return Promise.reject(new Error("trezor-ethereum: Invalid network name"));
3640

3741
if (!this.HDNodes[options.pathType.basePath]) {
@@ -59,7 +63,7 @@ class TrezorEthereum implements HWWalletProvider {
5963
}
6064

6165
getSupportedPaths(): PathType[] {
62-
return supportedPaths[this.network];
66+
return this.isExtension ? networkBasedSupportedPaths[this.network] : [];
6367
}
6468

6569
close(): Promise<void> {
@@ -130,7 +134,7 @@ class TrezorEthereum implements HWWalletProvider {
130134
}
131135

132136
static getSupportedNetworks(): NetworkNames[] {
133-
return Object.keys(supportedPaths) as NetworkNames[];
137+
return Object.keys(networkBasedSupportedPaths) as NetworkNames[];
134138
}
135139

136140
static getCapabilities(): string[] {

0 commit comments

Comments
 (0)