@getpara/core-sdk 2.0.0-alpha.52 → 2.0.0-alpha.54

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 (65) hide show
  1. package/dist/cjs/ParaCore.js +280 -69
  2. package/dist/cjs/constants.js +7 -1
  3. package/dist/cjs/index.js +8 -2
  4. package/dist/cjs/shares/enclave.js +266 -0
  5. package/dist/cjs/shares/shareDistribution.js +16 -1
  6. package/dist/cjs/types/{theme.js → assets.js} +2 -2
  7. package/dist/cjs/types/events.js +2 -0
  8. package/dist/cjs/types/index.js +0 -21
  9. package/dist/cjs/utils/formatting.js +41 -0
  10. package/dist/cjs/utils/onRamps.js +2 -3
  11. package/dist/cjs/utils/wallet.js +3 -0
  12. package/dist/esm/ParaCore.js +282 -72
  13. package/dist/esm/{chunk-7B52C2XE.js → chunk-W5CT3TVS.js} +2 -0
  14. package/dist/esm/constants.js +6 -2
  15. package/dist/esm/cryptography/utils.js +1 -1
  16. package/dist/esm/errors.js +1 -1
  17. package/dist/esm/external/mpcComputationClient.js +1 -1
  18. package/dist/esm/external/userManagementClient.js +1 -1
  19. package/dist/esm/index.js +9 -4
  20. package/dist/esm/shares/KeyContainer.js +1 -1
  21. package/dist/esm/shares/enclave.js +226 -0
  22. package/dist/esm/shares/recovery.js +1 -1
  23. package/dist/esm/shares/shareDistribution.js +17 -2
  24. package/dist/esm/transmission/transmissionUtils.js +1 -1
  25. package/dist/esm/types/auth.js +1 -1
  26. package/dist/esm/types/config.js +1 -1
  27. package/dist/esm/types/coreApi.js +1 -1
  28. package/dist/esm/types/events.js +3 -1
  29. package/dist/esm/types/index.js +0 -16
  30. package/dist/esm/types/popup.js +1 -1
  31. package/dist/esm/types/wallet.js +1 -1
  32. package/dist/esm/utils/autobind.js +1 -1
  33. package/dist/esm/utils/events.js +1 -1
  34. package/dist/esm/utils/formatting.js +41 -1
  35. package/dist/esm/utils/json.js +1 -1
  36. package/dist/esm/utils/listeners.js +1 -1
  37. package/dist/esm/utils/onRamps.js +3 -4
  38. package/dist/esm/utils/phone.js +1 -1
  39. package/dist/esm/utils/polling.js +1 -1
  40. package/dist/esm/utils/types.js +1 -1
  41. package/dist/esm/utils/url.js +1 -1
  42. package/dist/esm/utils/wallet.js +4 -1
  43. package/dist/types/ParaCore.d.ts +27 -3
  44. package/dist/types/constants.d.ts +2 -0
  45. package/dist/types/index.d.ts +4 -3
  46. package/dist/types/shares/enclave.d.ts +81 -0
  47. package/dist/types/shares/shareDistribution.d.ts +4 -2
  48. package/dist/types/types/assets.d.ts +14 -0
  49. package/dist/types/types/config.d.ts +3 -2
  50. package/dist/types/types/coreApi.d.ts +1 -0
  51. package/dist/types/types/events.d.ts +7 -2
  52. package/dist/types/types/index.d.ts +0 -4
  53. package/dist/types/types/methods.d.ts +15 -9
  54. package/dist/types/types/wallet.d.ts +3 -3
  55. package/dist/types/utils/formatting.d.ts +10 -1
  56. package/dist/types/utils/onRamps.d.ts +9 -10
  57. package/package.json +3 -3
  58. package/dist/cjs/types/onRamps.js +0 -33
  59. package/dist/cjs/types/recovery.js +0 -34
  60. package/dist/esm/types/onRamps.js +0 -11
  61. package/dist/esm/types/recovery.js +0 -12
  62. package/dist/types/types/onRamps.d.ts +0 -10
  63. package/dist/types/types/recovery.d.ts +0 -7
  64. package/dist/types/types/theme.d.ts +0 -12
  65. /package/dist/esm/types/{theme.js → assets.js} +0 -0
@@ -99,7 +99,8 @@ var import_recovery = require("./shares/recovery.js");
99
99
  var import_utils2 = require("./utils/index.js");
100
100
  var import_errors = require("./errors.js");
101
101
  var constants = __toESM(require("./constants.js"));
