@getpara/core-sdk 2.0.0-alpha.63 → 2.0.0-alpha.65
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 +372 -104
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/transmission/transmissionUtils.js +4 -3
- package/dist/cjs/types/coreApi.js +5 -2
- package/dist/cjs/types/popup.js +1 -0
- package/dist/cjs/utils/index.js +3 -1
- package/dist/cjs/utils/wallet.js +15 -0
- package/dist/cjs/utils/window.js +38 -0
- package/dist/esm/ParaCore.js +375 -105
- package/dist/esm/constants.js +1 -1
- package/dist/esm/index.js +10 -2
- package/dist/esm/transmission/transmissionUtils.js +4 -3
- package/dist/esm/types/coreApi.js +5 -2
- package/dist/esm/types/popup.js +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/wallet.js +14 -0
- package/dist/esm/utils/window.js +16 -0
- package/dist/types/ParaCore.d.ts +23 -7
- package/dist/types/index.d.ts +4 -4
- package/dist/types/shares/enclave.d.ts +1 -1
- package/dist/types/types/coreApi.d.ts +23 -4
- package/dist/types/types/methods.d.ts +15 -8
- package/dist/types/types/popup.d.ts +2 -1
- package/dist/types/types/wallet.d.ts +1 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/wallet.d.ts +1 -0
- package/dist/types/utils/window.d.ts +2 -0
- package/package.json +3 -3
package/dist/cjs/ParaCore.js
CHANGED
|
@@ -100,7 +100,7 @@ var import_utils2 = require("./utils/index.js");
|
|
|
100
100
|
var import_errors = require("./errors.js");
|
|
101
101
|
var constants = __toESM(require("./constants.js"));
|
|
102
102
|
var import_enclave = require("./shares/enclave.js");
|
|
103
|
-
var _authInfo, _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, prepareDoneState_fn, prepareVerificationState_fn, prepareLoginState_fn, prepareSignUpState_fn;
|
|
103
|
+
var _authInfo, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, assertIsLinkingAccount_fn, assertIsLinkingAccountOrStart_fn, getOAuthUrl_fn, waitForLoginProcess_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareDoneState_fn, prepareVerificationState_fn, prepareLoginState_fn, prepareSignUpState_fn;
|
|
104
104
|
if (typeof global !== "undefined") {
|
|
105
105
|
global.Buffer = global.Buffer || import_buffer.Buffer;
|
|
106
106
|
} else if (typeof window !== "undefined") {
|
|
@@ -116,6 +116,7 @@ const _ParaCore = class _ParaCore {
|
|
|
116
116
|
__privateAdd(this, _ParaCore_instances);
|
|
117
117
|
this.popupWindow = null;
|
|
118
118
|
__privateAdd(this, _authInfo);
|
|
119
|
+
this.isSwitchingWallets = false;
|
|
119
120
|
this.isNativePasskey = false;
|
|
120
121
|
this.isReady = false;
|
|
121
122
|
this.accountLinkInProgress = void 0;
|
|
@@ -134,20 +135,33 @@ const _ParaCore = class _ParaCore {
|
|
|
134
135
|
*/
|
|
135
136
|
this.externalWallets = {};
|
|
136
137
|
this.onRampPopup = void 0;
|
|
138
|
+
this.nonPersistedStorageKeys = [];
|
|
137
139
|
this.localStorageGetItem = (key) => {
|
|
138
|
-
|
|
140
|
+
var _a;
|
|
141
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
142
|
+
return this.platformUtils.localStorage.get(key);
|
|
143
|
+
}
|
|
139
144
|
};
|
|
140
145
|
this.localStorageSetItem = (key, value) => {
|
|
141
|
-
|
|
146
|
+
var _a;
|
|
147
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
148
|
+
return this.platformUtils.localStorage.set(key, value);
|
|
149
|
+
}
|
|
142
150
|
};
|
|
143
151
|
this.localStorageRemoveItem = (key) => {
|
|
144
152
|
return this.platformUtils.localStorage.removeItem(key);
|
|
145
153
|
};
|
|
146
154
|
this.sessionStorageGetItem = (key) => {
|
|
147
|
-
|
|
155
|
+
var _a;
|
|
156
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
157
|
+
return this.platformUtils.sessionStorage.get(key);
|
|
158
|
+
}
|
|
148
159
|
};
|
|
149
160
|
this.sessionStorageSetItem = (key, value) => {
|
|
150
|
-
|
|
161
|
+
var _a;
|
|
162
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
163
|
+
return this.platformUtils.sessionStorage.set(key, value);
|
|
164
|
+
}
|
|
151
165
|
};
|
|
152
166
|
this.sessionStorageRemoveItem = (key) => {
|
|
153
167
|
return this.platformUtils.sessionStorage.removeItem(key);
|
|
@@ -304,7 +318,7 @@ const _ParaCore = class _ParaCore {
|
|
|
304
318
|
this.setExternalWallets(_externalWallets);
|
|
305
319
|
};
|
|
306
320
|
this.initializeWorker = () => __async(this, null, function* () {
|
|
307
|
-
if (!this.isWorkerInitialized && !this.ctx.disableWebSockets && !this.ctx.disableWorkers) {
|
|
321
|
+
if (!this.isWorkerInitialized && !this.ctx.disableWebSockets && !this.ctx.disableWorkers && !this.isPortal()) {
|
|
308
322
|
try {
|
|
309
323
|
this.isWorkerInitialized = true;
|
|
310
324
|
yield this.platformUtils.initializeWorker(this.ctx);
|
|
@@ -628,15 +642,7 @@ const _ParaCore = class _ParaCore {
|
|
|
628
642
|
};
|
|
629
643
|
}
|
|
630
644
|
isPortal(envOverride) {
|
|
631
|
-
|
|
632
|
-
if (typeof window === "undefined") return false;
|
|
633
|
-
return !!((_a = window.location) == null ? void 0 : _a.host) && (0, import_utils2.getPortalBaseURL)(envOverride ? { env: envOverride } : this.ctx).includes(window.location.host);
|
|
634
|
-
}
|
|
635
|
-
isRecoveryPortal(envOverride) {
|
|
636
|
-
var _a, _b;
|
|
637
|
-
if (typeof window === "undefined") return false;
|
|
638
|
-
const normalizedUrl = (_b = (_a = window.location) == null ? void 0 : _a.host) == null ? void 0 : _b.replace("getpara", "usecapsule");
|
|
639
|
-
return !!normalizedUrl && (0, import_utils2.getPortalBaseURL)(envOverride ? { env: envOverride } : this.ctx).includes(normalizedUrl);
|
|
645
|
+
return (0, import_utils2.isPortal)(this.ctx, envOverride);
|
|
640
646
|
}
|
|
641
647
|
isParaConnect() {
|
|
642
648
|
var _a;
|
|
@@ -761,14 +767,28 @@ const _ParaCore = class _ParaCore {
|
|
|
761
767
|
constructPortalUrl(_0) {
|
|
762
768
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
763
769
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
764
|
-
const [
|
|
770
|
+
const [
|
|
771
|
+
isCreate,
|
|
772
|
+
isLogin,
|
|
773
|
+
isOnRamp,
|
|
774
|
+
isOAuth,
|
|
775
|
+
isOAuthCallback,
|
|
776
|
+
isTelegramLogin,
|
|
777
|
+
isFarcasterLogin,
|
|
778
|
+
isAddNewCredential,
|
|
779
|
+
isSwitchWallets,
|
|
780
|
+
isExportPrivateKey
|
|
781
|
+
] = [
|
|
765
782
|
["createAuth", "createPassword", "createPIN"].includes(type),
|
|
766
|
-
["loginAuth", "loginPassword", "loginPIN", "loginOTP"].includes(type),
|
|
783
|
+
["loginAuth", "loginPassword", "loginPIN", "loginOTP", "switchWallets"].includes(type),
|
|
767
784
|
type === "onRamp",
|
|
768
785
|
type === "oAuth",
|
|
769
786
|
type === "oAuthCallback",
|
|
770
787
|
["telegramLogin", "telegramLoginVerify"].includes(type),
|
|
771
|
-
type === "loginFarcaster"
|
|
788
|
+
type === "loginFarcaster",
|
|
789
|
+
type === "addNewCredential",
|
|
790
|
+
type === "switchWallets",
|
|
791
|
+
type === "exportPrivateKey"
|
|
772
792
|
];
|
|
773
793
|
if (isOAuth && !opts.oAuthMethod) {
|
|
774
794
|
throw new Error("oAuthMethod is required for oAuth portal URLs");
|
|
@@ -777,7 +797,7 @@ const _ParaCore = class _ParaCore {
|
|
|
777
797
|
this.assertIsAuthSet();
|
|
778
798
|
}
|
|
779
799
|
let sessionId = opts.sessionId;
|
|
780
|
-
if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin) && !sessionId) {
|
|
800
|
+
if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin || isExportPrivateKey) && !sessionId) {
|
|
781
801
|
const session = yield this.touchSession(true);
|
|
782
802
|
sessionId = session.sessionId;
|
|
783
803
|
}
|
|
@@ -843,6 +863,18 @@ const _ParaCore = class _ParaCore {
|
|
|
843
863
|
path = "/auth/farcaster";
|
|
844
864
|
break;
|
|
845
865
|
}
|
|
866
|
+
case "switchWallets": {
|
|
867
|
+
path = `/auth/wallets`;
|
|
868
|
+
break;
|
|
869
|
+
}
|
|
870
|
+
case "addNewCredential": {
|
|
871
|
+
path = "/auth/add-new-credential";
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
case "exportPrivateKey": {
|
|
875
|
+
path = `/web/users/${this.userId}/private-key/${opts.pathId}`;
|
|
876
|
+
break;
|
|
877
|
+
}
|
|
846
878
|
default: {
|
|
847
879
|
throw new Error(`invalid URL type ${type}`);
|
|
848
880
|
}
|
|
@@ -861,8 +893,9 @@ const _ParaCore = class _ParaCore {
|
|
|
861
893
|
encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
|
|
862
894
|
sessionId
|
|
863
895
|
};
|
|
864
|
-
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
896
|
+
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
865
897
|
apiKey: this.ctx.apiKey,
|
|
898
|
+
origin: typeof window !== "undefined" ? window.location.origin : void 0,
|
|
866
899
|
partnerId: partner == null ? void 0 : partner.id,
|
|
867
900
|
portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font) || (partner == null ? void 0 : partner.font),
|
|
868
901
|
portalBorderRadius: ((_d = opts.portalTheme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
|
|
@@ -874,12 +907,12 @@ const _ParaCore = class _ParaCore {
|
|
|
874
907
|
portalTextColor: this.portalTextColor,
|
|
875
908
|
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
876
909
|
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
877
|
-
}, isCreate || isLogin ? __spreadProps(__spreadValues({
|
|
910
|
+
}, this.authInfo && (isCreate || isLogin || isAddNewCredential || isOAuthCallback || isSwitchWallets || isExportPrivateKey) ? __spreadProps(__spreadValues({
|
|
878
911
|
authInfo: JSON.stringify(this.authInfo)
|
|
879
912
|
}, (0, import_user_management_client.isPhone)(this.authInfo.auth) ? (0, import_utils2.splitPhoneNumber)(this.authInfo.auth.phone) : this.authInfo.auth), {
|
|
880
913
|
pfpUrl: this.authInfo.pfpUrl,
|
|
881
914
|
displayName: this.authInfo.displayName
|
|
882
|
-
}) : {}), isOnRamp ? {
|
|
915
|
+
}) : {}), isOnRamp ? { email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin || isAddNewCredential || isExportPrivateKey ? __spreadProps(__spreadValues({
|
|
883
916
|
sessionId: thisDevice.sessionId,
|
|
884
917
|
encryptionKey: thisDevice.encryptionKey
|
|
885
918
|
}, opts.newDevice ? {
|
|
@@ -889,7 +922,10 @@ const _ParaCore = class _ParaCore {
|
|
|
889
922
|
pregenIds: JSON.stringify(this.pregenIds)
|
|
890
923
|
}) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
|
|
891
924
|
appScheme: opts.appScheme
|
|
892
|
-
} : {}), isTelegramLogin ? { isEmbed: "true" } : {}), opts.params || {})
|
|
925
|
+
} : {}), isTelegramLogin ? { isEmbed: "true" } : {}), isSwitchWallets ? __spreadValues(__spreadValues({}, this.currentWalletIds ? { currentWalletIds: JSON.stringify(this.currentWalletIds) } : {}), this.userId ? { userId: this.userId } : {}) : {}), opts.params || {}), isAddNewCredential ? __spreadProps(__spreadValues({}, opts.addNewCredentialType && { addNewCredentialType: opts.addNewCredentialType.toString() }), {
|
|
926
|
+
addNewCredentialPasskeyId: opts.addNewCredentialPasskeyId,
|
|
927
|
+
addNewCredentialPasswordId: opts.addNewCredentialPasswordId
|
|
928
|
+
}) : {});
|
|
893
929
|
const url = (0, import_utils2.constructUrl)({ base, path, params });
|
|
894
930
|
if (opts.shorten) {
|
|
895
931
|
return (0, import_utils2.shortenUrl)(this.ctx, url);
|
|
@@ -933,7 +969,7 @@ const _ParaCore = class _ParaCore {
|
|
|
933
969
|
throw error;
|
|
934
970
|
}
|
|
935
971
|
if (!this.partner || ((_a = this.partner) == null ? void 0 : _a.id) !== session.partnerId || !(0, import_utils2.supportedWalletTypesEq)(((_b = this.partner) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = this.partner) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
|
|
936
|
-
if (!session.partnerId && !this.
|
|
972
|
+
if (!session.partnerId && !this.isPortal()) {
|
|
937
973
|
this.displayModalError(
|
|
938
974
|
`Invalid API Key. Please ensure you have a valid API key for the current environment: ${(_d = this.ctx.env) == null ? void 0 : _d.toUpperCase()}.`
|
|
939
975
|
);
|
|
@@ -964,6 +1000,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
964
1000
|
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
965
1001
|
}
|
|
966
1002
|
}
|
|
1003
|
+
if (session.currentWalletIds && !(0, import_utils2.currentWalletIdsEq)(session.currentWalletIds, this.currentWalletIds)) {
|
|
1004
|
+
yield this.setCurrentWalletIds(session.currentWalletIds);
|
|
1005
|
+
}
|
|
967
1006
|
return session;
|
|
968
1007
|
});
|
|
969
1008
|
}
|
|
@@ -1424,6 +1463,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1424
1463
|
if (!wallet) return null;
|
|
1425
1464
|
return {
|
|
1426
1465
|
id: wallet.id,
|
|
1466
|
+
partner: wallet.partner,
|
|
1427
1467
|
type,
|
|
1428
1468
|
address: this.getDisplayAddress(id, { addressType: type }),
|
|
1429
1469
|
name: wallet.name
|
|
@@ -1534,7 +1574,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1534
1574
|
}
|
|
1535
1575
|
populateWalletAddresses() {
|
|
1536
1576
|
return __async(this, null, function* () {
|
|
1537
|
-
const res = yield this.ctx.client.getWallets(this.userId, true);
|
|
1577
|
+
const res = yield (this.isPortal() ? this.ctx.client.getAllWallets : this.ctx.client.getWallets)(this.userId, true);
|
|
1538
1578
|
const wallets = res.data.wallets;
|
|
1539
1579
|
wallets.forEach((entity) => {
|
|
1540
1580
|
if (this.wallets[entity.id]) {
|
|
@@ -1803,6 +1843,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1803
1843
|
if (this.externalWalletConnectionType === "VERIFICATION") {
|
|
1804
1844
|
return isSessionActive;
|
|
1805
1845
|
}
|
|
1846
|
+
if (this.isSwitchingWallets) {
|
|
1847
|
+
return isSessionActive;
|
|
1848
|
+
}
|
|
1806
1849
|
return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
|
|
1807
1850
|
});
|
|
1808
1851
|
}
|
|
@@ -1816,6 +1859,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1816
1859
|
}
|
|
1817
1860
|
/**
|
|
1818
1861
|
* Get the auth methods available to an existing user
|
|
1862
|
+
* @deprecated Use supportedUserAuthMethods instead
|
|
1819
1863
|
*/
|
|
1820
1864
|
supportedAuthMethods(auth) {
|
|
1821
1865
|
return __async(this, null, function* () {
|
|
@@ -1834,6 +1878,37 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1834
1878
|
return authMethods;
|
|
1835
1879
|
});
|
|
1836
1880
|
}
|
|
1881
|
+
/**
|
|
1882
|
+
* Get the auth methods available to an existing user
|
|
1883
|
+
*/
|
|
1884
|
+
supportedUserAuthMethods() {
|
|
1885
|
+
return __async(this, null, function* () {
|
|
1886
|
+
yield this.assertIsAuthSet();
|
|
1887
|
+
const { supportedAuthMethods, hasPasswordWithoutPIN } = yield this.ctx.client.getSupportedAuthMethodsV2(
|
|
1888
|
+
this.authInfo.auth
|
|
1889
|
+
);
|
|
1890
|
+
const authMethods = /* @__PURE__ */ new Set();
|
|
1891
|
+
for (const type of supportedAuthMethods) {
|
|
1892
|
+
switch (type) {
|
|
1893
|
+
case "PASSWORD":
|
|
1894
|
+
if (hasPasswordWithoutPIN) {
|
|
1895
|
+
authMethods.add(import_user_management_client.AuthMethod.PASSWORD);
|
|
1896
|
+
}
|
|
1897
|
+
break;
|
|
1898
|
+
case "PASSKEY":
|
|
1899
|
+
authMethods.add(import_user_management_client.AuthMethod.PASSKEY);
|
|
1900
|
+
break;
|
|
1901
|
+
case "PIN":
|
|
1902
|
+
authMethods.add(import_user_management_client.AuthMethod.PIN);
|
|
1903
|
+
break;
|
|
1904
|
+
case "BASIC_LOGIN":
|
|
1905
|
+
authMethods.add(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
1906
|
+
break;
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
return authMethods;
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1837
1912
|
/**
|
|
1838
1913
|
* Get hints associated with the users stored biometrics.
|
|
1839
1914
|
* @deprecated
|
|
@@ -2127,61 +2202,26 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2127
2202
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
2128
2203
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
2129
2204
|
**/
|
|
2130
|
-
waitForLogin() {
|
|
2131
|
-
return __async(this,
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
|
|
2151
|
-
try {
|
|
2152
|
-
let session = yield this.touchSession();
|
|
2153
|
-
if (!session.isAuthenticated) {
|
|
2154
|
-
onPoll == null ? void 0 : onPoll();
|
|
2155
|
-
continue;
|
|
2156
|
-
}
|
|
2157
|
-
session = yield this.userSetupAfterLogin();
|
|
2158
|
-
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
2159
|
-
if (!needsWallet) {
|
|
2160
|
-
if (this.currentWalletIdsArray.length === 0) {
|
|
2161
|
-
onPoll == null ? void 0 : onPoll();
|
|
2162
|
-
continue;
|
|
2163
|
-
}
|
|
2164
|
-
}
|
|
2165
|
-
const fetchedWallets = yield this.fetchWallets();
|
|
2166
|
-
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
2167
|
-
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
2168
|
-
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
2169
|
-
yield this.claimPregenWallets();
|
|
2170
|
-
const resp = {
|
|
2171
|
-
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
2172
|
-
partnerId: session.partnerId
|
|
2173
|
-
};
|
|
2174
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp);
|
|
2175
|
-
return resolve(resp);
|
|
2176
|
-
}
|
|
2177
|
-
onPoll == null ? void 0 : onPoll();
|
|
2178
|
-
} catch (err) {
|
|
2179
|
-
console.error(err);
|
|
2180
|
-
onPoll == null ? void 0 : onPoll();
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
}))();
|
|
2184
|
-
});
|
|
2205
|
+
waitForLogin(args) {
|
|
2206
|
+
return __async(this, null, function* () {
|
|
2207
|
+
return yield __privateMethod(this, _ParaCore_instances, waitForLoginProcess_fn).call(this, args);
|
|
2208
|
+
});
|
|
2209
|
+
}
|
|
2210
|
+
waitForWalletSwitching(args) {
|
|
2211
|
+
return __async(this, null, function* () {
|
|
2212
|
+
return yield __privateMethod(this, _ParaCore_instances, waitForLoginProcess_fn).call(this, __spreadProps(__spreadValues({}, args), { isSwitchingWallets: true }));
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
/**
|
|
2216
|
+
* Gets the switch wallets URL for wallet selection.
|
|
2217
|
+
* The authMethod is automatically included in the URL if available.
|
|
2218
|
+
*
|
|
2219
|
+
* @returns {Promise<{ url: string; authMethod: TAuthMethod }>} The switch wallets URL and authMethod
|
|
2220
|
+
*/
|
|
2221
|
+
getSwitchWalletsUrl() {
|
|
2222
|
+
return __async(this, null, function* () {
|
|
2223
|
+
const url = yield this.constructPortalUrl("switchWallets");
|
|
2224
|
+
return url;
|
|
2185
2225
|
});
|
|
2186
2226
|
}
|
|
2187
2227
|
/**
|
|
@@ -2311,7 +2351,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2311
2351
|
break;
|
|
2312
2352
|
}
|
|
2313
2353
|
++maxPolls;
|
|
2314
|
-
const res = yield this.ctx.client.getWallets(this.userId);
|
|
2354
|
+
const res = yield (this.isPortal() ? this.ctx.client.getAllWallets : this.ctx.client.getWallets)(this.userId);
|
|
2315
2355
|
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
2316
2356
|
if (wallet && wallet.address) {
|
|
2317
2357
|
return;
|
|
@@ -3178,49 +3218,80 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3178
3218
|
}
|
|
3179
3219
|
getNewCredentialAndUrl() {
|
|
3180
3220
|
return __async(this, arguments, function* ({
|
|
3181
|
-
authMethod
|
|
3221
|
+
authMethod: optsAuthMethod,
|
|
3182
3222
|
isForNewDevice = false,
|
|
3183
3223
|
portalTheme,
|
|
3184
3224
|
shorten = false
|
|
3185
3225
|
} = {}) {
|
|
3226
|
+
const userAuthMethods = yield this.supportedUserAuthMethods();
|
|
3227
|
+
const isEnclaveUser = userAuthMethods.has(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
3228
|
+
if (isEnclaveUser) {
|
|
3229
|
+
isForNewDevice = true;
|
|
3230
|
+
}
|
|
3231
|
+
const authMethods = optsAuthMethod ? [optsAuthMethod] : isForNewDevice ? ["PASSKEY", "PIN", "PASSWORD"] : ["PASSKEY"];
|
|
3186
3232
|
this.assertIsAuthSet();
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3233
|
+
const canAddPasswordOrPIN = !userAuthMethods.has(import_user_management_client.AuthMethod.PASSWORD) && !userAuthMethods.has(import_user_management_client.AuthMethod.PIN);
|
|
3234
|
+
let passkeyId, passwordId, urlType;
|
|
3235
|
+
if (authMethods.includes("PASSKEY") && (yield this.isPasskeySupported())) {
|
|
3236
|
+
({
|
|
3237
|
+
data: { id: passkeyId }
|
|
3238
|
+
} = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
3239
|
+
status: import_user_management_client.AuthMethodStatus.PENDING,
|
|
3240
|
+
type: import_user_management_client.PublicKeyType.WEB
|
|
3241
|
+
}));
|
|
3242
|
+
urlType = "createAuth";
|
|
3243
|
+
}
|
|
3244
|
+
if (authMethods.includes("PASSWORD")) {
|
|
3245
|
+
if (!canAddPasswordOrPIN) {
|
|
3246
|
+
if (optsAuthMethod === "PASSWORD") throw new Error("A user cannot have more than one password or PIN.");
|
|
3247
|
+
} else {
|
|
3199
3248
|
({
|
|
3200
|
-
data: { id:
|
|
3249
|
+
data: { id: passwordId }
|
|
3201
3250
|
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3202
3251
|
status: import_user_management_client.AuthMethodStatus.PENDING
|
|
3203
3252
|
}));
|
|
3204
3253
|
urlType = "createPassword";
|
|
3205
|
-
|
|
3206
|
-
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
if (authMethods.includes("PIN")) {
|
|
3257
|
+
if (!canAddPasswordOrPIN) {
|
|
3258
|
+
if (optsAuthMethod === "PIN") throw new Error("A user cannot have more than one password or PIN.");
|
|
3259
|
+
} else {
|
|
3207
3260
|
({
|
|
3208
|
-
data: { id:
|
|
3261
|
+
data: { id: passwordId }
|
|
3209
3262
|
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3210
3263
|
status: import_user_management_client.AuthMethodStatus.PENDING
|
|
3211
3264
|
}));
|
|
3212
3265
|
urlType = "createPIN";
|
|
3213
|
-
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
const credentialId = passkeyId != null ? passkeyId : passwordId;
|
|
3269
|
+
if (this.isNativePasskey && authMethods.includes("PASSKEY")) {
|
|
3270
|
+
return { credentialId };
|
|
3214
3271
|
}
|
|
3215
|
-
const
|
|
3272
|
+
const { sessionId } = yield this.touchSession();
|
|
3273
|
+
const url = yield this.constructPortalUrl(isForNewDevice ? "addNewCredential" : urlType, {
|
|
3216
3274
|
isForNewDevice,
|
|
3217
3275
|
pathId: credentialId,
|
|
3218
3276
|
portalTheme,
|
|
3219
|
-
shorten
|
|
3277
|
+
shorten,
|
|
3278
|
+
sessionId: isForNewDevice ? sessionId : void 0,
|
|
3279
|
+
addNewCredentialType: optsAuthMethod,
|
|
3280
|
+
addNewCredentialPasskeyId: passkeyId,
|
|
3281
|
+
addNewCredentialPasswordId: passwordId
|
|
3220
3282
|
});
|
|
3221
3283
|
return __spreadValues({ credentialId }, url ? { url } : {});
|
|
3222
3284
|
});
|
|
3223
3285
|
}
|
|
3286
|
+
addCredential(_0) {
|
|
3287
|
+
return __async(this, arguments, function* ({ authMethod }) {
|
|
3288
|
+
if (authMethod === "PASSKEY" && !(yield this.isPasskeySupported())) {
|
|
3289
|
+
throw new Error("Passkeys are not supported.");
|
|
3290
|
+
}
|
|
3291
|
+
const { url } = yield this.getNewCredentialAndUrl({ isForNewDevice: true, authMethod });
|
|
3292
|
+
return url;
|
|
3293
|
+
});
|
|
3294
|
+
}
|
|
3224
3295
|
/**
|
|
3225
3296
|
* Returns a Para Portal URL for logging in with a WebAuth passkey, password, PIN or OTP.
|
|
3226
3297
|
* @param {Object} opts the options object
|
|
@@ -3448,6 +3519,40 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3448
3519
|
this.setUserId(userId);
|
|
3449
3520
|
});
|
|
3450
3521
|
}
|
|
3522
|
+
exportPrivateKey() {
|
|
3523
|
+
return __async(this, arguments, function* (args = {}) {
|
|
3524
|
+
let walletId = args == null ? void 0 : args.walletId;
|
|
3525
|
+
if (!(args == null ? void 0 : args.walletId)) {
|
|
3526
|
+
walletId = this.findWalletId(void 0, { forbidPregen: true, scheme: ["DKLS"] });
|
|
3527
|
+
}
|
|
3528
|
+
const wallet = this.wallets[walletId];
|
|
3529
|
+
if (this.externalWallets[walletId]) {
|
|
3530
|
+
throw new Error("Cannot export private key for an external wallet");
|
|
3531
|
+
}
|
|
3532
|
+
if (!wallet || !wallet.signer) {
|
|
3533
|
+
throw new Error("Wallet not found with id: " + walletId);
|
|
3534
|
+
}
|
|
3535
|
+
if (wallet.scheme !== "DKLS") {
|
|
3536
|
+
throw new Error("Cannot export private key for a Solana wallet");
|
|
3537
|
+
}
|
|
3538
|
+
if (wallet.isPregen && !!wallet.pregenIdentifier && wallet.pregenIdentifierType !== "GUEST_ID") {
|
|
3539
|
+
throw new Error("Cannot export private key for a pregenerated wallet");
|
|
3540
|
+
}
|
|
3541
|
+
if (args.shouldOpenPopup) {
|
|
3542
|
+
this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: import_types.PopupType.EXPORT_PRIVATE_KEY });
|
|
3543
|
+
}
|
|
3544
|
+
const exportPrivateKeyUrl = yield this.constructPortalUrl("exportPrivateKey", {
|
|
3545
|
+
pathId: walletId
|
|
3546
|
+
});
|
|
3547
|
+
if (args.shouldOpenPopup) {
|
|
3548
|
+
this.popupWindow.location.href = exportPrivateKeyUrl;
|
|
3549
|
+
}
|
|
3550
|
+
return {
|
|
3551
|
+
url: exportPrivateKeyUrl,
|
|
3552
|
+
popupWindow: this.popupWindow
|
|
3553
|
+
};
|
|
3554
|
+
});
|
|
3555
|
+
}
|
|
3451
3556
|
};
|
|
3452
3557
|
_authInfo = new WeakMap();
|
|
3453
3558
|
_ParaCore_instances = new WeakSet();
|
|
@@ -3561,7 +3666,8 @@ getOAuthUrl_fn = function(_0) {
|
|
|
3561
3666
|
appScheme,
|
|
3562
3667
|
accountLinkInProgress,
|
|
3563
3668
|
sessionLookupId,
|
|
3564
|
-
encryptionKey
|
|
3669
|
+
encryptionKey,
|
|
3670
|
+
portalCallbackParams
|
|
3565
3671
|
}) {
|
|
3566
3672
|
if (!accountLinkInProgress && !this.isPortal()) {
|
|
3567
3673
|
return yield this.constructPortalUrl("oAuth", { sessionId: sessionLookupId, oAuthMethod: method, appScheme });
|
|
@@ -3575,13 +3681,14 @@ getOAuthUrl_fn = function(_0) {
|
|
|
3575
3681
|
path: `/auth/${method.toLowerCase()}`,
|
|
3576
3682
|
params: __spreadProps(__spreadValues({
|
|
3577
3683
|
apiKey: this.ctx.apiKey,
|
|
3684
|
+
origin: typeof window !== "undefined" ? window.location.origin : void 0,
|
|
3578
3685
|
sessionLookupId,
|
|
3579
3686
|
portalSessionLookupId,
|
|
3580
3687
|
appScheme
|
|
3581
3688
|
}, accountLinkInProgress ? {
|
|
3582
3689
|
linkedAccountId: this.accountLinkInProgress.id
|
|
3583
3690
|
} : {}), {
|
|
3584
|
-
callback: !accountLinkInProgress && (yield this.constructPortalUrl("oAuthCallback", {
|
|
3691
|
+
callback: !accountLinkInProgress && (yield this.constructPortalUrl("oAuthCallback", __spreadValues({
|
|
3585
3692
|
sessionId: sessionLookupId,
|
|
3586
3693
|
oAuthMethod: method,
|
|
3587
3694
|
appScheme,
|
|
@@ -3589,11 +3696,172 @@ getOAuthUrl_fn = function(_0) {
|
|
|
3589
3696
|
sessionId: sessionLookupId,
|
|
3590
3697
|
encryptionKey
|
|
3591
3698
|
}
|
|
3592
|
-
}))
|
|
3699
|
+
}, this.isPortal() && { params: portalCallbackParams })))
|
|
3593
3700
|
})
|
|
3594
3701
|
});
|
|
3595
3702
|
});
|
|
3596
3703
|
};
|
|
3704
|
+
waitForLoginProcess_fn = function() {
|
|
3705
|
+
return __async(this, arguments, function* ({
|
|
3706
|
+
isCanceled = () => false,
|
|
3707
|
+
onCancel,
|
|
3708
|
+
onPoll,
|
|
3709
|
+
skipSessionRefresh = false,
|
|
3710
|
+
isSwitchingWallets = false
|
|
3711
|
+
} = {}) {
|
|
3712
|
+
this.devLog("[waitForLoginProcess] Starting", {
|
|
3713
|
+
isSwitchingWallets,
|
|
3714
|
+
skipSessionRefresh,
|
|
3715
|
+
isExternalWalletAuth: this.isExternalWalletAuth
|
|
3716
|
+
});
|
|
3717
|
+
const startedAt = Date.now();
|
|
3718
|
+
let originalCurrentWalletIdsHash;
|
|
3719
|
+
if (isSwitchingWallets) {
|
|
3720
|
+
this.devLog("[waitForLoginProcess] Wallet switching mode enabled");
|
|
3721
|
+
this.isSwitchingWallets = true;
|
|
3722
|
+
const session = yield this.touchSession();
|
|
3723
|
+
originalCurrentWalletIdsHash = session.currentWalletIdsHash;
|
|
3724
|
+
this.devLog("[waitForLoginProcess] Original wallet IDs hash", { originalCurrentWalletIdsHash });
|
|
3725
|
+
}
|
|
3726
|
+
return new Promise((resolve, reject) => {
|
|
3727
|
+
(() => __async(this, null, function* () {
|
|
3728
|
+
var _a;
|
|
3729
|
+
if (!this.isExternalWalletAuth && !isSwitchingWallets) {
|
|
3730
|
+
this.devLog("[waitForLoginProcess] Clearing external wallets");
|
|
3731
|
+
this.externalWallets = {};
|
|
3732
|
+
}
|
|
3733
|
+
let pollCount = 0;
|
|
3734
|
+
while (true) {
|
|
3735
|
+
pollCount++;
|
|
3736
|
+
this.devLog("[waitForLoginProcess] Poll iteration", {
|
|
3737
|
+
pollCount,
|
|
3738
|
+
elapsedMs: Date.now() - startedAt
|
|
3739
|
+
});
|
|
3740
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
3741
|
+
this.devLog("[waitForLoginProcess] Canceled or timed out", {
|
|
3742
|
+
wasCanceled: isCanceled(),
|
|
3743
|
+
timedOut: Date.now() - startedAt > constants.POLLING_TIMEOUT_MS,
|
|
3744
|
+
elapsedMs: Date.now() - startedAt
|
|
3745
|
+
});
|
|
3746
|
+
if (isSwitchingWallets) {
|
|
3747
|
+
this.isSwitchingWallets = false;
|
|
3748
|
+
} else {
|
|
3749
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
|
|
3750
|
+
}
|
|
3751
|
+
onCancel == null ? void 0 : onCancel();
|
|
3752
|
+
return reject("canceled");
|
|
3753
|
+
}
|
|
3754
|
+
yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
|
|
3755
|
+
try {
|
|
3756
|
+
this.devLog("[waitForLoginProcess] Touching session");
|
|
3757
|
+
let session = yield this.touchSession();
|
|
3758
|
+
this.devLog("[waitForLoginProcess] Session state", {
|
|
3759
|
+
isAuthenticated: session.isAuthenticated,
|
|
3760
|
+
currentWalletIdsHash: session.currentWalletIdsHash,
|
|
3761
|
+
needsWallet: session.needsWallet
|
|
3762
|
+
});
|
|
3763
|
+
const shouldContinuePolling = isSwitchingWallets ? originalCurrentWalletIdsHash === session.currentWalletIdsHash : !session.isAuthenticated;
|
|
3764
|
+
this.devLog("[waitForLoginProcess] Should continue polling", {
|
|
3765
|
+
shouldContinuePolling,
|
|
3766
|
+
isSwitchingWallets,
|
|
3767
|
+
originalCurrentWalletIdsHash,
|
|
3768
|
+
sessionCurrentWalletIdsHash: session.currentWalletIdsHash,
|
|
3769
|
+
isAuthenticated: session.isAuthenticated
|
|
3770
|
+
});
|
|
3771
|
+
if (shouldContinuePolling) {
|
|
3772
|
+
onPoll == null ? void 0 : onPoll();
|
|
3773
|
+
continue;
|
|
3774
|
+
}
|
|
3775
|
+
this.devLog("[waitForLoginProcess] Authentication check passed, setting up user");
|
|
3776
|
+
session = yield this.userSetupAfterLogin();
|
|
3777
|
+
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
3778
|
+
this.devLog("[waitForLoginProcess] User setup complete", { needsWallet });
|
|
3779
|
+
if (isSwitchingWallets) {
|
|
3780
|
+
const isWalletSwitchingComplete = originalCurrentWalletIdsHash !== session.currentWalletIdsHash;
|
|
3781
|
+
this.devLog("[waitForLoginProcess] Wallet switching check", {
|
|
3782
|
+
isWalletSwitchingComplete,
|
|
3783
|
+
originalHash: originalCurrentWalletIdsHash,
|
|
3784
|
+
sessionHash: session.currentWalletIdsHash
|
|
3785
|
+
});
|
|
3786
|
+
if (!isWalletSwitchingComplete) {
|
|
3787
|
+
onPoll == null ? void 0 : onPoll();
|
|
3788
|
+
continue;
|
|
3789
|
+
}
|
|
3790
|
+
} else if (!needsWallet) {
|
|
3791
|
+
this.devLog("[waitForLoginProcess] Checking wallet IDs", {
|
|
3792
|
+
currentWalletIdsArrayLength: this.currentWalletIdsArray.length
|
|
3793
|
+
});
|
|
3794
|
+
if (this.currentWalletIdsArray.length === 0) {
|
|
3795
|
+
this.devLog("[waitForLoginProcess] No wallet IDs yet, continuing to poll");
|
|
3796
|
+
onPoll == null ? void 0 : onPoll();
|
|
3797
|
+
continue;
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
this.devLog("[waitForLoginProcess] Getting transmission key shares");
|
|
3801
|
+
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
3802
|
+
this.devLog("[waitForLoginProcess] Transmission shares received", {
|
|
3803
|
+
shareCount: tempSharesRes.data.temporaryShares.length,
|
|
3804
|
+
shares: tempSharesRes.data.temporaryShares.map((s) => ({
|
|
3805
|
+
walletId: s.walletId,
|
|
3806
|
+
walletScheme: s.walletScheme
|
|
3807
|
+
}))
|
|
3808
|
+
});
|
|
3809
|
+
let hasSharesForCurrentWallets;
|
|
3810
|
+
if (!isSwitchingWallets) {
|
|
3811
|
+
this.devLog("[waitForLoginProcess] Fetching wallets");
|
|
3812
|
+
const fetchedWallets = yield this.fetchWallets();
|
|
3813
|
+
this.devLog("[waitForLoginProcess] Wallets fetched", {
|
|
3814
|
+
walletCount: fetchedWallets.length,
|
|
3815
|
+
wallets: fetchedWallets.map((w) => ({ id: w.id, type: w.type, scheme: w.scheme }))
|
|
3816
|
+
});
|
|
3817
|
+
hasSharesForCurrentWallets = tempSharesRes.data.temporaryShares.length === fetchedWallets.length;
|
|
3818
|
+
} else {
|
|
3819
|
+
hasSharesForCurrentWallets = this.currentWalletIdsArray.every(([walletId]) => {
|
|
3820
|
+
return tempSharesRes.data.temporaryShares.some((share) => share.walletId === walletId);
|
|
3821
|
+
});
|
|
3822
|
+
}
|
|
3823
|
+
this.devLog("[waitForLoginProcess] Checking shares for current wallets", {
|
|
3824
|
+
hasSharesForCurrentWallets,
|
|
3825
|
+
currentWalletIdsCount: this.currentWalletIdsArray.length,
|
|
3826
|
+
shareCount: tempSharesRes.data.temporaryShares.length
|
|
3827
|
+
});
|
|
3828
|
+
if (hasSharesForCurrentWallets) {
|
|
3829
|
+
this.devLog("[waitForLoginProcess] Setting up after login");
|
|
3830
|
+
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
3831
|
+
this.devLog("[waitForLoginProcess] Setup after login complete");
|
|
3832
|
+
this.devLog("[waitForLoginProcess] Claiming pregen wallets");
|
|
3833
|
+
yield this.claimPregenWallets();
|
|
3834
|
+
this.devLog("[waitForLoginProcess] Pregen wallets claimed");
|
|
3835
|
+
const resp = {
|
|
3836
|
+
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
3837
|
+
partnerId: session.partnerId
|
|
3838
|
+
};
|
|
3839
|
+
this.devLog("[waitForLoginProcess] Login process complete", {
|
|
3840
|
+
needsWallet: resp.needsWallet,
|
|
3841
|
+
partnerId: resp.partnerId,
|
|
3842
|
+
walletCount: Object.values(this.wallets).length,
|
|
3843
|
+
isSwitchingWallets
|
|
3844
|
+
});
|
|
3845
|
+
if (isSwitchingWallets) {
|
|
3846
|
+
this.devLog("[waitForLoginProcess] Clearing wallet switching state");
|
|
3847
|
+
this.isSwitchingWallets = false;
|
|
3848
|
+
} else {
|
|
3849
|
+
this.devLog("[waitForLoginProcess] Dispatching LOGIN_EVENT");
|
|
3850
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp);
|
|
3851
|
+
}
|
|
3852
|
+
return resolve(resp);
|
|
3853
|
+
}
|
|
3854
|
+
this.devLog("[waitForLoginProcess] Not all shares available yet, continuing to poll");
|
|
3855
|
+
onPoll == null ? void 0 : onPoll();
|
|
3856
|
+
} catch (err) {
|
|
3857
|
+
console.error("[waitForLoginProcess] Error during polling iteration", err);
|
|
3858
|
+
onPoll == null ? void 0 : onPoll();
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
}))();
|
|
3862
|
+
});
|
|
3863
|
+
});
|
|
3864
|
+
};
|
|
3597
3865
|
createPregenWallet_fn = function(opts) {
|
|
3598
3866
|
return __async(this, null, function* () {
|
|
3599
3867
|
var _a, _b;
|