@getpara/core-sdk 2.0.0-alpha.62 → 2.0.0-alpha.64

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.
@@ -100,7 +100,7 @@ var import_utils2 = require("./utils/index.js");
100
100
  var import_errors = require("./errors.js");
101
101
  var constants = __toESM(require("./constants.js"));
102
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
+ var _authInfo, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, assertIsLinkingAccount_fn, assertIsLinkingAccountOrStart_fn, getOAuthUrl_fn, waitForLoginProcess_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareDoneState_fn, prepareVerificationState_fn, prepareLoginState_fn, prepareSignUpState_fn;
104
104
  if (typeof global !== "undefined") {
105
105
  global.Buffer = global.Buffer || import_buffer.Buffer;
106
106
  } else if (typeof window !== "undefined") {
@@ -116,6 +116,7 @@ const _ParaCore = class _ParaCore {
116
116
  __privateAdd(this, _ParaCore_instances);
117
117
  this.popupWindow = null;
118
118
  __privateAdd(this, _authInfo);
119
+ // Track expected wallet IDs during wallet switching
119
120
  this.isNativePasskey = false;
120
121
  this.isReady = false;
121
122
  this.accountLinkInProgress = void 0;
@@ -134,20 +135,33 @@ const _ParaCore = class _ParaCore {
134
135
  */
135
136
  this.externalWallets = {};
136
137
  this.onRampPopup = void 0;
138
+ this.nonPersistedStorageKeys = [];
137
139
  this.localStorageGetItem = (key) => {
138
- return this.platformUtils.localStorage.get(key);
140
+ var _a;
141
+ if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
142
+ return this.platformUtils.localStorage.get(key);
143
+ }
139
144
  };
140
145
  this.localStorageSetItem = (key, value) => {
141
- return this.platformUtils.localStorage.set(key, value);
146
+ var _a;
147
+ if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
148
+ return this.platformUtils.localStorage.set(key, value);
149
+ }
142
150
  };
143
151
  this.localStorageRemoveItem = (key) => {
144
152
  return this.platformUtils.localStorage.removeItem(key);
145
153
  };
146
154
  this.sessionStorageGetItem = (key) => {
147
- return this.platformUtils.sessionStorage.get(key);
155
+ var _a;
156
+ if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
157
+ return this.platformUtils.sessionStorage.get(key);
158
+ }
148
159
  };
149
160
  this.sessionStorageSetItem = (key, value) => {
150
- return this.platformUtils.sessionStorage.set(key, value);
161
+ var _a;
162
+ if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
163
+ return this.platformUtils.sessionStorage.set(key, value);
164
+ }
151
165
  };
