@getpara/core-sdk 1.12.0 → 2.0.0-alpha.10

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 (55) hide show
  1. package/dist/cjs/ParaCore.js +942 -975
  2. package/dist/cjs/constants.js +7 -1
  3. package/dist/cjs/index.js +15 -3
  4. package/dist/cjs/types/coreApi.js +74 -0
  5. package/dist/cjs/types/events.js +1 -0
  6. package/dist/cjs/types/index.js +4 -2
  7. package/dist/cjs/types/{params.js → methods.js} +2 -2
  8. package/dist/cjs/utils/autobind.js +41 -0
  9. package/dist/cjs/utils/formatting.js +0 -12
  10. package/dist/cjs/utils/index.js +10 -0
  11. package/dist/cjs/utils/json.js +37 -0
  12. package/dist/cjs/utils/listeners.js +2 -11
  13. package/dist/cjs/utils/phone.js +73 -0
  14. package/dist/cjs/utils/types.js +29 -0
  15. package/dist/cjs/utils/url.js +34 -2
  16. package/dist/cjs/utils/wallet.js +30 -17
  17. package/dist/esm/ParaCore.js +959 -980
  18. package/dist/esm/constants.js +5 -1
  19. package/dist/esm/index.js +12 -3
  20. package/dist/esm/types/coreApi.js +52 -0
  21. package/dist/esm/types/events.js +1 -0
  22. package/dist/esm/types/index.js +2 -1
  23. package/dist/esm/utils/autobind.js +19 -0
  24. package/dist/esm/utils/formatting.js +0 -10
  25. package/dist/esm/utils/index.js +5 -0
  26. package/dist/esm/utils/json.js +15 -0
  27. package/dist/esm/utils/listeners.js +2 -11
  28. package/dist/esm/utils/phone.js +39 -0
  29. package/dist/esm/utils/types.js +7 -0
  30. package/dist/esm/utils/url.js +15 -2
  31. package/dist/esm/utils/wallet.js +27 -16
  32. package/dist/types/ParaCore.d.ts +100 -391
  33. package/dist/types/PlatformUtils.d.ts +3 -3
  34. package/dist/types/constants.d.ts +2 -0
  35. package/dist/types/external/userManagementClient.d.ts +1 -1
  36. package/dist/types/index.d.ts +5 -3
  37. package/dist/types/types/config.d.ts +4 -24
  38. package/dist/types/types/coreApi.d.ts +475 -0
  39. package/dist/types/types/events.d.ts +4 -1
  40. package/dist/types/types/index.d.ts +2 -1
  41. package/dist/types/types/methods.d.ts +148 -0
  42. package/dist/types/types/onRamps.d.ts +3 -3
  43. package/dist/types/types/wallet.d.ts +4 -4
  44. package/dist/types/utils/autobind.d.ts +1 -0
  45. package/dist/types/utils/formatting.d.ts +2 -4
  46. package/dist/types/utils/index.d.ts +5 -0
  47. package/dist/types/utils/json.d.ts +1 -0
  48. package/dist/types/utils/onRamps.d.ts +3 -3
  49. package/dist/types/utils/phone.d.ts +11 -0
  50. package/dist/types/utils/types.d.ts +2 -0
  51. package/dist/types/utils/url.d.ts +2 -1
  52. package/dist/types/utils/wallet.d.ts +9 -7
  53. package/package.json +4 -3
  54. package/dist/types/types/params.d.ts +0 -73
  55. /package/dist/esm/types/{params.js → methods.js} +0 -0
@@ -95,13 +95,11 @@ var import_userManagementClient = require("./external/userManagementClient.js");
95
95
  var mpcComputationClient = __toESM(require("./external/mpcComputationClient.js"));
96
96
  var import_shareDistribution = require("./shares/shareDistribution.js");
97
97
  var import_types = require("./types/index.js");
98
- var transmissionUtils = __toESM(require("./transmission/transmissionUtils.js"));
99
98
  var import_recovery = require("./shares/recovery.js");
100
99
  var import_utils2 = require("./utils/index.js");
101
100
  var import_errors = require("./errors.js");
102
101
  var constants = __toESM(require("./constants.js"));
103
- var import_listeners = require("./utils/listeners.js");
104
- var _supportedWalletTypes, _supportedWalletTypesOpt, _ParaCore_instances, createPregenWallet_fn;
102
+ var _authInfo, _partner, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareLogin_fn, prepareLoginState_fn, prepareSignUpState_fn;
105
103
  if (typeof global !== "undefined") {
106
104
  global.Buffer = global.Buffer || import_buffer.Buffer;
107
105
  } else if (typeof window !== "undefined") {
@@ -122,6 +120,9 @@ const _ParaCore = class _ParaCore {
122
120
  */
123
121
  constructor(env, apiKey, opts) {
124
122
  __privateAdd(this, _ParaCore_instances);
123
+ __privateAdd(this, _authInfo);
124
+ this.isNativePasskey = false;
125
+ __privateAdd(this, _partner);
125
126
  this.isAwaitingAccountCreation = false;
126
127
  this.isAwaitingLogin = false;
127
128
  this.isAwaitingFarcaster = false;
@@ -130,14 +131,19 @@ const _ParaCore = class _ParaCore {
130
131
  * The IDs of the currently active wallets, for each supported wallet type. Any signer integrations will default to the first viable wallet ID in this dictionary.
131
132
  */
132
133
  this.currentWalletIds = {};
133
- __privateAdd(this, _supportedWalletTypes);
134
- __privateAdd(this, _supportedWalletTypesOpt);
134
+ /**
135
+ * Wallets associated with the `ParaCore` instance.
136
+ */
137
+ this.externalWallets = {};
135
138
  this.localStorageGetItem = (key) => {
136
139
  return this.platformUtils.localStorage.get(key);
137
140
  };
138
141
  this.localStorageSetItem = (key, value) => {
139
142
  return this.platformUtils.localStorage.set(key, value);
140
143
  };
144
+ this.localStorageRemoveItem = (key) => {
145
+ return this.platformUtils.localStorage.removeItem(key);
146
+ };
141
147
  this.sessionStorageGetItem = (key) => {
142
148
  return this.platformUtils.sessionStorage.get(key);
143
149
  };
@@ -194,38 +200,41 @@ const _ParaCore = class _ParaCore {
194
200
  }
195
201
  };
196
202
  this.initializeFromStorage = () => {
197
- this.updateEmailFromStorage();
198
- this.updateCountryCodeFromStorage();
199
- this.updatePhoneFromStorage();
203
+ this.updateExternalWalletsFromStorage();
204
+ this.updateAuthInfoFromStorage();
200
205
  this.updateUserIdFromStorage();
201
- this.updateTelegramUserIdFromStorage();
202
206
  this.updateWalletsFromStorage();
203
207
  this.updateWalletIdsFromStorage();
204
208
  this.updateSessionCookieFromStorage();
205
209
  this.updateLoginEncryptionKeyPairFromStorage();
206
- this.updateExternalWalletsFromStorage();
207
210
  };
208
- this.updateTelegramUserIdFromStorage = () => {
209
- this.telegramUserId = this.localStorageGetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0;
211
+ this.updateAuthInfoFromStorage = () => {
212
+ var _a;
213
+ const storageAuthInfo = this.localStorageGetItem(constants.LOCAL_STORAGE_AUTH_INFO) || void 0;
214
+ let authInfo = (0, import_utils2.jsonParse)(storageAuthInfo);
215
+ if (!authInfo) {
216
+ const authParams = {
217
+ email: this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL) || void 0,
218
+ phone: this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE) || void 0,
219
+ countryCode: this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE) || void 0,
220
+ farcasterUsername: this.localStorageGetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME) || void 0,
221
+ telegramUserId: this.localStorageGetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0,
222
+ // Using id here since we store the bech32 address for cosmos in the address field of the wallet
223
+ externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
224
+ };
225
+ authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
226
+ }
227
+ __privateSet(this, _authInfo, authInfo);
210
228
  };
211
229
  this.updateUserIdFromStorage = () => {
212
230
  this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
213
231
  };
