@injectivelabs/wallet-ledger 1.16.7 → 1.16.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +18 -19
  2. package/dist/cjs/index.d.ts +1 -1
  3. package/dist/cjs/index.js +3 -3
  4. package/dist/cjs/strategy/Ledger/Base.d.ts +5 -5
  5. package/dist/cjs/strategy/Ledger/Base.js +21 -20
  6. package/dist/cjs/strategy/Ledger/LedgerLegacy.d.ts +2 -2
  7. package/dist/cjs/strategy/Ledger/LedgerLegacy.js +1 -1
  8. package/dist/cjs/strategy/Ledger/LedgerLive.d.ts +2 -2
  9. package/dist/cjs/strategy/Ledger/LedgerLive.js +1 -1
  10. package/dist/cjs/strategy/Ledger/hw/AccountManager.d.ts +1 -1
  11. package/dist/cjs/strategy/Ledger/hw/AccountManager.js +2 -2
  12. package/dist/cjs/strategy/Ledger/hw/index.d.ts +2 -2
  13. package/dist/cjs/strategy/Ledger/hw/index.js +14 -13
  14. package/dist/cjs/strategy/LedgerCosmos/hw/AccountManager.d.ts +1 -1
  15. package/dist/cjs/strategy/LedgerCosmos/hw/index.d.ts +2 -2
  16. package/dist/cjs/strategy/LedgerCosmos/hw/index.js +10 -9
  17. package/dist/cjs/strategy/LedgerCosmos/index.d.ts +2 -2
  18. package/dist/cjs/strategy/LedgerCosmos/index.js +3 -2
  19. package/dist/cjs/strategy/lib.d.ts +14 -0
  20. package/dist/cjs/strategy/lib.js +86 -0
  21. package/dist/esm/index.d.ts +1 -1
  22. package/dist/esm/index.js +1 -1
  23. package/dist/esm/strategy/Ledger/Base.d.ts +5 -5
  24. package/dist/esm/strategy/Ledger/Base.js +20 -19
  25. package/dist/esm/strategy/Ledger/LedgerLegacy.d.ts +2 -2
  26. package/dist/esm/strategy/Ledger/LedgerLegacy.js +1 -1
  27. package/dist/esm/strategy/Ledger/LedgerLive.d.ts +2 -2
  28. package/dist/esm/strategy/Ledger/LedgerLive.js +1 -1
  29. package/dist/esm/strategy/Ledger/hw/AccountManager.d.ts +1 -1
  30. package/dist/esm/strategy/Ledger/hw/AccountManager.js +2 -2
  31. package/dist/esm/strategy/Ledger/hw/index.d.ts +2 -2
  32. package/dist/esm/strategy/Ledger/hw/index.js +4 -3
  33. package/dist/esm/strategy/LedgerCosmos/hw/AccountManager.d.ts +1 -1
  34. package/dist/esm/strategy/LedgerCosmos/hw/index.d.ts +2 -2
  35. package/dist/esm/strategy/LedgerCosmos/hw/index.js +4 -3
  36. package/dist/esm/strategy/LedgerCosmos/index.d.ts +2 -2
  37. package/dist/esm/strategy/LedgerCosmos/index.js +5 -4
  38. package/dist/esm/strategy/lib.d.ts +14 -0
  39. package/dist/esm/strategy/lib.js +46 -0
  40. package/package.json +10 -9
package/README.md CHANGED
@@ -13,7 +13,7 @@ _Package to use Ledger Wallets on Injective via the wallet strategy._
13
13
  ## 📚 Installation
14
14
 
15
15
  ```bash
16
- yarn add @injectivelabs/wallet-ledger
16
+ pnpm add @injectivelabs/wallet-ledger
17
17
  ```
18
18
 
19
19
  ---
@@ -30,10 +30,9 @@ dependencies and implementations for their specific wallets.
30
30
  Here's a brief example of how to use this package to send 1 INJ.:
31
31
 
32
32
  ```typescript
33
- import { Wallet } from '@injectivelabs/wallet-base';
34
- import { BaseWalletStrategy, MsgBroadcaster } from '@injectivelabs/wallet-core';
35
- import { LedgerLive } from '@injectivelabs/wallet-ledger';
36
-
33
+ import { Wallet } from '@injectivelabs/wallet-base'
34
+ import { BaseWalletStrategy, MsgBroadcaster } from '@injectivelabs/wallet-core'
35
+ import { LedgerLive } from '@injectivelabs/wallet-ledger'
37
36
 
38
37
  const strategyArgs: WalletStrategyArguments = {
39
38
  chainId: ChainId.Mainnet,
@@ -56,21 +55,21 @@ const msgBroadcaster = new MsgBroadcaster({
56
55
  })
57
56
 
58
57
  const sendTX = async () => {
59
- const injectiveAddress = 'someInjectiveAddress'
60
-
61
- const message = MsgSend.fromJSON({
62
- srcInjectiveAddress: injectiveAddress,
63
- dstInjectiveAddress: injectiveAddress,
64
- amount: {
65
- amount: '1',
66
- denom: 'inj',
67
- },
68
- })
69
-
70
- return await msgBroadcaster.broadcast({ msgs: message })
71
- }
58
+ const injectiveAddress = 'someInjectiveAddress'
59
+
60
+ const message = MsgSend.fromJSON({
61
+ srcInjectiveAddress: injectiveAddress,
62
+ dstInjectiveAddress: injectiveAddress,
63
+ amount: {
64
+ amount: '1',
65
+ denom: 'inj',
66
+ },
67
+ })
68
+
69
+ return await msgBroadcaster.broadcast({ msgs: message })
70
+ }
72
71
 
73
- const result = await sendTX()
72
+ const result = await sendTX()
74
73
  ```
75
74
 
76
75
  Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy)
@@ -1,4 +1,4 @@
1
1
  export { LedgerLive as LedgerLiveStrategy } from './strategy/Ledger/LedgerLive.js';
2
- export { LedgerLegacy as LedgerLegacyStrategy } from './strategy/Ledger/LedgerLegacy.js';
3
2
  export { LedgerCosmos as LedgerCosmosStrategy } from './strategy/LedgerCosmos/index.js';
3
+ export { LedgerLegacy as LedgerLegacyStrategy } from './strategy/Ledger/LedgerLegacy.js';
4
4
  export * from './types.js';
package/dist/cjs/index.js CHANGED
@@ -14,11 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.LedgerCosmosStrategy = exports.LedgerLegacyStrategy = exports.LedgerLiveStrategy = void 0;
17
+ exports.LedgerLegacyStrategy = exports.LedgerCosmosStrategy = exports.LedgerLiveStrategy = void 0;
18
18
  var LedgerLive_js_1 = require("./strategy/Ledger/LedgerLive.js");
19
19
  Object.defineProperty(exports, "LedgerLiveStrategy", { enumerable: true, get: function () { return LedgerLive_js_1.LedgerLive; } });
