@getpara/core-sdk 2.0.0-alpha.19 → 2.0.0-alpha.21

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.
@@ -99,7 +99,7 @@ var import_recovery = require("./shares/recovery.js");
99
99
  var import_utils2 = require("./utils/index.js");
100
100
  var import_errors = require("./errors.js");
101
101
  var constants = __toESM(require("./constants.js"));
102
- var _authInfo, _partner, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareLogin_fn, prepareLoginState_fn, prepareSignUpState_fn;
102
+ var _authInfo, _partner, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, assertIsLinkingAccount_fn, assertIsLinkingAccountOrStart_fn, getOAuthUrl_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareLogin_fn, prepareLoginState_fn, prepareSignUpState_fn;
103
103
  if (typeof global !== "undefined") {
104
104
  global.Buffer = global.Buffer || import_buffer.Buffer;
105
105
  } else if (typeof window !== "undefined") {
@@ -123,6 +123,7 @@ const _ParaCore = class _ParaCore {
123
123
  __privateAdd(this, _authInfo);
124
124
  this.isNativePasskey = false;
125
125
  __privateAdd(this, _partner);
126
+ this.accountLinkInProgress = void 0;
126
127
  this.isAwaitingAccountCreation = false;
127
128
  this.isAwaitingLogin = false;
128
129
  this.isAwaitingFarcaster = false;
@@ -505,6 +506,10 @@ const _ParaCore = class _ParaCore {
505
506
  var _a;
506
507
  return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
507
508
  }
509
+ get supportedAccountLinks() {
510
+ var _a, _b;
511
+ return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...import_user_management_client.LINKED_ACCOUNT_TYPES];
512
+ }
508
513
  get isWalletTypeEnabled() {
509
514
  var _a;
510
515
  return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
@@ -680,7 +685,7 @@ const _ParaCore = class _ParaCore {
680
685
  if (!this.loginEncryptionKeyPair) {
681
686
  yield this.setLoginEncryptionKeyPair();
682
687
  }
683
- const base = type === "onRamp" ? (0, import_utils2.getPortalBaseURL)(this.ctx) : yield this.getPortalURL();
688
+ const base = type === "onRamp" || type === "telegramLogin" ? (0, import_utils2.getPortalBaseURL)(this.ctx, type === "telegramLogin") : yield this.getPortalURL();
684
689
  let path;
685
690
  switch (type) {
686
691
  case "createPassword": {
@@ -707,6 +712,10 @@ const _ParaCore = class _ParaCore {
707
712
  path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
708
713
  break;
709
714
  }
715
+ case "telegramLogin": {
716
+ path = `/auth/telegram`;
717
+ break;
718
+ }
710
719
  default: {
711
720
  throw new Error(`invalid URL type ${type}`);
712
721
  }
@@ -716,7 +725,7 @@ const _ParaCore = class _ParaCore {
716
725
  encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
717
726
  sessionId
718
727
  };
719
- const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
728
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
720
729
  apiKey: this.ctx.apiKey,
721
730
  partnerId: partner.id,
722
731
  portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
@@ -742,7 +751,7 @@ const _ParaCore = class _ParaCore {
742
751
  newDeviceEncryptionKey: opts.newDevice.encryptionKey
743
752
  } : {}), {
744
753
  pregenIds: JSON.stringify(this.pregenIds)
745
- }) : {}), opts.params || {});
754
+ }) : {}), type === "telegramLogin" ? { isEmbed: "true" } : {}), opts.params || {});
746
755
  const url = (0, import_utils2.constructUrl)({ base, path, params });
747
756
  if (opts.shorten) {
748
757
  return (0, import_utils2.shortenUrl)(this.ctx, url);
@@ -855,7 +864,7 @@ const _ParaCore = class _ParaCore {
855
864
  });
856
865
  }
