@injectivelabs/wallet-strategy 1.16.38-alpha.7 → 1.16.38
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.d.ts +1 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/package.json +2 -2
- package/dist/cjs/strategy/index.d.ts +23 -0
- package/dist/cjs/strategy/index.js +182 -0
- package/dist/esm/index.d.ts +1 -58
- package/dist/esm/index.js +1 -247
- package/dist/esm/package.json +2 -2
- package/dist/esm/strategy/index.d.ts +23 -0
- package/dist/esm/strategy/index.js +177 -0
- package/package.json +61 -50
- package/dist/cjs/index.cjs +0 -248
- package/dist/cjs/index.d.cts +0 -58
|
@@ -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);
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "commonjs"
|
|
3
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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;
|
|
@@ -0,0 +1,182 @@
|
|
|
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;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,58 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { ConcreteWalletStrategy, Wallet, WalletMetadata, WalletStrategyArguments } from "@injectivelabs/wallet-base";
|
|
3
|
-
|
|
4
|
-
//#region src/strategy/index.d.ts
|
|
5
|
-
declare class WalletStrategy extends BaseWalletStrategy {
|
|
6
|
-
private loadingStrategies;
|
|
7
|
-
constructor(args: WalletStrategyArguments);
|
|
8
|
-
/**
|
|
9
|
-
* Set the current wallet and load its strategy.
|
|
10
|
-
* This method is async because strategies are lazy-loaded.
|
|
11
|
-
*
|
|
12
|
-
* @param wallet - The wallet to set as active
|
|
13
|
-
* @throws GeneralException if the wallet strategy cannot be loaded
|
|
14
|
-
*/
|
|
15
|
-
setWallet(wallet: Wallet): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* This method is used to set the metadata for the wallet strategies.
|
|
18
|
-
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
19
|
-
* some cases we are recreating the wallet strategies from scratch using the new
|
|
20
|
-
* metadata
|
|
21
|
-
*
|
|
22
|
-
* Case 1: Private Key is set dynamically
|
|
23
|
-
* If we have a dynamically set private key,
|
|
24
|
-
* we are creating a new PrivateKey strategy
|
|
25
|
-
* with the specified private key (passed as metadata)
|
|
26
|
-
*
|
|
27
|
-
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
setMetadata(metadata?: WalletMetadata): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Get the strategy for the current wallet.
|
|
33
|
-
*
|
|
34
|
-
* NOTE: Ensure the strategy is loaded first by calling setWallet() or loadStrategy().
|
|
35
|
-
* This method throws if the strategy hasn't been loaded yet.
|
|
36
|
-
*
|
|
37
|
-
* @throws GeneralException if the strategy hasn't been loaded
|
|
38
|
-
*/
|
|
39
|
-
getStrategy(): ConcreteWalletStrategy;
|
|
40
|
-
/**
|
|
41
|
-
* Load a wallet strategy. Strategies are lazy-loaded to reduce initial bundle size.
|
|
42
|
-
* Call this method before using getStrategy() for a wallet.
|
|
43
|
-
*
|
|
44
|
-
* @param wallet - The wallet strategy to load (defaults to current wallet)
|
|
45
|
-
* @returns The loaded strategy
|
|
46
|
-
*/
|
|
47
|
-
loadStrategy(wallet?: Wallet): Promise<ConcreteWalletStrategy | undefined>;
|
|
48
|
-
/**
|
|
49
|
-
* Load multiple wallet strategies in parallel.
|
|
50
|
-
* Useful for preloading commonly used wallets during app initialization.
|
|
51
|
-
*
|
|
52
|
-
* @param wallets - Array of wallets to preload
|
|
53
|
-
*/
|
|
54
|
-
loadStrategies(wallets: Wallet[]): Promise<void>;
|
|
55
|
-
}
|
|
56
|
-
declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
|
|
57
|
-
//#endregion
|
|
58
|
-
export { WalletStrategy, createStrategyFactory };
|
|
1
|
+
export * from './strategy/index.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,247 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
|
|
3
|
-
import { Wallet, isEvmWallet } from "@injectivelabs/wallet-base";
|
|
4
|
-
|
|
5
|
-
//#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
|
|
6
|
-
function _typeof(o) {
|
|
7
|
-
"@babel/helpers - typeof";
|
|
8
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
9
|
-
return typeof o$1;
|
|
10
|
-
} : function(o$1) {
|
|
11
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
12
|
-
}, _typeof(o);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
|
|
17
|
-
function toPrimitive(t, r) {
|
|
18
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
19
|
-
var e = t[Symbol.toPrimitive];
|
|
20
|
-
if (void 0 !== e) {
|
|
21
|
-
var i = e.call(t, r || "default");
|
|
22
|
-
if ("object" != _typeof(i)) return i;
|
|
23
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
24
|
-
}
|
|
25
|
-
return ("string" === r ? String : Number)(t);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
|
|
30
|
-
function toPropertyKey(t) {
|
|
31
|
-
var i = toPrimitive(t, "string");
|
|
32
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
|
|
37
|
-
function _defineProperty(e, r, t) {
|
|
38
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
39
|
-
value: t,
|
|
40
|
-
enumerable: !0,
|
|
41
|
-
configurable: !0,
|
|
42
|
-
writable: !0
|
|
43
|
-
}) : e[r] = t, e;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/strategy/index.ts
|
|
48
|
-
const loadEvmStrategy = () => import("@injectivelabs/wallet-evm").then((m) => m.EvmWalletStrategy);
|
|
49
|
-
const loadCosmosStrategy = () => import("@injectivelabs/wallet-cosmos").then((m) => m.CosmosWalletStrategy);
|
|
50
|
-
const loadCosmostationStrategy = () => import("@injectivelabs/wallet-cosmostation").then((m) => m.CosmostationWalletStrategy);
|
|
51
|
-
const loadLedgerStrategies = () => import("@injectivelabs/wallet-ledger").then((m) => ({
|
|
52
|
-
LedgerLiveStrategy: m.LedgerLiveStrategy,
|
|
53
|
-
LedgerLegacyStrategy: m.LedgerLegacyStrategy
|
|
54
|
-
}));
|
|
55
|
-
const loadTrezorStrategies = () => import("@injectivelabs/wallet-trezor").then((m) => ({
|
|
56
|
-
TrezorBip32Strategy: m.TrezorBip32Strategy,
|
|
57
|
-
TrezorBip44Strategy: m.TrezorBip44Strategy
|
|
58
|
-
}));
|
|
59
|
-
const loadPrivateKeyStrategy = () => import("@injectivelabs/wallet-private-key").then((m) => m.PrivateKeyWalletStrategy);
|
|
60
|
-
const loadTurnkeyStrategy = () => import("@injectivelabs/wallet-turnkey").then((m) => m.TurnkeyWalletStrategy);
|
|
61
|
-
const loadMagicStrategy = () => import("@injectivelabs/wallet-magic").then((m) => m.MagicStrategy);
|
|
62
|
-
const loadWalletConnectStrategy = () => import("@injectivelabs/wallet-wallet-connect").then((m) => m.WalletConnectStrategy);
|
|
63
|
-
const ethereumWalletsDisabled = (args) => {
|
|
64
|
-
const { evmOptions } = args;
|
|
65
|
-
if (!evmOptions) return true;
|
|
66
|
-
const { evmChainId } = evmOptions;
|
|
67
|
-
if (!evmChainId) return true;
|
|
68
|
-
return false;
|
|
69
|
-
};
|
|
70
|
-
const createStrategy = async ({ args, wallet }) => {
|
|
71
|
-
/**
|
|
72
|
-
* If we only want to use Cosmos Native Wallets
|
|
73
|
-
* We are not creating strategies for Ethereum Native Wallets
|
|
74
|
-
*/
|
|
75
|
-
if (isEvmWallet(wallet) && ethereumWalletsDisabled(args)) {
|
|
76
|
-
console.log("Skipping EVM wallet strategy creation due to disabled EVM options");
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const ethWalletArgs = {
|
|
80
|
-
...args,
|
|
81
|
-
chainId: args.chainId,
|
|
82
|
-
evmOptions: args.evmOptions
|
|
83
|
-
};
|
|
84
|
-
switch (wallet) {
|
|
85
|
-
case Wallet.Metamask:
|
|
86
|
-
case Wallet.TrustWallet:
|
|
87
|
-
case Wallet.Phantom:
|
|
88
|
-
case Wallet.OkxWallet:
|
|
89
|
-
case Wallet.BitGet:
|
|
90
|
-
case Wallet.Rainbow:
|
|
91
|
-
case Wallet.Rabby: return new (await (loadEvmStrategy()))({
|
|
92
|
-
...ethWalletArgs,
|
|
93
|
-
wallet
|
|
94
|
-
});
|
|
95
|
-
case Wallet.Keplr:
|
|
96
|
-
case Wallet.Leap:
|
|
97
|
-
case Wallet.Ninji:
|
|
98
|
-
case Wallet.OWallet: return new (await (loadCosmosStrategy()))({
|
|
99
|
-
...args,
|
|
100
|
-
wallet
|
|
101
|
-
});
|
|
102
|
-
case Wallet.Cosmostation: return new (await (loadCosmostationStrategy()))({ ...args });
|
|
103
|
-
case Wallet.Ledger: {
|
|
104
|
-
const { LedgerLiveStrategy } = await loadLedgerStrategies();
|
|
105
|
-
return new LedgerLiveStrategy(ethWalletArgs);
|
|
106
|
-
}
|
|
107
|
-
case Wallet.LedgerLegacy: {
|
|
108
|
-
const { LedgerLegacyStrategy } = await loadLedgerStrategies();
|
|
109
|
-
return new LedgerLegacyStrategy(ethWalletArgs);
|
|
110
|
-
}
|
|
111
|
-
case Wallet.TrezorBip32: {
|
|
112
|
-
const { TrezorBip32Strategy } = await loadTrezorStrategies();
|
|
113
|
-
return new TrezorBip32Strategy(ethWalletArgs);
|
|
114
|
-
}
|
|
115
|
-
case Wallet.TrezorBip44: {
|
|
116
|
-
const { TrezorBip44Strategy } = await loadTrezorStrategies();
|
|
117
|
-
return new TrezorBip44Strategy(ethWalletArgs);
|
|
118
|
-
}
|
|
119
|
-
case Wallet.PrivateKey: return new (await (loadPrivateKeyStrategy()))(ethWalletArgs);
|
|
120
|
-
case Wallet.Turnkey:
|
|
121
|
-
var _args$metadata;
|
|
122
|
-
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;
|
|
123
|
-
return new (await (loadTurnkeyStrategy()))(ethWalletArgs);
|
|
124
|
-
case Wallet.Magic:
|
|
125
|
-
var _args$metadata2, _args$metadata3;
|
|
126
|
-
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;
|
|
127
|
-
return new (await (loadMagicStrategy()))(args);
|
|
128
|
-
case Wallet.WalletConnect:
|
|
129
|
-
var _args$metadata4;
|
|
130
|
-
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;
|
|
131
|
-
return new (await (loadWalletConnectStrategy()))(ethWalletArgs);
|
|
132
|
-
default: return;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
var WalletStrategy = class extends BaseWalletStrategy {
|
|
136
|
-
constructor(args) {
|
|
137
|
-
const strategies = {};
|
|
138
|
-
super({
|
|
139
|
-
...args,
|
|
140
|
-
strategies
|
|
141
|
-
});
|
|
142
|
-
_defineProperty(this, "loadingStrategies", /* @__PURE__ */ new Map());
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Set the current wallet and load its strategy.
|
|
146
|
-
* This method is async because strategies are lazy-loaded.
|
|
147
|
-
*
|
|
148
|
-
* @param wallet - The wallet to set as active
|
|
149
|
-
* @throws GeneralException if the wallet strategy cannot be loaded
|
|
150
|
-
*/
|
|
151
|
-
async setWallet(wallet) {
|
|
152
|
-
this.wallet = wallet;
|
|
153
|
-
await this.loadStrategy(wallet);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* This method is used to set the metadata for the wallet strategies.
|
|
157
|
-
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
158
|
-
* some cases we are recreating the wallet strategies from scratch using the new
|
|
159
|
-
* metadata
|
|
160
|
-
*
|
|
161
|
-
* Case 1: Private Key is set dynamically
|
|
162
|
-
* If we have a dynamically set private key,
|
|
163
|
-
* we are creating a new PrivateKey strategy
|
|
164
|
-
* with the specified private key (passed as metadata)
|
|
165
|
-
*
|
|
166
|
-
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
167
|
-
*
|
|
168
|
-
*/
|
|
169
|
-
async setMetadata(metadata) {
|
|
170
|
-
const shouldRecreateStrategyOnMetadataChange = [Wallet.PrivateKey, Wallet.WalletConnect];
|
|
171
|
-
const strategiesWithPlaceholders = {
|
|
172
|
-
...this.strategies,
|
|
173
|
-
[Wallet.PrivateKey]: void 0,
|
|
174
|
-
[Wallet.WalletConnect]: void 0
|
|
175
|
-
};
|
|
176
|
-
for (const wallet of Object.keys(strategiesWithPlaceholders)) {
|
|
177
|
-
var _this$strategies$wall, _this$strategies$wall2;
|
|
178
|
-
const walletEnum = wallet;
|
|
179
|
-
if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
|
|
180
|
-
this.loadingStrategies.delete(walletEnum);
|
|
181
|
-
this.strategies[walletEnum] = await createStrategy({
|
|
182
|
-
args: {
|
|
183
|
-
...this.args,
|
|
184
|
-
metadata: {
|
|
185
|
-
...this.args.metadata,
|
|
186
|
-
...metadata
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
wallet: walletEnum
|
|
190
|
-
});
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
(_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);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Get the strategy for the current wallet.
|
|
198
|
-
*
|
|
199
|
-
* NOTE: Ensure the strategy is loaded first by calling setWallet() or loadStrategy().
|
|
200
|
-
* This method throws if the strategy hasn't been loaded yet.
|
|
201
|
-
*
|
|
202
|
-
* @throws GeneralException if the strategy hasn't been loaded
|
|
203
|
-
*/
|
|
204
|
-
getStrategy() {
|
|
205
|
-
if (this.strategies[this.wallet]) return this.strategies[this.wallet];
|
|
206
|
-
throw new GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} strategy not loaded. Call setWallet() or loadStrategy() first.`));
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Load a wallet strategy. Strategies are lazy-loaded to reduce initial bundle size.
|
|
210
|
-
* Call this method before using getStrategy() for a wallet.
|
|
211
|
-
*
|
|
212
|
-
* @param wallet - The wallet strategy to load (defaults to current wallet)
|
|
213
|
-
* @returns The loaded strategy
|
|
214
|
-
*/
|
|
215
|
-
async loadStrategy(wallet = this.wallet) {
|
|
216
|
-
if (this.strategies[wallet]) return this.strategies[wallet];
|
|
217
|
-
const existingLoad = this.loadingStrategies.get(wallet);
|
|
218
|
-
if (existingLoad) return existingLoad;
|
|
219
|
-
const loadPromise = createStrategy({
|
|
220
|
-
args: this.args,
|
|
221
|
-
wallet
|
|
222
|
-
});
|
|
223
|
-
this.loadingStrategies.set(wallet, loadPromise);
|
|
224
|
-
try {
|
|
225
|
-
const strategy = await loadPromise;
|
|
226
|
-
if (strategy) this.strategies[wallet] = strategy;
|
|
227
|
-
return strategy;
|
|
228
|
-
} finally {
|
|
229
|
-
this.loadingStrategies.delete(wallet);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Load multiple wallet strategies in parallel.
|
|
234
|
-
* Useful for preloading commonly used wallets during app initialization.
|
|
235
|
-
*
|
|
236
|
-
* @param wallets - Array of wallets to preload
|
|
237
|
-
*/
|
|
238
|
-
async loadStrategies(wallets) {
|
|
239
|
-
await Promise.all(wallets.map((wallet) => this.loadStrategy(wallet)));
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
const createStrategyFactory = (args) => {
|
|
243
|
-
return new WalletStrategy(args);
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
//#endregion
|
|
247
|
-
export { WalletStrategy, createStrategyFactory };
|
|
1
|
+
export * from './strategy/index.js';
|
package/dist/esm/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "module"
|
|
3
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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;
|
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,75 +1,86 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-strategy",
|
|
3
|
-
"version": "1.16.38-alpha.7",
|
|
4
3
|
"description": "Wallet strategy with instantiated wallets",
|
|
5
|
-
"
|
|
4
|
+
"version": "1.16.38",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"type": "module",
|
|
6
7
|
"author": {
|
|
7
8
|
"name": "InjectiveLabs",
|
|
8
9
|
"email": "admin@injectivelabs.org"
|
|
9
10
|
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"types": "dist/cjs/index.d.ts",
|
|
13
|
+
"main": "dist/cjs/index.js",
|
|
14
|
+
"module": "dist/esm/index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"_moduleAliases": {
|
|
19
|
+
"~wallet-strategy": "dist"
|
|
20
|
+
},
|
|
12
21
|
"exports": {
|
|
13
22
|
".": {
|
|
14
23
|
"react-native": {
|
|
15
24
|
"import": "./dist/esm/index.js",
|
|
16
|
-
"require": "./dist/cjs/index.
|
|
17
|
-
"types": "./dist/cjs/index.d.
|
|
18
|
-
"default": "./dist/cjs/index.
|
|
25
|
+
"require": "./dist/cjs/index.js",
|
|
26
|
+
"types": "./dist/cjs/index.d.ts",
|
|
27
|
+
"default": "./dist/cjs/index.js"
|
|
19
28
|
},
|
|
20
29
|
"require": {
|
|
21
|
-
"types": "./dist/cjs/index.d.
|
|
22
|
-
"default": "./dist/cjs/index.
|
|
30
|
+
"types": "./dist/cjs/index.d.ts",
|
|
31
|
+
"default": "./dist/cjs/index.js"
|
|
23
32
|
},
|
|
24
33
|
"import": {
|
|
25
34
|
"types": "./dist/esm/index.d.ts",
|
|
26
35
|
"default": "./dist/esm/index.js"
|
|
27
36
|
},
|
|
28
37
|
"default": {
|
|
29
|
-
"types": "./dist/cjs/index.d.
|
|
30
|
-
"default": "./dist/cjs/index.
|
|
38
|
+
"types": "./dist/cjs/index.d.ts",
|
|
39
|
+
"default": "./dist/cjs/index.js"
|
|
31
40
|
}
|
|
32
41
|
}
|
|
33
42
|
},
|
|
34
|
-
"main": "dist/cjs/index.cjs",
|
|
35
|
-
"module": "dist/esm/index.js",
|
|
36
|
-
"types": "dist/cjs/index.d.cts",
|
|
37
|
-
"files": [
|
|
38
|
-
"dist"
|
|
39
|
-
],
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"@injectivelabs/exceptions": "1.16.38-alpha.4",
|
|
42
|
-
"@injectivelabs/wallet-base": "1.16.38-alpha.7",
|
|
43
|
-
"@injectivelabs/wallet-cosmos": "1.16.38-alpha.7",
|
|
44
|
-
"@injectivelabs/wallet-core": "1.16.38-alpha.7",
|
|
45
|
-
"@injectivelabs/wallet-cosmostation": "1.16.38-alpha.7",
|
|
46
|
-
"@injectivelabs/wallet-evm": "1.16.38-alpha.7",
|
|
47
|
-
"@injectivelabs/wallet-magic": "1.16.38-alpha.7",
|
|
48
|
-
"@injectivelabs/wallet-ledger": "1.16.38-alpha.7",
|
|
49
|
-
"@injectivelabs/wallet-private-key": "1.16.38-alpha.7",
|
|
50
|
-
"@injectivelabs/wallet-trezor": "1.16.38-alpha.7",
|
|
51
|
-
"@injectivelabs/wallet-turnkey": "1.16.38-alpha.7",
|
|
52
|
-
"@injectivelabs/wallet-wallet-connect": "1.16.38-alpha.7"
|
|
53
|
-
},
|
|
54
|
-
"publishConfig": {
|
|
55
|
-
"access": "public"
|
|
56
|
-
},
|
|
57
|
-
"_moduleAliases": {
|
|
58
|
-
"~wallet-strategy": "dist"
|
|
59
|
-
},
|
|
60
43
|
"scripts": {
|
|
61
|
-
"build": "pnpm
|
|
62
|
-
"build:
|
|
63
|
-
"build:
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"test
|
|
68
|
-
"test:
|
|
69
|
-
"
|
|
44
|
+
"build": "pnpm build:cjs && pnpm build:esm && pnpm build:post",
|
|
45
|
+
"build:cjs": "tsc --build --force tsconfig.build.json",
|
|
46
|
+
"build:esm": "tsc --build --force tsconfig.build.esm.json",
|
|
47
|
+
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && pnpm build:post",
|
|
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
|
+
"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
|
+
"test": "jest",
|
|
51
|
+
"test:watch": "jest --watch",
|
|
52
|
+
"test:ci": "jest --coverage --ci --reporters='jest-junit'",
|
|
53
|
+
"coverage": "jest --coverage",
|
|
70
54
|
"coverage:show": "live-server coverage",
|
|
71
55
|
"dev": "ts-node -r tsconfig-paths/register src/index.ts",
|
|
72
|
-
"start": "node dist/index.js"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
56
|
+
"start": "node dist/index.js"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@injectivelabs/exceptions": "1.16.38",
|
|
60
|
+
"@injectivelabs/networks": "1.16.38",
|
|
61
|
+
"@injectivelabs/sdk-ts": "1.16.38",
|
|
62
|
+
"@injectivelabs/ts-types": "1.16.38",
|
|
63
|
+
"@injectivelabs/utils": "1.16.38",
|
|
64
|
+
"@injectivelabs/wallet-base": "1.16.38",
|
|
65
|
+
"@injectivelabs/wallet-core": "1.16.38",
|
|
66
|
+
"@injectivelabs/wallet-cosmos": "1.16.38",
|
|
67
|
+
"@injectivelabs/wallet-cosmostation": "1.16.38",
|
|
68
|
+
"@injectivelabs/wallet-evm": "1.16.38",
|
|
69
|
+
"@injectivelabs/wallet-ledger": "1.16.38",
|
|
70
|
+
"@injectivelabs/wallet-magic": "1.16.38",
|
|
71
|
+
"@injectivelabs/wallet-private-key": "1.16.38",
|
|
72
|
+
"@injectivelabs/wallet-trezor": "1.16.38",
|
|
73
|
+
"@injectivelabs/wallet-turnkey": "1.16.38",
|
|
74
|
+
"@injectivelabs/wallet-wallet-connect": "1.16.38",
|
|
75
|
+
"alchemy-sdk": "^3.4.7",
|
|
76
|
+
"eip1193-provider": "^1.0.1",
|
|
77
|
+
"ethers": "^6.5.1",
|
|
78
|
+
"hdkey": "^2.1.0",
|
|
79
|
+
"viem": "^2.40.3"
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"@types/hdkey": "^2.0.1",
|
|
83
|
+
"shx": "^0.3.3"
|
|
84
|
+
},
|
|
85
|
+
"gitHead": "c67633f9ba4c5efb2c969c3df815d54995459966"
|
|
86
|
+
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
|
|
2
|
-
let __injectivelabs_wallet_core = require("@injectivelabs/wallet-core");
|
|
3
|
-
let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
|
|
4
|
-
|
|
5
|
-
//#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
|
|
6
|
-
function _typeof(o) {
|
|
7
|
-
"@babel/helpers - typeof";
|
|
8
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
9
|
-
return typeof o$1;
|
|
10
|
-
} : function(o$1) {
|
|
11
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
12
|
-
}, _typeof(o);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
|
|
17
|
-
function toPrimitive(t, r) {
|
|
18
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
19
|
-
var e = t[Symbol.toPrimitive];
|
|
20
|
-
if (void 0 !== e) {
|
|
21
|
-
var i = e.call(t, r || "default");
|
|
22
|
-
if ("object" != _typeof(i)) return i;
|
|
23
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
24
|
-
}
|
|
25
|
-
return ("string" === r ? String : Number)(t);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
|
|
30
|
-
function toPropertyKey(t) {
|
|
31
|
-
var i = toPrimitive(t, "string");
|
|
32
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
|
|
37
|
-
function _defineProperty(e, r, t) {
|
|
38
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
39
|
-
value: t,
|
|
40
|
-
enumerable: !0,
|
|
41
|
-
configurable: !0,
|
|
42
|
-
writable: !0
|
|
43
|
-
}) : e[r] = t, e;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/strategy/index.ts
|
|
48
|
-
const loadEvmStrategy = () => import("@injectivelabs/wallet-evm").then((m) => m.EvmWalletStrategy);
|
|
49
|
-
const loadCosmosStrategy = () => import("@injectivelabs/wallet-cosmos").then((m) => m.CosmosWalletStrategy);
|
|
50
|
-
const loadCosmostationStrategy = () => import("@injectivelabs/wallet-cosmostation").then((m) => m.CosmostationWalletStrategy);
|
|
51
|
-
const loadLedgerStrategies = () => import("@injectivelabs/wallet-ledger").then((m) => ({
|
|
52
|
-
LedgerLiveStrategy: m.LedgerLiveStrategy,
|
|
53
|
-
LedgerLegacyStrategy: m.LedgerLegacyStrategy
|
|
54
|
-
}));
|
|
55
|
-
const loadTrezorStrategies = () => import("@injectivelabs/wallet-trezor").then((m) => ({
|
|
56
|
-
TrezorBip32Strategy: m.TrezorBip32Strategy,
|
|
57
|
-
TrezorBip44Strategy: m.TrezorBip44Strategy
|
|
58
|
-
}));
|
|
59
|
-
const loadPrivateKeyStrategy = () => import("@injectivelabs/wallet-private-key").then((m) => m.PrivateKeyWalletStrategy);
|
|
60
|
-
const loadTurnkeyStrategy = () => import("@injectivelabs/wallet-turnkey").then((m) => m.TurnkeyWalletStrategy);
|
|
61
|
-
const loadMagicStrategy = () => import("@injectivelabs/wallet-magic").then((m) => m.MagicStrategy);
|
|
62
|
-
const loadWalletConnectStrategy = () => import("@injectivelabs/wallet-wallet-connect").then((m) => m.WalletConnectStrategy);
|
|
63
|
-
const ethereumWalletsDisabled = (args) => {
|
|
64
|
-
const { evmOptions } = args;
|
|
65
|
-
if (!evmOptions) return true;
|
|
66
|
-
const { evmChainId } = evmOptions;
|
|
67
|
-
if (!evmChainId) return true;
|
|
68
|
-
return false;
|
|
69
|
-
};
|
|
70
|
-
const createStrategy = async ({ args, wallet }) => {
|
|
71
|
-
/**
|
|
72
|
-
* If we only want to use Cosmos Native Wallets
|
|
73
|
-
* We are not creating strategies for Ethereum Native Wallets
|
|
74
|
-
*/
|
|
75
|
-
if ((0, __injectivelabs_wallet_base.isEvmWallet)(wallet) && ethereumWalletsDisabled(args)) {
|
|
76
|
-
console.log("Skipping EVM wallet strategy creation due to disabled EVM options");
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const ethWalletArgs = {
|
|
80
|
-
...args,
|
|
81
|
-
chainId: args.chainId,
|
|
82
|
-
evmOptions: args.evmOptions
|
|
83
|
-
};
|
|
84
|
-
switch (wallet) {
|
|
85
|
-
case __injectivelabs_wallet_base.Wallet.Metamask:
|
|
86
|
-
case __injectivelabs_wallet_base.Wallet.TrustWallet:
|
|
87
|
-
case __injectivelabs_wallet_base.Wallet.Phantom:
|
|
88
|
-
case __injectivelabs_wallet_base.Wallet.OkxWallet:
|
|
89
|
-
case __injectivelabs_wallet_base.Wallet.BitGet:
|
|
90
|
-
case __injectivelabs_wallet_base.Wallet.Rainbow:
|
|
91
|
-
case __injectivelabs_wallet_base.Wallet.Rabby: return new (await (loadEvmStrategy()))({
|
|
92
|
-
...ethWalletArgs,
|
|
93
|
-
wallet
|
|
94
|
-
});
|
|
95
|
-
case __injectivelabs_wallet_base.Wallet.Keplr:
|
|
96
|
-
case __injectivelabs_wallet_base.Wallet.Leap:
|
|
97
|
-
case __injectivelabs_wallet_base.Wallet.Ninji:
|
|
98
|
-
case __injectivelabs_wallet_base.Wallet.OWallet: return new (await (loadCosmosStrategy()))({
|
|
99
|
-
...args,
|
|
100
|
-
wallet
|
|
101
|
-
});
|
|
102
|
-
case __injectivelabs_wallet_base.Wallet.Cosmostation: return new (await (loadCosmostationStrategy()))({ ...args });
|
|
103
|
-
case __injectivelabs_wallet_base.Wallet.Ledger: {
|
|
104
|
-
const { LedgerLiveStrategy } = await loadLedgerStrategies();
|
|
105
|
-
return new LedgerLiveStrategy(ethWalletArgs);
|
|
106
|
-
}
|
|
107
|
-
case __injectivelabs_wallet_base.Wallet.LedgerLegacy: {
|
|
108
|
-
const { LedgerLegacyStrategy } = await loadLedgerStrategies();
|
|
109
|
-
return new LedgerLegacyStrategy(ethWalletArgs);
|
|
110
|
-
}
|
|
111
|
-
case __injectivelabs_wallet_base.Wallet.TrezorBip32: {
|
|
112
|
-
const { TrezorBip32Strategy } = await loadTrezorStrategies();
|
|
113
|
-
return new TrezorBip32Strategy(ethWalletArgs);
|
|
114
|
-
}
|
|
115
|
-
case __injectivelabs_wallet_base.Wallet.TrezorBip44: {
|
|
116
|
-
const { TrezorBip44Strategy } = await loadTrezorStrategies();
|
|
117
|
-
return new TrezorBip44Strategy(ethWalletArgs);
|
|
118
|
-
}
|
|
119
|
-
case __injectivelabs_wallet_base.Wallet.PrivateKey: return new (await (loadPrivateKeyStrategy()))(ethWalletArgs);
|
|
120
|
-
case __injectivelabs_wallet_base.Wallet.Turnkey:
|
|
121
|
-
var _args$metadata;
|
|
122
|
-
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;
|
|
123
|
-
return new (await (loadTurnkeyStrategy()))(ethWalletArgs);
|
|
124
|
-
case __injectivelabs_wallet_base.Wallet.Magic:
|
|
125
|
-
var _args$metadata2, _args$metadata3;
|
|
126
|
-
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;
|
|
127
|
-
return new (await (loadMagicStrategy()))(args);
|
|
128
|
-
case __injectivelabs_wallet_base.Wallet.WalletConnect:
|
|
129
|
-
var _args$metadata4;
|
|
130
|
-
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;
|
|
131
|
-
return new (await (loadWalletConnectStrategy()))(ethWalletArgs);
|
|
132
|
-
default: return;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
var WalletStrategy = class extends __injectivelabs_wallet_core.BaseWalletStrategy {
|
|
136
|
-
constructor(args) {
|
|
137
|
-
const strategies = {};
|
|
138
|
-
super({
|
|
139
|
-
...args,
|
|
140
|
-
strategies
|
|
141
|
-
});
|
|
142
|
-
_defineProperty(this, "loadingStrategies", /* @__PURE__ */ new Map());
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Set the current wallet and load its strategy.
|
|
146
|
-
* This method is async because strategies are lazy-loaded.
|
|
147
|
-
*
|
|
148
|
-
* @param wallet - The wallet to set as active
|
|
149
|
-
* @throws GeneralException if the wallet strategy cannot be loaded
|
|
150
|
-
*/
|
|
151
|
-
async setWallet(wallet) {
|
|
152
|
-
this.wallet = wallet;
|
|
153
|
-
await this.loadStrategy(wallet);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* This method is used to set the metadata for the wallet strategies.
|
|
157
|
-
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
158
|
-
* some cases we are recreating the wallet strategies from scratch using the new
|
|
159
|
-
* metadata
|
|
160
|
-
*
|
|
161
|
-
* Case 1: Private Key is set dynamically
|
|
162
|
-
* If we have a dynamically set private key,
|
|
163
|
-
* we are creating a new PrivateKey strategy
|
|
164
|
-
* with the specified private key (passed as metadata)
|
|
165
|
-
*
|
|
166
|
-
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
167
|
-
*
|
|
168
|
-
*/
|
|
169
|
-
async setMetadata(metadata) {
|
|
170
|
-
const shouldRecreateStrategyOnMetadataChange = [__injectivelabs_wallet_base.Wallet.PrivateKey, __injectivelabs_wallet_base.Wallet.WalletConnect];
|
|
171
|
-
const strategiesWithPlaceholders = {
|
|
172
|
-
...this.strategies,
|
|
173
|
-
[__injectivelabs_wallet_base.Wallet.PrivateKey]: void 0,
|
|
174
|
-
[__injectivelabs_wallet_base.Wallet.WalletConnect]: void 0
|
|
175
|
-
};
|
|
176
|
-
for (const wallet of Object.keys(strategiesWithPlaceholders)) {
|
|
177
|
-
var _this$strategies$wall, _this$strategies$wall2;
|
|
178
|
-
const walletEnum = wallet;
|
|
179
|
-
if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
|
|
180
|
-
this.loadingStrategies.delete(walletEnum);
|
|
181
|
-
this.strategies[walletEnum] = await createStrategy({
|
|
182
|
-
args: {
|
|
183
|
-
...this.args,
|
|
184
|
-
metadata: {
|
|
185
|
-
...this.args.metadata,
|
|
186
|
-
...metadata
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
wallet: walletEnum
|
|
190
|
-
});
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
(_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);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Get the strategy for the current wallet.
|
|
198
|
-
*
|
|
199
|
-
* NOTE: Ensure the strategy is loaded first by calling setWallet() or loadStrategy().
|
|
200
|
-
* This method throws if the strategy hasn't been loaded yet.
|
|
201
|
-
*
|
|
202
|
-
* @throws GeneralException if the strategy hasn't been loaded
|
|
203
|
-
*/
|
|
204
|
-
getStrategy() {
|
|
205
|
-
if (this.strategies[this.wallet]) return this.strategies[this.wallet];
|
|
206
|
-
throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} strategy not loaded. Call setWallet() or loadStrategy() first.`));
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Load a wallet strategy. Strategies are lazy-loaded to reduce initial bundle size.
|
|
210
|
-
* Call this method before using getStrategy() for a wallet.
|
|
211
|
-
*
|
|
212
|
-
* @param wallet - The wallet strategy to load (defaults to current wallet)
|
|
213
|
-
* @returns The loaded strategy
|
|
214
|
-
*/
|
|
215
|
-
async loadStrategy(wallet = this.wallet) {
|
|
216
|
-
if (this.strategies[wallet]) return this.strategies[wallet];
|
|
217
|
-
const existingLoad = this.loadingStrategies.get(wallet);
|
|
218
|
-
if (existingLoad) return existingLoad;
|
|
219
|
-
const loadPromise = createStrategy({
|
|
220
|
-
args: this.args,
|
|
221
|
-
wallet
|
|
222
|
-
});
|
|
223
|
-
this.loadingStrategies.set(wallet, loadPromise);
|
|
224
|
-
try {
|
|
225
|
-
const strategy = await loadPromise;
|
|
226
|
-
if (strategy) this.strategies[wallet] = strategy;
|
|
227
|
-
return strategy;
|
|
228
|
-
} finally {
|
|
229
|
-
this.loadingStrategies.delete(wallet);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Load multiple wallet strategies in parallel.
|
|
234
|
-
* Useful for preloading commonly used wallets during app initialization.
|
|
235
|
-
*
|
|
236
|
-
* @param wallets - Array of wallets to preload
|
|
237
|
-
*/
|
|
238
|
-
async loadStrategies(wallets) {
|
|
239
|
-
await Promise.all(wallets.map((wallet) => this.loadStrategy(wallet)));
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
const createStrategyFactory = (args) => {
|
|
243
|
-
return new WalletStrategy(args);
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
//#endregion
|
|
247
|
-
exports.WalletStrategy = WalletStrategy;
|
|
248
|
-
exports.createStrategyFactory = createStrategyFactory;
|
package/dist/cjs/index.d.cts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
|
|
2
|
-
import { ConcreteWalletStrategy, Wallet, WalletMetadata, WalletStrategyArguments } from "@injectivelabs/wallet-base";
|
|
3
|
-
|
|
4
|
-
//#region src/strategy/index.d.ts
|
|
5
|
-
declare class WalletStrategy extends BaseWalletStrategy {
|
|
6
|
-
private loadingStrategies;
|
|
7
|
-
constructor(args: WalletStrategyArguments);
|
|
8
|
-
/**
|
|
9
|
-
* Set the current wallet and load its strategy.
|
|
10
|
-
* This method is async because strategies are lazy-loaded.
|
|
11
|
-
*
|
|
12
|
-
* @param wallet - The wallet to set as active
|
|
13
|
-
* @throws GeneralException if the wallet strategy cannot be loaded
|
|
14
|
-
*/
|
|
15
|
-
setWallet(wallet: Wallet): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* This method is used to set the metadata for the wallet strategies.
|
|
18
|
-
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
19
|
-
* some cases we are recreating the wallet strategies from scratch using the new
|
|
20
|
-
* metadata
|
|
21
|
-
*
|
|
22
|
-
* Case 1: Private Key is set dynamically
|
|
23
|
-
* If we have a dynamically set private key,
|
|
24
|
-
* we are creating a new PrivateKey strategy
|
|
25
|
-
* with the specified private key (passed as metadata)
|
|
26
|
-
*
|
|
27
|
-
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
setMetadata(metadata?: WalletMetadata): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Get the strategy for the current wallet.
|
|
33
|
-
*
|
|
34
|
-
* NOTE: Ensure the strategy is loaded first by calling setWallet() or loadStrategy().
|
|
35
|
-
* This method throws if the strategy hasn't been loaded yet.
|
|
36
|
-
*
|
|
37
|
-
* @throws GeneralException if the strategy hasn't been loaded
|
|
38
|
-
*/
|
|
39
|
-
getStrategy(): ConcreteWalletStrategy;
|
|
40
|
-
/**
|
|
41
|
-
* Load a wallet strategy. Strategies are lazy-loaded to reduce initial bundle size.
|
|
42
|
-
* Call this method before using getStrategy() for a wallet.
|
|
43
|
-
*
|
|
44
|
-
* @param wallet - The wallet strategy to load (defaults to current wallet)
|
|
45
|
-
* @returns The loaded strategy
|
|
46
|
-
*/
|
|
47
|
-
loadStrategy(wallet?: Wallet): Promise<ConcreteWalletStrategy | undefined>;
|
|
48
|
-
/**
|
|
49
|
-
* Load multiple wallet strategies in parallel.
|
|
50
|
-
* Useful for preloading commonly used wallets during app initialization.
|
|
51
|
-
*
|
|
52
|
-
* @param wallets - Array of wallets to preload
|
|
53
|
-
*/
|
|
54
|
-
loadStrategies(wallets: Wallet[]): Promise<void>;
|
|
55
|
-
}
|
|
56
|
-
declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
|
|
57
|
-
//#endregion
|
|
58
|
-
export { WalletStrategy, createStrategyFactory };
|