@getpara/core-sdk 2.0.0-alpha.5 → 2.0.0-alpha.50

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.
@@ -99,7 +99,7 @@ var import_recovery = require("./shares/recovery.js");
99
99
  var import_utils2 = require("./utils/index.js");
100
100
  var import_errors = require("./errors.js");
101
101
  var constants = __toESM(require("./constants.js"));
102
- var _authInfo, _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;
102
+ var _authInfo, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, assertIsLinkingAccount_fn, assertIsLinkingAccountOrStart_fn, getOAuthUrl_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareLoginState_fn, prepareSignUpState_fn;
103
103
  if (typeof global !== "undefined") {
104
104
  global.Buffer = global.Buffer || import_buffer.Buffer;
105
105
  } else if (typeof window !== "undefined") {
@@ -111,22 +111,17 @@ if (typeof global !== "undefined") {
111
111
  }
112
112
  const { pki, jsbn } = import_node_forge.default;
113
113
  const _ParaCore = class _ParaCore {
114
- /**
115
- * Constructs a new `ParaCore` instance.
116
- * @param env - `Environment` to use.
117
- * @param apiKey - API key to use.
118
- * @param opts - Additional constructor options; see `ConstructorOpts`.
119
- * @returns - A new ParaCore instance.
120
- */
121
- constructor(env, apiKey, opts) {
114
+ constructor(envOrApiKey, apiKeyOrOpts, opts) {
122
115
  __privateAdd(this, _ParaCore_instances);
123
116
  __privateAdd(this, _authInfo);
124
117
  this.isNativePasskey = false;
125
- __privateAdd(this, _partner);
118
+ this.isReady = false;
119
+ this.accountLinkInProgress = void 0;
126
120
  this.isAwaitingAccountCreation = false;
127
121
  this.isAwaitingLogin = false;
128
122
  this.isAwaitingFarcaster = false;
129
123
  this.isAwaitingOAuth = false;
124
+ this.isWorkerInitialized = false;
130
125
  /**
131
126
  * 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.
132
127
  */
@@ -135,6 +130,7 @@ const _ParaCore = class _ParaCore {
135
130
  * Wallets associated with the `ParaCore` instance.
136
131
  */
137
132
  this.externalWallets = {};
133
+ this.onRampPopup = void 0;
138
134
  this.localStorageGetItem = (key) => {
139
135
  return this.platformUtils.localStorage.get(key);
140
136
  };
@@ -162,10 +158,17 @@ const _ParaCore = class _ParaCore {
162
158
  */
163
159
  this.clearStorage = (type = "all") => __async(this, null, function* () {
164
160
  const isAll = type === "all";
165
- (isAll || type === "local") && this.platformUtils.localStorage.clear(constants.PREFIX);
166
- (isAll || type === "session") && this.platformUtils.sessionStorage.clear(constants.PREFIX);
161
+ if (isAll || type === "local") {
162
+ this.platformUtils.localStorage.clear(constants.PREFIX);
163
+ this.platformUtils.localStorage.clear(constants.PARA_PREFIX);
164
+ }
165
+ if (isAll || type === "session") {
166
+ this.platformUtils.sessionStorage.clear(constants.PREFIX);
167
+ this.platformUtils.sessionStorage.clear(constants.PARA_PREFIX);
168
+ }
167
169
  if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
168
170
  this.platformUtils.secureStorage.clear(constants.PREFIX);
171
+ this.platformUtils.secureStorage.clear(constants.PARA_PREFIX);
169
172
  }
170
173
  });
171
174
  this.trackError = (methodName, err) => __async(this, null, function* () {
@@ -286,6 +289,16 @@ const _ParaCore = class _ParaCore {
286
289
  const _externalWallets = JSON.parse(stringExternalWallets || "{}");
287
290
  this.setExternalWallets(_externalWallets);
288
291
  };
292
+ this.initializeWorker = () => __async(this, null, function* () {
293
+ if (!this.isWorkerInitialized && !this.ctx.disableWebSockets && !this.ctx.disableWorkers) {
294
+ try {
295
+ this.isWorkerInitialized = true;
296
+ yield this.platformUtils.initializeWorker(this.ctx);
297
+ } catch (e) {
298
+ this.devLog("error initializing worker:", e);
299
+ }
300
+ }
301
+ });
289
302
  /**
290
303
  * Creates several new wallets with the desired types. If no types are provided, this method
291
304
  * will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
@@ -302,8 +315,29 @@ const _ParaCore = class _ParaCore {
302
315
  }) {
303
316
  return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
304
317
  });
305
- if (!apiKey) {
306
- throw new Error("A Para API key is required.");
318
+ let env, apiKey;
319
+ const actualArgs = Array.from(arguments).filter((arg) => arg !== void 0);
320
+ const actualArgumentCount = actualArgs.length;
321
+ if (actualArgumentCount === 1) {
322
+ if (Object.values(import_types.Environment).includes(envOrApiKey)) {
323
+ throw new Error("A Para API key is required.");
324
+ }
325
+ env = _ParaCore.resolveEnvironment(void 0, actualArgs[0]);
326
+ apiKey = actualArgs[0];
327
+ opts = void 0;
328
+ } else if (actualArgumentCount === 2) {
329
+ if (typeof apiKeyOrOpts === "object" && apiKeyOrOpts !== null) {
330
+ env = _ParaCore.resolveEnvironment(void 0, envOrApiKey);
331
+ apiKey = envOrApiKey;
332
+ opts = apiKeyOrOpts;
333
+ } else {
334
+ env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
335
+ apiKey = apiKeyOrOpts;
336
+ opts = void 0;
337
+ }
338
+ } else {
339
+ env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
340
+ apiKey = apiKeyOrOpts;
307
341
  }
308
342
  if (!opts) opts = {};
309
343
  let isE2E = false;
@@ -326,6 +360,7 @@ const _ParaCore = class _ParaCore {
326
360
  this.portalTheme = opts.portalTheme;
327
361
  this.platformUtils = this.getPlatformUtils();
328
362
  this.disableProviderModal = this.platformUtils.disableProviderModal;
363
+ this.fetchPregenWalletsOverride = opts.fetchPregenWalletsOverride;
329
364
  if (opts.useStorageOverrides) {
330
365
  this.localStorageGetItem = opts.localStorageGetItemOverride;
331
366
  this.localStorageSetItem = opts.localStorageSetItemOverride;
@@ -417,6 +452,8 @@ const _ParaCore = class _ParaCore {
417
452
  get externalWalletConnectionType() {
418
453
  if (this.isExternalWalletAuth) {
419
454
  return "AUTHENTICATED";
455
+ } else if (this.isExternalWalletWithVerification) {
456
+ return "VERIFICATION";
420
457
  } else if (!!Object.keys(this.externalWallets).length) {
421
458
  return "CONNECTION_ONLY";
422
459
  }
@@ -439,16 +476,28 @@ const _ParaCore = class _ParaCore {
439
476
  return (0, import_user_management_client.isTelegram)((_a = this.authInfo) == null ? void 0 : _a.auth);
440
477
  }
441
478
  get isExternalWalletAuth() {
442
- var _a;
443
- return (0, import_user_management_client.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth);
479
+ var _a, _b, _c;
480
+ return (0, import_user_management_client.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) && !!((_c = (_b = __privateGet(this, _authInfo)) == null ? void 0 : _b.externalWallet) == null ? void 0 : _c.withFullParaAuth);
481
+ }
482
+ get isExternalWalletWithVerification() {
483
+ var _a, _b, _c;
484
+ return (0, import_user_management_client.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) && !!((_c = (_b = __privateGet(this, _authInfo)) == null ? void 0 : _b.externalWallet) == null ? void 0 : _c.withVerification);
444
485
  }
445
486
  get partnerId() {
446
487
  var _a;
447
- return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id;
488
+ return (_a = this.partner) == null ? void 0 : _a.id;
489
+ }
490
+ get partnerName() {
491
+ var _a;
492
+ return (_a = this.partner) == null ? void 0 : _a.displayName;
493
+ }
494
+ get partnerLogo() {
495
+ var _a;
496
+ return (_a = this.partner) == null ? void 0 : _a.logoUrl;
448
497
  }
449
498
  get currentWalletIdsArray() {
450
499
  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(
500
+ return ((_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
452
501
  (acc, { type }) => {
453
502
  var _a2;
454
503
  return [
@@ -488,19 +537,23 @@ const _ParaCore = class _ParaCore {
488
537
  }
489
538
  get isNoWalletConfig() {
490
539
  var _a;
491
- return !!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) && __privateGet(this, _partner).supportedWalletTypes.length === 0;
540
+ return !!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) && this.partner.supportedWalletTypes.length === 0;
492
541
  }
493
542
  get supportedWalletTypes() {
494
543
  var _a, _b;
495
- return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
544
+ return (_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
496
545
  }
497
546
  get cosmosPrefix() {
498
547
  var _a;
499
- return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
548
+ return (_a = this.partner) == null ? void 0 : _a.cosmosPrefix;
549
+ }
550
+ get supportedAccountLinks() {
551
+ var _a, _b;
552
+ return (_b = (_a = this.partner) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...import_user_management_client.LINKED_ACCOUNT_TYPES];
500
553
  }
501
554
  get isWalletTypeEnabled() {
502
555
  var _a;
503
- return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
556
+ return (((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
504
557
  return __spreadProps(__spreadValues({}, acc), { [type]: true });
505
558
  }, {});
506
559
  }
@@ -549,7 +602,7 @@ const _ParaCore = class _ParaCore {
549
602
  }
550
603
  isWalletSupported(wallet) {
551
604
  var _a, _b;
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);
605
+ return !((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || (0, import_utils2.isWalletSupported)((_b = this.partner.supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
553
606
  }
554
607
  isWalletOwned(wallet) {
555
608
  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;
@@ -575,12 +628,12 @@ const _ParaCore = class _ParaCore {
575
628
  } else {
576
629
  const wallet = this.wallets[walletId];
577
630
  const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
578
- if (forbidPregen && isUnclaimed) {
631
+ if (forbidPregen && isUnclaimed && wallet.pregenIdentifierType !== "GUEST_ID") {
579
632
  error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
580
633
  } else if (!isOwned && !isUnclaimed) {
581
634
  error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
582
635
  } else if (!this.isWalletSupported(wallet)) {
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(", ")}`;
636
+ error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b = this.partner) == null ? void 0 : _b.supportedWalletTypes) || []).map(({ type }) => type).join(", ")}`;
584
637
  } else if (types && (!(0, import_utils2.getEquivalentTypes)(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
585
638
  var _a2, _b2;
586
639
  return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
@@ -611,7 +664,7 @@ const _ParaCore = class _ParaCore {
611
664
  if (this.externalWallets[walletId]) {
612
665
  const wallet2 = this.externalWallets[walletId];
613
666
  return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, {
614
- prefix: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix,
667
+ prefix: (_a = this.partner) == null ? void 0 : _a.cosmosPrefix,
615
668
  targetLength: options.targetLength
616
669
  }) : wallet2.address;
617
670
  }
@@ -623,7 +676,7 @@ const _ParaCore = class _ParaCore {
623
676
  let prefix;
624
677
  switch (wallet.type) {
625
678
  case "COSMOS":
626
- prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
679
+ prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = this.partner) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
627
680
  str = (0, import_utils2.getCosmosAddress)(wallet.publicKey, prefix);
628
681
  break;
629
682
  default:
@@ -658,8 +711,8 @@ const _ParaCore = class _ParaCore {
658
711
  return __async(this, arguments, function* (type, opts = {}) {
659
712
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
660
713
  const [isCreate, isLogin, isOnRamp] = [
661
- ["createAuth", "createPassword"].includes(type),
662
- ["loginAuth", "loginPassword"].includes(type),
714
+ ["createAuth", "createPassword", "createPIN"].includes(type),
715
+ ["loginAuth", "loginPassword", "loginPIN"].includes(type),
663
716
  type === "onRamp"
664
717
  ];
665
718
  if (isCreate || isLogin) {
@@ -673,13 +726,17 @@ const _ParaCore = class _ParaCore {
673
726
  if (!this.loginEncryptionKeyPair) {
674
727
  yield this.setLoginEncryptionKeyPair();
675
728
  }
676
- const base = type === "onRamp" ? (0, import_utils2.getPortalBaseURL)(this.ctx) : yield this.getPortalURL();
729
+ const base = type === "onRamp" || type === "telegramLogin" ? (0, import_utils2.getPortalBaseURL)(this.ctx, type === "telegramLogin") : yield this.getPortalURL();
677
730
  let path;
678
731
  switch (type) {
679
732
  case "createPassword": {
680
733
  path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
681
734
  break;
682
735
  }
736
+ case "createPIN": {
737
+ path = `/web/users/${this.userId}/pin/${opts.pathId}`;
738
+ break;
739
+ }
683
740
  case "createAuth": {
684
741
  path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
685
742
  break;
@@ -692,26 +749,43 @@ const _ParaCore = class _ParaCore {
692
749
  path = "/web/biometrics/login";
693
750
  break;
694
751
  }
752
+ case "loginPIN": {
753
+ path = "/web/pin/login";
754
+ break;
755
+ }
695
756
  case "txReview": {
696
757
  path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
697
758
  break;
698
759
  }
699
760
  case "onRamp": {
700
- path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
761
+ path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
762
+ break;
763
+ }
764
+ case "telegramLogin": {
765
+ path = `/auth/telegram`;
701
766
  break;
702
767
  }
703
768
  default: {
704
769
  throw new Error(`invalid URL type ${type}`);
705
770
  }
706
771
  }
707
- const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
772
+ let partner = void 0;
773
+ try {
774
+ partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
775
+ } catch (e) {
776
+ if (this.isPartnerOptional) {
777
+ partner = void 0;
778
+ } else {
779
+ throw e;
780
+ }
781
+ }
708
782
  const thisDevice = (_a = opts.thisDevice) != null ? _a : {
709
783
  encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
710
784
  sessionId
711
785
  };
712
- const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
786
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
713
787
  apiKey: this.ctx.apiKey,
714
- partnerId: partner.id,
788
+ partnerId: partner == null ? void 0 : partner.id,
715
789
  portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
716
790
  portalBorderRadius: ((_d = opts.portalTheme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
717
791
  portalThemeMode: ((_f = opts.portalTheme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
@@ -722,7 +796,12 @@ const _ParaCore = class _ParaCore {
722
796
  portalTextColor: this.portalTextColor,
723
797
  portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
724
798
  isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
725
- }, isCreate || isLogin ? { authInfo: JSON.stringify(this.authInfo) } : {}), isOnRamp ? { sessionId } : {}), isLogin ? __spreadProps(__spreadValues({
799
+ }, isCreate || isLogin ? __spreadProps(__spreadValues({
800
+ authInfo: JSON.stringify(this.authInfo)
801
+ }, (0, import_user_management_client.isPhone)(this.authInfo.auth) ? (0, import_utils2.splitPhoneNumber)(this.authInfo.auth.phone) : this.authInfo.auth), {
802
+ pfpUrl: this.authInfo.pfpUrl,
803
+ displayName: this.authInfo.displayName
804
+ }) : {}), isOnRamp ? { origin: typeof window !== "undefined" ? window.location.origin : void 0, email: this.email } : {}), isLogin ? __spreadProps(__spreadValues({
726
805
  sessionId: thisDevice.sessionId,
727
806
  encryptionKey: thisDevice.encryptionKey
728
807
  }, opts.newDevice ? {
@@ -730,7 +809,7 @@ const _ParaCore = class _ParaCore {
730
809
  newDeviceEncryptionKey: opts.newDevice.encryptionKey
731
810
  } : {}), {
732
811
  pregenIds: JSON.stringify(this.pregenIds)
733
- }) : {}), opts.params || {});
812
+ }) : {}), type === "telegramLogin" ? { isEmbed: "true" } : {}), opts.params || {});
734
813
  const url = (0, import_utils2.constructUrl)({ base, path, params });
735
814
  if (opts.shorten) {
736
815
  return (0, import_utils2.shortenUrl)(this.ctx, url);
@@ -738,12 +817,62 @@ const _ParaCore = class _ParaCore {
738
817
  return url;
739
818
  });
740
819
  }
820
+ static resolveEnvironment(env, apiKey) {
821
+ var _a;
822
+ if (!apiKey) {
823
+ throw new Error("A Para API key is required.");
824
+ }
825
+ if (apiKey.includes("_")) {
826
+ const validEnvironmentPrefixes = Object.values(import_types.Environment);
827
+ const envPrefix = (_a = apiKey.split("_")[0]) == null ? void 0 : _a.toUpperCase();
828
+ const hasValidPrefix = validEnvironmentPrefixes.some((envValue) => envValue === envPrefix);
829
+ if (!hasValidPrefix) {
830
+ throw new Error(`Invalid API key environment prefix.`);
831
+ }
832
+ return envPrefix;
833
+ }
834
+ if (!env) {
835
+ throw new Error("Environment parameter is required.");
836
+ }
837
+ return env;
838
+ }
741
839
  touchSession(regenerate = false) {
742
840
  return __async(this, null, function* () {
743
- var _a, _b, _c;
841
+ var _a, _b, _c, _d;
842
+ if (!this.isWorkerInitialized) {
843
+ this.initializeWorker();
844
+ }
845
+ if (!this.isReady) {
846
+ yield this.ready();
847
+ }
744
848
  const session = yield this.ctx.client.touchSession(regenerate);
745
- 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) {
746
- yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
849
+ if (!this.partner || ((_a = this.partner) == null ? void 0 : _a.id) !== session.partnerId || !(0, import_utils2.supportedWalletTypesEq)(((_b = this.partner) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = this.partner) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
850
+ if (!session.partnerId) {
851
+ console.error(`
852
+ \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
853
+ \u{1F6A8} PARA SDK CONFIGURATION ERROR \u{1F6A8}
854
+
855
+ INVALID API KEY FOR CONFIGURED ENVIRONMENT
856
+
857
+ Your API key does not match the configured environment. This usually means:
858
+
859
+ 1. You're using a production API key with a development environment
860
+ 2. You're using a development API key with a production environment
861
+ 3. Your API key is invalid or has been regenerated
862
+
863
+ SOLUTION:
864
+ \u2022 Verify your API key at: https://developer.getpara.com
865
+ \u2022 If your API key doesn't contain an environment prefix, ensure your API key is the correct key for your target environment
866
+
867
+ Current Environment: ${this.ctx.env}
868
+ API Key Prefix: ${((_d = this.ctx.apiKey) == null ? void 0 : _d.split("_")[0].toUpperCase()) || "None"}
869
+
870
+ Need help? Visit: https://docs.getpara.com or contact support
871
+ \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
872
+ `);
873
+ } else {
874
+ yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
875
+ }
747
876
  }
748
877
  return session;
749
878
  });
@@ -842,8 +971,8 @@ const _ParaCore = class _ParaCore {
842
971
  return __privateGet(this, _authInfo);
843
972
  });
844
973
  }
845
- assertUserId() {
846
- if (!this.userId) {
974
+ assertUserId({ allowGuestMode = false } = {}) {
975
+ if (!this.userId || !allowGuestMode && this.isGuestMode) {
847
976
  throw new Error("no userId is set");
848
977
  }
849
978
  return this.userId;
@@ -899,19 +1028,75 @@ const _ParaCore = class _ParaCore {
899
1028
  * @param externalAddress - External wallet address to set.
900
1029
  * @param externalType - Type of external wallet to set.
901
1030
  */
902
- setExternalWallet(_0) {
903
- return __async(this, arguments, function* ({ address, type, provider, addressBech32, withFullParaAuth }) {
904
- this.externalWallets = {
905
- [address]: {
906
- id: address,
907
- address: addressBech32 != null ? addressBech32 : address,
1031
+ setExternalWallet(externalWallet) {
1032
+ return __async(this, null, function* () {
1033
+ const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1034
+ this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
1035
+ (acc, {
1036
+ partnerId: wPartnerId,
1037
+ address,
908
1038
  type,
909
- name: provider,
910
- isExternal: true,
911
- isExternalWithParaAuth: withFullParaAuth,
912
- signer: ""
1039
+ provider,
1040
+ providerId,
1041
+ addressBech32,
1042
+ withFullParaAuth,
1043
+ isConnectionOnly,
1044
+ withVerification
1045
+ }) => {
1046
+ if (partnerId === wPartnerId && supportedWalletTypes.some(({ type: supportedType }) => supportedType === type)) {
1047
+ return __spreadProps(__spreadValues({}, acc), {
1048
+ [address]: {
1049
+ id: address,
1050
+ partnerId,
1051
+ address: addressBech32 != null ? addressBech32 : address,
1052
+ type,
1053
+ name: provider,
1054
+ isExternal: true,
1055
+ isExternalWithParaAuth: withFullParaAuth,
1056
+ externalProviderId: providerId,
1057
+ signer: "",
1058
+ isExternalConnectionOnly: isConnectionOnly,
1059
+ isExternalWithVerification: withVerification
1060
+ }
1061
+ });
1062
+ }
1063
+ return acc;
1064
+ },
1065
+ {}
1066
+ ), this.setExternalWallets(this.externalWallets);
1067
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
1068
+ });
1069
+ }
1070
+ addExternalWallets(externalWallets) {
1071
+ return __async(this, null, function* () {
1072
+ const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1073
+ this.externalWallets = __spreadValues(__spreadValues({}, Object.entries(this.externalWallets).reduce((acc, [address, wallet]) => {
1074
+ if (partnerId === wallet.partnerId && supportedWalletTypes.some(({ type }) => type === wallet.type)) {
1075
+ return __spreadProps(__spreadValues({}, acc), {
1076
+ [address]: wallet
1077
+ });
913
1078
  }
914
- };
1079
+ return acc;
1080
+ }, {})), externalWallets.reduce(
1081
+ (acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
1082
+ return __spreadProps(__spreadValues({}, acc), {
1083
+ [address]: {
1084
+ id: address,
1085
+ partnerId,
1086
+ address: addressBech32 != null ? addressBech32 : address,
1087
+ type,
1088
+ name: provider,
1089
+ isExternal: true,
1090
+ isExternalWithParaAuth: withFullParaAuth,
1091
+ externalProviderId: providerId,
1092
+ signer: "",
1093
+ isExternalConnectionOnly: isConnectionOnly,
1094
+ isExternalWithVerification: withVerification
1095
+ }
1096
+ });
1097
+ },
1098
+ {}
1099
+ ));
915
1100
  this.setExternalWallets(this.externalWallets);
916
1101
  (0, import_utils2.dispatchEvent)(import_types.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
917
1102
  });
@@ -1023,6 +1208,7 @@ const _ParaCore = class _ParaCore {
1023
1208
  /**
1024
1209
  * Fetches the most recent OAuth account metadata for the signed-in user.
1025
1210
  * If applicable, this will include the user's most recent metadata from their Google, Apple, Facebook, X, Discord, Farcaster, or Telegram account, the last time they signed in to your app.
1211
+ * @deprecated use `para.getLinkedAccounts({ withMetadata: true })` instead.
1026
1212
  * @returns {Promise<AccountMetadata>} the user's account metadata.
1027
1213
  */
1028
1214
  getAccountMetadata() {
@@ -1168,8 +1354,15 @@ const _ParaCore = class _ParaCore {
1168
1354
  }
1169
1355
  getPartnerURL() {
1170
1356
  return __async(this, null, function* () {
1171
- const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1172
- return portalUrl;
1357
+ try {
1358
+ const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1359
+ return portalUrl;
1360
+ } catch (e) {
1361
+ if (this.isPartnerOptional) {
1362
+ return void 0;
1363
+ }
1364
+ throw e;
1365
+ }
1173
1366
  });
1174
1367
  }
1175
1368
  /**
@@ -1255,15 +1448,27 @@ const _ParaCore = class _ParaCore {
1255
1448
  } = _b, urlOptions = __objRest(_b, [
1256
1449
  "externalWallet"
1257
1450
  ]);
1258
- if (this.externalWalletConnectionOnly) {
1259
- externalWallet.withFullParaAuth = false;
1260
- yield this.setExternalWallet(externalWallet);
1451
+ const externalWallets = Array.isArray(externalWallet) ? externalWallet : [externalWallet];
1452
+ if (this.externalWalletConnectionOnly || externalWallets.every((wallet) => wallet.isConnectionOnly)) {
1453
+ yield this.addExternalWallets(
1454
+ externalWallets.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
1455
+ withFullParaAuth: false
1456
+ }))
1457
+ );
1261
1458
  return Promise.resolve({
1262
1459
  userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
1263
1460
  });
1264
1461
  }
1462
+ if (Array.isArray(externalWallet)) {
1463
+ throw new Error(
1464
+ "Cannot authenticate multiple external wallets at once. To connect multiple wallets at once, use CONNECTION_ONLY mode."
1465
+ );
1466
+ }
1265
1467
  this.requireApiKey();
1266
1468
  const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
1469
+ if (!externalWallet.withFullParaAuth && externalWallet.withVerification) {
1470
+ yield this.touchSession(true);
1471
+ }
1267
1472
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1268
1473
  });
1269
1474
  }
@@ -1280,36 +1485,78 @@ const _ParaCore = class _ParaCore {
1280
1485
  "cosmosPublicKeyHex",
1281
1486
  "cosmosSigner"
1282
1487
  ]);
1488
+ var _a;
1283
1489
  const serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
1284
1490
  externalWallet,
1285
1491
  signedMessage,
1286
1492
  cosmosPublicKeyHex,
1287
1493
  cosmosSigner
1288
1494
  });
1495
+ if (serverAuthState.stage === "login" && ((_a = serverAuthState.loginAuthMethods) == null ? void 0 : _a.includes(import_user_management_client.AuthMethod.PIN))) {
1496
+ const { sessionLookupId } = yield this.touchSession();
1497
+ return __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
1498
+ }
1289
1499
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1290
1500
  });
1291
1501
  }
1502
+ verifyExternalWalletLink(opts) {
1503
+ return __async(this, null, function* () {
1504
+ const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EXTERNAL_WALLET"]);
1505
+ if (!accountLinkInProgress.externalWallet) {
1506
+ throw new Error("no external wallet account link in progress");
1507
+ }
1508
+ const accounts = yield this.verifyLink(__spreadValues({
1509
+ accountLinkInProgress,
1510
+ externalWallet: accountLinkInProgress.externalWallet
1511
+ }, opts));
1512
+ return accounts;
1513
+ });
1514
+ }
1292
1515
  /**
1293
1516
  * Validates the response received from an attempted Telegram login for authenticity, then
1294
1517
  * creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
1295
1518
  * @param authResponse - the response JSON object received from the Telegram widget.
1296
1519
  * @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
1297
1520
  */
1298
- verifyTelegram(_e) {
1521
+ verifyTelegramProcess(_e) {
1299
1522
  return __async(this, null, function* () {
1300
1523
  var _f = _e, {
1301
- telegramAuthResponse
1524
+ telegramAuthResponse,
1525
+ isLinkAccount
1302
1526
  } = _f, urlOptions = __objRest(_f, [
1303
- "telegramAuthResponse"
1527
+ "telegramAuthResponse",
1528
+ "isLinkAccount"
1304
1529
  ]);
1305
1530
  try {
1306
- const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
1307
- return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1531
+ switch (isLinkAccount) {
1532
+ case false: {
1533
+ const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
1534
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1535
+ }
1536
+ case true: {
1537
+ const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
1538
+ const accounts = yield this.verifyLink({
1539
+ accountLinkInProgress,
1540
+ telegramAuthResponse
1541
+ });
1542
+ return accounts;
1543
+ }
1544
+ }
1308
1545
  } catch (e) {
1309
1546
  throw new Error(e.message);
1310
1547
  }
1311
1548
  });
1312
1549
  }
1550
+ verifyTelegram(opts) {
1551
+ return __async(this, null, function* () {
1552
+ return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
1553
+ });
1554
+ }
1555
+ verifyTelegramLink(opts) {
1556
+ return __async(this, null, function* () {
1557
+ return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
1558
+ });
1559
+ }
1313
1560
  /**
1314
1561
  * Performs 2FA verification.
1315
1562
  * @param {Object} opts the options object
@@ -1353,10 +1600,35 @@ const _ParaCore = class _ParaCore {
1353
1600
  /**
1354
1601
  * Resend a verification email for the current user.
1355
1602
  */
1356
- resendVerificationCode() {
1357
- return __async(this, null, function* () {
1603
+ resendVerificationCode(_0) {
1604
+ return __async(this, arguments, function* ({
1605
+ type: reason = "SIGNUP"
1606
+ }) {
1607
+ let type, linkedAccountId;
1608
+ switch (reason) {
1609
+ case "SIGNUP":
1610
+ case "LOGIN":
1611
+ {
1612
+ const authInfo = this.assertIsAuthSet(["email", "phone"]);
1613
+ type = authInfo.authType.toUpperCase();
1614
+ }
1615
+ break;
1616
+ case "LINK_ACCOUNT":
1617
+ {
1618
+ const accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]);
1619
+ linkedAccountId = accountLinkInProgress.id;
1620
+ type = accountLinkInProgress.type;
1621
+ }
1622
+ break;
1623
+ }
1624
+ const userId = this.assertUserId({ allowGuestMode: true });
1625
+ if (type !== "EMAIL" && type !== "PHONE") {
1626
+ throw new Error("invalid auth type for verification code");
1627
+ }
1358
1628
  yield this.ctx.client.resendVerificationCode(__spreadValues({
1359
- userId: this.userId
1629
+ userId,
1630
+ type,
1631
+ linkedAccountId
1360
1632
  }, this.getVerificationEmailProps()));
1361
1633
  });
1362
1634
  }
@@ -1369,7 +1641,14 @@ const _ParaCore = class _ParaCore {
1369
1641
  if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
1370
1642
  return true;
1371
1643
  }
1372
- const { isAuthenticated } = yield this.touchSession();
1644
+ const { isAuthenticated, verifiedExternalWalletAddresses } = yield this.touchSession();
1645
+ if (this.externalWalletConnectionType === "VERIFICATION") {
1646
+ if (!verifiedExternalWalletAddresses) {
1647
+ return false;
1648
+ }
1649
+ const externalAddresses = Object.values(this.externalWallets).map((w) => w.id);
1650
+ return externalAddresses.every((address) => verifiedExternalWalletAddresses.includes(address));
1651
+ }
1373
1652
  return !!isAuthenticated;
1374
1653
  });
1375
1654
  }
@@ -1380,12 +1659,18 @@ const _ParaCore = class _ParaCore {
1380
1659
  isFullyLoggedIn() {
1381
1660
  return __async(this, null, function* () {
1382
1661
  if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
1662
+ if (!this.isReady) {
1663
+ yield this.ready();
1664
+ }
1383
1665
  return true;
1384
1666
  }
1385
1667
  if (this.isGuestMode) {
1386
1668
  return true;
1387
1669
  }
1388
1670
  const isSessionActive = yield this.isSessionActive();
1671
+ if (this.externalWalletConnectionType === "VERIFICATION") {
1672
+ return isSessionActive;
1673
+ }
1389
1674
  return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
1390
1675
  });
1391
1676
  }
@@ -1393,10 +1678,13 @@ const _ParaCore = class _ParaCore {
1393
1678
  return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
1394
1679
  ({ userId, partnerId }) => {
1395
1680
  var _a;
1396
- return partnerId === ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
1681
+ return partnerId === ((_a = this.partner) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
1397
1682
  }
1398
1683
  );
1399
1684
  }
1685
+ /**
1686
+ * Get the auth methods available to an existing user
1687
+ */
1400
1688
  supportedAuthMethods(auth) {
1401
1689
  return __async(this, null, function* () {
1402
1690
  const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
@@ -1490,15 +1778,13 @@ const _ParaCore = class _ParaCore {
1490
1778
  });
1491
1779
  }
1492
1780
  /**
1493
- * Initiates a Farcaster login attempt and return the URI for the user to connect.
1781
+ * Initiates a Farcaster login attempt and returns the URL for the user to connect.
1494
1782
  * You can create a QR code with this URI that works with Farcaster's mobile app.
1495
1783
  * @return {string} the Farcaster connect URI
1496
1784
  */
1497
1785
  getFarcasterConnectUri() {
1498
- return __async(this, null, function* () {
1499
- const {
1500
- data: { connect_uri: connectUri }
1501
- } = yield this.ctx.client.initializeFarcasterLogin();
1786
+ return __async(this, arguments, function* ({ appScheme } = {}) {
1787
+ const { connect_uri: connectUri } = yield this.ctx.client.initializeFarcasterLogin({ appScheme });
1502
1788
  return connectUri;
1503
1789
  });
1504
1790
  }
@@ -1507,19 +1793,25 @@ const _ParaCore = class _ParaCore {
1507
1793
  * If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
1508
1794
  * @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
1509
1795
  */
1510
- verifyFarcaster(_g) {
1796
+ verifyFarcasterProcess(_g) {
1511
1797
  return __async(this, null, function* () {
1512
1798
  var _h = _g, {
1513
1799
  isCanceled = () => false,
1514
1800
  onConnectUri,
1515
1801
  onCancel,
1516
- onPoll
1802
+ onPoll,
1803
+ isLinkAccount
1517
1804
  } = _h, urlOptions = __objRest(_h, [
1518
1805
  "isCanceled",
1519
1806
  "onConnectUri",
1520
1807
  "onCancel",
1521
- "onPoll"
1808
+ "onPoll",
1809
+ "isLinkAccount"
1522
1810
  ]);
1811
+ let accountLinkInProgress;
1812
+ if (isLinkAccount) {
1813
+ accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
1814
+ }
1523
1815
  if (onConnectUri) {
1524
1816
  const connectUri = yield this.getFarcasterConnectUri();
1525
1817
  onConnectUri(connectUri);
@@ -1531,53 +1823,55 @@ const _ParaCore = class _ParaCore {
1531
1823
  try {
1532
1824
  if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
1533
1825
  onCancel == null ? void 0 : onCancel();
1534
- return reject("canceled");
1826
+ return reject("CANCELED");
1535
1827
  }
1536
1828
  yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
1537
- const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
1538
- if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
1539
- const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1540
- return resolve(authState);
1829
+ switch (isLinkAccount) {
1830
+ case false:
1831
+ {
1832
+ const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
1833
+ if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
1834
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1835
+ return resolve(authState);
1836
+ }
1837
+ }
1838
+ break;
1839
+ case true: {
1840
+ const result = yield this.verifyLink({
1841
+ accountLinkInProgress
1842
+ });
1843
+ if ("isConflict" in result) {
1844
+ throw new Error(import_types.AccountLinkError.Conflict);
1845
+ }
1846
+ return resolve(result);
1847
+ }
1541
1848
  }
1542
1849
  onPoll == null ? void 0 : onPoll();
1543
1850
  } catch (e) {
1544
- console.error(e);
1545
- return reject(e);
1851
+ if (!isLinkAccount || e.message === import_types.AccountLinkError.Conflict) {
1852
+ return reject(e.message);
1853
+ }
1546
1854
  }
1547
1855
  }
1548
1856
  }))();
1549
1857
  });
1550
1858
  });
1551
1859
  }
1552
- /**
1553
- * Generates a URL for the user to log in with OAuth using a desire method.
1554
- *
1555
- * @param {Object} opts the options object
1556
- * @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
1557
- * @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
1558
- * @returns {string} the URL for the user to log in with OAuth.
1559
- */
1560
- getOAuthUrl(_i) {
1860
+ verifyFarcaster(opts) {
1861
+ return __async(this, null, function* () {
1862
+ return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
1863
+ });
1864
+ }
1865
+ verifyFarcasterLink(opts) {
1866
+ return __async(this, null, function* () {
1867
+ return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
1868
+ });
1869
+ }
1870
+ getOAuthUrl(opts) {
1561
1871
  return __async(this, null, function* () {
1562
- var _j = _i, { method, deeplinkUrl } = _j, params = __objRest(_j, ["method", "deeplinkUrl"]);
1563
1872
  var _a;
1564
- if (deeplinkUrl) {
1565
- try {
1566
- new URL(deeplinkUrl);
1567
- } catch (e) {
1568
- throw new Error("Invalid deeplink URL");
1569
- }
1570
- }
1571
- const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
1572
- return (0, import_utils2.constructUrl)({
1573
- base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
1574
- path: `/auth/${method}`,
1575
- params: {
1576
- apiKey: this.ctx.apiKey,
1577
- sessionLookupId,
1578
- deeplinkUrl
1579
- }
1580
- });
1873
+ const sessionLookupId = (_a = opts.sessionLookupId) != null ? _a : yield this.prepareLogin();
1874
+ return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, __spreadProps(__spreadValues({}, opts), { sessionLookupId }));
1581
1875
  });
1582
1876
  }
1583
1877
  /**
@@ -1588,28 +1882,55 @@ const _ParaCore = class _ParaCore {
1588
1882
  * @param {Window} [opts.popupWindow] the popup window being used for login.
1589
1883
  * @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
1590
1884
  */
1591
- verifyOAuth(_k) {
1885
+ verifyOAuthProcess(_i) {
1592
1886
  return __async(this, null, function* () {
1593
- var _l = _k, {
1887
+ var _j = _i, {
1594
1888
  method,
1595
- deeplinkUrl,
1889
+ appScheme,
1596
1890
  isCanceled = () => false,
1597
1891
  onCancel,
1598
1892
  onPoll,
1599
- onOAuthUrl
1600
- } = _l, urlOptions = __objRest(_l, [
1893
+ onOAuthUrl,
1894
+ onOAuthPopup,
1895
+ isLinkAccount
1896
+ } = _j, urlOptions = __objRest(_j, [
1601
1897
  "method",
1602
- "deeplinkUrl",
1898
+ "appScheme",
1603
1899
  "isCanceled",
1604
1900
  "onCancel",
1605
1901
  "onPoll",
1606
- "onOAuthUrl"
1902
+ "onOAuthUrl",
1903
+ "onOAuthPopup",
1904
+ "isLinkAccount"
1607
1905
  ]);
1608
- let sessionLookupId;
1609
- if (onOAuthUrl) {
1610
- sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
1611
- const oAuthUrl = yield this.getOAuthUrl({ method, deeplinkUrl, sessionLookupId });
1612
- onOAuthUrl(oAuthUrl);
1906
+ let popupWindow;
1907
+ if (onOAuthPopup) {
1908
+ try {
1909
+ popupWindow = yield this.platformUtils.openPopup("about:blank", { type: import_types.PopupType.OAUTH });
1910
+ } catch (error) {
1911
+ throw new Error(`Failed to open OAuth popup: ${error}`);
1912
+ }
1913
+ }
1914
+ let sessionLookupId, accountLinkInProgress;
1915
+ if (onOAuthUrl || onOAuthPopup) {
1916
+ if (isLinkAccount) {
1917
+ accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
1918
+ sessionLookupId = (yield this.touchSession()).sessionLookupId;
1919
+ } else {
1920
+ sessionLookupId = yield this.prepareLogin();
1921
+ }
1922
+ const oAuthUrl = yield __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, { method, appScheme, sessionLookupId, accountLinkInProgress });
1923
+ switch (true) {
1924
+ case !!onOAuthUrl: {
1925
+ onOAuthUrl(oAuthUrl);
1926
+ break;
1927
+ }
1928
+ case (!!onOAuthPopup && !!popupWindow): {
1929
+ popupWindow.location.href = oAuthUrl;
1930
+ onOAuthPopup(popupWindow);
1931
+ break;
1932
+ }
1933
+ }
1613
1934
  } else {
1614
1935
  ({ sessionLookupId } = yield this.touchSession());
1615
1936
  }
@@ -1620,17 +1941,29 @@ const _ParaCore = class _ParaCore {
1620
1941
  try {
1621
1942
  if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
1622
1943
  onCancel == null ? void 0 : onCancel();
1623
- return reject("canceled");
1944
+ return reject(import_types.AccountLinkError.Canceled);
1624
1945
  }
1625
1946
  yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
1626
- const serverAuthState = yield this.ctx.client.verifyOAuth();
1627
- if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
1628
- const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
1629
- return resolve(authState);
1947
+ switch (isLinkAccount) {
1948
+ case false:
1949
+ {
1950
+ const serverAuthState = yield this.ctx.client.verifyOAuth();
1951
+ if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
1952
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
1953
+ return resolve(authState);
1954
+ }
1955
+ }
1956
+ break;
1957
+ case true: {
1958
+ const accounts = yield this.verifyLink({ accountLinkInProgress });
1959
+ return resolve(accounts);
1960
+ }
1630
1961
  }
1631
1962
  onPoll == null ? void 0 : onPoll();
1632
1963
  } catch (err) {
1633
- console.error(err);
1964
+ if (isLinkAccount && err.message === import_types.AccountLinkError.Conflict) {
1965
+ return reject(err.message);
1966
+ }
1634
1967
  onPoll == null ? void 0 : onPoll();
1635
1968
  }
1636
1969
  }
@@ -1638,6 +1971,16 @@ const _ParaCore = class _ParaCore {
1638
1971
  });
1639
1972
  });
1640
1973
  }
1974
+ verifyOAuth(opts) {
1975
+ return __async(this, null, function* () {
1976
+ return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
1977
+ });
1978
+ }
1979
+ verifyOAuthLink(opts) {
1980
+ return __async(this, null, function* () {
1981
+ return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
1982
+ });
1983
+ }
1641
1984
  /**
1642
1985
  * Waits for the session to be active and sets up the user.
1643
1986
  *
@@ -1723,7 +2066,7 @@ const _ParaCore = class _ParaCore {
1723
2066
  sessionId
1724
2067
  });
1725
2068
  if (shouldOpenPopup) {
1726
- this.platformUtils.openPopup(link);
2069
+ yield this.platformUtils.openPopup(link);
1727
2070
  }
1728
2071
  return link;
1729
2072
  });
@@ -2267,25 +2610,12 @@ const _ParaCore = class _ParaCore {
2267
2610
  });
2268
2611
  });
2269
2612
  }
2270
- getOnRampTransactionUrl(_m) {
2271
- return __async(this, null, function* () {
2272
- var _n = _m, {
2273
- purchaseId,
2274
- providerKey
2275
- } = _n, walletParams = __objRest(_n, [
2276
- "purchaseId",
2277
- "providerKey"
2278
- ]);
2279
- const { sessionId } = yield this.touchSession();
2280
- const [key, identifier] = (0, import_user_management_client.extractWalletRef)(walletParams);
2613
+ getOnRampTransactionUrl(_0) {
2614
+ return __async(this, arguments, function* ({
2615
+ purchaseId
2616
+ }) {
2281
2617
  return this.constructPortalUrl("onRamp", {
2282
- pathId: purchaseId,
2283
- sessionId,
2284
- params: {
2285
- [key]: identifier,
2286
- providerKey,
2287
- currentWalletIds: JSON.stringify(this.currentWalletIds)
2288
- }
2618
+ pathId: purchaseId
2289
2619
  });
2290
2620
  });
2291
2621
  }
@@ -2319,7 +2649,7 @@ const _ParaCore = class _ParaCore {
2319
2649
  let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
2320
2650
  let timeStart = Date.now();
2321
2651
  if (signRes.pendingTransactionId) {
2322
- this.platformUtils.openPopup(
2652
+ yield this.platformUtils.openPopup(
2323
2653
  yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
2324
2654
  { type: cosmosSignDocBase64 ? import_types.PopupType.SIGN_TRANSACTION_REVIEW : import_types.PopupType.SIGN_MESSAGE_REVIEW }
2325
2655
  );
@@ -2431,7 +2761,7 @@ const _ParaCore = class _ParaCore {
2431
2761
  );
2432
2762
  let timeStart = Date.now();
2433
2763
  if (signRes.pendingTransactionId) {
2434
- this.platformUtils.openPopup(
2764
+ yield this.platformUtils.openPopup(
2435
2765
  yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
2436
2766
  { type: import_types.PopupType.SIGN_TRANSACTION_REVIEW }
2437
2767
  );
@@ -2507,7 +2837,8 @@ const _ParaCore = class _ParaCore {
2507
2837
  providerKey: onRampPurchase.providerKey
2508
2838
  }, walletParams));
2509
2839
  if (shouldOpenPopup) {
2510
- this.platformUtils.openPopup(portalUrl, { type: import_types.PopupType.ON_RAMP_TRANSACTION });
2840
+ const onRampWindow = yield this.platformUtils.openPopup(portalUrl, { type: import_types.PopupType.ON_RAMP_TRANSACTION });
2841
+ this.onRampPopup = { window: onRampWindow, onRampPurchase };
2511
2842
  }
2512
2843
  return { onRampPurchase, portalUrl };
2513
2844
  });
@@ -2590,6 +2921,12 @@ const _ParaCore = class _ParaCore {
2590
2921
  return sessionLookupId;
2591
2922
  });
2592
2923
  }
2924
+ issueJwt() {
2925
+ return __async(this, arguments, function* ({ keyIndex = 0 } = {}) {
2926
+ const res = yield this.ctx.client.issueJwt({ keyIndex });
2927
+ return res;
2928
+ });
2929
+ }
2593
2930
  /**
2594
2931
  * Logs the user out.
2595
2932
  * @param {Object} opts the options object.
@@ -2597,6 +2934,7 @@ const _ParaCore = class _ParaCore {
2597
2934
  **/
2598
2935
  logout() {
2599
2936
  return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
2937
+ const shouldDispatchLogoutEvent = yield this.isSessionActive();
2600
2938
  yield this.ctx.client.logout();
2601
2939
  yield this.clearStorage();
2602
2940
  if (!clearPregenWallets) {
@@ -2613,22 +2951,17 @@ const _ParaCore = class _ParaCore {
2613
2951
  this.externalWallets = {};
2614
2952
  this.loginEncryptionKeyPair = void 0;
2615
2953
  __privateSet(this, _authInfo, void 0);
2954
+ this.accountLinkInProgress = void 0;
2616
2955
  this.userId = void 0;
2617
2956
  this.sessionCookie = void 0;
2618
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGOUT_EVENT, null);
2619
- });
2620
- }
2621
- /** @deprecated */
2622
- getSupportedCreateAuthMethods() {
2623
- return __async(this, null, function* () {
2624
- const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2625
- let supportedAuthMethods = /* @__PURE__ */ new Set();
2626
- for (const authMethod of partner.supportedAuthMethods) {
2627
- supportedAuthMethods.add(import_user_management_client.AuthMethod[authMethod]);
2957
+ if (shouldDispatchLogoutEvent) {
2958
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGOUT_EVENT, null);
2628
2959
  }
2629
- return supportedAuthMethods;
2630
2960
  });
2631
2961
  }
2962
+ get toStringAdditions() {
2963
+ return {};
2964
+ }
2632
2965
  /**
2633
2966
  * Converts to a string, removing sensitive data when logging this class.
2634
2967
  *
@@ -2652,10 +2985,10 @@ const _ParaCore = class _ParaCore {
2652
2985
  }),
2653
2986
  {}
2654
2987
  );
2655
- const obj = {
2656
- partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
2657
- supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
2658
- cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
2988
+ const obj = __spreadProps(__spreadValues({
2989
+ partnerId: (_a = this.partner) == null ? void 0 : _a.id,
2990
+ supportedWalletTypes: (_b = this.partner) == null ? void 0 : _b.supportedWalletTypes,
2991
+ cosmosPrefix: (_c = this.partner) == null ? void 0 : _c.cosmosPrefix,
2659
2992
  authInfo: __privateGet(this, _authInfo),
2660
2993
  isGuestMode: this.isGuestMode,
2661
2994
  userId: this.userId,
@@ -2665,6 +2998,8 @@ const _ParaCore = class _ParaCore {
2665
2998
  wallets: redactedWallets,
2666
2999
  externalWallets: redactedExternalWallets,
2667
3000
  loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
3001
+ isReady: this.isReady
3002
+ }, this.toStringAdditions), {
2668
3003
  ctx: {
2669
3004
  apiKey: this.ctx.apiKey,
2670
3005
  disableWorkers: this.ctx.disableWorkers,
@@ -2675,9 +3010,14 @@ const _ParaCore = class _ParaCore {
2675
3010
  useDKLS: this.ctx.useDKLS,
2676
3011
  cosmosPrefix: this.ctx.cosmosPrefix
2677
3012
  }
2678
- };
3013
+ });
2679
3014
  return `Para ${JSON.stringify(obj, null, 2)}`;
2680
3015
  }
3016
+ devLog(...s) {
3017
+ if (this.ctx.env === import_types.Environment.DEV || this.ctx.env === import_types.Environment.SANDBOX) {
3018
+ console.log(...s);
3019
+ }
3020
+ }
2681
3021
  getNewCredentialAndUrl() {
2682
3022
  return __async(this, arguments, function* ({
2683
3023
  authMethod = "PASSKEY",
@@ -2705,6 +3045,14 @@ const _ParaCore = class _ParaCore {
2705
3045
  }));
2706
3046
  urlType = "createPassword";
2707
3047
  break;
3048
+ case "PIN":
3049
+ ({
3050
+ data: { id: credentialId }
3051
+ } = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
3052
+ status: import_user_management_client.PasswordStatus.PENDING
3053
+ }));
3054
+ urlType = "createPIN";
3055
+ break;
2708
3056
  }
2709
3057
  const url = this.isNativePasskey && urlType === "createAuth" ? void 0 : yield this.constructPortalUrl(urlType, {
2710
3058
  isForNewDevice,
@@ -2716,7 +3064,7 @@ const _ParaCore = class _ParaCore {
2716
3064
  });
2717
3065
  }
2718
3066
  /**
2719
- * Returns a Para Portal URL for logging in with a WebAuth passkey or a password.
3067
+ * Returns a Para Portal URL for logging in with a WebAuth passkey, password or PIN.
2720
3068
  * @param {Object} opts the options object
2721
3069
  * @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
2722
3070
  * @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
@@ -2742,6 +3090,9 @@ const _ParaCore = class _ParaCore {
2742
3090
  case "PASSWORD":
2743
3091
  urlType = "loginPassword";
2744
3092
  break;
3093
+ case "PIN":
3094
+ urlType = "loginPIN";
3095
+ break;
2745
3096
  default:
2746
3097
  throw new Error(`invalid authentication method: '${authMethod}'`);
2747
3098
  }
@@ -2752,53 +3103,193 @@ const _ParaCore = class _ParaCore {
2752
3103
  });
2753
3104
  });
2754
3105
  }
2755
- signUpOrLogIn(_o) {
3106
+ prepareLogin() {
3107
+ return __async(this, null, function* () {
3108
+ yield this.logout();
3109
+ const { sessionLookupId } = yield this.touchSession(true);
3110
+ if (!this.loginEncryptionKeyPair) {
3111
+ yield this.setLoginEncryptionKeyPair();
3112
+ }
3113
+ return sessionLookupId;
3114
+ });
3115
+ }
3116
+ signUpOrLogIn(_k) {
2756
3117
  return __async(this, null, function* () {
2757
- var _p = _o, { auth } = _p, urlOptions = __objRest(_p, ["auth"]);
3118
+ var _l = _k, { auth } = _l, urlOptions = __objRest(_l, ["auth"]);
2758
3119
  const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
3120
+ const authInfo = serverAuthState.auth;
3121
+ if (this.fetchPregenWalletsOverride && (0, import_user_management_client.isPregenAuth)(authInfo)) {
3122
+ const { userShare } = yield this.fetchPregenWalletsOverride({ pregenId: authInfo });
3123
+ if (userShare) {
3124
+ yield this.setUserShare(userShare);
3125
+ }
3126
+ }
2759
3127
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
2760
3128
  });
2761
3129
  }
2762
- verifyNewAccount(_q) {
3130
+ verifyNewAccount(_m) {
2763
3131
  return __async(this, null, function* () {
2764
- var _r = _q, {
3132
+ var _n = _m, {
2765
3133
  verificationCode
2766
- } = _r, urlOptions = __objRest(_r, [
3134
+ } = _n, urlOptions = __objRest(_n, [
2767
3135
  "verificationCode"
2768
3136
  ]);
2769
3137
  this.assertIsAuthSet(["email", "phone"]);
2770
- const userId = this.assertUserId();
2771
- const serverAuthState = yield this.ctx.client.verifyNewAccount(userId, {
3138
+ const userId = this.assertUserId({ allowGuestMode: true });
3139
+ const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
2772
3140
  verificationCode
2773
3141
  });
3142
+ if (serverAuthState.stage === "login") {
3143
+ throw new Error("Account already exists.");
3144
+ }
2774
3145
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
2775
3146
  });
2776
3147
  }
3148
+ getLinkedAccounts() {
3149
+ return __async(this, arguments, function* ({
3150
+ withMetadata = false
3151
+ } = {}) {
3152
+ const userId = this.assertUserId();
3153
+ const { accounts } = yield this.ctx.client.getLinkedAccounts({ userId, withMetadata });
3154
+ return __spreadValues({
3155
+ userId
3156
+ }, accounts);
3157
+ });
3158
+ }
3159
+ linkAccount(opts) {
3160
+ return __async(this, null, function* () {
3161
+ const { supportedAccountLinks = [...import_user_management_client.LINKED_ACCOUNT_TYPES] } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
3162
+ let type, identifier, externalWallet, isPermitted;
3163
+ switch (true) {
3164
+ case "auth" in opts:
3165
+ {
3166
+ const authInfo = (0, import_user_management_client.extractAuthInfo)(opts.auth, { isRequired: true });
3167
+ if (authInfo.auth === this.authInfo.auth) {
3168
+ throw new Error(import_types.AccountLinkError.Conflict);
3169
+ }
3170
+ type = authInfo.authType.toUpperCase();
3171
+ identifier = authInfo.identifier;
3172
+ isPermitted = supportedAccountLinks.includes(type);
3173
+ }
3174
+ break;
3175
+ case "externalWallet" in opts:
3176
+ {
3177
+ externalWallet = opts.externalWallet;
3178
+ type = "EXTERNAL_WALLET";
3179
+ isPermitted = supportedAccountLinks.includes("EXTERNAL_WALLET") || supportedAccountLinks.includes(externalWallet.providerId);
3180
+ }
3181
+ break;
3182
+ case "type" in opts:
3183
+ {
3184
+ type = opts.type;
3185
+ if (type === "X") {
3186
+ type = "TWITTER";
3187
+ }
3188
+ isPermitted = supportedAccountLinks.includes(type);
3189
+ }
3190
+ break;
3191
+ default:
3192
+ throw new Error("Invalid parameters for linking account, must pass `auth` or `type` or `externalWallet");
3193
+ }
3194
+ if (!isPermitted) {
3195
+ throw new Error(`Account linking for type '${type}' is not supported by the current API key configuration`);
3196
+ }
3197
+ const userId = this.assertUserId();
3198
+ const result = yield this.ctx.client.linkAccount(__spreadValues(__spreadValues({
3199
+ userId,
3200
+ type
3201
+ }, identifier ? { identifier } : {}), externalWallet ? { externalWallet } : {}));
3202
+ if ("isConflict" in result) {
3203
+ throw new Error(import_types.AccountLinkError.Conflict);
3204
+ }
3205
+ const { linkedAccountId, signatureVerificationMessage } = result;
3206
+ this.accountLinkInProgress = __spreadValues(__spreadValues({
3207
+ id: linkedAccountId,
3208
+ type,
3209
+ isComplete: false
3210
+ }, identifier ? { identifier } : {}), signatureVerificationMessage && externalWallet ? {
3211
+ externalWallet: __spreadProps(__spreadValues({}, externalWallet), {
3212
+ signatureVerificationMessage
3213
+ })
3214
+ } : {});
3215
+ return this.accountLinkInProgress;
3216
+ });
3217
+ }
3218
+ unlinkAccount(_0) {
3219
+ return __async(this, arguments, function* ({
3220
+ linkedAccountId
3221
+ }) {
3222
+ if (!linkedAccountId) {
3223
+ throw new Error("No linked account ID provided");
3224
+ }
3225
+ const userId = this.assertUserId();
3226
+ const accounts = yield this.ctx.client.unlinkAccount({ linkedAccountId, userId });
3227
+ return accounts;
3228
+ });
3229
+ }
3230
+ verifyLink() {
3231
+ return __async(this, arguments, function* (_o = {}) {
3232
+ var _p = _o, {
3233
+ accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this)
3234
+ } = _p, opts = __objRest(_p, [
3235
+ "accountLinkInProgress"
3236
+ ]);
3237
+ try {
3238
+ const userId = this.assertUserId(), result = yield this.ctx.client.verifyLink(__spreadValues({
3239
+ linkedAccountId: accountLinkInProgress.id,
3240
+ userId
3241
+ }, opts));
3242
+ if ("isConflict" in result) {
3243
+ throw new Error(import_types.AccountLinkError.Conflict);
3244
+ }
3245
+ this.accountLinkInProgress = void 0;
3246
+ return result.accounts;
3247
+ } catch (e) {
3248
+ throw new Error(e.message === import_types.AccountLinkError.Conflict ? import_types.AccountLinkError.Conflict : e.message);
3249
+ }
3250
+ });
3251
+ }
3252
+ verifyEmailOrPhoneLink(_0) {
3253
+ return __async(this, arguments, function* ({
3254
+ verificationCode
3255
+ }) {
3256
+ const accounts = yield this.verifyLink({
3257
+ accountLinkInProgress: __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]),
3258
+ verificationCode
3259
+ });
3260
+ return accounts;
3261
+ });
3262
+ }
3263
+ sendLoginCode() {
3264
+ return __async(this, null, function* () {
3265
+ const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
3266
+ this.setUserId(userId);
3267
+ });
3268
+ }
2777
3269
  };
2778
3270
  _authInfo = new WeakMap();
2779
- _partner = new WeakMap();
2780
3271
  _ParaCore_instances = new WeakSet();
2781
3272
  assertPartner_fn = function() {
2782
3273
  return __async(this, null, function* () {
2783
3274
  var _a, _b;
2784
- if (!__privateGet(this, _partner)) {
3275
+ if (!this.partner) {
2785
3276
  yield this.touchSession();
2786
3277
  }
2787
- if (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== __privateGet(this, _partner).cosmosPrefix) {
2788
- this.ctx.cosmosPrefix = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix;
3278
+ if (((_a = this.partner) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== this.partner.cosmosPrefix) {
3279
+ this.ctx.cosmosPrefix = (_b = this.partner) == null ? void 0 : _b.cosmosPrefix;
2789
3280
  }
2790
- return __privateGet(this, _partner);
3281
+ return this.partner;
2791
3282
  });
2792
3283
  };
2793
3284
  guestWalletIds_get = function() {
2794
3285
  var _a, _b, _c;
2795
- if (!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes)) {
3286
+ if (!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes)) {
2796
3287
  return {};
2797
3288
  }
2798
3289
  const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
2799
3290
  return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
2800
3291
  if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
2801
- return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) => __privateGet(this, _partner).supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
3292
+ return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) => this.partner.supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
2802
3293
  var _a2;
2803
3294
  return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
2804
3295
  }, {}));
@@ -2855,9 +3346,57 @@ setAuthInfo_fn = function(authInfo) {
2855
3346
  };
2856
3347
  getPartner_fn = function(partnerId) {
2857
3348
  return __async(this, null, function* () {
3349
+ if (this.isPartnerOptional && !partnerId) {
3350
+ return void 0;
3351
+ }
2858
3352
  const res = yield this.ctx.client.getPartner(partnerId);
2859
- __privateSet(this, _partner, res.data.partner);
2860
- return __privateGet(this, _partner);
3353
+ this.partner = res.data.partner;
3354
+ return this.partner;
3355
+ });
3356
+ };
3357
+ assertIsLinkingAccount_fn = function(types) {
3358
+ if (!this.accountLinkInProgress || this.accountLinkInProgress.isComplete) {
3359
+ throw new Error("no account linking in progress");
3360
+ }
3361
+ if (types && !types.includes(this.accountLinkInProgress.type)) {
3362
+ throw new Error(
3363
+ `account linking in progress for type ${this.accountLinkInProgress.type}, expected one of ${types.join(", ")}`
3364
+ );
3365
+ }
3366
+ return this.accountLinkInProgress;
3367
+ };
3368
+ assertIsLinkingAccountOrStart_fn = function(type) {
3369
+ return __async(this, null, function* () {
3370
+ if (this.accountLinkInProgress && !this.accountLinkInProgress.isComplete) {
3371
+ return __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, [type]);
3372
+ }
3373
+ return yield this.linkAccount({ type });
3374
+ });
3375
+ };
3376
+ /**
3377
+ * Generates a URL for the user to log in with OAuth using a desire method.
3378
+ *
3379
+ * @param {Object} opts the options object
3380
+ * @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
3381
+ * @param {string} [opts.appScheme] the app scheme to redirect to after the OAuth flow. This is for mobile only.
3382
+ * @returns {string} the URL for the user to log in with OAuth.
3383
+ */
3384
+ getOAuthUrl_fn = function({
3385
+ method,
3386
+ appScheme,
3387
+ accountLinkInProgress,
3388
+ sessionLookupId
3389
+ }) {
3390
+ return (0, import_utils2.constructUrl)({
3391
+ base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
3392
+ path: `/auth/${method}`,
3393
+ params: __spreadValues({
3394
+ apiKey: this.ctx.apiKey,
3395
+ sessionLookupId,
3396
+ appScheme
3397
+ }, accountLinkInProgress ? {
3398
+ linkedAccountId: this.accountLinkInProgress.id
3399
+ } : {})
2861
3400
  });
2862
3401
  };
2863
3402
  createPregenWallet_fn = function(opts) {
@@ -2910,8 +3449,9 @@ createPregenWallet_fn = function(opts) {
2910
3449
  _isCreateGuestWalletsPending = new WeakMap();
2911
3450
  prepareAuthState_fn = function(_0) {
2912
3451
  return __async(this, arguments, function* (serverAuthState, opts = {}) {
2913
- if (!opts.sessionLookupId && serverAuthState.stage === "login") {
2914
- opts.sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
3452
+ var _a, _b;
3453
+ if (!opts.sessionLookupId && serverAuthState.stage === "login" && (!serverAuthState.externalWallet || !(((_a = serverAuthState.externalWallet) == null ? void 0 : _a.withFullParaAuth) && ((_b = serverAuthState.loginAuthMethods) == null ? void 0 : _b.includes(import_user_management_client.AuthMethod.PIN))))) {
3454
+ opts.sessionLookupId = yield this.prepareLogin();
2915
3455
  }
2916
3456
  const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
2917
3457
  const authInfo = __spreadValues(__spreadValues({}, (0, import_user_management_client.extractAuthInfo)(auth, { isRequired: true })), Object.fromEntries(
@@ -2925,7 +3465,7 @@ prepareAuthState_fn = function(_0) {
2925
3465
  yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
2926
3466
  yield this.assertIsAuthSet();
2927
3467
  if (!!externalWallet) {
2928
- yield this.setExternalWallet(externalWallet);
3468
+ yield this.setExternalWallet([externalWallet]);
2929
3469
  }
2930
3470
  if (!!userId) {
2931
3471
  yield this.setUserId(userId);
@@ -2936,33 +3476,34 @@ prepareAuthState_fn = function(_0) {
2936
3476
  authState = serverAuthState;
2937
3477
  break;
2938
3478
  case "login":
3479
+ if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
3480
+ authState = serverAuthState;
3481
+ break;
3482
+ }
2939
3483
  authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
2940
3484
  break;
2941
3485
  case "signup":
3486
+ if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
3487
+ authState = serverAuthState;
3488
+ break;
3489
+ }
2942
3490
  authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
2943
3491
  break;
2944
3492
  }
2945
3493
  return authState;
2946
3494
  });
2947
3495
  };
2948
- prepareLogin_fn = function() {
2949
- return __async(this, null, function* () {
2950
- yield this.logout();
2951
- const { sessionLookupId } = yield this.touchSession(true);
2952
- if (!this.loginEncryptionKeyPair) {
2953
- yield this.setLoginEncryptionKeyPair();
2954
- }
2955
- return sessionLookupId;
2956
- });
2957
- };
2958
3496
  prepareLoginState_fn = function(_0, _1) {
2959
3497
  return __async(this, arguments, function* (loginState, {
2960
3498
  useShortUrls: shorten = false,
2961
3499
  portalTheme,
2962
3500
  sessionLookupId
2963
3501
  }) {
2964
- const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
2965
- return __spreadValues(__spreadValues(__spreadValues({}, authState), !this.isNativePasskey && loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY) ? {
3502
+ const _a = loginState, { loginAuthMethods, hasPasswordWithoutPIN } = _a, authState = __objRest(_a, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
3503
+ const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) && hasPasswordWithoutPIN, isPINPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PIN);
3504
+ return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
3505
+ isPasskeySupported
3506
+ }), isPasskeyPossible ? {
2966
3507
  passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
2967
3508
  passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
2968
3509
  sessionId: sessionLookupId,
@@ -2973,11 +3514,19 @@ prepareLoginState_fn = function(_0, _1) {
2973
3514
  shorten,
2974
3515
  portalTheme
2975
3516
  })
2976
- } : {}), loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) ? {
3517
+ } : {}), isPasswordPossible ? {
2977
3518
  passwordUrl: yield this.constructPortalUrl("loginPassword", {
2978
3519
  sessionId: sessionLookupId,
2979
3520
  shorten,
2980
- portalTheme
3521
+ portalTheme,
3522
+ params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
3523
+ })
3524
+ } : {}), isPINPossible ? {
3525
+ pinUrl: yield this.constructPortalUrl("loginPIN", {
3526
+ sessionId: sessionLookupId,
3527
+ shorten,
3528
+ portalTheme,
3529
+ params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
2981
3530
  })
2982
3531
  } : {});
2983
3532
  });
@@ -2985,16 +3534,18 @@ prepareLoginState_fn = function(_0, _1) {
2985
3534
  prepareSignUpState_fn = function(_0, _1) {
2986
3535
  return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
2987
3536
  const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
2988
- const [isPasskey, isPassword] = [
3537
+ const isPasskeySupported = yield this.isPasskeySupported();
3538
+ const [isPasskey, isPassword, isPIN] = [
2989
3539
  signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY),
2990
- signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD)
3540
+ signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) || !isPasskeySupported,
3541
+ signupAuthMethods.includes(import_user_management_client.AuthMethod.PIN)
2991
3542
  ];
2992
- if (!isPasskey && !isPassword) {
3543
+ if (!isPasskey && !isPassword && !isPIN) {
2993
3544
  throw new Error(
2994
- "No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or passwords in your Developer Portal settings."
3545
+ "No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys, passwords or PINs in your Developer Portal settings."
2995
3546
  );
2996
3547
  }
2997
- const signupState = authState;
3548
+ const signupState = __spreadProps(__spreadValues({}, authState), { isPasskeySupported });
2998
3549
  if (isPasskey) {
2999
3550
  const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
3000
3551
  authMethod: "PASSKEY",
@@ -3012,6 +3563,15 @@ prepareSignUpState_fn = function(_0, _1) {
3012
3563
  signupState.passwordUrl = passwordUrl;
3013
3564
  signupState.passwordId = passwordId;
3014
3565
  }
3566
+ if (isPIN) {
3567
+ const { url: pinUrl, credentialId: pinId } = yield this.getNewCredentialAndUrl({
3568
+ authMethod: "PIN",
3569
+ portalTheme,
3570
+ shorten
3571
+ });
3572
+ signupState.pinUrl = pinUrl;
3573
+ signupState.pinId = pinId;
3574
+ }
3015
3575
  return signupState;
3016
3576
  });
3017
3577
  };