@getpara/core-sdk 2.0.0-alpha.53 → 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 (51) hide show
  1. package/dist/cjs/ParaCore.js +213 -60
  2. package/dist/cjs/constants.js +7 -1
  3. package/dist/cjs/index.js +2 -0
  4. package/dist/cjs/shares/enclave.js +266 -0
  5. package/dist/cjs/shares/shareDistribution.js +16 -1
  6. package/dist/cjs/types/assets.js +15 -0
  7. package/dist/cjs/types/events.js +2 -0
  8. package/dist/cjs/utils/formatting.js +41 -0
  9. package/dist/esm/ParaCore.js +214 -61
  10. package/dist/esm/{chunk-7B52C2XE.js → chunk-W5CT3TVS.js} +2 -0
  11. package/dist/esm/constants.js +6 -2
  12. package/dist/esm/cryptography/utils.js +1 -1
  13. package/dist/esm/errors.js +1 -1
  14. package/dist/esm/external/mpcComputationClient.js +1 -1
  15. package/dist/esm/external/userManagementClient.js +1 -1
  16. package/dist/esm/index.js +3 -2
  17. package/dist/esm/shares/KeyContainer.js +1 -1
  18. package/dist/esm/shares/enclave.js +226 -0
  19. package/dist/esm/shares/recovery.js +1 -1
  20. package/dist/esm/shares/shareDistribution.js +17 -2
  21. package/dist/esm/transmission/transmissionUtils.js +1 -1
  22. package/dist/esm/types/assets.js +0 -0
  23. package/dist/esm/types/auth.js +1 -1
  24. package/dist/esm/types/config.js +1 -1
  25. package/dist/esm/types/coreApi.js +1 -1
  26. package/dist/esm/types/events.js +3 -1
  27. package/dist/esm/types/popup.js +1 -1
  28. package/dist/esm/types/wallet.js +1 -1
  29. package/dist/esm/utils/autobind.js +1 -1
  30. package/dist/esm/utils/events.js +1 -1
  31. package/dist/esm/utils/formatting.js +41 -1
  32. package/dist/esm/utils/json.js +1 -1
  33. package/dist/esm/utils/listeners.js +1 -1
  34. package/dist/esm/utils/onRamps.js +1 -1
  35. package/dist/esm/utils/phone.js +1 -1
  36. package/dist/esm/utils/polling.js +1 -1
  37. package/dist/esm/utils/types.js +1 -1
  38. package/dist/esm/utils/url.js +1 -1
  39. package/dist/esm/utils/wallet.js +1 -1
  40. package/dist/types/ParaCore.d.ts +15 -2
  41. package/dist/types/constants.d.ts +2 -0
  42. package/dist/types/index.d.ts +3 -2
  43. package/dist/types/shares/enclave.d.ts +81 -0
  44. package/dist/types/shares/shareDistribution.d.ts +4 -2
  45. package/dist/types/types/assets.d.ts +14 -0
  46. package/dist/types/types/config.d.ts +2 -0
  47. package/dist/types/types/coreApi.d.ts +1 -0
  48. package/dist/types/types/events.d.ts +7 -2
  49. package/dist/types/types/methods.d.ts +15 -7
  50. package/dist/types/utils/formatting.d.ts +10 -1
  51. package/package.json +3 -3
@@ -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;
@@ -74,13 +74,16 @@ import {
74
74
  } from "./utils/index.js";
75
75
  import { TransactionReviewDenied, TransactionReviewTimeout } from "./errors.js";
76
76
  import * as constants from "./constants.js";
