@turnkey/react-wallet-kit 1.0.0-beta.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.
Files changed (248) hide show
  1. package/LICENSE +201 -0
  2. package/README.MD +112 -0
  3. package/dist/_virtual/_rollupPluginBabelHelpers.mjs +420 -0
  4. package/dist/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -0
  5. package/dist/components/auth/Action.d.ts +10 -0
  6. package/dist/components/auth/Action.d.ts.map +1 -0
  7. package/dist/components/auth/Action.js +76 -0
  8. package/dist/components/auth/Action.js.map +1 -0
  9. package/dist/components/auth/Action.mjs +97 -0
  10. package/dist/components/auth/Action.mjs.map +1 -0
  11. package/dist/components/auth/Email.d.ts +6 -0
  12. package/dist/components/auth/Email.d.ts.map +1 -0
  13. package/dist/components/auth/Email.js +73 -0
  14. package/dist/components/auth/Email.js.map +1 -0
  15. package/dist/components/auth/Email.mjs +95 -0
  16. package/dist/components/auth/Email.mjs.map +1 -0
  17. package/dist/components/auth/OAuth.d.ts +10 -0
  18. package/dist/components/auth/OAuth.d.ts.map +1 -0
  19. package/dist/components/auth/OAuth.js +42 -0
  20. package/dist/components/auth/OAuth.js.map +1 -0
  21. package/dist/components/auth/OAuth.mjs +46 -0
  22. package/dist/components/auth/OAuth.mjs.map +1 -0
  23. package/dist/components/auth/OTP.d.ts +19 -0
  24. package/dist/components/auth/OTP.d.ts.map +1 -0
  25. package/dist/components/auth/OTP.js +204 -0
  26. package/dist/components/auth/OTP.js.map +1 -0
  27. package/dist/components/auth/OTP.mjs +288 -0
  28. package/dist/components/auth/OTP.mjs.map +1 -0
  29. package/dist/components/auth/OrSeparator.d.ts +2 -0
  30. package/dist/components/auth/OrSeparator.d.ts.map +1 -0
  31. package/dist/components/auth/OrSeparator.js +20 -0
  32. package/dist/components/auth/OrSeparator.js.map +1 -0
  33. package/dist/components/auth/OrSeparator.mjs +18 -0
  34. package/dist/components/auth/OrSeparator.mjs.map +1 -0
  35. package/dist/components/auth/Passkey.d.ts +7 -0
  36. package/dist/components/auth/Passkey.d.ts.map +1 -0
  37. package/dist/components/auth/Passkey.js +26 -0
  38. package/dist/components/auth/Passkey.js.map +1 -0
  39. package/dist/components/auth/Passkey.mjs +22 -0
  40. package/dist/components/auth/Passkey.mjs.map +1 -0
  41. package/dist/components/auth/Phone.d.ts +6 -0
  42. package/dist/components/auth/Phone.d.ts.map +1 -0
  43. package/dist/components/auth/Phone.js +67 -0
  44. package/dist/components/auth/Phone.js.map +1 -0
  45. package/dist/components/auth/Phone.mjs +93 -0
  46. package/dist/components/auth/Phone.mjs.map +1 -0
  47. package/dist/components/auth/Wallet.d.ts +30 -0
  48. package/dist/components/auth/Wallet.d.ts.map +1 -0
  49. package/dist/components/auth/Wallet.js +408 -0
  50. package/dist/components/auth/Wallet.js.map +1 -0
  51. package/dist/components/auth/Wallet.mjs +509 -0
  52. package/dist/components/auth/Wallet.mjs.map +1 -0
  53. package/dist/components/auth/index.d.ts +2 -0
  54. package/dist/components/auth/index.d.ts.map +1 -0
  55. package/dist/components/auth/index.js +327 -0
  56. package/dist/components/auth/index.js.map +1 -0
  57. package/dist/components/auth/index.mjs +540 -0
  58. package/dist/components/auth/index.mjs.map +1 -0
  59. package/dist/components/design/Buttons.d.ts +26 -0
  60. package/dist/components/design/Buttons.d.ts.map +1 -0
  61. package/dist/components/design/Buttons.js +79 -0
  62. package/dist/components/design/Buttons.js.map +1 -0
  63. package/dist/components/design/Buttons.mjs +71 -0
  64. package/dist/components/design/Buttons.mjs.map +1 -0
  65. package/dist/components/design/Failure.d.ts +9 -0
  66. package/dist/components/design/Failure.d.ts.map +1 -0
  67. package/dist/components/design/Failure.js +33 -0
  68. package/dist/components/design/Failure.js.map +1 -0
  69. package/dist/components/design/Failure.mjs +34 -0
  70. package/dist/components/design/Failure.mjs.map +1 -0
  71. package/dist/components/design/Inputs.d.ts +9 -0
  72. package/dist/components/design/Inputs.d.ts.map +1 -0
  73. package/dist/components/design/Inputs.js +113 -0
  74. package/dist/components/design/Inputs.js.map +1 -0
  75. package/dist/components/design/Inputs.mjs +108 -0
  76. package/dist/components/design/Inputs.mjs.map +1 -0
  77. package/dist/components/design/Lottie/Dynamic.d.ts +2 -0
  78. package/dist/components/design/Lottie/Dynamic.d.ts.map +1 -0
  79. package/dist/components/design/Lottie/Dynamic.js +9 -0
  80. package/dist/components/design/Lottie/Dynamic.js.map +1 -0
  81. package/dist/components/design/Lottie/Dynamic.mjs +27 -0
  82. package/dist/components/design/Lottie/Dynamic.mjs.map +1 -0
  83. package/dist/components/design/Lottie/Wrapper.d.ts +8 -0
  84. package/dist/components/design/Lottie/Wrapper.d.ts.map +1 -0
  85. package/dist/components/design/Lottie/Wrapper.js +26 -0
  86. package/dist/components/design/Lottie/Wrapper.js.map +1 -0
  87. package/dist/components/design/Lottie/Wrapper.mjs +43 -0
  88. package/dist/components/design/Lottie/Wrapper.mjs.map +1 -0
  89. package/dist/components/design/Spinners.d.ts +9 -0
  90. package/dist/components/design/Spinners.d.ts.map +1 -0
  91. package/dist/components/design/Spinners.js +38 -0
  92. package/dist/components/design/Spinners.js.map +1 -0
  93. package/dist/components/design/Spinners.mjs +37 -0
  94. package/dist/components/design/Spinners.mjs.map +1 -0
  95. package/dist/components/design/Success.d.ts +8 -0
  96. package/dist/components/design/Success.d.ts.map +1 -0
  97. package/dist/components/design/Success.js +82 -0
  98. package/dist/components/design/Success.js.map +1 -0
  99. package/dist/components/design/Success.mjs +86 -0
  100. package/dist/components/design/Success.mjs.map +1 -0
  101. package/dist/components/design/Svg.d.ts +10 -0
  102. package/dist/components/design/Svg.d.ts.map +1 -0
  103. package/dist/components/design/Svg.js +156 -0
  104. package/dist/components/design/Svg.js.map +1 -0
  105. package/dist/components/design/Svg.mjs +153 -0
  106. package/dist/components/design/Svg.mjs.map +1 -0
  107. package/dist/components/export/Export.d.ts +9 -0
  108. package/dist/components/export/Export.d.ts.map +1 -0
  109. package/dist/components/export/Export.js +140 -0
  110. package/dist/components/export/Export.js.map +1 -0
  111. package/dist/components/export/Export.mjs +178 -0
  112. package/dist/components/export/Export.mjs.map +1 -0
  113. package/dist/components/export/ExportWarning.d.ts +12 -0
  114. package/dist/components/export/ExportWarning.d.ts.map +1 -0
  115. package/dist/components/export/ExportWarning.js +87 -0
  116. package/dist/components/export/ExportWarning.js.map +1 -0
  117. package/dist/components/export/ExportWarning.mjs +113 -0
  118. package/dist/components/export/ExportWarning.mjs.map +1 -0
  119. package/dist/components/import/Import.d.ts +14 -0
  120. package/dist/components/import/Import.d.ts.map +1 -0
  121. package/dist/components/import/Import.js +226 -0
  122. package/dist/components/import/Import.js.map +1 -0
  123. package/dist/components/import/Import.mjs +328 -0
  124. package/dist/components/import/Import.mjs.map +1 -0
  125. package/dist/components/sign/Message.d.ts +17 -0
  126. package/dist/components/sign/Message.d.ts.map +1 -0
  127. package/dist/components/sign/Message.js +127 -0
  128. package/dist/components/sign/Message.js.map +1 -0
  129. package/dist/components/sign/Message.mjs +145 -0
  130. package/dist/components/sign/Message.mjs.map +1 -0
  131. package/dist/components/user/LinkWallet.d.ts +8 -0
  132. package/dist/components/user/LinkWallet.d.ts.map +1 -0
  133. package/dist/components/user/LinkWallet.js +102 -0
  134. package/dist/components/user/LinkWallet.js.map +1 -0
  135. package/dist/components/user/LinkWallet.mjs +162 -0
  136. package/dist/components/user/LinkWallet.mjs.map +1 -0
  137. package/dist/components/user/RemoveEmail.d.ts +11 -0
  138. package/dist/components/user/RemoveEmail.d.ts.map +1 -0
  139. package/dist/components/user/RemoveEmail.js +101 -0
  140. package/dist/components/user/RemoveEmail.js.map +1 -0
  141. package/dist/components/user/RemoveEmail.mjs +122 -0
  142. package/dist/components/user/RemoveEmail.mjs.map +1 -0
  143. package/dist/components/user/RemoveOAuthProvider.d.ts +11 -0
  144. package/dist/components/user/RemoveOAuthProvider.d.ts.map +1 -0
  145. package/dist/components/user/RemoveOAuthProvider.js +106 -0
  146. package/dist/components/user/RemoveOAuthProvider.js.map +1 -0
  147. package/dist/components/user/RemoveOAuthProvider.mjs +129 -0
  148. package/dist/components/user/RemoveOAuthProvider.mjs.map +1 -0
  149. package/dist/components/user/RemovePasskey.d.ts +11 -0
  150. package/dist/components/user/RemovePasskey.d.ts.map +1 -0
  151. package/dist/components/user/RemovePasskey.js +109 -0
  152. package/dist/components/user/RemovePasskey.js.map +1 -0
  153. package/dist/components/user/RemovePasskey.mjs +132 -0
  154. package/dist/components/user/RemovePasskey.mjs.map +1 -0
  155. package/dist/components/user/RemovePhoneNumber.d.ts +11 -0
  156. package/dist/components/user/RemovePhoneNumber.d.ts.map +1 -0
  157. package/dist/components/user/RemovePhoneNumber.js +101 -0
  158. package/dist/components/user/RemovePhoneNumber.js.map +1 -0
  159. package/dist/components/user/RemovePhoneNumber.mjs +122 -0
  160. package/dist/components/user/RemovePhoneNumber.mjs.map +1 -0
  161. package/dist/components/user/UpdateEmail.d.ts +8 -0
  162. package/dist/components/user/UpdateEmail.d.ts.map +1 -0
  163. package/dist/components/user/UpdateEmail.js +139 -0
  164. package/dist/components/user/UpdateEmail.js.map +1 -0
  165. package/dist/components/user/UpdateEmail.mjs +186 -0
  166. package/dist/components/user/UpdateEmail.mjs.map +1 -0
  167. package/dist/components/user/UpdatePhoneNumber.d.ts +8 -0
  168. package/dist/components/user/UpdatePhoneNumber.d.ts.map +1 -0
  169. package/dist/components/user/UpdatePhoneNumber.js +136 -0
  170. package/dist/components/user/UpdatePhoneNumber.js.map +1 -0
  171. package/dist/components/user/UpdatePhoneNumber.mjs +187 -0
  172. package/dist/components/user/UpdatePhoneNumber.mjs.map +1 -0
  173. package/dist/components/user/UpdateUserName.d.ts +11 -0
  174. package/dist/components/user/UpdateUserName.d.ts.map +1 -0
  175. package/dist/components/user/UpdateUserName.js +112 -0
  176. package/dist/components/user/UpdateUserName.js.map +1 -0
  177. package/dist/components/user/UpdateUserName.mjs +139 -0
  178. package/dist/components/user/UpdateUserName.mjs.map +1 -0
  179. package/dist/index.d.ts +5 -0
  180. package/dist/index.d.ts.map +1 -0
  181. package/dist/index.js +32 -0
  182. package/dist/index.js.map +1 -0
  183. package/dist/index.mjs +6 -0
  184. package/dist/index.mjs.map +1 -0
  185. package/dist/providers/TurnkeyProvider.d.ts +8 -0
  186. package/dist/providers/TurnkeyProvider.d.ts.map +1 -0
  187. package/dist/providers/TurnkeyProvider.js +35 -0
  188. package/dist/providers/TurnkeyProvider.js.map +1 -0
  189. package/dist/providers/TurnkeyProvider.mjs +33 -0
  190. package/dist/providers/TurnkeyProvider.mjs.map +1 -0
  191. package/dist/providers/client/Hook.d.ts +3 -0
  192. package/dist/providers/client/Hook.d.ts.map +1 -0
  193. package/dist/providers/client/Hook.js +14 -0
  194. package/dist/providers/client/Hook.js.map +1 -0
  195. package/dist/providers/client/Hook.mjs +12 -0
  196. package/dist/providers/client/Hook.mjs.map +1 -0
  197. package/dist/providers/client/Provider.d.ts +39 -0
  198. package/dist/providers/client/Provider.d.ts.map +1 -0
  199. package/dist/providers/client/Provider.js +2489 -0
  200. package/dist/providers/client/Provider.js.map +1 -0
  201. package/dist/providers/client/Provider.mjs +4744 -0
  202. package/dist/providers/client/Provider.mjs.map +1 -0
  203. package/dist/providers/client/Types.d.ts +524 -0
  204. package/dist/providers/client/Types.d.ts.map +1 -0
  205. package/dist/providers/client/Types.js +9 -0
  206. package/dist/providers/client/Types.js.map +1 -0
  207. package/dist/providers/client/Types.mjs +7 -0
  208. package/dist/providers/client/Types.mjs.map +1 -0
  209. package/dist/providers/index.d.ts +5 -0
  210. package/dist/providers/index.d.ts.map +1 -0
  211. package/dist/providers/modal/Hook.d.ts +3 -0
  212. package/dist/providers/modal/Hook.d.ts.map +1 -0
  213. package/dist/providers/modal/Hook.js +14 -0
  214. package/dist/providers/modal/Hook.js.map +1 -0
  215. package/dist/providers/modal/Hook.mjs +12 -0
  216. package/dist/providers/modal/Hook.mjs.map +1 -0
  217. package/dist/providers/modal/Provider.d.ts +21 -0
  218. package/dist/providers/modal/Provider.d.ts.map +1 -0
  219. package/dist/providers/modal/Provider.js +37 -0
  220. package/dist/providers/modal/Provider.js.map +1 -0
  221. package/dist/providers/modal/Provider.mjs +48 -0
  222. package/dist/providers/modal/Provider.mjs.map +1 -0
  223. package/dist/providers/modal/Root.d.ts +7 -0
  224. package/dist/providers/modal/Root.d.ts.map +1 -0
  225. package/dist/providers/modal/Root.js +258 -0
  226. package/dist/providers/modal/Root.js.map +1 -0
  227. package/dist/providers/modal/Root.mjs +263 -0
  228. package/dist/providers/modal/Root.mjs.map +1 -0
  229. package/dist/providers/theme/Overrides.d.ts +18 -0
  230. package/dist/providers/theme/Overrides.d.ts.map +1 -0
  231. package/dist/providers/theme/Overrides.js +35 -0
  232. package/dist/providers/theme/Overrides.js.map +1 -0
  233. package/dist/providers/theme/Overrides.mjs +37 -0
  234. package/dist/providers/theme/Overrides.mjs.map +1 -0
  235. package/dist/styles.css +1 -0
  236. package/dist/types/base.d.ts +79 -0
  237. package/dist/types/base.d.ts.map +1 -0
  238. package/dist/types/base.js +19 -0
  239. package/dist/types/base.js.map +1 -0
  240. package/dist/types/base.mjs +19 -0
  241. package/dist/types/base.mjs.map +1 -0
  242. package/dist/utils.d.ts +72 -0
  243. package/dist/utils.d.ts.map +1 -0
  244. package/dist/utils.js +211 -0
  245. package/dist/utils.js.map +1 -0
  246. package/dist/utils.mjs +307 -0
  247. package/dist/utils.mjs.map +1 -0
  248. package/package.json +69 -0
