@injectivelabs/wallet-turnkey 1.16.6-alpha.0 → 1.16.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -32
- package/dist/cjs/strategy/strategy.d.ts +9 -8
- package/dist/cjs/strategy/strategy.js +37 -23
- package/dist/cjs/strategy/turnkey/oauth.d.ts +3 -3
- package/dist/cjs/strategy/turnkey/oauth.js +4 -5
- package/dist/cjs/strategy/turnkey/otp.d.ts +3 -4
- package/dist/cjs/strategy/turnkey/otp.js +10 -10
- package/dist/cjs/strategy/turnkey/turnkey.d.ts +12 -8
- package/dist/cjs/strategy/turnkey/turnkey.js +119 -73
- package/dist/cjs/strategy/types.d.ts +1 -1
- package/dist/esm/strategy/strategy.d.ts +9 -8
- package/dist/esm/strategy/strategy.js +34 -20
- package/dist/esm/strategy/turnkey/oauth.d.ts +3 -3
- package/dist/esm/strategy/turnkey/oauth.js +4 -5
- package/dist/esm/strategy/turnkey/otp.d.ts +3 -4
- package/dist/esm/strategy/turnkey/otp.js +10 -10
- package/dist/esm/strategy/turnkey/turnkey.d.ts +12 -8
- package/dist/esm/strategy/turnkey/turnkey.js +121 -75
- package/dist/esm/strategy/types.d.ts +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ _Package to use Turnkey Wallet on Injective via the wallet strategy._
|
|
|
11
11
|
## 📚 Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
|
|
14
|
+
yarn add @injectivelabs/wallet-turnkey
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
---
|
|
@@ -28,28 +28,30 @@ dependencies and implementations for their specific wallets.
|
|
|
28
28
|
Here's a brief example of how to use this package to send 1 INJ.:
|
|
29
29
|
|
|
30
30
|
```typescript
|
|
31
|
-
import { Wallet } from '@injectivelabs/wallet-base'
|
|
32
|
-
import { BaseWalletStrategy, MsgBroadcaster } from '@injectivelabs/wallet-core'
|
|
33
|
-
import { TurnkeyWallet } from '@injectivelabs/wallet-turnkey'
|
|
31
|
+
import { Wallet } from '@injectivelabs/wallet-base';
|
|
32
|
+
import { BaseWalletStrategy, MsgBroadcaster } from '@injectivelabs/wallet-core';
|
|
33
|
+
import { TurnkeyWallet } from '@injectivelabs/wallet-turnkey';
|
|
34
|
+
|
|
34
35
|
|
|
35
36
|
const strategyArgs: WalletStrategyArguments = {
|
|
36
37
|
chainId: ChainId.Mainnet,
|
|
37
38
|
wallet: Wallet.Turnkey,
|
|
38
39
|
strategies: {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
[Wallet.Turnkey]: new TurnkeyWallet({
|
|
41
|
+
onStatusChange(status) {
|
|
42
|
+
turnkeyStatus.value = status
|
|
43
|
+
},
|
|
44
|
+
chainId: injectiveClients.chainId,
|
|
45
|
+
ethereumOptions: {
|
|
46
|
+
ethereumChainId: injectiveClients.ethereumChainId!,
|
|
47
|
+
},
|
|
48
|
+
metadata: {
|
|
49
|
+
turnkeyAuthIframeContainerId,
|
|
50
|
+
defaultOrganizationId: import.meta.env
|
|
51
|
+
.VITE_TURNKEY_DEFAULT_ORGANIZATION_ID,
|
|
52
|
+
apiBaseUrl: 'https://api.turnkey.com',
|
|
53
|
+
},
|
|
54
|
+
})
|
|
53
55
|
},
|
|
54
56
|
}
|
|
55
57
|
const walletStrategy = new BaseWalletStrategy(strategyArgs)
|
|
@@ -63,21 +65,21 @@ const msgBroadcaster = new MsgBroadcaster({
|
|
|
63
65
|
})
|
|
64
66
|
|
|
65
67
|
const sendTX = async () => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
68
|
+
const injectiveAddress = 'someInjectiveAddress'
|
|
69
|
+
|
|
70
|
+
const message = MsgSend.fromJSON({
|
|
71
|
+
srcInjectiveAddress: injectiveAddress,
|
|
72
|
+
dstInjectiveAddress: injectiveAddress,
|
|
73
|
+
amount: {
|
|
74
|
+
amount: '1',
|
|
75
|
+
denom: 'inj',
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
return await msgBroadcaster.broadcast({ msgs: message })
|
|
80
|
+
}
|
|
79
81
|
|
|
80
|
-
const result = await sendTX()
|
|
82
|
+
const result = await sendTX()
|
|
81
83
|
```
|
|
82
84
|
|
|
83
85
|
Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { TxRaw, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
-
import { StdSignDoc, WalletDeviceType, type WalletMetadata, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, WalletStrategyEvmOptions, ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
3
2
|
import { HttpRestClient } from '@injectivelabs/utils';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
4
|
+
import { TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
5
|
+
import { StdSignDoc, WalletDeviceType, type WalletMetadata, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, WalletStrategyEthereumOptions, ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
6
6
|
import { TurnkeyWallet } from './turnkey/turnkey.js';
|
|
7
7
|
export declare class TurnkeyWalletStrategy extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
8
8
|
turnkeyWallet?: TurnkeyWallet;
|
|
9
|
-
|
|
9
|
+
ethereumOptions: WalletStrategyEthereumOptions;
|
|
10
10
|
client: HttpRestClient;
|
|
11
|
-
constructor(args:
|
|
11
|
+
constructor(args: ConcreteEthereumWalletStrategyArgs & {
|
|
12
12
|
apiServerEndpoint?: string;
|
|
13
13
|
});
|
|
14
14
|
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
@@ -22,7 +22,7 @@ export declare class TurnkeyWalletStrategy extends BaseConcreteStrategy implemen
|
|
|
22
22
|
getWalletClient<TurnkeyWallet>(): Promise<TurnkeyWallet>;
|
|
23
23
|
sendEvmTransaction(transaction: unknown, args: {
|
|
24
24
|
address: AccountAddress;
|
|
25
|
-
|
|
25
|
+
ethereumChainId: EthereumChainId;
|
|
26
26
|
}): Promise<string>;
|
|
27
27
|
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<any>;
|
|
28
28
|
signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
|
|
@@ -38,8 +38,9 @@ export declare class TurnkeyWalletStrategy extends BaseConcreteStrategy implemen
|
|
|
38
38
|
}): Promise<AminoSignResponse>;
|
|
39
39
|
signArbitrary(_signer: AccountAddress, _data: string | Uint8Array): Promise<string>;
|
|
40
40
|
getEthereumChainId(): Promise<string>;
|
|
41
|
-
getEvmTransactionReceipt(txHash: string,
|
|
41
|
+
getEvmTransactionReceipt(txHash: string, ethereumChainId?: EthereumChainId): Promise<Record<string, any>>;
|
|
42
42
|
getPubKey(): Promise<string>;
|
|
43
|
-
|
|
43
|
+
getIframeClient(): Promise<TurnkeyIframeClient>;
|
|
44
44
|
private getTurnkeyWallet;
|
|
45
|
+
private getOrganizationId;
|
|
45
46
|
}
|
|
@@ -5,14 +5,15 @@ exports.TurnkeyWalletStrategy = void 0;
|
|
|
5
5
|
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
6
6
|
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
7
7
|
const viem_1 = require("viem");
|
|
8
|
-
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
9
8
|
const utils_1 = require("@injectivelabs/utils");
|
|
9
|
+
const viem_2 = require("viem");
|
|
10
|
+
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
10
11
|
const types_js_1 = require("./types.js");
|
|
11
12
|
const turnkey_js_1 = require("./turnkey/turnkey.js");
|
|
12
13
|
const consts_js_1 = require("./consts.js");
|
|
13
14
|
class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
14
15
|
turnkeyWallet;
|
|
15
|
-
|
|
16
|
+
ethereumOptions;
|
|
16
17
|
client;
|
|
17
18
|
constructor(args) {
|
|
18
19
|
super(args);
|
|
@@ -21,7 +22,7 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
21
22
|
throw new exceptions_1.WalletException(new Error('apiServerEndpoint is required'));
|
|
22
23
|
}
|
|
23
24
|
this.client = new utils_1.HttpRestClient(endpoint);
|
|
24
|
-
this.
|
|
25
|
+
this.ethereumOptions = args.ethereumOptions;
|
|
25
26
|
}
|
|
26
27
|
async getWalletDeviceType() {
|
|
27
28
|
return Promise.resolve(wallet_base_1.WalletDeviceType.Browser);
|
|
@@ -49,7 +50,7 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
49
50
|
}
|
|
50
51
|
return true;
|
|
51
52
|
}
|
|
52
|
-
return !!(await turnkeyWallet.
|
|
53
|
+
return !!(await turnkeyWallet.getIframeClient());
|
|
53
54
|
}
|
|
54
55
|
catch (e) {
|
|
55
56
|
return false;
|
|
@@ -58,15 +59,15 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
58
59
|
async disconnect() {
|
|
59
60
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
60
61
|
const turnkey = await turnkeyWallet.getTurnkey();
|
|
61
|
-
const indexedDbClient = await turnkeyWallet.getIndexedDbClient();
|
|
62
62
|
const isUserLoggedIn = await turnkey.getSession();
|
|
63
63
|
if (!isUserLoggedIn) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
await
|
|
66
|
+
await turnkey.logout();
|
|
67
67
|
}
|
|
68
68
|
async getAddresses() {
|
|
69
69
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
70
|
+
await turnkeyWallet.getSession();
|
|
70
71
|
try {
|
|
71
72
|
return await turnkeyWallet.getAccounts();
|
|
72
73
|
}
|
|
@@ -91,18 +92,19 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
91
92
|
}
|
|
92
93
|
async sendEvmTransaction(transaction, args) {
|
|
93
94
|
try {
|
|
94
|
-
const options = this.
|
|
95
|
+
const options = this.ethereumOptions;
|
|
95
96
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
96
|
-
const
|
|
97
|
-
const
|
|
97
|
+
const organizationId = await this.getOrganizationId();
|
|
98
|
+
const chainId = args.ethereumChainId || options.ethereumChainId;
|
|
99
|
+
const url = options.rpcUrl || options.rpcUrls?.[args.ethereumChainId];
|
|
98
100
|
if (!url) {
|
|
99
|
-
throw new exceptions_1.WalletException(new Error('Please pass rpcUrl within the
|
|
101
|
+
throw new exceptions_1.WalletException(new Error('Please pass rpcUrl within the ethereumOptions'), {
|
|
100
102
|
code: exceptions_1.UnspecifiedErrorCode,
|
|
101
103
|
context: wallet_base_1.WalletAction.SendEvmTransaction,
|
|
102
104
|
});
|
|
103
105
|
}
|
|
104
|
-
const account = await turnkeyWallet.getOrCreateAndGetAccount((0, viem_1.getAddress)(args.address));
|
|
105
|
-
const accountClient = (0,
|
|
106
|
+
const account = await turnkeyWallet.getOrCreateAndGetAccount((0, viem_1.getAddress)(args.address), organizationId);
|
|
107
|
+
const accountClient = (0, viem_2.createWalletClient)({
|
|
106
108
|
account: account,
|
|
107
109
|
chain: {
|
|
108
110
|
...consts_js_1.DEFAULT_EVM_CHAIN_CONFIG,
|
|
@@ -113,7 +115,7 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
113
115
|
},
|
|
114
116
|
},
|
|
115
117
|
},
|
|
116
|
-
transport: (0,
|
|
118
|
+
transport: (0, viem_2.http)(url),
|
|
117
119
|
});
|
|
118
120
|
const preparedTransaction = await accountClient.prepareTransactionRequest(transaction);
|
|
119
121
|
delete preparedTransaction.account;
|
|
@@ -148,9 +150,10 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
148
150
|
}
|
|
149
151
|
async signEip712TypedData(eip712json, address) {
|
|
150
152
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
153
|
+
const organizationId = await this.getOrganizationId();
|
|
151
154
|
//? Turnkey expects the case sensitive address and the current impl of getChecksumAddress from sdk-ts doesn't play nice with browser envs
|
|
152
155
|
const checksumAddress = (0, viem_1.getAddress)(address);
|
|
153
|
-
const account = await turnkeyWallet.getOrCreateAndGetAccount(checksumAddress);
|
|
156
|
+
const account = await turnkeyWallet.getOrCreateAndGetAccount(checksumAddress, organizationId);
|
|
154
157
|
if (!account) {
|
|
155
158
|
throw new exceptions_1.WalletException(new Error('Turnkey account not found'));
|
|
156
159
|
}
|
|
@@ -196,19 +199,19 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
196
199
|
context: wallet_base_1.WalletAction.GetChainId,
|
|
197
200
|
});
|
|
198
201
|
}
|
|
199
|
-
async getEvmTransactionReceipt(txHash,
|
|
200
|
-
const options = this.
|
|
202
|
+
async getEvmTransactionReceipt(txHash, ethereumChainId) {
|
|
203
|
+
const options = this.ethereumOptions;
|
|
201
204
|
const maxAttempts = 10;
|
|
202
205
|
const interval = 3000;
|
|
203
|
-
const chainId =
|
|
206
|
+
const chainId = ethereumChainId || options.ethereumChainId;
|
|
204
207
|
const url = options.rpcUrl || options.rpcUrls?.[chainId];
|
|
205
208
|
if (!url) {
|
|
206
|
-
throw new exceptions_1.WalletException(new Error('Please pass rpcUrl within the
|
|
209
|
+
throw new exceptions_1.WalletException(new Error('Please pass rpcUrl within the ethereumOptions'), {
|
|
207
210
|
code: exceptions_1.UnspecifiedErrorCode,
|
|
208
211
|
context: wallet_base_1.WalletAction.GetEvmTransactionReceipt,
|
|
209
212
|
});
|
|
210
213
|
}
|
|
211
|
-
const publicClient = (0,
|
|
214
|
+
const publicClient = (0, viem_2.createPublicClient)({
|
|
212
215
|
chain: {
|
|
213
216
|
...consts_js_1.DEFAULT_EVM_CHAIN_CONFIG,
|
|
214
217
|
id: chainId,
|
|
@@ -218,7 +221,7 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
218
221
|
},
|
|
219
222
|
},
|
|
220
223
|
},
|
|
221
|
-
transport: (0,
|
|
224
|
+
transport: (0, viem_2.http)(url),
|
|
222
225
|
});
|
|
223
226
|
let attempts = 0;
|
|
224
227
|
while (attempts < maxAttempts) {
|
|
@@ -240,10 +243,9 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
240
243
|
async getPubKey() {
|
|
241
244
|
throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
|
|
242
245
|
}
|
|
243
|
-
async
|
|
246
|
+
async getIframeClient() {
|
|
244
247
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
245
|
-
|
|
246
|
-
return indexedDbClient;
|
|
248
|
+
return turnkeyWallet.getIframeClient();
|
|
247
249
|
}
|
|
248
250
|
async getTurnkeyWallet() {
|
|
249
251
|
const { metadata } = this;
|
|
@@ -257,9 +259,21 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
257
259
|
if (!metadata.turnkey.apiServerEndpoint) {
|
|
258
260
|
throw new exceptions_1.WalletException(new Error('Turnkey apiServerEndpoint is required'));
|
|
259
261
|
}
|
|
262
|
+
if (!metadata.turnkey.defaultOrganizationId) {
|
|
263
|
+
throw new exceptions_1.WalletException(new Error('Turnkey defaultOrganizationId is required'));
|
|
264
|
+
}
|
|
260
265
|
this.turnkeyWallet = new turnkey_js_1.TurnkeyWallet(metadata.turnkey);
|
|
261
266
|
}
|
|
262
267
|
return this.turnkeyWallet;
|
|
263
268
|
}
|
|
269
|
+
async getOrganizationId() {
|
|
270
|
+
const { metadata } = this;
|
|
271
|
+
const organizationId = metadata?.turnkey?.organizationId ||
|
|
272
|
+
metadata?.turnkey?.defaultOrganizationId;
|
|
273
|
+
if (!organizationId) {
|
|
274
|
+
throw new exceptions_1.WalletException(new Error('Organization ID is required'));
|
|
275
|
+
}
|
|
276
|
+
return organizationId;
|
|
277
|
+
}
|
|
264
278
|
}
|
|
265
279
|
exports.TurnkeyWalletStrategy = TurnkeyWalletStrategy;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
2
2
|
import { type HttpRestClient } from '@injectivelabs/utils';
|
|
3
3
|
export declare class TurnkeyOauthWallet {
|
|
4
|
-
static generateOAuthNonce(
|
|
4
|
+
static generateOAuthNonce(iframeClient: TurnkeyIframeClient): Promise<string>;
|
|
5
5
|
static oauthLogin(args: {
|
|
6
6
|
oidcToken: string;
|
|
7
7
|
client: HttpRestClient;
|
|
8
8
|
oauthLoginPath?: string;
|
|
9
9
|
providerName: 'google' | 'apple';
|
|
10
|
-
|
|
10
|
+
iframeClient: TurnkeyIframeClient;
|
|
11
11
|
expirationSeconds?: number;
|
|
12
12
|
}): Promise<{
|
|
13
13
|
organizationId: string;
|
|
@@ -5,10 +5,9 @@ const exceptions_1 = require("@injectivelabs/exceptions");
|
|
|
5
5
|
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
6
6
|
const consts_js_1 = require("../consts.js");
|
|
7
7
|
class TurnkeyOauthWallet {
|
|
8
|
-
static async generateOAuthNonce(
|
|
8
|
+
static async generateOAuthNonce(iframeClient) {
|
|
9
9
|
try {
|
|
10
|
-
|
|
11
|
-
const targetPublicKey = await indexedDbClient.getPublicKey();
|
|
10
|
+
const targetPublicKey = iframeClient.iframePublicKey;
|
|
12
11
|
if (!targetPublicKey) {
|
|
13
12
|
throw new exceptions_1.WalletException(new Error('Target public key not found'));
|
|
14
13
|
}
|
|
@@ -25,10 +24,10 @@ class TurnkeyOauthWallet {
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
static async oauthLogin(args) {
|
|
28
|
-
const { client,
|
|
27
|
+
const { client, iframeClient, expirationSeconds } = args;
|
|
29
28
|
const path = args.oauthLoginPath || consts_js_1.TURNKEY_OAUTH_PATH;
|
|
30
29
|
try {
|
|
31
|
-
const targetPublicKey =
|
|
30
|
+
const targetPublicKey = iframeClient.iframePublicKey;
|
|
32
31
|
if (!targetPublicKey) {
|
|
33
32
|
throw new exceptions_1.WalletException(new Error('Target public key not found'));
|
|
34
33
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
2
2
|
import { type TurnkeyConfirmEmailOTPResponse, type TurnkeyOTPCredentialsResponse } from './../types.js';
|
|
3
3
|
import { type HttpRestClient } from '@injectivelabs/utils';
|
|
4
4
|
export declare class TurnkeyOtpWallet {
|
|
@@ -7,16 +7,15 @@ export declare class TurnkeyOtpWallet {
|
|
|
7
7
|
subOrgId?: string;
|
|
8
8
|
otpInitPath?: string;
|
|
9
9
|
client: HttpRestClient;
|
|
10
|
-
|
|
10
|
+
iframeClient: TurnkeyIframeClient;
|
|
11
11
|
invalidateExistingSessions?: boolean;
|
|
12
|
-
expirationSeconds?: number;
|
|
13
12
|
}): Promise<TurnkeyOTPCredentialsResponse | undefined>;
|
|
14
13
|
static confirmEmailOTP(args: {
|
|
15
14
|
otpCode: string;
|
|
16
15
|
emailOTPId: string;
|
|
17
16
|
client: HttpRestClient;
|
|
18
|
-
targetPublicKey: string;
|
|
19
17
|
organizationId: string;
|
|
18
|
+
iframeClient: TurnkeyIframeClient;
|
|
20
19
|
otpVerifyPath?: string;
|
|
21
20
|
expirationSeconds?: number;
|
|
22
21
|
}): Promise<TurnkeyConfirmEmailOTPResponse | undefined>;
|
|
@@ -5,21 +5,18 @@ const exceptions_1 = require("@injectivelabs/exceptions");
|
|
|
5
5
|
const consts_js_1 = require("../consts.js");
|
|
6
6
|
class TurnkeyOtpWallet {
|
|
7
7
|
static async initEmailOTP(args) {
|
|
8
|
-
const { client,
|
|
8
|
+
const { client, iframeClient } = args;
|
|
9
9
|
try {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new exceptions_1.WalletException(new Error('Public key not found'));
|
|
10
|
+
const targetPublicKey = iframeClient.iframePublicKey;
|
|
11
|
+
if (!targetPublicKey) {
|
|
12
|
+
throw new exceptions_1.WalletException(new Error('Target public key not found'));
|
|
14
13
|
}
|
|
15
14
|
// client.$post is undefined, resorting to this for now
|
|
16
15
|
const response = await client.post(args.otpInitPath || consts_js_1.TURNKEY_OTP_INIT_PATH, {
|
|
17
|
-
targetPublicKey
|
|
16
|
+
targetPublicKey,
|
|
18
17
|
email: args.email,
|
|
19
18
|
suborgId: args.subOrgId,
|
|
20
19
|
invalidateExistingSessions: args.invalidateExistingSessions,
|
|
21
|
-
isUsingIndexedDB: true,
|
|
22
|
-
expirationSeconds: expirationSeconds || consts_js_1.DEFAULT_TURNKEY_REFRESH_SECONDS,
|
|
23
20
|
});
|
|
24
21
|
return response?.data;
|
|
25
22
|
}
|
|
@@ -32,11 +29,15 @@ class TurnkeyOtpWallet {
|
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
static async confirmEmailOTP(args) {
|
|
35
|
-
const { client,
|
|
32
|
+
const { client, iframeClient, expirationSeconds } = args;
|
|
36
33
|
try {
|
|
37
34
|
const organizationId = args.organizationId;
|
|
38
35
|
const emailOTPId = args.emailOTPId;
|
|
36
|
+
const targetPublicKey = iframeClient.iframePublicKey;
|
|
39
37
|
const otpVerifyPath = args.otpVerifyPath || consts_js_1.TURNKEY_OTP_VERIFY_PATH;
|
|
38
|
+
if (!targetPublicKey) {
|
|
39
|
+
throw new exceptions_1.WalletException(new Error('Target public key not found'));
|
|
40
|
+
}
|
|
40
41
|
if (!emailOTPId) {
|
|
41
42
|
throw new exceptions_1.WalletException(new Error('Email OTP ID is required'));
|
|
42
43
|
}
|
|
@@ -44,7 +45,6 @@ class TurnkeyOtpWallet {
|
|
|
44
45
|
throw new exceptions_1.WalletException(new Error('Organization ID is required'));
|
|
45
46
|
}
|
|
46
47
|
const response = await client.post(otpVerifyPath, {
|
|
47
|
-
isUsingIndexedDB: true,
|
|
48
48
|
targetPublicKey,
|
|
49
49
|
otpId: emailOTPId,
|
|
50
50
|
otpCode: args.otpCode,
|
|
@@ -1,33 +1,37 @@
|
|
|
1
1
|
import { TurnkeyMetadata, TurnkeyProvider } from '@injectivelabs/wallet-base';
|
|
2
2
|
import { createAccount } from '@turnkey/viem';
|
|
3
3
|
import { HttpRestClient } from '@injectivelabs/utils';
|
|
4
|
-
import { Turnkey,
|
|
4
|
+
import { Turnkey, TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
5
5
|
export declare class TurnkeyWallet {
|
|
6
6
|
private otpId?;
|
|
7
7
|
protected turnkey?: Turnkey;
|
|
8
|
-
|
|
8
|
+
organizationId: string;
|
|
9
9
|
protected client: HttpRestClient;
|
|
10
10
|
private metadata;
|
|
11
|
-
protected
|
|
11
|
+
protected iframeClient?: TurnkeyIframeClient;
|
|
12
12
|
private accountMap;
|
|
13
13
|
setMetadata(metadata: Partial<TurnkeyMetadata>): void;
|
|
14
14
|
constructor(metadata: TurnkeyMetadata);
|
|
15
15
|
static getTurnkeyInstance(metadata: TurnkeyMetadata): Promise<{
|
|
16
16
|
turnkey: Turnkey;
|
|
17
|
-
|
|
17
|
+
iframeClient: TurnkeyIframeClient;
|
|
18
18
|
}>;
|
|
19
19
|
getTurnkey(): Promise<Turnkey>;
|
|
20
|
-
|
|
20
|
+
getIframeClient(): Promise<TurnkeyIframeClient>;
|
|
21
21
|
getSession(existingCredentialBundle?: string): Promise<{
|
|
22
|
-
session: import("@turnkey/sdk-
|
|
22
|
+
session: import("@turnkey/sdk-types").Session | undefined;
|
|
23
23
|
organizationId: string;
|
|
24
24
|
}>;
|
|
25
25
|
getAccounts(): Promise<string[]>;
|
|
26
|
-
getOrCreateAndGetAccount(address: string): Promise<ReturnType<typeof createAccount>>;
|
|
26
|
+
getOrCreateAndGetAccount(address: string, organizationId: string): Promise<ReturnType<typeof createAccount>>;
|
|
27
|
+
injectAndRefresh(credentialBundle: string, options: {
|
|
28
|
+
expirationSeconds?: string;
|
|
29
|
+
organizationId?: string;
|
|
30
|
+
}): Promise<void>;
|
|
27
31
|
initOTP(email: string): Promise<import("../types.js").TurnkeyOTPCredentialsResponse>;
|
|
28
32
|
confirmOTP(otpCode: string): Promise<import("../types.js").TurnkeyConfirmEmailOTPResponse>;
|
|
29
33
|
initOAuth(provider: TurnkeyProvider.Google | TurnkeyProvider.Apple): Promise<string>;
|
|
30
34
|
confirmOAuth(provider: TurnkeyProvider.Google | TurnkeyProvider.Apple, oidcToken: string): Promise<string>;
|
|
31
35
|
refreshSession(): Promise<string>;
|
|
32
|
-
private
|
|
36
|
+
private initFrame;
|
|
33
37
|
}
|