@turnkey/react-wallet-kit 1.0.0-beta.5 → 1.0.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 +5 -2
- package/dist/_virtual/_rollupPluginBabelHelpers.mjs +49 -1
- package/dist/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -1
- package/dist/components/auth/Email.d.ts.map +1 -1
- package/dist/components/auth/Email.js +3 -0
- package/dist/components/auth/Email.js.map +1 -1
- package/dist/components/auth/Email.mjs +3 -0
- package/dist/components/auth/Email.mjs.map +1 -1
- package/dist/components/auth/OAuth.d.ts.map +1 -1
- package/dist/components/auth/OAuth.js +1 -0
- package/dist/components/auth/OAuth.js.map +1 -1
- package/dist/components/auth/OAuth.mjs +1 -0
- package/dist/components/auth/OAuth.mjs.map +1 -1
- package/dist/components/auth/OTP.d.ts +1 -0
- package/dist/components/auth/OTP.d.ts.map +1 -1
- package/dist/components/auth/OTP.js +5 -1
- package/dist/components/auth/OTP.js.map +1 -1
- package/dist/components/auth/OTP.mjs +6 -3
- package/dist/components/auth/OTP.mjs.map +1 -1
- package/dist/components/auth/Passkey.d.ts.map +1 -1
- package/dist/components/auth/Passkey.js +2 -0
- package/dist/components/auth/Passkey.js.map +1 -1
- package/dist/components/auth/Passkey.mjs +2 -0
- package/dist/components/auth/Passkey.mjs.map +1 -1
- package/dist/components/auth/Wallet.d.ts +4 -4
- package/dist/components/auth/Wallet.d.ts.map +1 -1
- package/dist/components/auth/Wallet.js +72 -50
- package/dist/components/auth/Wallet.js.map +1 -1
- package/dist/components/auth/Wallet.mjs +78 -57
- package/dist/components/auth/Wallet.mjs.map +1 -1
- package/dist/components/auth/index.d.ts +5 -1
- package/dist/components/auth/index.d.ts.map +1 -1
- package/dist/components/auth/index.js +100 -14
- package/dist/components/auth/index.js.map +1 -1
- package/dist/components/auth/index.mjs +187 -84
- package/dist/components/auth/index.mjs.map +1 -1
- package/dist/components/design/Buttons.d.ts +2 -0
- package/dist/components/design/Buttons.d.ts.map +1 -1
- package/dist/components/design/Buttons.js +8 -2
- package/dist/components/design/Buttons.js.map +1 -1
- package/dist/components/design/Buttons.mjs +9 -3
- package/dist/components/design/Buttons.mjs.map +1 -1
- package/dist/components/export/Export.d.ts +2 -1
- package/dist/components/export/Export.d.ts.map +1 -1
- package/dist/components/export/Export.js +8 -6
- package/dist/components/export/Export.js.map +1 -1
- package/dist/components/export/Export.mjs +8 -6
- package/dist/components/export/Export.mjs.map +1 -1
- package/dist/components/export/ExportWarning.d.ts +2 -1
- package/dist/components/export/ExportWarning.d.ts.map +1 -1
- package/dist/components/export/ExportWarning.js +4 -2
- package/dist/components/export/ExportWarning.js.map +1 -1
- package/dist/components/export/ExportWarning.mjs +4 -2
- package/dist/components/export/ExportWarning.mjs.map +1 -1
- package/dist/components/import/Import.d.ts +7 -3
- package/dist/components/import/Import.d.ts.map +1 -1
- package/dist/components/import/Import.js +77 -37
- package/dist/components/import/Import.js.map +1 -1
- package/dist/components/import/Import.mjs +120 -55
- package/dist/components/import/Import.mjs.map +1 -1
- package/dist/components/sign/Message.d.ts.map +1 -1
- package/dist/components/sign/Message.js +1 -0
- package/dist/components/sign/Message.js.map +1 -1
- package/dist/components/sign/Message.mjs +1 -0
- package/dist/components/sign/Message.mjs.map +1 -1
- package/dist/components/user/ConnectWallet.d.ts +8 -0
- package/dist/components/user/ConnectWallet.d.ts.map +1 -0
- package/dist/components/user/{LinkWallet.js → ConnectWallet.js} +18 -18
- package/dist/components/user/ConnectWallet.js.map +1 -0
- package/dist/components/user/{LinkWallet.mjs → ConnectWallet.mjs} +25 -25
- package/dist/components/user/ConnectWallet.mjs.map +1 -0
- package/dist/components/user/RemovePasskey.d.ts.map +1 -1
- package/dist/components/user/RemovePasskey.js +1 -0
- package/dist/components/user/RemovePasskey.js.map +1 -1
- package/dist/components/user/RemovePasskey.mjs +1 -0
- package/dist/components/user/RemovePasskey.mjs.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/client/Provider.d.ts +3 -3
- package/dist/providers/client/Provider.d.ts.map +1 -1
- package/dist/providers/client/Provider.js +760 -149
- package/dist/providers/client/Provider.js.map +1 -1
- package/dist/providers/client/Provider.mjs +2474 -1624
- package/dist/providers/client/Provider.mjs.map +1 -1
- package/dist/providers/client/Types.d.ts +116 -11
- package/dist/providers/client/Types.d.ts.map +1 -1
- package/dist/providers/client/Types.js.map +1 -1
- package/dist/providers/client/Types.mjs.map +1 -1
- package/dist/providers/modal/Provider.js +1 -1
- package/dist/providers/modal/Provider.mjs +1 -1
- package/dist/styles.css +1 -1
- package/dist/tests/timers-test.d.ts +2 -0
- package/dist/tests/timers-test.d.ts.map +1 -0
- package/dist/tests/utils-test.d.ts +2 -0
- package/dist/tests/utils-test.d.ts.map +1 -0
- package/dist/types/base.d.ts +31 -3
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/base.js +23 -0
- package/dist/types/base.js.map +1 -1
- package/dist/types/base.mjs +19 -1
- package/dist/types/base.mjs.map +1 -1
- package/dist/utils/timers.d.ts +73 -0
- package/dist/utils/timers.d.ts.map +1 -0
- package/dist/utils/timers.js +133 -0
- package/dist/utils/timers.js.map +1 -0
- package/dist/utils/timers.mjs +142 -0
- package/dist/utils/timers.mjs.map +1 -0
- package/dist/{utils.d.ts → utils/utils.d.ts} +8 -3
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/{utils.js → utils/utils.js} +12 -3
- package/dist/utils/utils.js.map +1 -0
- package/dist/{utils.mjs → utils/utils.mjs} +12 -5
- package/dist/utils/utils.mjs.map +1 -0
- package/package.json +6 -5
- package/dist/components/user/LinkWallet.d.ts +0 -8
- package/dist/components/user/LinkWallet.d.ts.map +0 -1
- package/dist/components/user/LinkWallet.js.map +0 -1
- package/dist/components/user/LinkWallet.mjs.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
- package/dist/utils.mjs.map +0 -1
package/dist/types/base.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { KeyFormat } from '@turnkey/iframe-stamper';
|
|
2
|
+
|
|
1
3
|
/**@internal */
|
|
2
4
|
var ExportType;
|
|
3
5
|
(function (ExportType) {
|
|
@@ -5,6 +7,12 @@ var ExportType;
|
|
|
5
7
|
ExportType["PrivateKey"] = "PRIVATE_KEY";
|
|
6
8
|
ExportType["WalletAccount"] = "WALLET_ACCOUNT";
|
|
7
9
|
})(ExportType || (ExportType = {}));
|
|
10
|
+
/**@internal */
|
|
11
|
+
var ImportType;
|
|
12
|
+
(function (ImportType) {
|
|
13
|
+
ImportType["Wallet"] = "WALLET";
|
|
14
|
+
ImportType["PrivateKey"] = "PRIVATE_KEY";
|
|
15
|
+
})(ImportType || (ImportType = {}));
|
|
8
16
|
/**
|
|
9
17
|
* Enum representing the authentication states of the user.
|
|
10
18
|
* - Unauthenticated: The user is not authenticated.
|
|
@@ -27,6 +35,16 @@ var ClientState;
|
|
|
27
35
|
ClientState["Ready"] = "ready";
|
|
28
36
|
ClientState["Error"] = "error";
|
|
29
37
|
})(ClientState || (ClientState = {}));
|
|
38
|
+
/**
|
|
39
|
+
* Enum representing the authentication methods.
|
|
40
|
+
*/
|
|
41
|
+
var AuthMethod;
|
|
42
|
+
(function (AuthMethod) {
|
|
43
|
+
AuthMethod["Otp"] = "otp";
|
|
44
|
+
AuthMethod["Passkey"] = "passkey";
|
|
45
|
+
AuthMethod["Wallet"] = "wallet";
|
|
46
|
+
AuthMethod["Oauth"] = "oauth";
|
|
47
|
+
})(AuthMethod || (AuthMethod = {}));
|
|
30
48
|
|
|
31
|
-
export { AuthState, ClientState, ExportType };
|
|
49
|
+
export { AuthMethod, AuthState, ClientState, ExportType, ImportType };
|
|
32
50
|
//# sourceMappingURL=base.mjs.map
|
package/dist/types/base.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.mjs","sources":["../../src/types/base.ts"],"sourcesContent":[null],"names":["ExportType","AuthState","ClientState"],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.mjs","sources":["../../src/types/base.ts"],"sourcesContent":[null],"names":["ExportType","ImportType","AuthState","ClientState","AuthMethod"],"mappings":";;AA0HA;IACYA;AAAZ,CAAA,UAAYA,UAAU,EAAA;AACpBA,EAAAA,UAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACjBA,EAAAA,UAAA,CAAA,YAAA,CAAA,GAAA,aAA0B;AAC1BA,EAAAA,UAAA,CAAA,eAAA,CAAA,GAAA,gBAAgC;AAClC,CAAC,EAJWA,UAAU,KAAVA,UAAU,GAIrB,EAAA,CAAA,CAAA;AAED;IACYC;AAAZ,CAAA,UAAYA,UAAU,EAAA;AACpBA,EAAAA,UAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACjBA,EAAAA,UAAA,CAAA,YAAA,CAAA,GAAA,aAA0B;AAC5B,CAAC,EAHWA,UAAU,KAAVA,UAAU,GAGrB,EAAA,CAAA,CAAA;AAID;;;;AAIG;IACSC;AAAZ,CAAA,UAAYA,SAAS,EAAA;AACnBA,EAAAA,SAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC;AACnCA,EAAAA,SAAA,CAAA,eAAA,CAAA,GAAA,eAA+B;AACjC,CAAC,EAHWA,SAAS,KAATA,SAAS,GAGpB,EAAA,CAAA,CAAA;AAED;;;;;AAKG;IACSC;AAAZ,CAAA,UAAYA,WAAW,EAAA;AACrBA,EAAAA,WAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnBA,EAAAA,WAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACfA,EAAAA,WAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACjB,CAAC,EAJWA,WAAW,KAAXA,WAAW,GAItB,EAAA,CAAA,CAAA;AASD;;AAEG;IACSC;AAAZ,CAAA,UAAYA,UAAU,EAAA;AACpBA,EAAAA,UAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACXA,EAAAA,UAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnBA,EAAAA,UAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACjBA,EAAAA,UAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACjB,CAAC,EALWA,UAAU,KAAVA,UAAU,GAKrB,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type TimerController = {
|
|
2
|
+
clear: () => void;
|
|
3
|
+
};
|
|
4
|
+
export type TimerMap = Record<string, TimerController>;
|
|
5
|
+
export declare const MAX_DELAY_MS = 2147483647;
|
|
6
|
+
/**
|
|
7
|
+
* @internal A drop-in replacement for `setTimeout` that supports arbitrarily long delays.
|
|
8
|
+
*
|
|
9
|
+
* ### Why?
|
|
10
|
+
* Browsers clamp `setTimeout` delays to a 32-bit signed integer,
|
|
11
|
+
* i.e. a maximum of ~24.8 days (`2_147_483_647ms`). Any larger value
|
|
12
|
+
* will fire almost immediately. This helper safely schedules timeouts
|
|
13
|
+
* that can be months or years into the future.
|
|
14
|
+
*
|
|
15
|
+
* ### How it works
|
|
16
|
+
* - On call, we record a fixed **target timestamp** (`now + delayMs`).
|
|
17
|
+
* - We schedule a single "leg" of at most ~24.8 days into the future,
|
|
18
|
+
* with an internal `tick` function as the callback.
|
|
19
|
+
* - When a leg expires, `tick` checks how much time is left:
|
|
20
|
+
* - If `remaining > 0`, it schedules the next leg (`min(MAX_DELAY_MS, remaining)`).
|
|
21
|
+
* - If `remaining <= 0`, the full delay has passed and we finally call your `cb()`.
|
|
22
|
+
* - At any time, only **one** leg is active. Calling `.clear()` cancels
|
|
23
|
+
* the current leg and prevents further hops.
|
|
24
|
+
*
|
|
25
|
+
* ### Benefits
|
|
26
|
+
* - Works seamlessly for both short and very long delays.
|
|
27
|
+
* - Survives tab sleep / system suspend: when the tab wakes,
|
|
28
|
+
* `tick` re-checks the target timestamp and fires immediately if overdue.
|
|
29
|
+
* - No drift accumulation: each hop recalculates based on the fixed target,
|
|
30
|
+
* so you always land as close as possible to the intended deadline.
|
|
31
|
+
*
|
|
32
|
+
* ### Example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const controller = setCappedTimeout(() => {
|
|
35
|
+
* console.log("A whole year later!");
|
|
36
|
+
* }, 1000 * 60 * 60 * 24 * 365);
|
|
37
|
+
*
|
|
38
|
+
* // Cancel if needed
|
|
39
|
+
* controller.clear();
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param cb - Function to run once the full delay has elapsed.
|
|
43
|
+
* @param delayMs - Delay in milliseconds (can exceed 2_147_483_647).
|
|
44
|
+
* @returns A controller with a `.clear()` method to cancel the timeout.
|
|
45
|
+
*/
|
|
46
|
+
export declare function setCappedTimeout(cb: () => void, delayMs: number): TimerController;
|
|
47
|
+
/** @internal Simple one-shot timeout that still returns a controller for uniformity. */
|
|
48
|
+
export declare function setTimeoutController(cb: () => void, delayMs: number): TimerController;
|
|
49
|
+
/** @internal Replace any existing timer for `key` with `controller`. */
|
|
50
|
+
export declare function putTimer(map: TimerMap, key: string, controller: TimerController): void;
|
|
51
|
+
/** @internal Clear a specific key (noop if missing). */
|
|
52
|
+
export declare function clearKey(map: TimerMap, key: string): void;
|
|
53
|
+
/** @internal Clear several keys at once (noop on missing). */
|
|
54
|
+
export declare function clearKeys(map: TimerMap, keys: string[]): void;
|
|
55
|
+
/** @internal Clear all timers in the map. */
|
|
56
|
+
export declare function clearAll(map: TimerMap): void;
|
|
57
|
+
/**
|
|
58
|
+
* @internal Convenience: set a capped timeout directly into the map for `key`.
|
|
59
|
+
* @param map The map to store the timer in (pass in the ref to the timer map)
|
|
60
|
+
* @param key The key to associate with the timer
|
|
61
|
+
* @param cb The callback to invoke when the timer expires
|
|
62
|
+
* @param delayMs The delay in milliseconds before the timer expires
|
|
63
|
+
* */
|
|
64
|
+
export declare function setCappedTimeoutInMap(map: TimerMap, key: string, cb: () => void, delayMs: number): void;
|
|
65
|
+
/**
|
|
66
|
+
* @internal Convenience: set a regular (short) timeout into the map for `key`.
|
|
67
|
+
* @param map The map to store the timer in (pass in the ref to the timer map)
|
|
68
|
+
* @param key The key to associate with the timer
|
|
69
|
+
* @param cb The callback to invoke when the timer expires
|
|
70
|
+
* @param delayMs The delay in milliseconds before the timer expires
|
|
71
|
+
*/
|
|
72
|
+
export declare function setTimeoutInMap(map: TimerMap, key: string, cb: () => void, delayMs: number): void;
|
|
73
|
+
//# sourceMappingURL=timers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timers.d.ts","sourceRoot":"","sources":["../../src/utils/timers.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,IAAI,CAAA;CAAE,CAAC;AACpD,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAEvD,eAAO,MAAM,YAAY,aAAgB,CAAC;AAO1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,MAAM,IAAI,EACd,OAAO,EAAE,MAAM,GACd,eAAe,CAuBjB;AAED,wFAAwF;AACxF,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,MAAM,IAAI,EACd,OAAO,EAAE,MAAM,GACd,eAAe,CAIjB;AAED,wEAAwE;AACxE,wBAAgB,QAAQ,CACtB,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,eAAe,QAI5B;AAED,wDAAwD;AACxD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,QAGlD;AAED,8DAA8D;AAC9D,wBAAgB,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,QAEtD;AAED,6CAA6C;AAC7C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,QAKrC;AAED;;;;;;KAMK;AACL,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,IAAI,EACd,OAAO,EAAE,MAAM,QAGhB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,IAAI,EACd,OAAO,EAAE,MAAM,QAGhB"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// This file contains utility functions for managing timers and timeouts for session management.
|
|
4
|
+
// Unfortunately, the delay param in Node Timeouts is a 32-bit signed integer, meaning it can only represent delays up to ~24.8 days.
|
|
5
|
+
// This file provides functions to handle long delays by breaking them into smaller chunks.
|
|
6
|
+
// These functions are separate from the normal utils function to reduce clutter and improve visibility.
|
|
7
|
+
// Use `setTimeoutInMap` for short, frequent nudges (10s), and `setCappedTimeoutInMap` for anything that could exceed ~24.8 days.
|
|
8
|
+
const MAX_DELAY_MS = 2_147_483_647; // ~24.8 days
|
|
9
|
+
/** @internal */
|
|
10
|
+
function toIntMs(x) {
|
|
11
|
+
return Math.max(0, Math.floor(Number.isFinite(x) ? x : 0));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @internal A drop-in replacement for `setTimeout` that supports arbitrarily long delays.
|
|
15
|
+
*
|
|
16
|
+
* ### Why?
|
|
17
|
+
* Browsers clamp `setTimeout` delays to a 32-bit signed integer,
|
|
18
|
+
* i.e. a maximum of ~24.8 days (`2_147_483_647ms`). Any larger value
|
|
19
|
+
* will fire almost immediately. This helper safely schedules timeouts
|
|
20
|
+
* that can be months or years into the future.
|
|
21
|
+
*
|
|
22
|
+
* ### How it works
|
|
23
|
+
* - On call, we record a fixed **target timestamp** (`now + delayMs`).
|
|
24
|
+
* - We schedule a single "leg" of at most ~24.8 days into the future,
|
|
25
|
+
* with an internal `tick` function as the callback.
|
|
26
|
+
* - When a leg expires, `tick` checks how much time is left:
|
|
27
|
+
* - If `remaining > 0`, it schedules the next leg (`min(MAX_DELAY_MS, remaining)`).
|
|
28
|
+
* - If `remaining <= 0`, the full delay has passed and we finally call your `cb()`.
|
|
29
|
+
* - At any time, only **one** leg is active. Calling `.clear()` cancels
|
|
30
|
+
* the current leg and prevents further hops.
|
|
31
|
+
*
|
|
32
|
+
* ### Benefits
|
|
33
|
+
* - Works seamlessly for both short and very long delays.
|
|
34
|
+
* - Survives tab sleep / system suspend: when the tab wakes,
|
|
35
|
+
* `tick` re-checks the target timestamp and fires immediately if overdue.
|
|
36
|
+
* - No drift accumulation: each hop recalculates based on the fixed target,
|
|
37
|
+
* so you always land as close as possible to the intended deadline.
|
|
38
|
+
*
|
|
39
|
+
* ### Example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const controller = setCappedTimeout(() => {
|
|
42
|
+
* console.log("A whole year later!");
|
|
43
|
+
* }, 1000 * 60 * 60 * 24 * 365);
|
|
44
|
+
*
|
|
45
|
+
* // Cancel if needed
|
|
46
|
+
* controller.clear();
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param cb - Function to run once the full delay has elapsed.
|
|
50
|
+
* @param delayMs - Delay in milliseconds (can exceed 2_147_483_647).
|
|
51
|
+
* @returns A controller with a `.clear()` method to cancel the timeout.
|
|
52
|
+
*/
|
|
53
|
+
function setCappedTimeout(cb, delayMs) {
|
|
54
|
+
const target = Date.now() + toIntMs(delayMs);
|
|
55
|
+
let handle;
|
|
56
|
+
const tick = () => {
|
|
57
|
+
const remaining = target - Date.now();
|
|
58
|
+
if (remaining <= 0) {
|
|
59
|
+
cb();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
handle = window.setTimeout(tick, Math.min(MAX_DELAY_MS, remaining));
|
|
63
|
+
};
|
|
64
|
+
tick();
|
|
65
|
+
return {
|
|
66
|
+
clear() {
|
|
67
|
+
if (handle !== undefined) {
|
|
68
|
+
window.clearTimeout(handle);
|
|
69
|
+
handle = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** @internal Simple one-shot timeout that still returns a controller for uniformity. */
|
|
75
|
+
function setTimeoutController(cb, delayMs) {
|
|
76
|
+
const ms = toIntMs(delayMs);
|
|
77
|
+
let id = window.setTimeout(cb, ms);
|
|
78
|
+
return {
|
|
79
|
+
clear: () => window.clearTimeout(id)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** @internal Replace any existing timer for `key` with `controller`. */
|
|
83
|
+
function putTimer(map, key, controller) {
|
|
84
|
+
map[key]?.clear?.();
|
|
85
|
+
map[key] = controller;
|
|
86
|
+
}
|
|
87
|
+
/** @internal Clear a specific key (noop if missing). */
|
|
88
|
+
function clearKey(map, key) {
|
|
89
|
+
map[key]?.clear?.();
|
|
90
|
+
delete map[key];
|
|
91
|
+
}
|
|
92
|
+
/** @internal Clear several keys at once (noop on missing). */
|
|
93
|
+
function clearKeys(map, keys) {
|
|
94
|
+
for (const k of keys) clearKey(map, k);
|
|
95
|
+
}
|
|
96
|
+
/** @internal Clear all timers in the map. */
|
|
97
|
+
function clearAll(map) {
|
|
98
|
+
for (const k of Object.keys(map)) {
|
|
99
|
+
map[k]?.clear?.();
|
|
100
|
+
delete map[k];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @internal Convenience: set a capped timeout directly into the map for `key`.
|
|
105
|
+
* @param map The map to store the timer in (pass in the ref to the timer map)
|
|
106
|
+
* @param key The key to associate with the timer
|
|
107
|
+
* @param cb The callback to invoke when the timer expires
|
|
108
|
+
* @param delayMs The delay in milliseconds before the timer expires
|
|
109
|
+
* */
|
|
110
|
+
function setCappedTimeoutInMap(map, key, cb, delayMs) {
|
|
111
|
+
putTimer(map, key, setCappedTimeout(cb, delayMs));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @internal Convenience: set a regular (short) timeout into the map for `key`.
|
|
115
|
+
* @param map The map to store the timer in (pass in the ref to the timer map)
|
|
116
|
+
* @param key The key to associate with the timer
|
|
117
|
+
* @param cb The callback to invoke when the timer expires
|
|
118
|
+
* @param delayMs The delay in milliseconds before the timer expires
|
|
119
|
+
*/
|
|
120
|
+
function setTimeoutInMap(map, key, cb, delayMs) {
|
|
121
|
+
putTimer(map, key, setTimeoutController(cb, delayMs));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
exports.MAX_DELAY_MS = MAX_DELAY_MS;
|
|
125
|
+
exports.clearAll = clearAll;
|
|
126
|
+
exports.clearKey = clearKey;
|
|
127
|
+
exports.clearKeys = clearKeys;
|
|
128
|
+
exports.putTimer = putTimer;
|
|
129
|
+
exports.setCappedTimeout = setCappedTimeout;
|
|
130
|
+
exports.setCappedTimeoutInMap = setCappedTimeoutInMap;
|
|
131
|
+
exports.setTimeoutController = setTimeoutController;
|
|
132
|
+
exports.setTimeoutInMap = setTimeoutInMap;
|
|
133
|
+
//# sourceMappingURL=timers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timers.js","sources":["../../src/utils/timers.ts"],"sourcesContent":[null],"names":["MAX_DELAY_MS","toIntMs","x","Math","max","floor","Number","isFinite","setCappedTimeout","cb","delayMs","target","Date","now","handle","tick","remaining","window","setTimeout","min","clear","undefined","clearTimeout","setTimeoutController","ms","id","putTimer","map","key","controller","clearKey","clearKeys","keys","k","clearAll","Object","setCappedTimeoutInMap","setTimeoutInMap"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAMaA,MAAAA,YAAY,GAAG,cAAc;AAE1C;AACA,SAASC,OAAOA,CAACC,CAAS,EAAA;EACxB,OAAOC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,KAAK,CAACC,MAAM,CAACC,QAAQ,CAACL,CAAC,CAAC,GAAGA,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5D;AAEA;;;;;;;;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AEC,GAAW,EAAA;AACjDD,EAAAA,GAAG,CAACC,GAAG,CAAC,EAAER,KAAK,IAAI;EACnB,OAAOO,GAAG,CAACC,GAAG,CAAC;AACjB;AAEA;AACgB,SAAAG,SAASA,CAACJ,GAAa,EAAEK,IAAc,EAAA;EACrD,KAAK,MAAMC,CAAC,IAAID,IAAI,EAAEF,QAAQ,CAACH,GAAG,EAAEM,CAAC,CAAC;AACxC;AAEA;AACM,SAAUC,QAAQA,CAACP,GAAa,EAAA;EACpC,KAAK,MAAMM,CAAC,IAAIE,MAAM,CAACH,IAAI,CAACL,GAAG,CAAC,EAAE;AAChCA,IAAAA,GAAG,CAACM,CAAC,CAAC,EAAEb,KAAK,IAAI;IACjB,OAAOO,GAAG,CAACM,CAAC,CAAC;AACf;AACF;AAEA;;;;;;AAMK;AACC,SAAUG,qBAAqBA,CACnCT,GAAa,EACbC,GAAW,EACXnB,EAAc,EACdC,OAAe,EAAA;EAEfgB,QAAQ,CAACC,GAAG,EAAEC,GAAG,EAAEpB,gBAAgB,CAACC,EAAE,EAAEC,OAAO,CAAC,CAAC;AACnD;AAEA;;;;;;AAMG;AACG,SAAU2B,eAAeA,CAC7BV,GAAa,EACbC,GAAW,EACXnB,EAAc,EACdC,OAAe,EAAA;EAEfgB,QAAQ,CAACC,GAAG,EAAEC,GAAG,EAAEL,oBAAoB,CAACd,EAAE,EAAEC,OAAO,CAAC,CAAC;AACvD;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { createForOfIteratorHelper as _createForOfIteratorHelper } from '../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
+
|
|
3
|
+
// This file contains utility functions for managing timers and timeouts for session management.
|
|
4
|
+
// Unfortunately, the delay param in Node Timeouts is a 32-bit signed integer, meaning it can only represent delays up to ~24.8 days.
|
|
5
|
+
// This file provides functions to handle long delays by breaking them into smaller chunks.
|
|
6
|
+
// These functions are separate from the normal utils function to reduce clutter and improve visibility.
|
|
7
|
+
// Use `setTimeoutInMap` for short, frequent nudges (10s), and `setCappedTimeoutInMap` for anything that could exceed ~24.8 days.
|
|
8
|
+
var MAX_DELAY_MS = 2147483647; // ~24.8 days
|
|
9
|
+
/** @internal */
|
|
10
|
+
function toIntMs(x) {
|
|
11
|
+
return Math.max(0, Math.floor(Number.isFinite(x) ? x : 0));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @internal A drop-in replacement for `setTimeout` that supports arbitrarily long delays.
|
|
15
|
+
*
|
|
16
|
+
* ### Why?
|
|
17
|
+
* Browsers clamp `setTimeout` delays to a 32-bit signed integer,
|
|
18
|
+
* i.e. a maximum of ~24.8 days (`2_147_483_647ms`). Any larger value
|
|
19
|
+
* will fire almost immediately. This helper safely schedules timeouts
|
|
20
|
+
* that can be months or years into the future.
|
|
21
|
+
*
|
|
22
|
+
* ### How it works
|
|
23
|
+
* - On call, we record a fixed **target timestamp** (`now + delayMs`).
|
|
24
|
+
* - We schedule a single "leg" of at most ~24.8 days into the future,
|
|
25
|
+
* with an internal `tick` function as the callback.
|
|
26
|
+
* - When a leg expires, `tick` checks how much time is left:
|
|
27
|
+
* - If `remaining > 0`, it schedules the next leg (`min(MAX_DELAY_MS, remaining)`).
|
|
28
|
+
* - If `remaining <= 0`, the full delay has passed and we finally call your `cb()`.
|
|
29
|
+
* - At any time, only **one** leg is active. Calling `.clear()` cancels
|
|
30
|
+
* the current leg and prevents further hops.
|
|
31
|
+
*
|
|
32
|
+
* ### Benefits
|
|
33
|
+
* - Works seamlessly for both short and very long delays.
|
|
34
|
+
* - Survives tab sleep / system suspend: when the tab wakes,
|
|
35
|
+
* `tick` re-checks the target timestamp and fires immediately if overdue.
|
|
36
|
+
* - No drift accumulation: each hop recalculates based on the fixed target,
|
|
37
|
+
* so you always land as close as possible to the intended deadline.
|
|
38
|
+
*
|
|
39
|
+
* ### Example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const controller = setCappedTimeout(() => {
|
|
42
|
+
* console.log("A whole year later!");
|
|
43
|
+
* }, 1000 * 60 * 60 * 24 * 365);
|
|
44
|
+
*
|
|
45
|
+
* // Cancel if needed
|
|
46
|
+
* controller.clear();
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param cb - Function to run once the full delay has elapsed.
|
|
50
|
+
* @param delayMs - Delay in milliseconds (can exceed 2_147_483_647).
|
|
51
|
+
* @returns A controller with a `.clear()` method to cancel the timeout.
|
|
52
|
+
*/
|
|
53
|
+
function setCappedTimeout(cb, delayMs) {
|
|
54
|
+
var target = Date.now() + toIntMs(delayMs);
|
|
55
|
+
var handle;
|
|
56
|
+
var _tick = function tick() {
|
|
57
|
+
var remaining = target - Date.now();
|
|
58
|
+
if (remaining <= 0) {
|
|
59
|
+
cb();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
handle = window.setTimeout(_tick, Math.min(MAX_DELAY_MS, remaining));
|
|
63
|
+
};
|
|
64
|
+
_tick();
|
|
65
|
+
return {
|
|
66
|
+
clear: function clear() {
|
|
67
|
+
if (handle !== undefined) {
|
|
68
|
+
window.clearTimeout(handle);
|
|
69
|
+
handle = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** @internal Simple one-shot timeout that still returns a controller for uniformity. */
|
|
75
|
+
function setTimeoutController(cb, delayMs) {
|
|
76
|
+
var ms = toIntMs(delayMs);
|
|
77
|
+
var id = window.setTimeout(cb, ms);
|
|
78
|
+
return {
|
|
79
|
+
clear: function clear() {
|
|
80
|
+
return window.clearTimeout(id);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** @internal Replace any existing timer for `key` with `controller`. */
|
|
85
|
+
function putTimer(map, key, controller) {
|
|
86
|
+
var _map$key, _map$key$clear;
|
|
87
|
+
(_map$key = map[key]) === null || _map$key === void 0 ? void 0 : (_map$key$clear = _map$key.clear) === null || _map$key$clear === void 0 ? void 0 : _map$key$clear.call(_map$key);
|
|
88
|
+
map[key] = controller;
|
|
89
|
+
}
|
|
90
|
+
/** @internal Clear a specific key (noop if missing). */
|
|
91
|
+
function clearKey(map, key) {
|
|
92
|
+
var _map$key2, _map$key2$clear;
|
|
93
|
+
(_map$key2 = map[key]) === null || _map$key2 === void 0 ? void 0 : (_map$key2$clear = _map$key2.clear) === null || _map$key2$clear === void 0 ? void 0 : _map$key2$clear.call(_map$key2);
|
|
94
|
+
delete map[key];
|
|
95
|
+
}
|
|
96
|
+
/** @internal Clear several keys at once (noop on missing). */
|
|
97
|
+
function clearKeys(map, keys) {
|
|
98
|
+
var _iterator = _createForOfIteratorHelper(keys),
|
|
99
|
+
_step;
|
|
100
|
+
try {
|
|
101
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
102
|
+
var k = _step.value;
|
|
103
|
+
clearKey(map, k);
|
|
104
|
+
}
|
|
105
|
+
} catch (err) {
|
|
106
|
+
_iterator.e(err);
|
|
107
|
+
} finally {
|
|
108
|
+
_iterator.f();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** @internal Clear all timers in the map. */
|
|
112
|
+
function clearAll(map) {
|
|
113
|
+
for (var _i = 0, _Object$keys = Object.keys(map); _i < _Object$keys.length; _i++) {
|
|
114
|
+
var _map$k, _map$k$clear;
|
|
115
|
+
var k = _Object$keys[_i];
|
|
116
|
+
(_map$k = map[k]) === null || _map$k === void 0 ? void 0 : (_map$k$clear = _map$k.clear) === null || _map$k$clear === void 0 ? void 0 : _map$k$clear.call(_map$k);
|
|
117
|
+
delete map[k];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @internal Convenience: set a capped timeout directly into the map for `key`.
|
|
122
|
+
* @param map The map to store the timer in (pass in the ref to the timer map)
|
|
123
|
+
* @param key The key to associate with the timer
|
|
124
|
+
* @param cb The callback to invoke when the timer expires
|
|
125
|
+
* @param delayMs The delay in milliseconds before the timer expires
|
|
126
|
+
* */
|
|
127
|
+
function setCappedTimeoutInMap(map, key, cb, delayMs) {
|
|
128
|
+
putTimer(map, key, setCappedTimeout(cb, delayMs));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @internal Convenience: set a regular (short) timeout into the map for `key`.
|
|
132
|
+
* @param map The map to store the timer in (pass in the ref to the timer map)
|
|
133
|
+
* @param key The key to associate with the timer
|
|
134
|
+
* @param cb The callback to invoke when the timer expires
|
|
135
|
+
* @param delayMs The delay in milliseconds before the timer expires
|
|
136
|
+
*/
|
|
137
|
+
function setTimeoutInMap(map, key, cb, delayMs) {
|
|
138
|
+
putTimer(map, key, setTimeoutController(cb, delayMs));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { MAX_DELAY_MS, clearAll, clearKey, clearKeys, putTimer, setCappedTimeout, setCappedTimeoutInMap, setTimeoutController, setTimeoutInMap };
|
|
142
|
+
//# sourceMappingURL=timers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timers.mjs","sources":["../../src/utils/timers.ts"],"sourcesContent":[null],"names":["MAX_DELAY_MS","toIntMs","x","Math","max","floor","Number","isFinite","setCappedTimeout","cb","delayMs","target","Date","now","handle","tick","remaining","window","setTimeout","min","clear","undefined","clearTimeout","setTimeoutController","ms","id","putTimer","map","key","controller","_map$key","_map$key$clear","call","clearKey","_map$key2","_map$key2$clear","clearKeys","keys","_iterator","_createForOfIteratorHelper","_step","s","n","done","k","value","err","e","f","clearAll","_i","_Object$keys","Object","length","_map$k","_map$k$clear","setCappedTimeoutInMap","setTimeoutInMap"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAMaA,IAAAA,YAAY,GAAG,WAAc;AAE1C;AACA,SAASC,OAAOA,CAACC,CAAS,EAAA;EACxB,OAAOC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,KAAK,CAACC,MAAM,CAACC,QAAQ,CAACL,CAAC,CAAC,GAAGA,CAAC,GAAG,CAAC,CAAC,C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AA,EAAAA,YAAA,GAAgBC,MAAM,CAACf,IAAI,CAACV,GAAG,CAAC,EAAAuB,EAAA,GAAAC,YAAA,CAAAE,MAAA,EAAAH,EAAA,EAAE,EAAA;IAAA,IAAAI,MAAA,EAAAC,YAAA;AAA7B,IAAA,IAAMX,CAAC,GAAAO,YAAA,CAAAD,EAAA,CAAA;IACV,CAAAI,MAAA,GAAA3B,GAAG,CAACiB,CAAC,CAAC,MAAA,IAAA,IAAAU,MAAA,KAAA,MAAA,GAAA,MAAA,GAAA,CAAAC,YAAA,GAAND,MAAA,CAAQlC,KAAK,cAAAmC,YAAA,KAAA,MAAA,GAAA,MAAA,GAAbA,YAAA,CAAAvB,IAAA,CAAAsB,OAAiB;IACjB,OAAO3B,GAAG,CAACiB,CAAC,CAAC;AACf;AACF;AAEA;;;;;;AAMK;AACC,SAAUY,qBAAqBA,CACnC7B,GAAa,EACbC,GAAW,EACXnB,EAAc,EACdC,OAAe,EAAA;EAEfgB,QAAQ,CAACC,GAAG,EAAEC,GAAG,EAAEpB,gBAAgB,CAACC,EAAE,EAAEC,OAAO,CAAC,CAAC;AACnD;AAEA;;;;;;AAMG;AACG,SAAU+C,eAAeA,CAC7B9B,GAAa,EACbC,GAAW,EACXnB,EAAc,EACdC,OAAe,EAAA;EAEfgB,QAAQ,CAACC,GAAG,EAAEC,GAAG,EAAEL,oBAAoB,CAACd,EAAE,EAAEC,OAAO,CAAC,CAAC;AACvD;;;;"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Session, TurnkeyError, TurnkeyErrorCodes } from "@turnkey/sdk-types";
|
|
2
|
-
import type { TurnkeyCallbacks } from "
|
|
1
|
+
import { AuthAction, BaseAuthResult, Session, TurnkeyError, TurnkeyErrorCodes } from "@turnkey/sdk-types";
|
|
2
|
+
import type { TurnkeyCallbacks } from "../types/base";
|
|
3
3
|
import { WalletProvider } from "@turnkey/core";
|
|
4
|
+
export declare const DISCORD_AUTH_URL = "https://discord.com/oauth2/authorize";
|
|
5
|
+
export declare const X_AUTH_URL = "https://x.com/i/oauth2/authorize";
|
|
4
6
|
export declare const GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
5
7
|
export declare const APPLE_AUTH_URL = "https://account.apple.com/auth/authorize";
|
|
6
8
|
export declare const APPLE_AUTH_SCRIPT_URL = "https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js";
|
|
@@ -43,6 +45,7 @@ export declare function parseOAuthRedirect(hash: string): {
|
|
|
43
45
|
flow: string | null;
|
|
44
46
|
publicKey: string | null;
|
|
45
47
|
openModal: string | null;
|
|
48
|
+
sessionKey: string | null;
|
|
46
49
|
};
|
|
47
50
|
export declare function generateChallengePair(): Promise<{
|
|
48
51
|
verifier: string;
|
|
@@ -61,7 +64,9 @@ export declare function handleFacebookPKCEFlow({ code, publicKey, openModal, cli
|
|
|
61
64
|
completeOauth: (params: {
|
|
62
65
|
oidcToken: string;
|
|
63
66
|
publicKey: string;
|
|
64
|
-
}) => Promise<
|
|
67
|
+
}) => Promise<BaseAuthResult & {
|
|
68
|
+
action: AuthAction;
|
|
69
|
+
}>;
|
|
65
70
|
onPushPage: (idToken: string) => Promise<void>;
|
|
66
71
|
}): Promise<void>;
|
|
67
72
|
export declare function useScreenSize(): {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,YAAY,EACZ,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAuB,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE,eAAO,MAAM,gBAAgB,yCAAyC,CAAC;AACvE,eAAO,MAAM,UAAU,qCAAqC,CAAC;AAC7D,eAAO,MAAM,eAAe,iDAAiD,C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BAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAyB/B;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,IAAI,EACJ,SAAS,EACT,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,aAAa,EACb,UAAU,GACX,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;IACzC,aAAa,EAAE,CAAC,MAAM,EAAE;QACtB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACnB,KAAK,OAAO,CAAC,cAAc,GAAG;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IACvD,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD,GAAG,OAAO,CAAC,IAAI,CAAC,CAiDhB;AAGD,wBAAgB,aAAa;;;EAkB5B;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAE/D;AAED,wBAAgB,sBAAsB,CAAC,YAAY,GAAE,cAAc,EAAO,8CA0BvD,cAAc,EAAE,WAWlC"}
|
|
@@ -4,6 +4,8 @@ var sdkTypes = require('@turnkey/sdk-types');
|
|
|
4
4
|
var react = require('react');
|
|
5
5
|
var core = require('@turnkey/core');
|
|
6
6
|
|
|
7
|
+
const DISCORD_AUTH_URL = "https://discord.com/oauth2/authorize";
|
|
8
|
+
const X_AUTH_URL = "https://x.com/i/oauth2/authorize";
|
|
7
9
|
const GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
8
10
|
const APPLE_AUTH_URL = "https://account.apple.com/auth/authorize";
|
|
9
11
|
const FACEBOOK_AUTH_URL = "https://www.facebook.com/v11.0/dialog/oauth";
|
|
@@ -52,7 +54,8 @@ function parseAppleOAuthRedirect(hash) {
|
|
|
52
54
|
provider: null,
|
|
53
55
|
flow: null,
|
|
54
56
|
publicKey: null,
|
|
55
|
-
openModal: null
|
|
57
|
+
openModal: null,
|
|
58
|
+
sessionKey: null
|
|
56
59
|
};
|
|
57
60
|
const stateContent = hash.substring(6, stateEndIndex); // Remove "state=" prefix
|
|
58
61
|
const stateParams = new URLSearchParams(stateContent);
|
|
@@ -61,7 +64,8 @@ function parseAppleOAuthRedirect(hash) {
|
|
|
61
64
|
provider: stateParams.get("provider"),
|
|
62
65
|
flow: stateParams.get("flow"),
|
|
63
66
|
publicKey: stateParams.get("publicKey"),
|
|
64
|
-
openModal: stateParams.get("openModal")
|
|
67
|
+
openModal: stateParams.get("openModal"),
|
|
68
|
+
sessionKey: stateParams.get("sessionKey")
|
|
65
69
|
};
|
|
66
70
|
}
|
|
67
71
|
// Helper function to parse Google OAuth redirects
|
|
@@ -73,19 +77,22 @@ function parseGoogleOAuthRedirect(hash) {
|
|
|
73
77
|
let flow = null;
|
|
74
78
|
let publicKey = null;
|
|
75
79
|
let openModal = null;
|
|
80
|
+
let sessionKey = null;
|
|
76
81
|
if (state) {
|
|
77
82
|
const stateParams = new URLSearchParams(state);
|
|
78
83
|
provider = stateParams.get("provider");
|
|
79
84
|
flow = stateParams.get("flow");
|
|
80
85
|
publicKey = stateParams.get("publicKey");
|
|
81
86
|
openModal = stateParams.get("openModal");
|
|
87
|
+
sessionKey = stateParams.get("sessionKey");
|
|
82
88
|
}
|
|
83
89
|
return {
|
|
84
90
|
idToken,
|
|
85
91
|
provider,
|
|
86
92
|
flow,
|
|
87
93
|
publicKey,
|
|
88
|
-
openModal
|
|
94
|
+
openModal,
|
|
95
|
+
sessionKey
|
|
89
96
|
};
|
|
90
97
|
}
|
|
91
98
|
// Main function to determine provider and parse accordingly
|
|
@@ -221,10 +228,12 @@ function useWalletProviderState(initialState = []) {
|
|
|
221
228
|
}
|
|
222
229
|
|
|
223
230
|
exports.APPLE_AUTH_URL = APPLE_AUTH_URL;
|
|
231
|
+
exports.DISCORD_AUTH_URL = DISCORD_AUTH_URL;
|
|
224
232
|
exports.FACEBOOK_AUTH_URL = FACEBOOK_AUTH_URL;
|
|
225
233
|
exports.FACEBOOK_GRAPH_URL = FACEBOOK_GRAPH_URL;
|
|
226
234
|
exports.GOOGLE_AUTH_URL = GOOGLE_AUTH_URL;
|
|
227
235
|
exports.SESSION_WARNING_THRESHOLD_MS = SESSION_WARNING_THRESHOLD_MS;
|
|
236
|
+
exports.X_AUTH_URL = X_AUTH_URL;
|
|
228
237
|
exports.exchangeCodeForToken = exchangeCodeForToken;
|
|
229
238
|
exports.generateChallengePair = generateChallengePair;
|
|
230
239
|
exports.handleFacebookPKCEFlow = handleFacebookPKCEFlow;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils/utils.ts"],"sourcesContent":[null],"names":["DISCORD_AUTH_URL","X_AUTH_URL","GOOGLE_AUTH_URL","APPLE_AUTH_URL","FACEBOOK_AUTH_URL","FACEBOOK_GRAPH_URL","popupWidth","popupHeight","SESSION_WARNING_THRESHOLD_MS","useDebouncedCallback","fn","wait","timer","useRef","fnRef","current","useCallback","args","clearTimeout","setTimeout","isValidSession","session","expiry","undefined","Date","now","withTurnkeyErrorHandling","callbacks","fallbackMessage","fallbackCode","TurnkeyErrorCodes","UNKNOWN","error","TurnkeyError","onError","tkError","parseAppleOAuthRedirect","hash","idTokenMatch","match","idToken","stateEndIndex","indexOf","provider","flow","publicKey","openModal","sessionKey","stateContent","substring","stateParams","URLSearchParams","get","parseGoogleOAuthRedirect","hashParams","state","parseOAuthRedirect","startsWith","generateChallengePair","randomBytes","Uint8Array","window","crypto","getRandomValues","verifier","btoa","String","fromCharCode","replace","encoder","TextEncoder","data","encode","digest","subtle","base64Challenge","codeChallenge","exchangeCodeForToken","clientId","redirectUri","code","codeVerifier","params","client_id","redirect_uri","code_verifier","grant_type","response","fetch","method","headers","body","toString","ok","errorData","json","Error","JSON","stringify","handleFacebookPKCEFlow","redirectURI","completeOauth","onPushPage","sessionStorage","getItem","OAUTH_SIGNUP_ERROR","tokenData","removeItem","id_token","onOauthRedirect","oidcToken","history","replaceState","document","title","location","pathname","console","useScreenSize","width","setWidth","useState","innerWidth","useEffect","handleResize","addEventListener","removeEventListener","isMobile","isWalletConnect","wallet","interfaceType","WalletInterfaceType","WalletConnect","useWalletProviderState","initialState","walletProviders","setWalletProviders","prevProvidersRef","isSameWalletProvider","a","b","length","key","name","info","namespace","chainInfo","connectedAddresses","map","x","toLowerCase","sort","join","A","B","i","updateWalletProviders","newProviders"],"mappings":";;;;;;AAWO,MAAMA,gBAAgB,GAAG;AACzB,MAAMC,UAAU,GAAG;AACnB,MAAMC,eAAe,GAAG;AACxB,MAAMC,cAAc,GAAG;AAGvB,MAAMC,iBAAiB,GAAG;AAC1B,MAAMC,kBAAkB,GAC7B;AACK,MAAMC,UAAU,GAAG;AACnB,MAAMC,WAAW,GAAG;MAEdC,4BAA4B,GAAG,EAAE,GAAG,KAAK;AAoC/C,MAAMC,oBAAoB,GAAGA,CAClCC,EAAK,EACLC,IAAI,GAAG,GAAG,KACL;AACL,EAAA,MAAMC,KAAK,GAAGC,YAAM,CAAuC,IAAI,CAAC;AAChE,EAAA,MAAMC,KAAK,GAAGD,YAAM,CAACH,EAAE,CAAC;EACxBI,KAAK,CAACC,OAAO,GAAGL,EAAE;AAElB,EAAA,OAAOM,iBAAW,CAChB,CAAC,GAAGC,IAAW,KAAI;IACjB,IAAIL,KAAK,CAACG,OAAO,EAAEG,YAAY,CAACN,KAAK,CAACG,OAAO,CAAC;AAC9CH,IAAAA,KAAK,CAACG,OAAO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AAE,CAAC,CAC3BC,IAAI,EAAE,CACNC,IAAI,CAAC,GAAG,CAAC;MACZ,OAAO,CAAA,EAAGP,SAAS,CAAIf,CAAAA,EAAAA,aAAa,IAAIa,IAAI,CAAA,CAAA,EAAII,kBAAkB,CAAE,CAAA;KACrE;IAED,MAAMM,CAAC,GAAGd,CAAC,CAACS,GAAG,CAACN,GAAG,CAAC,CAACS,IAAI,EAAE;IAC3B,MAAMG,CAAC,GAAGd,CAAC,CAACQ,GAAG,CAACN,GAAG,CAAC,CAACS,IAAI,EAAE;IAC3B,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,CAAC,CAACZ,MAAM,EAAEc,CAAC,EAAE,EAAE,IAAIF,CAAC,CAACE,CAAC,CAAC,KAAKD,CAAC,CAACC,CAAC,CAAC,EAAE,OAAO,KAAK;AAClE,IAAA,OAAO,IAAI;AACb;AAEA,EAAA,MAAMC,qBAAqB,GAAG5I,iBAAW,CACtC6I,YAA8B,IAAI;IACjC,IAAI,CAACnB,oBAAoB,CAACD,gBAAgB,CAAC1H,OAAO,EAAE8I,YAAY,CAAC,EAAE;MACjEpB,gBAAgB,CAAC1H,OAAO,GAAG8I,YAAY;MACvCrB,kBAAkB,CAACqB,YAAY,CAAC;AAClC;AACA;GACD,EACD,EAAE,CACH;AAED,EAAA,OAAO,CAACtB,eAAe,EAAEqB,qBAAqB,CAAU;AAC1D;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { slicedToArray as _slicedToArray, toConsumableArray as _toConsumableArray, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '
|
|
1
|
+
import { slicedToArray as _slicedToArray, toConsumableArray as _toConsumableArray, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
2
|
import { TurnkeyError, TurnkeyErrorCodes } from '@turnkey/sdk-types';
|
|
3
3
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
|
4
4
|
import { WalletInterfaceType } from '@turnkey/core';
|
|
5
5
|
|
|
6
|
+
var DISCORD_AUTH_URL = "https://discord.com/oauth2/authorize";
|
|
7
|
+
var X_AUTH_URL = "https://x.com/i/oauth2/authorize";
|
|
6
8
|
var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
7
9
|
var APPLE_AUTH_URL = "https://account.apple.com/auth/authorize";
|
|
8
10
|
var FACEBOOK_AUTH_URL = "https://www.facebook.com/v11.0/dialog/oauth";
|
|
@@ -84,7 +86,8 @@ function parseAppleOAuthRedirect(hash) {
|
|
|
84
86
|
provider: null,
|
|
85
87
|
flow: null,
|
|
86
88
|
publicKey: null,
|
|
87
|
-
openModal: null
|
|
89
|
+
openModal: null,
|
|
90
|
+
sessionKey: null
|
|
88
91
|
};
|
|
89
92
|
var stateContent = hash.substring(6, stateEndIndex); // Remove "state=" prefix
|
|
90
93
|
var stateParams = new URLSearchParams(stateContent);
|
|
@@ -93,7 +96,8 @@ function parseAppleOAuthRedirect(hash) {
|
|
|
93
96
|
provider: stateParams.get("provider"),
|
|
94
97
|
flow: stateParams.get("flow"),
|
|
95
98
|
publicKey: stateParams.get("publicKey"),
|
|
96
|
-
openModal: stateParams.get("openModal")
|
|
99
|
+
openModal: stateParams.get("openModal"),
|
|
100
|
+
sessionKey: stateParams.get("sessionKey")
|
|
97
101
|
};
|
|
98
102
|
}
|
|
99
103
|
// Helper function to parse Google OAuth redirects
|
|
@@ -105,19 +109,22 @@ function parseGoogleOAuthRedirect(hash) {
|
|
|
105
109
|
var flow = null;
|
|
106
110
|
var publicKey = null;
|
|
107
111
|
var openModal = null;
|
|
112
|
+
var sessionKey = null;
|
|
108
113
|
if (state) {
|
|
109
114
|
var stateParams = new URLSearchParams(state);
|
|
110
115
|
provider = stateParams.get("provider");
|
|
111
116
|
flow = stateParams.get("flow");
|
|
112
117
|
publicKey = stateParams.get("publicKey");
|
|
113
118
|
openModal = stateParams.get("openModal");
|
|
119
|
+
sessionKey = stateParams.get("sessionKey");
|
|
114
120
|
}
|
|
115
121
|
return {
|
|
116
122
|
idToken: idToken,
|
|
117
123
|
provider: provider,
|
|
118
124
|
flow: flow,
|
|
119
125
|
publicKey: publicKey,
|
|
120
|
-
openModal: openModal
|
|
126
|
+
openModal: openModal,
|
|
127
|
+
sessionKey: sessionKey
|
|
121
128
|
};
|
|
122
129
|
}
|
|
123
130
|
// Main function to determine provider and parse accordingly
|
|
@@ -337,5 +344,5 @@ function useWalletProviderState() {
|
|
|
337
344
|
return [walletProviders, updateWalletProviders];
|
|
338
345
|
}
|
|
339
346
|
|
|
340
|
-
export { APPLE_AUTH_URL, FACEBOOK_AUTH_URL, FACEBOOK_GRAPH_URL, GOOGLE_AUTH_URL, SESSION_WARNING_THRESHOLD_MS, exchangeCodeForToken, generateChallengePair, handleFacebookPKCEFlow, isValidSession, isWalletConnect, parseOAuthRedirect, popupHeight, popupWidth, useDebouncedCallback, useScreenSize, useWalletProviderState, withTurnkeyErrorHandling };
|
|
347
|
+
export { APPLE_AUTH_URL, DISCORD_AUTH_URL, FACEBOOK_AUTH_URL, FACEBOOK_GRAPH_URL, GOOGLE_AUTH_URL, SESSION_WARNING_THRESHOLD_MS, X_AUTH_URL, exchangeCodeForToken, generateChallengePair, handleFacebookPKCEFlow, isValidSession, isWalletConnect, parseOAuthRedirect, popupHeight, popupWidth, useDebouncedCallback, useScreenSize, useWalletProviderState, withTurnkeyErrorHandling };
|
|
341
348
|
//# sourceMappingURL=utils.mjs.map
|