@injectivelabs/wallet-strategy 1.16.37 → 1.16.38-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/dist/cjs/index.cjs +167 -0
- package/dist/cjs/index.d.cts +26 -0
- package/dist/cjs/package.json +2 -2
- package/dist/esm/index.d.ts +26 -1
- package/dist/esm/index.js +166 -1
- package/dist/esm/package.json +2 -2
- package/package.json +48 -47
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.js +0 -17
- package/dist/cjs/strategy/index.d.ts +0 -23
- package/dist/cjs/strategy/index.js +0 -182
- package/dist/esm/strategy/index.d.ts +0 -23
- package/dist/esm/strategy/index.js +0 -177
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
let __injectivelabs_wallet_magic = require("@injectivelabs/wallet-magic");
|
|
2
|
+
let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
|
|
3
|
+
let __injectivelabs_wallet_evm = require("@injectivelabs/wallet-evm");
|
|
4
|
+
let __injectivelabs_wallet_core = require("@injectivelabs/wallet-core");
|
|
5
|
+
let __injectivelabs_wallet_cosmos = require("@injectivelabs/wallet-cosmos");
|
|
6
|
+
let __injectivelabs_wallet_turnkey = require("@injectivelabs/wallet-turnkey");
|
|
7
|
+
let __injectivelabs_wallet_wallet_connect = require("@injectivelabs/wallet-wallet-connect");
|
|
8
|
+
let __injectivelabs_wallet_private_key = require("@injectivelabs/wallet-private-key");
|
|
9
|
+
let __injectivelabs_wallet_cosmostation = require("@injectivelabs/wallet-cosmostation");
|
|
10
|
+
let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
|
|
11
|
+
let __injectivelabs_wallet_ledger = require("@injectivelabs/wallet-ledger");
|
|
12
|
+
let __injectivelabs_wallet_trezor = require("@injectivelabs/wallet-trezor");
|
|
13
|
+
|
|
14
|
+
//#region src/strategy/index.ts
|
|
15
|
+
const ethereumWalletsDisabled = (args) => {
|
|
16
|
+
const { evmOptions } = args;
|
|
17
|
+
if (!evmOptions) return true;
|
|
18
|
+
const { evmChainId } = evmOptions;
|
|
19
|
+
if (!evmChainId) return true;
|
|
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 ((0, __injectivelabs_wallet_base.isEvmWallet)(wallet) && ethereumWalletsDisabled(args)) {
|
|
28
|
+
console.log("Skipping EVM wallet strategy creation due to disabled EVM options");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const ethWalletArgs = {
|
|
32
|
+
...args,
|
|
33
|
+
chainId: args.chainId,
|
|
34
|
+
evmOptions: args.evmOptions
|
|
35
|
+
};
|
|
36
|
+
switch (wallet) {
|
|
37
|
+
case __injectivelabs_wallet_base.Wallet.Metamask: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
|
|
38
|
+
...ethWalletArgs,
|
|
39
|
+
wallet: __injectivelabs_wallet_base.Wallet.Metamask
|
|
40
|
+
});
|
|
41
|
+
case __injectivelabs_wallet_base.Wallet.TrustWallet: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
|
|
42
|
+
...ethWalletArgs,
|
|
43
|
+
wallet: __injectivelabs_wallet_base.Wallet.TrustWallet
|
|
44
|
+
});
|
|
45
|
+
case __injectivelabs_wallet_base.Wallet.Phantom: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
|
|
46
|
+
...ethWalletArgs,
|
|
47
|
+
wallet: __injectivelabs_wallet_base.Wallet.Phantom
|
|
48
|
+
});
|
|
49
|
+
case __injectivelabs_wallet_base.Wallet.OkxWallet: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
|
|
50
|
+
...ethWalletArgs,
|
|
51
|
+
wallet: __injectivelabs_wallet_base.Wallet.OkxWallet
|
|
52
|
+
});
|
|
53
|
+
case __injectivelabs_wallet_base.Wallet.BitGet: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
|
|
54
|
+
...ethWalletArgs,
|
|
55
|
+
wallet: __injectivelabs_wallet_base.Wallet.BitGet
|
|
56
|
+
});
|
|
57
|
+
case __injectivelabs_wallet_base.Wallet.Rainbow: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
|
|
58
|
+
...ethWalletArgs,
|
|
59
|
+
wallet: __injectivelabs_wallet_base.Wallet.Rainbow
|
|
60
|
+
});
|
|
61
|
+
case __injectivelabs_wallet_base.Wallet.Rabby: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
|
|
62
|
+
...ethWalletArgs,
|
|
63
|
+
wallet: __injectivelabs_wallet_base.Wallet.Rabby
|
|
64
|
+
});
|
|
65
|
+
case __injectivelabs_wallet_base.Wallet.Keplr: return new __injectivelabs_wallet_cosmos.CosmosWalletStrategy({
|
|
66
|
+
...args,
|
|
67
|
+
wallet: __injectivelabs_wallet_base.Wallet.Keplr
|
|
68
|
+
});
|
|
69
|
+
case __injectivelabs_wallet_base.Wallet.Leap: return new __injectivelabs_wallet_cosmos.CosmosWalletStrategy({
|
|
70
|
+
...args,
|
|
71
|
+
wallet: __injectivelabs_wallet_base.Wallet.Leap
|
|
72
|
+
});
|
|
73
|
+
case __injectivelabs_wallet_base.Wallet.Ninji: return new __injectivelabs_wallet_cosmos.CosmosWalletStrategy({
|
|
74
|
+
...args,
|
|
75
|
+
wallet: __injectivelabs_wallet_base.Wallet.Ninji
|
|
76
|
+
});
|
|
77
|
+
case __injectivelabs_wallet_base.Wallet.OWallet: return new __injectivelabs_wallet_cosmos.CosmosWalletStrategy({
|
|
78
|
+
...args,
|
|
79
|
+
wallet: __injectivelabs_wallet_base.Wallet.OWallet
|
|
80
|
+
});
|
|
81
|
+
case __injectivelabs_wallet_base.Wallet.Cosmostation: return new __injectivelabs_wallet_cosmostation.CosmostationWalletStrategy({ ...args });
|
|
82
|
+
case __injectivelabs_wallet_base.Wallet.Ledger: return new __injectivelabs_wallet_ledger.LedgerLiveStrategy(ethWalletArgs);
|
|
83
|
+
case __injectivelabs_wallet_base.Wallet.LedgerLegacy: return new __injectivelabs_wallet_ledger.LedgerLegacyStrategy(ethWalletArgs);
|
|
84
|
+
case __injectivelabs_wallet_base.Wallet.TrezorBip32: return new __injectivelabs_wallet_trezor.TrezorBip32Strategy(ethWalletArgs);
|
|
85
|
+
case __injectivelabs_wallet_base.Wallet.TrezorBip44: return new __injectivelabs_wallet_trezor.TrezorBip44Strategy(ethWalletArgs);
|
|
86
|
+
case __injectivelabs_wallet_base.Wallet.PrivateKey: return new __injectivelabs_wallet_private_key.PrivateKeyWalletStrategy(ethWalletArgs);
|
|
87
|
+
case __injectivelabs_wallet_base.Wallet.Turnkey:
|
|
88
|
+
var _args$metadata;
|
|
89
|
+
if (!((_args$metadata = args.metadata) === null || _args$metadata === void 0 || (_args$metadata = _args$metadata.turnkey) === null || _args$metadata === void 0 ? void 0 : _args$metadata.defaultOrganizationId)) return;
|
|
90
|
+
return new __injectivelabs_wallet_turnkey.TurnkeyWalletStrategy(ethWalletArgs);
|
|
91
|
+
case __injectivelabs_wallet_base.Wallet.Magic:
|
|
92
|
+
var _args$metadata2, _args$metadata3;
|
|
93
|
+
if (!((_args$metadata2 = args.metadata) === null || _args$metadata2 === void 0 || (_args$metadata2 = _args$metadata2.magic) === null || _args$metadata2 === void 0 ? void 0 : _args$metadata2.apiKey) || !((_args$metadata3 = args.metadata) === null || _args$metadata3 === void 0 || (_args$metadata3 = _args$metadata3.magic) === null || _args$metadata3 === void 0 ? void 0 : _args$metadata3.rpcEndpoint)) return;
|
|
94
|
+
return new __injectivelabs_wallet_magic.MagicStrategy(args);
|
|
95
|
+
case __injectivelabs_wallet_base.Wallet.WalletConnect:
|
|
96
|
+
var _args$metadata4;
|
|
97
|
+
if (!((_args$metadata4 = args.metadata) === null || _args$metadata4 === void 0 || (_args$metadata4 = _args$metadata4.walletConnect) === null || _args$metadata4 === void 0 ? void 0 : _args$metadata4.projectId)) return;
|
|
98
|
+
return new __injectivelabs_wallet_wallet_connect.WalletConnectStrategy(ethWalletArgs);
|
|
99
|
+
default: return;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var WalletStrategy = class extends __injectivelabs_wallet_core.BaseWalletStrategy {
|
|
103
|
+
constructor(args) {
|
|
104
|
+
const strategies = {};
|
|
105
|
+
super({
|
|
106
|
+
...args,
|
|
107
|
+
strategies
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* This method is used to set the metadata for the wallet strategies.
|
|
112
|
+
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
113
|
+
* some cases we are recreating the wallet strategies from scratch using the new
|
|
114
|
+
* metadata
|
|
115
|
+
*
|
|
116
|
+
* Case 1: Private Key is set dynamically
|
|
117
|
+
* If we have a dynamically set private key,
|
|
118
|
+
* we are creating a new PrivateKey strategy
|
|
119
|
+
* with the specified private key (passed as metadata)
|
|
120
|
+
*
|
|
121
|
+
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
122
|
+
*
|
|
123
|
+
*/
|
|
124
|
+
setMetadata(metadata) {
|
|
125
|
+
const shouldRecreateStrategyOnMetadataChange = [__injectivelabs_wallet_base.Wallet.PrivateKey, __injectivelabs_wallet_base.Wallet.WalletConnect];
|
|
126
|
+
const strategiesWithPlaceholders = {
|
|
127
|
+
...this.strategies,
|
|
128
|
+
[__injectivelabs_wallet_base.Wallet.PrivateKey]: void 0,
|
|
129
|
+
[__injectivelabs_wallet_base.Wallet.WalletConnect]: void 0
|
|
130
|
+
};
|
|
131
|
+
for (const wallet of Object.keys(strategiesWithPlaceholders)) {
|
|
132
|
+
var _this$strategies$wall, _this$strategies$wall2;
|
|
133
|
+
const walletEnum = wallet;
|
|
134
|
+
if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
|
|
135
|
+
this.strategies[walletEnum] = createStrategy({
|
|
136
|
+
args: {
|
|
137
|
+
...this.args,
|
|
138
|
+
metadata: {
|
|
139
|
+
...this.args.metadata,
|
|
140
|
+
...metadata
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
wallet: walletEnum
|
|
144
|
+
});
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
(_this$strategies$wall = this.strategies[walletEnum]) === null || _this$strategies$wall === void 0 || (_this$strategies$wall2 = _this$strategies$wall.setMetadata) === null || _this$strategies$wall2 === void 0 || _this$strategies$wall2.call(_this$strategies$wall, metadata);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
getStrategy() {
|
|
151
|
+
if (this.strategies[this.wallet]) return this.strategies[this.wallet];
|
|
152
|
+
const strategy = createStrategy({
|
|
153
|
+
args: this.args,
|
|
154
|
+
wallet: this.wallet
|
|
155
|
+
});
|
|
156
|
+
if (!strategy) throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} is not enabled/available!`));
|
|
157
|
+
this.strategies[this.wallet] = strategy;
|
|
158
|
+
return strategy;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const createStrategyFactory = (args) => {
|
|
162
|
+
return new WalletStrategy(args);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
//#endregion
|
|
166
|
+
exports.WalletStrategy = WalletStrategy;
|
|
167
|
+
exports.createStrategyFactory = createStrategyFactory;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
|
|
2
|
+
import { ConcreteWalletStrategy, WalletMetadata, WalletStrategyArguments } from "@injectivelabs/wallet-base";
|
|
3
|
+
|
|
4
|
+
//#region src/strategy/index.d.ts
|
|
5
|
+
declare class WalletStrategy extends BaseWalletStrategy {
|
|
6
|
+
constructor(args: WalletStrategyArguments);
|
|
7
|
+
/**
|
|
8
|
+
* This method is used to set the metadata for the wallet strategies.
|
|
9
|
+
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
10
|
+
* some cases we are recreating the wallet strategies from scratch using the new
|
|
11
|
+
* metadata
|
|
12
|
+
*
|
|
13
|
+
* Case 1: Private Key is set dynamically
|
|
14
|
+
* If we have a dynamically set private key,
|
|
15
|
+
* we are creating a new PrivateKey strategy
|
|
16
|
+
* with the specified private key (passed as metadata)
|
|
17
|
+
*
|
|
18
|
+
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
setMetadata(metadata?: WalletMetadata): void;
|
|
22
|
+
getStrategy(): ConcreteWalletStrategy;
|
|
23
|
+
}
|
|
24
|
+
declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { WalletStrategy, createStrategyFactory };
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "commonjs"
|
|
3
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
|
|
2
|
+
import { ConcreteWalletStrategy, WalletMetadata, WalletStrategyArguments } from "@injectivelabs/wallet-base";
|
|
3
|
+
|
|
4
|
+
//#region src/strategy/index.d.ts
|
|
5
|
+
declare class WalletStrategy extends BaseWalletStrategy {
|
|
6
|
+
constructor(args: WalletStrategyArguments);
|
|
7
|
+
/**
|
|
8
|
+
* This method is used to set the metadata for the wallet strategies.
|
|
9
|
+
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
10
|
+
* some cases we are recreating the wallet strategies from scratch using the new
|
|
11
|
+
* metadata
|
|
12
|
+
*
|
|
13
|
+
* Case 1: Private Key is set dynamically
|
|
14
|
+
* If we have a dynamically set private key,
|
|
15
|
+
* we are creating a new PrivateKey strategy
|
|
16
|
+
* with the specified private key (passed as metadata)
|
|
17
|
+
*
|
|
18
|
+
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
setMetadata(metadata?: WalletMetadata): void;
|
|
22
|
+
getStrategy(): ConcreteWalletStrategy;
|
|
23
|
+
}
|
|
24
|
+
declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { WalletStrategy, createStrategyFactory };
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,166 @@
|
|
|
1
|
-
|
|
1
|
+
import { MagicStrategy } from "@injectivelabs/wallet-magic";
|
|
2
|
+
import { GeneralException } from "@injectivelabs/exceptions";
|
|
3
|
+
import { EvmWalletStrategy } from "@injectivelabs/wallet-evm";
|
|
4
|
+
import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
|
|
5
|
+
import { CosmosWalletStrategy } from "@injectivelabs/wallet-cosmos";
|
|
6
|
+
import { TurnkeyWalletStrategy } from "@injectivelabs/wallet-turnkey";
|
|
7
|
+
import { WalletConnectStrategy } from "@injectivelabs/wallet-wallet-connect";
|
|
8
|
+
import { PrivateKeyWalletStrategy } from "@injectivelabs/wallet-private-key";
|
|
9
|
+
import { CosmostationWalletStrategy } from "@injectivelabs/wallet-cosmostation";
|
|
10
|
+
import { Wallet, isEvmWallet } from "@injectivelabs/wallet-base";
|
|
11
|
+
import { LedgerLegacyStrategy, LedgerLiveStrategy } from "@injectivelabs/wallet-ledger";
|
|
12
|
+
import { TrezorBip32Strategy, TrezorBip44Strategy } from "@injectivelabs/wallet-trezor";
|
|
13
|
+
|
|
14
|
+
//#region src/strategy/index.ts
|
|
15
|
+
const ethereumWalletsDisabled = (args) => {
|
|
16
|
+
const { evmOptions } = args;
|
|
17
|
+
if (!evmOptions) return true;
|
|
18
|
+
const { evmChainId } = evmOptions;
|
|
19
|
+
if (!evmChainId) return true;
|
|
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
|
+
console.log("Skipping EVM wallet strategy creation due to disabled EVM options");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const ethWalletArgs = {
|
|
32
|
+
...args,
|
|
33
|
+
chainId: args.chainId,
|
|
34
|
+
evmOptions: args.evmOptions
|
|
35
|
+
};
|
|
36
|
+
switch (wallet) {
|
|
37
|
+
case Wallet.Metamask: return new EvmWalletStrategy({
|
|
38
|
+
...ethWalletArgs,
|
|
39
|
+
wallet: Wallet.Metamask
|
|
40
|
+
});
|
|
41
|
+
case Wallet.TrustWallet: return new EvmWalletStrategy({
|
|
42
|
+
...ethWalletArgs,
|
|
43
|
+
wallet: Wallet.TrustWallet
|
|
44
|
+
});
|
|
45
|
+
case Wallet.Phantom: return new EvmWalletStrategy({
|
|
46
|
+
...ethWalletArgs,
|
|
47
|
+
wallet: Wallet.Phantom
|
|
48
|
+
});
|
|
49
|
+
case Wallet.OkxWallet: return new EvmWalletStrategy({
|
|
50
|
+
...ethWalletArgs,
|
|
51
|
+
wallet: Wallet.OkxWallet
|
|
52
|
+
});
|
|
53
|
+
case Wallet.BitGet: return new EvmWalletStrategy({
|
|
54
|
+
...ethWalletArgs,
|
|
55
|
+
wallet: Wallet.BitGet
|
|
56
|
+
});
|
|
57
|
+
case Wallet.Rainbow: return new EvmWalletStrategy({
|
|
58
|
+
...ethWalletArgs,
|
|
59
|
+
wallet: Wallet.Rainbow
|
|
60
|
+
});
|
|
61
|
+
case Wallet.Rabby: return new EvmWalletStrategy({
|
|
62
|
+
...ethWalletArgs,
|
|
63
|
+
wallet: Wallet.Rabby
|
|
64
|
+
});
|
|
65
|
+
case Wallet.Keplr: return new CosmosWalletStrategy({
|
|
66
|
+
...args,
|
|
67
|
+
wallet: Wallet.Keplr
|
|
68
|
+
});
|
|
69
|
+
case Wallet.Leap: return new CosmosWalletStrategy({
|
|
70
|
+
...args,
|
|
71
|
+
wallet: Wallet.Leap
|
|
72
|
+
});
|
|
73
|
+
case Wallet.Ninji: return new CosmosWalletStrategy({
|
|
74
|
+
...args,
|
|
75
|
+
wallet: Wallet.Ninji
|
|
76
|
+
});
|
|
77
|
+
case Wallet.OWallet: return new CosmosWalletStrategy({
|
|
78
|
+
...args,
|
|
79
|
+
wallet: Wallet.OWallet
|
|
80
|
+
});
|
|
81
|
+
case Wallet.Cosmostation: return new CosmostationWalletStrategy({ ...args });
|
|
82
|
+
case Wallet.Ledger: return new LedgerLiveStrategy(ethWalletArgs);
|
|
83
|
+
case Wallet.LedgerLegacy: return new LedgerLegacyStrategy(ethWalletArgs);
|
|
84
|
+
case Wallet.TrezorBip32: return new TrezorBip32Strategy(ethWalletArgs);
|
|
85
|
+
case Wallet.TrezorBip44: return new TrezorBip44Strategy(ethWalletArgs);
|
|
86
|
+
case Wallet.PrivateKey: return new PrivateKeyWalletStrategy(ethWalletArgs);
|
|
87
|
+
case Wallet.Turnkey:
|
|
88
|
+
var _args$metadata;
|
|
89
|
+
if (!((_args$metadata = args.metadata) === null || _args$metadata === void 0 || (_args$metadata = _args$metadata.turnkey) === null || _args$metadata === void 0 ? void 0 : _args$metadata.defaultOrganizationId)) return;
|
|
90
|
+
return new TurnkeyWalletStrategy(ethWalletArgs);
|
|
91
|
+
case Wallet.Magic:
|
|
92
|
+
var _args$metadata2, _args$metadata3;
|
|
93
|
+
if (!((_args$metadata2 = args.metadata) === null || _args$metadata2 === void 0 || (_args$metadata2 = _args$metadata2.magic) === null || _args$metadata2 === void 0 ? void 0 : _args$metadata2.apiKey) || !((_args$metadata3 = args.metadata) === null || _args$metadata3 === void 0 || (_args$metadata3 = _args$metadata3.magic) === null || _args$metadata3 === void 0 ? void 0 : _args$metadata3.rpcEndpoint)) return;
|
|
94
|
+
return new MagicStrategy(args);
|
|
95
|
+
case Wallet.WalletConnect:
|
|
96
|
+
var _args$metadata4;
|
|
97
|
+
if (!((_args$metadata4 = args.metadata) === null || _args$metadata4 === void 0 || (_args$metadata4 = _args$metadata4.walletConnect) === null || _args$metadata4 === void 0 ? void 0 : _args$metadata4.projectId)) return;
|
|
98
|
+
return new WalletConnectStrategy(ethWalletArgs);
|
|
99
|
+
default: return;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var WalletStrategy = class extends BaseWalletStrategy {
|
|
103
|
+
constructor(args) {
|
|
104
|
+
const strategies = {};
|
|
105
|
+
super({
|
|
106
|
+
...args,
|
|
107
|
+
strategies
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* This method is used to set the metadata for the wallet strategies.
|
|
112
|
+
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
113
|
+
* some cases we are recreating the wallet strategies from scratch using the new
|
|
114
|
+
* metadata
|
|
115
|
+
*
|
|
116
|
+
* Case 1: Private Key is set dynamically
|
|
117
|
+
* If we have a dynamically set private key,
|
|
118
|
+
* we are creating a new PrivateKey strategy
|
|
119
|
+
* with the specified private key (passed as metadata)
|
|
120
|
+
*
|
|
121
|
+
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
122
|
+
*
|
|
123
|
+
*/
|
|
124
|
+
setMetadata(metadata) {
|
|
125
|
+
const shouldRecreateStrategyOnMetadataChange = [Wallet.PrivateKey, Wallet.WalletConnect];
|
|
126
|
+
const strategiesWithPlaceholders = {
|
|
127
|
+
...this.strategies,
|
|
128
|
+
[Wallet.PrivateKey]: void 0,
|
|
129
|
+
[Wallet.WalletConnect]: void 0
|
|
130
|
+
};
|
|
131
|
+
for (const wallet of Object.keys(strategiesWithPlaceholders)) {
|
|
132
|
+
var _this$strategies$wall, _this$strategies$wall2;
|
|
133
|
+
const walletEnum = wallet;
|
|
134
|
+
if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
|
|
135
|
+
this.strategies[walletEnum] = createStrategy({
|
|
136
|
+
args: {
|
|
137
|
+
...this.args,
|
|
138
|
+
metadata: {
|
|
139
|
+
...this.args.metadata,
|
|
140
|
+
...metadata
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
wallet: walletEnum
|
|
144
|
+
});
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
(_this$strategies$wall = this.strategies[walletEnum]) === null || _this$strategies$wall === void 0 || (_this$strategies$wall2 = _this$strategies$wall.setMetadata) === null || _this$strategies$wall2 === void 0 || _this$strategies$wall2.call(_this$strategies$wall, metadata);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
getStrategy() {
|
|
151
|
+
if (this.strategies[this.wallet]) return this.strategies[this.wallet];
|
|
152
|
+
const strategy = createStrategy({
|
|
153
|
+
args: this.args,
|
|
154
|
+
wallet: this.wallet
|
|
155
|
+
});
|
|
156
|
+
if (!strategy) throw new GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} is not enabled/available!`));
|
|
157
|
+
this.strategies[this.wallet] = strategy;
|
|
158
|
+
return strategy;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const createStrategyFactory = (args) => {
|
|
162
|
+
return new WalletStrategy(args);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
//#endregion
|
|
166
|
+
export { WalletStrategy, createStrategyFactory };
|
package/dist/esm/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "module"
|
|
3
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-strategy",
|
|
3
|
+
"version": "1.16.38-alpha.0",
|
|
3
4
|
"description": "Wallet strategy with instantiated wallets",
|
|
4
|
-
"
|
|
5
|
-
"sideEffects": false,
|
|
6
|
-
"type": "module",
|
|
5
|
+
"license": "Apache-2.0",
|
|
7
6
|
"author": {
|
|
8
7
|
"name": "InjectiveLabs",
|
|
9
8
|
"email": "admin@injectivelabs.org"
|
|
10
9
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"main": "dist/cjs/index.js",
|
|
14
|
-
"module": "dist/esm/index.js",
|
|
15
|
-
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
],
|
|
18
|
-
"_moduleAliases": {
|
|
19
|
-
"~wallet-strategy": "dist"
|
|
20
|
-
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
21
12
|
"exports": {
|
|
22
13
|
".": {
|
|
23
14
|
"react-native": {
|
|
@@ -40,47 +31,57 @@
|
|
|
40
31
|
}
|
|
41
32
|
}
|
|
42
33
|
},
|
|
34
|
+
"main": "dist/cjs/index.js",
|
|
35
|
+
"module": "dist/esm/index.js",
|
|
36
|
+
"types": "dist/cjs/index.d.ts",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
43
40
|
"scripts": {
|
|
44
|
-
"build": "pnpm
|
|
45
|
-
"build:
|
|
46
|
-
"build:
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"test": "
|
|
51
|
-
"test:
|
|
52
|
-
"
|
|
53
|
-
"coverage": "jest --coverage",
|
|
41
|
+
"build": "pnpm type-check && tsdown",
|
|
42
|
+
"build:fast": "tsdown",
|
|
43
|
+
"build:watch": "tsdown --watch",
|
|
44
|
+
"clean": "shx rm -rf dist coverage *.log junit.xml && shx mkdir -p dist",
|
|
45
|
+
"type-check": "tsc --noEmit",
|
|
46
|
+
"test": "vitest",
|
|
47
|
+
"test:watch": "vitest --watch",
|
|
48
|
+
"test:ci": "vitest run --coverage --reporter=verbose",
|
|
49
|
+
"coverage": "vitest run --coverage",
|
|
54
50
|
"coverage:show": "live-server coverage",
|
|
55
51
|
"dev": "ts-node -r tsconfig-paths/register src/index.ts",
|
|
56
|
-
"start": "node dist/index.js"
|
|
52
|
+
"start": "node dist/index.js",
|
|
53
|
+
"lint": "eslint . --ext .ts,.js"
|
|
57
54
|
},
|
|
58
55
|
"dependencies": {
|
|
59
|
-
"@injectivelabs/exceptions": "1.16.
|
|
60
|
-
"@injectivelabs/networks": "1.16.
|
|
61
|
-
"@injectivelabs/sdk-ts": "1.16.
|
|
62
|
-
"@injectivelabs/ts-types": "1.16.
|
|
63
|
-
"@injectivelabs/utils": "1.16.
|
|
64
|
-
"@injectivelabs/wallet-base": "1.16.
|
|
65
|
-
"@injectivelabs/wallet-core": "1.16.
|
|
66
|
-
"@injectivelabs/wallet-cosmos": "1.16.
|
|
67
|
-
"@injectivelabs/wallet-cosmostation": "1.16.
|
|
68
|
-
"@injectivelabs/wallet-evm": "1.16.
|
|
69
|
-
"@injectivelabs/wallet-ledger": "1.16.
|
|
70
|
-
"@injectivelabs/wallet-magic": "1.16.
|
|
71
|
-
"@injectivelabs/wallet-private-key": "1.16.
|
|
72
|
-
"@injectivelabs/wallet-trezor": "1.16.
|
|
73
|
-
"@injectivelabs/wallet-turnkey": "1.16.
|
|
74
|
-
"@injectivelabs/wallet-wallet-connect": "1.16.
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"ethers": "^6.5.1",
|
|
56
|
+
"@injectivelabs/exceptions": "1.16.38-alpha.0",
|
|
57
|
+
"@injectivelabs/networks": "1.16.38-alpha.0",
|
|
58
|
+
"@injectivelabs/sdk-ts": "1.16.38-alpha.0",
|
|
59
|
+
"@injectivelabs/ts-types": "1.16.38-alpha.0",
|
|
60
|
+
"@injectivelabs/utils": "1.16.38-alpha.0",
|
|
61
|
+
"@injectivelabs/wallet-base": "1.16.38-alpha.0",
|
|
62
|
+
"@injectivelabs/wallet-core": "1.16.38-alpha.0",
|
|
63
|
+
"@injectivelabs/wallet-cosmos": "1.16.38-alpha.0",
|
|
64
|
+
"@injectivelabs/wallet-cosmostation": "1.16.38-alpha.0",
|
|
65
|
+
"@injectivelabs/wallet-evm": "1.16.38-alpha.0",
|
|
66
|
+
"@injectivelabs/wallet-ledger": "1.16.38-alpha.0",
|
|
67
|
+
"@injectivelabs/wallet-magic": "1.16.38-alpha.0",
|
|
68
|
+
"@injectivelabs/wallet-private-key": "1.16.38-alpha.0",
|
|
69
|
+
"@injectivelabs/wallet-trezor": "1.16.38-alpha.0",
|
|
70
|
+
"@injectivelabs/wallet-turnkey": "1.16.38-alpha.0",
|
|
71
|
+
"@injectivelabs/wallet-wallet-connect": "1.16.38-alpha.0",
|
|
72
|
+
"eip1193-provider": "catalog:",
|
|
73
|
+
"ethers": "catalog:",
|
|
78
74
|
"hdkey": "^2.1.0",
|
|
79
|
-
"viem": "
|
|
75
|
+
"viem": "catalog:"
|
|
80
76
|
},
|
|
81
77
|
"devDependencies": {
|
|
82
|
-
"@types/hdkey": "^2.0.1"
|
|
83
|
-
|
|
78
|
+
"@types/hdkey": "^2.0.1"
|
|
79
|
+
},
|
|
80
|
+
"publishConfig": {
|
|
81
|
+
"access": "public"
|
|
82
|
+
},
|
|
83
|
+
"_moduleAliases": {
|
|
84
|
+
"~wallet-strategy": "dist"
|
|
84
85
|
},
|
|
85
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "35da21add71ed443fad349d811cf9458043baee7"
|
|
86
87
|
}
|
package/dist/cjs/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './strategy/index.js';
|
package/dist/cjs/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
|
|
2
|
-
import { type WalletMetadata } from '@injectivelabs/wallet-base';
|
|
3
|
-
import type { ConcreteWalletStrategy, WalletStrategyArguments } from '@injectivelabs/wallet-base';
|
|
4
|
-
export declare class WalletStrategy extends BaseWalletStrategy {
|
|
5
|
-
constructor(args: WalletStrategyArguments);
|
|
6
|
-
/**
|
|
7
|
-
* This method is used to set the metadata for the wallet strategies.
|
|
8
|
-
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
9
|
-
* some cases we are recreating the wallet strategies from scratch using the new
|
|
10
|
-
* metadata
|
|
11
|
-
*
|
|
12
|
-
* Case 1: Private Key is set dynamically
|
|
13
|
-
* If we have a dynamically set private key,
|
|
14
|
-
* we are creating a new PrivateKey strategy
|
|
15
|
-
* with the specified private key (passed as metadata)
|
|
16
|
-
*
|
|
17
|
-
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
setMetadata(metadata?: WalletMetadata): void;
|
|
21
|
-
getStrategy(): ConcreteWalletStrategy;
|
|
22
|
-
}
|
|
23
|
-
export declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createStrategyFactory = exports.WalletStrategy = void 0;
|
|
4
|
-
const wallet_magic_1 = require("@injectivelabs/wallet-magic");
|
|
5
|
-
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
6
|
-
const wallet_evm_1 = require("@injectivelabs/wallet-evm");
|
|
7
|
-
const wallet_core_1 = require("@injectivelabs/wallet-core");
|
|
8
|
-
const wallet_cosmos_1 = require("@injectivelabs/wallet-cosmos");
|
|
9
|
-
const wallet_turnkey_1 = require("@injectivelabs/wallet-turnkey");
|
|
10
|
-
const wallet_wallet_connect_1 = require("@injectivelabs/wallet-wallet-connect");
|
|
11
|
-
const wallet_private_key_1 = require("@injectivelabs/wallet-private-key");
|
|
12
|
-
const wallet_cosmostation_1 = require("@injectivelabs/wallet-cosmostation");
|
|
13
|
-
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
14
|
-
const wallet_ledger_1 = require("@injectivelabs/wallet-ledger");
|
|
15
|
-
const wallet_trezor_1 = require("@injectivelabs/wallet-trezor");
|
|
16
|
-
const ethereumWalletsDisabled = (args) => {
|
|
17
|
-
const { evmOptions } = args;
|
|
18
|
-
if (!evmOptions) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
const { evmChainId } = evmOptions;
|
|
22
|
-
if (!evmChainId) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
};
|
|
27
|
-
const createStrategy = ({ args, wallet, }) => {
|
|
28
|
-
/**
|
|
29
|
-
* If we only want to use Cosmos Native Wallets
|
|
30
|
-
* We are not creating strategies for Ethereum Native Wallets
|
|
31
|
-
*/
|
|
32
|
-
if ((0, wallet_base_1.isEvmWallet)(wallet) && ethereumWalletsDisabled(args)) {
|
|
33
|
-
console.log('Skipping EVM wallet strategy creation due to disabled EVM options');
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
const ethWalletArgs = {
|
|
37
|
-
...args,
|
|
38
|
-
chainId: args.chainId,
|
|
39
|
-
evmOptions: args.evmOptions,
|
|
40
|
-
};
|
|
41
|
-
switch (wallet) {
|
|
42
|
-
case wallet_base_1.Wallet.Metamask:
|
|
43
|
-
return new wallet_evm_1.EvmWalletStrategy({
|
|
44
|
-
...ethWalletArgs,
|
|
45
|
-
wallet: wallet_base_1.Wallet.Metamask,
|
|
46
|
-
});
|
|
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.Phantom:
|
|
53
|
-
return new wallet_evm_1.EvmWalletStrategy({
|
|
54
|
-
...ethWalletArgs,
|
|
55
|
-
wallet: wallet_base_1.Wallet.Phantom,
|
|
56
|
-
});
|
|
57
|
-
case wallet_base_1.Wallet.OkxWallet:
|
|
58
|
-
return new wallet_evm_1.EvmWalletStrategy({
|
|
59
|
-
...ethWalletArgs,
|
|
60
|
-
wallet: wallet_base_1.Wallet.OkxWallet,
|
|
61
|
-
});
|
|
62
|
-
case wallet_base_1.Wallet.BitGet:
|
|
63
|
-
return new wallet_evm_1.EvmWalletStrategy({
|
|
64
|
-
...ethWalletArgs,
|
|
65
|
-
wallet: wallet_base_1.Wallet.BitGet,
|
|
66
|
-
});
|
|
67
|
-
case wallet_base_1.Wallet.Rainbow:
|
|
68
|
-
return new wallet_evm_1.EvmWalletStrategy({
|
|
69
|
-
...ethWalletArgs,
|
|
70
|
-
wallet: wallet_base_1.Wallet.Rainbow,
|
|
71
|
-
});
|
|
72
|
-
case wallet_base_1.Wallet.Rabby:
|
|
73
|
-
return new wallet_evm_1.EvmWalletStrategy({
|
|
74
|
-
...ethWalletArgs,
|
|
75
|
-
wallet: wallet_base_1.Wallet.Rabby,
|
|
76
|
-
});
|
|
77
|
-
case wallet_base_1.Wallet.Keplr:
|
|
78
|
-
return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Keplr });
|
|
79
|
-
case wallet_base_1.Wallet.Leap:
|
|
80
|
-
return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Leap });
|
|
81
|
-
case wallet_base_1.Wallet.Ninji:
|
|
82
|
-
return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Ninji });
|
|
83
|
-
case wallet_base_1.Wallet.OWallet:
|
|
84
|
-
return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.OWallet });
|
|
85
|
-
case wallet_base_1.Wallet.Cosmostation:
|
|
86
|
-
return new wallet_cosmostation_1.CosmostationWalletStrategy({ ...args });
|
|
87
|
-
case wallet_base_1.Wallet.Ledger:
|
|
88
|
-
return new wallet_ledger_1.LedgerLiveStrategy(ethWalletArgs);
|
|
89
|
-
case wallet_base_1.Wallet.LedgerLegacy:
|
|
90
|
-
return new wallet_ledger_1.LedgerLegacyStrategy(ethWalletArgs);
|
|
91
|
-
case wallet_base_1.Wallet.TrezorBip32:
|
|
92
|
-
return new wallet_trezor_1.TrezorBip32Strategy(ethWalletArgs);
|
|
93
|
-
case wallet_base_1.Wallet.TrezorBip44:
|
|
94
|
-
return new wallet_trezor_1.TrezorBip44Strategy(ethWalletArgs);
|
|
95
|
-
case wallet_base_1.Wallet.PrivateKey:
|
|
96
|
-
return new wallet_private_key_1.PrivateKeyWalletStrategy(ethWalletArgs);
|
|
97
|
-
case wallet_base_1.Wallet.Turnkey:
|
|
98
|
-
if (!args.metadata?.turnkey?.defaultOrganizationId) {
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
return new wallet_turnkey_1.TurnkeyWalletStrategy(ethWalletArgs);
|
|
102
|
-
case wallet_base_1.Wallet.Magic:
|
|
103
|
-
if (!args.metadata?.magic?.apiKey || !args.metadata?.magic?.rpcEndpoint) {
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
return new wallet_magic_1.MagicStrategy(args);
|
|
107
|
-
case wallet_base_1.Wallet.WalletConnect:
|
|
108
|
-
if (!args.metadata?.walletConnect?.projectId) {
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
return new wallet_wallet_connect_1.WalletConnectStrategy(ethWalletArgs);
|
|
112
|
-
default:
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
|
|
117
|
-
constructor(args) {
|
|
118
|
-
const strategies = {};
|
|
119
|
-
super({
|
|
120
|
-
...args,
|
|
121
|
-
strategies,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* This method is used to set the metadata for the wallet strategies.
|
|
126
|
-
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
127
|
-
* some cases we are recreating the wallet strategies from scratch using the new
|
|
128
|
-
* metadata
|
|
129
|
-
*
|
|
130
|
-
* Case 1: Private Key is set dynamically
|
|
131
|
-
* If we have a dynamically set private key,
|
|
132
|
-
* we are creating a new PrivateKey strategy
|
|
133
|
-
* with the specified private key (passed as metadata)
|
|
134
|
-
*
|
|
135
|
-
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
136
|
-
*
|
|
137
|
-
*/
|
|
138
|
-
setMetadata(metadata) {
|
|
139
|
-
const shouldRecreateStrategyOnMetadataChange = [
|
|
140
|
-
wallet_base_1.Wallet.PrivateKey,
|
|
141
|
-
wallet_base_1.Wallet.WalletConnect,
|
|
142
|
-
];
|
|
143
|
-
const strategiesWithPlaceholders = {
|
|
144
|
-
...this.strategies,
|
|
145
|
-
[wallet_base_1.Wallet.PrivateKey]: undefined,
|
|
146
|
-
[wallet_base_1.Wallet.WalletConnect]: undefined,
|
|
147
|
-
};
|
|
148
|
-
for (const wallet of Object.keys(strategiesWithPlaceholders)) {
|
|
149
|
-
const walletEnum = wallet;
|
|
150
|
-
if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
|
|
151
|
-
this.strategies[walletEnum] = createStrategy({
|
|
152
|
-
args: {
|
|
153
|
-
...this.args,
|
|
154
|
-
metadata: { ...this.args.metadata, ...metadata },
|
|
155
|
-
},
|
|
156
|
-
wallet: walletEnum,
|
|
157
|
-
});
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
this.strategies[walletEnum]?.setMetadata?.(metadata);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
getStrategy() {
|
|
164
|
-
if (this.strategies[this.wallet]) {
|
|
165
|
-
return this.strategies[this.wallet];
|
|
166
|
-
}
|
|
167
|
-
const strategy = createStrategy({
|
|
168
|
-
args: this.args,
|
|
169
|
-
wallet: this.wallet,
|
|
170
|
-
});
|
|
171
|
-
if (!strategy) {
|
|
172
|
-
throw new exceptions_1.GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
|
|
173
|
-
}
|
|
174
|
-
this.strategies[this.wallet] = strategy;
|
|
175
|
-
return strategy;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
exports.WalletStrategy = WalletStrategy;
|
|
179
|
-
const createStrategyFactory = (args) => {
|
|
180
|
-
return new WalletStrategy(args);
|
|
181
|
-
};
|
|
182
|
-
exports.createStrategyFactory = createStrategyFactory;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
|
|
2
|
-
import { type WalletMetadata } from '@injectivelabs/wallet-base';
|
|
3
|
-
import type { ConcreteWalletStrategy, WalletStrategyArguments } from '@injectivelabs/wallet-base';
|
|
4
|
-
export declare class WalletStrategy extends BaseWalletStrategy {
|
|
5
|
-
constructor(args: WalletStrategyArguments);
|
|
6
|
-
/**
|
|
7
|
-
* This method is used to set the metadata for the wallet strategies.
|
|
8
|
-
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
9
|
-
* some cases we are recreating the wallet strategies from scratch using the new
|
|
10
|
-
* metadata
|
|
11
|
-
*
|
|
12
|
-
* Case 1: Private Key is set dynamically
|
|
13
|
-
* If we have a dynamically set private key,
|
|
14
|
-
* we are creating a new PrivateKey strategy
|
|
15
|
-
* with the specified private key (passed as metadata)
|
|
16
|
-
*
|
|
17
|
-
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
setMetadata(metadata?: WalletMetadata): void;
|
|
21
|
-
getStrategy(): ConcreteWalletStrategy;
|
|
22
|
-
}
|
|
23
|
-
export declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { MagicStrategy } from '@injectivelabs/wallet-magic';
|
|
2
|
-
import { GeneralException } from '@injectivelabs/exceptions';
|
|
3
|
-
import { EvmWalletStrategy } from '@injectivelabs/wallet-evm';
|
|
4
|
-
import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
|
|
5
|
-
import { CosmosWalletStrategy } from '@injectivelabs/wallet-cosmos';
|
|
6
|
-
import { TurnkeyWalletStrategy } from '@injectivelabs/wallet-turnkey';
|
|
7
|
-
import { WalletConnectStrategy } from '@injectivelabs/wallet-wallet-connect';
|
|
8
|
-
import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key';
|
|
9
|
-
import { CosmostationWalletStrategy } from '@injectivelabs/wallet-cosmostation';
|
|
10
|
-
import { Wallet, isEvmWallet, } from '@injectivelabs/wallet-base';
|
|
11
|
-
import { LedgerLiveStrategy, LedgerLegacyStrategy, } from '@injectivelabs/wallet-ledger';
|
|
12
|
-
import { TrezorBip32Strategy, TrezorBip44Strategy, } from '@injectivelabs/wallet-trezor';
|
|
13
|
-
const ethereumWalletsDisabled = (args) => {
|
|
14
|
-
const { evmOptions } = args;
|
|
15
|
-
if (!evmOptions) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
const { evmChainId } = evmOptions;
|
|
19
|
-
if (!evmChainId) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
};
|
|
24
|
-
const createStrategy = ({ args, wallet, }) => {
|
|
25
|
-
/**
|
|
26
|
-
* If we only want to use Cosmos Native Wallets
|
|
27
|
-
* We are not creating strategies for Ethereum Native Wallets
|
|
28
|
-
*/
|
|
29
|
-
if (isEvmWallet(wallet) && ethereumWalletsDisabled(args)) {
|
|
30
|
-
console.log('Skipping EVM wallet strategy creation due to disabled EVM options');
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
const ethWalletArgs = {
|
|
34
|
-
...args,
|
|
35
|
-
chainId: args.chainId,
|
|
36
|
-
evmOptions: args.evmOptions,
|
|
37
|
-
};
|
|
38
|
-
switch (wallet) {
|
|
39
|
-
case Wallet.Metamask:
|
|
40
|
-
return new EvmWalletStrategy({
|
|
41
|
-
...ethWalletArgs,
|
|
42
|
-
wallet: Wallet.Metamask,
|
|
43
|
-
});
|
|
44
|
-
case Wallet.TrustWallet:
|
|
45
|
-
return new EvmWalletStrategy({
|
|
46
|
-
...ethWalletArgs,
|
|
47
|
-
wallet: Wallet.TrustWallet,
|
|
48
|
-
});
|
|
49
|
-
case Wallet.Phantom:
|
|
50
|
-
return new EvmWalletStrategy({
|
|
51
|
-
...ethWalletArgs,
|
|
52
|
-
wallet: Wallet.Phantom,
|
|
53
|
-
});
|
|
54
|
-
case Wallet.OkxWallet:
|
|
55
|
-
return new EvmWalletStrategy({
|
|
56
|
-
...ethWalletArgs,
|
|
57
|
-
wallet: Wallet.OkxWallet,
|
|
58
|
-
});
|
|
59
|
-
case Wallet.BitGet:
|
|
60
|
-
return new EvmWalletStrategy({
|
|
61
|
-
...ethWalletArgs,
|
|
62
|
-
wallet: Wallet.BitGet,
|
|
63
|
-
});
|
|
64
|
-
case Wallet.Rainbow:
|
|
65
|
-
return new EvmWalletStrategy({
|
|
66
|
-
...ethWalletArgs,
|
|
67
|
-
wallet: Wallet.Rainbow,
|
|
68
|
-
});
|
|
69
|
-
case Wallet.Rabby:
|
|
70
|
-
return new EvmWalletStrategy({
|
|
71
|
-
...ethWalletArgs,
|
|
72
|
-
wallet: Wallet.Rabby,
|
|
73
|
-
});
|
|
74
|
-
case Wallet.Keplr:
|
|
75
|
-
return new CosmosWalletStrategy({ ...args, wallet: Wallet.Keplr });
|
|
76
|
-
case Wallet.Leap:
|
|
77
|
-
return new CosmosWalletStrategy({ ...args, wallet: Wallet.Leap });
|
|
78
|
-
case Wallet.Ninji:
|
|
79
|
-
return new CosmosWalletStrategy({ ...args, wallet: Wallet.Ninji });
|
|
80
|
-
case Wallet.OWallet:
|
|
81
|
-
return new CosmosWalletStrategy({ ...args, wallet: Wallet.OWallet });
|
|
82
|
-
case Wallet.Cosmostation:
|
|
83
|
-
return new CosmostationWalletStrategy({ ...args });
|
|
84
|
-
case Wallet.Ledger:
|
|
85
|
-
return new LedgerLiveStrategy(ethWalletArgs);
|
|
86
|
-
case Wallet.LedgerLegacy:
|
|
87
|
-
return new LedgerLegacyStrategy(ethWalletArgs);
|
|
88
|
-
case Wallet.TrezorBip32:
|
|
89
|
-
return new TrezorBip32Strategy(ethWalletArgs);
|
|
90
|
-
case Wallet.TrezorBip44:
|
|
91
|
-
return new TrezorBip44Strategy(ethWalletArgs);
|
|
92
|
-
case Wallet.PrivateKey:
|
|
93
|
-
return new PrivateKeyWalletStrategy(ethWalletArgs);
|
|
94
|
-
case Wallet.Turnkey:
|
|
95
|
-
if (!args.metadata?.turnkey?.defaultOrganizationId) {
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
return new TurnkeyWalletStrategy(ethWalletArgs);
|
|
99
|
-
case Wallet.Magic:
|
|
100
|
-
if (!args.metadata?.magic?.apiKey || !args.metadata?.magic?.rpcEndpoint) {
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
return new MagicStrategy(args);
|
|
104
|
-
case Wallet.WalletConnect:
|
|
105
|
-
if (!args.metadata?.walletConnect?.projectId) {
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
return new WalletConnectStrategy(ethWalletArgs);
|
|
109
|
-
default:
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
export class WalletStrategy extends BaseWalletStrategy {
|
|
114
|
-
constructor(args) {
|
|
115
|
-
const strategies = {};
|
|
116
|
-
super({
|
|
117
|
-
...args,
|
|
118
|
-
strategies,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* This method is used to set the metadata for the wallet strategies.
|
|
123
|
-
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
124
|
-
* some cases we are recreating the wallet strategies from scratch using the new
|
|
125
|
-
* metadata
|
|
126
|
-
*
|
|
127
|
-
* Case 1: Private Key is set dynamically
|
|
128
|
-
* If we have a dynamically set private key,
|
|
129
|
-
* we are creating a new PrivateKey strategy
|
|
130
|
-
* with the specified private key (passed as metadata)
|
|
131
|
-
*
|
|
132
|
-
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
133
|
-
*
|
|
134
|
-
*/
|
|
135
|
-
setMetadata(metadata) {
|
|
136
|
-
const shouldRecreateStrategyOnMetadataChange = [
|
|
137
|
-
Wallet.PrivateKey,
|
|
138
|
-
Wallet.WalletConnect,
|
|
139
|
-
];
|
|
140
|
-
const strategiesWithPlaceholders = {
|
|
141
|
-
...this.strategies,
|
|
142
|
-
[Wallet.PrivateKey]: undefined,
|
|
143
|
-
[Wallet.WalletConnect]: undefined,
|
|
144
|
-
};
|
|
145
|
-
for (const wallet of Object.keys(strategiesWithPlaceholders)) {
|
|
146
|
-
const walletEnum = wallet;
|
|
147
|
-
if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
|
|
148
|
-
this.strategies[walletEnum] = createStrategy({
|
|
149
|
-
args: {
|
|
150
|
-
...this.args,
|
|
151
|
-
metadata: { ...this.args.metadata, ...metadata },
|
|
152
|
-
},
|
|
153
|
-
wallet: walletEnum,
|
|
154
|
-
});
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
this.strategies[walletEnum]?.setMetadata?.(metadata);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
getStrategy() {
|
|
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
|
-
if (!strategy) {
|
|
169
|
-
throw new GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
|
|
170
|
-
}
|
|
171
|
-
this.strategies[this.wallet] = strategy;
|
|
172
|
-
return strategy;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
export const createStrategyFactory = (args) => {
|
|
176
|
-
return new WalletStrategy(args);
|
|
177
|
-
};
|