@turnkey/react-wallet-kit 1.0.0-beta.4 → 1.0.0-beta.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.
Files changed (114) hide show
  1. package/dist/_virtual/_rollupPluginBabelHelpers.mjs +49 -1
  2. package/dist/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -1
  3. package/dist/components/auth/OTP.d.ts +1 -0
  4. package/dist/components/auth/OTP.d.ts.map +1 -1
  5. package/dist/components/auth/OTP.js +5 -1
  6. package/dist/components/auth/OTP.js.map +1 -1
  7. package/dist/components/auth/OTP.mjs +6 -3
  8. package/dist/components/auth/OTP.mjs.map +1 -1
  9. package/dist/components/auth/Wallet.d.ts +4 -4
  10. package/dist/components/auth/Wallet.d.ts.map +1 -1
  11. package/dist/components/auth/Wallet.js +70 -49
  12. package/dist/components/auth/Wallet.js.map +1 -1
  13. package/dist/components/auth/Wallet.mjs +74 -54
  14. package/dist/components/auth/Wallet.mjs.map +1 -1
  15. package/dist/components/auth/index.d.ts +5 -1
  16. package/dist/components/auth/index.d.ts.map +1 -1
  17. package/dist/components/auth/index.js +98 -12
  18. package/dist/components/auth/index.js.map +1 -1
  19. package/dist/components/auth/index.mjs +185 -82
  20. package/dist/components/auth/index.mjs.map +1 -1
  21. package/dist/components/export/Export.d.ts +2 -1
  22. package/dist/components/export/Export.d.ts.map +1 -1
  23. package/dist/components/export/Export.js +7 -6
  24. package/dist/components/export/Export.js.map +1 -1
  25. package/dist/components/export/Export.mjs +7 -6
  26. package/dist/components/export/Export.mjs.map +1 -1
  27. package/dist/components/export/ExportWarning.d.ts +2 -1
  28. package/dist/components/export/ExportWarning.d.ts.map +1 -1
  29. package/dist/components/export/ExportWarning.js +3 -2
  30. package/dist/components/export/ExportWarning.js.map +1 -1
  31. package/dist/components/export/ExportWarning.mjs +3 -2
  32. package/dist/components/export/ExportWarning.mjs.map +1 -1
  33. package/dist/components/import/Import.d.ts +7 -3
  34. package/dist/components/import/Import.d.ts.map +1 -1
  35. package/dist/components/import/Import.js +74 -37
  36. package/dist/components/import/Import.js.map +1 -1
  37. package/dist/components/import/Import.mjs +116 -54
  38. package/dist/components/import/Import.mjs.map +1 -1
  39. package/dist/components/user/ConnectWallet.d.ts +8 -0
  40. package/dist/components/user/ConnectWallet.d.ts.map +1 -0
  41. package/dist/components/user/{LinkWallet.js → ConnectWallet.js} +18 -18
  42. package/dist/components/user/ConnectWallet.js.map +1 -0
  43. package/dist/components/user/{LinkWallet.mjs → ConnectWallet.mjs} +25 -25
  44. package/dist/components/user/ConnectWallet.mjs.map +1 -0
  45. package/dist/index.d.ts +2 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +13 -0
  48. package/dist/index.js.map +1 -1
  49. package/dist/index.mjs +2 -1
  50. package/dist/index.mjs.map +1 -1
  51. package/dist/providers/TurnkeyProvider.d.ts +1 -0
  52. package/dist/providers/TurnkeyProvider.d.ts.map +1 -1
  53. package/dist/providers/TurnkeyProvider.js +1 -0
  54. package/dist/providers/TurnkeyProvider.js.map +1 -1
  55. package/dist/providers/TurnkeyProvider.mjs +1 -0
  56. package/dist/providers/TurnkeyProvider.mjs.map +1 -1
  57. package/dist/providers/client/Hook.d.ts +1 -0
  58. package/dist/providers/client/Hook.d.ts.map +1 -1
  59. package/dist/providers/client/Hook.js +1 -0
  60. package/dist/providers/client/Hook.js.map +1 -1
  61. package/dist/providers/client/Hook.mjs +1 -0
  62. package/dist/providers/client/Hook.mjs.map +1 -1
  63. package/dist/providers/client/Provider.d.ts +3 -3
  64. package/dist/providers/client/Provider.d.ts.map +1 -1
  65. package/dist/providers/client/Provider.js +1019 -388
  66. package/dist/providers/client/Provider.js.map +1 -1
  67. package/dist/providers/client/Provider.mjs +2901 -2162
  68. package/dist/providers/client/Provider.mjs.map +1 -1
  69. package/dist/providers/client/Types.d.ts +164 -50
  70. package/dist/providers/client/Types.d.ts.map +1 -1
  71. package/dist/providers/client/Types.js +1 -0
  72. package/dist/providers/client/Types.js.map +1 -1
  73. package/dist/providers/client/Types.mjs +1 -0
  74. package/dist/providers/client/Types.mjs.map +1 -1
  75. package/dist/providers/modal/Hook.d.ts +1 -0
  76. package/dist/providers/modal/Hook.d.ts.map +1 -1
  77. package/dist/providers/modal/Hook.js +1 -0
  78. package/dist/providers/modal/Hook.js.map +1 -1
  79. package/dist/providers/modal/Hook.mjs +1 -0
  80. package/dist/providers/modal/Hook.mjs.map +1 -1
  81. package/dist/providers/modal/Provider.js +1 -1
  82. package/dist/providers/modal/Provider.mjs +1 -1
  83. package/dist/providers/modal/Root.d.ts.map +1 -1
  84. package/dist/providers/modal/Root.js +18 -14
  85. package/dist/providers/modal/Root.js.map +1 -1
  86. package/dist/providers/modal/Root.mjs +19 -17
  87. package/dist/providers/modal/Root.mjs.map +1 -1
  88. package/dist/styles.css +1 -1
  89. package/dist/types/base.d.ts +81 -2
  90. package/dist/types/base.d.ts.map +1 -1
  91. package/dist/types/base.js +35 -0
  92. package/dist/types/base.js.map +1 -1
  93. package/dist/types/base.mjs +31 -1
  94. package/dist/types/base.mjs.map +1 -1
  95. package/dist/utils/timers.d.ts +73 -0
  96. package/dist/utils/timers.d.ts.map +1 -0
  97. package/dist/utils/timers.js +133 -0
  98. package/dist/utils/timers.js.map +1 -0
  99. package/dist/utils/timers.mjs +142 -0
  100. package/dist/utils/timers.mjs.map +1 -0
  101. package/dist/{utils.d.ts → utils/utils.d.ts} +9 -3
  102. package/dist/utils/utils.d.ts.map +1 -0
  103. package/dist/{utils.js → utils/utils.js} +43 -5
  104. package/dist/utils/utils.js.map +1 -0
  105. package/dist/{utils.mjs → utils/utils.mjs} +48 -7
  106. package/dist/utils/utils.mjs.map +1 -0
  107. package/package.json +4 -4
  108. package/dist/components/user/LinkWallet.d.ts +0 -8
  109. package/dist/components/user/LinkWallet.d.ts.map +0 -1
  110. package/dist/components/user/LinkWallet.js.map +0 -1
  111. package/dist/components/user/LinkWallet.mjs.map +0 -1
  112. package/dist/utils.d.ts.map +0 -1
  113. package/dist/utils.js.map +0 -1
  114. package/dist/utils.mjs.map +0 -1
