@injectivelabs/wallet-strategy 1.20.65 → 1.20.66
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 +34 -6
- package/dist/esm/index.js +34 -6
- package/package.json +13 -12
package/dist/cjs/index.cjs
CHANGED
|
@@ -9,6 +9,7 @@ let cachedLedgerStrategies = null;
|
|
|
9
9
|
let cachedTrezorStrategies = null;
|
|
10
10
|
let cachedPrivateKeyStrategy = null;
|
|
11
11
|
let cachedTurnkeyStrategy = null;
|
|
12
|
+
let cachedPrivyStrategy = null;
|
|
12
13
|
let cachedMagicStrategy = null;
|
|
13
14
|
let cachedWalletConnectStrategy = null;
|
|
14
15
|
let cachedPrivateKeyCosmosStrategy = null;
|
|
@@ -52,6 +53,10 @@ const loadTurnkeyStrategy = async () => {
|
|
|
52
53
|
if (!cachedTurnkeyStrategy) cachedTurnkeyStrategy = (await import("@injectivelabs/wallet-turnkey")).TurnkeyWalletStrategy;
|
|
53
54
|
return cachedTurnkeyStrategy;
|
|
54
55
|
};
|
|
56
|
+
const loadPrivyStrategy = async () => {
|
|
57
|
+
if (!cachedPrivyStrategy) cachedPrivyStrategy = (await import("@injectivelabs/wallet-privy")).PrivyWalletStrategy;
|
|
58
|
+
return cachedPrivyStrategy;
|
|
59
|
+
};
|
|
55
60
|
const loadMagicStrategy = async () => {
|
|
56
61
|
if (!cachedMagicStrategy) cachedMagicStrategy = (await import("@injectivelabs/wallet-magic")).MagicStrategy;
|
|
57
62
|
return cachedMagicStrategy;
|
|
@@ -105,6 +110,7 @@ function _defineProperty(e, r, t) {
|
|
|
105
110
|
|
|
106
111
|
//#endregion
|
|
107
112
|
//#region src/strategy/index.ts
|
|
113
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
108
114
|
const ethereumWalletsDisabled = (args) => {
|
|
109
115
|
const { evmOptions } = args;
|
|
110
116
|
if (!evmOptions) return true;
|
|
@@ -173,6 +179,7 @@ const createStrategy = async ({ args, wallet, emitter }) => {
|
|
|
173
179
|
var _args$metadata;
|
|
174
180
|
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;
|
|
175
181
|
return new (await (loadTurnkeyStrategy()))(ethWalletArgs);
|
|
182
|
+
case __injectivelabs_wallet_base_runtime_light.Wallet.Privy: return new (await (loadPrivyStrategy()))(ethWalletArgs);
|
|
176
183
|
case __injectivelabs_wallet_base_runtime_light.Wallet.Magic:
|
|
177
184
|
var _args$metadata2, _args$metadata3;
|
|
178
185
|
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;
|
|
@@ -221,6 +228,23 @@ var WalletStrategy = class extends __injectivelabs_wallet_core_strategy.BaseWall
|
|
|
221
228
|
*
|
|
222
229
|
*/
|
|
223
230
|
async setMetadata(metadata) {
|
|
231
|
+
var _this$args$metadata;
|
|
232
|
+
const current = (_this$args$metadata = this.args.metadata) !== null && _this$args$metadata !== void 0 ? _this$args$metadata : {};
|
|
233
|
+
const merged = Object.fromEntries(Object.entries({
|
|
234
|
+
...current,
|
|
235
|
+
...metadata
|
|
236
|
+
}).map(([key, value]) => [key, isPlainObject(current[key]) && isPlainObject(value) ? {
|
|
237
|
+
...current[key],
|
|
238
|
+
...value
|
|
239
|
+
} : value]));
|
|
240
|
+
const { privateKey: _privateKey, ...kept } = merged;
|
|
241
|
+
this.args = {
|
|
242
|
+
...this.args,
|
|
243
|
+
metadata: current.privateKey ? {
|
|
244
|
+
...kept,
|
|
245
|
+
privateKey: current.privateKey
|
|
246
|
+
} : kept
|
|
247
|
+
};
|
|
224
248
|
const shouldRecreateStrategyOnMetadataChange = [__injectivelabs_wallet_base_runtime_light.Wallet.PrivateKey, __injectivelabs_wallet_base_runtime_light.Wallet.WalletConnect];
|
|
225
249
|
const strategiesWithPlaceholders = {
|
|
226
250
|
...this.strategies,
|
|
@@ -235,10 +259,7 @@ var WalletStrategy = class extends __injectivelabs_wallet_core_strategy.BaseWall
|
|
|
235
259
|
this.strategies[walletEnum] = await createStrategy({
|
|
236
260
|
args: {
|
|
237
261
|
...this.args,
|
|
238
|
-
metadata:
|
|
239
|
-
...this.args.metadata,
|
|
240
|
-
...metadata
|
|
241
|
-
}
|
|
262
|
+
metadata: merged
|
|
242
263
|
},
|
|
243
264
|
wallet: walletEnum,
|
|
244
265
|
emitter: this.getEmitter()
|
|
@@ -271,15 +292,22 @@ var WalletStrategy = class extends __injectivelabs_wallet_core_strategy.BaseWall
|
|
|
271
292
|
if (this.strategies[wallet]) return this.strategies[wallet];
|
|
272
293
|
const existingLoad = this.loadingStrategies.get(wallet);
|
|
273
294
|
if (existingLoad) return existingLoad;
|
|
295
|
+
const { args } = this;
|
|
274
296
|
const loadPromise = createStrategy({
|
|
275
|
-
args
|
|
297
|
+
args,
|
|
276
298
|
wallet,
|
|
277
299
|
emitter: this.getEmitter()
|
|
278
300
|
});
|
|
279
301
|
this.loadingStrategies.set(wallet, loadPromise);
|
|
280
302
|
try {
|
|
281
303
|
const strategy = await loadPromise;
|
|
282
|
-
if (strategy)
|
|
304
|
+
if (strategy) {
|
|
305
|
+
if (this.args !== args) {
|
|
306
|
+
var _strategy$setMetadata;
|
|
307
|
+
(_strategy$setMetadata = strategy.setMetadata) === null || _strategy$setMetadata === void 0 || _strategy$setMetadata.call(strategy, this.args.metadata);
|
|
308
|
+
}
|
|
309
|
+
this.strategies[wallet] = strategy;
|
|
310
|
+
}
|
|
283
311
|
return strategy;
|
|
284
312
|
} finally {
|
|
285
313
|
this.loadingStrategies.delete(wallet);
|
package/dist/esm/index.js
CHANGED
|
@@ -9,6 +9,7 @@ let cachedLedgerStrategies = null;
|
|
|
9
9
|
let cachedTrezorStrategies = null;
|
|
10
10
|
let cachedPrivateKeyStrategy = null;
|
|
11
11
|
let cachedTurnkeyStrategy = null;
|
|
12
|
+
let cachedPrivyStrategy = null;
|
|
12
13
|
let cachedMagicStrategy = null;
|
|
13
14
|
let cachedWalletConnectStrategy = null;
|
|
14
15
|
let cachedPrivateKeyCosmosStrategy = null;
|
|
@@ -52,6 +53,10 @@ const loadTurnkeyStrategy = async () => {
|
|
|
52
53
|
if (!cachedTurnkeyStrategy) cachedTurnkeyStrategy = (await import("@injectivelabs/wallet-turnkey")).TurnkeyWalletStrategy;
|
|
53
54
|
return cachedTurnkeyStrategy;
|
|
54
55
|
};
|
|
56
|
+
const loadPrivyStrategy = async () => {
|
|
57
|
+
if (!cachedPrivyStrategy) cachedPrivyStrategy = (await import("@injectivelabs/wallet-privy")).PrivyWalletStrategy;
|
|
58
|
+
return cachedPrivyStrategy;
|
|
59
|
+
};
|
|
55
60
|
const loadMagicStrategy = async () => {
|
|
56
61
|
if (!cachedMagicStrategy) cachedMagicStrategy = (await import("@injectivelabs/wallet-magic")).MagicStrategy;
|
|
57
62
|
return cachedMagicStrategy;
|
|
@@ -105,6 +110,7 @@ function _defineProperty(e, r, t) {
|
|
|
105
110
|
|
|
106
111
|
//#endregion
|
|
107
112
|
//#region src/strategy/index.ts
|
|
113
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
108
114
|
const ethereumWalletsDisabled = (args) => {
|
|
109
115
|
const { evmOptions } = args;
|
|
110
116
|
if (!evmOptions) return true;
|
|
@@ -173,6 +179,7 @@ const createStrategy = async ({ args, wallet, emitter }) => {
|
|
|
173
179
|
var _args$metadata;
|
|
174
180
|
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;
|
|
175
181
|
return new (await (loadTurnkeyStrategy()))(ethWalletArgs);
|
|
182
|
+
case Wallet.Privy: return new (await (loadPrivyStrategy()))(ethWalletArgs);
|
|
176
183
|
case Wallet.Magic:
|
|
177
184
|
var _args$metadata2, _args$metadata3;
|
|
178
185
|
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;
|
|
@@ -221,6 +228,23 @@ var WalletStrategy = class extends BaseWalletStrategy {
|
|
|
221
228
|
*
|
|
222
229
|
*/
|
|
223
230
|
async setMetadata(metadata) {
|
|
231
|
+
var _this$args$metadata;
|
|
232
|
+
const current = (_this$args$metadata = this.args.metadata) !== null && _this$args$metadata !== void 0 ? _this$args$metadata : {};
|
|
233
|
+
const merged = Object.fromEntries(Object.entries({
|
|
234
|
+
...current,
|
|
235
|
+
...metadata
|
|
236
|
+
}).map(([key, value]) => [key, isPlainObject(current[key]) && isPlainObject(value) ? {
|
|
237
|
+
...current[key],
|
|
238
|
+
...value
|
|
239
|
+
} : value]));
|
|
240
|
+
const { privateKey: _privateKey, ...kept } = merged;
|
|
241
|
+
this.args = {
|
|
242
|
+
...this.args,
|
|
243
|
+
metadata: current.privateKey ? {
|
|
244
|
+
...kept,
|
|
245
|
+
privateKey: current.privateKey
|
|
246
|
+
} : kept
|
|
247
|
+
};
|
|
224
248
|
const shouldRecreateStrategyOnMetadataChange = [Wallet.PrivateKey, Wallet.WalletConnect];
|
|
225
249
|
const strategiesWithPlaceholders = {
|
|
226
250
|
...this.strategies,
|
|
@@ -235,10 +259,7 @@ var WalletStrategy = class extends BaseWalletStrategy {
|
|
|
235
259
|
this.strategies[walletEnum] = await createStrategy({
|
|
236
260
|
args: {
|
|
237
261
|
...this.args,
|
|
238
|
-
metadata:
|
|
239
|
-
...this.args.metadata,
|
|
240
|
-
...metadata
|
|
241
|
-
}
|
|
262
|
+
metadata: merged
|
|
242
263
|
},
|
|
243
264
|
wallet: walletEnum,
|
|
244
265
|
emitter: this.getEmitter()
|
|
@@ -271,15 +292,22 @@ var WalletStrategy = class extends BaseWalletStrategy {
|
|
|
271
292
|
if (this.strategies[wallet]) return this.strategies[wallet];
|
|
272
293
|
const existingLoad = this.loadingStrategies.get(wallet);
|
|
273
294
|
if (existingLoad) return existingLoad;
|
|
295
|
+
const { args } = this;
|
|
274
296
|
const loadPromise = createStrategy({
|
|
275
|
-
args
|
|
297
|
+
args,
|
|
276
298
|
wallet,
|
|
277
299
|
emitter: this.getEmitter()
|
|
278
300
|
});
|
|
279
301
|
this.loadingStrategies.set(wallet, loadPromise);
|
|
280
302
|
try {
|
|
281
303
|
const strategy = await loadPromise;
|
|
282
|
-
if (strategy)
|
|
304
|
+
if (strategy) {
|
|
305
|
+
if (this.args !== args) {
|
|
306
|
+
var _strategy$setMetadata;
|
|
307
|
+
(_strategy$setMetadata = strategy.setMetadata) === null || _strategy$setMetadata === void 0 || _strategy$setMetadata.call(strategy, this.args.metadata);
|
|
308
|
+
}
|
|
309
|
+
this.strategies[wallet] = strategy;
|
|
310
|
+
}
|
|
283
311
|
return strategy;
|
|
284
312
|
} finally {
|
|
285
313
|
this.loadingStrategies.delete(wallet);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-strategy",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.66",
|
|
4
4
|
"description": "Wallet strategy with instantiated wallets",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -42,17 +42,18 @@
|
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@injectivelabs/exceptions": "1.20.
|
|
46
|
-
"@injectivelabs/wallet-
|
|
47
|
-
"@injectivelabs/wallet-
|
|
48
|
-
"@injectivelabs/wallet-cosmos": "1.20.
|
|
49
|
-
"@injectivelabs/wallet-
|
|
50
|
-
"@injectivelabs/wallet-
|
|
51
|
-
"@injectivelabs/wallet-magic": "1.20.
|
|
52
|
-
"@injectivelabs/wallet-private-key": "1.20.
|
|
53
|
-
"@injectivelabs/wallet-
|
|
54
|
-
"@injectivelabs/wallet-
|
|
55
|
-
"@injectivelabs/wallet-
|
|
45
|
+
"@injectivelabs/exceptions": "1.20.66",
|
|
46
|
+
"@injectivelabs/wallet-base": "1.20.66",
|
|
47
|
+
"@injectivelabs/wallet-core": "1.20.66",
|
|
48
|
+
"@injectivelabs/wallet-cosmos": "1.20.66",
|
|
49
|
+
"@injectivelabs/wallet-ledger": "1.20.66",
|
|
50
|
+
"@injectivelabs/wallet-evm": "1.20.66",
|
|
51
|
+
"@injectivelabs/wallet-magic": "1.20.66",
|
|
52
|
+
"@injectivelabs/wallet-private-key": "1.20.66",
|
|
53
|
+
"@injectivelabs/wallet-privy": "1.20.65",
|
|
54
|
+
"@injectivelabs/wallet-trezor": "1.20.66",
|
|
55
|
+
"@injectivelabs/wallet-turnkey": "1.20.66",
|
|
56
|
+
"@injectivelabs/wallet-wallet-connect": "1.20.66"
|
|
56
57
|
},
|
|
57
58
|
"publishConfig": {
|
|
58
59
|
"access": "public"
|