152
166
  this.sessionStorageRemoveItem = (key) => {
153
167
  return this.platformUtils.sessionStorage.removeItem(key);
@@ -304,7 +318,7 @@ const _ParaCore = class _ParaCore {
304
318
  this.setExternalWallets(_externalWallets);
305
319
  };
306
320
  this.initializeWorker = () => __async(this, null, function* () {
307
- if (!this.isWorkerInitialized && !this.ctx.disableWebSockets && !this.ctx.disableWorkers) {
321
+ if (!this.isWorkerInitialized && !this.ctx.disableWebSockets && !this.ctx.disableWorkers && !this.isPortal()) {
308
322
  try {
309
323
  this.isWorkerInitialized = true;
310
324
  yield this.platformUtils.initializeWorker(this.ctx);
@@ -628,15 +642,7 @@ const _ParaCore = class _ParaCore {
628
642
  };
629
643
  }
630
644
  isPortal(envOverride) {
631
- var _a;
632
- if (typeof window === "undefined") return false;
633
- return !!((_a = window.location) == null ? void 0 : _a.host) && (0, import_utils2.getPortalBaseURL)(envOverride ? { env: envOverride } : this.ctx).includes(window.location.host);
634
- }
635
- isRecoveryPortal(envOverride) {
636
- var _a, _b;
637
- if (typeof window === "undefined") return false;
638
- const normalizedUrl = (_b = (_a = window.location) == null ? void 0 : _a.host) == null ? void 0 : _b.replace("getpara", "usecapsule");
639
- return !!normalizedUrl && (0, import_utils2.getPortalBaseURL)(envOverride ? { env: envOverride } : this.ctx).includes(normalizedUrl);
645
+ return (0, import_utils2.isPortal)(this.ctx, envOverride);
640
646
  }
641
647
  isParaConnect() {
642
648
  var _a;
@@ -761,14 +767,26 @@ const _ParaCore = class _ParaCore {
761
767
  constructPortalUrl(_0) {
762
768
  return __async(this, arguments, function* (type, opts = {}) {
763
769
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
764
- const [isCreate, isLogin, isOnRamp, isOAuth, isOAuthCallback, isTelegramLogin, isFarcasterLogin] = [
770
+ const [
771
+ isCreate,
772
+ isLogin,
773
+ isOnRamp,
774
+ isOAuth,
775
+ isOAuthCallback,
776
+ isTelegramLogin,
777
+ isFarcasterLogin,
778
+ isAddNewCredential,
779
+ isSwitchWallets
780
+ ] = [
765
781
  ["createAuth", "createPassword", "createPIN"].includes(type),
766
- ["loginAuth", "loginPassword", "loginPIN", "loginOTP"].includes(type),
782
+ ["loginAuth", "loginPassword", "loginPIN", "loginOTP", "switchWallets"].includes(type),
767
783
  type === "onRamp",
768
784
  type === "oAuth",
769
785
  type === "oAuthCallback",
770
786
  ["telegramLogin", "telegramLoginVerify"].includes(type),
771
- type === "loginFarcaster"
787
+ type === "loginFarcaster",
788
+ type === "addNewCredential",
789
+ type === "switchWallets"
772
790
  ];
773
791
  if (isOAuth && !opts.oAuthMethod) {
774
792
  throw new Error("oAuthMethod is required for oAuth portal URLs");
@@ -843,6 +861,14 @@ const _ParaCore = class _ParaCore {
843
861
  path = "/auth/farcaster";
844
862
  break;
845
863
  }
864
+ case "switchWallets": {
865
+ path = `/auth/wallets`;
866
+ break;
867
+ }
868
+ case "addNewCredential": {
869
+ path = "/auth/add-new-credential";
870
+ break;
871
+ }
846
872
  default: {
847
873
  throw new Error(`invalid URL type ${type}`);
848
874
  }
@@ -861,8 +887,9 @@ const _ParaCore = class _ParaCore {
861
887
  encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
862
888
  sessionId
863
889
  };
864
- const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
890
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
865
891
  apiKey: this.ctx.apiKey,
892
+ origin: typeof window !== "undefined" ? window.location.origin : void 0,
866
893
  partnerId: partner == null ? void 0 : partner.id,
867
894
  portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font) || (partner == null ? void 0 : partner.font),
868
895
  portalBorderRadius: ((_d = opts.portalTheme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
@@ -874,12 +901,12 @@ const _ParaCore = class _ParaCore {
874
901
  portalTextColor: this.portalTextColor,
875
902
  portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
876
903
  isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
877
- }, isCreate || isLogin ? __spreadProps(__spreadValues({
904
+ }, this.authInfo && (isCreate || isLogin || isAddNewCredential || isOAuthCallback || isSwitchWallets) ? __spreadProps(__spreadValues({
878
905
  authInfo: JSON.stringify(this.authInfo)
879
906
  }, (0, import_user_management_client.isPhone)(this.authInfo.auth) ? (0, import_utils2.splitPhoneNumber)(this.authInfo.auth.phone) : this.authInfo.auth), {
880
907
  pfpUrl: this.authInfo.pfpUrl,
881
908
  displayName: this.authInfo.displayName
882
- }) : {}), isOnRamp ? { origin: typeof window !== "undefined" ? window.location.origin : void 0, email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin ? __spreadProps(__spreadValues({
909
+ }) : {}), isOnRamp ? { email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin || isAddNewCredential ? __spreadProps(__spreadValues({
883
910
  sessionId: thisDevice.sessionId,
884
911
  encryptionKey: thisDevice.encryptionKey
885
912
  }, opts.newDevice ? {
@@ -889,7 +916,10 @@ const _ParaCore = class _ParaCore {
889
916
  pregenIds: JSON.stringify(this.pregenIds)
890
917
  }) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
891
918
  appScheme: opts.appScheme
892
- } : {}), isTelegramLogin ? { isEmbed: "true" } : {}), opts.params || {});
919
+ } : {}), isTelegramLogin ? { isEmbed: "true" } : {}), isSwitchWallets ? __spreadValues(__spreadValues({}, this.currentWalletIds ? { currentWalletIds: JSON.stringify(this.currentWalletIds) } : {}), this.userId ? { userId: this.userId } : {}) : {}), opts.params || {}), isAddNewCredential ? __spreadProps(__spreadValues({}, opts.addNewCredentialType && { addNewCredentialType: opts.addNewCredentialType.toString() }), {
920
+ addNewCredentialPasskeyId: opts.addNewCredentialPasskeyId,
921
+ addNewCredentialPasswordId: opts.addNewCredentialPasswordId
922
+ }) : {});
893
923
  const url = (0, import_utils2.constructUrl)({ base, path, params });
894
924
  if (opts.shorten) {
895
925
  return (0, import_utils2.shortenUrl)(this.ctx, url);
@@ -933,7 +963,7 @@ const _ParaCore = class _ParaCore {
933
963
  throw error;
934
964
  }
935
965
  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) {
936
- if (!session.partnerId && !this.isRecoveryPortal()) {
966
+ if (!session.partnerId && !this.isPortal()) {
937
967
  this.displayModalError(
938
968
  `Invalid API Key. Please ensure you have a valid API key for the current environment: ${(_d = this.ctx.env) == null ? void 0 : _d.toUpperCase()}.`
939
969
  );
@@ -964,6 +994,9 @@ Need help? Visit: https://docs.getpara.com or contact support
964
994
  yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
965
995
  }
966
996
  }
997
+ if (session.currentWalletIds && !(0, import_utils2.currentWalletIdsEq)(session.currentWalletIds, this.currentWalletIds)) {
998
+ yield this.setCurrentWalletIds(session.currentWalletIds);
999
+ }
967
1000
  return session;
968
1001
  });
969
1002
  }
@@ -1424,6 +1457,7 @@ Need help? Visit: https://docs.getpara.com or contact support
1424
1457
  if (!wallet) return null;
1425
1458
  return {
1426
1459
  id: wallet.id,
1460
+ partner: wallet.partner,
1427
1461
  type,
1428
1462
  address: this.getDisplayAddress(id, { addressType: type }),
1429
1463
  name: wallet.name
@@ -1534,7 +1568,7 @@ Need help? Visit: https://docs.getpara.com or contact support
1534
1568
  }
1535
1569
  populateWalletAddresses() {
1536
1570
  return __async(this, null, function* () {
1537
- const res = yield this.ctx.client.getWallets(this.userId, true);
1571
+ const res = yield (this.isPortal() ? this.ctx.client.getAllWallets : this.ctx.client.getWallets)(this.userId, true);
1538
1572
  const wallets = res.data.wallets;
1539
1573
  wallets.forEach((entity) => {
1540
1574
  if (this.wallets[entity.id]) {
@@ -1803,6 +1837,9 @@ Need help? Visit: https://docs.getpara.com or contact support
1803
1837
  if (this.externalWalletConnectionType === "VERIFICATION") {
1804
1838
  return isSessionActive;
1805
1839
  }
1840
+ if (this.walletSwitchIds) {
1841
+ return isSessionActive;
1842
+ }
1806
1843
  return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
1807
1844
  });
1808
1845
  }
@@ -1816,6 +1853,7 @@ Need help? Visit: https://docs.getpara.com or contact support
1816
1853
  }
1817
1854
  /**
1818
1855
  * Get the auth methods available to an existing user
1856
+ * @deprecated Use supportedUserAuthMethods instead
1819
1857
  */
1820
1858
  supportedAuthMethods(auth) {
1821
1859
  return __async(this, null, function* () {
@@ -1834,6 +1872,37 @@ Need help? Visit: https://docs.getpara.com or contact support
1834
1872
  return authMethods;
1835
1873
  });
1836
1874
  }
1875
+ /**
1876
+ * Get the auth methods available to an existing user
1877
+ */
1878
+ supportedUserAuthMethods() {
1879
+ return __async(this, null, function* () {
1880
+ yield this.assertIsAuthSet();
1881
+ const { supportedAuthMethods, hasPasswordWithoutPIN } = yield this.ctx.client.getSupportedAuthMethodsV2(
1882
+ this.authInfo.auth
1883
+ );
1884
+ const authMethods = /* @__PURE__ */ new Set();
1885
+ for (const type of supportedAuthMethods) {
1886
+ switch (type) {
1887
+ case "PASSWORD":
1888
+ if (hasPasswordWithoutPIN) {
1889
+ authMethods.add(import_user_management_client.AuthMethod.PASSWORD);
1890
+ }
1891
+ break;
1892
+ case "PASSKEY":
1893
+ authMethods.add(import_user_management_client.AuthMethod.PASSKEY);
1894
+ break;
1895
+ case "PIN":
1896
+ authMethods.add(import_user_management_client.AuthMethod.PIN);
1897
+ break;
1898
+ case "BASIC_LOGIN":
1899
+ authMethods.add(import_user_management_client.AuthMethod.BASIC_LOGIN);
1900
+ break;
1901
+ }
1902
+ }
1903
+ return authMethods;
1904
+ });
1905
+ }
1837
1906
  /**
1838
1907
  * Get hints associated with the users stored biometrics.
1839
1908
  * @deprecated
@@ -2127,61 +2196,26 @@ Need help? Visit: https://docs.getpara.com or contact support
2127
2196
  * @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
2128
2197
  * @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
2129
2198
  **/
2130
- waitForLogin() {
2131
- return __async(this, arguments, function* ({
2132
- isCanceled = () => false,
2133
- onCancel,
2134
- onPoll,
2135
- skipSessionRefresh = false
2136
- } = {}) {
2137
- const startedAt = Date.now();
2138
- return new Promise((resolve, reject) => {
2139
- (() => __async(this, null, function* () {
2140
- var _a;
2141
- if (!this.isExternalWalletAuth) {
2142
- this.externalWallets = {};
2143
- }
2144
- while (true) {
2145
- if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
2146
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
2147
- onCancel == null ? void 0 : onCancel();
2148
- return reject("canceled");
2149
- }
2150
- yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
2151
- try {
2152
- let session = yield this.touchSession();
2153
- if (!session.isAuthenticated) {
2154
- onPoll == null ? void 0 : onPoll();
2155
- continue;
2156
- }
2157
- session = yield this.userSetupAfterLogin();
2158
- const needsWallet = (_a = session.needsWallet) != null ? _a : false;
2159
- if (!needsWallet) {
2160
- if (this.currentWalletIdsArray.length === 0) {
2161
- onPoll == null ? void 0 : onPoll();
2162
- continue;
2163
- }
2164
- }
2165
- const fetchedWallets = yield this.fetchWallets();
2166
- const tempSharesRes = yield this.getTransmissionKeyShares();
2167
- if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
2168
- yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
2169
- yield this.claimPregenWallets();
2170
- const resp = {
2171
- needsWallet: needsWallet || Object.values(this.wallets).length === 0,
2172
- partnerId: session.partnerId
2173
- };
2174
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp);
2175
- return resolve(resp);
2176
- }
2177
- onPoll == null ? void 0 : onPoll();
2178
- } catch (err) {
2179
- console.error(err);
2180
- onPoll == null ? void 0 : onPoll();
2181
- }
2182
- }
2183
- }))();
2184
- });
2199
+ waitForLogin(args) {
2200
+ return __async(this, null, function* () {
2201
+ return yield __privateMethod(this, _ParaCore_instances, waitForLoginProcess_fn).call(this, args);
2202
+ });
2203
+ }
2204
+ waitForWalletSwitching(args) {
2205
+ return __async(this, null, function* () {
2206
+ return yield __privateMethod(this, _ParaCore_instances, waitForLoginProcess_fn).call(this, __spreadProps(__spreadValues({}, args), { isSwitchingWallets: true }));
2207
+ });
2208
+ }
2209
+ /**
2210
+ * Gets the switch wallets URL for wallet selection.
2211
+ * The authMethod is automatically included in the URL if available.
2212
+ *
2213
+ * @returns {Promise<{ url: string; authMethod: TAuthMethod }>} The switch wallets URL and authMethod
2214
+ */
2215
+ getSwitchWalletsUrl() {
2216
+ return __async(this, null, function* () {
2217
+ const url = yield this.constructPortalUrl("switchWallets");
2218
+ return url;
2185
2219
  });
2186
2220
  }
2187
2221
  /**
@@ -2311,7 +2345,7 @@ Need help? Visit: https://docs.getpara.com or contact support
2311
2345
  break;
2312
2346
  }
2313
2347
  ++maxPolls;
2314
- const res = yield this.ctx.client.getWallets(this.userId);
2348
+ const res = yield (this.isPortal() ? this.ctx.client.getAllWallets : this.ctx.client.getWallets)(this.userId);
2315
2349
  const wallet = res.data.wallets.find((w) => w.id === walletId);
2316
2350
  if (wallet && wallet.address) {
2317
2351
  return;
@@ -3178,49 +3212,80 @@ Need help? Visit: https://docs.getpara.com or contact support
3178
3212
  }
3179
3213
  getNewCredentialAndUrl() {
3180
3214
  return __async(this, arguments, function* ({
3181
- authMethod = "PASSKEY",
3215
+ authMethod: optsAuthMethod,
3182
3216
  isForNewDevice = false,
3183
3217
  portalTheme,
3184
3218
  shorten = false
3185
3219
  } = {}) {
3220
+ const userAuthMethods = yield this.supportedUserAuthMethods();
3221
+ const isEnclaveUser = userAuthMethods.has(import_user_management_client.AuthMethod.BASIC_LOGIN);
3222
+ if (isEnclaveUser) {
3223
+ isForNewDevice = true;
3224
+ }
3225
+ const authMethods = optsAuthMethod ? [optsAuthMethod] : isForNewDevice ? ["PASSKEY", "PIN", "PASSWORD"] : ["PASSKEY"];
3186
3226
  this.assertIsAuthSet();
3187
- let credentialId, urlType;
3188
- switch (authMethod) {
3189
- case "PASSKEY":
3190
- ({
3191
- data: { id: credentialId }
3192
- } = yield this.ctx.client.addSessionPublicKey(this.userId, {
3193
- status: import_user_management_client.AuthMethodStatus.PENDING,
3194
- type: import_user_management_client.PublicKeyType.WEB
3195
- }));
3196
- urlType = "createAuth";
3197
- break;
3198
- case "PASSWORD":
3227
+ const canAddPasswordOrPIN = !userAuthMethods.has(import_user_management_client.AuthMethod.PASSWORD) && !userAuthMethods.has(import_user_management_client.AuthMethod.PIN);
3228
+ let passkeyId, passwordId, urlType;
3229
+ if (authMethods.includes("PASSKEY") && (yield this.isPasskeySupported())) {
3230
+ ({
3231
+ data: { id: passkeyId }
3232
+ } = yield this.ctx.client.addSessionPublicKey(this.userId, {
3233
+ status: import_user_management_client.AuthMethodStatus.PENDING,
3234
+ type: import_user_management_client.PublicKeyType.WEB
3235
+ }));
3236
+ urlType = "createAuth";
3237
+ }
3238
+ if (authMethods.includes("PASSWORD")) {
3239
+ if (!canAddPasswordOrPIN) {
3240
+ if (optsAuthMethod === "PASSWORD") throw new Error("A user cannot have more than one password or PIN.");
3241
+ } else {
3199
3242
  ({
3200
- data: { id: credentialId }
3243
+ data: { id: passwordId }
3201
3244
  } = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
3202
3245
  status: import_user_management_client.AuthMethodStatus.PENDING
3203
3246
  }));
3204
3247
  urlType = "createPassword";
3205
- break;
3206
- case "PIN":
3248
+ }
3249
+ }
3250
+ if (authMethods.includes("PIN")) {
3251
+ if (!canAddPasswordOrPIN) {
3252
+ if (optsAuthMethod === "PIN") throw new Error("A user cannot have more than one password or PIN.");
3253
+ } else {
3207
3254
  ({
3208
- data: { id: credentialId }
3255
+ data: { id: passwordId }
3209
3256
  } = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
3210
3257
  status: import_user_management_client.AuthMethodStatus.PENDING
3211
3258
  }));
3212
3259
  urlType = "createPIN";
3213
- break;
3260
+ }
3261
+ }
3262
+ const credentialId = passkeyId != null ? passkeyId : passwordId;
3263
+ if (this.isNativePasskey && authMethods.includes("PASSKEY")) {
3264
+ return { credentialId };
3214
3265
  }
3215
- const url = this.isNativePasskey && urlType === "createAuth" ? void 0 : yield this.constructPortalUrl(urlType, {
3266
+ const { sessionId } = yield this.touchSession();
3267
+ const url = yield this.constructPortalUrl(isForNewDevice ? "addNewCredential" : urlType, {
3216
3268
  isForNewDevice,
3217
3269
  pathId: credentialId,
3218
3270
  portalTheme,
3219
- shorten
3271
+ shorten,
3272
+ sessionId: isForNewDevice ? sessionId : void 0,
3273
+ addNewCredentialType: optsAuthMethod,
3274
+ addNewCredentialPasskeyId: passkeyId,
3275
+ addNewCredentialPasswordId: passwordId
3220
3276
  });
3221
3277
  return __spreadValues({ credentialId }, url ? { url } : {});
3222
3278
  });
3223
3279
  }
3280
+ addCredential(_0) {
3281
+ return __async(this, arguments, function* ({ authMethod }) {
3282
+ if (authMethod === "PASSKEY" && !(yield this.isPasskeySupported())) {
3283
+ throw new Error("Passkeys are not supported.");
3284
+ }
3285
+ const { url } = yield this.getNewCredentialAndUrl({ isForNewDevice: true, authMethod });
3286
+ return url;
3287
+ });
3288
+ }
3224
3289
  /**
3225
3290
  * Returns a Para Portal URL for logging in with a WebAuth passkey, password, PIN or OTP.
3226
3291
  * @param {Object} opts the options object
@@ -3561,7 +3626,8 @@ getOAuthUrl_fn = function(_0) {
3561
3626
  appScheme,
3562
3627
  accountLinkInProgress,
3563
3628
  sessionLookupId,
3564
- encryptionKey
3629
+ encryptionKey,
3630
+ portalCallbackParams
3565
3631
  }) {
3566
3632
  if (!accountLinkInProgress && !this.isPortal()) {
3567
3633
  return yield this.constructPortalUrl("oAuth", { sessionId: sessionLookupId, oAuthMethod: method, appScheme });
@@ -3575,13 +3641,14 @@ getOAuthUrl_fn = function(_0) {
3575
3641
  path: `/auth/${method.toLowerCase()}`,
3576
3642
  params: __spreadProps(__spreadValues({
3577
3643
  apiKey: this.ctx.apiKey,
3644
+ origin: typeof window !== "undefined" ? window.location.origin : void 0,
3578
3645
  sessionLookupId,
3579
3646
  portalSessionLookupId,
3580
3647
  appScheme
3581
3648
  }, accountLinkInProgress ? {
3582
3649
  linkedAccountId: this.accountLinkInProgress.id
3583
3650
  } : {}), {
3584
- callback: !accountLinkInProgress && (yield this.constructPortalUrl("oAuthCallback", {
3651
+ callback: !accountLinkInProgress && (yield this.constructPortalUrl("oAuthCallback", __spreadValues({
3585
3652
  sessionId: sessionLookupId,
3586
3653
  oAuthMethod: method,
3587
3654
  appScheme,
@@ -3589,11 +3656,97 @@ getOAuthUrl_fn = function(_0) {
3589
3656
  sessionId: sessionLookupId,
3590
3657
  encryptionKey
3591
3658
  }
3592
- }))
3659
+ }, this.isPortal() && { params: portalCallbackParams })))
3593
3660
  })
3594
3661
  });
3595
3662
  });
3596
3663
  };
3664
+ waitForLoginProcess_fn = function() {
3665
+ return __async(this, arguments, function* ({
3666
+ isCanceled = () => false,
3667
+ onCancel,
3668
+ onPoll,
3669
+ skipSessionRefresh = false,
3670
+ isSwitchingWallets = false
3671
+ } = {}) {
3672
+ const startedAt = Date.now();
3673
+ return new Promise((resolve, reject) => {
3674
+ (() => __async(this, null, function* () {
3675
+ var _a;
3676
+ if (!this.isExternalWalletAuth && !isSwitchingWallets) {
3677
+ this.externalWallets = {};
3678
+ }
3679
+ while (true) {
3680
+ if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
3681
+ if (isSwitchingWallets) {
3682
+ this.walletSwitchIds = void 0;
3683
+ } else {
3684
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
3685
+ }
3686
+ onCancel == null ? void 0 : onCancel();
3687
+ return reject("canceled");
3688
+ }
3689
+ yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
3690
+ try {
3691
+ let session = yield this.touchSession();
3692
+ const shouldContinuePolling = !isSwitchingWallets && !session.isAuthenticated || isSwitchingWallets && !this.walletSwitchIds;
3693
+ if (shouldContinuePolling) {
3694
+ onPoll == null ? void 0 : onPoll();
3695
+ continue;
3696
+ }
3697
+ session = yield this.userSetupAfterLogin();
3698
+ const needsWallet = (_a = session.needsWallet) != null ? _a : false;
3699
+ if (isSwitchingWallets) {
3700
+ if (this.walletSwitchIds) {
3701
+ const walletIdsMatch = (0, import_utils2.currentWalletIdsEq)(session.currentWalletIds, this.walletSwitchIds);
3702
+ if (!walletIdsMatch) {
3703
+ onPoll == null ? void 0 : onPoll();
3704
+ continue;
3705
+ }
3706
+ } else {
3707
+ onPoll == null ? void 0 : onPoll();
3708
+ continue;
3709
+ }
3710
+ } else if (!needsWallet) {
3711
+ if (this.currentWalletIdsArray.length === 0) {
3712
+ onPoll == null ? void 0 : onPoll();
3713
+ continue;
3714
+ }
3715
+ }
3716
+ const tempSharesRes = yield this.getTransmissionKeyShares();
3717
+ let hasSharesForCurrentWallets;
3718
+ if (!isSwitchingWallets) {
3719
+ const fetchedWallets = yield this.fetchWallets();
3720
+ hasSharesForCurrentWallets = tempSharesRes.data.temporaryShares.length === fetchedWallets.length;
3721
+ } else {
3722
+ hasSharesForCurrentWallets = this.currentWalletIdsArray.every(([walletId]) => {
3723
+ return tempSharesRes.data.temporaryShares.some((share) => share.walletId === walletId);
3724
+ });
3725
+ }
3726
+ if (hasSharesForCurrentWallets) {
3727
+ yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
3728
+ yield this.claimPregenWallets();
3729
+ const resp = {
3730
+ needsWallet: needsWallet || Object.values(this.wallets).length === 0,
3731
+ partnerId: session.partnerId
3732
+ };
3733
+ if (isSwitchingWallets) {
3734
+ this.walletSwitchIds = void 0;
3735
+ } else {
3736
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp);
3737
+ }
3738
+ return resolve(resp);
3739
+ }
3740
+ onPoll == null ? void 0 : onPoll();
3741
+ } catch (err) {
3742
+ console.error(err);
3743
+ onPoll == null ? void 0 : onPoll();
3744
+ }
3745
+ }
3746
+ }))();
3747
+ });
3748
+ });
3749
+ };
3597
3750
  createPregenWallet_fn = function(opts) {
3598
3751
  return __async(this, null, function* () {
3599
3752
  var _a, _b;
@@ -20,6 +20,7 @@ __export(constants_exports, {
20
20
  ACCOUNT_LINK_CONFLICT: () => ACCOUNT_LINK_CONFLICT,
21
21
  EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID: () => EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
22
22
  LOCAL_STORAGE_AUTH_INFO: () => LOCAL_STORAGE_AUTH_INFO,
23
+ LOCAL_STORAGE_AUTH_METHOD: () => LOCAL_STORAGE_AUTH_METHOD,
23
24
  LOCAL_STORAGE_COUNTRY_CODE: () => LOCAL_STORAGE_COUNTRY_CODE,
24
25
  LOCAL_STORAGE_CURRENT_WALLET_IDS: () => LOCAL_STORAGE_CURRENT_WALLET_IDS,
25
26
  LOCAL_STORAGE_ED25519_WALLETS: () => LOCAL_STORAGE_ED25519_WALLETS,
@@ -43,7 +44,7 @@ __export(constants_exports, {
43
44
  SHORT_POLLING_INTERVAL_MS: () => SHORT_POLLING_INTERVAL_MS
44
45
  });
45
46
  module.exports = __toCommonJS(constants_exports);
46
- const PARA_CORE_VERSION = "2.0.0-alpha.62";
47
+ const PARA_CORE_VERSION = "2.0.0-alpha.64";
47
48
  const PREFIX = "@CAPSULE/";
48
49
  const PARA_PREFIX = "@PARA/";
49
50
  const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
@@ -61,6 +62,7 @@ const LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
61
62
  const LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
62
63
  const LOCAL_STORAGE_ENCLAVE_JWT = `${PREFIX}enclaveJwt`;
63
64
  const LOCAL_STORAGE_ENCLAVE_REFRESH_JWT = `${PREFIX}enclaveRefreshJwt`;
65
+ const LOCAL_STORAGE_AUTH_METHOD = `${PREFIX}authMethod`;
64
66
  const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
65
67
  const POLLING_INTERVAL_MS = 2e3;
66
68
  const SHORT_POLLING_INTERVAL_MS = 1e3;
@@ -72,6 +74,7 @@ const ACCOUNT_LINK_CONFLICT = "Account already linked";
72
74
  ACCOUNT_LINK_CONFLICT,
73
75
  EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
74
76
  LOCAL_STORAGE_AUTH_INFO,
77
+ LOCAL_STORAGE_AUTH_METHOD,
75
78
  LOCAL_STORAGE_COUNTRY_CODE,
76
79
  LOCAL_STORAGE_CURRENT_WALLET_IDS,
77
80
  LOCAL_STORAGE_ED25519_WALLETS,
package/dist/cjs/index.js CHANGED
@@ -37,6 +37,8 @@ __export(src_exports, {
37
37
  EmailTheme: () => import_user_management_client.EmailTheme,
38
38
  KeyContainer: () => import_KeyContainer.KeyContainer,
39
39
  LINKED_ACCOUNT_TYPES: () => import_user_management_client.LINKED_ACCOUNT_TYPES,
40
+ LOCAL_STORAGE_CURRENT_WALLET_IDS: () => import_constants.LOCAL_STORAGE_CURRENT_WALLET_IDS,
41
+ LOCAL_STORAGE_WALLETS: () => import_constants.LOCAL_STORAGE_WALLETS,
40
42
  NON_ED25519: () => import_user_management_client.NON_ED25519,
41
43
  Network: () => import_user_management_client.Network,
42
44
  OAUTH_METHODS: () => import_user_management_client.OAUTH_METHODS,
@@ -85,6 +87,7 @@ __export(src_exports, {
85
87
  getSHA256HashHex: () => import_utils2.getSHA256HashHex,
86
88
  hashPasswordWithSalt: () => import_utils2.hashPasswordWithSalt,
87
89
  initClient: () => import_userManagementClient.initClient,
90
+ isPortal: () => import_utils.isPortal,
88
91
  isWalletSupported: () => import_wallet.isWalletSupported,
89
92
  mpcComputationClient: () => mpcComputationClient,
90
93
  paraVersion: () => paraVersion,
@@ -130,6 +133,8 @@ var src_default = import_ParaCore.ParaCore;
130
133
  EmailTheme,
131
134
  KeyContainer,
132
135
  LINKED_ACCOUNT_TYPES,
136
+ LOCAL_STORAGE_CURRENT_WALLET_IDS,
137
+ LOCAL_STORAGE_WALLETS,
133
138
  NON_ED25519,
134
139
  Network,
135
140
  OAUTH_METHODS,
@@ -177,6 +182,7 @@ var src_default = import_ParaCore.ParaCore;
177
182
  getSHA256HashHex,
178
183
  hashPasswordWithSalt,
179
184
  initClient,
185
+ isPortal,
180
186
  isWalletSupported,
181
187
  mpcComputationClient,
182
188
  paraVersion,
@@ -70,7 +70,8 @@ const PARA_CORE_METHODS = [
70
70
  "getWalletBalance",
71
71
  "issueJwt",
72
72
  "getLinkedAccounts",
73
- "accountLinkInProgress"
73
+ "accountLinkInProgress",
74
+ "addCredential"
74
75
  ];
75
76
  const PARA_INTERNAL_METHODS = [
76
77
  "linkAccount",
@@ -82,7 +83,8 @@ const PARA_INTERNAL_METHODS = [
82
83
  "verifyExternalWalletLink",
83
84
  "accountLinkInProgress",
84
85
  "prepareLogin",
85
- "sendLoginCode"
86
+ "sendLoginCode",
87
+ "supportedUserAuthMethods"
86
88
  ];
87
89
  // Annotate the CommonJS export names for ESM import in node:
88
90
  0 && (module.exports = {
@@ -26,6 +26,7 @@ __reExport(utils_exports, require("./polling.js"), module.exports);
26
26
  __reExport(utils_exports, require("./types.js"), module.exports);
27
27
  __reExport(utils_exports, require("./url.js"), module.exports);
28
28
  __reExport(utils_exports, require("./wallet.js"), module.exports);
29
+ __reExport(utils_exports, require("./window.js"), module.exports);
29
30
  // Annotate the CommonJS export names for ESM import in node:
30
31
  0 && (module.exports = {
31
32
  ...require("./autobind.js"),
@@ -39,5 +40,6 @@ __reExport(utils_exports, require("./wallet.js"), module.exports);
39
40
  ...require("./polling.js"),
40
41
  ...require("./types.js"),
41
42
  ...require("./url.js"),
42
- ...require("./wallet.js")
43
+ ...require("./wallet.js"),
44
+ ...require("./window.js")
43
45
  });