857
866
  assertUserId() {
858
- if (!this.userId) {
867
+ if (!this.userId || this.isGuestMode) {
859
868
  throw new Error("no userId is set");
860
869
  }
861
870
  return this.userId;
@@ -916,6 +925,7 @@ const _ParaCore = class _ParaCore {
916
925
  address,
917
926
  type,
918
927
  provider,
928
+ providerId,
919
929
  addressBech32,
920
930
  withFullParaAuth,
921
931
  isConnectionOnly,
@@ -929,6 +939,7 @@ const _ParaCore = class _ParaCore {
929
939
  name: provider,
930
940
  isExternal: true,
931
941
  isExternalWithParaAuth: withFullParaAuth,
942
+ externalProviderId: providerId,
932
943
  signer: "",
933
944
  isExternalConnectionOnly: isConnectionOnly,
934
945
  isExternalWithVerification: withVerification
@@ -1314,27 +1325,64 @@ const _ParaCore = class _ParaCore {
1314
1325
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1315
1326
  });
1316
1327
  }
1328
+ verifyExternalWalletLink(opts) {
1329
+ return __async(this, null, function* () {
1330
+ const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EXTERNAL_WALLET"]);
1331
+ if (!accountLinkInProgress.externalWallet) {
1332
+ throw new Error("no external wallet account link in progress");
1333
+ }
1334
+ const accounts = yield this.verifyLink(__spreadValues({
1335
+ accountLinkInProgress,
1336
+ externalWallet: accountLinkInProgress.externalWallet
1337
+ }, opts));
1338
+ return accounts;
1339
+ });
1340
+ }
1317
1341
  /**
1318
1342
  * Validates the response received from an attempted Telegram login for authenticity, then
1319
1343
  * creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
1320
1344
  * @param authResponse - the response JSON object received from the Telegram widget.
1321
1345
  * @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
1322
1346
  */
1323
- verifyTelegram(_e) {
1347
+ verifyTelegramProcess(_e) {
1324
1348
  return __async(this, null, function* () {
1325
1349
  var _f = _e, {
1326
- telegramAuthResponse
1350
+ telegramAuthResponse,
1351
+ isLinkAccount
1327
1352
  } = _f, urlOptions = __objRest(_f, [
1328
- "telegramAuthResponse"
1353
+ "telegramAuthResponse",
1354
+ "isLinkAccount"
1329
1355
  ]);
1330
1356
  try {
1331
- const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
1332
- return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1357
+ switch (isLinkAccount) {
1358
+ case false: {
1359
+ const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
1360
+ return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1361
+ }
1362
+ case true: {
1363
+ const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
1364
+ const accounts = yield this.verifyLink({
1365
+ accountLinkInProgress,
1366
+ telegramAuthResponse
1367
+ });
1368
+ return accounts;
1369
+ }
1370
+ }
1333
1371
  } catch (e) {
1334
1372
  throw new Error(e.message);
1335
1373
  }
1336
1374
  });
1337
1375
  }
1376
+ verifyTelegram(opts) {
1377
+ return __async(this, null, function* () {
1378
+ return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
1379
+ });
1380
+ }
1381
+ verifyTelegramLink(opts) {
1382
+ return __async(this, null, function* () {
1383
+ return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
1384
+ });
1385
+ }
1338
1386
  /**
1339
1387
  * Performs 2FA verification.
1340
1388
  * @param {Object} opts the options object
@@ -1378,10 +1426,34 @@ const _ParaCore = class _ParaCore {
1378
1426
  /**
1379
1427
  * Resend a verification email for the current user.
1380
1428
  */
1381
- resendVerificationCode() {
1382
- return __async(this, null, function* () {
1429
+ resendVerificationCode(_0) {
1430
+ return __async(this, arguments, function* ({
1431
+ type: reason = "SIGNUP"
1432
+ }) {
1433
+ let type, linkedAccountId;
1434
+ switch (reason) {
1435
+ case "SIGNUP":
1436
+ {
1437
+ const authInfo = this.assertIsAuthSet(["email", "phone"]);
1438
+ type = authInfo.authType.toUpperCase();
1439
+ }
1440
+ break;
1441
+ case "LINK_ACCOUNT":
1442
+ {
1443
+ const accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]);
1444
+ linkedAccountId = accountLinkInProgress.id;
1445
+ type = accountLinkInProgress.type;
1446
+ }
1447
+ break;
1448
+ }
1449
+ const userId = this.assertUserId();
1450
+ if (type !== "EMAIL" && type !== "PHONE") {
1451
+ throw new Error("invalid auth type for verification code");
1452
+ }
1383
1453
  yield this.ctx.client.resendVerificationCode(__spreadValues({
1384
- userId: this.userId
1454
+ userId,
1455
+ type,
1456
+ linkedAccountId
1385
1457
  }, this.getVerificationEmailProps()));
1386
1458
  });
1387
1459
  }
@@ -1540,19 +1612,25 @@ const _ParaCore = class _ParaCore {
1540
1612
  * If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
1541
1613
  * @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
1542
1614
  */
1543
- verifyFarcaster(_g) {
1615
+ verifyFarcasterProcess(_g) {
1544
1616
  return __async(this, null, function* () {
1545
1617
  var _h = _g, {
1546
1618
  isCanceled = () => false,
1547
1619
  onConnectUri,
1548
1620
  onCancel,
1549
- onPoll
1621
+ onPoll,
1622
+ isLinkAccount
1550
1623
  } = _h, urlOptions = __objRest(_h, [
1551
1624
  "isCanceled",
1552
1625
  "onConnectUri",
1553
1626
  "onCancel",
1554
- "onPoll"
1627
+ "onPoll",
1628
+ "isLinkAccount"
1555
1629
  ]);
1630
+ let accountLinkInProgress;
1631
+ if (isLinkAccount) {
1632
+ accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
1633
+ }
1556
1634
  if (onConnectUri) {
1557
1635
  const connectUri = yield this.getFarcasterConnectUri();
1558
1636
  onConnectUri(connectUri);
@@ -1564,46 +1642,53 @@ const _ParaCore = class _ParaCore {
1564
1642
  try {
1565
1643
  if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
1566
1644
  onCancel == null ? void 0 : onCancel();
1567
- return reject("canceled");
1645
+ return reject("CANCELED");
1568
1646
  }
1569
1647
  yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
1570
- const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
1571
- if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
1572
- const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1573
- return resolve(authState);
1648
+ switch (isLinkAccount) {
1649
+ case false:
1650
+ {
1651
+ const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
1652
+ if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
1653
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
1654
+ return resolve(authState);
1655
+ }
1656
+ }
1657
+ break;
1658
+ case true: {
1659
+ const result = yield this.verifyLink({
1660
+ accountLinkInProgress
1661
+ });
1662
+ if ("isConflict" in result) {
1663
+ throw new Error(import_types.AccountLinkError.Conflict);
1664
+ }
1665
+ return resolve(result);
1666
+ }
1574
1667
  }
1575
1668
  onPoll == null ? void 0 : onPoll();
1576
1669
  } catch (e) {
1577
- console.error(e);
1578
- return reject(e);
1670
+ if (!isLinkAccount || e.message === import_types.AccountLinkError.Conflict) {
1671
+ return reject(e.message);
1672
+ }
1579
1673
  }
1580
1674
  }
1581
1675
  }))();
1582
1676
  });
1583
1677
  });
1584
1678
  }