@@ -1,20 +1,55 @@
1
1
  'use strict';
2
2
 
3
+ var iframeStamper = require('@turnkey/iframe-stamper');
4
+
5
+ /**@internal */
3
6
  exports.ExportType = void 0;
4
7
  (function (ExportType) {
5
8
  ExportType["Wallet"] = "WALLET";
6
9
  ExportType["PrivateKey"] = "PRIVATE_KEY";
7
10
  ExportType["WalletAccount"] = "WALLET_ACCOUNT";
8
11
  })(exports.ExportType || (exports.ExportType = {}));
12
+ /**@internal */
13
+ exports.ImportType = void 0;
14
+ (function (ImportType) {
15
+ ImportType["Wallet"] = "WALLET";
16
+ ImportType["PrivateKey"] = "PRIVATE_KEY";
17
+ })(exports.ImportType || (exports.ImportType = {}));
18
+ /**
19
+ * Enum representing the authentication states of the user.
20
+ * - Unauthenticated: The user is not authenticated.
21
+ * - Authenticated: The user is authenticated.
22
+ */
9
23
  exports.AuthState = void 0;
10
24
  (function (AuthState) {
11
25
  AuthState["Unauthenticated"] = "unauthenticated";
12
26
  AuthState["Authenticated"] = "authenticated";
13
27
  })(exports.AuthState || (exports.AuthState = {}));
