@getpara/core-sdk 2.0.0-dev.0 → 2.0.0-dev.1

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.
package/dist/esm/index.js CHANGED
@@ -78,6 +78,8 @@ import {
78
78
  isPhone,
79
79
  isFarcaster,
80
80
  isTelegram,
81
+ toPregenTypeAndId,
82
+ toPregenIds,
81
83
  isExternalWallet
82
84
  } from "@getpara/user-management-client";
83
85
  import forge3 from "node-forge";
@@ -186,7 +188,7 @@ function jsonParse(data, validate) {
186
188
  }
187
189
 
188
190
  // src/constants.ts
189
- var PARA_CORE_VERSION = '2.0.0-dev.0';
191
+ var PARA_CORE_VERSION = '2.0.0-dev.1';
190
192
  var PREFIX = "@CAPSULE/";
191
193
  var LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
192
194
  var LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
@@ -203,6 +205,7 @@ var LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
203
205
  var SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
204
206
  var POLLING_INTERVAL_MS = 2e3;
205
207
  var SHORT_POLLING_INTERVAL_MS = 1e3;
208
+ var POLLING_TIMEOUT_MS = 3e5;
206
209
 
207
210
  // src/utils/listeners.ts
208
211
  function storageListener(e) {
@@ -277,10 +280,7 @@ function getOnRampAssets(data, {
277
280
  // src/utils/phone.ts
278
281
  import parsePhoneNumberFromString from "libphonenumber-js";
279
282
  function formatPhoneNumber(phone, countryCode, { forDisplay = false } = {}) {
280
- if (!phone) {
281
- return null;
282
- }
283
- phone = phone == null ? void 0 : phone.toString();
283
+ phone = phone.toString();
284
284
  countryCode = countryCode == null ? void 0 : countryCode.toString();
285
285
  let sanitizedNumber, parsedNumber;
286
286
  if (!!countryCode) {
@@ -316,6 +316,48 @@ function waitUntilTrue(condition, timeoutMs, intervalMs) {
316
316
  });
317
317
  }
318
318
 
319
+ // src/utils/types.ts
320
+ function isServerAuthState(obj) {
321
+ return "stage" in obj;
322
+ }
323
+
324
+ // src/transmission/transmissionUtils.ts
325
+ import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from "@celo/utils/lib/ecies.js";
326
+ import { Buffer as Buffer2 } from "buffer";
327
+ import * as eutil from "ethereumjs-util";
328
+ import { randomBytes } from "crypto";
329
+ function upload(message, userManagementClient) {
330
+ return __async(this, null, function* () {
331
+ let secret;
332
+ let publicKeyUint8Array;
333
+ while (true) {
334
+ try {
335
+ secret = randomBytes(32).toString("hex");
336
+ publicKeyUint8Array = eutil.privateToPublic(Buffer2.from(secret, "hex"));
337
+ break;
338
+ } catch (e) {
339
+ continue;
340
+ }
341
+ }
342
+ const pubkey = Buffer2.from(publicKeyUint8Array);
343
+ const data = ECIESEncrypt(pubkey, Buffer2.from(message, "ucs2")).toString("base64");
344
+ const {
345
+ data: { id }
346
+ } = yield userManagementClient.tempTrasmissionInit(data);
347
+ return encodeURIComponent(id + "|" + secret);
348
+ });
349
+ }
350
+ function retrieve(uriEncodedMessage, userManagementClient) {
351
+ return __async(this, null, function* () {
352
+ const [id, secret] = decodeURIComponent(uriEncodedMessage).split("|");
353
+ const response = yield userManagementClient.tempTrasmission(id);
354
+ const data = response.data.message;
355
+ const buf = Buffer2.from(data, "base64");
356
+ const res = Buffer2.from(ECIESDecrypt(Buffer2.from(secret, "hex"), buf).buffer).toString("ucs2");
357
+ return res;
358
+ });
359
+ }
360
+
319
361
  // src/types/config.ts
320
362
  var Environment = /* @__PURE__ */ ((Environment2) => {
321
363
  Environment2["DEV"] = "DEV";
@@ -333,6 +375,49 @@ var EnabledFlow = /* @__PURE__ */ ((EnabledFlow2) => {
333
375
  return EnabledFlow2;
334
376
  })(EnabledFlow || {});
335
377
 
378
+ // src/types/coreApi.ts
379
+ var PARA_CORE_METHODS = [
380
+ "signUpOrLogInV2",
381
+ "verifyNewAccountV2",
382
+ "waitForLoginV2",
383
+ "waitForSignupV2",
384
+ "waitForWalletCreationV2",
385
+ "verifyOAuthV2",
386
+ "verifyFarcasterV2",
387
+ "verifyTelegramV2",
388
+ "resendVerificationCode",
389
+ "loginExternalWalletV2",
390
+ "verifyExternalWalletV2",
391
+ "setup2faV2",
392
+ "enable2faV2",
393
+ "verify2faV2",
394
+ "logout",
395
+ "clearStorage",
396
+ "isSessionActive",
397
+ "isFullyLoggedIn",
398
+ "refreshSession",
399
+ "keepSessionAlive",
400
+ "exportSession",
401
+ "importSession",
402
+ "getVerificationToken",
403
+ "fetchWallets",
404
+ "createWallet",
405
+ "createWalletPerType",
406
+ "getPregenWalletsV2",
407
+ "hasPregenWalletV2",
408
+ "updatePregenWalletIdentifierV2",
409
+ "createPregenWalletV2",
410
+ "createPregenWalletPerTypeV2",
411
+ "claimPregenWalletsV2",
412
+ "distributeNewWalletShare",
413
+ "getUserShare",
414
+ "setUserShare",
415
+ "refreshShare",
416
+ "signMessage",
417
+ "signTransaction",
418
+ "initiateOnRampTransaction"
419
+ ];
420
+
336
421
  // src/types/wallet.ts
337
422
  var PregenIdentifierType = /* @__PURE__ */ ((PregenIdentifierType2) => {
338
423
  PregenIdentifierType2["EMAIL"] = "EMAIL";
@@ -455,6 +540,15 @@ function constructUrl({
455
540
  });
456
541
  return url.toString();
457
542
  }
543
+ function shortenUrl(ctx, url) {
544
+ return __async(this, null, function* () {
545
+ const compressedUrl = yield upload(url, ctx.client);
546
+ return constructUrl({
547
+ base: getPortalBaseURL(ctx),
548
+ path: `/short/${compressedUrl}`
549
+ });
550
+ });
551
+ }
458
552
 
459
553
  // src/utils/wallet.ts
460
554
  import {
@@ -897,8 +991,8 @@ import { EncryptorType as EncryptorType2, KeyShareType as KeyShareType2 } from "
897
991
  import { EncryptorType, KeyShareType } from "@getpara/user-management-client";
898
992
 
899
993
  // src/shares/KeyContainer.ts
900
- import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from "@celo/utils/lib/ecies.js";
901
- import * as eutil from "ethereumjs-util";
994
+ import { Encrypt as ECIESEncrypt2, Decrypt as ECIESDecrypt2 } from "@celo/utils/lib/ecies.js";
995
+ import * as eutil2 from "ethereumjs-util";
902
996
  import * as forge2 from "node-forge";
903
997
  var KeyContainer = class _KeyContainer {
904
998
  constructor(walletId, keyshare, address) {
@@ -918,7 +1012,7 @@ var KeyContainer = class _KeyContainer {
918
1012
  }
919
1013
  }
920
1014
  getPublicEncryptionKey() {
921
- return Buffer.from(eutil.privateToPublic(Buffer.from(this.backupDecryptionKey, "hex")));
1015
+ return Buffer.from(eutil2.privateToPublic(Buffer.from(this.backupDecryptionKey, "hex")));
922
1016
  }
923
1017
  getPublicEncryptionKeyHex() {
924
1018
  return this.getPublicEncryptionKey().toString("hex");
@@ -926,7 +1020,7 @@ var KeyContainer = class _KeyContainer {
926
1020
  encryptForSelf(backup) {
927
1021
  try {
928
1022
  const pubkey = this.getPublicEncryptionKey();
929
- const data = ECIESEncrypt(pubkey, Buffer.from(backup, "ucs2")).toString("base64");
1023
+ const data = ECIESEncrypt2(pubkey, Buffer.from(backup, "ucs2")).toString("base64");
930
1024
  return data;
931
1025
  } catch (error) {
932
1026
  throw Error("Error encrypting backup");
@@ -934,7 +1028,7 @@ var KeyContainer = class _KeyContainer {
934
1028
  }
935
1029
  static encryptWithPublicKey(publicKey, backup) {
936
1030
  try {
937
- const data = ECIESEncrypt(publicKey, Buffer.from(backup, "ucs2")).toString("base64");
1031
+ const data = ECIESEncrypt2(publicKey, Buffer.from(backup, "ucs2")).toString("base64");
938
1032
  return data;
939
1033
  } catch (error) {
940
1034
  throw Error("Error encrypting backup");
@@ -943,7 +1037,7 @@ var KeyContainer = class _KeyContainer {
943
1037
  decrypt(encryptedBackup) {
944
1038
  try {
945
1039
  const buf = Buffer.from(encryptedBackup, "base64");
946
- const data = ECIESDecrypt(Buffer.from(this.backupDecryptionKey, "hex"), buf);
1040
+ const data = ECIESDecrypt2(Buffer.from(this.backupDecryptionKey, "hex"), buf);
947
1041
  return Buffer.from(data.buffer).toString("ucs2");
948
1042
  } catch (error) {
949
1043
  throw Error("Error decrypting backup");
@@ -1075,43 +1169,6 @@ function distributeNewShare(_0) {
1075
1169
  });
1076
1170
  }
1077
1171
 
1078
- // src/transmission/transmissionUtils.ts
1079
- import { Encrypt as ECIESEncrypt2, Decrypt as ECIESDecrypt2 } from "@celo/utils/lib/ecies.js";
1080
- import { Buffer as Buffer2 } from "buffer";
1081
- import * as eutil2 from "ethereumjs-util";
1082
- import { randomBytes } from "crypto";
1083
- function upload(message, userManagementClient) {
1084
- return __async(this, null, function* () {
1085
- let secret;
1086
- let publicKeyUint8Array;
1087
- while (true) {
1088
- try {
1089
- secret = randomBytes(32).toString("hex");
1090
- publicKeyUint8Array = eutil2.privateToPublic(Buffer2.from(secret, "hex"));
1091
- break;
1092
- } catch (e) {
1093
- continue;
1094
- }
1095
- }
1096
- const pubkey = Buffer2.from(publicKeyUint8Array);
1097
- const data = ECIESEncrypt2(pubkey, Buffer2.from(message, "ucs2")).toString("base64");
1098
- const {
1099
- data: { id }
1100
- } = yield userManagementClient.tempTrasmissionInit(data);
1101
- return encodeURIComponent(id + "|" + secret);
1102
- });
1103
- }
1104
- function retrieve(uriEncodedMessage, userManagementClient) {
1105
- return __async(this, null, function* () {
1106
- const [id, secret] = decodeURIComponent(uriEncodedMessage).split("|");
1107
- const response = yield userManagementClient.tempTrasmission(id);
1108
- const data = response.data.message;
1109
- const buf = Buffer2.from(data, "base64");
1110
- const res = Buffer2.from(ECIESDecrypt2(Buffer2.from(secret, "hex"), buf).buffer).toString("ucs2");
1111
- return res;
1112
- });
1113
- }
1114
-
1115
1172
  // src/errors.ts
1116
1173
  var TransactionReviewError = class extends Error {
1117
1174
  constructor(transactionReviewUrl) {
@@ -1146,7 +1203,7 @@ if (typeof global !== "undefined") {
1146
1203
  self.global = self.global || self;
1147
1204
  }
1148
1205
  var { pki, jsbn } = forge3;
1149
- var _authInfo, _partner, _ParaCore_instances, assertPartner_fn, toAuthInfo_fn, setAuthInfo_fn, assertIsAuthSet_fn, getPartner_fn;
1206
+ var _authInfo, _partner, _ParaCore_instances, assertPartner_fn, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, prepareAuthState_fn, prepareLogin_fn, prepareLoginState_fn, prepareSignUpState_fn;
1150
1207
  var _ParaCore = class _ParaCore {
1151
1208
  /**
1152
1209
  * Constructs a new `ParaCore` instance.
@@ -1158,6 +1215,7 @@ var _ParaCore = class _ParaCore {
1158
1215
  constructor(env, apiKey, opts) {
1159
1216
  __privateAdd(this, _ParaCore_instances);
1160
1217
  __privateAdd(this, _authInfo);
1218
+ this.isNativePasskey = false;
1161
1219
  __privateAdd(this, _partner);
1162
1220
  this.isAwaitingAccountCreation = false;
1163
1221
  this.isAwaitingLogin = false;
@@ -1167,6 +1225,10 @@ var _ParaCore = class _ParaCore {
1167
1225
  * 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.
1168
1226
  */
1169
1227
  this.currentWalletIds = {};
1228
+ /**
1229
+ * Wallets associated with the `ParaCore` instance.
1230
+ */
1231
+ this.externalWallets = {};
1170
1232
  this.localStorageGetItem = (key) => {
1171
1233
  return this.platformUtils.localStorage.get(key);
1172
1234
  };
@@ -1621,6 +1683,91 @@ var _ParaCore = class _ParaCore {
1621
1683
  var _a, _b, _c;
1622
1684
  return walletId ? (_a = this.wallets[walletId]) == null ? void 0 : _a.address : (_c = (_b = Object.values(this.wallets)) == null ? void 0 : _b[0]) == null ? void 0 : _c.address;
1623
1685
  }
1686
+ constructPortalUrlV2(_0) {
1687
+ return __async(this, arguments, function* (type, opts = {}) {
1688
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1689
+ const [isCreate, isLogin, isOnRamp] = [
1690
+ ["createAuth", "createPassword"].includes(type),
1691
+ ["loginAuth", "loginPassword"].includes(type),
1692
+ type === "onRamp"
1693
+ ];
1694
+ let auth;
1695
+ if (isCreate || isLogin) {
1696
+ auth = this.assertIsAuthSet().auth;
1697
+ }
1698
+ let sessionId = opts.sessionId;
1699
+ if ((isLogin || isOnRamp) && !sessionId) {
1700
+ const session = yield this.touchSession(true);
1701
+ sessionId = session.sessionId;
1702
+ }
1703
+ if (!this.loginEncryptionKeyPair) {
1704
+ yield this.setLoginEncryptionKeyPair();
1705
+ }
1706
+ const base = type === "onRamp" ? getPortalBaseURL(this.ctx) : yield this.getPortalURL();
1707
+ let path;
1708
+ switch (type) {
1709
+ case "createPassword": {
1710
+ path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
1711
+ break;
1712
+ }
1713
+ case "createAuth": {
1714
+ path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
1715
+ break;
1716
+ }
1717
+ case "loginPassword": {
1718
+ path = "/web/passwords/login";
1719
+ break;
1720
+ }
1721
+ case "loginAuth": {
1722
+ path = "/web/biometrics/login";
1723
+ break;
1724
+ }
1725
+ case "txReview": {
1726
+ path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
1727
+ break;
1728
+ }
1729
+ case "onRamp": {
1730
+ path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
1731
+ break;
1732
+ }
1733
+ default: {
1734
+ throw new Error(`invalid URL type ${type}`);
1735
+ }
1736
+ }
1737
+ const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1738
+ const thisDevice = (_a = opts.thisDevice) != null ? _a : {
1739
+ encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
1740
+ sessionId
1741
+ };
1742
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
1743
+ apiKey: this.ctx.apiKey,
1744
+ partnerId: partner.id,
1745
+ portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
1746
+ portalBorderRadius: ((_d = opts.portalTheme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
1747
+ portalThemeMode: ((_f = opts.portalTheme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
1748
+ portalAccentColor: ((_h = opts.portalTheme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
1749
+ portalForegroundColor: ((_j = opts.portalTheme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
1750
+ portalBackgroundColor: ((_l = opts.portalTheme) == null ? void 0 : _l.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor || ((_m = this.portalTheme) == null ? void 0 : _m.backgroundColor),
1751
+ portalPrimaryButtonColor: this.portalPrimaryButtonColor,
1752
+ portalTextColor: this.portalTextColor,
1753
+ portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
1754
+ isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
1755
+ }, auth && (isCreate || isLogin) ? auth : {}), isOnRamp ? { sessionId } : {}), isLogin ? __spreadProps(__spreadValues({
1756
+ sessionId: thisDevice.sessionId,
1757
+ encryptionKey: thisDevice.encryptionKey
1758
+ }, opts.newDevice ? {
1759
+ newDeviceSessionLookupId: opts.newDevice.sessionId,
1760
+ newDeviceEncryptionKey: opts.newDevice.encryptionKey
1761
+ } : {}), {
1762
+ pregenIds: JSON.stringify(this.pregenIds)
1763
+ }) : {}), opts.params || {});
1764
+ const url = constructUrl({ base, path, params });
1765
+ if (opts.shorten) {
1766
+ return shortenUrl(this.ctx, url);
1767
+ }
1768
+ return url;
1769
+ });
1770
+ }
1624
1771
  constructPortalUrl(_0) {
1625
1772
  return __async(this, arguments, function* (type, opts = {}) {
1626
1773
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
@@ -1631,7 +1778,7 @@ var _ParaCore = class _ParaCore {
1631
1778
  ];
1632
1779
  let auth;
1633
1780
  if (isCreate || isLogin) {
1634
- auth = __privateMethod(this, _ParaCore_instances, assertIsAuthSet_fn).call(this);
1781
+ auth = this.assertIsAuthSet().auth;
1635
1782
  }
1636
1783
  if ((isLogin || isOnRamp) && !opts.sessionId) {
1637
1784
  opts.sessionId = (yield this.touchSession()).sessionLookupId;
@@ -1668,7 +1815,7 @@ var _ParaCore = class _ParaCore {
1668
1815
  }
1669
1816
  }
1670
1817
  const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1671
- const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
1818
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
1672
1819
  apiKey: this.ctx.apiKey,
1673
1820
  partnerId: partner.id,
1674
1821
  portalFont: ((_a = opts.theme) == null ? void 0 : _a.font) || (partner == null ? void 0 : partner.font) || ((_b = this.portalTheme) == null ? void 0 : _b.font),
@@ -1681,7 +1828,7 @@ var _ParaCore = class _ParaCore {
1681
1828
  portalTextColor: this.portalTextColor,
1682
1829
  portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
1683
1830
  isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
1684
- }, auth && (isCreate || isLogin) ? auth : {}), isLogin || isOnRamp ? { sessionId: opts.sessionId } : {}), isLogin ? {
1831
+ }, auth && (isCreate || isLogin) ? auth : {}), isCreate || isLogin ? { authInfo: JSON.stringify(this.authInfo) } : {}), isLogin || isOnRamp ? { sessionId: opts.sessionId } : {}), isLogin ? {
1685
1832
  encryptionKey: opts.loginEncryptionPublicKey,
1686
1833
  newDeviceSessionLookupId: opts.newDeviceSessionId,
1687
1834
  newDeviceEncryptionKey: opts.newDeviceEncryptionKey,
@@ -1796,6 +1943,21 @@ var _ParaCore = class _ParaCore {
1796
1943
  return __privateGet(this, _authInfo);
1797
1944
  });
1798
1945
  }
1946
+ assertUserId() {
1947
+ if (!this.userId) {
1948
+ throw new Error("no userId is set");
1949
+ }
1950
+ return this.userId;
1951
+ }
1952
+ assertIsAuthSet(allowed) {
1953
+ if (!__privateGet(this, _authInfo)) {
1954
+ throw new Error("auth is not set");
1955
+ }
1956
+ if (allowed && !allowed.includes(__privateGet(this, _authInfo).authType)) {
1957
+ throw new Error(`invalid auth type, expected ${allowed.join(", ")}`);
1958
+ }
1959
+ return __privateGet(this, _authInfo);
1960
+ }
1799
1961
  /**
1800
1962
  * Sets the email associated with the `ParaCore` instance.
1801
1963
  * @param email - Email to set.
@@ -2139,6 +2301,7 @@ var _ParaCore = class _ParaCore {
2139
2301
  }
2140
2302
  /**
2141
2303
  * Generates a URL for registering a new WebAuth passkey.
2304
+ * @deprecated
2142
2305
  * @param {GetWebAuthUrlForLoginParams} opts the options object
2143
2306
  * @returns - the URL for creating a new passkey
2144
2307
  */
@@ -2149,6 +2312,7 @@ var _ParaCore = class _ParaCore {
2149
2312
  }
2150
2313
  /**
2151
2314
  * Generates a URL for registering a new user password.
2315
+ * @deprecated
2152
2316
  * @param {GetWebAuthUrlForLoginParams} opts the options object
2153
2317
  * @returns - the URL for creating a new password
2154
2318
  */
@@ -2159,6 +2323,7 @@ var _ParaCore = class _ParaCore {
2159
2323
  }
2160
2324
  /**
2161
2325
  * Generates a URL for registering a new WebAuth passkey for a phone number.
2326
+ * @deprecated
2162
2327
  * @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
2163
2328
  * @returns - web auth url
2164
2329
  */
@@ -2219,7 +2384,7 @@ var _ParaCore = class _ParaCore {
2219
2384
  }
2220
2385
  populatePregenWalletAddresses() {
2221
2386
  return __async(this, null, function* () {
2222
- const res = yield this.getPregenWallets();
2387
+ const res = yield this.getPregenWalletsV2();
2223
2388
  res.forEach((entity) => {
2224
2389
  if (this.wallets[entity.id]) {
2225
2390
  this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
@@ -2230,6 +2395,7 @@ var _ParaCore = class _ParaCore {
2230
2395
  }
2231
2396
  /**
2232
2397
  * Checks if a user exists for an email address.
2398
+ * @deprecated
2233
2399
  * @param {Object} opts the options object
2234
2400
  * @param {string} opts.email the email to check.
2235
2401
  * @returns true if user exists, false otherwise.
@@ -2242,6 +2408,7 @@ var _ParaCore = class _ParaCore {
2242
2408
  }
2243
2409
  /**
2244
2410
  * Checks if a user exists for a phone number.
2411
+ * @deprecated
2245
2412
  * @param {Object} opts the options object
2246
2413
  * @param {string} opts.phone - phone number to check.
2247
2414
  * @param {string} opts.countryCode - the country code.
@@ -2255,6 +2422,7 @@ var _ParaCore = class _ParaCore {
2255
2422
  }
2256
2423
  /**
2257
2424
  * Creates a new user.
2425
+ * @deprecated
2258
2426
  * @param {Object} opts the options object
2259
2427
  * @param {string} opts.email the email to use.
2260
2428
  */
@@ -2270,6 +2438,7 @@ var _ParaCore = class _ParaCore {
2270
2438
  }
2271
2439
  /**
2272
2440
  * Creates a new user with a phone number.
2441
+ * @deprecated
2273
2442
  * @param {Object} opts the options object
2274
2443
  * @param {string} opts.phone - the phone number to use for creating the user.
2275
2444
  * @param {string} opts.countryCode - the country code to use for creating the user.
@@ -2284,6 +2453,7 @@ var _ParaCore = class _ParaCore {
2284
2453
  }
2285
2454
  /**
2286
2455
  * Logs in or creates a new user using an external wallet address.
2456
+ * @deprecated
2287
2457
  * @param {Object} opts the options object
2288
2458
  * @param {string} opts.address the external wallet address to use for identification.
2289
2459
  * @param {WalletType} opts.type type of external wallet to use for identification.
@@ -2306,6 +2476,7 @@ var _ParaCore = class _ParaCore {
2306
2476
  }
2307
2477
  /**
2308
2478
  * Passes the email code obtained from the user for verification.
2479
+ * @deprecated
2309
2480
  * @param {Object} opts the options object
2310
2481
  * @param {string} verificationCode the six-digit code to check
2311
2482
  * @returns {string} the web auth url for creating a new credential
@@ -2316,6 +2487,7 @@ var _ParaCore = class _ParaCore {
2316
2487
  return this.getSetUpBiometricsURL();
2317
2488
  });
2318
2489
  }
2490
+ /** @deprecated */
2319
2491
  verifyExternalWallet(_0) {
2320
2492
  return __async(this, arguments, function* ({
2321
2493
  address,
@@ -2324,11 +2496,12 @@ var _ParaCore = class _ParaCore {
2324
2496
  cosmosSigner
2325
2497
  }) {
2326
2498
  yield this.ctx.client.verifyExternalWallet(this.userId, { address, signedMessage, cosmosPublicKeyHex, cosmosSigner });
2327
- return this.getSetUpBiometricsURL({ authType: __privateGet(this, _authInfo).authType });
2499
+ return this.getSetUpBiometricsURL();
2328
2500
  });
2329
2501
  }
2330
2502
  /**
2331
2503
  * Passes the phone code obtained from the user for verification.
2504
+ * @deprecated
2332
2505
  * @param {Object} opts the options object
2333
2506
  * @param {string} verificationCode the six-digit code to check
2334
2507
  * @returns {string} the web auth url for creating a new credential
@@ -2342,6 +2515,7 @@ var _ParaCore = class _ParaCore {
2342
2515
  /**
2343
2516
  * Validates the response received from an attempted Telegram login for authenticity, then
2344
2517
  * creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
2518
+ * @deprecated
2345
2519
  * @param authResponse - the response JSON object received from the Telegram widget.
2346
2520
  * @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
2347
2521
  */
@@ -2372,6 +2546,7 @@ var _ParaCore = class _ParaCore {
2372
2546
  }
2373
2547
  /**
2374
2548
  * Performs 2FA verification.
2549
+ * @deprecated
2375
2550
  * @param {Object} opts the options object
2376
2551
  * @param {string} opts.email the email to use for performing a 2FA verification.
2377
2552
  * @param {string} opts.verificationCode the verification code to received via 2FA.
@@ -2390,6 +2565,7 @@ var _ParaCore = class _ParaCore {
2390
2565
  }
2391
2566
  /**
2392
2567
  * Performs 2FA verification.
2568
+ * @deprecated
2393
2569
  * @param {Object} opts the options object
2394
2570
  * @param {string} opts.phone the phone number
2395
2571
  * @param {string} opts.countryCode - the country code
@@ -2412,6 +2588,7 @@ var _ParaCore = class _ParaCore {
2412
2588
  }
2413
2589
  /**
2414
2590
  * Sets up two-factor authentication for the current user.
2591
+ * @deprecated
2415
2592
  * @returns {string} uri - uri to use for setting up 2FA
2416
2593
  * */
2417
2594
  setup2FA() {
@@ -2424,6 +2601,7 @@ var _ParaCore = class _ParaCore {
2424
2601
  }
2425
2602
  /**
2426
2603
  * Enables 2FA.
2604
+ * @deprecated
2427
2605
  * @param {Object} opts the options object
2428
2606
  * @param {string} opts.verificationCode - the verification code received via 2FA.
2429
2607
  */
@@ -2434,6 +2612,7 @@ var _ParaCore = class _ParaCore {
2434
2612
  }
2435
2613
  /**
2436
2614
  * Determines if 2FA has been set up.
2615
+ * @deprecated
2437
2616
  * @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
2438
2617
  */
2439
2618
  check2FAStatus() {
@@ -2459,6 +2638,7 @@ var _ParaCore = class _ParaCore {
2459
2638
  }
2460
2639
  /**
2461
2640
  * Resend a verification SMS for the current user.
2641
+ * @deprecated
2462
2642
  */
2463
2643
  resendVerificationCodeByPhone() {
2464
2644
  return __async(this, null, function* () {
@@ -2469,6 +2649,7 @@ var _ParaCore = class _ParaCore {
2469
2649
  }
2470
2650
  /**
2471
2651
  * Returns a URL for setting up a new WebAuth passkey.
2652
+ * @deprecated
2472
2653
  * @param {Object} opts the options object
2473
2654
  * @param {string} opts.authType - the auth type to use
2474
2655
  * @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
@@ -2493,6 +2674,7 @@ var _ParaCore = class _ParaCore {
2493
2674
  }
2494
2675
  /**
2495
2676
  * Returns a URL for setting up a new WebAuth passkey for a phone number.
2677
+ * @deprecated
2496
2678
  * @param {Object} opts the options object
2497
2679
  * @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
2498
2680
  * @returns {string} the URL
@@ -2515,6 +2697,7 @@ var _ParaCore = class _ParaCore {
2515
2697
  }
2516
2698
  /**
2517
2699
  * Returns a URL for setting up a new password.
2700
+ * @deprecated
2518
2701
  * @param {Object} opts the options object
2519
2702
  * @param {string} opts.authType - the auth type to use
2520
2703
  * @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
@@ -2565,6 +2748,7 @@ var _ParaCore = class _ParaCore {
2565
2748
  return isSessionActive && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true);
2566
2749
  });
2567
2750
  }
2751
+ /** @deprecated */
2568
2752
  supportedAuthMethods(auth) {
2569
2753
  return __async(this, null, function* () {
2570
2754
  const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
@@ -2584,16 +2768,18 @@ var _ParaCore = class _ParaCore {
2584
2768
  }
2585
2769
  /**
2586
2770
  * Get hints associated with the users stored biometrics.
2771
+ * @deprecated
2587
2772
  * @returns Array containing useragents and AAGuids for stored biometrics
2588
2773
  */
2589
2774
  getUserBiometricLocationHints() {
2590
2775
  return __async(this, null, function* () {
2591
- const auth = __privateMethod(this, _ParaCore_instances, assertIsAuthSet_fn).call(this);
2776
+ const { auth } = this.assertIsAuthSet();
2592
2777
  return yield this.ctx.client.getBiometricLocationHints(auth);
2593
2778
  });
2594
2779
  }
2595
2780
  /**
2596
2781
  * Initiates a login.
2782
+ * @deprecated
2597
2783
  * @param {Object} opts the options object
2598
2784
  * @param {String} opts.email - the email to login with
2599
2785
  * @param {boolean} opts.useShortURL - whether to shorten the link
@@ -2624,6 +2810,7 @@ var _ParaCore = class _ParaCore {
2624
2810
  }
2625
2811
  /**
2626
2812
  * Initiates a login.
2813
+ * @deprecated
2627
2814
  * @param email - the email to login with
2628
2815
  * @returns - a set of supported auth methods for the user
2629
2816
  **/
@@ -2645,6 +2832,7 @@ var _ParaCore = class _ParaCore {
2645
2832
  }
2646
2833
  /**
2647
2834
  * Initiates a login.
2835
+ * @deprecated
2648
2836
  * @param opts the options object
2649
2837
  * @param opts.phone the phone number
2650
2838
  * @param opts.countryCode the country code
@@ -2675,6 +2863,7 @@ var _ParaCore = class _ParaCore {
2675
2863
  });
2676
2864
  }
2677
2865
  /**
2866
+ * @deprecated
2678
2867
  * Waits for the session to be active.
2679
2868
  **/
2680
2869
  waitForAccountCreation() {
@@ -2704,13 +2893,16 @@ var _ParaCore = class _ParaCore {
2704
2893
  return false;
2705
2894
  });
2706
2895
  }
2896
+ /**
2897
+ * @deprecated
2898
+ */
2707
2899
  waitForPasskeyAndCreateWallet() {
2708
2900
  return __async(this, arguments, function* ({
2709
2901
  popupWindow
2710
2902
  } = {}) {
2711
2903
  yield this.waitForAccountCreation({ popupWindow });
2712
2904
  const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2713
- const pregenWallets = yield this.getPregenWallets();
2905
+ const pregenWallets = yield this.getPregenWalletsV2();
2714
2906
  let recoverySecret, walletIds = {};
2715
2907
  if (pregenWallets.length > 0) {
2716
2908
  recoverySecret = yield this.claimPregenWallets();
@@ -2732,6 +2924,7 @@ var _ParaCore = class _ParaCore {
2732
2924
  /**
2733
2925
  * Initiates a Farcaster login attempt and return the URI for the user to connect.
2734
2926
  * You can create a QR code with this URI that works with Farcaster's mobile app.
2927
+ * @deprecated
2735
2928
  * @return {string} the Farcaster connect URI
2736
2929
  */
2737
2930
  getFarcasterConnectURL() {
@@ -2747,6 +2940,7 @@ var _ParaCore = class _ParaCore {
2747
2940
  /**
2748
2941
  * Awaits the response from a user's attempt to log in with Farcaster.
2749
2942
  * If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
2943
+ * @deprecated
2750
2944
  * @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
2751
2945
  */
2752
2946
  waitForFarcasterStatus() {
@@ -2778,7 +2972,7 @@ var _ParaCore = class _ParaCore {
2778
2972
  }
2779
2973
  /**
2780
2974
  * Generates a URL for the user to log in with OAuth using a desire method.
2781
- *
2975
+ * @deprecated
2782
2976
  * @param {Object} opts the options object
2783
2977
  * @param {OAuthMethod} opts.method the third-party service to use for OAuth.
2784
2978
  * @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
@@ -2802,7 +2996,7 @@ var _ParaCore = class _ParaCore {
2802
2996
  /**
2803
2997
  * Awaits the response from a user's attempt to log in with OAuth.
2804
2998
  * If successful, this returns the user's email address and indicates whether the user already exists.
2805
- *
2999
+ * @deprecated
2806
3000
  * @param {Object} opts the options object.
2807
3001
  * @param {Window} [opts.popupWindow] the popup window being used for login.
2808
3002
  * @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
@@ -2840,7 +3034,7 @@ var _ParaCore = class _ParaCore {
2840
3034
  }
2841
3035
  /**
2842
3036
  * Waits for the session to be active and sets up the user.
2843
- *
3037
+ * @deprecated
2844
3038
  * @param {Object} opts the options object
2845
3039
  * @param {Window} [opts.popupWindow] the popup window being used for login.
2846
3040
  * @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
@@ -2913,7 +3107,9 @@ var _ParaCore = class _ParaCore {
2913
3107
  * @returns a URL for the user to reauthenticate.
2914
3108
  **/
2915
3109
  refreshSession() {
2916
- return __async(this, arguments, function* ({ shouldOpenPopup = false } = {}) {
3110
+ return __async(this, arguments, function* ({
3111
+ shouldOpenPopup = false
3112
+ } = {}) {
2917
3113
  const { sessionId } = yield this.touchSession(true);
2918
3114
  if (!this.loginEncryptionKeyPair) {
2919
3115
  yield this.setLoginEncryptionKeyPair();
@@ -3058,7 +3254,7 @@ var _ParaCore = class _ParaCore {
3058
3254
  break;
3059
3255
  }
3060
3256
  ++maxPolls;
3061
- const res = yield this.getPregenWallets();
3257
+ const res = yield this.getPregenWalletsV2();
3062
3258
  const wallet = res.find((w) => w.id === walletId);
3063
3259
  if (wallet && wallet.address) {
3064
3260
  return;
@@ -3212,7 +3408,7 @@ var _ParaCore = class _ParaCore {
3212
3408
  });
3213
3409
  }
3214
3410
  yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
3215
- [walletType]: [...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId]
3411
+ [walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
3216
3412
  }));
3217
3413
  const walletNoSigner = __spreadValues({}, wallet);
3218
3414
  delete walletNoSigner.signer;
@@ -3225,7 +3421,7 @@ var _ParaCore = class _ParaCore {
3225
3421
  }
3226
3422
  /**
3227
3423
  * Creates a new pregenerated wallet.
3228
- *
3424
+ * @deprecated
3229
3425
  * @param {Object} opts the options object.
3230
3426
  * @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
3231
3427
  * @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
@@ -3286,6 +3482,7 @@ var _ParaCore = class _ParaCore {
3286
3482
  * Creates new pregenerated wallets for each desired type.
3287
3483
  * If no types are provided, this method will create one for each of the non-optional types
3288
3484
  * specified in the instance's `supportedWalletTypes` array that are not already present.
3485
+ * @deprecated
3289
3486
  * @param {Object} opts the options object.
3290
3487
  * @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
3291
3488
  * @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
@@ -3308,7 +3505,7 @@ var _ParaCore = class _ParaCore {
3308
3505
  }
3309
3506
  /**
3310
3507
  * Claims a pregenerated wallet.
3311
- *
3508
+ * @deprecated
3312
3509
  * @param {Object} opts the options object.
3313
3510
  * @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
3314
3511
  * @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
@@ -3376,6 +3573,7 @@ var _ParaCore = class _ParaCore {
3376
3573
  }
3377
3574
  /**
3378
3575
  * Updates the identifier for a pregen wallet.
3576
+ * @deprecated
3379
3577
  * @param {Object} opts the options object.
3380
3578
  * @param {string} opts.walletId the pregen wallet ID
3381
3579
  * @param {string} opts.newPregenIdentifier the new identtifier
@@ -3403,6 +3601,7 @@ var _ParaCore = class _ParaCore {
3403
3601
  }
3404
3602
  /**
3405
3603
  * Checks if a pregen Wallet exists for the given identifier with the current partner.
3604
+ * @deprecated
3406
3605
  * @param {Object} opts the options object.
3407
3606
  * @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
3408
3607
  * @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
@@ -3424,6 +3623,7 @@ var _ParaCore = class _ParaCore {
3424
3623
  }
3425
3624
  /**
3426
3625
  * Get pregen wallets for the given identifier.
3626
+ * @deprecated
3427
3627
  * @param {Object} opts the options object.
3428
3628
  * @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet
3429
3629
  * @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
@@ -3528,7 +3728,10 @@ var _ParaCore = class _ParaCore {
3528
3728
  walletId,
3529
3729
  messageBase64,
3530
3730
  timeoutMs = 3e4,
3531
- cosmosSignDocBase64
3731
+ cosmosSignDocBase64,
3732
+ isCanceled = () => false,
3733
+ onCancel,
3734
+ onPoll
3532
3735
  }) {
3533
3736
  this.assertIsValidWalletId(walletId);
3534
3737
  const wallet = this.wallets[walletId];
@@ -3547,11 +3750,12 @@ var _ParaCore = class _ParaCore {
3547
3750
  dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
3548
3751
  return signRes;
3549
3752
  }
3550
- yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
3551
3753
  while (true) {
3552
- if (Date.now() - timeStart > timeoutMs) {
3754
+ if (isCanceled() || Date.now() - timeStart > timeoutMs) {
3755
+ onCancel == null ? void 0 : onCancel();
3553
3756
  break;
3554
3757
  }
3758
+ yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
3555
3759
  try {
3556
3760
  yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
3557
3761
  } catch (err) {
@@ -3561,7 +3765,8 @@ var _ParaCore = class _ParaCore {
3561
3765
  }
3562
3766
  signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
3563
3767
  if (signRes.pendingTransactionId) {
3564
- yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
3768
+ onPoll == null ? void 0 : onPoll();
3769
+ continue;
3565
3770
  } else {
3566
3771
  break;
3567
3772
  }
@@ -3626,7 +3831,10 @@ var _ParaCore = class _ParaCore {
3626
3831
  walletId,
3627
3832
  rlpEncodedTxBase64,
3628
3833
  chainId,
3629
- timeoutMs = 3e4
3834
+ timeoutMs = 3e4,
3835
+ isCanceled = () => false,
3836
+ onCancel,
3837
+ onPoll
3630
3838
  }) {
3631
3839
  this.assertIsValidWalletId(walletId);
3632
3840
  const wallet = this.wallets[walletId];
@@ -3654,11 +3862,12 @@ var _ParaCore = class _ParaCore {
3654
3862
  dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
3655
3863
  return signRes;
3656
3864
  }
3657
- yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
3658
3865
  while (true) {
3659
- if (Date.now() - timeStart > timeoutMs) {
3866
+ if (isCanceled() || Date.now() - timeStart > timeoutMs) {
3867
+ onCancel == null ? void 0 : onCancel();
3660
3868
  break;
3661
3869
  }
3870
+ yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
3662
3871
  try {
3663
3872
  yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
3664
3873
  } catch (err) {
@@ -3677,7 +3886,8 @@ var _ParaCore = class _ParaCore {
3677
3886
  wallet.scheme === WalletScheme2.DKLS
3678
3887
  );
3679
3888
  if (signRes.pendingTransactionId) {
3680
- yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
3889
+ onPoll == null ? void 0 : onPoll();
3890
+ continue;
3681
3891
  } else {
3682
3892
  break;
3683
3893
  }
@@ -3825,18 +4035,33 @@ var _ParaCore = class _ParaCore {
3825
4035
  this.persistSessionCookie(sessionInfo.sessionCookie);
3826
4036
  });
3827
4037
  }
4038
+ /**
4039
+ * @deprecated
4040
+ */
3828
4041
  exitAccountCreation() {
3829
4042
  this.isAwaitingAccountCreation = false;
3830
4043
  }
4044
+ /**
4045
+ * @deprecated
4046
+ */
3831
4047
  exitLogin() {
3832
4048
  this.isAwaitingLogin = false;
3833
4049
  }
4050
+ /**
4051
+ * @deprecated
4052
+ */
3834
4053
  exitFarcaster() {
3835
4054
  this.isAwaitingFarcaster = false;
3836
4055
  }
4056
+ /**
4057
+ * @deprecated
4058
+ */
3837
4059
  exitOAuth() {
3838
4060
  this.isAwaitingOAuth = false;
3839
4061
  }
4062
+ /**
4063
+ * @deprecated
4064
+ */
3840
4065
  exitLoops() {
3841
4066
  this.exitAccountCreation();
3842
4067
  this.exitLogin();
@@ -3881,6 +4106,7 @@ var _ParaCore = class _ParaCore {
3881
4106
  dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
3882
4107
  });
3883
4108
  }
4109
+ /** @deprecated */
3884
4110
  getSupportedCreateAuthMethods() {
3885
4111
  return __async(this, null, function* () {
3886
4112
  const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
@@ -3938,45 +4164,682 @@ var _ParaCore = class _ParaCore {
3938
4164
  };
3939
4165
  return `Para ${JSON.stringify(obj, null, 2)}`;
3940
4166
  }
3941
- };
3942
- _authInfo = new WeakMap();
3943
- _partner = new WeakMap();
3944
- _ParaCore_instances = new WeakSet();
3945
- assertPartner_fn = function() {
3946
- return __async(this, null, function* () {
3947
- var _a, _b;
3948
- if (!__privateGet(this, _partner)) {
3949
- yield this.touchSession();
3950
- }
3951
- if (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== __privateGet(this, _partner).cosmosPrefix) {
3952
- this.ctx.cosmosPrefix = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix;
3953
- }
3954
- return __privateGet(this, _partner);
3955
- });
3956
- };
3957
- toAuthInfo_fn = function({
3958
- email,
3959
- phone,
3960
- countryCode,
3961
- farcasterUsername,
3962
- telegramUserId,
3963
- externalWalletAddress
3964
- }) {
3965
- let auth;
3966
- switch (true) {
3967
- case !!email:
3968
- auth = { email };
3969
- break;
3970
- case !!phone:
3971
- {
3972
- const validPhone = formatPhoneNumber(phone, countryCode);
3973
- if (validPhone) auth = { phone: formatPhoneNumber(phone, countryCode) };
4167
+ /** NEW METHODS */
4168
+ getNewCredentialAndUrl(_0) {
4169
+ return __async(this, arguments, function* ({
4170
+ authMethod = "PASSKEY",
4171
+ isForNewDevice = false,
4172
+ portalTheme,
4173
+ shorten = false
4174
+ }) {
4175
+ this.assertIsAuthSet();
4176
+ let credentialId, urlType;
4177
+ switch (authMethod) {
4178
+ case "PASSKEY":
4179
+ ({
4180
+ data: { id: credentialId }
4181
+ } = yield this.ctx.client.addSessionPublicKey(this.userId, {
4182
+ status: PublicKeyStatus.PENDING,
4183
+ type: PublicKeyType.WEB
4184
+ }));
4185
+ urlType = "createAuth";
4186
+ break;
4187
+ case "PASSWORD":
4188
+ ({
4189
+ data: { id: credentialId }
4190
+ } = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
4191
+ status: PasswordStatus.PENDING
4192
+ }));
4193
+ urlType = "createPassword";
4194
+ break;
3974
4195
  }
3975
- break;
3976
- case !!farcasterUsername:
3977
- auth = { farcasterUsername };
3978
- break;
3979
- case !!telegramUserId:
4196
+ const url = yield this.constructPortalUrlV2(urlType, {
4197
+ isForNewDevice,
4198
+ pathId: credentialId,
4199
+ portalTheme,
4200
+ shorten
4201
+ });
4202
+ return { credentialId, url };
4203
+ });
4204
+ }
4205
+ getLoginUrlV2(_0) {
4206
+ return __async(this, arguments, function* ({
4207
+ authMethod = "PASSKEY",
4208
+ shorten = false,
4209
+ portalTheme,
4210
+ sessionId
4211
+ }) {
4212
+ if (!sessionId) {
4213
+ sessionId = (yield this.touchSession()).sessionLookupId;
4214
+ }
4215
+ this.assertIsAuthSet();
4216
+ let urlType;
4217
+ switch (authMethod) {
4218
+ case "PASSKEY":
4219
+ urlType = "loginAuth";
4220
+ break;
4221
+ case "PASSWORD":
4222
+ urlType = "loginPassword";
4223
+ break;
4224
+ default:
4225
+ throw new Error(`invalid authentication method: '${authMethod}'`);
4226
+ }
4227
+ return this.constructPortalUrlV2(urlType, {
4228
+ sessionId,
4229
+ shorten,
4230
+ portalTheme
4231
+ });
4232
+ });
4233
+ }
4234
+ getOAuthUrlV2(_0) {
4235
+ return __async(this, arguments, function* ({ method, deeplinkUrl }) {
4236
+ yield this.logout();
4237
+ const { sessionLookupId } = yield this.touchSession(true);
4238
+ return constructUrl({
4239
+ base: getBaseOAuthUrl(this.ctx.env),
4240
+ path: `/auth/${method}`,
4241
+ params: {
4242
+ apiKey: this.ctx.apiKey,
4243
+ sessionLookupId,
4244
+ deeplinkUrl
4245
+ }
4246
+ });
4247
+ });
4248
+ }
4249
+ signUpOrLogInV2(_k) {
4250
+ return __async(this, null, function* () {
4251
+ var _l = _k, {
4252
+ auth
4253
+ } = _l, urlOptions = __objRest(_l, [
4254
+ "auth"
4255
+ ]);
4256
+ const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
4257
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
4258
+ });
4259
+ }
4260
+ verifyNewAccountV2(_m) {
4261
+ return __async(this, null, function* () {
4262
+ var _n = _m, {
4263
+ verificationCode
4264
+ } = _n, urlOptions = __objRest(_n, [
4265
+ "verificationCode"
4266
+ ]);
4267
+ this.assertIsAuthSet(["email", "phone"]);
4268
+ const userId = this.assertUserId();
4269
+ const serverAuthState = yield this.ctx.client.verifyNewAccount(userId, {
4270
+ verificationCode
4271
+ });
4272
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
4273
+ });
4274
+ }
4275
+ verifyOAuthV2(_o) {
4276
+ return __async(this, null, function* () {
4277
+ var _p = _o, {
4278
+ method,
4279
+ deeplinkUrl,
4280
+ isCanceled = () => false,
4281
+ onCancel,
4282
+ onPoll,
4283
+ onOAuthUrl
4284
+ } = _p, urlOptions = __objRest(_p, [
4285
+ "method",
4286
+ "deeplinkUrl",
4287
+ "isCanceled",
4288
+ "onCancel",
4289
+ "onPoll",
4290
+ "onOAuthUrl"
4291
+ ]);
4292
+ const sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
4293
+ const oAuthUrl = constructUrl({
4294
+ base: getBaseOAuthUrl(this.ctx.env),
4295
+ path: `/auth/${method}`,
4296
+ params: {
4297
+ apiKey: this.ctx.apiKey,
4298
+ sessionLookupId,
4299
+ deeplinkUrl
4300
+ }
4301
+ });
4302
+ onOAuthUrl(oAuthUrl);
4303
+ const startedAt = Date.now();
4304
+ return new Promise((resolve, reject) => {
4305
+ (() => __async(this, null, function* () {
4306
+ while (true) {
4307
+ try {
4308
+ if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
4309
+ onCancel == null ? void 0 : onCancel();
4310
+ return reject("canceled");
4311
+ }
4312
+ yield new Promise((_resolve) => setTimeout(_resolve, POLLING_INTERVAL_MS));
4313
+ const serverAuthState = yield this.ctx.client.verifyOAuth();
4314
+ if (isServerAuthState(serverAuthState)) {
4315
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
4316
+ return resolve(authState);
4317
+ }
4318
+ onPoll == null ? void 0 : onPoll();
4319
+ } catch (err) {
4320
+ console.error(err);
4321
+ onPoll == null ? void 0 : onPoll();
4322
+ }
4323
+ }
4324
+ }))();
4325
+ });
4326
+ });
4327
+ }
4328
+ verifyFarcasterV2(_q) {
4329
+ return __async(this, null, function* () {
4330
+ var _r = _q, {
4331
+ isCanceled = () => false,
4332
+ onConnectUri,
4333
+ onCancel,
4334
+ onPoll
4335
+ } = _r, urlOptions = __objRest(_r, [
4336
+ "isCanceled",
4337
+ "onConnectUri",
4338
+ "onCancel",
4339
+ "onPoll"
4340
+ ]);
4341
+ const {
4342
+ data: { connect_uri: connectUri }
4343
+ } = yield this.ctx.client.initializeFarcasterLogin();
4344
+ onConnectUri(connectUri);
4345
+ return new Promise((resolve, reject) => {
4346
+ (() => __async(this, null, function* () {
4347
+ const startedAt = Date.now();
4348
+ while (true) {
4349
+ try {
4350
+ if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
4351
+ onCancel == null ? void 0 : onCancel();
4352
+ return reject("canceled");
4353
+ }
4354
+ yield new Promise((_resolve) => setTimeout(_resolve, POLLING_INTERVAL_MS));
4355
+ const serverAuthState = yield this.ctx.client.getFarcasterAuthStatusV2();
4356
+ if (isServerAuthState(serverAuthState)) {
4357
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
4358
+ return resolve(authState);
4359
+ }
4360
+ onPoll == null ? void 0 : onPoll();
4361
+ } catch (e) {
4362
+ console.error(e);
4363
+ return reject(e);
4364
+ }
4365
+ }
4366
+ }))();
4367
+ });
4368
+ });
4369
+ }
4370
+ /**
4371
+ * Validates the response received from an attempted Telegram login for authenticity, then
4372
+ * creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
4373
+ * @param authResponse - the response JSON object received from the Telegram widget.
4374
+ * @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
4375
+ */
4376
+ verifyTelegramV2(_s) {
4377
+ return __async(this, null, function* () {
4378
+ var _t = _s, {
4379
+ telegramAuthResponse
4380
+ } = _t, urlOptions = __objRest(_t, [
4381
+ "telegramAuthResponse"
4382
+ ]);
4383
+ try {
4384
+ const serverAuthState = yield this.ctx.client.verifyTelegramV2(telegramAuthResponse);
4385
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
4386
+ } catch (e) {
4387
+ throw new Error(e.message);
4388
+ }
4389
+ });
4390
+ }
4391
+ /**
4392
+ * Waits for the session to be active and sets up the user.
4393
+ *
4394
+ * @param {Object} opts the options object
4395
+ * @param {Window} [opts.popupWindow] the popup window being used for login.
4396
+ * @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
4397
+ * @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
4398
+ **/
4399
+ waitForLoginV2() {
4400
+ return __async(this, arguments, function* ({
4401
+ isCanceled = () => false,
4402
+ onCancel,
4403
+ onPoll,
4404
+ skipSessionRefresh = false
4405
+ } = {}) {
4406
+ const startedAt = Date.now();
4407
+ return new Promise((resolve, reject) => {
4408
+ (() => __async(this, null, function* () {
4409
+ var _a;
4410
+ if (!this.isExternalWalletAuth) {
4411
+ this.externalWallets = {};
4412
+ }
4413
+ while (true) {
4414
+ if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
4415
+ dispatchEvent(ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
4416
+ onCancel == null ? void 0 : onCancel();
4417
+ return reject("canceled");
4418
+ }
4419
+ yield new Promise((resolve2) => setTimeout(resolve2, POLLING_INTERVAL_MS));
4420
+ try {
4421
+ let session = yield this.touchSession();
4422
+ if (!session.isAuthenticated) {
4423
+ onPoll == null ? void 0 : onPoll();
4424
+ continue;
4425
+ }
4426
+ session = yield this.userSetupAfterLogin();
4427
+ const needsWallet = (_a = session.needsWallet) != null ? _a : false;
4428
+ if (!needsWallet) {
4429
+ if (this.currentWalletIdsArray.length === 0) {
4430
+ onPoll == null ? void 0 : onPoll();
4431
+ continue;
4432
+ }
4433
+ }
4434
+ const fetchedWallets = yield this.fetchWallets();
4435
+ const tempSharesRes = yield this.getTransmissionKeyShares();
4436
+ if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
4437
+ yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
4438
+ yield this.claimPregenWalletsV2();
4439
+ const resp = {
4440
+ needsWallet: needsWallet || Object.values(this.wallets).length === 0,
4441
+ partnerId: session.partnerId
4442
+ };
4443
+ dispatchEvent(ParaEvent.LOGIN_EVENT, resp);
4444
+ return resolve(resp);
4445
+ }
4446
+ onPoll == null ? void 0 : onPoll();
4447
+ } catch (err) {
4448
+ console.error(err);
4449
+ onPoll == null ? void 0 : onPoll();
4450
+ }
4451
+ }
4452
+ }))();
4453
+ });
4454
+ });
4455
+ }
4456
+ waitForSignupV2(_0) {
4457
+ return __async(this, arguments, function* ({
4458
+ isCanceled = () => false,
4459
+ onCancel,
4460
+ onPoll
4461
+ }) {
4462
+ const startedAt = Date.now();
4463
+ return new Promise((resolve, reject) => {
4464
+ (() => __async(this, null, function* () {
4465
+ yield this.touchSession();
4466
+ if (!this.isExternalWalletAuth) {
4467
+ this.externalWallets = {};
4468
+ }
4469
+ while (true) {
4470
+ try {
4471
+ if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
4472
+ onCancel == null ? void 0 : onCancel();
4473
+ dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, false, "failed to sign up user");
4474
+ return reject("canceled");
4475
+ }
4476
+ yield new Promise((_resolve) => setTimeout(_resolve, POLLING_INTERVAL_MS));
4477
+ if (yield this.isSessionActive()) {
4478
+ dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
4479
+ return resolve(true);
4480
+ }
4481
+ onPoll == null ? void 0 : onPoll();
4482
+ } catch (err) {
4483
+ console.error(err);
4484
+ onPoll == null ? void 0 : onPoll();
4485
+ }
4486
+ }
4487
+ }))();
4488
+ });
4489
+ });
4490
+ }
4491
+ waitForWalletCreationV2() {
4492
+ return __async(this, arguments, function* ({
4493
+ isCanceled = () => false,
4494
+ onCancel
4495
+ } = {}) {
4496
+ yield this.waitForSignupV2({ isCanceled, onCancel });
4497
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
4498
+ const pregenWallets = yield this.getPregenWalletsV2();
4499
+ let recoverySecret, walletIds = {};
4500
+ if (pregenWallets.length > 0) {
4501
+ recoverySecret = yield this.claimPregenWalletsV2();
4502
+ walletIds = supportedWalletTypes.reduce((acc, { type }) => {
4503
+ var _a;
4504
+ return __spreadProps(__spreadValues({}, acc), {
4505
+ [type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
4506
+ });
4507
+ }, {});
4508
+ }
4509
+ const created = yield this.createWalletPerType();
4510
+ recoverySecret = recoverySecret != null ? recoverySecret : created.recoverySecret;
4511
+ walletIds = __spreadValues(__spreadValues({}, walletIds), created.walletIds);
4512
+ const resp = { walletIds, recoverySecret };
4513
+ dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
4514
+ return resp;
4515
+ });
4516
+ }
4517
+ loginExternalWalletV2(_u) {
4518
+ return __async(this, null, function* () {
4519
+ var _v = _u, {
4520
+ externalWallet
4521
+ } = _v, urlOptions = __objRest(_v, [
4522
+ "externalWallet"
4523
+ ]);
4524
+ this.requireApiKey();
4525
+ const serverAuthState = yield this.ctx.client.loginExternalWalletV2({ externalWallet });
4526
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
4527
+ });
4528
+ }
4529
+ verifyExternalWalletV2(_w) {
4530
+ return __async(this, null, function* () {
4531
+ var _x = _w, {
4532
+ externalWallet,
4533
+ signedMessage,
4534
+ cosmosPublicKeyHex,
4535
+ cosmosSigner
4536
+ } = _x, urlOptions = __objRest(_x, [
4537
+ "externalWallet",
4538
+ "signedMessage",
4539
+ "cosmosPublicKeyHex",
4540
+ "cosmosSigner"
4541
+ ]);
4542
+ const serverAuthState = yield this.ctx.client.verifyExternalWalletV2(this.userId, {
4543
+ externalWallet,
4544
+ signedMessage,
4545
+ cosmosPublicKeyHex,
4546
+ cosmosSigner
4547
+ });
4548
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
4549
+ });
4550
+ }
4551
+ /**
4552
+ * Performs 2FA verification.
4553
+ * @param {Object} opts the options object
4554
+ * @param {string} opts.email the email to use for performing a 2FA verification.
4555
+ * @param {string} opts.verificationCode the verification code to received via 2FA.
4556
+ * @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
4557
+ */
4558
+ verify2faV2(_0) {
4559
+ return __async(this, arguments, function* ({ auth, verificationCode }) {
4560
+ const res = yield this.ctx.client.verify2FAV2(auth, verificationCode);
4561
+ return {
4562
+ initiatedAt: res.data.initiatedAt,
4563
+ status: res.data.status,
4564
+ userId: res.data.userId,
4565
+ wallets: res.data.wallets
4566
+ };
4567
+ });
4568
+ }
4569
+ /**
4570
+ * Sets up two-factor authentication for the current user.
4571
+ * @returns {string} uri - uri to use for setting up 2FA
4572
+ * */
4573
+ setup2faV2() {
4574
+ return __async(this, null, function* () {
4575
+ const userId = this.assertUserId();
4576
+ const res = yield this.ctx.client.setup2FAV2(userId);
4577
+ return res;
4578
+ });
4579
+ }
4580
+ /**
4581
+ * Enables 2FA.
4582
+ * @param {Object} opts the options object
4583
+ * @param {string} opts.verificationCode - the verification code received via 2FA.
4584
+ */
4585
+ enable2faV2(_0) {
4586
+ return __async(this, arguments, function* ({ verificationCode }) {
4587
+ const userId = this.assertUserId();
4588
+ yield this.ctx.client.enable2FA(userId, verificationCode);
4589
+ });
4590
+ }
4591
+ /**
4592
+ * Creates a new pregenerated wallet.
4593
+ *
4594
+ * @param {Object} opts the options object.
4595
+ * @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
4596
+ * @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
4597
+ * @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
4598
+ * @returns {Wallet} the created wallet.
4599
+ **/
4600
+ createPregenWalletV2(opts) {
4601
+ return __async(this, null, function* () {
4602
+ var _a, _b;
4603
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
4604
+ const { type: _type = (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type, pregenId } = opts;
4605
+ this.requireApiKey();
4606
+ const walletType = yield this.assertIsValidWalletType(
4607
+ _type != null ? _type : (_b = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
4608
+ );
4609
+ const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
4610
+ let keygenRes;
4611
+ switch (walletType) {
4612
+ case WalletType2.SOLANA:
4613
+ keygenRes = yield this.platformUtils.ed25519PreKeygen(
4614
+ this.ctx,
4615
+ pregenIdentifier,
4616
+ pregenIdentifierType,
4617
+ this.retrieveSessionCookie()
4618
+ );
4619
+ break;
4620
+ default:
4621
+ keygenRes = yield this.platformUtils.preKeygen(
4622
+ this.ctx,
4623
+ void 0,
4624
+ pregenIdentifier,
4625
+ pregenIdentifierType,
4626
+ walletType,
4627
+ null,
4628
+ this.retrieveSessionCookie()
4629
+ );
4630
+ break;
4631
+ }
4632
+ const { signer, walletId } = keygenRes;
4633
+ this.wallets[walletId] = {
4634
+ id: walletId,
4635
+ signer,
4636
+ scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
4637
+ type: walletType,
4638
+ isPregen: true,
4639
+ pregenIdentifier,
4640
+ pregenIdentifierType
4641
+ };
4642
+ yield this.waitForPregenWalletAddress(walletId);
4643
+ yield this.populatePregenWalletAddresses();
4644
+ return this.wallets[walletId];
4645
+ });
4646
+ }
4647
+ /**
4648
+ * Creates new pregenerated wallets for each desired type.
4649
+ * If no types are provided, this method will create one for each of the non-optional types
4650
+ * specified in the instance's `supportedWalletTypes` array that are not already present.
4651
+ * @param {Object} opts the options object.
4652
+ * @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
4653
+ * @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
4654
+ * @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
4655
+ * @returns {Wallet[]} an array containing the created wallets.
4656
+ **/
4657
+ createPregenWalletPerTypeV2(_0) {
4658
+ return __async(this, arguments, function* ({
4659
+ types,
4660
+ pregenId
4661
+ }) {
4662
+ const wallets = [];
4663
+ for (const type of yield this.getTypesToCreate(types)) {
4664
+ const wallet = yield this.createPregenWalletV2({ type, pregenId });
4665
+ wallets.push(wallet);
4666
+ }
4667
+ return wallets;
4668
+ });
4669
+ }
4670
+ /**
4671
+ * Claims a pregenerated wallet.
4672
+ * @param {Object} opts the options object.
4673
+ * @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
4674
+ * @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
4675
+ * @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
4676
+ **/
4677
+ claimPregenWalletsV2() {
4678
+ return __async(this, arguments, function* ({
4679
+ pregenId
4680
+ } = {}) {
4681
+ var _a;
4682
+ this.requireApiKey();
4683
+ const pregenWallets = pregenId ? yield this.getPregenWalletsV2({ pregenId }) : yield this.getPregenWalletsV2();
4684
+ if (pregenWallets.length === 0) {
4685
+ return void 0;
4686
+ }
4687
+ let newRecoverySecret;
4688
+ const { walletIds } = yield this.ctx.client.claimPregenWallets({
4689
+ userId: this.userId,
4690
+ walletIds: pregenWallets.map((w) => w.id)
4691
+ });
4692
+ for (const walletId of walletIds) {
4693
+ const wallet = this.wallets[walletId];
4694
+ let refreshedShare;
4695
+ if (wallet.scheme === WalletScheme2.ED25519) {
4696
+ const distributeRes = yield distributeNewShare({
4697
+ ctx: this.ctx,
4698
+ userId: this.userId,
4699
+ walletId: wallet.id,
4700
+ userShare: this.wallets[wallet.id].signer,
4701
+ emailProps: this.getBackupKitEmailProps(),
4702
+ partnerId: wallet.partnerId
4703
+ });
4704
+ if (distributeRes.length > 0) {
4705
+ newRecoverySecret = distributeRes;
4706
+ }
4707
+ } else {
4708
+ refreshedShare = yield this.refreshShare({
4709
+ walletId: wallet.id,
4710
+ share: this.wallets[wallet.id].signer,
4711
+ oldPartnerId: wallet.partnerId,
4712
+ newPartnerId: wallet.partnerId,
4713
+ redistributeBackupEncryptedShares: true
4714
+ });
4715
+ if (refreshedShare.recoverySecret) {
4716
+ newRecoverySecret = refreshedShare.recoverySecret;
4717
+ }
4718
+ }
4719
+ this.wallets[wallet.id] = __spreadProps(__spreadValues({}, this.wallets[wallet.id]), {
4720
+ signer: (_a = refreshedShare == null ? void 0 : refreshedShare.signer) != null ? _a : wallet.signer,
4721
+ userId: this.userId,
4722
+ pregenIdentifier: void 0,
4723
+ pregenIdentifierType: void 0
4724
+ });
4725
+ const walletNoSigner = __spreadValues({}, this.wallets[wallet.id]);
4726
+ delete walletNoSigner.signer;
4727
+ dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
4728
+ wallet: walletNoSigner,
4729
+ recoverySecret: newRecoverySecret
4730
+ });
4731
+ }
4732
+ yield this.setWallets(this.wallets);
4733
+ return newRecoverySecret;
4734
+ });
4735
+ }
4736
+ /**
4737
+ * Updates the identifier for a pregen wallet.
4738
+ * @param {Object} opts the options object.
4739
+ * @param {string} opts.walletId the pregen wallet ID
4740
+ * @param {string} opts.newPregenIdentifier the new identtifier
4741
+ * @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
4742
+ **/
4743
+ updatePregenWalletIdentifierV2(_0) {
4744
+ return __async(this, arguments, function* ({
4745
+ walletId,
4746
+ newPregenId
4747
+ }) {
4748
+ this.requireApiKey();
4749
+ const [newPregenIdentifierType, newPregenIdentifier] = toPregenTypeAndId(newPregenId);
4750
+ yield this.ctx.client.updatePregenWallet(walletId, {
4751
+ pregenIdentifier: newPregenIdentifier,
4752
+ pregenIdentifierType: newPregenIdentifierType
4753
+ });
4754
+ if (!!this.wallets[walletId]) {
4755
+ this.wallets[walletId] = __spreadProps(__spreadValues({}, this.wallets[walletId]), {
4756
+ pregenIdentifier: newPregenIdentifier,
4757
+ pregenIdentifierType: newPregenIdentifierType
4758
+ });
4759
+ yield this.setWallets(this.wallets);
4760
+ }
4761
+ });
4762
+ }
4763
+ /**
4764
+ * Checks if a pregen Wallet exists for the given identifier with the current partner.
4765
+ * @param {Object} opts the options object.
4766
+ * @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
4767
+ * @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
4768
+ * @returns {boolean} whether the pregen wallet exists
4769
+ **/
4770
+ hasPregenWalletV2(_0) {
4771
+ return __async(this, arguments, function* ({ pregenId }) {
4772
+ this.requireApiKey();
4773
+ const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
4774
+ const wallets = yield this.getPregenWalletsV2({ pregenId });
4775
+ const wallet = wallets.find(
4776
+ (w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType
4777
+ );
4778
+ if (!wallet) {
4779
+ return false;
4780
+ }
4781
+ return true;
4782
+ });
4783
+ }
4784
+ /**
4785
+ * Get pregen wallets for the given identifier.
4786
+ * @param {Object} opts the options object.
4787
+ * @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet
4788
+ * @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
4789
+ * @returns {Promise<WalletEntity[]>} the array of found wallets
4790
+ **/
4791
+ getPregenWalletsV2() {
4792
+ return __async(this, arguments, function* ({
4793
+ pregenId
4794
+ } = {}) {
4795
+ this.requireApiKey();
4796
+ const res = yield this.ctx.client.getPregenWallets(
4797
+ pregenId ? toPregenIds(pregenId) : this.pregenIds,
4798
+ this.isPortal(),
4799
+ this.userId
4800
+ );
4801
+ return res.wallets.filter((w) => this.isWalletSupported(entityToWallet(w)));
4802
+ });
4803
+ }
4804
+ };
4805
+ _authInfo = new WeakMap();
4806
+ _partner = new WeakMap();
4807
+ _ParaCore_instances = new WeakSet();
4808
+ assertPartner_fn = function() {
4809
+ return __async(this, null, function* () {
4810
+ var _a, _b;
4811
+ if (!__privateGet(this, _partner)) {
4812
+ yield this.touchSession();
4813
+ }
4814
+ if (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== __privateGet(this, _partner).cosmosPrefix) {
4815
+ this.ctx.cosmosPrefix = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix;
4816
+ }
4817
+ return __privateGet(this, _partner);
4818
+ });
4819
+ };
4820
+ toAuthInfo_fn = function({
4821
+ email,
4822
+ phone,
4823
+ countryCode,
4824
+ farcasterUsername,
4825
+ telegramUserId,
4826
+ externalWalletAddress
4827
+ }) {
4828
+ let auth;
4829
+ switch (true) {
4830
+ case !!email:
4831
+ auth = { email };
4832
+ break;
4833
+ case !!phone:
4834
+ {
4835
+ const validPhone = formatPhoneNumber(phone, countryCode);
4836
+ if (validPhone) auth = { phone: formatPhoneNumber(phone, countryCode) };
4837
+ }
4838
+ break;
4839
+ case !!farcasterUsername:
4840
+ auth = { farcasterUsername };
4841
+ break;
4842
+ case !!telegramUserId:
3980
4843
  auth = { telegramUserId };
3981
4844
  break;
3982
4845
  case !!externalWalletAddress:
@@ -3996,15 +4859,6 @@ setAuthInfo_fn = function(authInfo) {
3996
4859
  yield this.localStorageRemoveItem(LOCAL_STORAGE_TELEGRAM_USER_ID);
3997
4860
  });
3998
4861
  };
3999
- assertIsAuthSet_fn = function(allowed) {
4000
- if (!__privateGet(this, _authInfo)) {
4001
- throw new Error("auth is not set");
4002
- }
4003
- if (allowed && !allowed.includes(__privateGet(this, _authInfo).authType)) {
4004
- throw new Error(`invalid auth type, expected ${allowed.join(", ")}`);
4005
- }
4006
- return __privateGet(this, _authInfo).auth;
4007
- };
4008
4862
  getPartner_fn = function(partnerId) {
4009
4863
  return __async(this, null, function* () {
4010
4864
  const res = yield this.ctx.client.getPartner(partnerId);
@@ -4012,6 +4866,113 @@ getPartner_fn = function(partnerId) {
4012
4866
  return __privateGet(this, _partner);
4013
4867
  });
4014
4868
  };
4869
+ prepareAuthState_fn = function(_0) {
4870
+ return __async(this, arguments, function* (serverAuthState, opts = {}) {
4871
+ if (!opts.sessionLookupId && serverAuthState.stage === "login") {
4872
+ opts.sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
4873
+ }
4874
+ const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
4875
+ const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), Object.fromEntries(
4876
+ Object.entries({
4877
+ displayName,
4878
+ pfpUrl,
4879
+ username,
4880
+ externalWallet
4881
+ }).filter(([_, v]) => !!v)
4882
+ ));
4883
+ yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
4884
+ yield this.assertIsAuthSet();
4885
+ if (!!externalWallet) {
4886
+ yield this.setExternalWallet(externalWallet);
4887
+ }
4888
+ if (!!userId) {
4889
+ yield this.setUserId(userId);
4890
+ }
4891
+ let authState;
4892
+ switch (serverAuthState.stage) {
4893
+ case "verify":
4894
+ authState = serverAuthState;
4895
+ break;
4896
+ case "login":
4897
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
4898
+ break;
4899
+ case "signup":
4900
+ authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
4901
+ break;
4902
+ }
4903
+ return authState;
4904
+ });
4905
+ };
4906
+ prepareLogin_fn = function() {
4907
+ return __async(this, null, function* () {
4908
+ yield this.logout();
4909
+ const { sessionLookupId } = yield this.touchSession(true);
4910
+ if (!this.loginEncryptionKeyPair) {
4911
+ yield this.setLoginEncryptionKeyPair();
4912
+ }
4913
+ return sessionLookupId;
4914
+ });
4915
+ };
4916
+ prepareLoginState_fn = function(_0, _1) {
4917
+ return __async(this, arguments, function* (loginState, {
4918
+ useShortUrls: shorten = false,
4919
+ portalTheme,
4920
+ sessionLookupId
4921
+ }) {
4922
+ const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
4923
+ return __spreadValues(__spreadValues(__spreadValues({}, authState), !this.isNativePasskey && loginAuthMethods.includes(AuthMethod.PASSKEY) ? {
4924
+ passkeyUrl: yield this.getLoginUrlV2({ sessionId: sessionLookupId, shorten, portalTheme }),
4925
+ passkeyKnownDeviceUrl: yield this.constructPortalUrlV2("loginAuth", {
4926
+ sessionId: sessionLookupId,
4927
+ newDevice: {
4928
+ sessionId: sessionLookupId,
4929
+ encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair)
4930
+ },
4931
+ shorten,
4932
+ portalTheme
4933
+ })
4934
+ } : {}), loginAuthMethods.includes(AuthMethod.PASSWORD) ? {
4935
+ passwordUrl: yield this.constructPortalUrlV2("loginPassword", {
4936
+ sessionId: sessionLookupId,
4937
+ shorten,
4938
+ portalTheme
4939
+ })
4940
+ } : {});
4941
+ });
4942
+ };
4943
+ prepareSignUpState_fn = function(_0, _1) {
4944
+ return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
4945
+ const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
4946
+ const [isPasskey, isPassword] = [
4947
+ signupAuthMethods.includes(AuthMethod.PASSKEY),
4948
+ signupAuthMethods.includes(AuthMethod.PASSWORD)
4949
+ ];
4950
+ if (!isPasskey && !isPassword) {
4951
+ throw new Error(
4952
+ "No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or passwords in your Developer Portal settings."
4953
+ );
4954
+ }
4955
+ const signupState = authState;
4956
+ if (isPasskey) {
4957
+ const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
4958
+ authMethod: "PASSKEY",
4959
+ shorten
4960
+ });
4961
+ signupState.passkeyUrl = passkeyUrl;
4962
+ signupState.passkeyId = passkeyId;
4963
+ }
4964
+ if (isPassword) {
4965
+ const { url: passwordUrl, credentialId: passwordId } = yield this.getNewCredentialAndUrl({
4966
+ authMethod: "PASSWORD",
4967
+ portalTheme,
4968
+ shorten
4969
+ });
4970
+ signupState.passwordUrl = passwordUrl;
4971
+ signupState.passwordId = passwordId;
4972
+ }
4973
+ return signupState;
4974
+ });
4975
+ };
4015
4976
  _ParaCore.version = PARA_CORE_VERSION;
4016
4977
  var ParaCore = _ParaCore;
4017
4978
 
@@ -4046,6 +5007,7 @@ export {
4046
5007
  OnRampProvider,
4047
5008
  OnRampPurchaseStatus,
4048
5009
  OnRampPurchaseType,
5010
+ PARA_CORE_METHODS,
4049
5011
  PREGEN_IDENTIFIER_TYPES,
4050
5012
  ParaEvent,
4051
5013
  PopupType,
@@ -4057,6 +5019,7 @@ export {
4057
5019
  TransactionReviewTimeout,
4058
5020
  WalletScheme3 as WalletScheme,
4059
5021
  WalletType3 as WalletType,
5022
+ constructUrl,
4060
5023
  decimalToHex,
4061
5024
  decryptPrivateKey,
4062
5025
  decryptPrivateKeyAndDecryptShare,
@@ -4095,6 +5058,7 @@ export {
4095
5058
  mpcComputationClient_exports as mpcComputationClient,
4096
5059
  paraVersion,
4097
5060
  publicKeyFromHex,
5061
+ shortenUrl,
4098
5062
  toAssetInfoArray,
4099
5063
  retrieve as transmissionUtilsRetrieve,
4100
5064
  truncateAddress,