214
- this.updatePhoneFromStorage = () => {
215
- this.phone = this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE) || void 0;
216
- };
217
- this.updateCountryCodeFromStorage = () => {
218
- this.countryCode = this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE) || void 0;
219
- };
220
- this.updateEmailFromStorage = () => {
221
- this.email = this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL) || void 0;
222
- };
223
232
  this.updateWalletsFromStorage = () => __async(this, null, function* () {
224
233
  var _a;
225
234
  const _currentWalletIds = (_a = this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
226
235
  const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
227
236
  const fromJson = JSON.parse(_currentWalletIds);
228
- return Array.isArray(fromJson) ? Object.keys(import_user_management_client.WalletType).reduce((acc, type) => {
237
+ return Array.isArray(fromJson) ? import_user_management_client.WALLET_TYPES.reduce((acc, type) => {
229
238
  const wallet = Object.values(this.wallets).find(
230
239
  (w) => fromJson.includes(w.id) && import_utils2.WalletSchemeTypeMap[w.scheme][type]
231
240
  );
@@ -249,9 +258,9 @@ const _ParaCore = class _ParaCore {
249
258
  this.updateWalletIdsFromStorage = () => {
250
259
  var _a;
251
260
  const _currentWalletIds = (_a = this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
252
- const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
261
+ const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
253
262
  const fromJson = JSON.parse(_currentWalletIds);
254
- return Array.isArray(fromJson) ? Object.keys(import_user_management_client.WalletType).reduce((acc, type) => {
263
+ return Array.isArray(fromJson) ? import_user_management_client.WALLET_TYPES.reduce((acc, type) => {
255
264
  const wallet = Object.values(this.wallets).find(
256
265
  (w) => fromJson.includes(w.id) && import_utils2.WalletSchemeTypeMap[w.scheme][type]
257
266
  );
@@ -286,12 +295,16 @@ const _ParaCore = class _ParaCore {
286
295
  * @deprecated alias for `createWalletPerType`
287
296
  **/
288
297
  this.createWalletPerMissingType = this.createWalletPerType;
289
- this.getWalletBalance = (_0) => __async(this, [_0], function* ({ walletId, rpcUrl }) {
290
- if (!this.userId) {
291
- throw new Error("a user id is required to get a wallet balance");
292
- }
293
- return (yield this.ctx.client.getWalletBalance({ userId: this.userId, walletId, rpcUrl })).balance;
298
+ __privateAdd(this, _isCreateGuestWalletsPending, false);
299
+ this.getWalletBalance = (_0) => __async(this, [_0], function* ({
300
+ walletId,
301
+ rpcUrl
302
+ }) {
303
+ return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
294
304
  });
305
+ if (!apiKey) {
306
+ throw new Error("A Para API key is required.");
307
+ }
295
308
  if (!opts) opts = {};
296
309
  let isE2E = false;
297
310
  if (env === "E2E") {
@@ -350,49 +363,27 @@ const _ParaCore = class _ParaCore {
350
363
  useDKLS: opts.useDKLSForCreation || !opts.offloadMPCComputationURL,
351
364
  disableWebSockets: !!opts.disableWebSockets,
352
365
  wasmOverride: opts.wasmOverride,
353
- cosmosPrefix: this.cosmosPrefix,
354
366
  isE2E
355
367
  };
356
368
  if (opts.offloadMPCComputationURL) {
357
369
  this.ctx.mpcComputationClient = mpcComputationClient.initClient(opts.offloadMPCComputationURL, opts.disableWorkers);
358
370
  }
359
- try {
360
- __privateSet(this, _supportedWalletTypes, opts.supportedWalletTypes ? (() => {
361
- if (Object.values(opts.supportedWalletTypes).every(
362
- (config) => !!config && typeof config === "object" && config.optional
363
- )) {
364
- throw new Error("at least one wallet type must be non-optional");
365
- }
366
- if (!Object.keys(opts.supportedWalletTypes).every((type) => Object.values(import_user_management_client.WalletType).includes(type))) {
367
- throw new Error("unsupported wallet type");
368
- }
369
- __privateSet(this, _supportedWalletTypesOpt, opts.supportedWalletTypes);
370
- return Object.entries(opts.supportedWalletTypes).reduce((acc, [key, value]) => {
371
- var _a;
372
- if (!value) {
373
- return acc;
374
- }
375
- if (key === import_user_management_client.WalletType.COSMOS && typeof value === "object" && !!value.prefix) {
376
- this.cosmosPrefix = value.prefix;
377
- }
378
- return [...acc, { type: key, optional: value === true ? false : (_a = value.optional) != null ? _a : false }];
379
- }, []);
380
- })() : void 0);
381
- } catch (e) {
382
- __privateSet(this, _supportedWalletTypes, void 0);
383
- }
384
371
  if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
385
372
  return;
386
373
  }
387
374
  this.initializeFromStorage();
388
- import_listeners.setupListeners.bind(this)();
375
+ import_utils2.setupListeners.bind(this)();
376
+ (0, import_utils2.autoBind)(this);
389
377
  if (env !== import_types.Environment.PROD) {
390
378
  this.wrapMethodsWithErrorTracking([
391
- "createUser",
392
- "initiateUserLoginV2",
393
- "waitForPasskeyAndCreateWallet",
394
- "waitForOAuth",
395
- "waitForLoginAndSetup",
379
+ "signUpOrLogIn",
380
+ "verifyNewAccount",
381
+ "waitForLogin",
382
+ "waitForSignup",
383
+ "waitForWalletCreation",
384
+ "verifyOAuth",
385
+ "verifyTelegram",
386
+ "verifyFarcaster",
396
387
  "createPregenWallet",
397
388
  "claimPregenWallets",
398
389
  "signMessage",
@@ -400,35 +391,75 @@ const _ParaCore = class _ParaCore {
400
391
  ]);
401
392
  }
402
393
  }
403
- get isEmail() {
404
- return !!this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.telegramUserId && !this.externalWalletWithParaAuth;
394
+ get authInfo() {
395
+ return __privateGet(this, _authInfo);
405
396
  }
406
- get isPhone() {
407
- return !!this.phone && !!this.countryCode && !this.email && !this.farcasterUsername && !this.telegramUserId && !this.externalWalletWithParaAuth;
397
+ get email() {
398
+ var _a;
399
+ return (0, import_user_management_client.isEmail)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.email : void 0;
408
400
  }
409
- get isFarcaster() {
410
- return !!this.farcasterUsername && !this.email && !this.phone && !this.countryCode && !this.telegramUserId && !this.externalWalletWithParaAuth;
401
+ get phone() {
402
+ var _a;
403
+ return (0, import_user_management_client.isPhone)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.phone : void 0;
411
404
  }
412
- get isTelegram() {
413
- return !!this.telegramUserId && !this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.externalWalletWithParaAuth;
405
+ get farcasterUsername() {
406
+ var _a;
407
+ return (0, import_user_management_client.isFarcaster)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.farcasterUsername : void 0;
408
+ }
409
+ get telegramUserId() {
410
+ var _a;
411
+ return (0, import_user_management_client.isTelegram)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.telegramUserId : void 0;
414
412
  }
415
413
  get externalWalletWithParaAuth() {
416
414
  const externalWallets = Object.values(this.externalWallets);
417
415
  return externalWallets.find((w) => w.isExternalWithParaAuth);
418
416
  }
417
+ get externalWalletConnectionType() {
418
+ if (this.isExternalWalletAuth) {
419
+ return "AUTHENTICATED";
420
+ } else if (!!Object.keys(this.externalWallets).length) {
421
+ return "CONNECTION_ONLY";
422
+ }
423
+ return "NONE";
424
+ }
425
+ get isEmail() {
426
+ var _a;
427
+ return (0, import_user_management_client.isEmail)((_a = this.authInfo) == null ? void 0 : _a.auth);
428
+ }
429
+ get isPhone() {
430
+ var _a;
431
+ return (0, import_user_management_client.isPhone)((_a = this.authInfo) == null ? void 0 : _a.auth);
432
+ }
433
+ get isFarcaster() {
434
+ var _a;
435
+ return (0, import_user_management_client.isFarcaster)((_a = this.authInfo) == null ? void 0 : _a.auth);
436
+ }
437
+ get isTelegram() {
438
+ var _a;
439
+ return (0, import_user_management_client.isTelegram)((_a = this.authInfo) == null ? void 0 : _a.auth);
440
+ }
419
441
  get isExternalWalletAuth() {
420
- return !!this.externalWalletWithParaAuth && !this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.telegramUserId;
442
+ var _a;
443
+ return (0, import_user_management_client.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth);
444
+ }
445
+ get partnerId() {
446
+ var _a;
447
+ return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id;
421
448
  }
422
449
  get currentWalletIdsArray() {
423
- return this.supportedWalletTypes.reduce((acc, { type }) => {
424
- var _a;
425
- return [
426
- ...acc,
427
- ...((_a = this.currentWalletIds[type]) != null ? _a : []).map((id) => {
428
- return [id, type];
429
- })
430
- ];
431
- }, []);
450
+ var _a, _b;
451
+ return ((_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
452
+ (acc, { type }) => {
453
+ var _a2;
454
+ return [
455
+ ...acc,
456
+ ...((_a2 = this.currentWalletIds[type]) != null ? _a2 : []).map((id) => {
457
+ return [id, type];
458
+ })
459
+ ];
460
+ },
461
+ []
462
+ );
432
463
  }
433
464
  get currentWalletIdsUnique() {
434
465
  return [...new Set(Object.values(this.currentWalletIds).flat())];
@@ -453,17 +484,23 @@ const _ParaCore = class _ParaCore {
453
484
  * Whether the instance has multiple wallets connected.
454
485
  */
455
486
  get isMultiWallet() {
456
- return this.currentWalletIdsArray.length > 1;
487
+ return this.currentWalletIdsArray.length > 1 || __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 1;
457
488
  }
458
489
  get isNoWalletConfig() {
459
- return !!__privateGet(this, _supportedWalletTypes) && __privateGet(this, _supportedWalletTypes).length === 0;
490
+ var _a;
491
+ return !!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) && __privateGet(this, _partner).supportedWalletTypes.length === 0;
460
492
  }
461
493
  get supportedWalletTypes() {
494
+ var _a, _b;
495
+ return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
496
+ }
497
+ get cosmosPrefix() {
462
498
  var _a;
463
- return (_a = __privateGet(this, _supportedWalletTypes)) != null ? _a : [];
499
+ return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
464
500
  }
465
501
  get isWalletTypeEnabled() {
466
- return this.supportedWalletTypes.reduce((acc, { type }) => {
502
+ var _a;
503
+ return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
467
504
  return __spreadProps(__spreadValues({}, acc), { [type]: true });
468
505
  }, {});
469
506
  }
@@ -512,7 +549,7 @@ const _ParaCore = class _ParaCore {
512
549
  }
513
550
  isWalletSupported(wallet) {
514
551
  var _a, _b;
515
- return !__privateGet(this, _supportedWalletTypes) || (0, import_utils2.isWalletSupported)((_b = (_a = this.supportedWalletTypes) == null ? void 0 : _a.map(({ type }) => type)) != null ? _b : [], wallet);
552
+ return !((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || (0, import_utils2.isWalletSupported)((_b = __privateGet(this, _partner).supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
516
553
  }
517
554
  isWalletOwned(wallet) {
518
555
  return this.isWalletSupported(wallet) && !(wallet == null ? void 0 : wallet.pregenIdentifier) && !(wallet == null ? void 0 : wallet.pregenIdentifierType) && !!this.userId && (wallet == null ? void 0 : wallet.userId) === this.userId;
@@ -528,7 +565,7 @@ const _ParaCore = class _ParaCore {
528
565
  ));
529
566
  }
530
567
  isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
531
- var _a;
568
+ var _a, _b;
532
569
  let error;
533
570
  if ((_a = this.externalWallets) == null ? void 0 : _a[walletId]) {
534
571
  return true;
@@ -538,15 +575,15 @@ const _ParaCore = class _ParaCore {
538
575
  } else {
539
576
  const wallet = this.wallets[walletId];
540
577
  const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
541
- if (forbidPregen && isUnclaimed) {
578
+ if (forbidPregen && isUnclaimed && wallet.pregenIdentifierType !== "GUEST_ID") {
542
579
  error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
543
580
  } else if (!isOwned && !isUnclaimed) {
544
581
  error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
545
582
  } else if (!this.isWalletSupported(wallet)) {
546
- error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} is not supported, supported types are: ${this.supportedWalletTypes.map(({ type }) => type).join(", ")}`;
583
+ error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || []).map(({ type }) => type).join(", ")}`;
547
584
  } else if (types && (!(0, import_utils2.getEquivalentTypes)(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
548
- var _a2, _b;
549
- return (_b = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b.includes(walletId);
585
+ var _a2, _b2;
586
+ return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
550
587
  }))) {
551
588
  error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
552
589
  } else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
@@ -566,14 +603,17 @@ const _ParaCore = class _ParaCore {
566
603
  * @param {string} walletId the ID of the wallet address to display.
567
604
  * @param {object} options additional options for formatting the address.
568
605
  * @param {boolean} options.truncate whether to truncate the address.
569
- * @param {WalletType} options.addressType the type of address to display.
606
+ * @param {TWalletType} options.addressType the type of address to display.
570
607
  * @returns the formatted address
571
608
  */
572
609
  getDisplayAddress(walletId, options = {}) {
573
- var _a, _b;
610
+ var _a, _b, _c, _d;
574
611
  if (this.externalWallets[walletId]) {
575
612
  const wallet2 = this.externalWallets[walletId];
576
- return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, { prefix: this.cosmosPrefix, targetLength: options.targetLength }) : wallet2.address;
613
+ return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, {
614
+ prefix: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix,
615
+ targetLength: options.targetLength
616
+ }) : wallet2.address;
577
617
  }
578
618
  const wallet = this.findWallet(walletId, options.addressType);
579
619
  if (!wallet) {
@@ -582,8 +622,8 @@ const _ParaCore = class _ParaCore {
582
622
  let str;
583
623
  let prefix;
584
624
  switch (wallet.type) {
585
- case import_user_management_client.WalletType.COSMOS:
586
- prefix = (_b = (_a = options.cosmosPrefix) != null ? _a : this.cosmosPrefix) != null ? _b : "cosmos";
625
+ case "COSMOS":
626
+ prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
587
627
  str = (0, import_utils2.getCosmosAddress)(wallet.publicKey, prefix);
588
628
  break;
589
629
  default:
@@ -616,8 +656,24 @@ const _ParaCore = class _ParaCore {
616
656
  }
617
657
  constructPortalUrl(_0) {
618
658
  return __async(this, arguments, function* (type, opts = {}) {
619
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
620
- const base = type === "onRamp" ? (0, import_utils2.getPortalBaseURL)(this.ctx) : yield this.getPortalURL(opts.partnerId);
659
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
660
+ const [isCreate, isLogin, isOnRamp] = [
661
+ ["createAuth", "createPassword"].includes(type),
662
+ ["loginAuth", "loginPassword"].includes(type),
663
+ type === "onRamp"
664
+ ];
665
+ if (isCreate || isLogin) {
666
+ this.assertIsAuthSet();
667
+ }
668
+ let sessionId = opts.sessionId;
669
+ if ((isLogin || isOnRamp) && !sessionId) {
670
+ const session = yield this.touchSession(true);
671
+ sessionId = session.sessionId;
672
+ }
673
+ if (!this.loginEncryptionKeyPair) {
674
+ yield this.setLoginEncryptionKeyPair();
675
+ }
676
+ const base = type === "onRamp" ? (0, import_utils2.getPortalBaseURL)(this.ctx) : yield this.getPortalURL();
621
677
  let path;
622
678
  switch (type) {
623
679
  case "createPassword": {
@@ -648,61 +704,55 @@ const _ParaCore = class _ParaCore {
648
704
  throw new Error(`invalid URL type ${type}`);
649
705
  }
650
706
  }
651
- const [isCreate, isLogin, isOnRamp] = [
652
- ["createAuth", "createPassword"].includes(type),
653
- ["loginAuth", "loginPassword"].includes(type),
654
- type === "onRamp"
655
- ];
656
- const partner = opts.partnerId ? (_a = (yield this.ctx.client.getPartner(opts.partnerId)).data) == null ? void 0 : _a.partner : void 0;
707
+ const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
708
+ const thisDevice = (_a = opts.thisDevice) != null ? _a : {
709
+ encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
710
+ sessionId
711
+ };
657
712
  const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
658
713
  apiKey: this.ctx.apiKey,
659
- partnerId: opts.partnerId,
660
- portalFont: ((_b = opts.theme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
661
- portalBorderRadius: ((_d = opts.theme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
662
- portalThemeMode: ((_f = opts.theme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
663
- portalAccentColor: ((_h = opts.theme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
664
- portalForegroundColor: ((_j = opts.theme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
665
- portalBackgroundColor: ((_l = opts.theme) == null ? void 0 : _l.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor || ((_m = this.portalTheme) == null ? void 0 : _m.backgroundColor),
714
+ partnerId: partner.id,
715
+ portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
716
+ portalBorderRadius: ((_d = opts.portalTheme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
717
+ portalThemeMode: ((_f = opts.portalTheme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
718
+ portalAccentColor: ((_h = opts.portalTheme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
719
+ portalForegroundColor: ((_j = opts.portalTheme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
720
+ portalBackgroundColor: ((_l = opts.portalTheme) == null ? void 0 : _l.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor || ((_m = this.portalTheme) == null ? void 0 : _m.backgroundColor),
666
721
  portalPrimaryButtonColor: this.portalPrimaryButtonColor,
667
722
  portalTextColor: this.portalTextColor,
668
723
  portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
669
- isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0,
670
- supportedWalletTypes: __privateGet(this, _supportedWalletTypesOpt) ? JSON.stringify(__privateGet(this, _supportedWalletTypesOpt)) : void 0
671
- }, isCreate || isLogin ? __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, opts.authType === "email" ? { email: this.email } : {}), opts.authType === "phone" ? { phone: this.phone, countryCode: this.countryCode } : {}), opts.authType === "farcaster" ? { farcasterUsername: this.farcasterUsername } : {}), opts.authType === "telegram" ? { telegramUserId: this.telegramUserId } : {}), opts.authType === "externalWallet" ? {
672
- // Using id here since we store the bech32 address for cosmos in the address field of the wallet
673
- externalWalletAddress: (_n = this.externalWalletWithParaAuth) == null ? void 0 : _n.id
674
- } : {}) : {}), isLogin || isOnRamp ? { sessionId: opts.sessionId } : {}), isLogin ? {
675
- encryptionKey: opts.loginEncryptionPublicKey,
676
- newDeviceSessionLookupId: opts.newDeviceSessionId,
677
- newDeviceEncryptionKey: opts.newDeviceEncryptionKey,
678
- pregenIds: JSON.stringify(this.pregenIds),
679
- displayName: opts.displayName,
680
- pfpUrl: opts.pfpUrl
681
- } : {}), opts.params || {});
682
- return (0, import_utils2.constructUrl)({ base, path, params });
724
+ isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
725
+ }, isCreate || isLogin ? __spreadProps(__spreadValues({
726
+ authInfo: JSON.stringify(this.authInfo)
727
+ }, (0, import_user_management_client.isPhone)(this.authInfo.auth) ? (0, import_utils2.splitPhoneNumber)(this.authInfo.auth.phone) : this.authInfo.auth), {
728
+ pfpUrl: this.authInfo.pfpUrl,
729
+ displayName: this.authInfo.displayName
730
+ }) : {}), isOnRamp ? { sessionId } : {}), isLogin ? __spreadProps(__spreadValues({
731
+ sessionId: thisDevice.sessionId,
732
+ encryptionKey: thisDevice.encryptionKey
733
+ }, opts.newDevice ? {
734
+ newDeviceSessionLookupId: opts.newDevice.sessionId,
735
+ newDeviceEncryptionKey: opts.newDevice.encryptionKey
736
+ } : {}), {
737
+ pregenIds: JSON.stringify(this.pregenIds)
738
+ }) : {}), opts.params || {});
739
+ const url = (0, import_utils2.constructUrl)({ base, path, params });
740
+ if (opts.shorten) {
741
+ return (0, import_utils2.shortenUrl)(this.ctx, url);
742
+ }
743
+ return url;
683
744
  });
684
745
  }
685
746
  touchSession(regenerate = false) {
686
747
  return __async(this, null, function* () {
687
- const res = yield this.ctx.client.touchSession(regenerate);
688
- this.setSupportedWalletTypes(res.data.supportedWalletTypes, res.data.cosmosPrefix);
689
- return res;
748
+ var _a, _b, _c;
749
+ const session = yield this.ctx.client.touchSession(regenerate);
750
+ if (!__privateGet(this, _partner) || ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) !== session.partnerId || !(0, import_utils2.supportedWalletTypesEq)(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
751
+ yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
752
+ }
753
+ return session;
690
754
  });
691
755
  }
692
- setSupportedWalletTypes(supportedWalletTypes, cosmosPrefix) {
693
- if (supportedWalletTypes && !__privateGet(this, _supportedWalletTypes)) {
694
- __privateSet(this, _supportedWalletTypes, supportedWalletTypes);
695
- Object.keys(this.currentWalletIds).forEach((type) => {
696
- var _a;
697
- if (!((_a = __privateGet(this, _supportedWalletTypes)) == null ? void 0 : _a.some(({ type: supportedType }) => supportedType === type))) {
698
- delete this.currentWalletIds[type];
699
- }
700
- });
701
- }
702
- if (cosmosPrefix && !this.cosmosPrefix) {
703
- this.cosmosPrefix = cosmosPrefix;
704
- }
705
- }
706
756
  getVerificationEmailProps() {
707
757
  return {
708
758
  brandColor: this.emailPrimaryColor,
@@ -732,12 +782,26 @@ const _ParaCore = class _ParaCore {
732
782
  */
733
783
  init() {
734
784
  return __async(this, null, function* () {
735
- var _a;
736
- this.email = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL)) || void 0;
737
- this.countryCode = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE)) || void 0;
738
- this.phone = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE)) || void 0;
785
+ var _a, _b;
739
786
  this.userId = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID)) || void 0;
740
- this.telegramUserId = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0;
787
+ const storageAuthInfo = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_AUTH_INFO)) || void 0;
788
+ const stringExternalWallets = yield this.localStorageGetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS);
789
+ const _externalWallets = JSON.parse(stringExternalWallets || "{}");
790
+ yield this.setExternalWallets(_externalWallets);
791
+ let authInfo = (0, import_utils2.jsonParse)(storageAuthInfo);
792
+ if (!authInfo) {
793
+ const authParams = {
794
+ email: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL)) || void 0,
795
+ phone: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE)) || void 0,
796
+ countryCode: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE)) || void 0,
797
+ farcasterUsername: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME)) || void 0,
798
+ telegramUserId: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0,
799
+ // Using id here since we store the bech32 address for cosmos in the address field of the wallet
800
+ externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
801
+ };
802
+ authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
803
+ }
804
+ __privateSet(this, _authInfo, authInfo);
741
805
  const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_WALLETS);
742
806
  const _wallets = JSON.parse(stringWallets || "{}");
743
807
  const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_ED25519_WALLETS);
@@ -750,10 +814,10 @@ const _ParaCore = class _ParaCore {
750
814
  return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: (0, import_utils2.migrateWallet)(_ed25519Wallets[key]) } : {});
751
815
  }, {}));
752
816
  yield this.setWallets(wallets);
753
- const _currentWalletIds = (_a = yield this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
817
+ const _currentWalletIds = (_b = yield this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _b : void 0;
754
818
  const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
755
819
  const fromJson = JSON.parse(_currentWalletIds);
756
- return Array.isArray(fromJson) ? Object.keys(import_user_management_client.WalletType).reduce((acc, type) => {
820
+ return Array.isArray(fromJson) ? import_user_management_client.WALLET_TYPES.reduce((acc, type) => {
757
821
  const wallet = Object.values(this.wallets).find(
758
822
  (w) => fromJson.includes(w.id) && import_utils2.WalletSchemeTypeMap[w.scheme][type]
759
823
  );
@@ -769,21 +833,42 @@ const _ParaCore = class _ParaCore {
769
833
  if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
770
834
  this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
771
835
  }
772
- const stringExternalWallets = yield this.localStorageGetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS);
773
- const _externalWallets = JSON.parse(stringExternalWallets || "{}");
774
- yield this.setExternalWallets(_externalWallets);
775
- import_listeners.setupListeners.bind(this)();
836
+ import_utils2.setupListeners.bind(this)();
776
837
  yield this.touchSession();
777
838
  });
778
839
  }
840
+ setAuth(_0) {
841
+ return __async(this, arguments, function* (auth, { extras = {}, userId } = {}) {
842
+ const authInfo = __spreadValues(__spreadValues({}, (0, import_user_management_client.extractAuthInfo)(auth, { isRequired: true })), extras || {});
843
+ yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
844
+ if (!!userId) {
845
+ yield this.setUserId(userId);
846
+ }
847
+ return __privateGet(this, _authInfo);
848
+ });
849
+ }
850
+ assertUserId() {
851
+ if (!this.userId) {
852
+ throw new Error("no userId is set");
853
+ }
854
+ return this.userId;
855
+ }
856
+ assertIsAuthSet(allowed) {
857
+ if (!__privateGet(this, _authInfo)) {
858
+ throw new Error("auth is not set");
859
+ }
860
+ if (allowed && !allowed.includes(__privateGet(this, _authInfo).authType)) {
861
+ throw new Error(`invalid auth type, expected ${allowed.join(", ")}`);
862
+ }
863
+ return __privateGet(this, _authInfo);
864
+ }
779
865
  /**
780
866
  * Sets the email associated with the `ParaCore` instance.
781
867
  * @param email - Email to set.
782
868
  */
783
869
  setEmail(email) {
784
870
  return __async(this, null, function* () {
785
- this.email = email;
786
- yield this.localStorageSetItem(constants.LOCAL_STORAGE_EMAIL, email);
871
+ yield this.setAuth({ email });
787
872
  });
788
873
  }
789
874
  /**
@@ -792,8 +877,7 @@ const _ParaCore = class _ParaCore {
792
877
  */
793
878
  setTelegramUserId(telegramUserId) {
794
879
  return __async(this, null, function* () {
795
- this.telegramUserId = telegramUserId;
796
- yield this.localStorageSetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID, telegramUserId);
880
+ yield this.setAuth({ telegramUserId });
797
881
  });
798
882
  }
799
883
  /**
@@ -803,10 +887,7 @@ const _ParaCore = class _ParaCore {
803
887
  */
804
888
  setPhoneNumber(phone, countryCode) {
805
889
  return __async(this, null, function* () {
806
- this.phone = phone;
807
- this.countryCode = countryCode;
808
- yield this.localStorageSetItem(constants.LOCAL_STORAGE_PHONE, phone);
809
- yield this.localStorageSetItem(constants.LOCAL_STORAGE_COUNTRY_CODE, countryCode);
890
+ yield this.setAuth({ phone: (0, import_utils2.formatPhoneNumber)(phone, countryCode) });
810
891
  });
811
892
  }
812
893
  /**
@@ -815,8 +896,7 @@ const _ParaCore = class _ParaCore {
815
896
  */
816
897
  setFarcasterUsername(farcasterUsername) {
817
898
  return __async(this, null, function* () {
818
- this.farcasterUsername = farcasterUsername;
819
- yield this.localStorageSetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME, farcasterUsername);
899
+ yield this.setAuth({ farcasterUsername });
820
900
  });
821
901
  }
822
902
  /**
@@ -901,6 +981,9 @@ const _ParaCore = class _ParaCore {
901
981
  getUserId() {
902
982
  return this.userId;
903
983
  }
984
+ getAuthInfo() {
985
+ return this.authInfo;
986
+ }
904
987
  /**
905
988
  * Gets the email associated with the `ParaCore` instance.
906
989
  * @returns - email associated with the `ParaCore` instance.
@@ -908,22 +991,12 @@ const _ParaCore = class _ParaCore {
908
991
  getEmail() {
909
992
  return this.email;
910
993
  }
911
- /**
912
- * Gets the phone object associated with the `ParaCore` instance.
913
- * @returns - phone object with phone number and country code associated with the `ParaCore` instance.
914
- */
915
- getPhone() {
916
- return { phone: this.phone, countryCode: this.countryCode };
917
- }
918
994
  /**
919
995
  * Gets the formatted phone number associated with the `ParaCore` instance.
920
996
  * @returns - formatted phone number associated with the `ParaCore` instance.
921
997
  */
922
998
  getPhoneNumber() {
923
- if (!this.phone || !this.countryCode) {
924
- return void 0;
925
- }
926
- return (0, import_utils2.normalizePhoneNumber)(this.countryCode, this.phone);
999
+ return this.phone;
927
1000
  }
928
1001
  /**
929
1002
  * Gets the farcaster username associated with the `ParaCore` instance.
@@ -962,9 +1035,7 @@ const _ParaCore = class _ParaCore {
962
1035
  if (!(yield this.isSessionActive()) || !this.userId) {
963
1036
  throw new Error("no signed-in user");
964
1037
  }
965
- const {
966
- data: { partnerId }
967
- } = yield this.touchSession();
1038
+ const { partnerId } = yield this.touchSession();
968
1039
  const { accountMetadata } = yield this.ctx.client.getAccountMetadata(this.userId, partnerId);
969
1040
  return accountMetadata;
970
1041
  });
@@ -1022,8 +1093,10 @@ const _ParaCore = class _ParaCore {
1022
1093
  }
1023
1094
  findWallet(idOrAddress, overrideType, filter = {}) {
1024
1095
  var _a, _c, _d;
1025
- if (!this.isExternalWalletAuth && !idOrAddress && Object.keys(this.externalWallets).length > 0) {
1026
- return Object.values(this.externalWallets)[0];
1096
+ if (!this.isExternalWalletAuth) {
1097
+ if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
1098
+ return Object.values(this.externalWallets)[0];
1099
+ }
1027
1100
  }
1028
1101
  if ((_a = this.externalWallets) == null ? void 0 : _a[idOrAddress]) {
1029
1102
  return this.externalWallets[idOrAddress];
@@ -1034,7 +1107,7 @@ const _ParaCore = class _ParaCore {
1034
1107
  const _b = this.wallets[walletId], { signer: _signer } = _b, wallet = __objRest(_b, ["signer"]);
1035
1108
  const type = (_d = overrideType != null ? overrideType : (_c = this.currentWalletIdsArray.find(([id]) => id === walletId)) == null ? void 0 : _c[1]) != null ? _d : wallet.type;
1036
1109
  return __spreadProps(__spreadValues({}, wallet), {
1037
- type: import_user_management_client.WalletType[type]
1110
+ type
1038
1111
  });
1039
1112
  }
1040
1113
  } catch (e) {
@@ -1044,7 +1117,7 @@ const _ParaCore = class _ParaCore {
1044
1117
  get availableWallets() {
1045
1118
  var _a;
1046
1119
  return [
1047
- ...this.currentWalletIdsArray.map(([address, type]) => [address, type, false]).map(([id, type]) => {
1120
+ ...[...this.currentWalletIdsArray, ...__privateGet(this, _ParaCore_instances, guestWalletIdsArray_get)].map(([address, type]) => [address, type, false]).map(([id, type]) => {
1048
1121
  const wallet = this.findWallet(id, type);
1049
1122
  if (!wallet) return null;
1050
1123
  return {
@@ -1070,10 +1143,8 @@ const _ParaCore = class _ParaCore {
1070
1143
  }
1071
1144
  assertIsValidWalletType(type, walletTypes) {
1072
1145
  return __async(this, null, function* () {
1073
- if (!__privateGet(this, _supportedWalletTypes)) {
1074
- yield this.touchSession();
1075
- }
1076
- if (!type || !Object.values(import_user_management_client.WalletType).includes(type) || !(walletTypes != null ? walletTypes : this.supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
1146
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1147
+ if (!type || !import_user_management_client.WALLET_TYPES.includes(type) || !(walletTypes != null ? walletTypes : supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
1077
1148
  throw new Error(`wallet type ${type} is not supported`);
1078
1149
  }
1079
1150
  return type;
@@ -1081,33 +1152,29 @@ const _ParaCore = class _ParaCore {
1081
1152
  }
1082
1153
  getMissingTypes() {
1083
1154
  return __async(this, null, function* () {
1084
- if (!__privateGet(this, _supportedWalletTypes)) {
1085
- yield this.touchSession();
1086
- }
1087
- return this.supportedWalletTypes.filter(
1155
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1156
+ return supportedWalletTypes.filter(
1088
1157
  ({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !import_utils2.WalletSchemeTypeMap[w.scheme][t])
1089
1158
  ).map(({ type }) => type);
1090
1159
  });
1091
1160
  }
1092
1161
  getTypesToCreate(types) {
1093
1162
  return __async(this, null, function* () {
1094
- if (!__privateGet(this, _supportedWalletTypes)) {
1095
- yield this.touchSession();
1096
- }
1163
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1097
1164
  return (0, import_utils2.getSchemes)(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
1098
1165
  switch (scheme) {
1099
- case import_user_management_client.WalletScheme.ED25519:
1100
- return import_user_management_client.WalletType.SOLANA;
1166
+ case "ED25519":
1167
+ return "SOLANA";
1101
1168
  default:
1102
- return this.supportedWalletTypes.some(({ type, optional }) => type === import_user_management_client.WalletType.COSMOS && !optional) ? import_user_management_client.WalletType.COSMOS : import_user_management_client.WalletType.EVM;
1169
+ return supportedWalletTypes.some(({ type, optional }) => type === "COSMOS" && !optional) ? "COSMOS" : "EVM";
1103
1170
  }
1104
1171
  });
1105
1172
  });
1106
1173
  }
1107
- getPartnerURL(partnerId) {
1174
+ getPartnerURL() {
1108
1175
  return __async(this, null, function* () {
1109
- const res = yield this.ctx.client.getPartner(partnerId);
1110
- return res.data.partner.portalUrl;
1176
+ const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1177
+ return portalUrl;
1111
1178
  });
1112
1179
  }
1113
1180
  /**
@@ -1115,75 +1182,9 @@ const _ParaCore = class _ParaCore {
1115
1182
  * @param partnerId: string - id of the partner to get the portal URL for
1116
1183
  * @returns - portal URL
1117
1184
  */
1118
- getPortalURL(partnerId) {
1185
+ getPortalURL() {
1119
1186
  return __async(this, null, function* () {
1120
- return partnerId && (yield this.getPartnerURL(partnerId)) || (0, import_utils2.getPortalBaseURL)(this.ctx);
1121
- });
1122
- }
1123
- getWebAuthURLForCreate(_a) {
1124
- return __async(this, null, function* () {
1125
- var _b = _a, {
1126
- webAuthId
1127
- } = _b, options = __objRest(_b, [
1128
- "webAuthId"
1129
- ]);
1130
- return this.constructPortalUrl("createAuth", __spreadProps(__spreadValues({}, options), { pathId: webAuthId }));
1131
- });
1132
- }
1133
- getPasswordURLForCreate(_c) {
1134
- return __async(this, null, function* () {
1135
- var _d = _c, {
1136
- passwordId
1137
- } = _d, options = __objRest(_d, [
1138
- "passwordId"
1139
- ]);
1140
- return this.constructPortalUrl("createPassword", __spreadProps(__spreadValues({}, options), {
1141
- pathId: passwordId
1142
- }));
1143
- });
1144
- }
1145
- getShortUrl(compressedUrl) {
1146
- return (0, import_utils2.constructUrl)({
1147
- base: (0, import_utils2.getPortalBaseURL)(this.ctx),
1148
- path: `/short/${compressedUrl}`
1149
- });
1150
- }
1151
- shortenLoginLink(link) {
1152
- return __async(this, null, function* () {
1153
- const url = yield transmissionUtils.upload(link, this.ctx.client);
1154
- return this.getShortUrl(url);
1155
- });
1156
- }
1157
- /**
1158
- * Generates a URL for registering a new WebAuth passkey.
1159
- * @param {GetWebAuthUrlForLoginParams} opts the options object
1160
- * @returns - the URL for creating a new passkey
1161
- */
1162
- getWebAuthURLForLogin(opts) {
1163
- return __async(this, null, function* () {
1164
- return this.constructPortalUrl("loginAuth", opts);
1165
- });
1166
- }
1167
- /**
1168
- * Generates a URL for registering a new user password.
1169
- * @param {GetWebAuthUrlForLoginParams} opts the options object
1170
- * @returns - the URL for creating a new password
1171
- */
1172
- getPasswordURLForLogin(opts) {
1173
- return __async(this, null, function* () {
1174
- return this.constructPortalUrl("loginPassword", opts);
1175
- });
1176
- }
1177
- /**
1178
- * Generates a URL for registering a new WebAuth passkey for a phone number.
1179
- * @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
1180
- * @returns - web auth url
1181
- */
1182
- getWebAuthURLForLoginForPhone(opts) {
1183
- return __async(this, null, function* () {
1184
- return this.constructPortalUrl("loginAuth", __spreadValues({
1185
- authType: "phone"
1186
- }, opts));
1187
+ return (yield this.getPartnerURL()) || (0, import_utils2.getPortalBaseURL)(this.ctx);
1187
1188
  });
1188
1189
  }
1189
1190
  /**
@@ -1198,7 +1199,7 @@ const _ParaCore = class _ParaCore {
1198
1199
  if (!wallet) {
1199
1200
  throw new Error("wallet not found");
1200
1201
  }
1201
- if (wallet.scheme !== import_user_management_client.WalletScheme.DKLS) {
1202
+ if (wallet.scheme !== "DKLS") {
1202
1203
  throw new Error("invalid wallet scheme");
1203
1204
  }
1204
1205
  return yield this.platformUtils.getPrivateKey(
@@ -1245,131 +1246,52 @@ const _ParaCore = class _ParaCore {
1245
1246
  yield this.setWallets(this.wallets);
1246
1247
  });
1247
1248
  }
1248
- /**
1249
- * Checks if a user exists for an email address.
1250
- * @param {Object} opts the options object
1251
- * @param {string} opts.email the email to check.
1252
- * @returns true if user exists, false otherwise.
1253
- */
1254
- checkIfUserExists(_0) {
1255
- return __async(this, arguments, function* ({ email }) {
1256
- const res = yield this.ctx.client.checkUserExists({ email });
1257
- return res.data.exists;
1258
- });
1259
- }
1260
- /**
1261
- * Checks if a user exists for a phone number.
1262
- * @param {Object} opts the options object
1263
- * @param {string} opts.phone - phone number to check.
1264
- * @param {string} opts.countryCode - the country code.
1265
- * @returns true if user exists, false otherwise.
1266
- */
1267
- checkIfUserExistsByPhone(_0) {
1268
- return __async(this, arguments, function* ({ phone, countryCode }) {
1269
- const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
1270
- return res.data.exists;
1271
- });
1272
- }
1273
- /**
1274
- * Creates a new user.
1275
- * @param {Object} opts the options object
1276
- * @param {string} opts.email the email to use.
1277
- */
1278
- createUser(_0) {
1279
- return __async(this, arguments, function* ({ email }) {
1280
- this.requireApiKey();
1281
- yield this.setEmail(email);
1282
- const { userId } = yield this.ctx.client.createUser(__spreadValues({
1283
- email: this.email
1284
- }, this.getVerificationEmailProps()));
1285
- yield this.setUserId(userId);
1286
- });
1287
- }
1288
- /**
1289
- * Creates a new user with a phone number.
1290
- * @param {Object} opts the options object
1291
- * @param {string} opts.phone - the phone number to use for creating the user.
1292
- * @param {string} opts.countryCode - the country code to use for creating the user.
1293
- */
1294
- createUserByPhone(_0) {
1295
- return __async(this, arguments, function* ({ phone, countryCode }) {
1296
- this.requireApiKey();
1297
- yield this.setPhoneNumber(phone, countryCode);
1298
- const { userId } = yield this.ctx.client.createUser({
1299
- phone: this.phone,
1300
- countryCode: this.countryCode
1301
- });
1302
- yield this.setUserId(userId);
1303
- });
1304
- }
1305
1249
  /**
1306
1250
  * Logs in or creates a new user using an external wallet address.
1307
1251
  * @param {Object} opts the options object
1308
1252
  * @param {string} opts.address the external wallet address to use for identification.
1309
- * @param {WalletType} opts.type type of external wallet to use for identification.
1253
+ * @param {TWalletType} opts.type type of external wallet to use for identification.
1310
1254
  * @param {string} opts.provider the name of the provider for the external wallet.
1311
1255
  */
1312
- externalWalletLogin(wallet) {
1256
+ loginExternalWallet(_a) {
1313
1257
  return __async(this, null, function* () {
1258
+ var _b = _a, {
1259
+ externalWallet
1260
+ } = _b, urlOptions = __objRest(_b, [
1261
+ "externalWallet"
1262
+ ]);
1314
1263
  if (this.externalWalletConnectionOnly) {
1315
- wallet.withFullParaAuth = false;
1316
- yield this.setExternalWallet(wallet);
1264
+ externalWallet.withFullParaAuth = false;
1265
+ yield this.setExternalWallet(externalWallet);
1317
1266
  return Promise.resolve({
1318
1267
  userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
1319
1268
  });
1320
1269
  }
1321
1270
  this.requireApiKey();
1322
- const res = yield this.ctx.client.externalWalletLogin({
1323
- externalAddress: wallet.address,
1324
- type: wallet.type,
1325
- externalWalletProvider: wallet.provider,
1326
- // If the wallet isn't using full Para auth we want to track the login here
1327
- shouldTrackUser: !wallet.withFullParaAuth
1328
- });
1329
- yield this.setExternalWallet(wallet);
1330
- yield this.setUserId(res.userId);
1331
- return res;
1332
- });
1333
- }
1334
- /**
1335
- * Returns whether or not the user is connected with only an external wallet, not an external wallet with Para auth.
1336
- */
1337
- isUsingExternalWallet() {
1338
- return !this.isExternalWalletAuth && !!Object.keys(this.externalWallets).length;
1339
- }
1340
- /**
1341
- * Passes the email code obtained from the user for verification.
1342
- * @param {Object} opts the options object
1343
- * @param {string} verificationCode the six-digit code to check
1344
- * @returns {string} the web auth url for creating a new credential
1345
- */
1346
- verifyEmail(_0) {
1347
- return __async(this, arguments, function* ({ verificationCode }) {
1348
- yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
1349
- return this.getSetUpBiometricsURL();
1271
+ const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
1272
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1350
1273
  });
1351
1274
  }
1352
- verifyExternalWallet(_0) {
1353
- return __async(this, arguments, function* ({
1354
- address,
1355
- signedMessage,
1356
- cosmosPublicKeyHex,
1357
- cosmosSigner
1358
- }) {
1359
- yield this.ctx.client.verifyExternalWallet(this.userId, { address, signedMessage, cosmosPublicKeyHex, cosmosSigner });
1360
- return this.getSetUpBiometricsURL({ authType: "externalWallet" });
1361
- });
1362
- }
1363
- /**
1364
- * Passes the phone code obtained from the user for verification.
1365
- * @param {Object} opts the options object
1366
- * @param {string} verificationCode the six-digit code to check
1367
- * @returns {string} the web auth url for creating a new credential
1368
- */
1369
- verifyPhone(_0) {
1370
- return __async(this, arguments, function* ({ verificationCode }) {
1371
- yield this.ctx.client.verifyPhone(this.userId, { verificationCode });
1372
- return this.getSetUpBiometricsURLForPhone();
1275
+ verifyExternalWallet(_c) {
1276
+ return __async(this, null, function* () {
1277
+ var _d = _c, {
1278
+ externalWallet,
1279
+ signedMessage,
1280
+ cosmosPublicKeyHex,
1281
+ cosmosSigner
1282
+ } = _d, urlOptions = __objRest(_d, [
1283
+ "externalWallet",
1284
+ "signedMessage",
1285
+ "cosmosPublicKeyHex",
1286
+ "cosmosSigner"
1287
+ ]);
1288
+ const serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
1289
+ externalWallet,
1290
+ signedMessage,
1291
+ cosmosPublicKeyHex,
1292
+ cosmosSigner
1293
+ });
1294
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1373
1295
  });
1374
1296
  }
1375
1297
  /**
@@ -1378,18 +1300,19 @@ const _ParaCore = class _ParaCore {
1378
1300
  * @param authResponse - the response JSON object received from the Telegram widget.
1379
1301
  * @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
1380
1302
  */
1381
- verifyTelegram(authObject) {
1303
+ verifyTelegram(_e) {
1382
1304
  return __async(this, null, function* () {
1383
- const res = yield this.ctx.client.verifyTelegram(authObject);
1384
- if (res.isValid) {
1385
- yield this.setUserId(res.userId);
1386
- yield this.setTelegramUserId(res.telegramUserId);
1387
- yield this.touchSession(true);
1388
- if (!this.loginEncryptionKeyPair) {
1389
- yield this.setLoginEncryptionKeyPair();
1390
- }
1305
+ var _f = _e, {
1306
+ telegramAuthResponse
1307
+ } = _f, urlOptions = __objRest(_f, [
1308
+ "telegramAuthResponse"
1309
+ ]);
1310
+ try {
1311
+ const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
1312
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1313
+ } catch (e) {
1314
+ throw new Error(e.message);
1391
1315
  }
1392
- return res;
1393
1316
  });
1394
1317
  }
1395
1318
  /**
@@ -1399,32 +1322,9 @@ const _ParaCore = class _ParaCore {
1399
1322
  * @param {string} opts.verificationCode the verification code to received via 2FA.
1400
1323
  * @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
1401
1324
  */
1402
- verify2FA(_0) {
1403
- return __async(this, arguments, function* ({ email, verificationCode }) {
1404
- const res = yield this.ctx.client.verify2FA(email, verificationCode);
1405
- return {
1406
- initiatedAt: res.data.initiatedAt,
1407
- status: res.data.status,
1408
- userId: res.data.userId,
1409
- wallets: res.data.wallets
1410
- };
1411
- });
1412
- }
1413
- /**
1414
- * Performs 2FA verification.
1415
- * @param {Object} opts the options object
1416
- * @param {string} opts.phone the phone number
1417
- * @param {string} opts.countryCode - the country code
1418
- * @param {string} opts.verificationCode - verification code to received via 2FA.
1419
- * @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
1420
- */
1421
- verify2FAForPhone(_0) {
1422
- return __async(this, arguments, function* ({
1423
- phone,
1424
- countryCode,
1425
- verificationCode
1426
- }) {
1427
- const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
1325
+ verify2fa(_0) {
1326
+ return __async(this, arguments, function* ({ auth, verificationCode }) {
1327
+ const res = yield this.ctx.client.verify2FA(auth, verificationCode);
1428
1328
  return {
1429
1329
  initiatedAt: res.data.initiatedAt,
1430
1330
  status: res.data.status,
@@ -1437,12 +1337,11 @@ const _ParaCore = class _ParaCore {
1437
1337
  * Sets up two-factor authentication for the current user.
1438
1338
  * @returns {string} uri - uri to use for setting up 2FA
1439
1339
  * */
1440
- setup2FA() {
1340
+ setup2fa() {
1441
1341
  return __async(this, null, function* () {
1442
- const res = yield this.ctx.client.setup2FA(this.userId);
1443
- return {
1444
- uri: res.data.uri
1445
- };
1342
+ const userId = this.assertUserId();
1343
+ const res = yield this.ctx.client.setup2FA(userId);
1344
+ return res;
1446
1345
  });
1447
1346
  }
1448
1347
  /**
@@ -1450,24 +1349,10 @@ const _ParaCore = class _ParaCore {
1450
1349
  * @param {Object} opts the options object
1451
1350
  * @param {string} opts.verificationCode - the verification code received via 2FA.
1452
1351
  */
1453
- enable2FA(_0) {
1352
+ enable2fa(_0) {
1454
1353
  return __async(this, arguments, function* ({ verificationCode }) {
1455
- yield this.ctx.client.enable2FA(this.userId, verificationCode);
1456
- });
1457
- }
1458
- /**
1459
- * Determines if 2FA has been set up.
1460
- * @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
1461
- */
1462
- check2FAStatus() {
1463
- return __async(this, null, function* () {
1464
- if (!this.userId) {
1465
- return { isSetup: false };
1466
- }
1467
- const res = yield this.ctx.client.check2FAStatus(this.userId);
1468
- return {
1469
- isSetup: res.data.isSetup
1470
- };
1354
+ const userId = this.assertUserId();
1355
+ yield this.ctx.client.enable2FA(userId, verificationCode);
1471
1356
  });
1472
1357
  }
1473
1358
  /**
@@ -1480,99 +1365,17 @@ const _ParaCore = class _ParaCore {
1480
1365
  }, this.getVerificationEmailProps()));
1481
1366
  });
1482
1367
  }
1483
- /**
1484
- * Resend a verification SMS for the current user.
1485
- */
1486
- resendVerificationCodeByPhone() {
1487
- return __async(this, null, function* () {
1488
- yield this.ctx.client.resendVerificationCodeByPhone({
1489
- userId: this.userId
1490
- });
1491
- });
1492
- }
1493
- /**
1494
- * Returns a URL for setting up a new WebAuth passkey.
1495
- * @param {Object} opts the options object
1496
- * @param {string} opts.authType - the auth type to use
1497
- * @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
1498
- * @returns {string} the URL
1499
- */
1500
- getSetUpBiometricsURL() {
1501
- return __async(this, arguments, function* ({
1502
- authType = "email",
1503
- isForNewDevice = false
1504
- } = {}) {
1505
- const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
1506
- status: import_user_management_client.PublicKeyStatus.PENDING,
1507
- type: import_user_management_client.PublicKeyType.WEB
1508
- });
1509
- return this.getWebAuthURLForCreate({
1510
- authType,
1511
- isForNewDevice,
1512
- webAuthId: res.data.id,
1513
- partnerId: res.data.partnerId
1514
- });
1515
- });
1516
- }
1517
- /**
1518
- * Returns a URL for setting up a new WebAuth passkey for a phone number.
1519
- * @param {Object} opts the options object
1520
- * @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
1521
- * @returns {string} the URL
1522
- */
1523
- getSetUpBiometricsURLForPhone() {
1524
- return __async(this, arguments, function* ({
1525
- isForNewDevice = false
1526
- } = {}) {
1527
- const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
1528
- status: import_user_management_client.PublicKeyStatus.PENDING,
1529
- type: import_user_management_client.PublicKeyType.WEB
1530
- });
1531
- return this.getWebAuthURLForCreate({
1532
- authType: "phone",
1533
- isForNewDevice,
1534
- webAuthId: res.data.id,
1535
- partnerId: res.data.partnerId
1536
- });
1537
- });
1538
- }
1539
- /**
1540
- * Returns a URL for setting up a new password.
1541
- * @param {Object} opts the options object
1542
- * @param {string} opts.authType - the auth type to use
1543
- * @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
1544
- * @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
1545
- * @returns {string} the URL
1546
- */
1547
- getSetupPasswordURL() {
1548
- return __async(this, arguments, function* ({
1549
- authType = "email",
1550
- isForNewDevice = false,
1551
- theme
1552
- } = {}) {
1553
- const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
1554
- status: import_user_management_client.PasswordStatus.PENDING
1555
- });
1556
- return this.getPasswordURLForCreate({
1557
- authType,
1558
- isForNewDevice,
1559
- passwordId: res.data.id,
1560
- partnerId: res.data.partnerId,
1561
- theme
1562
- });
1563
- });
1564
- }
1565
1368
  /**
1566
1369
  * Checks if the current session is active.
1567
1370
  * @returns `true` if active, `false` otherwise
1568
1371
  */
1569
1372
  isSessionActive() {
1570
1373
  return __async(this, null, function* () {
1571
- if (this.isUsingExternalWallet()) {
1374
+ if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
1572
1375
  return true;
1573
1376
  }
1574
- const res = yield this.touchSession();
1575
- return !!res.data.isAuthenticated;
1377
+ const { isAuthenticated } = yield this.touchSession();
1378
+ return !!isAuthenticated;
1576
1379
  });
1577
1380
  }
1578
1381
  /**
@@ -1581,201 +1384,102 @@ const _ParaCore = class _ParaCore {
1581
1384
  **/
1582
1385
  isFullyLoggedIn() {
1583
1386
  return __async(this, null, function* () {
1584
- if (this.isUsingExternalWallet()) {
1585
- return true;
1586
- }
1587
- if (this.isGuestMode) {
1387
+ if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
1588
1388
  return true;
1589
1389
  }
1590
- const isSessionActive = yield this.isSessionActive();
1591
- return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
1592
- });
1593
- }
1594
- get isGuestMode() {
1595
- return !this.userId && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.every(([id]) => !!this.wallets[id] && this.wallets[id].pregenIdentifierType === "GUEST_ID");
1596
- }
1597
- supportedAuthMethods(auth) {
1598
- return __async(this, null, function* () {
1599
- const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
1600
- const authMethods = /* @__PURE__ */ new Set();
1601
- for (const type of supportedAuthMethods) {
1602
- switch (type) {
1603
- case "PASSWORD":
1604
- authMethods.add(import_user_management_client.AuthMethod.PASSWORD);
1605
- break;
1606
- case "BIOMETRIC":
1607
- authMethods.add(import_user_management_client.AuthMethod.PASSKEY);
1608
- break;
1609
- }
1610
- }
1611
- return authMethods;
1612
- });
1613
- }
1614
- /**
1615
- * Get hints associated with the users stored biometrics.
1616
- * @returns Array containing useragents and AAGuids for stored biometrics
1617
- */
1618
- getUserBiometricLocationHints() {
1619
- return __async(this, null, function* () {
1620
- var _a;
1621
- if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId && !this.isExternalWalletAuth) {
1622
- throw new Error(
1623
- "one of email, phone, farcaster username, telegram user id or external wallet with Para auth are required to get biometric location hints"
1624
- );
1625
- }
1626
- return yield this.ctx.client.getBiometricLocationHints({
1627
- email: this.email,
1628
- phone: this.phone,
1629
- countryCode: this.countryCode,
1630
- farcasterUsername: this.farcasterUsername,
1631
- telegramUserId: this.telegramUserId,
1632
- // Using id here since we store the bech32 address for cosmos in the address field of the wallet
1633
- externalWalletAddress: (_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id
1634
- });
1635
- });
1636
- }
1637
- setAuth(auth) {
1638
- return __async(this, null, function* () {
1639
- const authInfo = (0, import_user_management_client.extractAuthInfo)(auth);
1640
- if (!authInfo) {
1641
- return void 0;
1642
- }
1643
- switch (authInfo.authType) {
1644
- case "email":
1645
- yield this.setEmail(authInfo.identifier);
1646
- break;
1647
- case "phone":
1648
- yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
1649
- break;
1650
- case "farcaster":
1651
- yield this.setFarcasterUsername(authInfo.identifier);
1652
- break;
1653
- case "telegram":
1654
- yield this.setTelegramUserId(authInfo.identifier);
1655
- break;
1656
- }
1657
- return authInfo;
1658
- });
1659
- }
1660
- /**
1661
- * Initiates a login.
1662
- * @param {Object} opts the options object
1663
- * @param {String} opts.email - the email to login with
1664
- * @param {boolean} opts.useShortURL - whether to shorten the link
1665
- * @returns - the WebAuth URL for logging in
1666
- **/
1667
- initiateUserLogin(_e) {
1668
- return __async(this, null, function* () {
1669
- var _f = _e, { useShortUrl = false } = _f, auth = __objRest(_f, ["useShortUrl"]);
1670
- const authInfo = yield this.setAuth(auth);
1671
- if (!authInfo) {
1672
- return;
1673
- }
1674
- const res = yield this.touchSession(true);
1675
- if (!this.loginEncryptionKeyPair) {
1676
- yield this.setLoginEncryptionKeyPair();
1677
- }
1678
- const webAuthLoginURL = yield this.getWebAuthURLForLogin({
1679
- authType: authInfo.authType,
1680
- sessionId: res.data.sessionId,
1681
- partnerId: res.data.partnerId,
1682
- loginEncryptionPublicKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair)
1683
- });
1684
- if (!useShortUrl) {
1685
- return webAuthLoginURL;
1390
+ if (this.isGuestMode) {
1391
+ return true;
1686
1392
  }
1687
- return this.shortenLoginLink(webAuthLoginURL);
1393
+ const isSessionActive = yield this.isSessionActive();
1394
+ return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
1688
1395
  });
1689
1396
  }
1690
- /**
1691
- * Initiates a login.
1692
- * @param email - the email to login with
1693
- * @returns - a set of supported auth methods for the user
1694
- **/
1695
- initiateUserLoginV2(auth) {
1696
- return __async(this, null, function* () {
1697
- const authInfo = yield this.setAuth(auth);
1698
- if (!authInfo) {
1699
- return;
1397
+ get isGuestMode() {
1398
+ return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
1399
+ ({ userId, partnerId }) => {
1400
+ var _a;
1401
+ return partnerId === ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
1700
1402
  }
1701
- yield this.touchSession(true);
1702
- if (!this.loginEncryptionKeyPair) {
1703
- yield this.setLoginEncryptionKeyPair();
1403
+ );
1404
+ }
1405
+ supportedAuthMethods(auth) {
1406
+ return __async(this, null, function* () {
1407
+ const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
1408
+ const authMethods = /* @__PURE__ */ new Set();
1409
+ for (const type of supportedAuthMethods) {
1410
+ switch (type) {
1411
+ case "PASSWORD":
1412
+ authMethods.add(import_user_management_client.AuthMethod.PASSWORD);
1413
+ break;
1414
+ case "BIOMETRIC":
1415
+ authMethods.add(import_user_management_client.AuthMethod.PASSKEY);
1416
+ break;
1417
+ }
1704
1418
  }
1705
- return yield this.supportedAuthMethods(authInfo.auth);
1419
+ return authMethods;
1706
1420
  });
1707
1421
  }
1708
1422
  /**
1709
- * Initiates a login.
1710
- * @param opts the options object
1711
- * @param opts.phone the phone number
1712
- * @param opts.countryCode the country code
1713
- * @param opts.useShortURL - whether to shorten the link
1714
- * @returns - the WebAuth URL for logging in
1715
- **/
1716
- initiateUserLoginForPhone(_g) {
1423
+ * Get hints associated with the users stored biometrics.
1424
+ * @deprecated
1425
+ * @returns Array containing useragents and AAGuids for stored biometrics
1426
+ */
1427
+ getUserBiometricLocationHints() {
1717
1428
  return __async(this, null, function* () {
1718
- var _h = _g, {
1719
- useShortUrl = false
1720
- } = _h, auth = __objRest(_h, [
1721
- "useShortUrl"
1722
- ]);
1723
- yield this.setAuth(auth);
1724
- const res = yield this.touchSession(true);
1725
- if (!this.loginEncryptionKeyPair) {
1726
- yield this.setLoginEncryptionKeyPair();
1727
- }
1728
- const webAuthLoginURL = yield this.getWebAuthURLForLoginForPhone({
1729
- sessionId: res.data.sessionId,
1730
- loginEncryptionPublicKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
1731
- partnerId: res.data.partnerId
1732
- });
1733
- if (!useShortUrl) {
1734
- return webAuthLoginURL;
1735
- }
1736
- return this.shortenLoginLink(webAuthLoginURL);
1429
+ const { auth } = this.assertIsAuthSet();
1430
+ return yield this.ctx.client.getBiometricLocationHints(auth);
1737
1431
  });
1738
1432
  }
1739
1433
  /**
1740
1434
  * Waits for the session to be active.
1741
1435
  **/
1742
- waitForAccountCreation() {
1743
- return __async(this, arguments, function* ({ popupWindow } = {}) {
1744
- yield this.touchSession();
1745
- if (!this.isExternalWalletAuth) {
1746
- this.externalWallets = {};
1747
- }
1748
- this.isAwaitingAccountCreation = true;
1749
- while (this.isAwaitingAccountCreation) {
1750
- try {
1751
- yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
1752
- if (yield this.isSessionActive()) {
1753
- this.isAwaitingAccountCreation = false;
1754
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.ACCOUNT_CREATION_EVENT, true);
1755
- return true;
1756
- } else {
1757
- if (popupWindow == null ? void 0 : popupWindow.closed) {
1758
- this.isAwaitingAccountCreation = false;
1759
- return false;
1436
+ waitForSignup(_0) {
1437
+ return __async(this, arguments, function* ({
1438
+ isCanceled = () => false,
1439
+ onCancel,
1440
+ onPoll
1441
+ }) {
1442
+ const startedAt = Date.now();
1443
+ return new Promise((resolve, reject) => {
1444
+ (() => __async(this, null, function* () {
1445
+ yield this.touchSession();
1446
+ if (!this.isExternalWalletAuth) {
1447
+ this.externalWallets = {};
1448
+ }
1449
+ while (true) {
1450
+ try {
1451
+ if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
1452
+ onCancel == null ? void 0 : onCancel();
1453
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.ACCOUNT_CREATION_EVENT, false, "failed to sign up user");
1454
+ return reject("canceled");
1455
+ }
1456
+ yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
1457
+ if (yield this.isSessionActive()) {
1458
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.ACCOUNT_CREATION_EVENT, true);
1459
+ return resolve(true);
1460
+ }
1461
+ onPoll == null ? void 0 : onPoll();
1462
+ } catch (err) {
1463
+ console.error(err);
1464
+ onPoll == null ? void 0 : onPoll();
1760
1465
  }
1761
1466
  }
1762
- } catch (err) {
1763
- console.error(err);
1764
- }
1765
- }
1766
- return false;
1467
+ }))();
1468
+ });
1767
1469
  });
1768
1470
  }
1769
- waitForPasskeyAndCreateWallet() {
1471
+ waitForWalletCreation() {
1770
1472
  return __async(this, arguments, function* ({
1771
- popupWindow
1473
+ isCanceled = () => false,
1474
+ onCancel
1772
1475
  } = {}) {
1773
- yield this.waitForAccountCreation({ popupWindow });
1476
+ yield this.waitForSignup({ isCanceled, onCancel });
1477
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1774
1478
  const pregenWallets = yield this.getPregenWallets();
1775
1479
  let recoverySecret, walletIds = {};
1776
1480
  if (pregenWallets.length > 0) {
1777
1481
  recoverySecret = yield this.claimPregenWallets();
1778
- walletIds = this.supportedWalletTypes.reduce((acc, { type }) => {
1482
+ walletIds = supportedWalletTypes.reduce((acc, { type }) => {
1779
1483
  var _a;
1780
1484
  return __spreadProps(__spreadValues({}, acc), {
1781
1485
  [type]: [(_a = pregenWallets.find((w) => !!import_utils2.WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
@@ -1795,14 +1499,12 @@ const _ParaCore = class _ParaCore {
1795
1499
  * You can create a QR code with this URI that works with Farcaster's mobile app.
1796
1500
  * @return {string} the Farcaster connect URI
1797
1501
  */
1798
- getFarcasterConnectURL() {
1502
+ getFarcasterConnectUri() {
1799
1503
  return __async(this, null, function* () {
1800
- yield this.logout();
1801
- yield this.touchSession(true);
1802
1504
  const {
1803
- data: { connect_uri }
1505
+ data: { connect_uri: connectUri }
1804
1506
  } = yield this.ctx.client.initializeFarcasterLogin();
1805
- return connect_uri;
1507
+ return connectUri;
1806
1508
  });
1807
1509
  }
1808
1510
  /**
@@ -1810,40 +1512,60 @@ const _ParaCore = class _ParaCore {
1810
1512
  * If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
1811
1513
  * @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
1812
1514
  */
1813
- waitForFarcasterStatus() {
1515
+ verifyFarcaster(_g) {
1814
1516
  return __async(this, null, function* () {
1815
- this.isAwaitingFarcaster = true;
1816
- while (this.isAwaitingFarcaster) {
1817
- try {
1818
- yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
1819
- const res = yield this.ctx.client.getFarcasterAuthStatus();
1820
- if (res.data.state === "completed") {
1821
- const { userId, userExists, username, pfpUrl } = res.data;
1822
- yield this.setUserId(userId);
1823
- yield this.setFarcasterUsername(username);
1824
- return {
1825
- userExists,
1826
- username,
1827
- pfpUrl
1828
- };
1517
+ var _h = _g, {
1518
+ isCanceled = () => false,
1519
+ onConnectUri,
1520
+ onCancel,
1521
+ onPoll
1522
+ } = _h, urlOptions = __objRest(_h, [
1523
+ "isCanceled",
1524
+ "onConnectUri",
1525
+ "onCancel",
1526
+ "onPoll"
1527
+ ]);
1528
+ if (onConnectUri) {
1529
+ const connectUri = yield this.getFarcasterConnectUri();
1530
+ onConnectUri(connectUri);
1531
+ }
1532
+ return new Promise((resolve, reject) => {
1533
+ (() => __async(this, null, function* () {
1534
+ const startedAt = Date.now();
1535
+ while (true) {
1536
+ try {
1537
+ if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
1538
+ onCancel == null ? void 0 : onCancel();
1539
+ return reject("canceled");
1540
+ }
1541
+ yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
1542
+ const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
1543
+ if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
1544
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1545
+ return resolve(authState);
1546
+ }
1547
+ onPoll == null ? void 0 : onPoll();
1548
+ } catch (e) {
1549
+ console.error(e);
1550
+ return reject(e);
1551
+ }
1829
1552
  }
1830
- } catch (err) {
1831
- console.error(err);
1832
- this.isAwaitingFarcaster = false;
1833
- }
1834
- }
1553
+ }))();
1554
+ });
1835
1555
  });
1836
1556
  }
1837
1557
  /**
1838
1558
  * Generates a URL for the user to log in with OAuth using a desire method.
1839
1559
  *
1840
1560
  * @param {Object} opts the options object
1841
- * @param {OAuthMethod} opts.method the third-party service to use for OAuth.
1561
+ * @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
1842
1562
  * @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
1843
1563
  * @returns {string} the URL for the user to log in with OAuth.
1844
1564
  */
1845
- getOAuthURL(_0) {
1846
- return __async(this, arguments, function* ({ method, deeplinkUrl }) {
1565
+ getOAuthUrl(_i) {
1566
+ return __async(this, null, function* () {
1567
+ var _j = _i, { method, deeplinkUrl } = _j, params = __objRest(_j, ["method", "deeplinkUrl"]);
1568
+ var _a;
1847
1569
  if (deeplinkUrl) {
1848
1570
  try {
1849
1571
  new URL(deeplinkUrl);
@@ -1851,14 +1573,13 @@ const _ParaCore = class _ParaCore {
1851
1573
  throw new Error("Invalid deeplink URL");
1852
1574
  }
1853
1575
  }
1854
- yield this.logout();
1855
- const res = yield this.touchSession(true);
1576
+ const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
1856
1577
  return (0, import_utils2.constructUrl)({
1857
- base: method === import_user_management_client.OAuthMethod.TELEGRAM ? (0, import_utils2.getPortalBaseURL)(this.ctx, true) : (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
1858
- path: `/auth/${method.toLowerCase()}`,
1578
+ base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
1579
+ path: `/auth/${method}`,
1859
1580
  params: {
1860
1581
  apiKey: this.ctx.apiKey,
1861
- sessionLookupId: res.data.sessionLookupId,
1582
+ sessionLookupId,
1862
1583
  deeplinkUrl
1863
1584
  }
1864
1585
  });
@@ -1872,37 +1593,54 @@ const _ParaCore = class _ParaCore {
1872
1593
  * @param {Window} [opts.popupWindow] the popup window being used for login.
1873
1594
  * @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
1874
1595
  */
1875
- waitForOAuth() {
1876
- return __async(this, arguments, function* ({ popupWindow } = {}) {
1877
- this.isAwaitingOAuth = true;
1878
- while (this.isAwaitingOAuth) {
1879
- try {
1880
- if (popupWindow == null ? void 0 : popupWindow.closed) {
1881
- return { isError: true, userExists: false };
1882
- }
1883
- yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
1884
- if (this.isAwaitingOAuth) {
1885
- const res = yield this.touchSession();
1886
- if (res.data.userId) {
1887
- const { userId, email } = res.data;
1888
- if (!this.loginEncryptionKeyPair) {
1889
- yield this.setLoginEncryptionKeyPair();
1596
+ verifyOAuth(_k) {
1597
+ return __async(this, null, function* () {
1598
+ var _l = _k, {
1599
+ method,
1600
+ deeplinkUrl,
1601
+ isCanceled = () => false,
1602
+ onCancel,
1603
+ onPoll,
1604
+ onOAuthUrl
1605
+ } = _l, urlOptions = __objRest(_l, [
1606
+ "method",
1607
+ "deeplinkUrl",
1608
+ "isCanceled",
1609
+ "onCancel",
1610
+ "onPoll",
1611
+ "onOAuthUrl"
1612
+ ]);
1613
+ let sessionLookupId;
1614
+ if (onOAuthUrl) {
1615
+ sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
1616
+ const oAuthUrl = yield this.getOAuthUrl({ method, deeplinkUrl, sessionLookupId });
1617
+ onOAuthUrl(oAuthUrl);
1618
+ } else {
1619
+ ({ sessionLookupId } = yield this.touchSession());
1620
+ }
1621
+ const startedAt = Date.now();
1622
+ return new Promise((resolve, reject) => {
1623
+ (() => __async(this, null, function* () {
1624
+ while (true) {
1625
+ try {
1626
+ if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
1627
+ onCancel == null ? void 0 : onCancel();
1628
+ return reject("canceled");
1890
1629
  }
1891
- yield this.setUserId(userId);
1892
- yield this.setEmail(email);
1893
- const userExists = yield this.checkIfUserExists({ email });
1894
- this.isAwaitingOAuth = false;
1895
- return {
1896
- userExists,
1897
- email
1898
- };
1630
+ yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
1631
+ const serverAuthState = yield this.ctx.client.verifyOAuth();
1632
+ if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
1633
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
1634
+ return resolve(authState);
1635
+ }
1636
+ onPoll == null ? void 0 : onPoll();
1637
+ } catch (err) {
1638
+ console.error(err);
1639
+ onPoll == null ? void 0 : onPoll();
1899
1640
  }
1900
1641
  }
1901
- } catch (err) {
1902
- console.error(err);
1903
- }
1904
- }
1905
- return { userExists: false };
1642
+ }))();
1643
+ });
1906
1644
  });
1907
1645
  }
1908
1646
  /**
@@ -1913,60 +1651,61 @@ const _ParaCore = class _ParaCore {
1913
1651
  * @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
1914
1652
  * @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
1915
1653
  **/
1916
- waitForLoginAndSetup() {
1654
+ waitForLogin() {
1917
1655
  return __async(this, arguments, function* ({
1918
- popupWindow,
1656
+ isCanceled = () => false,
1657
+ onCancel,
1658
+ onPoll,
1919
1659
  skipSessionRefresh = false
1920
1660
  } = {}) {
1921
- var _a;
1922
- if (!this.isExternalWalletAuth) {
1923
- this.externalWallets = {};
1924
- }
1925
- this.isAwaitingLogin = true;
1926
- while (this.isAwaitingLogin) {
1927
- try {
1928
- yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
1929
- if (!(yield this.isSessionActive())) {
1930
- if (popupWindow == null ? void 0 : popupWindow.closed) {
1931
- const resp2 = { isComplete: false, isError: true };
1932
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
1933
- return resp2;
1934
- }
1935
- continue;
1661
+ const startedAt = Date.now();
1662
+ return new Promise((resolve, reject) => {
1663
+ (() => __async(this, null, function* () {
1664
+ var _a;
1665
+ if (!this.isExternalWalletAuth) {
1666
+ this.externalWallets = {};
1936
1667
  }
1937
- const postLoginData = yield this.userSetupAfterLogin();
1938
- const needsWallet = (_a = postLoginData.data.needsWallet) != null ? _a : false;
1939
- if (!needsWallet) {
1940
- if (this.currentWalletIdsArray.length === 0) {
1941
- if (popupWindow == null ? void 0 : popupWindow.closed) {
1942
- const resp2 = { isComplete: false, isError: true };
1943
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
1944
- return resp2;
1945
- } else {
1668
+ while (true) {
1669
+ if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
1670
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
1671
+ onCancel == null ? void 0 : onCancel();
1672
+ return reject("canceled");
1673
+ }
1674
+ yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
1675
+ try {
1676
+ let session = yield this.touchSession();
1677
+ if (!session.isAuthenticated) {
1678
+ onPoll == null ? void 0 : onPoll();
1946
1679
  continue;
1947
1680
  }
1681
+ session = yield this.userSetupAfterLogin();
1682
+ const needsWallet = (_a = session.needsWallet) != null ? _a : false;
1683
+ if (!needsWallet) {
1684
+ if (this.currentWalletIdsArray.length === 0) {
1685
+ onPoll == null ? void 0 : onPoll();
1686
+ continue;
1687
+ }
1688
+ }
1689
+ const fetchedWallets = yield this.fetchWallets();
1690
+ const tempSharesRes = yield this.getTransmissionKeyShares();
1691
+ if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
1692
+ yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
1693
+ yield this.claimPregenWallets();
1694
+ const resp = {
1695
+ needsWallet: needsWallet || Object.values(this.wallets).length === 0,
1696
+ partnerId: session.partnerId
1697
+ };
1698
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp);
1699
+ return resolve(resp);
1700
+ }
1701
+ onPoll == null ? void 0 : onPoll();
1702
+ } catch (err) {
1703
+ console.error(err);
1704
+ onPoll == null ? void 0 : onPoll();
1948
1705
  }
1949
1706
  }
1950
- const fetchedWallets = yield this.fetchWallets();
1951
- const tempSharesRes = yield this.getTransmissionKeyShares();
1952
- if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
1953
- yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
1954
- yield this.claimPregenWallets();
1955
- const resp2 = {
1956
- isComplete: true,
1957
- needsWallet: needsWallet || Object.values(this.wallets).length === 0,
1958
- partnerId: postLoginData.data.partnerId
1959
- };
1960
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp2);
1961
- return resp2;
1962
- }
1963
- } catch (err) {
1964
- console.error(err);
1965
- }
1966
- }
1967
- const resp = { isComplete: false };
1968
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp, "exitted login without setting up user");
1969
- return resp;
1707
+ }))();
1708
+ });
1970
1709
  });
1971
1710
  }
1972
1711
  /**
@@ -1978,14 +1717,15 @@ const _ParaCore = class _ParaCore {
1978
1717
  * @returns a URL for the user to reauthenticate.
1979
1718
  **/
1980
1719
  refreshSession() {
1981
- return __async(this, arguments, function* ({ shouldOpenPopup = false } = {}) {
1982
- const res = yield this.touchSession(true);
1720
+ return __async(this, arguments, function* ({
1721
+ shouldOpenPopup = false
1722
+ } = {}) {
1723
+ const { sessionId } = yield this.touchSession(true);
1983
1724
  if (!this.loginEncryptionKeyPair) {
1984
1725
  yield this.setLoginEncryptionKeyPair();
1985
1726
  }
1986
- const link = yield this.getWebAuthURLForLogin({
1987
- sessionId: res.data.sessionId,
1988
- loginEncryptionPublicKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair)
1727
+ const link = yield this.getLoginUrl({
1728
+ sessionId
1989
1729
  });
1990
1730
  if (shouldOpenPopup) {
1991
1731
  this.platformUtils.openPopup(link);
@@ -1999,13 +1739,13 @@ const _ParaCore = class _ParaCore {
1999
1739
  **/
2000
1740
  userSetupAfterLogin() {
2001
1741
  return __async(this, null, function* () {
2002
- const res = yield this.touchSession();
2003
- yield this.setUserId(res.data.userId);
2004
- if (res.data.currentWalletIds && res.data.currentWalletIds !== this.currentWalletIds)
2005
- yield this.setCurrentWalletIds(res.data.currentWalletIds, {
2006
- sessionLookupId: this.isPortal() ? res.data.sessionLookupId : void 0
1742
+ const session = yield this.touchSession();
1743
+ yield this.setUserId(session.userId);
1744
+ if (session.currentWalletIds && session.currentWalletIds !== this.currentWalletIds)
1745
+ yield this.setCurrentWalletIds(session.currentWalletIds, {
1746
+ sessionLookupId: this.isPortal() ? session.sessionLookupId : void 0
2007
1747
  });
2008
- return res;
1748
+ return session;
2009
1749
  });
2010
1750
  }
2011
1751
  /**
@@ -2016,8 +1756,8 @@ const _ParaCore = class _ParaCore {
2016
1756
  **/
2017
1757
  getTransmissionKeyShares() {
2018
1758
  return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
2019
- const res = yield this.touchSession();
2020
- const sessionLookupId = isForNewDevice ? `${res.data.sessionLookupId}-new-device` : res.data.sessionLookupId;
1759
+ const session = yield this.touchSession();
1760
+ const sessionLookupId = isForNewDevice ? `${session.sessionLookupId}-new-device` : session.sessionLookupId;
2021
1761
  return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
2022
1762
  });
2023
1763
  }
@@ -2144,7 +1884,7 @@ const _ParaCore = class _ParaCore {
2144
1884
  *
2145
1885
  * @param {Object} [opts] the options object.
2146
1886
  * @param {boolean} [opts.skipDistribute] if `true`, the wallets' recovery share will not be distributed.
2147
- * @param {WalletType[]} [opts.types] the types of wallets to create.
1887
+ * @param {TWalletType[]} [opts.types] the types of wallets to create.
2148
1888
  * @returns {Object} the wallets created, their ids, and the recovery secret.
2149
1889
  **/
2150
1890
  createWalletPerType() {
@@ -2215,7 +1955,7 @@ const _ParaCore = class _ParaCore {
2215
1955
  /**
2216
1956
  * Creates a new wallet.
2217
1957
  * @param {Object} opts the options object.
2218
- * @param {WalletType} opts.type the type of wallet to create.
1958
+ * @param {TWalletType} opts.type the type of wallet to create.
2219
1959
  * @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
2220
1960
  * @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
2221
1961
  **/
@@ -2226,14 +1966,15 @@ const _ParaCore = class _ParaCore {
2226
1966
  } = {}) {
2227
1967
  var _a, _b;
2228
1968
  this.requireApiKey();
1969
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2229
1970
  const walletType = yield this.assertIsValidWalletType(
2230
- _type != null ? _type : (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
1971
+ _type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
2231
1972
  );
2232
1973
  let signer;
2233
1974
  let wallet;
2234
1975
  let keygenRes;
2235
1976
  switch (walletType) {
2236
- case import_user_management_client.WalletType.SOLANA: {
1977
+ case "SOLANA": {
2237
1978
  keygenRes = yield this.platformUtils.ed25519Keygen(
2238
1979
  this.ctx,
2239
1980
  this.userId,
@@ -2259,7 +2000,7 @@ const _ParaCore = class _ParaCore {
2259
2000
  this.wallets[walletId] = {
2260
2001
  id: walletId,
2261
2002
  signer,
2262
- scheme: walletType === import_user_management_client.WalletType.SOLANA ? import_user_management_client.WalletScheme.ED25519 : import_user_management_client.WalletScheme.DKLS,
2003
+ scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
2263
2004
  type: walletType
2264
2005
  };
2265
2006
  wallet = this.wallets[walletId];
@@ -2276,7 +2017,7 @@ const _ParaCore = class _ParaCore {
2276
2017
  });
2277
2018
  }
2278
2019
  yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
2279
- [walletType]: [...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId]
2020
+ [walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
2280
2021
  }));
2281
2022
  const walletNoSigner = __spreadValues({}, wallet);
2282
2023
  delete walletNoSigner.signer;
@@ -2287,15 +2028,6 @@ const _ParaCore = class _ParaCore {
2287
2028
  return [wallet, recoveryShare];
2288
2029
  });
2289
2030
  }
2290
- /**
2291
- * Creates a new pregenerated wallet.
2292
- *
2293
- * @param {Object} opts the options object.
2294
- * @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
2295
- * @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
2296
- * @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
2297
- * @returns {Wallet} the created wallet.
2298
- **/
2299
2031
  createPregenWallet(opts) {
2300
2032
  return __async(this, null, function* () {
2301
2033
  return yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, opts);
@@ -2308,18 +2040,17 @@ const _ParaCore = class _ParaCore {
2308
2040
  * @param {Object} opts the options object.
2309
2041
  * @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
2310
2042
  * @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
2311
- * @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
2043
+ * @param {TWalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
2312
2044
  * @returns {Wallet[]} an array containing the created wallets.
2313
2045
  **/
2314
2046
  createPregenWalletPerType(_0) {
2315
2047
  return __async(this, arguments, function* ({
2316
2048
  types,
2317
- pregenIdentifier,
2318
- pregenIdentifierType = "EMAIL"
2049
+ pregenId
2319
2050
  }) {
2320
2051
  const wallets = [];
2321
2052
  for (const type of yield this.getTypesToCreate(types)) {
2322
- const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenIdentifier, pregenIdentifierType });
2053
+ const wallet = yield this.createPregenWallet({ type, pregenId });
2323
2054
  wallets.push(wallet);
2324
2055
  }
2325
2056
  return wallets;
@@ -2327,7 +2058,6 @@ const _ParaCore = class _ParaCore {
2327
2058
  }
2328
2059
  /**
2329
2060
  * Claims a pregenerated wallet.
2330
- *
2331
2061
  * @param {Object} opts the options object.
2332
2062
  * @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
2333
2063
  * @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
@@ -2335,12 +2065,11 @@ const _ParaCore = class _ParaCore {
2335
2065
  **/
2336
2066
  claimPregenWallets() {
2337
2067
  return __async(this, arguments, function* ({
2338
- pregenIdentifier,
2339
- pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
2068
+ pregenId
2340
2069
  } = {}) {
2341
2070
  var _a;
2342
2071
  this.requireApiKey();
2343
- const pregenWallets = pregenIdentifier && pregenIdentifierType ? yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType }) : yield this.getPregenWallets();
2072
+ const pregenWallets = pregenId ? yield this.getPregenWallets({ pregenId }) : yield this.getPregenWallets();
2344
2073
  if (pregenWallets.length === 0) {
2345
2074
  return void 0;
2346
2075
  }
@@ -2358,7 +2087,7 @@ const _ParaCore = class _ParaCore {
2358
2087
  for (const walletId of walletIds) {
2359
2088
  const wallet = this.wallets[walletId];
2360
2089
  let refreshedShare;
2361
- if (wallet.scheme === import_user_management_client.WalletScheme.ED25519) {
2090
+ if (wallet.scheme === "ED25519") {
2362
2091
  const distributeRes = yield (0, import_shareDistribution.distributeNewShare)({
2363
2092
  ctx: this.ctx,
2364
2093
  userId: this.userId,
@@ -2409,10 +2138,10 @@ const _ParaCore = class _ParaCore {
2409
2138
  updatePregenWalletIdentifier(_0) {
2410
2139
  return __async(this, arguments, function* ({
2411
2140
  walletId,
2412
- newPregenIdentifier,
2413
- newPregenIdentifierType
2141
+ newPregenId
2414
2142
  }) {
2415
2143
  this.requireApiKey();
2144
+ const [newPregenIdentifierType, newPregenIdentifier] = (0, import_user_management_client.toPregenTypeAndId)(newPregenId);
2416
2145
  yield this.ctx.client.updatePregenWallet(walletId, {
2417
2146
  pregenIdentifier: newPregenIdentifier,
2418
2147
  pregenIdentifierType: newPregenIdentifierType
@@ -2434,13 +2163,13 @@ const _ParaCore = class _ParaCore {
2434
2163
  * @returns {boolean} whether the pregen wallet exists
2435
2164
  **/
2436
2165
  hasPregenWallet(_0) {
2437
- return __async(this, arguments, function* ({
2438
- pregenIdentifier,
2439
- pregenIdentifierType
2440
- }) {
2166
+ return __async(this, arguments, function* ({ pregenId }) {
2441
2167
  this.requireApiKey();
2442
- const res = yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType });
2443
- const wallet = res.find((w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType);
2168
+ const [pregenIdentifierType, pregenIdentifier] = (0, import_user_management_client.toPregenTypeAndId)(pregenId);
2169
+ const wallets = yield this.getPregenWallets({ pregenId });
2170
+ const wallet = wallets.find(
2171
+ (w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType
2172
+ );
2444
2173
  if (!wallet) {
2445
2174
  return false;
2446
2175
  }
@@ -2455,13 +2184,10 @@ const _ParaCore = class _ParaCore {
2455
2184
  * @returns {Promise<WalletEntity[]>} the array of found wallets
2456
2185
  **/
2457
2186
  getPregenWallets() {
2458
- return __async(this, arguments, function* ({
2459
- pregenIdentifier,
2460
- pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
2461
- } = {}) {
2187
+ return __async(this, arguments, function* ({ pregenId } = {}) {
2462
2188
  this.requireApiKey();
2463
2189
  const res = yield this.ctx.client.getPregenWallets(
2464
- pregenIdentifier && pregenIdentifierType ? { [pregenIdentifierType]: [pregenIdentifier] } : this.pregenIds,
2190
+ pregenId ? (0, import_user_management_client.toPregenIds)(pregenId) : this.pregenIds,
2465
2191
  this.isPortal(),
2466
2192
  this.userId
2467
2193
  );
@@ -2469,21 +2195,37 @@ const _ParaCore = class _ParaCore {
2469
2195
  });
2470
2196
  }
2471
2197
  createGuestWallets() {
2472
- return __async(this, arguments, function* ({ types } = {}) {
2473
- const wallets = [];
2474
- const currentWalletIds = {};
2475
- const guestId = (0, import_utils2.newUuid)();
2476
- for (const type of yield this.getTypesToCreate(
2477
- types != null ? types : this.supportedWalletTypes.filter(({ optional }) => !optional).map(({ type: type2 }) => type2)
2478
- )) {
2479
- const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenIdentifier: guestId, pregenIdentifierType: "GUEST_ID" });
2480
- wallets.push(wallet);
2481
- (0, import_utils2.getEquivalentTypes)(type).filter((t) => __privateGet(this, _supportedWalletTypes).some(({ type: type2, optional }) => t === type2 && !optional)).forEach((eqType) => {
2482
- currentWalletIds[eqType] = [wallet.id];
2483
- });
2198
+ return __async(this, null, function* () {
2199
+ let error;
2200
+ if (__privateGet(this, _isCreateGuestWalletsPending)) {
2201
+ error = new Error("Guest wallets creation already in progress");
2202
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null, error.message);
2203
+ throw error;
2204
+ }
2205
+ if (this.isGuestMode) {
2206
+ error = new Error("Guest wallets already created");
2207
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null, error.message);
2208
+ throw error;
2209
+ }
2210
+ try {
2211
+ __privateSet(this, _isCreateGuestWalletsPending, true);
2212
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2213
+ const wallets = [];
2214
+ const guestId = (0, import_utils2.newUuid)();
2215
+ for (const type of yield this.getTypesToCreate(
2216
+ supportedWalletTypes.filter(({ optional }) => !optional).map(({ type: type2 }) => type2)
2217
+ )) {
2218
+ const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenId: { guestId } });
2219
+ wallets.push(wallet);
2220
+ }
2221
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, wallets);
2222
+ __privateSet(this, _isCreateGuestWalletsPending, false);
2223
+ return wallets;
2224
+ } catch (e) {
2225
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null, error == null ? void 0 : error.message);
2226
+ __privateSet(this, _isCreateGuestWalletsPending, false);
2227
+ throw error;
2484
2228
  }
2485
- yield this.setCurrentWalletIds(currentWalletIds);
2486
- return wallets;
2487
2229
  });
2488
2230
  }
2489
2231
  encodeWalletBase64(wallet) {
@@ -2521,9 +2263,7 @@ const _ParaCore = class _ParaCore {
2521
2263
  }
2522
2264
  getTransactionReviewUrl(transactionId, timeoutMs) {
2523
2265
  return __async(this, null, function* () {
2524
- const res = yield this.touchSession();
2525
2266
  return this.constructPortalUrl("txReview", {
2526
- partnerId: res.data.partnerId,
2527
2267
  pathId: transactionId,
2528
2268
  params: {
2529
2269
  email: this.email,
@@ -2532,21 +2272,20 @@ const _ParaCore = class _ParaCore {
2532
2272
  });
2533
2273
  });
2534
2274
  }
2535
- getOnRampTransactionUrl(_i) {
2275
+ getOnRampTransactionUrl(_m) {
2536
2276
  return __async(this, null, function* () {
2537
- var _j = _i, {
2277
+ var _n = _m, {
2538
2278
  purchaseId,
2539
2279
  providerKey
2540
- } = _j, walletParams = __objRest(_j, [
2280
+ } = _n, walletParams = __objRest(_n, [
2541
2281
  "purchaseId",
2542
2282
  "providerKey"
2543
2283
  ]);
2544
- const res = yield this.touchSession();
2284
+ const { sessionId } = yield this.touchSession();
2545
2285
  const [key, identifier] = (0, import_user_management_client.extractWalletRef)(walletParams);
2546
2286
  return this.constructPortalUrl("onRamp", {
2547
- partnerId: res.data.partnerId,
2548
2287
  pathId: purchaseId,
2549
- sessionId: res.data.sessionId,
2288
+ sessionId,
2550
2289
  params: {
2551
2290
  [key]: identifier,
2552
2291
  providerKey,
@@ -2571,7 +2310,10 @@ const _ParaCore = class _ParaCore {
2571
2310
  walletId,
2572
2311
  messageBase64,
2573
2312
  timeoutMs = 3e4,
2574
- cosmosSignDocBase64
2313
+ cosmosSignDocBase64,
2314
+ isCanceled = () => false,
2315
+ onCancel,
2316
+ onPoll
2575
2317
  }) {
2576
2318
  this.assertIsValidWalletId(walletId);
2577
2319
  const wallet = this.wallets[walletId];
@@ -2590,11 +2332,12 @@ const _ParaCore = class _ParaCore {
2590
2332
  (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_MESSAGE_EVENT, signRes);
2591
2333
  return signRes;
2592
2334
  }
2593
- yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
2594
2335
  while (true) {
2595
- if (Date.now() - timeStart > timeoutMs) {
2336
+ if (isCanceled() || Date.now() - timeStart > timeoutMs) {
2337
+ onCancel == null ? void 0 : onCancel();
2596
2338
  break;
2597
2339
  }
2340
+ yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
2598
2341
  try {
2599
2342
  yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
2600
2343
  } catch (err) {
@@ -2604,7 +2347,8 @@ const _ParaCore = class _ParaCore {
2604
2347
  }
2605
2348
  signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
2606
2349
  if (signRes.pendingTransactionId) {
2607
- yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
2350
+ onPoll == null ? void 0 : onPoll();
2351
+ continue;
2608
2352
  } else {
2609
2353
  break;
2610
2354
  }
@@ -2630,7 +2374,7 @@ const _ParaCore = class _ParaCore {
2630
2374
  }) {
2631
2375
  let signRes;
2632
2376
  switch (wallet.scheme) {
2633
- case import_user_management_client.WalletScheme.ED25519:
2377
+ case "ED25519":
2634
2378
  signRes = yield this.platformUtils.ed25519Sign(
2635
2379
  this.ctx,
2636
2380
  signerId,
@@ -2648,7 +2392,7 @@ const _ParaCore = class _ParaCore {
2648
2392
  wallet.signer,
2649
2393
  messageBase64,
2650
2394
  this.retrieveSessionCookie(),
2651
- wallet.scheme === import_user_management_client.WalletScheme.DKLS,
2395
+ wallet.scheme === "DKLS",
2652
2396
  cosmosSignDocBase64
2653
2397
  );
2654
2398
  break;
@@ -2669,7 +2413,10 @@ const _ParaCore = class _ParaCore {
2669
2413
  walletId,
2670
2414
  rlpEncodedTxBase64,
2671
2415
  chainId,
2672
- timeoutMs = 3e4
2416
+ timeoutMs = 3e4,
2417
+ isCanceled = () => false,
2418
+ onCancel,
2419
+ onPoll
2673
2420
  }) {
2674
2421
  this.assertIsValidWalletId(walletId);
2675
2422
  const wallet = this.wallets[walletId];
@@ -2685,7 +2432,7 @@ const _ParaCore = class _ParaCore {
2685
2432
  rlpEncodedTxBase64,
2686
2433
  chainId,
2687
2434
  this.retrieveSessionCookie(),
2688
- wallet.scheme === import_user_management_client.WalletScheme.DKLS
2435
+ wallet.scheme === "DKLS"
2689
2436
  );
2690
2437
  let timeStart = Date.now();
2691
2438
  if (signRes.pendingTransactionId) {
@@ -2697,11 +2444,12 @@ const _ParaCore = class _ParaCore {
2697
2444
  (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
2698
2445
  return signRes;
2699
2446
  }
2700
- yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
2701
2447
  while (true) {
2702
- if (Date.now() - timeStart > timeoutMs) {
2448
+ if (isCanceled() || Date.now() - timeStart > timeoutMs) {
2449
+ onCancel == null ? void 0 : onCancel();
2703
2450
  break;
2704
2451
  }
2452
+ yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
2705
2453
  try {
2706
2454
  yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
2707
2455
  } catch (err) {
@@ -2717,10 +2465,11 @@ const _ParaCore = class _ParaCore {
2717
2465
  rlpEncodedTxBase64,
2718
2466
  chainId,
2719
2467
  this.retrieveSessionCookie(),
2720
- wallet.scheme === import_user_management_client.WalletScheme.DKLS
2468
+ wallet.scheme === "DKLS"
2721
2469
  );
2722
2470
  if (signRes.pendingTransactionId) {
2723
- yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
2471
+ onPoll == null ? void 0 : onPoll();
2472
+ continue;
2724
2473
  } else {
2725
2474
  break;
2726
2475
  }
@@ -2737,44 +2486,6 @@ const _ParaCore = class _ParaCore {
2737
2486
  return signRes;
2738
2487
  });
2739
2488
  }
2740
- /**
2741
- * @deprecated
2742
- * Sends a transaction.
2743
- * @param walletId - id of the wallet to send the transaction from.
2744
- * @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
2745
- * @param chainId - chain id of the chain the transaction is being sent on.
2746
- **/
2747
- sendTransaction(_0) {
2748
- return __async(this, arguments, function* ({
2749
- walletId,
2750
- rlpEncodedTxBase64,
2751
- chainId
2752
- }) {
2753
- this.assertIsValidWalletId(walletId);
2754
- const wallet = this.wallets[walletId];
2755
- const signRes = yield this.platformUtils.sendTransaction(
2756
- this.ctx,
2757
- this.userId,
2758
- walletId,
2759
- this.wallets[walletId].signer,
2760
- rlpEncodedTxBase64,
2761
- chainId,
2762
- this.retrieveSessionCookie(),
2763
- wallet.scheme === import_user_management_client.WalletScheme.DKLS
2764
- );
2765
- if (signRes.pendingTransactionId) {
2766
- this.platformUtils.openPopup(
2767
- yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
2768
- { type: import_types.PopupType.SIGN_TRANSACTION_REVIEW }
2769
- );
2770
- const error = new import_errors.TransactionReviewError(
2771
- yield this.getTransactionReviewUrl(signRes.pendingTransactionId)
2772
- );
2773
- throw error;
2774
- }
2775
- return signRes;
2776
- });
2777
- }
2778
2489
  isProviderModalDisabled() {
2779
2490
  return !!this.disableProviderModal;
2780
2491
  }
@@ -2824,17 +2535,13 @@ const _ParaCore = class _ParaCore {
2824
2535
  * @param {boolean} excludeSigners - whether or not to exclude the signer from the exported wallets.
2825
2536
  * @returns {string} the serialized session
2826
2537
  */
2827
- exportSession({ excludeSigners } = {}) {
2538
+ exportSession({ excludeSigners = false } = {}) {
2828
2539
  const sessionInfo = {
2829
- email: this.email,
2540
+ authInfo: __privateGet(this, _authInfo),
2830
2541
  userId: this.userId,
2831
2542
  wallets: structuredClone(this.wallets),
2832
2543
  currentWalletIds: this.currentWalletIds,
2833
- sessionCookie: this.sessionCookie,
2834
- phone: this.phone,
2835
- countryCode: this.countryCode,
2836
- telegramUserId: this.telegramUserId,
2837
- farcasterUsername: this.farcasterUsername,
2544
+ sessionCookie: this.retrieveSessionCookie(),
2838
2545
  externalWallets: this.externalWallets
2839
2546
  };
2840
2547
  if (excludeSigners) {
@@ -2850,12 +2557,11 @@ const _ParaCore = class _ParaCore {
2850
2557
  */
2851
2558
  importSession(serializedInstanceBase64) {
2852
2559
  return __async(this, null, function* () {
2853
- var _a;
2560
+ var _a, _b;
2854
2561
  const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
2855
- const sessionInfo = JSON.parse(serializedInstance);
2856
- yield this.setEmail(sessionInfo.email);
2857
- yield this.setTelegramUserId(sessionInfo.telegramUserId);
2858
- yield this.setFarcasterUsername(sessionInfo.farcasterUsername);
2562
+ const sessionInfo = (0, import_utils2.jsonParse)(serializedInstance);
2563
+ const authInfo = (_a = sessionInfo.authInfo) != null ? _a : __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, sessionInfo);
2564
+ yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
2859
2565
  yield this.setUserId(sessionInfo.userId);
2860
2566
  yield this.setWallets(sessionInfo.wallets);
2861
2567
  yield this.setExternalWallets(sessionInfo.externalWallets || {});
@@ -2870,42 +2576,23 @@ const _ParaCore = class _ParaCore {
2870
2576
  const currentWalletIds = {};
2871
2577
  for (const walletId of Object.keys(sessionInfo.wallets)) {
2872
2578
  currentWalletIds[sessionInfo.wallets[walletId].type] = [
2873
- ...(_a = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _a : [],
2579
+ ...(_b = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _b : [],
2874
2580
  walletId
2875
2581
  ];
2876
2582
  }
2877
2583
  yield this.setCurrentWalletIds(currentWalletIds);
2878
2584
  }
2879
2585
  this.persistSessionCookie(sessionInfo.sessionCookie);
2880
- yield this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
2881
2586
  });
2882
2587
  }
2883
- exitAccountCreation() {
2884
- this.isAwaitingAccountCreation = false;
2885
- }
2886
- exitLogin() {
2887
- this.isAwaitingLogin = false;
2888
- }
2889
- exitFarcaster() {
2890
- this.isAwaitingFarcaster = false;
2891
- }
2892
- exitOAuth() {
2893
- this.isAwaitingOAuth = false;
2894
- }
2895
- exitLoops() {
2896
- this.exitAccountCreation();
2897
- this.exitLogin();
2898
- this.exitFarcaster();
2899
- this.exitOAuth();
2900
- }
2901
2588
  /**
2902
2589
  * Retrieves a token to verify the current session.
2903
2590
  * @returns {Promise<string>} the ID
2904
2591
  **/
2905
2592
  getVerificationToken() {
2906
2593
  return __async(this, null, function* () {
2907
- const { data } = yield this.touchSession();
2908
- return data.sessionLookupId;
2594
+ const { sessionLookupId } = yield this.touchSession();
2595
+ return sessionLookupId;
2909
2596
  });
2910
2597
  }
2911
2598
  /**
@@ -2930,22 +2617,18 @@ const _ParaCore = class _ParaCore {
2930
2617
  this.currentWalletIds = {};
2931
2618
  this.externalWallets = {};
2932
2619
  this.loginEncryptionKeyPair = void 0;
2933
- this.email = void 0;
2934
- this.telegramUserId = void 0;
2935
- this.phone = void 0;
2936
- this.countryCode = void 0;
2620
+ __privateSet(this, _authInfo, void 0);
2937
2621
  this.userId = void 0;
2938
2622
  this.sessionCookie = void 0;
2939
2623
  (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGOUT_EVENT, null);
2940
2624
  });
2941
2625
  }
2626
+ /** @deprecated */
2942
2627
  getSupportedCreateAuthMethods() {
2943
2628
  return __async(this, null, function* () {
2944
- const res = yield this.touchSession();
2945
- const partnerId = res.data.partnerId;
2946
- const partnerRes = yield this.ctx.client.getPartner(partnerId);
2629
+ const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2947
2630
  let supportedAuthMethods = /* @__PURE__ */ new Set();
2948
- for (const authMethod of partnerRes.data.partner.supportedAuthMethods) {
2631
+ for (const authMethod of partner.supportedAuthMethods) {
2949
2632
  supportedAuthMethods.add(import_user_management_client.AuthMethod[authMethod]);
2950
2633
  }
2951
2634
  return supportedAuthMethods;
@@ -2957,6 +2640,7 @@ const _ParaCore = class _ParaCore {
2957
2640
  * Doesn't work for all types of logging.
2958
2641
  **/
2959
2642
  toString() {
2643
+ var _a, _b, _c;
2960
2644
  const redactedWallets = Object.keys(this.wallets).reduce(
2961
2645
  (acc, walletId) => __spreadProps(__spreadValues({}, acc), {
2962
2646
  [walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
@@ -2974,16 +2658,15 @@ const _ParaCore = class _ParaCore {
2974
2658
  {}
2975
2659
  );
2976
2660
  const obj = {
2977
- supportedWalletTypes: this.supportedWalletTypes,
2978
- cosmosPrefix: this.cosmosPrefix,
2979
- email: this.email,
2980
- phone: this.phone,
2981
- countryCode: this.countryCode,
2982
- telegramUserId: this.telegramUserId,
2983
- farcasterUsername: this.farcasterUsername,
2661
+ partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
2662
+ supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
2663
+ cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
2664
+ authInfo: __privateGet(this, _authInfo),
2665
+ isGuestMode: this.isGuestMode,
2984
2666
  userId: this.userId,
2985
2667
  pregenIds: this.pregenIds,
2986
2668
  currentWalletIds: this.currentWalletIds,
2669
+ guestWalletIds: __privateGet(this, _ParaCore_instances, guestWalletIds_get),
2987
2670
  wallets: redactedWallets,
2988
2671
  externalWallets: redactedExternalWallets,
2989
2672
  loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
@@ -3000,25 +2683,201 @@ const _ParaCore = class _ParaCore {
3000
2683
  };
3001
2684
  return `Para ${JSON.stringify(obj, null, 2)}`;
3002
2685
  }
2686
+ getNewCredentialAndUrl() {
2687
+ return __async(this, arguments, function* ({
2688
+ authMethod = "PASSKEY",
2689
+ isForNewDevice = false,
2690
+ portalTheme,
2691
+ shorten = false
2692
+ } = {}) {
2693
+ this.assertIsAuthSet();
2694
+ let credentialId, urlType;
2695
+ switch (authMethod) {
2696
+ case "PASSKEY":
2697
+ ({
2698
+ data: { id: credentialId }
2699
+ } = yield this.ctx.client.addSessionPublicKey(this.userId, {
2700
+ status: import_user_management_client.PublicKeyStatus.PENDING,
2701
+ type: import_user_management_client.PublicKeyType.WEB
2702
+ }));
2703
+ urlType = "createAuth";
2704
+ break;
2705
+ case "PASSWORD":
2706
+ ({
2707
+ data: { id: credentialId }
2708
+ } = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
2709
+ status: import_user_management_client.PasswordStatus.PENDING
2710
+ }));
2711
+ urlType = "createPassword";
2712
+ break;
2713
+ }
2714
+ const url = this.isNativePasskey && urlType === "createAuth" ? void 0 : yield this.constructPortalUrl(urlType, {
2715
+ isForNewDevice,
2716
+ pathId: credentialId,
2717
+ portalTheme,
2718
+ shorten
2719
+ });
2720
+ return __spreadValues({ credentialId }, url ? { url } : {});
2721
+ });
2722
+ }
2723
+ /**
2724
+ * Returns a Para Portal URL for logging in with a WebAuth passkey or a password.
2725
+ * @param {Object} opts the options object
2726
+ * @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
2727
+ * @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
2728
+ * @param {Theme} opts.portalTheme the Para Portal theme to apply to the password creation URL, if other than the default theme
2729
+ * @returns {SignUpOrLogInResponse} an object in the form of either: `{ stage: 'verify' }` or `{ stage: 'login'; passkeyUrl?: string; passwordUrl?: string; biometricHints?: BiometricLocationHint[] }`
2730
+ */
2731
+ getLoginUrl(_0) {
2732
+ return __async(this, arguments, function* ({
2733
+ authMethod = "PASSKEY",
2734
+ shorten = false,
2735
+ portalTheme,
2736
+ sessionId
2737
+ }) {
2738
+ if (!sessionId) {
2739
+ sessionId = (yield this.touchSession()).sessionLookupId;
2740
+ }
2741
+ this.assertIsAuthSet();
2742
+ let urlType;
2743
+ switch (authMethod) {
2744
+ case "PASSKEY":
2745
+ urlType = "loginAuth";
2746
+ break;
2747
+ case "PASSWORD":
2748
+ urlType = "loginPassword";
2749
+ break;
2750
+ default:
2751
+ throw new Error(`invalid authentication method: '${authMethod}'`);
2752
+ }
2753
+ return this.constructPortalUrl(urlType, {
2754
+ sessionId,
2755
+ shorten,
2756
+ portalTheme
2757
+ });
2758
+ });
2759
+ }
2760
+ signUpOrLogIn(_o) {
2761
+ return __async(this, null, function* () {
2762
+ var _p = _o, { auth } = _p, urlOptions = __objRest(_p, ["auth"]);
2763
+ const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
2764
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
2765
+ });
2766
+ }
2767
+ verifyNewAccount(_q) {
2768
+ return __async(this, null, function* () {
2769
+ var _r = _q, {
2770
+ verificationCode
2771
+ } = _r, urlOptions = __objRest(_r, [
2772
+ "verificationCode"
2773
+ ]);
2774
+ this.assertIsAuthSet(["email", "phone"]);
2775
+ const userId = this.assertUserId();
2776
+ const serverAuthState = yield this.ctx.client.verifyNewAccount(userId, {
2777
+ verificationCode
2778
+ });
2779
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
2780
+ });
2781
+ }
3003
2782
  };
3004
- _supportedWalletTypes = new WeakMap();
3005
- _supportedWalletTypesOpt = new WeakMap();
2783
+ _authInfo = new WeakMap();
2784
+ _partner = new WeakMap();
3006
2785
  _ParaCore_instances = new WeakSet();
2786
+ assertPartner_fn = function() {
2787
+ return __async(this, null, function* () {
2788
+ var _a, _b;
2789
+ if (!__privateGet(this, _partner)) {
2790
+ yield this.touchSession();
2791
+ }
2792
+ if (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== __privateGet(this, _partner).cosmosPrefix) {
2793
+ this.ctx.cosmosPrefix = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix;
2794
+ }
2795
+ return __privateGet(this, _partner);
2796
+ });
2797
+ };
2798
+ guestWalletIds_get = function() {
2799
+ var _a, _b, _c;
2800
+ if (!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes)) {
2801
+ return {};
2802
+ }
2803
+ const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
2804
+ return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
2805
+ if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
2806
+ return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) => __privateGet(this, _partner).supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
2807
+ var _a2;
2808
+ return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
2809
+ }, {}));
2810
+ }
2811
+ return acc;
2812
+ }, {}) : {};
2813
+ };
2814
+ guestWalletIdsArray_get = function() {
2815
+ return Object.entries(__privateGet(this, _ParaCore_instances, guestWalletIds_get)).reduce((acc, [type, ids]) => {
2816
+ return [...acc, ...ids.map((id) => [id, type])];
2817
+ }, []);
2818
+ };
2819
+ toAuthInfo_fn = function({
2820
+ email,
2821
+ phone,
2822
+ countryCode,
2823
+ farcasterUsername,
2824
+ telegramUserId,
2825
+ externalWalletAddress
2826
+ }) {
2827
+ let auth;
2828
+ switch (true) {
2829
+ case !!email:
2830
+ auth = { email };
2831
+ break;
2832
+ case !!phone:
2833
+ {
2834
+ const validPhone = (0, import_utils2.formatPhoneNumber)(phone, countryCode);
2835
+ if (validPhone) auth = { phone: (0, import_utils2.formatPhoneNumber)(phone, countryCode) };
2836
+ }
2837
+ break;
2838
+ case !!farcasterUsername:
2839
+ auth = { farcasterUsername };
2840
+ break;
2841
+ case !!telegramUserId:
2842
+ auth = { telegramUserId };
2843
+ break;
2844
+ case !!externalWalletAddress:
2845
+ auth = { externalWalletAddress };
2846
+ break;
2847
+ }
2848
+ return (0, import_user_management_client.extractAuthInfo)(auth);
2849
+ };
2850
+ setAuthInfo_fn = function(authInfo) {
2851
+ return __async(this, null, function* () {
2852
+ __privateSet(this, _authInfo, authInfo);
2853
+ yield this.localStorageSetItem(constants.LOCAL_STORAGE_AUTH_INFO, JSON.stringify(authInfo));
2854
+ yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_EMAIL);
2855
+ yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_PHONE);
2856
+ yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_COUNTRY_CODE);
2857
+ yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME);
2858
+ yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID);
2859
+ });
2860
+ };
2861
+ getPartner_fn = function(partnerId) {
2862
+ return __async(this, null, function* () {
2863
+ const res = yield this.ctx.client.getPartner(partnerId);
2864
+ __privateSet(this, _partner, res.data.partner);
2865
+ return __privateGet(this, _partner);
2866
+ });
2867
+ };
3007
2868
  createPregenWallet_fn = function(opts) {
3008
2869
  return __async(this, null, function* () {
3009
2870
  var _a, _b;
3010
- const {
3011
- type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
3012
- pregenIdentifier,
3013
- pregenIdentifierType = "EMAIL"
3014
- } = opts;
2871
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2872
+ const { type: _type = (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type, pregenId } = opts;
3015
2873
  this.requireApiKey();
3016
2874
  const walletType = yield this.assertIsValidWalletType(
3017
- _type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
2875
+ _type != null ? _type : (_b = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
3018
2876
  );
2877
+ const [pregenIdentifierType, pregenIdentifier] = (0, import_user_management_client.toPregenTypeAndId)(pregenId);
3019
2878
  let keygenRes;
3020
2879
  switch (walletType) {
3021
- case import_user_management_client.WalletType.SOLANA:
2880
+ case "SOLANA":
3022
2881
  keygenRes = yield this.platformUtils.ed25519PreKeygen(
3023
2882
  this.ctx,
3024
2883
  pregenIdentifier,
@@ -3042,7 +2901,7 @@ createPregenWallet_fn = function(opts) {
3042
2901
  this.wallets[walletId] = {
3043
2902
  id: walletId,
3044
2903
  signer,
3045
- scheme: walletType === import_user_management_client.WalletType.SOLANA ? import_user_management_client.WalletScheme.ED25519 : import_user_management_client.WalletScheme.DKLS,
2904
+ scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
3046
2905
  type: walletType,
3047
2906
  isPregen: true,
3048
2907
  pregenIdentifier,
@@ -3053,6 +2912,114 @@ createPregenWallet_fn = function(opts) {
3053
2912
  return this.wallets[walletId];
3054
2913
  });
3055
2914
  };
2915
+ _isCreateGuestWalletsPending = new WeakMap();
2916
+ prepareAuthState_fn = function(_0) {
2917
+ return __async(this, arguments, function* (serverAuthState, opts = {}) {
2918
+ if (!opts.sessionLookupId && serverAuthState.stage === "login") {
2919
+ opts.sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
2920
+ }
2921
+ const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
2922
+ const authInfo = __spreadValues(__spreadValues({}, (0, import_user_management_client.extractAuthInfo)(auth, { isRequired: true })), Object.fromEntries(
2923
+ Object.entries({
2924
+ displayName,
2925
+ pfpUrl,
2926
+ username,
2927
+ externalWallet
2928
+ }).filter(([_, v]) => !!v)
2929
+ ));
2930
+ yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
2931
+ yield this.assertIsAuthSet();
2932
+ if (!!externalWallet) {
2933
+ yield this.setExternalWallet(externalWallet);
2934
+ }
2935
+ if (!!userId) {
2936
+ yield this.setUserId(userId);
2937
+ }
2938
+ let authState;
2939
+ switch (serverAuthState.stage) {
2940
+ case "verify":
2941
+ authState = serverAuthState;
2942
+ break;
2943
+ case "login":
2944
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
2945
+ break;
2946
+ case "signup":
2947
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
2948
+ break;
2949
+ }
2950
+ return authState;
2951
+ });
2952
+ };
2953
+ prepareLogin_fn = function() {
2954
+ return __async(this, null, function* () {
2955
+ yield this.logout();
2956
+ const { sessionLookupId } = yield this.touchSession(true);
2957
+ if (!this.loginEncryptionKeyPair) {
2958
+ yield this.setLoginEncryptionKeyPair();
2959
+ }
2960
+ return sessionLookupId;
2961
+ });
2962
+ };
2963
+ prepareLoginState_fn = function(_0, _1) {
2964
+ return __async(this, arguments, function* (loginState, {
2965
+ useShortUrls: shorten = false,
2966
+ portalTheme,
2967
+ sessionLookupId
2968
+ }) {
2969
+ const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
2970
+ return __spreadValues(__spreadValues(__spreadValues({}, authState), !this.isNativePasskey && loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY) ? {
2971
+ passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
2972
+ passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
2973
+ sessionId: sessionLookupId,
2974
+ newDevice: {
2975
+ sessionId: sessionLookupId,
2976
+ encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair)
2977
+ },
2978
+ shorten,
2979
+ portalTheme
2980
+ })
2981
+ } : {}), loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) ? {
2982
+ passwordUrl: yield this.constructPortalUrl("loginPassword", {
2983
+ sessionId: sessionLookupId,
2984
+ shorten,
2985
+ portalTheme
2986
+ })
2987
+ } : {});
2988
+ });
2989
+ };
2990
+ prepareSignUpState_fn = function(_0, _1) {
2991
+ return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
2992
+ const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
2993
+ const [isPasskey, isPassword] = [
2994
+ signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY),
2995
+ signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD)
2996
+ ];
2997
+ if (!isPasskey && !isPassword) {
2998
+ throw new Error(
2999
+ "No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or passwords in your Developer Portal settings."
3000
+ );
3001
+ }
3002
+ const signupState = authState;
3003
+ if (isPasskey) {
3004
+ const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
3005
+ authMethod: "PASSKEY",
3006
+ shorten
3007
+ });
3008
+ if (passkeyUrl) signupState.passkeyUrl = passkeyUrl;
3009
+ signupState.passkeyId = passkeyId;
3010
+ }
3011
+ if (isPassword) {
3012
+ const { url: passwordUrl, credentialId: passwordId } = yield this.getNewCredentialAndUrl({
3013
+ authMethod: "PASSWORD",
3014
+ portalTheme,
3015
+ shorten
3016
+ });
3017
+ signupState.passwordUrl = passwordUrl;
3018
+ signupState.passwordId = passwordId;
3019
+ }
3020
+ return signupState;
3021
+ });
3022
+ };
3056
3023
  _ParaCore.version = constants.PARA_CORE_VERSION;
3057
3024
  let ParaCore = _ParaCore;
3058
3025
  // Annotate the CommonJS export names for ESM import in node: