@injectivelabs/wallet-strategy 1.16.1-alpha.6 → 1.16.2-alpha.0

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,38 +3,41 @@ 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;
25
26
  };
26
27
  const createStrategy = ({ args, wallet, }) => {
28
+ console.log('creating strategy for wallet:', wallet);
27
29
  /**
28
30
  * If we only want to use Cosmos Native Wallets
29
31
  * We are not creating strategies for Ethereum Native Wallets
30
32
  */
31
33
  if ((0, wallet_base_1.isEvmWallet)(wallet) && ethereumWalletsDisabled(args)) {
34
+ console.log('Skipping EVM wallet strategy creation due to disabled EVM options');
32
35
  return undefined;
33
36
  }
34
37
  const ethWalletArgs = {
35
38
  ...args,
36
39
  chainId: args.chainId,
37
- ethereumOptions: args.ethereumOptions,
40
+ evmOptions: args.evmOptions,
38
41
  };
39
42
  switch (wallet) {
40
43
  case wallet_base_1.Wallet.Metamask:
@@ -98,8 +101,7 @@ const createStrategy = ({ args, wallet, }) => {
98
101
  }
99
102
  return new wallet_magic_1.MagicStrategy(args);
100
103
  case wallet_base_1.Wallet.Turnkey:
101
- if (!args.metadata?.turnkey?.iframeContainerId ||
102
- !args.metadata?.turnkey?.defaultOrganizationId) {
104
+ if (!args.metadata?.turnkey?.defaultOrganizationId) {
103
105
  return undefined;
104
106
  }
105
107
  return new wallet_turnkey_1.TurnkeyWalletStrategy(ethWalletArgs);
@@ -107,18 +109,9 @@ const createStrategy = ({ args, wallet, }) => {
107
109
  return undefined;
108
110
  }
109
111
  };
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
112
  class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
120
113
  constructor(args) {
121
- const strategies = createAllStrategies(args);
114
+ const strategies = {};
122
115
  super({
123
116
  ...args,
124
117
  strategies,
@@ -158,6 +151,25 @@ class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
158
151
  this.strategies[walletEnum]?.setMetadata?.(metadata);
159
152
  }
160
153
  }
154
+ getStrategy() {
155
+ console.log('creating strategy for wallet via getStrategy:', this.wallet);
156
+ if (this.strategies[this.wallet]) {
157
+ return this.strategies[this.wallet];
158
+ }
159
+ const strategy = createStrategy({
160
+ args: this.args,
161
+ wallet: this.wallet,
162
+ });
163
+ console.log(strategy, {
164
+ args: this.args,
165
+ wallet: this.wallet,
166
+ });
167
+ if (!strategy) {
168
+ throw new exceptions_1.GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
169
+ }
170
+ this.strategies[this.wallet] = strategy;
171
+ return strategy;
172
+ }
161
173
  }
162
174
  exports.WalletStrategy = WalletStrategy;
163
175
  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,37 +1,40 @@
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;
22
23
  };
23
24
  const createStrategy = ({ args, wallet, }) => {
25
+ console.log('creating strategy for wallet:', wallet);
24
26
  /**
25
27
  * If we only want to use Cosmos Native Wallets
26
28
  * We are not creating strategies for Ethereum Native Wallets
27
29
  */
28
30
  if (isEvmWallet(wallet) && ethereumWalletsDisabled(args)) {
31
+ console.log('Skipping EVM wallet strategy creation due to disabled EVM options');
29
32
  return undefined;
30
33
  }
31
34
  const ethWalletArgs = {
32
35
  ...args,
33
36
  chainId: args.chainId,
34
- ethereumOptions: args.ethereumOptions,
37
+ evmOptions: args.evmOptions,
35
38
  };
36
39
  switch (wallet) {
37
40
  case Wallet.Metamask:
@@ -95,8 +98,7 @@ const createStrategy = ({ args, wallet, }) => {
95
98
  }
96
99
  return new MagicStrategy(args);
97
100
  case Wallet.Turnkey:
98
- if (!args.metadata?.turnkey?.iframeContainerId ||
99
- !args.metadata?.turnkey?.defaultOrganizationId) {
101
+ if (!args.metadata?.turnkey?.defaultOrganizationId) {
100
102
  return undefined;
101
103
  }
102
104
  return new TurnkeyWalletStrategy(ethWalletArgs);
@@ -104,18 +106,9 @@ const createStrategy = ({ args, wallet, }) => {
104
106
  return undefined;
105
107
  }
106
108
  };
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
109
  export class WalletStrategy extends BaseWalletStrategy {
117
110
  constructor(args) {
118
- const strategies = createAllStrategies(args);
111
+ const strategies = {};
119
112
  super({
120
113
  ...args,
121
114
  strategies,
@@ -155,6 +148,25 @@ export class WalletStrategy extends BaseWalletStrategy {
155
148
  this.strategies[walletEnum]?.setMetadata?.(metadata);
156
149
  }
157
150
  }
151
+ getStrategy() {
152
+ console.log('creating strategy for wallet via getStrategy:', this.wallet);
153
+ if (this.strategies[this.wallet]) {
154
+ return this.strategies[this.wallet];
155
+ }
156
+ const strategy = createStrategy({
157
+ args: this.args,
158
+ wallet: this.wallet,
159
+ });
160
+ console.log(strategy, {
161
+ args: this.args,
162
+ wallet: this.wallet,
163
+ });
164
+ if (!strategy) {
165
+ throw new GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
166
+ }
167
+ this.strategies[this.wallet] = strategy;
168
+ return strategy;
169
+ }
158
170
  }
159
171
  export const createStrategyFactory = (args) => {
160
172
  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.1-alpha.6",
4
+ "version": "1.16.2-alpha.0",
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.1-alpha.6",
62
- "@injectivelabs/networks": "^1.16.1-alpha.6",
63
- "@injectivelabs/sdk-ts": "^1.16.1-alpha.6",
64
- "@injectivelabs/ts-types": "^1.16.1-alpha.6",
65
- "@injectivelabs/utils": "^1.16.1-alpha.6",
66
- "@injectivelabs/wallet-base": "^1.16.1-alpha.6",
67
- "@injectivelabs/wallet-core": "^1.16.1-alpha.6",
68
- "@injectivelabs/wallet-cosmos": "^1.16.1-alpha.6",
69
- "@injectivelabs/wallet-cosmostation": "^1.16.1-alpha.6",
70
- "@injectivelabs/wallet-evm": "^1.16.1-alpha.6",
71
- "@injectivelabs/wallet-ledger": "^1.16.1-alpha.6",
72
- "@injectivelabs/wallet-magic": "^1.16.1-alpha.6",
73
- "@injectivelabs/wallet-private-key": "^1.16.1-alpha.6",
74
- "@injectivelabs/wallet-trezor": "^1.16.1-alpha.6",
75
- "@injectivelabs/wallet-turnkey": "^1.16.1-alpha.6",
76
- "@injectivelabs/wallet-wallet-connect": "^1.16.1-alpha.6",
61
+ "@injectivelabs/exceptions": "1.16.2-alpha.0",
62
+ "@injectivelabs/networks": "1.16.2-alpha.0",
63
+ "@injectivelabs/sdk-ts": "1.16.2-alpha.0",
64
+ "@injectivelabs/ts-types": "1.16.2-alpha.0",
65
+ "@injectivelabs/utils": "1.16.2-alpha.0",
66
+ "@injectivelabs/wallet-base": "1.16.2-alpha.0",
67
+ "@injectivelabs/wallet-core": "1.16.2-alpha.0",
68
+ "@injectivelabs/wallet-cosmos": "1.16.2-alpha.0",
69
+ "@injectivelabs/wallet-cosmostation": "1.16.2-alpha.0",
70
+ "@injectivelabs/wallet-evm": "1.16.2-alpha.0",
71
+ "@injectivelabs/wallet-ledger": "1.16.2-alpha.0",
72
+ "@injectivelabs/wallet-magic": "1.16.2-alpha.0",
73
+ "@injectivelabs/wallet-private-key": "1.16.2-alpha.0",
74
+ "@injectivelabs/wallet-trezor": "1.16.2-alpha.0",
75
+ "@injectivelabs/wallet-turnkey": "1.16.2-alpha.0",
76
+ "@injectivelabs/wallet-wallet-connect": "1.16.2-alpha.0",
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": "2e0a988a094d8284191b29502dde14f9696e7932"
90
+ "gitHead": "0377b0c3b44d79b598d08ca01930057dc05d9c7a"
91
91
  }