28
+ /**
29
+ * Enum representing the states of the client.
30
+ * - Loading: The client is currently loading.
31
+ * - Ready: The client is ready for use.
32
+ * - Error: An error occurred while initializing the client.
33
+ */
14
34
  exports.ClientState = void 0;
15
35
  (function (ClientState) {
16
36
  ClientState["Loading"] = "loading";
17
37
  ClientState["Ready"] = "ready";
18
38
  ClientState["Error"] = "error";
19
39
  })(exports.ClientState || (exports.ClientState = {}));
40
+ /**
41
+ * Enum representing the authentication methods.
42
+ */
43
+ exports.AuthMethod = void 0;
44
+ (function (AuthMethod) {
45
+ AuthMethod["Otp"] = "otp";
46
+ AuthMethod["Passkey"] = "passkey";
47
+ AuthMethod["Wallet"] = "wallet";
48
+ AuthMethod["Oauth"] = "oauth";
49
+ })(exports.AuthMethod || (exports.AuthMethod = {}));
50
+
51
+ Object.defineProperty(exports, "KeyFormat", {
52
+ enumerable: true,
53
+ get: function () { return iframeStamper.KeyFormat; }
54
+ });
20
55
  //# sourceMappingURL=base.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sources":["../../src/types/base.ts"],"sourcesContent":[null],"names":["ExportType","AuthState","ClientState"],"mappings":";;AAmEYA;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,kBAAU,KAAVA,kBAAU,GAIrB,EAAA,CAAA,CAAA;AAEWC;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,iBAAS,KAATA,iBAAS,GAGpB,EAAA,CAAA,CAAA;AAEWC;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,mBAAW,KAAXA,mBAAW,GAItB,EAAA,CAAA,CAAA;;"}
1
+ {"version":3,"file":"base.js","sources":["../../src/types/base.ts"],"sourcesContent":[null],"names":["ExportType","ImportType","AuthState","ClientState","AuthMethod"],"mappings":";;;;AAwHA;AACYA;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;AACl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ET";
4
7
  ExportType["PrivateKey"] = "PRIVATE_KEY";
5
8
  ExportType["WalletAccount"] = "WALLET_ACCOUNT";
6
9
  })(ExportType || (ExportType = {}));
10
+ /**@internal */
11
+ var ImportType;
12
+ (function (ImportType) {
13
+ ImportType["Wallet"] = "WALLET";
14
+ ImportType["PrivateKey"] = "PRIVATE_KEY";
15
+ })(ImportType || (ImportType = {}));
16
+ /**
17
+ * Enum representing the authentication states of the user.
18
+ * - Unauthenticated: The user is not authenticated.
19
+ * - Authenticated: The user is authenticated.
20
+ */
7
21
  var AuthState;
8
22
  (function (AuthState) {
9
23
  AuthState["Unauthenticated"] = "unauthenticated";
10
24
  AuthState["Authenticated"] = "authenticated";
11
25
  })(AuthState || (AuthState = {}));
26
+ /**
27
+ * Enum representing the states of the client.
28
+ * - Loading: The client is currently loading.
29
+ * - Ready: The client is ready for use.
30
+ * - Error: An error occurred while initializing the client.
31
+ */
12
32
  var ClientState;
13
33
  (function (ClientState) {
14
34
  ClientState["Loading"] = "loading";
15
35
  ClientState["Ready"] = "ready";
16
36
  ClientState["Error"] = "error";
17
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 = {}));
18
48
 
19
- export { AuthState, ClientState, ExportType };
49
+ export { AuthMethod, AuthState, ClientState, ExportType, ImportType };
20
50
  //# sourceMappingURL=base.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.mjs","sources":["../../src/types/base.ts"],"sourcesContent":[null],"names":["ExportType","AuthState","ClientState"],"mappings":"IAmEYA;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;IAEWC;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;IAEWC;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;;;;"}
