@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
@@ -7,8 +7,8 @@ import {
7
7
  __privateSet,
8
8
  __spreadProps,
9
9
  __spreadValues
10
- } from "./chunk-7B52C2XE.js";
11
- 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;
10
+ } from "./chunk-W5CT3TVS.js";
11
+ 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;
12
12
  import { Buffer as NodeBuffer } from "buffer";
13
13
  if (typeof global !== "undefined") {
14
14
  global.Buffer = global.Buffer || NodeBuffer;
@@ -21,9 +21,8 @@ if (typeof global !== "undefined") {
21
21
  }
22
22
  import {
23
23
  AuthMethod,
24
- PublicKeyStatus,
24
+ AuthMethodStatus,
25
25
  PublicKeyType,
26
- PasswordStatus,
27
26
  extractAuthInfo,
28
27
  isEmail,
29
28
  isPhone,
@@ -75,13 +74,16 @@ import {
75
74
  } from "./utils/index.js";
76
75
  import { TransactionReviewDenied, TransactionReviewTimeout } from "./errors.js";
77
76
  import * as constants from "./constants.js";
77
+ import { EnclaveClient } from "./shares/enclave.js";
78
78
  const _ParaCore = class _ParaCore {
79
79
  constructor(envOrApiKey, apiKeyOrOpts, opts) {
80
80
  __privateAdd(this, _ParaCore_instances);
81
+ this.popupWindow = null;
81
82
  __privateAdd(this, _authInfo);
82
83
  this.isNativePasskey = false;
83
84
  this.isReady = false;
84
85
  this.accountLinkInProgress = void 0;
86
+ this.isEnclaveUser = false;
85
87
  this.isAwaitingAccountCreation = false;
86
88
  this.isAwaitingLogin = false;
87
89
  this.isAwaitingFarcaster = false;
@@ -117,6 +119,12 @@ const _ParaCore = class _ParaCore {
117
119
  this.retrieveSessionCookie = () => {
118
120
  return this.sessionCookie;
119
121
  };
122
+ this.retrieveEnclaveJwt = () => {
123
+ return this.enclaveJwt;
124
+ };
125
+ this.retrieveEnclaveRefreshJwt = () => {
126
+ return this.enclaveRefreshJwt;
127
+ };
120
128
  /**
121
129
  * Remove all local storage and prefixed session storage.
122
130
  * @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
@@ -175,6 +183,7 @@ const _ParaCore = class _ParaCore {
175
183
  this.updateWalletIdsFromStorage();
176
184
  this.updateSessionCookieFromStorage();
177
185
  this.updateLoginEncryptionKeyPairFromStorage();
186
+ this.updateEnclaveJwtFromStorage();
178
187
  };
179
188
  this.updateAuthInfoFromStorage = () => {
180
189
  var _a;
@@ -194,6 +203,10 @@ const _ParaCore = class _ParaCore {
194
203
  }
195
204
  __privateSet(this, _authInfo, authInfo);
196
205
  };
206
+ this.updateEnclaveJwtFromStorage = () => {
207
+ this.enclaveJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || void 0;
208
+ this.enclaveRefreshJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || void 0;
209
+ };
197
210
  this.updateUserIdFromStorage = () => {
198
211
  this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
199
212
  };
@@ -345,18 +358,41 @@ const _ParaCore = class _ParaCore {
345
358
  cookie
346
359
  );
347
360
  };
361
+ this.persistEnclaveJwt = (jwt) => {
362
+ this.enclaveJwt = jwt;
363
+ (opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
364
+ constants.LOCAL_STORAGE_ENCLAVE_JWT,
365
+ jwt
366
+ );
367
+ };
368
+ this.persistEnclaveRefreshJwt = (refreshJwt) => {
369
+ this.enclaveRefreshJwt = refreshJwt;
370
+ (opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
371
+ constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
372
+ refreshJwt
373
+ );
374
+ };
375
+ const client = initClient({
376
+ env,
377
+ version: _ParaCore.version,
378
+ apiKey,
379
+ partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
380
+ useFetchAdapter: !!opts.disableWorkers,
381
+ retrieveSessionCookie: this.retrieveSessionCookie,
382
+ persistSessionCookie: this.persistSessionCookie
383
+ });
384
+ const enclaveClient = new EnclaveClient({
385
+ userManagementClient: client,
386
+ retrieveJwt: this.retrieveEnclaveJwt,
387
+ persistJwt: this.persistEnclaveJwt,
388
+ retrieveRefreshJwt: this.retrieveEnclaveRefreshJwt,
389
+ persistRefreshJwt: this.persistEnclaveRefreshJwt
390
+ });
348
391
  this.ctx = {
349
392
  env,
350
393
  apiKey,
351
- client: initClient({
352
- env,
353
- version: _ParaCore.version,
354
- apiKey,
355
- partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
356
- useFetchAdapter: !!opts.disableWorkers,
357
- retrieveSessionCookie: this.retrieveSessionCookie,
358
- persistSessionCookie: this.persistSessionCookie
359
- }),
394
+ client,
395
+ enclaveClient,
360
396
  disableWorkers: opts.disableWorkers,
361
397
  offloadMPCComputationURL: opts.offloadMPCComputationURL,
362
398
  useLocalFiles: opts.useLocalFiles,
@@ -391,6 +427,9 @@ const _ParaCore = class _ParaCore {
391
427
  ]);
392
428
  }
393
429
  }
430
+ setModalError(_error) {
431
+ return;
432
+ }
394
433
  get authInfo() {
395
434
  return __privateGet(this, _authInfo);
396
435
  }
@@ -675,23 +714,30 @@ const _ParaCore = class _ParaCore {
675
714
  constructPortalUrl(_0) {
676
715
  return __async(this, arguments, function* (type, opts = {}) {
677
716
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
678
- const [isCreate, isLogin, isOnRamp] = [
717
+ const [isCreate, isLogin, isOnRamp, isOAuth, isOAuthCallback, isTelegramLogin, isFarcasterLogin] = [
679
718
  ["createAuth", "createPassword", "createPIN"].includes(type),
680
- ["loginAuth", "loginPassword", "loginPIN"].includes(type),
681
- type === "onRamp"
719
+ ["loginAuth", "loginPassword", "loginPIN", "loginOTP"].includes(type),
720
+ type === "onRamp",
721
+ type === "oAuth",
722
+ type === "oAuthCallback",
723
+ ["telegramLogin", "telegramLoginVerify"].includes(type),
724
+ type === "loginFarcaster"
682
725
  ];
726
+ if (isOAuth && !opts.oAuthMethod) {
727
+ throw new Error("oAuthMethod is required for oAuth portal URLs");
728
+ }
683
729
  if (isCreate || isLogin) {
684
730
  this.assertIsAuthSet();
685
731
  }
686
732
  let sessionId = opts.sessionId;
687
- if ((isLogin || isOnRamp) && !sessionId) {
733
+ if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin) && !sessionId) {
688
734
  const session = yield this.touchSession(true);
689
735
  sessionId = session.sessionId;
690
736
  }
691
737
  if (!this.loginEncryptionKeyPair) {
692
738
  yield this.setLoginEncryptionKeyPair();
693
739
  }
694
- const base = type === "onRamp" || type === "telegramLogin" ? getPortalBaseURL(this.ctx, type === "telegramLogin") : yield this.getPortalURL();
740
+ const base = type === "onRamp" || isTelegramLogin ? getPortalBaseURL(this.ctx, isTelegramLogin) : yield this.getPortalURL();
695
741
  let path;
696
742
  switch (type) {
697
743
  case "createPassword": {
@@ -726,10 +772,30 @@ const _ParaCore = class _ParaCore {
726
772
  path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
727
773
  break;
728
774
  }
775
+ case "telegramLoginVerify": {
776
+ path = `/auth/telegram/verify`;
777
+ break;
778
+ }
729
779
  case "telegramLogin": {
730
780
  path = `/auth/telegram`;
731
781
  break;
732
782
  }
783
+ case "oAuth": {
784
+ path = `/auth/${opts.oAuthMethod.toLowerCase()}`;
785
+ break;
786
+ }
787
+ case "oAuthCallback": {
788
+ path = `/auth/${opts.oAuthMethod.toLowerCase()}/callback`;
789
+ break;
790
+ }
791
+ case "loginOTP": {
792
+ path = "/auth/otp";
793
+ break;
794
+ }
795
+ case "loginFarcaster": {
796
+ path = "/auth/farcaster";
797
+ break;
798
+ }
733
799
  default: {
734
800
  throw new Error(`invalid URL type ${type}`);
735
801
  }
@@ -748,7 +814,7 @@ const _ParaCore = class _ParaCore {
748
814
  encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
749
815
  sessionId
750
816
  };
751
- const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
817
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
752
818
  apiKey: this.ctx.apiKey,
753
819
  partnerId: partner == null ? void 0 : partner.id,
754
820
  portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
@@ -766,7 +832,7 @@ const _ParaCore = class _ParaCore {
766
832
  }, isPhone(this.authInfo.auth) ? splitPhoneNumber(this.authInfo.auth.phone) : this.authInfo.auth), {
767
833
  pfpUrl: this.authInfo.pfpUrl,
768
834
  displayName: this.authInfo.displayName
769
- }) : {}), isOnRamp ? { origin: typeof window !== "undefined" ? window.location.origin : void 0, email: this.email } : {}), isLogin ? __spreadProps(__spreadValues({
835
+ }) : {}), isOnRamp ? { origin: typeof window !== "undefined" ? window.location.origin : void 0, email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin ? __spreadProps(__spreadValues({
770
836
  sessionId: thisDevice.sessionId,
771
837
  encryptionKey: thisDevice.encryptionKey
772
838
  }, opts.newDevice ? {
@@ -774,7 +840,9 @@ const _ParaCore = class _ParaCore {
774
840
  newDeviceEncryptionKey: opts.newDevice.encryptionKey
775
841
  } : {}), {
776
842
  pregenIds: JSON.stringify(this.pregenIds)
777
- }) : {}), type === "telegramLogin" ? { isEmbed: "true" } : {}), opts.params || {});
843
+ }) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
844
+ appScheme: opts.appScheme
845
+ } : {}), isTelegramLogin ? { isEmbed: "true" } : {}), opts.params || {});
778
846
  const url = constructUrl({ base, path, params });
779
847
  if (opts.shorten) {
780
848
  return shortenUrl(this.ctx, url);
@@ -803,16 +871,25 @@ const _ParaCore = class _ParaCore {
803
871
  }
804
872
  touchSession(regenerate = false) {
805
873
  return __async(this, null, function* () {
806
- var _a, _b, _c, _d;
874
+ var _a, _b, _c, _d, _e;
807
875
  if (!this.isWorkerInitialized) {
808
876
  this.initializeWorker();
809
877
  }
810
878
  if (!this.isReady) {
811
879
  yield this.ready();
812
880
  }
813
- const session = yield this.ctx.client.touchSession(regenerate);
881
+ let session;
882
+ try {
883
+ session = yield this.ctx.client.touchSession(regenerate);
884
+ } catch (error) {
885
+ this.handleTouchSessionError(error);
886
+ throw error;
887
+ }
814
888
  if (!this.partner || ((_a = this.partner) == null ? void 0 : _a.id) !== session.partnerId || !supportedWalletTypesEq(((_b = this.partner) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = this.partner) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
815
889
  if (!session.partnerId) {
890
+ this.displayModalError(
891
+ `Invalid API Key. Please ensure you have a valid API key for the current environment: ${(_d = this.ctx.env) == null ? void 0 : _d.toUpperCase()}.`
892
+ );
816
893
  console.error(`
817
894
  \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
818
895
  \u{1F6A8} PARA SDK CONFIGURATION ERROR \u{1F6A8}
@@ -830,11 +907,12 @@ SOLUTION:
830
907
  \u2022 If your API key doesn't contain an environment prefix, ensure your API key is the correct key for your target environment
831
908
 
832
909
  Current Environment: ${this.ctx.env}
833
- API Key Prefix: ${((_d = this.ctx.apiKey) == null ? void 0 : _d.split("_")[0].toUpperCase()) || "None"}
910
+ API Key Prefix: ${((_e = this.ctx.apiKey) == null ? void 0 : _e.split("_")[0].toUpperCase()) || "None"}
834
911
 
835
912
  Need help? Visit: https://docs.getpara.com or contact support
836
913
  \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
837
914
  `);
915
+ throw new Error("Invalid API Key.");
838
916
  } else {
839
917
  yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
840
918
  }
@@ -936,6 +1014,33 @@ Need help? Visit: https://docs.getpara.com or contact support
936
1014
  return __privateGet(this, _authInfo);
937
1015
  });
938
1016
  }
1017
+ /**
1018
+ * Display an error message in the modal (if available)
1019
+ * @internal
1020
+ */
1021
+ displayModalError(error) {
1022
+ if (this.ctx.env !== Environment.PROD) {
1023
+ this.setModalError(error);
1024
+ }
1025
+ }
1026
+ /**
1027
+ * Handle specific touchSession errors with user-friendly messages
1028
+ * @private
1029
+ */
1030
+ handleTouchSessionError(error) {
1031
+ const errorStr = String(error);
1032
+ const errorMessage = error instanceof Error ? error.message : "";
1033
+ if (errorStr.includes("blocked by CORS policy") && errorStr.includes("Access-Control-Allow-Origin")) {
1034
+ this.displayModalError("Request rate limit reached. Please wait a couple of minutes and try again.");
1035
+ return;
1036
+ }
1037
+ if (error.status === 403 && errorMessage.includes("origin not authorized")) {
1038
+ this.displayModalError(
1039
+ "The current origin is not allowed. Update your allowed origins in the Para developer portal to allow the current origin."
1040
+ );
1041
+ return;
1042
+ }
1043
+ }
939
1044
  assertUserId({ allowGuestMode = false } = {}) {
940
1045
  if (!this.userId || !allowGuestMode && this.isGuestMode) {
941
1046
  throw new Error("no userId is set");
@@ -1477,6 +1582,7 @@ Need help? Visit: https://docs.getpara.com or contact support
1477
1582
  return accounts;
1478
1583
  });
1479
1584
  }
1585
+ // TELEGRAM
1480
1586
  /**
1481
1587
  * Validates the response received from an attempted Telegram login for authenticity, then
1482
1588
  * creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
@@ -1486,19 +1592,28 @@ Need help? Visit: https://docs.getpara.com or contact support
1486
1592
  verifyTelegramProcess(_e) {
1487
1593
  return __async(this, null, function* () {
1488
1594
  var _f = _e, {
1595
+ serverAuthState: optsServerAuthState,
1489
1596
  telegramAuthResponse,
1490
1597
  isLinkAccount
1491
1598
  } = _f, urlOptions = __objRest(_f, [
1599
+ "serverAuthState",
1492
1600
  "telegramAuthResponse",
1493
1601
  "isLinkAccount"
1494
1602
  ]);
1495
1603
  try {
1496
1604
  switch (isLinkAccount) {
1497
1605
  case false: {
1498
- const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
1499
- return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1606
+ if (!optsServerAuthState && !telegramAuthResponse) {
1607
+ throw new Error("one of serverAuthState or telegramAuthResponse are required for verifying telegram");
1608
+ }
1609
+ const serverAuthState = optsServerAuthState != null ? optsServerAuthState : yield this.ctx.client.verifyTelegram({ authObject: telegramAuthResponse });
1610
+ const { sessionLookupId } = yield this.touchSession();
1611
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
1500
1612
  }
1501
1613
  case true: {
1614
+ if (!telegramAuthResponse) {
1615
+ throw new Error("telegramAuthResponse is required for verifying telegram link");
1616
+ }
1502
1617
  const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
1503
1618
  const accounts = yield this.verifyLink({
1504
1619
  accountLinkInProgress,
@@ -1508,7 +1623,8 @@ Need help? Visit: https://docs.getpara.com or contact support
1508
1623
  }
1509
1624
  }
1510
1625
  } catch (e) {
1511
- throw new Error(e.message);
1626
+ const errorMessage = e instanceof Error ? e.message : e ? String(e) : "Unknown error occurred";
1627
+ throw new Error(errorMessage);
1512
1628
  }
1513
1629
  });
1514
1630
  }
@@ -1753,6 +1869,7 @@ Need help? Visit: https://docs.getpara.com or contact support
1753
1869
  return connectUri;
1754
1870
  });
1755
1871
  }
1872
+ // FARCASTER
1756
1873
  /**
1757
1874
  * Awaits the response from a user's attempt to log in with Farcaster.
1758
1875
  * If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
@@ -1765,14 +1882,20 @@ Need help? Visit: https://docs.getpara.com or contact support
1765
1882
  onConnectUri,
1766
1883
  onCancel,
1767
1884
  onPoll,
1768
- isLinkAccount
1885
+ isLinkAccount,
1886
+ serverAuthState: optsServerAuthState
1769
1887
  } = _h, urlOptions = __objRest(_h, [
1770
1888
  "isCanceled",
1771
1889
  "onConnectUri",
1772
1890
  "onCancel",
1773
1891
  "onPoll",
1774
- "isLinkAccount"
1892
+ "isLinkAccount",
1893
+ "serverAuthState"
1775
1894
  ]);
1895
+ if (optsServerAuthState) {
1896
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, optsServerAuthState, urlOptions);
1897
+ return authState;
1898
+ }
1776
1899
  let accountLinkInProgress;
1777
1900
  if (isLinkAccount) {
1778
1901
  accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
@@ -1868,10 +1991,9 @@ Need help? Visit: https://docs.getpara.com or contact support
1868
1991
  "onOAuthPopup",
1869
1992
  "isLinkAccount"
1870
1993
  ]);
1871
- let popupWindow;
1872
1994
  if (onOAuthPopup) {
1873
1995
  try {
1874
- popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.OAUTH });
1996
+ this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.OAUTH });
1875
1997
  } catch (error) {
1876
1998
  throw new Error(`Failed to open OAuth popup: ${error}`);
1877
1999
  }
@@ -1890,9 +2012,9 @@ Need help? Visit: https://docs.getpara.com or contact support
1890
2012
  onOAuthUrl(oAuthUrl);
1891
2013
  break;
1892
2014
  }
1893
- case (!!onOAuthPopup && !!popupWindow): {
1894
- popupWindow.location.href = oAuthUrl;
1895
- onOAuthPopup(popupWindow);
2015
+ case (!!onOAuthPopup && !!this.popupWindow): {
2016
+ this.popupWindow.location.href = oAuthUrl;
2017
+ onOAuthPopup(this.popupWindow);
1896
2018
  break;
1897
2019
  }
1898
2020
  }
@@ -2122,7 +2244,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2122
2244
  userId: this.userId,
2123
2245
  walletId,
2124
2246
  userShare: userSigner,
2125
- emailProps: this.getBackupKitEmailProps()
2247
+ emailProps: this.getBackupKitEmailProps(),
2248
+ isEnclaveUser: this.isEnclaveUser,
2249
+ walletScheme: this.wallets[walletId].scheme
2126
2250
  });
2127
2251
  return recoveryShare;
2128
2252
  });
@@ -2250,7 +2374,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2250
2374
  ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
2251
2375
  emailProps: this.getBackupKitEmailProps(),
2252
2376
  partnerId: newPartnerId,
2253
- protocolId
2377
+ protocolId,
2378
+ isEnclaveUser: this.isEnclaveUser,
2379
+ walletScheme: this.wallets[walletId].scheme
2254
2380
  });
2255
2381
  return { signer, recoverySecret, protocolId };
2256
2382
  });
@@ -2316,7 +2442,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2316
2442
  userId: this.userId,
2317
2443
  walletId: wallet.id,
2318
2444
  userShare: signer,
2319
- emailProps: this.getBackupKitEmailProps()
2445
+ emailProps: this.getBackupKitEmailProps(),
2446
+ isEnclaveUser: this.isEnclaveUser,
2447
+ walletScheme: wallet.scheme
2320
2448
  });
2321
2449
  }
2322
2450
  yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
@@ -2397,7 +2525,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2397
2525
  walletId: wallet.id,
2398
2526
  userShare: this.wallets[wallet.id].signer,
2399
2527
  emailProps: this.getBackupKitEmailProps(),
2400
- partnerId: wallet.partnerId
2528
+ partnerId: wallet.partnerId,
2529
+ isEnclaveUser: this.isEnclaveUser,
2530
+ walletScheme: wallet.scheme
2401
2531
  });
2402
2532
  if (distributeRes.length > 0) {
2403
2533
  newRecoverySecret = distributeRes;
@@ -2888,8 +3018,16 @@ Need help? Visit: https://docs.getpara.com or contact support
2888
3018
  }
2889
3019
  issueJwt() {
2890
3020
  return __async(this, arguments, function* ({ keyIndex = 0 } = {}) {
2891
- const res = yield this.ctx.client.issueJwt({ keyIndex });
2892
- return res;
3021
+ try {
3022
+ return yield this.ctx.client.issueJwt({ keyIndex });
3023
+ } catch (error) {
3024
+ if (error.status === 403 || error.status === 401) {
3025
+ const errorMessage = "The user needs to be logged in to issue a JWT. Please log in and try again.";
3026
+ this.displayModalError(errorMessage);
3027
+ console.warn(errorMessage);
3028
+ }
3029
+ throw error;
3030
+ }
2893
3031
  });
2894
3032
  }
2895
3033
  /**
@@ -2997,7 +3135,7 @@ Need help? Visit: https://docs.getpara.com or contact support
2997
3135
  ({
2998
3136
  data: { id: credentialId }
2999
3137
  } = yield this.ctx.client.addSessionPublicKey(this.userId, {
3000
- status: PublicKeyStatus.PENDING,
3138
+ status: AuthMethodStatus.PENDING,
3001
3139
  type: PublicKeyType.WEB
3002
3140
  }));
3003
3141
  urlType = "createAuth";
@@ -3006,7 +3144,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3006
3144
  ({
3007
3145
  data: { id: credentialId }
3008
3146
  } = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
3009
- status: PasswordStatus.PENDING
3147
+ status: AuthMethodStatus.PENDING
3010
3148
  }));
3011
3149
  urlType = "createPassword";
3012
3150
  break;
@@ -3014,7 +3152,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3014
3152
  ({
3015
3153
  data: { id: credentialId }
3016
3154
  } = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
3017
- status: PasswordStatus.PENDING
3155
+ status: AuthMethodStatus.PENDING
3018
3156
  }));
3019
3157
  urlType = "createPIN";
3020
3158
  break;
@@ -3029,7 +3167,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3029
3167
  });
3030
3168
  }
3031
3169
  /**
3032
- * Returns a Para Portal URL for logging in with a WebAuth passkey, password or PIN.
3170
+ * Returns a Para Portal URL for logging in with a WebAuth passkey, password, PIN or OTP.
3033
3171
  * @param {Object} opts the options object
3034
3172
  * @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
3035
3173
  * @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
@@ -3058,6 +3196,9 @@ Need help? Visit: https://docs.getpara.com or contact support
3058
3196
  case "PIN":
3059
3197
  urlType = "loginPIN";
3060
3198
  break;
3199
+ case "BASIC_LOGIN":
3200
+ urlType = "loginOTP";
3201
+ break;
3061
3202
  default:
3062
3203
  throw new Error(`invalid authentication method: '${authMethod}'`);
3063
3204
  }
@@ -3081,7 +3222,17 @@ Need help? Visit: https://docs.getpara.com or contact support
3081
3222
  signUpOrLogIn(_k) {
3082
3223
  return __async(this, null, function* () {
3083
3224
  var _l = _k, { auth } = _l, urlOptions = __objRest(_l, ["auth"]);
3084
- const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
3225
+ let serverAuthState;
3226
+ try {
3227
+ serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
3228
+ } catch (error) {
3229
+ if (error.message.includes("max beta users reached")) {
3230
+ this.displayModalError(
3231
+ `50 user limit reached. [Go to Production.](https://docs.getpara.com/v2/general/checklist#go-live-checklist)`
3232
+ );
3233
+ }
3234
+ throw error;
3235
+ }
3085
3236
  const authInfo = serverAuthState.auth;
3086
3237
  if (this.fetchPregenWalletsOverride && isPregenAuth(authInfo)) {
3087
3238
  const { userShare } = yield this.fetchPregenWalletsOverride({ pregenId: authInfo });
@@ -3089,7 +3240,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3089
3240
  yield this.setUserShare(userShare);
3090
3241
  }
3091
3242
  }
3092
- return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
3243
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadValues({}, urlOptions));
3093
3244
  });
3094
3245
  }
3095
3246
  verifyNewAccount(_m) {
@@ -3104,7 +3255,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3104
3255
  const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
3105
3256
  verificationCode
3106
3257
  });
3107
- if (serverAuthState.stage === "login") {
3258
+ if (serverAuthState.stage === "login" || serverAuthState.stage === "done") {
3108
3259
  throw new Error("Account already exists.");
3109
3260
  }
3110
3261
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
@@ -3225,6 +3376,16 @@ Need help? Visit: https://docs.getpara.com or contact support
3225
3376
  return accounts;
3226
3377
  });
3227
3378
  }
3379
+ getProfileBalance() {
3380
+ return __async(this, arguments, function* ({ config, refetch = false } = {}) {
3381
+ const { balance } = yield this.ctx.client.getProfileBalance({
3382
+ config,
3383
+ wallets: this.availableWallets.map(({ type, address }) => ({ type, address })),
3384
+ refetch
3385
+ });
3386
+ return balance;
3387
+ });
3388
+ }
3228
3389
  sendLoginCode() {
3229
3390
  return __async(this, null, function* () {
3230
3391
  const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
@@ -3338,30 +3499,43 @@ assertIsLinkingAccountOrStart_fn = function(type) {
3338
3499
  return yield this.linkAccount({ type });
3339
3500
  });
3340
3501
  };
3341
- /**
3342
- * Generates a URL for the user to log in with OAuth using a desire method.
3343
- *
3344
- * @param {Object} opts the options object
3345
- * @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
3346
- * @param {string} [opts.appScheme] the app scheme to redirect to after the OAuth flow. This is for mobile only.
3347
- * @returns {string} the URL for the user to log in with OAuth.
3348
- */
3349
- getOAuthUrl_fn = function({
3350
- method,
3351
- appScheme,
3352
- accountLinkInProgress,
3353
- sessionLookupId
3354
- }) {
3355
- return constructUrl({
3356
- base: getBaseOAuthUrl(this.ctx.env),
3357
- path: `/auth/${method}`,
3358
- params: __spreadValues({
3359
- apiKey: this.ctx.apiKey,
3360
- sessionLookupId,
3361
- appScheme
3362
- }, accountLinkInProgress ? {
3363
- linkedAccountId: this.accountLinkInProgress.id
3364
- } : {})
3502
+ getOAuthUrl_fn = function(_0) {
3503
+ return __async(this, arguments, function* ({
3504
+ method,
3505
+ appScheme,
3506
+ accountLinkInProgress,
3507
+ sessionLookupId,
3508
+ encryptionKey
3509
+ }) {
3510
+ if (!accountLinkInProgress && !this.isPortal()) {
3511
+ return yield this.constructPortalUrl("oAuth", { sessionId: sessionLookupId, oAuthMethod: method, appScheme });
3512
+ }
3513
+ let portalSessionLookupId;
3514
+ if (this.isPortal()) {
3515
+ portalSessionLookupId = (yield this.touchSession(true)).sessionLookupId;
3516
+ }
3517
+ return constructUrl({
3518
+ base: getBaseOAuthUrl(this.ctx.env),
3519
+ path: `/auth/${method.toLowerCase()}`,
3520
+ params: __spreadProps(__spreadValues({
3521
+ apiKey: this.ctx.apiKey,
3522
+ sessionLookupId,
3523
+ portalSessionLookupId,
3524
+ appScheme
3525
+ }, accountLinkInProgress ? {
3526
+ linkedAccountId: this.accountLinkInProgress.id
3527
+ } : {}), {
3528
+ callback: !accountLinkInProgress && (yield this.constructPortalUrl("oAuthCallback", {
3529
+ sessionId: sessionLookupId,
3530
+ oAuthMethod: method,
3531
+ appScheme,
3532
+ thisDevice: {
3533
+ sessionId: sessionLookupId,
3534
+ encryptionKey
3535
+ }
3536
+ }))
3537
+ })
3538
+ });
3365
3539
  });
3366
3540
  };
3367
3541
  createPregenWallet_fn = function(opts) {
@@ -3437,8 +3611,14 @@ prepareAuthState_fn = function(_0) {
3437
3611
  }
3438
3612
  let authState;
3439
3613
  switch (serverAuthState.stage) {
3614
+ case "done": {
3615
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareDoneState_fn).call(this, serverAuthState);
3616
+ break;
3617
+ }
3440
3618
  case "verify":
3441
- authState = serverAuthState;
3619
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareVerificationState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), {
3620
+ sessionLookupId: opts.sessionLookupId
3621
+ }));
3442
3622
  break;
3443
3623
  case "login":
3444
3624
  if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
@@ -3458,6 +3638,36 @@ prepareAuthState_fn = function(_0) {
3458
3638
  return authState;
3459
3639
  });
3460
3640
  };
3641
+ prepareDoneState_fn = function(doneState) {
3642
+ return __async(this, null, function* () {
3643
+ let isSLOPossible = doneState.authMethods.includes(AuthMethod.BASIC_LOGIN);
3644
+ this.isEnclaveUser = isSLOPossible;
3645
+ return doneState;
3646
+ });
3647
+ };
3648
+ prepareVerificationState_fn = function(_0, _1) {
3649
+ return __async(this, arguments, function* (verifyState, {
3650
+ useShortUrls: shorten = false,
3651
+ portalTheme,
3652
+ sessionLookupId
3653
+ }) {
3654
+ let isSLOPossible = false;
3655
+ if (verifyState.nextStage === "login") {
3656
+ isSLOPossible = verifyState.loginAuthMethods.includes(AuthMethod.BASIC_LOGIN);
3657
+ } else if (verifyState.nextStage === "signup") {
3658
+ isSLOPossible = verifyState.signupAuthMethods.includes(AuthMethod.BASIC_LOGIN);
3659
+ }
3660
+ this.isEnclaveUser = isSLOPossible;
3661
+ return __spreadValues(__spreadValues({}, verifyState), isSLOPossible ? {
3662
+ loginUrl: yield this.getLoginUrl({
3663
+ authMethod: AuthMethod.BASIC_LOGIN,
3664
+ sessionId: sessionLookupId,
3665
+ shorten,
3666
+ portalTheme
3667
+ })
3668
+ } : {});
3669
+ });
3670
+ };
3461
3671
  prepareLoginState_fn = function(_0, _1) {
3462
3672
  return __async(this, arguments, function* (loginState, {
3463
3673
  useShortUrls: shorten = false,