77
+ import { EnclaveClient } from "./shares/enclave.js";
77
78
  const _ParaCore = class _ParaCore {
78
79
  constructor(envOrApiKey, apiKeyOrOpts, opts) {
79
80
  __privateAdd(this, _ParaCore_instances);
81
+ this.popupWindow = null;
80
82
  __privateAdd(this, _authInfo);
81
83
  this.isNativePasskey = false;
82
84
  this.isReady = false;
83
85
  this.accountLinkInProgress = void 0;
86
+ this.isEnclaveUser = false;
84
87
  this.isAwaitingAccountCreation = false;
85
88
  this.isAwaitingLogin = false;
86
89
  this.isAwaitingFarcaster = false;
@@ -116,6 +119,12 @@ const _ParaCore = class _ParaCore {
116
119
  this.retrieveSessionCookie = () => {
117
120
  return this.sessionCookie;
118
121
  };
122
+ this.retrieveEnclaveJwt = () => {
123
+ return this.enclaveJwt;
124
+ };
125
+ this.retrieveEnclaveRefreshJwt = () => {
126
+ return this.enclaveRefreshJwt;
127
+ };
119
128
  /**
120
129
  * Remove all local storage and prefixed session storage.
121
130
  * @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
@@ -174,6 +183,7 @@ const _ParaCore = class _ParaCore {
174
183
  this.updateWalletIdsFromStorage();
175
184
  this.updateSessionCookieFromStorage();
176
185
  this.updateLoginEncryptionKeyPairFromStorage();
186
+ this.updateEnclaveJwtFromStorage();
177
187
  };
178
188
  this.updateAuthInfoFromStorage = () => {
179
189
  var _a;
@@ -193,6 +203,10 @@ const _ParaCore = class _ParaCore {
193
203
  }
194
204
  __privateSet(this, _authInfo, authInfo);
195
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
+ };
196
210
  this.updateUserIdFromStorage = () => {
197
211
  this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
198
212
  };
@@ -344,18 +358,41 @@ const _ParaCore = class _ParaCore {
344
358
  cookie
345
359
  );
346
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
+ });
347
391
  this.ctx = {
348
392
  env,
349
393
  apiKey,
350
- client: initClient({
351
- env,
352
- version: _ParaCore.version,
353
- apiKey,
354
- partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
355
- useFetchAdapter: !!opts.disableWorkers,
356
- retrieveSessionCookie: this.retrieveSessionCookie,
357
- persistSessionCookie: this.persistSessionCookie
358
- }),
394
+ client,
395
+ enclaveClient,
359
396
  disableWorkers: opts.disableWorkers,
360
397
  offloadMPCComputationURL: opts.offloadMPCComputationURL,
361
398
  useLocalFiles: opts.useLocalFiles,
@@ -677,23 +714,30 @@ const _ParaCore = class _ParaCore {
677
714
  constructPortalUrl(_0) {
678
715
  return __async(this, arguments, function* (type, opts = {}) {
679
716
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
680
- const [isCreate, isLogin, isOnRamp] = [
717
+ const [isCreate, isLogin, isOnRamp, isOAuth, isOAuthCallback, isTelegramLogin, isFarcasterLogin] = [
681
718
  ["createAuth", "createPassword", "createPIN"].includes(type),
682
- ["loginAuth", "loginPassword", "loginPIN"].includes(type),
683
- 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"
684
725
  ];
726
+ if (isOAuth && !opts.oAuthMethod) {
727
+ throw new Error("oAuthMethod is required for oAuth portal URLs");
728
+ }
685
729
  if (isCreate || isLogin) {
686
730
  this.assertIsAuthSet();
687
731
  }
688
732
  let sessionId = opts.sessionId;
689
- if ((isLogin || isOnRamp) && !sessionId) {
733
+ if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin) && !sessionId) {
690
734
  const session = yield this.touchSession(true);
691
735
  sessionId = session.sessionId;
692
736
  }
693
737
  if (!this.loginEncryptionKeyPair) {
694
738
  yield this.setLoginEncryptionKeyPair();
695
739
  }
696
- 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();
697
741
  let path;
698
742
  switch (type) {
699
743
  case "createPassword": {
@@ -728,10 +772,30 @@ const _ParaCore = class _ParaCore {
728
772
  path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
729
773
  break;
730
774
  }
775
+ case "telegramLoginVerify": {
776
+ path = `/auth/telegram/verify`;
777
+ break;
778
+ }
731
779
  case "telegramLogin": {
732
780
  path = `/auth/telegram`;
733
781
  break;
734
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
+ }
735
799
  default: {
736
800
  throw new Error(`invalid URL type ${type}`);
737
801
  }
@@ -750,7 +814,7 @@ const _ParaCore = class _ParaCore {
750
814
  encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
751
815
  sessionId
752
816
  };
753
- const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
817
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
754
818
  apiKey: this.ctx.apiKey,
755
819
  partnerId: partner == null ? void 0 : partner.id,
756
820
  portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
@@ -768,7 +832,7 @@ const _ParaCore = class _ParaCore {
768
832
  }, isPhone(this.authInfo.auth) ? splitPhoneNumber(this.authInfo.auth.phone) : this.authInfo.auth), {
769
833
  pfpUrl: this.authInfo.pfpUrl,
770
834
  displayName: this.authInfo.displayName
771
- }) : {}), 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({
772
836
  sessionId: thisDevice.sessionId,
773
837
  encryptionKey: thisDevice.encryptionKey
774
838
  }, opts.newDevice ? {
@@ -776,7 +840,9 @@ const _ParaCore = class _ParaCore {
776
840
  newDeviceEncryptionKey: opts.newDevice.encryptionKey
777
841
  } : {}), {
778
842
  pregenIds: JSON.stringify(this.pregenIds)
779
- }) : {}), type === "telegramLogin" ? { isEmbed: "true" } : {}), opts.params || {});
843
+ }) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
844
+ appScheme: opts.appScheme
845
+ } : {}), isTelegramLogin ? { isEmbed: "true" } : {}), opts.params || {});
780
846
  const url = constructUrl({ base, path, params });
781
847
  if (opts.shorten) {
782
848
  return shortenUrl(this.ctx, url);
@@ -1516,6 +1582,7 @@ Need help? Visit: https://docs.getpara.com or contact support
1516
1582
  return accounts;
1517
1583
  });
1518
1584
  }
1585
+ // TELEGRAM
1519
1586
  /**
1520
1587
  * Validates the response received from an attempted Telegram login for authenticity, then
1521
1588
  * creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
@@ -1525,19 +1592,28 @@ Need help? Visit: https://docs.getpara.com or contact support
1525
1592
  verifyTelegramProcess(_e) {
1526
1593
  return __async(this, null, function* () {
1527
1594
  var _f = _e, {
1595
+ serverAuthState: optsServerAuthState,
1528
1596
  telegramAuthResponse,
1529
1597
  isLinkAccount
1530
1598
  } = _f, urlOptions = __objRest(_f, [
1599
+ "serverAuthState",
1531
1600
  "telegramAuthResponse",
1532
1601
  "isLinkAccount"
1533
1602
  ]);
1534
1603
  try {
1535
1604
  switch (isLinkAccount) {
1536
1605
  case false: {
1537
- const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
1538
- 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 }));
1539
1612
  }
1540
1613
  case true: {
1614
+ if (!telegramAuthResponse) {
1615
+ throw new Error("telegramAuthResponse is required for verifying telegram link");
1616
+ }
1541
1617
  const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
1542
1618
  const accounts = yield this.verifyLink({
1543
1619
  accountLinkInProgress,
@@ -1547,7 +1623,8 @@ Need help? Visit: https://docs.getpara.com or contact support
1547
1623
  }
1548
1624
  }
1549
1625
  } catch (e) {
1550
- throw new Error(e.message);
1626
+ const errorMessage = e instanceof Error ? e.message : e ? String(e) : "Unknown error occurred";
1627
+ throw new Error(errorMessage);
1551
1628
  }
1552
1629
  });
1553
1630
  }
@@ -1792,6 +1869,7 @@ Need help? Visit: https://docs.getpara.com or contact support
1792
1869
  return connectUri;
1793
1870
  });
1794
1871
  }
1872
+ // FARCASTER
1795
1873
  /**
1796
1874
  * Awaits the response from a user's attempt to log in with Farcaster.
1797
1875
  * If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
@@ -1804,14 +1882,20 @@ Need help? Visit: https://docs.getpara.com or contact support
1804
1882
  onConnectUri,
1805
1883
  onCancel,
1806
1884
  onPoll,
1807
- isLinkAccount
1885
+ isLinkAccount,
1886
+ serverAuthState: optsServerAuthState
1808
1887
  } = _h, urlOptions = __objRest(_h, [
1809
1888
  "isCanceled",
1810
1889
  "onConnectUri",
1811
1890
  "onCancel",
1812
1891
  "onPoll",
1813
- "isLinkAccount"
1892
+ "isLinkAccount",
1893
+ "serverAuthState"
1814
1894
  ]);
1895
+ if (optsServerAuthState) {
1896
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, optsServerAuthState, urlOptions);
1897
+ return authState;
1898
+ }
1815
1899
  let accountLinkInProgress;
1816
1900
  if (isLinkAccount) {
1817
1901
  accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
@@ -1907,10 +1991,9 @@ Need help? Visit: https://docs.getpara.com or contact support
1907
1991
  "onOAuthPopup",
1908
1992
  "isLinkAccount"
1909
1993
  ]);
1910
- let popupWindow;
1911
1994
  if (onOAuthPopup) {
1912
1995
  try {
1913
- popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.OAUTH });
1996
+ this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.OAUTH });
1914
1997
  } catch (error) {
1915
1998
  throw new Error(`Failed to open OAuth popup: ${error}`);
1916
1999
  }
@@ -1929,9 +2012,9 @@ Need help? Visit: https://docs.getpara.com or contact support
1929
2012
  onOAuthUrl(oAuthUrl);
1930
2013
  break;
1931
2014
  }
1932
- case (!!onOAuthPopup && !!popupWindow): {
1933
- popupWindow.location.href = oAuthUrl;
1934
- onOAuthPopup(popupWindow);
2015
+ case (!!onOAuthPopup && !!this.popupWindow): {
2016
+ this.popupWindow.location.href = oAuthUrl;
2017
+ onOAuthPopup(this.popupWindow);
1935
2018
  break;
1936
2019
  }
1937
2020
  }
@@ -2161,7 +2244,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2161
2244
  userId: this.userId,
2162
2245
  walletId,
2163
2246
  userShare: userSigner,
2164
- emailProps: this.getBackupKitEmailProps()
2247
+ emailProps: this.getBackupKitEmailProps(),
2248
+ isEnclaveUser: this.isEnclaveUser,
2249
+ walletScheme: this.wallets[walletId].scheme
2165
2250
  });
2166
2251
  return recoveryShare;
2167
2252
  });
@@ -2289,7 +2374,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2289
2374
  ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
2290
2375
  emailProps: this.getBackupKitEmailProps(),
2291
2376
  partnerId: newPartnerId,
2292
- protocolId
2377
+ protocolId,
2378
+ isEnclaveUser: this.isEnclaveUser,
2379
+ walletScheme: this.wallets[walletId].scheme
2293
2380
  });
2294
2381
  return { signer, recoverySecret, protocolId };
2295
2382
  });
@@ -2355,7 +2442,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2355
2442
  userId: this.userId,
2356
2443
  walletId: wallet.id,
2357
2444
  userShare: signer,
2358
- emailProps: this.getBackupKitEmailProps()
2445
+ emailProps: this.getBackupKitEmailProps(),
2446
+ isEnclaveUser: this.isEnclaveUser,
2447
+ walletScheme: wallet.scheme
2359
2448
  });
2360
2449
  }
2361
2450
  yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
@@ -2436,7 +2525,9 @@ Need help? Visit: https://docs.getpara.com or contact support
2436
2525
  walletId: wallet.id,
2437
2526
  userShare: this.wallets[wallet.id].signer,
2438
2527
  emailProps: this.getBackupKitEmailProps(),
2439
- partnerId: wallet.partnerId
2528
+ partnerId: wallet.partnerId,
2529
+ isEnclaveUser: this.isEnclaveUser,
2530
+ walletScheme: wallet.scheme
2440
2531
  });
2441
2532
  if (distributeRes.length > 0) {
2442
2533
  newRecoverySecret = distributeRes;
@@ -3076,7 +3167,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3076
3167
  });
3077
3168
  }
3078
3169
  /**
3079
- * 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.
3080
3171
  * @param {Object} opts the options object
3081
3172
  * @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
3082
3173
  * @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
@@ -3105,6 +3196,9 @@ Need help? Visit: https://docs.getpara.com or contact support
3105
3196
  case "PIN":
3106
3197
  urlType = "loginPIN";
3107
3198
  break;
3199
+ case "BASIC_LOGIN":
3200
+ urlType = "loginOTP";
3201
+ break;
3108
3202
  default:
3109
3203
  throw new Error(`invalid authentication method: '${authMethod}'`);
3110
3204
  }
@@ -3146,7 +3240,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3146
3240
  yield this.setUserShare(userShare);
3147
3241
  }
3148
3242
  }
3149
- return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
3243
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadValues({}, urlOptions));
3150
3244
  });
3151
3245
  }
3152
3246
  verifyNewAccount(_m) {
@@ -3161,7 +3255,7 @@ Need help? Visit: https://docs.getpara.com or contact support
3161
3255
  const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
3162
3256
  verificationCode
3163
3257
  });
3164
- if (serverAuthState.stage === "login") {
3258
+ if (serverAuthState.stage === "login" || serverAuthState.stage === "done") {
3165
3259
  throw new Error("Account already exists.");
3166
3260
  }
3167
3261
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
@@ -3282,6 +3376,16 @@ Need help? Visit: https://docs.getpara.com or contact support
3282
3376
  return accounts;
3283
3377
  });
3284
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
+ }
3285
3389
  sendLoginCode() {
3286
3390
  return __async(this, null, function* () {
3287
3391
  const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
@@ -3395,30 +3499,43 @@ assertIsLinkingAccountOrStart_fn = function(type) {
3395
3499
  return yield this.linkAccount({ type });
3396
3500
  });
3397
3501
  };
3398
- /**
3399
- * Generates a URL for the user to log in with OAuth using a desire method.
3400
- *
3401
- * @param {Object} opts the options object
3402
- * @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
3403
- * @param {string} [opts.appScheme] the app scheme to redirect to after the OAuth flow. This is for mobile only.
3404
- * @returns {string} the URL for the user to log in with OAuth.
3405
- */
3406
- getOAuthUrl_fn = function({
3407
- method,
3408
- appScheme,
3409
- accountLinkInProgress,
3410
- sessionLookupId
3411
- }) {
3412
- return constructUrl({
3413
- base: getBaseOAuthUrl(this.ctx.env),
3414
- path: `/auth/${method}`,
3415
- params: __spreadValues({
3416
- apiKey: this.ctx.apiKey,
3417
- sessionLookupId,
3418
- appScheme
3419
- }, accountLinkInProgress ? {
3420
- linkedAccountId: this.accountLinkInProgress.id
3421
- } : {})
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
+ });
3422
3539
  });
3423
3540
  };
3424
3541
  createPregenWallet_fn = function(opts) {
@@ -3494,8 +3611,14 @@ prepareAuthState_fn = function(_0) {
3494
3611
  }
3495
3612
  let authState;
3496
3613
  switch (serverAuthState.stage) {
3614
+ case "done": {
3615
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareDoneState_fn).call(this, serverAuthState);
3616
+ break;
3617
+ }
3497
3618
  case "verify":
3498
- authState = serverAuthState;
3619
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareVerificationState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), {
3620
+ sessionLookupId: opts.sessionLookupId
3621
+ }));
3499
3622
  break;