@@ -0,0 +1,4744 @@
1
+ 'use client';
2
+ import { slicedToArray as _slicedToArray, asyncToGenerator as _asyncToGenerator, objectSpread2 as _objectSpread2, regeneratorRuntime as _regeneratorRuntime } from '../../_virtual/_rollupPluginBabelHelpers.mjs';
3
+ import { jsx } from 'react/jsx-runtime';
4
+ import { sha256 } from '@noble/hashes/sha2';
5
+ import { bytesToHex } from '@noble/hashes/utils';
6
+ import { useDebouncedCallback, isValidSession, parseOAuthRedirect, handleFacebookPKCEFlow, SESSION_WARNING_THRESHOLD_MS, withTurnkeyErrorHandling, GOOGLE_AUTH_URL, popupWidth, popupHeight, APPLE_AUTH_URL, exchangeCodeForToken, FACEBOOK_AUTH_URL, generateChallengePair } from '../../utils.mjs';
7
+ import { TurnkeyClient, Chain, getAuthProxyConfig, DEFAULT_SESSION_EXPIRATION_IN_SECONDS, OtpType } from '@turnkey/core';
8
+ import { useState, useRef, useEffect } from 'react';
9
+ import { TurnkeyError, TurnkeyNetworkError, TurnkeyErrorCodes, OAuthProviders } from '@turnkey/sdk-types';
10
+ import { useModal } from '../modal/Hook.mjs';
11
+ import { AuthState, ClientState, ExportType } from '../../types/base.mjs';
12
+ import { AuthComponent } from '../../components/auth/index.mjs';
13
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
14
+ import { faApple, faGoogle, faFacebook } from '@fortawesome/free-brands-svg-icons';
15
+ import { ActionPage } from '../../components/auth/Action.mjs';
16
+ import { SignMessageModal } from '../../components/sign/Message.mjs';
17
+ import { ExportComponent } from '../../components/export/Export.mjs';
18
+ import { ImportComponent } from '../../components/import/Import.mjs';
19
+ import { SuccessPage } from '../../components/design/Success.mjs';
20
+ import { UpdateEmail } from '../../components/user/UpdateEmail.mjs';
21
+ import { UpdatePhoneNumber } from '../../components/user/UpdatePhoneNumber.mjs';
22
+ import { UpdateUserName } from '../../components/user/UpdateUserName.mjs';
23
+ import { RemoveOAuthProvider } from '../../components/user/RemoveOAuthProvider.mjs';
24
+ import { RemovePasskey } from '../../components/user/RemovePasskey.mjs';
25
+ import { LinkWalletModal } from '../../components/user/LinkWallet.mjs';
26
+ import { ClientContext } from './Types.mjs';
27
+ import { OtpVerification } from '../../components/auth/OTP.mjs';
28
+ import { RemoveEmail } from '../../components/user/RemoveEmail.mjs';
29
+ import { RemovePhoneNumber } from '../../components/user/RemovePhoneNumber.mjs';
30
+
31
+ /**
32
+ * Provides Turnkey client authentication, session management, wallet operations, and user profile management
33
+ * for the React Wallet Kit SDK. This context provider encapsulates all core authentication flows (Passkey, Wallet, OTP, OAuth),
34
+ * session lifecycle (creation, expiration, refresh), wallet linking/import/export, and user profile updates (email, phone, name).
35
+ *
36
+ * The provider automatically initializes the Turnkey client, fetches configuration (including proxy auth config if needed),
37
+ * and synchronizes session and authentication state. It exposes a comprehensive set of methods for authentication flows,
38
+ * wallet management, and user profile operations, as well as UI handlers for modal-driven flows.
39
+ *
40
+ * Features:
41
+ * - Passkey, Wallet, OTP (Email/SMS), and OAuth (Google, Apple, Facebook) authentication and sign-up flows.
42
+ * - Session management: creation, expiration scheduling, refresh, and clearing.
43
+ * - Wallet management: fetch, link, import, export, account management.
44
+ * - User profile management: email, phone, name, OAuth provider, and passkey linking/removal.
45
+ * - Modal-driven UI flows for authentication, wallet linking, and profile updates.
46
+ * - Error handling and callback integration for custom error and event responses.
47
+ *
48
+ * Usage:
49
+ * Wrap your application with `TurnkeyProvider` to enable authentication and wallet features via context.
50
+ *
51
+ * @param config - The Turnkey provider configuration object.
52
+ * @param children - React children to be rendered within the provider.
53
+ * @param callbacks - Optional callbacks for error handling and session events.
54
+ *
55
+ * @returns A React context provider exposing authentication, wallet, and user management methods and state.
56
+ */
57
+ var ClientProvider = function ClientProvider(_ref) {
58
+ var config = _ref.config,
59
+ children = _ref.children,
60
+ callbacks = _ref.callbacks;
61
+ var _useState = useState(undefined),
62
+ _useState2 = _slicedToArray(_useState, 2),
63
+ client = _useState2[0],
64
+ setClient = _useState2[1];
65
+ var _useState3 = useState(undefined),
66
+ _useState4 = _slicedToArray(_useState3, 2),
67
+ session = _useState4[0],
68
+ setSession = _useState4[1];
69
+ var _useState5 = useState(false),
70
+ _useState6 = _slicedToArray(_useState5, 2),
71
+ autoRefreshSession = _useState6[0],
72
+ setAutoRefreshSession = _useState6[1];
73
+ var _useState7 = useState(undefined),
74
+ _useState8 = _slicedToArray(_useState7, 2),
75
+ masterConfig = _useState8[0],
76
+ setMasterConfig = _useState8[1];
77
+ var _useState9 = useState([]),
78
+ _useState0 = _slicedToArray(_useState9, 2),
79
+ wallets = _useState0[0],
80
+ setWallets = _useState0[1];
81
+ var _useState1 = useState(undefined),
82
+ _useState10 = _slicedToArray(_useState1, 2),
83
+ user = _useState10[0],
84
+ setUser = _useState10[1];
85
+ var _useState11 = useState(),
86
+ _useState12 = _slicedToArray(_useState11, 2),
87
+ clientState = _useState12[0],
88
+ setClientState = _useState12[1];
89
+ var _useState13 = useState(AuthState.Unauthenticated),
90
+ _useState14 = _slicedToArray(_useState13, 2),
91
+ authState = _useState14[0],
92
+ setAuthState = _useState14[1];
93
+ var expiryTimeoutsRef = useRef({});
94
+ var proxyAuthConfigRef = useRef(null);
95
+ var _useState15 = useState(undefined),
96
+ _useState16 = _slicedToArray(_useState15, 2),
97
+ allSessions = _useState16[0],
98
+ setAllSessions = _useState16[1];
99
+ var _useModal = useModal(),
100
+ pushPage = _useModal.pushPage,
101
+ closeModal = _useModal.closeModal;
102
+ useEffect(function () {
103
+ if (proxyAuthConfigRef.current) return;
104
+ // Only fetch the proxy auth config once. Use that to build the master config.
105
+ var fetchProxyAuthConfig = /*#__PURE__*/function () {
106
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
107
+ var proxyAuthConfig;
108
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
109
+ while (1) switch (_context.prev = _context.next) {
110
+ case 0:
111
+ _context.prev = 0;
112
+ if (!config.authProxyConfigId) {
113
+ _context.next = 6;
114
+ break;
115
+ }
116
+ _context.next = 4;
117
+ return getAuthProxyConfig(config.authProxyConfigId, config.authProxyUrl);
118
+ case 4:
119
+ proxyAuthConfig = _context.sent;
120
+ proxyAuthConfigRef.current = proxyAuthConfig;
121
+ case 6:
122
+ setMasterConfig(buildConfig(proxyAuthConfig));
123
+ _context.next = 12;
124
+ break;
125
+ case 9:
126
+ _context.prev = 9;
127
+ _context.t0 = _context["catch"](0);
128
+ setClientState(ClientState.Error);
129
+ case 12:
130
+ case "end":
131
+ return _context.stop();
132
+ }
133
+ }, _callee, null, [[0, 9]]);
134
+ }));
135
+ return function fetchProxyAuthConfig() {
136
+ return _ref2.apply(this, arguments);
137
+ };
138
+ }();
139
+ fetchProxyAuthConfig();
140
+ }, []);
141
+ useEffect(function () {
142
+ // Start the client initialization process once we have the master config.
143
+ if (!masterConfig) return;
144
+ initializeClient();
145
+ }, [masterConfig]);
146
+ useEffect(function () {
147
+ var _proxyAuthConfigRef$c;
148
+ // Handle changes to the passed in config prop -- update the master config
149
+ // If the proxyAuthConfigRef is already set, we don't need to fetch it again. Rebuild the master config with the updated config and stored proxyAuthConfig
150
+ if (!proxyAuthConfigRef.current && config.authProxyConfigId) return;
151
+ setMasterConfig(buildConfig((_proxyAuthConfigRef$c = proxyAuthConfigRef.current) !== null && _proxyAuthConfigRef$c !== void 0 ? _proxyAuthConfigRef$c : undefined));
152
+ }, [config, proxyAuthConfigRef.current]);
153
+ /**
154
+ * @internal
155
+ * we use debouncedFetchWallets() to prevent multiple rapid wallet events
156
+ * like accountsChanged and disconnect from triggering fetchWallets repeatedly
157
+ * it must be defined outside the useEffect so all event listeners share the same
158
+ * debounced function instance - otherwise, a new one would be created on every render
159
+ */
160
+ var debouncedFetchWallets = useDebouncedCallback(fetchWallets, 100);
161
+ useEffect(function () {
162
+ if (!client) return;
163
+ var cleanup = function cleanup() {};
164
+ initializeProviders(getWalletProviders, debouncedFetchWallets).then(function (fn) {
165
+ cleanup = fn;
166
+ })["catch"](function (err) {
167
+ console.error("Failed to init providers:", err);
168
+ });
169
+ return function () {
170
+ cleanup();
171
+ };
172
+ }, [client, debouncedFetchWallets]);
173
+ useEffect(function () {
174
+ // authState must be consistent with session state. We found during testing that there are cases where the session and authState can be out of sync in very rare edge cases.
175
+ // This will ensure that they are always in sync and remove the need to setAuthState manually in other places.
176
+ if (session) {
177
+ setAuthState(AuthState.Authenticated);
178
+ } else {
179
+ setAuthState(AuthState.Unauthenticated);
180
+ }
181
+ }, [session]);
182
+ useEffect(function () {
183
+ // This will handle any redirect based oAuth. It then initializes the session. This is the last step before client is considered "ready"
184
+ if (!client || !masterConfig) return;
185
+ completeRedirectOauth()["finally"](function () {
186
+ clearSessionTimeouts();
187
+ initializeSessions()["finally"](function () {
188
+ // Set the client state to ready only after all initializations are done.
189
+ setClientState(ClientState.Ready);
190
+ });
191
+ });
192
+ return function () {
193
+ clearSessionTimeouts();
194
+ };
195
+ }, [client]);
196
+ var completeRedirectOauth = /*#__PURE__*/function () {
197
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
198
+ var searchParams, code, state, stateParams, provider, flow, publicKey, openModal, _masterConfig$auth, _masterConfig$auth$oa, _masterConfig$auth2, _masterConfig$auth2$o, clientId, redirectURI, hash, _parseOAuthRedirect, idToken, _provider, _flow, _publicKey, _openModal, providerName, icon;
199
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
200
+ while (1) switch (_context4.prev = _context4.next) {
201
+ case 0:
202
+ if (!(window.location.hash || window.location.search)) {
203
+ _context4.next = 32;
204
+ break;
205
+ }
206
+ if (!(window.location.search && window.location.search.includes("code=") && window.location.search.includes("state="))) {
207
+ _context4.next = 19;
208
+ break;
209
+ }
210
+ searchParams = new URLSearchParams(window.location.search.substring(1));
211
+ code = searchParams.get("code");
212
+ state = searchParams.get("state"); // Parse state parameter
213
+ if (!(state && code)) {
214
+ _context4.next = 17;
215
+ break;
216
+ }
217
+ stateParams = new URLSearchParams(state);
218
+ provider = stateParams.get("provider");
219
+ flow = stateParams.get("flow");
220
+ publicKey = stateParams.get("publicKey");
221
+ openModal = stateParams.get("openModal");
222
+ if (!(provider === "facebook" && flow === "redirect" && publicKey)) {
223
+ _context4.next = 17;
224
+ break;
225
+ }
226
+ // We have all the required parameters for a Facebook PKCE flow
227
+ clientId = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth = masterConfig.auth) === null || _masterConfig$auth === void 0 ? void 0 : (_masterConfig$auth$oa = _masterConfig$auth.oauthConfig) === null || _masterConfig$auth$oa === void 0 ? void 0 : _masterConfig$auth$oa.facebookClientId;
228
+ redirectURI = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth2 = masterConfig.auth) === null || _masterConfig$auth2 === void 0 ? void 0 : (_masterConfig$auth2$o = _masterConfig$auth2.oauthConfig) === null || _masterConfig$auth2$o === void 0 ? void 0 : _masterConfig$auth2$o.oauthRedirectUri;
229
+ if (!(clientId && redirectURI)) {
230
+ _context4.next = 17;
231
+ break;
232
+ }
233
+ _context4.next = 17;
234
+ return handleFacebookPKCEFlow({
235
+ code: code,
236
+ publicKey: publicKey,
237
+ openModal: openModal,
238
+ clientId: clientId,
239
+ redirectURI: redirectURI,
240
+ callbacks: callbacks,
241
+ completeOauth: completeOauth,
242
+ onPushPage: function onPushPage(oidcToken) {
243
+ return new Promise(function (resolve, reject) {
244
+ pushPage({
245
+ key: "Facebook OAuth",
246
+ content: jsx(ActionPage, {
247
+ title: "Authenticating with Facebook...",
248
+ action: function () {
249
+ var _action = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
250
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
251
+ while (1) switch (_context2.prev = _context2.next) {
252
+ case 0:
253
+ _context2.prev = 0;
254
+ _context2.next = 3;
255
+ return completeOauth({
256
+ oidcToken: oidcToken,
257
+ publicKey: publicKey,
258
+ providerName: "facebook"
259
+ });
260
+ case 3:
261
+ resolve();
262
+ _context2.next = 9;
263
+ break;
264
+ case 6:
265
+ _context2.prev = 6;
266
+ _context2.t0 = _context2["catch"](0);
267
+ reject(_context2.t0);
268
+ case 9:
269
+ case "end":
270
+ return _context2.stop();
271
+ }
272
+ }, _callee2, null, [[0, 6]]);
273
+ }));
274
+ function action() {
275
+ return _action.apply(this, arguments);
276
+ }
277
+ return action;
278
+ }(),
279
+ icon: jsx(FontAwesomeIcon, {
280
+ size: "3x",
281
+ icon: faFacebook
282
+ })
283
+ }),
284
+ showTitle: false
285
+ });
286
+ });
287
+ }
288
+ })["catch"](function (error) {
289
+ // Handle errors
290
+ if (callbacks !== null && callbacks !== void 0 && callbacks.onError) {
291
+ callbacks.onError(error instanceof TurnkeyError ? error : new TurnkeyError("Facebook authentication failed", TurnkeyErrorCodes.OAUTH_SIGNUP_ERROR, error));
292
+ }
293
+ });
294
+ case 17:
295
+ _context4.next = 32;
296
+ break;
297
+ case 19:
298
+ if (!window.location.hash) {
299
+ _context4.next = 32;
300
+ break;
301
+ }
302
+ hash = window.location.hash.substring(1); // Parse the hash using our helper functions
303
+ _parseOAuthRedirect = parseOAuthRedirect(hash), idToken = _parseOAuthRedirect.idToken, _provider = _parseOAuthRedirect.provider, _flow = _parseOAuthRedirect.flow, _publicKey = _parseOAuthRedirect.publicKey, _openModal = _parseOAuthRedirect.openModal;
304
+ if (!(idToken && _flow === "redirect" && _publicKey)) {
305
+ _context4.next = 32;
306
+ break;
307
+ }
308
+ if (!(_openModal === "true")) {
309
+ _context4.next = 30;
310
+ break;
311
+ }
312
+ providerName = _provider ? _provider.charAt(0).toUpperCase() + _provider.slice(1) : "Provider"; // Determine which icon to show based on the provider
313
+ if (_provider === "apple") {
314
+ icon = jsx(FontAwesomeIcon, {
315
+ size: "3x",
316
+ icon: faApple
317
+ });
318
+ } else {
319
+ // Default to Google icon
320
+ icon = jsx(FontAwesomeIcon, {
321
+ size: "3x",
322
+ icon: faGoogle
323
+ });
324
+ }
325
+ // This state is set when the OAuth flow comes from the AuthComponent
326
+ _context4.next = 28;
327
+ return new Promise(function (resolve, reject) {
328
+ pushPage({
329
+ key: "".concat(providerName, " OAuth"),
330
+ content: jsx(ActionPage, {
331
+ title: "Authenticating with ".concat(providerName, "..."),
332
+ action: function () {
333
+ var _action2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
334
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
335
+ while (1) switch (_context3.prev = _context3.next) {
336
+ case 0:
337
+ _context3.prev = 0;
338
+ _context3.next = 3;
339
+ return completeOauth(_objectSpread2({
340
+ oidcToken: idToken,
341
+ publicKey: _publicKey
342
+ }, _provider ? {
343
+ providerName: _provider
344
+ } : {}));
345
+ case 3:
346
+ resolve(null);
347
+ _context3.next = 9;
348
+ break;
349
+ case 6:
350
+ _context3.prev = 6;
351
+ _context3.t0 = _context3["catch"](0);
352
+ reject(_context3.t0);
353
+ case 9:
354
+ case "end":
355
+ return _context3.stop();
356
+ }
357
+ }, _callee3, null, [[0, 6]]);
358
+ }));
359
+ function action() {
360
+ return _action2.apply(this, arguments);
361
+ }
362
+ return action;
363
+ }(),
364
+ icon: icon
365
+ }),
366
+ showTitle: false
367
+ });
368
+ });
369
+ case 28:
370
+ _context4.next = 31;
371
+ break;
372
+ case 30:
373
+ if (callbacks !== null && callbacks !== void 0 && callbacks.onOauthRedirect) {
374
+ callbacks.onOauthRedirect({
375
+ idToken: idToken,
376
+ publicKey: _publicKey
377
+ });
378
+ } else {
379
+ completeOauth(_objectSpread2({
380
+ oidcToken: idToken,
381
+ publicKey: _publicKey
382
+ }, _provider ? {
383
+ providerName: _provider
384
+ } : {}));
385
+ }
386
+ case 31:
387
+ // Clean up the URL after processing
388
+ window.history.replaceState(null, document.title, window.location.pathname + window.location.search);
389
+ case 32:
390
+ case "end":
391
+ return _context4.stop();
392
+ }
393
+ }, _callee4);
394
+ }));
395
+ return function completeRedirectOauth() {
396
+ return _ref3.apply(this, arguments);
397
+ };
398
+ }();
399
+ var buildConfig = function buildConfig(proxyAuthConfig) {
400
+ var _config$auth$methods$, _config$auth, _config$auth$methods, _config$auth$methods$2, _config$auth2, _config$auth2$methods, _config$auth$methods$3, _config$auth3, _config$auth3$methods, _config$auth$methods$4, _config$auth4, _config$auth4$methods, _config$auth$methods$5, _config$auth5, _config$auth5$methods, _config$auth$methods$6, _config$auth6, _config$auth6$methods, _config$auth$methods$7, _config$auth7, _config$auth7$methods, _config$auth$oauthOrd, _config$auth8, _config$auth$methodOr, _config$auth9, _config$auth0, _config$auth1, _config$auth1$oauthCo, _config$walletConfig, _ref4, _resolvedMethods$wall, _config$walletConfig2, _config$walletConfig3, _config$walletConfig$, _config$walletConfig4, _config$walletConfig5, _config$walletConfig6, _config$walletConfig7, _config$walletConfig8, _config$walletConfig9, _config$walletConfig0, _config$importIframeU, _config$exportIframeU;
401
+ // Juggle the local overrides with the values set in the dashboard (proxyAuthConfig).
402
+ var resolvedMethods = {
403
+ emailOtpAuthEnabled: (_config$auth$methods$ = (_config$auth = config.auth) === null || _config$auth === void 0 ? void 0 : (_config$auth$methods = _config$auth.methods) === null || _config$auth$methods === void 0 ? void 0 : _config$auth$methods.emailOtpAuthEnabled) !== null && _config$auth$methods$ !== void 0 ? _config$auth$methods$ : proxyAuthConfig === null || proxyAuthConfig === void 0 ? void 0 : proxyAuthConfig.enabledProviders.includes("email"),
404
+ smsOtpAuthEnabled: (_config$auth$methods$2 = (_config$auth2 = config.auth) === null || _config$auth2 === void 0 ? void 0 : (_config$auth2$methods = _config$auth2.methods) === null || _config$auth2$methods === void 0 ? void 0 : _config$auth2$methods.smsOtpAuthEnabled) !== null && _config$auth$methods$2 !== void 0 ? _config$auth$methods$2 : proxyAuthConfig === null || proxyAuthConfig === void 0 ? void 0 : proxyAuthConfig.enabledProviders.includes("sms"),
405
+ passkeyAuthEnabled: (_config$auth$methods$3 = (_config$auth3 = config.auth) === null || _config$auth3 === void 0 ? void 0 : (_config$auth3$methods = _config$auth3.methods) === null || _config$auth3$methods === void 0 ? void 0 : _config$auth3$methods.passkeyAuthEnabled) !== null && _config$auth$methods$3 !== void 0 ? _config$auth$methods$3 : proxyAuthConfig === null || proxyAuthConfig === void 0 ? void 0 : proxyAuthConfig.enabledProviders.includes("passkey"),
406
+ walletAuthEnabled: (_config$auth$methods$4 = (_config$auth4 = config.auth) === null || _config$auth4 === void 0 ? void 0 : (_config$auth4$methods = _config$auth4.methods) === null || _config$auth4$methods === void 0 ? void 0 : _config$auth4$methods.walletAuthEnabled) !== null && _config$auth$methods$4 !== void 0 ? _config$auth$methods$4 : proxyAuthConfig === null || proxyAuthConfig === void 0 ? void 0 : proxyAuthConfig.enabledProviders.includes("wallet"),
407
+ googleOauthEnabled: (_config$auth$methods$5 = (_config$auth5 = config.auth) === null || _config$auth5 === void 0 ? void 0 : (_config$auth5$methods = _config$auth5.methods) === null || _config$auth5$methods === void 0 ? void 0 : _config$auth5$methods.googleOauthEnabled) !== null && _config$auth$methods$5 !== void 0 ? _config$auth$methods$5 : proxyAuthConfig === null || proxyAuthConfig === void 0 ? void 0 : proxyAuthConfig.enabledProviders.includes("google"),
408
+ appleOauthEnabled: (_config$auth$methods$6 = (_config$auth6 = config.auth) === null || _config$auth6 === void 0 ? void 0 : (_config$auth6$methods = _config$auth6.methods) === null || _config$auth6$methods === void 0 ? void 0 : _config$auth6$methods.appleOauthEnabled) !== null && _config$auth$methods$6 !== void 0 ? _config$auth$methods$6 : proxyAuthConfig === null || proxyAuthConfig === void 0 ? void 0 : proxyAuthConfig.enabledProviders.includes("apple"),
409
+ facebookOauthEnabled: (_config$auth$methods$7 = (_config$auth7 = config.auth) === null || _config$auth7 === void 0 ? void 0 : (_config$auth7$methods = _config$auth7.methods) === null || _config$auth7$methods === void 0 ? void 0 : _config$auth7$methods.facebookOauthEnabled) !== null && _config$auth$methods$7 !== void 0 ? _config$auth$methods$7 : proxyAuthConfig === null || proxyAuthConfig === void 0 ? void 0 : proxyAuthConfig.enabledProviders.includes("facebook")
410
+ };
411
+ // Set a default ordering for the oAuth methods
412
+ var oauthOrder = (_config$auth$oauthOrd = (_config$auth8 = config.auth) === null || _config$auth8 === void 0 ? void 0 : _config$auth8.oauthOrder) !== null && _config$auth$oauthOrd !== void 0 ? _config$auth$oauthOrd : ["google", "apple", "facebook"].filter(function (provider) {
413
+ return resolvedMethods["".concat(provider, "OauthEnabled")];
414
+ });
415
+ // Set a default ordering for the overall auth methods
416
+ var methodOrder = (_config$auth$methodOr = (_config$auth9 = config.auth) === null || _config$auth9 === void 0 ? void 0 : _config$auth9.methodOrder) !== null && _config$auth$methodOr !== void 0 ? _config$auth$methodOr : [oauthOrder.length > 0 ? "socials" : null, resolvedMethods.emailOtpAuthEnabled ? "email" : null, resolvedMethods.smsOtpAuthEnabled ? "sms" : null, resolvedMethods.passkeyAuthEnabled ? "passkey" : null, resolvedMethods.walletAuthEnabled ? "wallet" : null].filter(Boolean);
417
+ return _objectSpread2(_objectSpread2({}, config), {}, {
418
+ // Overrides:
419
+ auth: _objectSpread2(_objectSpread2({}, config.auth), {}, {
420
+ methods: resolvedMethods,
421
+ oauthConfig: _objectSpread2(_objectSpread2({}, (_config$auth0 = config.auth) === null || _config$auth0 === void 0 ? void 0 : _config$auth0.oauthConfig), {}, {
422
+ openOauthInPage: (_config$auth1 = config.auth) === null || _config$auth1 === void 0 ? void 0 : (_config$auth1$oauthCo = _config$auth1.oauthConfig) === null || _config$auth1$oauthCo === void 0 ? void 0 : _config$auth1$oauthCo.openOauthInPage
423
+ }),
424
+ sessionExpirationSeconds: proxyAuthConfig === null || proxyAuthConfig === void 0 ? void 0 : proxyAuthConfig.sessionExpirationSeconds,
425
+ methodOrder: methodOrder,
426
+ oauthOrder: oauthOrder
427
+ }),
428
+ walletConfig: _objectSpread2(_objectSpread2({}, config.walletConfig), {}, {
429
+ features: _objectSpread2(_objectSpread2({}, (_config$walletConfig = config.walletConfig) === null || _config$walletConfig === void 0 ? void 0 : _config$walletConfig.features), {}, {
430
+ auth: // If walletAuthEnabled is not set, default to true. Wallet auth can be enabled/disabled in the dashboard or by explicitly changing the walletAuthEnabled / walletConfig auth feature.
431
+ (_ref4 = (_resolvedMethods$wall = resolvedMethods.walletAuthEnabled) !== null && _resolvedMethods$wall !== void 0 ? _resolvedMethods$wall : (_config$walletConfig2 = config.walletConfig) === null || _config$walletConfig2 === void 0 ? void 0 : (_config$walletConfig3 = _config$walletConfig2.features) === null || _config$walletConfig3 === void 0 ? void 0 : _config$walletConfig3.auth) !== null && _ref4 !== void 0 ? _ref4 : true,
432
+ connecting: (_config$walletConfig$ = (_config$walletConfig4 = config.walletConfig) === null || _config$walletConfig4 === void 0 ? void 0 : (_config$walletConfig5 = _config$walletConfig4.features) === null || _config$walletConfig5 === void 0 ? void 0 : _config$walletConfig5.connecting) !== null && _config$walletConfig$ !== void 0 ? _config$walletConfig$ : true // Default connecting to true if not set. We don't care about auth settings here.
433
+ }),
434
+ chains: _objectSpread2(_objectSpread2({}, (_config$walletConfig6 = config.walletConfig) === null || _config$walletConfig6 === void 0 ? void 0 : _config$walletConfig6.chains), {}, {
435
+ ethereum: _objectSpread2(_objectSpread2({}, (_config$walletConfig7 = config.walletConfig) === null || _config$walletConfig7 === void 0 ? void 0 : (_config$walletConfig8 = _config$walletConfig7.chains) === null || _config$walletConfig8 === void 0 ? void 0 : _config$walletConfig8.ethereum), {}, {
436
+ "native": true // Always enable native Ethereum support
437
+ }),
438
+ solana: _objectSpread2(_objectSpread2({}, (_config$walletConfig9 = config.walletConfig) === null || _config$walletConfig9 === void 0 ? void 0 : (_config$walletConfig0 = _config$walletConfig9.chains) === null || _config$walletConfig0 === void 0 ? void 0 : _config$walletConfig0.solana), {}, {
439
+ "native": true // Always enable native Solana support
440
+ })
441
+ })
442
+ }),
443
+ importIframeUrl: (_config$importIframeU = config.importIframeUrl) !== null && _config$importIframeU !== void 0 ? _config$importIframeU : "https://import.turnkey.com",
444
+ exportIframeUrl: (_config$exportIframeU = config.exportIframeUrl) !== null && _config$exportIframeU !== void 0 ? _config$exportIframeU : "https://export.turnkey.com"
445
+ });
446
+ };
447
+ /**
448
+ * Initializes the Turnkey client with the provided configuration.
449
+ * This function sets up the client, fetches the proxy auth config if needed,
450
+ * and prepares the client for use in authentication and wallet operations.
451
+ *
452
+ * @internal
453
+ */
454
+ var initializeClient = /*#__PURE__*/function () {
455
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
456
+ var _masterConfig$passkey, _masterConfig$passkey2, _masterConfig$passkey3, _masterConfig$passkey4, _masterConfig$walletC, _masterConfig$walletC2, _masterConfig$walletC3, _masterConfig$auth$au, _masterConfig$auth3, turnkeyClient, _callbacks$onError, _callbacks$onError2;
457
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
458
+ while (1) switch (_context5.prev = _context5.next) {
459
+ case 0:
460
+ if (!(!masterConfig || client || clientState == ClientState.Loading)) {
461
+ _context5.next = 2;
462
+ break;
463
+ }
464
+ return _context5.abrupt("return");
465
+ case 2:
466
+ _context5.prev = 2;
467
+ setClientState(ClientState.Loading);
468
+ turnkeyClient = new TurnkeyClient({
469
+ apiBaseUrl: masterConfig.apiBaseUrl,
470
+ authProxyUrl: masterConfig.authProxyUrl,
471
+ authProxyConfigId: masterConfig.authProxyConfigId,
472
+ organizationId: masterConfig.organizationId,
473
+ // Define passkey and wallet config here. If we don't pass it into the client, Mr. Client will assume that we don't want to use passkeys/wallets and not create the stamper!
474
+ passkeyConfig: {
475
+ rpId: (_masterConfig$passkey = masterConfig.passkeyConfig) === null || _masterConfig$passkey === void 0 ? void 0 : _masterConfig$passkey.rpId,
476
+ timeout: ((_masterConfig$passkey2 = masterConfig.passkeyConfig) === null || _masterConfig$passkey2 === void 0 ? void 0 : _masterConfig$passkey2.timeout) || 60000,
477
+ // 60 seconds
478
+ userVerification: ((_masterConfig$passkey3 = masterConfig.passkeyConfig) === null || _masterConfig$passkey3 === void 0 ? void 0 : _masterConfig$passkey3.userVerification) || "preferred",
479
+ allowCredentials: ((_masterConfig$passkey4 = masterConfig.passkeyConfig) === null || _masterConfig$passkey4 === void 0 ? void 0 : _masterConfig$passkey4.allowCredentials) || []
480
+ },
481
+ walletConfig: _objectSpread2({
482
+ features: _objectSpread2({}, (_masterConfig$walletC = masterConfig.walletConfig) === null || _masterConfig$walletC === void 0 ? void 0 : _masterConfig$walletC.features),
483
+ chains: _objectSpread2({}, (_masterConfig$walletC2 = masterConfig.walletConfig) === null || _masterConfig$walletC2 === void 0 ? void 0 : _masterConfig$walletC2.chains)
484
+ }, ((_masterConfig$walletC3 = masterConfig.walletConfig) === null || _masterConfig$walletC3 === void 0 ? void 0 : _masterConfig$walletC3.walletConnect) && {
485
+ walletConnect: masterConfig.walletConfig.walletConnect
486
+ })
487
+ });
488
+ setAutoRefreshSession((_masterConfig$auth$au = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth3 = masterConfig.auth) === null || _masterConfig$auth3 === void 0 ? void 0 : _masterConfig$auth3.autoRefreshSession) !== null && _masterConfig$auth$au !== void 0 ? _masterConfig$auth$au : false);
489
+ _context5.next = 8;
490
+ return turnkeyClient.init();
491
+ case 8:
492
+ setClient(turnkeyClient);
493
+ // Don't set clientState to ready until we fetch the proxy auth config (See other fetchProxyAuthConfig useEffect)
494
+ _context5.next = 15;
495
+ break;
496
+ case 11:
497
+ _context5.prev = 11;
498
+ _context5.t0 = _context5["catch"](2);
499
+ setClientState(ClientState.Error);
500
+ if (_context5.t0 instanceof TurnkeyError || _context5.t0 instanceof TurnkeyNetworkError) {
501
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError = callbacks.onError) === null || _callbacks$onError === void 0 ? void 0 : _callbacks$onError.call(callbacks, _context5.t0);
502
+ } else {
503
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError2 = callbacks.onError) === null || _callbacks$onError2 === void 0 ? void 0 : _callbacks$onError2.call(callbacks, new TurnkeyError("Failed to initialize Turnkey client", TurnkeyErrorCodes.INITIALIZE_CLIENT_ERROR, _context5.t0));
504
+ }
505
+ case 15:
506
+ case "end":
507
+ return _context5.stop();
508
+ }
509
+ }, _callee5, null, [[2, 11]]);
510
+ }));
511
+ return function initializeClient() {
512
+ return _ref5.apply(this, arguments);
513
+ };
514
+ }();
515
+ /**
516
+ * Initializes the user sessions by fetching all active sessions and setting up their state.
517
+ * @internal
518
+ */
519
+ var initializeSessions = /*#__PURE__*/function () {
520
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
521
+ var _allSessions, activeSessionKey, _callbacks$onError3, _callbacks$onError4;
522
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
523
+ while (1) switch (_context7.prev = _context7.next) {
524
+ case 0:
525
+ _context7.prev = 0;
526
+ _context7.next = 3;
527
+ return getAllSessions();
528
+ case 3:
529
+ _allSessions = _context7.sent;
530
+ if (_allSessions) {
531
+ _context7.next = 6;
532
+ break;
533
+ }
534
+ return _context7.abrupt("return");
535
+ case 6:
536
+ _context7.next = 8;
537
+ return Promise.all(Object.keys(_allSessions).map(/*#__PURE__*/function () {
538
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(sessionKey) {
539
+ var session;
540
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
541
+ while (1) switch (_context6.prev = _context6.next) {
542
+ case 0:
543
+ session = _allSessions === null || _allSessions === void 0 ? void 0 : _allSessions[sessionKey];
544
+ if (isValidSession(session)) {
545
+ _context6.next = 5;
546
+ break;
547
+ }
548
+ _context6.next = 4;
549
+ return clearSession({
550
+ sessionKey: sessionKey
551
+ });
552
+ case 4:
553
+ return _context6.abrupt("return");
554
+ case 5:
555
+ scheduleSessionExpiration({
556
+ sessionKey: sessionKey,
557
+ expiry: session.expiry
558
+ });
559
+ case 6:
560
+ case "end":
561
+ return _context6.stop();
562
+ }
563
+ }, _callee6);
564
+ }));
565
+ return function (_x) {
566
+ return _ref7.apply(this, arguments);
567
+ };
568
+ }()));
569
+ case 8:
570
+ setAllSessions(_allSessions);
571
+ _context7.next = 11;
572
+ return client === null || client === void 0 ? void 0 : client.getActiveSessionKey();
573
+ case 11:
574
+ activeSessionKey = _context7.sent;
575
+ if (!activeSessionKey) {
576
+ _context7.next = 19;
577
+ break;
578
+ }
579
+ setSession(_allSessions === null || _allSessions === void 0 ? void 0 : _allSessions[activeSessionKey]);
580
+ _context7.next = 16;
581
+ return refreshUser();
582
+ case 16:
583
+ _context7.next = 18;
584
+ return refreshWallets();
585
+ case 18:
586
+ return _context7.abrupt("return");
587
+ case 19:
588
+ _context7.next = 24;
589
+ break;
590
+ case 21:
591
+ _context7.prev = 21;
592
+ _context7.t0 = _context7["catch"](0);
593
+ if (_context7.t0 instanceof TurnkeyError || _context7.t0 instanceof TurnkeyNetworkError) {
594
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError3 = callbacks.onError) === null || _callbacks$onError3 === void 0 ? void 0 : _callbacks$onError3.call(callbacks, _context7.t0);
595
+ } else {
596
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError4 = callbacks.onError) === null || _callbacks$onError4 === void 0 ? void 0 : _callbacks$onError4.call(callbacks, new TurnkeyError("Failed to initialize sessions", TurnkeyErrorCodes.INITIALIZE_SESSION_ERROR, _context7.t0));
597
+ }
598
+ case 24:
599
+ case "end":
600
+ return _context7.stop();
601
+ }
602
+ }, _callee7, null, [[0, 21]]);
603
+ }));
604
+ return function initializeSessions() {
605
+ return _ref6.apply(this, arguments);
606
+ };
607
+ }();
608
+ /**
609
+ * @internal
610
+ * Schedules a session expiration and warning timeout for the given session key.
611
+ *
612
+ * - This function sets up two timeouts: one for warning before the session expires and another to expire the session.
613
+ * - The warning timeout is set to trigger before the session expires, allowing for actions like refreshing the session.
614
+ * - The expiration timeout clears the session and triggers any necessary callbacks.
615
+ *
616
+ * @param params.sessionKey - The key of the session to schedule expiration for.
617
+ * @param params.expiry - The expiration time in seconds for the session.
618
+ * @throws {TurnkeyError} If an error occurs while scheduling the session expiration.
619
+ */
620
+ function scheduleSessionExpiration(_x2) {
621
+ return _scheduleSessionExpiration.apply(this, arguments);
622
+ }
623
+ /**
624
+ * Clears all scheduled session expiration and warning timeouts for the client.
625
+ *
626
+ * - This function removes all active session expiration and warning timeouts managed by the provider.
627
+ * - It is called automatically when sessions are re-initialized or on logout to prevent memory leaks and ensure no stale timeouts remain.
628
+ * - All timeouts stored in `expiryTimeoutsRef` are cleared and the reference is reset.
629
+ *
630
+ * @throws {TurnkeyError} If an error occurs while clearing the timeouts.
631
+ */
632
+ function _scheduleSessionExpiration() {
633
+ _scheduleSessionExpiration = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
634
+ var sessionKey, expiry, timeUntilExpiry, _beforeExpiry, expireSession, _callbacks$onError0, _callbacks$onError1;
635
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
636
+ while (1) switch (_context29.prev = _context29.next) {
637
+ case 0:
638
+ sessionKey = params.sessionKey, expiry = params.expiry;
639
+ try {
640
+ // Clear any existing timeout for this session key
641
+ if (expiryTimeoutsRef.current[sessionKey]) {
642
+ clearTimeout(expiryTimeoutsRef.current[sessionKey]);
643
+ delete expiryTimeoutsRef.current[sessionKey];
644
+ }
645
+ if (expiryTimeoutsRef.current["".concat(sessionKey, "-warning")]) {
646
+ clearTimeout(expiryTimeoutsRef.current["".concat(sessionKey, "-warning")]);
647
+ delete expiryTimeoutsRef.current["".concat(sessionKey, "-warning")];
648
+ }
649
+ timeUntilExpiry = expiry * 1000 - Date.now();
650
+ _beforeExpiry = /*#__PURE__*/function () {
651
+ var _ref33 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
652
+ var _callbacks$beforeSess;
653
+ var activeSession, session;
654
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
655
+ while (1) switch (_context27.prev = _context27.next) {
656
+ case 0:
657
+ _context27.next = 2;
658
+ return getSession();
659
+ case 2:
660
+ activeSession = _context27.sent;
661
+ if (!(!activeSession && expiryTimeoutsRef.current[sessionKey])) {
662
+ _context27.next = 7;
663
+ break;
664
+ }
665
+ clearTimeout(expiryTimeoutsRef.current["".concat(sessionKey, "-warning")]);
666
+ expiryTimeoutsRef.current["".concat(sessionKey, "-warning")] = setTimeout(_beforeExpiry, 10000);
667
+ return _context27.abrupt("return");
668
+ case 7:
669
+ _context27.next = 9;
670
+ return getSession({
671
+ sessionKey: sessionKey
672
+ });
673
+ case 9:
674
+ session = _context27.sent;
675
+ if (session) {
676
+ _context27.next = 12;
677
+ break;
678
+ }
679
+ return _context27.abrupt("return");
680
+ case 12:
681
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$beforeSess = callbacks.beforeSessionExpiry) === null || _callbacks$beforeSess === void 0 ? void 0 : _callbacks$beforeSess.call(callbacks, {
682
+ sessionKey: sessionKey
683
+ });
684
+ if (!autoRefreshSession) {
685
+ _context27.next = 16;
686
+ break;
687
+ }
688
+ _context27.next = 16;
689
+ return refreshSession({
690
+ expirationSeconds: session.expirationSeconds,
691
+ sessionKey: sessionKey
692
+ });
693
+ case 16:
694
+ case "end":
695
+ return _context27.stop();
696
+ }
697
+ }, _callee27);
698
+ }));
699
+ return function beforeExpiry() {
700
+ return _ref33.apply(this, arguments);
701
+ };
702
+ }();
703
+ expireSession = /*#__PURE__*/function () {
704
+ var _ref34 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
705
+ var _callbacks$onSessionE;
706
+ var expiredSession;
707
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
708
+ while (1) switch (_context28.prev = _context28.next) {
709
+ case 0:
710
+ _context28.next = 2;
711
+ return getSession({
712
+ sessionKey: sessionKey
713
+ });
714
+ case 2:
715
+ expiredSession = _context28.sent;
716
+ if (expiredSession) {
717
+ _context28.next = 5;
718
+ break;
719
+ }
720
+ return _context28.abrupt("return");
721
+ case 5:
722
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onSessionE = callbacks.onSessionExpired) === null || _callbacks$onSessionE === void 0 ? void 0 : _callbacks$onSessionE.call(callbacks, {
723
+ sessionKey: sessionKey
724
+ });
725
+ _context28.next = 8;
726
+ return clearSession({
727
+ sessionKey: sessionKey
728
+ });
729
+ case 8:
730
+ delete expiryTimeoutsRef.current[sessionKey];
731
+ delete expiryTimeoutsRef.current["".concat(sessionKey, "-warning")];
732
+ _context28.next = 12;
733
+ return logout();
734
+ case 12:
735
+ case "end":
736
+ return _context28.stop();
737
+ }
738
+ }, _callee28);
739
+ }));
740
+ return function expireSession() {
741
+ return _ref34.apply(this, arguments);
742
+ };
743
+ }();
744
+ if (timeUntilExpiry <= SESSION_WARNING_THRESHOLD_MS) {
745
+ _beforeExpiry();
746
+ } else {
747
+ expiryTimeoutsRef.current["".concat(sessionKey, "-warning")] = setTimeout(_beforeExpiry, timeUntilExpiry - SESSION_WARNING_THRESHOLD_MS);
748
+ }
749
+ expiryTimeoutsRef.current[sessionKey] = setTimeout(expireSession, timeUntilExpiry);
750
+ } catch (error) {
751
+ if (error instanceof TurnkeyError || error instanceof TurnkeyNetworkError) {
752
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError0 = callbacks.onError) === null || _callbacks$onError0 === void 0 ? void 0 : _callbacks$onError0.call(callbacks, error);
753
+ } else {
754
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError1 = callbacks.onError) === null || _callbacks$onError1 === void 0 ? void 0 : _callbacks$onError1.call(callbacks, new TurnkeyError("Failed to schedule session expiration for ".concat(sessionKey), TurnkeyErrorCodes.SCHEDULE_SESSION_EXPIRY_ERROR, error));
755
+ }
756
+ }
757
+ case 2:
758
+ case "end":
759
+ return _context29.stop();
760
+ }
761
+ }, _callee29);
762
+ }));
763
+ return _scheduleSessionExpiration.apply(this, arguments);
764
+ }
765
+ function clearSessionTimeouts() {
766
+ try {
767
+ Object.values(expiryTimeoutsRef.current).forEach(function (timeout) {
768
+ clearTimeout(timeout);
769
+ });
770
+ expiryTimeoutsRef.current = {};
771
+ } catch (error) {
772
+ if (error instanceof TurnkeyError || error instanceof TurnkeyNetworkError) {
773
+ var _callbacks$onError5;
774
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError5 = callbacks.onError) === null || _callbacks$onError5 === void 0 ? void 0 : _callbacks$onError5.call(callbacks, error);
775
+ } else {
776
+ var _callbacks$onError6;
777
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError6 = callbacks.onError) === null || _callbacks$onError6 === void 0 ? void 0 : _callbacks$onError6.call(callbacks, new TurnkeyError("Failed to clear session timeouts", TurnkeyErrorCodes.CLEAR_SESSION_TIMEOUTS_ERROR, error));
778
+ }
779
+ }
780
+ }
781
+ /**
782
+ * @internal
783
+ * Handles the post-authentication flow.
784
+ *
785
+ * - This function is called after a successful authentication (login or sign-up) via any supported method (Passkey, Wallet, OTP, OAuth).
786
+ * - It fetches the active session and all sessions, updates the session state, and schedules session expiration and warning timeouts.
787
+ * - It also refreshes the user's wallets and profile information to ensure the provider state is up to date.
788
+ * - This function is used internally after all authentication flows to synchronize state and trigger any necessary callbacks.
789
+ *
790
+ * @returns A void promise.
791
+ * @throws {TurnkeyError} If the client is not initialized or if there is an error during the process.
792
+ */
793
+ var handlePostAuth = /*#__PURE__*/function () {
794
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
795
+ var sessionKey, _session, _allSessions2, _callbacks$onError7, _callbacks$onError8;
796
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
797
+ while (1) switch (_context8.prev = _context8.next) {
798
+ case 0:
799
+ _context8.prev = 0;
800
+ _context8.next = 3;
801
+ return getActiveSessionKey();
802
+ case 3:
803
+ sessionKey = _context8.sent;
804
+ _context8.next = 6;
805
+ return getSession(_objectSpread2({}, sessionKey && {
806
+ sessionKey: sessionKey
807
+ }));
808
+ case 6:
809
+ _session = _context8.sent;
810
+ if (!(_session && sessionKey)) {
811
+ _context8.next = 10;
812
+ break;
813
+ }
814
+ _context8.next = 10;
815
+ return scheduleSessionExpiration({
816
+ sessionKey: sessionKey,
817
+ expiry: _session.expiry
818
+ });
819
+ case 10:
820
+ _context8.next = 12;
821
+ return client.getAllSessions();
822
+ case 12:
823
+ _allSessions2 = _context8.sent;
824
+ setSession(_session);
825
+ setAllSessions(_allSessions2);
826
+ _context8.next = 17;
827
+ return refreshWallets();
828
+ case 17:
829
+ _context8.next = 19;
830
+ return refreshUser();
831
+ case 19:
832
+ _context8.next = 24;
833
+ break;
834
+ case 21:
835
+ _context8.prev = 21;
836
+ _context8.t0 = _context8["catch"](0);
837
+ if (_context8.t0 instanceof TurnkeyError || _context8.t0 instanceof TurnkeyNetworkError) {
838
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError7 = callbacks.onError) === null || _callbacks$onError7 === void 0 ? void 0 : _callbacks$onError7.call(callbacks, _context8.t0);
839
+ } else {
840
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError8 = callbacks.onError) === null || _callbacks$onError8 === void 0 ? void 0 : _callbacks$onError8.call(callbacks, new TurnkeyError("Failed to handle post-authentication", TurnkeyErrorCodes.HANDLE_POST_AUTH_ERROR, _context8.t0));
841
+ }
842
+ case 24:
843
+ case "end":
844
+ return _context8.stop();
845
+ }
846
+ }, _callee8, null, [[0, 21]]);
847
+ }));
848
+ return function handlePostAuth() {
849
+ return _ref8.apply(this, arguments);
850
+ };
851
+ }();
852
+ /**
853
+ * @internal
854
+ * Handles the post-logout flow.
855
+ *
856
+ * - This function is called after a successful logout or session clear.
857
+ * - It clears all scheduled session expiration and warning timeouts to prevent memory leaks.
858
+ * - It resets the session state, removes all session and user data from memory, and clears the wallets list.
859
+ * - This ensures that all sensitive information is removed from the provider state after logout.
860
+ * - Called internally after logout or when all sessions are cleared.
861
+ *
862
+ * @returns void
863
+ * @throws {TurnkeyError} If there is an error during the post-logout process.
864
+ */
865
+ var handlePostLogout = function handlePostLogout() {
866
+ try {
867
+ clearSessionTimeouts();
868
+ setSession(undefined);
869
+ setAllSessions(undefined);
870
+ setUser(undefined);
871
+ setWallets([]);
872
+ } catch (error) {
873
+ var _callbacks$onError9;
874
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError9 = callbacks.onError) === null || _callbacks$onError9 === void 0 ? void 0 : _callbacks$onError9.call(callbacks, new TurnkeyError("Failed to initialize sessions", TurnkeyErrorCodes.HANDLE_POST_LOGOUT_ERROR, error));
875
+ }
876
+ };
877
+ function createPasskey(_x3) {
878
+ return _createPasskey.apply(this, arguments);
879
+ }
880
+ function _createPasskey() {
881
+ _createPasskey = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
882
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
883
+ while (1) switch (_context30.prev = _context30.next) {
884
+ case 0:
885
+ if (client) {
886
+ _context30.next = 2;
887
+ break;
888
+ }
889
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
890
+ case 2:
891
+ return _context30.abrupt("return", withTurnkeyErrorHandling(function () {
892
+ return client.createPasskey(_objectSpread2({}, params));
893
+ }, callbacks, "Failed to create passkey"));
894
+ case 3:
895
+ case "end":
896
+ return _context30.stop();
897
+ }
898
+ }, _callee30);
899
+ }));
900
+ return _createPasskey.apply(this, arguments);
901
+ }
902
+ function logout(_x4) {
903
+ return _logout.apply(this, arguments);
904
+ }
905
+ function _logout() {
906
+ _logout = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
907
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
908
+ while (1) switch (_context31.prev = _context31.next) {
909
+ case 0:
910
+ if (client) {
911
+ _context31.next = 2;
912
+ break;
913
+ }
914
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
915
+ case 2:
916
+ withTurnkeyErrorHandling(function () {
917
+ return client.logout(params);
918
+ }, callbacks, "Failed to logout");
919
+ handlePostLogout();
920
+ return _context31.abrupt("return");
921
+ case 5:
922
+ case "end":
923
+ return _context31.stop();
924
+ }
925
+ }, _callee31);
926
+ }));
927
+ return _logout.apply(this, arguments);
928
+ }
929
+ function loginWithPasskey(_x5) {
930
+ return _loginWithPasskey.apply(this, arguments);
931
+ }
932
+ function _loginWithPasskey() {
933
+ _loginWithPasskey = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
934
+ var _masterConfig$auth$se, _masterConfig$auth6;
935
+ var expirationSeconds, res;
936
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
937
+ while (1) switch (_context32.prev = _context32.next) {
938
+ case 0:
939
+ if (client) {
940
+ _context32.next = 2;
941
+ break;
942
+ }
943
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
944
+ case 2:
945
+ expirationSeconds = (_masterConfig$auth$se = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth6 = masterConfig.auth) === null || _masterConfig$auth6 === void 0 ? void 0 : _masterConfig$auth6.sessionExpirationSeconds) !== null && _masterConfig$auth$se !== void 0 ? _masterConfig$auth$se : DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
946
+ _context32.next = 5;
947
+ return withTurnkeyErrorHandling(function () {
948
+ return client.loginWithPasskey(_objectSpread2(_objectSpread2({}, params), {}, {
949
+ expirationSeconds: expirationSeconds
950
+ }));
951
+ }, callbacks, "Failed to login with passkey");
952
+ case 5:
953
+ res = _context32.sent;
954
+ if (!res) {
955
+ _context32.next = 9;
956
+ break;
957
+ }
958
+ _context32.next = 9;
959
+ return handlePostAuth();
960
+ case 9:
961
+ return _context32.abrupt("return", res);
962
+ case 10:
963
+ case "end":
964
+ return _context32.stop();
965
+ }
966
+ }, _callee32);
967
+ }));
968
+ return _loginWithPasskey.apply(this, arguments);
969
+ }
970
+ function signUpWithPasskey(_x6) {
971
+ return _signUpWithPasskey.apply(this, arguments);
972
+ }
973
+ function _signUpWithPasskey() {
974
+ _signUpWithPasskey = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
975
+ var _params$createSubOrgP, _params, _masterConfig$auth7, _masterConfig$auth7$c, _masterConfig$auth$se2, _masterConfig$auth8, _ref35, _params$passkeyDispla, _params2, _masterConfig$auth9, _masterConfig$auth9$c, _masterConfig$auth9$c2;
976
+ var createSubOrgParams, expirationSeconds, websiteName, timestamp, passkeyName, res;
977
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
978
+ while (1) switch (_context33.prev = _context33.next) {
979
+ case 0:
980
+ if (client) {
981
+ _context33.next = 2;
982
+ break;
983
+ }
984
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
985
+ case 2:
986
+ if (masterConfig) {
987
+ _context33.next = 4;
988
+ break;
989
+ }
990
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.INVALID_CONFIGURATION);
991
+ case 4:
992
+ // If createSubOrgParams is not provided, use the default from masterConfig
993
+ createSubOrgParams = (_params$createSubOrgP = (_params = params) === null || _params === void 0 ? void 0 : _params.createSubOrgParams) !== null && _params$createSubOrgP !== void 0 ? _params$createSubOrgP : (_masterConfig$auth7 = masterConfig.auth) === null || _masterConfig$auth7 === void 0 ? void 0 : (_masterConfig$auth7$c = _masterConfig$auth7.createSuborgParams) === null || _masterConfig$auth7$c === void 0 ? void 0 : _masterConfig$auth7$c.passkeyAuth;
994
+ params = createSubOrgParams !== undefined ? _objectSpread2(_objectSpread2({}, params), {}, {
995
+ createSubOrgParams: createSubOrgParams
996
+ }) : _objectSpread2({}, params);
997
+ expirationSeconds = (_masterConfig$auth$se2 = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth8 = masterConfig.auth) === null || _masterConfig$auth8 === void 0 ? void 0 : _masterConfig$auth8.sessionExpirationSeconds) !== null && _masterConfig$auth$se2 !== void 0 ? _masterConfig$auth$se2 : DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
998
+ websiteName = window.location.hostname;
999
+ timestamp = new Date().toLocaleDateString() + "-" + new Date().toLocaleTimeString([], {
1000
+ hour: "2-digit",
1001
+ minute: "2-digit"
1002
+ }); // We allow passkeyName to be passed in thru the provider or thru the params of this function directly.
1003
+ // This is because signUpWithPasskey will create a new passkey using that name.
1004
+ // Any extra authenticators will be created after the first one. (see core implementation)
1005
+ passkeyName = (_ref35 = (_params$passkeyDispla = (_params2 = params) === null || _params2 === void 0 ? void 0 : _params2.passkeyDisplayName) !== null && _params$passkeyDispla !== void 0 ? _params$passkeyDispla : (_masterConfig$auth9 = masterConfig.auth) === null || _masterConfig$auth9 === void 0 ? void 0 : (_masterConfig$auth9$c = _masterConfig$auth9.createSuborgParams) === null || _masterConfig$auth9$c === void 0 ? void 0 : (_masterConfig$auth9$c2 = _masterConfig$auth9$c.passkeyAuth) === null || _masterConfig$auth9$c2 === void 0 ? void 0 : _masterConfig$auth9$c2.passkeyName) !== null && _ref35 !== void 0 ? _ref35 : "".concat(websiteName, "-").concat(timestamp);
1006
+ _context33.next = 12;
1007
+ return withTurnkeyErrorHandling(function () {
1008
+ return client.signUpWithPasskey(_objectSpread2(_objectSpread2({}, params), {}, {
1009
+ passkeyDisplayName: passkeyName,
1010
+ expirationSeconds: expirationSeconds
1011
+ }));
1012
+ }, callbacks, "Failed to sign up with passkey");
1013
+ case 12:
1014
+ res = _context33.sent;
1015
+ if (!res) {
1016
+ _context33.next = 16;
1017
+ break;
1018
+ }
1019
+ _context33.next = 16;
1020
+ return handlePostAuth();
1021
+ case 16:
1022
+ return _context33.abrupt("return", res);
1023
+ case 17:
1024
+ case "end":
1025
+ return _context33.stop();
1026
+ }
1027
+ }, _callee33);
1028
+ }));
1029
+ return _signUpWithPasskey.apply(this, arguments);
1030
+ }
1031
+ function getWalletProviders(_x7) {
1032
+ return _getWalletProviders.apply(this, arguments);
1033
+ }
1034
+ function _getWalletProviders() {
1035
+ _getWalletProviders = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee34(chain) {
1036
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
1037
+ while (1) switch (_context34.prev = _context34.next) {
1038
+ case 0:
1039
+ if (client) {
1040
+ _context34.next = 2;
1041
+ break;
1042
+ }
1043
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1044
+ case 2:
1045
+ _context34.next = 4;
1046
+ return client.getWalletProviders(chain);
1047
+ case 4:
1048
+ return _context34.abrupt("return", _context34.sent);
1049
+ case 5:
1050
+ case "end":
1051
+ return _context34.stop();
1052
+ }
1053
+ }, _callee34);
1054
+ }));
1055
+ return _getWalletProviders.apply(this, arguments);
1056
+ }
1057
+ function connectWalletAccount(_x8) {
1058
+ return _connectWalletAccount.apply(this, arguments);
1059
+ }
1060
+ function _connectWalletAccount() {
1061
+ _connectWalletAccount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee35(walletProvider) {
1062
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
1063
+ while (1) switch (_context35.prev = _context35.next) {
1064
+ case 0:
1065
+ if (client) {
1066
+ _context35.next = 2;
1067
+ break;
1068
+ }
1069
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1070
+ case 2:
1071
+ _context35.next = 4;
1072
+ return client.connectWalletAccount(walletProvider);
1073
+ case 4:
1074
+ _context35.next = 6;
1075
+ return refreshWallets();
1076
+ case 6:
1077
+ case "end":
1078
+ return _context35.stop();
1079
+ }
1080
+ }, _callee35);
1081
+ }));
1082
+ return _connectWalletAccount.apply(this, arguments);
1083
+ }
1084
+ function disconnectWalletAccount(_x9) {
1085
+ return _disconnectWalletAccount.apply(this, arguments);
1086
+ }
1087
+ function _disconnectWalletAccount() {
1088
+ _disconnectWalletAccount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee36(walletProvider) {
1089
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
1090
+ while (1) switch (_context36.prev = _context36.next) {
1091
+ case 0:
1092
+ if (client) {
1093
+ _context36.next = 2;
1094
+ break;
1095
+ }
1096
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1097
+ case 2:
1098
+ _context36.next = 4;
1099
+ return client.disconnectWalletAccount(walletProvider);
1100
+ case 4:
1101
+ if (!session) {
1102
+ _context36.next = 7;
1103
+ break;
1104
+ }
1105
+ _context36.next = 7;
1106
+ return refreshWallets();
1107
+ case 7:
1108
+ case "end":
1109
+ return _context36.stop();
1110
+ }
1111
+ }, _callee36);
1112
+ }));
1113
+ return _disconnectWalletAccount.apply(this, arguments);
1114
+ }
1115
+ function switchWalletProviderChain(_x0, _x1) {
1116
+ return _switchWalletProviderChain.apply(this, arguments);
1117
+ } // TODO: MOE PLEASE COMMENT THESE
1118
+ function _switchWalletProviderChain() {
1119
+ _switchWalletProviderChain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee37(walletProvider, chainOrId) {
1120
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
1121
+ while (1) switch (_context37.prev = _context37.next) {
1122
+ case 0:
1123
+ if (client) {
1124
+ _context37.next = 2;
1125
+ break;
1126
+ }
1127
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1128
+ case 2:
1129
+ _context37.next = 4;
1130
+ return client.switchWalletProviderChain(walletProvider, chainOrId);
1131
+ case 4:
1132
+ case "end":
1133
+ return _context37.stop();
1134
+ }
1135
+ }, _callee37);
1136
+ }));
1137
+ return _switchWalletProviderChain.apply(this, arguments);
1138
+ }
1139
+ function initializeProviders(_x10, _x11) {
1140
+ return _initializeProviders.apply(this, arguments);
1141
+ }
1142
+ function _initializeProviders() {
1143
+ _initializeProviders = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee38(getWalletProviders, onWalletsChanged) {
1144
+ var cleanups, _yield$Promise$all, _yield$Promise$all2, ethProviders, solProviders, attachEthereumListeners, attachSolanaListeners;
1145
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
1146
+ while (1) switch (_context38.prev = _context38.next) {
1147
+ case 0:
1148
+ attachSolanaListeners = function _attachSolanaListener(provider, onWalletsChanged) {
1149
+ var _provider$features;
1150
+ var cleanups = [];
1151
+ var walletEvents = (_provider$features = provider.features) === null || _provider$features === void 0 ? void 0 : _provider$features["standard:events"];
1152
+ if (walletEvents !== null && walletEvents !== void 0 && walletEvents.on) {
1153
+ var handleChange = function handleChange(event) {
1154
+ if (event.type === "change" || event.type === "accountsChanged") {
1155
+ onWalletsChanged();
1156
+ }
1157
+ };
1158
+ walletEvents.on("change", handleChange);
1159
+ walletEvents.on("accountsChanged", handleChange);
1160
+ cleanups.push(function () {
1161
+ var _walletEvents$off, _walletEvents$off2;
1162
+ (_walletEvents$off = walletEvents.off) === null || _walletEvents$off === void 0 ? void 0 : _walletEvents$off.call(walletEvents, "change", handleChange);
1163
+ (_walletEvents$off2 = walletEvents.off) === null || _walletEvents$off2 === void 0 ? void 0 : _walletEvents$off2.call(walletEvents, "accountsChanged", handleChange);
1164
+ });
1165
+ }
1166
+ return cleanups.length > 0 ? function () {
1167
+ cleanups.forEach(function (fn) {
1168
+ return fn();
1169
+ });
1170
+ } : function () {};
1171
+ };
1172
+ attachEthereumListeners = function _attachEthereumListen(provider, onWalletsChanged) {
1173
+ if (typeof provider.on !== "function") return;
1174
+ var handleAccountsChanged = function handleAccountsChanged(accounts) {
1175
+ if (accounts.length === 0) onWalletsChanged();
1176
+ };
1177
+ var handleDisconnect = function handleDisconnect() {
1178
+ return onWalletsChanged();
1179
+ };
1180
+ provider.on("accountsChanged", handleAccountsChanged);
1181
+ provider.on("disconnect", handleDisconnect);
1182
+ return function () {
1183
+ provider.removeListener("accountsChanged", handleAccountsChanged);
1184
+ provider.removeListener("disconnect", handleDisconnect);
1185
+ };
1186
+ };
1187
+ cleanups = [];
1188
+ _context38.next = 5;
1189
+ return Promise.all([getWalletProviders(Chain.Ethereum), getWalletProviders(Chain.Solana)]);
1190
+ case 5:
1191
+ _yield$Promise$all = _context38.sent;
1192
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
1193
+ ethProviders = _yield$Promise$all2[0];
1194
+ solProviders = _yield$Promise$all2[1];
1195
+ ethProviders.forEach(function (p) {
1196
+ var cleanup = attachEthereumListeners(p.provider, onWalletsChanged);
1197
+ if (cleanup) cleanups.push(cleanup);
1198
+ });
1199
+ solProviders.forEach(function (p) {
1200
+ var cleanup = attachSolanaListeners(p.provider, onWalletsChanged);
1201
+ if (cleanup) cleanups.push(cleanup);
1202
+ });
1203
+ return _context38.abrupt("return", function () {
1204
+ cleanups.forEach(function (remove) {
1205
+ return remove();
1206
+ });
1207
+ });
1208
+ case 12:
1209
+ case "end":
1210
+ return _context38.stop();
1211
+ }
1212
+ }, _callee38);
1213
+ }));
1214
+ return _initializeProviders.apply(this, arguments);
1215
+ }
1216
+ function loginWithWallet(_x12) {
1217
+ return _loginWithWallet.apply(this, arguments);
1218
+ }
1219
+ function _loginWithWallet() {
1220
+ _loginWithWallet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
1221
+ var _masterConfig$auth$se3, _masterConfig$auth0;
1222
+ var expirationSeconds, res;
1223
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
1224
+ while (1) switch (_context39.prev = _context39.next) {
1225
+ case 0:
1226
+ if (client) {
1227
+ _context39.next = 2;
1228
+ break;
1229
+ }
1230
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1231
+ case 2:
1232
+ expirationSeconds = (_masterConfig$auth$se3 = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth0 = masterConfig.auth) === null || _masterConfig$auth0 === void 0 ? void 0 : _masterConfig$auth0.sessionExpirationSeconds) !== null && _masterConfig$auth$se3 !== void 0 ? _masterConfig$auth$se3 : DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
1233
+ _context39.next = 5;
1234
+ return withTurnkeyErrorHandling(function () {
1235
+ return client.loginWithWallet(_objectSpread2(_objectSpread2({}, params), {}, {
1236
+ expirationSeconds: expirationSeconds
1237
+ }));
1238
+ }, callbacks, "Failed to login with wallet");
1239
+ case 5:
1240
+ res = _context39.sent;
1241
+ if (!res) {
1242
+ _context39.next = 9;
1243
+ break;
1244
+ }
1245
+ _context39.next = 9;
1246
+ return handlePostAuth();
1247
+ case 9:
1248
+ return _context39.abrupt("return", res);
1249
+ case 10:
1250
+ case "end":
1251
+ return _context39.stop();
1252
+ }
1253
+ }, _callee39);
1254
+ }));
1255
+ return _loginWithWallet.apply(this, arguments);
1256
+ }
1257
+ function signUpWithWallet(_x13) {
1258
+ return _signUpWithWallet.apply(this, arguments);
1259
+ }
1260
+ function _signUpWithWallet() {
1261
+ _signUpWithWallet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
1262
+ var _params$createSubOrgP2, _masterConfig$auth1, _masterConfig$auth1$c, _masterConfig$auth$se4, _masterConfig$auth10;
1263
+ var createSubOrgParams, expirationSeconds, res;
1264
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
1265
+ while (1) switch (_context40.prev = _context40.next) {
1266
+ case 0:
1267
+ if (client) {
1268
+ _context40.next = 2;
1269
+ break;
1270
+ }
1271
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1272
+ case 2:
1273
+ if (masterConfig) {
1274
+ _context40.next = 4;
1275
+ break;
1276
+ }
1277
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.INVALID_CONFIGURATION);
1278
+ case 4:
1279
+ // If createSubOrgParams is not provided, use the default from masterConfig
1280
+ createSubOrgParams = (_params$createSubOrgP2 = params.createSubOrgParams) !== null && _params$createSubOrgP2 !== void 0 ? _params$createSubOrgP2 : (_masterConfig$auth1 = masterConfig.auth) === null || _masterConfig$auth1 === void 0 ? void 0 : (_masterConfig$auth1$c = _masterConfig$auth1.createSuborgParams) === null || _masterConfig$auth1$c === void 0 ? void 0 : _masterConfig$auth1$c.walletAuth;
1281
+ params = createSubOrgParams !== undefined ? _objectSpread2(_objectSpread2({}, params), {}, {
1282
+ createSubOrgParams: createSubOrgParams
1283
+ }) : _objectSpread2({}, params);
1284
+ expirationSeconds = (_masterConfig$auth$se4 = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth10 = masterConfig.auth) === null || _masterConfig$auth10 === void 0 ? void 0 : _masterConfig$auth10.sessionExpirationSeconds) !== null && _masterConfig$auth$se4 !== void 0 ? _masterConfig$auth$se4 : DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
1285
+ _context40.next = 9;
1286
+ return withTurnkeyErrorHandling(function () {
1287
+ return client.signUpWithWallet(_objectSpread2(_objectSpread2({}, params), {}, {
1288
+ expirationSeconds: expirationSeconds
1289
+ }));
1290
+ }, callbacks, "Failed to sign up with wallet");
1291
+ case 9:
1292
+ res = _context40.sent;
1293
+ if (!res) {
1294
+ _context40.next = 15;
1295
+ break;
1296
+ }
1297
+ _context40.next = 13;
1298
+ return handlePostAuth();
1299
+ case 13:
1300
+ _context40.next = 15;
1301
+ break;
1302
+ case 15:
1303
+ return _context40.abrupt("return", res);
1304
+ case 16:
1305
+ case "end":
1306
+ return _context40.stop();
1307
+ }
1308
+ }, _callee40);
1309
+ }));
1310
+ return _signUpWithWallet.apply(this, arguments);
1311
+ }
1312
+ function loginOrSignupWithWallet(_x14) {
1313
+ return _loginOrSignupWithWallet.apply(this, arguments);
1314
+ }
1315
+ function _loginOrSignupWithWallet() {
1316
+ _loginOrSignupWithWallet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
1317
+ var _params$createSubOrgP3, _masterConfig$auth11, _masterConfig$auth11$, _masterConfig$auth$se5, _masterConfig$auth12;
1318
+ var createSubOrgParams, expirationSeconds, res;
1319
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
1320
+ while (1) switch (_context41.prev = _context41.next) {
1321
+ case 0:
1322
+ if (client) {
1323
+ _context41.next = 2;
1324
+ break;
1325
+ }
1326
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1327
+ case 2:
1328
+ if (masterConfig) {
1329
+ _context41.next = 4;
1330
+ break;
1331
+ }
1332
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.INVALID_CONFIGURATION);
1333
+ case 4:
1334
+ // If createSubOrgParams is not provided, use the default from masterConfig
1335
+ createSubOrgParams = (_params$createSubOrgP3 = params.createSubOrgParams) !== null && _params$createSubOrgP3 !== void 0 ? _params$createSubOrgP3 : (_masterConfig$auth11 = masterConfig.auth) === null || _masterConfig$auth11 === void 0 ? void 0 : (_masterConfig$auth11$ = _masterConfig$auth11.createSuborgParams) === null || _masterConfig$auth11$ === void 0 ? void 0 : _masterConfig$auth11$.walletAuth;
1336
+ params = createSubOrgParams !== undefined ? _objectSpread2(_objectSpread2({}, params), {}, {
1337
+ createSubOrgParams: createSubOrgParams
1338
+ }) : _objectSpread2({}, params);
1339
+ expirationSeconds = (_masterConfig$auth$se5 = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth12 = masterConfig.auth) === null || _masterConfig$auth12 === void 0 ? void 0 : _masterConfig$auth12.sessionExpirationSeconds) !== null && _masterConfig$auth$se5 !== void 0 ? _masterConfig$auth$se5 : DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
1340
+ _context41.next = 9;
1341
+ return withTurnkeyErrorHandling(function () {
1342
+ return client.loginOrSignupWithWallet(_objectSpread2(_objectSpread2({}, params), {}, {
1343
+ expirationSeconds: expirationSeconds
1344
+ }));
1345
+ }, callbacks, "Failed to login or sign up with wallet");
1346
+ case 9:
1347
+ res = _context41.sent;
1348
+ if (!res) {
1349
+ _context41.next = 15;
1350
+ break;
1351
+ }
1352
+ _context41.next = 13;
1353
+ return handlePostAuth();
1354
+ case 13:
1355
+ _context41.next = 15;
1356
+ break;
1357
+ case 15:
1358
+ return _context41.abrupt("return", res);
1359
+ case 16:
1360
+ case "end":
1361
+ return _context41.stop();
1362
+ }
1363
+ }, _callee41);
1364
+ }));
1365
+ return _loginOrSignupWithWallet.apply(this, arguments);
1366
+ }
1367
+ function initOtp(_x15) {
1368
+ return _initOtp.apply(this, arguments);
1369
+ }
1370
+ function _initOtp() {
1371
+ _initOtp = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
1372
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
1373
+ while (1) switch (_context42.prev = _context42.next) {
1374
+ case 0:
1375
+ if (client) {
1376
+ _context42.next = 2;
1377
+ break;
1378
+ }
1379
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1380
+ case 2:
1381
+ return _context42.abrupt("return", withTurnkeyErrorHandling(function () {
1382
+ return client.initOtp(params);
1383
+ }, callbacks, "Failed to initialize OTP"));
1384
+ case 3:
1385
+ case "end":
1386
+ return _context42.stop();
1387
+ }
1388
+ }, _callee42);
1389
+ }));
1390
+ return _initOtp.apply(this, arguments);
1391
+ }
1392
+ function verifyOtp(_x16) {
1393
+ return _verifyOtp.apply(this, arguments);
1394
+ }
1395
+ function _verifyOtp() {
1396
+ _verifyOtp = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
1397
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
1398
+ while (1) switch (_context43.prev = _context43.next) {
1399
+ case 0:
1400
+ if (client) {
1401
+ _context43.next = 2;
1402
+ break;
1403
+ }
1404
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1405
+ case 2:
1406
+ return _context43.abrupt("return", withTurnkeyErrorHandling(function () {
1407
+ return client.verifyOtp(params);
1408
+ }, callbacks, "Failed to verify OTP"));
1409
+ case 3:
1410
+ case "end":
1411
+ return _context43.stop();
1412
+ }
1413
+ }, _callee43);
1414
+ }));
1415
+ return _verifyOtp.apply(this, arguments);
1416
+ }
1417
+ function loginWithOtp(_x17) {
1418
+ return _loginWithOtp.apply(this, arguments);
1419
+ }
1420
+ function _loginWithOtp() {
1421
+ _loginWithOtp = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee44(params) {
1422
+ var res;
1423
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
1424
+ while (1) switch (_context44.prev = _context44.next) {
1425
+ case 0:
1426
+ if (client) {
1427
+ _context44.next = 2;
1428
+ break;
1429
+ }
1430
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1431
+ case 2:
1432
+ _context44.next = 4;
1433
+ return withTurnkeyErrorHandling(function () {
1434
+ return client.loginWithOtp(params);
1435
+ }, callbacks, "Failed to login with OTP");
1436
+ case 4:
1437
+ res = _context44.sent;
1438
+ if (!res) {
1439
+ _context44.next = 10;
1440
+ break;
1441
+ }
1442
+ _context44.next = 8;
1443
+ return handlePostAuth();
1444
+ case 8:
1445
+ _context44.next = 10;
1446
+ break;
1447
+ case 10:
1448
+ return _context44.abrupt("return", res);
1449
+ case 11:
1450
+ case "end":
1451
+ return _context44.stop();
1452
+ }
1453
+ }, _callee44);
1454
+ }));
1455
+ return _loginWithOtp.apply(this, arguments);
1456
+ }
1457
+ function signUpWithOtp(_x18) {
1458
+ return _signUpWithOtp.apply(this, arguments);
1459
+ }
1460
+ function _signUpWithOtp() {
1461
+ _signUpWithOtp = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee45(params) {
1462
+ var _masterConfig$auth13;
1463
+ var createSubOrgParams, res;
1464
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
1465
+ while (1) switch (_context45.prev = _context45.next) {
1466
+ case 0:
1467
+ if (client) {
1468
+ _context45.next = 2;
1469
+ break;
1470
+ }
1471
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1472
+ case 2:
1473
+ if (masterConfig) {
1474
+ _context45.next = 4;
1475
+ break;
1476
+ }
1477
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.INVALID_CONFIGURATION);
1478
+ case 4:
1479
+ // If createSubOrgParams is not provided, use the default from masterConfig
1480
+ createSubOrgParams = params.createSubOrgParams;
1481
+ if (!createSubOrgParams && masterConfig !== null && masterConfig !== void 0 && (_masterConfig$auth13 = masterConfig.auth) !== null && _masterConfig$auth13 !== void 0 && _masterConfig$auth13.createSuborgParams) {
1482
+ if (params.otpType === OtpType.Email) {
1483
+ createSubOrgParams = masterConfig.auth.createSuborgParams.emailOtpAuth;
1484
+ } else if (params.otpType === OtpType.Sms) {
1485
+ createSubOrgParams = masterConfig.auth.createSuborgParams.smsOtpAuth;
1486
+ }
1487
+ }
1488
+ params = createSubOrgParams !== undefined ? _objectSpread2(_objectSpread2({}, params), {}, {
1489
+ createSubOrgParams: createSubOrgParams
1490
+ }) : _objectSpread2({}, params);
1491
+ _context45.next = 9;
1492
+ return withTurnkeyErrorHandling(function () {
1493
+ return client.signUpWithOtp(params);
1494
+ }, callbacks, "Failed to sign up with OTP");
1495
+ case 9:
1496
+ res = _context45.sent;
1497
+ if (!res) {
1498
+ _context45.next = 15;
1499
+ break;
1500
+ }
1501
+ _context45.next = 13;
1502
+ return handlePostAuth();
1503
+ case 13:
1504
+ _context45.next = 15;
1505
+ break;
1506
+ case 15:
1507
+ return _context45.abrupt("return", res);
1508
+ case 16:
1509
+ case "end":
1510
+ return _context45.stop();
1511
+ }
1512
+ }, _callee45);
1513
+ }));
1514
+ return _signUpWithOtp.apply(this, arguments);
1515
+ }
1516
+ function completeOtp(_x19) {
1517
+ return _completeOtp.apply(this, arguments);
1518
+ }
1519
+ function _completeOtp() {
1520
+ _completeOtp = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee46(params) {
1521
+ var _masterConfig$auth14;
1522
+ var createSubOrgParams, res;
1523
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
1524
+ while (1) switch (_context46.prev = _context46.next) {
1525
+ case 0:
1526
+ if (client) {
1527
+ _context46.next = 2;
1528
+ break;
1529
+ }
1530
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1531
+ case 2:
1532
+ if (masterConfig) {
1533
+ _context46.next = 4;
1534
+ break;
1535
+ }
1536
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.INVALID_CONFIGURATION);
1537
+ case 4:
1538
+ // If createSubOrgParams is not provided, use the default from masterConfig
1539
+ createSubOrgParams = params.createSubOrgParams;
1540
+ if (!createSubOrgParams && masterConfig !== null && masterConfig !== void 0 && (_masterConfig$auth14 = masterConfig.auth) !== null && _masterConfig$auth14 !== void 0 && _masterConfig$auth14.createSuborgParams) {
1541
+ if (params.otpType === OtpType.Email) {
1542
+ createSubOrgParams = masterConfig.auth.createSuborgParams.emailOtpAuth;
1543
+ } else if (params.otpType === OtpType.Sms) {
1544
+ createSubOrgParams = masterConfig.auth.createSuborgParams.smsOtpAuth;
1545
+ }
1546
+ }
1547
+ params = createSubOrgParams !== undefined ? _objectSpread2(_objectSpread2({}, params), {}, {
1548
+ createSubOrgParams: createSubOrgParams
1549
+ }) : _objectSpread2({}, params);
1550
+ _context46.next = 9;
1551
+ return withTurnkeyErrorHandling(function () {
1552
+ return client.completeOtp(params);
1553
+ }, callbacks, "Failed to complete OTP");
1554
+ case 9:
1555
+ res = _context46.sent;
1556
+ if (!res) {
1557
+ _context46.next = 15;
1558
+ break;
1559
+ }
1560
+ _context46.next = 13;
1561
+ return handlePostAuth();
1562
+ case 13:
1563
+ _context46.next = 15;
1564
+ break;
1565
+ case 15:
1566
+ return _context46.abrupt("return", res);
1567
+ case 16:
1568
+ case "end":
1569
+ return _context46.stop();
1570
+ }
1571
+ }, _callee46);
1572
+ }));
1573
+ return _completeOtp.apply(this, arguments);
1574
+ }
1575
+ function completeOauth(_x20) {
1576
+ return _completeOauth.apply(this, arguments);
1577
+ }
1578
+ function _completeOauth() {
1579
+ _completeOauth = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee47(params) {
1580
+ var _params$createSubOrgP4, _masterConfig$auth15, _masterConfig$auth15$;
1581
+ var createSubOrgParams, res;
1582
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
1583
+ while (1) switch (_context47.prev = _context47.next) {
1584
+ case 0:
1585
+ if (client) {
1586
+ _context47.next = 2;
1587
+ break;
1588
+ }
1589
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1590
+ case 2:
1591
+ if (masterConfig) {
1592
+ _context47.next = 4;
1593
+ break;
1594
+ }
1595
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.INVALID_CONFIGURATION);
1596
+ case 4:
1597
+ // If createSubOrgParams is not provided, use the default from masterConfig
1598
+ createSubOrgParams = (_params$createSubOrgP4 = params.createSubOrgParams) !== null && _params$createSubOrgP4 !== void 0 ? _params$createSubOrgP4 : (_masterConfig$auth15 = masterConfig.auth) === null || _masterConfig$auth15 === void 0 ? void 0 : (_masterConfig$auth15$ = _masterConfig$auth15.createSuborgParams) === null || _masterConfig$auth15$ === void 0 ? void 0 : _masterConfig$auth15$.oauth;
1599
+ params = createSubOrgParams !== undefined ? _objectSpread2(_objectSpread2({}, params), {}, {
1600
+ createSubOrgParams: createSubOrgParams
1601
+ }) : _objectSpread2({}, params);
1602
+ _context47.next = 8;
1603
+ return withTurnkeyErrorHandling(function () {
1604
+ return client.completeOauth(params);
1605
+ }, callbacks, "Failed to complete OAuth");
1606
+ case 8:
1607
+ res = _context47.sent;
1608
+ if (!res) {
1609
+ _context47.next = 14;
1610
+ break;
1611
+ }
1612
+ _context47.next = 12;
1613
+ return handlePostAuth();
1614
+ case 12:
1615
+ _context47.next = 14;
1616
+ break;
1617
+ case 14:
1618
+ return _context47.abrupt("return", res);
1619
+ case 15:
1620
+ case "end":
1621
+ return _context47.stop();
1622
+ }
1623
+ }, _callee47);
1624
+ }));
1625
+ return _completeOauth.apply(this, arguments);
1626
+ }
1627
+ function loginWithOauth(_x21) {
1628
+ return _loginWithOauth.apply(this, arguments);
1629
+ }
1630
+ function _loginWithOauth() {
1631
+ _loginWithOauth = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee48(params) {
1632
+ var res;
1633
+ return _regeneratorRuntime().wrap(function _callee48$(_context48) {
1634
+ while (1) switch (_context48.prev = _context48.next) {
1635
+ case 0:
1636
+ if (client) {
1637
+ _context48.next = 2;
1638
+ break;
1639
+ }
1640
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1641
+ case 2:
1642
+ _context48.next = 4;
1643
+ return withTurnkeyErrorHandling(function () {
1644
+ return client.loginWithOauth(params);
1645
+ }, callbacks, "Failed to login with OAuth");
1646
+ case 4:
1647
+ res = _context48.sent;
1648
+ if (!res) {
1649
+ _context48.next = 10;
1650
+ break;
1651
+ }
1652
+ _context48.next = 8;
1653
+ return handlePostAuth();
1654
+ case 8:
1655
+ _context48.next = 10;
1656
+ break;
1657
+ case 10:
1658
+ return _context48.abrupt("return", res);
1659
+ case 11:
1660
+ case "end":
1661
+ return _context48.stop();
1662
+ }
1663
+ }, _callee48);
1664
+ }));
1665
+ return _loginWithOauth.apply(this, arguments);
1666
+ }
1667
+ function signUpWithOauth(_x22) {
1668
+ return _signUpWithOauth.apply(this, arguments);
1669
+ }
1670
+ function _signUpWithOauth() {
1671
+ _signUpWithOauth = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee49(params) {
1672
+ var _params$createSubOrgP5, _masterConfig$auth16, _masterConfig$auth16$;
1673
+ var createSubOrgParams, res;
1674
+ return _regeneratorRuntime().wrap(function _callee49$(_context49) {
1675
+ while (1) switch (_context49.prev = _context49.next) {
1676
+ case 0:
1677
+ if (client) {
1678
+ _context49.next = 2;
1679
+ break;
1680
+ }
1681
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1682
+ case 2:
1683
+ if (masterConfig) {
1684
+ _context49.next = 4;
1685
+ break;
1686
+ }
1687
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.INVALID_CONFIGURATION);
1688
+ case 4:
1689
+ // If createSubOrgParams is not provided, use the default from masterConfig
1690
+ createSubOrgParams = (_params$createSubOrgP5 = params.createSubOrgParams) !== null && _params$createSubOrgP5 !== void 0 ? _params$createSubOrgP5 : (_masterConfig$auth16 = masterConfig.auth) === null || _masterConfig$auth16 === void 0 ? void 0 : (_masterConfig$auth16$ = _masterConfig$auth16.createSuborgParams) === null || _masterConfig$auth16$ === void 0 ? void 0 : _masterConfig$auth16$.oauth;
1691
+ params = createSubOrgParams !== undefined ? _objectSpread2(_objectSpread2({}, params), {}, {
1692
+ createSubOrgParams: createSubOrgParams
1693
+ }) : _objectSpread2({}, params);
1694
+ _context49.next = 8;
1695
+ return withTurnkeyErrorHandling(function () {
1696
+ return client.signUpWithOauth(params);
1697
+ }, callbacks, "Failed to sign up with OAuth");
1698
+ case 8:
1699
+ res = _context49.sent;
1700
+ if (!res) {
1701
+ _context49.next = 12;
1702
+ break;
1703
+ }
1704
+ _context49.next = 12;
1705
+ return handlePostAuth();
1706
+ case 12:
1707
+ return _context49.abrupt("return", res);
1708
+ case 13:
1709
+ case "end":
1710
+ return _context49.stop();
1711
+ }
1712
+ }, _callee49);
1713
+ }));
1714
+ return _signUpWithOauth.apply(this, arguments);
1715
+ }
1716
+ function fetchWallets(_x23) {
1717
+ return _fetchWallets.apply(this, arguments);
1718
+ }
1719
+ function _fetchWallets() {
1720
+ _fetchWallets = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee50(params) {
1721
+ return _regeneratorRuntime().wrap(function _callee50$(_context50) {
1722
+ while (1) switch (_context50.prev = _context50.next) {
1723
+ case 0:
1724
+ if (client) {
1725
+ _context50.next = 2;
1726
+ break;
1727
+ }
1728
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1729
+ case 2:
1730
+ return _context50.abrupt("return", withTurnkeyErrorHandling(function () {
1731
+ return client.fetchWallets(params);
1732
+ }, callbacks, "Failed to fetch wallets"));
1733
+ case 3:
1734
+ case "end":
1735
+ return _context50.stop();
1736
+ }
1737
+ }, _callee50);
1738
+ }));
1739
+ return _fetchWallets.apply(this, arguments);
1740
+ }
1741
+ function fetchWalletAccounts(_x24) {
1742
+ return _fetchWalletAccounts.apply(this, arguments);
1743
+ }
1744
+ function _fetchWalletAccounts() {
1745
+ _fetchWalletAccounts = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee51(params) {
1746
+ return _regeneratorRuntime().wrap(function _callee51$(_context51) {
1747
+ while (1) switch (_context51.prev = _context51.next) {
1748
+ case 0:
1749
+ if (client) {
1750
+ _context51.next = 2;
1751
+ break;
1752
+ }
1753
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1754
+ case 2:
1755
+ return _context51.abrupt("return", withTurnkeyErrorHandling(function () {
1756
+ return client.fetchWalletAccounts(params);
1757
+ }, callbacks, "Failed to fetch wallet accounts"));
1758
+ case 3:
1759
+ case "end":
1760
+ return _context51.stop();
1761
+ }
1762
+ }, _callee51);
1763
+ }));
1764
+ return _fetchWalletAccounts.apply(this, arguments);
1765
+ }
1766
+ function signMessage(_x25) {
1767
+ return _signMessage.apply(this, arguments);
1768
+ }
1769
+ function _signMessage() {
1770
+ _signMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee52(params) {
1771
+ return _regeneratorRuntime().wrap(function _callee52$(_context52) {
1772
+ while (1) switch (_context52.prev = _context52.next) {
1773
+ case 0:
1774
+ if (client) {
1775
+ _context52.next = 2;
1776
+ break;
1777
+ }
1778
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1779
+ case 2:
1780
+ return _context52.abrupt("return", withTurnkeyErrorHandling(function () {
1781
+ return client.signMessage(params);
1782
+ }, callbacks, "Failed to sign message"));
1783
+ case 3:
1784
+ case "end":
1785
+ return _context52.stop();
1786
+ }
1787
+ }, _callee52);
1788
+ }));
1789
+ return _signMessage.apply(this, arguments);
1790
+ }
1791
+ function handleSignMessage(_x26) {
1792
+ return _handleSignMessage.apply(this, arguments);
1793
+ }
1794
+ function _handleSignMessage() {
1795
+ _handleSignMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee53(params) {
1796
+ var _params$successPageDu3, successPageDuration;
1797
+ return _regeneratorRuntime().wrap(function _callee53$(_context53) {
1798
+ while (1) switch (_context53.prev = _context53.next) {
1799
+ case 0:
1800
+ _params$successPageDu3 = params.successPageDuration, successPageDuration = _params$successPageDu3 === void 0 ? 2000 : _params$successPageDu3;
1801
+ if (client) {
1802
+ _context53.next = 3;
1803
+ break;
1804
+ }
1805
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1806
+ case 3:
1807
+ return _context53.abrupt("return", new Promise(function (resolve, reject) {
1808
+ pushPage({
1809
+ key: "Sign Message",
1810
+ content: jsx(SignMessageModal, _objectSpread2(_objectSpread2(_objectSpread2({
1811
+ message: params.message,
1812
+ subText: params === null || params === void 0 ? void 0 : params.subText,
1813
+ walletAccount: params.walletAccount,
1814
+ stampWith: params.stampWith,
1815
+ successPageDuration: successPageDuration,
1816
+ onSuccess: function onSuccess(result) {
1817
+ resolve(result);
1818
+ },
1819
+ onError: function onError(error) {
1820
+ reject(error);
1821
+ }
1822
+ }, (params === null || params === void 0 ? void 0 : params.encoding) && {
1823
+ encoding: params.encoding
1824
+ }), (params === null || params === void 0 ? void 0 : params.hashFunction) && {
1825
+ hashFunction: params.hashFunction
1826
+ }), (params === null || params === void 0 ? void 0 : params.addEthereumPrefix) && {
1827
+ addEthereumPrefix: params.addEthereumPrefix
1828
+ }))
1829
+ });
1830
+ }));
1831
+ case 4:
1832
+ case "end":
1833
+ return _context53.stop();
1834
+ }
1835
+ }, _callee53);
1836
+ }));
1837
+ return _handleSignMessage.apply(this, arguments);
1838
+ }
1839
+ function signTransaction(_x27) {
1840
+ return _signTransaction.apply(this, arguments);
1841
+ }
1842
+ function _signTransaction() {
1843
+ _signTransaction = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee54(params) {
1844
+ return _regeneratorRuntime().wrap(function _callee54$(_context54) {
1845
+ while (1) switch (_context54.prev = _context54.next) {
1846
+ case 0:
1847
+ if (client) {
1848
+ _context54.next = 2;
1849
+ break;
1850
+ }
1851
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1852
+ case 2:
1853
+ return _context54.abrupt("return", withTurnkeyErrorHandling(function () {
1854
+ return client.signTransaction(params);
1855
+ }, callbacks, "Failed to sign transaction"));
1856
+ case 3:
1857
+ case "end":
1858
+ return _context54.stop();
1859
+ }
1860
+ }, _callee54);
1861
+ }));
1862
+ return _signTransaction.apply(this, arguments);
1863
+ }
1864
+ function signAndSendTransaction(_x28) {
1865
+ return _signAndSendTransaction.apply(this, arguments);
1866
+ }
1867
+ function _signAndSendTransaction() {
1868
+ _signAndSendTransaction = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee55(params) {
1869
+ return _regeneratorRuntime().wrap(function _callee55$(_context55) {
1870
+ while (1) switch (_context55.prev = _context55.next) {
1871
+ case 0:
1872
+ if (client) {
1873
+ _context55.next = 2;
1874
+ break;
1875
+ }
1876
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1877
+ case 2:
1878
+ return _context55.abrupt("return", withTurnkeyErrorHandling(function () {
1879
+ return client.signAndSendTransaction(params);
1880
+ }, callbacks, "Failed to sign transaction"));
1881
+ case 3:
1882
+ case "end":
1883
+ return _context55.stop();
1884
+ }
1885
+ }, _callee55);
1886
+ }));
1887
+ return _signAndSendTransaction.apply(this, arguments);
1888
+ }
1889
+ function fetchUser(_x29) {
1890
+ return _fetchUser.apply(this, arguments);
1891
+ }
1892
+ function _fetchUser() {
1893
+ _fetchUser = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee56(params) {
1894
+ return _regeneratorRuntime().wrap(function _callee56$(_context56) {
1895
+ while (1) switch (_context56.prev = _context56.next) {
1896
+ case 0:
1897
+ if (client) {
1898
+ _context56.next = 2;
1899
+ break;
1900
+ }
1901
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1902
+ case 2:
1903
+ return _context56.abrupt("return", withTurnkeyErrorHandling(function () {
1904
+ return client.fetchUser(params);
1905
+ }, callbacks, "Failed to fetch user"));
1906
+ case 3:
1907
+ case "end":
1908
+ return _context56.stop();
1909
+ }
1910
+ }, _callee56);
1911
+ }));
1912
+ return _fetchUser.apply(this, arguments);
1913
+ }
1914
+ function updateUserEmail(_x30) {
1915
+ return _updateUserEmail.apply(this, arguments);
1916
+ }
1917
+ function _updateUserEmail() {
1918
+ _updateUserEmail = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee57(params) {
1919
+ var res;
1920
+ return _regeneratorRuntime().wrap(function _callee57$(_context57) {
1921
+ while (1) switch (_context57.prev = _context57.next) {
1922
+ case 0:
1923
+ if (client) {
1924
+ _context57.next = 2;
1925
+ break;
1926
+ }
1927
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1928
+ case 2:
1929
+ _context57.next = 4;
1930
+ return withTurnkeyErrorHandling(function () {
1931
+ return client.updateUserEmail(params);
1932
+ }, callbacks, "Failed to update user email");
1933
+ case 4:
1934
+ res = _context57.sent;
1935
+ if (!res) {
1936
+ _context57.next = 8;
1937
+ break;
1938
+ }
1939
+ _context57.next = 8;
1940
+ return refreshUser({
1941
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
1942
+ });
1943
+ case 8:
1944
+ return _context57.abrupt("return", res);
1945
+ case 9:
1946
+ case "end":
1947
+ return _context57.stop();
1948
+ }
1949
+ }, _callee57);
1950
+ }));
1951
+ return _updateUserEmail.apply(this, arguments);
1952
+ }
1953
+ function removeUserEmail(_x31) {
1954
+ return _removeUserEmail.apply(this, arguments);
1955
+ }
1956
+ function _removeUserEmail() {
1957
+ _removeUserEmail = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee58(params) {
1958
+ var res;
1959
+ return _regeneratorRuntime().wrap(function _callee58$(_context58) {
1960
+ while (1) switch (_context58.prev = _context58.next) {
1961
+ case 0:
1962
+ if (client) {
1963
+ _context58.next = 2;
1964
+ break;
1965
+ }
1966
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
1967
+ case 2:
1968
+ _context58.next = 4;
1969
+ return withTurnkeyErrorHandling(function () {
1970
+ return client.removeUserEmail(params);
1971
+ }, callbacks, "Failed to remove user email");
1972
+ case 4:
1973
+ res = _context58.sent;
1974
+ if (!res) {
1975
+ _context58.next = 8;
1976
+ break;
1977
+ }
1978
+ _context58.next = 8;
1979
+ return refreshUser({
1980
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
1981
+ });
1982
+ case 8:
1983
+ return _context58.abrupt("return", res);
1984
+ case 9:
1985
+ case "end":
1986
+ return _context58.stop();
1987
+ }
1988
+ }, _callee58);
1989
+ }));
1990
+ return _removeUserEmail.apply(this, arguments);
1991
+ }
1992
+ function updateUserPhoneNumber(_x32) {
1993
+ return _updateUserPhoneNumber.apply(this, arguments);
1994
+ }
1995
+ function _updateUserPhoneNumber() {
1996
+ _updateUserPhoneNumber = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee59(params) {
1997
+ var res;
1998
+ return _regeneratorRuntime().wrap(function _callee59$(_context59) {
1999
+ while (1) switch (_context59.prev = _context59.next) {
2000
+ case 0:
2001
+ if (client) {
2002
+ _context59.next = 2;
2003
+ break;
2004
+ }
2005
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2006
+ case 2:
2007
+ _context59.next = 4;
2008
+ return withTurnkeyErrorHandling(function () {
2009
+ return client.updateUserPhoneNumber(params);
2010
+ }, callbacks, "Failed to update user phone number");
2011
+ case 4:
2012
+ res = _context59.sent;
2013
+ if (!res) {
2014
+ _context59.next = 8;
2015
+ break;
2016
+ }
2017
+ _context59.next = 8;
2018
+ return refreshUser({
2019
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2020
+ });
2021
+ case 8:
2022
+ return _context59.abrupt("return", res);
2023
+ case 9:
2024
+ case "end":
2025
+ return _context59.stop();
2026
+ }
2027
+ }, _callee59);
2028
+ }));
2029
+ return _updateUserPhoneNumber.apply(this, arguments);
2030
+ }
2031
+ function removeUserPhoneNumber(_x33) {
2032
+ return _removeUserPhoneNumber.apply(this, arguments);
2033
+ }
2034
+ function _removeUserPhoneNumber() {
2035
+ _removeUserPhoneNumber = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee60(params) {
2036
+ var res;
2037
+ return _regeneratorRuntime().wrap(function _callee60$(_context60) {
2038
+ while (1) switch (_context60.prev = _context60.next) {
2039
+ case 0:
2040
+ if (client) {
2041
+ _context60.next = 2;
2042
+ break;
2043
+ }
2044
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2045
+ case 2:
2046
+ _context60.next = 4;
2047
+ return withTurnkeyErrorHandling(function () {
2048
+ return client.removeUserPhoneNumber(params);
2049
+ }, callbacks, "Failed to remove user phone number");
2050
+ case 4:
2051
+ res = _context60.sent;
2052
+ if (!res) {
2053
+ _context60.next = 8;
2054
+ break;
2055
+ }
2056
+ _context60.next = 8;
2057
+ return refreshUser({
2058
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2059
+ });
2060
+ case 8:
2061
+ return _context60.abrupt("return", res);
2062
+ case 9:
2063
+ case "end":
2064
+ return _context60.stop();
2065
+ }
2066
+ }, _callee60);
2067
+ }));
2068
+ return _removeUserPhoneNumber.apply(this, arguments);
2069
+ }
2070
+ function updateUserName(_x34) {
2071
+ return _updateUserName.apply(this, arguments);
2072
+ }
2073
+ function _updateUserName() {
2074
+ _updateUserName = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee61(params) {
2075
+ var res;
2076
+ return _regeneratorRuntime().wrap(function _callee61$(_context61) {
2077
+ while (1) switch (_context61.prev = _context61.next) {
2078
+ case 0:
2079
+ if (client) {
2080
+ _context61.next = 2;
2081
+ break;
2082
+ }
2083
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2084
+ case 2:
2085
+ _context61.next = 4;
2086
+ return withTurnkeyErrorHandling(function () {
2087
+ return client.updateUserName(params);
2088
+ }, callbacks, "Failed to update user name");
2089
+ case 4:
2090
+ res = _context61.sent;
2091
+ if (!res) {
2092
+ _context61.next = 8;
2093
+ break;
2094
+ }
2095
+ _context61.next = 8;
2096
+ return refreshUser({
2097
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2098
+ });
2099
+ case 8:
2100
+ return _context61.abrupt("return", res);
2101
+ case 9:
2102
+ case "end":
2103
+ return _context61.stop();
2104
+ }
2105
+ }, _callee61);
2106
+ }));
2107
+ return _updateUserName.apply(this, arguments);
2108
+ }
2109
+ function addOauthProvider(_x35) {
2110
+ return _addOauthProvider.apply(this, arguments);
2111
+ }
2112
+ function _addOauthProvider() {
2113
+ _addOauthProvider = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee62(params) {
2114
+ var res;
2115
+ return _regeneratorRuntime().wrap(function _callee62$(_context62) {
2116
+ while (1) switch (_context62.prev = _context62.next) {
2117
+ case 0:
2118
+ if (client) {
2119
+ _context62.next = 2;
2120
+ break;
2121
+ }
2122
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2123
+ case 2:
2124
+ _context62.next = 4;
2125
+ return withTurnkeyErrorHandling(function () {
2126
+ return client.addOauthProvider(params);
2127
+ }, callbacks, "Failed to add OAuth provider");
2128
+ case 4:
2129
+ res = _context62.sent;
2130
+ if (!res) {
2131
+ _context62.next = 8;
2132
+ break;
2133
+ }
2134
+ _context62.next = 8;
2135
+ return refreshUser({
2136
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2137
+ });
2138
+ case 8:
2139
+ return _context62.abrupt("return", res);
2140
+ case 9:
2141
+ case "end":
2142
+ return _context62.stop();
2143
+ }
2144
+ }, _callee62);
2145
+ }));
2146
+ return _addOauthProvider.apply(this, arguments);
2147
+ }
2148
+ function removeOauthProviders(_x36) {
2149
+ return _removeOauthProviders.apply(this, arguments);
2150
+ }
2151
+ function _removeOauthProviders() {
2152
+ _removeOauthProviders = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee63(params) {
2153
+ var res;
2154
+ return _regeneratorRuntime().wrap(function _callee63$(_context63) {
2155
+ while (1) switch (_context63.prev = _context63.next) {
2156
+ case 0:
2157
+ if (client) {
2158
+ _context63.next = 2;
2159
+ break;
2160
+ }
2161
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2162
+ case 2:
2163
+ _context63.next = 4;
2164
+ return withTurnkeyErrorHandling(function () {
2165
+ return client.removeOauthProviders(params);
2166
+ }, callbacks, "Failed to remove OAuth providers");
2167
+ case 4:
2168
+ res = _context63.sent;
2169
+ if (!res) {
2170
+ _context63.next = 8;
2171
+ break;
2172
+ }
2173
+ _context63.next = 8;
2174
+ return refreshUser({
2175
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2176
+ });
2177
+ case 8:
2178
+ return _context63.abrupt("return", res);
2179
+ case 9:
2180
+ case "end":
2181
+ return _context63.stop();
2182
+ }
2183
+ }, _callee63);
2184
+ }));
2185
+ return _removeOauthProviders.apply(this, arguments);
2186
+ }
2187
+ function addPasskey(_x37) {
2188
+ return _addPasskey.apply(this, arguments);
2189
+ }
2190
+ function _addPasskey() {
2191
+ _addPasskey = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee64(params) {
2192
+ var res;
2193
+ return _regeneratorRuntime().wrap(function _callee64$(_context64) {
2194
+ while (1) switch (_context64.prev = _context64.next) {
2195
+ case 0:
2196
+ if (client) {
2197
+ _context64.next = 2;
2198
+ break;
2199
+ }
2200
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2201
+ case 2:
2202
+ _context64.next = 4;
2203
+ return withTurnkeyErrorHandling(function () {
2204
+ return client.addPasskey(params);
2205
+ }, callbacks, "Failed to add passkey");
2206
+ case 4:
2207
+ res = _context64.sent;
2208
+ if (!res) {
2209
+ _context64.next = 8;
2210
+ break;
2211
+ }
2212
+ _context64.next = 8;
2213
+ return refreshUser({
2214
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2215
+ });
2216
+ case 8:
2217
+ return _context64.abrupt("return", res);
2218
+ case 9:
2219
+ case "end":
2220
+ return _context64.stop();
2221
+ }
2222
+ }, _callee64);
2223
+ }));
2224
+ return _addPasskey.apply(this, arguments);
2225
+ }
2226
+ function removePasskeys(_x38) {
2227
+ return _removePasskeys.apply(this, arguments);
2228
+ }
2229
+ function _removePasskeys() {
2230
+ _removePasskeys = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee65(params) {
2231
+ var res;
2232
+ return _regeneratorRuntime().wrap(function _callee65$(_context65) {
2233
+ while (1) switch (_context65.prev = _context65.next) {
2234
+ case 0:
2235
+ if (client) {
2236
+ _context65.next = 2;
2237
+ break;
2238
+ }
2239
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2240
+ case 2:
2241
+ _context65.next = 4;
2242
+ return withTurnkeyErrorHandling(function () {
2243
+ return client.removePasskeys(params);
2244
+ }, callbacks, "Failed to remove passkeys");
2245
+ case 4:
2246
+ res = _context65.sent;
2247
+ if (!res) {
2248
+ _context65.next = 8;
2249
+ break;
2250
+ }
2251
+ _context65.next = 8;
2252
+ return refreshUser({
2253
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2254
+ });
2255
+ case 8:
2256
+ return _context65.abrupt("return", res);
2257
+ case 9:
2258
+ case "end":
2259
+ return _context65.stop();
2260
+ }
2261
+ }, _callee65);
2262
+ }));
2263
+ return _removePasskeys.apply(this, arguments);
2264
+ }
2265
+ function createWallet(_x39) {
2266
+ return _createWallet.apply(this, arguments);
2267
+ }
2268
+ function _createWallet() {
2269
+ _createWallet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee66(params) {
2270
+ var res;
2271
+ return _regeneratorRuntime().wrap(function _callee66$(_context66) {
2272
+ while (1) switch (_context66.prev = _context66.next) {
2273
+ case 0:
2274
+ if (client) {
2275
+ _context66.next = 2;
2276
+ break;
2277
+ }
2278
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2279
+ case 2:
2280
+ _context66.next = 4;
2281
+ return withTurnkeyErrorHandling(function () {
2282
+ return client.createWallet(params);
2283
+ }, callbacks, "Failed to create wallet");
2284
+ case 4:
2285
+ res = _context66.sent;
2286
+ if (!res) {
2287
+ _context66.next = 8;
2288
+ break;
2289
+ }
2290
+ _context66.next = 8;
2291
+ return refreshWallets({
2292
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2293
+ });
2294
+ case 8:
2295
+ return _context66.abrupt("return", res);
2296
+ case 9:
2297
+ case "end":
2298
+ return _context66.stop();
2299
+ }
2300
+ }, _callee66);
2301
+ }));
2302
+ return _createWallet.apply(this, arguments);
2303
+ }
2304
+ function createWalletAccounts(_x40) {
2305
+ return _createWalletAccounts.apply(this, arguments);
2306
+ }
2307
+ function _createWalletAccounts() {
2308
+ _createWalletAccounts = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee67(params) {
2309
+ var res;
2310
+ return _regeneratorRuntime().wrap(function _callee67$(_context67) {
2311
+ while (1) switch (_context67.prev = _context67.next) {
2312
+ case 0:
2313
+ if (client) {
2314
+ _context67.next = 2;
2315
+ break;
2316
+ }
2317
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2318
+ case 2:
2319
+ _context67.next = 4;
2320
+ return withTurnkeyErrorHandling(function () {
2321
+ return client.createWalletAccounts(params);
2322
+ }, callbacks, "Failed to create wallet accounts");
2323
+ case 4:
2324
+ res = _context67.sent;
2325
+ if (!res) {
2326
+ _context67.next = 8;
2327
+ break;
2328
+ }
2329
+ _context67.next = 8;
2330
+ return refreshWallets({
2331
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2332
+ });
2333
+ case 8:
2334
+ return _context67.abrupt("return", res);
2335
+ case 9:
2336
+ case "end":
2337
+ return _context67.stop();
2338
+ }
2339
+ }, _callee67);
2340
+ }));
2341
+ return _createWalletAccounts.apply(this, arguments);
2342
+ }
2343
+ function exportWallet(_x41) {
2344
+ return _exportWallet.apply(this, arguments);
2345
+ }
2346
+ function _exportWallet() {
2347
+ _exportWallet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee68(params) {
2348
+ var res;
2349
+ return _regeneratorRuntime().wrap(function _callee68$(_context68) {
2350
+ while (1) switch (_context68.prev = _context68.next) {
2351
+ case 0:
2352
+ if (client) {
2353
+ _context68.next = 2;
2354
+ break;
2355
+ }
2356
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2357
+ case 2:
2358
+ _context68.next = 4;
2359
+ return withTurnkeyErrorHandling(function () {
2360
+ return client.exportWallet(params);
2361
+ }, callbacks, "Failed to export wallet");
2362
+ case 4:
2363
+ res = _context68.sent;
2364
+ if (!res) {
2365
+ _context68.next = 8;
2366
+ break;
2367
+ }
2368
+ _context68.next = 8;
2369
+ return refreshWallets({
2370
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2371
+ });
2372
+ case 8:
2373
+ return _context68.abrupt("return", res);
2374
+ case 9:
2375
+ case "end":
2376
+ return _context68.stop();
2377
+ }
2378
+ }, _callee68);
2379
+ }));
2380
+ return _exportWallet.apply(this, arguments);
2381
+ }
2382
+ function importWallet(_x42) {
2383
+ return _importWallet.apply(this, arguments);
2384
+ }
2385
+ function _importWallet() {
2386
+ _importWallet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee69(params) {
2387
+ var res;
2388
+ return _regeneratorRuntime().wrap(function _callee69$(_context69) {
2389
+ while (1) switch (_context69.prev = _context69.next) {
2390
+ case 0:
2391
+ if (client) {
2392
+ _context69.next = 2;
2393
+ break;
2394
+ }
2395
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2396
+ case 2:
2397
+ _context69.next = 4;
2398
+ return withTurnkeyErrorHandling(function () {
2399
+ return client.importWallet(params);
2400
+ }, callbacks, "Failed to import wallet");
2401
+ case 4:
2402
+ res = _context69.sent;
2403
+ if (!res) {
2404
+ _context69.next = 8;
2405
+ break;
2406
+ }
2407
+ _context69.next = 8;
2408
+ return refreshWallets({
2409
+ stampWith: params === null || params === void 0 ? void 0 : params.stampWith
2410
+ });
2411
+ case 8:
2412
+ return _context69.abrupt("return", res);
2413
+ case 9:
2414
+ case "end":
2415
+ return _context69.stop();
2416
+ }
2417
+ }, _callee69);
2418
+ }));
2419
+ return _importWallet.apply(this, arguments);
2420
+ }
2421
+ function deleteSubOrganization(_x43) {
2422
+ return _deleteSubOrganization.apply(this, arguments);
2423
+ }
2424
+ function _deleteSubOrganization() {
2425
+ _deleteSubOrganization = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee70(params) {
2426
+ return _regeneratorRuntime().wrap(function _callee70$(_context70) {
2427
+ while (1) switch (_context70.prev = _context70.next) {
2428
+ case 0:
2429
+ if (client) {
2430
+ _context70.next = 2;
2431
+ break;
2432
+ }
2433
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2434
+ case 2:
2435
+ return _context70.abrupt("return", withTurnkeyErrorHandling(function () {
2436
+ return client.deleteSubOrganization(params);
2437
+ }, callbacks, "Failed to delete sub-organization"));
2438
+ case 3:
2439
+ case "end":
2440
+ return _context70.stop();
2441
+ }
2442
+ }, _callee70);
2443
+ }));
2444
+ return _deleteSubOrganization.apply(this, arguments);
2445
+ }
2446
+ function storeSession(_x44) {
2447
+ return _storeSession.apply(this, arguments);
2448
+ }
2449
+ function _storeSession() {
2450
+ _storeSession = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee71(params) {
2451
+ var sessionKey, session, allSessions;
2452
+ return _regeneratorRuntime().wrap(function _callee71$(_context71) {
2453
+ while (1) switch (_context71.prev = _context71.next) {
2454
+ case 0:
2455
+ if (client) {
2456
+ _context71.next = 2;
2457
+ break;
2458
+ }
2459
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2460
+ case 2:
2461
+ _context71.next = 4;
2462
+ return withTurnkeyErrorHandling(function () {
2463
+ return client.storeSession(params);
2464
+ }, callbacks, "Failed to store session");
2465
+ case 4:
2466
+ _context71.next = 6;
2467
+ return getActiveSessionKey();
2468
+ case 6:
2469
+ sessionKey = _context71.sent;
2470
+ _context71.next = 9;
2471
+ return getSession(_objectSpread2({}, sessionKey && {
2472
+ sessionKey: sessionKey
2473
+ }));
2474
+ case 9:
2475
+ session = _context71.sent;
2476
+ if (!(session && sessionKey)) {
2477
+ _context71.next = 13;
2478
+ break;
2479
+ }
2480
+ _context71.next = 13;
2481
+ return scheduleSessionExpiration({
2482
+ sessionKey: sessionKey,
2483
+ expiry: session.expiry
2484
+ });
2485
+ case 13:
2486
+ _context71.next = 15;
2487
+ return getAllSessions();
2488
+ case 15:
2489
+ allSessions = _context71.sent;
2490
+ setSession(session);
2491
+ setAllSessions(allSessions);
2492
+ return _context71.abrupt("return");
2493
+ case 19:
2494
+ case "end":
2495
+ return _context71.stop();
2496
+ }
2497
+ }, _callee71);
2498
+ }));
2499
+ return _storeSession.apply(this, arguments);
2500
+ }
2501
+ function clearSession(_x45) {
2502
+ return _clearSession.apply(this, arguments);
2503
+ }
2504
+ function _clearSession() {
2505
+ _clearSession = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee72(params) {
2506
+ var session, allSessions;
2507
+ return _regeneratorRuntime().wrap(function _callee72$(_context72) {
2508
+ while (1) switch (_context72.prev = _context72.next) {
2509
+ case 0:
2510
+ if (client) {
2511
+ _context72.next = 2;
2512
+ break;
2513
+ }
2514
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2515
+ case 2:
2516
+ _context72.next = 4;
2517
+ return withTurnkeyErrorHandling(function () {
2518
+ return client.clearSession(params);
2519
+ }, callbacks, "Failed to clear session");
2520
+ case 4:
2521
+ _context72.next = 6;
2522
+ return getSession();
2523
+ case 6:
2524
+ session = _context72.sent;
2525
+ _context72.next = 9;
2526
+ return getAllSessions();
2527
+ case 9:
2528
+ allSessions = _context72.sent;
2529
+ setSession(session);
2530
+ setAllSessions(allSessions);
2531
+ return _context72.abrupt("return");
2532
+ case 13:
2533
+ case "end":
2534
+ return _context72.stop();
2535
+ }
2536
+ }, _callee72);
2537
+ }));
2538
+ return _clearSession.apply(this, arguments);
2539
+ }
2540
+ function clearAllSessions() {
2541
+ return _clearAllSessions.apply(this, arguments);
2542
+ }
2543
+ function _clearAllSessions() {
2544
+ _clearAllSessions = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee73() {
2545
+ return _regeneratorRuntime().wrap(function _callee73$(_context73) {
2546
+ while (1) switch (_context73.prev = _context73.next) {
2547
+ case 0:
2548
+ if (client) {
2549
+ _context73.next = 2;
2550
+ break;
2551
+ }
2552
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2553
+ case 2:
2554
+ setSession(undefined);
2555
+ setAllSessions(undefined);
2556
+ _context73.next = 6;
2557
+ return withTurnkeyErrorHandling(function () {
2558
+ return client.clearAllSessions();
2559
+ }, callbacks, "Failed to clear all sessions");
2560
+ case 6:
2561
+ return _context73.abrupt("return", _context73.sent);
2562
+ case 7:
2563
+ case "end":
2564
+ return _context73.stop();
2565
+ }
2566
+ }, _callee73);
2567
+ }));
2568
+ return _clearAllSessions.apply(this, arguments);
2569
+ }
2570
+ function refreshSession(_x46) {
2571
+ return _refreshSession.apply(this, arguments);
2572
+ }
2573
+ function _refreshSession() {
2574
+ _refreshSession = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee74(params) {
2575
+ var _params$sessionKey;
2576
+ var activeSessionKey, sessionKey, res, session, allSessions;
2577
+ return _regeneratorRuntime().wrap(function _callee74$(_context74) {
2578
+ while (1) switch (_context74.prev = _context74.next) {
2579
+ case 0:
2580
+ if (client) {
2581
+ _context74.next = 2;
2582
+ break;
2583
+ }
2584
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2585
+ case 2:
2586
+ _context74.next = 4;
2587
+ return client.getActiveSessionKey();
2588
+ case 4:
2589
+ activeSessionKey = _context74.sent;
2590
+ if (activeSessionKey) {
2591
+ _context74.next = 7;
2592
+ break;
2593
+ }
2594
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
2595
+ case 7:
2596
+ sessionKey = (_params$sessionKey = params === null || params === void 0 ? void 0 : params.sessionKey) !== null && _params$sessionKey !== void 0 ? _params$sessionKey : activeSessionKey;
2597
+ _context74.next = 10;
2598
+ return withTurnkeyErrorHandling(function () {
2599
+ return client.refreshSession(_objectSpread2({}, params));
2600
+ }, callbacks, "Failed to refresh session");
2601
+ case 10:
2602
+ res = _context74.sent;
2603
+ _context74.next = 13;
2604
+ return getSession({
2605
+ sessionKey: sessionKey
2606
+ });
2607
+ case 13:
2608
+ session = _context74.sent;
2609
+ if (!(session && sessionKey)) {
2610
+ _context74.next = 17;
2611
+ break;
2612
+ }
2613
+ _context74.next = 17;
2614
+ return scheduleSessionExpiration(_objectSpread2({
2615
+ sessionKey: sessionKey,
2616
+ expiry: session.expiry
2617
+ }, (params === null || params === void 0 ? void 0 : params.expirationSeconds) && {
2618
+ expirationSeconds: params === null || params === void 0 ? void 0 : params.expirationSeconds
2619
+ }));
2620
+ case 17:
2621
+ _context74.next = 19;
2622
+ return getAllSessions();
2623
+ case 19:
2624
+ allSessions = _context74.sent;
2625
+ setSession(session);
2626
+ setAllSessions(allSessions);
2627
+ return _context74.abrupt("return", res);
2628
+ case 23:
2629
+ case "end":
2630
+ return _context74.stop();
2631
+ }
2632
+ }, _callee74);
2633
+ }));
2634
+ return _refreshSession.apply(this, arguments);
2635
+ }
2636
+ function getSession(_x47) {
2637
+ return _getSession.apply(this, arguments);
2638
+ }
2639
+ function _getSession() {
2640
+ _getSession = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee75(params) {
2641
+ return _regeneratorRuntime().wrap(function _callee75$(_context75) {
2642
+ while (1) switch (_context75.prev = _context75.next) {
2643
+ case 0:
2644
+ if (client) {
2645
+ _context75.next = 2;
2646
+ break;
2647
+ }
2648
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2649
+ case 2:
2650
+ return _context75.abrupt("return", withTurnkeyErrorHandling(function () {
2651
+ return client.getSession(params);
2652
+ }, callbacks, "Failed to get session"));
2653
+ case 3:
2654
+ case "end":
2655
+ return _context75.stop();
2656
+ }
2657
+ }, _callee75);
2658
+ }));
2659
+ return _getSession.apply(this, arguments);
2660
+ }
2661
+ function getAllSessions() {
2662
+ return _getAllSessions.apply(this, arguments);
2663
+ }
2664
+ function _getAllSessions() {
2665
+ _getAllSessions = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee76() {
2666
+ return _regeneratorRuntime().wrap(function _callee76$(_context76) {
2667
+ while (1) switch (_context76.prev = _context76.next) {
2668
+ case 0:
2669
+ if (client) {
2670
+ _context76.next = 2;
2671
+ break;
2672
+ }
2673
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2674
+ case 2:
2675
+ return _context76.abrupt("return", withTurnkeyErrorHandling(function () {
2676
+ return client.getAllSessions();
2677
+ }, callbacks, "Failed to get all sessions"));
2678
+ case 3:
2679
+ case "end":
2680
+ return _context76.stop();
2681
+ }
2682
+ }, _callee76);
2683
+ }));
2684
+ return _getAllSessions.apply(this, arguments);
2685
+ }
2686
+ function setActiveSession(_x48) {
2687
+ return _setActiveSession.apply(this, arguments);
2688
+ }
2689
+ function _setActiveSession() {
2690
+ _setActiveSession = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee77(params) {
2691
+ var session;
2692
+ return _regeneratorRuntime().wrap(function _callee77$(_context77) {
2693
+ while (1) switch (_context77.prev = _context77.next) {
2694
+ case 0:
2695
+ if (client) {
2696
+ _context77.next = 2;
2697
+ break;
2698
+ }
2699
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2700
+ case 2:
2701
+ _context77.next = 4;
2702
+ return withTurnkeyErrorHandling(function () {
2703
+ return client.getSession({
2704
+ sessionKey: params.sessionKey
2705
+ });
2706
+ }, callbacks, "Failed to get session");
2707
+ case 4:
2708
+ session = _context77.sent;
2709
+ if (session) {
2710
+ _context77.next = 7;
2711
+ break;
2712
+ }
2713
+ throw new TurnkeyError("Session not found.", TurnkeyErrorCodes.NOT_FOUND);
2714
+ case 7:
2715
+ _context77.next = 9;
2716
+ return withTurnkeyErrorHandling(function () {
2717
+ return client.setActiveSession(params);
2718
+ }, callbacks, "Failed to set active session");
2719
+ case 9:
2720
+ setSession(session);
2721
+ return _context77.abrupt("return");
2722
+ case 11:
2723
+ case "end":
2724
+ return _context77.stop();
2725
+ }
2726
+ }, _callee77);
2727
+ }));
2728
+ return _setActiveSession.apply(this, arguments);
2729
+ }
2730
+ function getActiveSessionKey() {
2731
+ return _getActiveSessionKey.apply(this, arguments);
2732
+ }
2733
+ function _getActiveSessionKey() {
2734
+ _getActiveSessionKey = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee78() {
2735
+ return _regeneratorRuntime().wrap(function _callee78$(_context78) {
2736
+ while (1) switch (_context78.prev = _context78.next) {
2737
+ case 0:
2738
+ if (client) {
2739
+ _context78.next = 2;
2740
+ break;
2741
+ }
2742
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2743
+ case 2:
2744
+ return _context78.abrupt("return", withTurnkeyErrorHandling(function () {
2745
+ return client.getActiveSessionKey();
2746
+ }, callbacks, "Failed to get active session key"));
2747
+ case 3:
2748
+ case "end":
2749
+ return _context78.stop();
2750
+ }
2751
+ }, _callee78);
2752
+ }));
2753
+ return _getActiveSessionKey.apply(this, arguments);
2754
+ }
2755
+ function clearUnusedKeyPairs() {
2756
+ return _clearUnusedKeyPairs.apply(this, arguments);
2757
+ }
2758
+ function _clearUnusedKeyPairs() {
2759
+ _clearUnusedKeyPairs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee79() {
2760
+ return _regeneratorRuntime().wrap(function _callee79$(_context79) {
2761
+ while (1) switch (_context79.prev = _context79.next) {
2762
+ case 0:
2763
+ if (client) {
2764
+ _context79.next = 2;
2765
+ break;
2766
+ }
2767
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2768
+ case 2:
2769
+ return _context79.abrupt("return", withTurnkeyErrorHandling(function () {
2770
+ return client.clearUnusedKeyPairs();
2771
+ }, callbacks, "Failed to clear unused key pairs"));
2772
+ case 3:
2773
+ case "end":
2774
+ return _context79.stop();
2775
+ }
2776
+ }, _callee79);
2777
+ }));
2778
+ return _clearUnusedKeyPairs.apply(this, arguments);
2779
+ }
2780
+ function createApiKeyPair(_x49) {
2781
+ return _createApiKeyPair.apply(this, arguments);
2782
+ }
2783
+ function _createApiKeyPair() {
2784
+ _createApiKeyPair = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee80(params) {
2785
+ return _regeneratorRuntime().wrap(function _callee80$(_context80) {
2786
+ while (1) switch (_context80.prev = _context80.next) {
2787
+ case 0:
2788
+ if (client) {
2789
+ _context80.next = 2;
2790
+ break;
2791
+ }
2792
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2793
+ case 2:
2794
+ return _context80.abrupt("return", withTurnkeyErrorHandling(function () {
2795
+ return client.createApiKeyPair(params);
2796
+ }, callbacks, "Failed to create API key pair"));
2797
+ case 3:
2798
+ case "end":
2799
+ return _context80.stop();
2800
+ }
2801
+ }, _callee80);
2802
+ }));
2803
+ return _createApiKeyPair.apply(this, arguments);
2804
+ }
2805
+ function getProxyAuthConfig() {
2806
+ return _getProxyAuthConfig.apply(this, arguments);
2807
+ }
2808
+ function _getProxyAuthConfig() {
2809
+ _getProxyAuthConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee81() {
2810
+ return _regeneratorRuntime().wrap(function _callee81$(_context81) {
2811
+ while (1) switch (_context81.prev = _context81.next) {
2812
+ case 0:
2813
+ if (client) {
2814
+ _context81.next = 2;
2815
+ break;
2816
+ }
2817
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2818
+ case 2:
2819
+ return _context81.abrupt("return", withTurnkeyErrorHandling(function () {
2820
+ return client.getProxyAuthConfig();
2821
+ }, callbacks, "Failed to get proxy auth config"));
2822
+ case 3:
2823
+ case "end":
2824
+ return _context81.stop();
2825
+ }
2826
+ }, _callee81);
2827
+ }));
2828
+ return _getProxyAuthConfig.apply(this, arguments);
2829
+ }
2830
+ function refreshUser(_x50) {
2831
+ return _refreshUser.apply(this, arguments);
2832
+ }
2833
+ function _refreshUser() {
2834
+ _refreshUser = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee82(params) {
2835
+ var _ref36, stampWith, user;
2836
+ return _regeneratorRuntime().wrap(function _callee82$(_context82) {
2837
+ while (1) switch (_context82.prev = _context82.next) {
2838
+ case 0:
2839
+ _ref36 = params || {}, stampWith = _ref36.stampWith;
2840
+ if (client) {
2841
+ _context82.next = 3;
2842
+ break;
2843
+ }
2844
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2845
+ case 3:
2846
+ _context82.next = 5;
2847
+ return withTurnkeyErrorHandling(function () {
2848
+ return fetchUser({
2849
+ stampWith: stampWith
2850
+ });
2851
+ }, callbacks, "Failed to refresh user");
2852
+ case 5:
2853
+ user = _context82.sent;
2854
+ if (user) {
2855
+ setUser(user);
2856
+ }
2857
+ case 7:
2858
+ case "end":
2859
+ return _context82.stop();
2860
+ }
2861
+ }, _callee82);
2862
+ }));
2863
+ return _refreshUser.apply(this, arguments);
2864
+ }
2865
+ function refreshWallets(_x51) {
2866
+ return _refreshWallets.apply(this, arguments);
2867
+ }
2868
+ function _refreshWallets() {
2869
+ _refreshWallets = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee83(params) {
2870
+ var _ref37, stampWith, wallets;
2871
+ return _regeneratorRuntime().wrap(function _callee83$(_context83) {
2872
+ while (1) switch (_context83.prev = _context83.next) {
2873
+ case 0:
2874
+ _ref37 = params || {}, stampWith = _ref37.stampWith;
2875
+ if (client) {
2876
+ _context83.next = 3;
2877
+ break;
2878
+ }
2879
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
2880
+ case 3:
2881
+ _context83.next = 5;
2882
+ return withTurnkeyErrorHandling(function () {
2883
+ return fetchWallets({
2884
+ stampWith: stampWith
2885
+ });
2886
+ }, callbacks, "Failed to refresh wallets");
2887
+ case 5:
2888
+ wallets = _context83.sent;
2889
+ if (wallets) {
2890
+ setWallets(wallets);
2891
+ }
2892
+ case 7:
2893
+ case "end":
2894
+ return _context83.stop();
2895
+ }
2896
+ }, _callee83);
2897
+ }));
2898
+ return _refreshWallets.apply(this, arguments);
2899
+ }
2900
+ function handleGoogleOauth(_x52) {
2901
+ return _handleGoogleOauth.apply(this, arguments);
2902
+ }
2903
+ function _handleGoogleOauth() {
2904
+ _handleGoogleOauth = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee84(params) {
2905
+ var _masterConfig$auth17, _masterConfig$auth17$, _masterConfig$auth$oa2, _masterConfig$auth18, _masterConfig$auth18$;
2906
+ var _ref38, _ref38$clientId, clientId, _ref38$openInPage, openInPage, additionalParameters, _masterConfig$auth19, _masterConfig$auth19$, _masterConfig$auth20, flow, redirectURI, publicKey, nonce, googleAuthUrl, state, additionalState, width, height, left, top, authWindow;
2907
+ return _regeneratorRuntime().wrap(function _callee84$(_context84) {
2908
+ while (1) switch (_context84.prev = _context84.next) {
2909
+ case 0:
2910
+ _ref38 = params || {}, _ref38$clientId = _ref38.clientId, clientId = _ref38$clientId === void 0 ? masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth17 = masterConfig.auth) === null || _masterConfig$auth17 === void 0 ? void 0 : (_masterConfig$auth17$ = _masterConfig$auth17.oauthConfig) === null || _masterConfig$auth17$ === void 0 ? void 0 : _masterConfig$auth17$.googleClientId : _ref38$clientId, _ref38$openInPage = _ref38.openInPage, openInPage = _ref38$openInPage === void 0 ? (_masterConfig$auth$oa2 = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth18 = masterConfig.auth) === null || _masterConfig$auth18 === void 0 ? void 0 : (_masterConfig$auth18$ = _masterConfig$auth18.oauthConfig) === null || _masterConfig$auth18$ === void 0 ? void 0 : _masterConfig$auth18$.openOauthInPage) !== null && _masterConfig$auth$oa2 !== void 0 ? _masterConfig$auth$oa2 : false : _ref38$openInPage, additionalParameters = _ref38.additionalState;
2911
+ _context84.prev = 1;
2912
+ if (masterConfig) {
2913
+ _context84.next = 4;
2914
+ break;
2915
+ }
2916
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.INVALID_CONFIGURATION);
2917
+ case 4:
2918
+ if (clientId) {
2919
+ _context84.next = 6;
2920
+ break;
2921
+ }
2922
+ throw new TurnkeyError("Google Client ID is not configured.", TurnkeyErrorCodes.INVALID_CONFIGURATION);
2923
+ case 6:
2924
+ if ((_masterConfig$auth19 = masterConfig.auth) !== null && _masterConfig$auth19 !== void 0 && (_masterConfig$auth19$ = _masterConfig$auth19.oauthConfig) !== null && _masterConfig$auth19$ !== void 0 && _masterConfig$auth19$.oauthRedirectUri) {
2925
+ _context84.next = 8;
2926
+ break;
2927
+ }
2928
+ throw new TurnkeyError("OAuth Redirect URI is not configured.", TurnkeyErrorCodes.INVALID_CONFIGURATION);
2929
+ case 8:
2930
+ flow = openInPage ? "redirect" : "popup";
2931
+ redirectURI = (_masterConfig$auth20 = masterConfig.auth) === null || _masterConfig$auth20 === void 0 ? void 0 : _masterConfig$auth20.oauthConfig.oauthRedirectUri.replace(/\/$/, ""); // Create key pair and generate nonce
2932
+ _context84.next = 12;
2933
+ return createApiKeyPair();
2934
+ case 12:
2935
+ publicKey = _context84.sent;
2936
+ if (publicKey) {
2937
+ _context84.next = 15;
2938
+ break;
2939
+ }
2940
+ throw new Error("Failed to create public key for OAuth.");
2941
+ case 15:
2942
+ nonce = bytesToHex(sha256(publicKey)); // Construct Google Auth URL
2943
+ googleAuthUrl = new URL(GOOGLE_AUTH_URL);
2944
+ googleAuthUrl.searchParams.set("client_id", clientId);
2945
+ googleAuthUrl.searchParams.set("redirect_uri", redirectURI);
2946
+ googleAuthUrl.searchParams.set("response_type", "id_token");
2947
+ googleAuthUrl.searchParams.set("scope", "openid email profile");
2948
+ googleAuthUrl.searchParams.set("nonce", nonce);
2949
+ googleAuthUrl.searchParams.set("prompt", "select_account");
2950
+ // Create state parameter
2951
+ state = "provider=google&flow=".concat(flow, "&publicKey=").concat(encodeURIComponent(publicKey));
2952
+ if (additionalParameters) {
2953
+ additionalState = Object.entries(additionalParameters).map(function (_ref39) {
2954
+ var _ref40 = _slicedToArray(_ref39, 2),
2955
+ key = _ref40[0],
2956
+ value = _ref40[1];
2957
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
2958
+ }).join("&");
2959
+ if (additionalState) {
2960
+ state += "&".concat(additionalState);
2961
+ }
2962
+ }
2963
+ googleAuthUrl.searchParams.set("state", state);
2964
+ if (!openInPage) {
2965
+ _context84.next = 31;
2966
+ break;
2967
+ }
2968
+ // Redirect current page to Google Auth
2969
+ window.location.href = googleAuthUrl.toString();
2970
+ return _context84.abrupt("return", new Promise(function (_, reject) {
2971
+ // By here, the page should have already redirected. We wait here since the function is async.
2972
+ // We want any function that runs this to simply wait until the page redirects.
2973
+ // A 5 min timeout is set just in case, idk
2974
+ var timeout = setTimeout(function () {
2975
+ reject(new Error("Authentication timed out."));
2976
+ }, 300000); // 5 minutes
2977
+ // If the page is unloaded (user navigates away), clear the timeout
2978
+ window.addEventListener("beforeunload", function () {
2979
+ return clearTimeout(timeout);
2980
+ });
2981
+ }));
2982
+ case 31:
2983
+ // Open popup window
2984
+ width = popupWidth;
2985
+ height = popupHeight;
2986
+ left = window.screenX + (window.innerWidth - width) / 2;
2987
+ top = window.screenY + (window.innerHeight - height) / 2;
2988
+ authWindow = window.open("about:blank", "_blank", "width=".concat(width, ",height=").concat(height, ",top=").concat(top, ",left=").concat(left, ",scrollbars=yes,resizable=yes"));
2989
+ if (authWindow) {
2990
+ _context84.next = 38;
2991
+ break;
2992
+ }
2993
+ throw new Error("Failed to open Google login window.");
2994
+ case 38:
2995
+ authWindow.location.href = googleAuthUrl.toString();
2996
+ // Return a promise that resolves when the OAuth flow completes
2997
+ // This following code will only run for the popup flow
2998
+ return _context84.abrupt("return", new Promise(function (resolve, reject) {
2999
+ var interval = setInterval(function () {
3000
+ try {
3001
+ // Check if window was closed without completing auth
3002
+ if (authWindow.closed) {
3003
+ clearInterval(interval);
3004
+ reject(new Error("Authentication window was closed."));
3005
+ return;
3006
+ }
3007
+ var url = authWindow.location.href || "";
3008
+ if (url.startsWith(window.location.origin)) {
3009
+ var hashParams = new URLSearchParams(url.split("#")[1]);
3010
+ var idToken = hashParams.get("id_token");
3011
+ if (idToken) {
3012
+ authWindow.close();
3013
+ clearInterval(interval);
3014
+ if (params !== null && params !== void 0 && params.onOauthSuccess) {
3015
+ params.onOauthSuccess({
3016
+ oidcToken: idToken,
3017
+ providerName: "google"
3018
+ });
3019
+ } else if (callbacks !== null && callbacks !== void 0 && callbacks.onOauthRedirect) {
3020
+ callbacks.onOauthRedirect({
3021
+ idToken: idToken,
3022
+ publicKey: publicKey
3023
+ });
3024
+ } else {
3025
+ completeOauth({
3026
+ oidcToken: idToken,
3027
+ publicKey: publicKey,
3028
+ providerName: "google"
3029
+ }).then(function () {
3030
+ return resolve();
3031
+ })["catch"](reject);
3032
+ return;
3033
+ }
3034
+ resolve();
3035
+ }
3036
+ }
3037
+ } catch (error) {
3038
+ // Ignore cross-origin errors
3039
+ }
3040
+ }, 500);
3041
+ if (authWindow.closed) {
3042
+ clearInterval(interval);
3043
+ }
3044
+ }));
3045
+ case 40:
3046
+ _context84.next = 45;
3047
+ break;
3048
+ case 42:
3049
+ _context84.prev = 42;
3050
+ _context84.t0 = _context84["catch"](1);
3051
+ throw _context84.t0;
3052
+ case 45:
3053
+ case "end":
3054
+ return _context84.stop();
3055
+ }
3056
+ }, _callee84, null, [[1, 42]]);
3057
+ }));
3058
+ return _handleGoogleOauth.apply(this, arguments);
3059
+ }
3060
+ function handleAppleOauth(_x53) {
3061
+ return _handleAppleOauth.apply(this, arguments);
3062
+ }
3063
+ function _handleAppleOauth() {
3064
+ _handleAppleOauth = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee85(params) {
3065
+ var _masterConfig$auth21, _masterConfig$auth21$, _masterConfig$auth$oa3, _masterConfig$auth22, _masterConfig$auth22$;
3066
+ var _ref41, _ref41$clientId, clientId, _ref41$openInPage, openInPage, additionalParameters, _masterConfig$auth23, _masterConfig$auth23$, _masterConfig$auth24, flow, redirectURI, publicKey, nonce, appleAuthUrl, state, additionalState, width, height, left, top, authWindow;
3067
+ return _regeneratorRuntime().wrap(function _callee85$(_context85) {
3068
+ while (1) switch (_context85.prev = _context85.next) {
3069
+ case 0:
3070
+ _ref41 = params || {}, _ref41$clientId = _ref41.clientId, clientId = _ref41$clientId === void 0 ? masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth21 = masterConfig.auth) === null || _masterConfig$auth21 === void 0 ? void 0 : (_masterConfig$auth21$ = _masterConfig$auth21.oauthConfig) === null || _masterConfig$auth21$ === void 0 ? void 0 : _masterConfig$auth21$.appleClientId : _ref41$clientId, _ref41$openInPage = _ref41.openInPage, openInPage = _ref41$openInPage === void 0 ? (_masterConfig$auth$oa3 = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth22 = masterConfig.auth) === null || _masterConfig$auth22 === void 0 ? void 0 : (_masterConfig$auth22$ = _masterConfig$auth22.oauthConfig) === null || _masterConfig$auth22$ === void 0 ? void 0 : _masterConfig$auth22$.openOauthInPage) !== null && _masterConfig$auth$oa3 !== void 0 ? _masterConfig$auth$oa3 : false : _ref41$openInPage, additionalParameters = _ref41.additionalState;
3071
+ _context85.prev = 1;
3072
+ if (masterConfig) {
3073
+ _context85.next = 4;
3074
+ break;
3075
+ }
3076
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.INVALID_CONFIGURATION);
3077
+ case 4:
3078
+ if (clientId) {
3079
+ _context85.next = 6;
3080
+ break;
3081
+ }
3082
+ throw new TurnkeyError("Apple Client ID is not configured.", TurnkeyErrorCodes.INVALID_CONFIGURATION);
3083
+ case 6:
3084
+ if ((_masterConfig$auth23 = masterConfig.auth) !== null && _masterConfig$auth23 !== void 0 && (_masterConfig$auth23$ = _masterConfig$auth23.oauthConfig) !== null && _masterConfig$auth23$ !== void 0 && _masterConfig$auth23$.oauthRedirectUri) {
3085
+ _context85.next = 8;
3086
+ break;
3087
+ }
3088
+ throw new TurnkeyError("OAuth Redirect URI is not configured.", TurnkeyErrorCodes.INVALID_CONFIGURATION);
3089
+ case 8:
3090
+ flow = openInPage ? "redirect" : "popup";
3091
+ redirectURI = (_masterConfig$auth24 = masterConfig.auth) === null || _masterConfig$auth24 === void 0 ? void 0 : _masterConfig$auth24.oauthConfig.oauthRedirectUri; // TODO (Amir): Apple needs the '/' at the end. Maybe we should add it if not there?
3092
+ // Create key pair and generate nonce
3093
+ _context85.next = 12;
3094
+ return createApiKeyPair();
3095
+ case 12:
3096
+ publicKey = _context85.sent;
3097
+ if (publicKey) {
3098
+ _context85.next = 15;
3099
+ break;
3100
+ }
3101
+ throw new Error("Failed to create public key for OAuth.");
3102
+ case 15:
3103
+ nonce = bytesToHex(sha256(publicKey)); // Construct Apple Auth URL
3104
+ appleAuthUrl = new URL(APPLE_AUTH_URL);
3105
+ appleAuthUrl.searchParams.set("client_id", clientId);
3106
+ appleAuthUrl.searchParams.set("redirect_uri", redirectURI);
3107
+ appleAuthUrl.searchParams.set("response_type", "code id_token");
3108
+ appleAuthUrl.searchParams.set("response_mode", "fragment");
3109
+ appleAuthUrl.searchParams.set("nonce", nonce);
3110
+ // Create state parameter
3111
+ state = "provider=apple&flow=".concat(flow, "&publicKey=").concat(encodeURIComponent(publicKey));
3112
+ if (additionalParameters) {
3113
+ additionalState = Object.entries(additionalParameters).map(function (_ref42) {
3114
+ var _ref43 = _slicedToArray(_ref42, 2),
3115
+ key = _ref43[0],
3116
+ value = _ref43[1];
3117
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
3118
+ }).join("&");
3119
+ if (additionalState) {
3120
+ state += "&".concat(additionalState);
3121
+ }
3122
+ }
3123
+ appleAuthUrl.searchParams.set("state", state);
3124
+ if (!openInPage) {
3125
+ _context85.next = 30;
3126
+ break;
3127
+ }
3128
+ // Redirect current page to Apple Auth
3129
+ window.location.href = appleAuthUrl.toString();
3130
+ return _context85.abrupt("return", new Promise(function (_, reject) {
3131
+ // Set a timeout just in case the redirect doesn't happen
3132
+ var timeout = setTimeout(function () {
3133
+ reject(new Error("Authentication timed out."));
3134
+ }, 300000); // 5 minutes
3135
+ // If the page is unloaded (user navigates away), clear the timeout
3136
+ window.addEventListener("beforeunload", function () {
3137
+ return clearTimeout(timeout);
3138
+ });
3139
+ }));
3140
+ case 30:
3141
+ // Open popup window
3142
+ width = popupWidth;
3143
+ height = popupHeight;
3144
+ left = window.screenX + (window.innerWidth - width) / 2;
3145
+ top = window.screenY + (window.innerHeight - height) / 2;
3146
+ authWindow = window.open("about:blank", "_blank", "width=".concat(width, ",height=").concat(height, ",top=").concat(top, ",left=").concat(left, ",scrollbars=yes,resizable=yes"));
3147
+ if (authWindow) {
3148
+ _context85.next = 37;
3149
+ break;
3150
+ }
3151
+ throw new Error("Failed to open Apple login window.");
3152
+ case 37:
3153
+ authWindow.location.href = appleAuthUrl.toString();
3154
+ // Return a promise that resolves when the OAuth flow completes
3155
+ return _context85.abrupt("return", new Promise(function (resolve, reject) {
3156
+ var interval = setInterval(function () {
3157
+ try {
3158
+ // Check if window was closed without completing auth
3159
+ if (authWindow.closed) {
3160
+ clearInterval(interval);
3161
+ reject(new Error("Authentication window was closed."));
3162
+ return;
3163
+ }
3164
+ var url = authWindow.location.href || "";
3165
+ if (url.startsWith(window.location.origin)) {
3166
+ var hashParams = new URLSearchParams(url.split("#")[1]);
3167
+ var idToken = hashParams.get("id_token");
3168
+ if (idToken) {
3169
+ authWindow.close();
3170
+ clearInterval(interval);
3171
+ if (params !== null && params !== void 0 && params.onOauthSuccess) {
3172
+ params.onOauthSuccess({
3173
+ oidcToken: idToken,
3174
+ providerName: "apple"
3175
+ });
3176
+ } else if (callbacks !== null && callbacks !== void 0 && callbacks.onOauthRedirect) {
3177
+ callbacks.onOauthRedirect({
3178
+ idToken: idToken,
3179
+ publicKey: publicKey
3180
+ });
3181
+ } else {
3182
+ completeOauth({
3183
+ oidcToken: idToken,
3184
+ publicKey: publicKey,
3185
+ providerName: "apple"
3186
+ }).then(function () {
3187
+ return resolve();
3188
+ })["catch"](reject);
3189
+ return;
3190
+ }
3191
+ resolve();
3192
+ }
3193
+ }
3194
+ } catch (error) {
3195
+ // Ignore cross-origin errors
3196
+ }
3197
+ }, 500);
3198
+ if (authWindow.closed) {
3199
+ clearInterval(interval);
3200
+ }
3201
+ }));
3202
+ case 39:
3203
+ _context85.next = 44;
3204
+ break;
3205
+ case 41:
3206
+ _context85.prev = 41;
3207
+ _context85.t0 = _context85["catch"](1);
3208
+ throw _context85.t0;
3209
+ case 44:
3210
+ case "end":
3211
+ return _context85.stop();
3212
+ }
3213
+ }, _callee85, null, [[1, 41]]);
3214
+ }));
3215
+ return _handleAppleOauth.apply(this, arguments);
3216
+ }
3217
+ function handleFacebookOauth(_x54) {
3218
+ return _handleFacebookOauth.apply(this, arguments);
3219
+ }
3220
+ function _handleFacebookOauth() {
3221
+ _handleFacebookOauth = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee86(params) {
3222
+ var _masterConfig$auth25, _masterConfig$auth25$, _masterConfig$auth$oa4, _masterConfig$auth26, _masterConfig$auth26$;
3223
+ var _ref44, _ref44$clientId, clientId, _ref44$openInPage, openInPage, additionalParameters, _masterConfig$auth27, _masterConfig$auth27$, _masterConfig$auth28, flow, redirectURI, publicKey, nonce, _yield$generateChalle, verifier, codeChallenge, facebookAuthUrl, state, additionalState, width, height, left, top, authWindow;
3224
+ return _regeneratorRuntime().wrap(function _callee86$(_context86) {
3225
+ while (1) switch (_context86.prev = _context86.next) {
3226
+ case 0:
3227
+ _ref44 = params || {}, _ref44$clientId = _ref44.clientId, clientId = _ref44$clientId === void 0 ? masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth25 = masterConfig.auth) === null || _masterConfig$auth25 === void 0 ? void 0 : (_masterConfig$auth25$ = _masterConfig$auth25.oauthConfig) === null || _masterConfig$auth25$ === void 0 ? void 0 : _masterConfig$auth25$.facebookClientId : _ref44$clientId, _ref44$openInPage = _ref44.openInPage, openInPage = _ref44$openInPage === void 0 ? (_masterConfig$auth$oa4 = masterConfig === null || masterConfig === void 0 ? void 0 : (_masterConfig$auth26 = masterConfig.auth) === null || _masterConfig$auth26 === void 0 ? void 0 : (_masterConfig$auth26$ = _masterConfig$auth26.oauthConfig) === null || _masterConfig$auth26$ === void 0 ? void 0 : _masterConfig$auth26$.openOauthInPage) !== null && _masterConfig$auth$oa4 !== void 0 ? _masterConfig$auth$oa4 : false : _ref44$openInPage, additionalParameters = _ref44.additionalState;
3228
+ _context86.prev = 1;
3229
+ if (masterConfig) {
3230
+ _context86.next = 4;
3231
+ break;
3232
+ }
3233
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.INVALID_CONFIGURATION);
3234
+ case 4:
3235
+ if (clientId) {
3236
+ _context86.next = 6;
3237
+ break;
3238
+ }
3239
+ throw new TurnkeyError("Facebook Client ID is not configured.", TurnkeyErrorCodes.INVALID_CONFIGURATION);
3240
+ case 6:
3241
+ if ((_masterConfig$auth27 = masterConfig.auth) !== null && _masterConfig$auth27 !== void 0 && (_masterConfig$auth27$ = _masterConfig$auth27.oauthConfig) !== null && _masterConfig$auth27$ !== void 0 && _masterConfig$auth27$.oauthRedirectUri) {
3242
+ _context86.next = 8;
3243
+ break;
3244
+ }
3245
+ throw new TurnkeyError("OAuth Redirect URI is not configured.", TurnkeyErrorCodes.INVALID_CONFIGURATION);
3246
+ case 8:
3247
+ flow = openInPage ? "redirect" : "popup";
3248
+ redirectURI = (_masterConfig$auth28 = masterConfig.auth) === null || _masterConfig$auth28 === void 0 ? void 0 : _masterConfig$auth28.oauthConfig.oauthRedirectUri; // Create key pair and generate nonce
3249
+ _context86.next = 12;
3250
+ return createApiKeyPair();
3251
+ case 12:
3252
+ publicKey = _context86.sent;
3253
+ if (publicKey) {
3254
+ _context86.next = 15;
3255
+ break;
3256
+ }
3257
+ throw new Error("Failed to create public key for OAuth.");
3258
+ case 15:
3259
+ nonce = bytesToHex(sha256(publicKey)); // Generate PKCE challenge pair
3260
+ _context86.next = 18;
3261
+ return generateChallengePair();
3262
+ case 18:
3263
+ _yield$generateChalle = _context86.sent;
3264
+ verifier = _yield$generateChalle.verifier;
3265
+ codeChallenge = _yield$generateChalle.codeChallenge;
3266
+ // Store verifier for later token exchange
3267
+ sessionStorage.setItem("facebook_verifier", verifier);
3268
+ // Construct Facebook Auth URL
3269
+ facebookAuthUrl = new URL(FACEBOOK_AUTH_URL);
3270
+ facebookAuthUrl.searchParams.set("client_id", clientId);
3271
+ facebookAuthUrl.searchParams.set("redirect_uri", redirectURI);
3272
+ facebookAuthUrl.searchParams.set("response_type", "code");
3273
+ facebookAuthUrl.searchParams.set("code_challenge", codeChallenge);
3274
+ facebookAuthUrl.searchParams.set("code_challenge_method", "S256");
3275
+ facebookAuthUrl.searchParams.set("nonce", nonce);
3276
+ facebookAuthUrl.searchParams.set("scope", "openid");
3277
+ // Create state parameter
3278
+ state = "provider=facebook&flow=".concat(flow, "&publicKey=").concat(encodeURIComponent(publicKey));
3279
+ if (additionalParameters) {
3280
+ additionalState = Object.entries(additionalParameters).map(function (_ref45) {
3281
+ var _ref46 = _slicedToArray(_ref45, 2),
3282
+ key = _ref46[0],
3283
+ value = _ref46[1];
3284
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
3285
+ }).join("&");
3286
+ if (additionalState) {
3287
+ state += "&".concat(additionalState);
3288
+ }
3289
+ }
3290
+ facebookAuthUrl.searchParams.set("state", state);
3291
+ if (!openInPage) {
3292
+ _context86.next = 38;
3293
+ break;
3294
+ }
3295
+ // Redirect current page to Facebook Auth
3296
+ window.location.href = facebookAuthUrl.toString();
3297
+ return _context86.abrupt("return", new Promise(function (_, reject) {
3298
+ // Set a timeout just in case the redirect doesn't happen
3299
+ var timeout = setTimeout(function () {
3300
+ reject(new Error("Authentication timed out."));
3301
+ }, 300000); // 5 minutes
3302
+ // If the page is unloaded (user navigates away), clear the timeout
3303
+ window.addEventListener("beforeunload", function () {
3304
+ return clearTimeout(timeout);
3305
+ });
3306
+ }));
3307
+ case 38:
3308
+ // Open popup window
3309
+ width = popupWidth;
3310
+ height = popupHeight;
3311
+ left = window.screenX + (window.innerWidth - width) / 2;
3312
+ top = window.screenY + (window.innerHeight - height) / 2;
3313
+ authWindow = window.open("about:blank", "_blank", "width=".concat(width, ",height=").concat(height, ",top=").concat(top, ",left=").concat(left, ",scrollbars=yes,resizable=yes"));
3314
+ if (authWindow) {
3315
+ _context86.next = 45;
3316
+ break;
3317
+ }
3318
+ throw new Error("Failed to open Facebook login window.");
3319
+ case 45:
3320
+ authWindow.location.href = facebookAuthUrl.toString();
3321
+ // Return a promise that resolves when the OAuth flow completes
3322
+ return _context86.abrupt("return", new Promise(function (resolve, reject) {
3323
+ var interval = setInterval(function () {
3324
+ try {
3325
+ // Check if window was closed without completing auth
3326
+ if (authWindow.closed) {
3327
+ clearInterval(interval);
3328
+ reject(new Error("Authentication window was closed."));
3329
+ return;
3330
+ }
3331
+ var url = authWindow.location.href || "";
3332
+ if (url.startsWith(window.location.origin)) {
3333
+ var urlParams = new URLSearchParams(new URL(url).search);
3334
+ var authCode = urlParams.get("code");
3335
+ var stateParam = urlParams.get("state");
3336
+ if (authCode && stateParam && stateParam.includes("provider=facebook")) {
3337
+ authWindow.close();
3338
+ clearInterval(interval);
3339
+ // Exchange code for token
3340
+ var _verifier = sessionStorage.getItem("facebook_verifier");
3341
+ if (!_verifier) {
3342
+ reject(new Error("Missing PKCE verifier"));
3343
+ return;
3344
+ }
3345
+ exchangeCodeForToken(clientId, redirectURI, authCode, _verifier).then(function (tokenData) {
3346
+ sessionStorage.removeItem("facebook_verifier");
3347
+ if (params !== null && params !== void 0 && params.onOauthSuccess) {
3348
+ params.onOauthSuccess({
3349
+ oidcToken: tokenData.id_token,
3350
+ providerName: "apple"
3351
+ });
3352
+ } else if (callbacks !== null && callbacks !== void 0 && callbacks.onOauthRedirect) {
3353
+ callbacks.onOauthRedirect({
3354
+ idToken: tokenData.id_token,
3355
+ publicKey: publicKey
3356
+ });
3357
+ } else {
3358
+ completeOauth({
3359
+ oidcToken: tokenData.id_token,
3360
+ publicKey: publicKey,
3361
+ providerName: "facebook"
3362
+ }).then(function () {
3363
+ return resolve();
3364
+ })["catch"](reject);
3365
+ return;
3366
+ }
3367
+ resolve();
3368
+ })["catch"](reject);
3369
+ }
3370
+ }
3371
+ } catch (error) {
3372
+ // Ignore cross-origin errors
3373
+ }
3374
+ }, 500);
3375
+ if (authWindow.closed) {
3376
+ clearInterval(interval);
3377
+ }
3378
+ }));
3379
+ case 47:
3380
+ _context86.next = 52;
3381
+ break;
3382
+ case 49:
3383
+ _context86.prev = 49;
3384
+ _context86.t0 = _context86["catch"](1);
3385
+ throw _context86.t0;
3386
+ case 52:
3387
+ case "end":
3388
+ return _context86.stop();
3389
+ }
3390
+ }, _callee86, null, [[1, 49]]);
3391
+ }));
3392
+ return _handleFacebookOauth.apply(this, arguments);
3393
+ }
3394
+ var handleLogin = /*#__PURE__*/function () {
3395
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
3396
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
3397
+ while (1) switch (_context9.prev = _context9.next) {
3398
+ case 0:
3399
+ pushPage({
3400
+ key: "Log in or sign up",
3401
+ content: jsx(AuthComponent, {})
3402
+ });
3403
+ case 1:
3404
+ case "end":
3405
+ return _context9.stop();
3406
+ }
3407
+ }, _callee9);
3408
+ }));
3409
+ return function handleLogin() {
3410
+ return _ref9.apply(this, arguments);
3411
+ };
3412
+ }();
3413
+ var handleExport = /*#__PURE__*/function () {
3414
+ var _ref0 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(params) {
3415
+ var _wallets$;
3416
+ var walletId, exportType, targetPublicKey, stampWith;
3417
+ return _regeneratorRuntime().wrap(function _callee0$(_context0) {
3418
+ while (1) switch (_context0.prev = _context0.next) {
3419
+ case 0:
3420
+ walletId = params.walletId, exportType = params.exportType, targetPublicKey = params.targetPublicKey, stampWith = params.stampWith;
3421
+ pushPage({
3422
+ key: "Export Wallet",
3423
+ content: jsx(ExportComponent, _objectSpread2(_objectSpread2({
3424
+ walletId: walletId !== null && walletId !== void 0 ? walletId : (_wallets$ = wallets[0]) === null || _wallets$ === void 0 ? void 0 : _wallets$.walletId,
3425
+ exportType: exportType !== null && exportType !== void 0 ? exportType : ExportType.Wallet
3426
+ }, targetPublicKey !== undefined ? {
3427
+ targetPublicKey: targetPublicKey
3428
+ } : {}), stampWith !== undefined ? {
3429
+ stampWith: stampWith
3430
+ } : {}))
3431
+ });
3432
+ case 2:
3433
+ case "end":
3434
+ return _context0.stop();
3435
+ }
3436
+ }, _callee0);
3437
+ }));
3438
+ return function handleExport(_x55) {
3439
+ return _ref0.apply(this, arguments);
3440
+ };
3441
+ }();
3442
+ var handleImport = /*#__PURE__*/function () {
3443
+ var _ref1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee1(params) {
3444
+ var _ref10, defaultWalletAccounts, _ref10$successPageDur, successPageDuration, stampWith;
3445
+ return _regeneratorRuntime().wrap(function _callee1$(_context1) {
3446
+ while (1) switch (_context1.prev = _context1.next) {
3447
+ case 0:
3448
+ _ref10 = params || {}, defaultWalletAccounts = _ref10.defaultWalletAccounts, _ref10$successPageDur = _ref10.successPageDuration, successPageDuration = _ref10$successPageDur === void 0 ? 2000 : _ref10$successPageDur, stampWith = _ref10.stampWith;
3449
+ _context1.prev = 1;
3450
+ return _context1.abrupt("return", withTurnkeyErrorHandling(function () {
3451
+ return new Promise(function (resolve, reject) {
3452
+ return pushPage({
3453
+ key: "Import Wallet",
3454
+ content: jsx(ImportComponent, _objectSpread2(_objectSpread2(_objectSpread2({
3455
+ onError: function onError(error) {
3456
+ reject(error);
3457
+ },
3458
+ onSuccess: function onSuccess(walletId) {
3459
+ return resolve(walletId);
3460
+ }
3461
+ }, defaultWalletAccounts !== undefined && {
3462
+ defaultWalletAccounts: defaultWalletAccounts
3463
+ }), successPageDuration !== undefined && {
3464
+ successPageDuration: successPageDuration
3465
+ }), stampWith !== undefined && {
3466
+ stampWith: stampWith
3467
+ }))
3468
+ });
3469
+ });
3470
+ }));
3471
+ case 5:
3472
+ _context1.prev = 5;
3473
+ _context1.t0 = _context1["catch"](1);
3474
+ if (!(_context1.t0 instanceof TurnkeyError)) {
3475
+ _context1.next = 9;
3476
+ break;
3477
+ }
3478
+ throw _context1.t0;
3479
+ case 9:
3480
+ throw new TurnkeyError("Failed to import wallet.", TurnkeyErrorCodes.IMPORT_WALLET_ERROR, _context1.t0);
3481
+ case 10:
3482
+ case "end":
3483
+ return _context1.stop();
3484
+ }
3485
+ }, _callee1, null, [[1, 5]]);
3486
+ }));
3487
+ return function handleImport(_x56) {
3488
+ return _ref1.apply(this, arguments);
3489
+ };
3490
+ }();
3491
+ var handleUpdateUserName = /*#__PURE__*/function () {
3492
+ var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
3493
+ var _ref12, _ref12$successPageDur, successPageDuration, subTitle, title, stampWith, onSuccess, res;
3494
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
3495
+ while (1) switch (_context10.prev = _context10.next) {
3496
+ case 0:
3497
+ _ref12 = params || {}, _ref12$successPageDur = _ref12.successPageDuration, successPageDuration = _ref12$successPageDur === void 0 ? 2000 : _ref12$successPageDur, subTitle = _ref12.subTitle, title = _ref12.title, stampWith = _ref12.stampWith;
3498
+ if (client) {
3499
+ _context10.next = 3;
3500
+ break;
3501
+ }
3502
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
3503
+ case 3:
3504
+ if (session) {
3505
+ _context10.next = 5;
3506
+ break;
3507
+ }
3508
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
3509
+ case 5:
3510
+ onSuccess = function onSuccess() {
3511
+ if (!successPageDuration) return;
3512
+ pushPage({
3513
+ key: "success",
3514
+ content: jsx(SuccessPage, {
3515
+ text: "User name changed successfully!",
3516
+ duration: successPageDuration,
3517
+ onComplete: function onComplete() {
3518
+ closeModal();
3519
+ }
3520
+ }),
3521
+ preventBack: true,
3522
+ showTitle: false
3523
+ });
3524
+ };
3525
+ _context10.prev = 6;
3526
+ if (!(!(params !== null && params !== void 0 && params.userName) && (params === null || params === void 0 ? void 0 : params.userName) !== "")) {
3527
+ _context10.next = 11;
3528
+ break;
3529
+ }
3530
+ return _context10.abrupt("return", withTurnkeyErrorHandling(function () {
3531
+ return new Promise(function (resolve, reject) {
3532
+ pushPage({
3533
+ key: "Update User Name",
3534
+ content: jsx(UpdateUserName, _objectSpread2(_objectSpread2({
3535
+ onSuccess: function onSuccess(userId) {
3536
+ resolve(userId);
3537
+ },
3538
+ onError: function onError(error) {
3539
+ reject(error);
3540
+ },
3541
+ successPageDuration: successPageDuration,
3542
+ stampWith: stampWith
3543
+ }, title !== undefined ? {
3544
+ title: title
3545
+ } : {}), subTitle !== undefined ? {
3546
+ subTitle: subTitle
3547
+ } : {})),
3548
+ showTitle: false
3549
+ });
3550
+ });
3551
+ }));
3552
+ case 11:
3553
+ _context10.next = 13;
3554
+ return updateUserName({
3555
+ userName: params.userName,
3556
+ userId: user.userId,
3557
+ stampWith: stampWith
3558
+ });
3559
+ case 13:
3560
+ res = _context10.sent;
3561
+ onSuccess();
3562
+ return _context10.abrupt("return", res);
3563
+ case 16:
3564
+ _context10.next = 23;
3565
+ break;
3566
+ case 18:
3567
+ _context10.prev = 18;
3568
+ _context10.t0 = _context10["catch"](6);
3569
+ if (!(_context10.t0 instanceof TurnkeyError)) {
3570
+ _context10.next = 22;
3571
+ break;
3572
+ }
3573
+ throw _context10.t0;
3574
+ case 22:
3575
+ throw new TurnkeyError("Failed to update user name.", TurnkeyErrorCodes.UPDATE_USER_NAME_ERROR, _context10.t0);
3576
+ case 23:
3577
+ case "end":
3578
+ return _context10.stop();
3579
+ }
3580
+ }, _callee10, null, [[6, 18]]);
3581
+ }));
3582
+ return function handleUpdateUserName(_x57) {
3583
+ return _ref11.apply(this, arguments);
3584
+ };
3585
+ }();
3586
+ var handleUpdateUserPhoneNumber = /*#__PURE__*/function () {
3587
+ var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
3588
+ var _masterConfig$auth4, _masterConfig$auth4$m;
3589
+ var _ref14, _ref14$successPageDur, successPageDuration, subTitle, title, onSuccess, otpId;
3590
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
3591
+ while (1) switch (_context12.prev = _context12.next) {
3592
+ case 0:
3593
+ _ref14 = params || {}, _ref14$successPageDur = _ref14.successPageDuration, successPageDuration = _ref14$successPageDur === void 0 ? 2000 : _ref14$successPageDur, subTitle = _ref14.subTitle, title = _ref14.title;
3594
+ if (client) {
3595
+ _context12.next = 3;
3596
+ break;
3597
+ }
3598
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
3599
+ case 3:
3600
+ if (session) {
3601
+ _context12.next = 5;
3602
+ break;
3603
+ }
3604
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
3605
+ case 5:
3606
+ if (masterConfig) {
3607
+ _context12.next = 7;
3608
+ break;
3609
+ }
3610
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.CONFIG_NOT_INITIALIZED);
3611
+ case 7:
3612
+ if ((_masterConfig$auth4 = masterConfig.auth) !== null && _masterConfig$auth4 !== void 0 && (_masterConfig$auth4$m = _masterConfig$auth4.methods) !== null && _masterConfig$auth4$m !== void 0 && _masterConfig$auth4$m.smsOtpAuthEnabled) {
3613
+ _context12.next = 9;
3614
+ break;
3615
+ }
3616
+ throw new TurnkeyError("SMS OTP authentication is not enabled in the configuration.", TurnkeyErrorCodes.AUTH_METHOD_NOT_ENABLED);
3617
+ case 9:
3618
+ onSuccess = function onSuccess() {
3619
+ if (!successPageDuration) return;
3620
+ pushPage({
3621
+ key: "success",
3622
+ content: jsx(SuccessPage, {
3623
+ text: "Phone number changed successfully!",
3624
+ duration: successPageDuration,
3625
+ onComplete: function onComplete() {
3626
+ closeModal();
3627
+ }
3628
+ }),
3629
+ preventBack: true,
3630
+ showTitle: false
3631
+ });
3632
+ };
3633
+ _context12.prev = 10;
3634
+ if (!(!(params !== null && params !== void 0 && params.phoneNumber) && (params === null || params === void 0 ? void 0 : params.phoneNumber) !== "")) {
3635
+ _context12.next = 15;
3636
+ break;
3637
+ }
3638
+ return _context12.abrupt("return", withTurnkeyErrorHandling(function () {
3639
+ return new Promise(function (resolve, reject) {
3640
+ pushPage({
3641
+ key: "Update Phone Number",
3642
+ content: jsx(UpdatePhoneNumber, _objectSpread2(_objectSpread2({
3643
+ successPageDuration: successPageDuration,
3644
+ onSuccess: function onSuccess(userId) {
3645
+ return resolve(userId);
3646
+ },
3647
+ onError: function onError(error) {
3648
+ return reject(error);
3649
+ }
3650
+ }, title !== undefined ? {
3651
+ title: title
3652
+ } : {}), subTitle !== undefined ? {
3653
+ subTitle: subTitle
3654
+ } : {})),
3655
+ showTitle: false
3656
+ });
3657
+ });
3658
+ }));
3659
+ case 15:
3660
+ _context12.next = 17;
3661
+ return initOtp({
3662
+ otpType: OtpType.Sms,
3663
+ contact: params.phoneNumber
3664
+ });
3665
+ case 17:
3666
+ otpId = _context12.sent;
3667
+ return _context12.abrupt("return", withTurnkeyErrorHandling(function () {
3668
+ return new Promise(function (resolve, reject) {
3669
+ pushPage({
3670
+ key: "Update Phone Number",
3671
+ content: jsx(OtpVerification, _objectSpread2(_objectSpread2(_objectSpread2({
3672
+ otpType: OtpType.Sms,
3673
+ contact: params.phoneNumber,
3674
+ otpId: otpId,
3675
+ onContinue: function () {
3676
+ var _onContinue = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(otpCode) {
3677
+ var _yield$verifyOtp, verificationToken, res;
3678
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
3679
+ while (1) switch (_context11.prev = _context11.next) {
3680
+ case 0:
3681
+ _context11.prev = 0;
3682
+ _context11.next = 3;
3683
+ return verifyOtp({
3684
+ otpId: otpId,
3685
+ otpCode: otpCode,
3686
+ contact: params.phoneNumber,
3687
+ otpType: OtpType.Sms
3688
+ });
3689
+ case 3:
3690
+ _yield$verifyOtp = _context11.sent;
3691
+ verificationToken = _yield$verifyOtp.verificationToken;
3692
+ _context11.next = 7;
3693
+ return updateUserPhoneNumber({
3694
+ phoneNumber: params.phoneNumber,
3695
+ verificationToken: verificationToken,
3696
+ userId: user.userId
3697
+ });
3698
+ case 7:
3699
+ res = _context11.sent;
3700
+ onSuccess();
3701
+ resolve(res);
3702
+ _context11.next = 15;
3703
+ break;
3704
+ case 12:
3705
+ _context11.prev = 12;
3706
+ _context11.t0 = _context11["catch"](0);
3707
+ reject(_context11.t0);
3708
+ case 15:
3709
+ case "end":
3710
+ return _context11.stop();
3711
+ }
3712
+ }, _callee11, null, [[0, 12]]);
3713
+ }));
3714
+ function onContinue(_x59) {
3715
+ return _onContinue.apply(this, arguments);
3716
+ }
3717
+ return onContinue;
3718
+ }()
3719
+ }, !(user !== null && user !== void 0 && user.userPhoneNumber) && {
3720
+ title: title !== null && title !== void 0 ? title : "Connect a phone number"
3721
+ }), subTitle !== undefined && {
3722
+ subTitle: subTitle
3723
+ }), params.formattedPhone && {
3724
+ formattedPhone: params.formattedPhone
3725
+ })),
3726
+ showTitle: false
3727
+ });
3728
+ });
3729
+ }, callbacks, "Failed to update phone number"));
3730
+ case 19:
3731
+ _context12.next = 26;
3732
+ break;
3733
+ case 21:
3734
+ _context12.prev = 21;
3735
+ _context12.t0 = _context12["catch"](10);
3736
+ if (!(_context12.t0 instanceof TurnkeyError)) {
3737
+ _context12.next = 25;
3738
+ break;
3739
+ }
3740
+ throw _context12.t0;
3741
+ case 25:
3742
+ throw new TurnkeyError("Failed to initialize OTP for sms verification.", TurnkeyErrorCodes.INIT_OTP_ERROR, _context12.t0);
3743
+ case 26:
3744
+ case "end":
3745
+ return _context12.stop();
3746
+ }
3747
+ }, _callee12, null, [[10, 21]]);
3748
+ }));
3749
+ return function handleUpdateUserPhoneNumber(_x58) {
3750
+ return _ref13.apply(this, arguments);
3751
+ };
3752
+ }();
3753
+ var handleUpdateUserEmail = /*#__PURE__*/function () {
3754
+ var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
3755
+ var _ref16, _ref16$successPageDur, successPageDuration, subTitle, title, onSuccess, otpId;
3756
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
3757
+ while (1) switch (_context14.prev = _context14.next) {
3758
+ case 0:
3759
+ _ref16 = params || {}, _ref16$successPageDur = _ref16.successPageDuration, successPageDuration = _ref16$successPageDur === void 0 ? 2000 : _ref16$successPageDur, subTitle = _ref16.subTitle, title = _ref16.title;
3760
+ if (client) {
3761
+ _context14.next = 3;
3762
+ break;
3763
+ }
3764
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
3765
+ case 3:
3766
+ if (session) {
3767
+ _context14.next = 5;
3768
+ break;
3769
+ }
3770
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
3771
+ case 5:
3772
+ onSuccess = function onSuccess() {
3773
+ if (!successPageDuration) return;
3774
+ pushPage({
3775
+ key: "success",
3776
+ content: jsx(SuccessPage, {
3777
+ text: "Email changed successfully!",
3778
+ duration: successPageDuration,
3779
+ onComplete: function onComplete() {
3780
+ closeModal();
3781
+ }
3782
+ }),
3783
+ preventBack: true,
3784
+ showTitle: false
3785
+ });
3786
+ };
3787
+ _context14.prev = 6;
3788
+ if (!(!(params !== null && params !== void 0 && params.email) && (params === null || params === void 0 ? void 0 : params.email) !== "")) {
3789
+ _context14.next = 11;
3790
+ break;
3791
+ }
3792
+ return _context14.abrupt("return", withTurnkeyErrorHandling(function () {
3793
+ return new Promise(function (resolve, reject) {
3794
+ pushPage({
3795
+ key: "Update Email",
3796
+ content: jsx(UpdateEmail, _objectSpread2(_objectSpread2({
3797
+ successPageDuration: successPageDuration,
3798
+ onSuccess: function onSuccess(userId) {
3799
+ resolve(userId);
3800
+ },
3801
+ onError: function onError(error) {
3802
+ return reject(error);
3803
+ }
3804
+ }, title !== undefined ? {
3805
+ title: title
3806
+ } : {}), subTitle !== undefined ? {
3807
+ subTitle: subTitle
3808
+ } : {})),
3809
+ showTitle: false
3810
+ });
3811
+ });
3812
+ }));
3813
+ case 11:
3814
+ _context14.next = 13;
3815
+ return initOtp({
3816
+ otpType: OtpType.Email,
3817
+ contact: params.email
3818
+ });
3819
+ case 13:
3820
+ otpId = _context14.sent;
3821
+ return _context14.abrupt("return", withTurnkeyErrorHandling(function () {
3822
+ return new Promise(function (resolve, reject) {
3823
+ pushPage({
3824
+ key: "Update Email",
3825
+ content: jsx(OtpVerification, _objectSpread2(_objectSpread2({
3826
+ otpType: OtpType.Email,
3827
+ contact: params.email,
3828
+ otpId: otpId,
3829
+ onContinue: function () {
3830
+ var _onContinue2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(otpCode) {
3831
+ var _yield$verifyOtp2, verificationToken, res;
3832
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
3833
+ while (1) switch (_context13.prev = _context13.next) {
3834
+ case 0:
3835
+ _context13.prev = 0;
3836
+ _context13.next = 3;
3837
+ return verifyOtp({
3838
+ otpId: otpId,
3839
+ otpCode: otpCode,
3840
+ contact: params.email,
3841
+ otpType: OtpType.Email
3842
+ });
3843
+ case 3:
3844
+ _yield$verifyOtp2 = _context13.sent;
3845
+ verificationToken = _yield$verifyOtp2.verificationToken;
3846
+ _context13.next = 7;
3847
+ return updateUserEmail({
3848
+ email: params.email,
3849
+ verificationToken: verificationToken,
3850
+ userId: user.userId
3851
+ });
3852
+ case 7:
3853
+ res = _context13.sent;
3854
+ onSuccess();
3855
+ resolve(res);
3856
+ _context13.next = 15;
3857
+ break;
3858
+ case 12:
3859
+ _context13.prev = 12;
3860
+ _context13.t0 = _context13["catch"](0);
3861
+ reject(_context13.t0);
3862
+ case 15:
3863
+ case "end":
3864
+ return _context13.stop();
3865
+ }
3866
+ }, _callee13, null, [[0, 12]]);
3867
+ }));
3868
+ function onContinue(_x61) {
3869
+ return _onContinue2.apply(this, arguments);
3870
+ }
3871
+ return onContinue;
3872
+ }()
3873
+ }, !(user !== null && user !== void 0 && user.userEmail) && {
3874
+ title: title !== null && title !== void 0 ? title : "Connect an email"
3875
+ }), subTitle !== undefined && {
3876
+ subTitle: subTitle
3877
+ })),
3878
+ showTitle: false
3879
+ });
3880
+ });
3881
+ }, callbacks, "Failed to update email"));
3882
+ case 15:
3883
+ _context14.next = 22;
3884
+ break;
3885
+ case 17:
3886
+ _context14.prev = 17;
3887
+ _context14.t0 = _context14["catch"](6);
3888
+ if (!(_context14.t0 instanceof TurnkeyError)) {
3889
+ _context14.next = 21;
3890
+ break;
3891
+ }
3892
+ throw _context14.t0;
3893
+ case 21:
3894
+ throw new TurnkeyError("Failed to initialize OTP for email verification.", TurnkeyErrorCodes.INIT_OTP_ERROR, _context14.t0);
3895
+ case 22:
3896
+ case "end":
3897
+ return _context14.stop();
3898
+ }
3899
+ }, _callee14, null, [[6, 17]]);
3900
+ }));
3901
+ return function handleUpdateUserEmail(_x60) {
3902
+ return _ref15.apply(this, arguments);
3903
+ };
3904
+ }();
3905
+ var handleAddEmail = /*#__PURE__*/function () {
3906
+ var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
3907
+ var _ref18, _ref18$successPageDur, successPageDuration, subTitle, title, onSuccess, otpId;
3908
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
3909
+ while (1) switch (_context16.prev = _context16.next) {
3910
+ case 0:
3911
+ _ref18 = params || {}, _ref18$successPageDur = _ref18.successPageDuration, successPageDuration = _ref18$successPageDur === void 0 ? 2000 : _ref18$successPageDur, subTitle = _ref18.subTitle, title = _ref18.title;
3912
+ if (client) {
3913
+ _context16.next = 3;
3914
+ break;
3915
+ }
3916
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
3917
+ case 3:
3918
+ if (session) {
3919
+ _context16.next = 5;
3920
+ break;
3921
+ }
3922
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
3923
+ case 5:
3924
+ onSuccess = function onSuccess() {
3925
+ if (!successPageDuration) return;
3926
+ pushPage({
3927
+ key: "success",
3928
+ content: jsx(SuccessPage, {
3929
+ text: "Email added successfully!",
3930
+ duration: successPageDuration,
3931
+ onComplete: function onComplete() {
3932
+ closeModal();
3933
+ }
3934
+ }),
3935
+ preventBack: true,
3936
+ showTitle: false
3937
+ });
3938
+ };
3939
+ _context16.prev = 6;
3940
+ if (!(!(params !== null && params !== void 0 && params.email) && (params === null || params === void 0 ? void 0 : params.email) !== "")) {
3941
+ _context16.next = 11;
3942
+ break;
3943
+ }
3944
+ return _context16.abrupt("return", withTurnkeyErrorHandling(function () {
3945
+ return new Promise(function (resolve, reject) {
3946
+ pushPage({
3947
+ key: "Add Email",
3948
+ content: jsx(UpdateEmail, _objectSpread2(_objectSpread2({
3949
+ successPageDuration: successPageDuration,
3950
+ onSuccess: function onSuccess(userId) {
3951
+ resolve(userId);
3952
+ },
3953
+ onError: function onError(error) {
3954
+ return reject(error);
3955
+ }
3956
+ }, !(user !== null && user !== void 0 && user.userEmail) ? {
3957
+ title: title !== null && title !== void 0 ? title : "Connect an email"
3958
+ } : {}), subTitle !== undefined ? {
3959
+ subTitle: subTitle
3960
+ } : {})),
3961
+ showTitle: false
3962
+ });
3963
+ });
3964
+ }));
3965
+ case 11:
3966
+ _context16.next = 13;
3967
+ return initOtp({
3968
+ otpType: OtpType.Email,
3969
+ contact: params.email
3970
+ });
3971
+ case 13:
3972
+ otpId = _context16.sent;
3973
+ return _context16.abrupt("return", withTurnkeyErrorHandling(function () {
3974
+ return new Promise(function (resolve, reject) {
3975
+ pushPage({
3976
+ key: "Add Email",
3977
+ content: jsx(OtpVerification, _objectSpread2(_objectSpread2({
3978
+ otpType: OtpType.Email,
3979
+ contact: params.email,
3980
+ otpId: otpId,
3981
+ onContinue: function () {
3982
+ var _onContinue3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15(otpCode) {
3983
+ var _yield$verifyOtp3, verificationToken, res;
3984
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
3985
+ while (1) switch (_context15.prev = _context15.next) {
3986
+ case 0:
3987
+ _context15.prev = 0;
3988
+ _context15.next = 3;
3989
+ return verifyOtp({
3990
+ otpId: otpId,
3991
+ otpCode: otpCode,
3992
+ contact: params.email,
3993
+ otpType: OtpType.Email
3994
+ });
3995
+ case 3:
3996
+ _yield$verifyOtp3 = _context15.sent;
3997
+ verificationToken = _yield$verifyOtp3.verificationToken;
3998
+ _context15.next = 7;
3999
+ return updateUserEmail({
4000
+ email: params.email,
4001
+ verificationToken: verificationToken,
4002
+ userId: user.userId
4003
+ });
4004
+ case 7:
4005
+ res = _context15.sent;
4006
+ onSuccess();
4007
+ resolve(res);
4008
+ _context15.next = 15;
4009
+ break;
4010
+ case 12:
4011
+ _context15.prev = 12;
4012
+ _context15.t0 = _context15["catch"](0);
4013
+ reject(_context15.t0);
4014
+ case 15:
4015
+ case "end":
4016
+ return _context15.stop();
4017
+ }
4018
+ }, _callee15, null, [[0, 12]]);
4019
+ }));
4020
+ function onContinue(_x63) {
4021
+ return _onContinue3.apply(this, arguments);
4022
+ }
4023
+ return onContinue;
4024
+ }()
4025
+ }, !(user !== null && user !== void 0 && user.userEmail) && {
4026
+ title: title !== null && title !== void 0 ? title : "Connect an email"
4027
+ }), subTitle !== undefined && {
4028
+ subTitle: subTitle
4029
+ })),
4030
+ showTitle: false
4031
+ });
4032
+ });
4033
+ }, callbacks, "Failed to add email"));
4034
+ case 15:
4035
+ _context16.next = 22;
4036
+ break;
4037
+ case 17:
4038
+ _context16.prev = 17;
4039
+ _context16.t0 = _context16["catch"](6);
4040
+ if (!(_context16.t0 instanceof TurnkeyError)) {
4041
+ _context16.next = 21;
4042
+ break;
4043
+ }
4044
+ throw _context16.t0;
4045
+ case 21:
4046
+ throw new TurnkeyError("Failed to initialize OTP for email verification.", TurnkeyErrorCodes.INIT_OTP_ERROR, _context16.t0);
4047
+ case 22:
4048
+ case "end":
4049
+ return _context16.stop();
4050
+ }
4051
+ }, _callee16, null, [[6, 17]]);
4052
+ }));
4053
+ return function handleAddEmail(_x62) {
4054
+ return _ref17.apply(this, arguments);
4055
+ };
4056
+ }();
4057
+ var handleAddPhoneNumber = /*#__PURE__*/function () {
4058
+ var _ref19 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
4059
+ var _masterConfig$auth5, _masterConfig$auth5$m;
4060
+ var _ref20, _ref20$successPageDur, successPageDuration, subTitle, title, onSuccess, otpId;
4061
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
4062
+ while (1) switch (_context18.prev = _context18.next) {
4063
+ case 0:
4064
+ _ref20 = params || {}, _ref20$successPageDur = _ref20.successPageDuration, successPageDuration = _ref20$successPageDur === void 0 ? 2000 : _ref20$successPageDur, subTitle = _ref20.subTitle, title = _ref20.title;
4065
+ if (client) {
4066
+ _context18.next = 3;
4067
+ break;
4068
+ }
4069
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
4070
+ case 3:
4071
+ if (session) {
4072
+ _context18.next = 5;
4073
+ break;
4074
+ }
4075
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
4076
+ case 5:
4077
+ if (masterConfig) {
4078
+ _context18.next = 7;
4079
+ break;
4080
+ }
4081
+ throw new TurnkeyError("Config is not ready yet!", TurnkeyErrorCodes.CONFIG_NOT_INITIALIZED);
4082
+ case 7:
4083
+ if ((_masterConfig$auth5 = masterConfig.auth) !== null && _masterConfig$auth5 !== void 0 && (_masterConfig$auth5$m = _masterConfig$auth5.methods) !== null && _masterConfig$auth5$m !== void 0 && _masterConfig$auth5$m.smsOtpAuthEnabled) {
4084
+ _context18.next = 9;
4085
+ break;
4086
+ }
4087
+ throw new TurnkeyError("SMS OTP authentication is not enabled in the configuration.", TurnkeyErrorCodes.AUTH_METHOD_NOT_ENABLED);
4088
+ case 9:
4089
+ onSuccess = function onSuccess() {
4090
+ if (!successPageDuration) return;
4091
+ pushPage({
4092
+ key: "success",
4093
+ content: jsx(SuccessPage, {
4094
+ text: "Phone number updated successfully!",
4095
+ duration: successPageDuration,
4096
+ onComplete: function onComplete() {
4097
+ closeModal();
4098
+ }
4099
+ }),
4100
+ preventBack: true,
4101
+ showTitle: false
4102
+ });
4103
+ };
4104
+ _context18.prev = 10;
4105
+ if (!(!(params !== null && params !== void 0 && params.phoneNumber) && (params === null || params === void 0 ? void 0 : params.phoneNumber) !== "")) {
4106
+ _context18.next = 15;
4107
+ break;
4108
+ }
4109
+ return _context18.abrupt("return", withTurnkeyErrorHandling(function () {
4110
+ return new Promise(function (resolve, reject) {
4111
+ pushPage({
4112
+ key: "Add Phone Number",
4113
+ content: jsx(UpdatePhoneNumber, _objectSpread2(_objectSpread2({
4114
+ successPageDuration: successPageDuration,
4115
+ onSuccess: function onSuccess(userId) {
4116
+ resolve(userId);
4117
+ },
4118
+ onError: function onError(error) {
4119
+ reject(error);
4120
+ }
4121
+ }, !(user !== null && user !== void 0 && user.userPhoneNumber) && {
4122
+ title: title !== null && title !== void 0 ? title : "Connect a phone number"
4123
+ }), subTitle !== undefined && {
4124
+ subTitle: subTitle
4125
+ })),
4126
+ showTitle: false
4127
+ });
4128
+ });
4129
+ }, callbacks, "Failed to add phone number"));
4130
+ case 15:
4131
+ _context18.next = 17;
4132
+ return initOtp({
4133
+ otpType: OtpType.Sms,
4134
+ contact: params.phoneNumber
4135
+ });
4136
+ case 17:
4137
+ otpId = _context18.sent;
4138
+ return _context18.abrupt("return", withTurnkeyErrorHandling(function () {
4139
+ return new Promise(function (resolve, reject) {
4140
+ pushPage({
4141
+ key: "Add Phone Number",
4142
+ content: jsx(OtpVerification, _objectSpread2(_objectSpread2(_objectSpread2({
4143
+ otpType: OtpType.Sms,
4144
+ contact: params.phoneNumber,
4145
+ otpId: otpId,
4146
+ onContinue: function () {
4147
+ var _onContinue4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee17(otpCode) {
4148
+ var _yield$verifyOtp4, verificationToken, res;
4149
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
4150
+ while (1) switch (_context17.prev = _context17.next) {
4151
+ case 0:
4152
+ _context17.prev = 0;
4153
+ _context17.next = 3;
4154
+ return verifyOtp({
4155
+ otpId: otpId,
4156
+ otpCode: otpCode,
4157
+ contact: params.phoneNumber,
4158
+ otpType: OtpType.Sms
4159
+ });
4160
+ case 3:
4161
+ _yield$verifyOtp4 = _context17.sent;
4162
+ verificationToken = _yield$verifyOtp4.verificationToken;
4163
+ _context17.next = 7;
4164
+ return updateUserPhoneNumber({
4165
+ phoneNumber: params.phoneNumber,
4166
+ verificationToken: verificationToken,
4167
+ userId: user.userId
4168
+ });
4169
+ case 7:
4170
+ res = _context17.sent;
4171
+ onSuccess();
4172
+ resolve(res);
4173
+ _context17.next = 15;
4174
+ break;
4175
+ case 12:
4176
+ _context17.prev = 12;
4177
+ _context17.t0 = _context17["catch"](0);
4178
+ reject(_context17.t0);
4179
+ case 15:
4180
+ case "end":
4181
+ return _context17.stop();
4182
+ }
4183
+ }, _callee17, null, [[0, 12]]);
4184
+ }));
4185
+ function onContinue(_x65) {
4186
+ return _onContinue4.apply(this, arguments);
4187
+ }
4188
+ return onContinue;
4189
+ }()
4190
+ }, !(user !== null && user !== void 0 && user.userPhoneNumber) && {
4191
+ title: title !== null && title !== void 0 ? title : "Connect a phone number"
4192
+ }), subTitle !== undefined && {
4193
+ subTitle: subTitle
4194
+ }), params.formattedPhone && {
4195
+ formattedPhone: params.formattedPhone
4196
+ })),
4197
+ showTitle: false
4198
+ });
4199
+ });
4200
+ }, callbacks, "Failed to add phone number"));
4201
+ case 19:
4202
+ _context18.next = 26;
4203
+ break;
4204
+ case 21:
4205
+ _context18.prev = 21;
4206
+ _context18.t0 = _context18["catch"](10);
4207
+ if (!(_context18.t0 instanceof TurnkeyError)) {
4208
+ _context18.next = 25;
4209
+ break;
4210
+ }
4211
+ throw _context18.t0;
4212
+ case 25:
4213
+ throw new TurnkeyError("Failed to initialize OTP for sms verification.", TurnkeyErrorCodes.INIT_OTP_ERROR, _context18.t0);
4214
+ case 26:
4215
+ case "end":
4216
+ return _context18.stop();
4217
+ }
4218
+ }, _callee18, null, [[10, 21]]);
4219
+ }));
4220
+ return function handleAddPhoneNumber(_x64) {
4221
+ return _ref19.apply(this, arguments);
4222
+ };
4223
+ }();
4224
+ var handleRemovePasskey = /*#__PURE__*/function () {
4225
+ var _ref21 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
4226
+ var authenticatorId, _params$successPageDu, successPageDuration, subTitle, title, stampWith, userId;
4227
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
4228
+ while (1) switch (_context19.prev = _context19.next) {
4229
+ case 0:
4230
+ authenticatorId = params.authenticatorId, _params$successPageDu = params.successPageDuration, successPageDuration = _params$successPageDu === void 0 ? 2000 : _params$successPageDu, subTitle = params.subTitle, title = params.title, stampWith = params.stampWith, userId = params.userId;
4231
+ if (client) {
4232
+ _context19.next = 3;
4233
+ break;
4234
+ }
4235
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
4236
+ case 3:
4237
+ if (session) {
4238
+ _context19.next = 5;
4239
+ break;
4240
+ }
4241
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
4242
+ case 5:
4243
+ return _context19.abrupt("return", withTurnkeyErrorHandling(function () {
4244
+ return new Promise(function (resolve, reject) {
4245
+ pushPage({
4246
+ key: "Remove Passkey",
4247
+ content: jsx(RemovePasskey, _objectSpread2(_objectSpread2(_objectSpread2({
4248
+ authenticatorId: authenticatorId,
4249
+ successPageDuration: successPageDuration,
4250
+ onSuccess: function onSuccess(authenticatorIds) {
4251
+ resolve(authenticatorIds);
4252
+ },
4253
+ onError: function onError(error) {
4254
+ reject(error);
4255
+ },
4256
+ stampWith: stampWith
4257
+ }, userId && {
4258
+ userId: userId
4259
+ }), title !== undefined && {
4260
+ title: title
4261
+ }), subTitle !== undefined && {
4262
+ subTitle: subTitle
4263
+ })),
4264
+ showTitle: false,
4265
+ preventBack: true
4266
+ });
4267
+ });
4268
+ }, callbacks, "Failed to remove passkey"));
4269
+ case 6:
4270
+ case "end":
4271
+ return _context19.stop();
4272
+ }
4273
+ }, _callee19);
4274
+ }));
4275
+ return function handleRemovePasskey(_x66) {
4276
+ return _ref21.apply(this, arguments);
4277
+ };
4278
+ }();
4279
+ var handleAddPasskey = /*#__PURE__*/function () {
4280
+ var _ref22 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
4281
+ var _ref23, name, displayName, _ref23$successPageDur, successPageDuration, stampWith, userId, resPromise;
4282
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
4283
+ while (1) switch (_context20.prev = _context20.next) {
4284
+ case 0:
4285
+ _ref23 = params || {}, name = _ref23.name, displayName = _ref23.displayName, _ref23$successPageDur = _ref23.successPageDuration, successPageDuration = _ref23$successPageDur === void 0 ? 2000 : _ref23$successPageDur, stampWith = _ref23.stampWith;
4286
+ if (client) {
4287
+ _context20.next = 3;
4288
+ break;
4289
+ }
4290
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
4291
+ case 3:
4292
+ if (session) {
4293
+ _context20.next = 5;
4294
+ break;
4295
+ }
4296
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
4297
+ case 5:
4298
+ userId = (params === null || params === void 0 ? void 0 : params.userId) || session.userId;
4299
+ _context20.prev = 6;
4300
+ resPromise = addPasskey(_objectSpread2(_objectSpread2(_objectSpread2({}, name && {
4301
+ name: name
4302
+ }), displayName && {
4303
+ displayName: displayName
4304
+ }), {}, {
4305
+ userId: userId,
4306
+ stampWith: stampWith
4307
+ }));
4308
+ resPromise.then(function () {
4309
+ pushPage({
4310
+ key: "Passkey Added",
4311
+ content: jsx(SuccessPage, {
4312
+ text: "Successfully added passkey!",
4313
+ duration: successPageDuration,
4314
+ onComplete: function onComplete() {
4315
+ closeModal();
4316
+ }
4317
+ }),
4318
+ preventBack: true,
4319
+ showTitle: false
4320
+ });
4321
+ });
4322
+ _context20.next = 11;
4323
+ return resPromise;
4324
+ case 11:
4325
+ return _context20.abrupt("return", _context20.sent);
4326
+ case 14:
4327
+ _context20.prev = 14;
4328
+ _context20.t0 = _context20["catch"](6);
4329
+ if (!(_context20.t0 instanceof TurnkeyError)) {
4330
+ _context20.next = 18;
4331
+ break;
4332
+ }
4333
+ throw _context20.t0;
4334
+ case 18:
4335
+ throw new TurnkeyError("Failed to add passkey in handler.", TurnkeyErrorCodes.ADD_PASSKEY_ERROR, _context20.t0);
4336
+ case 19:
4337
+ case "end":
4338
+ return _context20.stop();
4339
+ }
4340
+ }, _callee20, null, [[6, 14]]);
4341
+ }));
4342
+ return function handleAddPasskey(_x67) {
4343
+ return _ref22.apply(this, arguments);
4344
+ };
4345
+ }();
4346
+ var handleRemoveOauthProvider = /*#__PURE__*/function () {
4347
+ var _ref24 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
4348
+ var providerId, _params$successPageDu2, successPageDuration, subTitle, title, stampWith;
4349
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
4350
+ while (1) switch (_context21.prev = _context21.next) {
4351
+ case 0:
4352
+ providerId = params.providerId, _params$successPageDu2 = params.successPageDuration, successPageDuration = _params$successPageDu2 === void 0 ? 2000 : _params$successPageDu2, subTitle = params.subTitle, title = params.title, stampWith = params.stampWith;
4353
+ if (client) {
4354
+ _context21.next = 3;
4355
+ break;
4356
+ }
4357
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
4358
+ case 3:
4359
+ if (session) {
4360
+ _context21.next = 5;
4361
+ break;
4362
+ }
4363
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
4364
+ case 5:
4365
+ _context21.prev = 5;
4366
+ return _context21.abrupt("return", new Promise(function (resolve, reject) {
4367
+ pushPage({
4368
+ key: "Remove OAuth Provider",
4369
+ content: jsx(RemoveOAuthProvider, _objectSpread2(_objectSpread2({
4370
+ providerId: providerId,
4371
+ stampWith: stampWith,
4372
+ successPageDuration: successPageDuration,
4373
+ onSuccess: function onSuccess(providerIds) {
4374
+ resolve(providerIds);
4375
+ },
4376
+ onError: function onError(error) {
4377
+ reject(error);
4378
+ }
4379
+ }, title !== undefined && {
4380
+ title: title
4381
+ }), subTitle !== undefined && {
4382
+ subTitle: subTitle
4383
+ })),
4384
+ showTitle: false,
4385
+ preventBack: true
4386
+ });
4387
+ }));
4388
+ case 9:
4389
+ _context21.prev = 9;
4390
+ _context21.t0 = _context21["catch"](5);
4391
+ if (!(_context21.t0 instanceof TurnkeyError)) {
4392
+ _context21.next = 13;
4393
+ break;
4394
+ }
4395
+ throw _context21.t0;
4396
+ case 13:
4397
+ throw new TurnkeyError("Failed to remove OAuth provider in handler.", TurnkeyErrorCodes.REMOVE_OAUTH_PROVIDER_ERROR, _context21.t0);
4398
+ case 14:
4399
+ case "end":
4400
+ return _context21.stop();
4401
+ }
4402
+ }, _callee21, null, [[5, 9]]);
4403
+ }));
4404
+ return function handleRemoveOauthProvider(_x68) {
4405
+ return _ref24.apply(this, arguments);
4406
+ };
4407
+ }();
4408
+ var handleAddOauthProvider = /*#__PURE__*/function () {
4409
+ var _ref25 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4410
+ var providerName, stampWith, onOauthSuccess;
4411
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
4412
+ while (1) switch (_context23.prev = _context23.next) {
4413
+ case 0:
4414
+ if (client) {
4415
+ _context23.next = 2;
4416
+ break;
4417
+ }
4418
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
4419
+ case 2:
4420
+ if (session) {
4421
+ _context23.next = 4;
4422
+ break;
4423
+ }
4424
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
4425
+ case 4:
4426
+ providerName = params.providerName, stampWith = params.stampWith;
4427
+ onOauthSuccess = /*#__PURE__*/function () {
4428
+ var _ref26 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
4429
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
4430
+ while (1) switch (_context22.prev = _context22.next) {
4431
+ case 0:
4432
+ _context22.next = 2;
4433
+ return addOauthProvider({
4434
+ providerName: params.providerName,
4435
+ oidcToken: params.oidcToken,
4436
+ stampWith: stampWith
4437
+ });
4438
+ case 2:
4439
+ pushPage({
4440
+ key: "OAuth Provider Added",
4441
+ content: jsx(SuccessPage, {
4442
+ text: "Successfully added ".concat(params.providerName, " OAuth provider!"),
4443
+ duration: 3000,
4444
+ onComplete: function onComplete() {
4445
+ closeModal();
4446
+ }
4447
+ }),
4448
+ preventBack: true,
4449
+ showTitle: false
4450
+ });
4451
+ case 3:
4452
+ case "end":
4453
+ return _context22.stop();
4454
+ }
4455
+ }, _callee22);
4456
+ }));
4457
+ return function onOauthSuccess(_x70) {
4458
+ return _ref26.apply(this, arguments);
4459
+ };
4460
+ }();
4461
+ _context23.t0 = providerName;
4462
+ _context23.next = _context23.t0 === OAuthProviders.GOOGLE ? 9 : _context23.t0 === OAuthProviders.APPLE ? 12 : _context23.t0 === OAuthProviders.FACEBOOK ? 15 : 18;
4463
+ break;
4464
+ case 9:
4465
+ _context23.next = 11;
4466
+ return handleGoogleOauth({
4467
+ openInPage: false,
4468
+ onOauthSuccess: onOauthSuccess
4469
+ });
4470
+ case 11:
4471
+ return _context23.abrupt("break", 19);
4472
+ case 12:
4473
+ _context23.next = 14;
4474
+ return handleAppleOauth({
4475
+ openInPage: false,
4476
+ onOauthSuccess: onOauthSuccess
4477
+ });
4478
+ case 14:
4479
+ return _context23.abrupt("break", 19);
4480
+ case 15:
4481
+ _context23.next = 17;
4482
+ return handleFacebookOauth({
4483
+ openInPage: false,
4484
+ onOauthSuccess: onOauthSuccess
4485
+ });
4486
+ case 17:
4487
+ return _context23.abrupt("break", 19);
4488
+ case 18:
4489
+ throw new TurnkeyError("Unsupported OAuth provider: ".concat(providerName), TurnkeyErrorCodes.NOT_FOUND);
4490
+ case 19:
4491
+ case "end":
4492
+ return _context23.stop();
4493
+ }
4494
+ }, _callee23);
4495
+ }));
4496
+ return function handleAddOauthProvider(_x69) {
4497
+ return _ref25.apply(this, arguments);
4498
+ };
4499
+ }();
4500
+ var handleLinkExternalWallet = /*#__PURE__*/function () {
4501
+ var _ref27 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
4502
+ var _masterConfig$walletC4, _masterConfig$walletC5;
4503
+ var _ref28, _ref28$successPageDur, successPageDuration, providers;
4504
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
4505
+ while (1) switch (_context24.prev = _context24.next) {
4506
+ case 0:
4507
+ _ref28 = params || {}, _ref28$successPageDur = _ref28.successPageDuration, successPageDuration = _ref28$successPageDur === void 0 ? 2000 : _ref28$successPageDur;
4508
+ if (client) {
4509
+ _context24.next = 3;
4510
+ break;
4511
+ }
4512
+ throw new TurnkeyError("Client is not initialized.", TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
4513
+ case 3:
4514
+ if (session) {
4515
+ _context24.next = 5;
4516
+ break;
4517
+ }
4518
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
4519
+ case 5:
4520
+ if (masterConfig !== null && masterConfig !== void 0 && (_masterConfig$walletC4 = masterConfig.walletConfig) !== null && _masterConfig$walletC4 !== void 0 && (_masterConfig$walletC5 = _masterConfig$walletC4.features) !== null && _masterConfig$walletC5 !== void 0 && _masterConfig$walletC5.connecting) {
4521
+ _context24.next = 7;
4522
+ break;
4523
+ }
4524
+ throw new TurnkeyError("Wallet connecting is not enabled.", TurnkeyErrorCodes.FEATURE_NOT_ENABLED);
4525
+ case 7:
4526
+ _context24.next = 9;
4527
+ return getWalletProviders();
4528
+ case 9:
4529
+ providers = _context24.sent;
4530
+ pushPage({
4531
+ key: "Link Wallet",
4532
+ content: jsx(LinkWalletModal, {
4533
+ providers: providers,
4534
+ successPageDuration: successPageDuration
4535
+ })
4536
+ });
4537
+ case 11:
4538
+ case "end":
4539
+ return _context24.stop();
4540
+ }
4541
+ }, _callee24);
4542
+ }));
4543
+ return function handleLinkExternalWallet(_x71) {
4544
+ return _ref27.apply(this, arguments);
4545
+ };
4546
+ }();
4547
+ var handleRemoveUserEmail = /*#__PURE__*/function () {
4548
+ var _ref29 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4549
+ var _ref30, _ref30$successPageDur, successPageDuration, stampWith, userId;
4550
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4551
+ while (1) switch (_context25.prev = _context25.next) {
4552
+ case 0:
4553
+ _ref30 = params || {}, _ref30$successPageDur = _ref30.successPageDuration, successPageDuration = _ref30$successPageDur === void 0 ? 2000 : _ref30$successPageDur, stampWith = _ref30.stampWith, userId = _ref30.userId;
4554
+ if (session) {
4555
+ _context25.next = 3;
4556
+ break;
4557
+ }
4558
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
4559
+ case 3:
4560
+ _context25.prev = 3;
4561
+ return _context25.abrupt("return", new Promise(function (resolve, reject) {
4562
+ pushPage({
4563
+ key: "Remove Email",
4564
+ content: jsx(RemoveEmail, _objectSpread2(_objectSpread2(_objectSpread2({
4565
+ successPageDuration: successPageDuration
4566
+ }, userId && {
4567
+ userId: userId
4568
+ }), stampWith && {
4569
+ stampWith: stampWith
4570
+ }), {}, {
4571
+ onSuccess: function onSuccess(userId) {
4572
+ resolve(userId);
4573
+ },
4574
+ onError: function onError(error) {
4575
+ reject(error);
4576
+ }
4577
+ })),
4578
+ showTitle: false,
4579
+ preventBack: true
4580
+ });
4581
+ }));
4582
+ case 7:
4583
+ _context25.prev = 7;
4584
+ _context25.t0 = _context25["catch"](3);
4585
+ if (!(_context25.t0 instanceof TurnkeyError)) {
4586
+ _context25.next = 11;
4587
+ break;
4588
+ }
4589
+ throw _context25.t0;
4590
+ case 11:
4591
+ throw new TurnkeyError("Failed to remove user email.", TurnkeyErrorCodes.UPDATE_USER_EMAIL_ERROR, _context25.t0);
4592
+ case 12:
4593
+ case "end":
4594
+ return _context25.stop();
4595
+ }
4596
+ }, _callee25, null, [[3, 7]]);
4597
+ }));
4598
+ return function handleRemoveUserEmail(_x72) {
4599
+ return _ref29.apply(this, arguments);
4600
+ };
4601
+ }();
4602
+ var handleRemoveUserPhoneNumber = /*#__PURE__*/function () {
4603
+ var _ref31 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
4604
+ var _ref32, _ref32$successPageDur, successPageDuration, stampWith, userId;
4605
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4606
+ while (1) switch (_context26.prev = _context26.next) {
4607
+ case 0:
4608
+ _ref32 = params || {}, _ref32$successPageDur = _ref32.successPageDuration, successPageDuration = _ref32$successPageDur === void 0 ? 2000 : _ref32$successPageDur, stampWith = _ref32.stampWith, userId = _ref32.userId;
4609
+ if (session) {
4610
+ _context26.next = 3;
4611
+ break;
4612
+ }
4613
+ throw new TurnkeyError("No active session found.", TurnkeyErrorCodes.NO_SESSION_FOUND);
4614
+ case 3:
4615
+ _context26.prev = 3;
4616
+ return _context26.abrupt("return", new Promise(function (resolve, reject) {
4617
+ pushPage({
4618
+ key: "Remove Phone Number",
4619
+ content: jsx(RemovePhoneNumber, _objectSpread2(_objectSpread2(_objectSpread2({
4620
+ successPageDuration: successPageDuration
4621
+ }, userId && {
4622
+ userId: userId
4623
+ }), stampWith && {
4624
+ stampWith: stampWith
4625
+ }), {}, {
4626
+ onSuccess: function onSuccess(userId) {
4627
+ resolve(userId);
4628
+ },
4629
+ onError: function onError(error) {
4630
+ reject(error);
4631
+ }
4632
+ })),
4633
+ showTitle: false,
4634
+ preventBack: true
4635
+ });
4636
+ }));
4637
+ case 7:
4638
+ _context26.prev = 7;
4639
+ _context26.t0 = _context26["catch"](3);
4640
+ if (!(_context26.t0 instanceof TurnkeyError)) {
4641
+ _context26.next = 11;
4642
+ break;
4643
+ }
4644
+ throw _context26.t0;
4645
+ case 11:
4646
+ throw new TurnkeyError("Failed to remove user phone number.", TurnkeyErrorCodes.UPDATE_USER_PHONE_NUMBER_ERROR, _context26.t0);
4647
+ case 12:
4648
+ case "end":
4649
+ return _context26.stop();
4650
+ }
4651
+ }, _callee26, null, [[3, 7]]);
4652
+ }));
4653
+ return function handleRemoveUserPhoneNumber(_x73) {
4654
+ return _ref31.apply(this, arguments);
4655
+ };
4656
+ }();
4657
+ return jsx(ClientContext.Provider, {
4658
+ value: {
4659
+ session: session,
4660
+ allSessions: allSessions,
4661
+ clientState: clientState,
4662
+ authState: authState,
4663
+ user: user,
4664
+ wallets: wallets,
4665
+ config: masterConfig,
4666
+ httpClient: client === null || client === void 0 ? void 0 : client.httpClient,
4667
+ createPasskey: createPasskey,
4668
+ logout: logout,
4669
+ loginWithPasskey: loginWithPasskey,
4670
+ signUpWithPasskey: signUpWithPasskey,
4671
+ getWalletProviders: getWalletProviders,
4672
+ connectWalletAccount: connectWalletAccount,
4673
+ disconnectWalletAccount: disconnectWalletAccount,
4674
+ switchWalletProviderChain: switchWalletProviderChain,
4675
+ loginWithWallet: loginWithWallet,
4676
+ signUpWithWallet: signUpWithWallet,
4677
+ loginOrSignupWithWallet: loginOrSignupWithWallet,
4678
+ initOtp: initOtp,
4679
+ verifyOtp: verifyOtp,
4680
+ loginWithOtp: loginWithOtp,
4681
+ signUpWithOtp: signUpWithOtp,
4682
+ completeOtp: completeOtp,
4683
+ loginWithOauth: loginWithOauth,
4684
+ signUpWithOauth: signUpWithOauth,
4685
+ completeOauth: completeOauth,
4686
+ fetchWallets: fetchWallets,
4687
+ fetchWalletAccounts: fetchWalletAccounts,
4688
+ refreshWallets: refreshWallets,
4689
+ signMessage: signMessage,
4690
+ signTransaction: signTransaction,
4691
+ signAndSendTransaction: signAndSendTransaction,
4692
+ fetchUser: fetchUser,
4693
+ refreshUser: refreshUser,
4694
+ updateUserEmail: updateUserEmail,
4695
+ removeUserEmail: removeUserEmail,
4696
+ updateUserPhoneNumber: updateUserPhoneNumber,
4697
+ removeUserPhoneNumber: removeUserPhoneNumber,
4698
+ updateUserName: updateUserName,
4699
+ addOauthProvider: addOauthProvider,
4700
+ removeOauthProviders: removeOauthProviders,
4701
+ addPasskey: addPasskey,
4702
+ removePasskeys: removePasskeys,
4703
+ createWallet: createWallet,
4704
+ createWalletAccounts: createWalletAccounts,
4705
+ exportWallet: exportWallet,
4706
+ importWallet: importWallet,
4707
+ deleteSubOrganization: deleteSubOrganization,
4708
+ storeSession: storeSession,
4709
+ clearSession: clearSession,
4710
+ clearAllSessions: clearAllSessions,
4711
+ refreshSession: refreshSession,
4712
+ getSession: getSession,
4713
+ getAllSessions: getAllSessions,
4714
+ setActiveSession: setActiveSession,
4715
+ clearUnusedKeyPairs: clearUnusedKeyPairs,
4716
+ getActiveSessionKey: getActiveSessionKey,
4717
+ createApiKeyPair: createApiKeyPair,
4718
+ getProxyAuthConfig: getProxyAuthConfig,
4719
+ handleLogin: handleLogin,
4720
+ handleGoogleOauth: handleGoogleOauth,
4721
+ handleAppleOauth: handleAppleOauth,
4722
+ handleFacebookOauth: handleFacebookOauth,
4723
+ handleExport: handleExport,
4724
+ handleImport: handleImport,
4725
+ handleUpdateUserEmail: handleUpdateUserEmail,
4726
+ handleUpdateUserPhoneNumber: handleUpdateUserPhoneNumber,
4727
+ handleUpdateUserName: handleUpdateUserName,
4728
+ handleAddOauthProvider: handleAddOauthProvider,
4729
+ handleRemoveOauthProvider: handleRemoveOauthProvider,
4730
+ handleAddPasskey: handleAddPasskey,
4731
+ handleRemovePasskey: handleRemovePasskey,
4732
+ handleAddEmail: handleAddEmail,
4733
+ handleAddPhoneNumber: handleAddPhoneNumber,
4734
+ handleSignMessage: handleSignMessage,
4735
+ handleLinkExternalWallet: handleLinkExternalWallet,
4736
+ handleRemoveUserEmail: handleRemoveUserEmail,
4737
+ handleRemoveUserPhoneNumber: handleRemoveUserPhoneNumber
4738
+ },
4739
+ children: children
4740
+ });
4741
+ };
4742
+
4743
+ export { ClientProvider };
4744
+ //# sourceMappingURL=Provider.mjs.map