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

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/cjs/index.js CHANGED
@@ -61,6 +61,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
61
61
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
62
62
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
63
63
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
64
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
64
65
  var __async = (__this, __arguments, generator) => {
65
66
  return new Promise((resolve, reject) => {
66
67
  var fulfilled = (value) => {
@@ -116,12 +117,14 @@ __export(src_exports, {
116
117
  decryptWithKeyPair: () => decryptWithKeyPair,
117
118
  decryptWithPrivateKey: () => decryptWithPrivateKey,
118
119
  default: () => src_default,
120
+ displayPhoneNumber: () => displayPhoneNumber,
119
121
  distributeNewShare: () => distributeNewShare,
120
122
  encodePrivateKeyToPemHex: () => encodePrivateKeyToPemHex,
121
123
  encryptPrivateKey: () => encryptPrivateKey,
122
124
  encryptPrivateKeyWithPassword: () => encryptPrivateKeyWithPassword,
123
125
  encryptWithDerivedPublicKey: () => encryptWithDerivedPublicKey,
124
126
  entityToWallet: () => entityToWallet,
127
+ formatPhoneNumber: () => formatPhoneNumber,
125
128
  getAsymmetricKeyPair: () => getAsymmetricKeyPair,
126
129
  getBaseMPCNetworkUrl: () => getBaseMPCNetworkUrl,
127
130
  getBaseOAuthUrl: () => getBaseOAuthUrl,
@@ -143,10 +146,8 @@ __export(src_exports, {
143
146
  initClient: () => initClient,
144
147
  isWalletSupported: () => isWalletSupported,
145
148
  mpcComputationClient: () => mpcComputationClient_exports,
146
- normalizePhoneNumber: () => normalizePhoneNumber,
147
149
  paraVersion: () => paraVersion,
148
150
  publicKeyFromHex: () => publicKeyFromHex,
149
- stringToPhoneNumber: () => stringToPhoneNumber,
150
151
  toAssetInfoArray: () => toAssetInfoArray,
151
152
  transmissionUtilsRetrieve: () => retrieve,
152
153
  truncateAddress: () => truncateAddress,
@@ -163,6 +164,23 @@ var import_node_forge2 = __toESM(require("node-forge"));
163
164
  var import_base64url = __toESM(require("base64url"));
164
165
  var import_node_forge = __toESM(require("node-forge"));
165
166
 
167
+ // src/utils/autobind.ts
168
+ function autoBind(instance) {
169
+ let proto = instance;
170
+ while (proto && proto !== Object.prototype) {
171
+ for (const key of Object.getOwnPropertyNames(proto)) {
172
+ const value = instance[key];
173
+ if (typeof value === "function" && key !== "constructor") {
174
+ try {
175
+ instance[key] = value.bind(instance);
176
+ } catch (e) {
177
+ }
178
+ }
179
+ }
180
+ proto = Object.getPrototypeOf(proto);
181
+ }
182
+ }
183
+
166
184
  // src/utils/events.ts
167
185
  function dispatchEvent(type, data, error) {
168
186
  typeof window !== "undefined" && !!window.dispatchEvent && window.dispatchEvent(
@@ -175,7 +193,6 @@ var import_encoding = require("@cosmjs/encoding");
175
193
  var import_sha256 = require("@noble/hashes/sha256");
176
194
  var import_ripemd160 = require("@noble/hashes/ripemd160");
177
195
  var import_elliptic = __toESM(require("elliptic"));
178
- var import_libphonenumber_js = __toESM(require("libphonenumber-js"));
179
196
  var secp256k1 = new import_elliptic.default.ec("secp256k1");
180
197
  function hexStringToBase64(hexString) {
181
198
  if (hexString.substring(0, 2) === "0x") {
@@ -232,12 +249,71 @@ function truncateAddress(str, addressType, { prefix = addressType === "COSMOS" ?
232
249
  const headLength = (addressType === "COSMOS" ? prefix.length : addressType === "SOLANA" ? 0 : 2) + 4;
233
250
  return `${str.slice(0, headLength)}...${str.slice(-4)}`;
234
251
  }
235
- function stringToPhoneNumber(str) {
236
- var _a;
237
- return (_a = (0, import_libphonenumber_js.default)(str)) == null ? void 0 : _a.formatInternational().replace(/[^\d+]/g, "");
252
+
253
+ // src/utils/json.ts
254
+ function jsonParse(data, validate) {
255
+ try {
256
+ const res = JSON.parse(data);
257
+ if (validate && !validate(res)) {
258
+ return void 0;
259
+ }
260
+ return res;
261
+ } catch (e) {
262
+ return void 0;
263
+ }
238
264
  }
239
- function normalizePhoneNumber(countryCode, number) {
240
- return stringToPhoneNumber(`${countryCode[0] !== "+" ? "+" : ""}${countryCode}${number}`);
265
+
266
+ // src/constants.ts
267
+ var PARA_CORE_VERSION = '2.0.0-dev.0';
268
+ var PREFIX = "@CAPSULE/";
269
+ var LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
270
+ var LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
271
+ var LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
272
+ var LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
273
+ var LOCAL_STORAGE_FARCASTER_USERNAME = `${PREFIX}farcasterUsername`;
274
+ var LOCAL_STORAGE_TELEGRAM_USER_ID = `${PREFIX}telegramUserId`;
275
+ var LOCAL_STORAGE_USER_ID = `${PREFIX}userId`;
276
+ var LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
277
+ var LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
278
+ var LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
279
+ var LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
280
+ var LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
281
+ var SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
282
+ var POLLING_INTERVAL_MS = 2e3;
283
+ var SHORT_POLLING_INTERVAL_MS = 1e3;
284
+
285
+ // src/utils/listeners.ts
286
+ function storageListener(e) {
287
+ if (!e.url.includes(window.location.origin)) {
288
+ return;
289
+ }
290
+ if (e.key === LOCAL_STORAGE_EXTERNAL_WALLETS) {
291
+ this.updateExternalWalletsFromStorage();
292
+ }
293
+ if (e.key === SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR) {
294
+ this.updateLoginEncryptionKeyPairFromStorage();
295
+ }
296
+ if (e.key === LOCAL_STORAGE_SESSION_COOKIE) {
297
+ this.updateSessionCookieFromStorage();
298
+ }
299
+ if (e.key === LOCAL_STORAGE_CURRENT_WALLET_IDS) {
300
+ this.updateWalletIdsFromStorage();
301
+ }
302
+ if (e.key === LOCAL_STORAGE_WALLETS || e.key === LOCAL_STORAGE_ED25519_WALLETS) {
303
+ this.updateWalletsFromStorage();
304
+ }
305
+ if (e.key === LOCAL_STORAGE_AUTH_INFO) {
306
+ this.updateAuthInfoFromStorage();
307
+ }
308
+ if (e.key === LOCAL_STORAGE_USER_ID) {
309
+ this.updateUserIdFromStorage();
310
+ }
311
+ }
312
+ function setupListeners() {
313
+ if (typeof window !== "undefined" && window.addEventListener && window.location) {
314
+ window.removeEventListener("storage", storageListener.bind(this));
315
+ window.addEventListener("storage", storageListener.bind(this));
316
+ }
241
317
  }
242
318
 
243
319
  // src/utils/onRamps.ts
@@ -276,6 +352,34 @@ function getOnRampAssets(data, {
276
352
  ];
277
353
  }
278
354
 
355
+ // src/utils/phone.ts
356
+ var import_libphonenumber_js = __toESM(require("libphonenumber-js"));
357
+ function formatPhoneNumber(phone, countryCode, { forDisplay = false } = {}) {
358
+ if (!phone) {
359
+ return null;
360
+ }
361
+ phone = phone == null ? void 0 : phone.toString();
362
+ countryCode = countryCode == null ? void 0 : countryCode.toString();
363
+ let sanitizedNumber, parsedNumber;
364
+ if (!!countryCode) {
365
+ sanitizedNumber = phone.replace(/\D/g, "");
366
+ if (/^\+\d+$/.test(countryCode)) {
367
+ countryCode = countryCode.slice(1);
368
+ }
369
+ parsedNumber = (0, import_libphonenumber_js.default)(sanitizedNumber, { defaultCallingCode: countryCode });
370
+ } else {
371
+ sanitizedNumber = `+${phone.replace(/\D/g, "")}`;
372
+ parsedNumber = (0, import_libphonenumber_js.default)(sanitizedNumber);
373
+ }
374
+ if (parsedNumber == null ? void 0 : parsedNumber.isValid()) {
375
+ return forDisplay ? parsedNumber.formatInternational() : parsedNumber.formatInternational().replace(/[^\d+]/g, "");
376
+ }
377
+ return null;
378
+ }
379
+ function displayPhoneNumber(phone, countryCode) {
380
+ return formatPhoneNumber(phone, countryCode, { forDisplay: true });
381
+ }
382
+
279
383
  // src/utils/polling.ts
280
384
  function waitUntilTrue(condition, timeoutMs, intervalMs) {
281
385
  return __async(this, null, function* () {
@@ -453,7 +557,7 @@ function isPregenIdentifierMatch(a, b, type) {
453
557
  case "EMAIL":
454
558
  return a.toLowerCase() === b.toLowerCase();
455
559
  case "PHONE":
456
- return stringToPhoneNumber(a) === stringToPhoneNumber(b);
560
+ return formatPhoneNumber(a) === formatPhoneNumber(b);
457
561
  case "CUSTOM_ID":
458
562
  return a === b;
459
563
  default:
@@ -503,6 +607,9 @@ function migrateWallet(obj) {
503
607
  }
504
608
  return obj;
505
609
  }
610
+ function supportedWalletTypesEq(a, b) {
611
+ return a.length === b.length && a.every(({ type, optional }, index) => b[index].type === type && b[index].optional === optional);
612
+ }
506
613
 
507
614
  // src/cryptography/utils.ts
508
615
  var rsa = import_node_forge.default.pki.rsa;
@@ -1103,68 +1210,6 @@ var TransactionReviewTimeout = class extends Error {
1103
1210
  }
1104
1211
  };
1105
1212
 
1106
- // src/constants.ts
1107
- var PARA_CORE_VERSION = '1.7.0';
1108
- var PREFIX = "@CAPSULE/";
1109
- var LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
1110
- var LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
1111
- var LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
1112
- var LOCAL_STORAGE_FARCASTER_USERNAME = `${PREFIX}farcasterUsername`;
1113
- var LOCAL_STORAGE_TELEGRAM_USER_ID = `${PREFIX}telegramUserId`;
1114
- var LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID = `${PREFIX}externalWalletUserId`;
1115
- var LOCAL_STORAGE_USER_ID = `${PREFIX}userId`;
1116
- var LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
1117
- var LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
1118
- var LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
1119
- var LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
1120
- var LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
1121
- var SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
1122
- var POLLING_INTERVAL_MS = 2e3;
1123
- var SHORT_POLLING_INTERVAL_MS = 1e3;
1124
-
1125
- // src/utils/listeners.ts
1126
- function storageListener(e) {
1127
- if (!e.url.includes(window.location.origin)) {
1128
- return;
1129
- }
1130
- if (e.key === LOCAL_STORAGE_EXTERNAL_WALLETS) {
1131
- this.updateExternalWalletsFromStorage();
1132
- }
1133
- if (e.key === SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR) {
1134
- this.updateLoginEncryptionKeyPairFromStorage();
1135
- }
1136
- if (e.key === LOCAL_STORAGE_SESSION_COOKIE) {
1137
- this.updateSessionCookieFromStorage();
1138
- }
1139
- if (e.key === LOCAL_STORAGE_CURRENT_WALLET_IDS) {
1140
- this.updateWalletIdsFromStorage();
1141
- }
1142
- if (e.key === LOCAL_STORAGE_WALLETS || e.key === LOCAL_STORAGE_ED25519_WALLETS) {
1143
- this.updateWalletsFromStorage();
1144
- }
1145
- if (e.key === LOCAL_STORAGE_EMAIL) {
1146
- this.updateEmailFromStorage();
1147
- }
1148
- if (e.key === LOCAL_STORAGE_COUNTRY_CODE) {
1149
- this.updateCountryCodeFromStorage();
1150
- }
1151
- if (e.key === LOCAL_STORAGE_PHONE) {
1152
- this.updatePhoneFromStorage();
1153
- }
1154
- if (e.key === LOCAL_STORAGE_USER_ID) {
1155
- this.updateUserIdFromStorage();
1156
- }
1157
- if (e.key === LOCAL_STORAGE_TELEGRAM_USER_ID) {
1158
- this.updateTelegramUserIdFromStorage();
1159
- }
1160
- }
1161
- function setupListeners() {
1162
- if (typeof window !== "undefined" && window.addEventListener && window.location) {
1163
- window.removeEventListener("storage", storageListener.bind(this));
1164
- window.addEventListener("storage", storageListener.bind(this));
1165
- }
1166
- }
1167
-
1168
1213
  // src/ParaCore.ts
1169
1214
  if (typeof global !== "undefined") {
1170
1215
  global.Buffer = global.Buffer || import_buffer2.Buffer;
@@ -1176,7 +1221,7 @@ if (typeof global !== "undefined") {
1176
1221
  self.global = self.global || self;
1177
1222
  }
1178
1223
  var { pki, jsbn } = import_node_forge2.default;
1179
- var _supportedWalletTypes, _supportedWalletTypesOpt;
1224
+ var _authInfo, _partner, _ParaCore_instances, assertPartner_fn, toAuthInfo_fn, setAuthInfo_fn, assertIsAuthSet_fn, getPartner_fn;
1180
1225
  var _ParaCore = class _ParaCore {
1181
1226
  /**
1182
1227
  * Constructs a new `ParaCore` instance.
@@ -1186,6 +1231,9 @@ var _ParaCore = class _ParaCore {
1186
1231
  * @returns - A new ParaCore instance.
1187
1232
  */
1188
1233
  constructor(env, apiKey, opts) {
1234
+ __privateAdd(this, _ParaCore_instances);
1235
+ __privateAdd(this, _authInfo);
1236
+ __privateAdd(this, _partner);
1189
1237
  this.isAwaitingAccountCreation = false;
1190
1238
  this.isAwaitingLogin = false;
1191
1239
  this.isAwaitingFarcaster = false;
@@ -1194,14 +1242,15 @@ var _ParaCore = class _ParaCore {
1194
1242
  * 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.
1195
1243
  */
1196
1244
  this.currentWalletIds = {};
1197
- __privateAdd(this, _supportedWalletTypes);
1198
- __privateAdd(this, _supportedWalletTypesOpt);
1199
1245
  this.localStorageGetItem = (key) => {
1200
1246
  return this.platformUtils.localStorage.get(key);
1201
1247
  };
1202
1248
  this.localStorageSetItem = (key, value) => {
1203
1249
  return this.platformUtils.localStorage.set(key, value);
1204
1250
  };
1251
+ this.localStorageRemoveItem = (key) => {
1252
+ return this.platformUtils.localStorage.removeItem(key);
1253
+ };
1205
1254
  this.sessionStorageGetItem = (key) => {
1206
1255
  return this.platformUtils.sessionStorage.get(key);
1207
1256
  };
@@ -1227,32 +1276,35 @@ var _ParaCore = class _ParaCore {
1227
1276
  }
1228
1277
  });
1229
1278
  this.initializeFromStorage = () => {
1230
- this.updateEmailFromStorage();
1231
- this.updateCountryCodeFromStorage();
1232
- this.updatePhoneFromStorage();
1279
+ this.updateExternalWalletsFromStorage();
1280
+ this.updateAuthInfoFromStorage();
1233
1281
  this.updateUserIdFromStorage();
1234
- this.updateTelegramUserIdFromStorage();
1235
1282
  this.updateWalletsFromStorage();
1236
1283
  this.updateWalletIdsFromStorage();
1237
1284
  this.updateSessionCookieFromStorage();
1238
1285
  this.updateLoginEncryptionKeyPairFromStorage();
1239
- this.updateExternalWalletsFromStorage();
1240
1286
  };
1241
- this.updateTelegramUserIdFromStorage = () => {
1242
- this.telegramUserId = this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0;
1287
+ this.updateAuthInfoFromStorage = () => {
1288
+ var _a;
1289
+ const storageAuthInfo = this.localStorageGetItem(LOCAL_STORAGE_AUTH_INFO) || void 0;
1290
+ let authInfo = jsonParse(storageAuthInfo);
1291
+ if (!authInfo) {
1292
+ const authParams = {
1293
+ email: this.localStorageGetItem(LOCAL_STORAGE_EMAIL) || void 0,
1294
+ phone: this.localStorageGetItem(LOCAL_STORAGE_PHONE) || void 0,
1295
+ countryCode: this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE) || void 0,
1296
+ farcasterUsername: this.localStorageGetItem(LOCAL_STORAGE_FARCASTER_USERNAME) || void 0,
1297
+ telegramUserId: this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0,
1298
+ // Using id here since we store the bech32 address for cosmos in the address field of the wallet
1299
+ externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
1300
+ };
1301
+ authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
1302
+ }
1303
+ __privateSet(this, _authInfo, authInfo);
1243
1304
  };
1244
1305
  this.updateUserIdFromStorage = () => {
1245
1306
  this.userId = this.localStorageGetItem(LOCAL_STORAGE_USER_ID) || void 0;
1246
1307
  };
1247
- this.updatePhoneFromStorage = () => {
1248
- this.phone = this.localStorageGetItem(LOCAL_STORAGE_PHONE) || void 0;
1249
- };
1250
- this.updateCountryCodeFromStorage = () => {
1251
- this.countryCode = this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE) || void 0;
1252
- };
1253
- this.updateEmailFromStorage = () => {
1254
- this.email = this.localStorageGetItem(LOCAL_STORAGE_EMAIL) || void 0;
1255
- };
1256
1308
  this.updateWalletsFromStorage = () => __async(this, null, function* () {
1257
1309
  var _a;
1258
1310
  const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
@@ -1282,7 +1334,7 @@ var _ParaCore = class _ParaCore {
1282
1334
  this.updateWalletIdsFromStorage = () => {
1283
1335
  var _a;
1284
1336
  const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
1285
- const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
1337
+ const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
1286
1338
  const fromJson = JSON.parse(_currentWalletIds);
1287
1339
  return Array.isArray(fromJson) ? Object.keys(import_user_management_client5.WalletType).reduce((acc, type) => {
1288
1340
  const wallet = Object.values(this.wallets).find(
@@ -1319,6 +1371,9 @@ var _ParaCore = class _ParaCore {
1319
1371
  * @deprecated alias for `createWalletPerType`
1320
1372
  **/
1321
1373
  this.createWalletPerMissingType = this.createWalletPerType;
1374
+ if (!apiKey) {
1375
+ throw new Error("A Para API key is required.");
1376
+ }
1322
1377
  if (!opts) opts = {};
1323
1378
  let isE2E = false;
1324
1379
  if (env === "E2E") {
@@ -1376,72 +1431,87 @@ var _ParaCore = class _ParaCore {
1376
1431
  useDKLS: opts.useDKLSForCreation || !opts.offloadMPCComputationURL,
1377
1432
  disableWebSockets: !!opts.disableWebSockets,
1378
1433
  wasmOverride: opts.wasmOverride,
1379
- cosmosPrefix: this.cosmosPrefix,
1380
1434
  isE2E
1381
1435
  };
1382
1436
  if (opts.offloadMPCComputationURL) {
1383
1437
  this.ctx.mpcComputationClient = initClient2(opts.offloadMPCComputationURL, opts.disableWorkers);
1384
1438
  }
1385
- try {
1386
- __privateSet(this, _supportedWalletTypes, opts.supportedWalletTypes ? (() => {
1387
- if (Object.values(opts.supportedWalletTypes).every(
1388
- (config) => !!config && typeof config === "object" && config.optional
1389
- )) {
1390
- throw new Error("at least one wallet type must be non-optional");
1391
- }
1392
- if (!Object.keys(opts.supportedWalletTypes).every((type) => Object.values(import_user_management_client5.WalletType).includes(type))) {
1393
- throw new Error("unsupported wallet type");
1394
- }
1395
- __privateSet(this, _supportedWalletTypesOpt, opts.supportedWalletTypes);
1396
- return Object.entries(opts.supportedWalletTypes).reduce((acc, [key, value]) => {
1397
- var _a;
1398
- if (!value) {
1399
- return acc;
1400
- }
1401
- if (key === import_user_management_client5.WalletType.COSMOS && typeof value === "object" && !!value.prefix) {
1402
- this.cosmosPrefix = value.prefix;
1403
- }
1404
- return [...acc, { type: key, optional: value === true ? false : (_a = value.optional) != null ? _a : false }];
1405
- }, []);
1406
- })() : void 0);
1407
- } catch (e) {
1408
- __privateSet(this, _supportedWalletTypes, void 0);
1409
- }
1410
1439
  if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
1411
1440
  return;
1412
1441
  }
1413
1442
  this.initializeFromStorage();
1414
1443
  setupListeners.bind(this)();
1444
+ autoBind(this);
1415
1445
  }
1416
- get isEmail() {
1417
- return !!this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.telegramUserId && !this.externalWalletWithParaAuth;
1446
+ get authInfo() {
1447
+ return __privateGet(this, _authInfo);
1418
1448
  }
1419
- get isPhone() {
1420
- return !!this.phone && !!this.countryCode && !this.email && !this.farcasterUsername && !this.telegramUserId && !this.externalWalletWithParaAuth;
1449
+ get email() {
1450
+ var _a;
1451
+ return (0, import_user_management_client5.isEmail)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.email : void 0;
1421
1452
  }
1422
- get isFarcaster() {
1423
- return !!this.farcasterUsername && !this.email && !this.phone && !this.countryCode && !this.telegramUserId && !this.externalWalletWithParaAuth;
1453
+ get phone() {
1454
+ var _a;
1455
+ return (0, import_user_management_client5.isPhone)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.phone : void 0;
1424
1456
  }
1425
- get isTelegram() {
1426
- return !!this.telegramUserId && !this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.externalWalletWithParaAuth;
1457
+ get farcasterUsername() {
1458
+ var _a;
1459
+ return (0, import_user_management_client5.isFarcaster)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.farcasterUsername : void 0;
1460
+ }
1461
+ get telegramUserId() {
1462
+ var _a;
1463
+ return (0, import_user_management_client5.isTelegram)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.telegramUserId : void 0;
1427
1464
  }
1428
1465
  get externalWalletWithParaAuth() {
1429
1466
  const externalWallets = Object.values(this.externalWallets);
1430
1467
  return externalWallets.find((w) => w.isExternalWithParaAuth);
1431
1468
  }
1469
+ get externalWalletConnectionType() {
1470
+ if (this.isExternalWalletAuth) {
1471
+ return "AUTHENTICATED";
1472
+ } else if (!!Object.keys(this.externalWallets).length) {
1473
+ return "CONNECTION_ONLY";
1474
+ }
1475
+ return "NONE";
1476
+ }
1477
+ get isEmail() {
1478
+ var _a;
1479
+ return (0, import_user_management_client5.isEmail)((_a = this.authInfo) == null ? void 0 : _a.auth);
1480
+ }
1481
+ get isPhone() {
1482
+ var _a;
1483
+ return (0, import_user_management_client5.isPhone)((_a = this.authInfo) == null ? void 0 : _a.auth);
1484
+ }
1485
+ get isFarcaster() {
1486
+ var _a;
1487
+ return (0, import_user_management_client5.isFarcaster)((_a = this.authInfo) == null ? void 0 : _a.auth);
1488
+ }
1489
+ get isTelegram() {
1490
+ var _a;
1491
+ return (0, import_user_management_client5.isTelegram)((_a = this.authInfo) == null ? void 0 : _a.auth);
1492
+ }
1432
1493
  get isExternalWalletAuth() {
1433
- return !!this.externalWalletWithParaAuth && !this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.telegramUserId;
1494
+ var _a;
1495
+ return (0, import_user_management_client5.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth);
1496
+ }
1497
+ get partnerId() {
1498
+ var _a;
1499
+ return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id;
1434
1500
  }
1435
1501
  get currentWalletIdsArray() {
1436
- return this.supportedWalletTypes.reduce((acc, { type }) => {
1437
- var _a;
1438
- return [
1439
- ...acc,
1440
- ...((_a = this.currentWalletIds[type]) != null ? _a : []).map((id) => {
1441
- return [id, type];
1442
- })
1443
- ];
1444
- }, []);
1502
+ var _a, _b;
1503
+ return ((_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
1504
+ (acc, { type }) => {
1505
+ var _a2;
1506
+ return [
1507
+ ...acc,
1508
+ ...((_a2 = this.currentWalletIds[type]) != null ? _a2 : []).map((id) => {
1509
+ return [id, type];
1510
+ })
1511
+ ];
1512
+ },
1513
+ []
1514
+ );
1445
1515
  }
1446
1516
  get currentWalletIdsUnique() {
1447
1517
  return [...new Set(Object.values(this.currentWalletIds).flat())];
@@ -1469,11 +1539,16 @@ var _ParaCore = class _ParaCore {
1469
1539
  return this.currentWalletIdsArray.length > 1;
1470
1540
  }
1471
1541
  get supportedWalletTypes() {
1542
+ var _a, _b;
1543
+ return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
1544
+ }
1545
+ get cosmosPrefix() {
1472
1546
  var _a;
1473
- return (_a = __privateGet(this, _supportedWalletTypes)) != null ? _a : [];
1547
+ return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
1474
1548
  }
1475
1549
  get isWalletTypeEnabled() {
1476
- return this.supportedWalletTypes.reduce((acc, { type }) => {
1550
+ var _a;
1551
+ return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
1477
1552
  return __spreadProps(__spreadValues({}, acc), { [type]: true });
1478
1553
  }, {});
1479
1554
  }
@@ -1522,7 +1597,7 @@ var _ParaCore = class _ParaCore {
1522
1597
  }
1523
1598
  isWalletSupported(wallet) {
1524
1599
  var _a, _b;
1525
- return !__privateGet(this, _supportedWalletTypes) || isWalletSupported((_b = (_a = this.supportedWalletTypes) == null ? void 0 : _a.map(({ type }) => type)) != null ? _b : [], wallet);
1600
+ return !((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = __privateGet(this, _partner).supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
1526
1601
  }
1527
1602
  isWalletOwned(wallet) {
1528
1603
  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;
@@ -1538,7 +1613,7 @@ var _ParaCore = class _ParaCore {
1538
1613
  ));
1539
1614
  }
1540
1615
  isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
1541
- var _a;
1616
+ var _a, _b;
1542
1617
  let error;
1543
1618
  if ((_a = this.externalWallets) == null ? void 0 : _a[walletId]) {
1544
1619
  return true;
@@ -1553,10 +1628,10 @@ var _ParaCore = class _ParaCore {
1553
1628
  } else if (!isOwned && !isUnclaimed) {
1554
1629
  error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
1555
1630
  } else if (!this.isWalletSupported(wallet)) {
1556
- error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} is not supported, supported types are: ${this.supportedWalletTypes.map(({ type }) => type).join(", ")}`;
1631
+ 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(", ")}`;
1557
1632
  } else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
1558
- var _a2, _b;
1559
- return (_b = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b.includes(walletId);
1633
+ var _a2, _b2;
1634
+ return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
1560
1635
  }))) {
1561
1636
  error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
1562
1637
  } else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
@@ -1580,10 +1655,10 @@ var _ParaCore = class _ParaCore {
1580
1655
  * @returns the formatted address
1581
1656
  */
1582
1657
  getDisplayAddress(walletId, options = {}) {
1583
- var _a;
1658
+ var _a, _b, _c, _d;
1584
1659
  if (this.externalWallets[walletId]) {
1585
1660
  const wallet2 = this.externalWallets[walletId];
1586
- return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: this.cosmosPrefix }) : wallet2.address;
1661
+ return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix }) : wallet2.address;
1587
1662
  }
1588
1663
  const wallet = this.findWallet(walletId, options.addressType);
1589
1664
  if (!wallet) {
@@ -1592,13 +1667,13 @@ var _ParaCore = class _ParaCore {
1592
1667
  let str;
1593
1668
  switch (wallet.type) {
1594
1669
  case import_user_management_client5.WalletType.COSMOS:
1595
- str = getCosmosAddress(wallet.publicKey, (_a = this.cosmosPrefix) != null ? _a : "cosmos");
1670
+ str = getCosmosAddress(wallet.publicKey, (_c = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix) != null ? _c : "cosmos");
1596
1671
  break;
1597
1672
  default:
1598
1673
  str = wallet.address;
1599
1674
  break;
1600
1675
  }
1601
- return options.truncate ? truncateAddress(str, wallet.type, { prefix: this.cosmosPrefix }) : str;
1676
+ return options.truncate ? truncateAddress(str, wallet.type, { prefix: (_d = __privateGet(this, _partner)) == null ? void 0 : _d.cosmosPrefix }) : str;
1602
1677
  }
1603
1678
  /**
1604
1679
  * Returns a unique hash for a wallet suitable for use as an identicon seed.
@@ -1623,8 +1698,20 @@ var _ParaCore = class _ParaCore {
1623
1698
  }
1624
1699
  constructPortalUrl(_0) {
1625
1700
  return __async(this, arguments, function* (type, opts = {}) {
1626
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1627
- const base = type === "onRamp" ? getPortalBaseURL(this.ctx) : yield this.getPortalURL(opts.partnerId);
1701
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1702
+ const [isCreate, isLogin, isOnRamp] = [
1703
+ ["createAuth", "createPassword"].includes(type),
1704
+ ["loginAuth", "loginPassword"].includes(type),
1705
+ type === "onRamp"
1706
+ ];
1707
+ let auth;
1708
+ if (isCreate || isLogin) {
1709
+ auth = __privateMethod(this, _ParaCore_instances, assertIsAuthSet_fn).call(this);
1710
+ }
1711
+ if ((isLogin || isOnRamp) && !opts.sessionId) {
1712
+ opts.sessionId = (yield this.touchSession()).sessionLookupId;
1713
+ }
1714
+ const base = isOnRamp ? getPortalBaseURL(this.ctx) : yield this.getPortalURL();
1628
1715
  let path;
1629
1716
  switch (type) {
1630
1717
  case "createPassword": {
@@ -1655,30 +1742,21 @@ var _ParaCore = class _ParaCore {
1655
1742
  throw new Error(`invalid URL type ${type}`);
1656
1743
  }
1657
1744
  }
1658
- const [isCreate, isLogin, isOnRamp] = [
1659
- ["createAuth", "createPassword"].includes(type),
1660
- ["loginAuth", "loginPassword"].includes(type),
1661
- type === "onRamp"
1662
- ];
1663
- const partner = opts.partnerId ? (_a = (yield this.ctx.client.getPartner(opts.partnerId)).data) == null ? void 0 : _a.partner : void 0;
1745
+ const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1664
1746
  const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
1665
1747
  apiKey: this.ctx.apiKey,
1666
- partnerId: opts.partnerId,
1667
- portalFont: ((_b = opts.theme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
1668
- portalBorderRadius: ((_d = opts.theme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
1669
- portalThemeMode: ((_f = opts.theme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
1670
- portalAccentColor: ((_h = opts.theme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
1671
- portalForegroundColor: ((_j = opts.theme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
1672
- portalBackgroundColor: ((_l = opts.theme) == null ? void 0 : _l.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor || ((_m = this.portalTheme) == null ? void 0 : _m.backgroundColor),
1748
+ partnerId: partner.id,
1749
+ portalFont: ((_a = opts.theme) == null ? void 0 : _a.font) || (partner == null ? void 0 : partner.font) || ((_b = this.portalTheme) == null ? void 0 : _b.font),
1750
+ portalBorderRadius: ((_c = opts.theme) == null ? void 0 : _c.borderRadius) || ((_d = this.portalTheme) == null ? void 0 : _d.borderRadius),
1751
+ portalThemeMode: ((_e = opts.theme) == null ? void 0 : _e.mode) || (partner == null ? void 0 : partner.themeMode) || ((_f = this.portalTheme) == null ? void 0 : _f.mode),
1752
+ portalAccentColor: ((_g = opts.theme) == null ? void 0 : _g.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_h = this.portalTheme) == null ? void 0 : _h.accentColor),
1753
+ portalForegroundColor: ((_i = opts.theme) == null ? void 0 : _i.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_j = this.portalTheme) == null ? void 0 : _j.foregroundColor),
1754
+ portalBackgroundColor: ((_k = opts.theme) == null ? void 0 : _k.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor || ((_l = this.portalTheme) == null ? void 0 : _l.backgroundColor),
1673
1755
  portalPrimaryButtonColor: this.portalPrimaryButtonColor,
1674
1756
  portalTextColor: this.portalTextColor,
1675
1757
  portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
1676
- isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0,
1677
- supportedWalletTypes: __privateGet(this, _supportedWalletTypesOpt) ? JSON.stringify(__privateGet(this, _supportedWalletTypesOpt)) : void 0
1678
- }, isCreate || isLogin ? __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, opts.authType === "email" ? { email: this.email } : {}), opts.authType === "phone" ? { phone: this.phone, countryCode: this.countryCode } : {}), opts.authType === "farcaster" ? { farcasterUsername: this.farcasterUsername } : {}), opts.authType === "telegram" ? { telegramUserId: this.telegramUserId } : {}), opts.authType === "externalWallet" ? {
1679
- // Using id here since we store the bech32 address for cosmos in the address field of the wallet
1680
- externalWalletAddress: (_n = this.externalWalletWithParaAuth) == null ? void 0 : _n.id
1681
- } : {}) : {}), isLogin || isOnRamp ? { sessionId: opts.sessionId } : {}), isLogin ? {
1758
+ isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
1759
+ }, auth && (isCreate || isLogin) ? auth : {}), isLogin || isOnRamp ? { sessionId: opts.sessionId } : {}), isLogin ? {
1682
1760
  encryptionKey: opts.loginEncryptionPublicKey,
1683
1761
  newDeviceSessionLookupId: opts.newDeviceSessionId,
1684
1762
  newDeviceEncryptionKey: opts.newDeviceEncryptionKey,
@@ -1691,25 +1769,14 @@ var _ParaCore = class _ParaCore {
1691
1769
  }
1692
1770
  touchSession(regenerate = false) {
1693
1771
  return __async(this, null, function* () {
1694
- const res = yield this.ctx.client.touchSession(regenerate);
1695
- this.setSupportedWalletTypes(res.data.supportedWalletTypes, res.data.cosmosPrefix);
1696
- return res;
1772
+ var _a, _b, _c;
1773
+ const session = yield this.ctx.client.touchSession(regenerate);
1774
+ 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) {
1775
+ yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
1776
+ }
1777
+ return session;
1697
1778
  });
1698
1779
  }
1699
- setSupportedWalletTypes(supportedWalletTypes, cosmosPrefix) {
1700
- if (supportedWalletTypes && !__privateGet(this, _supportedWalletTypes)) {
1701
- __privateSet(this, _supportedWalletTypes, supportedWalletTypes);
1702
- Object.keys(this.currentWalletIds).forEach((type) => {
1703
- var _a;
1704
- if (!((_a = __privateGet(this, _supportedWalletTypes)) == null ? void 0 : _a.some(({ type: supportedType }) => supportedType === type))) {
1705
- delete this.currentWalletIds[type];
1706
- }
1707
- });
1708
- }
1709
- if (cosmosPrefix && !this.cosmosPrefix) {
1710
- this.cosmosPrefix = cosmosPrefix;
1711
- }
1712
- }
1713
1780
  getVerificationEmailProps() {
1714
1781
  return {
1715
1782
  brandColor: this.emailPrimaryColor,
@@ -1739,12 +1806,26 @@ var _ParaCore = class _ParaCore {
1739
1806
  */
1740
1807
  init() {
1741
1808
  return __async(this, null, function* () {
1742
- var _a;
1743
- this.email = (yield this.localStorageGetItem(LOCAL_STORAGE_EMAIL)) || void 0;
1744
- this.countryCode = (yield this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE)) || void 0;
1745
- this.phone = (yield this.localStorageGetItem(LOCAL_STORAGE_PHONE)) || void 0;
1809
+ var _a, _b;
1746
1810
  this.userId = (yield this.localStorageGetItem(LOCAL_STORAGE_USER_ID)) || void 0;
1747
- this.telegramUserId = (yield this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0;
1811
+ const storageAuthInfo = (yield this.localStorageGetItem(LOCAL_STORAGE_AUTH_INFO)) || void 0;
1812
+ const stringExternalWallets = yield this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
1813
+ const _externalWallets = JSON.parse(stringExternalWallets || "{}");
1814
+ yield this.setExternalWallets(_externalWallets);
1815
+ let authInfo = jsonParse(storageAuthInfo);
1816
+ if (!authInfo) {
1817
+ const authParams = {
1818
+ email: (yield this.localStorageGetItem(LOCAL_STORAGE_EMAIL)) || void 0,
1819
+ phone: (yield this.localStorageGetItem(LOCAL_STORAGE_PHONE)) || void 0,
1820
+ countryCode: (yield this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE)) || void 0,
1821
+ farcasterUsername: (yield this.localStorageGetItem(LOCAL_STORAGE_FARCASTER_USERNAME)) || void 0,
1822
+ telegramUserId: (yield this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0,
1823
+ // Using id here since we store the bech32 address for cosmos in the address field of the wallet
1824
+ externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
1825
+ };
1826
+ authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
1827
+ }
1828
+ __privateSet(this, _authInfo, authInfo);
1748
1829
  const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_WALLETS);
1749
1830
  const _wallets = JSON.parse(stringWallets || "{}");
1750
1831
  const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_ED25519_WALLETS);
@@ -1757,7 +1838,7 @@ var _ParaCore = class _ParaCore {
1757
1838
  return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
1758
1839
  }, {}));
1759
1840
  yield this.setWallets(wallets);
1760
- const _currentWalletIds = (_a = yield this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
1841
+ const _currentWalletIds = (_b = yield this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _b : void 0;
1761
1842
  const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
1762
1843
  const fromJson = JSON.parse(_currentWalletIds);
1763
1844
  return Array.isArray(fromJson) ? Object.keys(import_user_management_client5.WalletType).reduce((acc, type) => {
@@ -1776,21 +1857,27 @@ var _ParaCore = class _ParaCore {
1776
1857
  if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
1777
1858
  this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
1778
1859
  }
1779
- const stringExternalWallets = yield this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
1780
- const _externalWallets = JSON.parse(stringExternalWallets || "{}");
1781
- yield this.setExternalWallets(_externalWallets);
1782
1860
  setupListeners.bind(this)();
1783
1861
  yield this.touchSession();
1784
1862
  });
1785
1863
  }
1864
+ setAuth(_0) {
1865
+ return __async(this, arguments, function* (auth, { extras = {}, userId } = {}) {
1866
+ const authInfo = __spreadValues(__spreadValues({}, (0, import_user_management_client5.extractAuthInfo)(auth, { isRequired: true })), extras || {});
1867
+ yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
1868
+ if (!!userId) {
1869
+ yield this.setUserId(userId);
1870
+ }
1871
+ return __privateGet(this, _authInfo);
1872
+ });
1873
+ }
1786
1874
  /**
1787
1875
  * Sets the email associated with the `ParaCore` instance.
1788
1876
  * @param email - Email to set.
1789
1877
  */
1790
1878
  setEmail(email) {
1791
1879
  return __async(this, null, function* () {
1792
- this.email = email;
1793
- yield this.localStorageSetItem(LOCAL_STORAGE_EMAIL, email);
1880
+ yield this.setAuth({ email });
1794
1881
  });
1795
1882
  }
1796
1883
  /**
@@ -1799,8 +1886,7 @@ var _ParaCore = class _ParaCore {
1799
1886
  */
1800
1887
  setTelegramUserId(telegramUserId) {
1801
1888
  return __async(this, null, function* () {
1802
- this.telegramUserId = telegramUserId;
1803
- yield this.localStorageSetItem(LOCAL_STORAGE_TELEGRAM_USER_ID, telegramUserId);
1889
+ yield this.setAuth({ telegramUserId });
1804
1890
  });
1805
1891
  }
1806
1892
  /**
@@ -1810,10 +1896,7 @@ var _ParaCore = class _ParaCore {
1810
1896
  */
1811
1897
  setPhoneNumber(phone, countryCode) {
1812
1898
  return __async(this, null, function* () {
1813
- this.phone = phone;
1814
- this.countryCode = countryCode;
1815
- yield this.localStorageSetItem(LOCAL_STORAGE_PHONE, phone);
1816
- yield this.localStorageSetItem(LOCAL_STORAGE_COUNTRY_CODE, countryCode);
1899
+ yield this.setAuth({ phone: formatPhoneNumber(phone, countryCode) });
1817
1900
  });
1818
1901
  }
1819
1902
  /**
@@ -1822,8 +1905,7 @@ var _ParaCore = class _ParaCore {
1822
1905
  */
1823
1906
  setFarcasterUsername(farcasterUsername) {
1824
1907
  return __async(this, null, function* () {
1825
- this.farcasterUsername = farcasterUsername;
1826
- yield this.localStorageSetItem(LOCAL_STORAGE_FARCASTER_USERNAME, farcasterUsername);
1908
+ yield this.setAuth({ farcasterUsername });
1827
1909
  });
1828
1910
  }
1829
1911
  /**
@@ -1915,22 +1997,12 @@ var _ParaCore = class _ParaCore {
1915
1997
  getEmail() {
1916
1998
  return this.email;
1917
1999
  }
1918
- /**
1919
- * Gets the phone object associated with the `ParaCore` instance.
1920
- * @returns - phone object with phone number and country code associated with the `ParaCore` instance.
1921
- */
1922
- getPhone() {
1923
- return { phone: this.phone, countryCode: this.countryCode };
1924
- }
1925
2000
  /**
1926
2001
  * Gets the formatted phone number associated with the `ParaCore` instance.
1927
2002
  * @returns - formatted phone number associated with the `ParaCore` instance.
1928
2003
  */
1929
2004
  getPhoneNumber() {
1930
- if (!this.phone || !this.countryCode) {
1931
- return void 0;
1932
- }
1933
- return normalizePhoneNumber(this.countryCode, this.phone);
2005
+ return this.phone;
1934
2006
  }
1935
2007
  /**
1936
2008
  * Gets the farcaster username associated with the `ParaCore` instance.
@@ -1959,23 +2031,6 @@ var _ParaCore = class _ParaCore {
1959
2031
  dispatchEvent(ParaEvent.WALLETS_CHANGE_EVENT, null);
1960
2032
  });
1961
2033
  }
1962
- /**
1963
- * Fetches the most recent OAuth account metadata for the signed-in user.
1964
- * If applicable, this will include the user's most recent metadata from their Google, Apple, Facebook, X, Discord, Farcaster, or Telegram account, the last time they signed in to your app.
1965
- * @returns {Promise<AccountMetadata>} the user's account metadata.
1966
- */
1967
- getAccountMetadata() {
1968
- return __async(this, null, function* () {
1969
- if (!(yield this.isSessionActive()) || !this.userId) {
1970
- throw new Error("no signed-in user");
1971
- }
1972
- const {
1973
- data: { partnerId }
1974
- } = yield this.touchSession();
1975
- const { accountMetadata } = yield this.ctx.client.getAccountMetadata(this.userId, partnerId);
1976
- return accountMetadata;
1977
- });
1978
- }
1979
2034
  /**
1980
2035
  * Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
1981
2036
  * If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
@@ -2029,8 +2084,10 @@ var _ParaCore = class _ParaCore {
2029
2084
  }
2030
2085
  findWallet(idOrAddress, overrideType, filter = {}) {
2031
2086
  var _a, _c, _d;
2032
- if (!this.isExternalWalletAuth && !idOrAddress && Object.keys(this.externalWallets).length > 0) {
2033
- return Object.values(this.externalWallets)[0];
2087
+ if (!this.isExternalWalletAuth) {
2088
+ if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
2089
+ return Object.values(this.externalWallets)[0];
2090
+ }
2034
2091
  }
2035
2092
  if ((_a = this.externalWallets) == null ? void 0 : _a[idOrAddress]) {
2036
2093
  return this.externalWallets[idOrAddress];
@@ -2077,10 +2134,8 @@ var _ParaCore = class _ParaCore {
2077
2134
  }
2078
2135
  assertIsValidWalletType(type, walletTypes) {
2079
2136
  return __async(this, null, function* () {
2080
- if (!__privateGet(this, _supportedWalletTypes)) {
2081
- yield this.touchSession();
2082
- }
2083
- if (!type || !Object.values(import_user_management_client5.WalletType).includes(type) || !(walletTypes != null ? walletTypes : this.supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
2137
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2138
+ if (!type || !Object.values(import_user_management_client5.WalletType).includes(type) || !(walletTypes != null ? walletTypes : supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
2084
2139
  throw new Error(`wallet type ${type} is not supported`);
2085
2140
  }
2086
2141
  return type;
@@ -2088,33 +2143,29 @@ var _ParaCore = class _ParaCore {
2088
2143
  }
2089
2144
  getMissingTypes() {
2090
2145
  return __async(this, null, function* () {
2091
- if (!__privateGet(this, _supportedWalletTypes)) {
2092
- yield this.touchSession();
2093
- }
2094
- return this.supportedWalletTypes.filter(
2146
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2147
+ return supportedWalletTypes.filter(
2095
2148
  ({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
2096
2149
  ).map(({ type }) => type);
2097
2150
  });
2098
2151
  }
2099
2152
  getTypesToCreate(types) {
2100
2153
  return __async(this, null, function* () {
2101
- if (!__privateGet(this, _supportedWalletTypes)) {
2102
- yield this.touchSession();
2103
- }
2154
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2104
2155
  return getSchemes(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
2105
2156
  switch (scheme) {
2106
2157
  case import_user_management_client5.WalletScheme.ED25519:
2107
2158
  return import_user_management_client5.WalletType.SOLANA;
2108
2159
  default:
2109
- return this.supportedWalletTypes.some(({ type, optional }) => type === import_user_management_client5.WalletType.COSMOS && !optional) ? import_user_management_client5.WalletType.COSMOS : import_user_management_client5.WalletType.EVM;
2160
+ return supportedWalletTypes.some(({ type, optional }) => type === import_user_management_client5.WalletType.COSMOS && !optional) ? import_user_management_client5.WalletType.COSMOS : import_user_management_client5.WalletType.EVM;
2110
2161
  }
2111
2162
  });
2112
2163
  });
2113
2164
  }
2114
- getPartnerURL(partnerId) {
2165
+ getPartnerURL() {
2115
2166
  return __async(this, null, function* () {
2116
- const res = yield this.ctx.client.getPartner(partnerId);
2117
- return res.data.partner.portalUrl;
2167
+ const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2168
+ return portalUrl;
2118
2169
  });
2119
2170
  }
2120
2171
  /**
@@ -2122,9 +2173,9 @@ var _ParaCore = class _ParaCore {
2122
2173
  * @param partnerId: string - id of the partner to get the portal URL for
2123
2174
  * @returns - portal URL
2124
2175
  */
2125
- getPortalURL(partnerId) {
2176
+ getPortalURL() {
2126
2177
  return __async(this, null, function* () {
2127
- return partnerId && (yield this.getPartnerURL(partnerId)) || getPortalBaseURL(this.ctx);
2178
+ return (yield this.getPartnerURL()) || getPortalBaseURL(this.ctx);
2128
2179
  });
2129
2180
  }
2130
2181
  getWebAuthURLForCreate(_a) {
@@ -2271,9 +2322,9 @@ var _ParaCore = class _ParaCore {
2271
2322
  * @param {string} opts.countryCode - the country code.
2272
2323
  * @returns true if user exists, false otherwise.
2273
2324
  */
2274
- checkIfUserExistsByPhone(_0) {
2275
- return __async(this, arguments, function* ({ phone, countryCode }) {
2276
- const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
2325
+ checkIfUserExistsByPhone(auth) {
2326
+ return __async(this, null, function* () {
2327
+ const res = yield this.ctx.client.checkUserExists(auth);
2277
2328
  return res.data.exists;
2278
2329
  });
2279
2330
  }
@@ -2298,14 +2349,11 @@ var _ParaCore = class _ParaCore {
2298
2349
  * @param {string} opts.phone - the phone number to use for creating the user.
2299
2350
  * @param {string} opts.countryCode - the country code to use for creating the user.
2300
2351
  */
2301
- createUserByPhone(_0) {
2302
- return __async(this, arguments, function* ({ phone, countryCode }) {
2352
+ createUserByPhone(auth) {
2353
+ return __async(this, null, function* () {
2303
2354
  this.requireApiKey();
2304
- yield this.setPhoneNumber(phone, countryCode);
2305
- const { userId } = yield this.ctx.client.createUser({
2306
- phone: this.phone,
2307
- countryCode: this.countryCode
2308
- });
2355
+ yield this.setPhoneNumber(auth.phone);
2356
+ const { userId } = yield this.ctx.client.createUser(auth);
2309
2357
  yield this.setUserId(userId);
2310
2358
  });
2311
2359
  }
@@ -2331,12 +2379,6 @@ var _ParaCore = class _ParaCore {
2331
2379
  return res;
2332
2380
  });
2333
2381
  }
2334
- /**
2335
- * Returns whether or not the user is connected with only an external wallet, not an external wallet with Para auth.
2336
- */
2337
- isUsingExternalWallet() {
2338
- return !this.isExternalWalletAuth && !!Object.keys(this.externalWallets).length;
2339
- }
2340
2382
  /**
2341
2383
  * Passes the email code obtained from the user for verification.
2342
2384
  * @param {Object} opts the options object
@@ -2357,7 +2399,7 @@ var _ParaCore = class _ParaCore {
2357
2399
  cosmosSigner
2358
2400
  }) {
2359
2401
  yield this.ctx.client.verifyExternalWallet(this.userId, { address, signedMessage, cosmosPublicKeyHex, cosmosSigner });
2360
- return this.getSetUpBiometricsURL({ authType: "externalWallet" });
2402
+ return this.getSetUpBiometricsURL({ authType: __privateGet(this, _authInfo).authType });
2361
2403
  });
2362
2404
  }
2363
2405
  /**
@@ -2382,8 +2424,19 @@ var _ParaCore = class _ParaCore {
2382
2424
  return __async(this, null, function* () {
2383
2425
  const res = yield this.ctx.client.verifyTelegram(authObject);
2384
2426
  if (res.isValid) {
2385
- yield this.setUserId(res.userId);
2386
- yield this.setTelegramUserId(res.telegramUserId);
2427
+ const { userId, telegramUserId } = res;
2428
+ const { photo_url: pfpUrl, username, first_name: firstName, last_name: lastName } = authObject;
2429
+ yield this.setAuth(
2430
+ { telegramUserId },
2431
+ {
2432
+ extras: {
2433
+ pfpUrl,
2434
+ username,
2435
+ displayName: firstName ? `${firstName}${lastName ? ` ${lastName}` : ""}` : username ? `@${username}` : void 0
2436
+ },
2437
+ userId
2438
+ }
2439
+ );
2387
2440
  yield this.touchSession(true);
2388
2441
  if (!this.loginEncryptionKeyPair) {
2389
2442
  yield this.setLoginEncryptionKeyPair();
@@ -2421,10 +2474,9 @@ var _ParaCore = class _ParaCore {
2421
2474
  verify2FAForPhone(_0) {
2422
2475
  return __async(this, arguments, function* ({
2423
2476
  phone,
2424
- countryCode,
2425
2477
  verificationCode
2426
2478
  }) {
2427
- const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
2479
+ const res = yield this.ctx.client.verify2FAForPhone(phone, verificationCode);
2428
2480
  return {
2429
2481
  initiatedAt: res.data.initiatedAt,
2430
2482
  status: res.data.status,
@@ -2568,11 +2620,11 @@ var _ParaCore = class _ParaCore {
2568
2620
  */
2569
2621
  isSessionActive() {
2570
2622
  return __async(this, null, function* () {
2571
- if (this.isUsingExternalWallet()) {
2623
+ if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
2572
2624
  return true;
2573
2625
  }
2574
- const res = yield this.touchSession();
2575
- return !!res.data.isAuthenticated;
2626
+ const { isAuthenticated } = yield this.touchSession();
2627
+ return !!isAuthenticated;
2576
2628
  });
2577
2629
  }
2578
2630
  /**
@@ -2581,7 +2633,7 @@ var _ParaCore = class _ParaCore {
2581
2633
  **/
2582
2634
  isFullyLoggedIn() {
2583
2635
  return __async(this, null, function* () {
2584
- if (this.isUsingExternalWallet()) {
2636
+ if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
2585
2637
  return true;
2586
2638
  }
2587
2639
  const isSessionActive = yield this.isSessionActive();
@@ -2611,44 +2663,8 @@ var _ParaCore = class _ParaCore {
2611
2663
  */
2612
2664
  getUserBiometricLocationHints() {
2613
2665
  return __async(this, null, function* () {
2614
- var _a;
2615
- if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId && !this.isExternalWalletAuth) {
2616
- throw new Error(
2617
- "one of email, phone, farcaster username, telegram user id or external wallet with Para auth are required to get biometric location hints"
2618
- );
2619
- }
2620
- return yield this.ctx.client.getBiometricLocationHints({
2621
- email: this.email,
2622
- phone: this.phone,
2623
- countryCode: this.countryCode,
2624
- farcasterUsername: this.farcasterUsername,
2625
- telegramUserId: this.telegramUserId,
2626
- // Using id here since we store the bech32 address for cosmos in the address field of the wallet
2627
- externalWalletAddress: (_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id
2628
- });
2629
- });
2630
- }
2631
- setAuth(auth) {
2632
- return __async(this, null, function* () {
2633
- const authInfo = (0, import_user_management_client5.extractAuthInfo)(auth);
2634
- if (!authInfo) {
2635
- return void 0;
2636
- }
2637
- switch (authInfo.authType) {
2638
- case "email":
2639
- yield this.setEmail(authInfo.identifier);
2640
- break;
2641
- case "phone":
2642
- yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
2643
- break;
2644
- case "farcaster":
2645
- yield this.setFarcasterUsername(authInfo.identifier);
2646
- break;
2647
- case "telegram":
2648
- yield this.setTelegramUserId(authInfo.identifier);
2649
- break;
2650
- }
2651
- return authInfo;
2666
+ const auth = __privateMethod(this, _ParaCore_instances, assertIsAuthSet_fn).call(this);
2667
+ return yield this.ctx.client.getBiometricLocationHints(auth);
2652
2668
  });
2653
2669
  }
2654
2670
  /**
@@ -2665,14 +2681,14 @@ var _ParaCore = class _ParaCore {
2665
2681
  if (!authInfo) {
2666
2682
  return;
2667
2683
  }
2668
- const res = yield this.touchSession(true);
2684
+ const { partnerId, sessionId } = yield this.touchSession(true);
2669
2685
  if (!this.loginEncryptionKeyPair) {
2670
2686
  yield this.setLoginEncryptionKeyPair();
2671
2687
  }
2672
2688
  const webAuthLoginURL = yield this.getWebAuthURLForLogin({
2673
2689
  authType: authInfo.authType,
2674
- sessionId: res.data.sessionId,
2675
- partnerId: res.data.partnerId,
2690
+ sessionId,
2691
+ partnerId,
2676
2692
  loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
2677
2693
  });
2678
2694
  if (!useShortUrl) {
@@ -2688,7 +2704,10 @@ var _ParaCore = class _ParaCore {
2688
2704
  **/
2689
2705
  initiateUserLoginV2(auth) {
2690
2706
  return __async(this, null, function* () {
2691
- const authInfo = yield this.setAuth(auth);
2707
+ let authInfo = __privateGet(this, _authInfo);
2708
+ if (!authInfo || JSON.stringify(authInfo.auth) !== JSON.stringify(auth)) {
2709
+ authInfo = yield this.setAuth(auth);
2710
+ }
2692
2711
  if (!authInfo) {
2693
2712
  return;
2694
2713
  }
@@ -2715,14 +2734,14 @@ var _ParaCore = class _ParaCore {
2715
2734
  "useShortUrl"
2716
2735
  ]);
2717
2736
  yield this.setAuth(auth);
2718
- const res = yield this.touchSession(true);
2737
+ const { sessionId, partnerId } = yield this.touchSession(true);
2719
2738
  if (!this.loginEncryptionKeyPair) {
2720
2739
  yield this.setLoginEncryptionKeyPair();
2721
2740
  }
2722
2741
  const webAuthLoginURL = yield this.getWebAuthURLForLoginForPhone({
2723
- sessionId: res.data.sessionId,
2742
+ sessionId,
2724
2743
  loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair),
2725
- partnerId: res.data.partnerId
2744
+ partnerId
2726
2745
  });
2727
2746
  if (!useShortUrl) {
2728
2747
  return webAuthLoginURL;
@@ -2765,11 +2784,12 @@ var _ParaCore = class _ParaCore {
2765
2784
  popupWindow
2766
2785
  } = {}) {
2767
2786
  yield this.waitForAccountCreation({ popupWindow });
2787
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2768
2788
  const pregenWallets = yield this.getPregenWallets();
2769
2789
  let recoverySecret, walletIds = {};
2770
2790
  if (pregenWallets.length > 0) {
2771
2791
  recoverySecret = yield this.claimPregenWallets();
2772
- walletIds = this.supportedWalletTypes.reduce((acc, { type }) => {
2792
+ walletIds = supportedWalletTypes.reduce((acc, { type }) => {
2773
2793
  var _a;
2774
2794
  return __spreadProps(__spreadValues({}, acc), {
2775
2795
  [type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
@@ -2813,9 +2833,12 @@ var _ParaCore = class _ParaCore {
2813
2833
  const res = yield this.ctx.client.getFarcasterAuthStatus();
2814
2834
  if (res.data.state === "completed") {
2815
2835
  const { userId, userExists, username, pfpUrl } = res.data;
2816
- yield this.setUserId(userId);
2817
- yield this.setFarcasterUsername(username);
2836
+ yield this.setAuth(
2837
+ { farcasterUsername: username },
2838
+ { extras: { pfpUrl, username, displayName: username }, userId }
2839
+ );
2818
2840
  return {
2841
+ userId,
2819
2842
  userExists,
2820
2843
  username,
2821
2844
  pfpUrl
@@ -2839,13 +2862,13 @@ var _ParaCore = class _ParaCore {
2839
2862
  getOAuthURL(_0) {
2840
2863
  return __async(this, arguments, function* ({ method, deeplinkUrl }) {
2841
2864
  yield this.logout();
2842
- const res = yield this.touchSession(true);
2865
+ const { sessionLookupId } = yield this.touchSession(true);
2843
2866
  return constructUrl({
2844
2867
  base: method === import_user_management_client5.OAuthMethod.TELEGRAM ? getPortalBaseURL(this.ctx, true) : getBaseOAuthUrl(this.ctx.env),
2845
2868
  path: `/auth/${method.toLowerCase()}`,
2846
2869
  params: {
2847
2870
  apiKey: this.ctx.apiKey,
2848
- sessionLookupId: res.data.sessionLookupId,
2871
+ sessionLookupId,
2849
2872
  deeplinkUrl
2850
2873
  }
2851
2874
  });
@@ -2869,18 +2892,16 @@ var _ParaCore = class _ParaCore {
2869
2892
  }
2870
2893
  yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
2871
2894
  if (this.isAwaitingOAuth) {
2872
- const res = yield this.touchSession();
2873
- if (res.data.userId) {
2874
- const { userId, email } = res.data;
2895
+ const { userId, email } = yield this.touchSession();
2896
+ if (!!userId) {
2875
2897
  if (!this.loginEncryptionKeyPair) {
2876
2898
  yield this.setLoginEncryptionKeyPair();
2877
2899
  }
2878
2900
  yield this.setUserId(userId);
2879
2901
  yield this.setEmail(email);
2880
- const userExists = yield this.checkIfUserExists({ email });
2881
2902
  this.isAwaitingOAuth = false;
2882
2903
  return {
2883
- userExists,
2904
+ userExists: true,
2884
2905
  email
2885
2906
  };
2886
2907
  }
@@ -2911,9 +2932,11 @@ var _ParaCore = class _ParaCore {
2911
2932
  }
2912
2933
  this.isAwaitingLogin = true;
2913
2934
  while (this.isAwaitingLogin) {
2935
+ let session;
2914
2936
  try {
2915
2937
  yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
2916
- if (!(yield this.isSessionActive())) {
2938
+ session = yield this.touchSession();
2939
+ if (!session.isAuthenticated) {
2917
2940
  if (popupWindow == null ? void 0 : popupWindow.closed) {
2918
2941
  const resp2 = { isComplete: false, isError: true };
2919
2942
  dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
@@ -2921,8 +2944,8 @@ var _ParaCore = class _ParaCore {
2921
2944
  }
2922
2945
  continue;
2923
2946
  }
2924
- const postLoginData = yield this.userSetupAfterLogin();
2925
- const needsWallet = (_a = postLoginData.data.needsWallet) != null ? _a : false;
2947
+ session = yield this.userSetupAfterLogin();
2948
+ const needsWallet = (_a = session.needsWallet) != null ? _a : false;
2926
2949
  if (!needsWallet) {
2927
2950
  if (this.currentWalletIdsArray.length === 0) {
2928
2951
  if (popupWindow == null ? void 0 : popupWindow.closed) {
@@ -2942,7 +2965,7 @@ var _ParaCore = class _ParaCore {
2942
2965
  const resp2 = {
2943
2966
  isComplete: true,
2944
2967
  needsWallet: needsWallet || Object.values(this.wallets).length === 0,
2945
- partnerId: postLoginData.data.partnerId
2968
+ partnerId: session.partnerId
2946
2969
  };
2947
2970
  dispatchEvent(ParaEvent.LOGIN_EVENT, resp2);
2948
2971
  return resp2;
@@ -2966,12 +2989,12 @@ var _ParaCore = class _ParaCore {
2966
2989
  **/
2967
2990
  refreshSession() {
2968
2991
  return __async(this, arguments, function* ({ shouldOpenPopup = false } = {}) {
2969
- const res = yield this.touchSession(true);
2992
+ const { sessionId } = yield this.touchSession(true);
2970
2993
  if (!this.loginEncryptionKeyPair) {
2971
2994
  yield this.setLoginEncryptionKeyPair();
2972
2995
  }
2973
2996
  const link = yield this.getWebAuthURLForLogin({
2974
- sessionId: res.data.sessionId,
2997
+ sessionId,
2975
2998
  loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
2976
2999
  });
2977
3000
  if (shouldOpenPopup) {
@@ -2986,13 +3009,13 @@ var _ParaCore = class _ParaCore {
2986
3009
  **/
2987
3010
  userSetupAfterLogin() {
2988
3011
  return __async(this, null, function* () {
2989
- const res = yield this.touchSession();
2990
- yield this.setUserId(res.data.userId);
2991
- if (res.data.currentWalletIds && res.data.currentWalletIds !== this.currentWalletIds)
2992
- yield this.setCurrentWalletIds(res.data.currentWalletIds, {
2993
- sessionLookupId: this.isPortal() ? res.data.sessionLookupId : void 0
3012
+ const session = yield this.touchSession();
3013
+ yield this.setUserId(session.userId);
3014
+ if (session.currentWalletIds && session.currentWalletIds !== this.currentWalletIds)
3015
+ yield this.setCurrentWalletIds(session.currentWalletIds, {
3016
+ sessionLookupId: this.isPortal() ? session.sessionLookupId : void 0
2994
3017
  });
2995
- return res;
3018
+ return session;
2996
3019
  });
2997
3020
  }
2998
3021
  /**
@@ -3003,8 +3026,8 @@ var _ParaCore = class _ParaCore {
3003
3026
  **/
3004
3027
  getTransmissionKeyShares() {
3005
3028
  return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
3006
- const res = yield this.touchSession();
3007
- const sessionLookupId = isForNewDevice ? `${res.data.sessionLookupId}-new-device` : res.data.sessionLookupId;
3029
+ const session = yield this.touchSession();
3030
+ const sessionLookupId = isForNewDevice ? `${session.sessionLookupId}-new-device` : session.sessionLookupId;
3008
3031
  return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
3009
3032
  });
3010
3033
  }
@@ -3213,8 +3236,9 @@ var _ParaCore = class _ParaCore {
3213
3236
  } = {}) {
3214
3237
  var _a, _b;
3215
3238
  this.requireApiKey();
3239
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
3216
3240
  const walletType = yield this.assertIsValidWalletType(
3217
- _type != null ? _type : (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
3241
+ _type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
3218
3242
  );
3219
3243
  let signer;
3220
3244
  let wallet;
@@ -3286,14 +3310,15 @@ var _ParaCore = class _ParaCore {
3286
3310
  createPregenWallet(opts) {
3287
3311
  return __async(this, null, function* () {
3288
3312
  var _a, _b;
3313
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
3289
3314
  const {
3290
- type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
3315
+ type: _type = (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
3291
3316
  pregenIdentifier,
3292
3317
  pregenIdentifierType = "EMAIL"
3293
3318
  } = opts;
3294
3319
  this.requireApiKey();
3295
3320
  const walletType = yield this.assertIsValidWalletType(
3296
- _type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
3321
+ _type != null ? _type : (_b = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
3297
3322
  );
3298
3323
  let keygenRes;
3299
3324
  switch (walletType) {
@@ -3375,12 +3400,6 @@ var _ParaCore = class _ParaCore {
3375
3400
  if (pregenWallets.length === 0) {
3376
3401
  return void 0;
3377
3402
  }
3378
- const missingWallets = pregenWallets.filter((wallet) => !this.wallets[wallet.id]);
3379
- if (missingWallets.length > 0) {
3380
- throw new Error(
3381
- `Cannot claim pregen wallets because wallet data is missing. Please call setUserShare first to load the wallet data for the following wallet IDs: ${missingWallets.map((w) => w.id).join(", ")}`
3382
- );
3383
- }
3384
3403
  let newRecoverySecret;
3385
3404
  const { walletIds } = yield this.ctx.client.claimPregenWallets({
3386
3405
  userId: this.userId,
@@ -3534,9 +3553,9 @@ var _ParaCore = class _ParaCore {
3534
3553
  }
3535
3554
  getTransactionReviewUrl(transactionId, timeoutMs) {
3536
3555
  return __async(this, null, function* () {
3537
- const res = yield this.touchSession();
3556
+ const { id: partnerId } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
3538
3557
  return this.constructPortalUrl("txReview", {
3539
- partnerId: res.data.partnerId,
3558
+ partnerId,
3540
3559
  pathId: transactionId,
3541
3560
  params: {
3542
3561
  email: this.email,
@@ -3554,12 +3573,12 @@ var _ParaCore = class _ParaCore {
3554
3573
  "purchaseId",
3555
3574
  "providerKey"
3556
3575
  ]);
3557
- const res = yield this.touchSession();
3576
+ const { partnerId, sessionId } = yield this.touchSession();
3558
3577
  const [key, identifier] = (0, import_user_management_client5.extractWalletRef)(walletParams);
3559
3578
  return this.constructPortalUrl("onRamp", {
3560
- partnerId: res.data.partnerId,
3579
+ partnerId,
3561
3580
  pathId: purchaseId,
3562
- sessionId: res.data.sessionId,
3581
+ sessionId,
3563
3582
  params: {
3564
3583
  [key]: identifier,
3565
3584
  providerKey,
@@ -3834,27 +3853,17 @@ var _ParaCore = class _ParaCore {
3834
3853
  }
3835
3854
  /**
3836
3855
  * Serialize the current session for import by another Para instance.
3837
- * @param {boolean} excludeSigners - whether or not to exclude the signer from the exported wallets.
3838
3856
  * @returns {string} the serialized session
3839
3857
  */
3840
- exportSession({ excludeSigners } = {}) {
3858
+ exportSession() {
3841
3859
  const sessionInfo = {
3842
- email: this.email,
3860
+ authInfo: __privateGet(this, _authInfo),
3843
3861
  userId: this.userId,
3844
- wallets: structuredClone(this.wallets),
3862
+ wallets: this.wallets,
3845
3863
  currentWalletIds: this.currentWalletIds,
3846
- sessionCookie: this.sessionCookie,
3847
- phone: this.phone,
3848
- countryCode: this.countryCode,
3849
- telegramUserId: this.telegramUserId,
3850
- farcasterUsername: this.farcasterUsername,
3864
+ sessionCookie: this.retrieveSessionCookie(),
3851
3865
  externalWallets: this.externalWallets
3852
3866
  };
3853
- if (excludeSigners) {
3854
- for (const wallet of Object.values(sessionInfo.wallets)) {
3855
- delete wallet.signer;
3856
- }
3857
- }
3858
3867
  return Buffer.from(JSON.stringify(sessionInfo)).toString("base64");
3859
3868
  }
3860
3869
  /**
@@ -3863,12 +3872,11 @@ var _ParaCore = class _ParaCore {
3863
3872
  */
3864
3873
  importSession(serializedInstanceBase64) {
3865
3874
  return __async(this, null, function* () {
3866
- var _a;
3875
+ var _a, _b;
3867
3876
  const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
3868
- const sessionInfo = JSON.parse(serializedInstance);
3869
- yield this.setEmail(sessionInfo.email);
3870
- yield this.setTelegramUserId(sessionInfo.telegramUserId);
3871
- yield this.setFarcasterUsername(sessionInfo.farcasterUsername);
3877
+ const sessionInfo = jsonParse(serializedInstance);
3878
+ const authInfo = (_a = sessionInfo.authInfo) != null ? _a : __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, sessionInfo);
3879
+ yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
3872
3880
  yield this.setUserId(sessionInfo.userId);
3873
3881
  yield this.setWallets(sessionInfo.wallets);
3874
3882
  yield this.setExternalWallets(sessionInfo.externalWallets || {});
@@ -3883,14 +3891,13 @@ var _ParaCore = class _ParaCore {
3883
3891
  const currentWalletIds = {};
3884
3892
  for (const walletId of Object.keys(sessionInfo.wallets)) {
3885
3893
  currentWalletIds[sessionInfo.wallets[walletId].type] = [
3886
- ...(_a = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _a : [],
3894
+ ...(_b = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _b : [],
3887
3895
  walletId
3888
3896
  ];
3889
3897
  }
3890
3898
  yield this.setCurrentWalletIds(currentWalletIds);
3891
3899
  }
3892
3900
  this.persistSessionCookie(sessionInfo.sessionCookie);
3893
- yield this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
3894
3901
  });
3895
3902
  }
3896
3903
  exitAccountCreation() {
@@ -3917,8 +3924,8 @@ var _ParaCore = class _ParaCore {
3917
3924
  **/
3918
3925
  getVerificationToken() {
3919
3926
  return __async(this, null, function* () {
3920
- const { data } = yield this.touchSession();
3921
- return data.sessionLookupId;
3927
+ const { sessionLookupId } = yield this.touchSession();
3928
+ return sessionLookupId;
3922
3929
  });
3923
3930
  }
3924
3931
  /**
@@ -3943,10 +3950,7 @@ var _ParaCore = class _ParaCore {
3943
3950
  this.currentWalletIds = {};
3944
3951
  this.externalWallets = {};
3945
3952
  this.loginEncryptionKeyPair = void 0;
3946
- this.email = void 0;
3947
- this.telegramUserId = void 0;
3948
- this.phone = void 0;
3949
- this.countryCode = void 0;
3953
+ __privateSet(this, _authInfo, void 0);
3950
3954
  this.userId = void 0;
3951
3955
  this.sessionCookie = void 0;
3952
3956
  dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
@@ -3954,11 +3958,9 @@ var _ParaCore = class _ParaCore {
3954
3958
  }
3955
3959
  getSupportedCreateAuthMethods() {
3956
3960
  return __async(this, null, function* () {
3957
- const res = yield this.touchSession();
3958
- const partnerId = res.data.partnerId;
3959
- const partnerRes = yield this.ctx.client.getPartner(partnerId);
3961
+ const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
3960
3962
  let supportedAuthMethods = /* @__PURE__ */ new Set();
3961
- for (const authMethod of partnerRes.data.partner.supportedAuthMethods) {
3963
+ for (const authMethod of partner.supportedAuthMethods) {
3962
3964
  supportedAuthMethods.add(import_user_management_client5.AuthMethod[authMethod]);
3963
3965
  }
3964
3966
  return supportedAuthMethods;
@@ -3970,6 +3972,7 @@ var _ParaCore = class _ParaCore {
3970
3972
  * Doesn't work for all types of logging.
3971
3973
  **/
3972
3974
  toString() {
3975
+ var _a, _b, _c;
3973
3976
  const redactedWallets = Object.keys(this.wallets).reduce(
3974
3977
  (acc, walletId) => __spreadProps(__spreadValues({}, acc), {
3975
3978
  [walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
@@ -3987,13 +3990,10 @@ var _ParaCore = class _ParaCore {
3987
3990
  {}
3988
3991
  );
3989
3992
  const obj = {
3990
- supportedWalletTypes: this.supportedWalletTypes,
3991
- cosmosPrefix: this.cosmosPrefix,
3992
- email: this.email,
3993
- phone: this.phone,
3994
- countryCode: this.countryCode,
3995
- telegramUserId: this.telegramUserId,
3996
- farcasterUsername: this.farcasterUsername,
3993
+ partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
3994
+ supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
3995
+ cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
3996
+ authInfo: __privateGet(this, _authInfo),
3997
3997
  userId: this.userId,
3998
3998
  pregenIds: this.pregenIds,
3999
3999
  currentWalletIds: this.currentWalletIds,
@@ -4014,8 +4014,79 @@ var _ParaCore = class _ParaCore {
4014
4014
  return `Para ${JSON.stringify(obj, null, 2)}`;
4015
4015
  }
4016
4016
  };
4017
- _supportedWalletTypes = new WeakMap();
4018
- _supportedWalletTypesOpt = new WeakMap();
4017
+ _authInfo = new WeakMap();
4018
+ _partner = new WeakMap();
4019
+ _ParaCore_instances = new WeakSet();
4020
+ assertPartner_fn = function() {
4021
+ return __async(this, null, function* () {
4022
+ var _a, _b;
4023
+ if (!__privateGet(this, _partner)) {
4024
+ yield this.touchSession();
4025
+ }
4026
+ if (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== __privateGet(this, _partner).cosmosPrefix) {
4027
+ this.ctx.cosmosPrefix = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix;
4028
+ }
4029
+ return __privateGet(this, _partner);
4030
+ });
4031
+ };
4032
+ toAuthInfo_fn = function({
4033
+ email,
4034
+ phone,
4035
+ countryCode,
4036
+ farcasterUsername,
4037
+ telegramUserId,
4038
+ externalWalletAddress
4039
+ }) {
4040
+ let auth;
4041
+ switch (true) {
4042
+ case !!email:
4043
+ auth = { email };
4044
+ break;
4045
+ case !!phone:
4046
+ {
4047
+ const validPhone = formatPhoneNumber(phone, countryCode);
4048
+ if (validPhone) auth = { phone: formatPhoneNumber(phone, countryCode) };
4049
+ }
4050
+ break;
4051
+ case !!farcasterUsername:
4052
+ auth = { farcasterUsername };
4053
+ break;
4054
+ case !!telegramUserId:
4055
+ auth = { telegramUserId };
4056
+ break;
4057
+ case !!externalWalletAddress:
4058
+ auth = { externalWalletAddress };
4059
+ break;
4060
+ }
4061
+ return (0, import_user_management_client5.extractAuthInfo)(auth);
4062
+ };
4063
+ setAuthInfo_fn = function(authInfo) {
4064
+ return __async(this, null, function* () {
4065
+ __privateSet(this, _authInfo, authInfo);
4066
+ yield this.localStorageSetItem(LOCAL_STORAGE_AUTH_INFO, JSON.stringify(authInfo));
4067
+ yield this.localStorageRemoveItem(LOCAL_STORAGE_EMAIL);
4068
+ yield this.localStorageRemoveItem(LOCAL_STORAGE_PHONE);
4069
+ yield this.localStorageRemoveItem(LOCAL_STORAGE_COUNTRY_CODE);
4070
+ yield this.localStorageRemoveItem(LOCAL_STORAGE_FARCASTER_USERNAME);
4071
+ yield this.localStorageRemoveItem(LOCAL_STORAGE_TELEGRAM_USER_ID);
4072
+ });
4073
+ };
4074
+ assertIsAuthSet_fn = function(allowed) {
4075
+ if (!__privateGet(this, _authInfo)) {
4076
+ throw new Error("auth is not set");
4077
+ }
4078
+ if (allowed && !allowed.includes(__privateGet(this, _authInfo).authType)) {
4079
+ throw new Error(`invalid auth type, expected ${allowed.join(", ")}`);
4080
+ }
4081
+ return __privateGet(this, _authInfo).auth;
4082
+ };
4083
+ getPartner_fn = function(partnerId) {
4084
+ return __async(this, null, function* () {
4085
+ const res = yield this.ctx.client.getPartner(partnerId);
4086
+ __privateSet(this, _partner, res.data.partner);
4087
+ return __privateGet(this, _partner);
4088
+ });
4089
+ };
4019
4090
  _ParaCore.version = PARA_CORE_VERSION;
4020
4091
  var ParaCore = _ParaCore;
4021
4092
 
@@ -4055,12 +4126,14 @@ var src_default = ParaCore;
4055
4126
  decryptPrivateKeyWithPassword,
4056
4127
  decryptWithKeyPair,
4057
4128
  decryptWithPrivateKey,
4129
+ displayPhoneNumber,
4058
4130
  distributeNewShare,
4059
4131
  encodePrivateKeyToPemHex,
4060
4132
  encryptPrivateKey,
4061
4133
  encryptPrivateKeyWithPassword,
4062
4134
  encryptWithDerivedPublicKey,
4063
4135
  entityToWallet,
4136
+ formatPhoneNumber,
4064
4137
  getAsymmetricKeyPair,
4065
4138
  getBaseMPCNetworkUrl,
4066
4139
  getBaseOAuthUrl,
@@ -4082,10 +4155,8 @@ var src_default = ParaCore;
4082
4155
  initClient,
4083
4156
  isWalletSupported,
4084
4157
  mpcComputationClient,
4085
- normalizePhoneNumber,
4086
4158
  paraVersion,
4087
4159
  publicKeyFromHex,
4088
- stringToPhoneNumber,
4089
4160
  toAssetInfoArray,
4090
4161
  transmissionUtilsRetrieve,
4091
4162
  truncateAddress,