1585
- /**
1586
- * Generates a URL for the user to log in with OAuth using a desire method.
1587
- *
1588
- * @param {Object} opts the options object
1589
- * @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
1590
- * @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
1591
- * @returns {string} the URL for the user to log in with OAuth.
1592
- */
1593
- getOAuthUrl(_i) {
1679
+ verifyFarcaster(opts) {
1594
1680
  return __async(this, null, function* () {
1595
- var _j = _i, { method, deeplinkUrl } = _j, params = __objRest(_j, ["method", "deeplinkUrl"]);
1596
- var _a;
1597
- const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
1598
- return (0, import_utils2.constructUrl)({
1599
- base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
1600
- path: `/auth/${method}`,
1601
- params: {
1602
- apiKey: this.ctx.apiKey,
1603
- sessionLookupId,
1604
- deeplinkUrl
1605
- }
1606
- });
1681
+ return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
1682
+ });
1683
+ }
1684
+ verifyFarcasterLink(opts) {
1685
+ return __async(this, null, function* () {
1686
+ return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
1687
+ });
1688
+ }
1689
+ getOAuthUrl(opts) {
1690
+ return __async(this, null, function* () {
1691
+ return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, opts);
1607
1692
  });
1608
1693
  }
1609
1694
  /**
@@ -1614,7 +1699,7 @@ const _ParaCore = class _ParaCore {
1614
1699
  * @param {Window} [opts.popupWindow] the popup window being used for login.
1615
1700
  * @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
1616
1701
  */
