@injectivelabs/wallet-strategy 1.15.0 → 1.15.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.
@@ -0,0 +1 @@
1
+ export * from './strategy/index.js';
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./strategy/index.js"), exports);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,15 @@
1
+ import { WalletStrategyArguments, ConcreteWalletStrategyOptions } from '@injectivelabs/wallet-base';
2
+ import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
3
+ export declare class WalletStrategy extends BaseWalletStrategy {
4
+ constructor(args: WalletStrategyArguments);
5
+ /**
6
+ * Case 1: Private Key is set dynamically
7
+ * If we have a dynamically set private key,
8
+ * we are creating a new PrivateKey strategy
9
+ * with the specified private key
10
+ *
11
+ * Case 2: Wallet Connect Metadata set dynamically
12
+ */
13
+ setOptions(options?: ConcreteWalletStrategyOptions): void;
14
+ }
15
+ export declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStrategyFactory = exports.WalletStrategy = void 0;
4
+ const wallet_base_1 = require("@injectivelabs/wallet-base");
5
+ const wallet_ledger_1 = require("@injectivelabs/wallet-ledger");
6
+ const wallet_magic_1 = require("@injectivelabs/wallet-magic");
7
+ const wallet_evm_1 = require("@injectivelabs/wallet-evm");
8
+ const wallet_core_1 = require("@injectivelabs/wallet-core");
9
+ const wallet_cosmos_1 = require("@injectivelabs/wallet-cosmos");
10
+ const wallet_trezor_1 = require("@injectivelabs/wallet-trezor");
11
+ const wallet_wallet_connect_1 = require("@injectivelabs/wallet-wallet-connect");
12
+ const wallet_private_key_1 = require("@injectivelabs/wallet-private-key");
13
+ const wallet_cosmostation_1 = require("@injectivelabs/wallet-cosmostation");
14
+ const ethereumWalletsDisabled = (args) => {
15
+ const { ethereumOptions } = args;
16
+ if (!ethereumOptions) {
17
+ return true;
18
+ }
19
+ const { ethereumChainId } = ethereumOptions;
20
+ if (!ethereumChainId) {
21
+ return true;
22
+ }
23
+ return false;
24
+ };
25
+ const createStrategy = ({ args, wallet, }) => {
26
+ /**
27
+ * If we only want to use Cosmos Native Wallets
28
+ * We are not creating strategies for Ethereum Native Wallets
29
+ */
30
+ if ((0, wallet_base_1.isEvmWallet)(wallet) && ethereumWalletsDisabled(args)) {
31
+ return undefined;
32
+ }
33
+ const ethWalletArgs = {
34
+ chainId: args.chainId,
35
+ ethereumOptions: args.ethereumOptions,
36
+ };
37
+ switch (wallet) {
38
+ case wallet_base_1.Wallet.Metamask:
39
+ return new wallet_evm_1.EvmWalletStrategy({
40
+ ...ethWalletArgs,
41
+ wallet: wallet_base_1.Wallet.Metamask,
42
+ });
43
+ case wallet_base_1.Wallet.Ledger:
44
+ return new wallet_ledger_1.LedgerLiveStrategy(ethWalletArgs);
45
+ case wallet_base_1.Wallet.LedgerLegacy:
46
+ return new wallet_ledger_1.LedgerLegacyStrategy(ethWalletArgs);
47
+ case wallet_base_1.Wallet.TrustWallet:
48
+ return new wallet_evm_1.EvmWalletStrategy({
49
+ ...ethWalletArgs,
50
+ wallet: wallet_base_1.Wallet.TrustWallet,
51
+ });
52
+ case wallet_base_1.Wallet.TrezorBip32:
53
+ return new wallet_trezor_1.TrezorBip32Strategy(ethWalletArgs);
54
+ case wallet_base_1.Wallet.TrezorBip44:
55
+ return new wallet_trezor_1.TrezorBip44Strategy(ethWalletArgs);
56
+ case wallet_base_1.Wallet.Phantom:
57
+ return new wallet_evm_1.EvmWalletStrategy({
58
+ ...ethWalletArgs,
59
+ wallet: wallet_base_1.Wallet.Phantom,
60
+ });
61
+ case wallet_base_1.Wallet.OkxWallet:
62
+ return new wallet_evm_1.EvmWalletStrategy({
63
+ ...ethWalletArgs,
64
+ wallet: wallet_base_1.Wallet.OkxWallet,
65
+ });
66
+ case wallet_base_1.Wallet.BitGet:
67
+ return new wallet_evm_1.EvmWalletStrategy({
68
+ ...ethWalletArgs,
69
+ wallet: wallet_base_1.Wallet.BitGet,
70
+ });
71
+ case wallet_base_1.Wallet.WalletConnect:
72
+ return new wallet_wallet_connect_1.WalletConnectStrategy({
73
+ ...ethWalletArgs,
74
+ metadata: args.options?.metadata,
75
+ });
76
+ case wallet_base_1.Wallet.PrivateKey:
77
+ return new wallet_private_key_1.PrivateKeyWalletStrategy({
78
+ ...ethWalletArgs,
79
+ privateKey: args.options?.privateKey,
80
+ });
81
+ case wallet_base_1.Wallet.Keplr:
82
+ return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Keplr });
83
+ case wallet_base_1.Wallet.Cosmostation:
84
+ return new wallet_cosmostation_1.CosmostationWalletStrategy({ ...args });
85
+ case wallet_base_1.Wallet.Leap:
86
+ return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Leap });
87
+ case wallet_base_1.Wallet.Ninji:
88
+ return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Ninji });
89
+ case wallet_base_1.Wallet.OWallet:
90
+ return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.OWallet });
91
+ case wallet_base_1.Wallet.Magic:
92
+ if (!args.options?.metadata?.magic ||
93
+ !args.options?.metadata.magic?.apiKey ||
94
+ !args.options?.metadata.magic?.rpcEndpoint) {
95
+ return undefined;
96
+ }
97
+ return new wallet_magic_1.MagicStrategy({
98
+ ...args,
99
+ metadata: args.options.metadata.magic,
100
+ });
101
+ default:
102
+ return undefined;
103
+ }
104
+ };
105
+ const createAllStrategies = (args) => {
106
+ return Object.values(wallet_base_1.Wallet).reduce((strategies, wallet) => {
107
+ if (strategies[wallet]) {
108
+ return strategies;
109
+ }
110
+ strategies[wallet] = createStrategy({ args, wallet: wallet });
111
+ return strategies;
112
+ }, {});
113
+ };
114
+ class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
115
+ constructor(args) {
116
+ const strategies = createAllStrategies(args);
117
+ super({
118
+ ...args,
119
+ strategies,
120
+ });
121
+ }
122
+ /**
123
+ * Case 1: Private Key is set dynamically
124
+ * If we have a dynamically set private key,
125
+ * we are creating a new PrivateKey strategy
126
+ * with the specified private key
127
+ *
128
+ * Case 2: Wallet Connect Metadata set dynamically
129
+ */
130
+ setOptions(options) {
131
+ if (options?.privateKey) {
132
+ this.strategies[wallet_base_1.Wallet.PrivateKey] = createStrategy({
133
+ args: { ...this.args, options: { privateKey: options.privateKey } },
134
+ wallet: wallet_base_1.Wallet.PrivateKey,
135
+ });
136
+ }
137
+ if (options?.metadata) {
138
+ this.strategies[wallet_base_1.Wallet.WalletConnect] = createStrategy({
139
+ args: { ...this.args, options: { metadata: options.metadata } },
140
+ wallet: wallet_base_1.Wallet.WalletConnect,
141
+ });
142
+ }
143
+ }
144
+ }
145
+ exports.WalletStrategy = WalletStrategy;
146
+ const createStrategyFactory = (args) => {
147
+ return new WalletStrategy(args);
148
+ };
149
+ exports.createStrategyFactory = createStrategyFactory;
@@ -0,0 +1 @@
1
+ export * from './strategy/index.js';
@@ -0,0 +1 @@
1
+ export * from './strategy/index.js';
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,15 @@
1
+ import { WalletStrategyArguments, ConcreteWalletStrategyOptions } from '@injectivelabs/wallet-base';
2
+ import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
3
+ export declare class WalletStrategy extends BaseWalletStrategy {
4
+ constructor(args: WalletStrategyArguments);
5
+ /**
6
+ * Case 1: Private Key is set dynamically
7
+ * If we have a dynamically set private key,
8
+ * we are creating a new PrivateKey strategy
9
+ * with the specified private key
10
+ *
11
+ * Case 2: Wallet Connect Metadata set dynamically
12
+ */
13
+ setOptions(options?: ConcreteWalletStrategyOptions): void;
14
+ }
15
+ export declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
@@ -0,0 +1,144 @@
1
+ import { Wallet, isEvmWallet, } from '@injectivelabs/wallet-base';
2
+ import { LedgerLiveStrategy, LedgerLegacyStrategy, } from '@injectivelabs/wallet-ledger';
3
+ import { MagicStrategy } from '@injectivelabs/wallet-magic';
4
+ import { EvmWalletStrategy } from '@injectivelabs/wallet-evm';
5
+ import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
6
+ import { CosmosWalletStrategy } from '@injectivelabs/wallet-cosmos';
7
+ import { TrezorBip32Strategy, TrezorBip44Strategy } from '@injectivelabs/wallet-trezor';
8
+ import { WalletConnectStrategy } from '@injectivelabs/wallet-wallet-connect';
9
+ import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key';
10
+ import { CosmostationWalletStrategy } from '@injectivelabs/wallet-cosmostation';
11
+ const ethereumWalletsDisabled = (args) => {
12
+ const { ethereumOptions } = args;
13
+ if (!ethereumOptions) {
14
+ return true;
15
+ }
16
+ const { ethereumChainId } = ethereumOptions;
17
+ if (!ethereumChainId) {
18
+ return true;
19
+ }
20
+ return false;
21
+ };
22
+ const createStrategy = ({ args, wallet, }) => {
23
+ /**
24
+ * If we only want to use Cosmos Native Wallets
25
+ * We are not creating strategies for Ethereum Native Wallets
26
+ */
27
+ if (isEvmWallet(wallet) && ethereumWalletsDisabled(args)) {
28
+ return undefined;
29
+ }
30
+ const ethWalletArgs = {
31
+ chainId: args.chainId,
32
+ ethereumOptions: args.ethereumOptions,
33
+ };
34
+ switch (wallet) {
35
+ case Wallet.Metamask:
36
+ return new EvmWalletStrategy({
37
+ ...ethWalletArgs,
38
+ wallet: Wallet.Metamask,
39
+ });
40
+ case Wallet.Ledger:
41
+ return new LedgerLiveStrategy(ethWalletArgs);
42
+ case Wallet.LedgerLegacy:
43
+ return new LedgerLegacyStrategy(ethWalletArgs);
44
+ case Wallet.TrustWallet:
45
+ return new EvmWalletStrategy({
46
+ ...ethWalletArgs,
47
+ wallet: Wallet.TrustWallet,
48
+ });
49
+ case Wallet.TrezorBip32:
50
+ return new TrezorBip32Strategy(ethWalletArgs);
51
+ case Wallet.TrezorBip44:
52
+ return new TrezorBip44Strategy(ethWalletArgs);
53
+ case Wallet.Phantom:
54
+ return new EvmWalletStrategy({
55
+ ...ethWalletArgs,
56
+ wallet: Wallet.Phantom,
57
+ });
58
+ case Wallet.OkxWallet:
59
+ return new EvmWalletStrategy({
60
+ ...ethWalletArgs,
61
+ wallet: Wallet.OkxWallet,
62
+ });
63
+ case Wallet.BitGet:
64
+ return new EvmWalletStrategy({
65
+ ...ethWalletArgs,
66
+ wallet: Wallet.BitGet,
67
+ });
68
+ case Wallet.WalletConnect:
69
+ return new WalletConnectStrategy({
70
+ ...ethWalletArgs,
71
+ metadata: args.options?.metadata,
72
+ });
73
+ case Wallet.PrivateKey:
74
+ return new PrivateKeyWalletStrategy({
75
+ ...ethWalletArgs,
76
+ privateKey: args.options?.privateKey,
77
+ });
78
+ case Wallet.Keplr:
79
+ return new CosmosWalletStrategy({ ...args, wallet: Wallet.Keplr });
80
+ case Wallet.Cosmostation:
81
+ return new CosmostationWalletStrategy({ ...args });
82
+ case Wallet.Leap:
83
+ return new CosmosWalletStrategy({ ...args, wallet: Wallet.Leap });
84
+ case Wallet.Ninji:
85
+ return new CosmosWalletStrategy({ ...args, wallet: Wallet.Ninji });
86
+ case Wallet.OWallet:
87
+ return new CosmosWalletStrategy({ ...args, wallet: Wallet.OWallet });
88
+ case Wallet.Magic:
89
+ if (!args.options?.metadata?.magic ||
90
+ !args.options?.metadata.magic?.apiKey ||
91
+ !args.options?.metadata.magic?.rpcEndpoint) {
92
+ return undefined;
93
+ }
94
+ return new MagicStrategy({
95
+ ...args,
96
+ metadata: args.options.metadata.magic,
97
+ });
98
+ default:
99
+ return undefined;
100
+ }
101
+ };
102
+ const createAllStrategies = (args) => {
103
+ return Object.values(Wallet).reduce((strategies, wallet) => {
104
+ if (strategies[wallet]) {
105
+ return strategies;
106
+ }
107
+ strategies[wallet] = createStrategy({ args, wallet: wallet });
108
+ return strategies;
109
+ }, {});
110
+ };
111
+ export class WalletStrategy extends BaseWalletStrategy {
112
+ constructor(args) {
113
+ const strategies = createAllStrategies(args);
114
+ super({
115
+ ...args,
116
+ strategies,
117
+ });
118
+ }
119
+ /**
120
+ * Case 1: Private Key is set dynamically
121
+ * If we have a dynamically set private key,
122
+ * we are creating a new PrivateKey strategy
123
+ * with the specified private key
124
+ *
125
+ * Case 2: Wallet Connect Metadata set dynamically
126
+ */
127
+ setOptions(options) {
128
+ if (options?.privateKey) {
129
+ this.strategies[Wallet.PrivateKey] = createStrategy({
130
+ args: { ...this.args, options: { privateKey: options.privateKey } },
131
+ wallet: Wallet.PrivateKey,
132
+ });
133
+ }
134
+ if (options?.metadata) {
135
+ this.strategies[Wallet.WalletConnect] = createStrategy({
136
+ args: { ...this.args, options: { metadata: options.metadata } },
137
+ wallet: Wallet.WalletConnect,
138
+ });
139
+ }
140
+ }
141
+ }
142
+ export const createStrategyFactory = (args) => {
143
+ return new WalletStrategy(args);
144
+ };
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.15.0",
4
+ "version": "1.15.2",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -58,21 +58,21 @@
58
58
  "dependencies": {
59
59
  "@ethereumjs/common": "^3.1.1",
60
60
  "@ethereumjs/tx": "^4.1.1",
61
- "@injectivelabs/exceptions": "^1.15.0",
62
- "@injectivelabs/networks": "^1.15.0",
63
- "@injectivelabs/sdk-ts": "^1.15.0",
64
- "@injectivelabs/ts-types": "^1.15.0",
65
- "@injectivelabs/utils": "^1.15.0",
66
- "@injectivelabs/wallet-base": "^1.15.0",
67
- "@injectivelabs/wallet-core": "^1.15.0",
68
- "@injectivelabs/wallet-cosmos": "^1.15.0",
69
- "@injectivelabs/wallet-cosmostation": "^1.15.0",
70
- "@injectivelabs/wallet-evm": "^1.15.0",
71
- "@injectivelabs/wallet-ledger": "^1.15.0",
72
- "@injectivelabs/wallet-magic": "^1.15.0",
73
- "@injectivelabs/wallet-private-key": "^1.15.0",
74
- "@injectivelabs/wallet-trezor": "^1.15.0",
75
- "@injectivelabs/wallet-wallet-connect": "^1.15.0",
61
+ "@injectivelabs/exceptions": "^1.15.1",
62
+ "@injectivelabs/networks": "^1.15.2",
63
+ "@injectivelabs/sdk-ts": "^1.15.2",
64
+ "@injectivelabs/ts-types": "^1.15.2",
65
+ "@injectivelabs/utils": "^1.15.2",
66
+ "@injectivelabs/wallet-base": "^1.15.2",
67
+ "@injectivelabs/wallet-core": "^1.15.2",
68
+ "@injectivelabs/wallet-cosmos": "^1.15.2",
69
+ "@injectivelabs/wallet-cosmostation": "^1.15.2",
70
+ "@injectivelabs/wallet-evm": "^1.15.2",
71
+ "@injectivelabs/wallet-ledger": "^1.15.2",
72
+ "@injectivelabs/wallet-magic": "^1.15.2",
73
+ "@injectivelabs/wallet-private-key": "^1.15.2",
74
+ "@injectivelabs/wallet-trezor": "^1.15.2",
75
+ "@injectivelabs/wallet-wallet-connect": "^1.15.2",
76
76
  "alchemy-sdk": "^3.4.7",
77
77
  "eip1193-provider": "^1.0.1",
78
78
  "eth-sig-util": "^3.0.1",
@@ -86,5 +86,5 @@
86
86
  "@types/hdkey": "^2.0.1",
87
87
  "shx": "^0.3.3"
88
88
  },
89
- "gitHead": "acae5b41a4c8a0ac4f137cce434b9db81800a1c5"
89
+ "gitHead": "64a57f3115b63114124d0d1fb61f75e520905499"
90
90
  }