@injectivelabs/wallet-turnkey 1.15.18 → 1.15.20

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.
@@ -6,9 +6,9 @@ export declare class TurnkeyOauthWallet {
6
6
  oidcToken: string;
7
7
  client: HttpRestClient;
8
8
  oauthLoginPath?: string;
9
- expirationSeconds?: number;
10
9
  providerName: 'google' | 'apple';
11
10
  iframeClient: TurnkeyIframeClient;
11
+ expirationSeconds?: number;
12
12
  }): Promise<{
13
13
  organizationId: string;
14
14
  credentialBundle: string;
@@ -24,7 +24,7 @@ class TurnkeyOauthWallet {
24
24
  }
25
25
  }
26
26
  static async oauthLogin(args) {
27
- const { client, iframeClient } = args;
27
+ const { client, iframeClient, expirationSeconds } = args;
28
28
  const path = args.oauthLoginPath || consts_js_1.TURNKEY_OAUTH_PATH;
29
29
  try {
30
30
  const targetPublicKey = iframeClient.iframePublicKey;
@@ -36,6 +36,7 @@ class TurnkeyOauthWallet {
36
36
  targetPublicKey,
37
37
  oidcToken: args.oidcToken,
38
38
  providerName: args.providerName,
39
+ expirationSeconds: (expirationSeconds || consts_js_1.DEFAULT_TURNKEY_REFRESH_SECONDS)?.toString(),
39
40
  });
40
41
  return response.data;
41
42
  }
@@ -17,5 +17,6 @@ export declare class TurnkeyOtpWallet {
17
17
  organizationId: string;
18
18
  iframeClient: TurnkeyIframeClient;
19
19
  otpVerifyPath?: string;
20
+ expirationSeconds?: number;
20
21
  }): Promise<TurnkeyConfirmEmailOTPResponse | undefined>;
21
22
  }
@@ -29,7 +29,7 @@ class TurnkeyOtpWallet {
29
29
  }
30
30
  }
31
31
  static async confirmEmailOTP(args) {
32
- const { client, iframeClient } = args;
32
+ const { client, iframeClient, expirationSeconds } = args;
33
33
  try {
34
34
  const organizationId = args.organizationId;
35
35
  const emailOTPId = args.emailOTPId;
@@ -49,6 +49,7 @@ class TurnkeyOtpWallet {
49
49
  otpId: emailOTPId,
50
50
  otpCode: args.otpCode,
51
51
  suborgID: organizationId,
52
+ expirationSeconds: (expirationSeconds || consts_js_1.DEFAULT_TURNKEY_REFRESH_SECONDS)?.toString(),
52
53
  });
53
54
  return response?.data;
54
55
  }
