@getpara/core-sdk 2.12.0 → 2.14.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 (197) hide show
  1. package/dist/cjs/ParaCore.js +805 -1999
  2. package/dist/cjs/constants.js +4 -1
  3. package/dist/cjs/services/AuthService.js +787 -0
  4. package/dist/cjs/services/BaseAuthFlowService.js +78 -0
  5. package/dist/cjs/services/ExternalWalletService.js +386 -0
  6. package/dist/cjs/services/LoginFlowService.js +163 -0
  7. package/dist/cjs/services/PollingService.js +448 -0
  8. package/dist/cjs/services/PortalUrlService.js +379 -0
  9. package/dist/cjs/services/PregenWalletService.js +442 -0
  10. package/dist/cjs/services/SessionManagementService.js +280 -0
  11. package/dist/cjs/services/SignupFlowService.js +185 -0
  12. package/dist/cjs/services/VerificationFlowService.js +242 -0
  13. package/dist/cjs/services/WalletService.js +577 -0
  14. package/dist/cjs/services/types/AuthServiceTypes.js +15 -0
  15. package/dist/cjs/services/types/BaseAuthFlowServiceTypes.js +15 -0
  16. package/dist/cjs/services/types/ExternalWalletServiceTypes.js +15 -0
  17. package/dist/cjs/services/types/LoginFlowServiceTypes.js +15 -0
  18. package/dist/cjs/services/types/PollingServiceTypes.js +15 -0
  19. package/dist/cjs/services/types/PortalUrlServiceTypes.js +15 -0
  20. package/dist/cjs/services/types/PregenWalletServiceTypes.js +15 -0
  21. package/dist/cjs/services/types/SessionManagementServiceTypes.js +15 -0
  22. package/dist/cjs/services/types/SignupFlowServiceTypes.js +15 -0
  23. package/dist/cjs/services/types/VerificationFlowServiceTypes.js +15 -0
  24. package/dist/cjs/services/types/WalletServiceTypes.js +15 -0
  25. package/dist/cjs/services/types/index.js +15 -0
  26. package/dist/cjs/state/CoreStateManager.js +301 -0
  27. package/dist/cjs/state/actors/authenticateWithEmailOrPhone.js +50 -0
  28. package/dist/cjs/state/actors/authenticateWithExternalWallet.js +50 -0
  29. package/dist/cjs/state/actors/authenticateWithFarcaster.js +50 -0
  30. package/dist/cjs/state/actors/authenticateWithFarcasterLegacy.js +50 -0
  31. package/dist/cjs/state/actors/authenticateWithTelegram.js +50 -0
  32. package/dist/cjs/state/actors/authenticateWithTelegramLegacy.js +50 -0
  33. package/dist/cjs/state/actors/checkUserState.js +53 -0
  34. package/dist/cjs/state/actors/claimWallets.js +56 -0
  35. package/dist/cjs/state/actors/connectExternalConnectors.js +54 -0
  36. package/dist/cjs/state/actors/connectExternalWallet.js +50 -0
  37. package/dist/cjs/state/actors/createGuestWallets.js +50 -0
  38. package/dist/cjs/state/actors/createWallets.js +73 -0
  39. package/dist/cjs/state/actors/polling.js +91 -0
  40. package/dist/cjs/state/actors/processAuthentication.js +50 -0
  41. package/dist/cjs/state/actors/setupAfterLogin.js +52 -0
  42. package/dist/cjs/state/actors/setupPara.js +50 -0
  43. package/dist/cjs/state/actors/signExternalWalletVerification.js +79 -0
  44. package/dist/cjs/state/actors/switchExternalWallet.js +50 -0
  45. package/dist/cjs/state/actors/verifyExternalWallet.js +50 -0
  46. package/dist/cjs/state/actors/verifyNewAccount.js +50 -0
  47. package/dist/cjs/state/actors/waitForExternalWalletProviders.js +54 -0
  48. package/dist/cjs/state/machines/authStateMachine.helpers.js +137 -0
  49. package/dist/cjs/state/machines/authStateMachine.js +1084 -0
  50. package/dist/cjs/state/machines/coreStateMachine.js +383 -0
  51. package/dist/cjs/state/machines/walletStateMachine.js +456 -0
  52. package/dist/cjs/state/types/auth.js +15 -0
  53. package/dist/cjs/state/types/core.js +15 -0
  54. package/dist/cjs/state/types/wallet.js +15 -0
  55. package/dist/cjs/types/{auth.js → accountLinking.js} +3 -3
  56. package/dist/cjs/types/authState.js +15 -0
  57. package/dist/cjs/types/coreApi.js +3 -1
  58. package/dist/cjs/types/index.js +2 -2
  59. package/dist/cjs/types/serviceInterfaces.js +15 -0
  60. package/dist/cjs/types/util.js +15 -0
  61. package/dist/cjs/utils/formatting.js +6 -0
  62. package/dist/cjs/utils/retryBackoff.js +30 -0
  63. package/dist/cjs/utils/stateErrorHelpers.js +60 -0
  64. package/dist/cjs/utils/stateListener.js +129 -0
  65. package/dist/esm/ParaCore.js +808 -2026
  66. package/dist/esm/constants.js +3 -1
  67. package/dist/esm/services/AuthService.js +717 -0
  68. package/dist/esm/services/BaseAuthFlowService.js +25 -0
  69. package/dist/esm/services/ExternalWalletService.js +327 -0
  70. package/dist/esm/services/LoginFlowService.js +97 -0
  71. package/dist/esm/services/PollingService.js +389 -0
  72. package/dist/esm/services/PortalUrlService.js +320 -0
  73. package/dist/esm/services/PregenWalletService.js +393 -0
  74. package/dist/esm/services/SessionManagementService.js +236 -0
  75. package/dist/esm/services/SignupFlowService.js +119 -0
  76. package/dist/esm/services/VerificationFlowService.js +178 -0
  77. package/dist/esm/services/WalletService.js +514 -0
  78. package/dist/esm/services/types/AuthServiceTypes.js +0 -0
  79. package/dist/esm/services/types/BaseAuthFlowServiceTypes.js +0 -0
  80. package/dist/esm/services/types/ExternalWalletServiceTypes.js +0 -0
  81. package/dist/esm/services/types/LoginFlowServiceTypes.js +0 -0
  82. package/dist/esm/services/types/PollingServiceTypes.js +0 -0
  83. package/dist/esm/services/types/PortalUrlServiceTypes.js +0 -0
  84. package/dist/esm/services/types/PregenWalletServiceTypes.js +0 -0
  85. package/dist/esm/services/types/SessionManagementServiceTypes.js +0 -0
  86. package/dist/esm/services/types/SignupFlowServiceTypes.js +0 -0
  87. package/dist/esm/services/types/VerificationFlowServiceTypes.js +0 -0
  88. package/dist/esm/services/types/WalletServiceTypes.js +0 -0
  89. package/dist/esm/services/types/index.js +0 -0
  90. package/dist/esm/state/CoreStateManager.js +265 -0
  91. package/dist/esm/state/actors/authenticateWithEmailOrPhone.js +10 -0
  92. package/dist/esm/state/actors/authenticateWithExternalWallet.js +10 -0
  93. package/dist/esm/state/actors/authenticateWithFarcaster.js +10 -0
  94. package/dist/esm/state/actors/authenticateWithFarcasterLegacy.js +10 -0
  95. package/dist/esm/state/actors/authenticateWithTelegram.js +10 -0
  96. package/dist/esm/state/actors/authenticateWithTelegramLegacy.js +10 -0
  97. package/dist/esm/state/actors/checkUserState.js +13 -0
  98. package/dist/esm/state/actors/claimWallets.js +16 -0
  99. package/dist/esm/state/actors/connectExternalConnectors.js +14 -0
  100. package/dist/esm/state/actors/connectExternalWallet.js +10 -0
  101. package/dist/esm/state/actors/createGuestWallets.js +10 -0
  102. package/dist/esm/state/actors/createWallets.js +20 -0
  103. package/dist/esm/state/actors/polling.js +55 -0
  104. package/dist/esm/state/actors/processAuthentication.js +10 -0
  105. package/dist/esm/state/actors/setupAfterLogin.js +12 -0
  106. package/dist/esm/state/actors/setupPara.js +10 -0
  107. package/dist/esm/state/actors/signExternalWalletVerification.js +15 -0
  108. package/dist/esm/state/actors/switchExternalWallet.js +10 -0
  109. package/dist/esm/state/actors/verifyExternalWallet.js +10 -0
  110. package/dist/esm/state/actors/verifyNewAccount.js +10 -0
  111. package/dist/esm/state/actors/waitForExternalWalletProviders.js +14 -0
  112. package/dist/esm/state/machines/authStateMachine.helpers.js +92 -0
  113. package/dist/esm/state/machines/authStateMachine.js +1039 -0
  114. package/dist/esm/state/machines/coreStateMachine.js +343 -0
  115. package/dist/esm/state/machines/walletStateMachine.js +401 -0
  116. package/dist/esm/state/types/auth.js +0 -0
  117. package/dist/esm/state/types/core.js +0 -0
  118. package/dist/esm/state/types/wallet.js +0 -0
  119. package/dist/esm/types/authState.js +0 -0
  120. package/dist/esm/types/coreApi.js +3 -1
  121. package/dist/esm/types/index.js +1 -1
  122. package/dist/esm/types/serviceInterfaces.js +0 -0
  123. package/dist/esm/types/util.js +0 -0
  124. package/dist/esm/utils/formatting.js +6 -0
  125. package/dist/esm/utils/retryBackoff.js +7 -0
  126. package/dist/esm/utils/stateErrorHelpers.js +37 -0
  127. package/dist/esm/utils/stateListener.js +106 -0
  128. package/dist/types/ParaCore.d.ts +191 -119
  129. package/dist/types/PlatformUtils.d.ts +23 -0
  130. package/dist/types/constants.d.ts +1 -0
  131. package/dist/types/index.d.ts +4 -2
  132. package/dist/types/services/AuthService.d.ts +72 -0
  133. package/dist/types/services/BaseAuthFlowService.d.ts +28 -0
  134. package/dist/types/services/ExternalWalletService.d.ts +44 -0
  135. package/dist/types/services/LoginFlowService.d.ts +9 -0
  136. package/dist/types/services/PollingService.d.ts +35 -0
  137. package/dist/types/services/PortalUrlService.d.ts +26 -0
  138. package/dist/types/services/PregenWalletService.d.ts +38 -0
  139. package/dist/types/services/SessionManagementService.d.ts +28 -0
  140. package/dist/types/services/SignupFlowService.d.ts +10 -0
  141. package/dist/types/services/VerificationFlowService.d.ts +17 -0
  142. package/dist/types/services/WalletService.d.ts +54 -0
  143. package/dist/types/services/types/AuthServiceTypes.d.ts +147 -0
  144. package/dist/types/services/types/BaseAuthFlowServiceTypes.d.ts +4 -0
  145. package/dist/types/services/types/ExternalWalletServiceTypes.d.ts +67 -0
  146. package/dist/types/services/types/LoginFlowServiceTypes.d.ts +19 -0
  147. package/dist/types/services/types/PollingServiceTypes.d.ts +82 -0
  148. package/dist/types/services/types/PortalUrlServiceTypes.d.ts +46 -0
  149. package/dist/types/services/types/PregenWalletServiceTypes.d.ts +73 -0
  150. package/dist/types/services/types/SessionManagementServiceTypes.d.ts +27 -0
  151. package/dist/types/services/types/SignupFlowServiceTypes.d.ts +18 -0
  152. package/dist/types/services/types/VerificationFlowServiceTypes.d.ts +90 -0
  153. package/dist/types/services/types/WalletServiceTypes.d.ts +109 -0
  154. package/dist/types/services/types/index.d.ts +11 -0
  155. package/dist/types/state/CoreStateManager.d.ts +36 -0
  156. package/dist/types/state/actors/authenticateWithEmailOrPhone.d.ts +8 -0
  157. package/dist/types/state/actors/authenticateWithExternalWallet.d.ts +8 -0
  158. package/dist/types/state/actors/authenticateWithFarcaster.d.ts +3 -0
  159. package/dist/types/state/actors/authenticateWithFarcasterLegacy.d.ts +3 -0
  160. package/dist/types/state/actors/authenticateWithTelegram.d.ts +3 -0
  161. package/dist/types/state/actors/authenticateWithTelegramLegacy.d.ts +8 -0
  162. package/dist/types/state/actors/checkUserState.d.ts +6 -0
  163. package/dist/types/state/actors/claimWallets.d.ts +8 -0
  164. package/dist/types/state/actors/connectExternalConnectors.d.ts +4 -0
  165. package/dist/types/state/actors/connectExternalWallet.d.ts +3 -0
  166. package/dist/types/state/actors/createGuestWallets.d.ts +3 -0
  167. package/dist/types/state/actors/createWallets.d.ts +10 -0
  168. package/dist/types/state/actors/polling.d.ts +3 -0
  169. package/dist/types/state/actors/processAuthentication.d.ts +10 -0
  170. package/dist/types/state/actors/setupAfterLogin.d.ts +5 -0
  171. package/dist/types/state/actors/setupPara.d.ts +2 -0
  172. package/dist/types/state/actors/signExternalWalletVerification.d.ts +7 -0
  173. package/dist/types/state/actors/switchExternalWallet.d.ts +3 -0
  174. package/dist/types/state/actors/verifyExternalWallet.d.ts +8 -0
  175. package/dist/types/state/actors/verifyNewAccount.d.ts +8 -0
  176. package/dist/types/state/actors/waitForExternalWalletProviders.d.ts +2 -0
  177. package/dist/types/state/machines/authStateMachine.d.ts +2570 -0
  178. package/dist/types/state/machines/authStateMachine.helpers.d.ts +57 -0
  179. package/dist/types/state/machines/coreStateMachine.d.ts +22075 -0
  180. package/dist/types/state/machines/walletStateMachine.d.ts +1056 -0
  181. package/dist/types/state/types/auth.d.ts +113 -0
  182. package/dist/types/state/types/core.d.ts +116 -0
  183. package/dist/types/state/types/wallet.d.ts +76 -0
  184. package/dist/types/types/authState.d.ts +66 -0
  185. package/dist/types/types/config.d.ts +5 -0
  186. package/dist/types/types/coreApi.d.ts +148 -298
  187. package/dist/types/types/index.d.ts +3 -1
  188. package/dist/types/types/methods.d.ts +1 -191
  189. package/dist/types/types/serviceInterfaces.d.ts +125 -0
  190. package/dist/types/types/util.d.ts +43 -0
  191. package/dist/types/types/wallet.d.ts +3 -1
  192. package/dist/types/utils/retryBackoff.d.ts +2 -0
  193. package/dist/types/utils/stateErrorHelpers.d.ts +2 -0
  194. package/dist/types/utils/stateListener.d.ts +47 -0
  195. package/package.json +5 -4
  196. /package/dist/esm/types/{auth.js → accountLinking.js} +0 -0
  197. /package/dist/types/types/{auth.d.ts → accountLinking.d.ts} +0 -0