1617
- verifyOAuth(_k) {
1702
+ verifyOAuthProcess(_k) {
1618
1703
  return __async(this, null, function* () {
1619
1704
  var _l = _k, {
1620
1705
  method,
@@ -1622,19 +1707,26 @@ const _ParaCore = class _ParaCore {
1622
1707
  isCanceled = () => false,
1623
1708
  onCancel,
1624
1709
  onPoll,
1625
- onOAuthUrl
1710
+ onOAuthUrl,
1711
+ isLinkAccount
1626
1712
  } = _l, urlOptions = __objRest(_l, [
1627
1713
  "method",
1628
1714
  "deeplinkUrl",
1629
1715
  "isCanceled",
1630
1716
  "onCancel",
1631
1717
  "onPoll",
1632
- "onOAuthUrl"
1718
+ "onOAuthUrl",
1719
+ "isLinkAccount"
1633
1720
  ]);
1634
- let sessionLookupId;
1721
+ let sessionLookupId, accountLinkInProgress;
1635
1722
  if (onOAuthUrl) {
1636
- sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
1637
- const oAuthUrl = yield this.getOAuthUrl({ method, deeplinkUrl, sessionLookupId });
1723
+ if (isLinkAccount) {
1724
+ accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
1725
+ sessionLookupId = (yield this.touchSession()).sessionLookupId;
1726
+ } else {
1727
+ sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
1728
+ }
1729
+ const oAuthUrl = yield __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, { method, deeplinkUrl, sessionLookupId, accountLinkInProgress });
1638
1730
  onOAuthUrl(oAuthUrl);
1639
1731
  } else {
1640
1732
  ({ sessionLookupId } = yield this.touchSession());
@@ -1646,16 +1738,29 @@ const _ParaCore = class _ParaCore {
1646
1738
  try {
1647
1739
  if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
1648
1740
  onCancel == null ? void 0 : onCancel();
1649
- return reject("canceled");
1741
+ return reject(import_types.AccountLinkError.Canceled);
1650
1742
  }
1651
1743
  yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
1652
- const serverAuthState = yield this.ctx.client.verifyOAuth();
1653
- if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
1654
- const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
1655
- return resolve(authState);
1744
+ switch (isLinkAccount) {
1745
+ case false:
1746
+ {
1747
+ const serverAuthState = yield this.ctx.client.verifyOAuth();
1748
+ if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
1749
+ const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
1750
+ return resolve(authState);
1751
+ }
1752
+ }
1753
+ break;
1754
+ case true: {
1755
+ const accounts = yield this.verifyLink({ accountLinkInProgress });
1756
+ return resolve(accounts);
1757
+ }
1656
1758
  }
1657
1759
  onPoll == null ? void 0 : onPoll();
1658
1760
  } catch (err) {
1761
+ if (isLinkAccount && err.message === import_types.AccountLinkError.Conflict) {
1762
+ return reject(err.message);
1763
+ }
1659
1764
  onPoll == null ? void 0 : onPoll();
1660
1765
  }
1661
1766
  }
@@ -1663,6 +1768,16 @@ const _ParaCore = class _ParaCore {
1663
1768
  });
1664
1769
  });
1665
1770
  }