1
+ {"version":3,"file":"base.mjs","sources":["../../src/types/base.ts"],"sourcesContent":[null],"names":["ExportType","ImportType","AuthState","ClientState","AuthMethod"],"mappings":";;AAwHA;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;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CAACG,EAAE;GAAG;AACjD;AAEA;SACgBC,QAAQA,CACtBC,GAAa,EACbC,GAAW,EACXC,UAA2B,EAAA;AAE3BF,EAAAA,GAAG,CAACC,GAAG,CAAC,EAAER,KAAK,IAAI;AACnBO,EAAAA,GAAG,CAACC,GAAG,CAAC,GAAGC,UAAU;AACvB;AAEA;AACgB,SAAAC,QAAQA,CAACH,GAAa,EAAEC,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,CAAC;AAC5D;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCG;AACa,SAAAM,gBAAgBA,CAC9BC,EAAc,EACdC,OAAe,EAAA;EAEf,IAAMC,MAAM,GAAGC,IAAI,CAACC,GAAG,EAAE,GAAGZ,OAAO,CAACS,OAAO,CAAC;AAC5C,EAAA,IAAII,MAA0B;AAE9B,EAAA,IAAMC,KAAI,GAAG,SAAPA,IAAIA,GAAQ;IAChB,IAAMC,SAAS,GAAGL,MAAM,GAAGC,IAAI,CAACC,GAAG,EAAE;IACrC,IAAIG,SAAS,IAAI,CAAC,EAAE;AAClBP,MAAAA,EAAE,EAAE;AACJ,MAAA;AACF;AACAK,IAAAA,MAAM,GAAGG,MAAM,CAACC,UAAU,CAACH,KAAI,EAAEZ,IAAI,CAACgB,GAAG,CAACnB,YAAY,EAAEgB,SAAS,CAAC,CAAC;GACpE;AAEDD,EAAAA,KAAI,EAAE;EAEN,OAAO;IACLK,KAAK,EAAA,SAALA,KAAKA,GAAA;MACH,IAAIN,MAAM,KAAKO,SAAS,EAAE;AACxBJ,QAAAA,MAAM,CAACK,YAAY,CAACR,MAAM,CAAC;AAC3BA,QAAAA,MAAM,GAAGO,SAAS;AACpB;AACF;GACD;AACH;AAEA;AACgB,SAAAE,o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AQ,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 "./types/base";
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<string>;
67
+ }) => Promise<BaseAuthResult & {
68
+ action: AuthAction;
69
+ }>;
65
70
  onPushPage: (idToken: string) => Promise<void>;
66
71
  }): Promise<void>;
67
72
  export declare function useScreenSize(): {
@@ -69,4 +74,5 @@ export declare function useScreenSize(): {
69
74
  isMobile: boolean;
70
75
  };
71
76
  export declare function isWalletConnect(wallet: WalletProvider): boolean;
77
+ export declare function useWalletProviderState(initialState?: WalletProvider[]): readonly [WalletProvider[], (newProviders: WalletProvider[]) => void];
72
78
  //# s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AAC,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";
@@ -13,13 +15,15 @@ const popupHeight = 600;
13
15
  const SESSION_WARNING_THRESHOLD_MS = 60 * 1000; // 1 minute in milliseconds
14
16
  const useDebouncedCallback = (fn, wait = 100) => {
15
17
  const timer = react.useRef(null);
18
+ const fnRef = react.useRef(fn);
19
+ fnRef.current = fn;
16
20
  return react.useCallback((...args) => {
17
21
  if (timer.current) clearTimeout(timer.current);
18
22
  timer.current = setTimeout(() => {
19
- fn(...args);
23
+ fnRef.current(...args);
20
24
  timer.current = null;
21
25
  }, wait);
22
- }, [fn, wait]);
26
+ }, [wait]);
23
27
  };
24
28
  const isValidSession = session => {
25
29
  return session?.expiry !== undefined && session.expiry * 1000 > Date.now();
@@ -50,7 +54,8 @@ function parseAppleOAuthRedirect(hash) {
50
54
  provider: null,
51
55
  flow: null,
52
56
  publicKey: null,
53
- openModal: null
57
+ openModal: null,
58
+ sessionKey: null
54
59
  };
55
60
  const stateContent = hash.substring(6, stateEndIndex); // Remove "state=" prefix
56
61
  const stateParams = new URLSearchParams(stateContent);
@@ -59,7 +64,8 @@ function parseAppleOAuthRedirect(hash) {
59
64
  provider: stateParams.get("provider"),
60
65
  flow: stateParams.get("flow"),
61
66
  publicKey: stateParams.get("publicKey"),
62
- openModal: stateParams.get("openModal")
67
+ openModal: stateParams.get("openModal"),
68
+ sessionKey: stateParams.get("sessionKey")
63
69
  };
64
70
  }
