@injectivelabs/wallet-strategy 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.
package/README.md CHANGED
@@ -13,7 +13,7 @@ _Package to use All Wallets on Injective via the wallet strategy._
13
13
  ## 📚 Installation
14
14
 
15
15
  ```bash
16
- yarn add @injectivelabs/wallet-strategy
16
+ pnpm add @injectivelabs/wallet-strategy
17
17
  ```
18
18
 
19
19
  ---
@@ -1,4 +1,4 @@
1
- import { type WalletMetadata, WalletStrategyArguments } from '@injectivelabs/wallet-base';
1
+ import { type WalletMetadata, ConcreteWalletStrategy, WalletStrategyArguments } from '@injectivelabs/wallet-base';
2
2
  import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
3
3
  export declare class WalletStrategy extends BaseWalletStrategy {
4
4
  constructor(args: WalletStrategyArguments);
@@ -17,5 +17,6 @@ export declare class WalletStrategy extends BaseWalletStrategy {
17
17
  *
18
18
  */
19
19
  setMetadata(metadata?: WalletMetadata): void;
20
+ getStrategy(): ConcreteWalletStrategy;
20
21
  }
21
22
  export declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
@@ -3,22 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createStrategyFactory = exports.WalletStrategy = void 0;
4
4
  const wallet_base_1 = require("@injectivelabs/wallet-base");
5
5
  const wallet_ledger_1 = require("@injectivelabs/wallet-ledger");
6
+ const wallet_trezor_1 = require("@injectivelabs/wallet-trezor");
6
7
  const wallet_magic_1 = require("@injectivelabs/wallet-magic");
8
+ const exceptions_1 = require("@injectivelabs/exceptions");
7
9
  const wallet_evm_1 = require("@injectivelabs/wallet-evm");
8
10
  const wallet_core_1 = require("@injectivelabs/wallet-core");
9
11
  const wallet_cosmos_1 = require("@injectivelabs/wallet-cosmos");
10
- const wallet_trezor_1 = require("@injectivelabs/wallet-trezor");
11
12
  const wallet_turnkey_1 = require("@injectivelabs/wallet-turnkey");
12
13
  const wallet_wallet_connect_1 = require("@injectivelabs/wallet-wallet-connect");
13
14
  const wallet_private_key_1 = require("@injectivelabs/wallet-private-key");
14
15
  const wallet_cosmostation_1 = require("@injectivelabs/wallet-cosmostation");
15
16
  const ethereumWalletsDisabled = (args) => {
16
- const { ethereumOptions } = args;
17
- if (!ethereumOptions) {
17
+ const { evmOptions } = args;
18
+ if (!evmOptions) {
18
19
  return true;
19
20
  }
20
- const { ethereumChainId } = ethereumOptions;
21
- if (!ethereumChainId) {
21
+ const { evmChainId } = evmOptions;
22
+ if (!evmChainId) {
22
23
  return true;
23
24
  }
24
25
  return false;
@@ -34,7 +35,7 @@ const createStrategy = ({ args, wallet, }) => {
34
35
  const ethWalletArgs = {
35
36
  ...args,
36
37
  chainId: args.chainId,
37
- ethereumOptions: args.ethereumOptions,
38
+ evmOptions: args.evmOptions,
38
39
  };
39
40
  switch (wallet) {
40
41
  case wallet_base_1.Wallet.Metamask:
@@ -42,19 +43,11 @@ const createStrategy = ({ args, wallet, }) => {
42
43
  ...ethWalletArgs,
43
44
  wallet: wallet_base_1.Wallet.Metamask,
44
45
  });
45
- case wallet_base_1.Wallet.Ledger:
46
- return new wallet_ledger_1.LedgerLiveStrategy(ethWalletArgs);
47
- case wallet_base_1.Wallet.LedgerLegacy:
48
- return new wallet_ledger_1.LedgerLegacyStrategy(ethWalletArgs);
49
46
  case wallet_base_1.Wallet.TrustWallet:
50
47
  return new wallet_evm_1.EvmWalletStrategy({
51
48
  ...ethWalletArgs,
52
49
  wallet: wallet_base_1.Wallet.TrustWallet,
53
50
  });
54
- case wallet_base_1.Wallet.TrezorBip32:
55
- return new wallet_trezor_1.TrezorBip32Strategy(ethWalletArgs);
56
- case wallet_base_1.Wallet.TrezorBip44:
57
- return new wallet_trezor_1.TrezorBip44Strategy(ethWalletArgs);
58
51
  case wallet_base_1.Wallet.Phantom:
59
52
  return new wallet_evm_1.EvmWalletStrategy({
60
53
  ...ethWalletArgs,
@@ -75,50 +68,53 @@ const createStrategy = ({ args, wallet, }) => {
75
68
  ...ethWalletArgs,
76
69
  wallet: wallet_base_1.Wallet.Rainbow,
77
70
  });
78
- case wallet_base_1.Wallet.WalletConnect:
79
- if (!args.metadata?.walletConnect?.projectId) {
80
- return undefined;
81
- }
82
- return new wallet_wallet_connect_1.WalletConnectStrategy(ethWalletArgs);
83
- case wallet_base_1.Wallet.PrivateKey:
84
- return new wallet_private_key_1.PrivateKeyWalletStrategy(ethWalletArgs);
71
+ case wallet_base_1.Wallet.Rabby:
72
+ return new wallet_evm_1.EvmWalletStrategy({
73
+ ...ethWalletArgs,
74
+ wallet: wallet_base_1.Wallet.Rabby,
75
+ });
85
76
  case wallet_base_1.Wallet.Keplr:
86
77
  return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Keplr });
87
- case wallet_base_1.Wallet.Cosmostation:
88
- return new wallet_cosmostation_1.CosmostationWalletStrategy({ ...args });
89
78
  case wallet_base_1.Wallet.Leap:
90
79
  return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Leap });
91
80
  case wallet_base_1.Wallet.Ninji:
92
81
  return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Ninji });
