@getpara/core-sdk 2.0.0-alpha.20 → 2.0.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ParaCore.js +329 -66
- package/dist/cjs/constants.js +4 -1
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/types/auth.js +33 -0
- package/dist/cjs/types/coreApi.js +17 -3
- package/dist/cjs/types/index.js +2 -0
- package/dist/esm/ParaCore.js +332 -67
- package/dist/esm/constants.js +3 -1
- package/dist/esm/index.js +14 -2
- package/dist/esm/types/auth.js +11 -0
- package/dist/esm/types/coreApi.js +15 -2
- package/dist/esm/types/index.js +1 -0
- package/dist/types/ParaCore.d.ts +40 -38
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/types/auth.d.ts +16 -0
- package/dist/types/types/coreApi.d.ts +82 -34
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/methods.d.ts +30 -2
- package/dist/types/types/wallet.d.ts +2 -1
- package/package.json +3 -3
package/dist/esm/ParaCore.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
__spreadProps,
|
|
9
9
|
__spreadValues
|
|
10
10
|
} from "./chunk-7B52C2XE.js";
|
|
11
|
-
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;
|
|
11
|
+
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;
|
|
12
12
|
import { Buffer as NodeBuffer } from "buffer";
|
|
13
13
|
if (typeof global !== "undefined") {
|
|
14
14
|
global.Buffer = global.Buffer || NodeBuffer;
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
toPregenIds,
|
|
35
35
|
isExternalWallet,
|
|
36
36
|
WALLET_TYPES,
|
|
37
|
+
LINKED_ACCOUNT_TYPES,
|
|
37
38
|
isPregenAuth
|
|
38
39
|
} from "@getpara/user-management-client";
|
|
39
40
|
import forge from "node-forge";
|
|
@@ -45,7 +46,8 @@ import { distributeNewShare } from "./shares/shareDistribution.js";
|
|
|
45
46
|
import {
|
|
46
47
|
Environment,
|
|
47
48
|
PopupType,
|
|
48
|
-
ParaEvent
|
|
49
|
+
ParaEvent,
|
|
50
|
+
AccountLinkError
|
|
49
51
|
} from "./types/index.js";
|
|
50
52
|
import { sendRecoveryForShare } from "./shares/recovery.js";
|
|
51
53
|
import {
|
|
@@ -87,6 +89,7 @@ const _ParaCore = class _ParaCore {
|
|
|
87
89
|
__privateAdd(this, _authInfo);
|
|
88
90
|
this.isNativePasskey = false;
|
|
89
91
|
__privateAdd(this, _partner);
|
|
92
|
+
this.accountLinkInProgress = void 0;
|
|
90
93
|
this.isAwaitingAccountCreation = false;
|
|
91
94
|
this.isAwaitingLogin = false;
|
|
92
95
|
this.isAwaitingFarcaster = false;
|
|
@@ -469,6 +472,10 @@ const _ParaCore = class _ParaCore {
|
|
|
469
472
|
var _a;
|
|
470
473
|
return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
|
|
471
474
|
}
|
|
475
|
+
get supportedAccountLinks() {
|
|
476
|
+
var _a, _b;
|
|
477
|
+
return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...LINKED_ACCOUNT_TYPES];
|
|
478
|
+
}
|
|
472
479
|
get isWalletTypeEnabled() {
|
|
473
480
|
var _a;
|
|
474
481
|
return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
@@ -644,7 +651,7 @@ const _ParaCore = class _ParaCore {
|
|
|
644
651
|
if (!this.loginEncryptionKeyPair) {
|
|
645
652
|
yield this.setLoginEncryptionKeyPair();
|
|
646
653
|
}
|
|
647
|
-
const base = type === "onRamp" ? getPortalBaseURL(this.ctx) : yield this.getPortalURL();
|
|
654
|
+
const base = type === "onRamp" || type === "telegramLogin" ? getPortalBaseURL(this.ctx, type === "telegramLogin") : yield this.getPortalURL();
|
|
648
655
|
let path;
|
|
649
656
|
switch (type) {
|
|
650
657
|
case "createPassword": {
|
|
@@ -671,6 +678,10 @@ const _ParaCore = class _ParaCore {
|
|
|
671
678
|
path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
|
|
672
679
|
break;
|
|
673
680
|
}
|
|
681
|
+
case "telegramLogin": {
|
|
682
|
+
path = `/auth/telegram`;
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
674
685
|
default: {
|
|
675
686
|
throw new Error(`invalid URL type ${type}`);
|
|
676
687
|
}
|
|
@@ -680,7 +691,7 @@ const _ParaCore = class _ParaCore {
|
|
|
680
691
|
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
681
692
|
sessionId
|
|
682
693
|
};
|
|
683
|
-
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
694
|
+
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
684
695
|
apiKey: this.ctx.apiKey,
|
|
685
696
|
partnerId: partner.id,
|
|
686
697
|
portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
|
|
@@ -706,7 +717,7 @@ const _ParaCore = class _ParaCore {
|
|
|
706
717
|
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
707
718
|
} : {}), {
|
|
708
719
|
pregenIds: JSON.stringify(this.pregenIds)
|
|
709
|
-
}) : {}), opts.params || {});
|
|
720
|
+
}) : {}), type === "telegramLogin" ? { isEmbed: "true" } : {}), opts.params || {});
|
|
710
721
|
const url = constructUrl({ base, path, params });
|
|
711
722
|
if (opts.shorten) {
|
|
712
723
|
return shortenUrl(this.ctx, url);
|
|
@@ -819,7 +830,7 @@ const _ParaCore = class _ParaCore {
|
|
|
819
830
|
});
|
|
820
831
|
}
|
|
821
832
|
assertUserId() {
|
|
822
|
-
if (!this.userId) {
|
|
833
|
+
if (!this.userId || this.isGuestMode) {
|
|
823
834
|
throw new Error("no userId is set");
|
|
824
835
|
}
|
|
825
836
|
return this.userId;
|
|
@@ -880,6 +891,7 @@ const _ParaCore = class _ParaCore {
|
|
|
880
891
|
address,
|
|
881
892
|
type,
|
|
882
893
|
provider,
|
|
894
|
+
providerId,
|
|
883
895
|
addressBech32,
|
|
884
896
|
withFullParaAuth,
|
|
885
897
|
isConnectionOnly,
|
|
@@ -893,6 +905,7 @@ const _ParaCore = class _ParaCore {
|
|
|
893
905
|
name: provider,
|
|
894
906
|
isExternal: true,
|
|
895
907
|
isExternalWithParaAuth: withFullParaAuth,
|
|
908
|
+
externalProviderId: providerId,
|
|
896
909
|
signer: "",
|
|
897
910
|
isExternalConnectionOnly: isConnectionOnly,
|
|
898
911
|
isExternalWithVerification: withVerification
|
|
@@ -1278,27 +1291,64 @@ const _ParaCore = class _ParaCore {
|
|
|
1278
1291
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1279
1292
|
});
|
|
1280
1293
|
}
|
|
1294
|
+
verifyExternalWalletLink(opts) {
|
|
1295
|
+
return __async(this, null, function* () {
|
|
1296
|
+
const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EXTERNAL_WALLET"]);
|
|
1297
|
+
if (!accountLinkInProgress.externalWallet) {
|
|
1298
|
+
throw new Error("no external wallet account link in progress");
|
|
1299
|
+
}
|
|
1300
|
+
const accounts = yield this.verifyLink(__spreadValues({
|
|
1301
|
+
accountLinkInProgress,
|
|
1302
|
+
externalWallet: accountLinkInProgress.externalWallet
|
|
1303
|
+
}, opts));
|
|
1304
|
+
return accounts;
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1281
1307
|
/**
|
|
1282
1308
|
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
1283
1309
|
* creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
|
|
1284
1310
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
1285
1311
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
1286
1312
|
*/
|
|
1287
|
-
|
|
1313
|
+
verifyTelegramProcess(_e) {
|
|
1288
1314
|
return __async(this, null, function* () {
|
|
1289
1315
|
var _f = _e, {
|
|
1290
|
-
telegramAuthResponse
|
|
1316
|
+
telegramAuthResponse,
|
|
1317
|
+
isLinkAccount
|
|
1291
1318
|
} = _f, urlOptions = __objRest(_f, [
|
|
1292
|
-
"telegramAuthResponse"
|
|
1319
|
+
"telegramAuthResponse",
|
|
1320
|
+
"isLinkAccount"
|
|
1293
1321
|
]);
|
|
1294
1322
|
try {
|
|
1295
|
-
|
|
1296
|
-
|
|
1323
|
+
switch (isLinkAccount) {
|
|
1324
|
+
case false: {
|
|
1325
|
+
const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
|
|
1326
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1327
|
+
}
|
|
1328
|
+
case true: {
|
|
1329
|
+
const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
|
|
1330
|
+
const accounts = yield this.verifyLink({
|
|
1331
|
+
accountLinkInProgress,
|
|
1332
|
+
telegramAuthResponse
|
|
1333
|
+
});
|
|
1334
|
+
return accounts;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1297
1337
|
} catch (e) {
|
|
1298
1338
|
throw new Error(e.message);
|
|
1299
1339
|
}
|
|
1300
1340
|
});
|
|
1301
1341
|
}
|
|
1342
|
+
verifyTelegram(opts) {
|
|
1343
|
+
return __async(this, null, function* () {
|
|
1344
|
+
return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
verifyTelegramLink(opts) {
|
|
1348
|
+
return __async(this, null, function* () {
|
|
1349
|
+
return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1302
1352
|
/**
|
|
1303
1353
|
* Performs 2FA verification.
|
|
1304
1354
|
* @param {Object} opts the options object
|
|
@@ -1342,10 +1392,34 @@ const _ParaCore = class _ParaCore {
|
|
|
1342
1392
|
/**
|
|
1343
1393
|
* Resend a verification email for the current user.
|
|
1344
1394
|
*/
|
|
1345
|
-
resendVerificationCode() {
|
|
1346
|
-
return __async(this,
|
|
1395
|
+
resendVerificationCode(_0) {
|
|
1396
|
+
return __async(this, arguments, function* ({
|
|
1397
|
+
type: reason = "SIGNUP"
|
|
1398
|
+
}) {
|
|
1399
|
+
let type, linkedAccountId;
|
|
1400
|
+
switch (reason) {
|
|
1401
|
+
case "SIGNUP":
|
|
1402
|
+
{
|
|
1403
|
+
const authInfo = this.assertIsAuthSet(["email", "phone"]);
|
|
1404
|
+
type = authInfo.authType.toUpperCase();
|
|
1405
|
+
}
|
|
1406
|
+
break;
|
|
1407
|
+
case "LINK_ACCOUNT":
|
|
1408
|
+
{
|
|
1409
|
+
const accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]);
|
|
1410
|
+
linkedAccountId = accountLinkInProgress.id;
|
|
1411
|
+
type = accountLinkInProgress.type;
|
|
1412
|
+
}
|
|
1413
|
+
break;
|
|
1414
|
+
}
|
|
1415
|
+
const userId = this.assertUserId();
|
|
1416
|
+
if (type !== "EMAIL" && type !== "PHONE") {
|
|
1417
|
+
throw new Error("invalid auth type for verification code");
|
|
1418
|
+
}
|
|
1347
1419
|
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
1348
|
-
userId
|
|
1420
|
+
userId,
|
|
1421
|
+
type,
|
|
1422
|
+
linkedAccountId
|
|
1349
1423
|
}, this.getVerificationEmailProps()));
|
|
1350
1424
|
});
|
|
1351
1425
|
}
|
|
@@ -1504,19 +1578,25 @@ const _ParaCore = class _ParaCore {
|
|
|
1504
1578
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
1505
1579
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
1506
1580
|
*/
|
|
1507
|
-
|
|
1581
|
+
verifyFarcasterProcess(_g) {
|
|
1508
1582
|
return __async(this, null, function* () {
|
|
1509
1583
|
var _h = _g, {
|
|
1510
1584
|
isCanceled = () => false,
|
|
1511
1585
|
onConnectUri,
|
|
1512
1586
|
onCancel,
|
|
1513
|
-
onPoll
|
|
1587
|
+
onPoll,
|
|
1588
|
+
isLinkAccount
|
|
1514
1589
|
} = _h, urlOptions = __objRest(_h, [
|
|
1515
1590
|
"isCanceled",
|
|
1516
1591
|
"onConnectUri",
|
|
1517
1592
|
"onCancel",
|
|
1518
|
-
"onPoll"
|
|
1593
|
+
"onPoll",
|
|
1594
|
+
"isLinkAccount"
|
|
1519
1595
|
]);
|
|
1596
|
+
let accountLinkInProgress;
|
|
1597
|
+
if (isLinkAccount) {
|
|
1598
|
+
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
|
|
1599
|
+
}
|
|
1520
1600
|
if (onConnectUri) {
|
|
1521
1601
|
const connectUri = yield this.getFarcasterConnectUri();
|
|
1522
1602
|
onConnectUri(connectUri);
|
|
@@ -1528,46 +1608,53 @@ const _ParaCore = class _ParaCore {
|
|
|
1528
1608
|
try {
|
|
1529
1609
|
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1530
1610
|
onCancel == null ? void 0 : onCancel();
|
|
1531
|
-
return reject("
|
|
1611
|
+
return reject("CANCELED");
|
|
1532
1612
|
}
|
|
1533
1613
|
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1614
|
+
switch (isLinkAccount) {
|
|
1615
|
+
case false:
|
|
1616
|
+
{
|
|
1617
|
+
const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
|
|
1618
|
+
if (isServerAuthState(serverAuthState)) {
|
|
1619
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1620
|
+
return resolve(authState);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
break;
|
|
1624
|
+
case true: {
|
|
1625
|
+
const result = yield this.verifyLink({
|
|
1626
|
+
accountLinkInProgress
|
|
1627
|
+
});
|
|
1628
|
+
if ("isConflict" in result) {
|
|
1629
|
+
throw new Error(AccountLinkError.Conflict);
|
|
1630
|
+
}
|
|
1631
|
+
return resolve(result);
|
|
1632
|
+
}
|
|
1538
1633
|
}
|
|
1539
1634
|
onPoll == null ? void 0 : onPoll();
|
|
1540
1635
|
} catch (e) {
|
|
1541
|
-
|
|
1542
|
-
|
|
1636
|
+
if (!isLinkAccount || e.message === AccountLinkError.Conflict) {
|
|
1637
|
+
return reject(e.message);
|
|
1638
|
+
}
|
|
1543
1639
|
}
|
|
1544
1640
|
}
|
|
1545
1641
|
}))();
|
|
1546
1642
|
});
|
|
1547
1643
|
});
|
|
1548
1644
|
}
|
|
1549
|
-
|
|
1550
|
-
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
1551
|
-
*
|
|
1552
|
-
* @param {Object} opts the options object
|
|
1553
|
-
* @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
|
|
1554
|
-
* @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
|
|
1555
|
-
* @returns {string} the URL for the user to log in with OAuth.
|
|
1556
|
-
*/
|
|
1557
|
-
getOAuthUrl(_i) {
|
|
1645
|
+
verifyFarcaster(opts) {
|
|
1558
1646
|
return __async(this, null, function* () {
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
});
|
|
1647
|
+
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
verifyFarcasterLink(opts) {
|
|
1651
|
+
return __async(this, null, function* () {
|
|
1652
|
+
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
getOAuthUrl(opts) {
|
|
1656
|
+
return __async(this, null, function* () {
|
|
1657
|
+
return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, opts);
|
|
1571
1658
|
});
|
|
1572
1659
|
}
|
|
1573
1660
|
/**
|
|
@@ -1578,7 +1665,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1578
1665
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1579
1666
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
1580
1667
|
*/
|
|
1581
|
-
|
|
1668
|
+
verifyOAuthProcess(_k) {
|
|
1582
1669
|
return __async(this, null, function* () {
|
|
1583
1670
|
var _l = _k, {
|
|
1584
1671
|
method,
|
|
@@ -1586,19 +1673,26 @@ const _ParaCore = class _ParaCore {
|
|
|
1586
1673
|
isCanceled = () => false,
|
|
1587
1674
|
onCancel,
|
|
1588
1675
|
onPoll,
|
|
1589
|
-
onOAuthUrl
|
|
1676
|
+
onOAuthUrl,
|
|
1677
|
+
isLinkAccount
|
|
1590
1678
|
} = _l, urlOptions = __objRest(_l, [
|
|
1591
1679
|
"method",
|
|
1592
1680
|
"deeplinkUrl",
|
|
1593
1681
|
"isCanceled",
|
|
1594
1682
|
"onCancel",
|
|
1595
1683
|
"onPoll",
|
|
1596
|
-
"onOAuthUrl"
|
|
1684
|
+
"onOAuthUrl",
|
|
1685
|
+
"isLinkAccount"
|
|
1597
1686
|
]);
|
|
1598
|
-
let sessionLookupId;
|
|
1687
|
+
let sessionLookupId, accountLinkInProgress;
|
|
1599
1688
|
if (onOAuthUrl) {
|
|
1600
|
-
|
|
1601
|
-
|
|
1689
|
+
if (isLinkAccount) {
|
|
1690
|
+
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
|
|
1691
|
+
sessionLookupId = (yield this.touchSession()).sessionLookupId;
|
|
1692
|
+
} else {
|
|
1693
|
+
sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
1694
|
+
}
|
|
1695
|
+
const oAuthUrl = yield __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, { method, deeplinkUrl, sessionLookupId, accountLinkInProgress });
|
|
1602
1696
|
onOAuthUrl(oAuthUrl);
|
|
1603
1697
|
} else {
|
|
1604
1698
|
({ sessionLookupId } = yield this.touchSession());
|
|
@@ -1610,16 +1704,29 @@ const _ParaCore = class _ParaCore {
|
|
|
1610
1704
|
try {
|
|
1611
1705
|
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1612
1706
|
onCancel == null ? void 0 : onCancel();
|
|
1613
|
-
return reject(
|
|
1707
|
+
return reject(AccountLinkError.Canceled);
|
|
1614
1708
|
}
|
|
1615
1709
|
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1710
|
+
switch (isLinkAccount) {
|
|
1711
|
+
case false:
|
|
1712
|
+
{
|
|
1713
|
+
const serverAuthState = yield this.ctx.client.verifyOAuth();
|
|
1714
|
+
if (isServerAuthState(serverAuthState)) {
|
|
1715
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1716
|
+
return resolve(authState);
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
break;
|
|
1720
|
+
case true: {
|
|
1721
|
+
const accounts = yield this.verifyLink({ accountLinkInProgress });
|
|
1722
|
+
return resolve(accounts);
|
|
1723
|
+
}
|
|
1620
1724
|
}
|
|
1621
1725
|
onPoll == null ? void 0 : onPoll();
|
|
1622
1726
|
} catch (err) {
|
|
1727
|
+
if (isLinkAccount && err.message === AccountLinkError.Conflict) {
|
|
1728
|
+
return reject(err.message);
|
|
1729
|
+
}
|
|
1623
1730
|
onPoll == null ? void 0 : onPoll();
|
|
1624
1731
|
}
|
|
1625
1732
|
}
|
|
@@ -1627,6 +1734,16 @@ const _ParaCore = class _ParaCore {
|
|
|
1627
1734
|
});
|
|
1628
1735
|
});
|
|
1629
1736
|
}
|
|
1737
|
+
verifyOAuth(opts) {
|
|
1738
|
+
return __async(this, null, function* () {
|
|
1739
|
+
return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
verifyOAuthLink(opts) {
|
|
1743
|
+
return __async(this, null, function* () {
|
|
1744
|
+
return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1630
1747
|
/**
|
|
1631
1748
|
* Waits for the session to be active and sets up the user.
|
|
1632
1749
|
*
|
|
@@ -2608,22 +2725,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2608
2725
|
this.externalWallets = {};
|
|
2609
2726
|
this.loginEncryptionKeyPair = void 0;
|
|
2610
2727
|
__privateSet(this, _authInfo, void 0);
|
|
2728
|
+
this.accountLinkInProgress = void 0;
|
|
2611
2729
|
this.userId = void 0;
|
|
2612
2730
|
this.sessionCookie = void 0;
|
|
2613
2731
|
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
2614
2732
|
});
|
|
2615
2733
|
}
|
|
2616
|
-
/** @deprecated */
|
|
2617
|
-
getSupportedCreateAuthMethods() {
|
|
2618
|
-
return __async(this, null, function* () {
|
|
2619
|
-
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2620
|
-
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
2621
|
-
for (const authMethod of partner.supportedAuthMethods) {
|
|
2622
|
-
supportedAuthMethods.add(AuthMethod[authMethod]);
|
|
2623
|
-
}
|
|
2624
|
-
return supportedAuthMethods;
|
|
2625
|
-
});
|
|
2626
|
-
}
|
|
2627
2734
|
/**
|
|
2628
2735
|
* Converts to a string, removing sensitive data when logging this class.
|
|
2629
2736
|
*
|
|
@@ -2776,6 +2883,119 @@ const _ParaCore = class _ParaCore {
|
|
|
2776
2883
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2777
2884
|
});
|
|
2778
2885
|
}
|
|
2886
|
+
getLinkedAccounts() {
|
|
2887
|
+
return __async(this, null, function* () {
|
|
2888
|
+
const userId = this.assertUserId();
|
|
2889
|
+
const { accounts } = yield this.ctx.client.getLinkedAccounts({ userId });
|
|
2890
|
+
return __spreadValues({
|
|
2891
|
+
userId
|
|
2892
|
+
}, accounts);
|
|
2893
|
+
});
|
|
2894
|
+
}
|
|
2895
|
+
linkAccount(opts) {
|
|
2896
|
+
return __async(this, null, function* () {
|
|
2897
|
+
const { supportedAccountLinks = [...LINKED_ACCOUNT_TYPES] } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2898
|
+
let type, identifier, externalWallet, isPermitted;
|
|
2899
|
+
switch (true) {
|
|
2900
|
+
case "auth" in opts:
|
|
2901
|
+
{
|
|
2902
|
+
const authInfo = extractAuthInfo(opts.auth, { isRequired: true });
|
|
2903
|
+
if (authInfo.auth === this.authInfo.auth) {
|
|
2904
|
+
throw new Error(AccountLinkError.Conflict);
|
|
2905
|
+
}
|
|
2906
|
+
type = authInfo.authType.toUpperCase();
|
|
2907
|
+
identifier = authInfo.identifier;
|
|
2908
|
+
isPermitted = supportedAccountLinks.includes(type);
|
|
2909
|
+
}
|
|
2910
|
+
break;
|
|
2911
|
+
case "externalWallet" in opts:
|
|
2912
|
+
{
|
|
2913
|
+
externalWallet = opts.externalWallet;
|
|
2914
|
+
type = "EXTERNAL_WALLET";
|
|
2915
|
+
isPermitted = supportedAccountLinks.includes("EXTERNAL_WALLET") || supportedAccountLinks.includes(externalWallet.providerId);
|
|
2916
|
+
}
|
|
2917
|
+
break;
|
|
2918
|
+
case "type" in opts:
|
|
2919
|
+
{
|
|
2920
|
+
type = opts.type;
|
|
2921
|
+
if (type === "X") {
|
|
2922
|
+
type = "TWITTER";
|
|
2923
|
+
}
|
|
2924
|
+
isPermitted = supportedAccountLinks.includes(type);
|
|
2925
|
+
}
|
|
2926
|
+
break;
|
|
2927
|
+
default:
|
|
2928
|
+
throw new Error("Invalid parameters for linking account, must pass `auth` or `type` or `externalWallet");
|
|
2929
|
+
}
|
|
2930
|
+
if (!isPermitted) {
|
|
2931
|
+
throw new Error(`Account linking for type '${type}' is not supported by the current API key configuration`);
|
|
2932
|
+
}
|
|
2933
|
+
const userId = this.assertUserId();
|
|
2934
|
+
const result = yield this.ctx.client.linkAccount(__spreadValues(__spreadValues({
|
|
2935
|
+
userId,
|
|
2936
|
+
type
|
|
2937
|
+
}, identifier ? { identifier } : {}), externalWallet ? { externalWallet } : {}));
|
|
2938
|
+
if ("isConflict" in result) {
|
|
2939
|
+
throw new Error(AccountLinkError.Conflict);
|
|
2940
|
+
}
|
|
2941
|
+
const { linkedAccountId, signatureVerificationMessage } = result;
|
|
2942
|
+
this.accountLinkInProgress = __spreadValues(__spreadValues({
|
|
2943
|
+
id: linkedAccountId,
|
|
2944
|
+
type,
|
|
2945
|
+
isComplete: false
|
|
2946
|
+
}, identifier ? { identifier } : {}), signatureVerificationMessage && externalWallet ? {
|
|
2947
|
+
externalWallet: __spreadProps(__spreadValues({}, externalWallet), {
|
|
2948
|
+
signatureVerificationMessage
|
|
2949
|
+
})
|
|
2950
|
+
} : {});
|
|
2951
|
+
return this.accountLinkInProgress;
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
unlinkAccount(_0) {
|
|
2955
|
+
return __async(this, arguments, function* ({
|
|
2956
|
+
linkedAccountId
|
|
2957
|
+
}) {
|
|
2958
|
+
if (!linkedAccountId) {
|
|
2959
|
+
throw new Error("No linked account ID provided");
|
|
2960
|
+
}
|
|
2961
|
+
const userId = this.assertUserId();
|
|
2962
|
+
const accounts = yield this.ctx.client.unlinkAccount({ linkedAccountId, userId });
|
|
2963
|
+
return accounts;
|
|
2964
|
+
});
|
|
2965
|
+
}
|
|
2966
|
+
verifyLink() {
|
|
2967
|
+
return __async(this, arguments, function* (_s = {}) {
|
|
2968
|
+
var _t = _s, {
|
|
2969
|
+
accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this)
|
|
2970
|
+
} = _t, opts = __objRest(_t, [
|
|
2971
|
+
"accountLinkInProgress"
|
|
2972
|
+
]);
|
|
2973
|
+
try {
|
|
2974
|
+
const userId = this.assertUserId(), result = yield this.ctx.client.verifyLink(__spreadValues({
|
|
2975
|
+
linkedAccountId: accountLinkInProgress.id,
|
|
2976
|
+
userId
|
|
2977
|
+
}, opts));
|
|
2978
|
+
if ("isConflict" in result) {
|
|
2979
|
+
throw new Error(AccountLinkError.Conflict);
|
|
2980
|
+
}
|
|
2981
|
+
this.accountLinkInProgress = void 0;
|
|
2982
|
+
return result.accounts;
|
|
2983
|
+
} catch (e) {
|
|
2984
|
+
throw new Error(e.message === AccountLinkError.Conflict ? AccountLinkError.Conflict : e.message);
|
|
2985
|
+
}
|
|
2986
|
+
});
|
|
2987
|
+
}
|
|
2988
|
+
verifyEmailOrPhoneLink(_0) {
|
|
2989
|
+
return __async(this, arguments, function* ({
|
|
2990
|
+
verificationCode
|
|
2991
|
+
}) {
|
|
2992
|
+
const accounts = yield this.verifyLink({
|
|
2993
|
+
accountLinkInProgress: __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]),
|
|
2994
|
+
verificationCode
|
|
2995
|
+
});
|
|
2996
|
+
return accounts;
|
|
2997
|
+
});
|
|
2998
|
+
}
|
|
2779
2999
|
};
|
|
2780
3000
|
_authInfo = new WeakMap();
|
|
2781
3001
|
_partner = new WeakMap();
|
|
@@ -2862,6 +3082,51 @@ getPartner_fn = function(partnerId) {
|
|
|
2862
3082
|
return __privateGet(this, _partner);
|
|
2863
3083
|
});
|
|
2864
3084
|
};
|
|
3085
|
+
assertIsLinkingAccount_fn = function(types) {
|
|
3086
|
+
if (!this.accountLinkInProgress || this.accountLinkInProgress.isComplete) {
|
|
3087
|
+
throw new Error("no account linking in progress");
|
|
3088
|
+
}
|
|
3089
|
+
if (types && !types.includes(this.accountLinkInProgress.type)) {
|
|
3090
|
+
throw new Error(
|
|
3091
|
+
`account linking in progress for type ${this.accountLinkInProgress.type}, expected one of ${types.join(", ")}`
|
|
3092
|
+
);
|
|
3093
|
+
}
|
|
3094
|
+
return this.accountLinkInProgress;
|
|
3095
|
+
};
|
|
3096
|
+
assertIsLinkingAccountOrStart_fn = function(type) {
|
|
3097
|
+
return __async(this, null, function* () {
|
|
3098
|
+
if (this.accountLinkInProgress && !this.accountLinkInProgress.isComplete) {
|
|
3099
|
+
return __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, [type]);
|
|
3100
|
+
}
|
|
3101
|
+
return yield this.linkAccount({ type });
|
|
3102
|
+
});
|
|
3103
|
+
};
|
|
3104
|
+
getOAuthUrl_fn = function(_i) {
|
|
3105
|
+
return __async(this, null, function* () {
|
|
3106
|
+
var _j = _i, {
|
|
3107
|
+
method,
|
|
3108
|
+
deeplinkUrl,
|
|
3109
|
+
accountLinkInProgress
|
|
3110
|
+
} = _j, params = __objRest(_j, [
|
|
3111
|
+
"method",
|
|
3112
|
+
"deeplinkUrl",
|
|
3113
|
+
"accountLinkInProgress"
|
|
3114
|
+
]);
|
|
3115
|
+
var _a;
|
|
3116
|
+
const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
3117
|
+
return constructUrl({
|
|
3118
|
+
base: getBaseOAuthUrl(this.ctx.env),
|
|
3119
|
+
path: `/auth/${method}`,
|
|
3120
|
+
params: __spreadValues({
|
|
3121
|
+
apiKey: this.ctx.apiKey,
|
|
3122
|
+
sessionLookupId,
|
|
3123
|
+
deeplinkUrl
|
|
3124
|
+
}, accountLinkInProgress ? {
|
|
3125
|
+
linkedAccountId: this.accountLinkInProgress.id
|
|
3126
|
+
} : {})
|
|
3127
|
+
});
|
|
3128
|
+
});
|
|
3129
|
+
};
|
|
2865
3130
|
createPregenWallet_fn = function(opts) {
|
|
2866
3131
|
return __async(this, null, function* () {
|
|
2867
3132
|
var _a, _b;
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./chunk-7B52C2XE.js";
|
|
2
|
-
const PARA_CORE_VERSION = "2.0.0-alpha.
|
|
2
|
+
const PARA_CORE_VERSION = "2.0.0-alpha.22";
|
|
3
3
|
const PREFIX = "@CAPSULE/";
|
|
4
4
|
const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
|
|
5
5
|
const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
@@ -19,7 +19,9 @@ const POLLING_INTERVAL_MS = 2e3;
|
|
|
19
19
|
const SHORT_POLLING_INTERVAL_MS = 1e3;
|
|
20
20
|
const POLLING_TIMEOUT_MS = 3e5;
|
|
21
21
|
const EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID = "EXTERNAL_WALLET_CONNECTION_ONLY";
|
|
22
|
+
const ACCOUNT_LINK_CONFLICT = "Account already linked";
|
|
22
23
|
export {
|
|
24
|
+
ACCOUNT_LINK_CONFLICT,
|
|
23
25
|
EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
|
|
24
26
|
LOCAL_STORAGE_AUTH_INFO,
|
|
25
27
|
LOCAL_STORAGE_COUNTRY_CODE,
|
package/dist/esm/index.js
CHANGED
|
@@ -15,13 +15,19 @@ import {
|
|
|
15
15
|
PREGEN_IDENTIFIER_TYPES,
|
|
16
16
|
WALLET_TYPES,
|
|
17
17
|
WALLET_SCHEMES,
|
|
18
|
-
OAUTH_METHODS
|
|
18
|
+
OAUTH_METHODS,
|
|
19
|
+
LINKED_ACCOUNT_TYPES,
|
|
20
|
+
EXTERNAL_WALLET_TYPES,
|
|
21
|
+
EVM_WALLETS,
|
|
22
|
+
SOLANA_WALLETS,
|
|
23
|
+
COSMOS_WALLETS
|
|
19
24
|
} from "@getpara/user-management-client";
|
|
20
25
|
import {
|
|
21
26
|
OnRampMethod,
|
|
22
27
|
PopupType,
|
|
23
28
|
PregenIdentifierType,
|
|
24
|
-
RecoveryStatus
|
|
29
|
+
RecoveryStatus,
|
|
30
|
+
AccountLinkError
|
|
25
31
|
} from "./types/index.js";
|
|
26
32
|
export * from "./types/coreApi.js";
|
|
27
33
|
export * from "./types/events.js";
|
|
@@ -62,9 +68,14 @@ import { retrieve } from "./transmission/transmissionUtils.js";
|
|
|
62
68
|
const paraVersion = ParaCore.version;
|
|
63
69
|
var src_default = ParaCore;
|
|
64
70
|
export {
|
|
71
|
+
AccountLinkError,
|
|
65
72
|
AuthMethod,
|
|
73
|
+
COSMOS_WALLETS,
|
|
74
|
+
EVM_WALLETS,
|
|
75
|
+
EXTERNAL_WALLET_TYPES,
|
|
66
76
|
EmailTheme,
|
|
67
77
|
KeyContainer,
|
|
78
|
+
LINKED_ACCOUNT_TYPES,
|
|
68
79
|
NON_ED25519,
|
|
69
80
|
Network,
|
|
70
81
|
OAUTH_METHODS,
|
|
@@ -78,6 +89,7 @@ export {
|
|
|
78
89
|
PopupType,
|
|
79
90
|
PregenIdentifierType,
|
|
80
91
|
RecoveryStatus,
|
|
92
|
+
SOLANA_WALLETS,
|
|
81
93
|
PREFIX as STORAGE_PREFIX,
|
|
82
94
|
WALLET_SCHEMES,
|
|
83
95
|
WALLET_TYPES,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "../chunk-7B52C2XE.js";
|
|
2
|
+
var AccountLinkError = /* @__PURE__ */ ((AccountLinkError2) => {
|
|
3
|
+
AccountLinkError2["NotAuthenticated"] = "No user is currently authenticated";
|
|
4
|
+
AccountLinkError2["Conflict"] = "Account already linked";
|
|
5
|
+
AccountLinkError2["Canceled"] = "Account linking was canceled";
|
|
6
|
+
AccountLinkError2["Unknown"] = "An unknown error occurred";
|
|
7
|
+
return AccountLinkError2;
|
|
8
|
+
})(AccountLinkError || {});
|
|
9
|
+
export {
|
|
10
|
+
AccountLinkError
|
|
11
|
+
};
|