@injectivelabs/wallet-strategy 0.0.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 ADDED
@@ -0,0 +1,64 @@
1
+ # 🌟 Injective Protocol - Wallet Strategy
2
+
3
+ <!-- TODO -->
4
+
5
+ [![downloads](https://img.shields.io/npm/dm/@injectivelabs/wallet-strategy.svg)](https://www.npmjs.com/package/@injectivelabs/wallet-strategy)
6
+ [![npm-version](https://img.shields.io/npm/v/@injectivelabs/wallet-strategy.svg)](https://www.npmjs.com/package/@injectivelabs/wallet-strategy)
7
+ [![license](https://img.shields.io/npm/l/express.svg)]()
8
+
9
+ _Package to use All Wallets on Injective via the wallet strategy._
10
+
11
+ ---
12
+
13
+ ## 📚 Installation
14
+
15
+ ```bash
16
+ yarn add @injectivelabs/wallet-strategy
17
+ ```
18
+
19
+ ---
20
+
21
+ ## 📖 Documentation
22
+
23
+ ```typescript
24
+ import { WalletStrategy } from '@injectivelabs/wallet-strategy'
25
+
26
+ const walletStrategy = new WalletStrategy(args)
27
+ ```
28
+
29
+ Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy)
30
+
31
+ ---
32
+
33
+ ## 📜 Contribution
34
+
35
+ **Contribution guides and practices will be available once there is a stable foundation of the whole package set within the `injective-ts` repo.**
36
+
37
+ ---
38
+
39
+ ## ⛑ Support
40
+
41
+ Reach out to us at one of the following places!
42
+
43
+ - Website at <a href="https://injective.com" target="_blank">`injective.com`</a>
44
+ - Twitter at <a href="https://twitter.com/Injective_" target="_blank">`@Injective`</a>
45
+ - Discord at <a href="https://discord.com/invite/NK4qdbv" target="_blank">`Discord`</a>
46
+ - Telegram at <a href="https://t.me/joininjective" target="_blank">`Telegram`</a>
47
+
48
+ ---
49
+
50
+ ## 🔓 License
51
+
52
+ Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
53
+
54
+ <a href="https://iili.io/mNneZN.md.png"><img src="https://iili.io/mNneZN.md.png" style="width: 300px; max-width: 100%; height: auto" />
55
+
56
+ Originally released by Injective Labs Inc. under: <br />
57
+ Apache License <br />
58
+ Version 2.0, January 2004 <br />
59
+ http://www.apache.org/licenses/
60
+
61
+ <p>&nbsp;</p>
62
+ <div align="center">
63
+ <sub><em>Powering the future of decentralized finance.</em></sub>
64
+ </div>
@@ -0,0 +1,2 @@
1
+ export * from './strategy';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
@@ -0,0 +1,18 @@
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"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,16 @@
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;
16
+ //# sourceMappingURL=WalletStrategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WalletStrategy.d.ts","sourceRoot":"","sources":["../../../src/strategy/WalletStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,uBAAuB,EACvB,6BAA6B,EAG9B,MAAM,4BAA4B,CAAA;AAOnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AA6H/D,qBAAa,cAAe,SAAQ,kBAAkB;gBACxC,IAAI,EAAE,uBAAuB;IASzC;;;;;;;OAOG;IACI,UAAU,CAAC,OAAO,CAAC,EAAE,6BAA6B;CAe1D;AAED,eAAO,MAAM,qBAAqB,SAAU,uBAAuB,mBAElE,CAAA"}
@@ -0,0 +1,116 @@
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
+ var _a, _b, _c, _d, _e, _f, _g, _h;
27
+ /**
28
+ * If we only want to use Cosmos Native Wallets
29
+ * We are not creating strategies for Ethereum Native Wallets
30
+ */
31
+ if ((0, wallet_base_1.isEthWallet)(wallet) && ethereumWalletsDisabled(args)) {
32
+ return undefined;
33
+ }
34
+ const ethWalletArgs = {
35
+ chainId: args.chainId,
36
+ ethereumOptions: args.ethereumOptions,
37
+ };
38
+ switch (wallet) {
39
+ case wallet_base_1.Wallet.Metamask:
40
+ return new wallet_evm_1.EvmWalletStrategy(Object.assign(Object.assign({}, ethWalletArgs), { wallet: wallet_base_1.Wallet.Metamask }));
41
+ case wallet_base_1.Wallet.Ledger:
42
+ return new wallet_ledger_1.LedgerLiveStrategy(ethWalletArgs);
43
+ case wallet_base_1.Wallet.LedgerLegacy:
44
+ return new wallet_ledger_1.LedgerLegacyStrategy(ethWalletArgs);
45
+ case wallet_base_1.Wallet.TrustWallet:
46
+ return new wallet_evm_1.EvmWalletStrategy(Object.assign(Object.assign({}, ethWalletArgs), { wallet: wallet_base_1.Wallet.TrustWallet }));
47
+ case wallet_base_1.Wallet.Trezor:
48
+ return new wallet_trezor_1.TrezorWalletStrategy(ethWalletArgs);
49
+ case wallet_base_1.Wallet.Phantom:
50
+ return new wallet_evm_1.EvmWalletStrategy(Object.assign(Object.assign({}, ethWalletArgs), { wallet: wallet_base_1.Wallet.Phantom }));
51
+ case wallet_base_1.Wallet.OkxWallet:
52
+ return new wallet_evm_1.EvmWalletStrategy(Object.assign(Object.assign({}, ethWalletArgs), { wallet: wallet_base_1.Wallet.OkxWallet }));
53
+ case wallet_base_1.Wallet.BitGet:
54
+ return new wallet_evm_1.EvmWalletStrategy(Object.assign(Object.assign({}, ethWalletArgs), { wallet: wallet_base_1.Wallet.BitGet }));
55
+ case wallet_base_1.Wallet.WalletConnect:
56
+ return new wallet_wallet_connect_1.WalletConnectStrategy(Object.assign(Object.assign({}, ethWalletArgs), { metadata: (_a = args.options) === null || _a === void 0 ? void 0 : _a.metadata }));
57
+ case wallet_base_1.Wallet.PrivateKey:
58
+ return new wallet_private_key_1.PrivateKeyWalletStrategy(Object.assign(Object.assign({}, ethWalletArgs), { privateKey: (_b = args.options) === null || _b === void 0 ? void 0 : _b.privateKey }));
59
+ case wallet_base_1.Wallet.Keplr:
60
+ return new wallet_cosmos_1.CosmosWalletStrategy(Object.assign(Object.assign({}, args), { wallet: wallet_base_1.Wallet.Keplr }));
61
+ case wallet_base_1.Wallet.Cosmostation:
62
+ return new wallet_cosmostation_1.CosmostationWalletStrategy(Object.assign({}, args));
63
+ case wallet_base_1.Wallet.Leap:
64
+ return new wallet_cosmos_1.CosmosWalletStrategy(Object.assign(Object.assign({}, args), { wallet: wallet_base_1.Wallet.Leap }));
65
+ case wallet_base_1.Wallet.Ninji:
66
+ return new wallet_cosmos_1.CosmosWalletStrategy(Object.assign(Object.assign({}, args), { wallet: wallet_base_1.Wallet.Ninji }));
67
+ case wallet_base_1.Wallet.OWallet:
68
+ return new wallet_cosmos_1.CosmosWalletStrategy(Object.assign(Object.assign({}, args), { wallet: wallet_base_1.Wallet.OWallet }));
69
+ case wallet_base_1.Wallet.Magic:
70
+ if (!((_d = (_c = args.options) === null || _c === void 0 ? void 0 : _c.metadata) === null || _d === void 0 ? void 0 : _d.magic) ||
71
+ !((_f = (_e = args.options) === null || _e === void 0 ? void 0 : _e.metadata.magic) === null || _f === void 0 ? void 0 : _f.apiKey) ||
72
+ !((_h = (_g = args.options) === null || _g === void 0 ? void 0 : _g.metadata.magic) === null || _h === void 0 ? void 0 : _h.rpcEndpoint)) {
73
+ return undefined;
74
+ }
75
+ return new wallet_magic_1.MagicStrategy(Object.assign(Object.assign({}, args), { metadata: args.options.metadata.magic }));
76
+ default:
77
+ return undefined;
78
+ }
79
+ };
80
+ const createAllStrategies = (args) => {
81
+ return Object.values(wallet_base_1.Wallet).reduce((strategies, wallet) => (Object.assign(Object.assign({}, strategies), { [wallet]: createStrategy({ args, wallet: wallet }) })), {});
82
+ };
83
+ class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
84
+ constructor(args) {
85
+ const strategies = createAllStrategies(args);
86
+ super(Object.assign(Object.assign({}, args), { strategies }));
87
+ }
88
+ /**
89
+ * Case 1: Private Key is set dynamically
90
+ * If we have a dynamically set private key,
91
+ * we are creating a new PrivateKey strategy
92
+ * with the specified private key
93
+ *
94
+ * Case 2: Wallet Connect Metadata set dynamically
95
+ */
96
+ setOptions(options) {
97
+ if (options === null || options === void 0 ? void 0 : options.privateKey) {
98
+ this.strategies[wallet_base_1.Wallet.PrivateKey] = createStrategy({
99
+ args: Object.assign(Object.assign({}, this.args), { options: { privateKey: options.privateKey } }),
100
+ wallet: wallet_base_1.Wallet.PrivateKey,
101
+ });
102
+ }
103
+ if (options === null || options === void 0 ? void 0 : options.metadata) {
104
+ this.strategies[wallet_base_1.Wallet.WalletConnect] = createStrategy({
105
+ args: Object.assign(Object.assign({}, this.args), { options: { metadata: options.metadata } }),
106
+ wallet: wallet_base_1.Wallet.WalletConnect,
107
+ });
108
+ }
109
+ }
110
+ }
111
+ exports.WalletStrategy = WalletStrategy;
112
+ const createStrategyFactory = (args) => {
113
+ return new WalletStrategy(args);
114
+ };
115
+ exports.createStrategyFactory = createStrategyFactory;
116
+ //# sourceMappingURL=WalletStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WalletStrategy.js","sourceRoot":"","sources":["../../../src/strategy/WalletStrategy.ts"],"names":[],"mappings":";;;AAAA,4DAUmC;AACnC,gEAGqC;AACrC,8DAA2D;AAC3D,0DAA6D;AAC7D,4DAA+D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EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,GAAE;gBACnE,MAAM,EAAE,oBAAM,CAAC,UAAU;aAC1B,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,EAAE,CAAC;YACtB,IAAI,CAAC,UAAU,CAAC,oBAAM,CAAC,aAAa,CAAC,GAAG,cAAc,CAAC;gBACrD,IAAI,kCAAO,IAAI,CAAC,IAAI,KAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,GAAE;gBAC/D,MAAM,EAAE,oBAAM,CAAC,aAAa;aAC7B,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF;AAjCD,wCAiCC;AAEM,MAAM,qBAAqB,GAAG,CAAC,IAA6B,EAAE,EAAE;IACrE,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,CAAA;AACjC,CAAC,CAAA;AAFY,QAAA,qBAAqB,yBAEjC"}
@@ -0,0 +1,2 @@
1
+ export * from './WalletStrategy';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/strategy/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,18 @@
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("./WalletStrategy"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/strategy/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC"}
@@ -0,0 +1,2 @@
1
+ export * from './strategy';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './strategy';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,16 @@
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;
16
+ //# sourceMappingURL=WalletStrategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WalletStrategy.d.ts","sourceRoot":"","sources":["../../../src/strategy/WalletStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,uBAAuB,EACvB,6BAA6B,EAG9B,MAAM,4BAA4B,CAAA;AAOnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AA6H/D,qBAAa,cAAe,SAAQ,kBAAkB;gBACxC,IAAI,EAAE,uBAAuB;IASzC;;;;;;;OAOG;IACI,UAAU,CAAC,OAAO,CAAC,EAAE,6BAA6B;CAe1D;AAED,eAAO,MAAM,qBAAqB,SAAU,uBAAuB,mBAElE,CAAA"}
@@ -0,0 +1,140 @@
1
+ import { Wallet, isEthWallet, } 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 { TrezorWalletStrategy } 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 (isEthWallet(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.Trezor:
50
+ return new TrezorWalletStrategy(ethWalletArgs);
51
+ case Wallet.Phantom:
52
+ return new EvmWalletStrategy({
53
+ ...ethWalletArgs,
54
+ wallet: Wallet.Phantom,
55
+ });
56
+ case Wallet.OkxWallet:
57
+ return new EvmWalletStrategy({
58
+ ...ethWalletArgs,
59
+ wallet: Wallet.OkxWallet,
60
+ });
61
+ case Wallet.BitGet:
62
+ return new EvmWalletStrategy({
63
+ ...ethWalletArgs,
64
+ wallet: Wallet.BitGet,
65
+ });
66
+ case Wallet.WalletConnect:
67
+ return new WalletConnectStrategy({
68
+ ...ethWalletArgs,
69
+ metadata: args.options?.metadata,
70
+ });
71
+ case Wallet.PrivateKey:
72
+ return new PrivateKeyWalletStrategy({
73
+ ...ethWalletArgs,
74
+ privateKey: args.options?.privateKey,
75
+ });
76
+ case Wallet.Keplr:
77
+ return new CosmosWalletStrategy({ ...args, wallet: Wallet.Keplr });
78
+ case Wallet.Cosmostation:
79
+ return new CosmostationWalletStrategy({ ...args });
80
+ case Wallet.Leap:
81
+ return new CosmosWalletStrategy({ ...args, wallet: Wallet.Leap });
82
+ case Wallet.Ninji:
83
+ return new CosmosWalletStrategy({ ...args, wallet: Wallet.Ninji });
84
+ case Wallet.OWallet:
85
+ return new CosmosWalletStrategy({ ...args, wallet: Wallet.OWallet });
86
+ case Wallet.Magic:
87
+ if (!args.options?.metadata?.magic ||
88
+ !args.options?.metadata.magic?.apiKey ||
89
+ !args.options?.metadata.magic?.rpcEndpoint) {
90
+ return undefined;
91
+ }
92
+ return new MagicStrategy({
93
+ ...args,
94
+ metadata: args.options.metadata.magic,
95
+ });
96
+ default:
97
+ return undefined;
98
+ }
99
+ };
100
+ const createAllStrategies = (args) => {
101
+ return Object.values(Wallet).reduce((strategies, wallet) => ({
102
+ ...strategies,
103
+ [wallet]: createStrategy({ args, wallet: wallet }),
104
+ }), {});
105
+ };
106
+ export class WalletStrategy extends BaseWalletStrategy {
107
+ constructor(args) {
108
+ const strategies = createAllStrategies(args);
109
+ super({
110
+ ...args,
111
+ strategies,
112
+ });
113
+ }
114
+ /**
115
+ * Case 1: Private Key is set dynamically
116
+ * If we have a dynamically set private key,
117
+ * we are creating a new PrivateKey strategy
118
+ * with the specified private key
119
+ *
120
+ * Case 2: Wallet Connect Metadata set dynamically
121
+ */
122
+ setOptions(options) {
123
+ if (options?.privateKey) {
124
+ this.strategies[Wallet.PrivateKey] = createStrategy({
125
+ args: { ...this.args, options: { privateKey: options.privateKey } },
126
+ wallet: Wallet.PrivateKey,
127
+ });
128
+ }
129
+ if (options?.metadata) {
130
+ this.strategies[Wallet.WalletConnect] = createStrategy({
131
+ args: { ...this.args, options: { metadata: options.metadata } },
132
+ wallet: Wallet.WalletConnect,
133
+ });
134
+ }
135
+ }
136
+ }
137
+ export const createStrategyFactory = (args) => {
138
+ return new WalletStrategy(args);
139
+ };
140
+ //# sourceMappingURL=WalletStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WalletStrategy.js","sourceRoot":"","sources":["../../../src/strategy/WalletStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,WAAW,GAQZ,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,oBAAoB,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A;QAE5C,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;OAOG;IACI,UAAU,CAAC,OAAuC;QACvD,IAAI,OAAO,EAAE,UAAU,EAAE,CAAC;YACxB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;gBAClD,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,EAAE;gBACnE,MAAM,EAAE,MAAM,CAAC,UAAU;aAC1B,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,cAAc,CAAC;gBACrD,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE;gBAC/D,MAAM,EAAE,MAAM,CAAC,aAAa;aAC7B,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAA6B,EAAE,EAAE;IACrE,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,CAAA;AACjC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './WalletStrategy';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/strategy/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './WalletStrategy';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/strategy/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@injectivelabs/wallet-strategy",
3
+ "description": "Wallet strategy with instantiated wallets",
4
+ "version": "0.0.2",
5
+ "sideEffects": false,
6
+ "author": {
7
+ "name": "InjectiveLabs",
8
+ "email": "admin@injectivelabs.org"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "types": "dist/cjs/index.d.ts",
12
+ "main": "dist/cjs/index.js",
13
+ "module": "dist/esm/index.js",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "_moduleAliases": {
18
+ "~wallet-strategy": "dist"
19
+ },
20
+ "scripts": {
21
+ "postinstall": "link-module-alias",
22
+ "build:cjs": "BUILD_MODE=cjs tsc --build tsconfig.build.json",
23
+ "build:esm": "BUILD_MODE=esm tsc --build tsconfig.build.esm.json",
24
+ "build": "yarn build:esm && yarn build:cjs && yarn build:post && link-module-alias",
25
+ "build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post && link-module-alias",
26
+ "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",
27
+ "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",
28
+ "test": "jest",
29
+ "test:watch": "jest --watch",
30
+ "test:ci": "jest --coverage --ci --reporters='jest-junit'",
31
+ "coverage": "jest --coverage",
32
+ "coverage:show": "live-server coverage",
33
+ "dev": "ts-node -r tsconfig-paths/register src/index.ts",
34
+ "start": "node dist/index.js"
35
+ },
36
+ "dependencies": {
37
+ "@ethereumjs/common": "^3.1.1",
38
+ "@ethereumjs/tx": "^4.1.1",
39
+ "@injectivelabs/exceptions": "^1.14.14",
40
+ "@injectivelabs/networks": "^1.14.15",
41
+ "@injectivelabs/sdk-ts": "^1.14.15",
42
+ "@injectivelabs/ts-types": "^1.14.14",
43
+ "@injectivelabs/utils": "^1.14.14",
44
+ "@injectivelabs/wallet-base": "^0.0.2",
45
+ "@injectivelabs/wallet-core": "^0.0.2",
46
+ "@injectivelabs/wallet-cosmos": "^0.0.2",
47
+ "@injectivelabs/wallet-cosmostation": "^0.0.2",
48
+ "@injectivelabs/wallet-evm": "^0.0.2",
49
+ "@injectivelabs/wallet-ledger": "^0.0.2",
50
+ "@injectivelabs/wallet-magic": "^0.0.2",
51
+ "@injectivelabs/wallet-private-key": "^0.0.2",
52
+ "@injectivelabs/wallet-trezor": "^0.0.2",
53
+ "@injectivelabs/wallet-wallet-connect": "^0.0.2",
54
+ "alchemy-sdk": "^2.6.3",
55
+ "eip1193-provider": "^1.0.1",
56
+ "eth-sig-util": "^3.0.1",
57
+ "ethereumjs-util": "^7.1.0",
58
+ "ethers": "^6.5.1",
59
+ "hdkey": "^2.0.1",
60
+ "link-module-alias": "^1.2.0",
61
+ "long": "^5.2.1",
62
+ "shx": "^0.3.3"
63
+ },
64
+ "devDependencies": {
65
+ "@types/eth-sig-util": "^2.1.1",
66
+ "@types/ethereumjs-util": "^6.1.0",
67
+ "@types/hdkey": "^2.0.1"
68
+ },
69
+ "resolutions": {
70
+ "**/libsodium": "npm:@bangjelkoski/noop",
71
+ "**/libsodium-wrappers": "npm:@bangjelkoski/noop"
72
+ },
73
+ "gitHead": "6442ae377bbfb3459d2fb3a44c650630a5b7f445"
74
+ }