@getpara/core-sdk 2.0.0-dev.3 → 2.0.0-dev.6

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.
@@ -8,7 +8,7 @@ import {
8
8
  __spreadProps,
9
9
  __spreadValues
10
10
  } from "./chunk-7B52C2XE.js";
11
- var _authInfo, _partner, _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, prepareLogin_fn, prepareLoginState_fn, prepareSignUpState_fn;
11
+ var _authInfo, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, assertIsLinkingAccount_fn, assertIsLinkingAccountOrStart_fn, getOAuthUrl_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareDoneState_fn, prepareVerificationState_fn, prepareLoginState_fn, prepareSignUpState_fn;
12
12
  import { Buffer as NodeBuffer } from "buffer";
13
13
  if (typeof global !== "undefined") {
14
14
  global.Buffer = global.Buffer || NodeBuffer;
@@ -23,7 +23,6 @@ import {
23
23
  AuthMethod,
24
24
  PublicKeyStatus,
25
25
  PublicKeyType,
26
- extractWalletRef,
27
26
  PasswordStatus,
28
27
  extractAuthInfo,
29
28
  isEmail,
@@ -76,25 +75,21 @@ import {
76
75
  } from "./utils/index.js";
77
76
  import { TransactionReviewDenied, TransactionReviewTimeout } from "./errors.js";
78
77
  import * as constants from "./constants.js";
78
+ import { EnclaveClient } from "./shares/enclave.js";
79
79
  const _ParaCore = class _ParaCore {
80
- /**
81
- * Constructs a new `ParaCore` instance.
82
- * @param env - `Environment` to use.
83
- * @param apiKey - API key to use.
84
- * @param opts - Additional constructor options; see `ConstructorOpts`.
85
- * @returns - A new ParaCore instance.
86
- */
87
- constructor(env, apiKey, opts) {
80
+ constructor(envOrApiKey, apiKeyOrOpts, opts) {
88
81
  __privateAdd(this, _ParaCore_instances);
82
+ this.popupWindow = null;
89
83
  __privateAdd(this, _authInfo);
90
84
  this.isNativePasskey = false;
91
85
  this.isReady = false;
92
- __privateAdd(this, _partner);
93
86
  this.accountLinkInProgress = void 0;
87
+ this.isEnclaveUser = false;
94
88
  this.isAwaitingAccountCreation = false;
95
89
  this.isAwaitingLogin = false;
96
90
  this.isAwaitingFarcaster = false;
97
91
  this.isAwaitingOAuth = false;
92
+ this.isWorkerInitialized = false;
98
93
  /**
99
94
  * 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.
100
95
  */
@@ -103,6 +98,7 @@ const _ParaCore = class _ParaCore {
103
98
  * Wallets associated with the `ParaCore` instance.
104
99
  */
105
100
  this.externalWallets = {};
101
+ this.onRampPopup = void 0;
106
102
  this.localStorageGetItem = (key) => {
107
103
  return this.platformUtils.localStorage.get(key);
108
104
  };
@@ -124,16 +120,29 @@ const _ParaCore = class _ParaCore {
124
120
  this.retrieveSessionCookie = () => {
125
121
  return this.sessionCookie;
126
122
  };
123
+ this.retrieveEnclaveJwt = () => {
124
+ return this.enclaveJwt;
125
+ };
126
+ this.retrieveEnclaveRefreshJwt = () => {
127
+ return this.enclaveRefreshJwt;
128
+ };
127
129
  /**
128
130
  * Remove all local storage and prefixed session storage.
129
131
  * @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
130
132
  */
131
133
  this.clearStorage = (type = "all") => __async(this, null, function* () {
132
134
  const isAll = type === "all";
133
- (isAll || type === "local") && this.platformUtils.localStorage.clear(constants.PREFIX);
134
- (isAll || type === "session") && this.platformUtils.sessionStorage.clear(constants.PREFIX);
135
+ if (isAll || type === "local") {
136
+ this.platformUtils.localStorage.clear(constants.PREFIX);
137
+ this.platformUtils.localStorage.clear(constants.PARA_PREFIX);
138
+ }
139
+ if (isAll || type === "session") {
140
+ this.platformUtils.sessionStorage.clear(constants.PREFIX);
141
+ this.platformUtils.sessionStorage.clear(constants.PARA_PREFIX);
142
+ }
135
143
  if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
136
144
  this.platformUtils.secureStorage.clear(constants.PREFIX);
145
+ this.platformUtils.secureStorage.clear(constants.PARA_PREFIX);
137
146
  }
138
147
  });
139
148
  this.trackError = (methodName, err) => __async(this, null, function* () {
@@ -175,6 +184,7 @@ const _ParaCore = class _ParaCore {
175
184
  this.updateWalletIdsFromStorage();
176
185
  this.updateSessionCookieFromStorage();
177
186
  this.updateLoginEncryptionKeyPairFromStorage();
187
+ this.updateEnclaveJwtFromStorage();
178
188
  };
179
189
  this.updateAuthInfoFromStorage = () => {
180
190
  var _a;
@@ -194,6 +204,10 @@ const _ParaCore = class _ParaCore {
194
204
  }
195
205
  __privateSet(this, _authInfo, authInfo);
196
206
  };
207
+ this.updateEnclaveJwtFromStorage = () => {
208
+ this.enclaveJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || void 0;
209
+ this.enclaveRefreshJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || void 0;
210
+ };
197
211
  this.updateUserIdFromStorage = () => {
198
212
  this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
199
213
  };
@@ -254,6 +268,16 @@ const _ParaCore = class _ParaCore {
254
268
  const _externalWallets = JSON.parse(stringExternalWallets || "{}");
255
269
  this.setExternalWallets(_externalWallets);
256
270
  };
271
+ this.initializeWorker = () => __async(this, null, function* () {
272
+ if (!this.isWorkerInitialized && !this.ctx.disableWebSockets && !this.ctx.disableWorkers) {
273
+ try {
274
+ this.isWorkerInitialized = true;
275
+ yield this.platformUtils.initializeWorker(this.ctx);
276
+ } catch (e) {
277
+ this.devLog("error initializing worker:", e);
278
+ }
279
+ }
280
+ });
257
281
  /**
258
282
  * Creates several new wallets with the desired types. If no types are provided, this method
259
283
  * will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
@@ -270,8 +294,29 @@ const _ParaCore = class _ParaCore {
270
294
  }) {
271
295
  return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
272
296
  });
273
- if (!apiKey) {
274
- throw new Error("A Para API key is required.");
297
+ let env, apiKey;
298
+ const actualArgs = Array.from(arguments).filter((arg) => arg !== void 0);
299
+ const actualArgumentCount = actualArgs.length;
300
+ if (actualArgumentCount === 1) {
301
+ if (Object.values(Environment).includes(envOrApiKey)) {
302
+ throw new Error("A Para API key is required.");
303
+ }
304
+ env = _ParaCore.resolveEnvironment(void 0, actualArgs[0]);
305
+ apiKey = actualArgs[0];
306
+ opts = void 0;
307
+ } else if (actualArgumentCount === 2) {
308
+ if (typeof apiKeyOrOpts === "object" && apiKeyOrOpts !== null) {
309
+ env = _ParaCore.resolveEnvironment(void 0, envOrApiKey);
310
+ apiKey = envOrApiKey;
311
+ opts = apiKeyOrOpts;
312
+ } else {
313
+ env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
314
+ apiKey = apiKeyOrOpts;
315
+ opts = void 0;
316
+ }
317
+ } else {
318
+ env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
319
+ apiKey = apiKeyOrOpts;
275
320
  }
276
321
  if (!opts) opts = {};
277
322
  let isE2E = false;
@@ -314,18 +359,41 @@ const _ParaCore = class _ParaCore {
314
359
  cookie
315
360
  );
316
361
  };
362
+ this.persistEnclaveJwt = (jwt) => {
363
+ this.enclaveJwt = jwt;
364
+ (opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
365
+ constants.LOCAL_STORAGE_ENCLAVE_JWT,
366
+ jwt
367
+ );
368
+ };
369
+ this.persistEnclaveRefreshJwt = (refreshJwt) => {
370
+ this.enclaveRefreshJwt = refreshJwt;
371
+ (opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
372
+ constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
373
+ refreshJwt
374
+ );
375
+ };
376
+ const client = initClient({
377
+ env,
378
+ version: _ParaCore.version,
379
+ apiKey,
380
+ partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
381
+ useFetchAdapter: !!opts.disableWorkers,
382
+ retrieveSessionCookie: this.retrieveSessionCookie,
383
+ persistSessionCookie: this.persistSessionCookie
384
+ });
385
+ const enclaveClient = new EnclaveClient({
386
+ userManagementClient: client,
387
+ retrieveJwt: this.retrieveEnclaveJwt,
388
+ persistJwt: this.persistEnclaveJwt,
389
+ retrieveRefreshJwt: this.retrieveEnclaveRefreshJwt,
390
+ persistRefreshJwt: this.persistEnclaveRefreshJwt
391
+ });
317
392
  this.ctx = {
318
393
  env,
319
394
  apiKey,
320
- client: initClient({
321
- env,
322
- version: _ParaCore.version,
323
- apiKey,
324
- partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
325
- useFetchAdapter: !!opts.disableWorkers,
326
- retrieveSessionCookie: this.retrieveSessionCookie,
327
- persistSessionCookie: this.persistSessionCookie
328
- }),
395
+ client,
396
+ enclaveClient,
329
397
  disableWorkers: opts.disableWorkers,
330
398
  offloadMPCComputationURL: opts.offloadMPCComputationURL,
331
399
  useLocalFiles: opts.useLocalFiles,
@@ -419,11 +487,19 @@ const _ParaCore = class _ParaCore {
419
487
  }
420
488
  get partnerId() {
421
489
  var _a;
422
- return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id;
490
+ return (_a = this.partner) == null ? void 0 : _a.id;
491
+ }
492
+ get partnerName() {
493
+ var _a;
494
+ return (_a = this.partner) == null ? void 0 : _a.displayName;
495
+ }
496
+ get partnerLogo() {
497
+ var _a;
498
+ return (_a = this.partner) == null ? void 0 : _a.logoUrl;
423
499
  }
424
500
  get currentWalletIdsArray() {
425
501
  var _a, _b;
426
- return ((_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
502
+ return ((_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
427
503
  (acc, { type }) => {
428
504
  var _a2;
429
505
  return [
@@ -463,23 +539,23 @@ const _ParaCore = class _ParaCore {
463
539
  }
464
540
  get isNoWalletConfig() {
465
541
  var _a;
466
- return !!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) && __privateGet(this, _partner).supportedWalletTypes.length === 0;
542
+ return !!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) && this.partner.supportedWalletTypes.length === 0;
467
543
  }
468
544
  get supportedWalletTypes() {
469
545
  var _a, _b;
470
- return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
546
+ return (_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
471
547
  }
472
548
  get cosmosPrefix() {
473
549
  var _a;
474
- return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
550
+ return (_a = this.partner) == null ? void 0 : _a.cosmosPrefix;
475
551
  }
476
552
  get supportedAccountLinks() {
477
553
  var _a, _b;
478
- return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...LINKED_ACCOUNT_TYPES];
554
+ return (_b = (_a = this.partner) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...LINKED_ACCOUNT_TYPES];
479
555
  }
480
556
  get isWalletTypeEnabled() {
481
557
  var _a;
482
- return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
558
+ return (((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
483
559
  return __spreadProps(__spreadValues({}, acc), { [type]: true });
484
560
  }, {});
485
561
  }
@@ -528,7 +604,7 @@ const _ParaCore = class _ParaCore {
528
604
  }
529
605
  isWalletSupported(wallet) {
530
606
  var _a, _b;
531
- return !((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = __privateGet(this, _partner).supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
607
+ return !((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = this.partner.supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
532
608
  }
533
609
  isWalletOwned(wallet) {
534
610
  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;
@@ -559,7 +635,7 @@ const _ParaCore = class _ParaCore {
559
635
  } else if (!isOwned && !isUnclaimed) {
560
636
  error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
561
637
  } else if (!this.isWalletSupported(wallet)) {
562
- 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(", ")}`;
638
+ 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(", ")}`;
563
639
  } else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
564
640
  var _a2, _b2;
565
641
  return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
@@ -590,7 +666,7 @@ const _ParaCore = class _ParaCore {
590
666
  if (this.externalWallets[walletId]) {
591
667
  const wallet2 = this.externalWallets[walletId];
592
668
  return options.truncate ? truncateAddress(wallet2.address, wallet2.type, {
593
- prefix: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix,
669
+ prefix: (_a = this.partner) == null ? void 0 : _a.cosmosPrefix,
594
670
  targetLength: options.targetLength
595
671
  }) : wallet2.address;
596
672
  }
@@ -602,7 +678,7 @@ const _ParaCore = class _ParaCore {
602
678
  let prefix;
603
679
  switch (wallet.type) {
604
680
  case "COSMOS":
605
- prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
681
+ prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = this.partner) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
606
682
  str = getCosmosAddress(wallet.publicKey, prefix);
607
683
  break;
608
684
  default:
@@ -636,29 +712,40 @@ const _ParaCore = class _ParaCore {
636
712
  constructPortalUrl(_0) {
637
713
  return __async(this, arguments, function* (type, opts = {}) {
638
714
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
639
- const [isCreate, isLogin, isOnRamp] = [
640
- ["createAuth", "createPassword"].includes(type),
641
- ["loginAuth", "loginPassword"].includes(type),
642
- type === "onRamp"
715
+ const [isCreate, isLogin, isOnRamp, isOAuth, isOAuthCallback, isTelegramLogin, isFarcasterLogin] = [
716
+ ["createAuth", "createPassword", "createPIN"].includes(type),
717
+ ["loginAuth", "loginPassword", "loginPIN", "loginOTP"].includes(type),
718
+ type === "onRamp",
719
+ type === "oAuth",
720
+ type === "oAuthCallback",
721
+ ["telegramLogin", "telegramLoginVerify"].includes(type),
722
+ type === "loginFarcaster"
643
723
  ];
724
+ if (isOAuth && !opts.oAuthMethod) {
725
+ throw new Error("oAuthMethod is required for oAuth portal URLs");
726
+ }
644
727
  if (isCreate || isLogin) {
645
728
  this.assertIsAuthSet();
646
729
  }
647
730
  let sessionId = opts.sessionId;
648
- if ((isLogin || isOnRamp) && !sessionId) {
731
+ if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin) && !sessionId) {
649
732
  const session = yield this.touchSession(true);
650
733
  sessionId = session.sessionId;
651
734
  }
652
735
  if (!this.loginEncryptionKeyPair) {
653
736
  yield this.setLoginEncryptionKeyPair();
654
737
  }
655
- const base = type === "onRamp" || type === "telegramLogin" ? getPortalBaseURL(this.ctx, type === "telegramLogin") : yield this.getPortalURL();
738
+ const base = type === "onRamp" || isTelegramLogin ? getPortalBaseURL(this.ctx, isTelegramLogin) : yield this.getPortalURL();
656
739
  let path;
657
740
  switch (type) {
658
741
  case "createPassword": {
659
742
  path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
660
743
  break;
661
744
  }
745
+ case "createPIN": {
746
+ path = `/web/users/${this.userId}/pin/${opts.pathId}`;
747
+ break;
748
+ }
662
749
  case "createAuth": {
663
750
  path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
664
751
  break;
@@ -671,18 +758,42 @@ const _ParaCore = class _ParaCore {
671
758
  path = "/web/biometrics/login";
672
759
  break;
673
760
  }
761
+ case "loginPIN": {
762
+ path = "/web/pin/login";
763
+ break;
764
+ }
674
765
  case "txReview": {
675
766
  path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
676
767
  break;
677
768
  }
678
769
  case "onRamp": {
679
- path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
770
+ path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
771
+ break;
772
+ }
773
+ case "telegramLoginVerify": {
774
+ path = `/auth/telegram/verify`;
680
775
  break;
681
776
  }
682
777
  case "telegramLogin": {
683
778
  path = `/auth/telegram`;
684
779
  break;
685
780
  }
781
+ case "oAuth": {
782
+ path = `/auth/${opts.oAuthMethod.toLowerCase()}`;
783
+ break;
784
+ }
785
+ case "oAuthCallback": {
786
+ path = `/auth/${opts.oAuthMethod.toLowerCase()}/callback`;
787
+ break;
788
+ }
789
+ case "loginOTP": {
790
+ path = "/auth/otp";
791
+ break;
792
+ }
793
+ case "loginFarcaster": {
794
+ path = "/auth/farcaster";
795
+ break;
796
+ }
686
797
  default: {
687
798
  throw new Error(`invalid URL type ${type}`);
688
799
  }
@@ -701,7 +812,7 @@ const _ParaCore = class _ParaCore {
701
812
  encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
702
813
  sessionId
703
814
  };
704
- const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
815
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
705
816
  apiKey: this.ctx.apiKey,
706
817
  partnerId: partner == null ? void 0 : partner.id,
707
818
  portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
@@ -719,7 +830,7 @@ const _ParaCore = class _ParaCore {
719
830
  }, isPhone(this.authInfo.auth) ? splitPhoneNumber(this.authInfo.auth.phone) : this.authInfo.auth), {
720
831
  pfpUrl: this.authInfo.pfpUrl,
721
832
  displayName: this.authInfo.displayName
722
- }) : {}), isOnRamp ? { sessionId } : {}), isLogin ? __spreadProps(__spreadValues({
833
+ }) : {}), isOnRamp ? { origin: typeof window !== "undefined" ? window.location.origin : void 0, email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin ? __spreadProps(__spreadValues({
723
834
  sessionId: thisDevice.sessionId,
724
835
  encryptionKey: thisDevice.encryptionKey
725
836
  }, opts.newDevice ? {
@@ -727,7 +838,9 @@ const _ParaCore = class _ParaCore {
727
838
  newDeviceEncryptionKey: opts.newDevice.encryptionKey
728
839
  } : {}), {
729
840
  pregenIds: JSON.stringify(this.pregenIds)
730
- }) : {}), type === "telegramLogin" ? { isEmbed: "true" } : {}), opts.params || {});
841
+ }) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
842
+ appScheme: opts.appScheme
843
+ } : {}), isTelegramLogin ? { isEmbed: "true" } : {}), opts.params || {});
731
844
  const url = constructUrl({ base, path, params });
732
845
  if (opts.shorten) {
733
846
  return shortenUrl(this.ctx, url);
@@ -735,15 +848,62 @@ const _ParaCore = class _ParaCore {
735
848
  return url;
736
849
  });
737
850
  }
851
+ static resolveEnvironment(env, apiKey) {
852
+ var _a;
853
+ if (!apiKey) {
854
+ throw new Error("A Para API key is required.");
855
+ }
856
+ if (apiKey.includes("_")) {
857
+ const validEnvironmentPrefixes = Object.values(Environment);
858
+ const envPrefix = (_a = apiKey.split("_")[0]) == null ? void 0 : _a.toUpperCase();
859
+ const hasValidPrefix = validEnvironmentPrefixes.some((envValue) => envValue === envPrefix);
860
+ if (!hasValidPrefix) {
861
+ throw new Error(`Invalid API key environment prefix.`);
862
+ }
863
+ return envPrefix;
864
+ }
865
+ if (!env) {
866
+ throw new Error("Environment parameter is required.");
867
+ }
868
+ return env;
869
+ }
738
870
  touchSession(regenerate = false) {
739
871
  return __async(this, null, function* () {
740
- var _a, _b, _c;
872
+ var _a, _b, _c, _d;
873
+ if (!this.isWorkerInitialized) {
874
+ this.initializeWorker();
875
+ }
741
876
  if (!this.isReady) {
742
877
  yield this.ready();
743
878
  }
744
879
  const session = yield this.ctx.client.touchSession(regenerate);
745
- if (!__privateGet(this, _partner) || ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) !== session.partnerId || !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);
880
+ if (!this.partner || ((_a = this.partner) == null ? void 0 : _a.id) !== session.partnerId || !supportedWalletTypesEq(((_b = this.partner) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = this.partner) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
881
+ if (!session.partnerId) {
882
+ console.error(`
883
+ \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
884
+ \u{1F6A8} PARA SDK CONFIGURATION ERROR \u{1F6A8}
885
+
886
+ INVALID API KEY FOR CONFIGURED ENVIRONMENT
887
+
888
+ Your API key does not match the configured environment. This usually means:
889
+
890
+ 1. You're using a production API key with a development environment
891
+ 2. You're using a development API key with a production environment
892
+ 3. Your API key is invalid or has been regenerated
893
+
894
+ SOLUTION:
895
+ \u2022 Verify your API key at: https://developer.getpara.com
896
+ \u2022 If your API key doesn't contain an environment prefix, ensure your API key is the correct key for your target environment
897
+
898
+ Current Environment: ${this.ctx.env}
899
+ API Key Prefix: ${((_d = this.ctx.apiKey) == null ? void 0 : _d.split("_")[0].toUpperCase()) || "None"}
900
+
901
+ Need help? Visit: https://docs.getpara.com or contact support
902
+ \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
903
+ `);
904
+ } else {
905
+ yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
906
+ }
747
907
  }
748
908
  return session;
749
909
  });
@@ -842,8 +1002,8 @@ const _ParaCore = class _ParaCore {
842
1002
  return __privateGet(this, _authInfo);
843
1003
  });
844
1004
  }
845
- assertUserId() {
846
- if (!this.userId || this.isGuestMode) {
1005
+ assertUserId({ allowGuestMode = false } = {}) {
1006
+ if (!this.userId || !allowGuestMode && this.isGuestMode) {
847
1007
  throw new Error("no userId is set");
848
1008
  }
849
1009
  return this.userId;
@@ -901,11 +1061,59 @@ const _ParaCore = class _ParaCore {
901
1061
  */
902
1062
  setExternalWallet(externalWallet) {
903
1063
  return __async(this, null, function* () {
1064
+ const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
904
1065
  this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
1066
+ (acc, {
1067
+ partnerId: wPartnerId,
1068
+ address,
1069
+ type,
1070
+ provider,
1071
+ providerId,
1072
+ addressBech32,
1073
+ withFullParaAuth,
1074
+ isConnectionOnly,
1075
+ withVerification
1076
+ }) => {
1077
+ if (partnerId === wPartnerId && supportedWalletTypes.some(({ type: supportedType }) => supportedType === type)) {
1078
+ return __spreadProps(__spreadValues({}, acc), {
1079
+ [address]: {
1080
+ id: address,
1081
+ partnerId,
1082
+ address: addressBech32 != null ? addressBech32 : address,
1083
+ type,
1084
+ name: provider,
1085
+ isExternal: true,
1086
+ isExternalWithParaAuth: withFullParaAuth,
1087
+ externalProviderId: providerId,
1088
+ signer: "",
1089
+ isExternalConnectionOnly: isConnectionOnly,
1090
+ isExternalWithVerification: withVerification
1091
+ }
1092
+ });
1093
+ }
1094
+ return acc;
1095
+ },
1096
+ {}
1097
+ ), this.setExternalWallets(this.externalWallets);
1098
+ dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
1099
+ });
1100
+ }
1101
+ addExternalWallets(externalWallets) {
1102
+ return __async(this, null, function* () {
1103
+ const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1104
+ this.externalWallets = __spreadValues(__spreadValues({}, Object.entries(this.externalWallets).reduce((acc, [address, wallet]) => {
1105
+ if (partnerId === wallet.partnerId && supportedWalletTypes.some(({ type }) => type === wallet.type)) {
1106
+ return __spreadProps(__spreadValues({}, acc), {
1107
+ [address]: wallet
1108
+ });
1109
+ }
1110
+ return acc;
1111
+ }, {})), externalWallets.reduce(
905
1112
  (acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
906
1113
  return __spreadProps(__spreadValues({}, acc), {
907
1114
  [address]: {
908
1115
  id: address,
1116
+ partnerId,
909
1117
  address: addressBech32 != null ? addressBech32 : address,
910
1118
  type,
911
1119
  name: provider,
@@ -919,7 +1127,7 @@ const _ParaCore = class _ParaCore {
919
1127
  });
920
1128
  },
921
1129
  {}
922
- );
1130
+ ));
923
1131
  this.setExternalWallets(this.externalWallets);
924
1132
  dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
925
1133
  });
@@ -1273,7 +1481,7 @@ const _ParaCore = class _ParaCore {
1273
1481
  ]);
1274
1482
  const externalWallets = Array.isArray(externalWallet) ? externalWallet : [externalWallet];
1275
1483
  if (this.externalWalletConnectionOnly || externalWallets.every((wallet) => wallet.isConnectionOnly)) {
1276
- yield this.setExternalWallet(
1484
+ yield this.addExternalWallets(
1277
1485
  externalWallets.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
1278
1486
  withFullParaAuth: false
1279
1487
  }))
@@ -1308,12 +1516,17 @@ const _ParaCore = class _ParaCore {
1308
1516
  "cosmosPublicKeyHex",
1309
1517
  "cosmosSigner"
1310
1518
  ]);
1519
+ var _a;
1311
1520
  const serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
1312
1521
  externalWallet,
1313
1522
  signedMessage,
1314
1523
  cosmosPublicKeyHex,
1315
1524
  cosmosSigner
1316
1525
  });
1526
+ if (serverAuthState.stage === "login" && ((_a = serverAuthState.loginAuthMethods) == null ? void 0 : _a.includes(AuthMethod.PIN))) {
1527
+ const { sessionLookupId } = yield this.touchSession();
1528
+ return __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
1529
+ }
1317
1530
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1318
1531
  });
1319
1532
  }
@@ -1330,6 +1543,7 @@ const _ParaCore = class _ParaCore {
1330
1543
  return accounts;
1331
1544
  });
1332
1545
  }