@@ -0,0 +1,401 @@
1
+ import {
2
+ __async,
3
+ __spreadProps,
4
+ __spreadValues
5
+ } from "../../chunk-7B52C2XE.js";
6
+ import { assign, setup, or, and } from "xstate";
7
+ import { createPollingActor } from "../actors/polling.js";
8
+ import { createClaimWalletsActor } from "../actors/claimWallets.js";
9
+ import { createCreateWalletsActor } from "../actors/createWallets.js";
10
+ import { createSetupAfterLoginActor } from "../actors/setupAfterLogin.js";
11
+ import { extractErrorMessage, formatStateError } from "../../utils/stateErrorHelpers.js";
12
+ import { createConnectParaConnectorsActor } from "../actors/connectExternalConnectors.js";
13
+ import { createCreateGuestWalletsActor } from "../actors/createGuestWallets.js";
14
+ function createWalletStateMachine(paraCoreInterface) {
15
+ return setup({
16
+ types: {
17
+ context: {},
18
+ events: {}
19
+ },
20
+ actors: {
21
+ polling: createPollingActor(paraCoreInterface.pollingService),
22
+ claimWallets: createClaimWalletsActor(paraCoreInterface.pregenWalletService),
23
+ createWallets: createCreateWalletsActor(paraCoreInterface.walletService),
24
+ setupAfterLogin: createSetupAfterLoginActor(paraCoreInterface),
25
+ connectParaConnectors: createConnectParaConnectorsActor(paraCoreInterface.externalWalletService),
26
+ createGuestWallets: createCreateGuestWalletsActor(paraCoreInterface.pregenWalletService)
27
+ },
28
+ actions: {
29
+ setPollingCallbacks: assign({
30
+ pollingCallbacks: ({ event }) => {
31
+ if ("data" in event && event.data && typeof event.data === "object" && "pollingCallbacks" in event.data) {
32
+ return event.data.pollingCallbacks || null;
33
+ }
34
+ return null;
35
+ }
36
+ }),
37
+ incrementWalletRetry: assign({
38
+ retryAttempts: ({ context }, params) => {
39
+ var _a;
40
+ const newCount = (((_a = context.retryAttempts) == null ? void 0 : _a[params.type]) || 0) + 1;
41
+ paraCoreInterface.devLog(`[wallet] Retry ${params.type}: attempt ${newCount}/3`);
42
+ return __spreadProps(__spreadValues({}, context.retryAttempts), {
43
+ [params.type]: newCount
44
+ });
45
+ }
46
+ })
47
+ },
48
+ guards: {
49
+ canRetryClaiming: ({ context }) => {
50
+ var _a;
51
+ return (((_a = context.retryAttempts) == null ? void 0 : _a.claiming) || 0) < 3;
52
+ },
53
+ canRetryCreating: ({ context }) => {
54
+ var _a;
55
+ return (((_a = context.retryAttempts) == null ? void 0 : _a.creating) || 0) < 3;
56
+ },
57
+ canRetryConnecting: ({ context }) => {
58
+ var _a;
59
+ return (((_a = context.retryAttempts) == null ? void 0 : _a.connecting) || 0) < 3;
60
+ },
61
+ isNoWalletConfig: () => paraCoreInterface.isNoWalletConfig,
62
+ isExternalWalletConnectionOnly: () => paraCoreInterface.externalWalletService.externalWalletConnectionType === "CONNECTION_ONLY" || paraCoreInterface.externalWalletService.externalWalletConnectionType === "VERIFICATION",
63
+ isNewUser: ({ context }) => {
64
+ var _a;
65
+ return ((_a = context.authData) == null ? void 0 : _a.isNewUser) || false;
66
+ },
67
+ shouldAutoCreate: ({ context }) => {
68
+ var _a;
69
+ return ((_a = context.authData) == null ? void 0 : _a.shouldAutoCreateWallets) || false;
70
+ },
71
+ needsWallets: ({ context }) => context.needsWallet,
72
+ isLegacyOrEnclaveLogin: ({ context }) => {
73
+ var _a, _b;
74
+ const stage = (_b = (_a = context.authData) == null ? void 0 : _a.authStateResult) == null ? void 0 : _b.stage;
75
+ return stage === "login" || stage === "done" || stage === "verify" && paraCoreInterface.authService.isEnclaveUser;
76
+ },
77
+ hasPreviousWalletsResult: ({ context }) => context.newWalletsResult !== null,
78
+ isWalletsAlreadySetUp: ({ context }) => {
79
+ var _a, _b;
80
+ const stage = (_b = (_a = context.authData) == null ? void 0 : _a.authStateResult) == null ? void 0 : _b.stage;
81
+ const isLogin = stage === "login" || stage === "done";
82
+ if (!isLogin) return false;
83
+ const currentIds = paraCoreInterface.walletService.currentWalletIdsArray;
84
+ if (currentIds.length === 0) return false;
85
+ return currentIds.every(([walletId]) => {
86
+ const wallet = paraCoreInterface.walletService.wallets[walletId];
87
+ return wallet && !!wallet.signer;
88
+ });
89
+ },
90
+ // Check if the auth state is guest mode
91
+ isGuestMode: ({ context }) => {
92
+ var _a;
93
+ return ((_a = context.authData) == null ? void 0 : _a.isGuestMode) || false;
94
+ },
95
+ // Check if the user actually needs guest wallets created
96
+ needsGuestWallets: () => !paraCoreInterface.pregenWalletService.isGuestMode,
97
+ // Check if the user should claim guest wallets
98
+ shouldClaimGuestWallets: () => paraCoreInterface.pregenWalletService.isGuestMode
99
+ }
100
+ }).createMachine({
101
+ id: "wallets",
102
+ initial: "checking_wallet_state",
103
+ context: ({ input }) => ({
104
+ needsWallet: false,
105
+ newWalletsResult: (input == null ? void 0 : input.previousWalletsResult) || null,
106
+ temporaryShares: null,
107
+ pollingCallbacks: null,
108
+ error: null,
109
+ authData: {
110
+ isNewUser: (input == null ? void 0 : input.isNewUser) || false,
111
+ authStateResult: (input == null ? void 0 : input.authStateResult) || null,
112
+ shouldAutoCreateWallets: (input == null ? void 0 : input.shouldAutoCreateWallets) || false,
113
+ skipSessionRefreshOnSetup: (input == null ? void 0 : input.skipSessionRefreshOnSetup) || false,
114
+ isGuestMode: (input == null ? void 0 : input.isGuestMode) || false
115
+ },
116
+ guestWallets: null,
117
+ retryAttempts: {}
118
+ }),
119
+ states: {
120
+ checking_wallet_state: {
121
+ always: [
122
+ {
123
+ target: "creating_guest_wallets",
124
+ guard: and(["isGuestMode", "needsGuestWallets"])
125
+ },
126
+ {
127
+ target: "guest_mode",
128
+ guard: and(["isGuestMode"])
129
+ },
130
+ {
131
+ target: "no_wallets_needed",
132
+ guard: or(["isNoWalletConfig", "isExternalWalletConnectionOnly"])
133
+ },
134
+ {
135
+ // Skip claiming if we already have wallet results from a previous attempt
136
+ target: "creating_wallets",
137
+ guard: and(["hasPreviousWalletsResult", or(["isNewUser", "shouldAutoCreate"])])
138
+ },
139
+ {
140
+ target: "claiming_wallets",
141
+ guard: and([or(["isNewUser", "shouldClaimGuestWallets"]), "shouldAutoCreate"])
142
+ },
143
+ {
144
+ target: "needs_wallets",
145
+ guard: "isNewUser"
146
+ },
147
+ {
148
+ // Wallets already set up (e.g., by loginWithPasskey on mobile) — still
149
+ // go through creating_wallets so any missing provider-required types
150
+ // get created. createWalletPerType is idempotent (checks #getMissingTypes).
151
+ target: "creating_wallets",
152
+ guard: "isWalletsAlreadySetUp"
153
+ },
154
+ {
155
+ target: "waiting_for_wallets",
156
+ guard: "isLegacyOrEnclaveLogin"
157
+ },
158
+ {
159
+ target: "connecting_para_connectors"
160
+ }
161
+ ]
162
+ },
163
+ needs_wallets: {
164
+ on: {
165
+ WAIT_FOR_WALLET_CREATION: {
166
+ target: "claiming_wallets",
167
+ actions: "setPollingCallbacks"
168
+ }
169
+ }
170
+ },
171
+ creating_guest_wallets: {
172
+ invoke: {
173
+ src: "createGuestWallets",
174
+ onDone: [
175
+ {
176
+ target: "guest_mode",
177
+ actions: assign({
178
+ guestWallets: ({ event }) => {
179
+ return event.output || null;
180
+ }
181
+ })
182
+ }
183
+ ],
184
+ onError: {
185
+ target: "error",
186
+ actions: assign({
187
+ error: ({ event }) => formatStateError(event.error, "Failed to create guest wallets")
188
+ })
189
+ }
190
+ }
191
+ },
192
+ claiming_wallets: {
193
+ invoke: {
194
+ src: "claimWallets",
195
+ input: ({ context }) => {
196
+ var _a, _b;
197
+ return { retryCount: (_b = (_a = context.retryAttempts) == null ? void 0 : _a.claiming) != null ? _b : 0 };
198
+ },
199
+ onDone: [
200
+ {
201
+ target: "creating_wallets",
202
+ actions: assign({
203
+ newWalletsResult: ({ event }) => {
204
+ return event.output || null;
205
+ }
206
+ }),
207
+ guard: or(["isNewUser", "needsWallets"])
208
+ },
209
+ {
210
+ target: "connecting_para_connectors"
211
+ }
212
+ ],
213
+ onError: [
214
+ {
215
+ target: "claiming_wallets",
216
+ guard: "canRetryClaiming",
217
+ actions: [{ type: "incrementWalletRetry", params: { type: "claiming" } }]
218
+ },
219
+ {
220
+ target: "error",
221
+ actions: assign({
222
+ error: ({ event }) => formatStateError(event.error, "Failed to claim wallets")
223
+ })
224
+ }
225
+ ]
226
+ }
227
+ },
228
+ creating_wallets: {
229
+ invoke: {
230
+ src: "createWallets",
231
+ input: ({ context }) => {
232
+ var _a, _b;
233
+ return __spreadProps(__spreadValues({}, context.newWalletsResult), { retryCount: (_b = (_a = context.retryAttempts) == null ? void 0 : _a.creating) != null ? _b : 0 });
234
+ },
235
+ onDone: {
236
+ target: "connecting_para_connectors",
237
+ actions: assign({
238
+ newWalletsResult: ({ event }) => {
239
+ return event.output || null;
240
+ }
241
+ })
242
+ },
243
+ onError: [
244
+ {
245
+ target: "creating_wallets",
246
+ guard: "canRetryCreating",
247
+ actions: [{ type: "incrementWalletRetry", params: { type: "creating" } }]
248
+ },
249
+ {
250
+ target: "error",
251
+ actions: assign({
252
+ error: ({ event }) => formatStateError(event.error, "Failed to create wallets")
253
+ })
254
+ }
255
+ ]
256
+ }
257
+ },
258
+ waiting_for_wallets: {
259
+ invoke: {
260
+ src: "polling",
261
+ input: ({ context, self }) => {
262
+ var _a;
263
+ return {
264
+ checkCondition: () => __async(this, null, function* () {
265
+ try {
266
+ return yield paraCoreInterface.pollingService.waitForWallets({ parent: self })();
267
+ } catch (error) {
268
+ throw new Error(`Wallet polling failed: ${extractErrorMessage(error, "Unknown error")}`);
269
+ }
270
+ }),
271
+ onPoll: () => {
272
+ var _a2, _b;
273
+ return (_b = (_a2 = context.pollingCallbacks) == null ? void 0 : _a2.onPoll) == null ? void 0 : _b.call(_a2);
274
+ },
275
+ onCancel: () => {
276
+ var _a2, _b;
277
+ return (_b = (_a2 = context.pollingCallbacks) == null ? void 0 : _a2.onCancel) == null ? void 0 : _b.call(_a2);
278
+ },
279
+ isCanceled: ((_a = context.pollingCallbacks) == null ? void 0 : _a.isCanceled) || (() => false),
280
+ id: "waitingForWallets"
281
+ };
282
+ },
283
+ onError: {
284
+ target: "error",
285
+ actions: assign({
286
+ error: ({ event }) => formatStateError(event.error, "Wallet polling failed")
287
+ })
288
+ }
289
+ },
290
+ entry: "setPollingCallbacks",
291
+ on: {
292
+ SET_NEEDS_WALLET: {
293
+ actions: assign({
294
+ needsWallet: ({ event }) => {
295
+ if ("data" in event && event.data && typeof event.data === "object" && "needsWallet" in event.data) {
296
+ return Boolean(event.data.needsWallet);
297
+ }
298
+ return false;
299
+ }
300
+ })
301
+ },
302
+ SET_TEMPORARY_SHARES: {
303
+ actions: assign({
304
+ temporaryShares: ({ event }) => {
305
+ if ("data" in event && event.data && typeof event.data === "object" && "temporaryShares" in event.data) {
306
+ return event.data.temporaryShares;
307
+ }
308
+ return null;
309
+ }
310
+ })
311
+ },
312
+ COMPLETE: [
313
+ {
314
+ target: "needs_wallets",
315
+ guard: "needsWallets"
316
+ },
317
+ {
318
+ target: "setting_up_after_login"
319
+ }
320
+ ],
321
+ CANCEL: [
322
+ {
323
+ target: "checking_wallet_state"
324
+ }
325
+ ],
326
+ ERROR: {
327
+ target: "error",
328
+ actions: assign({
329
+ error: ({ event }) => formatStateError(event.error, "Wallet polling failed")
330
+ })
331
+ }
332
+ }
333
+ },
334
+ setting_up_after_login: {
335
+ invoke: {
336
+ src: "setupAfterLogin",
337
+ input: ({ context }) => {
338
+ var _a;
339
+ return {
340
+ temporaryShares: context.temporaryShares,
341
+ skipSessionRefresh: ((_a = context.authData) == null ? void 0 : _a.skipSessionRefreshOnSetup) || false
342
+ };
343
+ },
344
+ onDone: {
345
+ target: "claiming_wallets",
346
+ actions: assign({
347
+ // Reset temporary shares after successful setup
348
+ temporaryShares: null
349
+ })
350
+ },
351
+ onError: {
352
+ target: "error",
353
+ actions: assign({
354
+ error: ({ event }) => formatStateError(event.error, "Failed to setup after login")
355
+ })
356
+ }
357
+ }
358
+ },
359
+ connecting_para_connectors: {
360
+ invoke: {
361
+ src: "connectParaConnectors",
362
+ input: ({ context }) => {
363
+ var _a, _b;
364
+ return { retryCount: (_b = (_a = context.retryAttempts) == null ? void 0 : _a.connecting) != null ? _b : 0 };
365
+ },
366
+ onDone: {
367
+ target: "wallets_ready"
368
+ },
369
+ onError: [
370
+ {
371
+ target: "connecting_para_connectors",
372
+ guard: "canRetryConnecting",
373
+ actions: [{ type: "incrementWalletRetry", params: { type: "connecting" } }]
374
+ },
375
+ {
376
+ target: "error",
377
+ actions: assign({
378
+ error: ({ event }) => formatStateError(event.error, "Failed to connect Para connectors")
379
+ })
380
+ }
381
+ ]
382
+ }
383
+ },
384
+ no_wallets_needed: {
385
+ type: "final"
386
+ },
387
+ wallets_ready: {
388
+ type: "final"
389
+ },
390
+ guest_mode: {
391
+ type: "final"
392
+ },
393
+ error: {
394
+ type: "final"
395
+ }
396
+ }
397
+ });
398
+ }
399
+ export {
400
+ createWalletStateMachine
401
+ };
File without changes
File without changes
File without changes
File without changes
@@ -50,7 +50,9 @@ const PARA_CORE_METHODS = [
50
50
  "getLinkedAccounts",
51
51
  "accountLinkInProgress",
52
52
  "addCredential",
53
- "exportPrivateKey"
53
+ "exportPrivateKey",
54
+ "authenticateWithEmailOrPhone",
55
+ "authenticateWithOAuth"
54
56
  ];