20
- var LedgerLegacy_js_1 = require("./strategy/Ledger/LedgerLegacy.js");
21
- Object.defineProperty(exports, "LedgerLegacyStrategy", { enumerable: true, get: function () { return LedgerLegacy_js_1.LedgerLegacy; } });
22
20
  var index_js_1 = require("./strategy/LedgerCosmos/index.js");
23
21
  Object.defineProperty(exports, "LedgerCosmosStrategy", { enumerable: true, get: function () { return index_js_1.LedgerCosmos; } });
22
+ var LedgerLegacy_js_1 = require("./strategy/Ledger/LedgerLegacy.js");
23
+ Object.defineProperty(exports, "LedgerLegacyStrategy", { enumerable: true, get: function () { return LedgerLegacy_js_1.LedgerLegacy; } });
24
24
  __exportStar(require("./types.js"), exports);
@@ -1,14 +1,14 @@
1
- import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
2
1
  import { TxRaw, TxResponse, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
3
- import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, SendTransactionOptions, ConcreteWalletStrategy, ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
2
+ import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, SendTransactionOptions, ConcreteWalletStrategy, ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
3
+ import { AccountAddress, EvmChainId } from '@injectivelabs/ts-types';
4
4
  import { LedgerDerivationPathType } from '../../types.js';
5
5
  export default class LedgerBase extends BaseConcreteStrategy implements ConcreteWalletStrategy {
6
6
  private baseDerivationPath;
7
7
  private derivationPathType;
8
8
  private ledger;
9
- private ethereumOptions;
9
+ private evmOptions;
10
10
  private alchemy;
11
- constructor(args: ConcreteEthereumWalletStrategyArgs & {
11
+ constructor(args: ConcreteEvmWalletStrategyArgs & {
12
12
  derivationPathType: LedgerDerivationPathType;
13
13
  });
14
14
  getWalletDeviceType(): Promise<WalletDeviceType>;
@@ -18,7 +18,7 @@ export default class LedgerBase extends BaseConcreteStrategy implements Concrete
18
18
  getSessionOrConfirm(address: AccountAddress): Promise<string>;
19
19
  sendEvmTransaction(txData: any, args: {
20
20
  address: string;
21
- ethereumChainId: EthereumChainId;
21
+ evmChainId: EvmChainId;
22
22
  }): Promise<string>;
23
23
  sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
24
24
  signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
@@ -4,25 +4,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /* eslint-disable class-methods-use-this */
7
- const ts_types_1 = require("@injectivelabs/ts-types");
7
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
8
+ const exceptions_1 = require("@injectivelabs/exceptions");
9
+ const wallet_base_1 = require("@injectivelabs/wallet-base");
8
10
  const ethereumjs_util_1 = require("ethereumjs-util");
9
11
  const common_1 = require("@ethereumjs/common");
10
12
  const tx_1 = require("@ethereumjs/tx");
11
- const ledgerhq_hw_app_eth_1 = require("@bangjelkoski/ledgerhq-hw-app-eth");
12
- const exceptions_1 = require("@injectivelabs/exceptions");
13
- const sdk_ts_1 = require("@injectivelabs/sdk-ts");
14
- const wallet_base_1 = require("@injectivelabs/wallet-base");
13
+ const alchemy_sdk_1 = require("alchemy-sdk");
14
+ const ts_types_1 = require("@injectivelabs/ts-types");
15
15
  const index_js_1 = __importDefault(require("./hw/index.js"));
16
+ const lib_js_1 = require("./../lib.js");
16
17
  const utils_js_1 = require("./utils.js");
17
- const alchemy_sdk_1 = require("alchemy-sdk");
18
18
  const getNetworkFromChainId = (chainId) => {
19
- if (chainId === ts_types_1.EthereumChainId.Goerli) {
19
+ if (chainId === ts_types_1.EvmChainId.Goerli) {
20
20
  return common_1.Chain.Goerli;
21
21
  }
22
- if (chainId === ts_types_1.EthereumChainId.Sepolia) {
22
+ if (chainId === ts_types_1.EvmChainId.Sepolia) {
23
23
  return common_1.Chain.Sepolia;
24
24
  }
25
- if (chainId === ts_types_1.EthereumChainId.Kovan) {
25
+ if (chainId === ts_types_1.EvmChainId.Kovan) {
26
26
  return common_1.Chain.Goerli;
27
27
  }
28
28
  return common_1.Chain.Mainnet;
@@ -31,14 +31,14 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
31
31
  baseDerivationPath;
32
32
  derivationPathType;
33
33
  ledger;
34
- ethereumOptions;
34
+ evmOptions;
35
35
  alchemy;
36
36
  constructor(args) {
37
37
  super(args);
38
38
  this.baseDerivationPath = wallet_base_1.DEFAULT_BASE_DERIVATION_PATH;
39
39
  this.derivationPathType = args.derivationPathType;
40
40
  this.ledger = new index_js_1.default();
41
- this.ethereumOptions = args.ethereumOptions;
41
+ this.evmOptions = args.evmOptions;
42
42
  }
43
43
  async getWalletDeviceType() {
44
44
  return Promise.resolve(wallet_base_1.WalletDeviceType.Hardware);
@@ -70,7 +70,7 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
70
70
  async sendEvmTransaction(txData, args) {
71
71
  const signedTransaction = await this.signEvmTransaction(txData, args);
72
72
  try {
73
- const alchemy = await this.getAlchemy(args.ethereumChainId);
73
+ const alchemy = await this.getAlchemy(args.evmChainId);
74
74
  const txReceipt = await alchemy.core.sendTransaction((0, ethereumjs_util_1.addHexPrefix)(signedTransaction.serialize().toString('hex')));
75
75
  return txReceipt.hash;
76
76
  }
@@ -179,8 +179,9 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
179
179
  throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
180
180
  }
181
181
  async signEvmTransaction(txData, args) {
182
- const alchemy = await this.getAlchemy(args.ethereumChainId);
183
- const chainId = parseInt(args.ethereumChainId.toString(), 10);
182
+ const ledgerService = await (0, lib_js_1.loadLedgerServiceType)();
183
+ const alchemy = await this.getAlchemy(args.evmChainId);
184
+ const chainId = parseInt(args.evmChainId.toString(), 10);
184
185
  const nonce = await alchemy.core.getTransactionCount(args.address);
185
186
  const common = new common_1.Common({
186
187
  chain: getNetworkFromChainId(chainId),
@@ -203,7 +204,7 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
203
204
  try {
204
205
  const ledger = await this.ledger.getInstance();
205
206
  const { derivationPath } = await this.getWalletForAddress(args.address);
206
- const resolution = await ledgerhq_hw_app_eth_1.ledgerService.resolveTransaction(encodedMessageHex, {}, {});
207
+ const resolution = await ledgerService.resolveTransaction(encodedMessageHex, {}, {});
207
208
  const txSig = await ledger.signTransaction(derivationPath, encodedMessageHex, resolution);
208
209
  const signedTxData = {
209
210
  ...eip1559TxData,
@@ -245,19 +246,19 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
245
246
  });
246
247
  }
247
248
  }
248
- async getAlchemy(ethereumChainId) {
249
+ async getAlchemy(evmChainId) {
249
250
  if (this.alchemy) {
250
251
  return this.alchemy;
251
252
  }
252
- const options = this.ethereumOptions;
253
- const chainId = ethereumChainId || options.ethereumChainId;
253
+ const options = this.evmOptions;
254
+ const chainId = evmChainId || options.evmChainId;
254
255
  const url = options.rpcUrl || options.rpcUrls?.[chainId];
255
256
  if (!url) {
256
- throw new exceptions_1.GeneralException(new Error('Please pass rpcUrl within the ethereumOptions'));
257
+ throw new exceptions_1.GeneralException(new Error('Please pass rpcUrl within the evmOptions'));
257
258
  }
258
259
  this.alchemy = new alchemy_sdk_1.Alchemy({
259
260
  apiKey: (0, wallet_base_1.getKeyFromRpcUrl)(url),
260
- network: chainId === ts_types_1.EthereumChainId.Mainnet
261
+ network: chainId === ts_types_1.EvmChainId.Mainnet
261
262
  ? alchemy_sdk_1.Network.ETH_MAINNET
262
263
  : alchemy_sdk_1.Network.ETH_SEPOLIA,
263
264
  });
@@ -1,5 +1,5 @@
1
- import { ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
1
+ import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
2
2
  import LedgerBase from './Base.js';
3
3
  export declare class LedgerLegacy extends LedgerBase {
4
- constructor(args: ConcreteEthereumWalletStrategyArgs);
4
+ constructor(args: ConcreteEvmWalletStrategyArgs);
5
5
  }
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LedgerLegacy = void 0;
7
- const types_js_1 = require("../../types.js");
8
7
  const Base_js_1 = __importDefault(require("./Base.js"));
8
+ const types_js_1 = require("../../types.js");
9
9
  class LedgerLegacy extends Base_js_1.default {
10
10
  constructor(args) {
11
11
  super({
@@ -1,5 +1,5 @@
1
- import { ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
1
+ import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
2
2
  import LedgerBase from './Base.js';
3
3
  export declare class LedgerLive extends LedgerBase {
4
- constructor(args: ConcreteEthereumWalletStrategyArgs);
4
+ constructor(args: ConcreteEvmWalletStrategyArgs);
5
5
  }
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LedgerLive = void 0;
7
- const types_js_1 = require("../../types.js");
8
7
  const Base_js_1 = __importDefault(require("./Base.js"));
8
+ const types_js_1 = require("../../types.js");
9
9
  class LedgerLive extends Base_js_1.default {
10
10
  constructor(args) {
11
11
  super({
@@ -1,6 +1,6 @@
1
1
  import { AccountAddress } from '@injectivelabs/ts-types';
2
- import { Eth as EthereumApp } from '@bangjelkoski/ledgerhq-hw-app-eth';
3
2
  import { LedgerDerivationPathType, LedgerWalletInfo } from '../../../types.js';
3
+ import type { Eth as EthereumApp } from '@bangjelkoski/ledgerhq-hw-app-eth';
4
4
  export default class AccountManager {
5
5
  private wallets;
6
6
  private ledger;
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ethereumjs_util_1 = require("ethereumjs-util");
7
6
  const hdkey_1 = __importDefault(require("hdkey"));
8
- const types_js_1 = require("../../../types.js");
7
+ const ethereumjs_util_1 = require("ethereumjs-util");
9
8
  const wallet_base_1 = require("@injectivelabs/wallet-base");
9
+ const types_js_1 = require("../../../types.js");
10
10
  const addressOfHDKey = (hdKey) => {
11
11
  const shouldSanitizePublicKey = true;
12
12
  const derivedPublicKey = hdKey.publicKey;
@@ -1,6 +1,6 @@
1
- import { Eth as EthereumApp } from '@bangjelkoski/ledgerhq-hw-app-eth';
2
- import { Transport } from '@bangjelkoski/ledgerhq-hw-transport';
3
1
  import AccountManager from './AccountManager.js';
2
+ import type { Transport } from '@bangjelkoski/ledgerhq-hw-transport';
3
+ import type { Eth as EthereumApp } from '@bangjelkoski/ledgerhq-hw-app-eth';
4
4
  export default class LedgerTransport {
5
5
  private ledger;
6
6
  private accountManager;
@@ -3,44 +3,45 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ledgerhq_hw_transport_webhid_1 = require("@bangjelkoski/ledgerhq-hw-transport-webhid");
7
- const ledgerhq_hw_transport_webusb_1 = require("@bangjelkoski/ledgerhq-hw-transport-webusb");
8
- const ledgerhq_hw_app_eth_1 = require("@bangjelkoski/ledgerhq-hw-app-eth");
9
6
  const exceptions_1 = require("@injectivelabs/exceptions");
7
+ const lib_js_1 = require("../../lib.js");
10
8
  const AccountManager_js_1 = __importDefault(require("./AccountManager.js"));
11
9
  class LedgerTransport {
12
10
  ledger = null;
13
11
  accountManager = null;
14
12
  static async getTransport() {
13
+ const TransportWebUSB = await (0, lib_js_1.loadTransportWebUSB)();
14
+ const TransportWebHID = await (0, lib_js_1.loadTransportWebHIDType)();
15
15
  try {
16
- if (await ledgerhq_hw_transport_webhid_1.TransportWebHID.isSupported()) {
17
- const list = await ledgerhq_hw_transport_webhid_1.TransportWebHID.list();
16
+ if (await TransportWebHID.isSupported()) {
17
+ const list = await TransportWebHID.list();
18
18
  if (list.length > 0 && list[0].opened) {
19
- return new ledgerhq_hw_transport_webhid_1.TransportWebHID(list[0]);
19
+ return new TransportWebHID(list[0]);
20
20
  }
21
- const existing = await ledgerhq_hw_transport_webhid_1.TransportWebHID.openConnected().catch(() => null);
21
+ const existing = await TransportWebHID.openConnected().catch(() => null);
22
22
  if (existing) {
23
23
  return existing;
24
24
  }
25
- return await ledgerhq_hw_transport_webhid_1.TransportWebHID.request();
25
+ return await TransportWebHID.request();
26
26
  }
27
- if (await ledgerhq_hw_transport_webusb_1.TransportWebUSB.isSupported()) {
28
- const existing = await ledgerhq_hw_transport_webusb_1.TransportWebUSB.openConnected().catch(() => null);
27
+ if (await TransportWebUSB.isSupported()) {
28
+ const existing = await TransportWebUSB.openConnected().catch(() => null);
29
29
  if (existing) {
30
30
  return existing;
31
31
  }
32
- return await ledgerhq_hw_transport_webusb_1.TransportWebUSB.request();
32
+ return await TransportWebUSB.request();
33
33
  }
34
34
  }
35
35
  catch (e) {
36
36
  throw new exceptions_1.LedgerException(new Error(e.message));
37
37
  }
38
- return ledgerhq_hw_transport_webusb_1.TransportWebUSB.request();
38
+ return TransportWebUSB.request();
39
39
  }
40
40
  async getInstance() {
41
+ const EthereumApp = await (0, lib_js_1.loadEthType)();
41
42
  if (!this.ledger) {
42
43
  const transport = await LedgerTransport.getTransport();
43
- this.ledger = new ledgerhq_hw_app_eth_1.Eth(transport);
44
+ this.ledger = new EthereumApp(transport);
44
45
  transport.on('disconnect', () => {
45
46
  this.ledger = null;
46
47
  this.accountManager = null;
@@ -1,6 +1,6 @@
1
1
  import { AccountAddress } from '@injectivelabs/ts-types';
2
- import { Cosmos as CosmosApp } from '@bangjelkoski/ledgerhq-hw-app-cosmos';
3
2
  import { LedgerWalletInfo } from '../../../types.js';
3
+ import type { Cosmos as CosmosApp } from '@bangjelkoski/ledgerhq-hw-app-cosmos';
4
4
  export default class AccountManager {
5
5
  private wallets;
6
6
  private ledger;
@@ -1,6 +1,6 @@
1
- import { Cosmos as CosmosApp } from '@bangjelkoski/ledgerhq-hw-app-cosmos';
2
- import { Transport } from '@bangjelkoski/ledgerhq-hw-transport';
3
1
  import AccountManager from './AccountManager.js';
2
+ import type { Transport } from '@bangjelkoski/ledgerhq-hw-transport';
3
+ import type { Cosmos as CosmosApp } from '@bangjelkoski/ledgerhq-hw-app-cosmos';
4
4
  export default class LedgerTransport {
5
5
  private ledger;
6
6
  private accountManager;
@@ -3,31 +3,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ledgerhq_hw_transport_webusb_1 = require("@bangjelkoski/ledgerhq-hw-transport-webusb");
7
- const ledgerhq_hw_transport_webhid_1 = require("@bangjelkoski/ledgerhq-hw-transport-webhid");
8
- const ledgerhq_hw_app_cosmos_1 = require("@bangjelkoski/ledgerhq-hw-app-cosmos");
9
6
  const exceptions_1 = require("@injectivelabs/exceptions");
7
+ const lib_js_1 = require("./../../lib.js");
10
8
  const AccountManager_js_1 = __importDefault(require("./AccountManager.js"));
11
9
  class LedgerTransport {
12
10
  ledger = null;
13
11
  accountManager = null;
14
12
  static async getTransport() {
13
+ const TransportWebUSB = await (0, lib_js_1.loadTransportWebUSB)();
14
+ const TransportWebHID = await (0, lib_js_1.loadTransportWebHIDType)();
15
15
  try {
16
- if (await ledgerhq_hw_transport_webhid_1.TransportWebHID.isSupported()) {
17
- return await ledgerhq_hw_transport_webhid_1.TransportWebHID.create();
16
+ if (await TransportWebHID.isSupported()) {
17
+ return await TransportWebHID.create();
18
18
  }
19
- if (await ledgerhq_hw_transport_webusb_1.TransportWebUSB.isSupported()) {
20
- return await ledgerhq_hw_transport_webhid_1.TransportWebHID.create();
19
+ if (await TransportWebUSB.isSupported()) {
20
+ return await TransportWebHID.create();
21
21
  }
22
22
  }
23
23
  catch (e) {
24
24
  throw new exceptions_1.LedgerCosmosException(new Error(e.message));
25
25
  }
26
- return await ledgerhq_hw_transport_webhid_1.TransportWebHID.create();
26
+ return await TransportWebHID.create();
27
27
  }
28
28
  async getInstance() {
29
+ const CosmosApp = await (0, lib_js_1.loadCosmosType)();
29
30
  if (!this.ledger) {
30
- this.ledger = new ledgerhq_hw_app_cosmos_1.Cosmos((await LedgerTransport.getTransport()));
31
+ this.ledger = new CosmosApp((await LedgerTransport.getTransport()));
31
32
  }
32
33
  return this.ledger;
33
34
  }
@@ -1,6 +1,6 @@
1
- import { ChainId, AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
2
1
  import { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
3
2
  import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions } from '@injectivelabs/wallet-base';
3
+ import { ChainId, EvmChainId, AccountAddress } from '@injectivelabs/ts-types';
4
4
  export declare class LedgerCosmos extends BaseConcreteStrategy implements ConcreteWalletStrategy {
5
5
  private baseDerivationPath;
6
6
  private ledger;
@@ -14,7 +14,7 @@ export declare class LedgerCosmos extends BaseConcreteStrategy implements Concre
14
14
  getSessionOrConfirm(address: AccountAddress): Promise<string>;
15
15
  sendEvmTransaction(_txData: any, _options: {
16
16
  address: string;
17
- ethereumChainId: EthereumChainId;
17
+ evmChainId: EvmChainId;
18
18
  }): Promise<string>;
19
19
  sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
20
20
  signAminoCosmosTransaction(transaction: {
@@ -4,11 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LedgerCosmos = void 0;
7
+ /* eslint-disable class-methods-use-this */
7
8
  const exceptions_1 = require("@injectivelabs/exceptions");
8
9
  const sdk_ts_1 = require("@injectivelabs/sdk-ts");
9
10
  const wallet_base_1 = require("@injectivelabs/wallet-base");
10
- const index_js_1 = __importDefault(require("./hw/index.js"));
11
11
  const exceptions_2 = require("@injectivelabs/exceptions");
12
+ const index_js_1 = __importDefault(require("./hw/index.js"));
12
13
  class LedgerCosmos extends wallet_base_1.BaseConcreteStrategy {
13
14
  baseDerivationPath;
14
15
  ledger;
@@ -94,7 +95,7 @@ class LedgerCosmos extends wallet_base_1.BaseConcreteStrategy {
94
95
  });
95
96
  }
96
97
  async signEip712TypedData(_eip712Json, _address) {
97
- throw new exceptions_2.CosmosWalletException(new Error('This wallet does not support signing Ethereum transactions'), {
98
+ throw new exceptions_2.CosmosWalletException(new Error('This wallet does not support signing Evm transactions'), {
98
99
  code: exceptions_1.UnspecifiedErrorCode,
99
100
  context: wallet_base_1.WalletAction.SendTransaction,
100
101
  });
@@ -0,0 +1,14 @@
1
+ export type EthType = typeof import('@bangjelkoski/ledgerhq-hw-app-eth').Eth;
2
+ export type CosmosType = typeof import('@bangjelkoski/ledgerhq-hw-app-cosmos').Cosmos;
3
+ export type ledgerServiceType = typeof import('@bangjelkoski/ledgerhq-hw-app-eth').ledgerService;
4
+ export type TransportWebHIDType = typeof import('@bangjelkoski/ledgerhq-hw-transport-webhid').TransportWebHID;
5
+ export type TransportWebUSBType = typeof import('@bangjelkoski/ledgerhq-hw-transport-webusb').TransportWebUSB;
6
+ declare let EthType: EthType;
7
+ declare let CosmosType: CosmosType;
8
+ declare let ledgerServiceType: ledgerServiceType;
9
+ export declare function loadEthType(): Promise<typeof EthType>;
10
+ export declare function loadCosmosType(): Promise<typeof CosmosType>;
11
+ export declare function loadLedgerServiceType(): Promise<typeof ledgerServiceType>;
12
+ export declare function loadTransportWebUSB(): Promise<TransportWebUSBType>;
13
+ export declare function loadTransportWebHIDType(): Promise<TransportWebHIDType>;
14
+ export {};
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.loadEthType = loadEthType;
37
+ exports.loadCosmosType = loadCosmosType;
38
+ exports.loadLedgerServiceType = loadLedgerServiceType;
39
+ exports.loadTransportWebUSB = loadTransportWebUSB;
40
+ exports.loadTransportWebHIDType = loadTransportWebHIDType;
41
+ let EthType;
42
+ let CosmosType;
43
+ let ledgerServiceType;
44
+ let TransportWebUSB;
45
+ let TransportWebHID;
46
+ async function loadEthType() {
47
+ if (!EthType) {
48
+ const module = await Promise.resolve().then(() => __importStar(require('@bangjelkoski/ledgerhq-hw-app-eth')));
49
+ EthType = module.Eth ? module.Eth : module.default.Eth;
50
+ }
51
+ return EthType;
52
+ }
53
+ async function loadCosmosType() {
54
+ if (!CosmosType) {
55
+ const module = await Promise.resolve().then(() => __importStar(require('@bangjelkoski/ledgerhq-hw-app-cosmos')));
56
+ CosmosType = module.Cosmos ? module.Cosmos : module.default.Cosmos;
57
+ }
58
+ return CosmosType;
59
+ }
60
+ async function loadLedgerServiceType() {
61
+ if (!ledgerServiceType) {
62
+ const module = await Promise.resolve().then(() => __importStar(require('@bangjelkoski/ledgerhq-hw-app-eth')));
63
+ ledgerServiceType =
64
+ module.ledgerService ||
65
+ module.default.ledgerService;
66
+ }
67
+ return ledgerServiceType;
68
+ }
69
+ async function loadTransportWebUSB() {
70
+ if (!TransportWebUSB) {
71
+ const module = await Promise.resolve().then(() => __importStar(require('@bangjelkoski/ledgerhq-hw-transport-webusb')));
72
+ TransportWebUSB =
73
+ module.TransportWebUSB ||
74
+ module.default.TransportWebUSB;
75
+ }
76
+ return TransportWebUSB;
77
+ }
78
+ async function loadTransportWebHIDType() {
79
+ if (!TransportWebHID) {
80
+ const module = await Promise.resolve().then(() => __importStar(require('@bangjelkoski/ledgerhq-hw-transport-webhid')));
81
+ TransportWebHID =
82
+ module.TransportWebHID ||
83
+ module.default.TransportWebHID;
84
+ }
85
+ return TransportWebHID;
86
+ }
@@ -1,4 +1,4 @@
1
1
  export { LedgerLive as LedgerLiveStrategy } from './strategy/Ledger/LedgerLive.js';
2
- export { LedgerLegacy as LedgerLegacyStrategy } from './strategy/Ledger/LedgerLegacy.js';
3
2
  export { LedgerCosmos as LedgerCosmosStrategy } from './strategy/LedgerCosmos/index.js';
3
+ export { LedgerLegacy as LedgerLegacyStrategy } from './strategy/Ledger/LedgerLegacy.js';
4
4
  export * from './types.js';
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { LedgerLive as LedgerLiveStrategy } from './strategy/Ledger/LedgerLive.js';
2
- export { LedgerLegacy as LedgerLegacyStrategy } from './strategy/Ledger/LedgerLegacy.js';
3
2
  export { LedgerCosmos as LedgerCosmosStrategy } from './strategy/LedgerCosmos/index.js';
3
+ export { LedgerLegacy as LedgerLegacyStrategy } from './strategy/Ledger/LedgerLegacy.js';
4
4
  export * from './types.js';
@@ -1,14 +1,14 @@
1
- import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
2
1
  import { TxRaw, TxResponse, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
3
- import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, SendTransactionOptions, ConcreteWalletStrategy, ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
2
+ import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, SendTransactionOptions, ConcreteWalletStrategy, ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
3
+ import { AccountAddress, EvmChainId } from '@injectivelabs/ts-types';
4
4
  import { LedgerDerivationPathType } from '../../types.js';
5
5
  export default class LedgerBase extends BaseConcreteStrategy implements ConcreteWalletStrategy {
6
6
  private baseDerivationPath;
7
7
  private derivationPathType;
8
8
  private ledger;
9
- private ethereumOptions;
9
+ private evmOptions;
10
10
  private alchemy;
11
- constructor(args: ConcreteEthereumWalletStrategyArgs & {
11
+ constructor(args: ConcreteEvmWalletStrategyArgs & {
12
12
  derivationPathType: LedgerDerivationPathType;
13
13
  });
14
14
  getWalletDeviceType(): Promise<WalletDeviceType>;
@@ -18,7 +18,7 @@ export default class LedgerBase extends BaseConcreteStrategy implements Concrete
18
18
  getSessionOrConfirm(address: AccountAddress): Promise<string>;
19
19
  sendEvmTransaction(txData: any, args: {
20
20
  address: string;
21
- ethereumChainId: EthereumChainId;
21
+ evmChainId: EvmChainId;
22
22
  }): Promise<string>;
23
23
  sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
24
24
  signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
@@ -1,23 +1,23 @@
1
1
  /* eslint-disable class-methods-use-this */
2
- import { EthereumChainId } from '@injectivelabs/ts-types';
2
+ import { toUtf8, TxGrpcApi, } from '@injectivelabs/sdk-ts';
3
+ import { ErrorType, LedgerException, WalletException, GeneralException, UnspecifiedErrorCode, TransactionException, } from '@injectivelabs/exceptions';
4
+ import { TIP_IN_GWEI, WalletAction, getKeyFromRpcUrl, WalletDeviceType, BaseConcreteStrategy, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_NUM_ADDRESSES_TO_FETCH, } from '@injectivelabs/wallet-base';
3
5
  import { bufferToHex, addHexPrefix } from 'ethereumjs-util';
4
6
  import { Common, Chain, Hardfork } from '@ethereumjs/common';
5
7
  import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx';
6
- import { ledgerService } from '@bangjelkoski/ledgerhq-hw-app-eth';
7
- import { ErrorType, LedgerException, WalletException, GeneralException, UnspecifiedErrorCode, TransactionException, } from '@injectivelabs/exceptions';
8
- import { toUtf8, TxGrpcApi, } from '@injectivelabs/sdk-ts';
9
- import { TIP_IN_GWEI, WalletAction, getKeyFromRpcUrl, WalletDeviceType, BaseConcreteStrategy, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_NUM_ADDRESSES_TO_FETCH, } from '@injectivelabs/wallet-base';
8
+ import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk';
9
+ import { EvmChainId } from '@injectivelabs/ts-types';
10
10
  import LedgerHW from './hw/index.js';
11
+ import { loadLedgerServiceType } from './../lib.js';
11
12
  import { domainHash, messageHash } from './utils.js';
12
- import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk';
13
13
  const getNetworkFromChainId = (chainId) => {
14
- if (chainId === EthereumChainId.Goerli) {
14
+ if (chainId === EvmChainId.Goerli) {
15
15
  return Chain.Goerli;
16
16
  }
17
- if (chainId === EthereumChainId.Sepolia) {
17
+ if (chainId === EvmChainId.Sepolia) {
18
18
  return Chain.Sepolia;
19
19
  }
20
- if (chainId === EthereumChainId.Kovan) {
20
+ if (chainId === EvmChainId.Kovan) {
21
21
  return Chain.Goerli;
22
22
  }
23
23
  return Chain.Mainnet;
@@ -26,14 +26,14 @@ export default class LedgerBase extends BaseConcreteStrategy {
26
26
  baseDerivationPath;
27
27
  derivationPathType;
28
28
  ledger;
29
- ethereumOptions;
29
+ evmOptions;
30
30
  alchemy;
31
31
  constructor(args) {
32
32
  super(args);
33
33
  this.baseDerivationPath = DEFAULT_BASE_DERIVATION_PATH;
34
34
  this.derivationPathType = args.derivationPathType;
35
35
  this.ledger = new LedgerHW();
36
- this.ethereumOptions = args.ethereumOptions;
36
+ this.evmOptions = args.evmOptions;
37
37
  }
38
38
  async getWalletDeviceType() {
39
39
  return Promise.resolve(WalletDeviceType.Hardware);
@@ -65,7 +65,7 @@ export default class LedgerBase extends BaseConcreteStrategy {
65
65
  async sendEvmTransaction(txData, args) {
66
66
  const signedTransaction = await this.signEvmTransaction(txData, args);
67
67
  try {
68
- const alchemy = await this.getAlchemy(args.ethereumChainId);
68
+ const alchemy = await this.getAlchemy(args.evmChainId);
69
69
  const txReceipt = await alchemy.core.sendTransaction(addHexPrefix(signedTransaction.serialize().toString('hex')));
70
70
  return txReceipt.hash;
71
71
  }
@@ -174,8 +174,9 @@ export default class LedgerBase extends BaseConcreteStrategy {
174
174
  throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
175
175
  }
176
176
  async signEvmTransaction(txData, args) {
177
- const alchemy = await this.getAlchemy(args.ethereumChainId);
178
- const chainId = parseInt(args.ethereumChainId.toString(), 10);
177
+ const ledgerService = await loadLedgerServiceType();
178
+ const alchemy = await this.getAlchemy(args.evmChainId);
179
+ const chainId = parseInt(args.evmChainId.toString(), 10);
179
180
  const nonce = await alchemy.core.getTransactionCount(args.address);
180
181
  const common = new Common({
181
182
  chain: getNetworkFromChainId(chainId),
@@ -240,19 +241,19 @@ export default class LedgerBase extends BaseConcreteStrategy {
240
241
  });
241
242
  }
242
243
  }
243
- async getAlchemy(ethereumChainId) {
244
+ async getAlchemy(evmChainId) {
244
245
  if (this.alchemy) {
245
246
  return this.alchemy;
246
247
  }
247
- const options = this.ethereumOptions;
248
- const chainId = ethereumChainId || options.ethereumChainId;
248
+ const options = this.evmOptions;
249
+ const chainId = evmChainId || options.evmChainId;
249
250
  const url = options.rpcUrl || options.rpcUrls?.[chainId];
250
251
  if (!url) {
251
- throw new GeneralException(new Error('Please pass rpcUrl within the ethereumOptions'));
252
+ throw new GeneralException(new Error('Please pass rpcUrl within the evmOptions'));
252
253
  }
253
254
  this.alchemy = new Alchemy({
254
255
  apiKey: getKeyFromRpcUrl(url),
255
- network: chainId === EthereumChainId.Mainnet
256
+ network: chainId === EvmChainId.Mainnet
256
257
  ? AlchemyNetwork.ETH_MAINNET
257
258
  : AlchemyNetwork.ETH_SEPOLIA,
258
259
  });
@@ -1,5 +1,5 @@
1
- import { ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
1
+ import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
2
2
  import LedgerBase from './Base.js';
3
3
  export declare class LedgerLegacy extends LedgerBase {
4
- constructor(args: ConcreteEthereumWalletStrategyArgs);
4
+ constructor(args: ConcreteEvmWalletStrategyArgs);
5
5
  }
@@ -1,5 +1,5 @@
1
- import { LedgerDerivationPathType } from '../../types.js';
2
1
  import LedgerBase from './Base.js';
2
+ import { LedgerDerivationPathType } from '../../types.js';
3
3
  export class LedgerLegacy extends LedgerBase {
4
4
  constructor(args) {
5
5
  super({
@@ -1,5 +1,5 @@
1
- import { ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
1
+ import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
2
2
  import LedgerBase from './Base.js';
3
3
  export declare class LedgerLive extends LedgerBase {
4
- constructor(args: ConcreteEthereumWalletStrategyArgs);
4
+ constructor(args: ConcreteEvmWalletStrategyArgs);
5
5
  }
@@ -1,5 +1,5 @@
1
- import { LedgerDerivationPathType } from '../../types.js';
2
1
  import LedgerBase from './Base.js';
2
+ import { LedgerDerivationPathType } from '../../types.js';
3
3
  export class LedgerLive extends LedgerBase {
4
4
  constructor(args) {
5
5
  super({
@@ -1,6 +1,6 @@
1
1
  import { AccountAddress } from '@injectivelabs/ts-types';
2
- import { Eth as EthereumApp } from '@bangjelkoski/ledgerhq-hw-app-eth';
3
2
  import { LedgerDerivationPathType, LedgerWalletInfo } from '../../../types.js';
3
+ import type { Eth as EthereumApp } from '@bangjelkoski/ledgerhq-hw-app-eth';
4
4
  export default class AccountManager {
5
5
  private wallets;
6
6
  private ledger;
@@ -1,7 +1,7 @@
1
- import { publicToAddress, addHexPrefix } from 'ethereumjs-util';
2
1
  import HDNode from 'hdkey';
3
- import { LedgerDerivationPathType } from '../../../types.js';
2
+ import { publicToAddress, addHexPrefix } from 'ethereumjs-util';
4
3
  import { DEFAULT_NUM_ADDRESSES_TO_FETCH } from '@injectivelabs/wallet-base';
4
+ import { LedgerDerivationPathType } from '../../../types.js';
5
5
  const addressOfHDKey = (hdKey) => {
6
6
  const shouldSanitizePublicKey = true;
7
7
  const derivedPublicKey = hdKey.publicKey;
@@ -1,6 +1,6 @@
1
- import { Eth as EthereumApp } from '@bangjelkoski/ledgerhq-hw-app-eth';
2
- import { Transport } from '@bangjelkoski/ledgerhq-hw-transport';
3
1
  import AccountManager from './AccountManager.js';
2
+ import type { Transport } from '@bangjelkoski/ledgerhq-hw-transport';
3
+ import type { Eth as EthereumApp } from '@bangjelkoski/ledgerhq-hw-app-eth';
4
4
  export default class LedgerTransport {
5
5
  private ledger;
6
6
  private accountManager;
@@ -1,12 +1,12 @@
1
- import { TransportWebHID } from '@bangjelkoski/ledgerhq-hw-transport-webhid';
2
- import { TransportWebUSB } from '@bangjelkoski/ledgerhq-hw-transport-webusb';
3
- import { Eth as EthereumApp } from '@bangjelkoski/ledgerhq-hw-app-eth';
4
1
  import { LedgerException } from '@injectivelabs/exceptions';
2
+ import { loadEthType, loadTransportWebUSB, loadTransportWebHIDType, } from '../../lib.js';
5
3
  import AccountManager from './AccountManager.js';
6
4
  export default class LedgerTransport {
7
5
  ledger = null;
8
6
  accountManager = null;
9
7
  static async getTransport() {
8
+ const TransportWebUSB = await loadTransportWebUSB();
9
+ const TransportWebHID = await loadTransportWebHIDType();
10
10
  try {
11
11
  if (await TransportWebHID.isSupported()) {
12
12
  const list = await TransportWebHID.list();
@@ -33,6 +33,7 @@ export default class LedgerTransport {
33
33
  return TransportWebUSB.request();
34
34
  }
35
35
  async getInstance() {
36
+ const EthereumApp = await loadEthType();
36
37
  if (!this.ledger) {
37
38
  const transport = await LedgerTransport.getTransport();
38
39
  this.ledger = new EthereumApp(transport);
@@ -1,6 +1,6 @@
1
1
  import { AccountAddress } from '@injectivelabs/ts-types';
2
- import { Cosmos as CosmosApp } from '@bangjelkoski/ledgerhq-hw-app-cosmos';
3
2
  import { LedgerWalletInfo } from '../../../types.js';
3
+ import type { Cosmos as CosmosApp } from '@bangjelkoski/ledgerhq-hw-app-cosmos';
4
4
  export default class AccountManager {
5
5
  private wallets;
6
6
  private ledger;
@@ -1,6 +1,6 @@
1
- import { Cosmos as CosmosApp } from '@bangjelkoski/ledgerhq-hw-app-cosmos';
2
- import { Transport } from '@bangjelkoski/ledgerhq-hw-transport';
3
1
  import AccountManager from './AccountManager.js';
2
+ import type { Transport } from '@bangjelkoski/ledgerhq-hw-transport';
3
+ import type { Cosmos as CosmosApp } from '@bangjelkoski/ledgerhq-hw-app-cosmos';
4
4
  export default class LedgerTransport {
5
5
  private ledger;
6
6
  private accountManager;
@@ -1,12 +1,12 @@
1
- import { TransportWebUSB } from '@bangjelkoski/ledgerhq-hw-transport-webusb';
2
- import { TransportWebHID } from '@bangjelkoski/ledgerhq-hw-transport-webhid';
3
- import { Cosmos as CosmosApp } from '@bangjelkoski/ledgerhq-hw-app-cosmos';
4
1
  import { LedgerCosmosException } from '@injectivelabs/exceptions';
2
+ import { loadCosmosType, loadTransportWebUSB, loadTransportWebHIDType, } from './../../lib.js';
5
3
  import AccountManager from './AccountManager.js';
6
4
  export default class LedgerTransport {
7
5
  ledger = null;
8
6
  accountManager = null;
9
7
  static async getTransport() {
8
+ const TransportWebUSB = await loadTransportWebUSB();
9
+ const TransportWebHID = await loadTransportWebHIDType();
10
10
  try {
11
11
  if (await TransportWebHID.isSupported()) {
12
12
  return await TransportWebHID.create();
@@ -21,6 +21,7 @@ export default class LedgerTransport {
21
21
  return await TransportWebHID.create();
22
22
  }
23
23
  async getInstance() {
24
+ const CosmosApp = await loadCosmosType();
24
25
  if (!this.ledger) {
25
26
  this.ledger = new CosmosApp((await LedgerTransport.getTransport()));
26
27
  }
@@ -1,6 +1,6 @@
1
- import { ChainId, AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
2
1
  import { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
3
2
  import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions } from '@injectivelabs/wallet-base';
3
+ import { ChainId, EvmChainId, AccountAddress } from '@injectivelabs/ts-types';
4
4
  export declare class LedgerCosmos extends BaseConcreteStrategy implements ConcreteWalletStrategy {
5
5
  private baseDerivationPath;
6
6
  private ledger;
@@ -14,7 +14,7 @@ export declare class LedgerCosmos extends BaseConcreteStrategy implements Concre
14
14
  getSessionOrConfirm(address: AccountAddress): Promise<string>;
15
15
  sendEvmTransaction(_txData: any, _options: {
16
16
  address: string;
17
- ethereumChainId: EthereumChainId;
17
+ evmChainId: EvmChainId;
18
18
  }): Promise<string>;
19
19
  sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
20
20
  signAminoCosmosTransaction(transaction: {
@@ -1,8 +1,9 @@
1
- import { ErrorType, LedgerCosmosException, TransactionException, UnspecifiedErrorCode, WalletException, } from '@injectivelabs/exceptions';
1
+ /* eslint-disable class-methods-use-this */
2
+ import { ErrorType, WalletException, UnspecifiedErrorCode, TransactionException, LedgerCosmosException, } from '@injectivelabs/exceptions';
2
3
  import { toUtf8, TxGrpcApi, sortObjectByKeys, } from '@injectivelabs/sdk-ts';
3
- import { WalletAction, WalletDeviceType, BaseConcreteStrategy, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_NUM_ADDRESSES_TO_FETCH, } from '@injectivelabs/wallet-base';
4
- import LedgerHW from './hw/index.js';
4
+ import { WalletAction, WalletDeviceType, BaseConcreteStrategy, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_NUM_ADDRESSES_TO_FETCH, } from '@injectivelabs/wallet-base';
5
5
  import { CosmosWalletException } from '@injectivelabs/exceptions';
6
+ import LedgerHW from './hw/index.js';
6
7
  export class LedgerCosmos extends BaseConcreteStrategy {
7
8
  baseDerivationPath;
8
9
  ledger;
@@ -88,7 +89,7 @@ export class LedgerCosmos extends BaseConcreteStrategy {
88
89
  });
89
90
  }
90
91
  async signEip712TypedData(_eip712Json, _address) {
91
- throw new CosmosWalletException(new Error('This wallet does not support signing Ethereum transactions'), {
92
+ throw new CosmosWalletException(new Error('This wallet does not support signing Evm transactions'), {
92
93
  code: UnspecifiedErrorCode,
93
94
  context: WalletAction.SendTransaction,
94
95
  });
@@ -0,0 +1,14 @@
1
+ export type EthType = typeof import('@bangjelkoski/ledgerhq-hw-app-eth').Eth;
2
+ export type CosmosType = typeof import('@bangjelkoski/ledgerhq-hw-app-cosmos').Cosmos;
3
+ export type ledgerServiceType = typeof import('@bangjelkoski/ledgerhq-hw-app-eth').ledgerService;
4
+ export type TransportWebHIDType = typeof import('@bangjelkoski/ledgerhq-hw-transport-webhid').TransportWebHID;
5
+ export type TransportWebUSBType = typeof import('@bangjelkoski/ledgerhq-hw-transport-webusb').TransportWebUSB;
6
+ declare let EthType: EthType;
7
+ declare let CosmosType: CosmosType;
8
+ declare let ledgerServiceType: ledgerServiceType;
9
+ export declare function loadEthType(): Promise<typeof EthType>;
10
+ export declare function loadCosmosType(): Promise<typeof CosmosType>;
11
+ export declare function loadLedgerServiceType(): Promise<typeof ledgerServiceType>;
12
+ export declare function loadTransportWebUSB(): Promise<TransportWebUSBType>;
13
+ export declare function loadTransportWebHIDType(): Promise<TransportWebHIDType>;
14
+ export {};
@@ -0,0 +1,46 @@
1
+ let EthType;
2
+ let CosmosType;
3
+ let ledgerServiceType;
4
+ let TransportWebUSB;
5
+ let TransportWebHID;
6
+ export async function loadEthType() {
7
+ if (!EthType) {
8
+ const module = await import('@bangjelkoski/ledgerhq-hw-app-eth');
9
+ EthType = module.Eth ? module.Eth : module.default.Eth;
10
+ }
11
+ return EthType;
12
+ }
13
+ export async function loadCosmosType() {
14
+ if (!CosmosType) {
15
+ const module = await import('@bangjelkoski/ledgerhq-hw-app-cosmos');
16
+ CosmosType = module.Cosmos ? module.Cosmos : module.default.Cosmos;
17
+ }
18
+ return CosmosType;
19
+ }
20
+ export async function loadLedgerServiceType() {
21
+ if (!ledgerServiceType) {
22
+ const module = await import('@bangjelkoski/ledgerhq-hw-app-eth');
23
+ ledgerServiceType =
24
+ module.ledgerService ||
25
+ module.default.ledgerService;
26
+ }
27
+ return ledgerServiceType;
28
+ }
29
+ export async function loadTransportWebUSB() {
30
+ if (!TransportWebUSB) {
31
+ const module = await import('@bangjelkoski/ledgerhq-hw-transport-webusb');
32
+ TransportWebUSB =
33
+ module.TransportWebUSB ||
34
+ module.default.TransportWebUSB;
35
+ }
36
+ return TransportWebUSB;
37
+ }
38
+ export async function loadTransportWebHIDType() {
39
+ if (!TransportWebHID) {
40
+ const module = await import('@bangjelkoski/ledgerhq-hw-transport-webhid');
41
+ TransportWebHID =
42
+ module.TransportWebHID ||
43
+ module.default.TransportWebHID;
44
+ }
45
+ return TransportWebHID;
46
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-ledger",
3
3
  "description": "Ledger wallet strategy for use with @injectivelabs/wallet-core.",
4
- "version": "1.16.7",
4
+ "version": "1.16.8",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -41,10 +41,10 @@
41
41
  }
42
42
  },
43
43
  "scripts": {
44
- "build": "yarn build:esm && yarn build:cjs && yarn build:post",
44
+ "build": "pnpm build:esm && pnpm build:cjs && pnpm build:post",
45
45
  "build:cjs": "tsc --build --force tsconfig.build.json",
46
46
  "build:esm": "tsc --build --force tsconfig.build.esm.json",
47
- "build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post",
47
+ "build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && pnpm build:post",
48
48
  "build:post": "shx cp ../../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../../etc/stub/package.esm.json.stub dist/esm/package.json",
49
49
  "clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
50
50
  "test": "jest",
@@ -63,10 +63,10 @@
63
63
  "@bangjelkoski/ledgerhq-hw-transport-webusb": "6.29.4-beta.0",
64
64
  "@ethereumjs/common": "^3.1.1",
65
65
  "@ethereumjs/tx": "^4.1.1",
66
- "@injectivelabs/exceptions": "^1.16.7",
67
- "@injectivelabs/sdk-ts": "^1.16.7",
68
- "@injectivelabs/ts-types": "^1.16.7",
69
- "@injectivelabs/wallet-base": "^1.16.7",
66
+ "@injectivelabs/exceptions": "1.16.6",
67
+ "@injectivelabs/sdk-ts": "1.16.8",
68
+ "@injectivelabs/ts-types": "1.16.8",
69
+ "@injectivelabs/wallet-base": "1.16.8",
70
70
  "alchemy-sdk": "^3.4.7",
71
71
  "eth-sig-util": "^3.0.1",
72
72
  "ethereumjs-util": "^7.1.0",
@@ -76,7 +76,8 @@
76
76
  "@types/eth-sig-util": "^2.1.1",
77
77
  "@types/ethereumjs-util": "^6.1.0",
78
78
  "@types/hdkey": "^2.0.1",
79
- "@types/ledgerhq__hw-transport-webusb": "^4.70.1"
79
+ "@types/ledgerhq__hw-transport-webusb": "^4.70.1",
80
+ "shx": "^0.3.4"
80
81
  },
81
- "gitHead": "78f656ef404ef511dfe6e4cc9defcae0a7cbec76"
82
+ "gitHead": "8bdbbfff8a07053ec2cd91a7103bfe99975672b4"
82
83
  }