@getpara/core-sdk 0.1.0 → 0.2.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.
@@ -74,6 +74,11 @@ const libphonenumber_js_1 = __importDefault(require("libphonenumber-js"));
74
74
  const formattingUtils_js_1 = require("./utils/formattingUtils.js");
75
75
  const errors_js_1 = require("./errors.js");
76
76
  const PARA_CORE_VERSION = '0.1.0';
77
+ function dispatchEvent(type, data, error) {
78
+ typeof window !== 'undefined' &&
79
+ !!window.dispatchEvent &&
80
+ window.dispatchEvent(new CustomEvent(type, { detail: Object.assign({ data }, (error && { error: new Error(error) })) }));
81
+ }
77
82
  function isPregenIdentifierMatch(a, b, type) {
78
83
  if (!a || !b) {
79
84
  return false;
@@ -804,7 +809,7 @@ class ParaCore {
804
809
  this.currentExternalWalletAddresses = [address];
805
810
  this.setCurrentExternalWalletAddresses(this.currentExternalWalletAddresses);
806
811
  this.setExternalWallets(this.externalWallets);
807
- typeof window !== 'undefined' && !!window.dispatchEvent && window.dispatchEvent(new Event(definitions_js_1.EXTERNAL_WALLET_CHANGE_EVENT));
812
+ dispatchEvent(index_js_1.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
808
813
  });
809
814
  }
810
815
  /**
@@ -911,9 +916,7 @@ class ParaCore {
911
916
  if (sessionLookupId) {
912
917
  yield this.ctx.client.setCurrentWalletIds(this.getUserId(), this.currentWalletIds, needsWallet, sessionLookupId, newDeviceSessionLookupId);
913
918
  }
914
- typeof window !== 'undefined' &&
915
- !!window.dispatchEvent &&
916
- window.dispatchEvent(new Event(definitions_js_1.CURRENT_WALLET_IDS_CHANGE_EVENT));
919
+ dispatchEvent(index_js_1.ParaEvent.WALLETS_CHANGE_EVENT, null);
917
920
  });
918
921
  }
919
922
  /**
@@ -1098,44 +1101,39 @@ class ParaCore {
1098
1101
  });
1099
1102
  }
1100
1103
  /**
1101
- * Generates a URL that can be used to perform web auth
1102
- * for creating a new credential.
1103
- * @param sessionId - id of the session to use for web auth
1104
- * @param loginEncryptionPublicKey - public key to use for encrypting the login encryption key
1105
- * @param partnerId - id of the partner to get the portal URL for
1106
- * @param newDeviceSessionId - id of the session to use for web auth for a new device
1107
- * @param newDeviceEncryptionKey - public key to use for encrypting the login encryption key for a new device
1108
- * @returns - web auth url
1104
+ * Generates a URL for registering a new WebAuth passkey.
1105
+ * @param {GetWebAuthUrlForLoginParams} opts the options object
1106
+ * @returns - the URL for creating a new passkey
1109
1107
  */
1110
- getWebAuthURLForLogin(options) {
1108
+ getWebAuthURLForLogin(opts) {
1111
1109
  return __awaiter(this, void 0, void 0, function* () {
1112
- return this.constructPortalUrl('loginAuth', options);
1110
+ return this.constructPortalUrl('loginAuth', opts);
1113
1111
  });
1114
1112
  }
1115
- getPasswordURLForLogin(options) {
1113
+ /**
1114
+ * Generates a URL for registering a new user password.
1115
+ * @param {GetWebAuthUrlForLoginParams} opts the options object
1116
+ * @returns - the URL for creating a new password
1117
+ */
1118
+ getPasswordURLForLogin(opts) {
1116
1119
  return __awaiter(this, void 0, void 0, function* () {
1117
- return this.constructPortalUrl('loginPassword', options);
1120
+ return this.constructPortalUrl('loginPassword', opts);
1118
1121
  });
1119
1122
  }
1120
1123
  /**
1121
- * Generates a URL that can be used to perform web auth for phone number
1122
- * for creating a new credential.
1123
- * @param sessionId - id of the session to use for web auth
1124
- * @param loginEncryptionPublicKey - public key to use for encrypting the login encryption key
1125
- * @param partnerId - id of the partner to get the portal URL for
1126
- * @param newDeviceSessionId - id of the session to use for web auth for a new device
1127
- * @param newDeviceEncryptionKey - public key to use for encrypting the login encryption key for a new device
1124
+ * Generates a URL for registering a new WebAuth passkey for a phone number.
1125
+ * @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
1128
1126
  * @returns - web auth url
1129
1127
  */
1130
- getWebAuthURLForLoginForPhone(options) {
1128
+ getWebAuthURLForLoginForPhone(opts) {
1131
1129
  return __awaiter(this, void 0, void 0, function* () {
1132
- return this.constructPortalUrl('loginAuth', Object.assign({ authType: 'phone' }, options));
1130
+ return this.constructPortalUrl('loginAuth', Object.assign({ authType: 'phone' }, opts));
1133
1131
  });
1134
1132
  }
1135
1133
  /**
1136
1134
  * Gets the private key for the given wallet.
1137
- * @param walletId - (optional) id of the wallet to get the private key for. Will default to the first wallet if not provided.
1138
- * @returns - private key string.
1135
+ * @param {string } [walletId] id of the wallet to get the private key for. Will default to the first wallet if not provided.
1136
+ * @returns - the private key string.
1139
1137
  */
1140
1138
  getPrivateKey(walletId) {
1141
1139
  return __awaiter(this, void 0, void 0, function* () {
@@ -1153,7 +1151,7 @@ class ParaCore {
1153
1151
  }
1154
1152
  /**
1155
1153
  * Fetches the wallets associated with the user.
1156
- * @returns - wallets that were fetched.
1154
+ * @returns {WalletEntity[]} wallets that were fetched.
1157
1155
  */
1158
1156
  fetchWallets() {
1159
1157
  return __awaiter(this, void 0, void 0, function* () {
@@ -1188,28 +1186,34 @@ class ParaCore {
1188
1186
  });
1189
1187
  }
1190
1188
  /**
1191
- * Checks if a user exists.
1192
- * @returns - true if user exists, false otherwise.
1189
+ * Checks if a user exists for an email address.
1190
+ * @param {Object} opts the options object
1191
+ * @param {string} opts.email the email to check.
1192
+ * @returns true if user exists, false otherwise.
1193
1193
  */
1194
- checkIfUserExists(email) {
1194
+ checkIfUserExists({ email }) {
1195
1195
  return __awaiter(this, void 0, void 0, function* () {
1196
1196
  const res = yield this.ctx.client.checkUserExists({ email });
1197
1197
  return res.data.exists;
1198
1198
  });
1199
1199
  }
1200
1200
  /**
1201
- * Checks if a user exists by their phone number.
1202
- * @returns - true if user exists, false otherwise.
1201
+ * Checks if a user exists for a phone number.
1202
+ * @param {Object} opts the options object
1203
+ * @param {string} opts.phone - phone number to check.
1204
+ * @param {string} opts.countryCode - the country code.
1205
+ * @returns true if user exists, false otherwise.
1203
1206
  */
1204
- checkIfUserExistsByPhone(phone, countryCode) {
1207
+ checkIfUserExistsByPhone({ phone, countryCode }) {
1205
1208
  return __awaiter(this, void 0, void 0, function* () {
1206
1209
  const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
1207
1210
  return res.data.exists;
1208
1211
  });
1209
1212
  }
1210
- /*
1213
+ /**
1211
1214
  * Creates a new user.
1212
- * @param email - email to use for creating the user.
1215
+ * @param {Object} opts the options object
1216
+ * @param {string} opts.email the email to use.
1213
1217
  */
1214
1218
  createUser({ email }) {
1215
1219
  return __awaiter(this, void 0, void 0, function* () {
@@ -1221,8 +1225,9 @@ class ParaCore {
1221
1225
  }
1222
1226
  /**
1223
1227
  * Creates a new user with a phone number.
1224
- * @param phone - phone number to use for creating the user.
1225
- * @param countryCode - country code to use for creating the user.
1228
+ * @param {Object} opts the options object
1229
+ * @param {string} opts.phone - the phone number to use for creating the user.
1230
+ * @param {string} opts.countryCode - the country code to use for creating the user.
1226
1231
  */
1227
1232
  createUserByPhone({ phone, countryCode }) {
1228
1233
  return __awaiter(this, void 0, void 0, function* () {
@@ -1237,9 +1242,10 @@ class ParaCore {
1237
1242
  }
1238
1243
  /**
1239
1244
  * Logs in or creates a new user using an external wallet address.
1240
- * @param externalAddress - external wallet address to use for identification.
1241
- * @param type - type of external wallet to use for identification.
1242
- * @param externalWalletProvider - name of provider for the external wallet.
1245
+ * @param {Object} opts the options object
1246
+ * @param {string} opts.address the external wallet address to use for identification.
1247
+ * @param {WalletType} opts.type type of external wallet to use for identification.
1248
+ * @param {string} opts.provider the name of the provider for the external wallet.
1243
1249
  */
1244
1250
  externalWalletLogin(wallet) {
1245
1251
  return __awaiter(this, void 0, void 0, function* () {
@@ -1261,10 +1267,11 @@ class ParaCore {
1261
1267
  }
1262
1268
  /**
1263
1269
  * Passes the email code obtained from the user for verification.
1264
- * @param verificationCode
1265
- * @returns - web auth url for creating a new credential
1270
+ * @param {Object} opts the options object
1271
+ * @param {string} verificationCode the six-digit code to check
1272
+ * @returns {string} the web auth url for creating a new credential
1266
1273
  */
1267
- verifyEmail(verificationCode) {
1274
+ verifyEmail({ verificationCode }) {
1268
1275
  return __awaiter(this, void 0, void 0, function* () {
1269
1276
  yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
1270
1277
  return this.getSetUpBiometricsURL();
@@ -1272,10 +1279,11 @@ class ParaCore {
1272
1279
  }
1273
1280
  /**
1274
1281
  * Passes the phone code obtained from the user for verification.
1275
- * @param verificationCode
1276
- * @returns - web auth url for creating a new credential
1282
+ * @param {Object} opts the options object
1283
+ * @param {string} verificationCode the six-digit code to check
1284
+ * @returns {string} the web auth url for creating a new credential
1277
1285
  */
1278
- verifyPhone(verificationCode) {
1286
+ verifyPhone({ verificationCode }) {
1279
1287
  return __awaiter(this, void 0, void 0, function* () {
1280
1288
  yield this.ctx.client.verifyPhone(this.userId, { verificationCode });
1281
1289
  return this.getSetUpBiometricsURLForPhone();
@@ -1303,11 +1311,12 @@ class ParaCore {
1303
1311
  }
1304
1312
  /**
1305
1313
  * Performs 2FA verification.
1306
- * @param email - email to use for performing a 2FA verification.
1307
- * @param verificationCode - verification code to received via 2FA.
1308
- * @returns { address, initiatedAt, status, userId, walletId }
1314
+ * @param {Object} opts the options object
1315
+ * @param {string} opts.email the email to use for performing a 2FA verification.
1316
+ * @param {string} opts.verificationCode the verification code to received via 2FA.
1317
+ * @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
1309
1318
  */
1310
- verify2FA(email, verificationCode) {
1319
+ verify2FA({ email, verificationCode }) {
1311
1320
  return __awaiter(this, void 0, void 0, function* () {
1312
1321
  const res = yield this.ctx.client.verify2FA(email, verificationCode);
1313
1322
  return {
@@ -1320,11 +1329,13 @@ class ParaCore {
1320
1329
  }
1321
1330
  /**
1322
1331
  * Performs 2FA verification.
1323
- * @param phone - phone to use for performing a 2FA verification.
1324
- * @param verificationCode - verification code to received via 2FA.
1325
- * @returns { address, initiatedAt, status, userId, walletId }
1332
+ * @param {Object} opts the options object
1333
+ * @param {string} opts.phone the phone number
1334
+ * @param {string} opts.countryCode - the country code
1335
+ * @param {string} opts.verificationCode - verification code to received via 2FA.
1336
+ * @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
1326
1337
  */
1327
- verify2FAForPhone(phone, countryCode, verificationCode) {
1338
+ verify2FAForPhone({ phone, countryCode, verificationCode, }) {
1328
1339
  return __awaiter(this, void 0, void 0, function* () {
1329
1340
  const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
1330
1341
  return {
@@ -1336,8 +1347,8 @@ class ParaCore {
1336
1347
  });
1337
1348
  }
1338
1349
  /**
1339
- * Sets up 2FA.
1340
- * @returns uri - uri to use for setting up 2FA
1350
+ * Sets up two-factor authentication for the current user.
1351
+ * @returns {string} uri - uri to use for setting up 2FA
1341
1352
  * */
1342
1353
  setup2FA() {
1343
1354
  return __awaiter(this, void 0, void 0, function* () {
@@ -1349,16 +1360,17 @@ class ParaCore {
1349
1360
  }
1350
1361
  /**
1351
1362
  * Enables 2FA.
1352
- * @param verificationCode - verification code received via 2FA.
1363
+ * @param {Object} opts the options object
1364
+ * @param {string} opts.verificationCode - the verification code received via 2FA.
1353
1365
  */
1354
- enable2FA(verificationCode) {
1366
+ enable2FA({ verificationCode }) {
1355
1367
  return __awaiter(this, void 0, void 0, function* () {
1356
1368
  yield this.ctx.client.enable2FA(this.userId, verificationCode);
1357
1369
  });
1358
1370
  }
1359
1371
  /**
1360
1372
  * Determines if 2FA has been set up.
1361
- * @returns { isSetup } - true if 2FA is setup, false otherwise
1373
+ * @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
1362
1374
  */
1363
1375
  check2FAStatus() {
1364
1376
  return __awaiter(this, void 0, void 0, function* () {
@@ -1371,11 +1383,17 @@ class ParaCore {
1371
1383
  };
1372
1384
  });
1373
1385
  }
1386
+ /**
1387
+ * Resend a verification email for the current user.
1388
+ */
1374
1389
  resendVerificationCode() {
1375
1390
  return __awaiter(this, void 0, void 0, function* () {
1376
1391
  yield this.ctx.client.resendVerificationCode(Object.assign({ userId: this.userId }, this.getVerificationEmailProps()));
1377
1392
  });
1378
1393
  }
1394
+ /**
1395
+ * Resend a verification SMS for the current user.
1396
+ */
1379
1397
  resendVerificationCodeByPhone() {
1380
1398
  return __awaiter(this, void 0, void 0, function* () {
1381
1399
  yield this.ctx.client.resendVerificationCodeByPhone({
@@ -1383,7 +1401,13 @@ class ParaCore {
1383
1401
  });
1384
1402
  });
1385
1403
  }
1386
- // returns web auth url for creating a new credential
1404
+ /**
1405
+ * Returns a URL for setting up a new WebAuth passkey.
1406
+ * @param {Object} opts the options object
1407
+ * @param {string} opts.authType - the auth type to use
1408
+ * @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
1409
+ * @returns {string} the URL
1410
+ */
1387
1411
  getSetUpBiometricsURL({ authType = 'email', isForNewDevice = false, } = {}) {
1388
1412
  return __awaiter(this, void 0, void 0, function* () {
1389
1413
  const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
@@ -1398,7 +1422,12 @@ class ParaCore {
1398
1422
  });
1399
1423
  });
1400
1424
  }
1401
- // returns web auth url for creating a new credential
1425
+ /**
1426
+ * Returns a URL for setting up a new WebAuth passkey for a phone number.
1427
+ * @param {Object} opts the options object
1428
+ * @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
1429
+ * @returns {string} the URL
1430
+ */
1402
1431
  getSetUpBiometricsURLForPhone({ isForNewDevice = false, } = {}) {
1403
1432
  return __awaiter(this, void 0, void 0, function* () {
1404
1433
  const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
@@ -1413,6 +1442,14 @@ class ParaCore {
1413
1442
  });
1414
1443
  });
1415
1444
  }
1445
+ /**
1446
+ * Returns a URL for setting up a new password.
1447
+ * @param {Object} opts the options object
1448
+ * @param {string} opts.authType - the auth type to use
1449
+ * @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
1450
+ * @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
1451
+ * @returns {string} the URL
1452
+ */
1416
1453
  getSetupPasswordURL({ authType = 'email', isForNewDevice = false, theme, } = {}) {
1417
1454
  return __awaiter(this, void 0, void 0, function* () {
1418
1455
  const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
@@ -1427,6 +1464,10 @@ class ParaCore {
1427
1464
  });
1428
1465
  });
1429
1466
  }
1467
+ /**
1468
+ * Checks if the current session is active.
1469
+ * @returns `true` if active, `false` otherwise
1470
+ */
1430
1471
  isSessionActive() {
1431
1472
  return __awaiter(this, void 0, void 0, function* () {
1432
1473
  if (this.isUsingExternalWallet()) {
@@ -1438,8 +1479,7 @@ class ParaCore {
1438
1479
  }
1439
1480
  /**
1440
1481
  * Checks if a session is active and a wallet exists.
1441
- *
1442
- * @returns true if session is active and a wallet exists.
1482
+ * @returns `true` if active, `false` otherwise
1443
1483
  **/
1444
1484
  isFullyLoggedIn() {
1445
1485
  return __awaiter(this, void 0, void 0, function* () {
@@ -1509,9 +1549,10 @@ class ParaCore {
1509
1549
  }
1510
1550
  /**
1511
1551
  * Initiates a login.
1512
- * @param email - the email to login with
1513
- * @param useShortURL - whether to shorten the link
1514
- * @returns - web auth url for logging in
1552
+ * @param {Object} opts the options object
1553
+ * @param {String} opts.email - the email to login with
1554
+ * @param {boolean} opts.useShortURL - whether to shorten the link
1555
+ * @returns - the WebAuth URL for logging in
1515
1556
  **/
1516
1557
  initiateUserLogin(_a) {
1517
1558
  var { useShortUrl = false } = _a, auth = __rest(_a, ["useShortUrl"]);
@@ -1550,10 +1591,11 @@ class ParaCore {
1550
1591
  }
1551
1592
  /**
1552
1593
  * Initiates a login.
1553
- * @param phone - the phone number to login with
1554
- * @param countryCode
1555
- * @param useShortURL - whether to shorten the link
1556
- * @returns - web auth url for logging in
1594
+ * @param opts the options object
1595
+ * @param opts.phone the phone number
1596
+ * @param opts.countryCode the country code
1597
+ * @param opts.useShortURL - whether to shorten the link
1598
+ * @returns - the WebAuth URL for logging in
1557
1599
  **/
1558
1600
  initiateUserLoginForPhone(_a) {
1559
1601
  var { useShortUrl = false } = _a, auth = __rest(_a, ["useShortUrl"]);
@@ -1589,6 +1631,7 @@ class ParaCore {
1589
1631
  yield new Promise(resolve => setTimeout(resolve, POLLING_INTERVAL_MS));
1590
1632
  if (yield this.isSessionActive()) {
1591
1633
  this.isAwaitingAccountCreation = false;
1634
+ dispatchEvent(index_js_1.ParaEvent.ACCOUNT_CREATION_EVENT, true);
1592
1635
  return true;
1593
1636
  }
1594
1637
  }
@@ -1616,14 +1659,15 @@ class ParaCore {
1616
1659
  const created = yield this.createWalletPerType();
1617
1660
  recoverySecret = recoverySecret !== null && recoverySecret !== void 0 ? recoverySecret : created.recoverySecret;
1618
1661
  walletIds = Object.assign(Object.assign({}, walletIds), created.walletIds);
1619
- return { walletIds, recoverySecret };
1662
+ const resp = { walletIds, recoverySecret };
1663
+ dispatchEvent(index_js_1.ParaEvent.ACCOUNT_SETUP_EVENT, resp);
1664
+ return resp;
1620
1665
  });
1621
1666
  }
1622
1667
  /**
1623
1668
  * Initiates a Farcaster login attempt and return the URI for the user to connect.
1624
1669
  * You can create a QR code with this URI that works with Farcaster's mobile app.
1625
- *
1626
- * @return {string}
1670
+ * @return {string} the Farcaster connect URI
1627
1671
  */
1628
1672
  getFarcasterConnectURL() {
1629
1673
  return __awaiter(this, void 0, void 0, function* () {
@@ -1636,9 +1680,7 @@ class ParaCore {
1636
1680
  /**
1637
1681
  * Awaits the response from a user's attempt to log in with Farcaster.
1638
1682
  * If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
1639
- *
1640
- * @param {Object} opts the options object.
1641
- * @return {Object} the user's information and whether the user already exists.
1683
+ * @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
1642
1684
  */
1643
1685
  waitForFarcasterStatus() {
1644
1686
  return __awaiter(this, void 0, void 0, function* () {
@@ -1668,16 +1710,17 @@ class ParaCore {
1668
1710
  /**
1669
1711
  * Generates a URL for the user to log in with OAuth using a desire method.
1670
1712
  *
1671
- * @param {OAuthMethod} oAuthMethod the third-party service to use for OAuth.
1713
+ * @param {Object} opts the options object
1714
+ * @param {OAuthMethod} opts.method the third-party service to use for OAuth.
1672
1715
  * @returns {string} the URL for the user to log in with OAuth.
1673
1716
  */
1674
- getOAuthURL(oAuthMethod) {
1717
+ getOAuthURL({ method }) {
1675
1718
  return __awaiter(this, void 0, void 0, function* () {
1676
1719
  yield this.logout();
1677
1720
  const res = yield this.touchSession(true);
1678
1721
  return constructUrl({
1679
- base: oAuthMethod === user_management_client_1.OAuthMethod.TELEGRAM ? (0, definitions_js_1.getPortalBaseURL)(this.ctx, true) : (0, userManagementClient_js_1.getBaseUrl)(this.ctx.env),
1680
- path: `/auth/${oAuthMethod.toLowerCase()}`,
1722
+ base: method === user_management_client_1.OAuthMethod.TELEGRAM ? (0, definitions_js_1.getPortalBaseURL)(this.ctx, true) : (0, userManagementClient_js_1.getBaseUrl)(this.ctx.env),
1723
+ path: `/auth/${method.toLowerCase()}`,
1681
1724
  params: {
1682
1725
  apiKey: this.ctx.apiKey,
1683
1726
  sessionLookupId: res.data.sessionLookupId,
@@ -1691,7 +1734,7 @@ class ParaCore {
1691
1734
  *
1692
1735
  * @param {Object} opts the options object.
1693
1736
  * @param {Window} [opts.popupWindow] the popup window being used for login.
1694
- * @return {Object} the user's email address and whether the user already exists.
1737
+ * @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
1695
1738
  */
1696
1739
  waitForOAuth({ popupWindow } = {}) {
1697
1740
  return __awaiter(this, void 0, void 0, function* () {
@@ -1730,12 +1773,12 @@ class ParaCore {
1730
1773
  * @param {Object} opts the options object
1731
1774
  * @param {Window} [opts.popupWindow] the popup window being used for login.
1732
1775
  * @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
1733
- * @returns { needsWallet } - whether a wallet needs to be created
1776
+ * @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
1734
1777
  **/
1735
1778
  waitForLoginAndSetup({ popupWindow, skipSessionRefresh = false, } = {}) {
1736
1779
  var _a;
1737
1780
  return __awaiter(this, void 0, void 0, function* () {
1738
- // Remove external wallets if logging in with Para
1781
+ // Remove external wallets if logging in with Capsule
1739
1782
  this.currentExternalWalletAddresses = undefined;
1740
1783
  this.externalWallets = {};
1741
1784
  this.isAwaitingLogin = true;
@@ -1744,7 +1787,9 @@ class ParaCore {
1744
1787
  yield new Promise(resolve => setTimeout(resolve, POLLING_INTERVAL_MS));
1745
1788
  if (!(yield this.isSessionActive())) {
1746
1789
  if (popupWindow === null || popupWindow === void 0 ? void 0 : popupWindow.closed) {
1747
- return { isComplete: false, isError: true };
1790
+ const resp = { isComplete: false, isError: true };
1791
+ dispatchEvent(index_js_1.ParaEvent.LOGIN_EVENT, resp, 'failed to setup user');
1792
+ return resp;
1748
1793
  }
1749
1794
  continue;
1750
1795
  }
@@ -1753,7 +1798,9 @@ class ParaCore {
1753
1798
  if (!needsWallet) {
1754
1799
  if (this.currentWalletIdsArray.length === 0) {
1755
1800
  if (popupWindow === null || popupWindow === void 0 ? void 0 : popupWindow.closed) {
1756
- return { isComplete: false, isError: true };
1801
+ const resp = { isComplete: false, isError: true };
1802
+ dispatchEvent(index_js_1.ParaEvent.LOGIN_EVENT, resp, 'failed to setup user');
1803
+ return resp;
1757
1804
  }
1758
1805
  else {
1759
1806
  continue;
@@ -1767,11 +1814,13 @@ class ParaCore {
1767
1814
  if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
1768
1815
  yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
1769
1816
  yield this.claimPregenWallets();
1770
- return {
1817
+ const resp = {
1771
1818
  isComplete: true,
1772
1819
  needsWallet: needsWallet || Object.values(this.wallets).length === 0,
1773
1820
  partnerId: postLoginData.data.partnerId,
1774
1821
  };
1822
+ dispatchEvent(index_js_1.ParaEvent.LOGIN_EVENT, resp);
1823
+ return resp;
1775
1824
  }
1776
1825
  }
1777
1826
  catch (err) {
@@ -1779,7 +1828,9 @@ class ParaCore {
1779
1828
  console.error(err);
1780
1829
  }
1781
1830
  }
1782
- return { isComplete: false };
1831
+ const resp = { isComplete: false };
1832
+ dispatchEvent(index_js_1.ParaEvent.LOGIN_EVENT, resp, 'exitted login without setting up user');
1833
+ return resp;
1783
1834
  });
1784
1835
  }
1785
1836
  /**
@@ -1788,7 +1839,7 @@ class ParaCore {
1788
1839
  *
1789
1840
  * @param {Object} opts the options object.
1790
1841
  * @param {boolean} [shouldOpenPopup] - if `true`, the running device will open a popup to reauthenticate the user.
1791
- * @returns - a URL for the user to reauthenticate.
1842
+ * @returns a URL for the user to reauthenticate.
1792
1843
  **/
1793
1844
  refreshSession({ shouldOpenPopup = false } = {}) {
1794
1845
  return __awaiter(this, void 0, void 0, function* () {
@@ -1823,8 +1874,8 @@ class ParaCore {
1823
1874
  }
1824
1875
  /**
1825
1876
  * Get transmission shares associated with session.
1826
- *
1827
- * @param isForNewDevice - true if this device is registering.
1877
+ * @param {Object} opts the options object.
1878
+ * @param {boolean} opts.isForNewDevice - true if this device is registering.
1828
1879
  * @returns - transmission keyshares.
1829
1880
  **/
1830
1881
  getTransmissionKeyShares({ isForNewDevice = false } = {}) {
@@ -1836,8 +1887,9 @@ class ParaCore {
1836
1887
  }
1837
1888
  /**
1838
1889
  * Call this method after login to perform setup.
1839
- *
1840
- * @param temporaryShares - optional temporary shares to use for decryption.
1890
+ * @param {Object} opts the options object.
1891
+ * @param {any[]} opts.temporaryShares optional temporary shares to use for decryption.
1892
+ * @param {boolean} [opts.skipSessionRefresh] - whether or not to skip refreshing the session.
1841
1893
  **/
1842
1894
  setupAfterLogin({ temporaryShares, skipSessionRefresh = false, } = {}) {
1843
1895
  return __awaiter(this, void 0, void 0, function* () {
@@ -1858,12 +1910,12 @@ class ParaCore {
1858
1910
  }
1859
1911
  /**
1860
1912
  * Distributes a new wallet recovery share.
1861
- *
1862
- * @param walletId - the wallet to distribute the recovery share for.
1863
- * @param userShare - optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
1864
- * @param skipBiometricShareCreation - whether or not to skip biometric share creation. Used when regenerating recovery shares.
1865
- * @param forceRefreshRecovery - whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
1866
- * @returns - recovery share.
1913
+ * @param {Object} opts the options object.
1914
+ * @param {string} opts.walletId the wallet to distribute the recovery share for.
1915
+ * @param {string} opts.userShare optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
1916
+ * @param {boolean} opts.skipBiometricShareCreation whether or not to skip biometric share creation. Used when regenerating recovery shares.
1917
+ * @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
1918
+ * @returns {string} the recovery share.
1867
1919
  **/
1868
1920
  distributeNewWalletShare({ walletId, userShare, skipBiometricShareCreation = false, forceRefresh = false, }) {
1869
1921
  return __awaiter(this, void 0, void 0, function* () {
@@ -2007,10 +2059,10 @@ class ParaCore {
2007
2059
  }
2008
2060
  /**
2009
2061
  * Creates a new wallet.
2010
- *
2011
- * @param skipDistribute - if true, recovery share will not be distributed.
2012
- * @param [customFunction] - {deprecated} method called when createWallet is done.
2013
- * @returns [wallet, recoveryShare]
2062
+ * @param {Object} opts the options object.
2063
+ * @param {WalletType} opts.type the type of wallet to create.
2064
+ * @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
2065
+ * @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
2014
2066
  **/
2015
2067
  createWallet({ type: _type, skipDistribute = false, } = {}) {
2016
2068
  var _a, _b;
@@ -2052,6 +2104,12 @@ class ParaCore {
2052
2104
  });
2053
2105
  }
2054
2106
  yield this.setCurrentWalletIds(Object.assign(Object.assign({}, this.currentWalletIds), { [walletType]: [...((_b = this.currentWalletIds[walletType]) !== null && _b !== void 0 ? _b : []), walletId] }));
2107
+ const walletNoSigner = Object.assign({}, wallet);
2108
+ delete walletNoSigner.signer;
2109
+ dispatchEvent(index_js_1.ParaEvent.WALLET_CREATED, {
2110
+ wallet: walletNoSigner,
2111
+ recoverySecret: recoveryShare,
2112
+ });
2055
2113
  return [wallet, recoveryShare];
2056
2114
  });
2057
2115
  }
@@ -2064,7 +2122,7 @@ class ParaCore {
2064
2122
  * @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
2065
2123
  * @returns {Wallet} the created wallet.
2066
2124
  **/
2067
- createWalletPreGen(opts) {
2125
+ createPregenWallet(opts) {
2068
2126
  var _a, _b;
2069
2127
  return __awaiter(this, void 0, void 0, function* () {
2070
2128
  const { type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) === null || _a === void 0 ? void 0 : _a.type, pregenIdentifier, pregenIdentifierType = 'EMAIL', } = opts;
@@ -2098,17 +2156,17 @@ class ParaCore {
2098
2156
  * Creates new pregenerated wallets for each desired type.
2099
2157
  * If no types are provided, this method will create one for each of the non-optional types
2100
2158
  * specified in the instance's `supportedWalletTypes` array that are not already present.
2101
- *
2102
- * @param {string} pregenIdentifier the identifier to associate each wallet with.
2103
- * @param {TPregenIdentifierType} pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
2104
- * @param {WalletType[]} [types] the wallet types to create. Defaults to any types the instance supports that are not already present.
2105
- * @returns an array containing the created wallets.
2159
+ * @param {Object} opts the options object.
2160
+ * @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
2161
+ * @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
2162
+ * @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
2163
+ * @returns {Wallet[]} an array containing the created wallets.
2106
2164
  **/
2107
2165
  createPregenWalletPerType({ types, pregenIdentifier, pregenIdentifierType = 'EMAIL', }) {
2108
2166
  return __awaiter(this, void 0, void 0, function* () {
2109
2167
  const wallets = [];
2110
2168
  for (const type of yield this.getTypesToCreate(types)) {
2111
- const wallet = yield this.createWalletPreGen({ type, pregenIdentifier, pregenIdentifierType });
2169
+ const wallet = yield this.createPregenWallet({ type, pregenIdentifier, pregenIdentifierType });
2112
2170
  wallets.push(wallet);
2113
2171
  }
2114
2172
  return wallets;
@@ -2117,11 +2175,12 @@ class ParaCore {
2117
2175
  /**
2118
2176
  * Claims a pregenerated wallet.
2119
2177
  *
2120
- * @param pregenIdentifier string the identifier of the user claiming the wallet
2121
- * @param pregenIdentifierType type of the identifier of the user claiming the wallet
2122
- * @returns [wallet, recoveryShare]
2178
+ * @param {Object} opts the options object.
2179
+ * @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
2180
+ * @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
2181
+ * @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
2123
2182
  **/
2124
- claimPregenWallets(pregenIdentifier, pregenIdentifierType = !!pregenIdentifier ? 'EMAIL' : undefined) {
2183
+ claimPregenWallets({ pregenIdentifier, pregenIdentifierType = !!pregenIdentifier ? 'EMAIL' : undefined, } = {}) {
2125
2184
  var _a;
2126
2185
  return __awaiter(this, void 0, void 0, function* () {
2127
2186
  this.requireApiKey();
@@ -2165,17 +2224,23 @@ class ParaCore {
2165
2224
  }
2166
2225
  }
2167
2226
  this.wallets[wallet.id] = Object.assign(Object.assign({}, this.wallets[wallet.id]), { signer: (_a = refreshedShare === null || refreshedShare === void 0 ? void 0 : refreshedShare.signer) !== null && _a !== void 0 ? _a : wallet.signer, userId: this.userId, pregenIdentifier: undefined, pregenIdentifierType: undefined });
2227
+ const walletNoSigner = Object.assign({}, this.wallets[wallet.id]);
2228
+ delete walletNoSigner.signer;
2229
+ dispatchEvent(index_js_1.ParaEvent.PREGEN_WALLET_CLAIMED, {
2230
+ wallet: walletNoSigner,
2231
+ recoverySecret: newRecoverySecret,
2232
+ });
2168
2233
  }
2169
2234
  yield this.setWallets(this.wallets);
2170
2235
  return newRecoverySecret;
2171
2236
  });
2172
2237
  }
2173
2238
  /**
2174
- * Updates a pregenerated wallet identifier.
2175
- *
2176
- * @param newIdentifier - string
2177
- * @param walletId - string
2178
- * @returns Promise<void>
2239
+ * Updates the identifier for a pregen wallet.
2240
+ * @param {Object} opts the options object.
2241
+ * @param {string} opts.walletId the pregen wallet ID
2242
+ * @param {string} opts.newPregenIdentifier the new identtifier
2243
+ * @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
2179
2244
  **/
2180
2245
  updatePregenWalletIdentifier({ walletId, newPregenIdentifier, newPregenIdentifierType, }) {
2181
2246
  return __awaiter(this, void 0, void 0, function* () {
@@ -2191,11 +2256,11 @@ class ParaCore {
2191
2256
  });
2192
2257
  }
2193
2258
  /**
2194
- * Checks if Pregen Wallet exists for the identifier and partnerId
2195
- *
2196
- * @param pregenIdentifier string the identifier of the user claiming the wallet
2197
- * @param pregenIdentifierType type of the string of the identifier of the user claiming the wallet
2198
- * @returns Promise<boolean>
2259
+ * Checks if a pregen Wallet exists for the given identifier with the current partner.
2260
+ * @param {Object} opts the options object.
2261
+ * @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
2262
+ * @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
2263
+ * @returns {boolean} whether the pregen wallet exists
2199
2264
  **/
2200
2265
  hasPregenWallet({ pregenIdentifier, pregenIdentifierType, }) {
2201
2266
  return __awaiter(this, void 0, void 0, function* () {
@@ -2210,11 +2275,11 @@ class ParaCore {
2210
2275
  });
2211
2276
  }
2212
2277
  /**
2213
- * Get pregen wallets for the identifier
2214
- *
2215
- * @param {string} pregenIdentifier - the identifier of the user claiming the wallet
2216
- * @param {TPregenIdentifierType} pregenIdentifierType - type of the identifier of the user claiming the wallet
2217
- * @returns {Promise<WalletEntity[]>} Promise of pregen wallets
2278
+ * Get pregen wallets for the given identifier.
2279
+ * @param {Object} opts the options object.
2280
+ * @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet
2281
+ * @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
2282
+ * @returns {Promise<WalletEntity[]>} the array of found wallets
2218
2283
  **/
2219
2284
  getPregenWallets({ pregenIdentifier, pregenIdentifierType = !!pregenIdentifier ? 'EMAIL' : undefined, } = {}) {
2220
2285
  return __awaiter(this, void 0, void 0, function* () {
@@ -2229,9 +2294,8 @@ class ParaCore {
2229
2294
  return base64Wallet;
2230
2295
  }
2231
2296
  /**
2232
- * Returns a base64 encoded wallet
2233
- *
2234
- * @returns string base64 encoded wallet
2297
+ * Encodes the current wallets encoded in Base 64.
2298
+ * @returns {string} the encoded wallet string
2235
2299
  **/
2236
2300
  getUserShare() {
2237
2301
  if (Object.values(this.wallets).length === 0) {
@@ -2242,10 +2306,8 @@ class ParaCore {
2242
2306
  .join('-');
2243
2307
  }
2244
2308
  /**
2245
- * Sets a wallet from a base 64 encoded wallet
2246
- *
2247
- * @param base64Wallet
2248
- * @returns Promise<void>
2309
+ * Sets the current wallets from a Base 64 string.
2310
+ * @param {string} base64Wallet the encoded wallet string
2249
2311
  **/
2250
2312
  setUserShare(base64Wallets) {
2251
2313
  return __awaiter(this, void 0, void 0, function* () {
@@ -2292,13 +2354,15 @@ class ParaCore {
2292
2354
  });
2293
2355
  }
2294
2356
  /**
2295
- * Signs a message.
2357
+ * Signs a message using one of the current wallets.
2296
2358
  *
2297
2359
  * If you want to sign the keccak256 hash of a message, hash the
2298
2360
  * message first and then pass in the base64 encoded hash.
2299
- * @param walletId - id of the wallet to sign with.
2300
- * @param messageBase64 - base64 encoding of exact message that should be signed
2301
- * @param timeout - optional timeout in milliseconds. If not present, defaults to 30 seconds.
2361
+ * @param {Object} opts the options object.
2362
+ * @param {string} opts.walletId the id of the wallet to sign with.
2363
+ * @param {string} opts.messageBase64 the base64 encoding of exact message that should be signed
2364
+ * @param {number} [opts.timeout] optional timeout in milliseconds. If not present, defaults to 30 seconds.
2365
+ * @param {string} [opts.cosmosSignDocBase64] the Cosmos `SignDoc` in base64, if applicable
2302
2366
  **/
2303
2367
  signMessage({ walletId, messageBase64, timeoutMs = 30000, cosmosSignDocBase64, }) {
2304
2368
  return __awaiter(this, void 0, void 0, function* () {
@@ -2314,6 +2378,7 @@ class ParaCore {
2314
2378
  this.platformUtils.openPopup(yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs), { type: cosmosSignDocBase64 ? index_js_1.PopupType.SIGN_TRANSACTION_REVIEW : index_js_1.PopupType.SIGN_MESSAGE_REVIEW });
2315
2379
  }
2316
2380
  else {
2381
+ dispatchEvent(index_js_1.ParaEvent.SIGN_MESSAGE_EVENT, signRes);
2317
2382
  return signRes;
2318
2383
  }
2319
2384
  yield new Promise(resolve => setTimeout(resolve, POLLING_INTERVAL_MS));
@@ -2325,7 +2390,9 @@ class ParaCore {
2325
2390
  yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
2326
2391
  }
2327
2392
  catch (err) {
2328
- throw new errors_js_1.TransactionReviewDenied();
2393
+ const error = new errors_js_1.TransactionReviewDenied();
2394
+ dispatchEvent(index_js_1.ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
2395
+ throw error;
2329
2396
  }
2330
2397
  signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
2331
2398
  if (signRes.pendingTransactionId) {
@@ -2336,8 +2403,11 @@ class ParaCore {
2336
2403
  }
2337
2404
  }
2338
2405
  if (signRes.pendingTransactionId) {
2339
- throw new errors_js_1.TransactionReviewTimeout(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), signRes.pendingTransactionId);
2406
+ const error = new errors_js_1.TransactionReviewTimeout(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), signRes.pendingTransactionId);
2407
+ dispatchEvent(index_js_1.ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
2408
+ throw error;
2340
2409
  }
2410
+ dispatchEvent(index_js_1.ParaEvent.SIGN_MESSAGE_EVENT, signRes);
2341
2411
  return signRes;
2342
2412
  });
2343
2413
  }
@@ -2357,9 +2427,11 @@ class ParaCore {
2357
2427
  }
2358
2428
  /**
2359
2429
  * Signs a transaction.
2360
- * @param walletId - id of the wallet to sign the transaction from.
2361
- * @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
2362
- * @param chainId - chain id of the chain the transaction is being sent on.
2430
+ * @param {Object} opts the options object.
2431
+ * @param {string} opts.walletId the id of the wallet to sign with.
2432
+ * @param {string} opts.rlpEncodedTxBase64 the transaction to sign, in RLP base64 encoding
2433
+ * @param {string} [opts.chainId] the EVM chain id of the chain the transaction is being sent on, if applicable
2434
+ * @param {number} [opts.timeoutMs] the amount of time to wait for the user to sign the transaction, in milliseconds
2363
2435
  **/
2364
2436
  signTransaction({ walletId, rlpEncodedTxBase64, chainId, timeoutMs = 30000, }) {
2365
2437
  return __awaiter(this, void 0, void 0, function* () {
@@ -2375,6 +2447,7 @@ class ParaCore {
2375
2447
  this.platformUtils.openPopup(yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs), { type: index_js_1.PopupType.SIGN_TRANSACTION_REVIEW });
2376
2448
  }
2377
2449
  else {
2450
+ dispatchEvent(index_js_1.ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
2378
2451
  return signRes;
2379
2452
  }
2380
2453
  yield new Promise(resolve => setTimeout(resolve, POLLING_INTERVAL_MS));
@@ -2386,7 +2459,9 @@ class ParaCore {
2386
2459
  yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
2387
2460
  }
2388
2461
  catch (err) {
2389
- throw new errors_js_1.TransactionReviewDenied();
2462
+ const error = new errors_js_1.TransactionReviewDenied();
2463
+ dispatchEvent(index_js_1.ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
2464
+ throw error;
2390
2465
  }
2391
2466
  signRes = yield this.platformUtils.signTransaction(this.ctx, signerId, walletId, this.wallets[walletId].signer, rlpEncodedTxBase64, chainId, this.retrieveSessionCookie(), wallet.scheme === user_management_client_1.WalletScheme.DKLS);
2392
2467
  if (signRes.pendingTransactionId) {
@@ -2397,12 +2472,16 @@ class ParaCore {
2397
2472
  }
2398
2473
  }
2399
2474
  if (signRes.pendingTransactionId) {
2400
- throw new errors_js_1.TransactionReviewTimeout(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), signRes.pendingTransactionId);
2475
+ const error = new errors_js_1.TransactionReviewTimeout(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), signRes.pendingTransactionId);
2476
+ dispatchEvent(index_js_1.ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
2477
+ throw error;
2401
2478
  }
2479
+ dispatchEvent(index_js_1.ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
2402
2480
  return signRes;
2403
2481
  });
2404
2482
  }
2405
2483
  /**
2484
+ * @deprecated
2406
2485
  * Sends a transaction.
2407
2486
  * @param walletId - id of the wallet to send the transaction from.
2408
2487
  * @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
@@ -2415,7 +2494,8 @@ class ParaCore {
2415
2494
  const signRes = yield this.platformUtils.sendTransaction(this.ctx, this.userId, walletId, this.wallets[walletId].signer, rlpEncodedTxBase64, chainId, this.retrieveSessionCookie(), wallet.scheme === user_management_client_1.WalletScheme.DKLS);
2416
2495
  if (signRes.pendingTransactionId) {
2417
2496
  this.platformUtils.openPopup(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), { type: index_js_1.PopupType.SIGN_TRANSACTION_REVIEW });
2418
- throw new errors_js_1.TransactionReviewError(yield this.getTransactionReviewUrl(signRes.pendingTransactionId));
2497
+ const error = new errors_js_1.TransactionReviewError(yield this.getTransactionReviewUrl(signRes.pendingTransactionId));
2498
+ throw error;
2419
2499
  }
2420
2500
  return signRes;
2421
2501
  });
@@ -2425,11 +2505,11 @@ class ParaCore {
2425
2505
  }
2426
2506
  /**
2427
2507
  * Starts a on-ramp or off-ramp transaction and returns the Para Portal link for the user to finalize and complete it.
2428
- * @param {Object} options - the options for the transaction.
2429
- * @param {OnRampPurchaseCreateParams} options.params - the transaction settings.
2430
- * @param {boolean} options.shouldOpenPopup - if `true`, a popup window with the link will be opened.
2431
- * @param {string} options.walletId - the wallet ID to use for the transaction, where funds will be sent or withdrawn.
2432
- * @param {string} options.externalWalletAddress - the external wallet address to send funds to or withdraw funds from, if using an external wallet.
2508
+ * @param {Object} opts the options object
2509
+ * @param {OnRampPurchaseCreateParams} opts.params the transaction settings.
2510
+ * @param {boolean} opts.shouldOpenPopup if `true`, a popup window with the link will be opened.
2511
+ * @param {string} opts.walletId the wallet ID to use for the transaction, where funds will be sent or withdrawn.
2512
+ * @param {string} opts.externalWalletAddress the external wallet address to send funds to or withdraw funds from, if using an external wallet.
2433
2513
  **/
2434
2514
  initiateOnRampTransaction(options) {
2435
2515
  var _a;
@@ -2444,7 +2524,7 @@ class ParaCore {
2444
2524
  });
2445
2525
  }
2446
2526
  /**
2447
- * Returns true if session was successfully kept alive, false otherwise.
2527
+ * Returns `true` if session was successfully kept alive, `false` otherwise.
2448
2528
  **/
2449
2529
  keepSessionAlive() {
2450
2530
  return __awaiter(this, void 0, void 0, function* () {
@@ -2457,6 +2537,10 @@ class ParaCore {
2457
2537
  }
2458
2538
  });
2459
2539
  }
2540
+ /**
2541
+ * Serialize the current session for import by another Para instance.
2542
+ * @returns {string} the serialized session
2543
+ */
2460
2544
  exportSession() {
2461
2545
  const sessionInfo = {
2462
2546
  email: this.email,
@@ -2469,6 +2553,10 @@ class ParaCore {
2469
2553
  };
2470
2554
  return Buffer.from(JSON.stringify(sessionInfo)).toString('base64');
2471
2555
  }
2556
+ /**
2557
+ * Imports a session serialized by another Para instance.
2558
+ * @param {string} serializedInstanceBase64 the serialized session
2559
+ */
2472
2560
  importSession(serializedInstanceBase64) {
2473
2561
  var _a;
2474
2562
  return __awaiter(this, void 0, void 0, function* () {
@@ -2519,8 +2607,8 @@ class ParaCore {
2519
2607
  }
2520
2608
  /**
2521
2609
  * Logs the user out.
2522
- *
2523
- * @param preservePregenWallets - preserves the stored pregen wallets in memory after the logout.
2610
+ * @param {Object} opts the options object.
2611
+ * @param {boolean} opts.clearPregenWallets if `true`, will remove all pregen wallets from storage
2524
2612
  **/
2525
2613
  logout({ clearPregenWallets = false } = {}) {
2526
2614
  return __awaiter(this, void 0, void 0, function* () {
@@ -2547,6 +2635,7 @@ class ParaCore {
2547
2635
  this.countryCode = undefined;
2548
2636
  this.userId = undefined;
2549
2637
  this.sessionCookie = undefined;
2638
+ dispatchEvent(index_js_1.ParaEvent.LOGOUT_EVENT, null);
2550
2639
  });
2551
2640
  }
2552
2641
  getSupportedCreateAuthMethods() {