55
57
  const PARA_INTERNAL_METHODS = [
56
58
  "linkAccount",
@@ -1,4 +1,4 @@
1
- export * from "./auth.js";
1
+ export * from "./accountLinking.js";
2
2
  export * from "./config.js";
3
3
  export * from "./coreApi.js";
4
4
  export * from "./wallet.js";
File without changes
File without changes
@@ -49,6 +49,9 @@ function rawSecp256k1PubkeyToRawAddress(pubkeyData) {
49
49
  return ripemd160(sha256(pubkeyData));
50
50
  }
51
51
  function getCosmosAddress(publicKey, prefix) {
52
+ if (!publicKey || publicKey.length === 0) {
53
+ return "";
54
+ }
52
55
  const uncompressedPublicKey = new Uint8Array(
53
56
  Buffer.from(publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey, "hex")
54
57
  );
@@ -59,6 +62,9 @@ function truncateAddress(str, addressType, {
59
62
  prefix = addressType === "COSMOS" ? "cosmos" : void 0,
60
63
  targetLength
61
64
  } = {}) {
65
+ if (!str || str.length === 0) {
66
+ return "";
67
+ }
62
68
  const minimum = addressType === "COSMOS" ? prefix.length : addressType === "EVM" ? 2 : 0;
63
69
  const margin = targetLength !== void 0 ? (targetLength - minimum) / 2 : 4;
64
70
  return `${str.slice(0, minimum + margin)}...${str.slice(-1 * margin)}`;
@@ -0,0 +1,7 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ const retryDelay = (attempt) => Math.min(100 * Math.pow(2, attempt), 2e3);
3
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
4
+ export {
5
+ retryDelay,
6
+ sleep
7
+ };
@@ -0,0 +1,37 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ function extractErrorMessage(error, defaultMessage) {
3
+ if (typeof error === "string") {
4
+ return error;
5
+ }
6
+ if (error instanceof Error) {
7
+ return error.message;
8
+ }
9
+ if (error && typeof error === "object" && "message" in error) {
10
+ return String(error.message);
11
+ }
12
+ if (error && typeof error === "object" && "error" in error) {
13
+ return extractErrorMessage(error.error, defaultMessage);
14
+ }
15
+ console.error("Unexpected error format:", error);
16
+ return defaultMessage;
17
+ }
18
+ function formatStateError(error, defaultMessage) {
19
+ if (error instanceof Error) {
20
+ return error;
21
+ }
22
+ if (typeof error === "string") {
23
+ return new Error(error);
24
+ }
25
+ if (error && typeof error === "object" && "message" in error) {
26
+ return new Error(String(error.message));
27
+ }
28
+ if (error && typeof error === "object" && "error" in error) {
29
+ return formatStateError(error.error, defaultMessage);
30
+ }
31
+ console.error("Unexpected error format:", error);
32
+ return new Error(defaultMessage);
33
+ }
34
+ export {
35
+ extractErrorMessage,
36
+ formatStateError
37
+ };
@@ -0,0 +1,106 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ function createStateListener({
3
+ stateManager,
4
+ shouldResolve,
5
+ shouldReject,
6
+ onReject,
7
+ rejectInErrorPhaseOnly,
8
+ timeoutMs = 3e5
9
+ }) {
10
+ return new Promise((resolve, reject) => {
11
+ let unsubscribe;
12
+ let timer;
13
+ const cleanup = () => {
14
+ unsubscribe == null ? void 0 : unsubscribe();
15
+ if (timer) clearTimeout(timer);
16
+ };
17
+ timer = setTimeout(() => {
18
+ cleanup();
19
+ reject(new Error("State listener timed out"));
20
+ }, timeoutMs);
21
+ unsubscribe = stateManager.onStateChange((state) => {
22
+ const isInErrorPhase = state.phase === "error" || state.authStatePhase === "error" || state.walletStatePhase === "error";
23
+ if (rejectInErrorPhaseOnly ? isInErrorPhase : state.error) {
24
+ cleanup();
25
+ onReject == null ? void 0 : onReject(state);
26
+ reject(state.error);
27
+ return;
28
+ }
29
+ if (shouldReject) {
30
+ const error = shouldReject(state);
31
+ if (error) {
32
+ cleanup();
33
+ onReject == null ? void 0 : onReject(state);
34
+ reject(error);
35
+ return;
36
+ }
37
+ }
38
+ const result = shouldResolve(state);
39
+ if (result !== null) {
40
+ cleanup();
41
+ resolve(result);
42
+ }
43
+ });
44
+ });
45
+ }
46
+ function waitForCoreStateChange({
47
+ stateManager,
48
+ resolvePhases,
49
+ onReject,
50
+ rejectInErrorPhaseOnly,
51
+ timeoutMs
52
+ }) {
53
+ return createStateListener({
54
+ stateManager,
55
+ shouldResolve: (state) => {
56
+ const matchedPhase = resolvePhases.find((p) => p.phase === state.phase);
57
+ if (matchedPhase) {
58
+ return matchedPhase.onPhase(state);
59
+ }
60
+ return null;
61
+ },
62
+ onReject,
63
+ rejectInErrorPhaseOnly,
64
+ timeoutMs
65
+ });
66
+ }
67
+ function waitForAuthStateChange({
68
+ stateManager,
69
+ resolvePhases,
70
+ rejectPhases,
71
+ onReject,
72
+ waitForCoreAuthenticated = true,
73
+ rejectInErrorPhaseOnly,
74
+ timeoutMs
75
+ }) {
76
+ return createStateListener({
77
+ stateManager,
78
+ shouldResolve: (state) => {
79
+ const matchedPhase = resolvePhases.find((p) => p.phase === state.authStatePhase);
80
+ if (matchedPhase) {
81
+ if (matchedPhase.phase === "authenticated") {
82
+ if (!waitForCoreAuthenticated || waitForCoreAuthenticated && state.phase === "authenticated") {
83
+ return matchedPhase.onPhase(state);
84
+ }
85
+ return null;
86
+ }
87
+ return matchedPhase.onPhase(state);
88
+ }
89
+ return null;
90
+ },
91
+ shouldReject: (state) => {
92
+ const matchedPhase = rejectPhases == null ? void 0 : rejectPhases.find((p) => p.phase === state.authStatePhase);
93
+ if (matchedPhase) {
94
+ return matchedPhase.onPhase(state);
95
+ }
96
+ return null;
97
+ },
98
+ onReject,
99
+ rejectInErrorPhaseOnly,
100
+ timeoutMs
101
+ });
102
+ }
103
+ export {
104
+ waitForAuthStateChange,
105
+ waitForCoreStateChange
106
+ };