93
82
  case wallet_base_1.Wallet.OWallet:
94
83
  return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.OWallet });
84
+ case wallet_base_1.Wallet.Cosmostation:
85
+ return new wallet_cosmostation_1.CosmostationWalletStrategy({ ...args });
86
+ case wallet_base_1.Wallet.Ledger:
87
+ return new wallet_ledger_1.LedgerLiveStrategy(ethWalletArgs);
88
+ case wallet_base_1.Wallet.LedgerLegacy:
89
+ return new wallet_ledger_1.LedgerLegacyStrategy(ethWalletArgs);
90
+ case wallet_base_1.Wallet.TrezorBip32:
91
+ return new wallet_trezor_1.TrezorBip32Strategy(ethWalletArgs);
92
+ case wallet_base_1.Wallet.TrezorBip44:
93
+ return new wallet_trezor_1.TrezorBip44Strategy(ethWalletArgs);
94
+ case wallet_base_1.Wallet.PrivateKey:
95
+ return new wallet_private_key_1.PrivateKeyWalletStrategy(ethWalletArgs);
96
+ case wallet_base_1.Wallet.Turnkey:
97
+ if (!args.metadata?.turnkey?.defaultOrganizationId) {
98
+ return undefined;
99
+ }
100
+ return new wallet_turnkey_1.TurnkeyWalletStrategy(ethWalletArgs);
95
101
  case wallet_base_1.Wallet.Magic:
96
102
  if (!args.metadata?.magic?.apiKey || !args.metadata?.magic?.rpcEndpoint) {
97
103
  return undefined;
98
104
  }
99
105
  return new wallet_magic_1.MagicStrategy(args);
100
- case wallet_base_1.Wallet.Turnkey:
101
- if (!args.metadata?.turnkey?.iframeContainerId ||
102
- !args.metadata?.turnkey?.defaultOrganizationId) {
106
+ case wallet_base_1.Wallet.WalletConnect:
107
+ if (!args.metadata?.walletConnect?.projectId) {
103
108
  return undefined;
104
109
  }
105
- return new wallet_turnkey_1.TurnkeyWalletStrategy(ethWalletArgs);
110
+ return new wallet_wallet_connect_1.WalletConnectStrategy(ethWalletArgs);
106
111
  default:
107
112
  return undefined;
108
113
  }
109
114
  };
110
- const createAllStrategies = (args) => {
111
- return Object.values(wallet_base_1.Wallet).reduce((strategies, wallet) => {
112
- if (strategies[wallet]) {
113
- return strategies;
114
- }
115
- strategies[wallet] = createStrategy({ args, wallet: wallet });
116
- return strategies;
117
- }, {});
118
- };
119
115
  class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