1546
+ // TELEGRAM
1333
1547
  /**
1334
1548
  * Validates the response received from an attempted Telegram login for authenticity, then
1335
1549
  * creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
@@ -1339,19 +1553,28 @@ const _ParaCore = class _ParaCore {
1339
1553
  verifyTelegramProcess(_e) {
1340
1554
  return __async(this, null, function* () {
1341
1555
  var _f = _e, {
1556
+ serverAuthState: optsServerAuthState,
1342
1557
  telegramAuthResponse,
1343
1558
  isLinkAccount
1344
1559
  } = _f, urlOptions = __objRest(_f, [
1560
+ "serverAuthState",
1345
1561
  "telegramAuthResponse",
1346
1562
  "isLinkAccount"
1347
1563
  ]);
1348
1564
  try {
1349
1565
  switch (isLinkAccount) {
1350
1566
  case false: {
1351
- const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
1352
- return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1567
+ if (!optsServerAuthState && !telegramAuthResponse) {
1568
+ throw new Error("one of serverAuthState or telegramAuthResponse are required for verifying telegram");
1569
+ }
1570
+ const serverAuthState = optsServerAuthState != null ? optsServerAuthState : yield this.ctx.client.verifyTelegram({ authObject: telegramAuthResponse });
1571
+ const { sessionLookupId } = yield this.touchSession();
1572
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
1353
1573
  }
1354
1574
  case true: {
1575
+ if (!telegramAuthResponse) {
1576
+ throw new Error("telegramAuthResponse is required for verifying telegram link");
1577
+ }
1355
1578
  const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
1356
1579
  const accounts = yield this.verifyLink({
1357
1580
  accountLinkInProgress,
@@ -1425,6 +1648,7 @@ const _ParaCore = class _ParaCore {
1425
1648
  let type, linkedAccountId;
1426
1649
  switch (reason) {
1427
1650
  case "SIGNUP":
1651
+ case "LOGIN":
1428
1652
  {
1429
1653
  const authInfo = this.assertIsAuthSet(["email", "phone"]);
1430
1654
  type = authInfo.authType.toUpperCase();
@@ -1438,7 +1662,7 @@ const _ParaCore = class _ParaCore {
1438
1662
  }
1439
1663
  break;
1440
1664
  }
1441
- const userId = this.assertUserId();
1665
+ const userId = this.assertUserId({ allowGuestMode: true });
1442
1666
  if (type !== "EMAIL" && type !== "PHONE") {
1443
1667
  throw new Error("invalid auth type for verification code");
1444
1668
  }
@@ -1476,6 +1700,9 @@ const _ParaCore = class _ParaCore {
1476
1700
  isFullyLoggedIn() {
1477
1701
  return __async(this, null, function* () {
1478
1702
  if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
1703
+ if (!this.isReady) {
1704
+ yield this.ready();
1705
+ }
1479
1706
  return true;
1480
1707
  }
1481
1708
  if (this.isGuestMode) {
@@ -1492,10 +1719,13 @@ const _ParaCore = class _ParaCore {
1492
1719
  return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
1493
1720
  ({ userId, partnerId }) => {
1494
1721
  var _a;
1495
- return partnerId === ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
1722
+ return partnerId === ((_a = this.partner) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
1496
1723
  }
1497
1724
  );
1498
1725
  }
1726
+ /**
1727
+ * Get the auth methods available to an existing user
1728
+ */
1499
1729
  supportedAuthMethods(auth) {
1500
1730
  return __async(this, null, function* () {
1501
1731
  const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
@@ -1599,6 +1829,7 @@ const _ParaCore = class _ParaCore {
1599
1829
  return connectUri;
1600
1830
  });
1601
1831
  }
1832
+ // FARCASTER
1602
1833
  /**
1603
1834
  * Awaits the response from a user's attempt to log in with Farcaster.
1604
1835
  * If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
@@ -1611,14 +1842,20 @@ const _ParaCore = class _ParaCore {
1611
1842
  onConnectUri,
1612
1843
  onCancel,
1613
1844
  onPoll,
1614
- isLinkAccount
1845
+ isLinkAccount,
1846
+ serverAuthState: optsServerAuthState
1615
1847
  } = _h, urlOptions = __objRest(_h, [
1616
1848
  "isCanceled",
1617
1849
  "onConnectUri",
1618
1850
  "onCancel",
1619
1851
  "onPoll",
1620
- "isLinkAccount"
1852
+ "isLinkAccount",
1853
+ "serverAuthState"
1621
1854
  ]);
1855
+ if (optsServerAuthState) {
1856
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, optsServerAuthState, urlOptions);
1857
+ return authState;
1858
+ }
1622
1859
  let accountLinkInProgress;
1623
1860
  if (isLinkAccount) {
1624
1861
  accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
@@ -1680,7 +1917,9 @@ const _ParaCore = class _ParaCore {
1680
1917
  }
1681
1918
  getOAuthUrl(opts) {
1682
1919
  return __async(this, null, function* () {
1683
- return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, opts);
1920
+ var _a;
1921
+ const sessionLookupId = (_a = opts.sessionLookupId) != null ? _a : yield this.prepareLogin();
1922
+ return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, __spreadProps(__spreadValues({}, opts), { sessionLookupId }));
1684
1923
  });
1685
1924
  }
1686
1925
  /**
@@ -1691,35 +1930,54 @@ const _ParaCore = class _ParaCore {
1691
1930
  * @param {Window} [opts.popupWindow] the popup window being used for login.
1692
1931
  * @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
1693
1932
  */
1694
- verifyOAuthProcess(_k) {
1933
+ verifyOAuthProcess(_i) {
1695
1934
  return __async(this, null, function* () {
1696
- var _l = _k, {
1935
+ var _j = _i, {
1697
1936
  method,
1698
1937
  appScheme,
1699
1938
  isCanceled = () => false,
1700
1939
  onCancel,
1701
1940
  onPoll,
1702
1941
  onOAuthUrl,
1942
+ onOAuthPopup,
1703
1943
  isLinkAccount
1704
- } = _l, urlOptions = __objRest(_l, [
1944
+ } = _j, urlOptions = __objRest(_j, [
1705
1945
  "method",
1706
1946
  "appScheme",
1707
1947
  "isCanceled",
1708
1948
  "onCancel",
1709
1949
  "onPoll",
1710
1950
  "onOAuthUrl",
1951
+ "onOAuthPopup",
1711
1952
  "isLinkAccount"
1712
1953
  ]);
1954
+ if (onOAuthPopup) {
1955
+ try {
1956
+ this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.OAUTH });
1957
+ } catch (error) {
1958
+ throw new Error(`Failed to open OAuth popup: ${error}`);
1959
+ }
1960
+ }
1713
1961
  let sessionLookupId, accountLinkInProgress;
1714
- if (onOAuthUrl) {
1962
+ if (onOAuthUrl || onOAuthPopup) {
1715
1963
  if (isLinkAccount) {
1716
1964
  accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
1717
1965
  sessionLookupId = (yield this.touchSession()).sessionLookupId;
1718
1966
  } else {
1719
- sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
1967
+ sessionLookupId = yield this.prepareLogin();
1720
1968
  }
1721
1969
  const oAuthUrl = yield __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, { method, appScheme, sessionLookupId, accountLinkInProgress });
1722
- onOAuthUrl(oAuthUrl);
1970
+ switch (true) {
1971
+ case !!onOAuthUrl: {
1972
+ onOAuthUrl(oAuthUrl);
1973
+ break;
1974
+ }
1975
+ case (!!onOAuthPopup && !!this.popupWindow): {
1976
+ this.popupWindow.location.href = oAuthUrl;
1977
+ onOAuthPopup(this.popupWindow);
1978
+ break;
1979
+ }
1980
+ }
1723
1981
  } else {
1724
1982
  ({ sessionLookupId } = yield this.touchSession());
1725
1983
  }
@@ -1855,7 +2113,7 @@ const _ParaCore = class _ParaCore {
1855
2113
  sessionId
1856
2114
  });
1857
2115
  if (shouldOpenPopup) {
1858
- this.platformUtils.openPopup(link);
2116
+ yield this.platformUtils.openPopup(link);
1859
2117
  }
1860
2118
  return link;
1861
2119
  });
@@ -1946,7 +2204,9 @@ const _ParaCore = class _ParaCore {
1946
2204
  userId: this.userId,
1947
2205
  walletId,
1948
2206
  userShare: userSigner,
1949
- emailProps: this.getBackupKitEmailProps()
2207
+ emailProps: this.getBackupKitEmailProps(),
2208
+ isEnclaveUser: this.isEnclaveUser,
2209
+ walletScheme: this.wallets[walletId].scheme
1950
2210
  });
1951
2211
  return recoveryShare;
1952
2212
  });
