@injectivelabs/wallet-strategy 1.15.6 → 1.15.9
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/strategy/index.d.ts +10 -4
- package/dist/cjs/strategy/index.js +47 -29
- package/dist/esm/strategy/index.d.ts +10 -4
- package/dist/esm/strategy/index.js +48 -30
- package/package.json +18 -17
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type WalletMetadata, WalletStrategyArguments } from '@injectivelabs/wallet-base';
|
|
2
2
|
import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
|
|
3
3
|
export declare class WalletStrategy extends BaseWalletStrategy {
|
|
4
4
|
constructor(args: WalletStrategyArguments);
|
|
5
5
|
/**
|
|
6
|
+
* This method is used to set the metadata for the wallet strategies.
|
|
7
|
+
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
8
|
+
* some cases we are recreating the wallet strategies from scratch using the new
|
|
9
|
+
* metadata
|
|
10
|
+
*
|
|
6
11
|
* Case 1: Private Key is set dynamically
|
|
7
12
|
* If we have a dynamically set private key,
|
|
8
13
|
* we are creating a new PrivateKey strategy
|
|
9
|
-
* with the specified private key
|
|
14
|
+
* with the specified private key (passed as metadata)
|
|
15
|
+
*
|
|
16
|
+
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
10
17
|
*
|
|
11
|
-
* Case 2: Wallet Connect Metadata set dynamically
|
|
12
18
|
*/
|
|
13
|
-
|
|
19
|
+
setMetadata(metadata?: WalletMetadata): void;
|
|
14
20
|
}
|
|
15
21
|
export declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
|
|
@@ -8,6 +8,7 @@ const wallet_evm_1 = require("@injectivelabs/wallet-evm");
|
|
|
8
8
|
const wallet_core_1 = require("@injectivelabs/wallet-core");
|
|
9
9
|
const wallet_cosmos_1 = require("@injectivelabs/wallet-cosmos");
|
|
10
10
|
const wallet_trezor_1 = require("@injectivelabs/wallet-trezor");
|
|
11
|
+
const wallet_turnkey_1 = require("@injectivelabs/wallet-turnkey");
|
|
11
12
|
const wallet_wallet_connect_1 = require("@injectivelabs/wallet-wallet-connect");
|
|
12
13
|
const wallet_private_key_1 = require("@injectivelabs/wallet-private-key");
|
|
13
14
|
const wallet_cosmostation_1 = require("@injectivelabs/wallet-cosmostation");
|
|
@@ -31,6 +32,7 @@ const createStrategy = ({ args, wallet, }) => {
|
|
|
31
32
|
return undefined;
|
|
32
33
|
}
|
|
33
34
|
const ethWalletArgs = {
|
|
35
|
+
...args,
|
|
34
36
|
chainId: args.chainId,
|
|
35
37
|
ethereumOptions: args.ethereumOptions,
|
|
36
38
|
};
|
|
@@ -69,15 +71,12 @@ const createStrategy = ({ args, wallet, }) => {
|
|
|
69
71
|
wallet: wallet_base_1.Wallet.BitGet,
|
|
70
72
|
});
|
|
71
73
|
case wallet_base_1.Wallet.WalletConnect:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
if (!args.metadata?.walletConnect?.projectId) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return new wallet_wallet_connect_1.WalletConnectStrategy(ethWalletArgs);
|
|
76
78
|
case wallet_base_1.Wallet.PrivateKey:
|
|
77
|
-
return new wallet_private_key_1.PrivateKeyWalletStrategy(
|
|
78
|
-
...ethWalletArgs,
|
|
79
|
-
privateKey: args.options?.privateKey,
|
|
80
|
-
});
|
|
79
|
+
return new wallet_private_key_1.PrivateKeyWalletStrategy(ethWalletArgs);
|
|
81
80
|
case wallet_base_1.Wallet.Keplr:
|
|
82
81
|
return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.Keplr });
|
|
83
82
|
case wallet_base_1.Wallet.Cosmostation:
|
|
@@ -89,15 +88,22 @@ const createStrategy = ({ args, wallet, }) => {
|
|
|
89
88
|
case wallet_base_1.Wallet.OWallet:
|
|
90
89
|
return new wallet_cosmos_1.CosmosWalletStrategy({ ...args, wallet: wallet_base_1.Wallet.OWallet });
|
|
91
90
|
case wallet_base_1.Wallet.Magic:
|
|
92
|
-
if (!args.
|
|
93
|
-
!args.options?.metadata.magic?.apiKey ||
|
|
94
|
-
!args.options?.metadata.magic?.rpcEndpoint) {
|
|
91
|
+
if (!args.metadata?.magic?.apiKey || !args.metadata?.magic?.rpcEndpoint) {
|
|
95
92
|
return undefined;
|
|
96
93
|
}
|
|
97
|
-
return new wallet_magic_1.MagicStrategy(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
return new wallet_magic_1.MagicStrategy(args);
|
|
95
|
+
case wallet_base_1.Wallet.TurnkeyOtp:
|
|
96
|
+
if (!args.metadata?.turnkey?.defaultOrganizationId ||
|
|
97
|
+
!args.metadata?.turnkey?.iframeContainerId) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
return new wallet_turnkey_1.TurnkeyOtpWalletStrategy(ethWalletArgs);
|
|
101
|
+
case wallet_base_1.Wallet.TurnkeyOauth:
|
|
102
|
+
if (!args.metadata?.turnkey?.defaultOrganizationId ||
|
|
103
|
+
!args.metadata?.turnkey?.iframeContainerId) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
return new wallet_turnkey_1.TurnkeyOauthWalletStrategy(ethWalletArgs);
|
|
101
107
|
default:
|
|
102
108
|
return undefined;
|
|
103
109
|
}
|
|
@@ -120,25 +126,37 @@ class WalletStrategy extends wallet_core_1.BaseWalletStrategy {
|
|
|
120
126
|
});
|
|
121
127
|
}
|
|
122
128
|
/**
|
|
129
|
+
* This method is used to set the metadata for the wallet strategies.
|
|
130
|
+
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
131
|
+
* some cases we are recreating the wallet strategies from scratch using the new
|
|
132
|
+
* metadata
|
|
133
|
+
*
|
|
123
134
|
* Case 1: Private Key is set dynamically
|
|
124
135
|
* If we have a dynamically set private key,
|
|
125
136
|
* we are creating a new PrivateKey strategy
|
|
126
|
-
* with the specified private key
|
|
137
|
+
* with the specified private key (passed as metadata)
|
|
138
|
+
*
|
|
139
|
+
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
127
140
|
*
|
|
128
|
-
* Case 2: Wallet Connect Metadata set dynamically
|
|
129
141
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
setMetadata(metadata) {
|
|
143
|
+
const shouldRecreateStrategyOnMetadataChange = [
|
|
144
|
+
wallet_base_1.Wallet.PrivateKey,
|
|
145
|
+
wallet_base_1.Wallet.WalletConnect,
|
|
146
|
+
];
|
|
147
|
+
for (const wallet of Object.keys(this.strategies)) {
|
|
148
|
+
const walletEnum = wallet;
|
|
149
|
+
if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
|
|
150
|
+
this.strategies[walletEnum] = createStrategy({
|
|
151
|
+
args: {
|
|
152
|
+
...this.args,
|
|
153
|
+
metadata: { ...this.args.metadata, ...metadata },
|
|
154
|
+
},
|
|
155
|
+
wallet: walletEnum,
|
|
156
|
+
});
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
this.strategies[walletEnum]?.setMetadata?.(metadata);
|
|
142
160
|
}
|
|
143
161
|
}
|
|
144
162
|
}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type WalletMetadata, WalletStrategyArguments } from '@injectivelabs/wallet-base';
|
|
2
2
|
import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
|
|
3
3
|
export declare class WalletStrategy extends BaseWalletStrategy {
|
|
4
4
|
constructor(args: WalletStrategyArguments);
|
|
5
5
|
/**
|
|
6
|
+
* This method is used to set the metadata for the wallet strategies.
|
|
7
|
+
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
8
|
+
* some cases we are recreating the wallet strategies from scratch using the new
|
|
9
|
+
* metadata
|
|
10
|
+
*
|
|
6
11
|
* Case 1: Private Key is set dynamically
|
|
7
12
|
* If we have a dynamically set private key,
|
|
8
13
|
* we are creating a new PrivateKey strategy
|
|
9
|
-
* with the specified private key
|
|
14
|
+
* with the specified private key (passed as metadata)
|
|
15
|
+
*
|
|
16
|
+
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
10
17
|
*
|
|
11
|
-
* Case 2: Wallet Connect Metadata set dynamically
|
|
12
18
|
*/
|
|
13
|
-
|
|
19
|
+
setMetadata(metadata?: WalletMetadata): void;
|
|
14
20
|
}
|
|
15
21
|
export declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
|
|
@@ -4,7 +4,8 @@ import { MagicStrategy } from '@injectivelabs/wallet-magic';
|
|
|
4
4
|
import { EvmWalletStrategy } from '@injectivelabs/wallet-evm';
|
|
5
5
|
import { BaseWalletStrategy } from '@injectivelabs/wallet-core';
|
|
6
6
|
import { CosmosWalletStrategy } from '@injectivelabs/wallet-cosmos';
|
|
7
|
-
import { TrezorBip32Strategy, TrezorBip44Strategy } from '@injectivelabs/wallet-trezor';
|
|
7
|
+
import { TrezorBip32Strategy, TrezorBip44Strategy, } from '@injectivelabs/wallet-trezor';
|
|
8
|
+
import { TurnkeyOtpWalletStrategy, TurnkeyOauthWalletStrategy, } from '@injectivelabs/wallet-turnkey';
|
|
8
9
|
import { WalletConnectStrategy } from '@injectivelabs/wallet-wallet-connect';
|
|
9
10
|
import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key';
|
|
10
11
|
import { CosmostationWalletStrategy } from '@injectivelabs/wallet-cosmostation';
|
|
@@ -28,6 +29,7 @@ const createStrategy = ({ args, wallet, }) => {
|
|
|
28
29
|
return undefined;
|
|
29
30
|
}
|
|
30
31
|
const ethWalletArgs = {
|
|
32
|
+
...args,
|
|
31
33
|
chainId: args.chainId,
|
|
32
34
|
ethereumOptions: args.ethereumOptions,
|
|
33
35
|
};
|
|
@@ -66,15 +68,12 @@ const createStrategy = ({ args, wallet, }) => {
|
|
|
66
68
|
wallet: Wallet.BitGet,
|
|
67
69
|
});
|
|
68
70
|
case Wallet.WalletConnect:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
if (!args.metadata?.walletConnect?.projectId) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
return new WalletConnectStrategy(ethWalletArgs);
|
|
73
75
|
case Wallet.PrivateKey:
|
|
74
|
-
return new PrivateKeyWalletStrategy(
|
|
75
|
-
...ethWalletArgs,
|
|
76
|
-
privateKey: args.options?.privateKey,
|
|
77
|
-
});
|
|
76
|
+
return new PrivateKeyWalletStrategy(ethWalletArgs);
|
|
78
77
|
case Wallet.Keplr:
|
|
79
78
|
return new CosmosWalletStrategy({ ...args, wallet: Wallet.Keplr });
|
|
80
79
|
case Wallet.Cosmostation:
|
|
@@ -86,15 +85,22 @@ const createStrategy = ({ args, wallet, }) => {
|
|
|
86
85
|
case Wallet.OWallet:
|
|
87
86
|
return new CosmosWalletStrategy({ ...args, wallet: Wallet.OWallet });
|
|
88
87
|
case Wallet.Magic:
|
|
89
|
-
if (!args.
|
|
90
|
-
!args.options?.metadata.magic?.apiKey ||
|
|
91
|
-
!args.options?.metadata.magic?.rpcEndpoint) {
|
|
88
|
+
if (!args.metadata?.magic?.apiKey || !args.metadata?.magic?.rpcEndpoint) {
|
|
92
89
|
return undefined;
|
|
93
90
|
}
|
|
94
|
-
return new MagicStrategy(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
return new MagicStrategy(args);
|
|
92
|
+
case Wallet.TurnkeyOtp:
|
|
93
|
+
if (!args.metadata?.turnkey?.defaultOrganizationId ||
|
|
94
|
+
!args.metadata?.turnkey?.iframeContainerId) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
return new TurnkeyOtpWalletStrategy(ethWalletArgs);
|
|
98
|
+
case Wallet.TurnkeyOauth:
|
|
99
|
+
if (!args.metadata?.turnkey?.defaultOrganizationId ||
|
|
100
|
+
!args.metadata?.turnkey?.iframeContainerId) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
return new TurnkeyOauthWalletStrategy(ethWalletArgs);
|
|
98
104
|
default:
|
|
99
105
|
return undefined;
|
|
100
106
|
}
|
|
@@ -117,25 +123,37 @@ export class WalletStrategy extends BaseWalletStrategy {
|
|
|
117
123
|
});
|
|
118
124
|
}
|
|
119
125
|
/**
|
|
126
|
+
* This method is used to set the metadata for the wallet strategies.
|
|
127
|
+
* In some cases we are going to set the metadata dynamically on the fly, and in
|
|
128
|
+
* some cases we are recreating the wallet strategies from scratch using the new
|
|
129
|
+
* metadata
|
|
130
|
+
*
|
|
120
131
|
* Case 1: Private Key is set dynamically
|
|
121
132
|
* If we have a dynamically set private key,
|
|
122
133
|
* we are creating a new PrivateKey strategy
|
|
123
|
-
* with the specified private key
|
|
134
|
+
* with the specified private key (passed as metadata)
|
|
135
|
+
*
|
|
136
|
+
* Case 2: Similar to Case 1, but for Wallet Connect Metadata
|
|
124
137
|
*
|
|
125
|
-
* Case 2: Wallet Connect Metadata set dynamically
|
|
126
138
|
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
setMetadata(metadata) {
|
|
140
|
+
const shouldRecreateStrategyOnMetadataChange = [
|
|
141
|
+
Wallet.PrivateKey,
|
|
142
|
+
Wallet.WalletConnect,
|
|
143
|
+
];
|
|
144
|
+
for (const wallet of Object.keys(this.strategies)) {
|
|
145
|
+
const walletEnum = wallet;
|
|
146
|
+
if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
|
|
147
|
+
this.strategies[walletEnum] = createStrategy({
|
|
148
|
+
args: {
|
|
149
|
+
...this.args,
|
|
150
|
+
metadata: { ...this.args.metadata, ...metadata },
|
|
151
|
+
},
|
|
152
|
+
wallet: walletEnum,
|
|
153
|
+
});
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
this.strategies[walletEnum]?.setMetadata?.(metadata);
|
|
139
157
|
}
|
|
140
158
|
}
|
|
141
159
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-strategy",
|
|
3
3
|
"description": "Wallet strategy with instantiated wallets",
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.9",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
@@ -58,21 +58,22 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@ethereumjs/common": "^3.1.1",
|
|
60
60
|
"@ethereumjs/tx": "^4.1.1",
|
|
61
|
-
"@injectivelabs/exceptions": "^1.15.
|
|
62
|
-
"@injectivelabs/networks": "^1.15.
|
|
63
|
-
"@injectivelabs/sdk-ts": "^1.15.
|
|
64
|
-
"@injectivelabs/ts-types": "^1.15.
|
|
65
|
-
"@injectivelabs/utils": "^1.15.
|
|
66
|
-
"@injectivelabs/wallet-base": "^1.15.
|
|
67
|
-
"@injectivelabs/wallet-core": "^1.15.
|
|
68
|
-
"@injectivelabs/wallet-cosmos": "^1.15.
|
|
69
|
-
"@injectivelabs/wallet-cosmostation": "^1.15.
|
|
70
|
-
"@injectivelabs/wallet-evm": "^1.15.
|
|
71
|
-
"@injectivelabs/wallet-ledger": "^1.15.
|
|
72
|
-
"@injectivelabs/wallet-magic": "^1.15.
|
|
73
|
-
"@injectivelabs/wallet-private-key": "^1.15.
|
|
74
|
-
"@injectivelabs/wallet-trezor": "^1.15.
|
|
75
|
-
"@injectivelabs/wallet-
|
|
61
|
+
"@injectivelabs/exceptions": "^1.15.5",
|
|
62
|
+
"@injectivelabs/networks": "^1.15.6",
|
|
63
|
+
"@injectivelabs/sdk-ts": "^1.15.8",
|
|
64
|
+
"@injectivelabs/ts-types": "^1.15.6",
|
|
65
|
+
"@injectivelabs/utils": "^1.15.6",
|
|
66
|
+
"@injectivelabs/wallet-base": "^1.15.8",
|
|
67
|
+
"@injectivelabs/wallet-core": "^1.15.8",
|
|
68
|
+
"@injectivelabs/wallet-cosmos": "^1.15.8",
|
|
69
|
+
"@injectivelabs/wallet-cosmostation": "^1.15.8",
|
|
70
|
+
"@injectivelabs/wallet-evm": "^1.15.8",
|
|
71
|
+
"@injectivelabs/wallet-ledger": "^1.15.8",
|
|
72
|
+
"@injectivelabs/wallet-magic": "^1.15.8",
|
|
73
|
+
"@injectivelabs/wallet-private-key": "^1.15.8",
|
|
74
|
+
"@injectivelabs/wallet-trezor": "^1.15.8",
|
|
75
|
+
"@injectivelabs/wallet-turnkey": "^1.15.8",
|
|
76
|
+
"@injectivelabs/wallet-wallet-connect": "^1.15.8",
|
|
76
77
|
"alchemy-sdk": "^3.4.7",
|
|
77
78
|
"eip1193-provider": "^1.0.1",
|
|
78
79
|
"eth-sig-util": "^3.0.1",
|
|
@@ -86,5 +87,5 @@
|
|
|
86
87
|
"@types/hdkey": "^2.0.1",
|
|
87
88
|
"shx": "^0.3.3"
|
|
88
89
|
},
|
|
89
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "665d3c0d18f84887a39fbaab3513b4fbf940d225"
|
|
90
91
|
}
|