@injectivelabs/wallet-strategy 1.16.2-alpha.1 → 1.16.2

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
- pnpm add @injectivelabs/wallet-strategy
16
+ yarn add @injectivelabs/wallet-strategy
17
17
  ```
18
18
 
19
19
  ---
@@ -1,4 +1,4 @@
1
- import { type WalletMetadata, ConcreteWalletStrategy, WalletStrategyArguments } from '@injectivelabs/wallet-base';
1
+ import { type WalletMetadata, 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,6 +17,5 @@ export declare class WalletStrategy extends BaseWalletStrategy {
17
17
  *
18
18
  */
19
19
  setMetadata(metadata?: WalletMetadata): void;
20
- getStrategy(): ConcreteWalletStrategy;
21
20
  }
22
21
  export declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
@@ -3,41 +3,38 @@ 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");
7
6
  const wallet_magic_1 = require("@injectivelabs/wallet-magic");
8
- const exceptions_1 = require("@injectivelabs/exceptions");
9
7
  const wallet_evm_1 = require("@injectivelabs/wallet-evm");
10
8
  const wallet_core_1 = require("@injectivelabs/wallet-core");
11
9
  const wallet_cosmos_1 = require("@injectivelabs/wallet-cosmos");
10
+ const wallet_trezor_1 = require("@injectivelabs/wallet-trezor");
12
11
  const wallet_turnkey_1 = require("@injectivelabs/wallet-turnkey");
13
12
  const wallet_wallet_connect_1 = require("@injectivelabs/wallet-wallet-connect");
14
13
  const wallet_private_key_1 = require("@injectivelabs/wallet-private-key");
15
14
  const wallet_cosmostation_1 = require("@injectivelabs/wallet-cosmostation");
16
15
  const ethereumWalletsDisabled = (args) => {
17
- const { evmOptions } = args;
18
- if (!evmOptions) {
16
+ const { ethereumOptions } = args;
17
+ if (!ethereumOptions) {
19
18
  return true;
20
19
  }
21
- const { evmChainId } = evmOptions;
22
- if (!evmChainId) {
20
+ const { ethereumChainId } = ethereumOptions;
21
+ if (!ethereumChainId) {
23
22
  return true;
24
23
  }
25
24
  return false;
26
25
  };
27
26
  const createStrategy = ({ args, wallet, }) => {
28
- console.log('creating strategy for wallet:', wallet);
29
27
  /**
30
28
  * If we only want to use Cosmos Native Wallets
31
29
  * We are not creating strategies for Ethereum Native Wallets
32
30
  */
33
31
  if ((0, wallet_base_1.isEvmWallet)(wallet) && ethereumWalletsDisabled(args)) {
34
- console.log('Skipping EVM wallet strategy creation due to disabled EVM options');
35
32
  return undefined;
36
33
  }
37
34
  const ethWalletArgs = {
38
35
  ...args,
39
36
  chainId: args.chainId,
40
- evmOptions: args.evmOptions,
37
+ ethereumOptions: args.ethereumOptions,
41
38
  };
42
39
  switch (wallet) {
43
40
  case wallet_base_1.Wallet.Metamask:
@@ -45,11 +42,19 @@ const createStrategy = ({ args, wallet, }) => {
45
42
  ...ethWalletArgs,
46
43
  wallet: wallet_base_1.Wallet.Metamask,
47
44
  });
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);
48
49
  case wallet_base_1.Wallet.TrustWallet:
49
50
  return new wallet_evm_1.EvmWalletStrategy({
50
51
  ...ethWalletArgs,
51
52
  wallet: wallet_base_1.Wallet.TrustWallet,
52
53
  });
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);
53
58
  case wallet_base_1.Wallet.Phantom:
54
59
  return new wallet_evm_1.EvmWalletStrategy({
55
60
  ...ethWalletArgs,
@@ -70,53 +75,50 @@ const createStrategy = ({ args, wallet, }) => {
70
75
  ...ethWalletArgs,
71
76
  wallet: wallet_base_1.Wallet.Rainbow,
72
77
  });
73
- case wallet_base_1.Wallet.Rabby:
74
- return new wallet_evm_1.EvmWalletStrategy({
75
- ...ethWalletArgs,
76
- wallet: wallet_base_1.Wallet.Rabby,
77
- });
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);
78
85
  case wallet_base_1.Wallet.Keplr:
79
86
  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 });
80
89
  case wallet_base_1.Wallet.Leap:
81
90
  return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Leap });
82
91
  case wallet_base_1.Wallet.Ninji:
83
92
  return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Ninji });
84
93
  case wallet_base_1.Wallet.OWallet:
85
94
  return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.OWallet });
86
- case wallet_base_1.Wallet.Cosmostation:
87
- return new wallet_cosmostation_1.CosmostationWalletStrategy({ ...args });
88
- case wallet_base_1.Wallet.Ledger:
89
- return new wallet_ledger_1.LedgerLiveStrategy(ethWalletArgs);
90
- case wallet_base_1.Wallet.LedgerLegacy:
91
- return new wallet_ledger_1.LedgerLegacyStrategy(ethWalletArgs);
92
- case wallet_base_1.Wallet.TrezorBip32:
93
- return new wallet_trezor_1.TrezorBip32Strategy(ethWalletArgs);
94
- case wallet_base_1.Wallet.TrezorBip44:
95
- return new wallet_trezor_1.TrezorBip44Strategy(ethWalletArgs);
96
- case wallet_base_1.Wallet.PrivateKey:
97
- return new wallet_private_key_1.PrivateKeyWalletStrategy(ethWalletArgs);
98
- case wallet_base_1.Wallet.Turnkey:
99
- if (!args.metadata?.turnkey?.defaultOrganizationId) {
100
- return undefined;
101
- }
102
- return new wallet_turnkey_1.TurnkeyWalletStrategy(ethWalletArgs);
103
95
  case wallet_base_1.Wallet.Magic:
104
96
  if (!args.metadata?.magic?.apiKey || !args.metadata?.magic?.rpcEndpoint) {
105
97
  return undefined;
106
98
  }
107
99
  return new wallet_magic_1.MagicStrategy(args);
108
- case wallet_base_1.Wallet.WalletConnect:
109
- if (!args.metadata?.walletConnect?.projectId) {
100
+ case wallet_base_1.Wallet.Turnkey:
101
+ if (!args.metadata?.turnkey?.iframeContainerId ||
102
+ !args.metadata?.turnkey?.defaultOrganizationId) {
110
103
  return undefined;
111
104
  }
112
- return new wallet_wallet_connect_1.WalletConnectStrategy(ethWalletArgs);
105
+ return new wallet_turnkey_1.TurnkeyWalletStrategy(ethWalletArgs);
113
106
  default:
114
107
  return undefined;
115
108
  }
116
109
  };
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
+ };
117
119
  class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
118
120
  constructor(args) {
119
- const strategies = {};
121
+ const strategies = createAllStrategies(args);
120
122
  super({
121
123
  ...args,
122
124
  strategies,
@@ -156,25 +158,6 @@ class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
156
158
  this.strategies[walletEnum]?.setMetadata?.(metadata);
157
159
  }
158
160
  }
159
- getStrategy() {
160
- console.log('creating strategy for wallet via getStrategy:', this.wallet);
161
- if (this.strategies[this.wallet]) {
162
- return this.strategies[this.wallet];
163
- }
164
- const strategy = createStrategy({
165
- args: this.args,
166
- wallet: this.wallet,
167
- });
168
- console.log(strategy, {
169
- args: this.args,
170
- wallet: this.wallet,
171
- });
172
- if (!strategy) {
173
- throw new exceptions_1.GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
174
- }
175
- this.strategies[this.wallet] = strategy;
176
- return strategy;
177
- }
178
161
  }
179
162
  exports.WalletStrategy = WalletStrategy;
180
163
  const createStrategyFactory = (args) => {
@@ -1,4 +1,4 @@
1
- import { type WalletMetadata, ConcreteWalletStrategy, WalletStrategyArguments } from '@injectivelabs/wallet-base';
1
+ import { type WalletMetadata, 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,6 +17,5 @@ export declare class WalletStrategy extends BaseWalletStrategy {
17
17
  *
18
18
  */
19
19
  setMetadata(metadata?: WalletMetadata): void;
20
- getStrategy(): ConcreteWalletStrategy;
21
20
  }
22
21
  export declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
@@ -1,40 +1,37 @@
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';
4
3
  import { MagicStrategy } from '@injectivelabs/wallet-magic';
5
- import { GeneralException } from '@injectivelabs/exceptions';
6
4
  import { EvmWalletStrategy } from '@injectivelabs/wallet-evm';
7
5
  import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
8
6
  import { CosmosWalletStrategy } from '@injectivelabs/wallet-cosmos';
7
+ import { TrezorBip32Strategy, TrezorBip44Strategy, } from '@injectivelabs/wallet-trezor';
9
8
  import { TurnkeyWalletStrategy } from '@injectivelabs/wallet-turnkey';
10
9
  import { WalletConnectStrategy } from '@injectivelabs/wallet-wallet-connect';
11
10
  import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key';
12
11
  import { CosmostationWalletStrategy } from '@injectivelabs/wallet-cosmostation';
13
12
  const ethereumWalletsDisabled = (args) => {
14
- const { evmOptions } = args;
15
- if (!evmOptions) {
13
+ const { ethereumOptions } = args;
14
+ if (!ethereumOptions) {
16
15
  return true;
17
16
  }
18
- const { evmChainId } = evmOptions;
19
- if (!evmChainId) {
17
+ const { ethereumChainId } = ethereumOptions;
18
+ if (!ethereumChainId) {
20
19
  return true;
21
20
  }
22
21
  return false;
23
22
  };
24
23
  const createStrategy = ({ args, wallet, }) => {
25
- console.log('creating strategy for wallet:', wallet);
26
24
  /**
27
25
  * If we only want to use Cosmos Native Wallets
28
26
  * We are not creating strategies for Ethereum Native Wallets
29
27
  */
30
28
  if (isEvmWallet(wallet) && ethereumWalletsDisabled(args)) {
31
- console.log('Skipping EVM wallet strategy creation due to disabled EVM options');
32
29
  return undefined;
33
30
  }
34
31
  const ethWalletArgs = {
35
32
  ...args,
36
33
  chainId: args.chainId,
37
- evmOptions: args.evmOptions,
34
+ ethereumOptions: args.ethereumOptions,
38
35
  };
39
36
  switch (wallet) {
40
37
  case Wallet.Metamask:
@@ -42,11 +39,19 @@ const createStrategy = ({ args, wallet, }) => {
42
39
  ...ethWalletArgs,
43
40
  wallet: Wallet.Metamask,
44
41
  });
42
+ case Wallet.Ledger:
43
+ return new LedgerLiveStrategy(ethWalletArgs);
44
+ case Wallet.LedgerLegacy:
45
+ return new LedgerLegacyStrategy(ethWalletArgs);
45
46
  case Wallet.TrustWallet:
46
47
  return new EvmWalletStrategy({
47
48
  ...ethWalletArgs,
48
49
  wallet: Wallet.TrustWallet,
49
50
  });
51
+ case Wallet.TrezorBip32:
52
+ return new TrezorBip32Strategy(ethWalletArgs);
53
+ case Wallet.TrezorBip44:
54
+ return new TrezorBip44Strategy(ethWalletArgs);
50
55
  case Wallet.Phantom:
51
56
  return new EvmWalletStrategy({
52
57
  ...ethWalletArgs,
@@ -67,53 +72,50 @@ const createStrategy = ({ args, wallet, }) => {
67
72
  ...ethWalletArgs,
68
73
  wallet: Wallet.Rainbow,
69
74
  });
70
- case Wallet.Rabby:
71
- return new EvmWalletStrategy({
72
- ...ethWalletArgs,
73
- wallet: Wallet.Rabby,
74
- });
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);
75
82
  case Wallet.Keplr:
76
83
  return new CosmosWalletStrategy({ ...args, wallet: Wallet.Keplr });
84
+ case Wallet.Cosmostation:
85
+ return new CosmostationWalletStrategy({ ...args });
77
86
  case Wallet.Leap:
78
87
  return new CosmosWalletStrategy({ ...args, wallet: Wallet.Leap });
79
88
  case Wallet.Ninji:
80
89
  return new CosmosWalletStrategy({ ...args, wallet: Wallet.Ninji });
81
90
  case Wallet.OWallet:
82
91
  return new CosmosWalletStrategy({ ...args, wallet: Wallet.OWallet });
83
- case Wallet.Cosmostation:
84
- return new CosmostationWalletStrategy({ ...args });
85
- case Wallet.Ledger:
86
- return new LedgerLiveStrategy(ethWalletArgs);
87
- case Wallet.LedgerLegacy:
88
- return new LedgerLegacyStrategy(ethWalletArgs);
89
- case Wallet.TrezorBip32:
90
- return new TrezorBip32Strategy(ethWalletArgs);
91
- case Wallet.TrezorBip44:
92
- return new TrezorBip44Strategy(ethWalletArgs);
93
- case Wallet.PrivateKey:
94
- return new PrivateKeyWalletStrategy(ethWalletArgs);
95
- case Wallet.Turnkey:
96
- if (!args.metadata?.turnkey?.defaultOrganizationId) {
97
- return undefined;
98
- }
99
- return new TurnkeyWalletStrategy(ethWalletArgs);
100
92
  case Wallet.Magic:
101
93
  if (!args.metadata?.magic?.apiKey || !args.metadata?.magic?.rpcEndpoint) {
102
94
  return undefined;
103
95
  }
104
96
  return new MagicStrategy(args);
105
- case Wallet.WalletConnect:
106
- if (!args.metadata?.walletConnect?.projectId) {
97
+ case Wallet.Turnkey:
98
+ if (!args.metadata?.turnkey?.iframeContainerId ||
99
+ !args.metadata?.turnkey?.defaultOrganizationId) {
107
100
  return undefined;
108
101
  }
109
- return new WalletConnectStrategy(ethWalletArgs);
102
+ return new TurnkeyWalletStrategy(ethWalletArgs);
110
103
  default:
111
104
  return undefined;
112
105
  }
113
106
  };
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
+ };
114
116
  export class WalletStrategy extends BaseWalletStrategy {
115
117
  constructor(args) {
116
- const strategies = {};
118
+ const strategies = createAllStrategies(args);
117
119
  super({
118
120
  ...args,
119
121
  strategies,
@@ -153,25 +155,6 @@ export class WalletStrategy extends BaseWalletStrategy {
153
155
  this.strategies[walletEnum]?.setMetadata?.(metadata);
154
156
  }
155
157
  }
156
- getStrategy() {
157
- console.log('creating strategy for wallet via getStrategy:', this.wallet);
158
- if (this.strategies[this.wallet]) {
159
- return this.strategies[this.wallet];
160
- }
161
- const strategy = createStrategy({
162
- args: this.args,
163
- wallet: this.wallet,
164
- });
165
- console.log(strategy, {
166
- args: this.args,
167
- wallet: this.wallet,
168
- });
169
- if (!strategy) {
170
- throw new GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
171
- }
172
- this.strategies[this.wallet] = strategy;
173
- return strategy;
174
- }
175
158
  }
176
159
  export const createStrategyFactory = (args) => {
177
160
  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.2-alpha.1",
4
+ "version": "1.16.2",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -41,10 +41,10 @@
41
41
  }
42
42
  },
43
43
  "scripts": {
44
- "build": "pnpm build:cjs && pnpm build:esm && pnpm build:post",
44
+ "build": "yarn build:cjs && yarn build:esm && yarn 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 && pnpm build:post",
47
+ "build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn 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.2-alpha.1",
62
- "@injectivelabs/networks": "1.16.2-alpha.1",
63
- "@injectivelabs/sdk-ts": "1.16.2-alpha.1",
64
- "@injectivelabs/ts-types": "1.16.2-alpha.1",
65
- "@injectivelabs/utils": "1.16.2-alpha.1",
66
- "@injectivelabs/wallet-base": "1.16.2-alpha.1",
67
- "@injectivelabs/wallet-core": "1.16.2-alpha.1",
68
- "@injectivelabs/wallet-cosmos": "1.16.2-alpha.1",
69
- "@injectivelabs/wallet-cosmostation": "1.16.2-alpha.1",
70
- "@injectivelabs/wallet-evm": "1.16.2-alpha.1",
71
- "@injectivelabs/wallet-ledger": "1.16.2-alpha.1",
72
- "@injectivelabs/wallet-magic": "1.16.2-alpha.1",
73
- "@injectivelabs/wallet-private-key": "1.16.2-alpha.1",
74
- "@injectivelabs/wallet-trezor": "1.16.2-alpha.1",
75
- "@injectivelabs/wallet-turnkey": "1.16.2-alpha.1",
76
- "@injectivelabs/wallet-wallet-connect": "1.16.2-alpha.1",
61
+ "@injectivelabs/exceptions": "^1.16.2",
62
+ "@injectivelabs/networks": "^1.16.2",
63
+ "@injectivelabs/sdk-ts": "^1.16.2",
64
+ "@injectivelabs/ts-types": "^1.16.2",
65
+ "@injectivelabs/utils": "^1.16.2",
66
+ "@injectivelabs/wallet-base": "^1.16.2",
67
+ "@injectivelabs/wallet-core": "^1.16.2",
68
+ "@injectivelabs/wallet-cosmos": "^1.16.2",
69
+ "@injectivelabs/wallet-cosmostation": "^1.16.2",
70
+ "@injectivelabs/wallet-evm": "^1.16.2",
71
+ "@injectivelabs/wallet-ledger": "^1.16.2",
72
+ "@injectivelabs/wallet-magic": "^1.16.2",
73
+ "@injectivelabs/wallet-private-key": "^1.16.2",
74
+ "@injectivelabs/wallet-trezor": "^1.16.2",
75
+ "@injectivelabs/wallet-turnkey": "^1.16.2",
76
+ "@injectivelabs/wallet-wallet-connect": "^1.16.2",
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": "25f2492ee251504d8b0c1f3e4ce49e96e759294b"
90
+ "gitHead": "56e3f6c8f399c2d881a65858e8e0b1b39828a917"
91
91
  }