@getpara/core-sdk 1.7.1 → 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/esm/index.js CHANGED
@@ -40,6 +40,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
40
40
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
41
41
  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);
42
42
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
43
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
43
44
  var __async = (__this, __arguments, generator) => {
44
45
  return new Promise((resolve, reject) => {
45
46
  var fulfilled = (value) => {
@@ -72,7 +73,12 @@ import {
72
73
  OAuthMethod,
73
74
  extractWalletRef,
74
75
  PasswordStatus,
75
- extractAuthInfo
76
+ extractAuthInfo,
77
+ isEmail,
78
+ isPhone,
79
+ isFarcaster,
80
+ isTelegram,
81
+ isExternalWallet
76
82
  } from "@getpara/user-management-client";
77
83
  import forge3 from "node-forge";
78
84
 
@@ -80,6 +86,23 @@ import forge3 from "node-forge";
80
86
  import base64url from "base64url";
81
87
  import forge from "node-forge";
82
88
 
89
+ // src/utils/autobind.ts
90
+ function autoBind(instance) {
91
+ let proto = instance;
92
+ while (proto && proto !== Object.prototype) {
93
+ for (const key of Object.getOwnPropertyNames(proto)) {
94
+ const value = instance[key];
95
+ if (typeof value === "function" && key !== "constructor") {
96
+ try {
97
+ instance[key] = value.bind(instance);
98
+ } catch (e) {
99
+ }
100
+ }
101
+ }
102
+ proto = Object.getPrototypeOf(proto);
103
+ }
104
+ }
105
+
83
106
  // src/utils/events.ts
84
107
  function dispatchEvent(type, data, error) {
85
108
  typeof window !== "undefined" && !!window.dispatchEvent && window.dispatchEvent(
@@ -92,7 +115,6 @@ import { toBech32 } from "@cosmjs/encoding";
92
115
  import { sha256 } from "@noble/hashes/sha256";
93
116
  import { ripemd160 } from "@noble/hashes/ripemd160";
94
117
  import elliptic from "elliptic";
95
- import parsePhoneNumberFromString from "libphonenumber-js";
96
118
  var secp256k1 = new elliptic.ec("secp256k1");
97
119
  function hexStringToBase64(hexString) {
98
120
  if (hexString.substring(0, 2) === "0x") {
@@ -149,12 +171,71 @@ function truncateAddress(str, addressType, { prefix = addressType === "COSMOS" ?
149
171
  const headLength = (addressType === "COSMOS" ? prefix.length : addressType === "SOLANA" ? 0 : 2) + 4;
150
172
  return `${str.slice(0, headLength)}...${str.slice(-4)}`;
151
173
  }
152
- function stringToPhoneNumber(str) {
153
- var _a;
154
- return (_a = parsePhoneNumberFromString(str)) == null ? void 0 : _a.formatInternational().replace(/[^\d+]/g, "");
174
+
175
+ // src/utils/json.ts
176
+ function jsonParse(data, validate) {
177
+ try {
178
+ const res = JSON.parse(data);
179
+ if (validate && !validate(res)) {
180
+ return void 0;
181
+ }
182
+ return res;
183
+ } catch (e) {
184
+ return void 0;
185
+ }
186
+ }
187
+
188
+ // src/constants.ts
189
+ var PARA_CORE_VERSION = '2.0.0-dev.0';
190
+ var PREFIX = "@CAPSULE/";
191
+ var LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
192
+ var LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
193
+ var LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
194
+ var LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
195
+ var LOCAL_STORAGE_FARCASTER_USERNAME = `${PREFIX}farcasterUsername`;
196
+ var LOCAL_STORAGE_TELEGRAM_USER_ID = `${PREFIX}telegramUserId`;
197
+ var LOCAL_STORAGE_USER_ID = `${PREFIX}userId`;
198
+ var LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
199
+ var LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
200
+ var LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
201
+ var LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
202
+ var LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
203
+ var SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
204
+ var POLLING_INTERVAL_MS = 2e3;
205
+ var SHORT_POLLING_INTERVAL_MS = 1e3;
206
+
207
+ // src/utils/listeners.ts
208
+ function storageListener(e) {
209
+ if (!e.url.includes(window.location.origin)) {
210
+ return;
211
+ }
212
+ if (e.key === LOCAL_STORAGE_EXTERNAL_WALLETS) {
213
+ this.updateExternalWalletsFromStorage();
214
+ }
215
+ if (e.key === SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR) {
216
+ this.updateLoginEncryptionKeyPairFromStorage();
217
+ }
218
+ if (e.key === LOCAL_STORAGE_SESSION_COOKIE) {
219
+ this.updateSessionCookieFromStorage();
220
+ }
221
+ if (e.key === LOCAL_STORAGE_CURRENT_WALLET_IDS) {
222
+ this.updateWalletIdsFromStorage();
223
+ }
224
+ if (e.key === LOCAL_STORAGE_WALLETS || e.key === LOCAL_STORAGE_ED25519_WALLETS) {
225
+ this.updateWalletsFromStorage();
226
+ }
227
+ if (e.key === LOCAL_STORAGE_AUTH_INFO) {
228
+ this.updateAuthInfoFromStorage();
229
+ }
230
+ if (e.key === LOCAL_STORAGE_USER_ID) {
231
+ this.updateUserIdFromStorage();
232
+ }
155
233
  }
156
- function normalizePhoneNumber(countryCode, number) {
157
- return stringToPhoneNumber(`${countryCode[0] !== "+" ? "+" : ""}${countryCode}${number}`);
234
+ function setupListeners() {
235
+ if (typeof window !== "undefined" && window.addEventListener && window.location) {
236
+ window.removeEventListener("storage", storageListener.bind(this));
237
+ window.addEventListener("storage", storageListener.bind(this));
238
+ }
158
239
  }
159
240
 
160
241
  // src/utils/onRamps.ts
@@ -193,6 +274,34 @@ function getOnRampAssets(data, {
193
274
  ];
194
275
  }
195
276
 
277
+ // src/utils/phone.ts
278
+ import parsePhoneNumberFromString from "libphonenumber-js";
279
+ function formatPhoneNumber(phone, countryCode, { forDisplay = false } = {}) {
280
+ if (!phone) {
281
+ return null;
282
+ }
283
+ phone = phone == null ? void 0 : phone.toString();
284
+ countryCode = countryCode == null ? void 0 : countryCode.toString();
285
+ let sanitizedNumber, parsedNumber;
286
+ if (!!countryCode) {
287
+ sanitizedNumber = phone.replace(/\D/g, "");
288
+ if (/^\+\d+$/.test(countryCode)) {
289
+ countryCode = countryCode.slice(1);
290
+ }
291
+ parsedNumber = parsePhoneNumberFromString(sanitizedNumber, { defaultCallingCode: countryCode });
292
+ } else {
293
+ sanitizedNumber = `+${phone.replace(/\D/g, "")}`;
294
+ parsedNumber = parsePhoneNumberFromString(sanitizedNumber);
295
+ }
296
+ if (parsedNumber == null ? void 0 : parsedNumber.isValid()) {
297
+ return forDisplay ? parsedNumber.formatInternational() : parsedNumber.formatInternational().replace(/[^\d+]/g, "");
298
+ }
299
+ return null;
300
+ }
301
+ function displayPhoneNumber(phone, countryCode) {
302
+ return formatPhoneNumber(phone, countryCode, { forDisplay: true });
303
+ }
304
+
196
305
  // src/utils/polling.ts
197
306
  function waitUntilTrue(condition, timeoutMs, intervalMs) {
198
307
  return __async(this, null, function* () {
@@ -348,7 +457,10 @@ function constructUrl({
348
457
  }
349
458
 
350
459
  // src/utils/wallet.ts
351
- import { WalletScheme, WalletType } from "@getpara/user-management-client";
460
+ import {
461
+ WalletScheme,
462
+ WalletType
463
+ } from "@getpara/user-management-client";
352
464
  var WalletSchemeTypeMap = {
353
465
  [WalletScheme.DKLS]: {
354
466
  [WalletType.EVM]: true,
@@ -370,7 +482,7 @@ function isPregenIdentifierMatch(a, b, type) {
370
482
  case "EMAIL":
371
483
  return a.toLowerCase() === b.toLowerCase();
372
484
  case "PHONE":
373
- return stringToPhoneNumber(a) === stringToPhoneNumber(b);
485
+ return formatPhoneNumber(a) === formatPhoneNumber(b);
374
486
  case "CUSTOM_ID":
375
487
  return a === b;
376
488
  default:
@@ -420,6 +532,9 @@ function migrateWallet(obj) {
420
532
  }
421
533
  return obj;
422
534
  }
535
+ function supportedWalletTypesEq(a, b) {
536
+ return a.length === b.length && a.every(({ type, optional }, index) => b[index].type === type && b[index].optional === optional);
537
+ }
423
538
 
424
539
  // src/cryptography/utils.ts
425
540
  var rsa = forge.pki.rsa;
@@ -1020,68 +1135,6 @@ var TransactionReviewTimeout = class extends Error {
1020
1135
  }
1021
1136
  };
1022
1137
 
1023
- // src/constants.ts
1024
- var PARA_CORE_VERSION = '1.7.1';
1025
- var PREFIX = "@CAPSULE/";
1026
- var LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
1027
- var LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
1028
- var LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
1029
- var LOCAL_STORAGE_FARCASTER_USERNAME = `${PREFIX}farcasterUsername`;
1030
- var LOCAL_STORAGE_TELEGRAM_USER_ID = `${PREFIX}telegramUserId`;
1031
- var LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID = `${PREFIX}externalWalletUserId`;
1032
- var LOCAL_STORAGE_USER_ID = `${PREFIX}userId`;
1033
- var LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
1034
- var LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
1035
- var LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
1036
- var LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
1037
- var LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
1038
- var SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
1039
- var POLLING_INTERVAL_MS = 2e3;
1040
- var SHORT_POLLING_INTERVAL_MS = 1e3;
1041
-
1042
- // src/utils/listeners.ts
1043
- function storageListener(e) {
1044
- if (!e.url.includes(window.location.origin)) {
1045
- return;
1046
- }
1047
- if (e.key === LOCAL_STORAGE_EXTERNAL_WALLETS) {
1048
- this.updateExternalWalletsFromStorage();
1049
- }
1050
- if (e.key === SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR) {
1051
- this.updateLoginEncryptionKeyPairFromStorage();
1052
- }
1053
- if (e.key === LOCAL_STORAGE_SESSION_COOKIE) {
1054
- this.updateSessionCookieFromStorage();
1055
- }
1056
- if (e.key === LOCAL_STORAGE_CURRENT_WALLET_IDS) {
1057
- this.updateWalletIdsFromStorage();
1058
- }
1059
- if (e.key === LOCAL_STORAGE_WALLETS || e.key === LOCAL_STORAGE_ED25519_WALLETS) {
1060
- this.updateWalletsFromStorage();
1061
- }
1062
- if (e.key === LOCAL_STORAGE_EMAIL) {
1063
- this.updateEmailFromStorage();
1064
- }
1065
- if (e.key === LOCAL_STORAGE_COUNTRY_CODE) {
1066
- this.updateCountryCodeFromStorage();
1067
- }
1068
- if (e.key === LOCAL_STORAGE_PHONE) {
1069
- this.updatePhoneFromStorage();
1070
- }
1071
- if (e.key === LOCAL_STORAGE_USER_ID) {
1072
- this.updateUserIdFromStorage();
1073
- }
1074
- if (e.key === LOCAL_STORAGE_TELEGRAM_USER_ID) {
1075
- this.updateTelegramUserIdFromStorage();
1076
- }
1077
- }
1078
- function setupListeners() {
1079
- if (typeof window !== "undefined" && window.addEventListener && window.location) {
1080
- window.removeEventListener("storage", storageListener.bind(this));
1081
- window.addEventListener("storage", storageListener.bind(this));
1082
- }
1083
- }
1084
-
1085
1138
  // src/ParaCore.ts
1086
1139
  if (typeof global !== "undefined") {
1087
1140
  global.Buffer = global.Buffer || NodeBuffer;
@@ -1093,7 +1146,7 @@ if (typeof global !== "undefined") {
1093
1146
  self.global = self.global || self;
1094
1147
  }
1095
1148
  var { pki, jsbn } = forge3;
1096
- var _supportedWalletTypes, _supportedWalletTypesOpt;
1149
+ var _authInfo, _partner, _ParaCore_instances, assertPartner_fn, toAuthInfo_fn, setAuthInfo_fn, assertIsAuthSet_fn, getPartner_fn;
1097
1150
  var _ParaCore = class _ParaCore {
1098
1151
  /**
1099
1152
  * Constructs a new `ParaCore` instance.
@@ -1103,6 +1156,9 @@ var _ParaCore = class _ParaCore {
1103
1156
  * @returns - A new ParaCore instance.
1104
1157
  */
1105
1158
  constructor(env, apiKey, opts) {
1159
+ __privateAdd(this, _ParaCore_instances);
1160
+ __privateAdd(this, _authInfo);
1161
+ __privateAdd(this, _partner);
1106
1162
  this.isAwaitingAccountCreation = false;
1107
1163
  this.isAwaitingLogin = false;
1108
1164
  this.isAwaitingFarcaster = false;
@@ -1111,14 +1167,15 @@ var _ParaCore = class _ParaCore {
1111
1167
  * 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.
1112
1168
  */
1113
1169
  this.currentWalletIds = {};
1114
- __privateAdd(this, _supportedWalletTypes);
1115
- __privateAdd(this, _supportedWalletTypesOpt);
1116
1170
  this.localStorageGetItem = (key) => {
1117
1171
  return this.platformUtils.localStorage.get(key);
1118
1172
  };
1119
1173
  this.localStorageSetItem = (key, value) => {
1120
1174
  return this.platformUtils.localStorage.set(key, value);
1121
1175
  };
1176
+ this.localStorageRemoveItem = (key) => {
1177
+ return this.platformUtils.localStorage.removeItem(key);
1178
+ };
1122
1179
  this.sessionStorageGetItem = (key) => {
1123
1180
  return this.platformUtils.sessionStorage.get(key);
1124
1181
  };
@@ -1144,32 +1201,35 @@ var _ParaCore = class _ParaCore {
1144
1201
  }
1145
1202
  });
1146
1203
  this.initializeFromStorage = () => {
1147
- this.updateEmailFromStorage();
1148
- this.updateCountryCodeFromStorage();
1149
- this.updatePhoneFromStorage();
1204
+ this.updateExternalWalletsFromStorage();
1205
+ this.updateAuthInfoFromStorage();
1150
1206
  this.updateUserIdFromStorage();
1151
- this.updateTelegramUserIdFromStorage();
1152
1207
  this.updateWalletsFromStorage();
1153
1208
  this.updateWalletIdsFromStorage();
1154
1209
  this.updateSessionCookieFromStorage();
1155
1210
  this.updateLoginEncryptionKeyPairFromStorage();
1156
- this.updateExternalWalletsFromStorage();
1157
1211
  };
1158
- this.updateTelegramUserIdFromStorage = () => {
1159
- this.telegramUserId = this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0;
1212
+ this.updateAuthInfoFromStorage = () => {
1213
+ var _a;
1214
+ const storageAuthInfo = this.localStorageGetItem(LOCAL_STORAGE_AUTH_INFO) || void 0;
1215
+ let authInfo = jsonParse(storageAuthInfo);
1216
+ if (!authInfo) {
1217
+ const authParams = {
1218
+ email: this.localStorageGetItem(LOCAL_STORAGE_EMAIL) || void 0,
1219
+ phone: this.localStorageGetItem(LOCAL_STORAGE_PHONE) || void 0,
1220
+ countryCode: this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE) || void 0,
1221
+ farcasterUsername: this.localStorageGetItem(LOCAL_STORAGE_FARCASTER_USERNAME) || void 0,
1222
+ telegramUserId: this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0,
1223
+ // Using id here since we store the bech32 address for cosmos in the address field of the wallet
1224
+ externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
1225
+ };
1226
+ authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
1227
+ }
1228
+ __privateSet(this, _authInfo, authInfo);
1160
1229
  };
1161
1230
  this.updateUserIdFromStorage = () => {
1162
1231
  this.userId = this.localStorageGetItem(LOCAL_STORAGE_USER_ID) || void 0;
1163
1232
  };
1164
- this.updatePhoneFromStorage = () => {
1165
- this.phone = this.localStorageGetItem(LOCAL_STORAGE_PHONE) || void 0;
1166
- };
1167
- this.updateCountryCodeFromStorage = () => {
1168
- this.countryCode = this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE) || void 0;
1169
- };
1170
- this.updateEmailFromStorage = () => {
1171
- this.email = this.localStorageGetItem(LOCAL_STORAGE_EMAIL) || void 0;
1172
- };
1173
1233
  this.updateWalletsFromStorage = () => __async(this, null, function* () {
1174
1234
  var _a;
1175
1235
  const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
@@ -1199,7 +1259,7 @@ var _ParaCore = class _ParaCore {
1199
1259
  this.updateWalletIdsFromStorage = () => {
1200
1260
  var _a;
1201
1261
  const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
1202
- const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
1262
+ const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
1203
1263
  const fromJson = JSON.parse(_currentWalletIds);
1204
1264
  return Array.isArray(fromJson) ? Object.keys(WalletType2).reduce((acc, type) => {
1205
1265
  const wallet = Object.values(this.wallets).find(
@@ -1236,6 +1296,9 @@ var _ParaCore = class _ParaCore {
1236
1296
  * @deprecated alias for `createWalletPerType`
1237
1297
  **/
1238
1298
  this.createWalletPerMissingType = this.createWalletPerType;
1299
+ if (!apiKey) {
1300
+ throw new Error("A Para API key is required.");
1301
+ }
1239
1302
  if (!opts) opts = {};
1240
1303
  let isE2E = false;
1241
1304
  if (env === "E2E") {
@@ -1293,72 +1356,87 @@ var _ParaCore = class _ParaCore {
1293
1356
  useDKLS: opts.useDKLSForCreation || !opts.offloadMPCComputationURL,
1294
1357
  disableWebSockets: !!opts.disableWebSockets,
1295
1358
  wasmOverride: opts.wasmOverride,
1296
- cosmosPrefix: this.cosmosPrefix,
1297
1359
  isE2E
1298
1360
  };
1299
1361
  if (opts.offloadMPCComputationURL) {
1300
1362
  this.ctx.mpcComputationClient = initClient2(opts.offloadMPCComputationURL, opts.disableWorkers);
1301
1363
  }
1302
- try {
1303
- __privateSet(this, _supportedWalletTypes, opts.supportedWalletTypes ? (() => {
1304
- if (Object.values(opts.supportedWalletTypes).every(
1305
- (config) => !!config && typeof config === "object" && config.optional
1306
- )) {
1307
- throw new Error("at least one wallet type must be non-optional");
1308
- }
1309
- if (!Object.keys(opts.supportedWalletTypes).every((type) => Object.values(WalletType2).includes(type))) {
1310
- throw new Error("unsupported wallet type");
1311
- }
1312
- __privateSet(this, _supportedWalletTypesOpt, opts.supportedWalletTypes);
1313
- return Object.entries(opts.supportedWalletTypes).reduce((acc, [key, value]) => {
1314
- var _a;
1315
- if (!value) {
1316
- return acc;
1317
- }
1318
- if (key === WalletType2.COSMOS && typeof value === "object" && !!value.prefix) {
1319
- this.cosmosPrefix = value.prefix;
1320
- }
1321
- return [...acc, { type: key, optional: value === true ? false : (_a = value.optional) != null ? _a : false }];
1322
- }, []);
1323
- })() : void 0);
1324
- } catch (e) {
1325
- __privateSet(this, _supportedWalletTypes, void 0);
1326
- }
1327
1364
  if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
1328
1365
  return;
1329
1366
  }
1330
1367
  this.initializeFromStorage();
1331
1368
  setupListeners.bind(this)();
1369
+ autoBind(this);
1332
1370
  }
1333
- get isEmail() {
1334
- return !!this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.telegramUserId && !this.externalWalletWithParaAuth;
1371
+ get authInfo() {
1372
+ return __privateGet(this, _authInfo);
1335
1373
  }
1336
- get isPhone() {
1337
- return !!this.phone && !!this.countryCode && !this.email && !this.farcasterUsername && !this.telegramUserId && !this.externalWalletWithParaAuth;
1374
+ get email() {
1375
+ var _a;
1376
+ return isEmail((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.email : void 0;
1338
1377
  }
1339
- get isFarcaster() {
1340
- return !!this.farcasterUsername && !this.email && !this.phone && !this.countryCode && !this.telegramUserId && !this.externalWalletWithParaAuth;
1378
+ get phone() {
1379
+ var _a;
1380
+ return isPhone((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.phone : void 0;
1341
1381
  }
1342
- get isTelegram() {
1343
- return !!this.telegramUserId && !this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.externalWalletWithParaAuth;
1382
+ get farcasterUsername() {
1383
+ var _a;
1384
+ return isFarcaster((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.farcasterUsername : void 0;
1385
+ }
1386
+ get telegramUserId() {
1387
+ var _a;
1388
+ return isTelegram((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.telegramUserId : void 0;
1344
1389
  }
1345
1390
  get externalWalletWithParaAuth() {
1346
1391
  const externalWallets = Object.values(this.externalWallets);
1347
1392
  return externalWallets.find((w) => w.isExternalWithParaAuth);
1348
1393
  }
1394
+ get externalWalletConnectionType() {
1395
+ if (this.isExternalWalletAuth) {
1396
+ return "AUTHENTICATED";
1397
+ } else if (!!Object.keys(this.externalWallets).length) {
1398
+ return "CONNECTION_ONLY";
1399
+ }
1400
+ return "NONE";
1401
+ }
1402
+ get isEmail() {
1403
+ var _a;
1404
+ return isEmail((_a = this.authInfo) == null ? void 0 : _a.auth);
1405
+ }
1406
+ get isPhone() {
1407
+ var _a;
1408
+ return isPhone((_a = this.authInfo) == null ? void 0 : _a.auth);
1409
+ }
1410
+ get isFarcaster() {
1411
+ var _a;
1412
+ return isFarcaster((_a = this.authInfo) == null ? void 0 : _a.auth);
1413
+ }
1414
+ get isTelegram() {
1415
+ var _a;
1416
+ return isTelegram((_a = this.authInfo) == null ? void 0 : _a.auth);
1417
+ }
1349
1418
  get isExternalWalletAuth() {
1350
- return !!this.externalWalletWithParaAuth && !this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.telegramUserId;
1419
+ var _a;
1420
+ return isExternalWallet((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth);
1421
+ }
1422
+ get partnerId() {
1423
+ var _a;
1424
+ return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id;
1351
1425
  }
1352
1426
  get currentWalletIdsArray() {
1353
- return this.supportedWalletTypes.reduce((acc, { type }) => {
1354
- var _a;
1355
- return [
1356
- ...acc,
1357
- ...((_a = this.currentWalletIds[type]) != null ? _a : []).map((id) => {
1358
- return [id, type];
1359
- })
1360
- ];
1361
- }, []);
1427
+ var _a, _b;
1428
+ return ((_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
1429
+ (acc, { type }) => {
1430
+ var _a2;
1431
+ return [
1432
+ ...acc,
1433
+ ...((_a2 = this.currentWalletIds[type]) != null ? _a2 : []).map((id) => {
1434
+ return [id, type];
1435
+ })
1436
+ ];
1437
+ },
1438
+ []
1439
+ );
1362
1440
  }
1363
1441
  get currentWalletIdsUnique() {
1364
1442
  return [...new Set(Object.values(this.currentWalletIds).flat())];
@@ -1386,11 +1464,16 @@ var _ParaCore = class _ParaCore {
1386
1464
  return this.currentWalletIdsArray.length > 1;
1387
1465
  }
1388
1466
  get supportedWalletTypes() {
1467
+ var _a, _b;
1468
+ return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
1469
+ }
1470
+ get cosmosPrefix() {
1389
1471
  var _a;
1390
- return (_a = __privateGet(this, _supportedWalletTypes)) != null ? _a : [];
1472
+ return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
1391
1473
  }
1392
1474
  get isWalletTypeEnabled() {
1393
- return this.supportedWalletTypes.reduce((acc, { type }) => {
1475
+ var _a;
1476
+ return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
1394
1477
  return __spreadProps(__spreadValues({}, acc), { [type]: true });
1395
1478
  }, {});
1396
1479
  }
@@ -1439,7 +1522,7 @@ var _ParaCore = class _ParaCore {
1439
1522
  }
1440
1523
  isWalletSupported(wallet) {
1441
1524
  var _a, _b;
1442
- return !__privateGet(this, _supportedWalletTypes) || isWalletSupported((_b = (_a = this.supportedWalletTypes) == null ? void 0 : _a.map(({ type }) => type)) != null ? _b : [], wallet);
1525
+ return !((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = __privateGet(this, _partner).supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
1443
1526
  }
1444
1527
  isWalletOwned(wallet) {
1445
1528
  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;
@@ -1455,7 +1538,7 @@ var _ParaCore = class _ParaCore {
1455
1538
  ));
1456
1539
  }
1457
1540
  isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
1458
- var _a;
1541
+ var _a, _b;
1459
1542
  let error;
1460
1543
  if ((_a = this.externalWallets) == null ? void 0 : _a[walletId]) {
1461
1544
  return true;
@@ -1470,10 +1553,10 @@ var _ParaCore = class _ParaCore {
1470
1553
  } else if (!isOwned && !isUnclaimed) {
1471
1554
  error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
1472
1555
  } else if (!this.isWalletSupported(wallet)) {
1473
- 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(", ")}`;
1556
+ 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(", ")}`;
1474
1557
  } else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
1475
- var _a2, _b;
1476
- return (_b = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b.includes(walletId);
1558
+ var _a2, _b2;
1559
+ return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
1477
1560
  }))) {
1478
1561
  error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
1479
1562
  } else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
@@ -1497,10 +1580,10 @@ var _ParaCore = class _ParaCore {
1497
1580
  * @returns the formatted address
1498
1581
  */
1499
1582
  getDisplayAddress(walletId, options = {}) {
1500
- var _a;
1583
+ var _a, _b, _c, _d;
1501
1584
  if (this.externalWallets[walletId]) {
1502
1585
  const wallet2 = this.externalWallets[walletId];
1503
- return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: this.cosmosPrefix }) : wallet2.address;
1586
+ return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix }) : wallet2.address;
1504
1587
  }
1505
1588
  const wallet = this.findWallet(walletId, options.addressType);
1506
1589
  if (!wallet) {
@@ -1509,13 +1592,13 @@ var _ParaCore = class _ParaCore {
1509
1592
  let str;
1510
1593
  switch (wallet.type) {
1511
1594
  case WalletType2.COSMOS:
1512
- str = getCosmosAddress(wallet.publicKey, (_a = this.cosmosPrefix) != null ? _a : "cosmos");
1595
+ str = getCosmosAddress(wallet.publicKey, (_c = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix) != null ? _c : "cosmos");
1513
1596
  break;
1514
1597
  default:
1515
1598
  str = wallet.address;
1516
1599
  break;
1517
1600
  }
1518
- return options.truncate ? truncateAddress(str, wallet.type, { prefix: this.cosmosPrefix }) : str;
1601
+ return options.truncate ? truncateAddress(str, wallet.type, { prefix: (_d = __privateGet(this, _partner)) == null ? void 0 : _d.cosmosPrefix }) : str;
1519
1602
  }
1520
1603
  /**
1521
1604
  * Returns a unique hash for a wallet suitable for use as an identicon seed.
@@ -1540,8 +1623,20 @@ var _ParaCore = class _ParaCore {
1540
1623
  }
1541
1624
  constructPortalUrl(_0) {
1542
1625
  return __async(this, arguments, function* (type, opts = {}) {
1543
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1544
- const base = type === "onRamp" ? getPortalBaseURL(this.ctx) : yield this.getPortalURL(opts.partnerId);
1626
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1627
+ const [isCreate, isLogin, isOnRamp] = [
1628
+ ["createAuth", "createPassword"].includes(type),
1629
+ ["loginAuth", "loginPassword"].includes(type),
1630
+ type === "onRamp"
1631
+ ];
1632
+ let auth;
1633
+ if (isCreate || isLogin) {
1634
+ auth = __privateMethod(this, _ParaCore_instances, assertIsAuthSet_fn).call(this);
1635
+ }
1636
+ if ((isLogin || isOnRamp) && !opts.sessionId) {
1637
+ opts.sessionId = (yield this.touchSession()).sessionLookupId;
1638
+ }
1639
+ const base = isOnRamp ? getPortalBaseURL(this.ctx) : yield this.getPortalURL();
1545
1640
  let path;
1546
1641
  switch (type) {
1547
1642
  case "createPassword": {
@@ -1572,30 +1667,21 @@ var _ParaCore = class _ParaCore {
1572
1667
  throw new Error(`invalid URL type ${type}`);
1573
1668
  }
1574
1669
  }
1575
- const [isCreate, isLogin, isOnRamp] = [
1576
- ["createAuth", "createPassword"].includes(type),
1577
- ["loginAuth", "loginPassword"].includes(type),
1578
- type === "onRamp"
1579
- ];
1580
- const partner = opts.partnerId ? (_a = (yield this.ctx.client.getPartner(opts.partnerId)).data) == null ? void 0 : _a.partner : void 0;
1670
+ const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
1581
1671
  const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
1582
1672
  apiKey: this.ctx.apiKey,
1583
- partnerId: opts.partnerId,
1584
- portalFont: ((_b = opts.theme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
1585
- portalBorderRadius: ((_d = opts.theme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
1586
- portalThemeMode: ((_f = opts.theme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
1587
- portalAccentColor: ((_h = opts.theme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
1588
- portalForegroundColor: ((_j = opts.theme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
1589
- 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),
1673
+ partnerId: partner.id,
1674
+ portalFont: ((_a = opts.theme) == null ? void 0 : _a.font) || (partner == null ? void 0 : partner.font) || ((_b = this.portalTheme) == null ? void 0 : _b.font),
1675
+ portalBorderRadius: ((_c = opts.theme) == null ? void 0 : _c.borderRadius) || ((_d = this.portalTheme) == null ? void 0 : _d.borderRadius),
1676
+ portalThemeMode: ((_e = opts.theme) == null ? void 0 : _e.mode) || (partner == null ? void 0 : partner.themeMode) || ((_f = this.portalTheme) == null ? void 0 : _f.mode),
1677
+ portalAccentColor: ((_g = opts.theme) == null ? void 0 : _g.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_h = this.portalTheme) == null ? void 0 : _h.accentColor),
1678
+ portalForegroundColor: ((_i = opts.theme) == null ? void 0 : _i.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_j = this.portalTheme) == null ? void 0 : _j.foregroundColor),
1679
+ 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),
1590
1680
  portalPrimaryButtonColor: this.portalPrimaryButtonColor,
1591
1681
  portalTextColor: this.portalTextColor,
1592
1682
  portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
1593
- isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0,
1594
- supportedWalletTypes: __privateGet(this, _supportedWalletTypesOpt) ? JSON.stringify(__privateGet(this, _supportedWalletTypesOpt)) : void 0
1595
- }, 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" ? {
1596
- // Using id here since we store the bech32 address for cosmos in the address field of the wallet
1597
- externalWalletAddress: (_n = this.externalWalletWithParaAuth) == null ? void 0 : _n.id
1598
- } : {}) : {}), isLogin || isOnRamp ? { sessionId: opts.sessionId } : {}), isLogin ? {
1683
+ isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
1684
+ }, auth && (isCreate || isLogin) ? auth : {}), isLogin || isOnRamp ? { sessionId: opts.sessionId } : {}), isLogin ? {
1599
1685
  encryptionKey: opts.loginEncryptionPublicKey,
1600
1686
  newDeviceSessionLookupId: opts.newDeviceSessionId,
1601
1687
  newDeviceEncryptionKey: opts.newDeviceEncryptionKey,
@@ -1608,25 +1694,14 @@ var _ParaCore = class _ParaCore {
1608
1694
  }
1609
1695
  touchSession(regenerate = false) {
1610
1696
  return __async(this, null, function* () {
1611
- const res = yield this.ctx.client.touchSession(regenerate);
1612
- this.setSupportedWalletTypes(res.data.supportedWalletTypes, res.data.cosmosPrefix);
1613
- return res;
1697
+ var _a, _b, _c;
1698
+ const session = yield this.ctx.client.touchSession(regenerate);
1699
+ 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) {
1700
+ yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
1701
+ }
1702
+ return session;
1614
1703
  });
1615
1704
  }
1616
- setSupportedWalletTypes(supportedWalletTypes, cosmosPrefix) {
1617
- if (supportedWalletTypes && !__privateGet(this, _supportedWalletTypes)) {
1618
- __privateSet(this, _supportedWalletTypes, supportedWalletTypes);
1619
- Object.keys(this.currentWalletIds).forEach((type) => {
1620
- var _a;
1621
- if (!((_a = __privateGet(this, _supportedWalletTypes)) == null ? void 0 : _a.some(({ type: supportedType }) => supportedType === type))) {
1622
- delete this.currentWalletIds[type];
1623
- }
1624
- });
1625
- }
1626
- if (cosmosPrefix && !this.cosmosPrefix) {
1627
- this.cosmosPrefix = cosmosPrefix;
1628
- }
1629
- }
1630
1705
  getVerificationEmailProps() {
1631
1706
  return {
1632
1707
  brandColor: this.emailPrimaryColor,
@@ -1656,12 +1731,26 @@ var _ParaCore = class _ParaCore {
1656
1731
  */
1657
1732
  init() {
1658
1733
  return __async(this, null, function* () {
1659
- var _a;
1660
- this.email = (yield this.localStorageGetItem(LOCAL_STORAGE_EMAIL)) || void 0;
1661
- this.countryCode = (yield this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE)) || void 0;
1662
- this.phone = (yield this.localStorageGetItem(LOCAL_STORAGE_PHONE)) || void 0;
1734
+ var _a, _b;
1663
1735
  this.userId = (yield this.localStorageGetItem(LOCAL_STORAGE_USER_ID)) || void 0;
1664
- this.telegramUserId = (yield this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0;
1736
+ const storageAuthInfo = (yield this.localStorageGetItem(LOCAL_STORAGE_AUTH_INFO)) || void 0;
1737
+ const stringExternalWallets = yield this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
1738
+ const _externalWallets = JSON.parse(stringExternalWallets || "{}");
1739
+ yield this.setExternalWallets(_externalWallets);
1740
+ let authInfo = jsonParse(storageAuthInfo);
1741
+ if (!authInfo) {
1742
+ const authParams = {
1743
+ email: (yield this.localStorageGetItem(LOCAL_STORAGE_EMAIL)) || void 0,
1744
+ phone: (yield this.localStorageGetItem(LOCAL_STORAGE_PHONE)) || void 0,
1745
+ countryCode: (yield this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE)) || void 0,
1746
+ farcasterUsername: (yield this.localStorageGetItem(LOCAL_STORAGE_FARCASTER_USERNAME)) || void 0,
1747
+ telegramUserId: (yield this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0,
1748
+ // Using id here since we store the bech32 address for cosmos in the address field of the wallet
1749
+ externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
1750
+ };
1751
+ authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
1752
+ }
1753
+ __privateSet(this, _authInfo, authInfo);
1665
1754
  const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_WALLETS);
1666
1755
  const _wallets = JSON.parse(stringWallets || "{}");
1667
1756
  const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_ED25519_WALLETS);
@@ -1674,7 +1763,7 @@ var _ParaCore = class _ParaCore {
1674
1763
  return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
1675
1764
  }, {}));
1676
1765
  yield this.setWallets(wallets);
1677
- const _currentWalletIds = (_a = yield this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
1766
+ const _currentWalletIds = (_b = yield this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _b : void 0;
1678
1767
  const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
1679
1768
  const fromJson = JSON.parse(_currentWalletIds);
1680
1769
  return Array.isArray(fromJson) ? Object.keys(WalletType2).reduce((acc, type) => {
@@ -1693,21 +1782,27 @@ var _ParaCore = class _ParaCore {
1693
1782
  if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
1694
1783
  this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
1695
1784
  }
1696
- const stringExternalWallets = yield this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
1697
- const _externalWallets = JSON.parse(stringExternalWallets || "{}");
1698
- yield this.setExternalWallets(_externalWallets);
1699
1785
  setupListeners.bind(this)();
1700
1786
  yield this.touchSession();
1701
1787
  });
1702
1788
  }
1789
+ setAuth(_0) {
1790
+ return __async(this, arguments, function* (auth, { extras = {}, userId } = {}) {
1791
+ const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), extras || {});
1792
+ yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
1793
+ if (!!userId) {
1794
+ yield this.setUserId(userId);
1795
+ }
1796
+ return __privateGet(this, _authInfo);
1797
+ });
1798
+ }
1703
1799
  /**
1704
1800
  * Sets the email associated with the `ParaCore` instance.
1705
1801
  * @param email - Email to set.
1706
1802
  */
1707
1803
  setEmail(email) {
1708
1804
  return __async(this, null, function* () {
1709
- this.email = email;
1710
- yield this.localStorageSetItem(LOCAL_STORAGE_EMAIL, email);
1805
+ yield this.setAuth({ email });
1711
1806
  });
1712
1807
  }
1713
1808
  /**
@@ -1716,8 +1811,7 @@ var _ParaCore = class _ParaCore {
1716
1811
  */
1717
1812
  setTelegramUserId(telegramUserId) {
1718
1813
  return __async(this, null, function* () {
1719
- this.telegramUserId = telegramUserId;
1720
- yield this.localStorageSetItem(LOCAL_STORAGE_TELEGRAM_USER_ID, telegramUserId);
1814
+ yield this.setAuth({ telegramUserId });
1721
1815
  });
1722
1816
  }
1723
1817
  /**
@@ -1727,10 +1821,7 @@ var _ParaCore = class _ParaCore {
1727
1821
  */
1728
1822
  setPhoneNumber(phone, countryCode) {
1729
1823
  return __async(this, null, function* () {
1730
- this.phone = phone;
1731
- this.countryCode = countryCode;
1732
- yield this.localStorageSetItem(LOCAL_STORAGE_PHONE, phone);
1733
- yield this.localStorageSetItem(LOCAL_STORAGE_COUNTRY_CODE, countryCode);
1824
+ yield this.setAuth({ phone: formatPhoneNumber(phone, countryCode) });
1734
1825
  });
1735
1826
  }
1736
1827
  /**
@@ -1739,8 +1830,7 @@ var _ParaCore = class _ParaCore {
1739
1830
  */
1740
1831
  setFarcasterUsername(farcasterUsername) {
1741
1832
  return __async(this, null, function* () {
1742
- this.farcasterUsername = farcasterUsername;
1743
- yield this.localStorageSetItem(LOCAL_STORAGE_FARCASTER_USERNAME, farcasterUsername);
1833
+ yield this.setAuth({ farcasterUsername });
1744
1834
  });
1745
1835
  }
1746
1836
  /**
@@ -1832,22 +1922,12 @@ var _ParaCore = class _ParaCore {
1832
1922
  getEmail() {
1833
1923
  return this.email;
1834
1924
  }
1835
- /**
1836
- * Gets the phone object associated with the `ParaCore` instance.
1837
- * @returns - phone object with phone number and country code associated with the `ParaCore` instance.
1838
- */
1839
- getPhone() {
1840
- return { phone: this.phone, countryCode: this.countryCode };
1841
- }
1842
1925
  /**
1843
1926
  * Gets the formatted phone number associated with the `ParaCore` instance.
1844
1927
  * @returns - formatted phone number associated with the `ParaCore` instance.
1845
1928
  */
1846
1929
  getPhoneNumber() {
1847
- if (!this.phone || !this.countryCode) {
1848
- return void 0;
1849
- }
1850
- return normalizePhoneNumber(this.countryCode, this.phone);
1930
+ return this.phone;
1851
1931
  }
1852
1932
  /**
1853
1933
  * Gets the farcaster username associated with the `ParaCore` instance.
@@ -1876,23 +1956,6 @@ var _ParaCore = class _ParaCore {
1876
1956
  dispatchEvent(ParaEvent.WALLETS_CHANGE_EVENT, null);
1877
1957
  });
1878
1958
  }
1879
- /**
1880
- * Fetches the most recent OAuth account metadata for the signed-in user.
1881
- * 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.
1882
- * @returns {Promise<AccountMetadata>} the user's account metadata.
1883
- */
1884
- getAccountMetadata() {
1885
- return __async(this, null, function* () {
1886
- if (!(yield this.isSessionActive()) || !this.userId) {
1887
- throw new Error("no signed-in user");
1888
- }
1889
- const {
1890
- data: { partnerId }
1891
- } = yield this.touchSession();
1892
- const { accountMetadata } = yield this.ctx.client.getAccountMetadata(this.userId, partnerId);
1893
- return accountMetadata;
1894
- });
1895
- }
1896
1959
  /**
1897
1960
  * Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
1898
1961
  * If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
@@ -1946,8 +2009,10 @@ var _ParaCore = class _ParaCore {
1946
2009
  }
1947
2010
  findWallet(idOrAddress, overrideType, filter = {}) {
1948
2011
  var _a, _c, _d;
1949
- if (!this.isExternalWalletAuth && !idOrAddress && Object.keys(this.externalWallets).length > 0) {
1950
- return Object.values(this.externalWallets)[0];
2012
+ if (!this.isExternalWalletAuth) {
2013
+ if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
2014
+ return Object.values(this.externalWallets)[0];
2015
+ }
1951
2016
  }
1952
2017
  if ((_a = this.externalWallets) == null ? void 0 : _a[idOrAddress]) {
1953
2018
  return this.externalWallets[idOrAddress];
@@ -1994,10 +2059,8 @@ var _ParaCore = class _ParaCore {
1994
2059
  }
1995
2060
  assertIsValidWalletType(type, walletTypes) {
1996
2061
  return __async(this, null, function* () {
1997
- if (!__privateGet(this, _supportedWalletTypes)) {
1998
- yield this.touchSession();
1999
- }
2000
- if (!type || !Object.values(WalletType2).includes(type) || !(walletTypes != null ? walletTypes : this.supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
2062
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2063
+ if (!type || !Object.values(WalletType2).includes(type) || !(walletTypes != null ? walletTypes : supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
2001
2064
  throw new Error(`wallet type ${type} is not supported`);
2002
2065
  }
2003
2066
  return type;
@@ -2005,33 +2068,29 @@ var _ParaCore = class _ParaCore {
2005
2068
  }
2006
2069
  getMissingTypes() {
2007
2070
  return __async(this, null, function* () {
2008
- if (!__privateGet(this, _supportedWalletTypes)) {
2009
- yield this.touchSession();
2010
- }
2011
- return this.supportedWalletTypes.filter(
2071
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2072
+ return supportedWalletTypes.filter(
2012
2073
  ({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
2013
2074
  ).map(({ type }) => type);
2014
2075
  });
2015
2076
  }
2016
2077
  getTypesToCreate(types) {
2017
2078
  return __async(this, null, function* () {
2018
- if (!__privateGet(this, _supportedWalletTypes)) {
2019
- yield this.touchSession();
2020
- }
2079
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2021
2080
  return getSchemes(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
2022
2081
  switch (scheme) {
2023
2082
  case WalletScheme2.ED25519:
2024
2083
  return WalletType2.SOLANA;
2025
2084
  default:
2026
- return this.supportedWalletTypes.some(({ type, optional }) => type === WalletType2.COSMOS && !optional) ? WalletType2.COSMOS : WalletType2.EVM;
2085
+ return supportedWalletTypes.some(({ type, optional }) => type === WalletType2.COSMOS && !optional) ? WalletType2.COSMOS : WalletType2.EVM;
2027
2086
  }
2028
2087
  });
2029
2088
  });
2030
2089
  }
2031
- getPartnerURL(partnerId) {
2090
+ getPartnerURL() {
2032
2091
  return __async(this, null, function* () {
2033
- const res = yield this.ctx.client.getPartner(partnerId);
2034
- return res.data.partner.portalUrl;
2092
+ const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2093
+ return portalUrl;
2035
2094
  });
2036
2095
  }
2037
2096
  /**
@@ -2039,9 +2098,9 @@ var _ParaCore = class _ParaCore {
2039
2098
  * @param partnerId: string - id of the partner to get the portal URL for
2040
2099
  * @returns - portal URL
2041
2100
  */
2042
- getPortalURL(partnerId) {
2101
+ getPortalURL() {
2043
2102
  return __async(this, null, function* () {
2044
- return partnerId && (yield this.getPartnerURL(partnerId)) || getPortalBaseURL(this.ctx);
2103
+ return (yield this.getPartnerURL()) || getPortalBaseURL(this.ctx);
2045
2104
  });
2046
2105
  }
2047
2106
  getWebAuthURLForCreate(_a) {
@@ -2188,9 +2247,9 @@ var _ParaCore = class _ParaCore {
2188
2247
  * @param {string} opts.countryCode - the country code.
2189
2248
  * @returns true if user exists, false otherwise.
2190
2249
  */
2191
- checkIfUserExistsByPhone(_0) {
2192
- return __async(this, arguments, function* ({ phone, countryCode }) {
2193
- const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
2250
+ checkIfUserExistsByPhone(auth) {
2251
+ return __async(this, null, function* () {
2252
+ const res = yield this.ctx.client.checkUserExists(auth);
2194
2253
  return res.data.exists;
2195
2254
  });
2196
2255
  }
@@ -2215,14 +2274,11 @@ var _ParaCore = class _ParaCore {
2215
2274
  * @param {string} opts.phone - the phone number to use for creating the user.
2216
2275
  * @param {string} opts.countryCode - the country code to use for creating the user.
2217
2276
  */
2218
- createUserByPhone(_0) {
2219
- return __async(this, arguments, function* ({ phone, countryCode }) {
2277
+ createUserByPhone(auth) {
2278
+ return __async(this, null, function* () {
2220
2279
  this.requireApiKey();
2221
- yield this.setPhoneNumber(phone, countryCode);
2222
- const { userId } = yield this.ctx.client.createUser({
2223
- phone: this.phone,
2224
- countryCode: this.countryCode
2225
- });
2280
+ yield this.setPhoneNumber(auth.phone);
2281
+ const { userId } = yield this.ctx.client.createUser(auth);
2226
2282
  yield this.setUserId(userId);
2227
2283
  });
2228
2284
  }
@@ -2248,12 +2304,6 @@ var _ParaCore = class _ParaCore {
2248
2304
  return res;
2249
2305
  });
2250
2306
  }
2251
- /**
2252
- * Returns whether or not the user is connected with only an external wallet, not an external wallet with Para auth.
2253
- */
2254
- isUsingExternalWallet() {
2255
- return !this.isExternalWalletAuth && !!Object.keys(this.externalWallets).length;
2256
- }
2257
2307
  /**
2258
2308
  * Passes the email code obtained from the user for verification.
2259
2309
  * @param {Object} opts the options object
@@ -2274,7 +2324,7 @@ var _ParaCore = class _ParaCore {
2274
2324
  cosmosSigner
2275
2325
  }) {
2276
2326
  yield this.ctx.client.verifyExternalWallet(this.userId, { address, signedMessage, cosmosPublicKeyHex, cosmosSigner });
2277
- return this.getSetUpBiometricsURL({ authType: "externalWallet" });
2327
+ return this.getSetUpBiometricsURL({ authType: __privateGet(this, _authInfo).authType });
2278
2328
  });
2279
2329
  }
2280
2330
  /**
@@ -2299,8 +2349,19 @@ var _ParaCore = class _ParaCore {
2299
2349
  return __async(this, null, function* () {
2300
2350
  const res = yield this.ctx.client.verifyTelegram(authObject);
2301
2351
  if (res.isValid) {
2302
- yield this.setUserId(res.userId);
2303
- yield this.setTelegramUserId(res.telegramUserId);
2352
+ const { userId, telegramUserId } = res;
2353
+ const { photo_url: pfpUrl, username, first_name: firstName, last_name: lastName } = authObject;
2354
+ yield this.setAuth(
2355
+ { telegramUserId },
2356
+ {
2357
+ extras: {
2358
+ pfpUrl,
2359
+ username,
2360
+ displayName: firstName ? `${firstName}${lastName ? ` ${lastName}` : ""}` : username ? `@${username}` : void 0
2361
+ },
2362
+ userId
2363
+ }
2364
+ );
2304
2365
  yield this.touchSession(true);
2305
2366
  if (!this.loginEncryptionKeyPair) {
2306
2367
  yield this.setLoginEncryptionKeyPair();
@@ -2338,10 +2399,9 @@ var _ParaCore = class _ParaCore {
2338
2399
  verify2FAForPhone(_0) {
2339
2400
  return __async(this, arguments, function* ({
2340
2401
  phone,
2341
- countryCode,
2342
2402
  verificationCode
2343
2403
  }) {
2344
- const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
2404
+ const res = yield this.ctx.client.verify2FAForPhone(phone, verificationCode);
2345
2405
  return {
2346
2406
  initiatedAt: res.data.initiatedAt,
2347
2407
  status: res.data.status,
@@ -2485,11 +2545,11 @@ var _ParaCore = class _ParaCore {
2485
2545
  */
2486
2546
  isSessionActive() {
2487
2547
  return __async(this, null, function* () {
2488
- if (this.isUsingExternalWallet()) {
2548
+ if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
2489
2549
  return true;
2490
2550
  }
2491
- const res = yield this.touchSession();
2492
- return !!res.data.isAuthenticated;
2551
+ const { isAuthenticated } = yield this.touchSession();
2552
+ return !!isAuthenticated;
2493
2553
  });
2494
2554
  }
2495
2555
  /**
@@ -2498,7 +2558,7 @@ var _ParaCore = class _ParaCore {
2498
2558
  **/
2499
2559
  isFullyLoggedIn() {
2500
2560
  return __async(this, null, function* () {
2501
- if (this.isUsingExternalWallet()) {
2561
+ if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
2502
2562
  return true;
2503
2563
  }
2504
2564
  const isSessionActive = yield this.isSessionActive();
@@ -2528,44 +2588,8 @@ var _ParaCore = class _ParaCore {
2528
2588
  */
2529
2589
  getUserBiometricLocationHints() {
2530
2590
  return __async(this, null, function* () {
2531
- var _a;
2532
- if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId && !this.isExternalWalletAuth) {
2533
- throw new Error(
2534
- "one of email, phone, farcaster username, telegram user id or external wallet with Para auth are required to get biometric location hints"
2535
- );
2536
- }
2537
- return yield this.ctx.client.getBiometricLocationHints({
2538
- email: this.email,
2539
- phone: this.phone,
2540
- countryCode: this.countryCode,
2541
- farcasterUsername: this.farcasterUsername,
2542
- telegramUserId: this.telegramUserId,
2543
- // Using id here since we store the bech32 address for cosmos in the address field of the wallet
2544
- externalWalletAddress: (_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id
2545
- });
2546
- });
2547
- }
2548
- setAuth(auth) {
2549
- return __async(this, null, function* () {
2550
- const authInfo = extractAuthInfo(auth);
2551
- if (!authInfo) {
2552
- return void 0;
2553
- }
2554
- switch (authInfo.authType) {
2555
- case "email":
2556
- yield this.setEmail(authInfo.identifier);
2557
- break;
2558
- case "phone":
2559
- yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
2560
- break;
2561
- case "farcaster":
2562
- yield this.setFarcasterUsername(authInfo.identifier);
2563
- break;
2564
- case "telegram":
2565
- yield this.setTelegramUserId(authInfo.identifier);
2566
- break;
2567
- }
2568
- return authInfo;
2591
+ const auth = __privateMethod(this, _ParaCore_instances, assertIsAuthSet_fn).call(this);
2592
+ return yield this.ctx.client.getBiometricLocationHints(auth);
2569
2593
  });
2570
2594
  }
2571
2595
  /**
@@ -2582,14 +2606,14 @@ var _ParaCore = class _ParaCore {
2582
2606
  if (!authInfo) {
2583
2607
  return;
2584
2608
  }
2585
- const res = yield this.touchSession(true);
2609
+ const { partnerId, sessionId } = yield this.touchSession(true);
2586
2610
  if (!this.loginEncryptionKeyPair) {
2587
2611
  yield this.setLoginEncryptionKeyPair();
2588
2612
  }
2589
2613
  const webAuthLoginURL = yield this.getWebAuthURLForLogin({
2590
2614
  authType: authInfo.authType,
2591
- sessionId: res.data.sessionId,
2592
- partnerId: res.data.partnerId,
2615
+ sessionId,
2616
+ partnerId,
2593
2617
  loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
2594
2618
  });
2595
2619
  if (!useShortUrl) {
@@ -2605,7 +2629,10 @@ var _ParaCore = class _ParaCore {
2605
2629
  **/
2606
2630
  initiateUserLoginV2(auth) {
2607
2631
  return __async(this, null, function* () {
2608
- const authInfo = yield this.setAuth(auth);
2632
+ let authInfo = __privateGet(this, _authInfo);
2633
+ if (!authInfo || JSON.stringify(authInfo.auth) !== JSON.stringify(auth)) {
2634
+ authInfo = yield this.setAuth(auth);
2635
+ }
2609
2636
  if (!authInfo) {
2610
2637
  return;
2611
2638
  }
@@ -2632,14 +2659,14 @@ var _ParaCore = class _ParaCore {
2632
2659
  "useShortUrl"
2633
2660
  ]);
2634
2661
  yield this.setAuth(auth);
2635
- const res = yield this.touchSession(true);
2662
+ const { sessionId, partnerId } = yield this.touchSession(true);
2636
2663
  if (!this.loginEncryptionKeyPair) {
2637
2664
  yield this.setLoginEncryptionKeyPair();
2638
2665
  }
2639
2666
  const webAuthLoginURL = yield this.getWebAuthURLForLoginForPhone({
2640
- sessionId: res.data.sessionId,
2667
+ sessionId,
2641
2668
  loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair),
2642
- partnerId: res.data.partnerId
2669
+ partnerId
2643
2670
  });
2644
2671
  if (!useShortUrl) {
2645
2672
  return webAuthLoginURL;
@@ -2682,11 +2709,12 @@ var _ParaCore = class _ParaCore {
2682
2709
  popupWindow
2683
2710
  } = {}) {
2684
2711
  yield this.waitForAccountCreation({ popupWindow });
2712
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2685
2713
  const pregenWallets = yield this.getPregenWallets();
2686
2714
  let recoverySecret, walletIds = {};
2687
2715
  if (pregenWallets.length > 0) {
2688
2716
  recoverySecret = yield this.claimPregenWallets();
2689
- walletIds = this.supportedWalletTypes.reduce((acc, { type }) => {
2717
+ walletIds = supportedWalletTypes.reduce((acc, { type }) => {
2690
2718
  var _a;
2691
2719
  return __spreadProps(__spreadValues({}, acc), {
2692
2720
  [type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
@@ -2730,9 +2758,12 @@ var _ParaCore = class _ParaCore {
2730
2758
  const res = yield this.ctx.client.getFarcasterAuthStatus();
2731
2759
  if (res.data.state === "completed") {
2732
2760
  const { userId, userExists, username, pfpUrl } = res.data;
2733
- yield this.setUserId(userId);
2734
- yield this.setFarcasterUsername(username);
2761
+ yield this.setAuth(
2762
+ { farcasterUsername: username },
2763
+ { extras: { pfpUrl, username, displayName: username }, userId }
2764
+ );
2735
2765
  return {
2766
+ userId,
2736
2767
  userExists,
2737
2768
  username,
2738
2769
  pfpUrl
@@ -2756,13 +2787,13 @@ var _ParaCore = class _ParaCore {
2756
2787
  getOAuthURL(_0) {
2757
2788
  return __async(this, arguments, function* ({ method, deeplinkUrl }) {
2758
2789
  yield this.logout();
2759
- const res = yield this.touchSession(true);
2790
+ const { sessionLookupId } = yield this.touchSession(true);
2760
2791
  return constructUrl({
2761
2792
  base: method === OAuthMethod.TELEGRAM ? getPortalBaseURL(this.ctx, true) : getBaseOAuthUrl(this.ctx.env),
2762
2793
  path: `/auth/${method.toLowerCase()}`,
2763
2794
  params: {
2764
2795
  apiKey: this.ctx.apiKey,
2765
- sessionLookupId: res.data.sessionLookupId,
2796
+ sessionLookupId,
2766
2797
  deeplinkUrl
2767
2798
  }
2768
2799
  });
@@ -2786,18 +2817,16 @@ var _ParaCore = class _ParaCore {
2786
2817
  }
2787
2818
  yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
2788
2819
  if (this.isAwaitingOAuth) {
2789
- const res = yield this.touchSession();
2790
- if (res.data.userId) {
2791
- const { userId, email } = res.data;
2820
+ const { userId, email } = yield this.touchSession();
2821
+ if (!!userId) {
2792
2822
  if (!this.loginEncryptionKeyPair) {
2793
2823
  yield this.setLoginEncryptionKeyPair();
2794
2824
  }
2795
2825
  yield this.setUserId(userId);
2796
2826
  yield this.setEmail(email);
2797
- const userExists = yield this.checkIfUserExists({ email });
2798
2827
  this.isAwaitingOAuth = false;
2799
2828
  return {
2800
- userExists,
2829
+ userExists: true,
2801
2830
  email
2802
2831
  };
2803
2832
  }
@@ -2828,9 +2857,11 @@ var _ParaCore = class _ParaCore {
2828
2857
  }
2829
2858
  this.isAwaitingLogin = true;
2830
2859
  while (this.isAwaitingLogin) {
2860
+ let session;
2831
2861
  try {
2832
2862
  yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
2833
- if (!(yield this.isSessionActive())) {
2863
+ session = yield this.touchSession();
2864
+ if (!session.isAuthenticated) {
2834
2865
  if (popupWindow == null ? void 0 : popupWindow.closed) {
2835
2866
  const resp2 = { isComplete: false, isError: true };
2836
2867
  dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
@@ -2838,8 +2869,8 @@ var _ParaCore = class _ParaCore {
2838
2869
  }
2839
2870
  continue;
2840
2871
  }
2841
- const postLoginData = yield this.userSetupAfterLogin();
2842
- const needsWallet = (_a = postLoginData.data.needsWallet) != null ? _a : false;
2872
+ session = yield this.userSetupAfterLogin();
2873
+ const needsWallet = (_a = session.needsWallet) != null ? _a : false;
2843
2874
  if (!needsWallet) {
2844
2875
  if (this.currentWalletIdsArray.length === 0) {
2845
2876
  if (popupWindow == null ? void 0 : popupWindow.closed) {
@@ -2859,7 +2890,7 @@ var _ParaCore = class _ParaCore {
2859
2890
  const resp2 = {
2860
2891
  isComplete: true,
2861
2892
  needsWallet: needsWallet || Object.values(this.wallets).length === 0,
2862
- partnerId: postLoginData.data.partnerId
2893
+ partnerId: session.partnerId
2863
2894
  };
2864
2895
  dispatchEvent(ParaEvent.LOGIN_EVENT, resp2);
2865
2896
  return resp2;
@@ -2883,12 +2914,12 @@ var _ParaCore = class _ParaCore {
2883
2914
  **/
2884
2915
  refreshSession() {
2885
2916
  return __async(this, arguments, function* ({ shouldOpenPopup = false } = {}) {
2886
- const res = yield this.touchSession(true);
2917
+ const { sessionId } = yield this.touchSession(true);
2887
2918
  if (!this.loginEncryptionKeyPair) {
2888
2919
  yield this.setLoginEncryptionKeyPair();
2889
2920
  }
2890
2921
  const link = yield this.getWebAuthURLForLogin({
2891
- sessionId: res.data.sessionId,
2922
+ sessionId,
2892
2923
  loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
2893
2924
  });
2894
2925
  if (shouldOpenPopup) {
@@ -2903,13 +2934,13 @@ var _ParaCore = class _ParaCore {
2903
2934
  **/
2904
2935
  userSetupAfterLogin() {
2905
2936
  return __async(this, null, function* () {
2906
- const res = yield this.touchSession();
2907
- yield this.setUserId(res.data.userId);
2908
- if (res.data.currentWalletIds && res.data.currentWalletIds !== this.currentWalletIds)
2909
- yield this.setCurrentWalletIds(res.data.currentWalletIds, {
2910
- sessionLookupId: this.isPortal() ? res.data.sessionLookupId : void 0
2937
+ const session = yield this.touchSession();
2938
+ yield this.setUserId(session.userId);
2939
+ if (session.currentWalletIds && session.currentWalletIds !== this.currentWalletIds)
2940
+ yield this.setCurrentWalletIds(session.currentWalletIds, {
2941
+ sessionLookupId: this.isPortal() ? session.sessionLookupId : void 0
2911
2942
  });
2912
- return res;
2943
+ return session;
2913
2944
  });
2914
2945
  }
2915
2946
  /**
@@ -2920,8 +2951,8 @@ var _ParaCore = class _ParaCore {
2920
2951
  **/
2921
2952
  getTransmissionKeyShares() {
2922
2953
  return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
2923
- const res = yield this.touchSession();
2924
- const sessionLookupId = isForNewDevice ? `${res.data.sessionLookupId}-new-device` : res.data.sessionLookupId;
2954
+ const session = yield this.touchSession();
2955
+ const sessionLookupId = isForNewDevice ? `${session.sessionLookupId}-new-device` : session.sessionLookupId;
2925
2956
  return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
2926
2957
  });
2927
2958
  }
@@ -3130,8 +3161,9 @@ var _ParaCore = class _ParaCore {
3130
3161
  } = {}) {
3131
3162
  var _a, _b;
3132
3163
  this.requireApiKey();
3164
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
3133
3165
  const walletType = yield this.assertIsValidWalletType(
3134
- _type != null ? _type : (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
3166
+ _type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
3135
3167
  );
3136
3168
  let signer;
3137
3169
  let wallet;
@@ -3203,14 +3235,15 @@ var _ParaCore = class _ParaCore {
3203
3235
  createPregenWallet(opts) {
3204
3236
  return __async(this, null, function* () {
3205
3237
  var _a, _b;
3238
+ const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
3206
3239
  const {
3207
- type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
3240
+ type: _type = (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
3208
3241
  pregenIdentifier,
3209
3242
  pregenIdentifierType = "EMAIL"
3210
3243
  } = opts;
3211
3244
  this.requireApiKey();
3212
3245
  const walletType = yield this.assertIsValidWalletType(
3213
- _type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
3246
+ _type != null ? _type : (_b = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
3214
3247
  );
3215
3248
  let keygenRes;
3216
3249
  switch (walletType) {
@@ -3292,12 +3325,6 @@ var _ParaCore = class _ParaCore {
3292
3325
  if (pregenWallets.length === 0) {
3293
3326
  return void 0;
3294
3327
  }
3295
- const missingWallets = pregenWallets.filter((wallet) => !this.wallets[wallet.id]);
3296
- if (missingWallets.length > 0) {
3297
- throw new Error(
3298
- `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(", ")}`
3299
- );
3300
- }
3301
3328
  let newRecoverySecret;
3302
3329
  const { walletIds } = yield this.ctx.client.claimPregenWallets({
3303
3330
  userId: this.userId,
@@ -3451,9 +3478,9 @@ var _ParaCore = class _ParaCore {
3451
3478
  }
3452
3479
  getTransactionReviewUrl(transactionId, timeoutMs) {
3453
3480
  return __async(this, null, function* () {
3454
- const res = yield this.touchSession();
3481
+ const { id: partnerId } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
3455
3482
  return this.constructPortalUrl("txReview", {
3456
- partnerId: res.data.partnerId,
3483
+ partnerId,
3457
3484
  pathId: transactionId,
3458
3485
  params: {
3459
3486
  email: this.email,
@@ -3471,12 +3498,12 @@ var _ParaCore = class _ParaCore {
3471
3498
  "purchaseId",
3472
3499
  "providerKey"
3473
3500
  ]);
3474
- const res = yield this.touchSession();
3501
+ const { partnerId, sessionId } = yield this.touchSession();
3475
3502
  const [key, identifier] = extractWalletRef(walletParams);
3476
3503
  return this.constructPortalUrl("onRamp", {
3477
- partnerId: res.data.partnerId,
3504
+ partnerId,
3478
3505
  pathId: purchaseId,
3479
- sessionId: res.data.sessionId,
3506
+ sessionId,
3480
3507
  params: {
3481
3508
  [key]: identifier,
3482
3509
  providerKey,
@@ -3751,27 +3778,17 @@ var _ParaCore = class _ParaCore {
3751
3778
  }
3752
3779
  /**
3753
3780
  * Serialize the current session for import by another Para instance.
3754
- * @param {boolean} excludeSigners - whether or not to exclude the signer from the exported wallets.
3755
3781
  * @returns {string} the serialized session
3756
3782
  */
3757
- exportSession({ excludeSigners } = {}) {
3783
+ exportSession() {
3758
3784
  const sessionInfo = {
3759
- email: this.email,
3785
+ authInfo: __privateGet(this, _authInfo),
3760
3786
  userId: this.userId,
3761
- wallets: structuredClone(this.wallets),
3787
+ wallets: this.wallets,
3762
3788
  currentWalletIds: this.currentWalletIds,
3763
- sessionCookie: this.sessionCookie,
3764
- phone: this.phone,
3765
- countryCode: this.countryCode,
3766
- telegramUserId: this.telegramUserId,
3767
- farcasterUsername: this.farcasterUsername,
3789
+ sessionCookie: this.retrieveSessionCookie(),
3768
3790
  externalWallets: this.externalWallets
3769
3791
  };
3770
- if (excludeSigners) {
3771
- for (const wallet of Object.values(sessionInfo.wallets)) {
3772
- delete wallet.signer;
3773
- }
3774
- }
3775
3792
  return Buffer.from(JSON.stringify(sessionInfo)).toString("base64");
3776
3793
  }
3777
3794
  /**
@@ -3780,12 +3797,11 @@ var _ParaCore = class _ParaCore {
3780
3797
  */
3781
3798
  importSession(serializedInstanceBase64) {
3782
3799
  return __async(this, null, function* () {
3783
- var _a;
3800
+ var _a, _b;
3784
3801
  const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
3785
- const sessionInfo = JSON.parse(serializedInstance);
3786
- yield this.setEmail(sessionInfo.email);
3787
- yield this.setTelegramUserId(sessionInfo.telegramUserId);
3788
- yield this.setFarcasterUsername(sessionInfo.farcasterUsername);
3802
+ const sessionInfo = jsonParse(serializedInstance);
3803
+ const authInfo = (_a = sessionInfo.authInfo) != null ? _a : __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, sessionInfo);
3804
+ yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
3789
3805
  yield this.setUserId(sessionInfo.userId);
3790
3806
  yield this.setWallets(sessionInfo.wallets);
3791
3807
  yield this.setExternalWallets(sessionInfo.externalWallets || {});
@@ -3800,14 +3816,13 @@ var _ParaCore = class _ParaCore {
3800
3816
  const currentWalletIds = {};
3801
3817
  for (const walletId of Object.keys(sessionInfo.wallets)) {
3802
3818
  currentWalletIds[sessionInfo.wallets[walletId].type] = [
3803
- ...(_a = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _a : [],
3819
+ ...(_b = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _b : [],
3804
3820
  walletId
3805
3821
  ];
3806
3822
  }
3807
3823
  yield this.setCurrentWalletIds(currentWalletIds);
3808
3824
  }
3809
3825
  this.persistSessionCookie(sessionInfo.sessionCookie);
3810
- yield this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
3811
3826
  });
3812
3827
  }
3813
3828
  exitAccountCreation() {
@@ -3834,8 +3849,8 @@ var _ParaCore = class _ParaCore {
3834
3849
  **/
3835
3850
  getVerificationToken() {
3836
3851
  return __async(this, null, function* () {
3837
- const { data } = yield this.touchSession();
3838
- return data.sessionLookupId;
3852
+ const { sessionLookupId } = yield this.touchSession();
3853
+ return sessionLookupId;
3839
3854
  });
3840
3855
  }
3841
3856
  /**
@@ -3860,10 +3875,7 @@ var _ParaCore = class _ParaCore {
3860
3875
  this.currentWalletIds = {};
3861
3876
  this.externalWallets = {};
3862
3877
  this.loginEncryptionKeyPair = void 0;
3863
- this.email = void 0;
3864
- this.telegramUserId = void 0;
3865
- this.phone = void 0;
3866
- this.countryCode = void 0;
3878
+ __privateSet(this, _authInfo, void 0);
3867
3879
  this.userId = void 0;
3868
3880
  this.sessionCookie = void 0;
3869
3881
  dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
@@ -3871,11 +3883,9 @@ var _ParaCore = class _ParaCore {
3871
3883
  }
3872
3884
  getSupportedCreateAuthMethods() {
3873
3885
  return __async(this, null, function* () {
3874
- const res = yield this.touchSession();
3875
- const partnerId = res.data.partnerId;
3876
- const partnerRes = yield this.ctx.client.getPartner(partnerId);
3886
+ const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
3877
3887
  let supportedAuthMethods = /* @__PURE__ */ new Set();
3878
- for (const authMethod of partnerRes.data.partner.supportedAuthMethods) {
3888
+ for (const authMethod of partner.supportedAuthMethods) {
3879
3889
  supportedAuthMethods.add(AuthMethod[authMethod]);
3880
3890
  }
3881
3891
  return supportedAuthMethods;
@@ -3887,6 +3897,7 @@ var _ParaCore = class _ParaCore {
3887
3897
  * Doesn't work for all types of logging.
3888
3898
  **/
3889
3899
  toString() {
3900
+ var _a, _b, _c;
3890
3901
  const redactedWallets = Object.keys(this.wallets).reduce(
3891
3902
  (acc, walletId) => __spreadProps(__spreadValues({}, acc), {
3892
3903
  [walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
@@ -3904,13 +3915,10 @@ var _ParaCore = class _ParaCore {
3904
3915
  {}
3905
3916
  );
3906
3917
  const obj = {
3907
- supportedWalletTypes: this.supportedWalletTypes,
3908
- cosmosPrefix: this.cosmosPrefix,
3909
- email: this.email,
3910
- phone: this.phone,
3911
- countryCode: this.countryCode,
3912
- telegramUserId: this.telegramUserId,
3913
- farcasterUsername: this.farcasterUsername,
3918
+ partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
3919
+ supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
3920
+ cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
3921
+ authInfo: __privateGet(this, _authInfo),
3914
3922
  userId: this.userId,
3915
3923
  pregenIds: this.pregenIds,
3916
3924
  currentWalletIds: this.currentWalletIds,
@@ -3931,8 +3939,79 @@ var _ParaCore = class _ParaCore {
3931
3939
  return `Para ${JSON.stringify(obj, null, 2)}`;
3932
3940
  }
3933
3941
  };
3934
- _supportedWalletTypes = new WeakMap();
3935
- _supportedWalletTypesOpt = new WeakMap();
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) };
3974
+ }
3975
+ break;
3976
+ case !!farcasterUsername:
3977
+ auth = { farcasterUsername };
3978
+ break;
3979
+ case !!telegramUserId:
3980
+ auth = { telegramUserId };
3981
+ break;
3982
+ case !!externalWalletAddress:
3983
+ auth = { externalWalletAddress };
3984
+ break;
3985
+ }
3986
+ return extractAuthInfo(auth);
3987
+ };
3988
+ setAuthInfo_fn = function(authInfo) {
3989
+ return __async(this, null, function* () {
3990
+ __privateSet(this, _authInfo, authInfo);
3991
+ yield this.localStorageSetItem(LOCAL_STORAGE_AUTH_INFO, JSON.stringify(authInfo));
3992
+ yield this.localStorageRemoveItem(LOCAL_STORAGE_EMAIL);
3993
+ yield this.localStorageRemoveItem(LOCAL_STORAGE_PHONE);
3994
+ yield this.localStorageRemoveItem(LOCAL_STORAGE_COUNTRY_CODE);
3995
+ yield this.localStorageRemoveItem(LOCAL_STORAGE_FARCASTER_USERNAME);
3996
+ yield this.localStorageRemoveItem(LOCAL_STORAGE_TELEGRAM_USER_ID);
3997
+ });
3998
+ };
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
+ getPartner_fn = function(partnerId) {
4009
+ return __async(this, null, function* () {
4010
+ const res = yield this.ctx.client.getPartner(partnerId);
4011
+ __privateSet(this, _partner, res.data.partner);
4012
+ return __privateGet(this, _partner);
4013
+ });
4014
+ };
3936
4015
  _ParaCore.version = PARA_CORE_VERSION;
3937
4016
  var ParaCore = _ParaCore;
3938
4017
 
@@ -3985,12 +4064,14 @@ export {
3985
4064
  decryptWithKeyPair,
3986
4065
  decryptWithPrivateKey,
3987
4066
  src_default as default,
4067
+ displayPhoneNumber,
3988
4068
  distributeNewShare,
3989
4069
  encodePrivateKeyToPemHex,
3990
4070
  encryptPrivateKey,
3991
4071
  encryptPrivateKeyWithPassword,
3992
4072
  encryptWithDerivedPublicKey,
3993
4073
  entityToWallet,
4074
+ formatPhoneNumber,
3994
4075
  getAsymmetricKeyPair,
3995
4076
  getBaseMPCNetworkUrl,
3996
4077
  getBaseOAuthUrl,
@@ -4012,10 +4093,8 @@ export {
4012
4093
  initClient,
4013
4094
  isWalletSupported,
4014
4095
  mpcComputationClient_exports as mpcComputationClient,
4015
- normalizePhoneNumber,
4016
4096
  paraVersion,
4017
4097
  publicKeyFromHex,
4018
- stringToPhoneNumber,
4019
4098
  toAssetInfoArray,
4020
4099
  retrieve as transmissionUtilsRetrieve,
4021
4100
  truncateAddress,