1771
+ verifyOAuth(opts) {
1772
+ return __async(this, null, function* () {
1773
+ return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
1774
+ });
1775
+ }
1776
+ verifyOAuthLink(opts) {
1777
+ return __async(this, null, function* () {
1778
+ return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
1779
+ });
1780
+ }
1666
1781
  /**
1667
1782
  * Waits for the session to be active and sets up the user.
1668
1783
  *
@@ -2644,22 +2759,12 @@ const _ParaCore = class _ParaCore {
2644
2759
  this.externalWallets = {};
2645
2760
  this.loginEncryptionKeyPair = void 0;
2646
2761
  __privateSet(this, _authInfo, void 0);
2762
+ this.accountLinkInProgress = void 0;
2647
2763
  this.userId = void 0;
2648
2764
  this.sessionCookie = void 0;
2649
2765
  (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGOUT_EVENT, null);
2650
2766
  });
2651
2767
  }
2652
- /** @deprecated */
2653
- getSupportedCreateAuthMethods() {
2654
- return __async(this, null, function* () {
2655
- const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2656
- let supportedAuthMethods = /* @__PURE__ */ new Set();
2657
- for (const authMethod of partner.supportedAuthMethods) {
2658
- supportedAuthMethods.add(import_user_management_client.AuthMethod[authMethod]);
2659
- }
2660
- return supportedAuthMethods;
2661
- });
2662
- }
2663
2768
  /**
2664
2769
  * Converts to a string, removing sensitive data when logging this class.
2665
2770
  *
@@ -2812,6 +2917,119 @@ const _ParaCore = class _ParaCore {
2812
2917
  return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
2813
2918
  });
2814
2919
  }
2920
+ getLinkedAccounts() {
2921
+ return __async(this, null, function* () {
2922
+ const userId = this.assertUserId();
2923
+ const { accounts } = yield this.ctx.client.getLinkedAccounts({ userId });
2924
+ return __spreadValues({
2925
+ userId
2926
+ }, accounts);
2927
+ });
2928
+ }
2929
+ linkAccount(opts) {
2930
+ return __async(this, null, function* () {
2931
+ const { supportedAccountLinks = [...import_user_management_client.LINKED_ACCOUNT_TYPES] } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
2932
+ let type, identifier, externalWallet, isPermitted;
2933
+ switch (true) {
2934
+ case "auth" in opts:
2935
+ {
2936
+ const authInfo = (0, import_user_management_client.extractAuthInfo)(opts.auth, { isRequired: true });
2937
+ if (authInfo.auth === this.authInfo.auth) {
2938
+ throw new Error(import_types.AccountLinkError.Conflict);
2939
+ }
2940
+ type = authInfo.authType.toUpperCase();
2941
+ identifier = authInfo.identifier;
2942
+ isPermitted = supportedAccountLinks.includes(type);
2943
+ }
2944
+ break;
2945
+ case "externalWallet" in opts:
2946
+ {
2947
+ externalWallet = opts.externalWallet;
2948
+ type = "EXTERNAL_WALLET";
2949
+ isPermitted = supportedAccountLinks.includes("EXTERNAL_WALLET") || supportedAccountLinks.includes(externalWallet.providerId);
2950
+ }
2951
+ break;
2952
+ case "type" in opts:
2953
+ {
2954
+ type = opts.type;
2955
+ if (type === "X") {
2956
+ type = "TWITTER";
2957
+ }
2958
+ isPermitted = supportedAccountLinks.includes(type);
2959
+ }
2960
+ break;
2961
+ default:
2962
+ throw new Error("Invalid parameters for linking account, must pass `auth` or `type` or `externalWallet");
2963
+ }
2964
+ if (!isPermitted) {
2965
+ throw new Error(`Account linking for type '${type}' is not supported by the current API key configuration`);
2966
+ }
2967
+ const userId = this.assertUserId();
2968
+ const result = yield this.ctx.client.linkAccount(__spreadValues(__spreadValues({
2969
+ userId,
2970
+ type
2971
+ }, identifier ? { identifier } : {}), externalWallet ? { externalWallet } : {}));
2972
+ if ("isConflict" in result) {
2973
+ throw new Error(import_types.AccountLinkError.Conflict);
2974
+ }
2975
+ const { linkedAccountId, signatureVerificationMessage } = result;
2976
+ this.accountLinkInProgress = __spreadValues(__spreadValues({
2977
+ id: linkedAccountId,
2978
+ type,
2979
+ isComplete: false
2980
+ }, identifier ? { identifier } : {}), signatureVerificationMessage && externalWallet ? {
2981
+ externalWallet: __spreadProps(__spreadValues({}, externalWallet), {
2982
+ signatureVerificationMessage
2983
+ })
2984
+ } : {});
2985
+ return this.accountLinkInProgress;
2986
+ });
2987
+ }
2988
+ unlinkAccount(_0) {
2989
+ return __async(this, arguments, function* ({
2990
+ linkedAccountId
2991
+ }) {
2992
+ if (!linkedAccountId) {
2993
+ throw new Error("No linked account ID provided");
2994
+ }
2995
+ const userId = this.assertUserId();
2996
+ const accounts = yield this.ctx.client.unlinkAccount({ linkedAccountId, userId });
2997
+ return accounts;
2998
+ });
2999
+ }
3000
+ verifyLink() {
3001
+ return __async(this, arguments, function* (_s = {}) {
3002
+ var _t = _s, {
3003
+ accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this)
3004
+ } = _t, opts = __objRest(_t, [
3005
+ "accountLinkInProgress"
3006
+ ]);
3007
+ try {
3008
+ const userId = this.assertUserId(), result = yield this.ctx.client.verifyLink(__spreadValues({
3009
+ linkedAccountId: accountLinkInProgress.id,
3010
+ userId
3011
+ }, opts));
3012
+ if ("isConflict" in result) {
3013
+ throw new Error(import_types.AccountLinkError.Conflict);
3014
+ }
3015
+ this.accountLinkInProgress = void 0;
3016
+ return result.accounts;
3017
+ } catch (e) {
3018
+ throw new Error(e.message === import_types.AccountLinkError.Conflict ? import_types.AccountLinkError.Conflict : e.message);
3019
+ }
3020
+ });
3021
+ }
3022
+ verifyEmailOrPhoneLink(_0) {
3023
+ return __async(this, arguments, function* ({
3024
+ verificationCode
3025
+ }) {
3026
+ const accounts = yield this.verifyLink({
3027
+ accountLinkInProgress: __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]),
3028
+ verificationCode
3029
+ });
3030
+ return accounts;
3031
+ });
3032
+ }
2815
3033
  };
2816
3034
  _authInfo = new WeakMap();
2817
3035
  _partner = new WeakMap();
@@ -2898,6 +3116,51 @@ getPartner_fn = function(partnerId) {
2898
3116
  return __privateGet(this, _partner);
2899
3117
  });
2900
3118
  };
3119
+ assertIsLinkingAccount_fn = function(types) {
3120
+ if (!this.accountLinkInProgress || this.accountLinkInProgress.isComplete) {
3121
+ throw new Error("no account linking in progress");
3122
+ }
3123
+ if (types && !types.includes(this.accountLinkInProgress.type)) {
3124
+ throw new Error(
3125
+ `account linking in progress for type ${this.accountLinkInProgress.type}, expected one of ${types.join(", ")}`
3126
+ );
3127
+ }
3128
+ return this.accountLinkInProgress;
3129
+ };
3130
+ assertIsLinkingAccountOrStart_fn = function(type) {
3131
+ return __async(this, null, function* () {
3132
+ if (this.accountLinkInProgress && !this.accountLinkInProgress.isComplete) {
3133
+ return __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, [type]);
3134
+ }
3135
+ return yield this.linkAccount({ type });
3136
+ });
3137
+ };
3138
+ getOAuthUrl_fn = function(_i) {
3139
+ return __async(this, null, function* () {
3140
+ var _j = _i, {
3141
+ method,
3142
+ deeplinkUrl,
3143
+ accountLinkInProgress
3144
+ } = _j, params = __objRest(_j, [
3145
+ "method",
3146
+ "deeplinkUrl",
3147
+ "accountLinkInProgress"
3148
+ ]);
3149
+ var _a;
3150
+ const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
3151
+ return (0, import_utils2.constructUrl)({
3152
+ base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
3153
+ path: `/auth/${method}`,
3154
+ params: __spreadValues({
3155
+ apiKey: this.ctx.apiKey,
3156
+ sessionLookupId,
3157
+ deeplinkUrl
3158
+ }, accountLinkInProgress ? {
3159
+ linkedAccountId: this.accountLinkInProgress.id
3160
+ } : {})
3161
+ });
3162
+ });
3163
+ };
2901
3164
  createPregenWallet_fn = function(opts) {
2902
3165
  return __async(this, null, function* () {
2903
3166
  var _a, _b;
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var constants_exports = {};
19
19
  __export(constants_exports, {
20
+ ACCOUNT_LINK_CONFLICT: () => ACCOUNT_LINK_CONFLICT,
20
21
  EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID: () => EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
21
22
  LOCAL_STORAGE_AUTH_INFO: () => LOCAL_STORAGE_AUTH_INFO,
22
23
  LOCAL_STORAGE_COUNTRY_CODE: () => LOCAL_STORAGE_COUNTRY_CODE,
@@ -39,7 +40,7 @@ __export(constants_exports, {
39
40
  SHORT_POLLING_INTERVAL_MS: () => SHORT_POLLING_INTERVAL_MS
40
41
  });
41
42
  module.exports = __toCommonJS(constants_exports);
42
- const PARA_CORE_VERSION = "2.0.0-alpha.19";
43
+ const PARA_CORE_VERSION = "2.0.0-alpha.21";
43
44
  const PREFIX = "@CAPSULE/";
44
45
  const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
45
46
  const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
@@ -59,8 +60,10 @@ const POLLING_INTERVAL_MS = 2e3;
59
60
  const SHORT_POLLING_INTERVAL_MS = 1e3;
60
61
  const POLLING_TIMEOUT_MS = 3e5;
61
62
  const EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID = "EXTERNAL_WALLET_CONNECTION_ONLY";
63
+ const ACCOUNT_LINK_CONFLICT = "Account already linked";
62
64
  // Annotate the CommonJS export names for ESM import in node:
63
65
  0 && (module.exports = {
66
+ ACCOUNT_LINK_CONFLICT,
64
67
  EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
65
68
  LOCAL_STORAGE_AUTH_INFO,
66
69
  LOCAL_STORAGE_COUNTRY_CODE,
package/dist/cjs/index.js CHANGED
@@ -28,9 +28,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var src_exports = {};
30
30
  __export(src_exports, {
31
+ AccountLinkError: () => import_types.AccountLinkError,
31
32
  AuthMethod: () => import_user_management_client.AuthMethod,
33
+ COSMOS_WALLETS: () => import_user_management_client.COSMOS_WALLETS,
34
+ EVM_WALLETS: () => import_user_management_client.EVM_WALLETS,
35
+ EXTERNAL_WALLET_TYPES: () => import_user_management_client.EXTERNAL_WALLET_TYPES,
32
36
  EmailTheme: () => import_user_management_client.EmailTheme,
33
37
  KeyContainer: () => import_KeyContainer.KeyContainer,
38
+ LINKED_ACCOUNT_TYPES: () => import_user_management_client.LINKED_ACCOUNT_TYPES,
34
39
  NON_ED25519: () => import_user_management_client.NON_ED25519,
35
40
  Network: () => import_user_management_client.Network,
36
41
  OAUTH_METHODS: () => import_user_management_client.OAUTH_METHODS,
@@ -44,6 +49,7 @@ __export(src_exports, {
44
49
  PopupType: () => import_types.PopupType,
45
50
  PregenIdentifierType: () => import_types.PregenIdentifierType,
46
51
  RecoveryStatus: () => import_types.RecoveryStatus,
52
+ SOLANA_WALLETS: () => import_user_management_client.SOLANA_WALLETS,
47
53
  STORAGE_PREFIX: () => import_constants.PREFIX,
48
54
  WALLET_SCHEMES: () => import_user_management_client.WALLET_SCHEMES,
49
55
  WALLET_TYPES: () => import_user_management_client.WALLET_TYPES,
@@ -110,9 +116,14 @@ const paraVersion = import_ParaCore.ParaCore.version;
110
116
  var src_default = import_ParaCore.ParaCore;
111
117
  // Annotate the CommonJS export names for ESM import in node:
112
118
  0 && (module.exports = {
119
+ AccountLinkError,
113
120
  AuthMethod,
121
+ COSMOS_WALLETS,
122
+ EVM_WALLETS,
123
+ EXTERNAL_WALLET_TYPES,
114
124
  EmailTheme,
115
125
  KeyContainer,
126
+ LINKED_ACCOUNT_TYPES,
116
127
  NON_ED25519,
117
128
  Network,
118
129
  OAUTH_METHODS,
@@ -126,6 +137,7 @@ var src_default = import_ParaCore.ParaCore;
126
137
  PopupType,
127
138
  PregenIdentifierType,
128
139
  RecoveryStatus,
140
+ SOLANA_WALLETS,
129
141
  STORAGE_PREFIX,
130
142
  WALLET_SCHEMES,
131
143
  WALLET_TYPES,