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