@@ -2074,7 +2334,9 @@ const _ParaCore = class _ParaCore {
2074
2334
  ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
2075
2335
  emailProps: this.getBackupKitEmailProps(),
2076
2336
  partnerId: newPartnerId,
2077
- protocolId
2337
+ protocolId,
2338
+ isEnclaveUser: this.isEnclaveUser,
2339
+ walletScheme: this.wallets[walletId].scheme
2078
2340
  });
2079
2341
  return { signer, recoverySecret, protocolId };
2080
2342
  });
@@ -2140,7 +2402,9 @@ const _ParaCore = class _ParaCore {
2140
2402
  userId: this.userId,
2141
2403
  walletId: wallet.id,
2142
2404
  userShare: signer,
2143
- emailProps: this.getBackupKitEmailProps()
2405
+ emailProps: this.getBackupKitEmailProps(),
2406
+ isEnclaveUser: this.isEnclaveUser,
2407
+ walletScheme: wallet.scheme
2144
2408
  });
2145
2409
  }
2146
2410
  yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
@@ -2221,7 +2485,9 @@ const _ParaCore = class _ParaCore {
2221
2485
  walletId: wallet.id,
2222
2486
  userShare: this.wallets[wallet.id].signer,
2223
2487
  emailProps: this.getBackupKitEmailProps(),
2224
- partnerId: wallet.partnerId
2488
+ partnerId: wallet.partnerId,
2489
+ isEnclaveUser: this.isEnclaveUser,
2490
+ walletScheme: wallet.scheme
2225
2491
  });