@@ -162,23 +162,19 @@ class TurnkeyWallet {
162
162
  await iframeClient.injectCredentialBundle(credentialBundle);
163
163
  await iframeClient.refreshSession({
164
164
  sessionType: sdk_browser_1.SessionType.READ_WRITE,
165
- expirationSeconds: options.expirationSeconds,
166
165
  targetPublicKey: iframeClient.iframePublicKey,
166
+ expirationSeconds,
167
167
  });
168
- // If we just logged in, we have the new org ID here and don't need to wait on getSession method
169
- if (options.organizationId) {
170
- this.organizationId = options.organizationId;
171
- this.metadata.organizationId = options.organizationId;
172
- }
173
- else {
174
- const session = await this.getSession();
175
- this.organizationId = session.organizationId;
176
- this.metadata.organizationId = session.organizationId;
168
+ const session = await this.turnkey?.getSession();
169
+ if (!session) {
170
+ throw new exceptions_1.WalletException(new Error('Failed to refresh session'));
177
171
  }
172
+ this.organizationId = session.organizationId;
173
+ this.metadata.organizationId = session.organizationId;
178
174
  // Refresh the session 2 minutes before it expires
179
175
  setTimeout(() => {
180
176
  iframeClient.refreshSession({
181
- expirationSeconds,
177
+ expirationSeconds: session?.expiry,
182
178
  sessionType: sdk_browser_1.SessionType.READ_WRITE,
183
179
  targetPublicKey: iframeClient.iframePublicKey,
184
180
  });
@@ -264,7 +260,7 @@ class TurnkeyWallet {
264
260
  const session = await this.getSession();
265
261
  if (session.session?.token) {
266
262
  await this.injectAndRefresh(session.session.token, {
267
- expirationSeconds: this.metadata.expirationSeconds,
263
+ expirationSeconds: this.metadata.expirationSeconds || consts_js_1.DEFAULT_TURNKEY_REFRESH_SECONDS,
268
264
  });
269
265
  return session.session.token;
270
266
  }
@@ -6,9 +6,9 @@ export declare class TurnkeyOauthWallet {
6
6
  oidcToken: string;
7
7
  client: HttpRestClient;
8
8
  oauthLoginPath?: string;
9
- expirationSeconds?: number;
10
9
  providerName: 'google' | 'apple';
11
10
  iframeClient: TurnkeyIframeClient;
11
+ expirationSeconds?: number;
12
12
  }): Promise<{
13
13
  organizationId: string;
14
14
  credentialBundle: string;
@@ -1,6 +1,6 @@
1
1
  import { ErrorType, WalletException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions';
2
2
  import { sha256 } from '@injectivelabs/sdk-ts';
3
- import { TURNKEY_OAUTH_PATH } from '../consts.js';
3
+ import { DEFAULT_TURNKEY_REFRESH_SECONDS, TURNKEY_OAUTH_PATH, } from '../consts.js';
4
4
  export class TurnkeyOauthWallet {
5
5
  static async generateOAuthNonce(iframeClient) {
6
6
  try {
@@ -21,7 +21,7 @@ export class TurnkeyOauthWallet {
21
21
  }
22
22
  }
23
23
  static async oauthLogin(args) {
24
- const { client, iframeClient } = args;
24
+ const { client, iframeClient, expirationSeconds } = args;
25
25
  const path = args.oauthLoginPath || TURNKEY_OAUTH_PATH;
26
26
  try {
27
27
  const targetPublicKey = iframeClient.iframePublicKey;
@@ -33,6 +33,7 @@ export class TurnkeyOauthWallet {
33
33
  targetPublicKey,
34
34
  oidcToken: args.oidcToken,
35
35
  providerName: args.providerName,
36
+ expirationSeconds: (expirationSeconds || DEFAULT_TURNKEY_REFRESH_SECONDS)?.toString(),
36
37
  });
37
38
  return response.data;
38
39
  }
@@ -17,5 +17,6 @@ export declare class TurnkeyOtpWallet {
17
17
  organizationId: string;
18
18
  iframeClient: TurnkeyIframeClient;
19
19
  otpVerifyPath?: string;
20
+ expirationSeconds?: number;
20
21
  }): Promise<TurnkeyConfirmEmailOTPResponse | undefined>;
21
22
  }
@@ -1,5 +1,5 @@
1
1
  import { ErrorType, WalletException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions';
2
- import { TURNKEY_OTP_INIT_PATH, TURNKEY_OTP_VERIFY_PATH } from '../consts.js';
2
+ import { DEFAULT_TURNKEY_REFRESH_SECONDS, TURNKEY_OTP_INIT_PATH, TURNKEY_OTP_VERIFY_PATH, } from '../consts.js';
3
3
  export class TurnkeyOtpWallet {
4
4
  static async initEmailOTP(args) {
5
5
  const { client, iframeClient } = args;
@@ -26,7 +26,7 @@ export class TurnkeyOtpWallet {
26
26
  }
27
27
  }
28
28
  static async confirmEmailOTP(args) {
29
- const { client, iframeClient } = args;
29
+ const { client, iframeClient, expirationSeconds } = args;
30
30
  try {
31
31
  const organizationId = args.organizationId;
32
32
  const emailOTPId = args.emailOTPId;
@@ -46,6 +46,7 @@ export class TurnkeyOtpWallet {
46
46
  otpId: emailOTPId,
47
47
  otpCode: args.otpCode,
48
48
  suborgID: organizationId,
49
+ expirationSeconds: (expirationSeconds || DEFAULT_TURNKEY_REFRESH_SECONDS)?.toString(),
49
50
  });
50
51
  return response?.data;
51
52
  }
@@ -159,23 +159,19 @@ export class TurnkeyWallet {
159
159
  await iframeClient.injectCredentialBundle(credentialBundle);
160
160
  await iframeClient.refreshSession({
161
161
  sessionType: SessionType.READ_WRITE,
162
- expirationSeconds: options.expirationSeconds,
163
162
  targetPublicKey: iframeClient.iframePublicKey,
163
+ expirationSeconds,
164
164
  });
165
- // If we just logged in, we have the new org ID here and don't need to wait on getSession method
166
- if (options.organizationId) {
167
- this.organizationId = options.organizationId;
168
- this.metadata.organizationId = options.organizationId;
169
- }
170
- else {
171
- const session = await this.getSession();
172
- this.organizationId = session.organizationId;
173
- this.metadata.organizationId = session.organizationId;
165
+ const session = await this.turnkey?.getSession();
166
+ if (!session) {
167
+ throw new WalletException(new Error('Failed to refresh session'));
174
168
  }
169
+ this.organizationId = session.organizationId;
170
+ this.metadata.organizationId = session.organizationId;
175
171
  // Refresh the session 2 minutes before it expires
176
172
  setTimeout(() => {
177
173
  iframeClient.refreshSession({
178
- expirationSeconds,
174
+ expirationSeconds: session?.expiry,
179
175
  sessionType: SessionType.READ_WRITE,
180
176
  targetPublicKey: iframeClient.iframePublicKey,
181
177
  });
@@ -261,7 +257,7 @@ export class TurnkeyWallet {
261
257
  const session = await this.getSession();
262
258
  if (session.session?.token) {
263
259
  await this.injectAndRefresh(session.session.token, {
264
- expirationSeconds: this.metadata.expirationSeconds,
260
+ expirationSeconds: this.metadata.expirationSeconds || DEFAULT_TURNKEY_REFRESH_SECONDS,
265
261
  });
266
262
  return session.session.token;
267
263
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-turnkey",
3
3
  "description": "Turnkey wallet strategy for use with @injectivelabs/wallet-core.",
4
- "version": "1.15.18",
4
+ "version": "1.15.20",
5
5
  "sideEffects": false,
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -59,11 +59,11 @@
59
59
  "start": "node dist/index.js"
60
60
  },
61
61
  "dependencies": {
62
- "@injectivelabs/exceptions": "^1.15.15",
63
- "@injectivelabs/sdk-ts": "^1.15.18",
64
- "@injectivelabs/ts-types": "^1.15.16",
65
- "@injectivelabs/utils": "^1.15.16",
66
- "@injectivelabs/wallet-base": "^1.15.18",
62
+ "@injectivelabs/exceptions": "^1.15.17",
63
+ "@injectivelabs/sdk-ts": "^1.15.20",
64
+ "@injectivelabs/ts-types": "^1.15.18",
65
+ "@injectivelabs/utils": "^1.15.18",
66
+ "@injectivelabs/wallet-base": "^1.15.20",
67
67
  "@turnkey/sdk-browser": "^4.1.0",
68
68
  "@turnkey/viem": "^0.9.0",
69
69
  "viem": "^2.28.1"
@@ -77,5 +77,5 @@
77
77
  "tsconfig-paths": "^4.2.0",
78
78
  "typescript": "^5.0.0"
79
79
  },
80
- "gitHead": "f27adbec3b9a84e4af2c2fbf5dbcac802b254130"
80
+ "gitHead": "a80d42fd4220e1e9a6d0e8b211dcd229f84dd54e"
81
81
  }