3500
3623
  case "login":
3501
3624
  if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
@@ -3515,6 +3638,36 @@ prepareAuthState_fn = function(_0) {
3515
3638
  return authState;
3516
3639
  });
3517
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
+ };
3518
3671
  prepareLoginState_fn = function(_0, _1) {
3519
3672
  return __async(this, arguments, function* (loginState, {
3520
3673
  useShortUrls: shorten = false,
@@ -7,6 +7,7 @@ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
7
  var __typeError = (msg) => {
8
8
  throw TypeError(msg);
9
9
  };
10
+ var __pow = Math.pow;
10
11
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
12
  var __spreadValues = (a, b) => {
12
13
  for (var prop in b || (b = {}))
@@ -59,6 +60,7 @@ var __async = (__this, __arguments, generator) => {
59
60
  };
60
61
 
61
62
  export {
63
+ __pow,
62
64
  __spreadValues,
63
65
  __spreadProps,
64
66
  __objRest,
@@ -1,5 +1,5 @@
1
- import "./chunk-7B52C2XE.js";
2
- const PARA_CORE_VERSION = "2.0.0-alpha.53";
1
+ import "./chunk-W5CT3TVS.js";
2
+ const PARA_CORE_VERSION = "2.0.0-alpha.54";
3
3
  const PREFIX = "@CAPSULE/";
4
4
  const PARA_PREFIX = "@PARA/";
5
5
  const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
@@ -15,6 +15,8 @@ const LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
15
15
  const LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
16
16
  const LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
17
17
  const LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
18
+ const LOCAL_STORAGE_ENCLAVE_JWT = `${PREFIX}enclaveJwt`;
19
+ const LOCAL_STORAGE_ENCLAVE_REFRESH_JWT = `${PREFIX}enclaveRefreshJwt`;
18
20
  const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
19
21
  const POLLING_INTERVAL_MS = 2e3;
20
22
  const SHORT_POLLING_INTERVAL_MS = 1e3;
@@ -29,6 +31,8 @@ export {
29
31
  LOCAL_STORAGE_CURRENT_WALLET_IDS,
30
32
  LOCAL_STORAGE_ED25519_WALLETS,
31
33
  LOCAL_STORAGE_EMAIL,
34
+ LOCAL_STORAGE_ENCLAVE_JWT,
35
+ LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
32
36
  LOCAL_STORAGE_EXTERNAL_WALLETS,
33
37
  LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID,
34
38
  LOCAL_STORAGE_FARCASTER_USERNAME,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __async
3
- } from "../chunk-7B52C2XE.js";
3
+ } from "../chunk-W5CT3TVS.js";
4
4
  import base64url from "base64url";
5
5
  import forge from "node-forge";
6
6
  import { getPortalBaseURL } from "../utils/index.js";
@@ -1,4 +1,4 @@
1
- import "./chunk-7B52C2XE.js";
1
+ import "./chunk-W5CT3TVS.js";
2
2
  class TransactionReviewError extends Error {
3
3
  constructor(transactionReviewUrl) {
4
4
  super("transaction review error");
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  import axios from "axios";
3
3
  function initClient(baseURL, useAdapter) {
4
4
  const client = axios.create({ baseURL });
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  import Client from "@getpara/user-management-client";
3
3
  import { Environment } from "../types/index.js";
4
4
  function getBaseOAuthUrl(env) {
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./chunk-7B52C2XE.js";
1
+ import "./chunk-W5CT3TVS.js";
2
2
  import { ParaCore } from "./ParaCore.js";
3
3
  import {
4
4
  AuthMethod,
@@ -34,7 +34,7 @@ import {
34
34
  export * from "./types/coreApi.js";
35
35
  export * from "./types/events.js";
36
36
  export * from "./types/config.js";
37
- import { getPortalDomain, entityToWallet, constructUrl, shortenUrl } from "./utils/index.js";
37
+ import { getPortalDomain, dispatchEvent, entityToWallet, constructUrl, shortenUrl } from "./utils/index.js";
38
38
  import { PREFIX, PARA_PREFIX } from "./constants.js";
39
39
  import { distributeNewShare } from "./shares/shareDistribution.js";
40
40
  import { KeyContainer } from "./shares/KeyContainer.js";
@@ -107,6 +107,7 @@ export {
107
107
  decryptWithKeyPair,
108
108
  decryptWithPrivateKey,
109
109
  src_default as default,
110
+ dispatchEvent,
110
111
  distributeNewShare,
111
112
  encodePrivateKeyToPemHex,
112
113
  encryptPrivateKey,
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from "@celo/utils/lib/ecies.js";
3
3
  import * as eutil from "@ethereumjs/util";
4
4
  import * as forge from "node-forge";