2226
2492
  if (distributeRes.length > 0) {
2227
2493
  newRecoverySecret = distributeRes;
@@ -2399,25 +2665,12 @@ const _ParaCore = class _ParaCore {
2399
2665
  });
2400
2666
  });
2401
2667
  }
2402
- getOnRampTransactionUrl(_m) {
2403
- return __async(this, null, function* () {
2404
- var _n = _m, {
2405
- purchaseId,
2406
- providerKey
2407
- } = _n, walletParams = __objRest(_n, [
2408
- "purchaseId",
2409
- "providerKey"
2410
- ]);
2411
- const { sessionId } = yield this.touchSession();
2412
- const [key, identifier] = extractWalletRef(walletParams);
2668
+ getOnRampTransactionUrl(_0) {
2669
+ return __async(this, arguments, function* ({
2670
+ purchaseId
2671
+ }) {
2413
2672
  return this.constructPortalUrl("onRamp", {
2414
- pathId: purchaseId,
2415
- sessionId,
2416
- params: {
2417
- [key]: identifier,
2418
- providerKey,
2419
- currentWalletIds: JSON.stringify(this.currentWalletIds)
2420
- }
2673
+ pathId: purchaseId
2421
2674
  });
2422
2675
  });
2423
2676
  }
@@ -2451,7 +2704,7 @@ const _ParaCore = class _ParaCore {
2451
2704
  let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
2452
2705
  let timeStart = Date.now();
2453
2706
  if (signRes.pendingTransactionId) {
2454
- this.platformUtils.openPopup(
2707
+ yield this.platformUtils.openPopup(
2455
2708
  yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
2456
2709
  { type: cosmosSignDocBase64 ? PopupType.SIGN_TRANSACTION_REVIEW : PopupType.SIGN_MESSAGE_REVIEW }
2457
2710
  );
@@ -2563,7 +2816,7 @@ const _ParaCore = class _ParaCore {
2563
2816
  );
2564
2817
  let timeStart = Date.now();
2565
2818
  if (signRes.pendingTransactionId) {
2566
- this.platformUtils.openPopup(
2819
+ yield this.platformUtils.openPopup(
2567
2820
  yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
2568
2821
  { type: PopupType.SIGN_TRANSACTION_REVIEW }
2569
2822
  );
@@ -2639,7 +2892,8 @@ const _ParaCore = class _ParaCore {
2639
2892
  providerKey: onRampPurchase.providerKey
2640
2893
  }, walletParams));
2641
2894
  if (shouldOpenPopup) {
2642
- this.platformUtils.openPopup(portalUrl, { type: PopupType.ON_RAMP_TRANSACTION });
2895
+ const onRampWindow = yield this.platformUtils.openPopup(portalUrl, { type: PopupType.ON_RAMP_TRANSACTION });
2896
+ this.onRampPopup = { window: onRampWindow, onRampPurchase };
2643
2897
  }
2644
2898
  return { onRampPurchase, portalUrl };
2645
2899
  });
@@ -2735,6 +2989,7 @@ const _ParaCore = class _ParaCore {
2735
2989
  **/
2736
2990
  logout() {
2737
2991
  return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
2992
+ const shouldDispatchLogoutEvent = yield this.isSessionActive();
2738
2993
  yield this.ctx.client.logout();
2739
2994
  yield this.clearStorage();
2740
2995
  if (!clearPregenWallets) {
@@ -2754,7 +3009,9 @@ const _ParaCore = class _ParaCore {
2754
3009
  this.accountLinkInProgress = void 0;
2755
3010
  this.userId = void 0;
2756
3011
  this.sessionCookie = void 0;
2757
- dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
3012
+ if (shouldDispatchLogoutEvent) {
3013
+ dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
3014
+ }
2758
3015
  });
2759
3016
  }
2760
3017
  get toStringAdditions() {
@@ -2784,9 +3041,9 @@ const _ParaCore = class _ParaCore {
2784
3041
  {}
2785
3042
  );
2786
3043
  const obj = __spreadProps(__spreadValues({
2787
- partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
2788
- supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
2789
- cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
3044
+ partnerId: (_a = this.partner) == null ? void 0 : _a.id,
3045
+ supportedWalletTypes: (_b = this.partner) == null ? void 0 : _b.supportedWalletTypes,
3046
+ cosmosPrefix: (_c = this.partner) == null ? void 0 : _c.cosmosPrefix,
2790
3047
  authInfo: __privateGet(this, _authInfo),
2791
3048
  isGuestMode: this.isGuestMode,
2792
3049
  userId: this.userId,
@@ -2843,6 +3100,14 @@ const _ParaCore = class _ParaCore {
2843
3100
  }));
2844
3101
  urlType = "createPassword";
2845
3102
  break;
3103
+ case "PIN":
3104
+ ({
3105
+ data: { id: credentialId }
3106
+ } = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
3107
+ status: PasswordStatus.PENDING
3108
+ }));
3109
+ urlType = "createPIN";
3110
+ break;
2846
3111
  }
2847
3112
  const url = this.isNativePasskey && urlType === "createAuth" ? void 0 : yield this.constructPortalUrl(urlType, {
2848
3113
  isForNewDevice,
@@ -2854,7 +3119,7 @@ const _ParaCore = class _ParaCore {
2854
3119
  });
2855
3120
  }
2856
3121
  /**
2857
- * Returns a Para Portal URL for logging in with a WebAuth passkey or a password.
3122
+ * Returns a Para Portal URL for logging in with a WebAuth passkey, password, PIN or OTP.
2858
3123
  * @param {Object} opts the options object
2859
3124
  * @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
2860
3125
  * @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
@@ -2880,6 +3145,12 @@ const _ParaCore = class _ParaCore {
2880
3145
  case "PASSWORD":
2881
3146
  urlType = "loginPassword";
2882
3147
  break;
3148
+ case "PIN":
3149
+ urlType = "loginPIN";
3150
+ break;
3151
+ case "SLO":
3152
+ urlType = "loginOTP";
3153
+ break;
2883
3154
  default:
2884
3155
  throw new Error(`invalid authentication method: '${authMethod}'`);
2885
3156
  }
@@ -2890,9 +3161,19 @@ const _ParaCore = class _ParaCore {
2890
3161
  });
2891
3162
  });
2892
3163
  }
2893
- signUpOrLogIn(_o) {
3164
+ prepareLogin() {
2894
3165
  return __async(this, null, function* () {
2895
- var _p = _o, { auth } = _p, urlOptions = __objRest(_p, ["auth"]);
3166
+ yield this.logout();
3167
+ const { sessionLookupId } = yield this.touchSession(true);
3168
+ if (!this.loginEncryptionKeyPair) {
3169
+ yield this.setLoginEncryptionKeyPair();
3170
+ }
3171
+ return sessionLookupId;
3172
+ });
3173
+ }
3174
+ signUpOrLogIn(_k) {
3175
+ return __async(this, null, function* () {
3176
+ var _l = _k, { auth } = _l, urlOptions = __objRest(_l, ["auth"]);
2896
3177
  const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
2897
3178
  const authInfo = serverAuthState.auth;
2898
3179
  if (this.fetchPregenWalletsOverride && isPregenAuth(authInfo)) {
@@ -2901,21 +3182,24 @@ const _ParaCore = class _ParaCore {
2901
3182
  yield this.setUserShare(userShare);
2902
3183
  }
2903
3184
  }
2904
- return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
3185
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadValues({}, urlOptions));
2905
3186
  });
2906
3187
  }
2907
- verifyNewAccount(_q) {
3188
+ verifyNewAccount(_m) {
2908
3189
  return __async(this, null, function* () {
2909
- var _r = _q, {
3190
+ var _n = _m, {
2910
3191
  verificationCode
2911
- } = _r, urlOptions = __objRest(_r, [
3192
+ } = _n, urlOptions = __objRest(_n, [
2912
3193
  "verificationCode"
2913
3194
  ]);
2914
3195
  this.assertIsAuthSet(["email", "phone"]);
2915
- const userId = this.assertUserId();
2916
- const serverAuthState = yield this.ctx.client.verifyNewAccount(userId, {
3196
+ const userId = this.assertUserId({ allowGuestMode: true });
3197
+ const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
2917
3198
  verificationCode
2918
3199
  });
3200
+ if (serverAuthState.stage === "login" || serverAuthState.stage === "done") {
3201
+ throw new Error("Account already exists.");
3202
+ }
2919
3203
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
2920
3204
  });
2921
3205
  }
@@ -3002,10 +3286,10 @@ const _ParaCore = class _ParaCore {
3002
3286
  });
3003
3287
  }
3004
3288
  verifyLink() {
3005
- return __async(this, arguments, function* (_s = {}) {
3006
- var _t = _s, {
3289
+ return __async(this, arguments, function* (_o = {}) {
3290
+ var _p = _o, {
3007
3291
  accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this)
3008
- } = _t, opts = __objRest(_t, [
3292
+ } = _p, opts = __objRest(_p, [
3009
3293
  "accountLinkInProgress"
3010
3294
  ]);
3011
3295
  try {
@@ -3034,31 +3318,36 @@ const _ParaCore = class _ParaCore {
3034
3318
  return accounts;
3035
3319
  });
3036
3320
  }
3321
+ sendLoginCode() {
3322
+ return __async(this, null, function* () {
3323
+ const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
3324
+ this.setUserId(userId);
3325
+ });
3326
+ }
3037
3327
  };
3038
3328
  _authInfo = new WeakMap();
3039
- _partner = new WeakMap();
3040
3329
  _ParaCore_instances = new WeakSet();
3041
3330
  assertPartner_fn = function() {
3042
3331
  return __async(this, null, function* () {
3043
3332
  var _a, _b;
3044
- if (!__privateGet(this, _partner)) {
3333
+ if (!this.partner) {
3045
3334
  yield this.touchSession();
3046
3335
  }
3047
- if (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== __privateGet(this, _partner).cosmosPrefix) {
3048
- this.ctx.cosmosPrefix = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix;
3336
+ if (((_a = this.partner) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== this.partner.cosmosPrefix) {
3337
+ this.ctx.cosmosPrefix = (_b = this.partner) == null ? void 0 : _b.cosmosPrefix;
3049
3338
  }
3050
- return __privateGet(this, _partner);
3339
+ return this.partner;
3051
3340
  });
3052
3341
  };
3053
3342
  guestWalletIds_get = function() {
3054
3343
  var _a, _b, _c;
3055
- if (!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes)) {
3344
+ if (!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes)) {
3056
3345
  return {};
3057
3346
  }
3058
3347
  const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
3059
3348
  return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
3060
3349
  if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
3061
- return __spreadValues(__spreadValues({}, acc), getEquivalentTypes(wallet.type).filter((type) => __privateGet(this, _partner).supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
3350
+ return __spreadValues(__spreadValues({}, acc), getEquivalentTypes(wallet.type).filter((type) => this.partner.supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
3062
3351
  var _a2;
3063
3352
  return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
3064
3353
  }, {}));
@@ -3119,8 +3408,8 @@ getPartner_fn = function(partnerId) {
3119
3408
  return void 0;
3120
3409
  }
3121
3410
  const res = yield this.ctx.client.getPartner(partnerId);
3122
- __privateSet(this, _partner, res.data.partner);
3123
- return __privateGet(this, _partner);
3411
+ this.partner = res.data.partner;
3412
+ return this.partner;
3124
3413
  });
3125
3414
  };
3126
3415
  assertIsLinkingAccount_fn = function(types) {
@@ -3142,29 +3431,42 @@ assertIsLinkingAccountOrStart_fn = function(type) {
3142
3431
  return yield this.linkAccount({ type });
3143
3432
  });
3144
3433
  };
3145
- getOAuthUrl_fn = function(_i) {
3146
- return __async(this, null, function* () {
3147
- var _j = _i, {
3148
- method,
3149
- appScheme,
3150
- accountLinkInProgress
3151
- } = _j, params = __objRest(_j, [
3152
- "method",
3153
- "appScheme",
3154
- "accountLinkInProgress"
3155
- ]);
3156
- var _a;
3157
- const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
3434
+ getOAuthUrl_fn = function(_0) {
3435
+ return __async(this, arguments, function* ({
3436
+ method,
3437
+ appScheme,
3438
+ accountLinkInProgress,
3439
+ sessionLookupId,
3440
+ encryptionKey
3441
+ }) {
3442
+ if (!accountLinkInProgress && !this.isPortal()) {
3443
+ return yield this.constructPortalUrl("oAuth", { sessionId: sessionLookupId, oAuthMethod: method, appScheme });
3444
+ }
3445
+ let portalSessionLookupId;
3446
+ if (this.isPortal()) {
3447
+ portalSessionLookupId = (yield this.touchSession(true)).sessionLookupId;
3448
+ }
3158
3449
  return constructUrl({
3159
3450
  base: getBaseOAuthUrl(this.ctx.env),
3160
3451
  path: `/auth/${method}`,
3161
- params: __spreadValues({
3452
+ params: __spreadProps(__spreadValues({
3162
3453
  apiKey: this.ctx.apiKey,
3163
3454
  sessionLookupId,
3455
+ portalSessionLookupId,
3164
3456
  appScheme
3165
3457
  }, accountLinkInProgress ? {
3166
3458
  linkedAccountId: this.accountLinkInProgress.id
3167
- } : {})
3459
+ } : {}), {
3460
+ callback: !accountLinkInProgress && (yield this.constructPortalUrl("oAuthCallback", {
3461
+ sessionId: sessionLookupId,
3462
+ oAuthMethod: method,
3463
+ appScheme,
3464
+ thisDevice: {
3465
+ sessionId: sessionLookupId,
3466
+ encryptionKey
3467
+ }
3468
+ }))
3469
+ })
3168
3470
  });
3169
3471
  });
3170
3472
  };
@@ -3218,8 +3520,9 @@ createPregenWallet_fn = function(opts) {
3218
3520
  _isCreateGuestWalletsPending = new WeakMap();
3219
3521
  prepareAuthState_fn = function(_0) {
3220
3522
  return __async(this, arguments, function* (serverAuthState, opts = {}) {
3221
- if (!opts.sessionLookupId && serverAuthState.stage === "login") {
3222
- opts.sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
3523
+ var _a, _b;
3524
+ if (!opts.sessionLookupId && serverAuthState.stage === "login" && (!serverAuthState.externalWallet || !(((_a = serverAuthState.externalWallet) == null ? void 0 : _a.withFullParaAuth) && ((_b = serverAuthState.loginAuthMethods) == null ? void 0 : _b.includes(AuthMethod.PIN))))) {
3525
+ opts.sessionLookupId = yield this.prepareLogin();
3223
3526
  }
3224
3527
  const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
3225
3528
  const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), Object.fromEntries(
@@ -3240,8 +3543,14 @@ prepareAuthState_fn = function(_0) {
3240
3543
  }
3241
3544
  let authState;
3242
3545
  switch (serverAuthState.stage) {
3546
+ case "done": {
3547
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareDoneState_fn).call(this, serverAuthState);
3548
+ break;
3549
+ }
3243
3550
  case "verify":
3244
- authState = serverAuthState;
3551
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareVerificationState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), {
3552
+ sessionLookupId: opts.sessionLookupId
3553
+ }));
3245
3554
  break;
3246
3555
  case "login":
3247
3556
  if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
@@ -3261,14 +3570,34 @@ prepareAuthState_fn = function(_0) {
3261
3570
  return authState;
3262
3571
  });
3263
3572
  };
3264
- prepareLogin_fn = function() {
3573
+ prepareDoneState_fn = function(doneState) {
3265
3574
  return __async(this, null, function* () {
3266
- yield this.logout();
3267
- const { sessionLookupId } = yield this.touchSession(true);
3268
- if (!this.loginEncryptionKeyPair) {
3269
- yield this.setLoginEncryptionKeyPair();
3575
+ let isSLOPossible = doneState.authMethods.includes(AuthMethod.SLO);
3576
+ this.isEnclaveUser = isSLOPossible;
3577
+ return doneState;
3578
+ });
3579
+ };
3580
+ prepareVerificationState_fn = function(_0, _1) {
3581
+ return __async(this, arguments, function* (verifyState, {
3582
+ useShortUrls: shorten = false,
3583
+ portalTheme,
3584
+ sessionLookupId
3585
+ }) {
3586
+ let isSLOPossible = false;
3587
+ if (verifyState.nextStage === "login") {
3588
+ isSLOPossible = verifyState.loginAuthMethods.includes(AuthMethod.SLO);
3589
+ } else if (verifyState.nextStage === "signup") {
3590
+ isSLOPossible = verifyState.signupAuthMethods.includes(AuthMethod.SLO);
3270
3591
  }
3271
- return sessionLookupId;
3592
+ this.isEnclaveUser = isSLOPossible;
3593
+ return __spreadValues(__spreadValues({}, verifyState), isSLOPossible ? {
3594
+ loginUrl: yield this.getLoginUrl({
3595
+ authMethod: AuthMethod.SLO,
3596
+ sessionId: sessionLookupId,
3597
+ shorten,
3598
+ portalTheme
3599
+ })
3600
+ } : {});
3272
3601
  });
3273
3602
  };
3274
3603
  prepareLoginState_fn = function(_0, _1) {
@@ -3277,9 +3606,9 @@ prepareLoginState_fn = function(_0, _1) {
3277
3606
  portalTheme,
3278
3607
  sessionLookupId
3279
3608
  }) {
3280
- const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
3281
- const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(AuthMethod.PASSWORD);
3282
- return __spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
3609
+ const _a = loginState, { loginAuthMethods, hasPasswordWithoutPIN } = _a, authState = __objRest(_a, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
3610
+ const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(AuthMethod.PASSWORD) && hasPasswordWithoutPIN, isPINPossible = loginAuthMethods.includes(AuthMethod.PIN);
3611
+ return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
3283
3612
  isPasskeySupported
3284
3613
  }), isPasskeyPossible ? {
3285
3614
  passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
@@ -3299,6 +3628,13 @@ prepareLoginState_fn = function(_0, _1) {
3299
3628
  portalTheme,
3300
3629
  params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
3301
3630
  })
3631
+ } : {}), isPINPossible ? {
3632
+ pinUrl: yield this.constructPortalUrl("loginPIN", {
3633
+ sessionId: sessionLookupId,
3634
+ shorten,
3635
+ portalTheme,
3636
+ params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
3637
+ })
3302
3638
  } : {});
3303
3639
  });
3304
3640
  };
@@ -3306,13 +3642,14 @@ prepareSignUpState_fn = function(_0, _1) {
3306
3642
  return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
3307
3643
  const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
3308
3644
  const isPasskeySupported = yield this.isPasskeySupported();
3309
- const [isPasskey, isPassword] = [
3645
+ const [isPasskey, isPassword, isPIN] = [
3310
3646
  signupAuthMethods.includes(AuthMethod.PASSKEY),
3311
- signupAuthMethods.includes(AuthMethod.PASSWORD) || !isPasskeySupported
3647
+ signupAuthMethods.includes(AuthMethod.PASSWORD) || !isPasskeySupported,
3648
+ signupAuthMethods.includes(AuthMethod.PIN)
3312
3649
  ];
3313
- if (!isPasskey && !isPassword) {
3650
+ if (!isPasskey && !isPassword && !isPIN) {
3314
3651
  throw new Error(
3315
- "No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or passwords in your Developer Portal settings."
3652
+ "No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys, passwords or PINs in your Developer Portal settings."
3316
3653
  );
3317
3654
  }
3318
3655
  const signupState = __spreadProps(__spreadValues({}, authState), { isPasskeySupported });
@@ -3333,6 +3670,15 @@ prepareSignUpState_fn = function(_0, _1) {
3333
3670
  signupState.passwordUrl = passwordUrl;
3334
3671
  signupState.passwordId = passwordId;
3335
3672
  }
3673
+ if (isPIN) {
3674
+ const { url: pinUrl, credentialId: pinId } = yield this.getNewCredentialAndUrl({
3675
+ authMethod: "PIN",
3676
+ portalTheme,
3677
+ shorten
3678
+ });
3679
+ signupState.pinUrl = pinUrl;
3680
+ signupState.pinId = pinId;
3681
+ }
3336
3682
  return signupState;
3337
3683
  });
3338
3684
  };