65
71
  // Helper function to parse Google OAuth redirects
@@ -71,19 +77,22 @@ function parseGoogleOAuthRedirect(hash) {
71
77
  let flow = null;
72
78
  let publicKey = null;
73
79
  let openModal = null;
80
+ let sessionKey = null;
74
81
  if (state) {
75
82
  const stateParams = new URLSearchParams(state);
76
83
  provider = stateParams.get("provider");
77
84
  flow = stateParams.get("flow");
78
85
  publicKey = stateParams.get("publicKey");
79
86
  openModal = stateParams.get("openModal");
87
+ sessionKey = stateParams.get("sessionKey");
80
88
  }
81
89
  return {
82
90
  idToken,
83
91
  provider,
84
92
  flow,
85
93
  publicKey,
86
- openModal
94
+ openModal,
95
+ sessionKey
87
96
  };
88
97
  }
89
98
  // Main function to determine provider and parse accordingly
@@ -191,12 +200,40 @@ function useScreenSize() {
191
200
  function isWalletConnect(wallet) {
192
201
  return wallet.interfaceType == core.WalletInterfaceType.WalletConnect;
193
202
  }
203
+ function useWalletProviderState(initialState = []) {
204
+ const [walletProviders, setWalletProviders] = react.useState(initialState);
205
+ const prevProvidersRef = react.useRef(initialState);
206
+ function isSameWalletProvider(a, b) {
207
+ if (a.length !== b.length) return false;
208
+ const key = provider => {
209
+ const name = provider.info.name;
210
+ const namespace = provider.chainInfo.namespace;
211
+ const interfaceType = provider.interfaceType;
212
+ const connectedAddresses = [...provider.connectedAddresses].map(x => x.toLowerCase()).sort().join(",");
213
+ return `${namespace}|${interfaceType}|${name}|${connectedAddresses}`;
214
+ };
215
+ const A = a.map(key).sort();
216
+ const B = b.map(key).sort();
217
+ for (let i = 0; i < A.length; i++) if (A[i] !== B[i]) return false;
218
+ return true;
219
+ }
220
+ const updateWalletProviders = react.useCallback(newProviders => {
221
+ if (!isSameWalletProvider(prevProvidersRef.current, newProviders)) {
222
+ prevProvidersRef.current = newProviders;
223
+ setWalletProviders(newProviders);
224
+ }
225
+ // we do nothing if the wallet providers are the same
226
+ }, []);
227
+ return [walletProviders, updateWalletProviders];
228
+ }
194
229
 
195
230
  exports.APPLE_AUTH_URL = APPLE_AUTH_URL;
231
+ exports.DISCORD_AUTH_URL = DISCORD_AUTH_URL;
196
232
  exports.FACEBOOK_AUTH_URL = FACEBOOK_AUTH_URL;
197
233
  exports.FACEBOOK_GRAPH_URL = FACEBOOK_GRAPH_URL;
198
234
  exports.GOOGLE_AUTH_URL = GOOGLE_AUTH_URL;
199
235
  exports.SESSION_WARNING_THRESHOLD_MS = SESSION_WARNING_THRESHOLD_MS;
236
+ exports.X_AUTH_URL = X_AUTH_URL;
200
237
  exports.exchangeCodeForToken = exchangeCodeForToken;
201
238
  exports.generateChallengePair = generateChallengePair;
202
239
  exports.handleFacebookPKCEFlow = handleFacebookPKCEFlow;
@@ -207,5 +244,6 @@ exports.popupHeight = popupHeight;
207
244
  exports.popupWidth = popupWidth;
208
245
  exports.useDebouncedCallback = useDebouncedCallback;
209
246
  exports.useScreenSize = useScreenSize;
247
+ exports.useWalletProviderState = useWalletProviderState;
210
248
  exports.withTurnkeyErrorHandling = withTurnkeyErrorHandling;
211
249
  //# sourceMappingURL=utils.js.map