120
116
  constructor(args) {
121
- const strategies = createAllStrategies(args);
117
+ const strategies = {};
122
118
  super({
123
119
  ...args,
124
120
  strategies,
@@ -143,7 +139,12 @@ class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
143
139
  wallet_base_1.Wallet.PrivateKey,
144
140
  wallet_base_1.Wallet.WalletConnect,
145
141
  ];
146
- for (const wallet of Object.keys(this.strategies)) {
142
+ const strategiesWithPlaceholders = {
143
+ ...this.strategies,
144
+ [wallet_base_1.Wallet.PrivateKey]: undefined,
145
+ [wallet_base_1.Wallet.WalletConnect]: undefined,
146
+ };
147
+ for (const wallet of Object.keys(strategiesWithPlaceholders)) {
147
148
  const walletEnum = wallet;
148
149
  if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
149
150
  this.strategies[walletEnum] = createStrategy({
@@ -158,6 +159,20 @@ class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
158
159
  this.strategies[walletEnum]?.setMetadata?.(metadata);
159
160
  }
160
161
  }
162
+ getStrategy() {
163
+ if (this.strategies[this.wallet]) {
164
+ return this.strategies[this.wallet];
165
+ }
166
+ const strategy = createStrategy({
167
+ args: this.args,
168
+ wallet: this.wallet,
169
+ });
170
+ if (!strategy) {
171
+ throw new exceptions_1.GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
172
+ }
173
+ this.strategies[this.wallet] = strategy;
174
+ return strategy;
175
+ }
161
176
  }
162
177
  exports.WalletStrategy = WalletStrategy;
163
178
  const createStrategyFactory = (args) => {
@@ -1,4 +1,4 @@
1
- import { type WalletMetadata, WalletStrategyArguments } from '@injectivelabs/wallet-base';
1
+ import { type WalletMetadata, ConcreteWalletStrategy, WalletStrategyArguments } from '@injectivelabs/wallet-base';
2
2
  import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
3
3
  export declare class WalletStrategy extends BaseWalletStrategy {
4
4
  constructor(args: WalletStrategyArguments);
@@ -17,5 +17,6 @@ export declare class WalletStrategy extends BaseWalletStrategy {
17
17
  *
18
18
  */
19
19
  setMetadata(metadata?: WalletMetadata): void;
20
+ getStrategy(): ConcreteWalletStrategy;
20
21
  }
21
22
  export declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
@@ -1,21 +1,22 @@
1
1
  import { Wallet, isEvmWallet, } from '@injectivelabs/wallet-base';
2
2
  import { LedgerLiveStrategy, LedgerLegacyStrategy, } from '@injectivelabs/wallet-ledger';
3
+ import { TrezorBip32Strategy, TrezorBip44Strategy, } from '@injectivelabs/wallet-trezor';
3
4
  import { MagicStrategy } from '@injectivelabs/wallet-magic';
5
+ import { GeneralException } from '@injectivelabs/exceptions';
4
6
  import { EvmWalletStrategy } from '@injectivelabs/wallet-evm';
5
7
  import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
6
8
  import { CosmosWalletStrategy } from '@injectivelabs/wallet-cosmos';
7
- import { TrezorBip32Strategy, TrezorBip44Strategy, } from '@injectivelabs/wallet-trezor';
8
9
  import { TurnkeyWalletStrategy } from '@injectivelabs/wallet-turnkey';
9
10
  import { WalletConnectStrategy } from '@injectivelabs/wallet-wallet-connect';
10
11
  import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key';
11
12
  import { CosmostationWalletStrategy } from '@injectivelabs/wallet-cosmostation';
12
13
  const ethereumWalletsDisabled = (args) => {
13
- const { ethereumOptions } = args;
14
- if (!ethereumOptions) {
14
+ const { evmOptions } = args;
15
+ if (!evmOptions) {
15
16
  return true;
16
17
  }
17
- const { ethereumChainId } = ethereumOptions;
18
- if (!ethereumChainId) {
18
+ const { evmChainId } = evmOptions;
19
+ if (!evmChainId) {
19
20
  return true;
20
21
  }
21
22
  return false;
@@ -31,7 +32,7 @@ const createStrategy = ({ args, wallet, }) => {
31
32
  const ethWalletArgs = {
32
33
  ...args,
33
34
  chainId: args.chainId,
34
- ethereumOptions: args.ethereumOptions,
35
+ evmOptions: args.evmOptions,
35
36
  };
36
37
  switch (wallet) {
37
38
  case Wallet.Metamask:
@@ -39,19 +40,11 @@ const createStrategy = ({ args, wallet, }) => {
39
40
  ...ethWalletArgs,
40
41
  wallet: Wallet.Metamask,
41
42
  });
42
- case Wallet.Ledger:
43
- return new LedgerLiveStrategy(ethWalletArgs);
44
- case Wallet.LedgerLegacy:
45
- return new LedgerLegacyStrategy(ethWalletArgs);
46
43
  case Wallet.TrustWallet:
47
44
  return new EvmWalletStrategy({
48
45
  ...ethWalletArgs,
49
46
  wallet: Wallet.TrustWallet,
50
47
  });
51
- case Wallet.TrezorBip32:
52
- return new TrezorBip32Strategy(ethWalletArgs);
53
- case Wallet.TrezorBip44:
54
- return new TrezorBip44Strategy(ethWalletArgs);
55
48
  case Wallet.Phantom:
56
49
  return new EvmWalletStrategy({
57
50
  ...ethWalletArgs,
@@ -72,50 +65,53 @@ const createStrategy = ({ args, wallet, }) => {
72
65
  ...ethWalletArgs,
73
66
  wallet: Wallet.Rainbow,
74
67
  });
75
- case Wallet.WalletConnect:
76
- if (!args.metadata?.walletConnect?.projectId) {
77
- return undefined;
78
- }
79
- return new WalletConnectStrategy(ethWalletArgs);
80
- case Wallet.PrivateKey:
81
- return new PrivateKeyWalletStrategy(ethWalletArgs);
68
+ case Wallet.Rabby:
69
+ return new EvmWalletStrategy({
70
+ ...ethWalletArgs,
71
+ wallet: Wallet.Rabby,
72
+ });
82
73
  case Wallet.Keplr:
83
74
  return new CosmosWalletStrategy({ ...args, wallet: Wallet.Keplr });
84
- case Wallet.Cosmostation:
85
- return new CosmostationWalletStrategy({ ...args });
86
75
  case Wallet.Leap:
87
76
  return new CosmosWalletStrategy({ ...args, wallet: Wallet.Leap });
88
77
  case Wallet.Ninji:
89
78
  return new CosmosWalletStrategy({ ...args, wallet: Wallet.Ninji });
90
79
  case Wallet.OWallet:
91
80
  return new CosmosWalletStrategy({ ...args, wallet: Wallet.OWallet });
81
+ case Wallet.Cosmostation:
82
+ return new CosmostationWalletStrategy({ ...args });
83
+ case Wallet.Ledger:
84
+ return new LedgerLiveStrategy(ethWalletArgs);
85
+ case Wallet.LedgerLegacy:
86
+ return new LedgerLegacyStrategy(ethWalletArgs);
87
+ case Wallet.TrezorBip32:
88
+ return new TrezorBip32Strategy(ethWalletArgs);
89
+ case Wallet.TrezorBip44:
90
+ return new TrezorBip44Strategy(ethWalletArgs);
91
+ case Wallet.PrivateKey:
92
+ return new PrivateKeyWalletStrategy(ethWalletArgs);
93
+ case Wallet.Turnkey:
94
+ if (!args.metadata?.turnkey?.defaultOrganizationId) {
95
+ return undefined;
96
+ }
97
+ return new TurnkeyWalletStrategy(ethWalletArgs);
92
98
  case Wallet.Magic:
93
99
  if (!args.metadata?.magic?.apiKey || !args.metadata?.magic?.rpcEndpoint) {
94
100
  return undefined;
95
101
  }
96
102
  return new MagicStrategy(args);
97
- case Wallet.Turnkey:
98
- if (!args.metadata?.turnkey?.iframeContainerId ||
99
- !args.metadata?.turnkey?.defaultOrganizationId) {
103
+ case Wallet.WalletConnect:
104
+ if (!args.metadata?.walletConnect?.projectId) {
100
105
  return undefined;
101
106
  }
102
- return new TurnkeyWalletStrategy(ethWalletArgs);
107
+ return new WalletConnectStrategy(ethWalletArgs);
103
108
  default:
104
109
  return undefined;
105
110
  }
106
111
  };
107
- const createAllStrategies = (args) => {
108
- return Object.values(Wallet).reduce((strategies, wallet) => {
109
- if (strategies[wallet]) {
110
- return strategies;
111
- }
112
- strategies[wallet] = createStrategy({ args, wallet: wallet });
113
- return strategies;
114
- }, {});
115
- };
116
112
  export class WalletStrategy extends BaseWalletStrategy {
117
113
  constructor(args) {
118
- const strategies = createAllStrategies(args);
114
+ const strategies = {};
119
115
  super({
120
116
  ...args,
121
117
  strategies,
@@ -140,7 +136,12 @@ export class WalletStrategy extends BaseWalletStrategy {
140
136
  Wallet.PrivateKey,
141
137
  Wallet.WalletConnect,
142
138
  ];
143
- for (const wallet of Object.keys(this.strategies)) {
139
+ const strategiesWithPlaceholders = {
140
+ ...this.strategies,
141
+ [Wallet.PrivateKey]: undefined,
142
+ [Wallet.WalletConnect]: undefined,
143
+ };
144
+ for (const wallet of Object.keys(strategiesWithPlaceholders)) {
144
145
  const walletEnum = wallet;
145
146
  if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
146
147
  this.strategies[walletEnum] = createStrategy({
@@ -155,6 +156,20 @@ export class WalletStrategy extends BaseWalletStrategy {
155
156
  this.strategies[walletEnum]?.setMetadata?.(metadata);
156
157
  }
157
158
  }
159
+ getStrategy() {
160
+ if (this.strategies[this.wallet]) {
161
+ return this.strategies[this.wallet];
162
+ }
163
+ const strategy = createStrategy({
164
+ args: this.args,
165
+ wallet: this.wallet,
166
+ });
167
+ if (!strategy) {
168
+ throw new GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
169
+ }
170
+ this.strategies[this.wallet] = strategy;
171
+ return strategy;
172
+ }
158
173
  }
159
174
  export const createStrategyFactory = (args) => {
160
175
  return new WalletStrategy(args);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-strategy",
3
3
  "description": "Wallet strategy with instantiated wallets",
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:cjs && yarn build:esm && yarn build:post",
44
+ "build": "pnpm build:cjs && pnpm build:esm && 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",
@@ -58,22 +58,22 @@
58
58
  "dependencies": {
59
59
  "@ethereumjs/common": "^3.1.1",
60
60
  "@ethereumjs/tx": "^4.1.1",
61
- "@injectivelabs/exceptions": "^1.16.7",
62
- "@injectivelabs/networks": "^1.16.7",
63
- "@injectivelabs/sdk-ts": "^1.16.7",
64
- "@injectivelabs/ts-types": "^1.16.7",
65
- "@injectivelabs/utils": "^1.16.7",
66
- "@injectivelabs/wallet-base": "^1.16.7",
67
- "@injectivelabs/wallet-core": "^1.16.7",
68
- "@injectivelabs/wallet-cosmos": "^1.16.7",
69
- "@injectivelabs/wallet-cosmostation": "^1.16.7",
70
- "@injectivelabs/wallet-evm": "^1.16.7",
71
- "@injectivelabs/wallet-ledger": "^1.16.7",
72
- "@injectivelabs/wallet-magic": "^1.16.7",
73
- "@injectivelabs/wallet-private-key": "^1.16.7",
74
- "@injectivelabs/wallet-trezor": "^1.16.7",
75
- "@injectivelabs/wallet-turnkey": "^1.16.7",
76
- "@injectivelabs/wallet-wallet-connect": "^1.16.7",
61
+ "@injectivelabs/exceptions": "1.16.6",
62
+ "@injectivelabs/networks": "1.16.8",
63
+ "@injectivelabs/sdk-ts": "1.16.8",
64
+ "@injectivelabs/ts-types": "1.16.8",
65
+ "@injectivelabs/utils": "1.16.8",
66
+ "@injectivelabs/wallet-base": "1.16.8",
67
+ "@injectivelabs/wallet-core": "1.16.8",
68
+ "@injectivelabs/wallet-cosmos": "1.16.8",
69
+ "@injectivelabs/wallet-cosmostation": "1.16.8",
70
+ "@injectivelabs/wallet-evm": "1.16.8",
71
+ "@injectivelabs/wallet-ledger": "1.16.8",
72
+ "@injectivelabs/wallet-magic": "1.16.8",
73
+ "@injectivelabs/wallet-private-key": "1.16.8",
74
+ "@injectivelabs/wallet-trezor": "1.16.8",
75
+ "@injectivelabs/wallet-turnkey": "1.16.8",
76
+ "@injectivelabs/wallet-wallet-connect": "1.16.8",
77
77
  "alchemy-sdk": "^3.4.7",
78
78
  "eip1193-provider": "^1.0.1",
79
79
  "eth-sig-util": "^3.0.1",
@@ -87,5 +87,5 @@
87
87
  "@types/hdkey": "^2.0.1",
88
88
  "shx": "^0.3.3"
89
89
  },
90
- "gitHead": "78f656ef404ef511dfe6e4cc9defcae0a7cbec76"
90
+ "gitHead": "8bdbbfff8a07053ec2cd91a7103bfe99975672b4"
91
91
  }