102
- var _authInfo, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, assertIsLinkingAccount_fn, assertIsLinkingAccountOrStart_fn, getOAuthUrl_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareLoginState_fn, prepareSignUpState_fn;
102
+ var import_enclave = require("./shares/enclave.js");
103
+ var _authInfo, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, assertIsLinkingAccount_fn, assertIsLinkingAccountOrStart_fn, getOAuthUrl_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareDoneState_fn, prepareVerificationState_fn, prepareLoginState_fn, prepareSignUpState_fn;
103
104
  if (typeof global !== "undefined") {
104
105
  global.Buffer = global.Buffer || import_buffer.Buffer;
105
106
  } else if (typeof window !== "undefined") {
@@ -113,10 +114,12 @@ const { pki, jsbn } = import_node_forge.default;
113
114
  const _ParaCore = class _ParaCore {
114
115
  constructor(envOrApiKey, apiKeyOrOpts, opts) {
115
116
  __privateAdd(this, _ParaCore_instances);
117
+ this.popupWindow = null;
116
118
  __privateAdd(this, _authInfo);
117
119
  this.isNativePasskey = false;
118
120
  this.isReady = false;
119
121
  this.accountLinkInProgress = void 0;
122
+ this.isEnclaveUser = false;
120
123
  this.isAwaitingAccountCreation = false;
121
124
  this.isAwaitingLogin = false;
122
125
  this.isAwaitingFarcaster = false;
@@ -152,6 +155,12 @@ const _ParaCore = class _ParaCore {
152
155
  this.retrieveSessionCookie = () => {
153
156
  return this.sessionCookie;
154
157
  };
158
+ this.retrieveEnclaveJwt = () => {
159
+ return this.enclaveJwt;
160
+ };
161
+ this.retrieveEnclaveRefreshJwt = () => {
162
+ return this.enclaveRefreshJwt;
163
+ };
155
164
  /**
156
165
  * Remove all local storage and prefixed session storage.
157
166
  * @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
@@ -210,6 +219,7 @@ const _ParaCore = class _ParaCore {
210
219
  this.updateWalletIdsFromStorage();
211
220
  this.updateSessionCookieFromStorage();
212
221
  this.updateLoginEncryptionKeyPairFromStorage();
222
+ this.updateEnclaveJwtFromStorage();
213
223
  };
214
224
  this.updateAuthInfoFromStorage = () => {
215
225
  var _a;
@@ -229,6 +239,10 @@ const _ParaCore = class _ParaCore {
229
239
  }
230
240
  __privateSet(this, _authInfo, authInfo);
231
241
  };
242
+ this.updateEnclaveJwtFromStorage = () => {
243
+ this.enclaveJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || void 0;
244
+ this.enclaveRefreshJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || void 0;
245
+ };
232
246
  this.updateUserIdFromStorage = () => {
233
247
  this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
234
248
  };
@@ -380,18 +394,41 @@ const _ParaCore = class _ParaCore {
380
394
  cookie
381
395
  );
382
396
  };
397
+ this.persistEnclaveJwt = (jwt) => {
398
+ this.enclaveJwt = jwt;
399
+ (opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
400
+ constants.LOCAL_STORAGE_ENCLAVE_JWT,
401
+ jwt
402
+ );
403
+ };
404
+ this.persistEnclaveRefreshJwt = (refreshJwt) => {
405
+ this.enclaveRefreshJwt = refreshJwt;
406
+ (opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
407
+ constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
408
+ refreshJwt
409
+ );
410
+ };
411
+ const client = (0, import_userManagementClient.initClient)({
412
+ env,
413
+ version: _ParaCore.version,
414
+ apiKey,
415
+ partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
416
+ useFetchAdapter: !!opts.disableWorkers,
417
+ retrieveSessionCookie: this.retrieveSessionCookie,
418
+ persistSessionCookie: this.persistSessionCookie
419
+ });
420
+ const enclaveClient = new import_enclave.EnclaveClient({
421
+ userManagementClient: client,
422
+ retrieveJwt: this.retrieveEnclaveJwt,
423
+ persistJwt: this.persistEnclaveJwt,
424
+ retrieveRefreshJwt: this.retrieveEnclaveRefreshJwt,
425
+ persistRefreshJwt: this.persistEnclaveRefreshJwt
426
+ });
383
427
  this.ctx = {
384
428
  env,
385
429
  apiKey,
386
- client: (0, import_userManagementClient.initClient)({
387
- env,
388
- version: _ParaCore.version,
389
- apiKey,
390
- partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
391
- useFetchAdapter: !!opts.disableWorkers,
392
- retrieveSessionCookie: this.retrieveSessionCookie,
393
- persistSessionCookie: this.persistSessionCookie
394
- }),
430
+ client,
431
+ enclaveClient,
395
432
  disableWorkers: opts.disableWorkers,
396
433
  offloadMPCComputationURL: opts.offloadMPCComputationURL,
397
434
  useLocalFiles: opts.useLocalFiles,
@@ -426,6 +463,9 @@ const _ParaCore = class _ParaCore {
426
463
  ]);
427
464
  }
428
465
  }
466
+ setModalError(_error) {
467
+ return;
468
+ }
429
469
  get authInfo() {
430
470
  return __privateGet(this, _authInfo);
431
471
  }
@@ -710,23 +750,30 @@ const _ParaCore = class _ParaCore {
710
750
  constructPortalUrl(_0) {
711
751
  return __async(this, arguments, function* (type, opts = {}) {
712
752
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
713
- const [isCreate, isLogin, isOnRamp] = [
753
+ const [isCreate, isLogin, isOnRamp, isOAuth, isOAuthCallback, isTelegramLogin, isFarcasterLogin] = [
714
754
  ["createAuth", "createPassword", "createPIN"].includes(type),
715
- ["loginAuth", "loginPassword", "loginPIN"].includes(type),
716
- type === "onRamp"
755
+ ["loginAuth", "loginPassword", "loginPIN", "loginOTP"].includes(type),
756
+ type === "onRamp",
757
+ type === "oAuth",
758
+ type === "oAuthCallback",
759
+ ["telegramLogin", "telegramLoginVerify"].includes(type),
760
+ type === "loginFarcaster"
717
761
  ];
762
+ if (isOAuth && !opts.oAuthMethod) {
763
+ throw new Error("oAuthMethod is required for oAuth portal URLs");
764
+ }
718
765
  if (isCreate || isLogin) {
719
766
  this.assertIsAuthSet();
720
767
  }
721
768
  let sessionId = opts.sessionId;
722
- if ((isLogin || isOnRamp) && !sessionId) {
769
+ if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin) && !sessionId) {
723
770
  const session = yield this.touchSession(true);
724
771
  sessionId = session.sessionId;
725
772
  }
726
773
  if (!this.loginEncryptionKeyPair) {
727
774
  yield this.setLoginEncryptionKeyPair();
728
775
  }
729
- const base = type === "onRamp" || type === "telegramLogin" ? (0, import_utils2.getPortalBaseURL)(this.ctx, type === "telegramLogin") : yield this.getPortalURL();
776
+ const base = type === "onRamp" || isTelegramLogin ? (0, import_utils2.getPortalBaseURL)(this.ctx, isTelegramLogin) : yield this.getPortalURL();
730
777
  let path;
731
778
  switch (type) {
732
779
  case "createPassword": {
@@ -761,10 +808,30 @@ const _ParaCore = class _ParaCore {
761
808
  path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
762
809
  break;
763
810
  }
811
+ case "telegramLoginVerify": {
812
+ path = `/auth/telegram/verify`;
813
+ break;
814
+ }
764
815
  case "telegramLogin": {
765
816
  path = `/auth/telegram`;
766
817
  break;
767
818
  }
819
+ case "oAuth": {
820
+ path = `/auth/${opts.oAuthMethod.toLowerCase()}`;
821
+ break;
822
+ }
823
+ case "oAuthCallback": {
824
+ path = `/auth/${opts.oAuthMethod.toLowerCase()}/callback`;
825
+ break;
826
+ }
827
+ case "loginOTP": {
828
+ path = "/auth/otp";
829
+ break;
830
+ }
831
+ case "loginFarcaster": {
832
+ path = "/auth/farcaster";
833
+ break;
834
+ }
768
835
  default: {
769
836
  throw new Error(`invalid URL type ${type}`);
770
837
  }
@@ -783,7 +850,7 @@ const _ParaCore = class _ParaCore {
783
850
  encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
784
851
  sessionId
785
852
  };
786
- const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
853
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
787
854
  apiKey: this.ctx.apiKey,
788
855
  partnerId: partner == null ? void 0 : partner.id,
789
856
  portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
@@ -801,7 +868,7 @@ const _ParaCore = class _ParaCore {
801
868
  }, (0, import_user_management_client.isPhone)(this.authInfo.auth) ? (0, import_utils2.splitPhoneNumber)(this.authInfo.auth.phone) : this.authInfo.auth), {
802
869
  pfpUrl: this.authInfo.pfpUrl,
803
870
  displayName: this.authInfo.displayName
804
- }) : {}), isOnRamp ? { origin: typeof window !== "undefined" ? window.location.origin : void 0, email: this.email } : {}), isLogin ? __spreadProps(__spreadValues({
871
+ }) : {}), isOnRamp ? { origin: typeof window !== "undefined" ? window.location.origin : void 0, email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin ? __spreadProps(__spreadValues({
805
872
  sessionId: thisDevice.sessionId,
806
873
  encryptionKey: thisDevice.encryptionKey
807
874
  }, opts.newDevice ? {
@@ -809,7 +876,9 @@ const _ParaCore = class _ParaCore {
809
876
  newDeviceEncryptionKey: opts.newDevice.encryptionKey
810
877
  } : {}), {
811
878
  pregenIds: JSON.stringify(this.pregenIds)
812
- }) : {}), type === "telegramLogin" ? { isEmbed: "true" } : {}), opts.params || {});
879
+ }) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
880
+ appScheme: opts.appScheme
881
+ } : {}), isTelegramLogin ? { isEmbed: "true" } : {}), opts.params || {});
813
882
  const url = (0, import_utils2.constructUrl)({ base, path, params });
814
883
  if (opts.shorten) {
815
884
  return (0, import_utils2.shortenUrl)(this.ctx, url);
@@ -838,16 +907,25 @@ const _ParaCore = class _ParaCore {
838
907
  }
839
908
  touchSession(regenerate = false) {
840
909
  return __async(this, null, function* () {
841
- var _a, _b, _c, _d;
910
+ var _a, _b, _c, _d, _e;
842
911
  if (!this.isWorkerInitialized) {
843
912
  this.initializeWorker();
844
913
  }
845
914
  if (!this.isReady) {
846
915
  yield this.ready();
847
916
  }
848
- const session = yield this.ctx.client.touchSession(regenerate);
917
+ let session;
918
+ try {
919
+ session = yield this.ctx.client.touchSession(regenerate);
920
+ } catch (error) {
921
+ this.handleTouchSessionError(error);
922
+ throw error;
923
+ }
849
924
  if (!this.partner || ((_a = this.partner) == null ? void 0 : _a.id) !== session.partnerId || !(0, import_utils2.supportedWalletTypesEq)(((_b = this.partner) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = this.partner) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
850
925
  if (!session.partnerId) {
926
+ this.displayModalError(
927
+ `Invalid API Key. Please ensure you have a valid API key for the current environment: ${(_d = this.ctx.env) == null ? void 0 : _d.toUpperCase()}.`
928
+ );
851
929
  console.error(`
852
930
  \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
853
931
  \u{1F6A8} PARA SDK CONFIGURATION ERROR \u{1F6A8}
@@ -865,11 +943,12 @@ SOLUTION:
865
943
  \u2022 If your API key doesn't contain an environment prefix, ensure your API key is the correct key for your target environment
866
944
 
867
945
  Current Environment: ${this.ctx.env}
868
- API Key Prefix: ${((_d = this.ctx.apiKey) == null ? void 0 : _d.split("_")[0].toUpperCase()) || "None"}
946
+ API Key Prefix: ${((_e = this.ctx.apiKey) == null ? void 0 : _e.split("_")[0].toUpperCase()) || "None"}
869
947
 
870
948
  Need help? Visit: https://docs.getpara.com or contact support
871
949
  \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
872
950
  `);
951
+ throw new Error("Invalid API Key.");
873
952
  } else {
874
953
  yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
875
954
  }
@@ -971,6 +1050,33 @@ Need help? Visit: https://docs.getpara.com or contact support
971
1050
  return __privateGet(this, _authInfo);
972
1051
  });
973
1052
  }
1053
+ /**
1054
+ * Display an error message in the modal (if available)
1055
+ * @internal
1056
+ */
1057
+ displayModalError(error) {
1058
+ if (this.ctx.env !== import_types.Environment.PROD) {
1059
+ this.setModalError(error);
1060
+ }
1061
+ }
1062
+ /**
1063
+ * Handle specific touchSession errors with user-friendly messages
1064
+ * @private
1065
+ */
1066
+ handleTouchSessionError(error) {
1067
+ const errorStr = String(error);
1068
+ const errorMessage = error instanceof Error ? error.message : "";
1069
+ if (errorStr.includes("blocked by CORS policy") && errorStr.includes("Access-Control-Allow-Origin")) {
1070
+ this.displayModalError("Request rate limit reached. Please wait a couple of minutes and try again.");
1071
+ return;
1072
+ }
1073
+ if (error.status === 403 && errorMessage.includes("origin not authorized")) {
1074
+ this.displayModalError(
1075
+ "The current origin is not allowed. Update your allowed origins in the Para developer portal to allow the current origin."
1076
+ );
1077
+ return;
1078
+ }
1079
+ }
974
1080
  assertUserId({ allowGuestMode = false } = {}) {
975
1081
  if (!this.userId || !allowGuestMode && this.isGuestMode) {
976
1082
  throw new Error("no userId is set");
@@ -1512,6 +1618,7 @@ Need help? Visit: https://docs.getpara.com or contact support
1512
1618
  return accounts;
1513
1619
  });
1514
1620
  }
1621
+ // TELEGRAM
1515
1622
  /**
1516
1623
  * Validates the response received from an attempted Telegram login for authenticity, then
1517
1624
  * creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
@@ -1521,19 +1628,28 @@ Need help? Visit: https://docs.getpara.com or contact support
1521
1628
  verifyTelegramProcess(_e) {
1522
1629
  return __async(this, null, function* () {
1523
1630
  var _f = _e, {
1631
+ serverAuthState: optsServerAuthState,
1524
1632
  telegramAuthResponse,
1525
1633
  isLinkAccount
1526
1634
  } = _f, urlOptions = __objRest(_f, [
1635
+ "serverAuthState",
1527
1636
  "telegramAuthResponse",
1528
1637
  "isLinkAccount"
1529
1638
  ]);
1530
1639
  try {
1531
1640
  switch (isLinkAccount) {
1532
1641
  case false: {
1533
- const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
1534
- return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1642
+ if (!optsServerAuthState && !telegramAuthResponse) {
1643
+ throw new Error("one of serverAuthState or telegramAuthResponse are required for verifying telegram");
1644
+ }
1645
+ const serverAuthState = optsServerAuthState != null ? optsServerAuthState : yield this.ctx.client.verifyTelegram({ authObject: telegramAuthResponse });
1646
+ const { sessionLookupId } = yield this.touchSession();
1647
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
1535
1648
  }
1536
1649
  case true: {
1650
+ if (!telegramAuthResponse) {
1651
+ throw new Error("telegramAuthResponse is required for verifying telegram link");
1652
+ }
1537
1653
  const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
1538
1654
  const accounts = yield this.verifyLink({
1539
1655
  accountLinkInProgress,
@@ -1543,7 +1659,8 @@ Need help? Visit: https://docs.getpara.com or contact support
1543
1659
  }
1544
1660
  }
1545
1661
  } catch (e) {
1546
- throw new Error(e.message);
1662
+ const errorMessage = e instanceof Error ? e.message : e ? String(e) : "Unknown error occurred";
1663
+ throw new Error(errorMessage);
1547
1664
  }
1548
1665
  });
1549
1666
  }
@@ -1788,6 +1905,7 @@ Need help? Visit: https://docs.getpara.com or contact support
1788
1905
  return connectUri;
1789
1906
  });
1790
1907
  }
1908
+ // FARCASTER
1791
1909
  /**
1792
1910
  * Awaits the response from a user's attempt to log in with Farcaster.
1793
1911
  * If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
@@ -1800,14 +1918,20 @@ Need help? Visit: https://docs.getpara.com or contact support
1800
1918
  onConnectUri,
1801
1919
  onCancel,
1802
1920
  onPoll,
1803
- isLinkAccount
1921
+ isLinkAccount,
1922
+ serverAuthState: optsServerAuthState
1804
1923
  } = _h, urlOptions = __objRest(_h, [
1805
1924
  "isCanceled",
1806
1925
  "onConnectUri",
1807
1926
  "onCancel",
1808
1927
  "onPoll",
1809
- "isLinkAccount"
1928
+ "isLinkAccount",
1929
+ "serverAuthState"
1810
1930
  ]);
1931
+ if (optsServerAuthState) {
1932
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, optsServerAuthState, urlOptions);
1933
+ return authState;
1934
+ }
1811
1935
  let accountLinkInProgress;
1812
1936
  if (isLinkAccount) {
1813
1937
  accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
@@ -1903,10 +2027,9 @@ Need help? Visit: https://docs.getpara.com or contact support
1903
2027
  "onOAuthPopup",
1904
2028
  "isLinkAccount"
1905
2029
  ]);
1906
- let popupWindow;
1907
2030
  if (onOAuthPopup) {
1908
2031
  try {
1909
- popupWindow = yield this.platformUtils.openPopup("about:blank", { type: import_types.PopupType.OAUTH });
2032
+ this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: import_types.PopupType.OAUTH });
1910
2033
  } catch (error) {
1911
2034
  throw new Error(`Failed to open OAuth popup: ${error}`);
1912
2035
  }
@@ -1925,9 +2048,9 @@ Need help? Visit: https://docs.getpara.com or contact support
1925
2048
  onOAuthUrl(oAuthUrl);
1926
2049
  break;
1927
2050
  }
1928
- case (!!onOAuthPopup && !!popupWindow): {
1929
- popupWindow.location.href = oAuthUrl;
1930
- onOAuthPopup(popupWindow);
2051
+ case (!!onOAuthPopup && !!this.popupWindow): {
2052
+ this.popupWindow.location.href = oAuthUrl;
2053
+ onOAuthPopup(this.popupWindow);
1931
2054
  break;
1932
2055
  }
1933
2056
  }
@@ -2157,7 +2280,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2157
2280
  userId: this.userId,
2158
2281
  walletId,
2159
2282
  userShare: userSigner,
2160
- emailProps: this.getBackupKitEmailProps()
2283
+ emailProps: this.getBackupKitEmailProps(),
2284
+ isEnclaveUser: this.isEnclaveUser,
2285
+ walletScheme: this.wallets[walletId].scheme
2161
2286
  });
2162
2287
  return recoveryShare;
2163
2288
  });
@@ -2285,7 +2410,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2285
2410
  ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
2286
2411
  emailProps: this.getBackupKitEmailProps(),
2287
2412
  partnerId: newPartnerId,
2288
- protocolId
2413
+ protocolId,
2414
+ isEnclaveUser: this.isEnclaveUser,
2415
+ walletScheme: this.wallets[walletId].scheme
2289
2416
  });
2290
2417
  return { signer, recoverySecret, protocolId };
2291
2418
  });
@@ -2351,7 +2478,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2351
2478
  userId: this.userId,
2352
2479
  walletId: wallet.id,
2353
2480
  userShare: signer,
2354
- emailProps: this.getBackupKitEmailProps()
2481
+ emailProps: this.getBackupKitEmailProps(),
2482
+ isEnclaveUser: this.isEnclaveUser,
2483
+ walletScheme: wallet.scheme
2355
2484
  });
2356
2485
  }
2357
2486
  yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
@@ -2432,7 +2561,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2432
2561
  walletId: wallet.id,
2433
2562
  userShare: this.wallets[wallet.id].signer,
2434
2563
  emailProps: this.getBackupKitEmailProps(),
2435
- partnerId: wallet.partnerId
2564
+ partnerId: wallet.partnerId,
2565
+ isEnclaveUser: this.isEnclaveUser,
2566
+ walletScheme: wallet.scheme
2436
2567
  });
2437
2568
  if (distributeRes.length > 0) {
2438
2569
  newRecoverySecret = distributeRes;
@@ -2923,8 +3054,16 @@ Need help? Visit: https://docs.getpara.com or contact support
2923
3054
  }
2924
3055
  issueJwt() {
2925
3056
  return __async(this, arguments, function* ({ keyIndex = 0 } = {}) {
2926
- const res = yield this.ctx.client.issueJwt({ keyIndex });
2927
- return res;
3057
+ try {
3058
+ return yield this.ctx.client.issueJwt({ keyIndex });
3059
+ } catch (error) {
3060
+ if (error.status === 403 || error.status === 401) {
3061
+ const errorMessage = "The user needs to be logged in to issue a JWT. Please log in and try again.";
3062
+ this.displayModalError(errorMessage);
3063
+ console.warn(errorMessage);
3064
+ }
3065
+ throw error;
3066
+ }
2928
3067
  });
2929
3068
  }
2930
3069
  /**
@@ -3032,7 +3171,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3032
3171
  ({
3033
3172
  data: { id: credentialId }
3034
3173
  } = yield this.ctx.client.addSessionPublicKey(this.userId, {
3035
- status: import_user_management_client.PublicKeyStatus.PENDING,
3174
+ status: import_user_management_client.AuthMethodStatus.PENDING,
3036
3175
  type: import_user_management_client.PublicKeyType.WEB
3037
3176
  }));
3038
3177
  urlType = "createAuth";
@@ -3041,7 +3180,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3041
3180
  ({
3042
3181
  data: { id: credentialId }
3043
3182
  } = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
3044
- status: import_user_management_client.PasswordStatus.PENDING
3183
+ status: import_user_management_client.AuthMethodStatus.PENDING
3045
3184
  }));
3046
3185
  urlType = "createPassword";
3047
3186
  break;
@@ -3049,7 +3188,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3049
3188
  ({
3050
3189
  data: { id: credentialId }
3051
3190
  } = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
3052
- status: import_user_management_client.PasswordStatus.PENDING
3191
+ status: import_user_management_client.AuthMethodStatus.PENDING
3053
3192
  }));
3054
3193
  urlType = "createPIN";
3055
3194
  break;
@@ -3064,7 +3203,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3064
3203
  });
3065
3204
  }
3066
3205
  /**
3067
- * Returns a Para Portal URL for logging in with a WebAuth passkey, password or PIN.
3206
+ * Returns a Para Portal URL for logging in with a WebAuth passkey, password, PIN or OTP.
3068
3207
  * @param {Object} opts the options object
3069
3208
  * @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
3070
3209
  * @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
@@ -3093,6 +3232,9 @@ Need help? Visit: https://docs.getpara.com or contact support
3093
3232
  case "PIN":
3094
3233
  urlType = "loginPIN";
3095
3234
  break;
3235
+ case "BASIC_LOGIN":
3236
+ urlType = "loginOTP";
3237
+ break;
3096
3238
  default:
3097
3239
  throw new Error(`invalid authentication method: '${authMethod}'`);
3098
3240
  }
@@ -3116,7 +3258,17 @@ Need help? Visit: https://docs.getpara.com or contact support
3116
3258
  signUpOrLogIn(_k) {
3117
3259
  return __async(this, null, function* () {
3118
3260
  var _l = _k, { auth } = _l, urlOptions = __objRest(_l, ["auth"]);
3119
- const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
3261
+ let serverAuthState;
3262
+ try {
3263
+ serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
3264
+ } catch (error) {
3265
+ if (error.message.includes("max beta users reached")) {
3266
+ this.displayModalError(
3267
+ `50 user limit reached. [Go to Production.](https://docs.getpara.com/v2/general/checklist#go-live-checklist)`
3268
+ );
3269
+ }
3270
+ throw error;
3271
+ }
3120
3272
  const authInfo = serverAuthState.auth;
3121
3273
  if (this.fetchPregenWalletsOverride && (0, import_user_management_client.isPregenAuth)(authInfo)) {
3122
3274
  const { userShare } = yield this.fetchPregenWalletsOverride({ pregenId: authInfo });
@@ -3124,7 +3276,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3124
3276
  yield this.setUserShare(userShare);
3125
3277
  }
3126
3278
  }
3127
- return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
3279
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadValues({}, urlOptions));
3128
3280
  });
3129
3281
  }
3130
3282
  verifyNewAccount(_m) {
@@ -3139,7 +3291,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3139
3291
  const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
3140
3292
  verificationCode
3141
3293
  });
3142
- if (serverAuthState.stage === "login") {
3294
+ if (serverAuthState.stage === "login" || serverAuthState.stage === "done") {
3143
3295
  throw new Error("Account already exists.");
3144
3296
  }
3145
3297
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
@@ -3260,6 +3412,16 @@ Need help? Visit: https://docs.getpara.com or contact support
3260
3412
  return accounts;
3261
3413
  });
3262
3414
  }
3415
+ getProfileBalance() {
3416
+ return __async(this, arguments, function* ({ config, refetch = false } = {}) {
3417
+ const { balance } = yield this.ctx.client.getProfileBalance({
3418
+ config,
3419
+ wallets: this.availableWallets.map(({ type, address }) => ({ type, address })),
3420
+ refetch
3421
+ });
3422
+ return balance;
3423
+ });
3424
+ }
3263
3425
  sendLoginCode() {
3264
3426
  return __async(this, null, function* () {
3265
3427
  const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
@@ -3373,30 +3535,43 @@ assertIsLinkingAccountOrStart_fn = function(type) {
3373
3535
  return yield this.linkAccount({ type });
3374
3536
  });
3375
3537
  };
3376
- /**
3377
- * Generates a URL for the user to log in with OAuth using a desire method.
3378
- *
3379
- * @param {Object} opts the options object
3380
- * @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
3381
- * @param {string} [opts.appScheme] the app scheme to redirect to after the OAuth flow. This is for mobile only.
3382
- * @returns {string} the URL for the user to log in with OAuth.
3383
- */
3384
- getOAuthUrl_fn = function({
3385
- method,
3386
- appScheme,
3387
- accountLinkInProgress,
3388
- sessionLookupId
3389
- }) {
3390
- return (0, import_utils2.constructUrl)({
3391
- base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
3392
- path: `/auth/${method}`,
3393
- params: __spreadValues({
3394
- apiKey: this.ctx.apiKey,
3395
- sessionLookupId,
3396
- appScheme
3397
- }, accountLinkInProgress ? {
3398
- linkedAccountId: this.accountLinkInProgress.id
3399
- } : {})
3538
+ getOAuthUrl_fn = function(_0) {
3539
+ return __async(this, arguments, function* ({
3540
+ method,
3541
+ appScheme,
3542
+ accountLinkInProgress,
3543
+ sessionLookupId,
3544
+ encryptionKey
3545
+ }) {
3546
+ if (!accountLinkInProgress && !this.isPortal()) {
3547
+ return yield this.constructPortalUrl("oAuth", { sessionId: sessionLookupId, oAuthMethod: method, appScheme });
3548
+ }
3549
+ let portalSessionLookupId;
3550
+ if (this.isPortal()) {
3551
+ portalSessionLookupId = (yield this.touchSession(true)).sessionLookupId;
3552
+ }
3553
+ return (0, import_utils2.constructUrl)({
3554
+ base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
3555
+ path: `/auth/${method.toLowerCase()}`,
3556
+ params: __spreadProps(__spreadValues({
3557
+ apiKey: this.ctx.apiKey,
3558
+ sessionLookupId,
3559
+ portalSessionLookupId,
3560
+ appScheme
3561
+ }, accountLinkInProgress ? {
3562
+ linkedAccountId: this.accountLinkInProgress.id
3563
+ } : {}), {
3564
+ callback: !accountLinkInProgress && (yield this.constructPortalUrl("oAuthCallback", {
3565
+ sessionId: sessionLookupId,
3566
+ oAuthMethod: method,
3567
+ appScheme,
3568
+ thisDevice: {
3569
+ sessionId: sessionLookupId,
3570
+ encryptionKey
3571
+ }
3572
+ }))
3573
+ })
3574
+ });
3400
3575
  });
3401
3576
  };
3402
3577
  createPregenWallet_fn = function(opts) {
@@ -3472,8 +3647,14 @@ prepareAuthState_fn = function(_0) {
3472
3647
  }
3473
3648
  let authState;
3474
3649
  switch (serverAuthState.stage) {
3650
+ case "done": {
3651
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareDoneState_fn).call(this, serverAuthState);
3652
+ break;
3653
+ }
3475
3654
  case "verify":
3476
- authState = serverAuthState;
3655
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareVerificationState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), {
3656
+ sessionLookupId: opts.sessionLookupId
3657
+ }));
3477
3658
  break;
3478
3659
  case "login":
3479
3660
  if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
@@ -3493,6 +3674,36 @@ prepareAuthState_fn = function(_0) {
3493
3674
  return authState;
3494
3675
  });
3495
3676
  };
3677
+ prepareDoneState_fn = function(doneState) {
3678
+ return __async(this, null, function* () {
3679
+ let isSLOPossible = doneState.authMethods.includes(import_user_management_client.AuthMethod.BASIC_LOGIN);
3680
+ this.isEnclaveUser = isSLOPossible;
3681
+ return doneState;
3682
+ });
3683
+ };
3684
+ prepareVerificationState_fn = function(_0, _1) {
3685
+ return __async(this, arguments, function* (verifyState, {
3686
+ useShortUrls: shorten = false,
3687
+ portalTheme,
3688
+ sessionLookupId
3689
+ }) {
3690
+ let isSLOPossible = false;
3691
+ if (verifyState.nextStage === "login") {
3692
+ isSLOPossible = verifyState.loginAuthMethods.includes(import_user_management_client.AuthMethod.BASIC_LOGIN);
3693
+ } else if (verifyState.nextStage === "signup") {
3694
+ isSLOPossible = verifyState.signupAuthMethods.includes(import_user_management_client.AuthMethod.BASIC_LOGIN);
3695
+ }
3696
+ this.isEnclaveUser = isSLOPossible;
3697
+ return __spreadValues(__spreadValues({}, verifyState), isSLOPossible ? {
3698
+ loginUrl: yield this.getLoginUrl({
3699
+ authMethod: import_user_management_client.AuthMethod.BASIC_LOGIN,
3700
+ sessionId: sessionLookupId,
3701
+ shorten,
3702
+ portalTheme
3703
+ })
3704
+ } : {});
3705
+ });
3706
+ };
3496
3707
  prepareLoginState_fn = function(_0, _1) {
3497
3708
  return __async(this, arguments, function* (loginState, {
3498
3709
  useShortUrls: shorten = false,